home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d571 / gwin.lha / Gwin / Examples / spiceplot.c < prev    next >
C/C++ Source or Header  |  1991-12-22  |  3KB  |  156 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.  
  12. main()
  13. {
  14. char string[256];
  15. char string1[100];
  16. int i,j;
  17. float x,y,xanchor,yanchor,xold,yold;
  18.  
  19.  
  20.    while(1 == 1){
  21.       if(!gets(string))exit(1); /* read one line */
  22.       if(!strncmp("     TIME",string,(int)9)){  /* look for data */
  23.          printf("FOUND DATA\n");
  24.          break;
  25.       }
  26.    }
  27.    n = sscanf(string,"%s %s %s %s %s %s %s %s %s %s",
  28.                       s[0],s[1],s[2],s[3],s[4],s[5],s[6]
  29.                       ,s[7],s[8],s[9]);  /* store field names */
  30.  
  31.  
  32.    /* print field names */
  33.    printf("%s %s %s %s %s\n",s[0],s[1],s[2],s[3],s[4],s[5]);
  34.  
  35.    if(!gets(string))exit(1);  /* skip blank line */
  36.  
  37.    j = 0;
  38.    while(1 == 1){
  39.       for(i=0;i<n;i++){
  40.          if(scanf("%e",&sdata[i][j]) < 1)goto plot;
  41.          if(sdata[i][j]>maxdata) maxdata = sdata[i][j];
  42.          if(sdata[i][j]<mindata) mindata = sdata[i][j];
  43.       }
  44.       j++;
  45.    }
  46.  
  47. plot:
  48.    npoints = j;
  49.  
  50.    USTART("high2",(float)0.,(float)640.0,(float)0.,(float)400.0);
  51.  
  52.    uamenu(G,1,0,0,"COMMANDS",' ',0,MIDRAWN|MENUENABLED,NULL);
  53.    uamenu(G,1,1,0,"RESET",'R',0,MIDRAWN|ITEMTEXT|HIGHCOMP
  54.           |COMMSEQ|ITEMENABLED,reset);
  55.    uamenu(G,1,2,0,"QUIT",'Q',0,MIDRAWN|ITEMTEXT|HIGHCOMP
  56.           |COMMSEQ|ITEMENABLED,quit);
  57.  
  58.    reset();
  59.    uuev.key = '\0';
  60.  
  61.    while(1 == 1){
  62.       while(uuev.key != 'a') {
  63.          if(ugrinl(G,&x,&y,&uuev)){UEND();exit(0);};
  64.  
  65.          sprintf(string1,"x = %15.8e",x);
  66.          uprint(G, wind[0] + .1*width, wind[3] -.05*height, string1);
  67.          sprintf(string1,"y = %15.8e",y);
  68.          uprint(G, wind[0] + .5*width, wind[3] -.05*height, string1);
  69.       }
  70.       uset(G,"comp");
  71.       xanchor = x;   /* anchor point */
  72.       yanchor = y;
  73.       xold = x;
  74.       yold = y;
  75.  
  76.       while (uuev.key != 'A'){
  77.          if(ugrinl(G,&x,&y,&uuev)){UEND();exit(0);};
  78.          urect(G,xanchor,yanchor,xold,yold);
  79.          urect(G,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(G,wind[0],wind[1],wind[2],wind[3]);
  95.  
  96.       uset(G,"ncom");
  97.       uerase(G);
  98.       uoutln(G);
  99.       uset(G,"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(G,wind[0],wind[1],wind[2],wind[3]);
  117.  
  118.    uset(G,"ncli");
  119.  
  120.    upset(G,"ccol",(float)0.0);
  121.    uerase(G);
  122.    uoutln(G);
  123.  
  124.    redraw();
  125.    cancel_redraw = 1;
  126. }
  127.  
  128. redraw()
  129. {
  130. int i,j;
  131. float x,y;
  132.  
  133.    cancel_redraw = 0;
  134.    for(i=1;i<n;i++){
  135.       upset(G,"colo",(float)(i+2));
  136.       uprint(G, wind[0]+.8*width, wind[3]-(.04 + .03*(i-1))*height,s[i]);
  137.       umove(G,sdata[0][0],sdata[i][0]);
  138.       for(j=1;j<npoints;j++){
  139.          if(ugrina(G,&x,&y,&uuev)){UEND();exit(0);};
  140.          if(cancel_redraw){
  141.             upset(G,"colo",7.0);
  142.             return(0);
  143.          }
  144.          udraw(G,sdata[0][j],sdata[i][j]);
  145.       }
  146.    }
  147.    upset(G,"colo",7.0);
  148. }
  149.  
  150. quit()
  151. {
  152.    UEND();
  153.    exit(0);
  154. }
  155.  
  156.