/* mapfit.c * mapfit [infile] [outfile] [coef_file] coef_file format: LAT_COEF = 2 -0.0939 1.00253 LON_COEF = 6 24.84284 1.41358 0.00156 -0.55813 0.00267 -0.00528 */ #include #include #include double A[10],B[10]; int NumLat,NumLon; char *At[10]= { "intercept", "Lat", "Lon", "Lat**2", "Lat*Lon", "Lon**2", "Lat**3", "Lat**2*Lon", "Lat*Lon**2", "Lon**3" }; char *Bt[10]= { "intercept", "Lon", "Lat", "Lon**2", "Lon*Lat", "Lat**2", "Lon**3", "Lon**2*Lat", "Lon*Lat**2", "Lat**3" }; double convert(int num,double *coef,double x,double y); main(int argc,char *argv[]) { int i,j,k=0; char string[100],str1[100],cr=0xd; FILE *fpin,*fpout,*fpcof; double islat,islon,sblat,sblon; int end=0; long attrib; if(argc<4) error(); fpcof=fopen(argv[3],"rt"); if(!fpcof) { printf("Could not open '%s'\n",argv[3]); error(); } fscanf(fpcof,"%s",string); if(strcmpi(string,"LAT_COEF")!=0) { printf("no LAT_COEF id\n"); error(); } fscanf(fpcof,"%s%d",string,&NumLat); if(NumLat<1||NumLat>10) { printf("Bad Num Lat\n"); error(); } for(i=0;i10) { printf("Bad Num Lon\n"); error(); } for(i=0;i1) z+=coef[1]*x; if(num>2) z+=coef[2]*y; if(num>3) z+=coef[3]*x*x; if(num>4) z+=coef[4]*x*y; if(num>5) z+=coef[5]*y*y; if(num>6) z+=coef[6]*x*x*x; if(num>7) z+=coef[7]*x*x*y; if(num>8) z+=coef[8]*x*y*y; if(num>9) z+=coef[9]*y*y*y; return(z); } /************************************************************************** ** ** ** ************************************************************************* */ int error() { printf("\n\nmapfit [infile] [outfile] [coef_file]\n"); printf("mapfit test.raw newtest.raw test.cof\n"); printf("\n"); printf("coef_file FORMAT:\n\n"); printf("LAT_COEF = N\n"); printf("intercept \n"); printf("Lat Lon \n"); printf("Lat**2 Lat*Lon Lon**2 \n"); printf("Lat**3 Lat**2*Lon Lat*Lon**2 Lon** \n"); printf("LON_COEF = M\n"); printf("intercept \n"); printf("Lon Lat \n"); printf("Lon**2 Lon*Lat Lat**2 \n"); printf("Lon**3 Lon**2*Lat Lon*Lat**2 Lat** \n"); printf("\n"); printf("EXAMPLE:\n"); printf("\n"); printf("LAT_COEF = 2\n"); printf(" -0.0939 1.00253\n"); printf("LON_COEF = 6\n"); printf(" 24.84284 1.41358 0.00156 -0.55813 0.00267 -0.00528\n\n"); exit(0); }