--- ray/src/util/wrapBSDF.c 2015/05/29 07:45:48 2.16 +++ ray/src/util/wrapBSDF.c 2019/04/03 23:50:25 2.23 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: wrapBSDF.c,v 2.16 2015/05/29 07:45:48 greg Exp $"; +static const char RCSid[] = "$Id: wrapBSDF.c,v 2.23 2019/04/03 23:50:25 greg Exp $"; #endif /* * Wrap BSDF data in valid WINDOW XML file @@ -7,9 +7,10 @@ static const char RCSid[] = "$Id: wrapBSDF.c,v 2.16 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" @@ -51,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"}, @@ -62,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 ';' @@ -82,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"; @@ -118,6 +122,23 @@ static char basis_definition[][256] = { "\t\n", }; +/* Check that the last-added data file is unique */ +static int +check_new_data_file() +{ + int i = ndataf; + + while (i-- > 0) + if ((data_file[i].spectrum == data_file[ndataf].spectrum) & + (data_file[i].type == data_file[ndataf].type)) { + fprintf(stderr, + "%s: warning - ignoring duplicate component\n", + data_file[ndataf].fname); + return 0; + } + return 1; +} + /* Copy data from file descriptor to stdout and close */ static int copy_and_close(int fd) @@ -163,7 +184,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); @@ -391,9 +413,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) @@ -401,15 +421,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) @@ -418,7 +432,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); } @@ -428,7 +442,6 @@ filter_klems_matrix(FILE *fp) return 0; } return 1; /* all is good */ -#undef MAX_COLUMNS } /* Write out BSDF data block with surrounding tags */ @@ -604,7 +617,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 */ @@ -768,6 +792,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]); @@ -825,7 +852,7 @@ main(int argc, char *argv[]) } data_file[ndataf].fname = argv[i]; data_file[ndataf].spectrum = cur_spectrum; - ndataf++; + ndataf += check_new_data_file(); continue; case 'r': /* reflection */ if (i >= argc-1)