Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions | Variables
mgvars.h File Reference
#include <errno.h>
#include "calcomp.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DARRAY
struct  ivar
struct  VARIABLE
union  VARIABLE.v

Defines

#define FTHICK   0 /* frame thickness */
#define GRID   1 /* grid on? */
#define LEGEND   2 /* legend title */
#define OTHICK   3 /* origin thickness */
#define PERIOD   4 /* period of polar plot */
#define SUBTITLE   5 /* subtitle */
#define SYMFILE   6 /* symbol file */
#define TSTYLE   7 /* tick mark style */
#define TITLE   8 /* title */
#define XLABEL   9 /* x axis label */
#define XMAP   10 /* x axis mapping */
#define XMAX   11 /* x axis maximum */
#define XMIN   12 /* x axis minimum */
#define XSTEP   13 /* x axis step */
#define YLABEL   14 /* y axis label */
#define YMAP   15 /* y axis mapping */
#define YMAX   16 /* y axis maximum */
#define YMIN   17 /* y axis minimum */
#define YSTEP   18 /* y axis step */
#define NVARS   19 /* number of standard variables */
#define C   0 /* the curve function */
#define CCOLOR   1 /* the curve color */
#define CDATA   2 /* the curve data */
#define CLABEL   3 /* the curve label */
#define CLINTYPE   4 /* the curve line type */
#define CNPOINTS   5 /* number of curve points to plot */
#define CSYMSIZE   6 /* the curve symbol size */
#define CSYMTYPE   7 /* the curve symbol type */
#define CTHICK   8 /* the curve line thickness */
#define NCVARS   9 /* number of curve variables */
#define MAXCUR   8 /* maximum number of curves */
#define REAL   1 /* floating point */
#define STRING   2 /* character array */
#define FUNCTION   3 /* function definition */
#define DATA   4 /* a set of real points */
#define DEFINED   01 /* variable is defined */
#define mgclear(vname)   undefine(vlookup(vname))

Typedefs

typedef struct ivar IVAR

Functions

VARIABLEvlookup ()
void mgclearall (void)
void mgload (char *file)
void mgsave (char *file)
void setmgvar (char *fname, FILE *fp, char *string)
int mgcurve (int c, void(*f)(int c, double x, double y))
void mgtoa (register char *s, VARIABLE *vp)

Variables

IVARivhead
VARIABLE gparam [NVARS]
VARIABLE cparam [MAXCUR][NCVARS]

Class Documentation

struct DARRAY

Definition at line 24 of file mgvars.h.

Class Members
float * data
int size
struct ivar

Definition at line 35 of file mgvars.h.

Collaboration diagram for ivar:
Class Members
char * dfn
char * name
struct ivar * next
struct VARIABLE

Definition at line 94 of file mgvars.h.

Class Members
char * descrip
unsigned short flags
char * name
short type
union VARIABLE v
union VARIABLE.v

Definition at line 99 of file mgvars.h.

Class Members
DARRAY d
char * dfn
char * s

Define Documentation

#define C   0 /* the curve function */

Definition at line 71 of file mgvars.h.

#define CCOLOR   1 /* the curve color */

Definition at line 72 of file mgvars.h.

#define CDATA   2 /* the curve data */

Definition at line 73 of file mgvars.h.

#define CLABEL   3 /* the curve label */

Definition at line 74 of file mgvars.h.

#define CLINTYPE   4 /* the curve line type */

Definition at line 75 of file mgvars.h.

#define CNPOINTS   5 /* number of curve points to plot */

Definition at line 76 of file mgvars.h.

#define CSYMSIZE   6 /* the curve symbol size */

Definition at line 77 of file mgvars.h.

#define CSYMTYPE   7 /* the curve symbol type */

Definition at line 78 of file mgvars.h.

#define CTHICK   8 /* the curve line thickness */

Definition at line 79 of file mgvars.h.

#define DATA   4 /* a set of real points */

Definition at line 89 of file mgvars.h.

#define DEFINED   01 /* variable is defined */

Definition at line 92 of file mgvars.h.

#define FTHICK   0 /* frame thickness */

Definition at line 48 of file mgvars.h.

#define FUNCTION   3 /* function definition */

Definition at line 88 of file mgvars.h.

#define GRID   1 /* grid on? */

Definition at line 49 of file mgvars.h.

#define LEGEND   2 /* legend title */

Definition at line 50 of file mgvars.h.

#define MAXCUR   8 /* maximum number of curves */

Definition at line 83 of file mgvars.h.

#define mgclear (   vname)    undefine(vlookup(vname))

Definition at line 113 of file mgvars.h.

#define NCVARS   9 /* number of curve variables */

Definition at line 81 of file mgvars.h.

#define NVARS   19 /* number of standard variables */

Definition at line 68 of file mgvars.h.

#define OTHICK   3 /* origin thickness */

Definition at line 51 of file mgvars.h.

#define PERIOD   4 /* period of polar plot */

Definition at line 52 of file mgvars.h.

#define REAL   1 /* floating point */

Definition at line 86 of file mgvars.h.

#define STRING   2 /* character array */

Definition at line 87 of file mgvars.h.

#define SUBTITLE   5 /* subtitle */

Definition at line 53 of file mgvars.h.

#define SYMFILE   6 /* symbol file */

Definition at line 54 of file mgvars.h.

#define TITLE   8 /* title */

Definition at line 56 of file mgvars.h.

#define TSTYLE   7 /* tick mark style */

Definition at line 55 of file mgvars.h.

#define XLABEL   9 /* x axis label */

Definition at line 57 of file mgvars.h.

#define XMAP   10 /* x axis mapping */

Definition at line 58 of file mgvars.h.

#define XMAX   11 /* x axis maximum */

Definition at line 59 of file mgvars.h.

#define XMIN   12 /* x axis minimum */

Definition at line 60 of file mgvars.h.

#define XSTEP   13 /* x axis step */

Definition at line 61 of file mgvars.h.

#define YLABEL   14 /* y axis label */

Definition at line 62 of file mgvars.h.

#define YMAP   15 /* y axis mapping */

Definition at line 63 of file mgvars.h.

#define YMAX   16 /* y axis maximum */

Definition at line 64 of file mgvars.h.

#define YMIN   17 /* y axis minimum */

Definition at line 65 of file mgvars.h.

#define YSTEP   18 /* y axis step */

Definition at line 66 of file mgvars.h.


Typedef Documentation

typedef struct ivar IVAR

Function Documentation

void mgclearall ( void  )

Definition at line 147 of file mgvars.c.

{
       int  j;
       register IVAR  *iv;
       register int  i;

       for (iv = ivhead; iv != NULL; iv = iv->next) {
              dremove(iv->name);
              freestr(iv->name);
              freestr(iv->dfn);
              efree((char *)iv);
       }
       ivhead = NULL;

       for (i = 0; i < NVARS; i++)
              if (gparam[i].flags & DEFINED)
                     undefine(&gparam[i]);
       
       for (j = 0; j < MAXCUR; j++)
              for (i = 0; i < NCVARS; i++)
                     if (cparam[j][i].flags & DEFINED)
                            undefine(&cparam[j][i]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mgcurve ( int  c,
void(*)(int c, double x, double y)  f 
)

Definition at line 580 of file mgvars.c.

{
       int  nargs;
       double  x[2], step;
       register VARIABLE  *cv;
       register float  *p;
       register int npts = 0;

       if (c < 0 || c >= MAXCUR)
              return(-1);
       cv = cparam[c];

       if (cv[C].flags & DEFINED) {              /* function or map */

              nargs = fundefined(cv[C].name);
              if (nargs < 1 || nargs > 2) {
                     fprintf(stderr, "%s: bad # of arguments for '%c'\n",
                                   progname, c+'A');
                     quit(1);
              }

              if (cv[CDATA].flags & DEFINED) {          /* map */
                     npts = cv[CDATA].v.d.size / nargs;
                     p = cv[CDATA].v.d.data;
                     while (npts--) {
                            x[0] = *p++;
                            if (nargs == 2)
                                   x[1] = *p++;
                            (*f)(c, x[0],
                                   funvalue(cv[C].name, nargs, x));
                     }
                     npts = cv[CDATA].v.d.size / nargs;
              } else if ( nargs == 1 &&                 /* function */
                            gparam[XMIN].flags & DEFINED &&
                            gparam[XMAX].flags & DEFINED &&
                            cv[CNPOINTS].flags & DEFINED ) {
                     npts = varvalue(cv[CNPOINTS].name);
                     if (npts > 1)
                            step = (varvalue(gparam[XMAX].name) -
                                   varvalue(gparam[XMIN].name)) /
                                   (npts - 1);
                     else
                            step = 0.0;
                     for (x[0] = varvalue(gparam[XMIN].name);
                                   npts--; x[0] += step)
                            (*f)(c, x[0],
                                   funvalue(cv[C].name, 1, x));
                     npts = varvalue(cv[CNPOINTS].name);
              } else {
                     fprintf(stderr,
                     "%s: function '%c' needs %cdata or xmin, xmax, %cnpoints\n",
                                   progname, c+'A', c+'A', c+'A');
                     quit(1);
              }

       } else if (cv[CDATA].flags & DEFINED) {   /* data */

              npts = cv[CDATA].v.d.size / 2;
              p = cv[CDATA].v.d.data;
              while (npts--) {
                     (*f)(c, p[0], p[1]);
                     p += 2;
              }
              npts = cv[CDATA].v.d.size / 2;

       } else

              npts = 0;

       return(npts);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mgload ( char *  file)

Definition at line 173 of file mgvars.c.

{
       FILE  *fp;
       char  sbuf[MAXLINE], *fgets();
       int  inquote;
       register char  *cp, *cp2;

       if (file == NULL) {
              fp = stdin;
              file = "<stdin>";
       } else if ((fp = fopen(file, "r")) == NULL) {
              fprintf(stderr, "%s: Cannot open: %s\n", progname, file);
              quit(1);
       }
       while (fgets(sbuf+1, sizeof(sbuf)-1, fp) != NULL) {
              inquote = 0;
              cp2 = sbuf;
              for (cp = sbuf+1; *cp; cp++)       /* condition the input line */
                     switch (*cp) {
                     case '#':
                            if (!inquote) {
                                   cp[0] = '\n';
                                   cp[1] = '\0';
                                   break;
                            }
                            *cp2++ = *cp;
                            break;
                     case '"':
                            inquote = !inquote;
                            break;
                     case '\\':
                            if (!cp[1])
                                   break;
                            if (cp[1] == '\n') {
                                   cp[0] = '\0';
                                   fgets(cp, sizeof(sbuf)-(cp-sbuf), fp);
                                   cp--;
                                   break;
                            }
                            *cp2++ = *++cp;
                            break;
                     case ' ':
                     case '\t':
                     case '\n':
                            if (!inquote)
                                   break;
                            *cp2++ = *cp;
                            break;
                     default:
                            *cp2++ = *cp;
                            break;
                     }
              *cp2 = '\0';
              if (inquote) {
                     fputs(sbuf, stderr);
                     fprintf(stderr, "%s: %s: Missing quote\n",
                                   progname, file);
                     quit(1);
              }
              if (sbuf[0])
                     setmgvar(file, fp, sbuf);
       }
       if (fp != stdin)
              fclose(fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mgsave ( char *  file)

Definition at line 243 of file mgvars.c.

{
       FILE  *fp;
       int  j;
       register IVAR  *iv;
       register int  i;

       if (file == NULL)
              fp = stdout;
       else if ((fp = fopen(file, "w")) == NULL) {
              fprintf(stderr, "%s: Cannot write: %s\n", progname, file);
              quit(1);
       }
       for (iv = ivhead; iv != NULL; iv = iv->next)
              fprintf(fp, "%s\n", iv->dfn);

       for (i = 0; i < NVARS; i++)
              if (gparam[i].flags & DEFINED)
                     mgprint(&gparam[i], fp);
       
       for (j = 0; j < MAXCUR; j++)
              for (i = 0; i < NCVARS; i++)
                     if (cparam[j][i].flags & DEFINED)
                            mgprint(&cparam[j][i], fp);

       if (fp != stdout)
              fclose(fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mgtoa ( register char *  s,
VARIABLE vp 
)

Definition at line 401 of file mgvars.c.

{
       register  char  *sv;

       if (!(vp->flags & DEFINED)) {
              strcpy(s, "UNDEFINED");
              return;
       }
       switch (vp->type) {
       case REAL:
       case FUNCTION:
              sv = vp->v.dfn;
              while (*sv != '=' && *sv != ':')
                     sv++;
              while (*++sv && *sv != ';')
                     *s++ = *sv;
              *s = '\0';
              break;
       case STRING:
              strcpy(s, vp->v.s);
              break;
       case DATA:
              strcpy(s, "DATA");
              break;
       }
}

Here is the caller graph for this function:

void setmgvar ( char *  fname,
FILE *  fp,
char *  string 
)

Definition at line 276 of file mgvars.c.

{
       char  name[128];
       FILE  *fp2;
       register int  i;
       register char  *s;
       register VARIABLE  *vp;

       if (!strncmp(string, "include=", 8)) {    /* include file */
              if ((s = findfile(string+8, libpath)) == NULL) {
                     fprintf(stderr, "%s\n", string);
                     fprintf(stderr, "%s: %s: File not found: %s\n",
                                   progname, fname, string+8);
                     quit(1);
              }
              strcpy(name, s);
              mgload(name);
              return;
       }
       s = string;
       i = 0;
       while (i < sizeof(name)-1 && isid(*s))
              name[i++] = *s++;
       name[i] = '\0';
       vp = vlookup(name);
       if (vp != NULL) {
              undefine(vp);
              switch (vp->type) {
              case REAL:
              case FUNCTION:
                     if ((*s == '(') != (vp->type == FUNCTION)) {
                            fprintf(stderr, "%s\n", string);
                            fprintf(stderr,
                                   "%s: %s: Bad %s declaration: %s\n",
                                   progname, fname,
                                   vp->type == FUNCTION ?
                                   "function" : "variable",
                                   name);
                            quit(1);
                     }
                     scompile(string, fname, 0);
                     vp->v.dfn = savestr(string);
                     break;
              case STRING:
                     if (*s++ != '=') {
                            fprintf(stderr, "%s\n", string);
                            fprintf(stderr, "%s: %s: Missing '='\n",
                                          progname, fname);
                            quit(1);
                     }
                     vp->v.s = savestr(s);
                     break;
              case DATA:
                     if (*s++ != '=') {
                            fprintf(stderr, "%s\n", string);
                            fprintf(stderr, "%s: %s: Missing '='\n",
                                          progname, fname);
                            quit(1);
                     }
                     if (!*s) {
                            loaddata(fname, fp, &vp->v.d);
                     } else if (*s == '!') {
                            if ((fp2 = popen(s+1, "r")) == NULL) {
                                   fprintf(stderr, "%s\n", string);
                                   fprintf(stderr,
                                   "%s: %s: Cannot execute: %s\n",
                                                 progname, fname, s+1);
                                   quit(1);
                            }
                            loaddata(s, fp2, &vp->v.d);
                            pclose(fp2);
                     } else {
                            if ((fp2 = fopen(s, "r")) == NULL) {
                                fprintf(stderr, "%s\n", string);
                                fprintf(stderr,
                                       "%s: %s: Data file not found: %s\n",
                                       progname, fname, s);
                                quit(1);
                            }
                            loaddata(s, fp2, &vp->v.d);
                            fclose(fp2);
                     }
                     break;
              }
              vp->flags |= DEFINED;
       } else
              setivar(name, fname, string);             /* intermediate */
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 61 of file mgvars.c.

Definition at line 39 of file mgvars.c.

Definition at line 37 of file mgvars.c.