`Return-Path: Date: Thu, 15 Oct 1998 12:43:24 -0500 X-Authentication-Warning: flight.uchicago.edu: goldin set sender to goldin@flight.uchicago.edu using -f From: Alexey Goldin Subject: pgplot interface Reply-To: alexey@oddjob.uchicago.edu PGPLOT is astronomical/physical 2D plotting library written in FORTRAN. homepage: http://astro.caltech.edu/~tjp/pgplot/ It is not complete, but useful as it is and straightforward to extend (what I am doing each time I need new function) Note that documentation is cut and pasted from original pgplot doc file /*---------------- cut here ----------------*/ /* -*- C -*- */ /* To build: yorick -batch make.i ypgplot pgplot.i + matrix.i fft.i Then: make Then copy pgplot.i to startup directory (like /usr/local/share/yorick/1.4/startup) */ /* MAKE-INSTRUCTIONS SRCS = dummy.c LIB = ypgplot DEPLIBS = cpgplot pgplot f2c */ /* Tested on Linux with egcs-g77 --- you may need other libraries */ /* Using C bindings */ extern pgenv_; /* PROTOTYPE void cpgenv(float xmin, float xmax, float ymin, float ymax, int just, int axis); */ /* DOCUMENT SUBROUTINE PGENV (XMIN, XMAX, YMIN, YMAX, JUST, AXIS) REAL XMIN, XMAX, YMIN, YMAX INTEGER JUST, AXIS Set PGPLOT "Plotter Environment". PGENV establishes the scaling for subsequent calls to PGPT, PGLINE, etc. The plotter is advanced to a new page or panel, clearing the screen if necessary. If the "prompt state" is ON (see PGASK), confirmation is requested from the user before clearing the screen. If requested, a box, axes, labels, etc. are drawn according to the setting of argument AXIS. Arguments: XMIN (input) : the world x-coordinate at the bottom left corner of the viewport. XMAX (input) : the world x-coordinate at the top right corner of the viewport (note XMAX may be less than XMIN). YMIN (input) : the world y-coordinate at the bottom left corner of the viewport. YMAX (input) : the world y-coordinate at the top right corner of the viewport (note YMAX may be less than YMIN). JUST (input) : if JUST=1, the scales of the x and y axes (in world coordinates per inch) will be equal, otherwise they will be scaled independently. AXIS (input) : controls the plotting of axes, tick marks, etc: AXIS = -2 : draw no box, axes or labels; AXIS = -1 : draw box only; AXIS = 0 : draw box and label it with coordinates; AXIS = 1 : same as AXIS=0, but also draw the coordinate axes (X=0, Y=0); AXIS = 2 : same as AXIS=1, but also draw grid lines at major increments of the coordinates; AXIS = 10 : draw box and label X-axis logarithmically; AXIS = 20 : draw box and label Y-axis logarithmically; AXIS = 30 : draw box and label both axes logarithmically. For other axis options, use routine PGBOX. PGENV can be persuaded to call PGBOX with additional axis options by defining an environment parameter PGPLOT_ENVOPT containing the required option codes. Examples: PGPLOT_ENVOPT=P ! draw Projecting tick marks PGPLOT_ENVOPT=I ! Invert the tick marks PGPLOT_ENVOPT=IV ! Invert tick marks and label y Vertically */ func pgenv(xmin, xmax, ymin, ymax, just=, axis=) { /* DOCUMENT func pgenv(xmin, xmax, ymin, ymax, just=, axis=) See docs for pgenv_ just = 0, axis=0 by default */ if(is_void(just)) { just = 0; } if(is_void(axis)) { axis = 0; } pgenv_,xmin, xmax, ymin, ymax, just, axis; } extern pglab; /* PROTOTYPE void cpglab(string xlbl, string ylbl, string toplbl); */ extern pgpage; /* PROTOTYPE void cpgpage(void); */ extern pgopen; /* PROTOTYPE int cpgopen(string device); */ /* DOCUMENT Open a graphics device for PGPLOT output. If the device is opened successfully, it becomes the selected device to which graphics output is directed until another device is selected with PGSLCT or the device is closed with PGCLOS. The value returned by PGOPEN should be tested to ensure that the device was opened successfully, e.g., ISTAT = PGOPEN('plot.ps/PS') IF (ISTAT .LE. 0 ) STOP */ extern pgclos; /* PROTOTYPE void cpgclos(void); */ extern pgpap; /* PROTOTYPE void cpgpap(float width, float aspect); */ /* DOCUMENT ------------------------------------------------------------------------ Module: PGPAP -- change the size of the view surface ------------------------------------------------------------------------ SUBROUTINE PGPAP (WIDTH, ASPECT) REAL WIDTH, ASPECT This routine changes the size of the view surface ("paper size") to a specified width and aspect ratio (height/width), in so far as this is possible on the specific device. It is always possible to obtain a view surface smaller than the default size; on some devices (e.g., printers that print on roll or fan-feed paper) it is possible to obtain a view surface larger than the default. This routine should be called either immediately after PGBEG or immediately before PGPAGE. The new size applies to all subsequent images until the next call to PGPAP. Arguments: WIDTH (input) : the requested width of the view surface in inches; if WIDTH=0.0, PGPAP will obtain the largest view surface available consistent with argument ASPECT. (1 inch = 25.4 mm.) ASPECT (input) : the aspect ratio (height/width) of the view surface; e.g., ASPECT=1.0 gives a square view surface, ASPECT=0.618 gives a horizontal rectangle, ASPECT=1.618 gives a vertical rectangle. */ extern pgsubp; /* PROTOTYPE void cpgsubp(int nxsub, int nysub); */ /* DOCUMENT ------------------------------------------------------------------------ Module: PGSUBP -- subdivide view surface into panels ------------------------------------------------------------------------ SUBROUTINE PGSUBP (NXSUB, NYSUB) INTEGER NXSUB, NYSUB PGPLOT divides the physical surface of the plotting device (screen, window, or sheet of paper) into NXSUB x NYSUB `panels'. When the view surface is sub-divided in this way, PGPAGE moves to the next panel, not the next physical page. The initial subdivision of the view surface is set in the call to PGBEG. When PGSUBP is called, it forces the next call to PGPAGE to start a new physical page, subdivided in the manner indicated. No plotting should be done between a call of PGSUBP and a call of PGPAGE (or PGENV, which calls PGPAGE). If NXSUB > 0, PGPLOT uses the panels in row order; if <0, PGPLOT uses them in column order, e.g., NXSUB=3, NYSUB=2 NXSUB=-3, NYSUB=2 +-----+-----+-----+ +-----+-----+-----+ | 1 | 2 | 3 | | 1 | 3 | 5 | +-----+-----+-----+ +-----+-----+-----+ | 4 | 5 | 6 | | 2 | 4 | 6 | +-----+-----+-----+ +-----+-----+-----+ PGPLOT advances from one panels to the next when PGPAGE is called, clearing the screen or starting a new page when the last panel has been used. It is also possible to jump from one panel to another in random order by calling PGPANL. Arguments: NXSUB (input) : the number of subdivisions of the view surface in X (>0 or <0). NYSUB (input) : the number of subdivisions of the view surface in Y (>0). */ extern pgpanl; /* PROTOTYPE void cpgpanl(int nxc, int nyc); */ /* DOCUMENT SUBROUTINE PGPANL(IX, IY) INTEGER IX, IY Start plotting in a different panel. If the view surface has been divided into panels by PGBEG or PGSUBP, this routine can be used to move to a different panel. Note that PGPLOT does not remember what viewport and window were in use in each panel; these should be reset if necessary after calling PGPANL. Nor does PGPLOT clear the panel: call PGERAS after calling PGPANL to do this. Arguments: IX (input) : the horizontal index of the panel (in the range 1 <= IX <= number of panels in horizontal direction). IY (input) : the vertical index of the panel (in the range 1 <= IY <= number of panels in horizontal direction). */ extern pgsvp; /* PROTOTYPE void cpgsvp(float xleft, float xright, float ybot, float ytop); */ /* DOCUMENT Change the size and position of the viewport, specifying the viewport in normalized device coordinates. Normalized device coordinates run from 0 to 1 in each dimension. The viewport is the rectangle on the view surface "through" which one views the graph. All the PG routines which plot lines etc. plot them within the viewport, and lines are truncated at the edge of the viewport (except for axes, labels etc drawn with PGBOX or PGLAB). The region of world space (the coordinate space of the graph) which is visible through the viewport is specified by a call to PGSWIN. It is legal to request a viewport larger than the view surface; only the part which appears on the view surface will be plotted. Arguments: XLEFT (input) : x-coordinate of left hand edge of viewport, in NDC. XRIGHT (input) : x-coordinate of right hand edge of viewport, in NDC. YBOT (input) : y-coordinate of bottom edge of viewport, in NDC. YTOP (input) : y-coordinate of top edge of viewport, in NDC. */ extern pgswin; /* PROTOTYPE void cpgswin(float x1, float x2, float y1, float y2); */ /* DOCUMENT PGSWIN -- set window SUBROUTINE PGSWIN (X1, X2, Y1, Y2) REAL X1, X2, Y1, Y2 Change the window in world coordinate space that is to be mapped on to the viewport. Usually PGSWIN is called automatically by PGENV, but it may be called directly by the user. Arguments: X1 (input) : the x-coordinate of the bottom left corner of the viewport. X2 (input) : the x-coordinate of the top right corner of the viewport (note X2 may be less than X1). Y1 (input) : the y-coordinate of the bottom left corner of the viewport. Y2 (input) : the y-coordinate of the top right corner of the viewport (note Y2 may be less than Y1). */ extern pgwnad; /* PROTOTYPE void cpgwnad(float x1, float x2, float y1, float y2); */ /* DOCUMENT SUBROUTINE PGWNAD (X1, X2, Y1, Y2) REAL X1, X2, Y1, Y2 Change the window in world coordinate space that is to be mapped on to the viewport, and simultaneously adjust the viewport so that the world-coordinate scales are equal in x and y. The new viewport is the largest one that can fit within the previously set viewport while retaining the required aspect ratio. */ extern pgbox; /* PROTOTYPE void cpgbox(string xopt, float xtick, int nxsub, string yopt, float ytick, int nysub); */ /* DOCUMENT PGBOX -- draw labeled frame around viewport SUBROUTINE PGBOX (XOPT, XTICK, NXSUB, YOPT, YTICK, NYSUB) CHARACTER*(*) XOPT, YOPT REAL XTICK, YTICK INTEGER NXSUB, NYSUB Annotate the viewport with frame, axes, numeric labels, etc. PGBOX is called by on the user's behalf by PGENV, but may also be called explicitly. Arguments: XOPT (input) : string of options for X (horizontal) axis of plot. Options are single letters, and may be in any order (see below). XTICK (input) : world coordinate interval between major tick marks on X axis. If XTICK=0.0, the interval is chosen by PGBOX, so that there will be at least 3 major tick marks along the axis. NXSUB (input) : the number of subintervals to divide the major coordinate interval into. If XTICK=0.0 or NXSUB=0, the number is chosen by PGBOX. YOPT (input) : string of options for Y (vertical) axis of plot. Coding is the same as for XOPT. YTICK (input) : like XTICK for the Y axis. NYSUB (input) : like NXSUB for the Y axis. Options (for parameters XOPT and YOPT): A : draw Axis (X axis is horizontal line Y=0, Y axis is vertical line X=0). B : draw bottom (X) or left (Y) edge of frame. C : draw top (X) or right (Y) edge of frame. G : draw Grid of vertical (X) or horizontal (Y) lines. I : Invert the tick marks; ie draw them outside the viewport instead of inside. L : label axis Logarithmically (see below). N : write Numeric labels in the conventional location below the viewport (X) or to the left of the viewport (Y). P : extend ("Project") major tick marks outside the box (ignored if option I is specified). M : write numeric labels in the unconventional location above the viewport (X) or to the right of the viewport (Y). T : draw major Tick marks at the major coordinate interval. S : draw minor tick marks (Subticks). V : orient numeric labels Vertically. This is only applicable to Y. The default is to write Y-labels parallel to the axis. 1 : force decimal labelling, instead of automatic choice (see PGNUMB). 2 : force exponential labelling, instead of automatic. To get a complete frame, specify BC in both XOPT and YOPT. Tick marks, if requested, are drawn on the axes or frame or both, depending which are requested. If none of ABC is specified, tick marks will not be drawn. When PGENV calls PGBOX, it sets both XOPT and YOPT according to the value of its parameter AXIS: -1: 'BC', 0: 'BCNST', 1: 'ABCNST', 2: 'ABCGNST'. For a logarithmic axis, the major tick interval is always 1.0. The numeric label is 10**(x) where x is the world coordinate at the tick mark. If subticks are requested, 8 subticks are drawn between each major tick at equal logarithmic intervals. To label an axis with time (days, hours, minutes, seconds) or angle (degrees, arcmin, arcsec), use routine PGTBOX. */ extern pgmtxt; /* PROTOTYPE void cpgmtxt(string side, float disp, float coord, float fjust, string text); */ /* DOCUMENT PGMTXT -- write text at position relative to viewport SUBROUTINE PGMTXT (SIDE, DISP, COORD, FJUST, TEXT) CHARACTER*(*) SIDE, TEXT REAL DISP, COORD, FJUST Write text at a position specified relative to the viewport (outside or inside). This routine is useful for annotating graphs. It is used by routine PGLAB. The text is written using the current values of attributes color-index, line-width, character-height, and character-font. Arguments: SIDE (input) : must include one of the characters 'B', 'L', 'T', or 'R' signifying the Bottom, Left, Top, or Right margin of the viewport. If it includes 'LV' or 'RV', the string is written perpendicular to the frame rather than parallel to it. DISP (input) : the displacement of the character string from the specified edge of the viewport, measured outwards from the viewport in units of the character height. Use a negative value to write inside the viewport, a positive value to write outside. COORD (input) : the location of the character string along the specified edge of the viewport, as a fraction of the length of the edge. FJUST (input) : controls justification of the string parallel to the specified edge of the viewport. If FJUST = 0.0, the left-hand end of the string will be placed at COORD; if JUST = 0.5, the center of the string will be placed at COORD; if JUST = 1.0, the right-hand end of the string will be placed at at COORD. Other values between 0 and 1 give inter- mediate placing, but they are not very useful. TEXT (input) : the text string to be plotted. Trailing spaces are ignored when justifying the string, but leading spaces are significant. */ extern pgptxt_; /* PROTOTYPE void cpgptxt(float x, float y, float angle, float fjust, string text); */ /* DOCUMENT SUBROUTINE PGPTXT (X, Y, ANGLE, FJUST, TEXT) REAL X, Y, ANGLE, FJUST CHARACTER*(*) TEXT Primitive routine for drawing text. The text may be drawn at any angle with the horizontal, and may be centered or left- or right- justified at a specified position. Routine PGTEXT provides a simple interface to PGPTXT for horizontal strings. Text is drawn using the current values of attributes color-index, line-width, character-height, and character-font. Text is NOT subject to clipping at the edge of the window. Arguments: X (input) : world x-coordinate. Y (input) : world y-coordinate. The string is drawn with the baseline of all the characters passing through point (X,Y); the positioning of the string along this line is controlled by argument FJUST. ANGLE (input) : angle, in degrees, that the baseline is to make with the horizontal, increasing counter-clockwise (0.0 is horizontal). FJUST (input) : controls horizontal justification of the string. If FJUST = 0.0, the string will be left-justified at the point (X,Y); if FJUST = 0.5, it will be centered, and if FJUST = 1.0, it will be right justified. [Other values of FJUST give other justifications.] TEXT (input) : the character string to be plotted. */ func pgptxt(x,y, text, just=,angle=) { /* DOCUMENT func pgptxt(x,y, text, just=,angle= ) See documentation for pgptxt_ */ if(is_void(just)) { just=0; } if(is_void(angle)) { angle=0.0; } pgptxt_, x,y, angle, just, text; } extern pgbbuf; /* PROTOTYPE void cpgbbuf(void); */ /* DOCUMENT SUBROUTINE PGBBUF Begin saving graphical output commands in an internal buffer; the commands are held until a matching PGEBUF call (or until the buffer is emptied by PGUPDT). This can greatly improve the efficiency of PGPLOT. PGBBUF increments an internal counter, while PGEBUF decrements this counter and flushes the buffer to the output device when the counter drops to zero. PGBBUF and PGEBUF calls should always be paired. Arguments: none */ extern pgpt_; /* PROTOTYPE void cpgpt(int n, float array xpts, float array ypts, int symbol); */ func pgpt(x, y, symbol=) { /* DOCUMENT func pgpt(x, y, symbol=) */ if(is_void(symbol)) { } symbol=1; pgpt_, numberof(x), x, y, symbol; } extern pgline_; /* PROTOTYPE void cpgline(int n, float array xpts, float array ypts); */ func pgline(x, y) { /* DOCUMENT func pgline(x, y) */ pgline_, numberof(x), x, y; } extern pgdraw; /* PROTOTYPE void cpgdraw(float x, float y); */ /* DOCUMENT SUBROUTINE PGDRAW (X, Y) REAL X, Y Draw a line from the current pen position to the point with world-coordinates (X,Y). The line is clipped at the edge of the current window. The new pen position is (X,Y) in world coordinates. Arguments: X (input) : world x-coordinate of the end point of the line. Y (input) : world y-coordinate of the end point of the line. */ extern pgqpos_; /* PROTOTYPE void cpgqpos(float array x, float array y); */ func pgqpos(&x, &y) { /* DOCUMENT SUBROUTINE PGQPOS (X, Y) REAL X, Y Query the current "pen" position in world C coordinates (X,Y). Arguments: X (output) : world x-coordinate of the pen position. Y (output) : world y-coordinate of the pen position. */ xa = ya = array(float,1); pgqpos_, xa, ya; x = xa(1); y = ya(1); } extern pgslw; /* PROTOTYPE void cpgslw(int lw); */ /* DOCUMENT SUBROUTINE PGSLW (LW) INTEGER LW Set the line-width attribute. This attribute affects lines, graph markers, and text. The line width is specified in units of 1/200 (0.005) inch (about 0.13 mm) and must be an integer in the range 1-201. On some devices, thick lines are generated by tracing each line with multiple strokes offset in the direction perpendicular to the line. Argument: LW (input) : width of line, in units of 0.005 inch (0.13 mm) in range 1-201. */ extern pgsci; /* PROTOTYPE void cpgsci(int ci); */ /* DOCUMENT SUBROUTINE PGSCI (CI) INTEGER CI Set the Color Index for subsequent plotting, if the output device permits this. The default color index is 1, usually white on a black background for video displays or black on a white background for printer plots. The color index is an integer in the range 0 to a device-dependent maximum. Color index 0 corresponds to the background color; lines may be "erased" by overwriting them with color index 0 (if the device permits this). If the requested color index is not available on the selected device, color index 1 will be substituted. The assignment of colors to color indices can be changed with subroutine PGSCR (set color representation). Color indices 0-15 have predefined color representations (see the PGPLOT manual), but these may be changed with PGSCR. Color indices above 15 have no predefined representations: if these indices are used, PGSCR must be called to define the representation. Argument: CI (input) : the color index to be used for subsequent plotting on the current device (in range 0-max). If the index exceeds the device-dependent maximum, the default color index (1) is used. */ extern pgshls; /* PROTOTYPE void cpgshls(int ci, float ch, float cl, float cs); */ /* DOCUMENT SUBROUTINE PGSHLS (CI, CH, CL, CS) INTEGER CI REAL CH, CL, CS Set color representation: i.e., define the color to be associated with a color index. This routine is equivalent to PGSCR, but the color is defined in the Hue-Lightness-Saturation model instead of the Red-Green-Blue model. Hue is represented by an angle in degrees, with red at 120, green at 240, and blue at 0 (or 360). Lightness ranges from 0.0 to 1.0, with black at lightness 0.0 and white at lightness 1.0. Saturation ranges from 0.0 (gray) to 1.0 (pure color). Hue is irrelevant when saturation is 0.0. Examples: H L S R G B black any 0.0 0.0 0.0 0.0 0.0 white any 1.0 0.0 1.0 1.0 1.0 medium gray any 0.5 0.0 0.5 0.5 0.5 red 120 0.5 1.0 1.0 0.0 0.0 yellow 180 0.5 1.0 1.0 1.0 0.0 pink 120 0.7 0.8 0.94 0.46 0.46 Reference: SIGGRAPH Status Report of the Graphic Standards Planning Committee, Computer Graphics, Vol.13, No.3, Association for Computing Machinery, New York, NY, 1979. See also: J. D. Foley et al, ``Computer Graphics: Principles and Practice'', second edition, Addison-Wesley, 1990, section 13.3.5. Argument: CI (input) : the color index to be defined, in the range 0-max. If the color index greater than the device maximum is specified, the call is ignored. Color index 0 applies to the background color. CH (input) : hue, in range 0.0 to 360.0. CL (input) : lightness, in range 0.0 to 1.0. CS (input) : saturation, in range 0.0 to 1.0. */ extern pgsls; /* PROTOTYPE void cpgsls(int ls); */ /* DOCUMENT SUBROUTINE PGSLS (LS) INTEGER LS Set the line style attribute for subsequent plotting. This attribute affects line primitives only; it does not affect graph markers, text, or area fill. Five different line styles are available, with the following codes: 1 (full line), 2 (dashed), 3 (dot-dash-dot-dash), 4 (dotted), 5 (dash-dot-dot-dot). The default is 1 (normal full line). Argument: LS (input) : the line-style code for subsequent plotting (in range 1-5). */ extern pgunsa; /* PROTOTYPE void cpgunsa(void); */ /* DOCUMENT see pgsave */ extern pgsave; /* PROTOTYPE void cpgsave(void); */ /* DOCUMENT SUBROUTINE PGSAVE This routine saves the current PGPLOT attributes in a private storage area. They can be restored by calling PGUNSA (unsave). Attributes saved are: character font, character height, color index, fill-area style, line style, line width, pen position, arrow-head style, hatching style, and clipping state. Color representation is not saved. Calls to PGSAVE and PGUNSA should always be paired. Up to 20 copies of the attributes may be saved. PGUNSA always retrieves the last-saved values (last-in first-out stack). Note that when multiple devices are in use, PGUNSA retrieves the values saved by the last PGSAVE call, even if they were for a different device. Arguments: none */ func pgcont(A,C, tr=,blank=) { /* DOCUMENT pgcont(A,C, tr=, blank=) frontend to pgcont_ and pgconb_ */ if(is_void(tr)) { tr = [0.0, 1.0, 0.0, 0.0, 0.0, 1.0]; } dim = dimsof(A); if(is_void(blank)) { pgcont_, A, dim(2), dim(3), 1, dim(2), 1, dim(3), float(C), numberof(C), float(tr); } else { pgconb_, A, dim(2), dim(3), 1, dim(2), 1, dim(3), float(C), numberof(C), float(tr), blank; } } extern pgcont_; /* PROTOTYPE void cpgcont(float array a, int idim, int jdim, int i1, int i2, int j1, int j2, float array c, int nc, float array tr); */ /* DOCUMENT SUBROUTINE PGCONT (A, IDIM, JDIM, I1, I2, J1, J2, C, NC, TR) INTEGER IDIM, JDIM, I1, J1, I2, J2, NC REAL A(IDIM,JDIM), C(*), TR(6) Draw a contour map of an array. The map is truncated if necessary at the boundaries of the viewport. Each contour line is drawn with the current line attributes (color index, style, and width); except that if argument NC is positive (see below), the line style is set by PGCONT to 1 (solid) for positive contours or 2 (dashed) for negative contours. Arguments: A (input) : data array. IDIM (input) : first dimension of A. JDIM (input) : second dimension of A. I1, I2 (input) : range of first index to be contoured (inclusive). J1, J2 (input) : range of second index to be contoured (inclusive). C (input) : array of NC contour levels; dimension at least NC. NC (input) : +/- number of contour levels (less than or equal to dimension of C). If NC is positive, it is the number of contour levels, and the line-style is chosen automatically as described above. If NC is negative, it is minus the number of contour levels, and the current setting of line-style is used for all the contours. TR (input) : array defining a transformation between the I,J grid of the array and the world coordinates. The world coordinates of the array point A(I,J) are given by: X = TR(1) + TR(2)*I + TR(3)*J Y = TR(4) + TR(5)*I + TR(6)*J Usually TR(3) and TR(5) are zero - unless the coordinate transformation involves a rotation or shear. */ extern pgconb_; /* PROTOTYPE void cpgconb(float array a, int idim, int jdim, int i1, int i2, int j1, int j2, float array c, int nc, float array tr, float blank); */ /* DOCUMENT ------------------------------------------------------------------------ Module: PGCONB -- contour map of a 2D data array, with blanking ------------------------------------------------------------------------ SUBROUTINE PGCONB (A, IDIM, JDIM, I1, I2, J1, J2, C, NC, TR, 1 BLANK) INTEGER IDIM, JDIM, I1, I2, J1, J2, NC REAL A(IDIM,JDIM), C(*), TR(6), BLANK Draw a contour map of an array. This routine is the same as PGCONS, except that array elements that have the "magic value" defined by argument BLANK are ignored, making gaps in the contour map. The routine may be useful for data measured on most but not all of the points of a grid. Arguments: A (input) : data array. IDIM (input) : first dimension of A. JDIM (input) : second dimension of A. I1,I2 (input) : range of first index to be contoured (inclusive). J1,J2 (input) : range of second index to be contoured (inclusive). C (input) : array of contour levels (in the same units as the data in array A); dimension at least NC. NC (input) : number of contour levels (less than or equal to dimension of C). The absolute value of this argument is used (for compatibility with PGCONT, where the sign of NC is significant). TR (input) : array defining a transformation between the I,J grid of the array and the world coordinates. The world coordinates of the array point A(I,J) are given by: X = TR(1) + TR(2)*I + TR(3)*J Y = TR(4) + TR(5)*I + TR(6)*J Usually TR(3) and TR(5) are zero - unless the coordinate transformation involves a rotation or shear. BLANK (input) : elements of array A that are exactly equal to this value are ignored (blanked). */ extern pgebuf; /* PROTOTYPE void cpgend(void); */ /* DOCUMENT SUBROUTINE PGEBUF A call to PGEBUF marks the end of a batch of graphical output begun with the last call of PGBBUF. PGBBUF and PGEBUF calls should always be paired. Each call to PGBBUF increments a counter, while each call to PGEBUF decrements the counter. When the counter reaches 0, the batch of output is written on the output device. Arguments: none */ func pg_palette(index) { /* DOCUMENT Installs one of predefined palettes. */ GL = [ 0.0, 1.]; GR = [ 0.0, 1.]; GG = [ 0.0, 1.]; GB = [ 0.0, 1.]; RL = [-0.5, 0.0, 0.17, 0.33, 0.50, 0.67, 0.83, 1.0, 1.7]; RR = [ 0.0, 0.0, 0.0, 0.0, 0.6, 1.0, 1.0, 1.0, 1.]; RG = [0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.6, 0.0, 1.]; RB = [0.0, 0.3, 0.8, 1.0, 0.3, 0.0, 0.0, 0.0, 1.]; HL = [ 0.0, 0.2, 0.4, 0.6, 1.]; HR = [ 0.0, 0.5, 1.0, 1.0, 1.]; HG = [ 0.0, 0.0, 0.5, 1.0, 1.]; HB = [ 0.0, 0.0, 0.0, 0.3, 1.]; WL = [ 0.0, 0.5, 0.5, 0.7, 0.7, 0.85, 0.85, 0.95, 0.95, 1.]; WR = [ 0.0, 1.0, 0.0, 0.0, 0.3, 0.8, 0.3, 1.0, 1.0, 1.]; WG = [ 0.0, 0.5, 0.4, 1.0, 0.0, 0.0, 0.2, 0.7, 1.0, 1.]; WB = [ 0.0, 0.0, 0.0, 0.0, 0.4, 1.0, 0.0, 0.0, 0.95, 1.]; AL = [ 0.0, 0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.5, 0.5, 0.6, 0.6, 0.7, 0.7, 0.8, 0.8, 0.9, 0.9, 1.]; AR = [ 0.0, 0.0, 0.3, 0.3, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.]; AG = [ 0.0, 0.0, 0.3, 0.3, 0.0, 0.0, 0.0, 0.0, 0.8, 0.8, 0.6, 0.6, 1.0, 1.0, 1.0, 1.0, 0.8, 0.8, 0.0, 0.]; AB = [ 0.0, 0.0, 0.3, 0.3, 0.7, 0.7, 0.7, 0.7, 0.9, 0.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.]; if(index==1) { pgctab(GL, GR, GG, GB); } else if(index==2) { pgctab(RL, RR, RG, RB); } else if(index==3) { pgctab(HL, HR, HG, HB); } else if(index==4) { pgctab(WL, WR, WG, WB); } else if(index==5) { pgctab(AL, AR, AG, AB); } ; } func pgctab(l, r, g, b, contrast=, brightness=) { /* DOCUMENT void pgctab(l, r, g, b, contrast=, brightness=) Se help on builtin pgctab_ */ if(is_void(contrast)) { contrast = 1.0; } if(is_void(brightness)) { brightness = 0.5; } pgctab_, float(l), float(r), float(g), float(b),numberof(l), contrast, brightness; } extern pgctab_; /* PROTOTYPE void cpgctab(float array l, float array r, float array g, float array b, int nc, float contra, float bright); */ /* DOCUMENT ------------------------------------------------------------------------ Module: PGCTAB -- install the color table to be used by PGIMAG ------------------------------------------------------------------------ SUBROUTINE PGCTAB(L, R, G, B, NC, CONTRA, BRIGHT) INTEGER NC REAL L(NC), R(NC), G(NC), B(NC), CONTRA, BRIGHT Use the given color table to change the color representations of all color indexes marked for use by PGIMAG. To change which color indexes are thus marked, call PGSCIR before calling PGCTAB or PGIMAG. On devices that can change the color representations of previously plotted graphics, PGCTAB will also change the colors of existing graphics that were plotted with the marked color indexes. This feature can then be combined with PGBAND to interactively manipulate the displayed colors of data previously plotted with PGIMAG. Limitations: 1. Some devices do not propagate color representation changes to previously drawn graphics. 2. Some devices ignore requests to change color representations. 3. The appearance of specific color representations on grey-scale devices is device-dependent. Notes: To reverse the sense of a color table, change the chosen contrast and brightness to -CONTRA and 1-BRIGHT. In the following, the term 'color table' refers to the input L,R,G,B arrays, whereas 'color ramp' refers to the resulting ramp of colors that would be seen with PGWEDG. Arguments: L (input) : An array of NC normalized ramp-intensity levels corresponding to the RGB primary color intensities in R(),G(),B(). Colors on the ramp are linearly interpolated from neighbouring levels. Levels must be sorted in increasing order. 0.0 places a color at the beginning of the ramp. 1.0 places a color at the end of the ramp. Colors outside these limits are legal, but will not be visible if CONTRA=1.0 and BRIGHT=0.5. R (input) : An array of NC normalized red intensities. G (input) : An array of NC normalized green intensities. B (input) : An array of NC normalized blue intensities. NC (input) : The number of color table entries. CONTRA (input) : The contrast of the color ramp (normally 1.0). Negative values reverse the direction of the ramp. BRIGHT (input) : The brightness of the color ramp. This is normally 0.5, but can sensibly hold any value between 0.0 and 1.0. Values at or beyond the latter two extremes, saturate the color ramp with the colors of the respective end of the color table. */ func pgimag(A, C1=, C2=, tr=) { /* DOCUMENT pgimag(A, C1=, C2=, tr=) frontend to pgimag_ */ if(is_void(tr)) { tr = [0.0, 1.0, 0.0, 0.0, 0.0, 1.0]; } if(is_void(C1)) { C1 = A(*)(min); } if(is_void(C2)) { C2 = A(*)(min); } dim = dimsof(A); pgimag_, float(A), dim(2), dim(3), 1, dim(2), 1, dim(3), float(C1), float(C2), float(tr); } extern pgimag_; /* PROTOTYPE void cpgimag(float array a, int idim, int jdim, int i1, int i2, int j1, int j2, float a1, float a2, float array tr); */ /* DOCUMENT SUBROUTINE PGIMAG (A, IDIM, JDIM, I1, I2, J1, J2, 1 A1, A2, TR) INTEGER IDIM, JDIM, I1, I2, J1, J2 REAL A(IDIM,JDIM), A1, A2, TR(6) Draw a color image of an array in current window. The subsection of the array A defined by indices (I1:I2, J1:J2) is mapped onto the view surface world-coordinate system by the transformation matrix TR. The resulting quadrilateral region is clipped at the edge of the window. Each element of the array is represented in the image by a small quadrilateral, which is filled with a color specified by the corresponding array value. The subroutine uses color indices in the range C1 to C2, which can be specified by calling PGSCIR before PGIMAG. The default values for C1 and C2 are device-dependent; these values can be determined by calling PGQCIR. Note that color representations should be assigned to color indices C1 to C2 by calling PGSCR before calling PGIMAG. On some devices (but not all), the color representation can be changed after the call to PGIMAG by calling PGSCR again. Array values in the range A1 to A2 are mapped on to the range of color indices C1 to C2, with array values <= A1 being given color index C1 and values >= A2 being given color index C2. The mapping function for intermediate array values can be specified by calling routine PGSITF before PGIMAG; the default is linear. On devices which have no available color indices (C1 > C2), PGIMAG will return without doing anything. On devices with only one color index (C1=C2), all array values map to the same color which is rather uninteresting. An image is always "opaque", i.e., it obscures all graphical elements previously drawn in the region. The transformation matrix TR is used to calculate the world coordinates of the center of the "cell" that represents each array element. The world coordinates of the center of the cell corresponding to array element A(I,J) are given by: X = TR(1) + TR(2)*I + TR(3)*J Y = TR(4) + TR(5)*I + TR(6)*J Usually TR(3) and TR(5) are zero -- unless the coordinate transformation involves a rotation or shear. The corners of the quadrilateral region that is shaded by PGIMAG are given by applying this transformation to (I1-0.5,J1-0.5), (I2+0.5, J2+0.5). Arguments: A (input) : the array to be plotted. IDIM (input) : the first dimension of array A. JDIM (input) : the second dimension of array A. I1, I2 (input) : the inclusive range of the first index (I) to be plotted. J1, J2 (input) : the inclusive range of the second index (J) to be plotted. A1 (input) : the array value which is to appear with shade C1. A2 (input) : the array value which is to appear with shade C2. TR (input) : transformation matrix between array grid and world coordinates. */ func pggray(A, C1=, C2=, tr=) { /* DOCUMENT pgimag(A, C1=, C2=, tr=) frontend to pgimag_ */ if(is_void(tr)) { tr = [0.0, 1.0, 0.0, 0.0, 0.0, 1.0]; } if(is_void(C1)) { C1 = A(*)(min); } if(is_void(C2)) { C2 = A(*)(min); } dim = dimsof(A); pggray_, float(A), dim(2), dim(3), 1, dim(2), 1, dim(3), float(C1), float(C2), float(tr); } extern pggray_; /* PROTOTYPE void cpggray(float array a, int idim, int jdim, int i1, int i2, int j1, int j2, float fg, float bg, float array tr); */ /* DOCUMENT SUBROUTINE PGGRAY (A, IDIM, JDIM, I1, I2, J1, J2, 1 FG, BG, TR) INTEGER IDIM, JDIM, I1, I2, J1, J2 REAL A(IDIM,JDIM), FG, BG, TR(6) Draw gray-scale map of an array in current window. The subsection of the array A defined by indices (I1:I2, J1:J2) is mapped onto the view surface world-coordinate system by the transformation matrix TR. The resulting quadrilateral region is clipped at the edge of the window and shaded with the shade at each point determined by the corresponding array value. The shade is a number in the range 0 to 1 obtained by linear interpolation between the background level (BG) and the foreground level (FG), i.e., shade = [A(i,j) - BG] / [FG - BG] The background level BG can be either less than or greater than the foreground level FG. Points in the array that are outside the range BG to FG are assigned shade 0 or 1 as appropriate. PGGRAY uses two different algorithms, depending how many color indices are available in the color index range specified for images. (This range is set with routine PGSCIR, and the current or default range can be queried by calling routine PGQCIR). If 16 or more color indices are available, PGGRAY first assigns color representations to these color indices to give a linear ramp between the background color (color index 0) and the foreground color (color index 1), and then calls PGIMAG to draw the image using these color indices. In this mode, the shaded region is "opaque": every pixel is assigned a color. If less than 16 color indices are available, PGGRAY uses only color index 1, and uses a "dithering" algorithm to fill in pixels, with the shade (computed as above) determining the faction of pixels that are filled. In this mode the shaded region is "transparent" and allows previously-drawn graphics to show through. The transformation matrix TR is used to calculate the world coordinates of the center of the "cell" that represents each array element. The world coordinates of the center of the cell corresponding to array element A(I,J) are given by: X = TR(1) + TR(2)*I + TR(3)*J Y = TR(4) + TR(5)*I + TR(6)*J Usually TR(3) and TR(5) are zero -- unless the coordinate transformation involves a rotation or shear. The corners of the quadrilateral region that is shaded by PGGRAY are given by applying this transformation to (I1-0.5,J1-0.5), (I2+0.5, J2+0.5). Arguments: A (input) : the array to be plotted. IDIM (input) : the first dimension of array A. JDIM (input) : the second dimension of array A. I1, I2 (input) : the inclusive range of the first index (I) to be plotted. J1, J2 (input) : the inclusive range of the second index (J) to be plotted. FG (input) : the array value which is to appear with the foreground color (corresponding to color index 1). BG (input) : the array value which is to appear with the background color (corresponding to color index 0). TR (input) : transformation matrix between array grid and world coordinates. */ func pgwedge(side=, disp=,width=, fg=, bg=, label=) { /* DOCUMENT See documentation for pgwedg_ */ if(is_void(label)) { label=" "; } if(is_void(side)) { side="bi"; } if(is_void(disp)) { disp=4.0; } if(is_void(width)) { width=5.0; } pgwedg_, side, disp, width, fg, bg, label; } extern pgwedg_; /* PROTOTYPE void cpgwedg(string side, float disp, float width, float fg, float bg, string label); */ /* DOCUMENT SUBROUTINE PGWEDG(SIDE, DISP, WIDTH, FG, BG, LABEL) CHARACTER *(*) SIDE,LABEL REAL DISP, WIDTH, FG, BG Plot an annotated grey-scale or color wedge parallel to a given axis of the the current viewport. This routine is designed to provide a brightness/color scale for an image drawn with PGIMAG or PGGRAY. The wedge will be drawn with the transfer function set by PGSITF and using the color index range set by PGSCIR. Arguments: SIDE (input) : The first character must be one of the characters 'B', 'L', 'T', or 'R' signifying the Bottom, Left, Top, or Right edge of the viewport. The second character should be 'I' to use PGIMAG to draw the wedge, or 'G' to use PGGRAY. DISP (input) : the displacement of the wedge from the specified edge of the viewport, measured outwards from the viewport in units of the character height. Use a negative value to write inside the viewport, a positive value to write outside. WIDTH (input) : The total width of the wedge including annotation, in units of the character height. FG (input) : The value which is to appear with shade 1 ("foreground"). Use the values of FG and BG that were supplied to PGGRAY or PGIMAG. BG (input) : the value which is to appear with shade 0 ("background"). LABEL (input) : Optional units label. If no label is required use ' '. */ extern pgvect_; /* PROTOTYPE void cpgvect( float array a, float array b, int idim, int jdim, int i1, int i2, int j1, int j2, float c, int nc, float array tr, float blank); */ /* DOCUMENT SUBROUTINE PGVECT (A, B, IDIM, JDIM, I1, I2, J1, J2, C, NC, TR, 1 BLANK) INTEGER IDIM, JDIM, I1, I2, J1, J2, NC REAL A(IDIM,JDIM), B(IDIM, JDIM), TR(6), BLANK, C Draw a vector map of two arrays. This routine is similar to PGCONB in that array elements that have the "magic value" defined by the argument BLANK are ignored, making gaps in the vector map. The routine may be useful for data measured on most but not all of the points of a grid. Vectors are displayed as arrows; the style of the arrowhead can be set with routine PGSAH, and the the size of the arrowhead is determined by the current character size, set by PGSCH. Arguments: A (input) : horizontal component data array. B (input) : vertical component data array. IDIM (input) : first dimension of A and B. JDIM (input) : second dimension of A and B. I1,I2 (input) : range of first index to be mapped (inclusive). J1,J2 (input) : range of second index to be mapped (inclusive). C (input) : scale factor for vector lengths, if 0.0, C will be set so that the longest vector is equal to the smaller of TR(2)+TR(3) and TR(5)+TR(6). NC (input) : vector positioning code. <0 vector head positioned on coordinates >0 vector base positioned on coordinates =0 vector centered on the coordinates TR (input) : array defining a transformation between the I,J grid of the array and the world coordinates. The world coordinates of the array point A(I,J) are given by: X = TR(1) + TR(2)*I + TR(3)*J Y = TR(4) + TR(5)*I + TR(6)*J Usually TR(3) and TR(5) are zero - unless the coordinate transformation involves a rotation or shear. BLANK (input) : elements of arrays A or B that are exactly equal to this value are ignored (blanked). */ func pgvect(X=,Y=,scale=,position=, tr=,blank=) { /* DOCUMENT pgvect(X=, Y=, tr=, blank=) frontend to pgvect_ */ if(is_void(tr)) { tr = [0.0, 1.0, 0.0, 0.0, 0.0, 1.0]; } if(is_void(scale)) { scale = 0.0; } if(is_void(position)) { position = 0; } dim = dimsof(X); if(is_void(blank)) { blank = [X(*)(max), Y(*)(max)](max)*1.01; } pgvect_, X,Y, dim(2), dim(3), 1, dim(2), 1, dim(3), scale, position, float(tr), blank; } func hsv_to_rgb(h,l,s, &r,&g,&b) { /* DOCUMENT Convert a color specified in the HLS color model to one in the RGB model. This is a support routine: no graphics I/O occurs. Reference: SIGGRAPH Status Report of the Graphic Standards Planning Committee, Computer Graphics, Vol.13, No.3, Association for Computing Machinery, New York, NY, 1979. Hue is in degrees. Copied from pgplot. */ hm = h % 360; r = array(structof(l), dimsof(l)); g = array(structof(l), dimsof(l)); b = array(structof(l), dimsof(l)); ind = where(hm < 0); if(numberof(ind) != 0) { hm(ind)+=360; } ma = array(structof(hm), dimsof(hm)); ind = where(l<=0.5); if(numberof(ind) != 0) { ma(ind) = l(ind) *(1.0+s(ind)); } ind = where(l>0.5); if(numberof(ind) != 0) { ma(ind) = l(ind) + s(ind) - l(ind)*s(ind); } mi = 2.0*l-ma; /* R component */ ind = where(hm < 60.0); if(numberof(ind) != 0) { r(ind) = mi(ind) + (ma(ind)-mi(ind))*hm(ind)/60.0; } ind = where((hm >= 60.0) & (hm < 180.0) ); if(numberof(ind) != 0) { r = ma; } ind = where((hm >= 180.0) & (hm < 240.0) ); if(numberof(ind) != 0) { r(ind) = mi(ind) + (ma(ind)-mi(ind))*(240.0-hm(ind))/60.0; } ind = where((hm >= 240.0) & (hm < 360.0) ); if(numberof(ind) != 0) { r(ind) = mi(ind); } /* G component */ ind = where(hm < 120.0); if(numberof(ind) != 0) { g(ind) = mi(ind); } ind = where((hm >= 120.0) & (hm < 180.0) ); if(numberof(ind) != 0) { g(ind) = mi(ind) + (ma(ind)-mi(ind))*(hm(ind)-120.0)/60.0; } ind = where((hm >= 180.0) & (hm < 300.0) ); if(numberof(ind) != 0) { g(ind) = ma(ind); } ind = where((hm >= 300.0) & (hm < 360.0) ); if(numberof(ind) != 0) { g(ind) = mi(ind) + (ma(ind)-mi(ind))*(360.0-hm(ind))/60.0 } /* B component */ ind = where((hm < 60.0) | (hm >= 300.0) ); if(numberof(ind) != 0) { b(ind) = ma(ind); }; ind = where((hm >= 60.0) & (hm < 120.0) ); if(numberof(ind) != 0) { b(ind) = mi(ind) + (ma(ind)-mi(ind))*(120.0-hm(ind))/60.0; } ind = where((hm >= 120.0) & (hm < 240.0) ); if(numberof(ind) != 0) { b(ind) = mi(ind); } ind = where((hm >= 240.0) & (hm < 300.0) ); if(numberof(ind) != 0) { b(ind) = mi(ind) + (ma(ind)-mi(ind))*(hm(ind)-240.0)/60.0; } ind = where(r>1.0); if(numberof(ind) != 0) { r(ind) =1; } ind = where(g>1.0); if(numberof(ind) != 0) { g(ind) =1; } ind = where(b>1.0); if(numberof(ind) != 0) { b(ind) =1; } }