home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / gwin_433.lzh / Gwin / exsrc.lzh / spiceplot.c < prev    next >
C/C++ Source or Header  |  1991-01-12  |  3KB  |  157 lines

  1. #include "gwin.user.h"
  2.  
  3. float sdata[10][1000];
  4. float mindata =  1e15;
  5. float maxdata = -1e15;
  6. char s[8][20];
  7. float wind[4],xdx,height,width;
  8. int n,npoints;
  9. int reset(),cancel_redraw;
  10. int quit();
  11. int event;
  12.  
  13. main()
  14. {
  15. char string[256];
  16. char string1[100];
  17. int i,j;
  18. float x,y,xanchor,yanchor,xold,yold;
  19. char key;
  20.  
  21.    while(1 == 1){
  22.       if(!gets(string))exit(1); /* read one line */
  23.       if(!strncmp("     TIME",string,(int)9)){  /* look for data */
  24.          printf("FOUND DATA\n");
  25.          break;
  26.       }
  27.    }
  28.    n = sscanf(string,"%s %s %s %s %s %s %s %s %s %s",
  29.                       s[0],s[1],s[2],s[3],s[4],s[5],s[6]
  30.                       ,s[7],s[8],s[9]);  /* store field names */
  31.  
  32.  
  33.    /* print field names */
  34.    printf("%s %s %s %s %s\n",s[0],s[1],s[2],s[3],s[4],s[5]);
  35.  
  36.    if(!gets(string))exit(1);  /* skip blank line */
  37.  
  38.    j = 0;
  39.    while(1 == 1){
  40.       for(i=0;i<n;i++){
  41.          if(scanf("%e",&sdata[i][j]) < 1)goto plot;
  42.          if(sdata[i][j]>maxdata) maxdata = sdata[i][j];
  43.          if(sdata[i][j]<mindata) mindata = sdata[i][j];
  44.       }
  45.       j++;
  46.    }
  47.  
  48. plot:
  49.    npoints = j;
  50.  
  51.    ustart("high2",(float)0.,(float)640.0,(float)0.,(float)400.0);
  52.  
  53.    uamenu(1,0,0,"COMMANDS",' ',0,MIDRAWN|MENUENABLED,7);
  54.    uamenu(1,1,0,"RESET",'R',0,MIDRAWN|ITEMTEXT|HIGHCOMP
  55.           |COMMSEQ|ITEMENABLED,reset);
  56.    uamenu(1,2,0,"QUIT",'Q',0,MIDRAWN|ITEMTEXT|HIGHCOMP
  57.           |COMMSEQ|ITEMENABLED,quit);
  58.  
  59.    reset();
  60.  
  61.    while(1 == 1){
  62.       while(key != 'a') {
  63.          ugrinl(&x,&y,&event,&key);
  64.  
  65.          sprintf(string1,"x = %15.8e",x);
  66.          uprint( wind[0] + .1*width, wind[3] -.05*height, string1);
  67.          sprintf(string1,"y = %15.8e",y);
  68.          uprint( wind[0] + .5*width, wind[3] -.05*height, string1);
  69.       }
  70.       uset("comp");
  71.       xanchor = x;   /* anchor point */
  72.       yanchor = y;
  73.       xold = x;
  74.       yold = y;
  75.  
  76.       while (key != 'A'){
  77.          ugrinl(&x,&y,&event,&key);
  78.          urect(xanchor,yanchor,xold,yold);
  79.          urect(xanchor,yanchor,x,y);
  80.          xold = x;
  81.          yold = y;
  82.       }
  83.  
  84.       if((xanchor != x) && (yanchor != y)){
  85.          wind[0] = (xanchor < x) ? xanchor : x;
  86.          wind[1] = (xanchor > x) ? xanchor : x;
  87.          wind[2] = (yanchor < y) ? yanchor : y;
  88.          wind[3] = (yanchor > y) ? yanchor : y;
  89.       }
  90.  
  91.       width  = wind[1] - wind[0];
  92.       height = wind[3] - wind[2];
  93.  
  94.       uwindo(wind[0],wind[1],wind[2],wind[3]);
  95.  
  96.       uset("ncom");
  97.       uerase();
  98.       uoutln();
  99.       uset("clip");
  100.  
  101.       redraw();
  102.    }
  103. }
  104.  
  105.  
  106. reset()
  107. {
  108.    wind[0] = sdata[0][0];
  109.    wind[1] = sdata[0][npoints-1];
  110.    wind[2] = mindata - .1*(maxdata-mindata);
  111.    wind[3] = maxdata + .1*(maxdata-mindata);
  112.  
  113.    width  = wind[1] - wind[0];
  114.    height = wind[3] - wind[2];
  115.  
  116.    uwindo(wind[0],wind[1],wind[2],wind[3]);
  117.  
  118.    uset("ncli");
  119.  
  120.    upset("ccol",(float)0.0);
  121.    uerase();
  122.    uoutln();
  123.  
  124.    redraw();
  125.    cancel_redraw = 1;
  126. }
  127.  
  128. redraw()
  129. {
  130. int i,j;
  131. float x,y;
  132. char key;
  133.  
  134.    cancel_redraw = 0;
  135.    for(i=1;i<n;i++){
  136.       upset("colo",(float)(i+2));
  137.       uprint( wind[0]+.8*width, wind[3]-(.04 + .03*(i-1))*height,s[i]);
  138.       umove(sdata[0][0],sdata[i][0]);
  139.       for(j=1;j<npoints;j++){
  140.          ugrina(&x,&y,&event,&key);
  141.          if(cancel_redraw){
  142.             upset("colo",7.0);
  143.             return(0);
  144.          }
  145.          udraw(sdata[0][j],sdata[i][j]);
  146.       }
  147.    }
  148.    upset("colo",7.0);
  149. }
  150.  
  151. quit()
  152. {
  153.    uend();
  154.    exit(0);
  155. }
  156.  
  157.