#include extern FILE *inf, *opf, *opf2, *stf, *hdf; grdinp(infile,outfile,stfile,popfile,hdrfile,intdat,nlat,nlon,maxlat,minlat, maxlon,minlon,dmin,dmax,nbmin,nbmax,pop_flag,hdr_flag) /*********************************/ /* input variable declarations */ /*********************************/ int *intdat; int *nlat,*nlon,*nbmin,*nbmax,*pop_flag,*hdr_flag; float *maxlat,*minlat,*maxlon,*minlon; float *dmin,*dmax; char *infile,*outfile,*stfile,*popfile,*hdrfile; { /*********************************/ /* local variables */ /*********************************/ FILE *fopen(); char c,csel[3],s[20]; double atof(); int i,j,k,n,inpok,istat,same,pos; char temp[60]; printf(" Please enter the input file name: "); gets(infile); while ((inf = fopen(infile,"r")) == NULL) { printf(" Unable to open input file, please try again! "); printf(" Please enter the input file name: "); gets(infile); } printf(" Please enter the output file name: "); gets(temp); strcpy(outfile,temp); while ((opf = fopen(outfile,"w")) == NULL) { printf(" Unable to open output file, please try again! "); printf(" Please enter the output file name: "); gets(outfile); } pos = index(outfile,'.'); if (pos != 0) { while (index(outfile+pos,'.') != 0) { i = index(outfile+pos,'.'); pos = pos + i; } if (index(outfile+pos,'.') == 0) { if (stringcmp(outfile,pos,pos+1,"..") == 0) { j = index(outfile+pos,'\0'); for (i=0; i<=j-1; i++) { stfile[i] = outfile[i]; } stfile[j] = 's'; stfile[j+1] = 't'; stfile[j+2] = 'a'; stfile[j+3] = 't'; stfile[j+4] = 'u'; stfile[j+5] = 's'; stfile[j+6] = '\0'; } else { for (i=0; i<=pos; i++) { stfile[i] = outfile[i]; } stfile[pos+1] = 's'; stfile[pos+2] = 't'; stfile[pos+3] = 'a'; stfile[pos+4] = 't'; stfile[pos+5] = 'u'; stfile[pos+6] = 's'; stfile[pos+7] = '\0'; } } } else { pos = index(outfile,'\0'); for (i=0; i= *maxlat) { if (*minlat != 0.0 || *maxlat != 0.0) { printf("\n Lower latitude bound must be less than the upper bound"); printf("\n Please re-enter latitude bounds!"); } printf("\n Enter lower latitude bound(-90.0,90.0): "); gets(s); *minlat = atof(s); while ((*minlat > 90.0) || (*minlat < -90.0)) { printf("\n Latitude out of bounds, please re-enter!"); printf("\n Enter lower latitude bound(-90.0,90.0): "); gets(s); *minlat = atof(s); } printf("\n Enter upper latitude bound(-90.0,90.0): "); gets(s); *maxlat = atof(s); while ((*maxlat > 90.0) || (*maxlat < -90.0)) { printf("\n Latitude out of bounds, please re-enter!"); printf("\n Enter upper latitude bound(-90.0,90.0): "); gets(s); *maxlat = atof(s); } } printf("\n Enter lower longitude bound(-180.0,360.0): "); gets(s); *minlon = atof(s); while ((*minlon > 360.0) || (*minlon < -180.0)) { printf("\n Longitude out of bounds, please re-enter!"); printf("\n Enter lower longitude bound(-180.0,360.0): "); gets(s); *minlon = atof(s); } printf("\n Enter upper longitude bound(-180.0,360.0): "); gets(s); *maxlon = atof(s); while ((*maxlon > 360.0) || (*maxlon < -180.0)) { printf("\n Longitude out of bounds, please re-enter!"); printf("\n Enter upper longitude bound(-180.0,360.0): "); gets(s); *maxlon = atof(s); } } else { *minlon = 0.0; *maxlon = 360.0; *minlat = -90.0; *maxlat = 90.0; } /**************************************************/ /* get input on output grid */ /**************************************************/ printf("\n Enter the number of longitude bins: "); gets(s); *nlon = atoi(s); while (*nlon < 1) { printf("\n Invalid selection, please re-enter!"); printf("\n Value must be greater than 0"); printf("\n Enter the number of longitude bins: "); gets(s); *nlon = atoi(s); } if (*maxlon > *minlon) printf("\n bin width is %7.2f degrees",(*maxlon-*minlon)/(float)*nlon); else printf("\n bin width is %7.2f degrees",(360.0+*maxlon-*minlon)/(float)*nlon); printf("\n Enter the number of latitude bins: "); gets(s); *nlat = atoi(s); while (*nlat < 1) { printf("\n Invalid selection, please re-enter!"); printf("\n Value must be greater than 0"); printf("\n Enter the number of latitude bins: "); gets(s); *nlat = atoi(s); } printf("\n bin height is %7.2f degrees",(*maxlat-*minlat)/(float)*nlat); inpok = 0; while (inpok == 0) { printf("\n Interpolate the grid to remove holes (y/n)? "); gets(csel); inpok = 1; if (stringcmp(csel,0,0,"y")==0 || stringcmp(csel,0,0,"Y")==0) *intdat = 1; else if (stringcmp(csel,0,0,"n")==0 || stringcmp(csel,0,0,"N")==0) *intdat = 0; else { inpok = 0; printf("\n Invalid selection, please re-enter!"); } } printf("\n\n"); } stringcmp(s,istart,iend,t) char s[],t[]; int istart,iend; { int i; i = istart; while (s[i] == t[i]) { if (s[i+1] == '\0' || i==iend) return(0); i++; } return(s[i] - t[i]); } oaname2(filename,temp,stfile) char filename[],temp[],stfile[]; { int i,j; i = 0; j = -1; while (filename[i] != '\0') { if (filename[i] == '/') j = i; i++; } for (i=0; i<=j; i++) temp[i] = filename[i]; i = j+1; while (filename[i] != '\0') { temp[i] = toupper(filename[i]); stfile[i] = toupper(filename[i]); ++i; } temp[i] = '.'; temp[i+1] = 'p'; temp[i+2] = 'i'; temp[i+3] = 'x'; temp[i+4] = '\0'; stfile[i] = '.'; stfile[i+1] = 's'; stfile[i+2] = 't'; stfile[i+3] = 'a'; stfile[i+4] = 't'; stfile[i+5] = 'u'; stfile[i+6] = 's'; stfile[i+7] = '\0'; } index(s,t) char s[],t; { int i; i = 0; while (s[i] != t && s[i] != '\0') { i++; if (s[i] == '\0' && t != '\0') { i = 0; break; } } return i; }