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

  1. #include "plplot.h"
  2. #include <stdio.h>
  3. #include <limits.h>
  4.  
  5. /* This file contains the tektronix dependent routines for use with plplot. */
  6.  
  7. #define TEKX   1023
  8. #define TEKY    779
  9.  
  10. /* Define graphics control characters. */
  11. #define FF   12
  12. #define CAN  24
  13. #define ESC  27
  14. #define GS   29
  15. #define US   31
  16.  
  17. static FILE *OutFile;
  18. static int select=0;
  19. static int porient;
  20. static char FileName[80];
  21.  
  22. void tektsetup(xdpi,ydpi,xwid,ywid)
  23. PLFLT xdpi, ydpi;
  24. PLINT xwid, ywid;
  25. {
  26.    /* ignore */
  27. }
  28.  
  29. void tekfsetup(xdpi,ydpi,xwid,ywid)
  30. PLFLT xdpi, ydpi;
  31. PLINT xwid, ywid;
  32. {
  33. }
  34.  
  35. void tektinit()
  36. {
  37.       smod(1);   /* an interactive device */
  38.       OutFile = stdout;
  39.       teksetup(0);
  40. }
  41.  
  42. void tekfinit()
  43. {
  44.       char response[80];
  45.       int ori;
  46.  
  47.       smod(0);  /* not an interactive terminal */
  48.       if(!select) {
  49.          printf("Landscape or portrait orientation? (0 or 1): ");
  50.          fgets(response,sizeof(response),stdin);
  51.          if(sscanf(response,"%d",&ori) != 1)
  52.             ori = 0;   /* carriage return defaults to landscape */
  53.       }
  54.       
  55.       OutFile = NULL;
  56.       while(!OutFile) {
  57.          if(!select) {
  58.             printf("Enter graphics command storage file name. ");
  59.             fgets(response,sizeof(response),stdin);
  60.             if(sscanf(response,"%s",FileName) != 1)  {
  61.                 printf("Invalid entry.n");
  62.                 continue;
  63.             }
  64.          }
  65.          select =0;
  66.          if ((OutFile = fopen(FileName,"w")) == NULL) 
  67.              printf("Can't open %s.\n",FileName);
  68.       }
  69.       teksetup(ori);
  70. }
  71.  
  72. teksetup(portrait)
  73. int portrait;
  74. {
  75.       /* set default pen color*/
  76.       scol(1);
  77.       porient = portrait;
  78.  
  79.       if(!portrait) {
  80.          /* set device resolution in dots/mm */
  81.          setpxl(4.771*16,4.653*16);
  82.          /* set page size */
  83.          setphy(0,TEKX*16,0,TEKY*16);
  84.       }
  85.       else {
  86.          /* set device resolution in dots/mm */
  87.          setpxl(4.653*16,4.771*16);
  88.          /* set page size */
  89.          setphy(0,TEKY*16,0,TEKX*16);
  90.       }
  91.       fprintf(OutFile,"%c",GS);
  92. }
  93.  
  94. /* Sets the tektronix to text mode */
  95. void tektext()
  96. {
  97.     fprintf(OutFile,"%c",US);
  98. }
  99.  
  100. /* Sets the tektronix to graphics mode */
  101. void tekgraph()
  102. {
  103.     /* Nothing has to be done here */
  104. }
  105.  
  106. /* Clears the tektronix screen */
  107. void tektclear()
  108. {
  109.      putchar('\007');
  110.      fflush(stdout);
  111.      while(getchar() != '\n')
  112.         ;
  113.      fprintf(OutFile,"%c%c",ESC,FF);
  114. }
  115.  
  116. void tekfclear()
  117. {
  118.      fprintf(OutFile,"%c%c",ESC,FF);
  119. }
  120.  
  121. void tektselect(ori,file)
  122. PLINT ori;
  123. char *file;
  124. {
  125. }
  126.  
  127. void tekfselect(ori,file)
  128. PLINT ori;
  129. char *file;
  130. {
  131.    porient = ori;
  132.    strncpy(FileName,file,sizeof(FileName)-1);
  133.    FileName[sizeof(FileName)-1] = '\0';
  134.    select = 1;
  135. }
  136.  
  137. /* Change color */
  138. void tekcolor(colour)
  139. PLINT colour;
  140. {
  141. }
  142.  
  143. static PLINT xold, yold;
  144.  
  145. void tekpage()
  146. {
  147.    xold = -100000;
  148.    yold = -100000;
  149. }
  150.  
  151.  
  152. /* Change pen width */
  153. void tekwidth(width)
  154. PLINT width;
  155. {
  156. }
  157.  
  158. /* Draws a line in the current colour from (x1,y1) to (x2,y2) */
  159. void tekline(x1a,y1a,x2a,y2a)
  160. PLINT x1a,y1a,x2a,y2a;
  161. {
  162.     int x1,y1,x2,y2,hy,ly,hx,lx;
  163.  
  164.     x1a >>= 4;
  165.     y1a >>= 4;
  166.     x2a >>= 4;
  167.     y2a >>= 4;
  168.  
  169.     if(!porient) {
  170.        x1 = x1a;
  171.        y1 = y1a;
  172.        x2 = x2a;
  173.        y2 = y2a;
  174.     }
  175.     else {
  176.        x1 = TEKX - y1a;
  177.        y1 = x1a;
  178.        x2 = TEKX - y2a;
  179.        y2 = x2a;
  180.     }
  181.  
  182.     /* If continuation of previous line just send new point */
  183.     if(x1 == xold && y1 == yold) {
  184.        hy = y2/32 + 32;
  185.        ly = y2 - (y2/32)*32 + 96;
  186.        hx = x2/32 + 32;
  187.        lx = x2 - (x2/32)*32 + 64;
  188.        fprintf(OutFile,"%c%c%c%c",hy,ly,hx,lx);
  189.     }
  190.     else {
  191.        fprintf(OutFile,"%c",GS);
  192.        hy = y1/32 + 32;
  193.        ly = y1 - (y1/32)*32 + 96;
  194.        hx = x1/32 + 32;
  195.        lx = x1 - (x1/32)*32 + 64;
  196.        fprintf(OutFile,"%c%c%c%c",hy,ly,hx,lx);
  197.        hy = y2/32 + 32;
  198.        ly = y2 - (y2/32)*32 + 96;
  199.        hx = x2/32 + 32;
  200.        lx = x2 - (x2/32)*32 + 64;
  201.        fprintf(OutFile,"%c%c%c%c",hy,ly,hx,lx);
  202.     }
  203.     xold = x2;
  204.     yold = y2;
  205. }
  206.  
  207. /* Close file */
  208. void tekftidy()
  209. {
  210.    fclose(OutFile);
  211. }
  212.  
  213. void tekttidy()
  214. {
  215.    tektclear();
  216.    fprintf(OutFile,"%c%c",US,CAN);
  217.    fflush(OutFile);
  218. }
  219.  
  220.