--- ray/src/cv/pkgBSDF.c 2011/06/23 18:05:18 2.1 +++ ray/src/cv/pkgBSDF.c 2013/04/21 22:56:14 2.5 @@ -1,10 +1,11 @@ #ifndef lint -static const char RCSid[] = "$Id: pkgBSDF.c,v 2.1 2011/06/23 18:05:18 greg Exp $"; +static const char RCSid[] = "$Id: pkgBSDF.c,v 2.5 2013/04/21 22:56:14 greg Exp $"; #endif /* * Take BSDF XML file and generate a referencing Radiance object */ +#include "rtio.h" #include "paths.h" #include "bsdf.h" @@ -52,12 +53,12 @@ geomBSDF(const SDData *bsp) char command[SDnameLn+64]; int fd; /* write MGF to temp file */ - fd = open(mktemp(strcpy(tmpfile,TEMPLATE)), O_WRONLY|O_CREAT|O_EXCL); + fd = open(mktemp(strcpy(tmpfile,TEMPLATE)), O_WRONLY|O_CREAT|O_EXCL, 0600); if (fd < 0) { fprintf(stderr, "Cannot open temp file '%s'\n", tmpfile); return(0); } - write(fd, bsp->mgf, strlen(bsp->mgf)); + (void)write(fd, bsp->mgf, strlen(bsp->mgf)); close(fd); /* set up command */ if (do_instance) { @@ -82,18 +83,24 @@ geomBSDF(const SDData *bsp) /* Load a BSDF XML file and produce a corresponding Radiance object */ static int -cvtBSDF(const char *fname) +cvtBSDF(char *fname) { int retOK; SDData myBSDF; - /* load the XML file */ + char *pname; + /* find and load the XML file */ retOK = strlen(fname); if (retOK < 5 || strcmp(fname+retOK-4, ".xml")) { fprintf(stderr, "%s: input does not end in '.xml'\n", fname); return(0); } + pname = getpath(fname, getrlibpath(), R_OK); + if (pname == NULL) { + fprintf(stderr, "%s: cannot find BSDF file\n", fname); + return(0); + } SDclearBSDF(&myBSDF, fname); - if (SDreportEnglish(SDloadFile(&myBSDF, fname), stderr)) + if (SDreportError(SDloadFile(&myBSDF, pname), stderr)) return(0); retOK = (myBSDF.dim[0] > FTINY) & (myBSDF.dim[1] > FTINY); if (!retOK) { @@ -106,6 +113,9 @@ cvtBSDF(const char *fname) retOK = (freopen(rname, "w", stdout) != NULL); } if (retOK) { + if (myBSDF.matn[0] && myBSDF.makr[0]) + printf("# Material '%s' by '%s'\n\n", + myBSDF.matn, myBSDF.makr); if (myBSDF.mgf == NULL) { faceBSDF(&myBSDF, .0); } else {