| 1 | 
– | 
/* Copyright (c) 1996 Regents of the University of California */ | 
| 2 | 
– | 
 | 
| 1 | 
  | 
#ifndef lint | 
| 2 | 
< | 
static char SCCSid[] = "$SunId$ LBL"; | 
| 2 | 
> | 
static const char       RCSid[] = "$Id$"; | 
| 3 | 
  | 
#endif | 
| 6 | 
– | 
 | 
| 4 | 
  | 
/* | 
| 5 | 
  | 
 * Convert IES luminaire data to Radiance description | 
| 6 | 
  | 
 * | 
| 7 | 
  | 
 *      07Apr90         Greg Ward | 
| 8 | 
+ | 
 * | 
| 9 | 
+ | 
 *  Fixed correction factor for flat sources 29Oct2001 GW | 
| 10 | 
  | 
 */ | 
| 11 | 
  | 
 | 
| 12 | 
  | 
#include <stdio.h> | 
| 13 | 
+ | 
#include <string.h> | 
| 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 | 
  | 
 | 
| 76 | 
  | 
                                        /* photometric types */ | 
| 77 | 
  | 
#define PM_C            1 | 
| 78 | 
  | 
#define PM_B            2 | 
| 79 | 
+ | 
#define PM_A            3 | 
| 80 | 
  | 
                                        /* unit types */ | 
| 81 | 
  | 
#define U_FEET          1 | 
| 82 | 
  | 
#define U_METERS        2 | 
| 83 | 
  | 
                                        /* string lengths */ | 
| 84 | 
  | 
#define MAXLINE         132 | 
| 85 | 
< | 
#define MAXWORD         76 | 
| 85 | 
> | 
#define RMAXWORD        76 | 
| 86 | 
  | 
                                        /* file types */ | 
| 87 | 
  | 
#define T_RAD           ".rad" | 
| 88 | 
  | 
#define T_DST           ".dat" | 
| 127 | 
  | 
int     gargc;                          /* global argc (minus filenames) */ | 
| 128 | 
  | 
char    **gargv;                        /* global argv */ | 
| 129 | 
  | 
 | 
| 127 | 
– | 
extern char     *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), | 
| 128 | 
– | 
                *filename(), *libname(), *fullname(), *malloc(), | 
| 129 | 
– | 
                *getword(), *atos(); | 
| 130 | 
– | 
extern float    *matchlamp(); | 
| 131 | 
– | 
extern time_t   fdate(); | 
| 130 | 
  | 
 | 
| 131 | 
  | 
#define scnint(fp,ip)   cvtint(ip,getword(fp)) | 
| 132 | 
  | 
#define scnflt(fp,rp)   cvtflt(rp,getword(fp)) | 
| 133 | 
  | 
#define isint           isflt                   /* IES allows real as integer */ | 
| 134 | 
  | 
 | 
| 135 | 
  | 
 | 
| 136 | 
< | 
main(argc, argv) | 
| 137 | 
< | 
int     argc; | 
| 138 | 
< | 
char    *argv[]; | 
| 136 | 
> | 
static int ies2rad(char *inpname, char *outname); | 
| 137 | 
> | 
static void initlamps(void); | 
| 138 | 
> | 
static int dosource(SRCINFO *sinf, FILE *in, FILE *out, char *mod, char *name); | 
| 139 | 
> | 
static int dotilt(FILE *in, FILE *out, char *dir, char *tltspec, | 
| 140 | 
> | 
                char *dfltname, char *tltid); | 
| 141 | 
> | 
static int cvgeometry(char *inpname, SRCINFO *sinf, char *outname, FILE *outfp); | 
| 142 | 
> | 
static int cvtint(int *ip, char *wrd); | 
| 143 | 
> | 
static int cvdata(FILE *in, FILE *out, int ndim, int npts[], double mult, | 
| 144 | 
> | 
                double lim[][2]); | 
| 145 | 
> | 
static int cvtflt(double *rp, char *wrd); | 
| 146 | 
> | 
static int makeshape(SRCINFO *shp, double width, double length, double height); | 
| 147 | 
> | 
static int putsource(SRCINFO *shp, FILE *fp, char *mod, char *name, | 
| 148 | 
> | 
                int dolower, int doupper, int dosides); | 
| 149 | 
> | 
static void putrectsrc(SRCINFO *shp, FILE *fp, char *mod, char *name, int up); | 
| 150 | 
> | 
static void putsides(SRCINFO *shp, FILE *fp, char *mod, char *name); | 
| 151 | 
> | 
static void putdisksrc(SRCINFO *shp, FILE *fp, char *mod, char *name, int up); | 
| 152 | 
> | 
static void putspheresrc(SRCINFO *shp, FILE *fp, char *mod, char *name); | 
| 153 | 
> | 
static void putrect(SRCINFO *shp, FILE *fp, char *mod, char *name, char *suffix, | 
| 154 | 
> | 
                int a, int b, int c, int d); | 
| 155 | 
> | 
static void putpoint(SRCINFO *shp, FILE *fp, int p); | 
| 156 | 
> | 
static void putcyl(SRCINFO *shp, FILE *fp, char *mod, char *name); | 
| 157 | 
> | 
static char * tailtrunc(char *name); | 
| 158 | 
> | 
static char * filename(char *path); | 
| 159 | 
> | 
static char * libname(char *path, char *fname, char *suffix); | 
| 160 | 
> | 
static char * getword(FILE *fp); | 
| 161 | 
> | 
static char * fullnam(char *path, char *fname, char *suffix); | 
| 162 | 
> | 
 | 
| 163 | 
> | 
 | 
| 164 | 
> | 
int | 
| 165 | 
> | 
main( | 
| 166 | 
> | 
        int     argc, | 
| 167 | 
> | 
        char    *argv[] | 
| 168 | 
> | 
) | 
| 169 | 
  | 
{ | 
| 170 | 
  | 
        char    *outfile = NULL; | 
| 171 | 
  | 
        int     status; | 
| 172 | 
< | 
        char    outname[MAXWORD]; | 
| 172 | 
> | 
        char    outname[RMAXWORD]; | 
| 173 | 
  | 
        double  d1; | 
| 174 | 
  | 
        int     i; | 
| 175 | 
  | 
         | 
| 296 | 
  | 
        exit(1); | 
| 297 | 
  | 
} | 
| 298 | 
  | 
 | 
| 299 | 
< | 
 | 
| 300 | 
< | 
initlamps()                             /* set up lamps */ | 
| 299 | 
> | 
void | 
| 300 | 
> | 
initlamps(void)                         /* set up lamps */ | 
| 301 | 
  | 
{ | 
| 302 | 
  | 
        float   *lcol; | 
| 303 | 
  | 
        int     status; | 
| 338 | 
  | 
 | 
| 339 | 
  | 
 | 
| 340 | 
  | 
char * | 
| 341 | 
< | 
stradd(dst, src, sep)                   /* add a string at dst */ | 
| 342 | 
< | 
register char   *dst, *src; | 
| 343 | 
< | 
int     sep; | 
| 341 | 
> | 
stradd(                 /* add a string at dst */ | 
| 342 | 
> | 
        char    *dst, | 
| 343 | 
> | 
        char    *src, | 
| 344 | 
> | 
        int     sep | 
| 345 | 
> | 
) | 
| 346 | 
  | 
{ | 
| 347 | 
  | 
        if (src && *src) { | 
| 348 | 
  | 
                do | 
| 357 | 
  | 
 | 
| 358 | 
  | 
 | 
| 359 | 
  | 
char * | 
| 360 | 
< | 
fullname(path, fname, suffix)           /* return full path name */ | 
| 361 | 
< | 
char    *path, *fname, *suffix; | 
| 360 | 
> | 
fullnam(                /* return full path name */ | 
| 361 | 
> | 
        char    *path, | 
| 362 | 
> | 
        char    *fname, | 
| 363 | 
> | 
        char    *suffix | 
| 364 | 
> | 
) | 
| 365 | 
  | 
{ | 
| 366 | 
  | 
        if (prefdir != NULL && abspath(prefdir)) | 
| 367 | 
  | 
                libname(path, fname, suffix); | 
| 375 | 
  | 
 | 
| 376 | 
  | 
 | 
| 377 | 
  | 
char * | 
| 378 | 
< | 
libname(path, fname, suffix)            /* return library relative name */ | 
| 379 | 
< | 
char    *path, *fname, *suffix; | 
| 378 | 
> | 
libname(                /* return library relative name */ | 
| 379 | 
> | 
        char    *path, | 
| 380 | 
> | 
        char    *fname, | 
| 381 | 
> | 
        char    *suffix | 
| 382 | 
> | 
) | 
| 383 | 
  | 
{ | 
| 384 | 
  | 
        if (abspath(fname)) | 
| 385 | 
  | 
                strcpy(stradd(path, fname, 0), suffix); | 
| 391 | 
  | 
 | 
| 392 | 
  | 
 | 
| 393 | 
  | 
char * | 
| 394 | 
< | 
filename(path)                  /* get final component of pathname */ | 
| 395 | 
< | 
register char   *path; | 
| 394 | 
> | 
filename(                       /* get final component of pathname */ | 
| 395 | 
> | 
        char    *path | 
| 396 | 
> | 
) | 
| 397 | 
  | 
{ | 
| 398 | 
< | 
        register char   *cp; | 
| 398 | 
> | 
        char    *cp; | 
| 399 | 
  | 
 | 
| 400 | 
  | 
        for (cp = path; *path; path++) | 
| 401 | 
  | 
                if (ISDIRSEP(*path)) | 
| 405 | 
  | 
 | 
| 406 | 
  | 
 | 
| 407 | 
  | 
char * | 
| 408 | 
< | 
filetrunc(path)                         /* truncate filename at end of path */ | 
| 409 | 
< | 
char    *path; | 
| 408 | 
> | 
filetrunc(                              /* truncate filename at end of path */ | 
| 409 | 
> | 
        char    *path | 
| 410 | 
> | 
) | 
| 411 | 
  | 
{ | 
| 412 | 
< | 
        register char   *p1, *p2; | 
| 412 | 
> | 
        char    *p1, *p2; | 
| 413 | 
  | 
 | 
| 414 | 
  | 
        for (p1 = p2 = path; *p2; p2++) | 
| 415 | 
  | 
                if (ISDIRSEP(*p2)) | 
| 422 | 
  | 
 | 
| 423 | 
  | 
 | 
| 424 | 
  | 
char * | 
| 425 | 
< | 
tailtrunc(name)                         /* truncate tail of filename */ | 
| 426 | 
< | 
char    *name; | 
| 425 | 
> | 
tailtrunc(                              /* truncate tail of filename */ | 
| 426 | 
> | 
        char    *name | 
| 427 | 
> | 
) | 
| 428 | 
  | 
{ | 
| 429 | 
< | 
        register char   *p1, *p2; | 
| 429 | 
> | 
        char    *p1, *p2; | 
| 430 | 
  | 
 | 
| 431 | 
  | 
        for (p1 = filename(name); *p1 == '.'; p1++) | 
| 432 | 
  | 
                ; | 
| 440 | 
  | 
} | 
| 441 | 
  | 
 | 
| 442 | 
  | 
 | 
| 443 | 
< | 
blanktrunc(s)                           /* truncate spaces at end of line */ | 
| 444 | 
< | 
char    *s; | 
| 443 | 
> | 
void | 
| 444 | 
> | 
blanktrunc(                             /* truncate spaces at end of line */ | 
| 445 | 
> | 
        char    *s | 
| 446 | 
> | 
) | 
| 447 | 
  | 
{ | 
| 448 | 
< | 
        register char   *cp; | 
| 448 | 
> | 
        char    *cp; | 
| 449 | 
  | 
 | 
| 450 | 
  | 
        for (cp = s; *cp; cp++) | 
| 451 | 
  | 
                ; | 
| 455 | 
  | 
} | 
| 456 | 
  | 
 | 
| 457 | 
  | 
 | 
| 458 | 
< | 
k_match(kwd, hdl)                       /* header line matches keyword? */ | 
| 459 | 
< | 
register char   *kwd, *hdl; | 
| 458 | 
> | 
int | 
| 459 | 
> | 
k_match(                        /* header line matches keyword? */ | 
| 460 | 
> | 
        char    *kwd, | 
| 461 | 
> | 
        char    *hdl | 
| 462 | 
> | 
) | 
| 463 | 
  | 
{ | 
| 464 | 
< | 
        if (!*hdl++ == '[') | 
| 464 | 
> | 
        if (*hdl++ != '[') | 
| 465 | 
  | 
                return(0); | 
| 466 | 
  | 
        while (islower(*hdl) ? toupper(*hdl) == *kwd++ : *hdl == *kwd++) | 
| 467 | 
  | 
                if (!*hdl++) | 
| 468 | 
  | 
                        return(0); | 
| 469 | 
< | 
        return(!*kwd & *hdl == ']'); | 
| 469 | 
> | 
        return((!*kwd) & (*hdl == ']')); | 
| 470 | 
  | 
} | 
| 471 | 
  | 
 | 
| 472 | 
  | 
 | 
| 473 | 
  | 
char * | 
| 474 | 
< | 
keyargs(hdl)                            /* return keyword arguments */ | 
| 475 | 
< | 
register char   *hdl; | 
| 474 | 
> | 
keyargs(                                /* return keyword arguments */ | 
| 475 | 
> | 
        char    *hdl | 
| 476 | 
> | 
) | 
| 477 | 
  | 
{ | 
| 478 | 
  | 
        while (*hdl && *hdl++ != ']') | 
| 479 | 
  | 
                ; | 
| 483 | 
  | 
} | 
| 484 | 
  | 
 | 
| 485 | 
  | 
 | 
| 486 | 
< | 
putheader(out)                          /* print header */ | 
| 487 | 
< | 
FILE    *out; | 
| 486 | 
> | 
void | 
| 487 | 
> | 
putheader(                              /* print header */ | 
| 488 | 
> | 
        FILE    *out | 
| 489 | 
> | 
) | 
| 490 | 
  | 
{ | 
| 491 | 
< | 
        register int    i; | 
| 491 | 
> | 
        int     i; | 
| 492 | 
  | 
         | 
| 493 | 
  | 
        putc('#', out); | 
| 494 | 
  | 
        for (i = 0; i < gargc; i++) { | 
| 501 | 
  | 
} | 
| 502 | 
  | 
 | 
| 503 | 
  | 
 | 
| 504 | 
< | 
ies2rad(inpname, outname)               /* convert IES file */ | 
| 505 | 
< | 
char    *inpname, *outname; | 
| 504 | 
> | 
int | 
| 505 | 
> | 
ies2rad(                /* convert IES file */ | 
| 506 | 
> | 
        char    *inpname, | 
| 507 | 
> | 
        char    *outname | 
| 508 | 
> | 
) | 
| 509 | 
  | 
{ | 
| 510 | 
  | 
        SRCINFO srcinfo; | 
| 511 | 
< | 
        char    buf[MAXLINE], tltid[MAXWORD]; | 
| 511 | 
> | 
        char    buf[MAXLINE], tltid[RMAXWORD]; | 
| 512 | 
  | 
        char    geomfile[128]; | 
| 513 | 
  | 
        FILE    *inpfp, *outfp; | 
| 514 | 
  | 
        int     lineno = 0; | 
| 524 | 
  | 
        } | 
| 525 | 
  | 
        if (out2stdout) | 
| 526 | 
  | 
                outfp = stdout; | 
| 527 | 
< | 
        else if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { | 
| 527 | 
> | 
        else if ((outfp = fopen(fullnam(buf,outname,T_RAD), "w")) == NULL) { | 
| 528 | 
  | 
                perror(buf); | 
| 529 | 
  | 
                fclose(inpfp); | 
| 530 | 
  | 
                return(-1); | 
| 567 | 
  | 
                fprintf(stderr, "%s: not in IES format\n", inpname); | 
| 568 | 
  | 
                goto readerr; | 
| 569 | 
  | 
        } | 
| 570 | 
< | 
        atos(tltid, MAXWORD, buf+TLTSTRLEN); | 
| 570 | 
> | 
        atos(tltid, RMAXWORD, buf+TLTSTRLEN); | 
| 571 | 
  | 
        if (inpfp == stdin) | 
| 572 | 
  | 
                buf[0] = '\0'; | 
| 573 | 
  | 
        else | 
| 590 | 
  | 
readerr: | 
| 591 | 
  | 
        fclose(inpfp); | 
| 592 | 
  | 
        fclose(outfp); | 
| 593 | 
< | 
        unlink(fullname(buf,outname,T_RAD)); | 
| 593 | 
> | 
        unlink(fullnam(buf,outname,T_RAD)); | 
| 594 | 
  | 
        return(-1); | 
| 595 | 
  | 
} | 
| 596 | 
  | 
 | 
| 597 | 
  | 
 | 
| 598 | 
< | 
dotilt(in, out, dir, tltspec, dfltname, tltid)  /* convert tilt data */ | 
| 599 | 
< | 
FILE    *in, *out; | 
| 600 | 
< | 
char    *dir, *tltspec, *dfltname, *tltid; | 
| 598 | 
> | 
int | 
| 599 | 
> | 
dotilt( /* convert tilt data */ | 
| 600 | 
> | 
        FILE    *in, | 
| 601 | 
> | 
        FILE    *out, | 
| 602 | 
> | 
        char    *dir, | 
| 603 | 
> | 
        char    *tltspec, | 
| 604 | 
> | 
        char    *dfltname, | 
| 605 | 
> | 
        char    *tltid | 
| 606 | 
> | 
) | 
| 607 | 
  | 
{ | 
| 608 | 
  | 
        int     nangles, tlt_type; | 
| 609 | 
< | 
        double  minmax[2]; | 
| 610 | 
< | 
        char    buf[MAXPATH], tltname[MAXWORD]; | 
| 609 | 
> | 
        double  minmax[1][2]; | 
| 610 | 
> | 
        char    buf[PATH_MAX], tltname[RMAXWORD]; | 
| 611 | 
  | 
        FILE    *datin, *datout; | 
| 612 | 
  | 
 | 
| 613 | 
  | 
        if (!strcmp(tltspec, TLTNONE)) { | 
| 628 | 
  | 
                tailtrunc(strcpy(tltname,filename(tltspec))); | 
| 629 | 
  | 
        } | 
| 630 | 
  | 
        if (datin != NULL) { | 
| 631 | 
< | 
                if ((datout = fopen(fullname(buf,tltname,T_TLT),"w")) == NULL) { | 
| 631 | 
> | 
                if ((datout = fopen(fullnam(buf,tltname,T_TLT),"w")) == NULL) { | 
| 632 | 
  | 
                        perror(buf); | 
| 633 | 
  | 
                        if (datin != in) | 
| 634 | 
  | 
                                fclose(datin); | 
| 640 | 
  | 
                        fclose(datout); | 
| 641 | 
  | 
                        if (datin != in) | 
| 642 | 
  | 
                                fclose(datin); | 
| 643 | 
< | 
                        unlink(fullname(buf,tltname,T_TLT)); | 
| 643 | 
> | 
                        unlink(fullnam(buf,tltname,T_TLT)); | 
| 644 | 
  | 
                        return(-1); | 
| 645 | 
  | 
                } | 
| 646 | 
  | 
                fclose(datout); | 
| 652 | 
  | 
                switch (tlt_type) { | 
| 653 | 
  | 
                case TLT_VERT:                  /* vertical */ | 
| 654 | 
  | 
                        fprintf(out, "4 noop %s tilt.cal %s\n", buf, | 
| 655 | 
< | 
                                minmax[1]>90.+FTINY ? "tilt_ang" : "tilt_ang2"); | 
| 655 | 
> | 
                                minmax[0][1]>90.+FTINY ? "tilt_ang" : "tilt_ang2"); | 
| 656 | 
  | 
                        break; | 
| 657 | 
  | 
                case TLT_H0:                    /* horiz. in 0 deg. plane */ | 
| 658 | 
  | 
                        fprintf(out, "6 noop %s tilt.cal %s -rz 90\n", buf, | 
| 659 | 
< | 
                        minmax[1]>90.+FTINY ? "tilt_xang" : "tilt_xang2"); | 
| 659 | 
> | 
                        minmax[0][1]>90.+FTINY ? "tilt_xang" : "tilt_xang2"); | 
| 660 | 
  | 
                        break; | 
| 661 | 
  | 
                case TLT_H90: | 
| 662 | 
  | 
                        fprintf(out, "4 noop %s tilt.cal %s\n", buf, | 
| 663 | 
< | 
                        minmax[1]>90.+FTINY ? "tilt_xang" : "tilt_xang2"); | 
| 663 | 
> | 
                        minmax[0][1]>90.+FTINY ? "tilt_xang" : "tilt_xang2"); | 
| 664 | 
  | 
                        break; | 
| 665 | 
  | 
                default: | 
| 666 | 
  | 
                        fprintf(stderr, | 
| 674 | 
  | 
} | 
| 675 | 
  | 
 | 
| 676 | 
  | 
 | 
| 677 | 
< | 
dosource(sinf, in, out, mod, name)      /* create source and distribution */ | 
| 678 | 
< | 
SRCINFO *sinf; | 
| 679 | 
< | 
FILE    *in, *out; | 
| 680 | 
< | 
char    *mod, *name; | 
| 677 | 
> | 
int | 
| 678 | 
> | 
dosource(       /* create source and distribution */ | 
| 679 | 
> | 
        SRCINFO *sinf, | 
| 680 | 
> | 
        FILE    *in, | 
| 681 | 
> | 
        FILE    *out, | 
| 682 | 
> | 
        char    *mod, | 
| 683 | 
> | 
        char    *name | 
| 684 | 
> | 
) | 
| 685 | 
  | 
{ | 
| 686 | 
< | 
        char    buf[MAXPATH], id[MAXWORD]; | 
| 686 | 
> | 
        char    buf[PATH_MAX], id[RMAXWORD]; | 
| 687 | 
  | 
        FILE    *datout; | 
| 688 | 
  | 
        double  mult, bfactor, pfactor, width, length, height, wattage; | 
| 689 | 
  | 
        double  bounds[2][2]; | 
| 690 | 
  | 
        int     nangles[2], pmtype, unitype; | 
| 691 | 
  | 
        double  d1; | 
| 692 | 
+ | 
        int     doupper, dolower, dosides;  | 
| 693 | 
  | 
 | 
| 694 | 
  | 
        if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult) | 
| 695 | 
  | 
                        || !scnint(in,&nangles[0]) || !scnint(in,&nangles[1]) | 
| 700 | 
  | 
                fprintf(stderr, "dosource: bad lamp specification\n"); | 
| 701 | 
  | 
                return(-1); | 
| 702 | 
  | 
        } | 
| 703 | 
+ | 
        if (pmtype != PM_C && pmtype != PM_B) { | 
| 704 | 
+ | 
                fprintf(stderr, "dosource: unsupported photometric type (%d)\n", | 
| 705 | 
+ | 
                                pmtype); | 
| 706 | 
+ | 
                return(-1); | 
| 707 | 
+ | 
        } | 
| 708 | 
  | 
        sinf->mult = multiplier*mult*bfactor*pfactor; | 
| 709 | 
  | 
        if (nangles[0] < 2 || nangles[1] < 1) { | 
| 710 | 
  | 
                fprintf(stderr, "dosource: too few measured angles\n"); | 
| 719 | 
  | 
                fprintf(stderr, "dosource: illegal source dimensions"); | 
| 720 | 
  | 
                return(-1); | 
| 721 | 
  | 
        } | 
| 722 | 
< | 
        if ((datout = fopen(fullname(buf,name,T_DST), "w")) == NULL) { | 
| 722 | 
> | 
        if ((datout = fopen(fullnam(buf,name,T_DST), "w")) == NULL) { | 
| 723 | 
  | 
                perror(buf); | 
| 724 | 
  | 
                return(-1); | 
| 725 | 
  | 
        } | 
| 726 | 
  | 
        if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) { | 
| 727 | 
  | 
                fprintf(stderr, "dosource: bad distribution data\n"); | 
| 728 | 
  | 
                fclose(datout); | 
| 729 | 
< | 
                unlink(fullname(buf,name,T_DST)); | 
| 729 | 
> | 
                unlink(fullnam(buf,name,T_DST)); | 
| 730 | 
  | 
                return(-1); | 
| 731 | 
  | 
        } | 
| 732 | 
  | 
        fclose(datout); | 
| 742 | 
  | 
                fprintf(out, "7 "); | 
| 743 | 
  | 
        else | 
| 744 | 
  | 
                fprintf(out, "5 "); | 
| 745 | 
+ | 
        dolower = (bounds[0][0] < 90.-FTINY); | 
| 746 | 
+ | 
        doupper = (bounds[0][1] > 90.+FTINY); | 
| 747 | 
+ | 
        dosides = (doupper & dolower && sinf->h > MINDIM); | 
| 748 | 
  | 
        fprintf(out, "%s %s source.cal ", | 
| 749 | 
  | 
                        sinf->type==SPHERE ? "corr" : | 
| 750 | 
+ | 
                        !dosides ? "flatcorr" : | 
| 751 | 
  | 
                        sinf->type==DISK ? "cylcorr" : "boxcorr", | 
| 752 | 
  | 
                        libname(buf,name,T_DST)); | 
| 753 | 
  | 
        if (pmtype == PM_B) { | 
| 756 | 
  | 
                else | 
| 757 | 
  | 
                        fprintf(out, "srcB_horiz "); | 
| 758 | 
  | 
                fprintf(out, "srcB_vert "); | 
| 759 | 
< | 
        } else { | 
| 759 | 
> | 
        } else /* pmtype == PM_C */ { | 
| 760 | 
  | 
                if (nangles[1] >= 2) { | 
| 761 | 
  | 
                        d1 = bounds[1][1] - bounds[1][0]; | 
| 762 | 
  | 
                        if (d1 <= 90.+FTINY) | 
| 763 | 
  | 
                                fprintf(out, "src_phi4 "); | 
| 764 | 
< | 
                        else if (d1 <= 180.+FTINY) | 
| 765 | 
< | 
                                fprintf(out, "src_phi2 "); | 
| 766 | 
< | 
                        else | 
| 764 | 
> | 
                        else if (d1 <= 180.+FTINY) { | 
| 765 | 
> | 
                                if (FEQ(bounds[1][0],90.)) | 
| 766 | 
> | 
                                        fprintf(out, "src_phi2+90 "); | 
| 767 | 
> | 
                                else | 
| 768 | 
> | 
                                        fprintf(out, "src_phi2 "); | 
| 769 | 
> | 
                        } else | 
| 770 | 
  | 
                                fprintf(out, "src_phi "); | 
| 771 | 
  | 
                        fprintf(out, "src_theta "); | 
| 772 | 
  | 
                        if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) | 
| 774 | 
  | 
                } else | 
| 775 | 
  | 
                        fprintf(out, "src_theta "); | 
| 776 | 
  | 
        } | 
| 777 | 
< | 
        if (sinf->type == SPHERE) | 
| 777 | 
> | 
        if (!dosides || sinf->type == SPHERE) | 
| 778 | 
  | 
                fprintf(out, "\n0\n1 %g\n", sinf->mult/sinf->area); | 
| 779 | 
  | 
        else if (sinf->type == DISK) | 
| 780 | 
  | 
                fprintf(out, "\n0\n3 %g %g %g\n", sinf->mult, | 
| 781 | 
< | 
                                sinf->l, sinf->h); | 
| 781 | 
> | 
                                sinf->w, sinf->h); | 
| 782 | 
  | 
        else | 
| 783 | 
  | 
                fprintf(out, "\n0\n4 %g %g %g %g\n", sinf->mult, | 
| 784 | 
  | 
                                sinf->l, sinf->w, sinf->h); | 
| 785 | 
  | 
        if (putsource(sinf, out, id, filename(name), | 
| 786 | 
< | 
                        bounds[0][0]<90., bounds[0][1]>90.) != 0) | 
| 786 | 
> | 
                        dolower, doupper, dosides) != 0) | 
| 787 | 
  | 
                return(-1); | 
| 788 | 
  | 
        return(0); | 
| 789 | 
  | 
} | 
| 790 | 
  | 
 | 
| 791 | 
  | 
 | 
| 792 | 
< | 
putsource(shp, fp, mod, name, dolower, doupper)         /* put out source */ | 
| 793 | 
< | 
SRCINFO *shp; | 
| 794 | 
< | 
FILE    *fp; | 
| 795 | 
< | 
char    *mod, *name; | 
| 796 | 
< | 
int     dolower, doupper; | 
| 792 | 
> | 
int | 
| 793 | 
> | 
putsource( /* put out source */ | 
| 794 | 
> | 
        SRCINFO *shp, | 
| 795 | 
> | 
        FILE    *fp, | 
| 796 | 
> | 
        char    *mod, | 
| 797 | 
> | 
        char    *name, | 
| 798 | 
> | 
        int     dolower, | 
| 799 | 
> | 
        int     doupper, | 
| 800 | 
> | 
        int dosides | 
| 801 | 
> | 
) | 
| 802 | 
  | 
{ | 
| 803 | 
< | 
        int     dosides = doupper && dolower && shp->h > MINDIM; | 
| 726 | 
< | 
        char    lname[MAXWORD]; | 
| 803 | 
> | 
        char    lname[RMAXWORD]; | 
| 804 | 
  | 
         | 
| 805 | 
  | 
        strcat(strcpy(lname, name), "_light"); | 
| 806 | 
  | 
        fprintf(fp, "\n%s %s %s\n", mod, | 
| 832 | 
  | 
} | 
| 833 | 
  | 
 | 
| 834 | 
  | 
 | 
| 835 | 
< | 
makeshape(shp, width, length, height)           /* make source shape */ | 
| 836 | 
< | 
register SRCINFO        *shp; | 
| 837 | 
< | 
double  width, length, height; | 
| 835 | 
> | 
int | 
| 836 | 
> | 
makeshape(              /* make source shape */ | 
| 837 | 
> | 
        SRCINFO *shp, | 
| 838 | 
> | 
        double  width, | 
| 839 | 
> | 
        double  length, | 
| 840 | 
> | 
        double  height | 
| 841 | 
> | 
) | 
| 842 | 
  | 
{ | 
| 843 | 
  | 
        if (illumrad/meters2out >= MINDIM/2.) { | 
| 844 | 
  | 
                shp->isillum = 1; | 
| 885 | 
  | 
} | 
| 886 | 
  | 
 | 
| 887 | 
  | 
 | 
| 888 | 
< | 
putrectsrc(shp, fp, mod, name, up)              /* rectangular source */ | 
| 889 | 
< | 
SRCINFO *shp; | 
| 890 | 
< | 
FILE    *fp; | 
| 891 | 
< | 
char    *mod, *name; | 
| 892 | 
< | 
int     up; | 
| 888 | 
> | 
void | 
| 889 | 
> | 
putrectsrc(             /* rectangular source */ | 
| 890 | 
> | 
        SRCINFO *shp, | 
| 891 | 
> | 
        FILE    *fp, | 
| 892 | 
> | 
        char    *mod, | 
| 893 | 
> | 
        char    *name, | 
| 894 | 
> | 
        int     up | 
| 895 | 
> | 
) | 
| 896 | 
  | 
{ | 
| 897 | 
  | 
        if (up) | 
| 898 | 
  | 
                putrect(shp, fp, mod, name, ".u", 4, 5, 7, 6); | 
| 901 | 
  | 
} | 
| 902 | 
  | 
 | 
| 903 | 
  | 
 | 
| 904 | 
< | 
putsides(shp, fp, mod, name)                    /* put out sides of box */ | 
| 905 | 
< | 
register SRCINFO        *shp; | 
| 906 | 
< | 
FILE    *fp; | 
| 907 | 
< | 
char    *mod, *name; | 
| 904 | 
> | 
void | 
| 905 | 
> | 
putsides(                       /* put out sides of box */ | 
| 906 | 
> | 
        SRCINFO *shp, | 
| 907 | 
> | 
        FILE    *fp, | 
| 908 | 
> | 
        char    *mod, | 
| 909 | 
> | 
        char    *name | 
| 910 | 
> | 
) | 
| 911 | 
  | 
{ | 
| 912 | 
  | 
        putrect(shp, fp, mod, name, ".1", 0, 1, 5, 4); | 
| 913 | 
  | 
        putrect(shp, fp, mod, name, ".2", 1, 3, 7, 5); | 
| 916 | 
  | 
} | 
| 917 | 
  | 
         | 
| 918 | 
  | 
 | 
| 919 | 
< | 
putrect(shp, fp, mod, name, suffix, a, b, c, d) /* put out a rectangle */ | 
| 920 | 
< | 
SRCINFO *shp; | 
| 921 | 
< | 
FILE    *fp; | 
| 922 | 
< | 
char    *mod, *name, *suffix; | 
| 923 | 
< | 
int     a, b, c, d; | 
| 919 | 
> | 
void | 
| 920 | 
> | 
putrect(        /* put out a rectangle */ | 
| 921 | 
> | 
        SRCINFO *shp, | 
| 922 | 
> | 
        FILE    *fp, | 
| 923 | 
> | 
        char    *mod, | 
| 924 | 
> | 
        char    *name, | 
| 925 | 
> | 
        char    *suffix, | 
| 926 | 
> | 
        int     a, | 
| 927 | 
> | 
        int b, | 
| 928 | 
> | 
        int c, | 
| 929 | 
> | 
        int d | 
| 930 | 
> | 
) | 
| 931 | 
  | 
{ | 
| 932 | 
  | 
        fprintf(fp, "\n%s polygon %s%s\n0\n0\n12\n", mod, name, suffix); | 
| 933 | 
  | 
        putpoint(shp, fp, a); | 
| 937 | 
  | 
} | 
| 938 | 
  | 
 | 
| 939 | 
  | 
 | 
| 940 | 
< | 
putpoint(shp, fp, p)                            /* put out a point */ | 
| 941 | 
< | 
register SRCINFO        *shp; | 
| 942 | 
< | 
FILE    *fp; | 
| 943 | 
< | 
int     p; | 
| 940 | 
> | 
void | 
| 941 | 
> | 
putpoint(                               /* put out a point */ | 
| 942 | 
> | 
        SRCINFO *shp, | 
| 943 | 
> | 
        FILE    *fp, | 
| 944 | 
> | 
        int     p | 
| 945 | 
> | 
) | 
| 946 | 
  | 
{ | 
| 947 | 
  | 
        static double   mult[2] = {-.5, .5}; | 
| 948 | 
  | 
 | 
| 953 | 
  | 
} | 
| 954 | 
  | 
 | 
| 955 | 
  | 
 | 
| 956 | 
< | 
putdisksrc(shp, fp, mod, name, up)              /* put out a disk source */ | 
| 957 | 
< | 
register SRCINFO        *shp; | 
| 958 | 
< | 
FILE    *fp; | 
| 959 | 
< | 
char    *mod, *name; | 
| 960 | 
< | 
int     up; | 
| 956 | 
> | 
void | 
| 957 | 
> | 
putdisksrc(             /* put out a disk source */ | 
| 958 | 
> | 
        SRCINFO *shp, | 
| 959 | 
> | 
        FILE    *fp, | 
| 960 | 
> | 
        char    *mod, | 
| 961 | 
> | 
        char    *name, | 
| 962 | 
> | 
        int     up | 
| 963 | 
> | 
) | 
| 964 | 
  | 
{ | 
| 965 | 
  | 
        if (up) { | 
| 966 | 
  | 
                fprintf(fp, "\n%s ring %s.u\n", mod, name); | 
| 978 | 
  | 
} | 
| 979 | 
  | 
 | 
| 980 | 
  | 
 | 
| 981 | 
< | 
putcyl(shp, fp, mod, name)                      /* put out a cylinder */ | 
| 982 | 
< | 
register SRCINFO        *shp; | 
| 983 | 
< | 
FILE    *fp; | 
| 984 | 
< | 
char    *mod, *name; | 
| 981 | 
> | 
void | 
| 982 | 
> | 
putcyl(                 /* put out a cylinder */ | 
| 983 | 
> | 
        SRCINFO *shp, | 
| 984 | 
> | 
        FILE    *fp, | 
| 985 | 
> | 
        char    *mod, | 
| 986 | 
> | 
        char    *name | 
| 987 | 
> | 
) | 
| 988 | 
  | 
{ | 
| 989 | 
  | 
        fprintf(fp, "\n%s cylinder %s.c\n", mod, name); | 
| 990 | 
  | 
        fprintf(fp, "0\n0\n7\n"); | 
| 994 | 
  | 
} | 
| 995 | 
  | 
 | 
| 996 | 
  | 
 | 
| 997 | 
< | 
putspheresrc(shp, fp, mod, name)                /* put out a sphere source */ | 
| 998 | 
< | 
SRCINFO *shp; | 
| 999 | 
< | 
FILE    *fp; | 
| 1000 | 
< | 
char    *mod, *name; | 
| 997 | 
> | 
void | 
| 998 | 
> | 
putspheresrc(           /* put out a sphere source */ | 
| 999 | 
> | 
        SRCINFO *shp, | 
| 1000 | 
> | 
        FILE    *fp, | 
| 1001 | 
> | 
        char    *mod, | 
| 1002 | 
> | 
        char    *name | 
| 1003 | 
> | 
) | 
| 1004 | 
  | 
{ | 
| 1005 | 
  | 
        fprintf(fp, "\n%s sphere %s.s\n", mod, name); | 
| 1006 | 
  | 
        fprintf(fp, "0\n0\n4 0 0 0 %g\n", .5*shp->w*meters2out); | 
| 1007 | 
  | 
} | 
| 1008 | 
  | 
 | 
| 1009 | 
  | 
 | 
| 1010 | 
< | 
cvdata(in, out, ndim, npts, mult, lim)          /* convert data */ | 
| 1011 | 
< | 
FILE    *in, *out; | 
| 1012 | 
< | 
int     ndim, npts[]; | 
| 1013 | 
< | 
double  mult, lim[][2]; | 
| 1010 | 
> | 
int | 
| 1011 | 
> | 
cvdata(         /* convert data */ | 
| 1012 | 
> | 
        FILE    *in, | 
| 1013 | 
> | 
        FILE    *out, | 
| 1014 | 
> | 
        int     ndim, | 
| 1015 | 
> | 
        int     npts[], | 
| 1016 | 
> | 
        double  mult, | 
| 1017 | 
> | 
        double  lim[][2] | 
| 1018 | 
> | 
) | 
| 1019 | 
  | 
{ | 
| 1020 | 
  | 
        double  *pt[4]; | 
| 1021 | 
< | 
        register int    i, j; | 
| 1021 | 
> | 
        int     i, j; | 
| 1022 | 
  | 
        double  val; | 
| 1023 | 
  | 
        int     total; | 
| 1024 | 
  | 
 | 
| 1060 | 
  | 
                                putc('\n', out); | 
| 1061 | 
  | 
                        } | 
| 1062 | 
  | 
                } | 
| 1063 | 
< | 
                free((char *)pt[i]); | 
| 1063 | 
> | 
                free((void *)pt[i]); | 
| 1064 | 
  | 
        } | 
| 1065 | 
  | 
        for (i = 0; i < total; i++) { | 
| 1066 | 
  | 
                if (i%4 == 0) | 
| 1075 | 
  | 
 | 
| 1076 | 
  | 
 | 
| 1077 | 
  | 
char * | 
| 1078 | 
< | 
getword(fp)                     /* scan a word from fp */ | 
| 1079 | 
< | 
register FILE   *fp; | 
| 1078 | 
> | 
getword(                        /* scan a word from fp */ | 
| 1079 | 
> | 
        FILE    *fp | 
| 1080 | 
> | 
) | 
| 1081 | 
  | 
{ | 
| 1082 | 
< | 
        static char     wrd[MAXWORD]; | 
| 1083 | 
< | 
        register char   *cp; | 
| 1084 | 
< | 
        register int    c; | 
| 1082 | 
> | 
        static char     wrd[RMAXWORD]; | 
| 1083 | 
> | 
        char    *cp; | 
| 1084 | 
> | 
        int     c; | 
| 1085 | 
  | 
 | 
| 1086 | 
  | 
        while (isspace(c=getc(fp))) | 
| 1087 | 
  | 
                ; | 
| 1088 | 
< | 
        for (cp = wrd; c != EOF && cp < wrd+MAXWORD-1; | 
| 1088 | 
> | 
        for (cp = wrd; c != EOF && cp < wrd+RMAXWORD-1; | 
| 1089 | 
  | 
                        *cp++ = c, c = getc(fp)) | 
| 1090 | 
  | 
                if (isspace(c) || c == ',') { | 
| 1091 | 
  | 
                        while (isspace(c)) | 
| 1092 | 
  | 
                                c = getc(fp); | 
| 1093 | 
< | 
                        if (c != EOF & c != ',') | 
| 1093 | 
> | 
                        if ((c != EOF) & (c != ',')) | 
| 1094 | 
  | 
                                ungetc(c, fp); | 
| 1095 | 
  | 
                        *cp = '\0'; | 
| 1096 | 
  | 
                        return(wrd); | 
| 1100 | 
  | 
} | 
| 1101 | 
  | 
 | 
| 1102 | 
  | 
 | 
| 1103 | 
< | 
cvtint(ip, wrd)                 /* convert a word to an integer */ | 
| 1104 | 
< | 
int     *ip; | 
| 1105 | 
< | 
char    *wrd; | 
| 1103 | 
> | 
int | 
| 1104 | 
> | 
cvtint(                 /* convert a word to an integer */ | 
| 1105 | 
> | 
        int     *ip, | 
| 1106 | 
> | 
        char    *wrd | 
| 1107 | 
> | 
) | 
| 1108 | 
  | 
{ | 
| 1109 | 
  | 
        if (wrd == NULL || !isint(wrd)) | 
| 1110 | 
  | 
                return(0); | 
| 1113 | 
  | 
} | 
| 1114 | 
  | 
 | 
| 1115 | 
  | 
 | 
| 1116 | 
< | 
cvtflt(rp, wrd)                 /* convert a word to a double */ | 
| 1117 | 
< | 
double  *rp; | 
| 1118 | 
< | 
char    *wrd; | 
| 1116 | 
> | 
int | 
| 1117 | 
> | 
cvtflt(                 /* convert a word to a double */ | 
| 1118 | 
> | 
        double  *rp, | 
| 1119 | 
> | 
        char    *wrd | 
| 1120 | 
> | 
) | 
| 1121 | 
  | 
{ | 
| 1122 | 
  | 
        if (wrd == NULL || !isflt(wrd)) | 
| 1123 | 
  | 
                return(0); | 
| 1126 | 
  | 
} | 
| 1127 | 
  | 
 | 
| 1128 | 
  | 
 | 
| 1129 | 
< | 
cvgeometry(inpname, sinf, outname, outfp) | 
| 1130 | 
< | 
char    *inpname; | 
| 1131 | 
< | 
register SRCINFO        *sinf; | 
| 1132 | 
< | 
char    *outname; | 
| 1133 | 
< | 
FILE    *outfp;                 /* close output file upon return */ | 
| 1129 | 
> | 
int | 
| 1130 | 
> | 
cvgeometry( | 
| 1131 | 
> | 
        char    *inpname, | 
| 1132 | 
> | 
        SRCINFO *sinf, | 
| 1133 | 
> | 
        char    *outname, | 
| 1134 | 
> | 
        FILE    *outfp                  /* close output file upon return */ | 
| 1135 | 
> | 
) | 
| 1136 | 
  | 
{ | 
| 1137 | 
  | 
        char    buf[256]; | 
| 1138 | 
< | 
        register char   *cp; | 
| 1138 | 
> | 
        char    *cp; | 
| 1139 | 
  | 
 | 
| 1140 | 
  | 
        if (inpname == NULL || !inpname[0]) {   /* no geometry file */ | 
| 1141 | 
  | 
                fclose(outfp); | 
| 1145 | 
  | 
        strcpy(buf, "mgf2rad ");                /* build mgf2rad command */ | 
| 1146 | 
  | 
        cp = buf+8; | 
| 1147 | 
  | 
        if (!FEQ(sinf->mult, 1.0)) { | 
| 1148 | 
< | 
                sprintf(cp, "-m %f ", sinf->mult); | 
| 1148 | 
> | 
                sprintf(cp, "-e %f ", sinf->mult); | 
| 1149 | 
  | 
                cp += strlen(cp); | 
| 1150 | 
  | 
        } | 
| 1151 | 
  | 
        sprintf(cp, "-g %f %s ", | 
| 1155 | 
  | 
        if (instantiate) {              /* instantiate octree */ | 
| 1156 | 
  | 
                strcpy(cp, "| oconv - > "); | 
| 1157 | 
  | 
                cp += 12; | 
| 1158 | 
< | 
                fullname(cp,outname,T_OCT); | 
| 1158 | 
> | 
                fullnam(cp,outname,T_OCT); | 
| 1159 | 
  | 
                if (fdate(inpname) > fdate(outname) && | 
| 1160 | 
  | 
                                system(buf)) {          /* create octree */ | 
| 1161 | 
  | 
                        fclose(outfp); | 
| 1179 | 
  | 
                        fclose(outfp); | 
| 1180 | 
  | 
                        strcpy(cp, ">> ");      /* append works for DOS? */ | 
| 1181 | 
  | 
                        cp += 3; | 
| 1182 | 
< | 
                        fullname(cp,outname,T_RAD); | 
| 1182 | 
> | 
                        fullnam(cp,outname,T_RAD); | 
| 1183 | 
  | 
                } | 
| 1184 | 
  | 
                if (system(buf)) | 
| 1185 | 
  | 
                        return(-1); |