--- ray/src/util/wrapBSDF.c 2015/02/20 17:05:40 2.10 +++ ray/src/util/wrapBSDF.c 2016/02/03 00:22:55 2.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: wrapBSDF.c,v 2.10 2015/02/20 17:05:40 greg Exp $"; +static const char RCSid[] = "$Id: wrapBSDF.c,v 2.19 2016/02/03 00:22:55 greg Exp $"; #endif /* * Wrap BSDF data in valid WINDOW XML file @@ -9,7 +9,7 @@ static const char RCSid[] = "$Id: wrapBSDF.c,v 2.10 20 #include #include "rtio.h" -#include "rtprocess.h" +#include "paths.h" #include "ezxml.h" #include "bsdf.h" #include "bsdf_m.h" @@ -25,7 +25,10 @@ const char *attr_unit = "meter"; const char legal_units[] = "meter|foot|inch|centimeter|millimeter"; /* system materials & geometry */ const char *mgf_geometry = NULL; - + /* comment list */ +#define MAXCOMM 30 +const char *commlist[MAXCOMM]; +int ncomm = 0; /* angle bases */ enum { ABdefault=-1, ABklemsFull=0, ABklemsHalf, ABklemsQuarter, ABtensorTree3, ABtensorTree4, ABend }; @@ -66,7 +69,8 @@ int nfield_assign = 0; /* data file(s) & spectra */ enum { DTtransForward, DTtransBackward, DTreflForward, DTreflBackward }; -enum { DSsolar=-1, DSnir=-2, DSxbar31=-3, DSvisible=-4, DSzbar31=-5 }; +enum { DSsolar=-1, DSnir=-2, DSxbar31=-3, DSvisible=-4, DSzbar31=-5, + DSuprime=-6, DSvprime=-7 }; #define MAXFILES 20 @@ -78,6 +82,8 @@ struct s_dfile { int ndataf = 0; /* number of data files */ +int unlink_datafiles = 0; /* unlink data files when done */ + const char *spectr_file[MAXFILES]; /* custom spectral curve input */ const char top_level_name[] = "WindowElement"; @@ -159,6 +165,7 @@ input2str(const char *inpspec) fprintf(stderr, "%s: cannot open\n", inpspec); return ""; } +#ifndef _WIN32 /* XXX somehow broken on Windows */ len = lseek(fd, 0L, SEEK_END); if (len > 0) { lseek(fd, 0L, SEEK_SET); @@ -177,6 +184,7 @@ input2str(const char *inpspec) close(fd); return str; } +#endif fp = fdopen(fd, "r"); /* not a regular file */ } /* reading from stream */ @@ -442,22 +450,30 @@ writeBSDFblock(const char *caller, struct s_dfile *df) break; case DSxbar31: puts("\t\tCIE-X"); - puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp"); + puts("\t\tCIE Illuminant D65 1nm.ssp"); puts("\t\tASTM E308 1931 X.dsp"); break; case DSzbar31: puts("\t\tCIE-Z"); - puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp"); + puts("\t\tCIE Illuminant D65 1nm.ssp"); puts("\t\tASTM E308 1931 Z.dsp"); break; + case DSuprime: + puts("\t\tCIE-u"); + puts("\t\tCIE Illuminant D65 1nm.ssp"); + break; + case DSvprime: + puts("\t\tCIE-v"); + puts("\t\tCIE Illuminant D65 1nm.ssp"); + break; case DSsolar: puts("\t\tSolar"); - puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp"); + puts("\t\tCIE Illuminant D65 1nm.ssp"); puts("\t\tNone"); break; case DSnir: puts("\t\tNIR"); - puts("\t\tSourceSpectrum>PLACE_HOLDER"); + puts("\t\tPLACE_HOLDER"); puts("\t\tPLACE_HOLDER"); break; default: @@ -468,7 +484,7 @@ writeBSDFblock(const char *caller, struct s_dfile *df) spectr_file[df->spectrum]); if (cp != NULL) *cp = '.'; - puts("\t\tSourceSpectrum>CIE Illuminant D65 1nm.ssp"); + puts("\t\tCIE Illuminant D65 1nm.ssp"); printf("\t\t%s\n", spectr_file[df->spectrum]); break; @@ -574,6 +590,9 @@ writeBSDF(const char *caller, ezxml_t fl) free(xml); return 0; } + puts(""); + for (i = 0; i < ncomm; i++) + printf("\n", commlist[i]); fflush(stdout); /* write previous XML info. */ if (write(fileno(stdout), xml, ei) != ei) { free(xml); @@ -587,7 +606,18 @@ writeBSDF(const char *caller, ezxml_t fl) fputs(xml+ei, stdout); /* write trailer */ free(xml); /* free string */ fputc('\n', stdout); - return (fflush(stdout) == 0); + if (fflush(stdout) != 0) + return 0; + /* unlink data files if req. */ + for (i = ndataf*(unlink_datafiles != 0); i--; ) + if (data_file[i].fname != stdin_name && + data_file[i].fname[0] != '!') + unlink(data_file[i].fname); + if (unlink_datafiles > 1 && mgf_geometry != NULL && + mgf_geometry != stdin_name && + mgf_geometry[0] != '!') + unlink(mgf_geometry); + return 1; } /* Insert BSDF data into XML wrapper */ @@ -705,8 +735,8 @@ UsageExit(const char *pname) { fputs("Usage: ", stderr); fputs(pname, stderr); - fputs(" [-W][-a {kf|kh|kq|t3|t4}][-u unit][-g geom][-f 'x=string;y=string']", stderr); - fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp]", stderr); + fputs(" [-W][-c][-a {kf|kh|kq|t3|t4}][-u unit][-g geom][-f 'x=string;y=string']", stderr); + fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp][-C comm]", stderr); fputs(" [input.xml]\n", stderr); exit(1); } @@ -751,6 +781,9 @@ main(int argc, char *argv[]) } attr_unit = argv[i]; continue; + case 'U': /* unlink data files when done */ + unlink_datafiles = 1 + (argv[i][2] == 'U'); + continue; case 'a': /* angle basis */ if (++i >= argc) UsageExit(argv[0]); @@ -775,6 +808,19 @@ main(int argc, char *argv[]) case 'c': /* correct solid angle */ correct_solid_angle = 1; continue; + case 'C': /* comment */ + if (ncomm >= MAXCOMM) { + fprintf(stderr, "%s: too many comments\n", + argv[0]); + return 1; + } + if (strchr(argv[++i], '>') != NULL) { + fprintf(stderr, "%s: illegal character in comment\n", + argv[0]); + return 1; + } + commlist[ncomm++] = argv[i]; + continue; case 't': /* transmission */ if (i >= argc-1) UsageExit(argv[0]); @@ -831,6 +877,10 @@ main(int argc, char *argv[]) cur_spectrum = DSxbar31; else if (!strcasecmp(argv[i], "CIE-Z")) cur_spectrum = DSzbar31; + else if (!strcasecmp(argv[i], "CIE-u")) + cur_spectrum = DSuprime; + else if (!strcasecmp(argv[i], "CIE-v")) + cur_spectrum = DSvprime; else if (!strcasecmp(argv[i], "NIR")) cur_spectrum = DSnir; else {