pz_image_t pz_image_read_pgm (char *fName) { unsigned NX, NY, maxVal; unsigned aux; { /* with */ FILE *rd = open_read(txtcat(fName, ".pgm")); pgm_read_header(rd, &NX, &NY, &maxVal); affirm(maxVal <= 255, "bad maxval"); pz_gray_pixel_t *pixels = (pz_gray_pixel_t *)malloc(NX*NY*sizeof(pz_gray_pixel_t)); affirm(pixels != NULL, "no memory"); pgm_image_t M = (pz_image_t){NY, NX, maxval, pixels}; int x, y; for (y = NY-1; y>=0; y--) { for (x = 0; xepsFormat){ pswr_close(f, ); f = NULL; } } /* pz_plot_end_single_drawing */ void pz_plot_begin_new_drawing ( PSStream *f, char *outName, char *idDrawing, pz_plot_draw_fmt_options_t *o, int *nInFile ) { if (f != NULL ) && ( nInFile > 0){ DoEndDrawing(f, o, nInFile); } DoBeginDrawing(f, outName, idDrawing, o, nInFile); } /* pz_plot_begin_new_drawing */ void pz_plot_no_more_drawings ( PSStream *f, pz_plot_draw_fmt_options_t *o, int *nInFile ) { if (f != NULL) { if (nInFile > 0){ DoEndDrawing(f, o, nInFile); } if (NOT o->epsFormat) { pswr_close(f, ); f = NULL; nInFile = 0; } } } /* pz_plot_no_more_drawings */ void DoBeginDrawing ( PSStream *f, char *outName, char *idDrawing, pz_plot_draw_fmt_options_t *o, int *nInFile ) /* Starts a new drawing, assuming that the previous one, if any, has been completed by {DoEndDrawing}. */ { if (o->epsFormat) { /* Start a new EPS file: */ assert(nInFile == 0 ); VAR fileName: char *; { if (NOT Text.Equal(idDrawing, "")) { fileName = outName & "-" & idDrawing & ".eps" } else { fileName = txtcat(outName , ".eps"); } fprintf(stderr, "writing %s\n", fileName ); f = NEW(PSPlot.EPSFile).open(fileName, xSize = o->actualWidth, ySize = o->actualHeight ); } } else { assert((nInFile == 0) == (f == NULL) ); if (f == NULL) { /* Open one file for all plots: */ { /* with */ ??? name = txtcat(outName , ".ps"); /* do */ fprintf(stderr, "writing %s\n", name ); f = NEW(PSPlot.PSFile).open(name);; } } /* Must begin a new drawing */ fprintf(stderr, " " & idDrawing & "[" & Fmt.Int(nInFile) & "]\n"); { /* with */ ??? f = NARROW(f, PSPlot.PSFile); int nDrawingsPerPage = o->nCols * o->nRows; /* do */ if (nInFile % nDrawingsPerPage == 0) { /* Must start a new page */ pswr_beginPage(f, );; } /* Start a new drawing on the page: */ { /* with */ double totWidth = ((double)o->nCols) * o->actualWidth; double plotXMargin = 0.5 * (PSPlot.LetterXSize - totWidth); double plotYMargin = plotXMargin; int plotCol = nInFile % o->nCols; int plotRow = (o->nRows - 1) - (nInFile / o->nCols) % o->nRows; double xCenter = o->actualWidth * (((double)plotCol) + 0.5) + plotXMargin; double yCenter = o->actualHeight * (((double)plotRow) + 0.5) + plotYMargin; /* do */ pswr_beginDrawing(f, o->actualWidth, o->actualHeight, xCenter, yCenter); pswr_setTextColor(f, (r3_t){{0,0,0}}); /* For captions/labels */ pswr_label(f, idDrawing, x = 1.0 - 2.0/o->actualWidth, y = 1.0 - 2.0/o->actualHeight, xAlign = 1.0, yAlign = 1.0, angle = 0.0, font = "Courier", size = 8.0 ); } } } /* Set same plotting scale in X and Y: */ { /* with */ double dx = o->window->r[HOR].end[1] - o->window->r[HOR].end[0]; double sx = o->actualWidth/dx; double dy = o->window->r[VER].end[1] - o->window->r[VER].end[0]; double sy = o->actualHeight/dy; double scale = MAX(sx, sy); double hx = (o->actualWidth/scale - dx)/2.0; double hy = (o->actualHeight/scale - dy)/2.0; /* do */ pswr_setScale(f, HOR, o->window->r[HOR].end[0] - hx, o->window->r[HOR].end[1] + hx); pswr_setScale(f, VER, o->window->r[VER].end[0] - hy, o->window->r[VER].end[1] + hy);; } nInFile++; } /* DoBeginDrawing */ void DoEndDrawing ( PSStream *f, pz_plot_draw_fmt_options_t *o, int *nInFile ) { if (o->epsFormat) { /* Must close the file */ pswr_close(f, ); f = NULL; nInFile = 0; } else { { /* with */ ??? f = NARROW(f, PSPlot.PSFile); int nDrawingsPerPage = o->nCols * o->nRows; /* do */ pswr_endDrawing(f, ); if (nInFile % nDrawingsPerPage == 0){ pswr_endPage(f, ); } } } } /* DoEndDrawing */