| 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 |
|
* data.c - routines dealing with interpolated data. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
< |
#include "standard.h" |
| 8 |
> |
#include "copyright.h" |
| 9 |
|
|
| 10 |
< |
#include "color.h" |
| 10 |
> |
#include <time.h> |
| 11 |
|
|
| 12 |
+ |
#include "standard.h" |
| 13 |
+ |
#include "platform.h" |
| 14 |
+ |
#include "color.h" |
| 15 |
|
#include "resolu.h" |
| 16 |
– |
|
| 16 |
|
#include "data.h" |
| 17 |
|
|
| 18 |
|
/* picture memory usage before warning */ |
| 19 |
|
#ifndef PSIZWARN |
| 20 |
< |
#ifdef BIGMEM |
| 22 |
< |
#define PSIZWARN 5000000 |
| 23 |
< |
#else |
| 20 |
> |
#ifdef SMLMEM |
| 21 |
|
#define PSIZWARN 1500000 |
| 22 |
+ |
#else |
| 23 |
+ |
#define PSIZWARN 5000000 |
| 24 |
|
#endif |
| 25 |
|
#endif |
| 26 |
|
|
| 31 |
|
#define hash(s) (shash(s)%TABSIZ) |
| 32 |
|
|
| 33 |
|
|
| 35 |
– |
extern char *getlibpath(); /* library search path */ |
| 36 |
– |
|
| 34 |
|
static DATARRAY *dtab[TABSIZ]; /* data array list */ |
| 35 |
|
|
| 36 |
|
|
| 47 |
|
for (dp = dtab[hash(dname)]; dp != NULL; dp = dp->next) |
| 48 |
|
if (!strcmp(dname, dp->name)) |
| 49 |
|
return(dp); /* found! */ |
| 53 |
– |
|
| 50 |
|
/* |
| 51 |
|
* If we haven't loaded the data already, we will look |
| 52 |
|
* for it in the directories specified by the library path. |
| 67 |
|
* 0 0 ni p0i p1i .. pni |
| 68 |
|
*/ |
| 69 |
|
|
| 70 |
< |
if ((dfname = getpath(dname, getlibpath(), R_OK)) == NULL) { |
| 70 |
> |
if ((dfname = getpath(dname, getrlibpath(), R_OK)) == NULL) { |
| 71 |
|
sprintf(errmsg, "cannot find data file \"%s\"", dname); |
| 72 |
|
error(USER, errmsg); |
| 73 |
|
} |
| 76 |
|
error(SYSTEM, errmsg); |
| 77 |
|
} |
| 78 |
|
/* get dimensions */ |
| 79 |
< |
if (fgetval(fp, 'i', &asize) <= 0) |
| 79 |
> |
if (fgetval(fp, 'i', (char *)&asize) <= 0) |
| 80 |
|
goto scanerr; |
| 81 |
< |
if (asize <= 0 | asize > MAXDDIM) { |
| 81 |
> |
if ((asize <= 0) | (asize > MAXDDIM)) { |
| 82 |
|
sprintf(errmsg, "bad number of dimensions for \"%s\"", dname); |
| 83 |
|
error(USER, errmsg); |
| 84 |
|
} |
| 89 |
|
dp->nd = asize; |
| 90 |
|
asize = 1; |
| 91 |
|
for (i = 0; i < dp->nd; i++) { |
| 92 |
< |
if (fgetval(fp, DATATY, &dp->dim[i].org) <= 0) |
| 92 |
> |
if (fgetval(fp, DATATY, (char *)&dp->dim[i].org) <= 0) |
| 93 |
|
goto scanerr; |
| 94 |
< |
if (fgetval(fp, DATATY, &dp->dim[i].siz) <= 0) |
| 94 |
> |
if (fgetval(fp, DATATY, (char *)&dp->dim[i].siz) <= 0) |
| 95 |
|
goto scanerr; |
| 96 |
< |
if (fgetval(fp, 'i', &dp->dim[i].ne) <= 0) |
| 96 |
> |
if (fgetval(fp, 'i', (char *)&dp->dim[i].ne) <= 0) |
| 97 |
|
goto scanerr; |
| 98 |
|
if (dp->dim[i].ne < 2) |
| 99 |
|
goto scanerr; |
| 104 |
|
if (dp->dim[i].p == NULL) |
| 105 |
|
goto memerr; |
| 106 |
|
for (j = 0; j < dp->dim[i].ne; j++) |
| 107 |
< |
if (fgetval(fp, DATATY, &dp->dim[i].p[j]) <= 0) |
| 107 |
> |
if (fgetval(fp, DATATY, |
| 108 |
> |
(char *)&dp->dim[i].p[j]) <= 0) |
| 109 |
|
goto scanerr; |
| 110 |
|
for (j = 1; j < dp->dim[i].ne-1; j++) |
| 111 |
|
if ((dp->dim[i].p[j-1] < dp->dim[i].p[j]) != |
| 121 |
|
goto memerr; |
| 122 |
|
|
| 123 |
|
for (i = 0; i < asize; i++) |
| 124 |
< |
if (fgetval(fp, DATATY, &dp->arr.d[i]) <= 0) |
| 124 |
> |
if (fgetval(fp, DATATY, (char *)&dp->arr.d[i]) <= 0) |
| 125 |
|
goto scanerr; |
| 126 |
|
fclose(fp); |
| 127 |
|
i = hash(dname); |
| 137 |
|
} |
| 138 |
|
|
| 139 |
|
|
| 140 |
< |
static |
| 140 |
> |
static int |
| 141 |
|
headaspect(s, iap) /* check string for aspect ratio */ |
| 142 |
|
char *s; |
| 143 |
|
double *iap; |
| 146 |
|
|
| 147 |
|
if (isaspect(s)) |
| 148 |
|
*iap *= aspectval(s); |
| 149 |
< |
else if (formatval(fmt, s) && strcmp(fmt, COLRFMT)) |
| 149 |
> |
else if (formatval(fmt, s) && !globmatch(PICFMT, fmt)) |
| 150 |
|
*iap = 0.0; |
| 151 |
|
return(0); |
| 152 |
|
} |
| 162 |
|
COLR *scanin; |
| 163 |
|
int sl, ns; |
| 164 |
|
RESOLU inpres; |
| 165 |
< |
FLOAT loc[2]; |
| 165 |
> |
RREAL loc[2]; |
| 166 |
|
int y; |
| 167 |
|
register int x, i; |
| 168 |
|
register DATARRAY *pp; |
| 171 |
|
if (!strcmp(pname, pp->name)) |
| 172 |
|
return(pp); /* found! */ |
| 173 |
|
|
| 174 |
< |
if ((pfname = getpath(pname, getlibpath(), R_OK)) == NULL) { |
| 174 |
> |
if ((pfname = getpath(pname, getrlibpath(), R_OK)) == NULL) { |
| 175 |
|
sprintf(errmsg, "cannot find picture file \"%s\"", pname); |
| 176 |
|
error(USER, errmsg); |
| 177 |
|
} |
| 184 |
|
sprintf(errmsg, "cannot open picture file \"%s\"", pfname); |
| 185 |
|
error(SYSTEM, errmsg); |
| 186 |
|
} |
| 187 |
< |
#ifdef MSDOS |
| 191 |
< |
setmode(fileno(fp), O_BINARY); |
| 192 |
< |
#endif |
| 187 |
> |
SET_FILE_BINARY(fp); |
| 188 |
|
/* get dimensions */ |
| 189 |
|
inpaspect = 1.0; |
| 190 |
< |
getheader(fp, headaspect, &inpaspect); |
| 190 |
> |
getheader(fp, headaspect, (char *)&inpaspect); |
| 191 |
|
if (inpaspect <= FTINY || !fgetsresolu(&inpres, fp)) |
| 192 |
|
goto readerr; |
| 193 |
|
pp[0].nd = 2; |
| 230 |
|
copycolr(pp[0].arr.c[i], scanin[x]); |
| 231 |
|
} |
| 232 |
|
} |
| 233 |
< |
free((char *)scanin); |
| 233 |
> |
free((void *)scanin); |
| 234 |
|
fclose(fp); |
| 235 |
|
i = hash(pname); |
| 236 |
|
pp[0].next = dtab[i]; /* link into picture list */ |
| 237 |
< |
copystruct(&pp[1], &pp[0]); |
| 238 |
< |
copystruct(&pp[2], &pp[0]); |
| 237 |
> |
pp[1] = pp[0]; |
| 238 |
> |
pp[2] = pp[0]; |
| 239 |
|
pp[0].type = RED; /* differentiate RGB records */ |
| 240 |
|
pp[1].type = GRN; |
| 241 |
|
pp[2].type = BLU; |
| 249 |
|
} |
| 250 |
|
|
| 251 |
|
|
| 252 |
< |
freedata(dname) /* free memory associated with dname */ |
| 253 |
< |
char *dname; |
| 252 |
> |
void |
| 253 |
> |
freedata(dta) /* release data array reference */ |
| 254 |
> |
DATARRAY *dta; |
| 255 |
|
{ |
| 256 |
|
DATARRAY head; |
| 257 |
|
int hval, nents; |
| 258 |
< |
register DATARRAY *dp, *dpl; |
| 258 |
> |
register DATARRAY *dpl, *dp; |
| 259 |
|
register int i; |
| 260 |
|
|
| 261 |
< |
if (dname == NULL) { /* free all if NULL */ |
| 261 |
> |
if (dta == NULL) { /* free all if NULL */ |
| 262 |
|
hval = 0; nents = TABSIZ; |
| 263 |
|
} else { |
| 264 |
< |
hval = hash(dname); nents = 1; |
| 264 |
> |
hval = hash(dta->name); nents = 1; |
| 265 |
|
} |
| 266 |
|
while (nents--) { |
| 267 |
|
head.next = dtab[hval]; |
| 268 |
|
dpl = &head; |
| 269 |
|
while ((dp = dpl->next) != NULL) |
| 270 |
< |
if (dname == NULL || !strcmp(dname, dp->name)) { |
| 270 |
> |
if ((dta == NULL) | (dta == dp)) { |
| 271 |
|
dpl->next = dp->next; |
| 272 |
|
if (dp->type == DATATY) |
| 273 |
< |
free((char *)dp->arr.d); |
| 273 |
> |
free((void *)dp->arr.d); |
| 274 |
|
else |
| 275 |
< |
free((char *)dp->arr.c); |
| 275 |
> |
free((void *)dp->arr.c); |
| 276 |
|
for (i = 0; i < dp->nd; i++) |
| 277 |
|
if (dp->dim[i].p != NULL) |
| 278 |
< |
free((char *)dp->dim[i].p); |
| 278 |
> |
free((void *)dp->dim[i].p); |
| 279 |
|
freestr(dp->name); |
| 280 |
< |
free((char *)dp); |
| 280 |
> |
free((void *)dp); |
| 281 |
|
} else |
| 282 |
|
dpl = dp; |
| 283 |
|
dtab[hval++] = head.next; |