| 14 |  | #include <math.h> | 
| 15 |  | #include <sys/types.h> | 
| 16 |  | #include <ctype.h> | 
| 17 | + |  | 
| 18 | + | #include "rtio.h" | 
| 19 |  | #include "color.h" | 
| 20 |  | #include "paths.h" | 
| 21 |  |  | 
| 126 |  | int     gargc;                          /* global argc (minus filenames) */ | 
| 127 |  | char    **gargv;                        /* global argv */ | 
| 128 |  |  | 
| 127 | – | extern char     *stradd(), *tailtrunc(), *filetrunc(), | 
| 128 | – | *filename(), *libname(), *fullnam(), *getword(), *atos(); | 
| 129 | – | extern float    *matchlamp(); | 
| 130 | – | extern time_t   fdate(); | 
| 129 |  |  | 
| 130 |  | #define scnint(fp,ip)   cvtint(ip,getword(fp)) | 
| 131 |  | #define scnflt(fp,rp)   cvtflt(rp,getword(fp)) | 
| 132 |  | #define isint           isflt                   /* IES allows real as integer */ | 
| 133 |  |  | 
| 134 |  |  | 
| 135 | < | main(argc, argv) | 
| 136 | < | int     argc; | 
| 137 | < | char    *argv[]; | 
| 135 | > | static int ies2rad(char *inpname, char *outname); | 
| 136 | > | static void initlamps(void); | 
| 137 | > | static int dosource(SRCINFO *sinf, FILE *in, FILE *out, char *mod, char *name); | 
| 138 | > | static int dotilt(FILE *in, FILE *out, char *dir, char *tltspec, | 
| 139 | > | char *dfltname, char *tltid); | 
| 140 | > | static int cvgeometry(char *inpname, SRCINFO *sinf, char *outname, FILE *outfp); | 
| 141 | > | static int cvtint(int *ip, char *wrd); | 
| 142 | > | static int cvdata(FILE *in, FILE *out, int ndim, int npts[], double mult, | 
| 143 | > | double lim[][2]); | 
| 144 | > | static int cvtflt(double *rp, char *wrd); | 
| 145 | > | static int makeshape(SRCINFO *shp, double width, double length, double height); | 
| 146 | > | static int putsource(SRCINFO *shp, FILE *fp, char *mod, char *name, | 
| 147 | > | int dolower, int doupper, int dosides); | 
| 148 | > | static void putrectsrc(SRCINFO *shp, FILE *fp, char *mod, char *name, int up); | 
| 149 | > | static void putsides(SRCINFO *shp, FILE *fp, char *mod, char *name); | 
| 150 | > | static void putdisksrc(SRCINFO *shp, FILE *fp, char *mod, char *name, int up); | 
| 151 | > | static void putspheresrc(SRCINFO *shp, FILE *fp, char *mod, char *name); | 
| 152 | > | static void putrect(SRCINFO *shp, FILE *fp, char *mod, char *name, char *suffix, | 
| 153 | > | int a, int b, int c, int d); | 
| 154 | > | static void putpoint(SRCINFO *shp, FILE *fp, int p); | 
| 155 | > | static void putcyl(SRCINFO *shp, FILE *fp, char *mod, char *name); | 
| 156 | > | static char * tailtrunc(char *name); | 
| 157 | > | static char * filename(char *path); | 
| 158 | > | static char * libname(char *path, char *fname, char *suffix); | 
| 159 | > | static char * getword(FILE *fp); | 
| 160 | > | static char * fullnam(char *path, char *fname, char *suffix); | 
| 161 | > |  | 
| 162 | > |  | 
| 163 | > | int | 
| 164 | > | main( | 
| 165 | > | int     argc, | 
| 166 | > | char    *argv[] | 
| 167 | > | ) | 
| 168 |  | { | 
| 169 |  | char    *outfile = NULL; | 
| 170 |  | int     status; | 
| 295 |  | exit(1); | 
| 296 |  | } | 
| 297 |  |  | 
| 298 | < |  | 
| 299 | < | initlamps()                             /* set up lamps */ | 
| 298 | > | void | 
| 299 | > | initlamps(void)                         /* set up lamps */ | 
| 300 |  | { | 
| 301 |  | float   *lcol; | 
| 302 |  | int     status; | 
| 337 |  |  | 
| 338 |  |  | 
| 339 |  | char * | 
| 340 | < | stradd(dst, src, sep)                   /* add a string at dst */ | 
| 341 | < | register char   *dst, *src; | 
| 342 | < | int     sep; | 
| 340 | > | stradd(                 /* add a string at dst */ | 
| 341 | > | register char   *dst, | 
| 342 | > | register char   *src, | 
| 343 | > | int     sep | 
| 344 | > | ) | 
| 345 |  | { | 
| 346 |  | if (src && *src) { | 
| 347 |  | do | 
| 356 |  |  | 
| 357 |  |  | 
| 358 |  | char * | 
| 359 | < | fullnam(path, fname, suffix)            /* return full path name */ | 
| 360 | < | char    *path, *fname, *suffix; | 
| 359 | > | fullnam(                /* return full path name */ | 
| 360 | > | char    *path, | 
| 361 | > | char    *fname, | 
| 362 | > | char    *suffix | 
| 363 | > | ) | 
| 364 |  | { | 
| 365 |  | if (prefdir != NULL && abspath(prefdir)) | 
| 366 |  | libname(path, fname, suffix); | 
| 374 |  |  | 
| 375 |  |  | 
| 376 |  | char * | 
| 377 | < | libname(path, fname, suffix)            /* return library relative name */ | 
| 378 | < | char    *path, *fname, *suffix; | 
| 377 | > | libname(                /* return library relative name */ | 
| 378 | > | char    *path, | 
| 379 | > | char    *fname, | 
| 380 | > | char    *suffix | 
| 381 | > | ) | 
| 382 |  | { | 
| 383 |  | if (abspath(fname)) | 
| 384 |  | strcpy(stradd(path, fname, 0), suffix); | 
| 390 |  |  | 
| 391 |  |  | 
| 392 |  | char * | 
| 393 | < | filename(path)                  /* get final component of pathname */ | 
| 394 | < | register char   *path; | 
| 393 | > | filename(                       /* get final component of pathname */ | 
| 394 | > | register char   *path | 
| 395 | > | ) | 
| 396 |  | { | 
| 397 |  | register char   *cp; | 
| 398 |  |  | 
| 404 |  |  | 
| 405 |  |  | 
| 406 |  | char * | 
| 407 | < | filetrunc(path)                         /* truncate filename at end of path */ | 
| 408 | < | char    *path; | 
| 407 | > | filetrunc(                              /* truncate filename at end of path */ | 
| 408 | > | char    *path | 
| 409 | > | ) | 
| 410 |  | { | 
| 411 |  | register char   *p1, *p2; | 
| 412 |  |  | 
| 421 |  |  | 
| 422 |  |  | 
| 423 |  | char * | 
| 424 | < | tailtrunc(name)                         /* truncate tail of filename */ | 
| 425 | < | char    *name; | 
| 424 | > | tailtrunc(                              /* truncate tail of filename */ | 
| 425 | > | char    *name | 
| 426 | > | ) | 
| 427 |  | { | 
| 428 |  | register char   *p1, *p2; | 
| 429 |  |  | 
| 439 |  | } | 
| 440 |  |  | 
| 441 |  |  | 
| 442 | < | blanktrunc(s)                           /* truncate spaces at end of line */ | 
| 443 | < | char    *s; | 
| 442 | > | void | 
| 443 | > | blanktrunc(                             /* truncate spaces at end of line */ | 
| 444 | > | char    *s | 
| 445 | > | ) | 
| 446 |  | { | 
| 447 |  | register char   *cp; | 
| 448 |  |  | 
| 454 |  | } | 
| 455 |  |  | 
| 456 |  |  | 
| 457 | < | k_match(kwd, hdl)                       /* header line matches keyword? */ | 
| 458 | < | register char   *kwd, *hdl; | 
| 457 | > | int | 
| 458 | > | k_match(                        /* header line matches keyword? */ | 
| 459 | > | register char   *kwd, | 
| 460 | > | register char   *hdl | 
| 461 | > | ) | 
| 462 |  | { | 
| 463 |  | if (!*hdl++ == '[') | 
| 464 |  | return(0); | 
| 470 |  |  | 
| 471 |  |  | 
| 472 |  | char * | 
| 473 | < | keyargs(hdl)                            /* return keyword arguments */ | 
| 474 | < | register char   *hdl; | 
| 473 | > | keyargs(                                /* return keyword arguments */ | 
| 474 | > | register char   *hdl | 
| 475 | > | ) | 
| 476 |  | { | 
| 477 |  | while (*hdl && *hdl++ != ']') | 
| 478 |  | ; | 
| 482 |  | } | 
| 483 |  |  | 
| 484 |  |  | 
| 485 | < | putheader(out)                          /* print header */ | 
| 486 | < | FILE    *out; | 
| 485 | > | void | 
| 486 | > | putheader(                              /* print header */ | 
| 487 | > | FILE    *out | 
| 488 | > | ) | 
| 489 |  | { | 
| 490 |  | register int    i; | 
| 491 |  |  | 
| 500 |  | } | 
| 501 |  |  | 
| 502 |  |  | 
| 503 | < | ies2rad(inpname, outname)               /* convert IES file */ | 
| 504 | < | char    *inpname, *outname; | 
| 503 | > | int | 
| 504 | > | ies2rad(                /* convert IES file */ | 
| 505 | > | char    *inpname, | 
| 506 | > | char    *outname | 
| 507 | > | ) | 
| 508 |  | { | 
| 509 |  | SRCINFO srcinfo; | 
| 510 |  | char    buf[MAXLINE], tltid[RMAXWORD]; | 
| 594 |  | } | 
| 595 |  |  | 
| 596 |  |  | 
| 597 | < | dotilt(in, out, dir, tltspec, dfltname, tltid)  /* convert tilt data */ | 
| 598 | < | FILE    *in, *out; | 
| 599 | < | char    *dir, *tltspec, *dfltname, *tltid; | 
| 597 | > | int | 
| 598 | > | dotilt( /* convert tilt data */ | 
| 599 | > | FILE    *in, | 
| 600 | > | FILE    *out, | 
| 601 | > | char    *dir, | 
| 602 | > | char    *tltspec, | 
| 603 | > | char    *dfltname, | 
| 604 | > | char    *tltid | 
| 605 | > | ) | 
| 606 |  | { | 
| 607 |  | int     nangles, tlt_type; | 
| 608 | < | double  minmax[2]; | 
| 608 | > | double  minmax[1][2]; | 
| 609 |  | char    buf[PATH_MAX], tltname[RMAXWORD]; | 
| 610 |  | FILE    *datin, *datout; | 
| 611 |  |  | 
| 651 |  | switch (tlt_type) { | 
| 652 |  | case TLT_VERT:                  /* vertical */ | 
| 653 |  | fprintf(out, "4 noop %s tilt.cal %s\n", buf, | 
| 654 | < | minmax[1]>90.+FTINY ? "tilt_ang" : "tilt_ang2"); | 
| 654 | > | minmax[0][1]>90.+FTINY ? "tilt_ang" : "tilt_ang2"); | 
| 655 |  | break; | 
| 656 |  | case TLT_H0:                    /* horiz. in 0 deg. plane */ | 
| 657 |  | fprintf(out, "6 noop %s tilt.cal %s -rz 90\n", buf, | 
| 658 | < | minmax[1]>90.+FTINY ? "tilt_xang" : "tilt_xang2"); | 
| 658 | > | minmax[0][1]>90.+FTINY ? "tilt_xang" : "tilt_xang2"); | 
| 659 |  | break; | 
| 660 |  | case TLT_H90: | 
| 661 |  | fprintf(out, "4 noop %s tilt.cal %s\n", buf, | 
| 662 | < | minmax[1]>90.+FTINY ? "tilt_xang" : "tilt_xang2"); | 
| 662 | > | minmax[0][1]>90.+FTINY ? "tilt_xang" : "tilt_xang2"); | 
| 663 |  | break; | 
| 664 |  | default: | 
| 665 |  | fprintf(stderr, | 
| 673 |  | } | 
| 674 |  |  | 
| 675 |  |  | 
| 676 | < | dosource(sinf, in, out, mod, name)      /* create source and distribution */ | 
| 677 | < | SRCINFO *sinf; | 
| 678 | < | FILE    *in, *out; | 
| 679 | < | char    *mod, *name; | 
| 676 | > | int | 
| 677 | > | dosource(       /* create source and distribution */ | 
| 678 | > | SRCINFO *sinf, | 
| 679 | > | FILE    *in, | 
| 680 | > | FILE    *out, | 
| 681 | > | char    *mod, | 
| 682 | > | char    *name | 
| 683 | > | ) | 
| 684 |  | { | 
| 685 |  | char    buf[PATH_MAX], id[RMAXWORD]; | 
| 686 |  | FILE    *datout; | 
| 783 |  | } | 
| 784 |  |  | 
| 785 |  |  | 
| 786 | < | putsource(shp, fp, mod, name, dolower, doupper, dosides) /* put out source */ | 
| 787 | < | SRCINFO *shp; | 
| 788 | < | FILE    *fp; | 
| 789 | < | char    *mod, *name; | 
| 790 | < | int     dolower, doupper; | 
| 786 | > | int | 
| 787 | > | putsource( /* put out source */ | 
| 788 | > | SRCINFO *shp, | 
| 789 | > | FILE    *fp, | 
| 790 | > | char    *mod, | 
| 791 | > | char    *name, | 
| 792 | > | int     dolower, | 
| 793 | > | int     doupper, | 
| 794 | > | int dosides | 
| 795 | > | ) | 
| 796 |  | { | 
| 797 |  | char    lname[RMAXWORD]; | 
| 798 |  |  | 
| 826 |  | } | 
| 827 |  |  | 
| 828 |  |  | 
| 829 | < | makeshape(shp, width, length, height)           /* make source shape */ | 
| 830 | < | register SRCINFO        *shp; | 
| 831 | < | double  width, length, height; | 
| 829 | > | int | 
| 830 | > | makeshape(              /* make source shape */ | 
| 831 | > | register SRCINFO        *shp, | 
| 832 | > | double  width, | 
| 833 | > | double  length, | 
| 834 | > | double  height | 
| 835 | > | ) | 
| 836 |  | { | 
| 837 |  | if (illumrad/meters2out >= MINDIM/2.) { | 
| 838 |  | shp->isillum = 1; | 
| 879 |  | } | 
| 880 |  |  | 
| 881 |  |  | 
| 882 | < | putrectsrc(shp, fp, mod, name, up)              /* rectangular source */ | 
| 883 | < | SRCINFO *shp; | 
| 884 | < | FILE    *fp; | 
| 885 | < | char    *mod, *name; | 
| 886 | < | int     up; | 
| 882 | > | void | 
| 883 | > | putrectsrc(             /* rectangular source */ | 
| 884 | > | SRCINFO *shp, | 
| 885 | > | FILE    *fp, | 
| 886 | > | char    *mod, | 
| 887 | > | char    *name, | 
| 888 | > | int     up | 
| 889 | > | ) | 
| 890 |  | { | 
| 891 |  | if (up) | 
| 892 |  | putrect(shp, fp, mod, name, ".u", 4, 5, 7, 6); | 
| 895 |  | } | 
| 896 |  |  | 
| 897 |  |  | 
| 898 | < | putsides(shp, fp, mod, name)                    /* put out sides of box */ | 
| 899 | < | register SRCINFO        *shp; | 
| 900 | < | FILE    *fp; | 
| 901 | < | char    *mod, *name; | 
| 898 | > | void | 
| 899 | > | putsides(                       /* put out sides of box */ | 
| 900 | > | register SRCINFO        *shp, | 
| 901 | > | FILE    *fp, | 
| 902 | > | char    *mod, | 
| 903 | > | char    *name | 
| 904 | > | ) | 
| 905 |  | { | 
| 906 |  | putrect(shp, fp, mod, name, ".1", 0, 1, 5, 4); | 
| 907 |  | putrect(shp, fp, mod, name, ".2", 1, 3, 7, 5); | 
| 910 |  | } | 
| 911 |  |  | 
| 912 |  |  | 
| 913 | < | putrect(shp, fp, mod, name, suffix, a, b, c, d) /* put out a rectangle */ | 
| 914 | < | SRCINFO *shp; | 
| 915 | < | FILE    *fp; | 
| 916 | < | char    *mod, *name, *suffix; | 
| 917 | < | int     a, b, c, d; | 
| 913 | > | void | 
| 914 | > | putrect(        /* put out a rectangle */ | 
| 915 | > | SRCINFO *shp, | 
| 916 | > | FILE    *fp, | 
| 917 | > | char    *mod, | 
| 918 | > | char    *name, | 
| 919 | > | char    *suffix, | 
| 920 | > | int     a, | 
| 921 | > | int b, | 
| 922 | > | int c, | 
| 923 | > | int d | 
| 924 | > | ) | 
| 925 |  | { | 
| 926 |  | fprintf(fp, "\n%s polygon %s%s\n0\n0\n12\n", mod, name, suffix); | 
| 927 |  | putpoint(shp, fp, a); | 
| 931 |  | } | 
| 932 |  |  | 
| 933 |  |  | 
| 934 | < | putpoint(shp, fp, p)                            /* put out a point */ | 
| 935 | < | register SRCINFO        *shp; | 
| 936 | < | FILE    *fp; | 
| 937 | < | int     p; | 
| 934 | > | void | 
| 935 | > | putpoint(                               /* put out a point */ | 
| 936 | > | register SRCINFO        *shp, | 
| 937 | > | FILE    *fp, | 
| 938 | > | int     p | 
| 939 | > | ) | 
| 940 |  | { | 
| 941 |  | static double   mult[2] = {-.5, .5}; | 
| 942 |  |  | 
| 947 |  | } | 
| 948 |  |  | 
| 949 |  |  | 
| 950 | < | putdisksrc(shp, fp, mod, name, up)              /* put out a disk source */ | 
| 951 | < | register SRCINFO        *shp; | 
| 952 | < | FILE    *fp; | 
| 953 | < | char    *mod, *name; | 
| 954 | < | int     up; | 
| 950 | > | void | 
| 951 | > | putdisksrc(             /* put out a disk source */ | 
| 952 | > | register SRCINFO        *shp, | 
| 953 | > | FILE    *fp, | 
| 954 | > | char    *mod, | 
| 955 | > | char    *name, | 
| 956 | > | int     up | 
| 957 | > | ) | 
| 958 |  | { | 
| 959 |  | if (up) { | 
| 960 |  | fprintf(fp, "\n%s ring %s.u\n", mod, name); | 
| 972 |  | } | 
| 973 |  |  | 
| 974 |  |  | 
| 975 | < | putcyl(shp, fp, mod, name)                      /* put out a cylinder */ | 
| 976 | < | register SRCINFO        *shp; | 
| 977 | < | FILE    *fp; | 
| 978 | < | char    *mod, *name; | 
| 975 | > | void | 
| 976 | > | putcyl(                 /* put out a cylinder */ | 
| 977 | > | register SRCINFO        *shp, | 
| 978 | > | FILE    *fp, | 
| 979 | > | char    *mod, | 
| 980 | > | char    *name | 
| 981 | > | ) | 
| 982 |  | { | 
| 983 |  | fprintf(fp, "\n%s cylinder %s.c\n", mod, name); | 
| 984 |  | fprintf(fp, "0\n0\n7\n"); | 
| 988 |  | } | 
| 989 |  |  | 
| 990 |  |  | 
| 991 | < | putspheresrc(shp, fp, mod, name)                /* put out a sphere source */ | 
| 992 | < | SRCINFO *shp; | 
| 993 | < | FILE    *fp; | 
| 994 | < | char    *mod, *name; | 
| 991 | > | void | 
| 992 | > | putspheresrc(           /* put out a sphere source */ | 
| 993 | > | SRCINFO *shp, | 
| 994 | > | FILE    *fp, | 
| 995 | > | char    *mod, | 
| 996 | > | char    *name | 
| 997 | > | ) | 
| 998 |  | { | 
| 999 |  | fprintf(fp, "\n%s sphere %s.s\n", mod, name); | 
| 1000 |  | fprintf(fp, "0\n0\n4 0 0 0 %g\n", .5*shp->w*meters2out); | 
| 1001 |  | } | 
| 1002 |  |  | 
| 1003 |  |  | 
| 1004 | < | cvdata(in, out, ndim, npts, mult, lim)          /* convert data */ | 
| 1005 | < | FILE    *in, *out; | 
| 1006 | < | int     ndim, npts[]; | 
| 1007 | < | double  mult, lim[][2]; | 
| 1004 | > | int | 
| 1005 | > | cvdata(         /* convert data */ | 
| 1006 | > | FILE    *in, | 
| 1007 | > | FILE    *out, | 
| 1008 | > | int     ndim, | 
| 1009 | > | int     npts[], | 
| 1010 | > | double  mult, | 
| 1011 | > | double  lim[][2] | 
| 1012 | > | ) | 
| 1013 |  | { | 
| 1014 |  | double  *pt[4]; | 
| 1015 |  | register int    i, j; | 
| 1069 |  |  | 
| 1070 |  |  | 
| 1071 |  | char * | 
| 1072 | < | getword(fp)                     /* scan a word from fp */ | 
| 1073 | < | register FILE   *fp; | 
| 1072 | > | getword(                        /* scan a word from fp */ | 
| 1073 | > | register FILE   *fp | 
| 1074 | > | ) | 
| 1075 |  | { | 
| 1076 |  | static char     wrd[RMAXWORD]; | 
| 1077 |  | register char   *cp; | 
| 1094 |  | } | 
| 1095 |  |  | 
| 1096 |  |  | 
| 1097 | < | cvtint(ip, wrd)                 /* convert a word to an integer */ | 
| 1098 | < | int     *ip; | 
| 1099 | < | char    *wrd; | 
| 1097 | > | int | 
| 1098 | > | cvtint(                 /* convert a word to an integer */ | 
| 1099 | > | int     *ip, | 
| 1100 | > | char    *wrd | 
| 1101 | > | ) | 
| 1102 |  | { | 
| 1103 |  | if (wrd == NULL || !isint(wrd)) | 
| 1104 |  | return(0); | 
| 1107 |  | } | 
| 1108 |  |  | 
| 1109 |  |  | 
| 1110 | < | cvtflt(rp, wrd)                 /* convert a word to a double */ | 
| 1111 | < | double  *rp; | 
| 1112 | < | char    *wrd; | 
| 1110 | > | int | 
| 1111 | > | cvtflt(                 /* convert a word to a double */ | 
| 1112 | > | double  *rp, | 
| 1113 | > | char    *wrd | 
| 1114 | > | ) | 
| 1115 |  | { | 
| 1116 |  | if (wrd == NULL || !isflt(wrd)) | 
| 1117 |  | return(0); | 
| 1120 |  | } | 
| 1121 |  |  | 
| 1122 |  |  | 
| 1123 | < | cvgeometry(inpname, sinf, outname, outfp) | 
| 1124 | < | char    *inpname; | 
| 1125 | < | register SRCINFO        *sinf; | 
| 1126 | < | char    *outname; | 
| 1127 | < | FILE    *outfp;                 /* close output file upon return */ | 
| 1123 | > | int | 
| 1124 | > | cvgeometry( | 
| 1125 | > | char    *inpname, | 
| 1126 | > | register SRCINFO        *sinf, | 
| 1127 | > | char    *outname, | 
| 1128 | > | FILE    *outfp                  /* close output file upon return */ | 
| 1129 | > | ) | 
| 1130 |  | { | 
| 1131 |  | char    buf[256]; | 
| 1132 |  | register char   *cp; |