home *** CD-ROM | disk | FTP | other *** search
- /* vi: set ts=2 sw=2: */
- /* G E N
-
- Update history, most recent first.
-
- Date Int Modification
- --------- --- ---------------------------------------------------------------
- 09-Mar-88 JBM Mods to run Bennett's benchmark.
- 17-Feb-88 JBM Added 1/1 aspect mode with -t switch for Tracer output.
- 15-Feb-88 JBM Moved both loops out for assembly.
- 11-Feb-88 JBM Changes to inner.
- 05-Feb-88 JBM Split inner loop off for optimization.
- 01-Feb-88 JBM Fixed bug where only count mod 256 was being written.
- 25-Jan-88 JBM Well, the -O compiler switch does not help the FP code, but
- register storage class surely does.
- 21-Jan-88 JBM Worked up version for the Sperry. Very weird, when put in
- background with &, it still pays attention to signals!!
- 19-Jan-88 JBM Decided to do it the UNIX way. This has now been split into a
- generator and a displayer. That means this module is now machine
- INDEPENDANT. Added cols and rows limits, mostly for proofing.
- Added auto aspect for proofing.
- 17-Jan-88 JBM Thanks to my wonderful cleanup, after leaving it run all night
- last night, I woke up to find nothing. Switched to 24 (288)
- line for now. Time to fix the aspect ratio.
- 16-Jan-88 JBM Got the wrastop() stuff working, thanks to the code in the mac
- paint file viewer from Emmet P. Gray. Added the signal trapping
- stuff, pulled in Jim Prior's fr3.c fractal stuff. For original
- comments, see the original code.
- 15-Jan-88 JBM Started on the wrastop stuff. It doesn't look like it's going
- to let me have the whole screen.
- */
-
- #include <sys/types.h>
- #include <sys/times.h>
- #include <math.h>
- #include <setjmp.h>
- #include <signal.h>
- #include <stdio.h>
-
- /*#define DOBENCH /* uncomment if you want to run benchmark */
-
- #ifdef DOBENCH
- # define ROWS 500
- # define COLS 500
- # define ASPECT 1.0 /* benchmark parameters */
- #else
- # define ROWS 348
- # define COLS 720
- # define ASPECT 1.5625 /* pixel aspect ratio 720 x 288, takes up 8" x 5" */
- #endif
-
- static jmp_buf env;
- static int TheSig=0;
-
- void Do(ArgWid,ArgX,ArgY,cols,rows,iter,onetoone)
- double ArgX,ArgY,ArgWid;
- int cols,rows,iter;
- {
- long clicks,clstart,clstop,hold;
- double real_min,real_inc;
- double imag_min,imag_inc;
- double aspect,real_max,imag_max;
- struct tms start,done;
- static unsigned short int buf[ROWS][COLS];
- long time(),times();
-
- if (onetoone)
- aspect=1.0/((cols+0.)/(rows+0.));
- else
- aspect=ASPECT/((cols+0.)/(rows+0.));
- real_min=ArgX-.5*ArgWid;
- real_max=ArgX+.5*ArgWid;
- real_inc=(real_max-real_min)/cols;
- imag_min=ArgY-.5*aspect*ArgWid;
- imag_max=ArgY+.5*aspect*ArgWid;
- imag_inc=(imag_max-imag_min)/rows;
-
- printf("%04d %04d\n",cols,rows);
- printf("%.17le %.17le %.17le %.17le\n",ArgX,real_min,real_max,real_inc);
- printf("%.17le %.17le %.17le %.17le\n",ArgY,imag_min,imag_max,imag_inc);
-
- memset(buf,'Z',ROWS*COLS*2); /* debugging */
-
- time(&clstart); /* this is whole seconds */
- times(&start);
- Calc(buf,cols,rows,iter,real_min,real_inc,imag_min,imag_inc);
- times(&done);
- time(&clstop);
-
- fprintf(stderr,"elapsed time: %ld seconds\n",clstop-clstart);
- clicks=done.tms_utime-start.tms_utime;
- fprintf(stderr,"cpu time: %d clicks ( ",clicks);
- if ((hold=clicks/(24*60*60*60))>0) {
- fprintf(stderr,"%d days ",hold);
- clicks%=24*60*60*60;
- }
- if ((hold=clicks/(60*60*60))>0) {
- fprintf(stderr,"%d hours ",hold);
- clicks%=60*60*60;
- }
- if ((hold=clicks/(60*60))>0) {
- fprintf(stderr,"%d minutes ",hold);
- clicks%=60*60;
- }
- if ((hold=clicks/60)>0) {
- fprintf(stderr,"%d seconds ",hold);
- clicks%=60;
- }
- if (clicks>0)
- fprintf(stderr,"%d clicks ",clicks);
- fprintf(stderr,")\n\n");
-
- fwrite(buf,rows*cols*2,1,stdout); /* it's actually stored linearly */
- }
-
- static int GetSig(sig)
- int sig;
- {
- TheSig=sig;
- longjmp (env,1);
- }
-
- void Init()
- {
- signal(SIGHUP,SIG_IGN);
- signal(SIGINT,SIG_IGN);
- signal(SIGQUIT,GetSig);
- signal(SIGSEGV,GetSig);
- signal(SIGTERM,GetSig); /* as from kill (1) command */
- }
-
- void Term()
- {
- if (TheSig==0)
- fprintf(stderr,"gen completed.\n");
- else
- fprintf(stderr,"gen aborted, signal=%d\n",TheSig);
- exit(TheSig);
- }
-
- int main(argc,argv)
- int argc;
- char *argv[];
- {
- char c,Trace=0;
- extern int optind;
- extern char *optarg;
-
- while ((c=getopt(argc,argv,"t"))!=EOF)
- switch (c) {
- case 't':
- Trace=1;
- break;
- }
- if (argc!=optind+6) {
- printf("Usage: %s width x y cols rows iter\n",argv[0]);
- exit();
- }
- #ifdef DOBENCH
- fprintf(stderr,"RUNNING BENCHMARK\n");
- #endif
- Init();
- if (!setjmp(env))
- Do(atof(argv[optind]),atof(argv[optind+1]),atof(argv[optind+2]),
- atoi(argv[optind+3]),atoi(argv[optind+4]),atoi(argv[optind+5]),Trace);
- Term();
- }
-