home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / plotting / contour / contour.lha / Contour / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-28  |  3.4 KB  |  128 lines

  1. /***  main.c  ***/
  2.  
  3. /* CONTOUR Version 1.1 : Kenny K.H. Toh, Aug 28 1990 */
  4.  
  5. #include <stdio.h>
  6. #include <strings.h>
  7. #include <math.h>
  8. #include "common.h"
  9. #include "contour.h"
  10. #include "plot.h"
  11.  
  12. main(argc,argv)
  13. int argc;
  14. char *argv[];
  15. {
  16.    extern int cont_out, expand;
  17.  
  18.    fprintf(stdout,"Contour V1.2  2/2/90\n");
  19.    system("cat /home/mascot1/ktoh/SPLAT/SRC/Contour/README");
  20.    initialize_data();                     /* Initialize the variables */
  21.    fileopen(argc,argv);                   /* read the data and options */
  22.    if (expand) expand_cont();             /* Produce 3D surface */
  23.    if (cont_out) draw_cont();
  24.    else          draw_view(argc,argv);    /* draw the picture */
  25.    fprintf(stdout,"Congratulations!!!  You have been TERMINATED...\n");
  26. }
  27.  
  28. /* Initialize some data */
  29. initialize_data()
  30. {
  31.    char   *getenv();
  32.    char   *strcpy();
  33.    char   *sprintf();
  34.    extern char    *term;
  35.    extern char    xlabel[MAXCHAR];
  36.    extern char    ylabel[MAXCHAR];
  37.    extern char    toplabel[MAXCHAR];
  38.    extern char    printer[MAXCHAR];
  39.    extern int     grid,equalscale,postscript,printplot;
  40.    extern int     xticks,yticks;
  41.    extern int     linetypes, contlabel, joincurve;
  42.    extern int     landscape;
  43.    extern int     cont_out;
  44.    extern int     expand;
  45.    extern int     oldformat;
  46.    extern double  scale;
  47.  
  48.    char   *ptr;
  49.  
  50.    /* Terminal Type */
  51.    term = getenv("TERM");
  52.    fprintf(stdout,"   Terminal type             = %s\n",term);
  53.  
  54.    /* Labeling information */
  55.    strcpy(xlabel , "X-AXIS");
  56.    strcpy(ylabel , "Y-AXIS");
  57.    strcpy(toplabel , "CONTOUR PLOT");
  58.  
  59.    /* options */
  60.    expand       = OFF;
  61.    cont_out     = OFF;
  62.    oldformat    = OFF;
  63.    joincurve    = OFF;
  64.  
  65.    /* Plotting parameters/options */
  66.    grid         = OFF;
  67.    equalscale   = ON;
  68.    postscript   = ON;
  69.    printplot    = ON;
  70.    contlabel    = ON;
  71.    landscape    = OFF;
  72.    linetypes    = 2;
  73.    scale        = 1.00;
  74.    xticks       = 4;
  75.    yticks       = 4;
  76.  
  77.    /* list initialization */
  78.    initialize_list();
  79.  
  80.    /* printer type */
  81.    if ((ptr = getenv("PRINTER")) == NULL)
  82.       strcpy(printer,"-Plp550M");
  83.    else
  84.       sprintf(printer,"-P%s",ptr);
  85.    fprintf(stdout,"   Default Printer           = %s\n",printer);
  86. }
  87.  
  88. expand_cont()
  89. {
  90.    FILE    *fopen(), *fo;
  91.    char    *strcpy();
  92.    extern  triaptr tria_listhead;
  93.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  94.    char    outputfile[MAXCHAR];
  95.    int     ncurves=0;
  96.    triaptr T;
  97.  
  98.    /* prepare output file */
  99.    strcpy(outputfile,imagefile);
  100.    strcat(outputfile,".3D");
  101.    if ((fo =  fopen(outputfile,"w")) == NULL) {
  102.       fprintf(stderr,"cat: can't open %s\n", outputfile);
  103.       exit(1);
  104.    }
  105.  
  106.    /* count the number of triangles */
  107.    for (T=tria_listhead; T!=NULL; T=T->next) ncurves++;
  108.  
  109.    /* print out header - xmin,xmax,ymin,ymax,zmin,zmax,ncurves */
  110.    fprintf(fo,"%10.5f %10.5f  ",xmin,xmax);
  111.    fprintf(fo,"%10.5f %10.5f  ",ymin,ymax);
  112.    fprintf(fo,"%10.5f %10.5f\n",zmin,zmax);
  113.    fprintf(fo,"%10.5f\n",(double)ncurves);
  114.  
  115.    /* now print out the triangles */
  116.    for (T=tria_listhead; T!=NULL; T=T->next) {
  117.       fprintf(fo,"%10.5f\n",4.0);
  118.       fprintf(fo,"%10.5f %10.5f %10.5f\n",T->pt1.x,T->pt1.y,T->pt1.z);
  119.       fprintf(fo,"%10.5f %10.5f %10.5f\n",T->pt2.x,T->pt2.y,T->pt2.z);
  120.       fprintf(fo,"%10.5f %10.5f %10.5f\n",T->pt3.x,T->pt3.y,T->pt3.z);
  121.       fprintf(fo,"%10.5f %10.5f %10.5f\n",T->pt1.x,T->pt1.y,T->pt1.z);
  122.    }      
  123.  
  124.    /* now close the file */
  125.    fclose(fo);
  126.    fprintf(stdout,"   %d Triangles saved in \"%s\"\n",ncurves,outputfile);
  127. }
  128.