/* ******************************************************************* * * * Copyright (c) L-DGO/MIT/JGOFS * * * * * * File : defw.c * * * * Purpose : * * * * Version Number : 1.2 * * * * Revision History : * * * * Date Developer * * ---- --------- * * * * Sat Oct 17 1992 10.00 Glenn Flierl * * Oct 1993 tabattributes * * 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 * * July 1995 Christine Hammond * * change to allow subfiles to be located in different * * directories from header file * * * ******************************************************************* */ #include #include double atof(); #define DIRSEP '/' /* #define DEBUG */ #define TOKEN 40 #define NVAR 250 #define COMMENTSIZE 2430 #define SEPARATOR " \t,\n" #define W_EXTEND '_' char tabnames[NVAR][TOKEN]; char tabvalues[NVAR][TOKEN]; char tabattributes[NVAR][TOKEN]; char tabcomments[COMMENTSIZE]; int tabwidths[NVAR]; int nvarlevel[6]; int fileopen[5] = {0,0,0,0,0}; FILE *fl[5]; int maxlev; int pointers[NVAR]; char dirstring[80]; err(s,t) char *s,*t; { printf("&x %s%s\n",s,t); exit(1); } proclabel(n, ptr, attr) int n; char *ptr, attr[]; /* 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 to be saved in the calling routine, beginning with 'width='. Then, the W_EXTEND characters must be stripped from the tabnames. Same name separators are used as before (space, tab, comma, newline). */ { int len; /* so as not to overwrite an attribute, and to check for an explicit width attribute */ if (attr == NULL || strncmp(attr,"width=",6) != 0) { /* assign to field width the len of (possibly) extended label */ len = strlen(ptr); sprintf(attr, "width=%d", len); } /* strip off the column extenders from the label */ striptoken(ptr); /* and save label name without the extra W_EXTEND characters */ strcpy(tabnames[n], ptr); return; } 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 scanheader(lev) int lev; { int ncnt,i,j,k,m; char tmp[1258],*tok,attrsav[TOKEN],*attr; ncnt= 0; i=0;j=1; if(lev>0){ for(i=nvarlevel[lev-1];i")) { for(k=nvarlevel[lev-1];k') ncnt--; else j=0; nvarlevel[i]=ncnt; if(j) i++; } else j=0; }; if(lev==0) maxlev=i; else for(i=lev;i=0;i--)if (*vn >= nvarlevel[i]) return i+1; return 0; } int ioattrout_(vn,str) int *vn; char *str; { char *at; int j; j= *vn; /* if there IS an attribute, find one and move next one to front of string */ if (tabattributes[j][0]){ at=strchr(tabattributes[j],';'); if(at){ /* there is more than 1 attribute */ *at = '\0'; strcpy(str,tabattributes[j]); if (strncmp(str,"width=",6) == 0) { /* width attr, use it for tabwidths */ getwidth(&j,str); str = '\0'; /* don't show the width attr */ } strcpy(tabattributes[j],at+1); } else { /* this is the only attribute for variable vn */ strcpy(str,tabattributes[j]); if (strncmp(str,"width=",6) == 0) { getwidth(&j,str); str = '\0'; } tabattributes[j][0]='\0'; }; return 1; } else return 0; } iovalreal_(vn,f) int *vn; float *f; { int i; i=pointers[*vn]; if(i<0){*f= -9999.0;return;}; if(strspn(tabvalues[i],"0123456789.+-")) *f=atof(tabvalues[i]); else *f= -9999.0; #ifdef DEBUG printf("iovalreal %d %f\n",*vn,f); #endif } iovalstr_(vn,tmp) int *vn; char *tmp; { static char *s; int i; i=pointers[*vn]; if(i<0){strcpy(tmp,"nd");return;}; s=tabvalues[i]; s=s+strspn(s," "); strcpy(tmp,s); #ifdef DEBUG printf("iovalstr %d %s\n",*vn,tmp); #endif } static char subfilename[80]; int ioreadrec_(level) int *level; { char tmp[1258],*tok; int i,j,k; #ifdef DEBUG printf("ioreadrec %d\n",*level); #endif /* fprintf(stderr,"ioreadrec %d\n",*level); */ k= *level; if (! fileopen[k]) { #ifdef DEBUG printf("open %s\n",subfilename); #endif if((fl[k]=fopen(subfilename,"r")) == NULL)err("Missing file ",subfilename); scanheader(k); fileopen[k]=1; }; j=1; while(j){ if(fgets(tmp,1257,fl[k]) == NULL){ #ifdef DEBUG printf("eof at level %d\n",k); #endif fclose(fl[k]); fileopen[k]=0; return 0; }; i=strspn(tmp,SEPARATOR); if(i