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