home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1062 / gen.c < prev   
Encoding:
C/C++ Source or Header  |  1990-12-28  |  4.6 KB  |  168 lines

  1. /* vi: set ts=2 sw=2: */
  2. /*                         G E N
  3.  
  4.      Update history, most recent first.
  5.  
  6.   Date     Int  Modification
  7. ---------  ---  ---------------------------------------------------------------
  8. 09-Mar-88  JBM  Mods to run Bennett's benchmark.
  9. 17-Feb-88  JBM  Added 1/1 aspect mode with -t switch for Tracer output.
  10. 15-Feb-88  JBM  Moved both loops out for assembly.
  11. 11-Feb-88  JBM  Changes to inner.
  12. 05-Feb-88  JBM  Split inner loop off for optimization.
  13. 01-Feb-88  JBM  Fixed bug where only count mod 256 was being written.
  14. 25-Jan-88  JBM  Well, the -O compiler switch does not help the FP code, but
  15.                                 register storage class surely does.
  16. 21-Jan-88  JBM  Worked up version for the Sperry. Very weird, when put in
  17.                                 background with &, it still pays attention to signals!!
  18. 19-Jan-88  JBM  Decided to do it the UNIX way. This has now been split into a
  19.                                 generator and a displayer. That means this module is now machine
  20.                                 INDEPENDANT. Added cols and rows limits, mostly for proofing.
  21.                                 Added auto aspect for proofing.
  22. 17-Jan-88  JBM  Thanks to my wonderful cleanup, after leaving it run all night
  23.                                 last night, I woke up to find nothing. Switched to 24 (288)
  24.                                 line for now. Time to fix the aspect ratio.
  25. 16-Jan-88  JBM  Got the wrastop() stuff working, thanks to the code in the mac
  26.                                 paint file viewer from Emmet P. Gray. Added the signal trapping
  27.                                 stuff, pulled in Jim Prior's fr3.c fractal stuff. For original
  28.                                 comments, see the original code.
  29. 15-Jan-88  JBM  Started on the wrastop stuff. It doesn't look like it's going
  30.                                 to let me have the whole screen.
  31. */
  32.  
  33. #include <sys/types.h>
  34. #include <sys/times.h>
  35. #include <math.h>
  36. #include <setjmp.h>
  37. #include <signal.h>
  38. #include <stdio.h>
  39.  
  40. /*#define DOBENCH /* uncomment if you want to run benchmark */
  41.  
  42. #ifdef DOBENCH
  43. #    define ROWS 500
  44. #    define COLS 500
  45. #    define ASPECT 1.0 /* benchmark parameters */
  46. #else
  47. #    define ROWS 348
  48. #    define COLS 720
  49. #    define ASPECT 1.5625 /* pixel aspect ratio 720 x 288, takes up 8" x 5" */
  50. #endif
  51.  
  52. static jmp_buf env;
  53. static int TheSig=0;
  54.  
  55. void Do(ArgWid,ArgX,ArgY,cols,rows,iter,onetoone)
  56. double ArgX,ArgY,ArgWid;
  57. int cols,rows,iter;
  58. {
  59.     long clicks,clstart,clstop,hold;
  60.     double real_min,real_inc;
  61.     double imag_min,imag_inc;
  62.     double aspect,real_max,imag_max;
  63.     struct tms start,done;
  64.     static unsigned short int buf[ROWS][COLS];
  65.     long time(),times();
  66.  
  67.     if (onetoone)
  68.         aspect=1.0/((cols+0.)/(rows+0.));
  69.     else
  70.         aspect=ASPECT/((cols+0.)/(rows+0.));
  71.     real_min=ArgX-.5*ArgWid;
  72.     real_max=ArgX+.5*ArgWid;
  73.     real_inc=(real_max-real_min)/cols;
  74.     imag_min=ArgY-.5*aspect*ArgWid;
  75.     imag_max=ArgY+.5*aspect*ArgWid;
  76.     imag_inc=(imag_max-imag_min)/rows;
  77.  
  78.     printf("%04d %04d\n",cols,rows);
  79.     printf("%.17le %.17le %.17le %.17le\n",ArgX,real_min,real_max,real_inc);
  80.     printf("%.17le %.17le %.17le %.17le\n",ArgY,imag_min,imag_max,imag_inc);
  81.  
  82.     memset(buf,'Z',ROWS*COLS*2); /* debugging */
  83.  
  84.     time(&clstart); /* this is whole seconds */
  85.     times(&start);
  86.     Calc(buf,cols,rows,iter,real_min,real_inc,imag_min,imag_inc);
  87.     times(&done);
  88.     time(&clstop);
  89.  
  90.     fprintf(stderr,"elapsed time: %ld seconds\n",clstop-clstart);
  91.     clicks=done.tms_utime-start.tms_utime;
  92.     fprintf(stderr,"cpu time: %d clicks ( ",clicks);
  93.     if ((hold=clicks/(24*60*60*60))>0) {
  94.         fprintf(stderr,"%d days ",hold);
  95.         clicks%=24*60*60*60;
  96.     }
  97.     if ((hold=clicks/(60*60*60))>0) {
  98.         fprintf(stderr,"%d hours ",hold);
  99.         clicks%=60*60*60;
  100.     }
  101.     if ((hold=clicks/(60*60))>0) {
  102.         fprintf(stderr,"%d minutes ",hold);
  103.         clicks%=60*60;
  104.     }
  105.     if ((hold=clicks/60)>0) {
  106.         fprintf(stderr,"%d seconds ",hold);
  107.         clicks%=60;
  108.     }
  109.     if (clicks>0)
  110.         fprintf(stderr,"%d clicks ",clicks);
  111.     fprintf(stderr,")\n\n");
  112.     
  113.     fwrite(buf,rows*cols*2,1,stdout); /* it's actually stored linearly */
  114. }
  115.  
  116. static int GetSig(sig)
  117. int sig;
  118. {
  119.     TheSig=sig;
  120.     longjmp (env,1);
  121. }
  122.  
  123. void Init()
  124. {
  125.     signal(SIGHUP,SIG_IGN);
  126.     signal(SIGINT,SIG_IGN);
  127.     signal(SIGQUIT,GetSig);
  128.     signal(SIGSEGV,GetSig);
  129.     signal(SIGTERM,GetSig); /* as from kill (1) command */
  130. }
  131.  
  132. void Term()
  133. {
  134.     if (TheSig==0)
  135.         fprintf(stderr,"gen completed.\n");
  136.     else
  137.         fprintf(stderr,"gen aborted, signal=%d\n",TheSig);
  138.     exit(TheSig);
  139. }
  140.  
  141. int main(argc,argv)
  142. int argc;
  143. char *argv[];
  144. {
  145.     char c,Trace=0;
  146.     extern int optind;
  147.     extern char *optarg;
  148.  
  149.     while ((c=getopt(argc,argv,"t"))!=EOF)
  150.         switch (c) {
  151.             case 't':
  152.                 Trace=1;
  153.                 break;
  154.             }
  155.     if (argc!=optind+6) {
  156.         printf("Usage: %s width x y cols rows iter\n",argv[0]);
  157.         exit();
  158.     }
  159. #ifdef DOBENCH
  160.     fprintf(stderr,"RUNNING BENCHMARK\n");
  161. #endif
  162.     Init();
  163.     if (!setjmp(env))
  164.         Do(atof(argv[optind]),atof(argv[optind+1]),atof(argv[optind+2]),
  165.             atoi(argv[optind+3]),atoi(argv[optind+4]),atoi(argv[optind+5]),Trace);
  166.     Term();
  167. }
  168.