⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spread.c

📁 CA仿真模型中SLEUTH模型
💻 C
📖 第 1 页 / 共 3 页
字号:
#include <assert.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <errno.h>#include "igrid_obj.h"#include "landclass_obj.h"#include "globals.h"#include "random.h"#include "utilities.h"#include "memory_obj.h"#include "igrid_obj.h"#include "ugm_macros.h"#include "coeff_obj.h"#include "timer_obj.h"#include "proc_obj.h"#include "scenario_obj.h"#include "stats_obj.h"/*****************************************************************************\*********************************************************************************                                                                           ****                                 MACROS                                    ****                                                                           *********************************************************************************\*****************************************************************************/#define SPREAD_MODULE#define SWGHT_TYPE float#define SLOPE_WEIGHT_ARRAY_SZ 256/*****************************************************************************\*********************************************************************************                                                                           ****                        STATIC FUNCTION PROTOTYPES                         ****                                                                           *********************************************************************************\*****************************************************************************/static void    spr_LogSlopeWeights (FILE * fp, int array_size, SWGHT_TYPE * lut);static void    spr_spiral (int index,                                   /* IN     */                int *i_out,                                  /* OUT    */                int *j_out);                               /* OUT    */static void    spr_phase1n3 (COEFF_TYPE diffusion_coefficient,          /* IN     */                  COEFF_TYPE breed_coefficient,              /* IN     */                  GRID_P z,                                  /* IN     */                  GRID_P delta,                              /* IN/OUT */                  GRID_P slp,                                /* IN     */                  GRID_P excld,                              /* IN     */                  SWGHT_TYPE * swght,                        /* IN     */                  int *sng,                                  /* IN/OUT */                  int *sdc);                               /* IN/OUT */static void    spr_phase4 (COEFF_TYPE spread_coefficient,               /* IN     */                GRID_P z,                                    /* IN     */                GRID_P excld,                                /* IN     */                GRID_P delta,                                /* IN/OUT */                GRID_P slp,                                  /* IN     */                SWGHT_TYPE * swght,                          /* IN     */                int *og);                                  /* IN/OUT */static void    spr_phase5 (COEFF_TYPE road_gravity,                     /* IN     */                COEFF_TYPE diffusion_coefficient,            /* IN     */                COEFF_TYPE breed_coefficient,                /* IN     */                GRID_P z,                                    /* IN     */                GRID_P delta,                                /* IN/OUT */                GRID_P slp,                                  /* IN     */                GRID_P excld,                                /* IN     */                GRID_P roads,                                /* IN     */                SWGHT_TYPE * swght,                          /* IN     */                int *rt,                                     /* IN/OUT */                GRID_P workspace);                         /* MOD    */static void    spr_get_slp_weights (int array_size,                     /* IN     */                         SWGHT_TYPE * lut);                /* OUT    */static BOOLEAN spr_road_search (int i_grwth_center,          /* IN     */                                int j_grwth_center,          /* IN     */                                int *i_road,                 /* OUT    */                                int *j_road,                 /* OUT    */                                int max_search_index,        /* IN     */                                GRID_P roads);             /* IN     */static  BOOLEAN spr_road_walk (int i_road_start,                   /* IN     */                         int j_road_start,                   /* IN     */                         int *i_road_end,                    /* OUT    */                         int *j_road_end,                    /* OUT    */                         GRID_P roads,                       /* IN     */                         double diffusion_coefficient);    /* IN     */static  BOOLEAN spr_urbanize_nghbr (int i,                         /* IN     */                              int j,                         /* IN     */                              int *i_nghbr,                  /* OUT    */                              int *j_nghbr,                  /* OUT    */                              GRID_P z,                      /* IN     */                              GRID_P delta,                  /* IN     */                              GRID_P slp,                    /* IN     */                              GRID_P excld,                  /* IN     */                              SWGHT_TYPE * swght,            /* IN     */                              PIXEL pixel_value,             /* IN     */                              int *stat);                  /* OUT    */static  void spr_get_neighbor (int i_in,                           /* IN     */                         int j_in,                           /* IN     */                         int *i_out,                         /* OUT    */                         int *j_out);                      /* OUT    */static BOOLEAN    spr_urbanize (int row,                                   /* IN     */                  int col,                                   /* IN     */                  GRID_P z,                                  /* IN     */                  GRID_P delta,                              /* IN     */                  GRID_P slp,                                /* IN     */                  GRID_P excld,                              /* IN     */                  SWGHT_TYPE * swght,                        /* IN     */                  PIXEL pixel_value,                         /* IN     */                  int *stat);                              /* OUT    */static COEFF_TYPE    spr_GetDiffusionValue (COEFF_TYPE diffusion_coeff);    /* IN    */static COEFF_TYPE    spr_GetRoadGravValue (COEFF_TYPE rg_coeff);            /* IN    *//*****************************************************************************\*********************************************************************************                                                                           ****                               SCCS ID                                     ****                                                                           *********************************************************************************\*****************************************************************************/char spread_c_sccs_id[] = "@(#)spread.c	1.427	12/4/00";/*************************************************************************************************************************************************************** FUNCTION NAME: spr_phase1n3** PURPOSE:       perform phase 1 & 3 growth types** AUTHOR:        Keith Clarke** PROGRAMMER:    Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void  spr_phase1n3 (COEFF_TYPE diffusion_coefficient,            /* IN     */                COEFF_TYPE breed_coefficient,                /* IN     */                GRID_P z,                                    /* IN     */                GRID_P delta,                                /* IN/OUT */                GRID_P slp,                                  /* IN     */                GRID_P excld,                                /* IN     */                SWGHT_TYPE * swght,                          /* IN     */                int *sng,                                    /* IN/OUT */                int *sdc)                                  /* IN/OUT */{  char func[] = "spr_phase1n3";  int i;  int j;  int i_out;  int j_out;  int k;  int count;  int tries;  int max_tries;  COEFF_TYPE diffusion_value;  BOOLEAN urbanized;  FUNC_INIT;  assert (MIN_DIFFUSION_VALUE <= diffusion_coefficient);  assert (diffusion_coefficient <= MAX_DIFFUSION_VALUE);  assert (MIN_BREED_VALUE <= breed_coefficient);  assert (breed_coefficient <= MAX_BREED_VALUE);  assert (z != NULL);  assert (delta != NULL);  assert (slp != NULL);  assert (excld != NULL);  assert (swght != NULL);  assert (sng != NULL);  assert (sdc != NULL);  diffusion_value = spr_GetDiffusionValue (diffusion_coefficient);  for (k = 0; k < 1 + (int) diffusion_value; k++)  {    i = RANDOM_ROW;    j = RANDOM_COL;    if (INTERIOR_PT (i, j))    {      if (spr_urbanize (i,                                     /* IN     */                        j,                                     /* IN     */                        z,                                     /* IN     */                        delta,                                 /* IN/OUT */                        slp,                                   /* IN     */                        excld,                                 /* IN     */                        swght,                                 /* IN     */                        PHASE1G,                               /* IN     */                        sng))                              /* IN/OUT */      {        if (RANDOM_INT (101) < (int) breed_coefficient)        {          count = 0;          max_tries = 8;          for (tries = 0; tries < max_tries; tries++)          {            urbanized = FALSE;            urbanized =              spr_urbanize_nghbr (i,                         /* IN     */                                  j,                         /* IN     */                                  &i_out,                    /* OUT    */                                  &j_out,                    /* OUT    */                                  z,                         /* IN     */                                  delta,                     /* IN/OUT */                                  slp,                       /* IN     */                                  excld,                     /* IN     */                                  swght,                     /* IN     */                                  PHASE3G,                   /* IN     */                                  sdc);                    /* IN/OUT */            if (urbanized)            {              count++;              if (count == MIN_NGHBR_TO_SPREAD)              {                break;              }            }          }        }      }    }  }  FUNC_END;}/*************************************************************************************************************************************************************** FUNCTION NAME: spr_phase4** PURPOSE:       perform phase 4 growth** AUTHOR:        Keith Clarke** PROGRAMMER:    Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void  spr_phase4 (COEFF_TYPE spread_coefficient,                 /* IN     */              GRID_P z,                                      /* IN     */              GRID_P excld,                                  /* IN     */              GRID_P delta,                                  /* IN/OUT */              GRID_P slp,                                    /* IN     */              SWGHT_TYPE * swght,                            /* IN     */              int *og)                                     /* IN/OUT */{  char func[] = "spr_phase4";  int row;  int col;  int row_nghbr;  int col_nghbr;  int pixel;  int walkabout_row[8] = {-1, -1, -1, 0, 0, 1, 1, 1};  int walkabout_col[8] = {-1, 0, 1, -1, 1, -1, 0, 1};  int urb_count;  int nrows;  int ncols;  FUNC_INIT;  assert (z != NULL);  assert (excld != NULL);  assert (delta != NULL);  assert (slp != NULL);  assert (swght != NULL);  assert (og != NULL);  nrows = igrid_GetNumRows ();  ncols = igrid_GetNumCols ();  assert (nrows > 0);  assert (ncols > 0);  /*   *   * LOOP OVER THE INTERIOR PIXELS LOOKING FOR URBAN FROM WHICH   * TO PERFORM ORGANIC GROWTH   *   */  for (row = 1; row < nrows - 1; row++)  {    for (col = 1; col < ncols - 1; col++)    {      /*       *       * IS THIS AN URBAN PIXEL AND DO WE PASS THE RANDOM        * SPREAD COEFFICIENT TEST       *       */      if ((z[OFFSET (row, col)] > 0) &&          (RANDOM_INT (101) < spread_coefficient))      {        /*         * EXAMINE THE EIGHT CELL NEIGHBORS         * SPREAD AT RANDOM IF AT LEAST TWO ARE URBAN         * PIXEL ITSELF MUST BE URBAN (3)         *         */        urb_count = util_count_neighbors (z, row, col, GT, 0);        if ((urb_count >= 2) && (urb_count < 8))        {          pixel = RANDOM_INT (8);          row_nghbr = row + walkabout_row[pixel];          col_nghbr = col + walkabout_col[pixel];          spr_urbanize (row_nghbr,                           /* IN     */                        col_nghbr,                           /* IN     */                        z,                                   /* IN     */                        delta,                               /* IN/OUT */                        slp,                                 /* IN     */                        excld,                               /* IN     */                        swght,                               /* IN     */                        PHASE4G,                             /* IN     */                        og);                               /* IN/OUT */        }      }    }  }  FUNC_END;}/*************************************************************************************************************************************************************** FUNCTION NAME: spr_phase5** PURPOSE:       perform phase 5 growth** AUTHOR:        Keith Clarke** PROGRAMMER:    Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void  spr_phase5 (COEFF_TYPE road_gravity,                       /* IN     */              COEFF_TYPE diffusion_coefficient,              /* IN     */              COEFF_TYPE breed_coefficient,                  /* IN     */              GRID_P z,                                      /* IN     */              GRID_P delta,                                  /* IN/OUT */              GRID_P slp,                                    /* IN     */              GRID_P excld,                                  /* IN     */              GRID_P roads,                                  /* IN     */              SWGHT_TYPE * swght,                            /* IN     */              int *rt,                                       /* IN/OUT */              GRID_P workspace)                            /* MOD    */{  char func[] = "spr_phase5";  int iii;  int int_road_gravity;  int growth_count;  int *growth_row;  int *growth_col;  int max_search_index;  int growth_index;  BOOLEAN road_found;  int i_rd_start;  int j_rd_start;  int max_tries;  BOOLEAN spread;  BOOLEAN urbanized;  int i_rd_end;  int j_rd_end;  int i_rd_end_nghbr;  int j_rd_end_nghbr;  int i_rd_end_nghbr_nghbr;  int j_rd_end_nghbr_nghbr;  int tries;  int nrows;  int ncols;  int total_pixels;  FUNC_INIT;  assert (road_gravity > 0.0);  assert (diffusion_coefficient > 0.0);  assert (breed_coefficient > 0.0);  assert (z != NULL);  assert (delta != NULL);  assert (slp != NULL);  assert (excld != NULL);  assert (roads != NULL);  assert (swght != NULL);  assert (rt != NULL);  assert (workspace != NULL);  nrows = igrid_GetNumRows ();  ncols = igrid_GetNumCols ();  assert (nrows > 0);  assert (ncols > 0);  total_pixels = mem_GetTotalPixels ();  assert (total_pixels > 0);  /*   *   * SET UP WORKSPACE   *   */  growth_row = (int *) workspace;  growth_col = (int *) workspace + (nrows);  /*   *   * DETERMINE THE TOTAL GROWTH COUNT AND SAVE THE   * ROW AND COL LOCATIONS OF THE NEW GROWTH   *   */  growth_count = 0;#ifdef CRAY_C90#pragma _CRI ivdep#endif  for (iii = 0; iii < total_pixels; iii++)  {    if (delta[iii] > 0)    {      growth_row[growth_count] = iii / ncols;      growth_col[growth_count] = iii % ncols;      growth_count++;    }  }  /*   *   * PHASE 5:  ROAD TRIPS   * IF THERE IS NEW GROWTH, BEGIN PROCESSING ROAD TRIPS   *   */  if (growth_count > 0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -