home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / crc_plot / part01 next >
Encoding:
Text File  |  1987-07-07  |  26.4 KB  |  1,002 lines

  1. Path: uunet!rs
  2. From: rs@uunet.UU.NET (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v10i045:  CRC Plotting Package, Part01/06
  5. Message-ID: <604@uunet.UU.NET>
  6. Date: 9 Jul 87 01:14:13 GMT
  7. Organization: UUNET Communications Services, Arlington, VA
  8. Lines: 991
  9. Approved: rs@uunet.UU.NET
  10.  
  11. Submitted-by: "Wombat" <rsk@j.cc.purdue.edu>
  12. Posting-Number: Volume 10, Issue 45
  13. Archive-name: crc_plot/Part01
  14.  
  15. [  No more inconsistant headers; I've got my posting tool back.  --r$ ]
  16.  
  17. #    This is a shell archive.
  18. #    Remove everything above and including the cut line.
  19. #    Then run the rest of the file through sh.
  20. #----cut here-----cut here-----cut here-----cut here----#
  21. #!/bin/sh
  22. # shar:    Shell Archiver
  23. #    Run the following text with /bin/sh to create:
  24. #    README
  25. #    Makefile
  26. #    crc.h
  27. #    examples
  28. cat << \SHAR_EOF > README
  29.  
  30. The CRC plotting package is a device independent graphics system. 
  31. It includes subroutines for generating graphics which may be called
  32. from Fortran or C, a two-dimensional plotting utility, and a
  33. three-dimensional plotting utility.
  34.  
  35. The CRC package was originally developed at the Purdue University School
  36. of Electrical Engineering by Carl Crawford; additional work has been
  37. contributed by Mani Azimi and Malcolm Slaney, notably "plot3d".  This
  38. software has been in use locally for several years, and so most of the
  39. obvious bugs have hopefully been caught and fixed.  Although nobody's
  40. willing to promise to fix future bugs immediately, it is not unreasonable
  41. to assume that this package will continue to be supported, so please
  42. do report bugs.  (If you like, send them to me, and I'll forward them
  43. to the folks at EE.)  HOWEVER, no guarantees, folks.
  44.  
  45. This software has been developed on Vaxen running 4.XBSD; it's likely that
  46. it will work on most machines running some variant of 4.XBSD.  The two
  47. user programs contained herein (qplot and plot3d) are probably of some use
  48. to folks who need quick plots with reasonable resolution and labels
  49. and annotation and so on without a lot of bother.  Nice features of qplot
  50. and plot3d include the ability to overlay multiple plots, tolerance of
  51. a lot of different data formats, automatic or explicit scaling, logarithmic
  52. plotting, ability to plot "bar graphs", and adjustable surface tilt (plot3d).
  53. -- 
  54. Rich Kulawiec, rsk@j.cc.purdue.edu, j.cc.purdue.edu!rsk
  55. SHAR_EOF
  56. cat << \SHAR_EOF > Makefile
  57. #
  58. # crc Makefile
  59. #
  60. # $Header: /usr/src/unsup/bin/crc/RCS/Makefile,v 2.0 87/02/28 13:47:25 ksb Exp $
  61. #
  62. #    Richard S. Kulawiec, Purdue University Computing Center
  63. #    9/26/86
  64. #
  65.  
  66. SUBDIR=    src lib
  67.  
  68. LOOP=    for i in ${SUBDIR}; do\
  69.         echo $$i:;\
  70.         cd $$i;\
  71.         [ -f Makefile ] || co Makefile;\
  72.         make ${MFLAGS} DESTDIR=${DESTDIR}  $@;\
  73.         cd ..;\
  74.     done
  75.  
  76. all clean depend install lint print source spotless tags: FRC
  77.     ${LOOP}
  78.  
  79. FRC:
  80. SHAR_EOF
  81. cat << \SHAR_EOF > crc.h
  82. #
  83. /*
  84.     crc.h - include file for the CRC graphics package
  85.  
  86.     Carl Crawford
  87.     Purdue University
  88.     W. Lafayette, IN 47907
  89.  
  90.     Jan. 1981
  91. */
  92.  
  93. #include <stdio.h>
  94. #include <math.h>
  95. #include <signal.h>
  96.  
  97. unsigned short *_pic;   /* pointer to bit plane */
  98. int     _xp,_yp;        /* integer position */
  99. float   _axp,_ayp;      /* real position */
  100. float   _xo,_yo;        /* current origin */
  101. int     _ud;            /* indicates up/down for pen */
  102. int     _error;         /* indicates error in plotting */
  103. float    _fac;        /* scale factor */
  104. float    _ipsz;        /* size of the internal file - 1 */
  105. float    _ipsz10;    /* ipsize / 10.0 */
  106. int     DEV;            /* major device number */
  107. char    DEVN;           /* minor device number */
  108. int    BLANK;        /* 1 = don't blank device before plotting */
  109. char    *STORE;        /* default storage file */
  110. char    *PLOTFILT;    /* Plot Filter Name */
  111. float    TICDIS;        /* distance between tic marks on the axis */
  112. float    HEIGHT;        /* char height in axis routines */
  113. int    DIGITS;        /* number of dec. digits + 1 in axis annotation */
  114. unsigned _bufsize;    /* size of point buffer */
  115. char    _abuf[100];    /* char buffer for anyone */
  116. char    *SITE;        /* site for gplp */ 
  117. FILE    *_pipe_fd;    /* file descriptor for pipes and pseudo pipes */
  118. int    (*_isig)();    /* save SIGINT signal */
  119. int    (*_qsig)();    /* save SIGQUIT signal */
  120. int    (*_hsig)();    /* save SIGHUP signal */
  121. int    _intty[3];    /* save current tty modes in here */
  122.  
  123. /*    control characters */
  124.  
  125. #define    NUL 0        /* <nul> */
  126. #define    SOH 1        /* <soh> */
  127. #define    STX 2        /* <stx> */
  128. #define    ETC 3        /* <etc> */
  129. #define ETX 3           /* <etx> */
  130. #define EOT 4           /* <eot> */
  131. #define ENQ 5           /* <enq> */
  132. #define ACK 6        /* <ack> */
  133. #define BEL 7        /* <bel> */
  134. #define BS 8            /* <bs> */
  135. #define HT 9        /* <ht> */
  136. #define LF 10           /* <lf> */
  137. #define VT 11           /* <vt> */
  138. #define FF 12           /* <ff> */
  139. #define CR 13           /* <cr> */
  140. #define SO 14           /* <so> */
  141. #define SI 15           /* <si> */
  142. #define DLE 16        /* <dle> */
  143. #define DC1 17        /* <dc1> */
  144. #define DC2 18        /* <dc2> */
  145. #define DC3 19        /* <dc3> */
  146. #define DC4 20        /* <dc4> */
  147. #define NAK 21        /* <nak> */
  148. #define    SYN 22        /* <syn> */
  149. #define ETB 23          /* <etb> */
  150. #define CAN 24        /* <can> */
  151. #define EM 25        /* <em> */
  152. #define SUB 26          /* <sub> */
  153. #define ESC 27          /* <esc> */
  154. #define    FS 28        /* <fs> */
  155. #define GS 29           /* <gs> */
  156. #define RS 30           /* <rs> */
  157. #define US 31           /* <us> */
  158.  
  159.  
  160.  
  161. /*      variables for HP and TEK */
  162.  
  163. int _CM;    /* current mode */
  164. int _X;        /* x position */
  165. int _Y;        /* y position */
  166. int _FILL;    /* number of fill characters */
  167.  
  168. #define    BINARY_FONT_FILE    "/usr/unsup/lib/crc/font.5x7"
  169. #define    PLOTBIN            "/usr/bin/plot"
  170.  
  171. #define    BIT    0    /* major device table */
  172. #define GOV    1
  173. #define IMAGE    2
  174. #define    GGOV    3
  175. #define    GIMAGE    4
  176. #define    PLOT    5
  177. #define    TEK    6
  178. #define HP    7
  179.  
  180. #define MBIT    4
  181. /* maximum device in bit plane mode */
  182.  
  183. /*
  184.     Major and minor device tables
  185.  
  186.     DEV     DEVN    dev     OUTPUT
  187.     0       0       0       file or standard output
  188.         1       8       Versatec through gp (I)
  189.         2       16      Printronix through gplp (I) and opr (I)
  190.  
  191.     1       0       1       Comtal graphics overlay 0(*)
  192.         1       9       Comtal graphics overlay 1(*)
  193.         2       17      Comtal graphics overlay 2(*)
  194.  
  195.  
  196.     2       0       2       Comtal image image displayed(*)
  197.         1       10      Comtal image 0(*)
  198.         2       18      Comtal image 1(*)
  199.         3       26      Comtal image 2(*)
  200.  
  201.     3       0       3       Grinnell graphics overlay 0(*)
  202.         1       11      Grinnell graphics overlay 1(*)
  203.         2       19      Grinnell graphics overlay 2(*)
  204.         3       27      Grinnell graphics overlay 3(*)
  205.  
  206.     4       0       4       Grinnell Image being Displayed (*)
  207.         1       12      Grinnell Image Plane 0(*)
  208.         2       20      Grinnell Image Plane 1(*)
  209.         3       28      Grinnell Image Plane 2(*)
  210.         4       36      Grinnell Image Plane 3(*)
  211.         5       44      Grinnell Image Plane 4(*)
  212.  
  213.     5    0    5    Plot Subroutines
  214.  
  215.     6       0       6       Tektronix through standard output
  216.         1    14    Retro-Graphics through standard output
  217.         2    22    Tektronix 4113
  218.  
  219.     7       0       7       HP through /u/lib/graphics/hpd
  220.  
  221. (*) - through /u/lib/graphics/gd
  222.  
  223. */
  224. SHAR_EOF
  225. mkdir examples
  226. chdir examples
  227. cat << \SHAR_EOF > ex1.c
  228. /*
  229.  *    C Example 1 - Compute and plot a sinc(r) function.
  230.  *
  231.  *    Compile with 
  232.  *        cc ex1.c -lm -o ex1
  233.  *
  234.  *    Run with
  235.  *        ex1
  236.  *
  237.  *    Look at the data by typing the command
  238.  *        od -f data
  239.  */
  240.  
  241. #include    <stdio.h>
  242. #include    <math.h>
  243. #define    N    64
  244.  
  245. float    z[N][N];
  246.  
  247. main(){
  248.     int    i, j;
  249.     double    x, y, r;
  250.     FILE    *output;
  251.  
  252.     output = fopen("data","w");    /* Open the output file */
  253.     if (!output){            /* And make sure the open succeeded */
  254.         fprintf(stderr,"Can't open data file for output.\n");
  255.         exit(1);
  256.     }
  257.  
  258.     for (i=0;i<N;i++){        /* Increment the x-direction */
  259.         x = i - N/2;
  260.         for (j=0;j<N;j++){    /* Increment the y-direction */
  261.             y = j - N/2;
  262.             r = sqrt(x*x+y*y);
  263.             if ( r < .0001)
  264.                 z[i][j] = 1.0;
  265.             else
  266.                 z[i][j] = sin(r)/r;
  267.         }
  268.     }
  269.  
  270.                     /* Write the data out in binary
  271.                      * format.
  272.                      */
  273.     fwrite(z,sizeof(z[0][0]),N*N,output);
  274. }
  275. SHAR_EOF
  276. cat << \SHAR_EOF > ex2.c
  277. /*
  278.  *    C Example 2 - Compute and plot a sinc(x)*sinc(y) function.
  279.  *
  280.  *    Compile with 
  281.  *        cc ex2.c -lm -o ex2
  282.  *    
  283.  *    Run with
  284.  *        ex2 > data
  285.  */
  286.  
  287. #include    <stdio.h>
  288. #include    <math.h>
  289. #define    N    64
  290.  
  291. main(){
  292.     int    i, j;
  293.     double    x, y, z, sinc();
  294.  
  295.     for (i=0;i<N;i++){            /* For each x */
  296.         x = i - N/2;
  297.         for (j=0;j<N;j++){        /* and for each y */
  298.             y = j - N/2;
  299.             z = sinc(x)*sinc(y);
  300.             printf("%f\n",z);    /* Write out the value */
  301.         }
  302.     }
  303.  
  304. }
  305.  
  306. double sinc(x)                    /* Compute the sinc(x) */
  307. double    x;
  308. {
  309.     if (fabs(x) < .0001)
  310.         return(1.0);
  311.     else
  312.         return(sin(x)/x);
  313. }
  314. SHAR_EOF
  315. cat << \SHAR_EOF > ex3.c
  316. /*
  317.  *    Qplot C Example - Compute and plot a Gaussian Random Variable
  318.  *
  319.  *    Compile with 
  320.  *        cc ex3.c -lm -o ex3
  321.  *
  322.  *    Run with
  323.  *        ex3
  324.  */
  325.  
  326. #include    <stdio.h>
  327. #include    <math.h>
  328.  
  329. main(){
  330.     int    i;
  331.     double    x, y, Gauss();
  332.     FILE    *xfile, *yfile;
  333.  
  334.     xfile = fopen("x","w");            /* Open the x and y files */
  335.     yfile = fopen("y","w");
  336.  
  337.     if (!xfile || !yfile){            /* Check for Errors */
  338.         printf("Can't open files for output.\n");
  339.         exit(1);
  340.     }
  341.  
  342.     for (i=0;i<100;i++){            /* Now compute 100 RV's */
  343.         x = Gauss()*3.0;        
  344.         y = Gauss();
  345.                         /* Check for out of bounds */
  346.         if (x < -1 || x > 1 || y < -1 || y > 1)
  347.             continue;
  348.         fprintf(xfile,"%f\n",x);    /* Print out the values */
  349.         fprintf(yfile,"%f\n",y);
  350.     }
  351.     fclose(xfile);                /* Close the files */
  352.     fclose(yfile);
  353. }
  354.  
  355. #define    NUM    25
  356.  
  357.                         /*
  358.                          * Compute a Gaussian random
  359.                          * variable by summing a number
  360.                          * of uniformly distributed
  361.                          * variables.
  362.                          *
  363.                          * The returned value will 
  364.                          * have a mean of 0.
  365.                          */
  366. double
  367. Gauss(){
  368.     int    i;
  369.     float    x;
  370.  
  371.     x = 0;
  372.     for (i=0;i<NUM;i++)            
  373.         x += (float)random();
  374.  
  375.                         /*
  376.                          * Scale the sum by the 
  377.                          * maximum value from the
  378.                          * random() subroutine and
  379.                          * the number of RV's summed.
  380.                          */
  381.     return(x/((float)0x7fffffff*NUM/2) - 1.0);
  382. }
  383. SHAR_EOF
  384. cat << \SHAR_EOF > a.f
  385. c
  386. c    Plot3d Fortran Example - Compute and plot a semi-Gaussian function
  387. c
  388. c    Compile with
  389. c        f77 ex.3 -lU77 -o ex3
  390. c
  391. c    Run with
  392. c        ex3
  393. c
  394. c
  395. c                Set the different damping constants
  396. c                of the Gaussian function. 
  397.     sigx1    = 7.0
  398.     sigx2    = 15.0
  399.     sigy    = 5.0
  400. c                Open the z file.
  401.     open(unit=2,file="z",status="unknown",form="formatted")
  402. c                The damping constant is different for 
  403. c                negative and positive values of x while 
  404. c                it is constant along the y axis.
  405. c                Compute the function.
  406.     do 30 j=1 , 32
  407.         yfact    = exp( - ( abs(j-7.0) / sigy ) ** 2 )
  408. c                Compute the first half of the Gaussian function.
  409.         do 10 i=1 , 32
  410.         tmp    = exp( - ( abs(i-33.0) / sigx1 ) ** 2 ) * yfact
  411.         write(2,*)tmp
  412. 10        continue
  413. c                Compute the second half of the Gaussian
  414. c                function with a different damping constant.
  415.         do 20 i=33 , 64
  416.         tmp    = exp( - ( abs(i-33.0) / sigx2 ) ** 2 ) * yfact
  417.         write(2,*)tmp
  418. 20        continue
  419. 30    continue
  420. c                Close the z file.
  421.     close(2)
  422.     stop
  423.     end
  424. SHAR_EOF
  425. cat << \SHAR_EOF > b.f
  426. c
  427. c    Plot3d Fortran Example - Compute and plot a semi-Gaussian function
  428. c                 for non-uniform values of x and y.
  429. c
  430. c    Compile with
  431. c        f77 ex.4 -lU77 -o ex4
  432. c
  433. c    Run with
  434. c        ex4
  435. c
  436.     real    tmp(32)
  437.     integer    ucreat
  438. c                The damping constant is different for 
  439. c                negative and positive values of x while 
  440. c                it is constant along the y axis.
  441. c                Set the different damping constants
  442. c                of the Gaussian function. 
  443.     sigx1    = 3.5
  444.     sigx2    = 7.5
  445.     sigy    = 12.5
  446. c                Create the z file.
  447.     ifd    = ucreat("z",420)
  448. c                Compute the function.
  449.     do 30 j=1 , 16
  450.         yfact    = exp( - ( abs(j-3.5) / sigy ) ** 2 )
  451. c                Compute the first half of the Gaussian function.
  452.         do 10 i=1 , 16
  453.         tmp(i)    = exp( - ( abs(i-16.5) / sigx1 ) ** 2 ) * yfact
  454. 10        continue
  455. c                Compute the second half of the Gaussian
  456. c                function with a different damping constant.
  457.         do 20 i=17 , 32
  458.         tmp(i)    = exp( - ( abs(i-16.5) / sigx2 ) ** 2 ) * yfact
  459. 20        continue
  460.         call uwrite(ifd,tmp,4*32)
  461. 30    continue
  462. c                Open the file x.
  463.     open(unit=2,file="x",status="unknown",form="formatted")
  464. c                Compute the values of x.
  465.     x    = - 10.0 * 16.0 * 0.5 * 0.5
  466. c                To make the sampling non-uniform,
  467. c                use the random function generater.
  468.     do 40 i=1 , 32
  469.         x    = x + 10.0 * rand(13*i) * rand(17*i)
  470.         write(2,*)x
  471. 40    continue
  472. c                Close the file x.
  473.     close(2)
  474. c                Open the file x.
  475.     open(unit=3,file="y",status="unknown",form="formatted")
  476. c                Compute the values of y.
  477.     y    = - 30.0 * 8.0 * 0.5 * 0.5
  478. c                To make the sampling non-uniform,
  479. c                use the random function generater.
  480.     do 50 i=1 , 16
  481.         y    = y + 30.0 * rand(13*i) * rand(17*i)
  482.         write(3,*)y
  483. 50    continue
  484. c                Close the file y.
  485.     close(3)
  486.     stop
  487.     end
  488. SHAR_EOF
  489. cat << \SHAR_EOF > hide.f
  490.  
  491.       subroutine hide(x,y,xg,g,xh,h,ng,maxdim,n1,nfns,
  492.      &xlnth,ylnth,xmin,deltax,xlabel,ymin,deltay,ylabel)
  493.  
  494. c
  495. c     n1 = the number of points plotted in a given call.  If
  496. c          n1 < 0 Y vs X will be plotted in reverse order.
  497. c     x  = a real array containing the horizontal coodinates.
  498. c          The contents of x must be in increasing order.
  499. c          x has dimension n1.
  500. c     y  = a real array containing the vertical coordinates. y has
  501. c          dimension n1.
  502. c     g & xg = two real arrays that hold the current visual
  503. c          maxima.
  504. c     h & xh = two work arrays.
  505. c     ng = a non-positive integer.
  506. c            ng = 0  - draw the 8 1/2 x 11 border and plot visual
  507. c                      maxima.
  508. c            ng = -1 - don't draw the 8 1/2 x 11 border but plot
  509. c                      visual maxima.
  510. c            ng = -2 - draw the border and plot visual minima.  This
  511. c                      results in the "bottom view" of the graph.
  512. c            ng = -3 - don't draw the border but plot the visual
  513. c                      minima.
  514. c     maxdim = the dimension of g, xg, h, xh. If the program is
  515. c          about to go out of bounds in these arrays maxdim will
  516. c          be returned as its negative.  When the subroutine is
  517. c          called with maxdim < 0 it will immediately return.
  518. c     nfns = the total number of curves to be plotted.  If a plot
  519. c          is desired with no shift then nfns is the negative of
  520. c          this number.  nfns = 0 will plot the curve with the
  521. c          same ammount of shift as in the last call.
  522. c     xlnth = length (in inches) of the horizontal axis.
  523. c     ylnth = length (in inches) of the vertical axis.
  524. c     xmin = the minimum value of x.
  525. c     ymin = the minimun value of y.
  526. c     deltax = the x increment per inch.
  527. c     deltay = the y increment per inch.
  528. c
  529.       dimension x(1), y(1), xg(1), g(1), h(1), xh(1)
  530.       character xlabel(1), ylabel(1)
  531. c
  532. c the only purpose of the following equivalence statement
  533. c is to save storage.
  534. c
  535.       equivalence (k1,iwhich), (k2,slope), (fnsm1,z1),
  536.      +            (iggp1,k1), (k1,n2)
  537. c
  538. c eps1 is the relative abcissa increment used to simulate
  539. c discontinuities in the maximum function.
  540. c
  541.       data eps1 /1.0e-3/
  542. c
  543. c the following statement function computes the ordinate on
  544. c the line joining (xi,yi) and (xip1,yip1) corresponding to
  545. c the abcissa xx.
  546. c
  547.       f(xx,xi,yi,xip1,yip1) = yi + (xx - xi) * (yip1 - yi) /
  548.      +                        (xip1 - xi)
  549.       if (maxdim.le.0) return
  550.       ifplot = 1
  551.       if (n1.gt.0) go to 76
  552.       n1 = -n1
  553.       ifplot = 0
  554.    76 do 71 i=2,n1
  555.       if (x(i-1).lt.x(i)) go to 71
  556.       maxdim = 0
  557.       write(6,1020)
  558. 1020  format('abcissa array not in increasing order')
  559.       go to 75
  560.    71 continue
  561.       if (ng.gt.0) go to 5000
  562.       if (n1 + 4.0.le.maxdim) go to 74
  563.       maxdim = -maxdim
  564.    75 return
  565. c
  566. c we want sign = 1 if we are plotting maximum, = -1 if
  567. c minimum
  568. c
  569.    74 sign = 1.0
  570.       if (ng.lt.-1) sign = -1.0
  571. c
  572. c the kth curve to be plotted will (optionally) be
  573. c translated by the vector (-dxin,dyin) * (k - 1) to
  574. c simulate stepping in the depth dimension.
  575. c
  576.       fnsm1 = 0.0
  577.       if (nfns.le.0) go to 46
  578.       fnsm1 = nfns - 1
  579.       dxin = (9.0 - abs(xlnth)) * deltax / fnsm1
  580.       dyin = (6.0 - abs(ylnth)) * deltay / fnsm1
  581. c
  582. c systems routine plot moves the pen to a point whose
  583. c coordinates are specified in inches by the first two
  584. c parameters.  the pen is picked up if the absolute value of
  585. c the third parameter is 3, is put down if 2, and is left as
  586. c after last call if 1.  if the third parameter is negative,
  587. c a new reference point will be established.
  588. c
  589.    46 if (ng.eq.-1.or.ng.eq.-3) go to 41
  590. c
  591. c draw 8 1/2 by 11 inch border.
  592. c
  593.       call plot(0.0,0.0,3)
  594.       call plot (11.0,0.0,2)
  595.       call plot (11.0,8.5,1)
  596.       call plot (00.0,8.5,1)
  597.       call plot (00.0,0.0,1)
  598.       call plot (01.625,2.0,-3)
  599. c
  600. c call systems routine to plot the 80-character title.
  601. c the first two arguments are the coordinates in inches
  602. c relative to the reference point of the lower left-hand
  603. c corner of the first character.  the third argument
  604. c determines the height in inches of the characters.  the
  605. c fifth argument gives the angle relative to horizontal of
  606. c the plotted characters.
  607. c
  608.    41 if (xlnth.lt.0.0) go to 42
  609. c
  610. c call systems routine to draw the horizontal axis.  the
  611. c left end is specified in inches relative to the reference
  612. c point by the first two arguments.
  613. c
  614.       call axis (9.0 - xlnth, 0.0, xlabel, 0, xlnth, 
  615.      *xmin, xlnth*deltax+xmin, 1)
  616.       if (ylnth.lt.0.0) go to 43
  617. c
  618. c draw the depth axis.
  619. c
  620.       call plot (9.0 - xlnth, 0.0, 3)
  621.       call plot (0.0, 6.0 - ylnth, 2)
  622.    42 if (ylnth.lt.0.0) go to 43
  623. c
  624. c draw the vertical axis.  the bottom point is specified in
  625. c inches relative to the reference point by the first two
  626. c arguments.
  627. c
  628.       call axis (0.0, 6.0 - ylnth, ylabel, 1, ylnth, ymin,
  629.      *ylnth*deltay+ymin, 0)
  630. c
  631. c curves successively farther in the background will be
  632. c plotted where they are not hidden by g vs xg.  g vs xg
  633. c will be updated each time a new curve is drawn and will be
  634. c the visual maximum (or minimum) function of the curves
  635. c already plotted.
  636. c
  637.    43 indext = 3
  638.       do 3 j=1,n1
  639.       xg(indext) = x(j)
  640.       g(indext) = sign * y(j)
  641.     3 indext = indext + 1
  642. c
  643. c the following precautionary step is used in place of a
  644. c test in subroutine lookup to see if the value for which we
  645. c want an index is outside the table.
  646. c the last xg value will be set equal to the last abcissa
  647. c of the curve to be plotted in the next call to hide.
  648. c
  649.       eps = eps1 * (abs(xmin) + abs(deltax))
  650.       ng = n1 + 4
  651.       xg(1) = -fnsm1 * dxin + xmin - abs(xmin) - abs(xg(3)) - 1.0
  652.       xg(2) = xg(3) - eps
  653.       xg(n1 + 3) = xg(n1 + 2) + eps
  654.       zz = ymin
  655.       if (sign.lt.0.0) zz = -ymin - 50.0 * deltay
  656.       g(1) = zz
  657.       g(2) = zz
  658.       g(n1+3) = zz
  659.       g(ng) = zz
  660. c call systems routine to produce a line plot of
  661. c (x(i), y(i), i=1,n1) - this is the curve farthest in the
  662. c foreground.
  663. c xstart is the x value at the reference point.
  664. c
  665.       xstart = xmin - (9.0 - abs(xlnth)) * deltax
  666. c
  667.       if(ifplot.eq.1) call pdatax(x,y,n1,xstart,deltax,ymin,deltay)
  668.       dxkk = 0.0
  669.       dykk = 0.0
  670.       relinc = deltax / deltay
  671.       xg(ng) = sign
  672.       return
  673. c
  674. c statement 5000 is reached if any except the curve farthest
  675. c in the foreground is to be plotted.
  676. c
  677.  5000 sign = xg(ng)
  678.       xg(ng) = x(n1)
  679. c
  680. c translate the arrays before plotting to simulate stepping
  681. c in the depth dimension.
  682. c
  683.       if (nfns) 52, 48, 49
  684.    49 dxkk = dxkk + dxin
  685.       dykk = dykk + dyin
  686.    48 do 4 j=1,n1
  687.       y(j) = sign * (y(j) + dykk)
  688.     4 x(j) = x(j) - dxkk
  689.    52 call lookup (x(1), xg(1), jj)
  690.       if (jj.ge.maxdim) go to 700
  691.       do 31 j=1,jj
  692.       xh(j) = xg(j)
  693.    31 h(j) = g(j)
  694.       ig = jj + 1
  695.       xh(ig) = x(1)
  696.       h(ig) = f(x(1), xg(jj), g(jj), xg(ig), g(ig))
  697. c
  698. c we will be making table lookups for an increasing sequence
  699. c of numbers - therefore, we do not have to search from the
  700. c first of the (xg and x) tables each time.  hence indexg
  701. c and indext.
  702. c
  703.       indexg = jj
  704.       indext = 1
  705.       z1 = x(1)
  706.       f1 = h(ig) - y(1)
  707.       it = 2
  708.       jj = ig
  709.       if (h(ig).ge.y(1)) go to 32
  710.       if (jj.ge.maxdim) go to 700
  711.       jj = ig + 1
  712.       h(jj) = y(1)
  713.       xh(jj) = z1 + eps
  714.    32 last = 0
  715.       x1 = z1
  716. c
  717. c find the first zero, z2, of the function g-y to the right
  718. c of z1.
  719. c
  720.  1100 if (xg(ig).lt.x(it)) go to 1001
  721. c
  722. c do not jump if we are to look for a zero between x1 and
  723. c x(i).
  724. c
  725.       iwhich = 0
  726.       x2 = x(it)
  727.       f2 = f(x2, xg(ig - 1), g(ig - 1), xg(ig), g(ig)) - y(it)
  728.       it = it + 1
  729.       go to 1002
  730. c
  731. c come to 1001 if we are to look for a zero between x1 and
  732. c xg(ig).
  733. c
  734.  1001 x2 = xg(ig)
  735.       iwhich = 1
  736.       f2 = g(ig) - f(x2, x(it - 1), y(it - 1), x(it), y(it))
  737.       ig = ig + 1
  738. c
  739. c the function (g - y) has a zero z2 such that x1 le z2 le x2
  740. c if and only if (g - y at x1) * (g - y at x2) le 0.
  741. c (g - y is assumed, for plotting purposes, to be linear on
  742. c each interval (x1, x2).)
  743. c
  744.  1002 if (f1 * f2.gt.0.) go to 1005
  745.       if (f1.eq.f2) go to 1005
  746.       slope = (f2 - f1) / (x2 - x1)
  747.       igg = ig - 1 - iwhich
  748.       itt = it - 2 + iwhich
  749.       if (abs(slope * relinc) .gt. eps1) goto 1007
  750. c
  751. c if g and y differ imperceptibly (for plotting purposes)
  752. c on the interval (x1, x2), set z2 = x2.  this step prevents
  753. c division by zero.
  754. c
  755.       z2 = x2
  756.       go to 1006
  757. c
  758. c otherwise, compute the zero z2.
  759. c
  760.  1007 z2 = x1 - f1 / slope
  761.       go to 1006
  762. c
  763. c if no zero was found between x1 and x2, continue the
  764. c search for zeroes.
  765. c
  766.  1005 x1 = x2
  767.       f1 = f2
  768.       if (it.le.n1) go to 1100
  769. c
  770. c if the end of the x table has been reached, consider the
  771. c interval from the last zero found to the end of the x
  772. c table (plot, update maximum function as indicated).
  773. c
  774.  1008 last = 1
  775.       z2 = x(n1)
  776.       call lookup (z2, xg(indexg), igg)
  777.       igg = indexg + igg - 1
  778.       itt = n1 - 1
  779. c
  780. c it is necessary to plot y vs x on the interval (z1, z2)
  781. c only if y is unhidden at each zz such that z1 lt zz lt z2.
  782. c we choose zz near the left end of the interval for
  783. c efficiency in the table lookup.
  784. c note that it is more efficient to choose this value for zz
  785. c than, say, 0.99 * x(indext) + 0.01 * x(indext + 1), which
  786. c would eliminate one of the two table lookups, but would
  787. c necessitate a test to determine if zz was between z1 and z2.
  788. c
  789.  1006 zz = 0.99 * z1 + 0.01 * z2
  790.       call lookup (zz, x(indext), k1)
  791.       call lookup (zz, xg(indexg), k2)
  792.       k1 = k1 + indext - 1
  793.       k2 = k2 + indexg - 1
  794.       if (f(zz, x(k1), y(k1), x(k1 + 1), y(k1 + 1)).gt.
  795.      +       f(zz, xg(k2), g(k2), xg(k2 + 1), g(k2 + 1))) go to 7
  796. c
  797. c if y is hidden between z1 and z2, update the maximum
  798. c function.
  799. c for generality, the maximum function is updated even if
  800. c this is the (nfns)th curve.
  801. c
  802.       if (jj + igg - indexg.ge.maxdim) go to 700
  803.       if (indexg.eq.igg) go to 712
  804.       j1 = indexg + 1
  805.       do 12 i=j1,igg
  806.       jj = jj + 1
  807.       xh(jj) = xg(i)
  808.    12 h(jj) = g(i)
  809.   712 jj = jj +1
  810.       xh(jj) = z2
  811.       h(jj) = f(z2, xg(igg), g(igg), xg(igg + 1), g(igg + 1))
  812.       indexg = igg
  813.       indext = itt
  814.       go to 60
  815. c
  816. c if y is not hidden between z1 and z2, update the maximum
  817. c function and plot.
  818. c
  819.     7 ngraph = itt - indext + 2
  820.       if (jj + ngraph - 1.gt.maxdim) go to 700
  821.       n2 = jj
  822.       if (ngraph.eq.2) go to 9
  823.       j1 = indext + 1
  824.       do 11 i=j1,itt
  825.       jj = jj + 1
  826.       xh(jj) = x(i)
  827.    11 h(jj) = y(i)
  828.     9 jj = jj + 1
  829.       xh(jj) = z2
  830.       h(jj) = f(z2, x(itt), y(itt), x(itt + 1), y(itt + 1))
  831. c
  832. c call systems routine to produce line plot of
  833. c (xh(i), h(i), i=n2, n2 + ngraph - 1).
  834. c
  835.       if(ifplot.eq.1) call pdatax(xh(n2),h(n2),ngraph,xstart,deltax,
  836.      1                            sign*ymin,sign*deltay)
  837. c
  838.       indext = itt
  839.       indexg = igg
  840.    60 if (last.eq.1) go to 61
  841.       x1 = x2
  842.       f1 = f2
  843.       z1 = z2
  844. c
  845. c after plotting and/or updating the maximum function on the
  846. c interval (z1, z2), search for the next zero if the end of
  847. c the abcissa table xt has not been reached.
  848. c
  849.       if (it.le.n1) go to 1100
  850.       go to 1008
  851. c
  852. c after y vs x has been plotted, finish updating and store
  853. c the new maximum function.
  854. c allow for the possibility that the previous maximum
  855. c function extends to the right of the function just
  856. c plotted.
  857. c
  858.    61 if (xg(ng).le.xg(ng - 1)) ng = ng - 1
  859.       if (xg(ng).le.x(n1)) go to 33
  860.       if (jj + 3 + ng - igg.gt.maxdim) go to 700
  861.       xh(jj + 1) = xh(jj) + eps
  862.       jj = jj + 1
  863.       h(jj) = f(x(n1), xg(igg), g(igg), xg(igg + 1), g(igg + 1))
  864.       iggp1 = igg + 1
  865.       do 34 j = iggp1, ng
  866.       jj = jj + 1
  867.       xh(jj) = xg(j)
  868.    34 h(jj) = g(j)
  869.    33 ng = jj + 2
  870.       if (ng.gt.maxdim) go to 700
  871.       do 13 i=1,jj
  872.       g(i) = h(i)
  873.    13 xg(i) = xh(i)
  874. c
  875. c the following precautionary step is used in place of a
  876. c test in subroutine lookup to see if the value for which we
  877. c want an index is outside the table.
  878. c the last xg value will be set equal to the last abcissa
  879. c of the next curve to be plotted.
  880. c
  881.       xg(jj + 1) = xg(jj) + eps
  882.       g(jj + 1) = ymin + dykk
  883.       if (sign.lt.0.) g(jj + 1) = -ymin - 50.0 * deltay + dykk
  884.       g(ng) = g(jj + 1)
  885. c
  886. c restore arrays x and y before returning.
  887. c
  888.    66 if (nfns.lt.0) go to 53
  889.       do 82 i=1,n1
  890.       x(i) = x(i) + dxkk
  891.    82 y(i) = sign * y(i) - dykk
  892.    53 xg(ng) = sign
  893.       return
  894. c
  895. c if statement 700 is reached, dimensions would have been
  896. c exceeded.  see comments on calling sequence for hide.
  897. c
  898.   700 maxdim = -maxdim
  899.       write(6,1030)
  900. 1030  format('visual maximum exceeds maxdim')
  901.       go to 66
  902.       end
  903.       subroutine lookup (x, xtbl, j)
  904. c
  905. c this subroutine is called by hide to perform a table
  906. c lookup.  because of precautions taken in hide, a test to
  907. c see if x is outside the table is unnecessary.
  908. c
  909.       dimension xtbl(1)
  910.       j = 2
  911.     4 if (xtbl(j) - x) 1, 2, 3
  912.     1 j = j + 1
  913.       go to 4
  914.     2 return
  915.     3 j = j - 1
  916.       return
  917.       end
  918.       subroutine pdatax(x,y,n,xm,dx,ym,dy)
  919. c
  920. c     purdue calcomp/dipl compatable data ploting routine
  921. c
  922.       dimension x(n),y(n)
  923.       data cx,cy/2*0.0/
  924.       px(i)=(x(i)-xm)/dx
  925.       py(i)=(y(i)-ym)/dy
  926. c
  927.     i1 = 1
  928.     i2 = 1
  929.       if(amax1(abs(cx-px(1)),abs(cy-py(1))).lt.
  930.      1   amax1(abs(cx-px(n)),abs(cy-py(n)))) goto 1
  931.     i1 = n
  932.     i2 = -i2
  933. 1     call plot(px(i1),py(i1),3)
  934.       do 2 i3=2,n
  935.       i1=i1+i2
  936. 2     call plot(px(i1),py(i1),2)
  937.     cx = px(i1)
  938.     cy = py(i1)
  939.       return
  940.       end
  941.  
  942.  
  943. SHAR_EOF
  944. cat << \SHAR_EOF > pl3d.f
  945.     dimension xg(1400),g(1400),xh(1400),h(1400),x(1400)
  946.     integer uread,uopen
  947.     dimension pic(32,32),p(1024)
  948.     equivalence (pic(1,1),p(1))
  949.  
  950.     maxdim = 1000
  951.     write(6,1000)
  952. 1000    format('hi carl')
  953.     npic = 32
  954.     npic2 = npic * npic
  955.     ng = 0
  956.     xl = 6.5
  957.     yl = 4.0
  958.     ifd = uopen('pic.r',0)
  959.     write(6,1000)
  960.     if(ifd .ne. -1) goto 20
  961.     write(6,10)
  962. 10    format(' can not open: pic.r')
  963.     stop
  964. 20    ic = uread(ifd,pic,4 * npic2)
  965.     write(6,1000)
  966.     if(ic .eq. 4 * npic2) goto 40
  967.     write(6,30)
  968. 30    format(' bad data structure')
  969.     stop
  970. 40    amax = p(1)
  971.     amin = amax
  972.     call plots(3,0)
  973.     do 50 i=1,npic2
  974.     a = p(i)
  975.     if(a .gt. amax) amax = a
  976.     if(a .lt. amin) amin = a
  977. 50    continue
  978.     dx = float(npic) / xl
  979.     rmin = amin
  980.     dy = (amax - amin) / yl
  981.     l = 1
  982.     do 60 i=1,npic
  983. 60    x(i) = i
  984.     do 70 i=1,npic
  985.     call hide(x,p(l),xg,g,xh,h,ng,maxdim,npic,npic,xl,yl
  986.      *    ,1.0,dx,rmin,dy)
  987.     l = l + npic
  988. 70    continue
  989.     call plot(0.0,0.0,999)
  990.     stop
  991.     end
  992. SHAR_EOF
  993. chdir ..
  994. #    End of shell archive
  995. exit 0
  996.  
  997. -- 
  998.  
  999. Rich $alz            "Anger is an energy"
  1000. Cronus Project, BBN Labs    rsalz@bbn.com
  1001. Moderator, comp.sources.unix    sources@uunet.uu.net
  1002.