| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | #include <stdio.h> |
|---|
| 11 | #include <string.h> |
|---|
| 12 | #include <math.h> |
|---|
| 13 | |
|---|
| 14 | #define COLS 1 |
|---|
| 15 | #define ROWS 1 |
|---|
| 16 | #define THRESH 37 |
|---|
| 17 | #define COLOR 2 |
|---|
| 18 | #define POWER 1 |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | #define AA (16450-23200) |
|---|
| 23 | #define BB (12.36-11.74) |
|---|
| 24 | #define CC (-1.023+0.66) |
|---|
| 25 | #define DD 0. |
|---|
| 26 | #define CONST 1.33216 |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | #define PI 3.141592653589793 |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | void main (int argc, char *argv[]) |
|---|
| 46 | { |
|---|
| 47 | int i, j, n=0, rowd, cold; |
|---|
| 48 | double *rower, total=0., last, func(), fTH, f255; |
|---|
| 49 | unsigned char insup [80], *outs; |
|---|
| 50 | FILE *ppmout; |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | scanf ("%s", insup); |
|---|
| 54 | if (strcmp (insup, "P6")) |
|---|
| 55 | exit (printf ("Not PPM.\n"), 1); |
|---|
| 56 | |
|---|
| 57 | scanf ("%s", insup); |
|---|
| 58 | if (insup [0] == '#') |
|---|
| 59 | { |
|---|
| 60 | while (insup [1] != 13 && insup [1] != 10) |
|---|
| 61 | scanf ("%c", insup+1); |
|---|
| 62 | scanf ("%s", insup); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | sscanf (insup, "%d", &cold); |
|---|
| 66 | scanf ("%d", &rowd); |
|---|
| 67 | scanf ("%d", &i); |
|---|
| 68 | printf ("Picture rows: %d, columns: %d, bytemask:%d\n", rowd, cold, i); |
|---|
| 69 | scanf ("%c", insup+1); |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | if ((ppmout = fopen ("map.ppm", "w")) == NULL) |
|---|
| 73 | exit (printf ("No ppm file!\n"), 1); |
|---|
| 74 | fprintf (ppmout, "P5\n# CREATOR: Adam Powell's ebaporate software\n"); |
|---|
| 75 | fprintf (ppmout, "%d %d\n255\n", |
|---|
| 76 | (cold+COLS-1)/COLS, (rowd+ROWS-1)/ROWS); |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | if ((rower = (double *)malloc (sizeof (double)*((cold+COLS-1)/COLS))) == NULL) |
|---|
| 80 | exit (printf ("Not enough memory...\n")); |
|---|
| 81 | if ((outs = (char *)malloc (sizeof (char)*((cold+COLS-1)/COLS))) == NULL) |
|---|
| 82 | exit (printf ("Not enough memory...\n")); |
|---|
| 83 | for (j=0; j<(cold+COLS-1)/COLS; j++) |
|---|
| 84 | rower [j]=0.; |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | for (i=0; i<rowd; i++) |
|---|
| 89 | { |
|---|
| 90 | for (j=0; j<cold; j++) |
|---|
| 91 | { |
|---|
| 92 | scanf ("%c%c%c", insup+1, insup+2, insup+3); |
|---|
| 93 | if (insup [COLOR] < THRESH) |
|---|
| 94 | rower [j/COLS] = 256. * ROWS * COLS; |
|---|
| 95 | rower [j/COLS] += insup [COLOR]; |
|---|
| 96 | } |
|---|
| 97 | fTH = func ((double)THRESH); |
|---|
| 98 | f255=func (255.); |
|---|
| 99 | if (i%ROWS == ROWS-1 || i == rowd-1) |
|---|
| 100 | for (j=0;j<(cold+COLS-1)/COLS;j++) |
|---|
| 101 | { |
|---|
| 102 | last = rower [j] /= ROWS*COLS; |
|---|
| 103 | if (rower [j] < 256) |
|---|
| 104 | { |
|---|
| 105 | total += func (rower [j]); |
|---|
| 106 | n++; |
|---|
| 107 | outs [j] = (unsigned char) |
|---|
| 108 | (220. - 220.*pow ((func (rower [j])-fTH)/(f255-fTH), POWER)); |
|---|
| 109 | } |
|---|
| 110 | else |
|---|
| 111 | { |
|---|
| 112 | outs [j] = 255; |
|---|
| 113 | } |
|---|
| 114 | fprintf (ppmout, "%c", outs [j]); |
|---|
| 115 | rower [j] = 0.; |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | fclose (ppmout); |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | printf ("Making Tbar...\n"); |
|---|
| 122 | if ((ppmout = fopen ("tbar.ppm", "w")) == NULL) |
|---|
| 123 | exit (printf ("No Tbar file!\n"), 1); |
|---|
| 124 | fprintf (ppmout, "P5\n# CREATOR: Adam's evapometer software\n216 20\n255\n"); |
|---|
| 125 | for (i=0; i<20;i++) |
|---|
| 126 | { |
|---|
| 127 | for (j=0; j<24;j++) |
|---|
| 128 | fprintf (ppmout, "%c", 255); |
|---|
| 129 | for (j=24; j<216;j++) |
|---|
| 130 | fprintf (ppmout, "%c", (unsigned char) |
|---|
| 131 | (220.-220.*pow(((double)j-24.)/192., POWER))); |
|---|
| 132 | } |
|---|
| 133 | fclose (ppmout); |
|---|
| 134 | |
|---|
| 135 | printf ("Min, max function values: %lf %lf\n", fTH, f255); |
|---|
| 136 | printf ("(Last rower: %.2lf; last chars: %d %d %d)\n", last, |
|---|
| 137 | *(insup+1), *(insup+2), *(insup+3)); |
|---|
| 138 | printf ("Average functional value: %le, based on %d out of %d cells.\n\n", |
|---|
| 139 | total/n, n, ((cold+COLS-1)/COLS)*((rowd+ROWS-1)/ROWS)); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | double func (double color) |
|---|
| 155 | { |
|---|
| 156 | double temp, vp; |
|---|
| 157 | temp = 288.31 * log (color*23.02927); |
|---|
| 158 | |
|---|
| 159 | vp = exp (log (10.) * (-AA/temp + BB + CC*log10 (temp) + DD*.001*temp)); |
|---|
| 160 | |
|---|
| 161 | vp *= CONST; |
|---|
| 162 | |
|---|
| 163 | return (temp); } |
|---|