static void printdefaults(void) /* print default values to stdout */ { char *cp; printf("-c %-5d\t\t\t# accumulated rays per record\n", accumulate); printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-', contrib ? "contributions" : "coefficients"); if (imm_irrad) printf("-I+\t\t\t\t# immediate irradiance on\n"); printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); printf("-x %-9d\t\t\t# %s\n", xres, yres && xres ? "x resolution" : "flush interval"); printf("-y %-9d\t\t\t# y resolution\n", yres); printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : "-ld-\t\t\t\t# limit distance off\n"); printf("-h%c\t\t\t\t# %s header\n", header ? '+' : '-', header ? "output" : "no"); printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", inpfmt, outfmt, formstr(inpfmt), formstr(outfmt)); printf(erract[WARNING].pf != NULL ? "-w+\t\t\t\t# warning messages on\n" : "-w-\t\t\t\t# warning messages off\n"); print_rdefaults(); }
/* Write header to the given output stream */ static void printheader(FILE *fout, const char *info) { extern char VersionID[]; /* copy octree header */ if (octname[0] == '!') { newheader("RADIANCE", fout); fputs(octname+1, fout); if (octname[strlen(octname)-1] != '\n') fputc('\n', fout); } else { FILE *fin = fopen(octname, (outfmt=='a') ? "r" : "rb"); if (fin == NULL) quit(1); checkheader(fin, OCTFMT, fout); fclose(fin); } printargs(gargc-1, gargv, fout); /* add our command */ fprintf(fout, "SOFTWARE= %s\n", VersionID); fputnow(fout); fputs("NCOMP=3\n", fout); /* always RGB */ if (info != NULL) /* add extra info if given */ fputs(info, fout); fputformat(formstr(outfmt), fout); fputc('\n', fout); /* empty line ends header */ }
/* Load previously accumulated values */ void reload_output() { int i, j; MODCONT *mp; int ofl; char oname[1024]; char *fmode = "rb"; char *outvfmt; LUENT *oent; int xr, yr; STREAMOUT sout; DCOLOR rgbv; if (outfmt == 'a') fmode = "r"; outvfmt = formstr(outfmt); /* reload modifier values */ for (i = 0; i < nmods; i++) { mp = (MODCONT *)lu_find(&modconttab,modname[i])->data; if (mp->outspec == NULL) error(USER, "cannot reload from stdout"); if (mp->outspec[0] == '!') error(USER, "cannot reload from command"); for (j = 0; ; j++) { /* load each modifier bin */ ofl = ofname(oname, mp->outspec, mp->modname, j); if (ofl < 0) error(USER, "bad output file specification"); oent = lu_find(&ofiletab, oname); if (oent->data != NULL) { sout = *(STREAMOUT *)oent->data; } else { sout.reclen = 0; sout.outpipe = 0; sout.xr = xres; sout.yr = yres; sout.ofp = NULL; } if (sout.ofp == NULL) { /* open output as input */ sout.ofp = fopen(oname, fmode); if (sout.ofp == NULL) { if (j == mp->nbins) break; /* assume end of modifier */ sprintf(errmsg, "missing reload file '%s'", oname); error(WARNING, errmsg); break; } #ifdef getc_unlocked flockfile(sout.ofp); #endif if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) { sprintf(errmsg, "format mismatch for '%s'", oname); error(USER, errmsg); } if ((sout.xr > 0) & (sout.yr > 0) && (!fscnresolu(&xr, &yr, sout.ofp) || (xr != sout.xr) | (yr != sout.yr))) { sprintf(errmsg, "resolution mismatch for '%s'", oname); error(USER, errmsg); } } /* read in RGB value */ if (!get_contrib(rgbv, sout.ofp)) { if (!j) { fclose(sout.ofp); break; /* ignore empty file */ } if (j < mp->nbins) { sprintf(errmsg, "missing data in '%s'", oname); error(USER, errmsg); } break; } if (j >= mp->nbins) { /* check modifier size */ sprintf(errmsg, "mismatched -bn setting for reloading '%s'", modname[i]); error(USER, errmsg); } copycolor(mp->cbin[j], rgbv); if (oent->key == NULL) /* new file entry */ oent->key = strcpy((char *) malloc(strlen(oname)+1), oname); if (oent->data == NULL) oent->data = (char *)malloc(sizeof(STREAMOUT)); *(STREAMOUT *)oent->data = sout; } } lu_doall(&ofiletab, &myclose, NULL); /* close all files */ }
/* Recover output if possible */ void recover_output() { off_t lastout = -1; int outvsiz, recsiz; char *outvfmt; int i, j; MODCONT *mp; int ofl; char oname[1024]; LUENT *oent; STREAMOUT sout; off_t nvals; int xr, yr; switch (outfmt) { case 'a': error(USER, "cannot recover ASCII output"); return; case 'f': outvsiz = sizeof(float)*3; break; case 'd': outvsiz = sizeof(double)*3; break; case 'c': outvsiz = sizeof(COLR); break; default: error(INTERNAL, "botched output format"); return; } outvfmt = formstr(outfmt); /* check modifier outputs */ for (i = 0; i < nmods; i++) { mp = (MODCONT *)lu_find(&modconttab,modname[i])->data; if (mp->outspec == NULL) error(USER, "cannot recover from stdout"); if (mp->outspec[0] == '!') error(USER, "cannot recover from command"); for (j = 0; ; j++) { /* check each bin's file */ ofl = ofname(oname, mp->outspec, mp->modname, j); if (ofl < 0) error(USER, "bad output file specification"); oent = lu_find(&ofiletab, oname); if (oent->data != NULL) { sout = *(STREAMOUT *)oent->data; } else { sout.reclen = 0; sout.outpipe = 0; sout.ofp = NULL; } if (sout.ofp != NULL) { /* already open? */ if (ofl & OF_BIN) continue; break; } /* open output */ sout.ofp = fopen(oname, "rb+"); if (sout.ofp == NULL) { if (j == mp->nbins) break; /* assume end of modifier */ sprintf(errmsg, "missing recover file '%s'", oname); error(WARNING, errmsg); break; } nvals = lseek(fileno(sout.ofp), 0, SEEK_END); if (nvals <= 0) { lastout = 0; /* empty output, quit here */ fclose(sout.ofp); break; } if (!sout.reclen) { if (!(ofl & OF_BIN)) { sprintf(errmsg, "need -bn to recover file '%s'", oname); error(USER, errmsg); } recsiz = outvsiz; } else recsiz = outvsiz * sout.reclen; lseek(fileno(sout.ofp), 0, SEEK_SET); if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) { sprintf(errmsg, "format mismatch for '%s'", oname); error(USER, errmsg); } sout.xr = xres; sout.yr = yres; if ((sout.xr > 0) & (sout.yr > 0) && (!fscnresolu(&xr, &yr, sout.ofp) || (xr != sout.xr) | (yr != sout.yr))) { sprintf(errmsg, "resolution mismatch for '%s'", oname); error(USER, errmsg); } nvals = (nvals - (off_t)ftell(sout.ofp)) / recsiz; if ((lastout < 0) | (nvals < lastout)) lastout = nvals; if (oent->key == NULL) /* new entry */ oent->key = strcpy((char *) malloc(strlen(oname)+1), oname); if (oent->data == NULL) oent->data = (char *)malloc(sizeof(STREAMOUT)); *(STREAMOUT *)oent->data = sout; if (!(ofl & OF_BIN)) break; /* no bin separation */ } if (!lastout) { /* empty output */ error(WARNING, "no previous data to recover"); lu_done(&ofiletab); /* reclose all outputs */ return; } if (j > mp->nbins) { /* check modifier size */ sprintf(errmsg, "mismatched -bn setting for recovering '%s'", modname[i]); error(USER, errmsg); } } if (lastout < 0) { error(WARNING, "no output files to recover"); return; } if (raysleft && lastout >= raysleft/accumulate) { error(WARNING, "output appears to be complete"); /* XXX should read & discard input? */ quit(0); } /* seek on all files */ nvals = lastout * outvsiz; lu_doall(&ofiletab, &myseeko, &nvals); /* skip repeated input */ lastout *= accumulate; for (nvals = 0; nvals < lastout; nvals++) { FVECT vdummy; if (getvec(vdummy) < 0 || getvec(vdummy) < 0) error(USER, "unexpected EOF on input"); } lastray = lastdone = (RNUMBER)lastout; if (raysleft) raysleft -= lastray; }
/* Load previously accumulated values */ void reload_output() { int i, j; MODCONT *mp; int ofl; char oname[1024]; char *fmode = "rb"; char *outvfmt; LUENT *oent; int xr, yr; STREAMOUT *sop; DCOLOR rgbv; if (outfmt == 'a') fmode = "r"; outvfmt = formstr(outfmt); /* reload modifier values */ for (i = 0; i < nmods; i++) { mp = (MODCONT *)lu_find(&modconttab,modname[i])->data; if (mp->outspec == NULL) error(USER, "cannot reload from stdout"); if (mp->outspec[0] == '!') error(USER, "cannot reload from command"); for (j = 0; j < mp->nbins; j++) { /* load each modifier bin */ ofl = ofname(oname, mp->outspec, mp->modname, mp->bin0+j); if (ofl < 0) error(USER, "bad output file specification"); oent = lu_find(&ofiletab, oname); if (oent->data == NULL) error(INTERNAL, "unallocated stream in reload_output()"); sop = (STREAMOUT *)oent->data; if (sop->ofp == NULL) { /* open output as input */ sop->ofp = fopen(oname, fmode); if (sop->ofp == NULL) { sprintf(errmsg, "missing reload file '%s'", oname); error(WARNING, errmsg); break; } #ifdef getc_unlocked flockfile(sop->ofp); #endif if (header && checkheader(sop->ofp, outvfmt, NULL) != 1) { sprintf(errmsg, "format mismatch for '%s'", oname); error(USER, errmsg); } if ((sop->reclen == 1) & (sop->xr > 0) & (sop->yr > 0) && (!fscnresolu(&xr, &yr, sop->ofp) || (xr != sop->xr) | (yr != sop->yr))) { sprintf(errmsg, "resolution mismatch for '%s'", oname); error(USER, errmsg); } } /* read in RGB value */ if (!get_contrib(rgbv, sop->ofp)) { if (!j) { fclose(sop->ofp); break; /* ignore empty file */ } if (j < mp->nbins) { sprintf(errmsg, "missing data in '%s'", oname); error(USER, errmsg); } break; } copycolor(mp->cbin[j], rgbv); } } lu_doall(&ofiletab, &myclose, NULL); /* close all files */ }