/* defexec.c
* Copyright (c) MIT/JGOFS
A version of def which allows subshells to be executed rather than files
- All columns must be tab separated - spaces will be incorporated into
the strings
- Where def normally expects a filename, one can put a command
enclosed in parentheses. This command will be executed as the
stdout from the command will be treated as the contents of the file.
Example:
toplevel file:
# The physics here is a two-dimensional turbulence calculation
# in a 64x64 psuedospectral model.
#
experiment description mpeg_movie >
time
u0 "Passive particles " "u0_mpeg" (/d5/glenn/qgmod/patch/modhtml1 u0)
u3 "Attracting particles (u=3)" "u3_mpeg" (/d5/glenn/qgmod/patch/modhtml1 u3)
u6 "Attracting particles (u=6)" "u6_mpeg" (/d5/glenn/qgmod/patch/modhtml1 u6)
t0 "Tracer patch (only filtering)" "t0_mpeg" (/d5/glenn/qgmod/patch/modhtml1 t0)
t2f "Tracer patch (hyperviscosity)" "t2f_mpeg" (/d5/glenn/qgmod/patch/modhtml1 t2f)
script modhtml1
#!/bin/csh -f
cd /d5/glenn/qgmod/patch
echo "time"
foreach g ($1.*.Z)
set h=$g:r
set n=$h:e
echo \"\$n\\"
end
*/
#include
#include
double atof();
#define DIRSEP '/'
/* #define DEBUG */
#define TOKEN 80
#define NVAR 250
#define COMMENTSIZE 2430
#define SEPARATOR "\t,\n"
char tabnames[NVAR][TOKEN];
char tabvalues[NVAR][TOKEN];
char tabattributes[NVAR][TOKEN];
char tabcomments[COMMENTSIZE];
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);
}
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 (tabattributes[j][0]){
at=strchr(tabattributes[j],';');
if(at){
*at = '\0';
strcpy(str,tabattributes[j]);
strcpy(tabattributes[j],at+1);
} else {
strcpy(str,tabattributes[j]);
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];
FILE *fin;
int ioreadrec_(level)
int *level;
{
char tmp[1258],*tok;
int i,j,k;
#ifdef DEBUG
printf("ioreadrec %d\n",*level);
#endif
k= *level;
if (! fileopen[k]) {
#ifdef DEBUG
printf("open %s\n",subfilename);
#endif
if(*subfilename == '('){
subfilename[strlen(subfilename)-1]=0;
startchild(subfilename+1,&fin,fl+k);
}
else 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