--- ray/src/util/wrapBSDF.c 2015/05/29 07:16:49 2.15 +++ ray/src/util/wrapBSDF.c 2017/02/14 19:58:37 2.22 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: wrapBSDF.c,v 2.15 2015/05/29 07:16:49 greg Exp $"; +static const char RCSid[] = "$Id: wrapBSDF.c,v 2.22 2017/02/14 19:58:37 greg Exp $"; #endif /* * Wrap BSDF data in valid WINDOW XML file @@ -7,9 +7,10 @@ static const char RCSid[] = "$Id: wrapBSDF.c,v 2.15 20 * G. Ward February 2015 */ +#include "platform.h" #include #include "rtio.h" -#include "rtprocess.h" +#include "paths.h" #include "ezxml.h" #include "bsdf.h" #include "bsdf_m.h" @@ -25,7 +26,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 }; @@ -48,6 +52,7 @@ struct s_fieldID { } XMLfieldID[] = { {"m", 0, 1, "Manufacturer"}, {"n", 0, 1, "Name"}, + {"d", 0, 0, "DeviceType"}, {"c", 0, 0, "ThermalConductivity"}, {"ef", 0, 0, "EmissivityFront"}, {"eb", 0, 0, "EmissivityBack"}, @@ -59,7 +64,7 @@ struct s_fieldID { {"\0", 0, 0, NULL} /* terminator */ }; /* field assignments */ -#define MAXASSIGN 12 +#define MAXASSIGN 16 const char *field_assignment[MAXASSIGN]; int nfield_assign = 0; #define FASEP ';' @@ -79,6 +84,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"; @@ -160,7 +167,8 @@ input2str(const char *inpspec) fprintf(stderr, "%s: cannot open\n", inpspec); return ""; } -#ifndef _WIN32 /* XXX somehow broken on Windows */ +#if !defined(_WIN32) && !defined(_WIN64) + /* XXX somehow broken on Windows */ len = lseek(fd, 0L, SEEK_END); if (len > 0) { lseek(fd, 0L, SEEK_SET); @@ -388,9 +396,7 @@ determine_angle_basis(const char *fn, ezxml_t wtl) static int filter_klems_matrix(FILE *fp) { -#define MAX_COLUMNS 145 const char *bn = klems_basis_name[angle_basis]; - float col_corr[MAX_COLUMNS]; int i, j, n = nabases; /* get angle basis */ while (n-- > 0) @@ -398,15 +404,9 @@ filter_klems_matrix(FILE *fp) break; if (n < 0) return 0; - if (abase_list[n].nangles > MAX_COLUMNS) { - fputs("Internal error - too many Klems columns!\n", stderr); - return 0; - } - /* get correction factors */ - for (j = abase_list[n].nangles; j--; ) - col_corr[j] = 1.f / io_getohm(j, &abase_list[n]); /* read/correct/write matrix */ for (i = 0; i < abase_list[n].nangles; i++) { + const double corr = 1./io_getohm(i, &abase_list[n]); for (j = 0; j < abase_list[n].nangles; j++) { double d; if (fscanf(fp, "%lf", &d) != 1) @@ -415,7 +415,7 @@ filter_klems_matrix(FILE *fp) fputs("Negative BSDF data!\n", stderr); return 0; } - printf(" %.3e", d*col_corr[j]*(d > 0)); + printf(" %.3e", d*corr*(d > 0)); } fputc('\n', stdout); } @@ -425,7 +425,6 @@ filter_klems_matrix(FILE *fp) return 0; } return 1; /* all is good */ -#undef MAX_COLUMNS } /* Write out BSDF data block with surrounding tags */ @@ -586,6 +585,8 @@ writeBSDF(const char *caller, ezxml_t fl) 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); @@ -599,7 +600,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 */ @@ -718,7 +730,7 @@ UsageExit(const char *pname) fputs("Usage: ", stderr); fputs(pname, 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]", stderr); + fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp][-C comm]", stderr); fputs(" [input.xml]\n", stderr); exit(1); } @@ -763,6 +775,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]); @@ -786,6 +801,19 @@ main(int argc, char *argv[]) continue; 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)