igrid_obj.c
来自「CA仿真模型中SLEUTH模型」· C语言 代码 · 共 1,823 行 · 第 1/4 页
C
1,823 行
/*************************************************************************************************************************************************************** MODULE PROLOG *********************************************************************************This object encapsulates the management of the input data grids.*************************************************************************************************************************************************************/#include <assert.h>#include <stdlib.h>#include <string.h>#include <stdio.h>#include <errno.h>#ifdef MPI#include "mpi.h"#endif#include "igrid_obj.h"#include "scenario_obj.h"#include "globals.h"#include "memory_obj.h"#include "gdif_obj.h"#include "output.h"#include "color_obj.h"#include "landclass_obj.h"#include "ugm_macros.h"#include "proc_obj.h"/*****************************************************************************\********************************************************************************* **** SCCS ID **** *********************************************************************************\*****************************************************************************/char igrid_obj_c_sccs_id[] = "@(#)igrid_obj.c 1.84 12/4/00";/*****************************************************************************\********************************************************************************* **** STATIC MEMORY FOR THIS OBJECT **** *********************************************************************************\*****************************************************************************/static igrid_info igrid;static int igrid_count;static int road_pixel_count[MAX_ROAD_YEARS];static int excld_count;static road_percent_t percent_road[MAX_ROAD_YEARS];static int total_pixels;/*****************************************************************************\********************************************************************************* **** MACROS **** *********************************************************************************\*****************************************************************************/#define EXTRACT_FILENAME(a) \ filename = strrchr ((a), '/'); \ if (filename) \ { \ filename++; \ } \ else \ { \ filename = (a); \ }/*****************************************************************************\********************************************************************************* **** STATIC FUNCTION PROTOTYPES **** *********************************************************************************\*****************************************************************************/static void igrid_CalculatePercentRoads ();static BOOLEAN igrid_ValidateUrbanGrids (FILE * fp);static BOOLEAN igrid_ValidateRoadGrids (FILE * fp);static BOOLEAN igrid_ValidateLanduseGrids (FILE * fp);static BOOLEAN igrid_ValidateSlopeGrid (FILE * fp);static BOOLEAN igrid_ValidateExcludedGrid (FILE * fp);static BOOLEAN igrid_ValidateBackgroundGrid (FILE * fp);static void igrid_CountRoadPixels ();static void igrid_echo_input (GRID_P ptr, char *filename);static void igrid_SetLocation ();static void igrid_SetFilenames ();static void igrid_SetGridSizes (grid_info * grid_ptr);static void igrid_ReadGrid (char *filepath, GRID_P scrtch_pad, GRID_P grid_p);/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_MemoryLog** PURPOSE: write out memory map to FILE* fp** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void igrid_MemoryLog (FILE * fp){ LOG_MEM (fp, &igrid, sizeof (igrid_info), 1); LOG_MEM (fp, &igrid_count, sizeof (int), 1); LOG_MEM (fp, &road_pixel_count[0], sizeof (int), MAX_ROAD_YEARS); LOG_MEM (fp, &excld_count, sizeof (int), 1); LOG_MEM (fp, &percent_road[0], sizeof (road_percent_t), MAX_ROAD_YEARS); LOG_MEM (fp, &total_pixels, sizeof (int), 1);}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetIGridRoadPixelCount** PURPOSE: get road year pixel count by date** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION: A year is pasted into the function and it then searches** all the road years igrid structs looking for the road** eqaul to or previous to the requested year. It returns** the road pixel count for that year.***/int igrid_GetIGridRoadPixelCount (int year){ int i; for (i = igrid.road_count - 1; i > 0; i--) { if (year >= igrid.road[i].year.digit) { break; } } return road_pixel_count[i];}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetIGridExcludedPixelCount** PURPOSE: return the # of excluded pixels** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/int igrid_GetIGridExcludedPixelCount (){ return excld_count;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetIGridRoadPercentage** PURPOSE: return the % of road pixels for a given year** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/road_percent_t igrid_GetIGridRoadPercentage (int year){ int i; for (i = igrid.road_count - 1; i > 0; i--) { if (year > igrid.road[i].year.digit) { break; } } return percent_road[i];}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetIGridCount** PURPOSE: return the # of igrids (or input grids)** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/int igrid_GetIGridCount (){ return igrid_count;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetNumRows** PURPOSE: return the # rows in a grid** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/int igrid_GetNumRows (){ return igrid.slope.nrows;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetNumCols** PURPOSE: return the # cols in a grid** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/int igrid_GetNumCols (){ return igrid.slope.ncols;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetNumTotalPixels** PURPOSE: return the total # pixels in grid** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/int igrid_GetNumTotalPixels (){ return igrid.slope.ncols * igrid.slope.nrows;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetUrbanYear** PURPOSE: return urban date as a digit for a given urban index** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/int igrid_GetUrbanYear (int i){ return igrid.urban[i].year.digit;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetLanduseYear** PURPOSE: return landuse date as a digit for a given landuse index** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/int igrid_GetLanduseYear (int i){ return igrid.landuse[i].year.digit;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetUrbanCount** PURPOSE: return the # of urban grids** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/int igrid_GetUrbanCount (){ return igrid.urban_count;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetLocation** PURPOSE: return location string for this scenario** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/char * igrid_GetLocation (){ return igrid.location;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GridRelease** PURPOSE: release the memory used by a grid** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/GRID_P igrid_GridRelease (char *file, char *fun, int line, GRID_P ptr){#ifdef PACKING return mem_GetWGridFree (file, fun, line, ptr);#else return NULL;#endif}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetUrbanGridPtr** PURPOSE: return ptr to urban 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_GetUrbanGridPtr (char *file, char *fun, int line, int index){ GRID_P ptr;#ifdef PACKING ptr = mem_GetWGridPtr (file, fun, line); _unpack ((char *) igrid.urban[index].ptr, ptr, total_pixels, -1);#else ptr = igrid.urban[index].ptr;#endif return ptr;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetRoadGridPtr** PURPOSE: return ptr to road 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_GetRoadGridPtr (char *file, char *fun, int line, int index){ GRID_P ptr;#ifdef PACKING ptr = mem_GetWGridPtr (file, fun, line); _unpack ((char *) igrid.road[index].ptr, ptr, total_pixels, -1);#else ptr = igrid.road[index].ptr;#endif return ptr;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetUrbanGridPtrByYear** PURPOSE: return ptr to urban grid data by year** 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_GetUrbanGridPtrByYear (char *file, char *fun, int line, int year){ GRID_P ptr; int i; assert (year >= igrid.urban[0].year.digit); for (i = igrid.urban_count - 1; i > 0; i--) { if (year >= igrid.urban[i].year.digit) { break; } }#ifdef PACKING ptr = mem_GetWGridPtr (file, fun, line); _unpack ((char *) igrid.urban[i].ptr, ptr, total_pixels, -1);#else ptr = igrid.urban[i].ptr;#endif return ptr;}/*************************************************************************************************************************************************************** FUNCTION NAME: igrid_GetRoadGridPtrByYear** PURPOSE: return ptr to road grid data by year** 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_GetRoadGridPtrByYear (char *file, char *fun, int line, int year){ GRID_P ptr; int i; for (i = igrid.road_count - 1; i > 0; i--) { if (year >= igrid.road[i].year.digit)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?