int main( /* convert object files to an octree */ int argc, char *argv[] ) { FVECT bbmin, bbmax; char *infile = NULL; int inpfrozen = 0; int outflags = IO_ALL; OBJECT startobj; int i; progname = argv[0] = fixargv0(argv[0]); ot_initotypes(); for (i = 1; i < argc && argv[i][0] == '-'; i++) switch (argv[i][1]) { case '\0': /* scene from stdin */ goto breakopt; case 'i': /* input octree */ infile = argv[++i]; break; case 'b': /* bounding cube */ thescene.cuorg[0] = atof(argv[++i]) - OMARGIN; thescene.cuorg[1] = atof(argv[++i]) - OMARGIN; thescene.cuorg[2] = atof(argv[++i]) - OMARGIN; thescene.cusize = atof(argv[++i]) + 2*OMARGIN; break; case 'n': /* set limit */ objlim = atoi(argv[++i]); break; case 'r': /* resolution limit */ resolu = atoi(argv[++i]); break; case 'f': /* freeze octree */ outflags &= ~IO_FILES; break; case 'w': /* supress warnings */ nowarn = 1; break; default: sprintf(errmsg, "unknown option: '%s'", argv[i]); error(USER, errmsg); break; } breakopt: SET_FILE_BINARY(stdout); if (infile != NULL) { /* get old octree & objects */ if (thescene.cusize > FTINY) error(USER, "only one of '-b' or '-i'"); nfiles = readoct(infile, IO_ALL, &thescene, ofname); if (nfiles == 0) inpfrozen++; } else newheader("RADIANCE", stdout); /* new binary file header */ printargs(argc, argv, stdout); fputformat(OCTFMT, stdout); printf("\n"); startobj = nobjects; /* previous objects already converted */ for ( ; i < argc; i++) /* read new scene descriptions */ if (!strcmp(argv[i], "-")) { /* from stdin */ readobj(NULL); outflags &= ~IO_FILES; } else { /* from file */ if (nfiles >= MAXOBJFIL) error(INTERNAL, "too many scene files"); readobj(ofname[nfiles++] = argv[i]); } ofname[nfiles] = NULL; if (inpfrozen && outflags & IO_FILES) { error(WARNING, "frozen octree"); outflags &= ~IO_FILES; } /* find bounding box */ bbmin[0] = bbmin[1] = bbmin[2] = FHUGE; bbmax[0] = bbmax[1] = bbmax[2] = -FHUGE; for (i = startobj; i < nobjects; i++) add2bbox(objptr(i), bbmin, bbmax); /* set/check cube */ if (thescene.cusize == 0.0) { if (bbmin[0] <= bbmax[0]) { for (i = 0; i < 3; i++) { bbmin[i] -= OMARGIN; bbmax[i] += OMARGIN; } for (i = 0; i < 3; i++) if (bbmax[i] - bbmin[i] > thescene.cusize) thescene.cusize = bbmax[i] - bbmin[i]; for (i = 0; i < 3; i++) thescene.cuorg[i] = (bbmax[i]+bbmin[i]-thescene.cusize)*.5; } } else { for (i = 0; i < 3; i++) if (bbmin[i] < thescene.cuorg[i] || bbmax[i] > thescene.cuorg[i] + thescene.cusize) error(USER, "boundary does not encompass scene"); } mincusize = thescene.cusize / resolu - FTINY; for (i = startobj; i < nobjects; i++) /* add new objects */ addobject(&thescene, i); thescene.cutree = combine(thescene.cutree); /* optimize */ writeoct(outflags, &thescene, ofname); /* write structures to stdout */ quit(0); return 0; /* pro forma return */ }
int main(int argc, char *argv[]) { #define check(ol,al) if (argv[i][ol] || \ badarg(argc-i-1,argv+i+1,al)) \ goto badopt #define bool(olen,var) switch (argv[i][olen]) { \ case '\0': var = !var; break; \ case 'y': case 'Y': case 't': case 'T': \ case '+': case '1': var = 1; break; \ case 'n': case 'N': case 'f': case 'F': \ case '-': case '0': var = 0; break; \ default: goto badopt; } char *curout = NULL; char *binval = NULL; int bincnt = 0; int rval; int i; /* global program name */ progname = argv[0] = fixargv0(argv[0]); gargv = argv; gargc = argc; /* initialize calcomp routines early */ initfunc(); setcontext(RCCONTEXT); /* option city */ for (i = 1; i < argc; i++) { /* expand arguments */ while ((rval = expandarg(&argc, &argv, i)) > 0) ; if (rval < 0) { sprintf(errmsg, "cannot expand '%s'", argv[i]); error(SYSTEM, errmsg); } if (argv[i] == NULL || argv[i][0] != '-') break; /* break from options */ if (!strcmp(argv[i], "-version")) { puts(VersionID); quit(0); } if (!strcmp(argv[i], "-defaults") || !strcmp(argv[i], "-help")) { override_options(); printdefaults(); quit(0); } rval = getrenderopt(argc-i, argv+i); if (rval >= 0) { i += rval; continue; } switch (argv[i][1]) { case 'n': /* number of cores */ check(2,"i"); nproc = atoi(argv[++i]); if (nproc <= 0) error(USER, "bad number of processes"); break; case 'V': /* output contributions */ bool(2,contrib); break; case 'x': /* x resolution */ check(2,"i"); xres = atoi(argv[++i]); break; case 'y': /* y resolution */ check(2,"i"); yres = atoi(argv[++i]); break; case 'w': /* warnings */ rval = (erract[WARNING].pf != NULL); bool(2,rval); if (rval) erract[WARNING].pf = wputs; else erract[WARNING].pf = NULL; break; case 'e': /* expression */ check(2,"s"); scompile(argv[++i], NULL, 0); break; case 'l': /* limit distance */ if (argv[i][2] != 'd') goto badopt; bool(3,lim_dist); break; case 'I': /* immed. irradiance */ bool(2,imm_irrad); break; case 'f': /* file or force or format */ if (!argv[i][2]) { check(2,"s"); loadfunc(argv[++i]); break; } if (argv[i][2] == 'o') { bool(3,force_open); break; } setformat(argv[i]+2); break; case 'o': /* output */ check(2,"s"); curout = argv[++i]; break; case 'c': /* input rays per output */ check(2,"i"); accumulate = atoi(argv[++i]); break; case 'r': /* recover output */ bool(2,recover); break; case 'h': /* header output */ bool(2,header); break; case 'b': /* bin expression/count */ if (argv[i][2] == 'n') { check(3,"s"); bincnt = (int)(eval(argv[++i]) + .5); break; } check(2,"s"); binval = argv[++i]; break; case 'm': /* modifier name */ check(2,"s"); addmodifier(argv[++i], curout, binval, bincnt); break; case 'M': /* modifier file */ check(2,"s"); addmodfile(argv[++i], curout, binval, bincnt); break; default: goto badopt; } } if (nmods <= 0) error(USER, "missing required modifier argument"); /* override some option settings */ override_options(); /* initialize object types */ initotypes(); /* initialize urand */ if (rand_samp) { srandom((long)time(0)); initurand(0); } else { srandom(0L); initurand(2048); } /* set up signal handling */ sigdie(SIGINT, "Interrupt"); #ifdef SIGHUP sigdie(SIGHUP, "Hangup"); #endif sigdie(SIGTERM, "Terminate"); #ifdef SIGPIPE sigdie(SIGPIPE, "Broken pipe"); #endif #ifdef SIGALRM sigdie(SIGALRM, "Alarm clock"); #endif #ifdef SIGXCPU sigdie(SIGXCPU, "CPU limit exceeded"); sigdie(SIGXFSZ, "File size exceeded"); #endif #ifdef NICE nice(NICE); /* lower priority */ #endif /* get octree */ if (i == argc) octname = NULL; else if (i == argc-1) octname = argv[i]; else goto badopt; if (octname == NULL) error(USER, "missing octree argument"); readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL); nsceneobjs = nobjects; marksources(); /* find and mark sources */ setambient(); /* initialize ambient calculation */ rcontrib(); /* trace ray contributions (loop) */ ambsync(); /* flush ambient file */ quit(0); /* exit clean */ badopt: fprintf(stderr, "Usage: %s [-n nprocs][-V][-r][-e expr][-f source][-o ospec][-b binv][-bn N] {-m mod | -M file} [rtrace options] octree\n", progname); sprintf(errmsg, "command line error at '%s'", argv[i]); error(USER, errmsg); return(1); /* pro forma return */ #undef check #undef bool }
int main (int argc, char* argv []) { #define check(ol, al) if (argv [i][ol] || \ badarg(argc - i - 1,argv + i + 1, al)) \ goto badopt #define check_bool(olen, var) switch (argv [i][olen]) { \ case '\0': var = !var; break; \ case 'y': case 'Y': case 't': case 'T': \ case '+': case '1': var = 1; break; \ case 'n': case 'N': case 'f': case 'F': \ case '-': case '0': var = 0; break; \ default: goto badopt; \ } int loadflags = IO_CHECK | IO_SCENE | IO_TREE | IO_BOUNDS, rval, i, j, n; char **portLp = photonPortList, **sensLp = photonSensorList, **amblp = NULL; struct stat pmstat; /* Global program name */ progname = fixargv0(argv [0]); /* Initialize object types */ initotypes(); /* Parse options */ for (i = 1; i < argc; i++) { /* Eggs-pand arguments */ while ((rval = expandarg(&argc, &argv, i))) if (rval < 0) { sprintf(errmsg, "cannot eggs-pand '%s'", argv [i]); error(SYSTEM, errmsg); } if (argv[i] == NULL) break; if (!strcmp(argv [i], "-version")) { puts(VersionID); quit(0); } if (!strcmp(argv [i], "-defaults") || !strcmp(argv [i], "-help")) { printdefaults(); quit(0); } /* Get octree */ if (i == argc - 1) { octname = argv [i]; break; } switch (argv [i][1]) { case 'a': /* Ambient */ switch (argv [i][2]) { case 'i': /* Ambient include */ case 'I': check(3, "s"); if (ambincl != 1) { ambincl = 1; amblp = amblist; } if (argv [i][2] == 'I') { /* Add modifiers from file */ rval = wordfile(amblp, AMBLLEN - (amblp - amblist), getpath(argv [++i], getrlibpath(), R_OK)); if (rval < 0) { sprintf(errmsg, "cannot open ambient include file \"%s\"", argv [i]); error(SYSTEM, errmsg); } amblp += rval; } else { /* Add modifier from next arg */ *amblp++ = savqstr(argv [++i]); *amblp = NULL; } break; case 'e': /* Ambient exclude */ case 'E': check(3, "s"); if (ambincl != 0) { ambincl = 0; amblp = amblist; } if (argv [i][2] == 'E') { /* Add modifiers from file */ rval = wordfile(amblp, AMBLLEN - (amblp - amblist), getpath(argv [++i], getrlibpath(), R_OK)); if (rval < 0) { sprintf(errmsg, "cannot open ambient exclude file \"%s\"", argv [i]); error(SYSTEM, errmsg); } amblp += rval; } else { /* Add modifier from next arg */ *amblp++ = savqstr(argv [++i]); *amblp = NULL; } break; case 'p': /* Pmap-specific */ switch (argv [i][3]) { case 'g': /* Global photon map */ check(4, "ss"); globalPmapParams.fileName = argv [++i]; globalPmapParams.distribTarget = parseMultiplier(argv [++i]); if (!globalPmapParams.distribTarget) goto badopt; globalPmapParams.minGather = globalPmapParams.maxGather = 0; break; case 'p': /* Precomputed global photon map */ check(4, "ssi"); preCompPmapParams.fileName = argv [++i]; preCompPmapParams.distribTarget = parseMultiplier(argv [++i]); if (!preCompPmapParams.distribTarget) goto badopt; preCompPmapParams.minGather = preCompPmapParams.maxGather = atoi(argv [++i]); if (!preCompPmapParams.maxGather) goto badopt; break; case 'c': /* Caustic photon map */ check(4, "ss"); causticPmapParams.fileName = argv [++i]; causticPmapParams.distribTarget = parseMultiplier(argv [++i]); if (!causticPmapParams.distribTarget) goto badopt; break; case 'v': /* Volume photon map */ check(4, "ss"); volumePmapParams.fileName = argv [++i]; volumePmapParams.distribTarget = parseMultiplier(argv [++i]); if (!volumePmapParams.distribTarget) goto badopt; break; case 'd': /* Direct photon map */ check(4, "ss"); directPmapParams.fileName = argv [++i]; directPmapParams.distribTarget = parseMultiplier(argv [++i]); if (!directPmapParams.distribTarget) goto badopt; break; case 'C': /* Contribution photon map */ check(4, "ss"); contribPmapParams.fileName = argv [++i]; contribPmapParams.distribTarget = parseMultiplier(argv [++i]); if (!contribPmapParams.distribTarget) goto badopt; break; case 'D': /* Predistribution factor */ check(4, "f"); preDistrib = atof(argv [++i]); if (preDistrib <= 0) error(USER, "predistrib factor must be > 0"); break; case 'M': /* Max predistribution passes */ check(4, "i"); maxPreDistrib = atoi(argv [++i]); if (maxPreDistrib <= 0) error(USER, "max predistrib passes must be > 0"); break; #if 1 /* Kept for backwards compat, to be phased out by -lr */ case 'm': /* Max photon bounces */ check(4, "i"); photonMaxBounce = atol(argv [++i]); if (photonMaxBounce <= 0) error(USER, "max photon bounces must be > 0"); break; #endif #ifdef PMAP_EKSPERTZ case 'i': /* Add region of interest */ check(4, "ffffff"); n = pmapNumROI; pmapROI = realloc(pmapROI, ++pmapNumROI * sizeof(PhotonMapROI)); if (!pmapROI) error(SYSTEM, "failed to allocate ROI"); pmapROI [n].min [0] = atof(argv [++i]); pmapROI [n].min [1] = atof(argv [++i]); pmapROI [n].min [2] = atof(argv [++i]); pmapROI [n].max [0] = atof(argv [++i]); pmapROI [n].max [1] = atof(argv [++i]); pmapROI [n].max [2] = atof(argv [++i]); for (j = 0; j < 3; j++) if (pmapROI [n].min [j] >= pmapROI [n].max [j]) error(USER, "invalid region of interest " "(swapped min/max?)"); break; #endif case 'P': /* Global photon precomp ratio */ check(4, "f"); finalGather = atof(argv [++i]); if (finalGather <= 0 || finalGather > 1) error(USER, "global photon precomputation ratio " "must be in range ]0, 1]"); break; case 'o': /* Photon port */ case 'O': check(4, "s"); if (argv [i][3] == 'O') { /* Add port modifiers from file */ rval = wordfile(portLp, MAXSET - (portLp - photonPortList), getpath(argv [++i], getrlibpath(), R_OK)); if (rval < 0) { sprintf(errmsg, "cannot open photon port file %s", argv [i]); error(SYSTEM, errmsg); } portLp += rval; } else { /* Add port modifier from next arg, mark end with * NULL */ *portLp++ = savqstr(argv [++i]); *portLp = NULL; } break; case 'r': /* Random seed */ check(4, "i"); randSeed = atoi(argv [++i]); break; case 's': /* Antimatter sensor */ case 'S': check(4, "s"); if (argv[i][3] == 'S') { /* Add sensor modifiers from file */ rval = wordfile(sensLp, MAXSET - (sensLp - photonSensorList), getpath(argv [++i], getrlibpath(), R_OK)); if (rval < 0) { sprintf(errmsg, "cannot open antimatter sensor file %s", argv [i]); error(SYSTEM, errmsg); } sensLp += rval; } else { /* Append modifier to sensor list, mark end with * NULL */ *sensLp++ = savqstr(argv [++i]); *sensLp = NULL; } break; default: goto badopt; } break; default: goto badopt; } break; case 'b': /* Back face visibility */ if (argv [i][2] == 'v') { check_bool(3, backvis); } else goto badopt; break; case 'd': /* Direct */ switch (argv [i][2]) { case 'p': /* PDF samples */ check(3, "f"); pdfSamples = atof(argv [++i]); break; case 's': /* Source partition size ratio */ check(3, "f"); srcsizerat = atof(argv [++i]); break; default: goto badopt; } break; case 'e': /* Diagnostics file */ check(2, "s"); diagFile = argv [++i]; break; case 'f': /* Force overwrite */ if (argv [i][2] == 'o') { check_bool(3, clobber); } else goto badopt; break; #ifdef PMAP_EKSPERTZ case 'l': /* Limits */ switch (argv [i][2]) { case 'd': /* Limit photon path distance */ check(3, "f"); photonMaxDist = atof(argv [++i]); if (photonMaxDist <= 0) error(USER, "max photon distance must be > 0"); break; case 'r': /* Limit photon bounces */ check(3, "i"); photonMaxBounce = atol(argv [++i]); if (photonMaxBounce <= 0) error(USER, "max photon bounces must be > 0"); break; default: goto badopt; } break; #endif case 'm': /* Medium */ switch (argv[i][2]) { case 'e': /* Eggs-tinction coefficient */ check(3, "fff"); setcolor(cextinction, atof(argv [i + 1]), atof(argv [i + 2]), atof(argv [i + 3])); i += 3; break; case 'a': /* Albedo */ check(3, "fff"); setcolor(salbedo, atof(argv [i + 1]), atof(argv [i + 2]), atof(argv [i + 3])); i += 3; break; case 'g': /* Scattering eccentricity */ check(3, "f"); seccg = atof(argv [++i]); break; default: goto badopt; } break; #if NIX case 'n': /* Num parallel processes (NIX only) */ check(2, "i"); nproc = atoi(argv [++i]); if (nproc > PMAP_MAXPROC) { nproc = PMAP_MAXPROC; sprintf(errmsg, "too many parallel processes, clamping to " "%d\n", nproc); error(WARNING, errmsg); } break; #endif case 't': /* Timer */ check(2, "i"); photonRepTime = atoi(argv [++i]); break; case 'v': /* Verbosity */ check_bool(2, verbose); break; #ifdef EVALDRC_HACK case 'A': /* Angular source file */ check(2,"s"); angsrcfile = argv[++i]; break; #endif default: goto badopt; } } /* Open diagnostics file */ if (diagFile) { if (!freopen(diagFile, "a", stderr)) quit(2); fprintf(stderr, "**************\n*** PID %5d: ", getpid()); printargs(argc, argv, stderr); putc('\n', stderr); fflush(stderr); } #ifdef NICE /* Lower priority */ nice(NICE); #endif if (octname == NULL) error(USER, "missing octree argument"); /* Allocate photon maps and set parameters */ for (i = 0; i < NUM_PMAP_TYPES; i++) { setPmapParam(photonMaps + i, pmapParams + i); /* Don't overwrite existing photon map unless clobbering enabled */ if (photonMaps [i] && !stat(photonMaps [i] -> fileName, &pmstat) && !clobber) { sprintf(errmsg, "photon map file %s exists, not overwritten", photonMaps [i] -> fileName); error(USER, errmsg); } } for (i = 0; i < NUM_PMAP_TYPES && !photonMaps [i]; i++); if (i >= NUM_PMAP_TYPES) error(USER, "no photon maps specified"); readoct(octname, loadflags, &thescene, NULL); #ifdef EVALDRC_HACK if (angsrcfile) readobj(angsrcfile); /* load angular sources */ #endif nsceneobjs = nobjects; /* Get sources */ marksources(); /* Do forward pass and build photon maps */ if (contribPmap) /* Just build contrib pmap, ignore others */ distribPhotonContrib(contribPmap, nproc); else distribPhotons(photonMaps, nproc); /* Save photon maps; no idea why GCC needs an explicit cast here... */ savePmaps((const PhotonMap**)photonMaps, argc, argv); cleanUpPmaps(photonMaps); quit(0); badopt: sprintf(errmsg, "command line error at '%s'", argv[i]); error(USER, errmsg); #undef check #undef check_bool return 0; }
int main(int argc, char *argv[]) { #define check(ol,al) if (argv[i][ol] || \ badarg(argc-i-1,argv+i+1,al)) \ goto badopt #define bool(olen,var) switch (argv[i][olen]) { \ case '\0': var = !var; break; \ case 'y': case 'Y': case 't': case 'T': \ case '+': case '1': var = 1; break; \ case 'n': case 'N': case 'f': case 'F': \ case '-': case '0': var = 0; break; \ default: goto badopt; } char *err; char *recover = NULL; char *outfile = NULL; char *zfile = NULL; int loadflags = ~IO_FILES; int seqstart = 0; int persist = 0; int duped1 = -1; int rval; int i; /* record start time */ tstart = time((time_t *)NULL); /* global program name */ progname = argv[0] = fixargv0(argv[0]); /* option city */ for (i = 1; i < argc; i++) { /* expand arguments */ while ((rval = expandarg(&argc, &argv, i)) > 0) ; if (rval < 0) { sprintf(errmsg, "cannot expand '%s'", argv[i]); error(SYSTEM, errmsg); } if (argv[i] == NULL || argv[i][0] != '-') break; /* break from options */ if (!strcmp(argv[i], "-version")) { puts(VersionID); quit(0); } if (!strcmp(argv[i], "-defaults") || !strcmp(argv[i], "-help")) { printdefaults(); quit(0); } rval = getrenderopt(argc-i, argv+i); if (rval >= 0) { i += rval; continue; } rval = getviewopt(&ourview, argc-i, argv+i); if (rval >= 0) { i += rval; continue; } /* rpict options */ switch (argv[i][1]) { case 'v': /* view file */ if (argv[i][2] != 'f') goto badopt; check(3,"s"); rval = viewfile(argv[++i], &ourview, NULL); if (rval < 0) { sprintf(errmsg, "cannot open view file \"%s\"", argv[i]); error(SYSTEM, errmsg); } else if (rval == 0) { sprintf(errmsg, "bad view file \"%s\"", argv[i]); error(USER, errmsg); } break; case 'p': /* pixel */ switch (argv[i][2]) { case 's': /* sample */ check(3,"i"); psample = atoi(argv[++i]); break; case 't': /* threshold */ check(3,"f"); maxdiff = atof(argv[++i]); break; case 'j': /* jitter */ check(3,"f"); dstrpix = atof(argv[++i]); break; case 'a': /* aspect */ check(3,"f"); pixaspect = atof(argv[++i]); break; case 'm': /* motion */ check(3,"f"); mblur = atof(argv[++i]); break; case 'd': /* aperture */ check(3,"f"); dblur = atof(argv[++i]); break; default: goto badopt; } break; case 'x': /* x resolution */ check(2,"i"); hresolu = atoi(argv[++i]); break; case 'y': /* y resolution */ check(2,"i"); vresolu = atoi(argv[++i]); break; case 'S': /* slave index */ check(2,"i"); seqstart = atoi(argv[++i]); break; case 'o': /* output file */ check(2,"s"); outfile = argv[++i]; break; case 'z': /* z file */ check(2,"s"); zfile = argv[++i]; break; case 'r': /* recover file */ if (argv[i][2] == 'o') { /* +output */ check(3,"s"); outfile = argv[i+1]; } else check(2,"s"); recover = argv[++i]; break; case 't': /* timer */ check(2,"i"); ralrm = atoi(argv[++i]); break; #ifdef PERSIST case 'P': /* persist file */ if (argv[i][2] == 'P') { check(3,"s"); persist = PARALLEL; } else { check(2,"s"); persist = PERSIST; } persistfile(argv[++i]); break; #endif case 'w': /* warnings */ rval = erract[WARNING].pf != NULL; bool(2,rval); if (rval) erract[WARNING].pf = wputs; else erract[WARNING].pf = NULL; break; case 'e': /* error file */ check(2,"s"); errfile = argv[++i]; break; default: goto badopt; } } err = setview(&ourview); /* set viewing parameters */ if (err != NULL) error(USER, err); /* initialize object types */ initotypes(); /* initialize urand */ if (rand_samp) { srandom((long)time(0)); initurand(0); } else { srandom(0L); initurand(2048); } /* set up signal handling */ sigdie(SIGINT, "Interrupt"); #ifdef SIGHUP sigdie(SIGHUP, "Hangup"); #endif sigdie(SIGTERM, "Terminate"); #ifdef SIGPIPE sigdie(SIGPIPE, "Broken pipe"); #endif #ifdef SIGALRM sigdie(SIGALRM, "Alarm clock"); #endif #ifdef SIGXCPU sigdie(SIGXCPU, "CPU limit exceeded"); sigdie(SIGXFSZ, "File size exceeded"); #endif /* open error file */ if (errfile != NULL) { if (freopen(errfile, "a", stderr) == NULL) quit(2); fprintf(stderr, "**************\n*** PID %5d: ", getpid()); printargs(argc, argv, stderr); putc('\n', stderr); fflush(stderr); } #ifdef NICE nice(NICE); /* lower priority */ #endif /* get octree */ if (i == argc) octname = NULL; else if (i == argc-1) octname = argv[i]; else goto badopt; if (seqstart > 0 && octname == NULL) error(USER, "missing octree argument"); /* set up output */ #ifdef PERSIST if (persist) { if (recover != NULL) error(USER, "persist option used with recover file"); if (seqstart <= 0) error(USER, "persist option only for sequences"); if (outfile == NULL) duped1 = dup(fileno(stdout)); /* don't lose our output */ openheader(); } else #endif if (outfile != NULL) openheader(); #ifdef _WIN32 SET_FILE_BINARY(stdout); if (octname == NULL) SET_FILE_BINARY(stdin); #endif readoct(octname, loadflags, &thescene, NULL); nsceneobjs = nobjects; if (loadflags & IO_INFO) { /* print header */ printargs(i, argv, stdout); printf("SOFTWARE= %s\n", VersionID); } marksources(); /* find and mark sources */ setambient(); /* initialize ambient calculation */ #ifdef PERSIST if (persist) { fflush(stdout); if (outfile == NULL) { /* reconnect stdout */ dup2(duped1, fileno(stdout)); close(duped1); } if (persist == PARALLEL) { /* multiprocessing */ preload_objs(); /* preload scene */ shm_boundary = (char *)malloc(16); strcpy(shm_boundary, "SHM_BOUNDARY"); while ((rval=fork()) == 0) { /* keep on forkin' */ pflock(1); pfhold(); tstart = time((time_t *)NULL); ambsync(); /* load new values */ } if (rval < 0) error(SYSTEM, "cannot fork child for persist function"); pfdetach(); /* parent will run then exit */ } } runagain: if (persist) { if (outfile == NULL) /* if out to stdout */ dupheader(); /* send header */ else /* if out to file */ duped1 = dup(fileno(stdout)); /* hang onto pipe */ } #endif /* batch render picture(s) */ rpict(seqstart, outfile, zfile, recover); /* flush ambient file */ ambsync(); #ifdef PERSIST if (persist == PERSIST) { /* first run-through */ if ((rval=fork()) == 0) { /* child loops until killed */ pflock(1); persist = PCHILD; } else { /* original process exits */ if (rval < 0) error(SYSTEM, "cannot fork child for persist function"); pfdetach(); /* parent exits */ } } if (persist == PCHILD) { /* wait for a signal then go again */ if (outfile != NULL) close(duped1); /* release output handle */ pfhold(); tstart = time((time_t *)NULL); /* reinitialize */ raynum = nrays = 0; goto runagain; } #endif quit(0); badopt: sprintf(errmsg, "command line error at '%s'", argv[i]); error(USER, errmsg); return 1; /* pro forma return */ #undef check #undef bool }
int main(int argc, char *argv[]) { #define check(ol,al) if (argv[i][ol] || \ badarg(argc-i-1,argv+i+1,al)) \ goto badopt #define check_bool(olen,var) switch (argv[i][olen]) { \ case '\0': var = !var; break; \ case 'y': case 'Y': case 't': case 'T': \ case '+': case '1': var = 1; break; \ case 'n': case 'N': case 'f': case 'F': \ case '-': case '0': var = 0; break; \ default: goto badopt; } char *octnm = NULL; char *err; int rval; int i; /* global program name */ progname = argv[0] = fixargv0(argv[0]); /* set our defaults */ shadthresh = .1; shadcert = .25; directrelay = 0; vspretest = 128; srcsizerat = 0.; specthresh = .3; specjitter = 1.; maxdepth = 6; minweight = 1e-2; ambacc = 0.3; ambres = 32; ambdiv = 256; ambssamp = 64; /* option city */ for (i = 1; i < argc; i++) { /* expand arguments */ while ((rval = expandarg(&argc, &argv, i)) > 0) ; if (rval < 0) { sprintf(errmsg, "cannot expand '%s'", argv[i]); error(SYSTEM, errmsg); } if (argv[i] == NULL || argv[i][0] != '-') break; /* break from options */ if (!strcmp(argv[i], "-version")) { puts(VersionID); quit(0); } if (!strcmp(argv[i], "-defaults") || !strcmp(argv[i], "-help")) { printdefaults(); quit(0); } if (!strcmp(argv[i], "-devices")) { printdevices(); quit(0); } rval = getrenderopt(argc-i, argv+i); if (rval >= 0) { i += rval; continue; } rval = getviewopt(&ourview, argc-i, argv+i); if (rval >= 0) { i += rval; continue; } switch (argv[i][1]) { case 'n': /* # processes */ check(2,"i"); nproc = atoi(argv[++i]); if (nproc <= 0) error(USER, "bad number of processes"); break; case 'v': /* view file */ if (argv[i][2] != 'f') goto badopt; check(3,"s"); rval = viewfile(argv[++i], &ourview, NULL); if (rval < 0) { sprintf(errmsg, "cannot open view file \"%s\"", argv[i]); error(SYSTEM, errmsg); } else if (rval == 0) { sprintf(errmsg, "bad view file \"%s\"", argv[i]); error(USER, errmsg); } break; case 'b': /* grayscale */ check_bool(2,greyscale); break; case 'p': /* pixel */ switch (argv[i][2]) { case 's': /* sample */ check(3,"i"); psample = atoi(argv[++i]); break; case 't': /* threshold */ check(3,"f"); maxdiff = atof(argv[++i]); break; case 'e': /* exposure */ check(3,"f"); exposure = atof(argv[++i]); if (argv[i][0] == '+' || argv[i][0] == '-') exposure = pow(2.0, exposure); break; default: goto badopt; } break; case 'w': /* warnings */ rval = erract[WARNING].pf != NULL; check_bool(2,rval); if (rval) erract[WARNING].pf = wputs; else erract[WARNING].pf = NULL; break; case 'e': /* error file */ check(2,"s"); errfile = argv[++i]; break; case 'o': /* output device */ check(2,"s"); dvcname = argv[++i]; break; case 'R': /* render input file */ check(2,"s"); strcpy(rifname, argv[++i]); break; default: goto badopt; } } err = setview(&ourview); /* set viewing parameters */ if (err != NULL) error(USER, err); /* set up signal handling */ sigdie(SIGINT, "Interrupt"); sigdie(SIGTERM, "Terminate"); #if !defined(_WIN32) && !defined(_WIN64) sigdie(SIGHUP, "Hangup"); sigdie(SIGPIPE, "Broken pipe"); sigdie(SIGALRM, "Alarm clock"); #endif /* open error file */ if (errfile != NULL) { if (freopen(errfile, "a", stderr) == NULL) quit(2); fprintf(stderr, "**************\n*** PID %5d: ", getpid()); printargs(argc, argv, stderr); putc('\n', stderr); fflush(stderr); } #ifdef NICE nice(NICE); /* lower priority */ #endif /* get octree */ if (i == argc) octnm = NULL; else if (i == argc-1) octnm = argv[i]; else goto badopt; if (octnm == NULL) error(USER, "missing octree argument"); /* set up output & start process(es) */ SET_FILE_BINARY(stdout); ray_init(octnm); /* also calls ray_init_pmap() */ /* temporary shortcut, until winrview is refactored into a "device" */ #ifndef WIN_RVIEW rview(); /* run interactive viewer */ devclose(); /* close output device */ #endif /* PMAP: free photon maps */ ray_done_pmap(); #ifdef WIN_RVIEW return 1; #endif quit(0); badopt: sprintf(errmsg, "command line error at '%s'", argv[i]); error(USER, errmsg); return 1; /* pro forma return */ #undef check #undef check_bool }
int main(int argc, char *argv[]) { int i, j, k; int nh=0; /* counter for the total number of hours */ int nhd=0; /* counter for the number of hours of the actual day */ int month=0, day=0, jday=0, jday_hoy=0, last_day=0, last_month=0, last_jday=0; int status=6; /* indicates EOF of the input weather data file */ int fatal=0; /* indicates soon exit due to fatal error */ int azimuth_class=0; int *daylight_status; /* 0=night hour, 1=sunrise/sunset hour, 2=innerday hour */ double time, centrum_time, *times; double irrad_glo = 0.0, irrad_beam_nor, irrad_beam_hor, irrad_dif; /* in W/m² */ double *irrads_glo, *irrads_beam_nor, *irrads_dif, *indices_glo, *indices_beam, sr_ss_indices_glo[3]; double *irrads_glo_st, *irrads_glo_clear_st, *irrads_beam_nor_st, *irrads_dif_st, *indices_glo_st; double time_t, time_k, mean_glo_st, mean_beam_st, mean_dif_st, sum_beam_nor, sum_beam_hor, sum_dif; double sunrise_localtime, sunset_localtime; double solar_elevation, solar_azimuth, eccentricity_correction; double punk; /* indicates nice sound */ double previous_ligoh = 0, actual_ligoh; /* ligoh = last index_glo of an hour: introduced to minimize discontinuities between subsequent hours */ if (argc == 1) { char *progname = fixargv0(argv[0]); fprintf(stdout, "%s: fatal error - header file missing\n", progname); fprintf(stdout, "start program with: %s <header file>\n ", progname); exit(1); } if (!strcmp(argv[1], "-version")) { puts(VersionID); exit(0); } header=argv[1]; read_in_genshortterm_header(); /*printf("input_weather_data=%s\n",input_weather_data); printf("input_weather_data_shortterm=%s\n",input_weather_data_shortterm); printf("shortterm_timestep=%d\n",shortterm_timestep); printf("input_units_genshortterm=%d\n",input_units_genshortterm); printf("output_units_genshortterm=%d\n",output_units_genshortterm); printf("solar_time=%d\n",solar_time); printf("latitude=%f \nlongitude=%f \ntime_zone=%f\n",latitude,longitude,time_zone); printf("site_elevation=%f\n",site_elevation); printf("horizon_in=%d horizon_data_in=%s\n",horizon_in,horizon_data_in); printf("horizon_out=%d horizon_data_out=%s\n",horizon_out,horizon_data_out); printf("linke_estimation=%d\n",linke_estimation);*/ HOURLY_DATA = open_input(input_weather_data); /* added by C. Reinhart */ /* test whether input file has a header */ /* in case the is a header, it is skipped */ fscanf(HOURLY_DATA,"%s", keyword); if( !strcmp(keyword,"place") ){ rewind(HOURLY_DATA); fgets(header_line_1,300,HOURLY_DATA); fgets(header_line_2,300,HOURLY_DATA); fgets(header_line_3,300,HOURLY_DATA); fgets(header_line_4,300,HOURLY_DATA); fgets(header_line_5,300,HOURLY_DATA); fgets(header_line_6,300,HOURLY_DATA); // get time step of input file fscanf(HOURLY_DATA,"%d %d %lf", &month, &day, ¢rum_time);fscanf(HOURLY_DATA,"%*[^\n]");fscanf(HOURLY_DATA,"%*[\n\r]"); fscanf(HOURLY_DATA,"%d %d %lf", &month, &day, &time);fscanf(HOURLY_DATA,"%*[^\n]");fscanf(HOURLY_DATA,"%*[\n\r]"); test_input_time_step=(int)(60.0*fabs(time-centrum_time)); //printf("The time step of the input file (%s) is %d minutes\n",input_weather_data, test_input_time_step); if(test_input_time_step != shortterm_timestep && test_input_time_step != 60 ){ printf("wea_data_file does not have a 60 minute time step interval! %d\n",test_input_time_step); } rewind(HOURLY_DATA); fgets(header_line_1,300,HOURLY_DATA); fgets(header_line_2,300,HOURLY_DATA); fgets(header_line_3,300,HOURLY_DATA); fgets(header_line_4,300,HOURLY_DATA); fgets(header_line_5,300,HOURLY_DATA); fgets(header_line_6,300,HOURLY_DATA); }else{ // input file has no header rewind(HOURLY_DATA); // get time step of input file fscanf(HOURLY_DATA,"%d %d %lf", &month, &day, ¢rum_time);fscanf(HOURLY_DATA,"%*[^\n]");fscanf(HOURLY_DATA,"%*[\n\r]"); fscanf(HOURLY_DATA,"%d %d %lf", &month, &day, &time);fscanf(HOURLY_DATA,"%*[^\n]");fscanf(HOURLY_DATA,"%*[\n\r]"); test_input_time_step=(int)(60.0*fabs(time-centrum_time)); fprintf(stderr,"The time step of the inpt file (%s) is %d minutes\n",input_weather_data, test_input_time_step); if(test_input_time_step != shortterm_timestep && test_input_time_step != 60 ){ fprintf(stderr,"wea_data_file does not have a 60 minute time step interval! %d\n",test_input_time_step); } rewind(HOURLY_DATA); sprintf(header_line_1,"place %s\n",input_weather_data); sprintf(header_line_2,"latitude %f\n",latitude); sprintf(header_line_3,"longitude %f\n",longitude); sprintf(header_line_4,"time_zone %f\n",time_zone); sprintf(header_line_5,"site_elevation %f\n",site_elevation); sprintf(header_line_6,"weather_data_file_units %d\n",output_units_genshortterm); } SHORT_TERM_DATA = open_output(input_weather_data_shortterm); //print file header fprintf(SHORT_TERM_DATA,"%s", header_line_1); fprintf(SHORT_TERM_DATA,"%s", header_line_2); fprintf(SHORT_TERM_DATA,"%s", header_line_3); fprintf(SHORT_TERM_DATA,"%s", header_line_4); fprintf(SHORT_TERM_DATA,"%s", header_line_5); fprintf(SHORT_TERM_DATA,"%s", header_line_6); if ((times = malloc(24 * sizeof(double))) == NULL) goto memerr; if ((irrads_glo = malloc(24 * sizeof(double))) == NULL) goto memerr; if ((irrads_beam_nor = malloc(24 * sizeof(double))) == NULL) goto memerr; if ((irrads_dif = malloc(24 * sizeof(double))) == NULL) goto memerr; if ((indices_glo = malloc(24 * sizeof(double))) == NULL) goto memerr; if ((indices_beam = malloc(24 * sizeof(double))) == NULL) goto memerr; if ((daylight_status = malloc(24 * sizeof(int))) == NULL) goto memerr; if ((irrads_glo_st = malloc(sph*sizeof(double))) == NULL) goto memerr; if ((irrads_glo_clear_st = malloc(sph*sizeof(double))) == NULL) goto memerr; if ((irrads_beam_nor_st = malloc(sph*sizeof(double))) == NULL) goto memerr; if ((irrads_dif_st = malloc(sph*sizeof(double))) == NULL) goto memerr; if ((indices_glo_st = malloc(sph*sizeof(double))) == NULL) goto memerr; if ( shortterm_timestep == test_input_time_step ) /* no generation of shortterm data, but conversion of direct-hor to direct-norm irradiance */ { //fprintf(stderr,"ds_shortterm: message: input time step equals output time step.\n"); while ( status > 0 ) /* as long as EOF is not reached */ { if ( input_units_genshortterm == 1 ) { status = fscanf(HOURLY_DATA,"%d %d %lf %lf %lf", &month, &day, &time, &irrad_beam_nor, &irrad_dif); if(irrad_beam_nor<0|| irrad_dif<0) { status=-1; printf("FATAL ERROR: Negative direct or diffuse irradiance at month: %d, day: %d, time %.1f\n",month,day,time); printf("Generating cliamte file stopped.\n"); } } if ( input_units_genshortterm == 2 ) { status = fscanf(HOURLY_DATA,"%d %d %lf %lf %lf", &month, &day, &time, &irrad_beam_hor, &irrad_dif); if(irrad_beam_hor<0|| irrad_dif<0) { status=-1; printf("FATAL ERROR: Negative direct or diffuse irradiance at month: %d, day: %d, time %.1f\n",month,day,time); printf("Generating cliamte file stopped.\n"); } } if ( status <= 0 ) goto end; if ( input_units_genshortterm == 2 ) /* calculate irrad_beam_nor */ { if ( irrad_beam_hor > 0 ) { jday = jdate(month, day); sunrise_sunset_localtime ( latitude, longitude, time_zone, jday, &sunrise_localtime, &sunset_localtime ); centrum_time=time; if ( fabs(time-sunrise_localtime) <= 0.5 ) centrum_time=sunrise_localtime+(time+0.5-sunrise_localtime)/2.0; if ( fabs(time-sunset_localtime) <= 0.5 ) centrum_time=time-0.5+(sunset_localtime-(time-0.5))/2.0; solar_elev_azi_ecc ( latitude, longitude, time_zone, jday, centrum_time, solar_time, &solar_elevation, &solar_azimuth, &eccentricity_correction); irrad_beam_nor = irrad_beam_hor / sin(radians(solar_elevation)); if ( irrad_beam_nor < 0 ) irrad_beam_nor=0; } else irrad_beam_nor=0; } //} fprintf(SHORT_TERM_DATA,"%d %d %.3f %.0f %.0f\n", month, day, time, irrad_beam_nor, irrad_dif); } } else /* generation of 1-min short-term data according to modified Skartveit & Olseth */ { /* by Oliver Walkenhorst, November 2000 */ if ( test_input_time_step < 60 )create60minTempFile(); if ( horizon_in ) { printf("reads in input horizon data ... \n"); read_horizon_azimuth_data ( horizon_data_in, &horizon_azimuth_in[0] ); } else for ( i=0 ; i<36 ; i++ ) horizon_azimuth_in[i]=0; if ( horizon_out ) { printf("reads in output horizon data ... \n"); read_horizon_azimuth_data ( horizon_data_out, &horizon_azimuth_out[0] ); } else for ( i=0 ; i<36 ; i++ ) horizon_azimuth_out[i]=0; if ( linke_estimation ) { //printf("\nEstimating monthly Linke Turbidities from hourly direct irradiances ... "); estimate_linke_factor_from_hourly_direct_irradiances(); //for (i=0;i<12;i++) printf("%.1f ",linke_turbidity_factor_am2[i]); //printf(" "); } rewind(HOURLY_DATA); /* added by C. Reinhart */ /* test whether input file has a header */ /* in case the is a header, it is skipped */ fscanf(HOURLY_DATA,"%s", keyword); if( !strcmp(keyword,"place") ) { fscanf(HOURLY_DATA,"%*[^\n]");fscanf(HOURLY_DATA,"%*[\n\r]"); fscanf(HOURLY_DATA,"%*[^\n]");fscanf(HOURLY_DATA,"%*[\n\r]"); fscanf(HOURLY_DATA,"%*[^\n]");fscanf(HOURLY_DATA,"%*[\n\r]"); fscanf(HOURLY_DATA,"%*[^\n]");fscanf(HOURLY_DATA,"%*[\n\r]"); fscanf(HOURLY_DATA,"%*[^\n]");fscanf(HOURLY_DATA,"%*[\n\r]"); fscanf(HOURLY_DATA,"%*[^\n]");fscanf(HOURLY_DATA,"%*[\n\r]"); }else{ rewind(HOURLY_DATA); } while ( status > 0 ) /* read data from the input weather file as long as EOF is not reached */ { if ( input_units_genshortterm == 1 ) status = fscanf(HOURLY_DATA,"%d %d %lf %lf %lf", &month, &day, &time, &irrad_beam_nor, &irrad_dif); if ( input_units_genshortterm == 2 ) status = fscanf(HOURLY_DATA,"%d %d %lf %lf %lf", &month, &day, &time, &irrad_beam_hor, &irrad_dif); if ( status <= 0 ) goto process_last_day; nh++; jday = jdate(month, day); if ( input_units_genshortterm == 1 ) /* calculation of the global irradiance for the actual hour */ { if ( irrad_beam_nor > 0 ) { sunrise_sunset_localtime ( latitude, longitude, time_zone, jday, &sunrise_localtime, &sunset_localtime ); centrum_time=time; if ( fabs(time-sunrise_localtime) <= 0.5 ) centrum_time=sunrise_localtime+(time+0.5-sunrise_localtime)/2.0; if ( fabs(time-sunset_localtime) <= 0.5 ) centrum_time=time-0.5+(sunset_localtime-(time-0.5))/2.0; solar_elev_azi_ecc ( latitude, longitude, time_zone, jday, centrum_time, solar_time, &solar_elevation, &solar_azimuth, &eccentricity_correction); irrad_beam_hor = irrad_beam_nor * sin(radians(solar_elevation)); if ( irrad_beam_hor < 0 ) irrad_beam_hor=0; } else irrad_beam_hor=0; irrad_glo=irrad_beam_hor+irrad_dif; } if ( input_units_genshortterm == 2 ) /* calculation of the global irradiance for the actual hour */ { if ( irrad_beam_hor > 0 ) { sunrise_sunset_localtime ( latitude, longitude, time_zone, jday, &sunrise_localtime, &sunset_localtime ); centrum_time=time; if ( fabs(time-sunrise_localtime) <= 0.5 ) centrum_time=sunrise_localtime+(time+0.5-sunrise_localtime)/2.0; if ( fabs(time-sunset_localtime) <= 0.5 ) centrum_time=time-0.5+(sunset_localtime-(time-0.5))/2.0; solar_elev_azi_ecc ( latitude, longitude, time_zone, jday, centrum_time, solar_time, &solar_elevation, &solar_azimuth, &eccentricity_correction); irrad_beam_nor = irrad_beam_hor / sin(radians(solar_elevation)); if ( irrad_beam_nor < 0 ) irrad_beam_nor=0; } else irrad_beam_nor=0; irrad_glo=irrad_beam_hor+irrad_dif; } /* check irradiances and correct numbers if necessary */ if ( irrad_glo < 0 ) { sprintf(errmsg, "irrad_glo=%f at month: %d day: %d time: %.3f has been replaced with 0", irrad_glo, month, day, time); error(WARNING, errmsg); irrad_glo=0.0; } if (irrad_glo > SOLAR_CONSTANT_E) { sprintf(errmsg, "irrad_glo=%f at month: %d day: %d time: %.3f has been replaced with %f\n", irrad_glo, month, day, time, SOLAR_CONSTANT_E); error(WARNING, errmsg); irrad_glo = SOLAR_CONSTANT_E; } if ( irrad_beam_nor < 0 ) { sprintf(errmsg, "irrad_beam_nor=%e at month: %d day: %d time: %.3f has been replaced with %f\n", irrad_beam_nor, month, day, time, 0.0); error(WARNING, errmsg); irrad_beam_nor = 0.0; } if (irrad_beam_nor > SOLAR_CONSTANT_E) { sprintf(errmsg, "irrad_beam_nor=%f at month: %d day: %d time: %.3f has been replaced with %f\n", irrad_beam_nor, month, day, time, SOLAR_CONSTANT_E); error(WARNING, errmsg); irrad_beam_nor = SOLAR_CONSTANT_E; } if ( irrad_dif < 0 ) { sprintf(errmsg, "irrad_dif=%f at month: %d day: %d time: %.3f has been replaced with %f\n", irrad_beam_nor, month, day, time, 0.0); error(WARNING, errmsg); irrad_dif = 0.0; } if (irrad_dif > SOLAR_CONSTANT_E) { sprintf(errmsg, "irrad_dif=%f at month: %d day: %d time: %.3f has been replaced with %f\n", irrad_beam_nor, month, day, time, SOLAR_CONSTANT_E); error(WARNING, errmsg); irrad_dif = SOLAR_CONSTANT_E; } if ( fatal == 1 ) exit(1); if ( last_jday == jday || nh == 1 ) /* store the hourly irradiances of the actual day */ { times[nhd]=time; irrads_glo[nhd] = irrad_glo; irrads_beam_nor[nhd] = irrad_beam_nor; irrads_dif[nhd] = irrad_dif; nhd++; } else { process_last_day: /* process the last day */ { for ( i=0 ; i<nhd ; i++ ) /* determine the daylight status of each hour */ { if ( i == 0 || i == nhd-1 ) { if ( irrads_glo[i] < 0.001 ) daylight_status[i]=0; if ( irrads_glo[i] >= 0.001 ) daylight_status[i]=1; } if ( i > 0 && i<nhd-1 ) { if ( irrads_glo[i-1] < 0.001 && irrads_glo[i] < 0.001 ) daylight_status[i]=0; if ( irrads_glo[i] < 0.001 && irrads_glo[i+1] < 0.001 ) daylight_status[i]=0; if ( irrads_glo[i-1] >= 0.001 && irrads_glo[i] < 0.001 && irrads_glo[i+1] >= 0.001 ) { irrads_glo[i]=0.5*(irrads_glo[i-1]+irrads_glo[i+1]); sprintf(errmsg, "at %d %d %.3f global irradiance = 0 in between two hours with\n non-vanishing global irradiance: check your data and try again", last_month, last_day, times[i]); error(WARNING, errmsg); } if ( irrads_glo[i-1] < 0.001 && irrads_glo[i] >= 0.001 && irrads_glo[i+1] < 0.001 ) { irrads_glo[i]=0.5*(irrads_glo[i-1]+irrads_glo[i+1]); sprintf(errmsg, "month=%d day=%d contains only one hour with non-vanishing global irradiance: remove this day from your input data file and try again", last_month, last_day); error(WARNING, errmsg); } if ( irrads_glo[i-1] < 0.001 && irrads_glo[i] >= 0.001 && irrads_glo[i+1] >= 0.001 ) daylight_status[i]=1; if ( irrads_glo[i-1] >= 0.001 && irrads_glo[i] >= 0.001 && irrads_glo[i+1] < 0.001 ) daylight_status[i]=1; if ( irrads_glo[i-1] >= 0.001 && irrads_glo[i] >= 0.001 && irrads_glo[i+1] >= 0.001 ) daylight_status[i]=2; } if ( daylight_status[i] > 0 ) /* calculate the clearness indices */ { glo_and_beam_indices_hour ( latitude, longitude, time_zone, last_jday, times[i], solar_time, irrads_glo[i], irrads_beam_nor[i], &indices_glo[i], &indices_beam[i] ); if ( i < nhd-1 && times[i+1]-times[i] > 1.5 ) { sprintf(errmsg, "at %d %d %.3f the time difference to the subsequent hour is greater than 1.5: check your data and try again (innerday time differences should equal 1)", last_month, last_day, times[i]); error(USER, errmsg); } } } for ( i=0 ; i<nhd ; i++ ) /* process each hour */ { if ( daylight_status[i] == 0 ) /* print zeros for hours without global irradiance */ { for ( j=1 ; j<=(60/shortterm_timestep) ; j++ ) { time_t = times[i] - 0.5 + ( j - 0.5 ) / (60/shortterm_timestep); if ( output_units_genshortterm == 1 ) fprintf ( SHORT_TERM_DATA,"%d %d %.3f %.0f %.0f\n", last_month, last_day, time_t, 0.0, 0.0 ); if ( output_units_genshortterm == 2 ) { jday_hoy = jdate(last_month, last_day); solar_elev_azi_ecc (latitude, longitude, time_zone, jday_hoy, time_t, solar_time, &solar_elevation, &solar_azimuth, &eccentricity_correction); fprintf ( SHORT_TERM_DATA,"%d %d %.3f %.0f %.0f\n", last_month, last_day, time_t, 0.0, 0.0 ); } } } else /* generate short-term irradiances for daylight hours */ { irrads_clear_st ( latitude, longitude, time_zone, last_jday, times[i], solar_time, sph, irrads_glo_clear_st); if ( daylight_status[i] == 1 && times[i] < 12 ) /* sunrise hour */ { sr_ss_indices_glo[0] = indices_glo[i+1]; sr_ss_indices_glo[1] = indices_glo[i]; sr_ss_indices_glo[2] = indices_glo[i+1]; skartveit ( sr_ss_indices_glo, indices_beam[i], sph, previous_ligoh, indices_glo_st, &actual_ligoh ); } if ( daylight_status[i] == 1 && times[i] >= 12 ) /* sunset hour */ { sr_ss_indices_glo[0] = indices_glo[i-1]; sr_ss_indices_glo[1] = indices_glo[i]; sr_ss_indices_glo[2] = indices_glo[i-1]; skartveit ( sr_ss_indices_glo, indices_beam[i], sph, previous_ligoh, indices_glo_st, &actual_ligoh ); } if ( daylight_status[i] == 2 ) /* innerday hours */ { if ( irrads_glo[i] <= 0.001 ) { irrads_glo[i]=0.5*(irrads_glo[i-1]+irrads_glo[i+1]); sprintf(errmsg, "at month=%d day=%d time=%.3f should be non-vanishing global irradiance: check your input file and try again", last_month, last_day, times[i]); error(USER, errmsg); } else skartveit ( &indices_glo[i-1], indices_beam[i], sph, previous_ligoh, indices_glo_st, &actual_ligoh ); } previous_ligoh = actual_ligoh; for ( j=1 ; j<=sph ; j++ ) irrads_glo_st[j-1] = indices_glo_st[j-1] * irrads_glo_clear_st[j-1]; mean_glo_st = mean ( sph, &irrads_glo_st[0] ); if ( mean_glo_st > 0 ) /* global renormalization to the given hourly mean value */ for ( j=1 ; j<=sph ; j++ ) irrads_glo_st[j-1] = irrads_glo[i] / mean_glo_st * irrads_glo_st[j-1]; for (j = 1; j <= sph; j++) if (irrads_glo_st[j - 1] > SOLAR_CONSTANT_E) irrads_glo_st[j - 1] = SOLAR_CONSTANT_E; for ( j=1 ; j<=sph ; j++ ) /* Reindl diffuse fraction estimation */ { solar_elev_azi_ecc (latitude, longitude, time_zone, last_jday, times[i]-0.5+(j-0.5)/sph, solar_time, &solar_elevation, &solar_azimuth, &eccentricity_correction); irrads_dif_st[j-1]= diffuse_fraction(irrads_glo_st[j-1],solar_elevation,eccentricity_correction)*irrads_glo_st[j-1]; if ( solar_azimuth < 0 ) azimuth_class = ((int)solar_azimuth)/10 + 17; else azimuth_class = ((int)solar_azimuth)/10 + 18; if ( solar_elevation > horizon_azimuth_out[azimuth_class] ) irrads_beam_nor_st[j - 1] = (irrads_glo_st[j - 1] - irrads_dif_st[j - 1]) / sin(radians(solar_elevation)); else { irrads_beam_nor_st[j-1]=0; irrads_dif_st[j-1]=irrads_glo_st[j-1]; } if (irrads_beam_nor_st[j - 1] > SOLAR_CONSTANT_E) irrads_beam_nor_st[j - 1] = SOLAR_CONSTANT_E; } mean_beam_st = mean ( sph, &irrads_beam_nor_st[0] ); mean_dif_st = mean ( sph, &irrads_dif_st[0] ); if ( mean_beam_st > 0 ) /* beam renormalization to the given hourly mean value */ for ( j=1 ; j<=sph ; j++ ) irrads_beam_nor_st[j-1] = irrads_beam_nor[i] / mean_beam_st * irrads_beam_nor_st[j-1]; if ( daylight_status[i] == 1 ) { /* Tito */ k=0; for ( j=1 ; j<=sph ; j++ ){ if( irrads_dif_st[j-1]>0.01){ k++;} } if( (k+30) < 60 ) irrads_dif[i]*=(k*1.0/(k+30.0)); } if ( mean_dif_st > 0 ) /* diffuse renormalization to the given hourly mean value */ for ( j=1 ; j<=sph ; j++ ) irrads_dif_st[j-1] = irrads_dif[i] / mean_dif_st * irrads_dif_st[j-1]; for ( j=1 ; j<=sph ; j++ ) if (irrads_beam_nor_st[j - 1] > SOLAR_CONSTANT_E) irrads_beam_nor_st[j - 1] = SOLAR_CONSTANT_E; for ( j=1 ; j<=(60/shortterm_timestep) ; j++ ) { time_t = times[i] - 0.5 + ( j - 0.5 ) / (60/shortterm_timestep); if ( shortterm_timestep == 1 ) { if ( output_units_genshortterm == 1 ) fprintf ( SHORT_TERM_DATA,"%d %d %.3f %.0f %.0f\n", last_month, last_day, time_t, irrads_beam_nor_st[j-1], irrads_dif_st[j-1] ); if ( output_units_genshortterm == 2 ) { solar_elev_azi_ecc (latitude, longitude, time_zone, last_jday, time_t, solar_time,&solar_elevation, &solar_azimuth, &eccentricity_correction); /*if ( solar_elevation < 0 ) solar_elevation=0;*/ punk = solar_elevation; if ( solar_elevation < 0 ) punk=0; fprintf(SHORT_TERM_DATA, "%.3f %.0f %.0f %.3f %.3f\n", (last_jday - 1) * 24 + time_t, irrads_beam_nor_st[j - 1] * sin(radians(punk)), irrads_dif_st[j - 1], solar_elevation, solar_azimuth); } } else { if ( output_units_genshortterm == 1 ) { sum_beam_nor=0; sum_dif=0; for ( k=(j-1)*shortterm_timestep ; k<j*shortterm_timestep ; k++ ) { sum_beam_nor+=irrads_beam_nor_st[k]; sum_dif+=irrads_dif_st[k]; } fprintf ( SHORT_TERM_DATA,"%d %d %.3f %.0f %.0f\n",last_month, last_day, time_t, sum_beam_nor/shortterm_timestep, sum_dif/shortterm_timestep ); } if ( output_units_genshortterm == 2 ) { sum_beam_hor=0; sum_dif=0; for ( k=(j-1)*shortterm_timestep ; k<j*shortterm_timestep ; k++ ) { time_k = times[i] - 0.5 + ( k + 0.5 ) / 60; solar_elev_azi_ecc (latitude, longitude, time_zone, last_jday, time_k, solar_time,&solar_elevation, &solar_azimuth, &eccentricity_correction); if ( solar_elevation < 0 ) solar_elevation=0; sum_beam_hor += irrads_beam_nor_st[k] * sin(radians(solar_elevation)); sum_dif+=irrads_dif_st[k]; } fprintf ( SHORT_TERM_DATA,"%.3f %.0f %.0f\n", (last_jday-1)*24+time_t, sum_beam_hor/shortterm_timestep, sum_dif/shortterm_timestep ); } } } } } if ( status <= 0 ) goto end; times[0]=time; irrads_glo[0] = irrad_glo; irrads_beam_nor[0] = irrad_beam_nor; irrads_dif[0] = irrad_dif; nhd=1; } } last_day=day; last_month=month; last_jday=jday; } } end: { close_file(HOURLY_DATA); close_file(SHORT_TERM_DATA); } if (day!=31 || month !=12) { printf("WARNING - Incomplete input climate file (%s)! The file ends on month %d and day %d.\n",input_weather_data,month,day); printf("Please review the output file before proceedingto Step3 using SITE>>OPEN CLIMATE FILE IN TEXT EDITOR.\n"); } else { printf("DS_SHORTTERM - A climate file with a time step of %d minutes has been generated under %s.\n\n",time_step,input_weather_data_shortterm); } return 0; memerr: error(SYSTEM, "out of memory in function main"); }