#include #include double atof(); /* #define DEBUG */ #define TOKEN 40 #define NVAR 250 #define COMMENTSIZE 2430 #define SEPARATOR " ,\n" char names[NVAR][TOKEN]; char values[NVAR][TOKEN]; char attr[NVAR][TOKEN]; char comments[COMMENTSIZE]; int nvarlevel[6]; FILE *fl; int maxlev,newlev; int eofflag=0; int ateq=0; err(s,t) char *s,*t; { printf("&x error - %s%s",s,t); ioclose_(); exit(1); } int ftok(fl,s) FILE *fl; char *s; { char *sp; int ok,c; sp=s; ok=1; while(ok){ c=fgetc(fl); if(c==EOF) return EOF; if(c==' ' || c==',' || c=='\n'){ if(ok==2)ok=0; } else { ok=2; *(sp++)=c; }; }; *sp = '\0'; return 0; } readheader() { char tmp[82],*sp; int ncnt,i; maxlev= -1; newlev=0; nvarlevel[0]=0; ncnt=0; strcpy(tmp,"#"); while(tmp[0] == '#'){ if(fgets(tmp,82,fl) == NULL)err("file structure",""); if(tmp[0]=='#')strcat(comments,tmp+1); }; while(1) { if(tmp[0] == '='){ maxlev++; while(1){ if(ftok(fl,tmp) == EOF)err("unexpected EOF",""); if(tmp[0] == '.' || tmp[0] == '-')break; /* if(tmp[strlen(tmp)-1] == ',')tmp[strlen(tmp)-1]=0; */ if(sp=strchr(tmp,'[')){ strcpy(attr[ncnt],sp+1); attr[ncnt][strlen(attr[ncnt])-1]='\0'; *sp='\0'; } else attr[ncnt][0]='\0'; strcpy(names[ncnt++],tmp); }; nvarlevel[maxlev+1]=ncnt; }; if(tmp[0] == '-') return; for(i=nvarlevel[maxlev];i=0;i--)if (*vn >= nvarlevel[i]) return i; return 0; } ioattrout_(vn,str) int *vn; char *str; { char *at; int j; j= *vn; if (attr[j][0]){ at=strchr(attr[j],';'); if(at){ *at = '\0'; strcpy(str,attr[j]); strcpy(attr[j],at+1); } else { strcpy(str,attr[j]); attr[j][0]='\0'; }; return 1; } else return 0; } int iocommout_(str) char *str; { char *at; if (comments[0]){ at=strchr(comments,'\n'); if(at){ *at = '\0'; strcpy(str,comments); strcpy(comments,at+1); } else { strcpy(str,comments); comments[0]='\0'; }; return 1; } else return 0; } iovalreal_(vn,f) int *vn; float *f; { int i; i= *vn; if(i<0){*f= -9999.0;return;}; if(strspn(values[i],"0123456789.+-")) *f=atof(values[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= *vn; if(i<0){strcpy(tmp,"nd");return;}; s=values[i]; s=s+strspn(s," "); strcpy(tmp,s); #ifdef DEBUG printf("iovalstr %d %s\n",*vn,tmp); #endif } readnewheader() { char tmp[82],*sp; int i,clev,mlev; if(!ateq){ strcpy(tmp,"xx"); while(tmp[0] != '='){ if(ftok(fl,tmp)==EOF)err("unexpected EOF",""); if(tmp[0]=='*'){eofflag=1;newlev= -1;return;}; } } else strcpy(tmp,"=="); ateq=0; mlev=maxlev; while(1) { if(tmp[0] == '='){ clev= -1; while(1){ if(clev >= 0)break; if(ftok(fl,tmp) == EOF)err("unexpected EOF",""); if(tmp[0] == '.' || tmp[0] == '-')break; /* if(tmp[strlen(tmp)-1] == ',')tmp[strlen(tmp)-1]=0; */ if(sp=strchr(tmp,'['))*sp='\0'; for(i=0;i<=maxlev;i++) if(!strcmp(tmp,names[nvarlevel[i]])) clev = i; }; while(tmp[0] != '.' && tmp[0] != '-') if(ftok(fl,tmp) == EOF)err("unexpected EOF",""); if(clev newlev)return 0; if(*level == newlev && newlev == maxlev){ for(i=nvarlevel[maxlev];i *level); if(newlev<*level)return 0; newlev++; return 1; } ioclose_(maxlevel) int *maxlevel; { fclose(fl); }