--- ray/src/rt/data.c 1998/11/05 17:11:56 2.14 +++ ray/src/rt/data.c 2004/03/30 16:13:01 2.27 @@ -1,27 +1,27 @@ -/* 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.27 2004/03/30 16:13:01 schorsch Exp $"; #endif - /* * data.c - routines dealing with interpolated data. */ -#include "standard.h" +#include "copyright.h" -#include "color.h" +#include +#include "platform.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 -#define PSIZWARN 5000000 -#else +#ifdef SMLMEM #define PSIZWARN 1500000 +#else +#define PSIZWARN 5000000 #endif #endif @@ -32,14 +32,15 @@ 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; @@ -50,7 +51,6 @@ char *dname; 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 +71,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 +80,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 +93,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 +108,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 +125,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,27 +138,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); - else if (formatval(fmt, s) && strcmp(fmt, COLRFMT)) - *iap = 0.0; + *(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; @@ -165,7 +169,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; @@ -174,7 +178,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); } @@ -187,9 +191,7 @@ 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); @@ -235,12 +237,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; @@ -251,37 +253,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; @@ -289,10 +294,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;