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

📄 growth.c

📁 CA仿真模型中SLEUTH模型
💻 C
📖 第 1 页 / 共 2 页
字号:
  void  grw_landuse (                GRID_P land1_ptr,                            /* OUT    */                int num_growth_pix                           /* IN     */  ){  char func[] = "grw_landuse";  char gif_filename[MAX_FILENAME_LEN];  char date_str[5];  int ticktock;  int landuse0_year;  int landuse1_year;  int urban_code;  int *new_indices;  Classes *landuse_classes;  Classes *class_indices;  GRID_P background_ptr;  GRID_P grw_landuse_ws1;  GRID_P deltatron_ptr;  GRID_P z_ptr;  GRID_P deltatron_workspace1;  GRID_P slp_ptr;  GRID_P land2_ptr;  double *class_slope;  double *ftransition;  FUNC_INIT;  ticktock = proc_GetCurrentYear ();  landuse0_year = igrid_GetLanduseYear (0);  landuse1_year = igrid_GetLanduseYear (1);  urban_code = landclass_GetUrbanCode ();  new_indices = landclass_GetNewIndicesPtr ();  landuse_classes = landclass_GetClassesPtr ();  class_indices = landclass_GetReducedClassesPtr ();  background_ptr = igrid_GetBackgroundGridPtr (__FILE__, func, __LINE__);  grw_landuse_ws1 = mem_GetWGridPtr (__FILE__, func, __LINE__);  deltatron_workspace1 = mem_GetWGridPtr (__FILE__, func, __LINE__);  slp_ptr = igrid_GetSlopeGridPtr (__FILE__, func, __LINE__);  deltatron_ptr = pgrid_GetDeltatronPtr ();  z_ptr = pgrid_GetZPtr ();  land2_ptr = pgrid_GetLand2Ptr ();  class_slope = trans_GetClassSlope ();  ftransition = trans_GetFTransition ();  assert (ticktock >= 0);  assert (z_ptr != NULL);  assert (urban_code > 0);  assert (new_indices != NULL);  assert (landuse_classes != NULL);  assert (class_indices != NULL);  assert (grw_landuse_ws1 != NULL);  assert (deltatron_workspace1 != NULL);  assert (deltatron_ptr != NULL);  assert (land1_ptr != NULL);  assert (land2_ptr != NULL);  assert (slp_ptr != NULL);  assert (class_slope != NULL);  assert (ftransition != NULL);  /* influence land use */  if (ticktock >= landuse0_year)  {    /*     *     * PLACE THE NEW URBAN SIMULATION INTO THE LAND USE IMAGE     *     */    util_condition_gif (mem_GetTotalPixels (),                        z_ptr,                        GT,                        0,                        land1_ptr,                        urban_code);    delta_deltatron (new_indices,                            /* IN     */                     landuse_classes,                        /* IN     */                     class_indices,                          /* IN     */                     deltatron_workspace1,                   /* MOD    */                     deltatron_ptr,                          /* IN/OUT */                     land1_ptr,                              /* IN     */                     land2_ptr,                              /* OUT    */                     slp_ptr,                                /* IN     */                     num_growth_pix,                         /* IN     */                     class_slope,                            /* IN     */                     ftransition);                         /* IN     */    /*     *     * SWITCH THE OLD AND THE NEW     *     */    util_copy_grid (land2_ptr,                    land1_ptr);  }  if ((proc_GetProcessingType () == PREDICTING) ||      (proc_GetProcessingType () == TESTING) &&      (proc_GetLastMonteCarloFlag ()))  {    /*     *     * WRITE LAND1 GIF TO FILE     *     */    sprintf (gif_filename, "%s%s_land_n_urban.%u.gif",     scen_GetOutputDir (), igrid_GetLocation (), proc_GetCurrentYear ());    sprintf (date_str, "%u", proc_GetCurrentYear ());    gdif_WriteGIF (land1_ptr,                   color_GetColortable (LANDUSE_COLORTABLE),                   gif_filename,                   date_str,                   255);  }  /*   *   * COMPUTE FINAL MATCH STATISTIC FOR LANDUSE   *   */  if (proc_GetCurrentYear () == landuse1_year)  {    util_condition_gif (mem_GetTotalPixels (),                        z_ptr,                        GT,                        0,                        land1_ptr,                        urban_code);  }  background_ptr =    igrid_GridRelease (__FILE__, func, __LINE__, background_ptr);  grw_landuse_ws1 =    mem_GetWGridFree (__FILE__, func, __LINE__, grw_landuse_ws1);  deltatron_workspace1 =    mem_GetWGridFree (__FILE__, func, __LINE__, deltatron_workspace1);  slp_ptr = igrid_GridRelease (__FILE__, func, __LINE__, slp_ptr);  FUNC_END;}/*************************************************************************************************************************************************************** FUNCTION NAME: grw_non_landuse** PURPOSE:       routine for handling non landuse processing** AUTHOR:        Keith Clarke** PROGRAMMER:    Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void  grw_non_landuse (GRID_P z_ptr){  char func[] = "grw_non_landuse";  char command[2 * MAX_FILENAME_LEN + 20];  GRID_P workspace1;  GRID_P workspace2;  int num_monte_carlo;  char name[] = "_urban_";  char gif_filename[MAX_FILENAME_LEN];  GRID_P cumulate_monte_carlo;  int i;  FUNC_INIT;  workspace1 = mem_GetWGridPtr (__FILE__, func, __LINE__);  workspace2 = mem_GetWGridPtr (__FILE__, func, __LINE__);  num_monte_carlo = scen_GetMonteCarloIterations ();  assert (workspace1 != NULL);  assert (workspace2 != NULL);  assert (z_ptr != NULL);  cumulate_monte_carlo = workspace1;  if (proc_GetProcessingType () != CALIBRATING)  {    if (proc_GetCurrentMonteCarlo () == 0)    {      /*       *       * ZERO OUT THE ACCUMULATION GRID       *       */      util_init_grid (cumulate_monte_carlo, 0);    }    else    {      /*       *       * READ IN THE ACCUMULATION GRID       *       */      sprintf (gif_filename, "%scumulate_monte_carlo.year_%u",               scen_GetOutputDir (), proc_GetCurrentYear ());      inp_slurp (gif_filename,                               /* IN    */                 cumulate_monte_carlo,                       /* OUT   */                 memGetBytesPerGridRound ());              /* IN    */    }    /*     *     * ACCUMULATE Z OVER MONTE CARLOS     *     */    for (i = 0; i < mem_GetTotalPixels (); i++)    {      if (z_ptr[i] > 0)      {        cumulate_monte_carlo[i]++;      }    }    if (proc_GetCurrentMonteCarlo () == num_monte_carlo - 1)    {      if (proc_GetProcessingType () == TESTING)      {        util_condition_gif (mem_GetTotalPixels (),           /* IN     */                            z_ptr,                           /* IN     */                            GT,                              /* IN     */                            0,                               /* IN     */                            cumulate_monte_carlo,            /* IN/OUT */                            100);                          /* IN     */      }      else      {        /*         *         * NORMALIZE ACCULUMLATED GRID         *         */        for (i = 0; i < mem_GetTotalPixels (); i++)        {          cumulate_monte_carlo[i] =            100 * cumulate_monte_carlo[i] / num_monte_carlo;        }      }      util_WriteZProbGrid (cumulate_monte_carlo, name);      if (proc_GetCurrentMonteCarlo () != 0)      {        sprintf (command, "rm %s", gif_filename);        system (command);      }    }    else    {      /*       *       * DUMP ACCULUMLATED GRID TO DISK       *       */      sprintf (gif_filename, "%scumulate_monte_carlo.year_%u",               scen_GetOutputDir (), proc_GetCurrentYear ());      out_dump (gif_filename,                cumulate_monte_carlo,                memGetBytesPerGridRound ());    }  }  workspace1 = mem_GetWGridFree (__FILE__, func, __LINE__, workspace1);  workspace2 = mem_GetWGridFree (__FILE__, func, __LINE__, workspace2);  FUNC_END;}/*************************************************************************************************************************************************************** FUNCTION NAME: grw_completion_status** PURPOSE:       write completion status on FILE* fp** AUTHOR:        Keith Clarke** PROGRAMMER:    Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void  grw_completion_status (FILE * fp){  int total_mc;  int total_mc_executed;  int wd1;  int wd2;  char buf1[25];  char buf2[25];  char buf3[25];  char buf4[25];  float complete;  float elapsed_sec;  float est_execution_time;  float est_remaining_sec;  char elapsed_sec_f[15];  char est_remaining_sec_f[15];  total_mc =    (scen_GetMonteCarloIterations () * proc_GetTotalRuns ()) / glb_npes;  total_mc_executed = scen_GetMonteCarloIterations () *    proc_GetNumRunsExecThisCPU () + proc_GetCurrentMonteCarlo ();  complete = (float) total_mc_executed / (float) total_mc;  complete = MIN (complete, 1.0);  elapsed_sec = timer_Read (TOTAL_TIME) / 1000;  est_remaining_sec = 0.0;  sprintf (buf1, "%15u", proc_GetTotalRuns ());  sprintf (buf2, "%15u", proc_GetCurrentRun ());  util_trim (buf1);  wd1 = strlen (buf1);  sprintf (buf3, "%15u", scen_GetMonteCarloIterations ());  sprintf (buf4, "%15u", proc_GetCurrentMonteCarlo ());  util_trim (buf3);  wd2 = strlen (buf3);#if 1  fprintf (fp, "%s %u Run= %s of %s MC=%s of %s ",           __FILE__, __LINE__,           &buf2[15 - wd1], buf1,           &buf4[15 - wd2], buf3);#else  fprintf (fp, "%s %u Run= %u of %u MC=%u of %u ",           __FILE__, __LINE__,           proc_GetCurrentRun (), proc_GetTotalRuns (),           proc_GetCurrentMonteCarlo (), scen_GetMonteCarloIterations ());#endif  if (complete > 0.0)  {    est_execution_time = elapsed_sec / complete;    est_remaining_sec = (est_execution_time - elapsed_sec);    timer_Format (elapsed_sec_f, (unsigned int) elapsed_sec);    timer_Format (est_remaining_sec_f, (unsigned int) est_remaining_sec);    fprintf (fp,             "%7.3f%% complete; Elapsed=%s ; ETC=%s\n",             100.0 * complete, elapsed_sec_f,             est_remaining_sec_f);  }  else  {    fprintf (fp, "\n");  }}

⌨️ 快捷键说明

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