11 |
|
*/ |
12 |
|
|
13 |
|
#include <stdio.h> |
14 |
+ |
#include <math.h> |
15 |
|
#include <ctype.h> |
16 |
|
#include "color.h" |
17 |
|
#include "paths.h" |
77 |
|
char **gargv; /* global argv */ |
78 |
|
|
79 |
|
extern char *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), |
80 |
< |
*filename(), *libname(), *fullname(), *malloc(); |
80 |
> |
*filename(), *libname(), *fullname(), *malloc(), |
81 |
> |
*getword(), *atos(); |
82 |
|
extern float *matchlamp(); |
83 |
|
|
84 |
+ |
#define scnint(fp,ip) cvtint(ip,getword(fp)) |
85 |
+ |
#define scnflt(fp,rp) cvtflt(rp,getword(fp)) |
86 |
+ |
#define isint isflt /* IES allows real as integer */ |
87 |
|
|
88 |
+ |
|
89 |
|
main(argc, argv) |
90 |
|
int argc; |
91 |
|
char *argv[]; |
407 |
|
} |
408 |
|
if (lampcolor == NULL) { |
409 |
|
fprintf(stderr, "%s: warning - no lamp type\n", inpname); |
410 |
+ |
fputs("# Unknown lamp type (used default)\n", outfp); |
411 |
|
lampcolor = defcolor; |
412 |
< |
} |
412 |
> |
} else if (lamptype == NULL) |
413 |
> |
fprintf(outfp,"# CIE(x,y) = (%f,%f)\n# Depreciation = %.1f%%\n", |
414 |
> |
lampcolor[3], lampcolor[4], 100.*lampcolor[5]); |
415 |
|
if (feof(inpfp)) { |
416 |
|
fprintf(stderr, "%s: not in IES format\n", inpname); |
417 |
|
goto readerr; |
418 |
|
} |
419 |
< |
sscanf(buf+TLTSTRLEN, "%s", tltid); |
419 |
> |
atos(tltid, MAXWORD, buf+TLTSTRLEN); |
420 |
|
if (inpfp == stdin) |
421 |
|
buf[0] = '\0'; |
422 |
|
else |
473 |
|
fclose(datin); |
474 |
|
return(-1); |
475 |
|
} |
476 |
< |
if (fscanf(datin, "%d %d", &tlt_type, &nangles) != 2 |
476 |
> |
if (!scnint(datin,&tlt_type) || !scnint(datin,&nangles) |
477 |
|
|| cvdata(datin,datout,1,&nangles,1.,minmax) != 0) { |
478 |
|
fprintf(stderr, "%s: data format error\n", tltspec); |
479 |
|
fclose(datout); |
525 |
|
int nangles[2], pmtype, unitype; |
526 |
|
double d1; |
527 |
|
|
528 |
< |
if (fscanf(in, "%*d %*f %lf %d %d %d %d %lf %lf %lf %lf %lf %lf", |
529 |
< |
&mult, &nangles[0], &nangles[1], &pmtype, &unitype, |
530 |
< |
&width, &length, &height, &bfactor, &pfactor, |
531 |
< |
&wattage) != 11) { |
528 |
> |
if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult) |
529 |
> |
|| !scnint(in,&nangles[0]) || !scnint(in,&nangles[1]) |
530 |
> |
|| !scnint(in,&pmtype) || !scnint(in,&unitype) |
531 |
> |
|| !scnflt(in,&width) || !scnflt(in,&length) |
532 |
> |
|| !scnflt(in,&height) || !scnflt(in,&bfactor) |
533 |
> |
|| !scnflt(in,&pfactor) || !scnflt(in,&wattage)) { |
534 |
|
fprintf(stderr, "dosource: bad lamp specification\n"); |
535 |
|
return(-1); |
536 |
|
} |
567 |
|
else if (pmtype == PM_B) |
568 |
|
fprintf(out, "5 "); |
569 |
|
else if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) |
570 |
< |
fprintf(out, "8 "); |
570 |
> |
fprintf(out, "7 "); |
571 |
|
else |
572 |
< |
fprintf(out, "6 "); |
572 |
> |
fprintf(out, "5 "); |
573 |
|
fprintf(out, "%s %s source.cal ", |
574 |
|
srcshape.type==SPHERE ? "corr" : "flatcorr", |
575 |
|
libname(buf,name,T_DST)); |
588 |
|
fprintf(out, "src_phi2 "); |
589 |
|
else |
590 |
|
fprintf(out, "src_phi "); |
591 |
< |
fprintf(out, "src_theta -my "); |
591 |
> |
fprintf(out, "src_theta "); |
592 |
|
if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) |
593 |
|
fprintf(out, "-rz -90 "); |
594 |
|
} else |
823 |
|
for (i = 0; i < ndim; i++) { |
824 |
|
pt[i] = (double *)malloc(npts[i]*sizeof(double)); |
825 |
|
for (j = 0; j < npts[i]; j++) |
826 |
< |
fscanf(in, "%lf", &pt[i][j]); |
826 |
> |
if (!scnflt(in, &pt[i][j])) |
827 |
> |
return(-1); |
828 |
|
if (lim != NULL) { |
829 |
|
lim[i][0] = pt[i][0]; |
830 |
|
lim[i][1] = pt[i][npts[i]-1]; |
855 |
|
for (i = 0; i < total; i++) { |
856 |
|
if (i%4 == 0) |
857 |
|
putc('\n', out); |
858 |
< |
if (fscanf(in, "%lf", &val) != 1) |
858 |
> |
if (!scnflt(in, &val)) |
859 |
|
return(-1); |
860 |
|
fprintf(out, "\t%g", val*mult); |
861 |
|
} |
862 |
|
putc('\n', out); |
863 |
|
return(0); |
864 |
+ |
} |
865 |
+ |
|
866 |
+ |
|
867 |
+ |
char * |
868 |
+ |
getword(fp) /* scan a word from fp */ |
869 |
+ |
register FILE *fp; |
870 |
+ |
{ |
871 |
+ |
static char word[MAXWORD]; |
872 |
+ |
register char *cp; |
873 |
+ |
register int c; |
874 |
+ |
|
875 |
+ |
while (isspace(c=getc(fp))) |
876 |
+ |
; |
877 |
+ |
for (cp = word; c != EOF && cp < word+MAXWORD-1; |
878 |
+ |
*cp++ = c, c = getc(fp)) |
879 |
+ |
if (isspace(c) || c == ',') { |
880 |
+ |
while (isspace(c)) |
881 |
+ |
c = getc(fp); |
882 |
+ |
if (c != EOF & c != ',') |
883 |
+ |
ungetc(c, fp); |
884 |
+ |
*cp = '\0'; |
885 |
+ |
return(word); |
886 |
+ |
} |
887 |
+ |
*cp = '\0'; |
888 |
+ |
return(cp > word ? word : NULL); |
889 |
+ |
} |
890 |
+ |
|
891 |
+ |
|
892 |
+ |
cvtint(ip, word) /* convert a word to an integer */ |
893 |
+ |
int *ip; |
894 |
+ |
char *word; |
895 |
+ |
{ |
896 |
+ |
if (word == NULL || !isint(word)) |
897 |
+ |
return(0); |
898 |
+ |
*ip = atoi(word); |
899 |
+ |
return(1); |
900 |
+ |
} |
901 |
+ |
|
902 |
+ |
|
903 |
+ |
cvtflt(rp, word) /* convert a word to a double */ |
904 |
+ |
double *rp; |
905 |
+ |
char *word; |
906 |
+ |
{ |
907 |
+ |
if (word == NULL || !isflt(word)) |
908 |
+ |
return(0); |
909 |
+ |
*rp = atof(word); |
910 |
+ |
return(1); |
911 |
|
} |