| 1 | greg | 1.1 | /* Copyright (c) 1988 Regents of the University of California */ | 
| 2 |  |  |  | 
| 3 |  |  | #ifndef lint | 
| 4 |  |  | static char SCCSid[] = "$SunId$ LBL"; | 
| 5 |  |  | #endif | 
| 6 |  |  |  | 
| 7 |  |  | /* | 
| 8 |  |  | *  mx_data.c - routine for stored mixtures. | 
| 9 |  |  | * | 
| 10 |  |  | *     11/2/88 | 
| 11 |  |  | */ | 
| 12 |  |  |  | 
| 13 |  |  | #include  "ray.h" | 
| 14 |  |  |  | 
| 15 |  |  | #include  "data.h" | 
| 16 |  |  |  | 
| 17 |  |  | /* | 
| 18 |  |  | *      A stored mixture is specified: | 
| 19 |  |  | * | 
| 20 |  |  | *      modifier mixdata name | 
| 21 |  |  | *      6+ foremod backmod func dfname vfname v0 v1 .. xf | 
| 22 |  |  | *      0 | 
| 23 |  |  | *      n A1 A2 .. | 
| 24 |  |  | * | 
| 25 |  |  | *  Vfname is the name of the file where the variable definitions | 
| 26 |  |  | *  can be found.  The list of real arguments can be accessed by | 
| 27 |  |  | *  definitions in the file.  Dfname is the data file. | 
| 28 |  |  | *  The dimensions of the data files and the number | 
| 29 |  |  | *  of variables must match.  The func is a single argument | 
| 30 |  |  | *  function which returns the corrected data value given the | 
| 31 |  |  | *  interpolated value from the file.  The xf is a transformation | 
| 32 |  |  | *  to get from the original coordinates to the current coordinates. | 
| 33 |  |  | */ | 
| 34 |  |  |  | 
| 35 |  |  |  | 
| 36 |  |  | mx_data(m, r)                   /* interpolate mixture data */ | 
| 37 |  |  | register OBJREC  *m; | 
| 38 |  |  | RAY  *r; | 
| 39 |  |  | { | 
| 40 |  |  | extern double  varvalue(), funvalue(), datavalue(); | 
| 41 |  |  | extern int  errno; | 
| 42 |  |  | register int  i; | 
| 43 |  |  | double  coef; | 
| 44 |  |  | double  pt[MAXDIM]; | 
| 45 |  |  | DATARRAY  *dp; | 
| 46 |  |  | OBJECT  mod[2]; | 
| 47 |  |  | register char  **sa; | 
| 48 |  |  |  | 
| 49 |  |  | setfunc(m, r); | 
| 50 |  |  |  | 
| 51 |  |  | sa = m->oargs.sarg; | 
| 52 |  |  |  | 
| 53 |  |  | if (m->oargs.nsargs < 6) | 
| 54 |  |  | objerror(m, USER, "bad # arguments"); | 
| 55 |  |  | for (i = 0; i < 2; i++) | 
| 56 |  |  | if (!strcmp(sa[i], VOIDID)) | 
| 57 |  |  | mod[i] = OVOID; | 
| 58 |  |  | else if ((mod[i] = modifier(sa[i])) == OVOID) { | 
| 59 |  |  | sprintf(errmsg, "undefined modifier \"%s\"", sa[i]); | 
| 60 |  |  | objerror(m, USER, errmsg); | 
| 61 |  |  | } | 
| 62 | greg | 1.2 | funcfile(sa[4]); | 
| 63 | greg | 1.1 | for (i = 0; i+5 < m->oargs.nsargs && | 
| 64 |  |  | sa[i+5][0] != '-'; i++) { | 
| 65 |  |  | if (i >= MAXDIM) | 
| 66 |  |  | objerror(m, USER, "dimension error"); | 
| 67 |  |  | errno = 0; | 
| 68 |  |  | pt[i] = varvalue(sa[i+5]); | 
| 69 |  |  | if (errno) | 
| 70 |  |  | goto computerr; | 
| 71 |  |  | } | 
| 72 |  |  | dp = getdata(sa[3]); | 
| 73 |  |  | if (dp->nd != i) | 
| 74 |  |  | objerror(m, USER, "dimension error"); | 
| 75 |  |  | coef = datavalue(dp, pt); | 
| 76 |  |  | errno = 0; | 
| 77 |  |  | coef = funvalue(sa[2], 1, &coef); | 
| 78 |  |  | if (errno) | 
| 79 |  |  | goto computerr; | 
| 80 |  |  | raymixture(r, mod[0], mod[1], coef); | 
| 81 |  |  | return; | 
| 82 |  |  |  | 
| 83 |  |  | computerr: | 
| 84 |  |  | objerror(m, WARNING, "compute error"); | 
| 85 |  |  | } |