/* ******************************************************************* * * * Copyright (c) MIT/JGOFS * * * * * * File : nm.c * * * * Purpose : * * * * Version Number : 1.5 * * * * Revision History : * * * * Date Developer * * ---- --------- * * * * Sat Oct 17 1992 10.00 Glenn Flierl * * Oct 1993 attr[][] * * July 1995 Christine Hammond * * change to add field width determination based on width of * * the label in the data. Preparer must determine max width * * of column from inspection of data column width. * * Ex: event___ , sta__ ,bot * * will give lengths of 8, 5, and 3 for the respective cols * * * * January 1996 Christine Hammond * * 'type' the functions that outer method calls to avoid * * warnings on ANSI compilers - void() used for functions * * returning no value (e.g., return;) * * * * March 1996 Christine Hammond * * fix in_proclabel (width sensing) to ignore attributes with a* * substring 'width=', ex: 'inpwidth=N', and to properly deal * * with a 'width=N' attr when it occurs after a ';', as in * * a series of attributes, ex: 'meters;color=pink;width=12' * * * * March 1996 Warren Sass, Christine Hammond * * use a .h include file to set sizes of buffers used * * NOTE: 'minbufsize.h' also included in outer.c, to achieve * * some correspondence. User-specified include file allowed * * (see minbufsize.h) as a compile switch IOBUF_INCLUDE * * * * November 1996 Warren Sass, Christine Hammond * * ioattrout change - remove code after getwidth() call whose * * comment stated: don't show the width attribute * * code was: str = '\0'; * * we want outer to determine what gets shown. * * * * November 1996 Christine Hammond * * proclabel change - place separating ';' AFTER first attrib * * * * May 1997 Glenn Flierl * * changed error calls to use error_ in outer.c * * * * June 1997 grf * * changed sub names to in_xxxx, fixes for v 1.5 * ******************************************************************* */ #include #include #include OPTIONS #include INNEROPTIONS double strtod(); /* #define DEBUG */ #define SEPARATOR " ,=\t\n" #define W_EXTEND '_' char names[NVAR][VARNAMESIZE]; char values[NVAR][DATUMSIZE]; char attr[NVAR][ATTRSIZE]; int fldwidths[NVAR]; int map[NVAR]; int nheader, ndata; FILE *fl; int maxlev,newlev; int eofflag=0; char str[INBUFSIZE],*strp; char tabcomments[COMMENTSIZE]; /* * * * * * end of declarations * * * * * */ in_proclabel(n, ptr) int n; char *ptr; /* attr[] is the global array. routine to determine the length of the title string indexed at 'n' and pointed to by 'ptr', and based on the idea that the user preparing the data has placed W_EXTEND characters to pad the title to the desired width. An attribute is constructed and saved in attr[], either by appending to existing attr's or saving as the sole attribute, beginning with 'width='. Then, the W_EXTEND characters must be stripped from the names. Same name separators are used as before (space, tab, comma, newline). If an explicit 'width=' attribute is found, it is used. */ { #define YES 0 #define NO 1 int len, docalc, others; char attrib[ATTRSIZE], *attrptr; /* default value for flag indicating attributes other than 'width=' */ others = NO; /* calculate a field width, if no attributes are present or, if none of the attributes are exactly == 'width=N' */ docalc = YES; attrptr = attr[n]; while (*attrptr) { if (strncmp(attrptr,"width=",6) == 0) docalc = NO; if ((attrptr = strchr(attrptr,';')) != NULL){ attrptr++; others = YES; } } if (docalc == YES) { len = strlen(ptr); /* length of (possibly) extended label */ sprintf(attrib, "width=%d", len); if (others == YES) { /* add to end of other attributes? */ strcat(attr[n],";"); strcat(attr[n],attrib); } else strcpy(attr[n],attrib); }; /* end docalc loop */ /* strip off the column extenders from the label */ in_striptoken(ptr); /* and save label name without the extra W_EXTEND characters */ strcpy(names[n], ptr); return; } in_striptoken(p) char *p; { char *tp; int i; /* if there are extending characters at end of string, strip them */ i = strlen(p); while ( (tp = strrchr(p,W_EXTEND)) == p+i-1) { *tp = '\0'; /* shorten string by that one extend char */ i = strlen(p); }; return; } int in_fg(str) char *str; { *str = 0; while(*str == 0){ if(fgets(str,INBUFSIZE-1,fl) == NULL) return 1; if(strspn(str,SEPARATOR)==strlen(str))*str = 0; }; return 0; } int in_readdata(flag) int flag; { int state,nn,i; char *pstr; state=1; nn=0; if(*str == 0) if(in_fg(str))return -1; if (str[0] == '#'){ *tabcomments=0; while (str[0] == '#') { strcat(tabcomments,str+1); if (in_fg(str)) return -1; }; }; if(flag<=1) while(strchr(str,'=')==NULL) if(in_fg(str))return -1; while(strchr(str,'=')){ state=2; strp=strtok(str,SEPARATOR); while(strp){ if(flag==0){ if(pstr=strchr(strp,'[')){ *(pstr+strlen(pstr)-1)=0; strcpy(attr[nheader],pstr+1); *pstr=0; } else attr[nheader][0]=0; /* routine to determine field width and assign field name */ in_proclabel(nheader, strp); nn=nheader++; } else { if(pstr=strchr(strp,'['))*pstr=0; for(nn=0;nn0){newlev=3;return 1;}; newlev=2;return 0; } void ioname_(vn,s) int *vn; char *s; { strcpy(s,names[*vn]); } int iovarlevel_(vn) int *vn; { if(*vn