#include #include #include #include static char vcid[] = "$Id: read_arcinfo_ascii.c,v 4.2 2005/08/25 21:04:19 vicadmin Exp $"; double read_arcinfo_value(char *filename, double lat, double lng) { /********************************************************************** read_arcinfo_value Keith Cherkauer May 5, 1998 This subroutine reads a single data value from an ARC/INFO ASCII output grid file. The latitude and longitude of the center of the grid cell of interest is provided to this routine. **********************************************************************/ FILE *farc; int i, j; int ncols; int nrows; double ll_lat; double ll_lng; double cellsize; double NODATA; double value; double tmp_lat; double tmp_lng; double tmpvalue; char errstr[MAXSTRING]; if((farc=fopen(filename,"r"))==NULL) { sprintf(errstr,"Unable to open ARC/INFO soil file %s",filename); nrerror(errstr); } /***** Read ARC/INFO Header *****/ fscanf(farc,"%*s %d",&ncols); fscanf(farc,"%*s %d",&nrows); fscanf(farc,"%*s %lf",&ll_lng); fscanf(farc,"%*s %lf",&ll_lat); fscanf(farc,"%*s %lf",&cellsize); fscanf(farc,"%*s %lf",&NODATA); /***** Check for Valid Location *****/ if(latll_lat+cellsize*(double)nrows) { sprintf(errstr,"Given latitude %f does not fall within ARC file %s", lat,filename); nrerror(errstr); } if(lngll_lng+cellsize*(double)ncols) { sprintf(errstr,"Given longitude %f does not fall within ARC file %s", lng,filename); nrerror(errstr); } value = NODATA; for(j=0;j