--- ray/src/cv/ies2rad.c 1996/06/18 21:28:52 2.14 +++ ray/src/cv/ies2rad.c 2003/07/03 22:41:44 2.21 @@ -1,16 +1,16 @@ -/* Copyright (c) 1996 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: ies2rad.c,v 2.21 2003/07/03 22:41:44 schorsch Exp $"; #endif - /* * Convert IES luminaire data to Radiance description * * 07Apr90 Greg Ward + * + * Fixed correction factor for flat sources 29Oct2001 GW */ #include +#include #include #include #include @@ -79,7 +79,7 @@ int filerev = FIRSTREV; #define U_METERS 2 /* string lengths */ #define MAXLINE 132 -#define MAXWORD 76 +#define RMAXWORD 76 /* file types */ #define T_RAD ".rad" #define T_DST ".dat" @@ -124,9 +124,8 @@ typedef struct { int gargc; /* global argc (minus filenames) */ char **gargv; /* global argv */ -extern char *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), - *filename(), *libname(), *fullname(), *malloc(), - *getword(), *atos(); +extern char *stradd(), *tailtrunc(), *filetrunc(), + *filename(), *libname(), *fullnam(), *getword(), *atos(); extern float *matchlamp(); extern time_t fdate(); @@ -141,7 +140,7 @@ char *argv[]; { char *outfile = NULL; int status; - char outname[MAXWORD]; + char outname[RMAXWORD]; double d1; int i; @@ -327,7 +326,7 @@ int sep; char * -fullname(path, fname, suffix) /* return full path name */ +fullnam(path, fname, suffix) /* return full path name */ char *path, *fname, *suffix; { if (prefdir != NULL && abspath(prefdir)) @@ -458,7 +457,7 @@ ies2rad(inpname, outname) /* convert IES file */ char *inpname, *outname; { SRCINFO srcinfo; - char buf[MAXLINE], tltid[MAXWORD]; + char buf[MAXLINE], tltid[RMAXWORD]; char geomfile[128]; FILE *inpfp, *outfp; int lineno = 0; @@ -474,7 +473,7 @@ char *inpname, *outname; } if (out2stdout) outfp = stdout; - else if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { + else if ((outfp = fopen(fullnam(buf,outname,T_RAD), "w")) == NULL) { perror(buf); fclose(inpfp); return(-1); @@ -517,7 +516,7 @@ char *inpname, *outname; fprintf(stderr, "%s: not in IES format\n", inpname); goto readerr; } - atos(tltid, MAXWORD, buf+TLTSTRLEN); + atos(tltid, RMAXWORD, buf+TLTSTRLEN); if (inpfp == stdin) buf[0] = '\0'; else @@ -540,7 +539,7 @@ char *inpname, *outname; readerr: fclose(inpfp); fclose(outfp); - unlink(fullname(buf,outname,T_RAD)); + unlink(fullnam(buf,outname,T_RAD)); return(-1); } @@ -551,7 +550,7 @@ char *dir, *tltspec, *dfltname, *tltid; { int nangles, tlt_type; double minmax[2]; - char buf[MAXPATH], tltname[MAXWORD]; + char buf[PATH_MAX], tltname[RMAXWORD]; FILE *datin, *datout; if (!strcmp(tltspec, TLTNONE)) { @@ -572,7 +571,7 @@ char *dir, *tltspec, *dfltname, *tltid; tailtrunc(strcpy(tltname,filename(tltspec))); } if (datin != NULL) { - if ((datout = fopen(fullname(buf,tltname,T_TLT),"w")) == NULL) { + if ((datout = fopen(fullnam(buf,tltname,T_TLT),"w")) == NULL) { perror(buf); if (datin != in) fclose(datin); @@ -584,7 +583,7 @@ char *dir, *tltspec, *dfltname, *tltid; fclose(datout); if (datin != in) fclose(datin); - unlink(fullname(buf,tltname,T_TLT)); + unlink(fullnam(buf,tltname,T_TLT)); return(-1); } fclose(datout); @@ -623,12 +622,13 @@ SRCINFO *sinf; FILE *in, *out; char *mod, *name; { - char buf[MAXPATH], id[MAXWORD]; + char buf[PATH_MAX], id[RMAXWORD]; FILE *datout; double mult, bfactor, pfactor, width, length, height, wattage; double bounds[2][2]; int nangles[2], pmtype, unitype; double d1; + int doupper, dolower, dosides; if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult) || !scnint(in,&nangles[0]) || !scnint(in,&nangles[1]) @@ -653,14 +653,14 @@ char *mod, *name; fprintf(stderr, "dosource: illegal source dimensions"); return(-1); } - if ((datout = fopen(fullname(buf,name,T_DST), "w")) == NULL) { + if ((datout = fopen(fullnam(buf,name,T_DST), "w")) == NULL) { perror(buf); return(-1); } if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) { fprintf(stderr, "dosource: bad distribution data\n"); fclose(datout); - unlink(fullname(buf,name,T_DST)); + unlink(fullnam(buf,name,T_DST)); return(-1); } fclose(datout); @@ -676,8 +676,13 @@ char *mod, *name; fprintf(out, "7 "); else fprintf(out, "5 "); + dolower = (bounds[0][0] < 90.); + doupper = (bounds[0][1] > 90.); + dosides = (doupper & dolower && sinf->h > MINDIM); fprintf(out, "%s %s source.cal ", - sinf->type==SPHERE ? "corr" : "flatcorr", + sinf->type==SPHERE ? "corr" : + !dosides ? "flatcorr" : + sinf->type==DISK ? "cylcorr" : "boxcorr", libname(buf,name,T_DST)); if (pmtype == PM_B) { if (FEQ(bounds[1][0],0.)) @@ -685,14 +690,17 @@ char *mod, *name; else fprintf(out, "srcB_horiz "); fprintf(out, "srcB_vert "); - } else { + } else /* pmtype == PM_A */ { if (nangles[1] >= 2) { d1 = bounds[1][1] - bounds[1][0]; if (d1 <= 90.+FTINY) fprintf(out, "src_phi4 "); - else if (d1 <= 180.+FTINY) - fprintf(out, "src_phi2 "); - else + else if (d1 <= 180.+FTINY) { + if (FEQ(bounds[1][0],90.)) + fprintf(out, "src_phi2+90 "); + else + fprintf(out, "src_phi2 "); + } else fprintf(out, "src_phi "); fprintf(out, "src_theta "); if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) @@ -700,66 +708,53 @@ char *mod, *name; } else fprintf(out, "src_theta "); } - fprintf(out, "\n0\n1 %g\n", sinf->mult); + if (!dosides || sinf->type == SPHERE) + fprintf(out, "\n0\n1 %g\n", sinf->mult/sinf->area); + else if (sinf->type == DISK) + fprintf(out, "\n0\n3 %g %g %g\n", sinf->mult, + sinf->w, sinf->h); + else + fprintf(out, "\n0\n4 %g %g %g %g\n", sinf->mult, + sinf->l, sinf->w, sinf->h); if (putsource(sinf, out, id, filename(name), - bounds[0][0]<90., bounds[0][1]>90.) != 0) + dolower, doupper, dosides) != 0) return(-1); return(0); } -putsource(shp, fp, mod, name, dolower, doupper) /* put out source */ +putsource(shp, fp, mod, name, dolower, doupper, dosides) /* put out source */ SRCINFO *shp; FILE *fp; char *mod, *name; int dolower, doupper; { - char buf[MAXWORD]; + char lname[RMAXWORD]; - fprintf(fp, "\n%s %s %s_light\n", mod, - shp->isillum ? "illum" : "light", - name); + strcat(strcpy(lname, name), "_light"); + fprintf(fp, "\n%s %s %s\n", mod, + shp->isillum ? "illum" : "light", lname); fprintf(fp, "0\n0\n3 %g %g %g\n", - lampcolor[0]/shp->area, - 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 { - 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); - } + lampcolor[0], lampcolor[1], lampcolor[2]); switch (shp->type) { case RECT: - strcat(strcpy(buf, name), "_light"); if (dolower) - putrectsrc(shp, fp, buf, name, 0); + putrectsrc(shp, fp, lname, name, 0); if (doupper) - putrectsrc(shp, fp, buf, name, 1); - if (doupper && dolower && shp->h > MINDIM) { - strcat(strcpy(buf, name), "_glow"); - putsides(shp, fp, buf, name); - } + putrectsrc(shp, fp, lname, name, 1); + if (dosides) + putsides(shp, fp, lname, name); break; case DISK: - strcat(strcpy(buf, name), "_light"); if (dolower) - putdisksrc(shp, fp, buf, name, 0); + putdisksrc(shp, fp, lname, name, 0); if (doupper) - putdisksrc(shp, fp, buf, name, 1); - if (doupper && dolower && shp->h > MINDIM) { - strcat(strcpy(buf, name), "_glow"); - putcyl(shp, fp, buf, name); - } + putdisksrc(shp, fp, lname, name, 1); + if (dosides) + putcyl(shp, fp, lname, name); break; case SPHERE: - strcat(strcpy(buf, name), "_light"); - putspheresrc(shp, fp, buf, name); + putspheresrc(shp, fp, lname, name); break; } return(0); @@ -961,7 +956,7 @@ double mult, lim[][2]; putc('\n', out); } } - free((char *)pt[i]); + free((void *)pt[i]); } for (i = 0; i < total; i++) { if (i%4 == 0) @@ -979,13 +974,13 @@ char * getword(fp) /* scan a word from fp */ register FILE *fp; { - static char word[MAXWORD]; + static char wrd[RMAXWORD]; register char *cp; register int c; while (isspace(c=getc(fp))) ; - for (cp = word; c != EOF && cp < word+MAXWORD-1; + for (cp = wrd; c != EOF && cp < wrd+RMAXWORD-1; *cp++ = c, c = getc(fp)) if (isspace(c) || c == ',') { while (isspace(c)) @@ -993,31 +988,31 @@ register FILE *fp; if (c != EOF & c != ',') ungetc(c, fp); *cp = '\0'; - return(word); + return(wrd); } *cp = '\0'; - return(cp > word ? word : NULL); + return(cp > wrd ? wrd : NULL); } -cvtint(ip, word) /* convert a word to an integer */ +cvtint(ip, wrd) /* convert a word to an integer */ int *ip; -char *word; +char *wrd; { - if (word == NULL || !isint(word)) + if (wrd == NULL || !isint(wrd)) return(0); - *ip = atoi(word); + *ip = atoi(wrd); return(1); } -cvtflt(rp, word) /* convert a word to a double */ +cvtflt(rp, wrd) /* convert a word to a double */ double *rp; -char *word; +char *wrd; { - if (word == NULL || !isflt(word)) + if (wrd == NULL || !isflt(wrd)) return(0); - *rp = atof(word); + *rp = atof(wrd); return(1); } @@ -1049,7 +1044,7 @@ FILE *outfp; /* close output file upon return */ if (instantiate) { /* instantiate octree */ strcpy(cp, "| oconv - > "); cp += 12; - fullname(cp,outname,T_OCT); + fullnam(cp,outname,T_OCT); if (fdate(inpname) > fdate(outname) && system(buf)) { /* create octree */ fclose(outfp); @@ -1073,7 +1068,7 @@ FILE *outfp; /* close output file upon return */ fclose(outfp); strcpy(cp, ">> "); /* append works for DOS? */ cp += 3; - fullname(cp,outname,T_RAD); + fullnam(cp,outname,T_RAD); } if (system(buf)) return(-1);