--- ray/src/rt/data.c 1996/02/15 18:46:54 2.12 +++ ray/src/rt/data.c 2013/08/07 05:10:09 2.30 @@ -1,27 +1,28 @@ -/* Copyright (c) 1996 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: data.c,v 2.30 2013/08/07 05:10:09 greg Exp $"; #endif - /* * data.c - routines dealing with interpolated data. */ -#include "standard.h" +#include "copyright.h" -#include "color.h" +#include +#include "platform.h" +#include "paths.h" +#include "standard.h" +#include "color.h" #include "resolu.h" - +#include "view.h" #include "data.h" /* picture memory usage before warning */ #ifndef PSIZWARN -#ifdef BIGMEM +#ifdef SMLMEM #define PSIZWARN 3000000 #else -#define PSIZWARN 1000000 +#define PSIZWARN 10000000 #endif #endif @@ -32,25 +33,25 @@ static char SCCSid[] = "$SunId$ LBL"; #define hash(s) (shash(s)%TABSIZ) -extern char *getlibpath(); /* library search path */ - static DATARRAY *dtab[TABSIZ]; /* data array list */ +static gethfunc headaspect; -DATARRAY * -getdata(dname) /* get data array dname */ -char *dname; + +extern DATARRAY * +getdata( /* get data array dname */ + char *dname +) { char *dfname; FILE *fp; - int asize; + int asize=0; register int i, j; register DATARRAY *dp; /* look for array in list */ for (dp = dtab[hash(dname)]; dp != NULL; dp = dp->next) if (!strcmp(dname, dp->name)) return(dp); /* found! */ - /* * If we haven't loaded the data already, we will look * for it in the directories specified by the library path. @@ -71,7 +72,7 @@ char *dname; * 0 0 ni p0i p1i .. pni */ - if ((dfname = getpath(dname, getlibpath(), R_OK)) == NULL) { + if ((dfname = getpath(dname, getrlibpath(), R_OK)) == NULL) { sprintf(errmsg, "cannot find data file \"%s\"", dname); error(USER, errmsg); } @@ -80,9 +81,9 @@ char *dname; error(SYSTEM, errmsg); } /* get dimensions */ - if (fgetval(fp, 'i', &asize) <= 0) + if (fgetval(fp, 'i', (char *)&asize) <= 0) goto scanerr; - if (asize <= 0 | asize > MAXDDIM) { + if ((asize <= 0) | (asize > MAXDDIM)) { sprintf(errmsg, "bad number of dimensions for \"%s\"", dname); error(USER, errmsg); } @@ -93,11 +94,11 @@ char *dname; dp->nd = asize; asize = 1; for (i = 0; i < dp->nd; i++) { - if (fgetval(fp, DATATY, &dp->dim[i].org) <= 0) + if (fgetval(fp, DATATY, (char *)&dp->dim[i].org) <= 0) goto scanerr; - if (fgetval(fp, DATATY, &dp->dim[i].siz) <= 0) + if (fgetval(fp, DATATY, (char *)&dp->dim[i].siz) <= 0) goto scanerr; - if (fgetval(fp, 'i', &dp->dim[i].ne) <= 0) + if (fgetval(fp, 'i', (char *)&dp->dim[i].ne) <= 0) goto scanerr; if (dp->dim[i].ne < 2) goto scanerr; @@ -108,7 +109,8 @@ char *dname; if (dp->dim[i].p == NULL) goto memerr; for (j = 0; j < dp->dim[i].ne; j++) - if (fgetval(fp, DATATY, &dp->dim[i].p[j]) <= 0) + if (fgetval(fp, DATATY, + (char *)&dp->dim[i].p[j]) <= 0) goto scanerr; for (j = 1; j < dp->dim[i].ne-1; j++) if ((dp->dim[i].p[j-1] < dp->dim[i].p[j]) != @@ -124,7 +126,7 @@ char *dname; goto memerr; for (i = 0; i < asize; i++) - if (fgetval(fp, DATATY, &dp->arr.d[i]) <= 0) + if (fgetval(fp, DATATY, (char *)&dp->arr.d[i]) <= 0) goto scanerr; fclose(fp); i = hash(dname); @@ -137,22 +139,30 @@ scanerr: sprintf(errmsg, "%s in data file \"%s\"", feof(fp) ? "unexpected EOF" : "bad format", dfname); error(USER, errmsg); + return NULL; /* pro forma return */ } -static -headaspect(s, iap) /* check string for aspect ratio */ -char *s; -double *iap; +static int +headaspect( /* check string for aspect ratio */ + char *s, + void *iap +) { + char fmt[32]; + if (isaspect(s)) - *iap *= aspectval(s); + *(double*)iap *= aspectval(s); + else if (formatval(fmt, s) && !globmatch(PICFMT, fmt)) + *(double*)iap = 0.0; + return(0); } -DATARRAY * -getpict(pname) /* get picture pname */ -char *pname; +extern DATARRAY * +getpict( /* get picture pname */ + char *pname +) { double inpaspect; char *pfname; @@ -160,7 +170,7 @@ char *pname; COLR *scanin; int sl, ns; RESOLU inpres; - FLOAT loc[2]; + RREAL loc[2]; int y; register int x, i; register DATARRAY *pp; @@ -169,7 +179,7 @@ char *pname; if (!strcmp(pname, pp->name)) return(pp); /* found! */ - if ((pfname = getpath(pname, getlibpath(), R_OK)) == NULL) { + if ((pfname = getpath(pname, getrlibpath(), R_OK)) == NULL) { sprintf(errmsg, "cannot find picture file \"%s\"", pname); error(USER, errmsg); } @@ -182,13 +192,11 @@ char *pname; sprintf(errmsg, "cannot open picture file \"%s\"", pfname); error(SYSTEM, errmsg); } -#ifdef MSDOS - setmode(fileno(fp), O_BINARY); -#endif + SET_FILE_BINARY(fp); /* get dimensions */ inpaspect = 1.0; getheader(fp, headaspect, &inpaspect); - if (!fgetsresolu(&inpres, fp)) + if (inpaspect <= FTINY || !fgetsresolu(&inpres, fp)) goto readerr; pp[0].nd = 2; pp[0].dim[0].ne = inpres.yr; @@ -210,8 +218,8 @@ char *pname; i = ns*sl*sizeof(COLR); #if PSIZWARN if (i > PSIZWARN) { /* memory warning */ - sprintf(errmsg, "picture file \"%s\" using %d bytes of memory", - pname, i); + sprintf(errmsg, "picture file \"%s\" using %.1f MB of memory", + pname, i*(1.0/(1024*1024))); error(WARNING, errmsg); } #endif @@ -230,12 +238,12 @@ char *pname; copycolr(pp[0].arr.c[i], scanin[x]); } } - free((char *)scanin); + free((void *)scanin); fclose(fp); i = hash(pname); pp[0].next = dtab[i]; /* link into picture list */ - copystruct(&pp[1], &pp[0]); - copystruct(&pp[2], &pp[0]); + pp[1] = pp[0]; + pp[2] = pp[0]; pp[0].type = RED; /* differentiate RGB records */ pp[1].type = GRN; pp[2].type = BLU; @@ -246,37 +254,40 @@ memerr: readerr: sprintf(errmsg, "bad picture file \"%s\"", pfname); error(USER, errmsg); + return NULL; /* pro forma return */ } -freedata(dname) /* free memory associated with dname */ -char *dname; +extern void +freedata( /* release data array reference */ + DATARRAY *dta +) { DATARRAY head; int hval, nents; - register DATARRAY *dp, *dpl; + register DATARRAY *dpl, *dp; register int i; - if (dname == NULL) { /* free all if NULL */ + if (dta == NULL) { /* free all if NULL */ hval = 0; nents = TABSIZ; } else { - hval = hash(dname); nents = 1; + hval = hash(dta->name); nents = 1; } while (nents--) { head.next = dtab[hval]; dpl = &head; while ((dp = dpl->next) != NULL) - if (dname == NULL || !strcmp(dname, dp->name)) { + if ((dta == NULL) | (dta == dp)) { dpl->next = dp->next; if (dp->type == DATATY) - free((char *)dp->arr.d); + free((void *)dp->arr.d); else - free((char *)dp->arr.c); + free((void *)dp->arr.c); for (i = 0; i < dp->nd; i++) if (dp->dim[i].p != NULL) - free((char *)dp->dim[i].p); + free((void *)dp->dim[i].p); freestr(dp->name); - free((char *)dp); + free((void *)dp); } else dpl = dp; dtab[hval++] = head.next; @@ -284,10 +295,11 @@ char *dname; } -double -datavalue(dp, pt) /* interpolate data value at a point */ -register DATARRAY *dp; -double *pt; +extern double +datavalue( /* interpolate data value at a point */ + register DATARRAY *dp, + double *pt +) { DATARRAY sd; int asize;