#include #include #include #include double get_dist(double,double,double,double); int main(int argc, char *argv[]) { /*********************************************************************** clac_xmask.c Keith Cherkauer November 24, 1998 This program reads the routing model direction file, and uses the cell location and direction of flow to determine the length of the flow path through the grid cell. It uses the routine new_get_dist.c to compute the actual horizontal, vertical, and diagonal distances in meters on the globe. 1-8-99 Modified for newest version of routing model which uses standard ARC/INFO ASCII Grid headers, and reads xmask values in meters. KAC ***********************************************************************/ FILE *fdirec, *fxmask; int row, col, nrows, ncols; int direc; double cell_lat, cell_lng; double ll_lat, ll_lng; double cellsize; double NODATA; if(argc!=3) { fprintf(stderr,"Usage: %s \n",argv[0]); exit(0); } if((fdirec=fopen(argv[1],"r"))==NULL) { fprintf(stderr,"ERROR: Unable to open input file %s\n",argv[1]); exit(0); } if((fxmask=fopen(argv[2],"w"))==NULL) { fprintf(stderr,"ERROR: Unable to open output file %s\n",argv[2]); exit(0); } /** Read Header **/ fscanf(fdirec,"%*s %i", &ncols); fscanf(fdirec,"%*s %i", &nrows); fscanf(fdirec,"%*s %lf",&ll_lng); fscanf(fdirec,"%*s %lf",&ll_lat); fscanf(fdirec,"%*s %lf",&cellsize); fscanf(fdirec,"%*s %lf",&NODATA); fprintf(fxmask,"ncols\t%i\n", ncols); fprintf(fxmask,"nrows\t%i\n", nrows); fprintf(fxmask,"xllcorner\t%.1lf\n",ll_lng); fprintf(fxmask,"yllcorner\t%.1lf\n",ll_lat); fprintf(fxmask,"cellsize\t%.3lf\n",cellsize); fprintf(fxmask,"NODATA_value\t%.0lf\n",NODATA); /** Process Direction Number **/ for(row=0;row