--- ray/src/cv/ies2rad.c 1995/04/25 21:37:14 2.12 +++ ray/src/cv/ies2rad.c 1997/07/25 11:18:18 2.15 @@ -1,4 +1,4 @@ -/* Copyright (c) 1992 Regents of the University of California */ +/* Copyright (c) 1996 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -12,6 +12,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include +#include #include #include "color.h" #include "paths.h" @@ -108,6 +109,7 @@ float defcolor[3] = {1.,1.,1.}; /* default lamp color float *lampcolor = defcolor; /* pointer to current lamp color */ double multiplier = 1.0; /* multiplier for all light sources */ char units[64] = "meters"; /* output units */ +int out2stdout = 0; /* put out to stdout r.t. file */ int instantiate = 0; /* instantiate geometry */ double illumrad = 0.0; /* radius for illum sphere */ @@ -126,6 +128,7 @@ extern char *strcpy(), *strcat(), *stradd(), *tailtrun *filename(), *libname(), *fullname(), *malloc(), *getword(), *atos(); extern float *matchlamp(); +extern time_t fdate(); #define scnint(fp,ip) cvtint(ip,getword(fp)) #define scnflt(fp,rp) cvtflt(rp,getword(fp)) @@ -203,9 +206,12 @@ char *argv[]; case 'f': /* lamp data file */ lampdat = argv[++i]; break; - case 'o': /* output file name */ + case 'o': /* output file root name */ outfile = argv[++i]; break; + case 's': /* output to stdout */ + out2stdout = !out2stdout; + break; case 'i': /* illum */ illumrad = atof(argv[++i]); break; @@ -241,16 +247,15 @@ char *argv[]; exit(ies2rad(NULL, outfile) == 0 ? 0 : 1); else if (i == argc-1) exit(ies2rad(argv[i], outfile) == 0 ? 0 : 1); - else { - fprintf(stderr, "%s: single input file required\n", - argv[0]); - exit(1); - } + else + goto needsingle; } else if (i >= argc) { fprintf(stderr, "%s: missing output file specification\n", argv[0]); exit(1); } + if (out2stdout && i != argc-1) + goto needsingle; status = 0; for ( ; i < argc; i++) { tailtrunc(strcpy(outname,filename(argv[i]))); @@ -258,6 +263,9 @@ char *argv[]; status = 1; } exit(status); +needsingle: + fprintf(stderr, "%s: single input file required\n", argv[0]); + exit(1); } @@ -464,7 +472,9 @@ char *inpname, *outname; perror(inpname); return(-1); } - if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { + if (out2stdout) + outfp = stdout; + else if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { perror(buf); fclose(inpfp); return(-1); @@ -704,6 +714,7 @@ FILE *fp; char *mod, *name; int dolower, doupper; { + int dosides = 0; char buf[MAXWORD]; fprintf(fp, "\n%s %s %s_light\n", mod, @@ -714,15 +725,13 @@ int dolower, doupper; lampcolor[1]/shp->area, lampcolor[2]/shp->area); if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) - if (shp->isillum) { - fprintf(fp, "\nvoid illum %s_glow\n", name); - fprintf(fp, "0\n0\n3 0 0 0\n"); - } else { + if (!shp->isillum) { fprintf(fp, "\n%s glow %s_glow\n", mod, name); fprintf(fp, "0\n0\n4 %g %g %g -1\n", lampcolor[0]/shp->area, lampcolor[1]/shp->area, lampcolor[2]/shp->area); + dosides++; } switch (shp->type) { case RECT: @@ -731,7 +740,7 @@ int dolower, doupper; putrectsrc(shp, fp, buf, name, 0); if (doupper) putrectsrc(shp, fp, buf, name, 1); - if (doupper && dolower && shp->h > MINDIM) { + if (dosides) { strcat(strcpy(buf, name), "_glow"); putsides(shp, fp, buf, name); } @@ -742,7 +751,7 @@ int dolower, doupper; putdisksrc(shp, fp, buf, name, 0); if (doupper) putdisksrc(shp, fp, buf, name, 1); - if (doupper && dolower && shp->h > MINDIM) { + if (dosides) { strcat(strcpy(buf, name), "_glow"); putcyl(shp, fp, buf, name); } @@ -1040,7 +1049,8 @@ FILE *outfp; /* close output file upon return */ strcpy(cp, "| oconv - > "); cp += 12; fullname(cp,outname,T_OCT); - if (system(buf)) { /* create octree */ + if (fdate(inpname) > fdate(outname) && + system(buf)) { /* create octree */ fclose(outfp); return(-1); } @@ -1054,14 +1064,16 @@ FILE *outfp; /* close output file upon return */ fprintf(outfp, "0\n0\n"); fclose(outfp); } else { /* else append to luminaire file */ - fclose(outfp); if (!FEQ(meters2out, 1.0)) { /* apply scalefactor */ sprintf(cp, "| xform -s %f ", meters2out); cp += strlen(cp); } - strcpy(cp, ">> "); /* append works for DOS? */ - cp += 3; - fullname(cp,outname,T_RAD); + if (!out2stdout) { + fclose(outfp); + strcpy(cp, ">> "); /* append works for DOS? */ + cp += 3; + fullname(cp,outname,T_RAD); + } if (system(buf)) return(-1); }