| 252 |  | #define NSUNPATCH       4               /* max. # patches to spread sun into */ | 
| 253 |  | #endif | 
| 254 |  |  | 
| 255 | + | #define SUN_ANG_DEG     0.533           /* sun full-angle in degrees */ | 
| 256 | + |  | 
| 257 |  | int             nsuns = NSUNPATCH;      /* number of sun patches to use */ | 
| 258 |  | double          fixed_sun_sa = -1;      /* fixed solid angle per sun? */ | 
| 259 |  |  | 
| 283 |  |  | 
| 284 |  | extern int      rh_init(void); | 
| 285 |  | extern float *  resize_dmatrix(float *mtx_data, int nsteps, int npatch); | 
| 286 | + | extern void     OutputSun(int id, FILE *fp); | 
| 287 |  | extern void     AddDirect(float *parr); | 
| 288 |  |  | 
| 289 |  |  | 
| 383 |  | sunsfp = fopen(argv[++i], "w"); | 
| 384 |  | if (!sunsfp) { | 
| 385 |  | fprintf(stderr, "%s: cannot open '%s' for output\n", | 
| 386 | < | argv[0], argv[i]); | 
| 386 | > | progname, argv[i]); | 
| 387 |  | exit(1); | 
| 388 |  | } | 
| 386 | – | fixed_sun_sa = PI/360.*0.533; | 
| 387 | – | fixed_sun_sa *= PI*fixed_sun_sa; | 
| 389 |  | break; | 
| 390 |  | case 's':                       /* sky only (no direct) */ | 
| 391 |  | suncolor[0] = suncolor[1] = suncolor[2] = 0; | 
| 400 |  | fixed_sun_sa = PI/360.*atof(argv[++i]); | 
| 401 |  | if (fixed_sun_sa <= 0) { | 
| 402 |  | fprintf(stderr, "%s: missing solar disk size argument for '-5' option\n", | 
| 403 | < | argv[0]); | 
| 403 | > | progname); | 
| 404 |  | exit(1); | 
| 405 |  | } | 
| 406 |  | fixed_sun_sa *= fixed_sun_sa*PI; | 
| 460 |  | fprintf(stderr, "%s: location '%s'\n", progname, buf); | 
| 461 |  | fprintf(stderr, "%s: (lat,long)=(%.1f,%.1f) degrees north, west\n", | 
| 462 |  | progname, s_latitude, s_longitude); | 
| 463 | < | fprintf(stderr, "%s: %d sky patches per time step\n", | 
| 464 | < | progname, nskypatch); | 
| 463 | > | if (avgSky >= 0) | 
| 464 | > | fprintf(stderr, "%s: %d sky patches\n", | 
| 465 | > | progname, nskypatch); | 
| 466 | > | if (sunsfp) | 
| 467 | > | fprintf(stderr, "%s: outputting suns to file\n", | 
| 468 | > | progname); | 
| 469 |  | if (rotation != 0) | 
| 470 |  | fprintf(stderr, "%s: rotating output %.0f degrees\n", | 
| 471 |  | progname, rotation); | 
| 511 |  | } | 
| 512 |  | /* compute sky patch values */ | 
| 513 |  | ComputeSky(mtx_data+mtx_offset); | 
| 514 | < | /* output sun if indicated */ | 
| 515 | < | if (sunsfp && (altitude > 0) & (dir_illum > 1e-4)) { | 
| 516 | < | double  srad = dir_illum/(WHTEFFICACY * fixed_sun_sa); | 
| 517 | < | FVECT   sv; | 
| 513 | < | vector(sv, altitude, azimuth); | 
| 514 | < | fprintf(sunsfp, "\nvoid light solar%d\n0\n0\n", ntsteps); | 
| 515 | < | fprintf(sunsfp, "3 %.3e %.3e %.3e\n", srad*suncolor[0], | 
| 516 | < | srad*suncolor[1], srad*suncolor[2]); | 
| 517 | < | fprintf(sunsfp, "\nsolar%d source sun%d\n0\n0\n", ntsteps, ntsteps); | 
| 518 | < | fprintf(sunsfp, "4 %.6f %.6f %.6f 0.533\n", sv[0], sv[1], sv[2]); | 
| 519 | < | } | 
| 514 | > |  | 
| 515 | > | if (sunsfp)             /* output sun if indicated */ | 
| 516 | > | OutputSun(ntsteps, sunsfp); | 
| 517 | > |  | 
| 518 |  | if (avgSky < 0)         /* no matrix? */ | 
| 519 |  | continue; | 
| 520 |  |  | 
| 774 |  | *pdest++ += val_add*suncolor[1]; | 
| 775 |  | *pdest++ += val_add*suncolor[2]; | 
| 776 |  | } | 
| 777 | + | } | 
| 778 | + |  | 
| 779 | + | /* Output a sun to indicated file if appropriate for this time step */ | 
| 780 | + | void | 
| 781 | + | OutputSun(int id, FILE *fp) | 
| 782 | + | { | 
| 783 | + | double  srad; | 
| 784 | + | FVECT   sv; | 
| 785 | + |  | 
| 786 | + | if ((altitude <= 0) | (dir_illum <= 1e-4)) | 
| 787 | + | return; | 
| 788 | + |  | 
| 789 | + | srad = DegToRad(SUN_ANG_DEG/2.); | 
| 790 | + | srad = dir_illum/(WHTEFFICACY * PI*srad*srad); | 
| 791 | + | vector(sv, altitude, azimuth); | 
| 792 | + | fprintf(fp, "\nvoid light solar%d\n0\n0\n", id); | 
| 793 | + | fprintf(fp, "3 %.3e %.3e %.3e\n", srad*suncolor[0], | 
| 794 | + | srad*suncolor[1], srad*suncolor[2]); | 
| 795 | + | fprintf(fp, "\nsolar%d source sun%d\n0\n0\n", id, id); | 
| 796 | + | fprintf(fp, "4 %.6f %.6f %.6f %.4f\n", sv[0], sv[1], sv[2], SUN_ANG_DEG); | 
| 797 |  | } | 
| 798 |  |  | 
| 799 |  | /* Initialize Reinhart sky patch positions (GW) */ |