| 1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 32 |
|
extern double s_longitude; |
| 33 |
|
extern double s_meridian; |
| 34 |
|
/* required values */ |
| 35 |
< |
int month, day; |
| 36 |
< |
double hour; |
| 35 |
> |
int month, day; /* date */ |
| 36 |
> |
double hour; /* time */ |
| 37 |
> |
int tsolar; /* 0=standard, 1=solar */ |
| 38 |
> |
double altitude, azimuth; /* or solar angles */ |
| 39 |
|
/* default values */ |
| 40 |
< |
int cloudy = 0; |
| 40 |
> |
int cloudy = 0; /* 1=standard, 2=uniform */ |
| 41 |
|
int dosun = 1; |
| 42 |
|
double zenithbr = -1.0; |
| 43 |
|
double turbidity = 2.75; |
| 46 |
|
double sundir[3]; |
| 47 |
|
double groundbr; |
| 48 |
|
double F2; |
| 49 |
< |
double solarbr; |
| 49 |
> |
double solarbr = -1.0; |
| 50 |
|
|
| 51 |
|
char *progname; |
| 52 |
|
char errmsg[128]; |
| 56 |
|
int argc; |
| 57 |
|
char *argv[]; |
| 58 |
|
{ |
| 57 |
– |
extern double atof(), fabs(); |
| 59 |
|
int i; |
| 60 |
|
|
| 61 |
|
progname = argv[0]; |
| 65 |
|
} |
| 66 |
|
if (argc < 4) |
| 67 |
|
userror("arg count"); |
| 68 |
< |
month = atoi(argv[1]); |
| 69 |
< |
day = atoi(argv[2]); |
| 70 |
< |
hour = atof(argv[3]); |
| 68 |
> |
if (!strcmp(argv[1], "-ang")) { |
| 69 |
> |
altitude = atof(argv[2]) * (PI/180); |
| 70 |
> |
azimuth = atof(argv[3]) * (PI/180); |
| 71 |
> |
month = 0; |
| 72 |
> |
} else { |
| 73 |
> |
month = atoi(argv[1]); |
| 74 |
> |
if (month < 1 || month > 12) |
| 75 |
> |
userror("bad month"); |
| 76 |
> |
day = atoi(argv[2]); |
| 77 |
> |
if (day < 1 || day > 31) |
| 78 |
> |
userror("bad day"); |
| 79 |
> |
hour = atof(argv[3]); |
| 80 |
> |
if (hour < 0 || hour >= 24) |
| 81 |
> |
userror("bad hour"); |
| 82 |
> |
tsolar = argv[3][0] == '+'; |
| 83 |
> |
} |
| 84 |
|
for (i = 4; i < argc; i++) |
| 85 |
|
if (argv[i][0] == '-' || argv[i][0] == '+') |
| 86 |
|
switch (argv[i][1]) { |
| 88 |
|
cloudy = 0; |
| 89 |
|
dosun = argv[i][0] == '+'; |
| 90 |
|
break; |
| 91 |
+ |
case 'r': |
| 92 |
+ |
solarbr = atof(argv[++i]); |
| 93 |
+ |
break; |
| 94 |
|
case 'c': |
| 95 |
< |
cloudy = 1; |
| 95 |
> |
cloudy = argv[i][0] == '+' ? 2 : 1; |
| 96 |
|
dosun = 0; |
| 97 |
|
break; |
| 98 |
|
case 't': |
| 134 |
|
|
| 135 |
|
computesky() /* compute sky parameters */ |
| 136 |
|
{ |
| 120 |
– |
int jd; |
| 121 |
– |
double sd, st; |
| 122 |
– |
double altitude, azimuth; |
| 137 |
|
/* compute solar direction */ |
| 138 |
< |
jd = jdate(month, day); /* Julian date */ |
| 139 |
< |
sd = sdec(jd); /* solar declination */ |
| 140 |
< |
st = hour + stadj(jd); /* solar time */ |
| 141 |
< |
altitude = salt(sd, st); |
| 142 |
< |
azimuth = sazi(sd, st); |
| 138 |
> |
if (month) { /* from date and time */ |
| 139 |
> |
int jd; |
| 140 |
> |
double sd, st; |
| 141 |
> |
|
| 142 |
> |
jd = jdate(month, day); /* Julian date */ |
| 143 |
> |
sd = sdec(jd); /* solar declination */ |
| 144 |
> |
if (tsolar) /* solar time */ |
| 145 |
> |
st = hour; |
| 146 |
> |
else |
| 147 |
> |
st = hour + stadj(jd); |
| 148 |
> |
altitude = salt(sd, st); |
| 149 |
> |
azimuth = sazi(sd, st); |
| 150 |
> |
} |
| 151 |
> |
if (!cloudy && altitude > 87.*PI/180.) { |
| 152 |
> |
fprintf(stderr, |
| 153 |
> |
"%s: warning - sun too close to zenith, reducing altitude to 87 degrees\n", |
| 154 |
> |
progname); |
| 155 |
> |
printf( |
| 156 |
> |
"# warning - sun too close to zenith, reducing altitude to 87 degrees\n"); |
| 157 |
> |
altitude = 87.*PI/180.; |
| 158 |
> |
} |
| 159 |
|
sundir[0] = -sin(azimuth)*cos(altitude); |
| 160 |
|
sundir[1] = -cos(azimuth)*cos(altitude); |
| 161 |
|
sundir[2] = sin(altitude); |
| 164 |
|
if (zenithbr <= 0.0) |
| 165 |
|
if (cloudy) { |
| 166 |
|
zenithbr = 8.6*sundir[2] + .123; |
| 167 |
< |
zenithbr *= 1000.0/SKYEFFICACY; |
| 167 |
> |
zenithbr *= 1000.0/WHTEFFICACY; |
| 168 |
|
} else { |
| 169 |
|
zenithbr = (1.376*turbidity-1.81)*tan(altitude)+0.38; |
| 170 |
|
zenithbr *= 1000.0/SKYEFFICACY; |
| 173 |
|
zenithbr = 0.0; |
| 174 |
|
/* Compute horizontal radiance */ |
| 175 |
|
if (cloudy) { |
| 176 |
< |
groundbr = zenithbr*0.777778; |
| 176 |
> |
if (cloudy == 2) |
| 177 |
> |
groundbr = zenithbr; |
| 178 |
> |
else |
| 179 |
> |
groundbr = zenithbr*0.777778; |
| 180 |
|
printf("# Ground ambient level: %f\n", groundbr); |
| 181 |
|
} else { |
| 182 |
|
F2 = 0.274*(0.91 + 10.0*exp(-3.0*(PI/2.0-altitude)) + |
| 183 |
|
0.45*sundir[2]*sundir[2]); |
| 184 |
< |
groundbr = zenithbr*normsc(PI/2.0-altitude)/F2/PI; |
| 184 |
> |
groundbr = zenithbr*normsc(altitude)/F2/PI; |
| 185 |
|
printf("# Ground ambient level: %f\n", groundbr); |
| 186 |
< |
if (sundir[2] > 0.0) { |
| 187 |
< |
if (sundir[2] > .16) |
| 188 |
< |
solarbr = (1.5e9/SUNEFFICACY) * |
| 189 |
< |
(1.147 - .147/sundir[2]); |
| 157 |
< |
else |
| 158 |
< |
solarbr = 1.5e9/SUNEFFICACY*(1.147-.147/.16); |
| 186 |
> |
if (sundir[2] > 0.0 && solarbr != 0.0) { |
| 187 |
> |
if (solarbr < 0.0) |
| 188 |
> |
solarbr = 1.5e9/SUNEFFICACY * |
| 189 |
> |
(1.147 - .147/(sundir[2]>.16?sundir[2]:.16)); |
| 190 |
|
groundbr += solarbr*6e-5*sundir[2]/PI; |
| 191 |
|
} else |
| 192 |
|
dosun = 0; |
| 210 |
|
printf("2 skybright skybright.cal\n"); |
| 211 |
|
printf("0\n"); |
| 212 |
|
if (cloudy) |
| 213 |
< |
printf("3 1 %.2e %.2e\n", zenithbr, groundbr); |
| 213 |
> |
printf("3 %d %.2e %.2e\n", cloudy, zenithbr, groundbr); |
| 214 |
|
else |
| 215 |
|
printf("7 -1 %.2e %.2e %.2e %f %f %f\n", zenithbr, groundbr, |
| 216 |
|
F2, sundir[0], sundir[1], sundir[2]); |
| 219 |
|
|
| 220 |
|
printdefaults() /* print default values */ |
| 221 |
|
{ |
| 222 |
< |
if (cloudy) |
| 222 |
> |
if (cloudy == 1) |
| 223 |
|
printf("-c\t\t\t\t# Cloudy sky\n"); |
| 224 |
+ |
else if (cloudy == 2) |
| 225 |
+ |
printf("+c\t\t\t\t# Uniform cloudy sky\n"); |
| 226 |
|
else if (dosun) |
| 227 |
|
printf("+s\t\t\t\t# Sunny sky with sun\n"); |
| 228 |
|
else |
| 244 |
|
if (msg != NULL) |
| 245 |
|
fprintf(stderr, "%s: Use error - %s\n", progname, msg); |
| 246 |
|
fprintf(stderr, "Usage: %s month day hour [options]\n", progname); |
| 247 |
+ |
fprintf(stderr, " Or: %s -ang altitude azimuth [options]\n", progname); |
| 248 |
|
fprintf(stderr, " Or: %s -defaults\n", progname); |
| 249 |
|
exit(1); |
| 250 |
|
} |