home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / src / plenv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  2.9 KB  |  86 lines

  1. /* Simple interface for defining viewport and window. If "just"=1,  */
  2. /* X and Y scales will be the same, otherwise they are scaled       */
  3. /* independently. The "axis" parameter is interpreted as follows:   */
  4. /* axis=-2 : draw no box, axis or labels                            */
  5. /* axis=-1 : draw box only                                          */
  6. /* axis= 0 : Draw box and label with coordinates                    */
  7. /* axis= 1 : Also draw the coordinate axes                          */
  8. /* axis= 2 : Draw a grid at major tick positions                    */
  9. /* axis=10 : Logarithmic X axis, L!=r Y axis, No X=0 axis         */
  10. /* axis=11 : Logarithmic X axis, L!=r Y axis, X=0 axis            */
  11. /* axis=20 : L!=r X axis, Logarithmic Y axis, No Y=0 axis         */
  12. /* axis=21 : L!=r X axis, Logarithmic Y axis, Y=0 axis            */
  13. /* axis=30 : Logarithmic X and Y axes                               */
  14.  
  15. #include "plplot.h"
  16. #include <stdio.h>
  17. #include <math.h>
  18.  
  19. void plenv(xmin,xmax,ymin,ymax,just,axis)
  20. PLINT just,axis;
  21. PLFLT xmin, xmax, ymin, ymax;
  22. {
  23.     PLINT level;
  24.     PLFLT chrdef, chrht;
  25.     PLFLT lb, rb, tb, bb, dx, dy;
  26.     PLFLT xsize, ysize, xscale, yscale;
  27.     PLFLT spxmin, spxmax, spymin, spymax;
  28.     PLFLT vpxmin, vpxmax, vpymin, vpymax;
  29.     PLFLT scale;
  30.  
  31.     glev(&level);
  32.     if (level < 1) plexit("Please call plstar before plenv.");
  33.  
  34.     if (xmin == xmax) plexit("Invalid xmin and xmax arguments in plenv");
  35.     if (ymin == ymax) plexit("Invalid ymin and ymax arguments in plenv");
  36.     if ((just != 0) && (just != 1)) plexit("Invalid just option in plenv");
  37.  
  38.  
  39.     pladv(0);
  40.     if (just == 0)
  41.       plvsta();
  42.     else {
  43.       gchr(&chrdef,&chrht);
  44.       lb = 7.0 * chrht;
  45.       rb = 4.0 * chrht;
  46.       tb = 4.0 * chrht;
  47.       bb = 4.0 * chrht;
  48.       dx = abs(xmax-xmin);
  49.       dy = abs(ymax-ymin);
  50.       plgspa(&spxmin,&spxmax,&spymin,&spymax);
  51.       xsize = spxmax - spxmin;
  52.       ysize = spymax - spymin;
  53.       xscale = dx/(xsize - lb - rb);
  54.       yscale = dy/(ysize - tb - bb);
  55.       scale = max(xscale,yscale);
  56.       vpxmin = max(lb,0.5*(xsize - dx/scale));
  57.       vpxmax = vpxmin + (dx/scale);
  58.       vpymin = max(bb,0.5*(ysize - dy/scale));
  59.       vpymax = vpymin + (dy/scale);
  60.       plsvpa(vpxmin,vpxmax,vpymin,vpymax);
  61.     }
  62.     plwind(xmin,xmax,ymin,ymax);
  63.     if (axis == -2)
  64.        ;
  65.     else if (axis == -1)
  66.        plbox("bc",0.0,0,"bc",0.0,0);
  67.     else if (axis == 0)
  68.        plbox("bcnst",0.0,0,"bcnstv",0.0,0);
  69.     else if (axis == 1)
  70.        plbox("abcnst",0.0,0,"abcnstv",0.0,0);
  71.     else if (axis == 2)
  72.        plbox("abcgnst",0.0,0,"abcgnstv",0.0,0);
  73.     else if (axis == 10)
  74.        plbox("bclnst",0.0,0,"bcnstv",0.0,0);
  75.     else if (axis == 11)
  76.        plbox("bclnst",0.0,0,"abcnstv",0.0,0);
  77.     else if (axis == 20)
  78.        plbox("bcnst",0.0,0,"bclnstv",0.0,0);
  79.     else if (axis == 21)
  80.        plbox("bcnst",0.0,0,"abclnstv",0.0,0);
  81.     else if (axis == 30)
  82.        plbox("bclnst",0.0,0,"bclnstv",0.0,0);
  83.     else
  84.        fprintf(stderr,"Invalid axis argument in plenv.\n");
  85. }
  86.