ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/data.c
(Generate patch)

Comparing ray/src/rt/data.c (file contents):
Revision 2.7 by greg, Mon Feb 8 13:12:28 1993 UTC vs.
Revision 2.36 by greg, Wed Dec 13 23:26:16 2023 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1993 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   *  data.c - routines dealing with interpolated data.
9 *
10 *     6/4/86
6   */
7  
8 < #include  "standard.h"
8 > #include "copyright.h"
9  
10 < #include  "color.h"
10 > #include  <time.h>
11  
12 + #include  "platform.h"
13 + #include  "paths.h"
14 + #include  "standard.h"
15 + #include  "color.h"
16   #include  "resolu.h"
17 <
17 > #include  "view.h"
18   #include  "data.h"
19  
20                                  /* picture memory usage before warning */
21   #ifndef PSIZWARN
22 < #ifdef BIGMEM
22 > #ifdef SMLMEM
23   #define PSIZWARN        3000000
24   #else
25 < #define PSIZWARN        1000000
25 > #define PSIZWARN        50000000
26   #endif
27   #endif
28  
29   #ifndef TABSIZ
30 < #define TABSIZ          97              /* table size (prime) */
30 > #define TABSIZ          997             /* table size (prime) */
31   #endif
32  
33   #define hash(s)         (shash(s)%TABSIZ)
34  
35  
37 extern char  *fgetword();
38
39 extern char  *libpath;                  /* library search path */
40
36   static DATARRAY  *dtab[TABSIZ];         /* data array list */
37  
38 < static DATARRAY  *ptab[TABSIZ];         /* picture list */
38 > static gethfunc headaspect;
39  
40  
41   DATARRAY *
42 < getdata(dname)                          /* get data array dname */
43 < char  *dname;
42 > getdata(                                /* get data array dname */
43 >        char  *dname
44 > )
45   {
50        char  word[64];
46          char  *dfname;
47          FILE  *fp;
48 <        int  asize;
49 <        register int  i, j;
50 <        register DATARRAY  *dp;
48 >        int  asize=0;
49 >        int  i, j;
50 >        DATARRAY  *dp;
51                                                  /* look for array in list */
52          for (dp = dtab[hash(dname)]; dp != NULL; dp = dp->next)
53                  if (!strcmp(dname, dp->name))
54                          return(dp);             /* found! */
60
55          /*
56           *      If we haven't loaded the data already, we will look
57           *  for it in the directories specified by the library path.
# Line 78 | Line 72 | char  *dname;
72           *              0 0 ni p0i p1i .. pni
73           */
74  
75 <        if ((dfname = getpath(dname, libpath, R_OK)) == NULL) {
75 >        if ((dfname = getpath(dname, getrlibpath(), R_OK)) == NULL) {
76                  sprintf(errmsg, "cannot find data file \"%s\"", dname);
77 <                error(USER, errmsg);
77 >                error(SYSTEM, errmsg);
78          }
85        if ((dp = (DATARRAY *)malloc(sizeof(DATARRAY))) == NULL)
86                goto memerr;
87
88        dp->name = savestr(dname);
89
79          if ((fp = fopen(dfname, "r")) == NULL) {
80                  sprintf(errmsg, "cannot open data file \"%s\"", dfname);
81                  error(SYSTEM, errmsg);
82          }
83                                                          /* get dimensions */
84 <        if (fgetword(word, sizeof(word), fp) == NULL || !isint(word))
84 >        if (fgetval(fp, 'i', &asize) <= 0)
85                  goto scanerr;
86 <        dp->nd = atoi(word);
98 <        if (dp->nd <= 0 || dp->nd > MAXDDIM) {
86 >        if ((asize <= 0) | (asize > MAXDDIM)) {
87                  sprintf(errmsg, "bad number of dimensions for \"%s\"", dname);
88                  error(USER, errmsg);
89          }
90 +        if ((dp = (DATARRAY *)malloc(sizeof(DATARRAY))) == NULL)
91 +                goto memerr;
92 +        dp->name = savestr(dname);
93 +        dp->type = DATATY;
94 +        dp->nd = asize;
95          asize = 1;
96          for (i = 0; i < dp->nd; i++) {
97 <                if (fgetword(word, sizeof(word), fp) == NULL || !isflt(word))
97 >                if (fgetval(fp, DATATY, &dp->dim[i].org) <= 0)
98                          goto scanerr;
99 <                dp->dim[i].org = atof(word);
107 <                if (fgetword(word, sizeof(word), fp) == NULL || !isflt(word))
99 >                if (fgetval(fp, DATATY, &dp->dim[i].siz) <= 0)
100                          goto scanerr;
101 <                dp->dim[i].siz = atof(word);
110 <                if (fgetword(word, sizeof(word), fp) == NULL || !isint(word))
101 >                if (fgetval(fp, 'i', &dp->dim[i].ne) <= 0)
102                          goto scanerr;
112                dp->dim[i].ne = atoi(word);
103                  if (dp->dim[i].ne < 2)
104                          goto scanerr;
105                  asize *= dp->dim[i].ne;
106                  if ((dp->dim[i].siz -= dp->dim[i].org) == 0) {
107 <                        dp->dim[i].p = (double *)malloc(dp->dim[i].ne*sizeof(double));
107 >                        dp->dim[i].p = (DATATYPE *)
108 >                                        malloc(dp->dim[i].ne*sizeof(DATATYPE));
109                          if (dp->dim[i].p == NULL)
110                                  goto memerr;
111 <                        for (j = 0; j < dp->dim[i].ne; j++) {
112 <                                if (fgetword(word, sizeof(word), fp) == NULL ||
122 <                                                !isflt(word))
111 >                        for (j = 0; j < dp->dim[i].ne; j++)
112 >                                if (fgetval(fp, DATATY, &dp->dim[i].p[j]) <= 0)
113                                          goto scanerr;
124                                dp->dim[i].p[j] = atof(word);
125                        }
114                          for (j = 1; j < dp->dim[i].ne-1; j++)
115                                  if ((dp->dim[i].p[j-1] < dp->dim[i].p[j]) !=
116                                          (dp->dim[i].p[j] < dp->dim[i].p[j+1]))
# Line 133 | Line 121 | char  *dname;
121                  } else
122                          dp->dim[i].p = NULL;
123          }
124 <        if ((dp->arr = (DATATYPE *)malloc(asize*sizeof(DATATYPE))) == NULL)
124 >        if ((dp->arr.d = (DATATYPE *)malloc(asize*sizeof(DATATYPE))) == NULL)
125                  goto memerr;
126          
127 <        for (i = 0; i < asize; i++) {
128 <                if (fgetword(word, sizeof(word), fp) == NULL || !isflt(word))
127 >        for (i = 0; i < asize; i++)
128 >                if (fgetval(fp, DATATY, &dp->arr.d[i]) <= 0)
129                          goto scanerr;
142                dp->arr[i] = atof(word);
143        }
130          fclose(fp);
131          i = hash(dname);
132          dp->next = dtab[i];
133          return(dtab[i] = dp);
148
134   memerr:
135          error(SYSTEM, "out of memory in getdata");
136   scanerr:
137          sprintf(errmsg, "%s in data file \"%s\"",
138                          feof(fp) ? "unexpected EOF" : "bad format", dfname);
139          error(USER, errmsg);
140 +        return NULL;    /* pro forma return */
141   }
142  
143  
144 < static
145 < headaspect(s, iap)                      /* check string for aspect ratio */
146 < char  *s;
147 < double  *iap;
144 > static int
145 > headaspect(                     /* check string for aspect ratio */
146 >        char  *s,
147 >        void  *iap
148 > )
149   {
150 +        char    fmt[MAXFMTLEN];
151 +
152          if (isaspect(s))
153 <                *iap *= aspectval(s);
153 >                *(double*)iap *= aspectval(s);
154 >        else if (formatval(fmt, s) && strcmp(fmt, COLRFMT))
155 >                *(double*)iap = 0.0;
156 >        return(0);
157   }
158  
167
159   DATARRAY *
160 < getpict(pname)                          /* get picture pname */
161 < char  *pname;
160 > getpict(                                /* get picture pname */
161 >        char  *pname
162 > )
163   {
172        extern char  *libpath;
164          double  inpaspect;
165          char  *pfname;
166          FILE  *fp;
167 <        COLOR  *scanin;
167 >        COLR  *scanin;
168          int  sl, ns;
169          RESOLU  inpres;
170 <        FLOAT  loc[2];
170 >        RREAL  loc[2];
171          int  y;
172 <        register int  x, i;
173 <        register DATARRAY  *pp;
172 >        int  x, i;
173 >        DATARRAY  *pp;
174                                                  /* look for array in list */
175 <        for (pp = ptab[hash(pname)]; pp != NULL; pp = pp->next)
175 >        for (pp = dtab[hash(pname)]; pp != NULL; pp = pp->next)
176                  if (!strcmp(pname, pp->name))
177                          return(pp);             /* found! */
178  
179 <        if ((pfname = getpath(pname, libpath, R_OK)) == NULL) {
179 >        if ((pfname = getpath(pname, getrlibpath(), R_OK)) == NULL) {
180                  sprintf(errmsg, "cannot find picture file \"%s\"", pname);
181 <                error(USER, errmsg);
181 >                error(SYSTEM, errmsg);
182          }
183 <        if ((pp = (DATARRAY *)calloc(3, sizeof(DATARRAY))) == NULL)
183 >        if ((pp = (DATARRAY *)malloc(3*sizeof(DATARRAY))) == NULL)
184                  goto memerr;
185  
186 <        pp[0].name =
196 <        pp[1].name =
197 <        pp[2].name = savestr(pname);
186 >        pp[0].name = savestr(pname);
187  
188 <        if ((fp = fopen(pfname, "r")) == NULL) {
188 >        if ((fp = fopen(pfname, "rb")) == NULL) {
189                  sprintf(errmsg, "cannot open picture file \"%s\"", pfname);
190                  error(SYSTEM, errmsg);
191          }
203 #ifdef MSDOS
204        setmode(fileno(fp), O_BINARY);
205 #endif
192                                                  /* get dimensions */
193          inpaspect = 1.0;
194          getheader(fp, headaspect, &inpaspect);
195 <        if (!fgetsresolu(&inpres, fp))
195 >        if (inpaspect <= FTINY || !fgetsresolu(&inpres, fp))
196                  goto readerr;
197 +        pp[0].nd = 2;
198 +        pp[0].dim[0].ne = inpres.yr;
199 +        pp[0].dim[1].ne = inpres.xr;
200 +        pp[0].dim[0].org =
201 +        pp[0].dim[1].org = 0.0;
202 +        if (inpres.xr <= inpres.yr*inpaspect) {
203 +                pp[0].dim[0].siz = inpaspect *
204 +                                        (double)inpres.yr/inpres.xr;
205 +                pp[0].dim[1].siz = 1.0;
206 +        } else {
207 +                pp[0].dim[0].siz = 1.0;
208 +                pp[0].dim[1].siz = (double)inpres.xr/inpres.yr /
209 +                                        inpaspect;
210 +        }
211 +        pp[0].dim[0].p = pp[0].dim[1].p = NULL;
212 +        sl = scanlen(&inpres);                          /* allocate array */
213 +        ns = numscans(&inpres);
214 +        i = ns*sl*sizeof(COLR);
215   #if PSIZWARN
216 <                                                /* check memory usage */
217 <        i = 3*sizeof(DATATYPE)*inpres.xr*inpres.yr;
218 <        if (i > PSIZWARN) {
215 <                sprintf(errmsg, "picture file \"%s\" using %d bytes of memory",
216 <                                pname, i);
216 >        if (i > PSIZWARN) {                             /* memory warning */
217 >                sprintf(errmsg, "picture file \"%s\" using %.1f MB of memory",
218 >                                pname, i*(1.0/(1024*1024)));
219                  error(WARNING, errmsg);
220          }
221   #endif
222 <        for (i = 0; i < 3; i++) {
223 <                pp[i].nd = 2;
222 <                pp[i].dim[0].ne = inpres.yr;
223 <                pp[i].dim[1].ne = inpres.xr;
224 <                pp[i].dim[0].org =
225 <                pp[i].dim[1].org = 0.0;
226 <                if (inpres.xr <= inpres.yr*inpaspect) {
227 <                        pp[i].dim[0].siz = inpaspect *
228 <                                                (double)inpres.yr/inpres.xr;
229 <                        pp[i].dim[1].siz = 1.0;
230 <                } else {
231 <                        pp[i].dim[0].siz = 1.0;
232 <                        pp[i].dim[1].siz = (double)inpres.xr/inpres.yr /
233 <                                                inpaspect;
234 <                }
235 <                pp[i].dim[0].p = pp[i].dim[1].p = NULL;
236 <                pp[i].arr = (DATATYPE *)
237 <                                malloc(inpres.xr*inpres.yr*sizeof(DATATYPE));
238 <                if (pp[i].arr == NULL)
239 <                        goto memerr;
240 <        }
222 >        if ((pp[0].arr.c = (COLR *)malloc(i)) == NULL)
223 >                goto memerr;
224                                                          /* load picture */
225 <        sl = scanlen(&inpres);
243 <        ns = numscans(&inpres);
244 <        if ((scanin = (COLOR *)malloc(sl*sizeof(COLOR))) == NULL)
225 >        if ((scanin = (COLR *)malloc(sl*sizeof(COLR))) == NULL)
226                  goto memerr;
227          for (y = 0; y < ns; y++) {
228 <                if (freadscan(scanin, sl, fp) < 0)
228 >                if (freadcolrs(scanin, sl, fp) < 0)
229                          goto readerr;
230                  for (x = 0; x < sl; x++) {
231                          pix2loc(loc, &inpres, x, y);
232                          i = (int)(loc[1]*inpres.yr)*inpres.xr +
233                                          (int)(loc[0]*inpres.xr);
234 <                        pp[0].arr[i] = colval(scanin[x],RED);
254 <                        pp[1].arr[i] = colval(scanin[x],GRN);
255 <                        pp[2].arr[i] = colval(scanin[x],BLU);
234 >                        copycolr(pp[0].arr.c[i], scanin[x]);
235                  }
236          }
237 <        free((char *)scanin);
237 >        free(scanin);
238          fclose(fp);
239          i = hash(pname);
240 <        pp[0].next =
241 <        pp[1].next =
242 <        pp[2].next = ptab[i];
243 <        return(ptab[i] = pp);
244 <
240 >        pp[0].next = dtab[i];           /* link into picture list */
241 >        pp[1] = pp[0];
242 >        pp[2] = pp[0];
243 >        pp[0].type = RED;               /* differentiate RGB records */
244 >        pp[1].type = GRN;
245 >        pp[2].type = BLU;
246 >        return(dtab[i] = pp);
247   memerr:
248          error(SYSTEM, "out of memory in getpict");
249   readerr:
250          sprintf(errmsg, "bad picture file \"%s\"", pfname);
251          error(USER, errmsg);
252 +        return NULL;    /* pro forma return */
253   }
254  
255  
256 < freedata(dname)                 /* free memory associated with dname */
257 < char  *dname;
256 > /* header info type for hyperspectral image */
257 > typedef struct {
258 >        float   wlpart[4];      /* wavelength partitions */
259 >        int     nc;             /* number of components */
260 >        double  inpaspect;      /* pixel aspect ratio */
261 > } SPECINFO;
262 >
263 > static int
264 > specheadline(                           /* get info for spectral image */
265 >        char  *s,
266 >        void  *cdp
267 > )
268   {
269 +        SPECINFO        *sip = (SPECINFO *)cdp;
270 +        char            fmt[MAXFMTLEN];
271 +
272 +        if (isaspect(s))
273 +                sip->inpaspect *= aspectval(s);
274 +        else if (isncomp(s))
275 +                sip->nc = ncompval(s);
276 +        else if (iswlsplit(s))
277 +                wlsplitval(sip->wlpart, s);
278 +        else if (formatval(fmt, s) && strcmp(fmt, SPECFMT))
279 +                return(-1);
280 +        return(0);
281 + }
282 +
283 + DATARRAY *
284 + getspec(                /* load hyperspectral image as data */
285 +        char *sname
286 + )
287 + {
288 +        SPECINFO        si;
289 +        char            *pfname;
290 +        FILE            *fp;
291 +        int             sl, ns;
292 +        int             y, i;
293 +        DATARRAY        *pp;
294 +                                                /* look for array in list */
295 +        for (pp = dtab[hash(sname)]; pp != NULL; pp = pp->next)
296 +                if (!strcmp(sname, pp->name))
297 +                        return(pp);             /* found! */
298 +
299 +        if ((pfname = getpath(sname, getrlibpath(), R_OK)) == NULL) {
300 +                sprintf(errmsg, "cannot find hyperspectral image \"%s\"", sname);
301 +                error(SYSTEM, errmsg);
302 +        }
303 +        if ((fp = fopen(pfname, "rb")) == NULL) {
304 +                sprintf(errmsg, "cannot open hyperspectral image \"%s\"", pfname);
305 +                error(SYSTEM, errmsg);
306 +        }
307 +        si.wlpart[3] = 0;
308 +        si.nc = 0;
309 +        si.inpaspect = 1.0;
310 +        if (getheader(fp, specheadline, &si) < 0 ||
311 +                        (si.nc <= 3) | (si.nc > MAXCSAMP) | (si.wlpart[3] < 1) ||
312 +                        !fscnresolu(&sl, &ns, fp))
313 +                goto readerr;
314 +
315 +        if ((pp = (DATARRAY *)malloc(sizeof(DATARRAY))) == NULL)
316 +                goto memerr;
317 +
318 +        pp->name = savestr(sname);
319 +        pp->type = SPECTY;
320 +        pp->nd = 3;
321 +        pp->dim[0].ne = ns;
322 +        pp->dim[1].ne = sl;
323 +        pp->dim[0].org =
324 +        pp->dim[1].org = 0.0;
325 +        if (sl <= ns*si.inpaspect) {
326 +                pp->dim[0].siz = si.inpaspect * (double)ns/sl;
327 +                pp->dim[1].siz = 1.0;
328 +        } else {
329 +                pp->dim[0].siz = 1.0;
330 +                pp->dim[1].siz = (double)sl/ns / si.inpaspect;
331 +        }
332 +        pp->dim[2].ne = si.nc;
333 +        pp->dim[2].siz = si.wlpart[3] - si.wlpart[0];
334 +        pp->dim[2].org = si.wlpart[0] + 0.5*pp->dim[2].siz/si.nc;
335 +        pp->dim[2].siz *= (si.nc - 1.0)/si.nc;
336 +        pp->dim[0].p = pp->dim[1].p = pp->dim[2].p = NULL;
337 +        i = ns*sl*(si.nc+1);
338 + #if PSIZWARN
339 +        if (i > PSIZWARN) {                     /* memory warning */
340 +                sprintf(errmsg, "hyperspectral image \"%s\" using %.1f MB of memory",
341 +                                sname, i*(1.0/(1024*1024)));
342 +                error(WARNING, errmsg);
343 +        }
344 + #endif
345 +        if ((pp->arr.s = (uby8 *)malloc(i)) == NULL)
346 +                goto memerr;
347 +        for (y = 0; y < ns; y++)                /* read each scanline */
348 +                if (freadscolrs(pp->arr.s + y*sl*(si.nc+1), si.nc, sl, fp) < 0)
349 +                        goto readerr;
350 +        fclose(fp);
351 +        i = hash(sname);                        /* insert in hash table */
352 +        pp->next = dtab[i];
353 +        return(dtab[i] = pp);
354 + memerr:
355 +        error(SYSTEM, "out of memory in getspec");
356 + readerr:
357 +        sprintf(errmsg, "bad hyperspectral image \"%s\"", pfname);
358 +        error(USER, errmsg);
359 +        return NULL;    /* pro forma return */
360 + }
361 +
362 +
363 + void
364 + freedata(                       /* release data array reference */
365 +        DATARRAY  *dta
366 + )
367 + {
368          DATARRAY  head;
369          int  hval, nents;
370 <        register DATARRAY  *dp, *dpl;
371 <        register int  i;
370 >        DATARRAY  *dpl, *dp;
371 >        int  i;
372  
373 <        if (dname == NULL) {                    /* free all if NULL */
373 >        if (dta == NULL) {                      /* free all if NULL */
374                  hval = 0; nents = TABSIZ;
375          } else {
376 <                hval = hash(dname); nents = 1;
376 >                hval = hash(dta->name); nents = 1;
377          }
378          while (nents--) {
379                  head.next = dtab[hval];
380                  dpl = &head;
381                  while ((dp = dpl->next) != NULL)
382 <                        if (dname == NULL || !strcmp(dname, dp->name)) {
382 >                        if ((dta == NULL) | (dta == dp)) {
383                                  dpl->next = dp->next;
384 <                                free((char *)dp->arr);
384 >                                free(dp->arr.p);
385                                  for (i = 0; i < dp->nd; i++)
386                                          if (dp->dim[i].p != NULL)
387 <                                                free((char *)dp->dim[i].p);
387 >                                                free(dp->dim[i].p);
388                                  freestr(dp->name);
389 <                                free((char *)dp);
389 >                                free(dp);
390                          } else
391                                  dpl = dp;
392                  dtab[hval++] = head.next;
# Line 303 | Line 394 | char  *dname;
394   }
395  
396  
306 freepict(pname)                 /* free memory associated with pname */
307 char  *pname;
308 {
309        DATARRAY  head;
310        int  hval, nents;
311        register DATARRAY  *pp, *ppl;
312
313        if (pname == NULL) {                    /* free all if NULL */
314                hval = 0; nents = TABSIZ;
315        } else {
316                hval = hash(pname); nents = 1;
317        }
318        while (nents--) {
319                head.next = ptab[hval];
320                ppl = &head;
321                while ((pp = ppl->next) != NULL)
322                        if (pname == NULL || !strcmp(pname, pp->name)) {
323                                ppl->next = pp->next;
324                                free((char *)pp[0].arr);
325                                free((char *)pp[1].arr);
326                                free((char *)pp[2].arr);
327                                freestr(pp[0].name);
328                                free((char *)pp);
329                        } else
330                                ppl = pp;
331                ptab[hval++] = head.next;
332        }
333 }
334
335
397   double
398 < datavalue(dp, pt)               /* interpolate data value at a point */
399 < register DATARRAY  *dp;
400 < double  *pt;
398 > datavalue(              /* interpolate data value at a point */
399 >        DATARRAY  *dp,
400 >        double  *pt
401 > )
402   {
403          DATARRAY  sd;
404          int  asize;
405          int  lower, upper;
406 <        register int  i;
407 <        double  x, y, y0, y1;
406 >        int  i;
407 >        double  x, y0, y1;
408                                          /* set up dimensions for recursion */
409 <        sd.nd = dp->nd - 1;
410 <        asize = 1;
411 <        for (i = 0; i < sd.nd; i++) {
412 <                sd.dim[i].org = dp->dim[i+1].org;
413 <                sd.dim[i].siz = dp->dim[i+1].siz;
414 <                sd.dim[i].p = dp->dim[i+1].p;
415 <                asize *= sd.dim[i].ne = dp->dim[i+1].ne;
409 >        if (dp->nd > 1) {
410 >                sd.name = dp->name;
411 >                sd.type = dp->type;
412 >                sd.nd = dp->nd - 1;
413 >                asize = 1;
414 >                for (i = 0; i < sd.nd; i++) {
415 >                        sd.dim[i].org = dp->dim[i+1].org;
416 >                        sd.dim[i].siz = dp->dim[i+1].siz;
417 >                        sd.dim[i].p = dp->dim[i+1].p;
418 >                        asize *= (sd.dim[i].ne = dp->dim[i+1].ne) +
419 >                                ((sd.type==SPECTY) & (i==sd.nd-1));
420 >                }
421          }
422                                          /* get independent variable */
423          if (dp->dim[0].p == NULL) {             /* evenly spaced points */
424                  x = (pt[0] - dp->dim[0].org)/dp->dim[0].siz;
425 <                x = x * (dp->dim[0].ne - 1);
425 >                x *= (double)(dp->dim[0].ne - 1);
426                  i = x;
427                  if (i < 0)
428                          i = 0;
# Line 376 | Line 443 | double *pt;
443                          else
444                                  upper = i;
445                  } while (i != (lower + upper) >> 1);
446 +
447                  if (i > dp->dim[0].ne - 2)
448                          i = dp->dim[0].ne - 2;
449 +
450                  x = i + (pt[0] - dp->dim[0].p[i]) /
451                                  (dp->dim[0].p[i+1] - dp->dim[0].p[i]);
452          }
453                                          /* get dependent variable */
454 <        if (dp->nd == 1) {
455 <                y0 = dp->arr[i];
456 <                y1 = dp->arr[i+1];
454 >        if (dp->nd > 1) {
455 >                if (dp->type == DATATY) {
456 >                        sd.arr.d = dp->arr.d + i*asize;
457 >                        y0 = datavalue(&sd, pt+1);
458 >                        sd.arr.d += asize;
459 >                        y1 = datavalue(&sd, pt+1);
460 >                } else if (dp->type == SPECTY) {
461 >                        sd.arr.s = dp->arr.s + i*asize;
462 >                        y0 = datavalue(&sd, pt+1);
463 >                        sd.arr.s += asize;
464 >                        y1 = datavalue(&sd, pt+1);
465 >                } else {
466 >                        sd.arr.c = dp->arr.c + i*asize;
467 >                        y0 = datavalue(&sd, pt+1);
468 >                        sd.arr.c += asize;
469 >                        y1 = datavalue(&sd, pt+1);
470 >                }
471          } else {
472 <                sd.arr = &dp->arr[i*asize];
473 <                y0 = datavalue(&sd, pt+1);
474 <                sd.arr = &dp->arr[(i+1)*asize];
475 <                y1 = datavalue(&sd, pt+1);
472 >                if (dp->type == DATATY) {
473 >                        y0 = dp->arr.d[i];
474 >                        y1 = dp->arr.d[i+1];
475 >                } else if (dp->type == SPECTY) {
476 >                        if (dp->arr.s[dp->dim[0].ne]) {
477 >                                double  f = ldexp(1.0, -(COLXS+8) +
478 >                                                (int)dp->arr.s[dp->dim[0].ne]);
479 >                                y0 = (dp->arr.s[i] + 0.5)*f;
480 >                                y1 = (dp->arr.s[i+1] + 0.5)*f;
481 >                        } else
482 >                                y0 = y1 = 0.0;
483 >                } else {
484 >                        y0 = colrval(dp->arr.c[i],dp->type);
485 >                        y1 = colrval(dp->arr.c[i+1],dp->type);
486 >                }
487          }
488          /*
489           * Extrapolate as far as one division, then
490           * taper off harmonically to zero.
491           */
492          if (x > i+2)
493 <                y = (2*y1-y0)/(x-i-1);
400 <        else if (x < i-1)
401 <                y = (2*y0-y1)/(i-x);
402 <        else
403 <                y = y0*((i+1)-x) + y1*(x-i);
493 >                return( (2*y1-y0)/(x-(i-1)) );
494  
495 <        return(y);
495 >        if (x < i-1)
496 >                return( (2*y0-y1)/(i-x) );
497 >
498 >        return( y0*((i+1)-x) + y1*(x-i) );
499   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines