Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions
data.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  datarray
struct  datarray.dim
union  datarray.arr

Defines

#define MAXDDIM   5 /* maximum data dimensions */
#define DATATYPE   float /* single precision to save space */
#define DATATY   'f' /* format for DATATYPE */

Typedefs

typedef struct datarray DATARRAY

Functions

DATARRAYgetdata (char *dname)
DATARRAYgetpict (char *pname)
void freedata (DATARRAY *dta)
double datavalue (DATARRAY *dp, double *pt)

Class Documentation

struct datarray

Definition at line 16 of file data.h.

Collaboration diagram for datarray:
Class Members
union datarray arr
struct datarray dim
char * name
short nd
struct datarray * next
short type
struct datarray.dim

Definition at line 20 of file data.h.

Class Members
int ne
DATATYPE org
DATATYPE * p
DATATYPE siz
union datarray.arr

Definition at line 25 of file data.h.

Class Members
COLR * c
DATATYPE * d

Define Documentation

#define DATATY   'f' /* format for DATATYPE */

Definition at line 14 of file data.h.

#define DATATYPE   float /* single precision to save space */

Definition at line 13 of file data.h.

#define MAXDDIM   5 /* maximum data dimensions */

Definition at line 11 of file data.h.


Typedef Documentation

typedef struct datarray DATARRAY

Function Documentation

double datavalue ( DATARRAY dp,
double *  pt 
)
void freedata ( DATARRAY dta)

Definition at line 262 of file data.c.

{
       DATARRAY  head;
       int  hval, nents;
       register DATARRAY  *dpl, *dp;
       register int  i;

       if (dta == NULL) {                 /* free all if NULL */
              hval = 0; nents = TABSIZ;
       } else {
              hval = hash(dta->name); nents = 1;
       }
       while (nents--) {
              head.next = dtab[hval];
              dpl = &head;
              while ((dp = dpl->next) != NULL)
                     if ((dta == NULL) | (dta == dp)) {
                            dpl->next = dp->next;
                            if (dp->type == DATATY)
                                   free((void *)dp->arr.d);
                            else
                                   free((void *)dp->arr.c);
                            for (i = 0; i < dp->nd; i++)
                                   if (dp->dim[i].p != NULL)
                                          free((void *)dp->dim[i].p);
                            freestr(dp->name);
                            free((void *)dp);
                     } else
                            dpl = dp;
              dtab[hval++] = head.next;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

DATARRAY* getdata ( char *  dname)

Definition at line 42 of file data.c.

{
       char  *dfname;
       FILE  *fp;
       int  asize;
       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.
        *
        *     The file has the following format:
        *
        *            N
        *            beg0   end0   n0
        *            beg1   end1   n1
        *            . . .
        *            begN   endN   nN
        *            data, later dimensions changing faster
        *            . . .
        *
        *     For irregularly spaced points, the following can be
        *  substituted for begi endi ni:
        *
        *            0 0 ni p0i p1i .. pni
        */

       if ((dfname = getpath(dname, getrlibpath(), R_OK)) == NULL) {
              sprintf(errmsg, "cannot find data file \"%s\"", dname);
              error(USER, errmsg);
       }
       if ((fp = fopen(dfname, "r")) == NULL) {
              sprintf(errmsg, "cannot open data file \"%s\"", dfname);
              error(SYSTEM, errmsg);
       }
                                                 /* get dimensions */
       if (fgetval(fp, 'i', (char *)&asize) <= 0)
              goto scanerr;
       if ((asize <= 0) | (asize > MAXDDIM)) {
              sprintf(errmsg, "bad number of dimensions for \"%s\"", dname);
              error(USER, errmsg);
       }
       if ((dp = (DATARRAY *)malloc(sizeof(DATARRAY))) == NULL)
              goto memerr;
       dp->name = savestr(dname);
       dp->type = DATATY;
       dp->nd = asize;
       asize = 1;
       for (i = 0; i < dp->nd; i++) {
              if (fgetval(fp, DATATY, (char *)&dp->dim[i].org) <= 0)
                     goto scanerr;
              if (fgetval(fp, DATATY, (char *)&dp->dim[i].siz) <= 0)
                     goto scanerr;
              if (fgetval(fp, 'i', (char *)&dp->dim[i].ne) <= 0)
                     goto scanerr;
              if (dp->dim[i].ne < 2)
                     goto scanerr;
              asize *= dp->dim[i].ne;
              if ((dp->dim[i].siz -= dp->dim[i].org) == 0) {
                     dp->dim[i].p = (DATATYPE *)
                                   malloc(dp->dim[i].ne*sizeof(DATATYPE));
                     if (dp->dim[i].p == NULL)
                            goto memerr;
                     for (j = 0; j < dp->dim[i].ne; j++)
                            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]) !=
                                   (dp->dim[i].p[j] < dp->dim[i].p[j+1]))
                                   goto scanerr;
                     dp->dim[i].org = dp->dim[i].p[0];
                     dp->dim[i].siz = dp->dim[i].p[dp->dim[i].ne-1]
                                          - dp->dim[i].p[0];
              } else
                     dp->dim[i].p = NULL;
       }
       if ((dp->arr.d = (DATATYPE *)malloc(asize*sizeof(DATATYPE))) == NULL)
              goto memerr;
       
       for (i = 0; i < asize; i++)
              if (fgetval(fp, DATATY, (char *)&dp->arr.d[i]) <= 0)
                     goto scanerr;
       fclose(fp);
       i = hash(dname);
       dp->next = dtab[i];
       return(dtab[i] = dp);

memerr:
       error(SYSTEM, "out of memory in getdata");
scanerr:
       sprintf(errmsg, "%s in data file \"%s\"",
                     feof(fp) ? "unexpected EOF" : "bad format", dfname);
       error(USER, errmsg);
       return NULL; /* pro forma return */
}

Here is the call graph for this function:

Here is the caller graph for this function:

DATARRAY* getpict ( char *  pname)

Definition at line 163 of file data.c.

{
       double  inpaspect;
       char  *pfname;
       FILE  *fp;
       COLR  *scanin;
       int  sl, ns;
       RESOLU inpres;
       RREAL  loc[2];
       int  y;
       register int  x, i;
       register DATARRAY  *pp;
                                          /* look for array in list */
       for (pp = dtab[hash(pname)]; pp != NULL; pp = pp->next)
              if (!strcmp(pname, pp->name))
                     return(pp);          /* found! */

       if ((pfname = getpath(pname, getrlibpath(), R_OK)) == NULL) {
              sprintf(errmsg, "cannot find picture file \"%s\"", pname);
              error(USER, errmsg);
       }
       if ((pp = (DATARRAY *)malloc(3*sizeof(DATARRAY))) == NULL)
              goto memerr;

       pp[0].name = savestr(pname);

       if ((fp = fopen(pfname, "r")) == NULL) {
              sprintf(errmsg, "cannot open picture file \"%s\"", pfname);
              error(SYSTEM, errmsg);
       }
       SET_FILE_BINARY(fp);
                                          /* get dimensions */
       inpaspect = 1.0;
       getheader(fp, headaspect, &inpaspect);
       if (inpaspect <= FTINY || !fgetsresolu(&inpres, fp))
              goto readerr;
       pp[0].nd = 2;
       pp[0].dim[0].ne = inpres.yr;
       pp[0].dim[1].ne = inpres.xr;
       pp[0].dim[0].org =
       pp[0].dim[1].org = 0.0;
       if (inpres.xr <= inpres.yr*inpaspect) {
              pp[0].dim[0].siz = inpaspect *
                                   (double)inpres.yr/inpres.xr;
              pp[0].dim[1].siz = 1.0;
       } else {
              pp[0].dim[0].siz = 1.0;
              pp[0].dim[1].siz = (double)inpres.xr/inpres.yr /
                                   inpaspect;
       }
       pp[0].dim[0].p = pp[0].dim[1].p = NULL;
       sl = scanlen(&inpres);                           /* allocate array */
       ns = numscans(&inpres);
       i = ns*sl*sizeof(COLR);
#if PSIZWARN
       if (i > PSIZWARN) {                       /* memory warning */
              sprintf(errmsg, "picture file \"%s\" using %.1f MB of memory",
                            pname, i*(1.0/(1024*1024)));
              error(WARNING, errmsg);
       }
#endif
       if ((pp[0].arr.c = (COLR *)malloc(i)) == NULL)
              goto memerr;
                                                 /* load picture */
       if ((scanin = (COLR *)malloc(sl*sizeof(COLR))) == NULL)
              goto memerr;
       for (y = 0; y < ns; y++) {
              if (freadcolrs(scanin, sl, fp) < 0)
                     goto readerr;
              for (x = 0; x < sl; x++) {
                     pix2loc(loc, &inpres, x, y);
                     i = (int)(loc[1]*inpres.yr)*inpres.xr +
                                   (int)(loc[0]*inpres.xr);
                     copycolr(pp[0].arr.c[i], scanin[x]);
              }
       }
       free((void *)scanin);
       fclose(fp);
       i = hash(pname);
       pp[0].next = dtab[i];              /* link into picture list */
       pp[1] = pp[0];
       pp[2] = pp[0];
       pp[0].type = RED;           /* differentiate RGB records */
       pp[1].type = GRN;
       pp[2].type = BLU;
       return(dtab[i] = pp);

memerr:
       error(SYSTEM, "out of memory in getpict");
readerr:
       sprintf(errmsg, "bad picture file \"%s\"", pfname);
       error(USER, errmsg);
       return NULL; /* pro forma return */
}

Here is the call graph for this function:

Here is the caller graph for this function: