Annotation of os2sdk/demos/apps/mandel/mstat.c, revision 1.1.1.1

1.1       root        1: /**    Mstat.c - display Mandelbrot set statistics
                      2:  *     R. A. Garmoe  87/01/07
                      3:  */
                      4: 
                      5: 
                      6: 
                      7: /**    Mstat displays the statistics of the Mandelbrot set contained
                      8:  *     in the specified file.  The Mandelbrot set is defined by
                      9:  *
                     10:  *             z = z**2 + c
                     11:  *
                     12:  *     where z and c are in the complex plane and z = 0 + 0i for the first
                     13:  *     iteration.
                     14:  */
                     15: 
                     16: /*
                     17:  *     The .cnt file has the format
                     18:  *             int     number of points along the real axis
                     19:  *             int     number of points along the imaginary axis
                     20:  *             int     maximum iteration point for each point
                     21:  *             double  real coordinate of upper left
                     22:  *             double  imaginary coordinate of upper left
                     23:  *             double  real coordinate of lower right
                     24:  *             double  imaginary coordinate lower rightft
                     25:  *             double  increment between points on real axis
                     26:  *             double  increment between points on imaginary axis
                     27:  *             long    (loop + 1) counters for histogram values
                     28:  *
                     29:  *     The remainder of the file is the run length encoded scan
                     30:  *     lines encoded as:
                     31:  *             int     number of words in scan line encoded as:
                     32:  *                     +int        actual count value for pixel
                     33:  *                     -int int    The first value is the run length and
                     34:  *                                 second value is the run value
                     35:  */
                     36: 
                     37: 
                     38: 
                     39: 
                     40: #include <stdio.h>
                     41: 
                     42: #define FALSE  0
                     43: #define TRUE   ~FALSE
                     44: 
                     45: #define MAXREAL 2000           /* maximum number of real coordinates */
                     46: #define MAXLOOP 1000           /* maximum number of iterations */
                     47: 
                     48: struct cmplx {
                     49:        double   realp;         /* real part of number */
                     50:        double   imagp;         /* imaginary part of number */
                     51: };
                     52: char   pmand[60] = "mandel.cnt";
                     53: FILE   *fmand;
                     54: 
                     55: struct cmplx ul;               /* coordinates of upper left corner */
                     56: struct cmplx lr;               /* coordinates of lower right corner */
                     57: 
                     58: int    nimag;                  /* number of imaginary coordinates */
                     59: int    mloop;                  /* maximum loop count */
                     60: int    nreal;                  /* number of real coordinates */
                     61: int    verbose = FALSE;        /* print verbose statistics */
                     62: 
                     63: double rinc;                   /* increment in real coordinate */
                     64: double iinc;                   /* increment in imaginary coordinate */
                     65: double aspect;                 /* aspect ratio */
                     66: 
                     67: long   hist[MAXLOOP + 1] = {0}; /* histogram counters */
                     68: 
                     69: main (argc, argv)
                     70: int    argc;
                     71: char   **argv;
                     72: {
                     73:        int     lnr;
                     74:        int     lni;
                     75:        int     ni;
                     76:        int     i;
                     77:        int     j;
                     78:        long   *hp;
                     79: 
                     80:        nextarg (argc, argv);
                     81:        if ((fmand = fopen (pmand, "rb")) == NULL) {
                     82:                printf ("Unable to open count file %s\n", pmand);
                     83:                exit (3);
                     84:        }
                     85: 
                     86:        if (fread ((char *)&nreal, sizeof (int), 1, fmand) != 1) {
                     87:                printf ("Error reading maximum number of reals %d\n", nreal);
                     88:                exit (2);
                     89:        }
                     90:        lnr = (nreal > 640)? 640: nreal;
                     91:        printf ("nreal = %d %d\n", nreal, lnr);
                     92:        if (fread ((char *)&nimag, sizeof (int), 1, fmand) != 1) {
                     93:                printf ("Error reading maximum number of imaginaries %d\n", nimag);
                     94:                exit (2);
                     95:        }
                     96:        lni = (nimag > 350)? 350: nimag;
                     97:        printf ("nimag = %d %d\n", nimag, lni);
                     98:        if (fread ((char *)&mloop, sizeof (int), 1, fmand) != 1) {
                     99:                printf ("Error reading maximum loop count %d\n", mloop);
                    100:                exit (2);
                    101:        }
                    102:        printf ("mloop = %d\n", mloop);
                    103:        if (fread ((char *)&ul, sizeof (ul), 1, fmand) != 1) {
                    104:                printf ("Error reading upper left coordinates\n");
                    105:                exit (2);
                    106:        }
                    107:        printf ("ul = %e+%ei\n", ul.realp, ul.imagp);
                    108:        if (fread ((char *)&lr, sizeof (lr), 1, fmand) != 1) {
                    109:                printf ("Error reading lower right coordinates\n");
                    110:                exit (2);
                    111:        }
                    112:        printf ("lr = %e+%ei\n", lr.realp, lr.imagp);
                    113: 
                    114:        if (fread ((char *)&rinc, sizeof (rinc), 1, fmand) != 1) {
                    115:                printf ("Error reading real increment\n");
                    116:                exit (2);
                    117:        }
                    118:        printf ("rinc = %e\n", rinc);
                    119:        if (fread ((char *)&iinc, sizeof (iinc), 1, fmand) != 1) {
                    120:                printf ("Error reading imaginary increment\n");
                    121:                exit (2);
                    122:        }
                    123:        printf ("iinc = %e\n", iinc);
                    124:        if (fread ((char *)&aspect, sizeof (aspect), 1, fmand) != 1) {
                    125:                printf ("Error reading aspect ratio\n");
                    126:                exit (2);
                    127:        }
                    128:        printf ("aspect = %e\n", aspect);
                    129: 
                    130:        if (fread ((char *)hist, sizeof (long), mloop + 1, fmand) != mloop + 1) {
                    131:                printf ("Error reading histogram\n");
                    132:                exit (2);
                    133:        }
                    134:        if (verbose) {
                    135:                printf ("     ");
                    136:                for ( i = 0; i < 10; i++)
                    137:                        printf ("%7d", i);
                    138:                printf ("\n");
                    139:                ni = (mloop + 1) / 10;
                    140:                hp = hist;
                    141:                for (i = 0; i < ni; i++) {
                    142:                        printf ("%4d ", i * 10);
                    143:                        for (j = 0; j < 10; j++)
                    144:                                printf ("%7ld", *hp++);
                    145:                        printf ("\n");
                    146:                }
                    147:                if ((j = (mloop + 1 - ni * 10)) > 0) {
                    148:                        printf ("%4d ", ni * 10);
                    149:                        for (; j > 0; j--)
                    150:                                printf ("%7ld", *hp++);
                    151:                        printf ("\n");
                    152:                }
                    153:        }
                    154: }
                    155: 
                    156: 
                    157: 
                    158: 
                    159: /**    nextarg - process arguments
                    160:  *
                    161:  */
                    162: 
                    163: 
                    164: nextarg (argc, argv)
                    165: int    argc;
                    166: char   **argv;
                    167: {
                    168: 
                    169:        argv++;
                    170:        while ((argc-- > 0) && (**argv == '-')) {
                    171:                switch (*(*argv+1)) {
                    172:                        case 'f':
                    173:                                argv++;
                    174:                                /* set file name */
                    175:                                strcpy (pmand, *argv);
                    176:                                strcat (pmand, ".cnt");
                    177:                                break;
                    178: 
                    179:                        case 'v':
                    180:                                argv++;
                    181:                                verbose = TRUE;
                    182:                                break;
                    183: 
                    184:                        default:
                    185:                                printf ("Unknown argument %s\n", *argv);
                    186:                                exit (1);
                    187: 
                    188:                }
                    189:        }
                    190: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.