23 |
|
#endif |
24 |
|
|
25 |
|
#ifdef _WIN32 |
26 |
< |
#define SPECIALS " \t$*?" |
26 |
> |
#define SPECIALS " \t\"$*?" |
27 |
|
#define QUOTCHAR '"' |
28 |
|
#else |
29 |
< |
#define SPECIALS " \t\n'\"()${}*?[]" |
29 |
> |
#define SPECIALS " \t\n'\"()${}*?[];|&" |
30 |
|
#define QUOTCHAR '\'' |
31 |
|
#define ALTQUOT '"' |
32 |
|
#endif |
45 |
|
#define CHECKARGC(n) if (nrcargs >= MAXRCARG-(n)) \ |
46 |
|
{ fprintf(stderr, overflowerr, progname); exit(1); } |
47 |
|
|
48 |
< |
int sampcnt = 0; /* sample count (unset) */ |
48 |
> |
int sampcnt = 0; /* sample count (0==unset) */ |
49 |
|
|
50 |
< |
char *reinhfn = "reinhart.cal"; |
51 |
< |
char *shirchufn = "disk2square.cal"; |
50 |
> |
char *reinhfn = "reinhartb.cal"; |
51 |
> |
char *shirchiufn = "disk2square.cal"; |
52 |
|
char *kfullfn = "klems_full.cal"; |
53 |
|
char *khalffn = "klems_half.cal"; |
54 |
|
char *kquarterfn = "klems_quarter.cal"; |
55 |
|
|
56 |
< |
#define PARAMSTART "@rfluxmtx" /* string indicating parameters */ |
56 |
> |
/* string indicating parameters */ |
57 |
> |
const char PARAMSTART[] = "@rfluxmtx"; |
58 |
|
|
59 |
|
/* surface type IDs */ |
60 |
|
#define ST_NONE 0 |
67 |
|
void *priv; /* private data (malloc'ed) */ |
68 |
|
char sname[32]; /* surface name */ |
69 |
|
FVECT snrm; /* surface normal */ |
70 |
< |
double area; /* surface area (or solid angle) */ |
70 |
> |
double area; /* surface area / proj. solid angle */ |
71 |
|
short styp; /* surface type */ |
72 |
< |
short nfargs; /* number of arguments */ |
73 |
< |
double farg[1]; /* arguments (extends struct) */ |
72 |
> |
short nfargs; /* number of real arguments */ |
73 |
> |
double farg[1]; /* real values (extends struct) */ |
74 |
|
} SURF; /* surface structure */ |
75 |
|
|
76 |
|
typedef struct { |
373 |
|
static void |
374 |
|
finish_receiver(void) |
375 |
|
{ |
376 |
< |
char binbuf[128]; |
376 |
> |
char sbuf[256]; |
377 |
> |
int uniform = 0; |
378 |
> |
char *calfn = NULL; |
379 |
> |
char *params = NULL; |
380 |
> |
char *binv = NULL; |
381 |
> |
char *binf = NULL; |
382 |
> |
char *nbins = NULL; |
383 |
|
|
384 |
|
if (!curmod[0]) { |
385 |
|
fputs(progname, stderr); |
391 |
|
rcarg[nrcargs++] = "-o"; |
392 |
|
rcarg[nrcargs++] = curparams.outfn; |
393 |
|
} |
394 |
< |
/* add bin specification */ |
394 |
> |
/* check arguments */ |
395 |
|
if (!curparams.hemis[0]) { |
396 |
|
fputs(progname, stderr); |
397 |
|
fputs(": missing hemisphere sampling type!\n", stderr); |
407 |
|
curparams.vup[2] = 1; |
408 |
|
else |
409 |
|
curparams.vup[1] = 1; |
410 |
+ |
/* determine sample type/bin */ |
411 |
|
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
412 |
< |
CHECKARGC(2); |
413 |
< |
rcarg[nrcargs++] = "-b"; |
406 |
< |
rcarg[nrcargs++] = "0"; |
412 |
> |
binv = "0"; /* uniform sampling -- one bin */ |
413 |
> |
uniform = 1; |
414 |
|
} else if (tolower(curparams.hemis[0]) == 's' && |
415 |
|
tolower(curparams.hemis[1]) == 'c') { |
416 |
< |
if (shirchufn != NULL) { |
410 |
< |
CHECKARGC(2); |
411 |
< |
rcarg[nrcargs++] = "-f"; |
412 |
< |
rcarg[nrcargs++] = shirchufn; |
413 |
< |
shirchufn = NULL; |
414 |
< |
} |
415 |
< |
fputs("Shirley-Chiu unimplemented...\n",stderr); exit(1); |
416 |
> |
/* assign parameters */ |
417 |
|
if (curparams.hsiz <= 1) { |
418 |
|
fputs(progname, stderr); |
419 |
|
fputs(": missing size for Shirley-Chiu sampling!\n", stderr); |
420 |
|
exit(1); |
421 |
|
} |
422 |
+ |
calfn = shirchiufn; shirchiufn = NULL; |
423 |
+ |
sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", |
424 |
+ |
curparams.hsiz, |
425 |
+ |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
426 |
+ |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
427 |
+ |
params = savqstr(sbuf); |
428 |
+ |
binv = "scbin"; |
429 |
+ |
nbins = "SCdim*SCdim"; |
430 |
|
} else if ((tolower(curparams.hemis[0]) == 'r') | |
431 |
|
(tolower(curparams.hemis[0]) == 't')) { |
432 |
< |
if (reinhfn != NULL) { |
433 |
< |
CHECKARGC(2); |
434 |
< |
rcarg[nrcargs++] = "-f"; |
435 |
< |
rcarg[nrcargs++] = reinhfn; |
436 |
< |
reinhfn = NULL; |
437 |
< |
} |
438 |
< |
fputs("Reinhart/Tregenza unimplemented...\n",stderr); exit(1); |
432 |
> |
calfn = reinhfn; reinhfn = NULL; |
433 |
> |
sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", |
434 |
> |
curparams.hsiz, |
435 |
> |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
436 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
437 |
> |
params = savqstr(sbuf); |
438 |
> |
binv = "rbin"; |
439 |
> |
nbins = "Nrbins"; |
440 |
|
} else if (tolower(curparams.hemis[0]) == 'k' && |
441 |
|
!curparams.hemis[1] | |
442 |
|
(tolower(curparams.hemis[1]) == 'f') | |
443 |
|
(curparams.hemis[1] == '1')) { |
444 |
< |
if (kfullfn != NULL) { |
445 |
< |
CHECKARGC(2); |
446 |
< |
rcarg[nrcargs++] = "-f"; |
437 |
< |
rcarg[nrcargs++] = kfullfn; |
438 |
< |
kfullfn = NULL; |
439 |
< |
} |
440 |
< |
CHECKARGC(4); |
441 |
< |
sprintf(binbuf, "kbin(%g,%g,%g,%g,%g,%g)", |
442 |
< |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
443 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
444 |
< |
rcarg[nrcargs++] = "-b"; |
445 |
< |
rcarg[nrcargs++] = savqstr(binbuf); |
446 |
< |
rcarg[nrcargs++] = "-bn"; |
447 |
< |
rcarg[nrcargs++] = "Nkbins"; |
444 |
> |
calfn = kfullfn; kfullfn = NULL; |
445 |
> |
binf = "kbin"; |
446 |
> |
nbins = "Nkbins"; |
447 |
|
} else if (tolower(curparams.hemis[0]) == 'k' && |
448 |
|
(tolower(curparams.hemis[1]) == 'h') | |
449 |
|
(curparams.hemis[1] == '2')) { |
450 |
< |
if (khalffn != NULL) { |
451 |
< |
CHECKARGC(2); |
452 |
< |
rcarg[nrcargs++] = "-f"; |
454 |
< |
rcarg[nrcargs++] = khalffn; |
455 |
< |
khalffn = NULL; |
456 |
< |
} |
457 |
< |
CHECKARGC(4); |
458 |
< |
sprintf(binbuf, "khbin(%g,%g,%g,%g,%g,%g)", |
459 |
< |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
460 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
461 |
< |
rcarg[nrcargs++] = "-b"; |
462 |
< |
rcarg[nrcargs++] = savqstr(binbuf); |
463 |
< |
rcarg[nrcargs++] = "-bn"; |
464 |
< |
rcarg[nrcargs++] = "Nkhbins"; |
450 |
> |
calfn = khalffn; khalffn = NULL; |
451 |
> |
binf = "khbin"; |
452 |
> |
nbins = "Nkhbins"; |
453 |
|
} else if (tolower(curparams.hemis[0]) == 'k' && |
454 |
|
(tolower(curparams.hemis[1]) == 'q') | |
455 |
|
(curparams.hemis[1] == '4')) { |
456 |
< |
if (kquarterfn != NULL) { |
457 |
< |
CHECKARGC(2); |
458 |
< |
rcarg[nrcargs++] = "-f"; |
471 |
< |
rcarg[nrcargs++] = kquarterfn; |
472 |
< |
kquarterfn = NULL; |
473 |
< |
} |
474 |
< |
CHECKARGC(4); |
475 |
< |
sprintf(binbuf, "kqbin(%g,%g,%g,%g,%g,%g)", |
476 |
< |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
477 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
478 |
< |
rcarg[nrcargs++] = "-b"; |
479 |
< |
rcarg[nrcargs++] = savqstr(binbuf); |
480 |
< |
rcarg[nrcargs++] = "-bn"; |
481 |
< |
rcarg[nrcargs++] = "Nkqbins"; |
456 |
> |
calfn = kquarterfn; kquarterfn = NULL; |
457 |
> |
binf = "kqbin"; |
458 |
> |
nbins = "Nkqbins"; |
459 |
|
} else { |
460 |
|
fprintf(stderr, "%s: unrecognized hemisphere sampling: h=%s\n", |
461 |
|
progname, curparams.hemis); |
462 |
|
exit(1); |
463 |
|
} |
464 |
< |
CHECKARGC(2); /* modifier argument goes last */ |
464 |
> |
if (!uniform & (curparams.slist->styp == ST_SOURCE)) { |
465 |
> |
SURF *sp; |
466 |
> |
for (sp = curparams.slist; sp != NULL; sp = sp->next) |
467 |
> |
if (fabs(sp->area - PI) > 1e-3) { |
468 |
> |
fprintf(stderr, "%s: source '%s' must be 180-degrees\n", |
469 |
> |
progname, sp->sname); |
470 |
> |
exit(1); |
471 |
> |
} |
472 |
> |
} |
473 |
> |
if (calfn != NULL) { /* add cal file if needed */ |
474 |
> |
CHECKARGC(2); |
475 |
> |
rcarg[nrcargs++] = "-f"; |
476 |
> |
rcarg[nrcargs++] = calfn; |
477 |
> |
} |
478 |
> |
if (params != NULL) { /* parameters _after_ cal file */ |
479 |
> |
CHECKARGC(2); |
480 |
> |
rcarg[nrcargs++] = "-p"; |
481 |
> |
rcarg[nrcargs++] = params; |
482 |
> |
} |
483 |
> |
if (nbins != NULL) { /* add #bins if set */ |
484 |
> |
CHECKARGC(2); |
485 |
> |
rcarg[nrcargs++] = "-bn"; |
486 |
> |
rcarg[nrcargs++] = nbins; |
487 |
> |
} |
488 |
> |
if (binv != NULL) { |
489 |
> |
CHECKARGC(2); /* assign bin variable */ |
490 |
> |
rcarg[nrcargs++] = "-b"; |
491 |
> |
rcarg[nrcargs++] = binv; |
492 |
> |
} else if (binf != NULL) { |
493 |
> |
CHECKARGC(2); /* assign bin function */ |
494 |
> |
rcarg[nrcargs++] = "-b"; |
495 |
> |
sprintf(sbuf, "%s(%g,%g,%g,%g,%g,%g)", binf, |
496 |
> |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
497 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
498 |
> |
rcarg[nrcargs++] = savqstr(sbuf); |
499 |
> |
} |
500 |
> |
CHECKARGC(2); /* modifier argument goes last */ |
501 |
|
rcarg[nrcargs++] = "-m"; |
502 |
|
rcarg[nrcargs++] = savqstr(curmod); |
503 |
|
} |
992 |
|
VCOPY(snew->snrm, snew->farg); |
993 |
|
if (normalize(snew->snrm) == 0) |
994 |
|
goto badnorm; |
995 |
< |
snew->area = 2.*PI*(1. - cos((PI/180./2.)*snew->farg[3])); |
995 |
> |
snew->area = sin((PI/180./2.)*snew->farg[3]); |
996 |
> |
snew->area *= PI*snew->area; |
997 |
|
break; |
998 |
|
} |
999 |
|
if (snew->area <= FTINY) { |
1123 |
|
continue; |
1124 |
|
} |
1125 |
|
if (c == '#') { /* parameters/comment */ |
1126 |
< |
if (fscanf(fp, "%s", inpbuf) == 1 && |
1126 |
> |
if ((c = getc(fp)) == EOF || ungetc(c,fp) == EOF) |
1127 |
> |
break; |
1128 |
> |
if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 && |
1129 |
|
!strcmp(inpbuf, PARAMSTART)) { |
1130 |
|
if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL) |
1131 |
|
parse_params(inpbuf); |
1155 |
|
main(int argc, char *argv[]) |
1156 |
|
{ |
1157 |
|
char fmtopt[6] = "-faa"; /* default output is ASCII */ |
1158 |
+ |
char *xrs=NULL, *yrs=NULL, *ldopt=NULL; |
1159 |
|
char *sendfn; |
1160 |
|
char sampcntbuf[32], nsbinbuf[32]; |
1161 |
|
FILE *rcfp; |
1189 |
|
goto userr; |
1190 |
|
} |
1191 |
|
break; |
1192 |
+ |
case 'x': /* x-resolution */ |
1193 |
+ |
xrs = argv[++a]; |
1194 |
+ |
na = 0; |
1195 |
+ |
continue; |
1196 |
+ |
case 'y': /* y-resolution */ |
1197 |
+ |
yrs = argv[++a]; |
1198 |
+ |
na = 0; |
1199 |
+ |
continue; |
1200 |
|
case 'c': /* number of samples */ |
1201 |
|
sampcnt = atoi(argv[a+1]); |
1202 |
|
if (sampcnt <= 0) |
1208 |
|
case 'u': |
1209 |
|
case 'i': |
1210 |
|
case 'h': |
1211 |
+ |
case 'r': |
1212 |
|
break; |
1213 |
|
case 'n': /* options with 1 argument */ |
1214 |
|
case 's': |
1219 |
|
if (argv[a][2] != 'v') goto userr; |
1220 |
|
break; |
1221 |
|
case 'l': /* special case */ |
1222 |
< |
if (argv[a][2] == 'd') goto userr; |
1222 |
> |
if (argv[a][2] == 'd') { |
1223 |
> |
ldopt = argv[a]; |
1224 |
> |
na = 0; |
1225 |
> |
continue; |
1226 |
> |
} |
1227 |
|
na = 2; |
1228 |
|
break; |
1229 |
|
case 'd': /* special case */ |
1254 |
|
if (sendfn[0] == '-') { /* user wants pass-through mode? */ |
1255 |
|
if (sendfn[1]) goto userr; |
1256 |
|
sendfn = NULL; |
1257 |
+ |
if (xrs) { |
1258 |
+ |
CHECKARGC(2); |
1259 |
+ |
rcarg[nrcargs++] = "-x"; |
1260 |
+ |
rcarg[nrcargs++] = xrs; |
1261 |
+ |
} |
1262 |
+ |
if (yrs) { |
1263 |
+ |
CHECKARGC(2); |
1264 |
+ |
rcarg[nrcargs++] = "-y"; |
1265 |
+ |
rcarg[nrcargs++] = yrs; |
1266 |
+ |
} |
1267 |
+ |
if (ldopt) { |
1268 |
+ |
CHECKARGC(1); |
1269 |
+ |
rcarg[nrcargs++] = ldopt; |
1270 |
+ |
} |
1271 |
|
if (sampcnt <= 0) sampcnt = 1; |
1272 |
|
} else { /* else FVECT determines input format */ |
1273 |
|
fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
1320 |
|
userr: |
1321 |
|
if (a < argc-2) |
1322 |
|
fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]); |
1323 |
< |
fprintf(stderr, "Usage: %s [rcontrib options] sender.rad receiver.rad [system.rad ..]\n", |
1323 |
> |
fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n", |
1324 |
|
progname); |
1325 |
|
return(1); |
1326 |
|
} |