igrid_obj.c
来自「CA仿真模型中SLEUTH模型」· C语言 代码 · 共 1,823 行 · 第 1/4 页
C
1,823 行
{ break; } }#ifdef PACKING ptr = mem_GetWGridPtr (file, fun, line); _unpack ((char *) igrid.road[i].ptr, ptr, total_pixels, -1);#else ptr = igrid.road[i].ptr;#endif return ptr;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetLanduseGridPtr** PURPOSE: return ptr to landuse grid data by index** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION: if the data is packed then we need to allocate space to** hold the unpacked data and then unpack it.***/GRID_P igrid_GetLanduseGridPtr (char *file, char *fun, int line, int index){ GRID_P ptr;#ifdef PACKING ptr = mem_GetWGridPtr (file, fun, line); _unpack ((char *) igrid.landuse[index].ptr, ptr, total_pixels, -1);#else ptr = igrid.landuse[index].ptr;#endif return ptr;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetSlopeGridPtr** PURPOSE: return ptr to slope grid data** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION: if the data is packed then we need to allocate space to** hold the unpacked data and then unpack it.***/GRID_P igrid_GetSlopeGridPtr (char *file, char *fun, int line){ GRID_P ptr;#ifdef PACKING ptr = mem_GetWGridPtr (file, fun, line); _unpack ((char *) igrid.slope.ptr, ptr, total_pixels, -1);#else ptr = igrid.slope.ptr;#endif return ptr;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetExcludedGridPtr** PURPOSE: return ptr to excluded grid data** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION: if the data is packed then we need to allocate space to** hold the unpacked data and then unpack it.***/GRID_P igrid_GetExcludedGridPtr (char *file, char *fun, int line){ GRID_P ptr;#ifdef PACKING ptr = mem_GetWGridPtr (file, fun, line); _unpack ((char *) igrid.excluded.ptr, ptr, total_pixels, -1);#else ptr = igrid.excluded.ptr;#endif return ptr;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetBackgroundGridPtr** PURPOSE: return ptr to background grid data** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION: if the data is packed then we need to allocate space to** hold the unpacked data and then unpack it.***/GRID_P igrid_GetBackgroundGridPtr (char *file, char *fun, int line){ GRID_P ptr;#ifdef PACKING ptr = mem_GetWGridPtr (file, fun, line); _unpack ((char *) igrid.background.ptr, ptr, total_pixels, -1);#else ptr = igrid.background.ptr;#endif return ptr;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_Debug** PURPOSE: a debug routine which can be called at various places** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void igrid_Debug (FILE * fp, char *caller, int location){ int i; fprintf (fp, "%s %u *******************************************\n", __FILE__, __LINE__); fprintf (fp, "%s %u CURRENT STATE OF IGRID OBJECT\n", __FILE__, __LINE__); fprintf (fp, "%s %u module: %s line: %u\n", __FILE__, __LINE__, caller, location); fprintf (fp, "%s %u *******************************************\n", __FILE__, __LINE__); fprintf (fp, "%s %u &igrid = %d\n", __FILE__, __LINE__, &igrid); fprintf (fp, "%s %u igrid.location = %s\n", __FILE__, __LINE__, igrid.location); fprintf (fp, "%s %u igrid.urban_count = %d\n", __FILE__, __LINE__, igrid.urban_count); fprintf (fp, "%s %u igrid.road_count = %d\n", __FILE__, __LINE__, igrid.road_count); fprintf (fp, "%s %u igrid.landuse_count = %d\n", __FILE__, __LINE__, igrid.landuse_count); fprintf (fp, "%s %u igrid.excluded_count = %d\n", __FILE__, __LINE__, igrid.excluded_count); fprintf (fp, "%s %u igrid.slope_count = %d\n", __FILE__, __LINE__, igrid.slope_count); fprintf (fp, "%s %u igrid.background_count = %d\n", __FILE__, __LINE__, igrid.background_count); for (i = 0; i < igrid.urban_count; i++) { fprintf (fp, "\n%s %u Urban grid #%u \n", __FILE__, __LINE__, i); grid_dump (fp, &igrid.urban[i]); } for (i = 0; i < igrid.road_count; i++) { fprintf (fp, "\n%s %u Road grid #%u \n", __FILE__, __LINE__, i); grid_dump (fp, &igrid.road[i]); } for (i = 0; i < igrid.landuse_count; i++) { fprintf (fp, "\n%s %u Landuse grid #%u \n", __FILE__, __LINE__, i); grid_dump (fp, &igrid.landuse[i]); } fprintf (fp, "\n%s %u Excluded grid\n", __FILE__, __LINE__); grid_dump (fp, &igrid.excluded); fprintf (fp, "\n%s %u Slope grid\n", __FILE__, __LINE__); grid_dump (fp, &igrid.slope); fprintf (fp, "\n%s %u Background grid\n", __FILE__, __LINE__); grid_dump (fp, &igrid.background); fprintf (fp, "%s %u *******************************************\n", __FILE__, __LINE__); fprintf (fp, "%s %u *******************************************\n", __FILE__, __LINE__);}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_Dump** PURPOSE: dump the values in a grid** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void igrid_Dump (GRID_P ptr, FILE * fp){ int i; int j; int k = 0; int rows; int cols; rows = igrid_GetNumRows (); cols = igrid_GetNumCols (); for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { fprintf (fp, " %3u", ptr[k++]); } fprintf (fp, "\n"); }}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_NormalizeRoads** PURPOSE: normalizes road grids** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void igrid_NormalizeRoads (){ char func[] = "igrid_NormalizeRoads"; int i; int j; PIXEL max_of_max = 0; GRID_P grid_ptr; float image_max; float norm_factor;#ifdef PACKING grid_ptr = mem_GetWGridPtr (__FILE__, func, __LINE__);#endif for (i = 0; i < igrid.road_count; i++) { max_of_max = MAX (max_of_max, igrid.road[i].max); } for (i = 0; i < igrid.road_count; i++) {#ifdef PACKING _unpack ((char *) igrid.road[i].ptr, grid_ptr, total_pixels, -1);#else grid_ptr = igrid.road[i].ptr;#endif image_max = (float) igrid.road[i].max; norm_factor = image_max / (float) max_of_max; for (j = 0; j < total_pixels; j++) { grid_ptr[j] = (PIXEL) (((100.0 * grid_ptr[j]) / image_max) * norm_factor); } }#ifdef PACKING mem_GetWGridFree (__FILE__, func, __LINE__, grid_ptr);#endif}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_ValidateGrids** PURPOSE: validate all input grid values** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void igrid_ValidateGrids (FILE * fp){ FILE *loc_fp; BOOLEAN AOK = TRUE; if (fp) { fprintf (fp, "\n*******************************************************\n"); fprintf (fp, "*******************************************************\n"); fprintf (fp, " VALIDATING INPUT GRIDS\n"); } if (!igrid_ValidateUrbanGrids (fp)) AOK = FALSE; if (!igrid_ValidateRoadGrids (fp)) AOK = FALSE; if (!igrid_ValidateLanduseGrids (fp)) AOK = FALSE; if (!igrid_ValidateSlopeGrid (fp)) AOK = FALSE; if (!igrid_ValidateExcludedGrid (fp)) AOK = FALSE; if (!igrid_ValidateBackgroundGrid (fp)) AOK = FALSE; if (!AOK) { if (!fp) loc_fp = stderr; fprintf (loc_fp, "\nERROR\n"); fprintf (loc_fp, "\nInput data images contain errors.\n"); EXIT (1); } else { if (fp) { fprintf (fp, "\nValidation OK\n"); } } if (fp) { fprintf (fp, "*******************************************************\n"); fprintf (fp, "*******************************************************\n"); }}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_ValidateUrbanGrids** PURPOSE: check the validity of the urban grids** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static BOOLEAN igrid_ValidateUrbanGrids (FILE * fp){ BOOLEAN rv = TRUE; int i; int j; for (i = 0; i < igrid.urban_count; i++) { if (fp) { fprintf (fp, "\nValidating urban input grid: %s\n", igrid.urban[i].filename); fprintf (fp, "\nIndex Count PercentOfImage\n"); } for (j = 0; j < 256; j++) { if (igrid.urban[i].histogram[j] > 0) { if (fp) { fprintf (fp, "%3u %5u %8.2f%%\n", j, igrid.urban[i].histogram[j], 100.0 * igrid.urban[i].histogram[j] / total_pixels); } } } if (igrid.urban[i].histogram[0] == 0) { if (fp) { fprintf (fp, "ERROR input grid: %s is completely urbanized\n", igrid.urban[i].filename); } else { fprintf (stderr, "ERROR input grid: %s is completely urbanized\n", igrid.urban[i].filename); } rv = FALSE; } } return rv;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_ValidateRoadGrids** PURPOSE: check the validity of the road grids** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static BOOLEAN igrid_ValidateRoadGrids (FILE * fp){ BOOLEAN rv = TRUE; int i; int j; for (i = 0; i < igrid.road_count; i++) { if (fp) { fprintf (fp, "\nValidating road input grid: %s\n", igrid.road[i].filename); fprintf (fp, "\nIndex Count PercentOfImage\n"); for (j = 0; j < 256; j++) { if (igrid.road[i].histogram[j] > 0) { fprintf (fp, "%3u %5u %8.2f%%\n", j, igrid.road[i].histogram[j], 100.0 * igrid.road[i].histogram[j] / total_pixels); } } } if (igrid.road[i].histogram[0] == 0) { if (fp) { fprintf (fp, "ERROR input grid: %s is 100%% roads\n", igrid.road[i].filename); } else { fprintf (stderr, "ERROR input grid: %s is 100%% roads\n", igrid.road[i].filename); } rv = FALSE; } } return rv;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_ValidateLanduseGrids** PURPOSE: check validity of landuse grid values** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static BOOLEAN
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?