📄 growth.c
字号:
#define GROWTH_MODULE#include <assert.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "coeff_obj.h"#include "igrid_obj.h"#include "pgrid_obj.h"#include "landclass_obj.h"#include "globals.h"#include "input.h"#include "output.h"#include "utilities.h"#include "growth.h"#include "spread.h"#include "random.h"#include "deltatron.h"#include "ugm_macros.h"#include "proc_obj.h"#include "scenario_obj.h"#include "memory_obj.h"#include "transition_obj.h"#include "color_obj.h"#include "timer_obj.h"#include "gdif_obj.h"#include "timer_obj.h"#include "stats_obj.h"/*****************************************************************************\********************************************************************************* **** SCCS ID **** *********************************************************************************\*****************************************************************************/char growth_c_sccs_id[] = "@(#)growth.c 1.629 12/4/00";/*****************************************************************************\********************************************************************************* **** STATIC FUNCTION PROTOTYPES **** *********************************************************************************\*****************************************************************************/static void grw_non_landuse (GRID_P z_ptr);static void grw_landuse_init (GRID_P deltatron_ptr, GRID_P land1_ptr);static void grw_landuse ( GRID_P land1_ptr, int num_growth_pix);static void grw_completion_status (FILE * fp);/*************************************************************************************************************************************************************** FUNCTION NAME: grw_grow** PURPOSE: loop over simulated years** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void grw_grow (GRID_P z_ptr, GRID_P land1_ptr){ char func[] = "grw_grow"; char gif_filename[MAX_FILENAME_LEN]; char date_str[5]; GRID_P deltatron_ptr; GRID_P seed_ptr; int total_pixels; float average_slope; int num_growth_pix = 0; int sng; int sdg; int sdc; int og; int rt; int pop; FUNC_INIT; timer_Start (GRW_GROWTH); total_pixels = mem_GetTotalPixels (); deltatron_ptr = pgrid_GetDeltatronPtr (); assert (total_pixels > 0); assert (deltatron_ptr != NULL); if (proc_GetProcessingType () == PREDICTING) { proc_SetCurrentYear (scen_GetPredictionStartDate ()); } else { proc_SetCurrentYear (igrid_GetUrbanYear (0)); } util_init_grid (z_ptr, 0); if (scen_GetDoingLanduseFlag ()) { grw_landuse_init (deltatron_ptr, land1_ptr); } seed_ptr = igrid_GetUrbanGridPtr (__FILE__, func, __LINE__, 0); util_condition_gif (total_pixels, seed_ptr, GT, 0, z_ptr, PHASE0G); seed_ptr = igrid_GridRelease (__FILE__, func, __LINE__, seed_ptr); if (scen_GetEchoFlag ()) { printf ("\n%s %u ******************************************\n", __FILE__, __LINE__); if (proc_GetProcessingType () == CALIBRATING) { printf ("%s %u Run = %u of %u (%8.1f percent complete)\n", __FILE__, __LINE__, proc_GetCurrentRun (), proc_GetTotalRuns (), (100.0 * proc_GetCurrentRun ()) / proc_GetTotalRuns ()); } printf ("%s %u Monte Carlo = %u of %u\n", __FILE__, __LINE__, proc_GetCurrentMonteCarlo () + 1, scen_GetMonteCarloIterations ()); fprintf (stdout, "%s %u proc_GetCurrentYear=%u\n", __FILE__, __LINE__, proc_GetCurrentYear ()); fprintf (stdout, "%s %u proc_GetStopYear=%u\n", __FILE__, __LINE__, proc_GetStopYear ()); } if (scen_GetLogFlag ()) { if (scen_GetLogProcessingStatusFlag () > 0) { scen_Append2Log (); grw_completion_status (scen_GetLogFP ()); scen_CloseLog (); } } while (proc_GetCurrentYear () < proc_GetStopYear ()) { /* * * INCREMENT CURRENT YEAR * */ proc_IncrementCurrentYear (); if (scen_GetEchoFlag ()) { fprintf (stdout, " %u", proc_GetCurrentYear ()); fflush (stdout); if (((proc_GetCurrentYear () + 1) % 10) == 0) { fprintf (stdout, "\n"); fflush (stdout); } if (proc_GetCurrentYear () == proc_GetStopYear ()) { fprintf (stdout, "\n"); fflush (stdout); } } if (scen_GetLogFlag ()) { if (scen_GetLogProcessingStatusFlag () > 1) { scen_Append2Log (); fprintf (scen_GetLogFP (), " %u", proc_GetCurrentYear ()); if (((proc_GetCurrentYear () + 1) % 10) == 0) { fprintf (scen_GetLogFP (), "\n"); fflush (scen_GetLogFP ()); } if (proc_GetCurrentYear () == proc_GetStopYear ()) { fprintf (scen_GetLogFP (), "\n"); fflush (scen_GetLogFP ()); } scen_CloseLog (); } } /* * * APPLY THE CELLULAR AUTOMATON RULES FOR THIS YEAR * */ sng = 0; sdg = 0; sdc = 0; og = 0; rt = 0; pop = 0; timer_Start (SPREAD_TOTAL_TIME); spr_spread (&average_slope, &num_growth_pix, &sng, &sdc, &og, &rt, &pop, z_ptr); timer_Stop (SPREAD_TOTAL_TIME); stats_SetSNG (sng); stats_SetSDG (sdg); stats_SetSDG (sdc); stats_SetOG (og); stats_SetRT (rt); stats_SetPOP (pop); if (scen_GetViewGrowthTypesFlag ()) { sprintf (gif_filename, "%sz_growth_types_%u_%u_%u.gif", scen_GetOutputDir (), proc_GetCurrentRun (), proc_GetCurrentMonteCarlo (), proc_GetCurrentYear ()); sprintf (date_str, "%u", proc_GetCurrentYear ()); gdif_WriteGIF (z_ptr, color_GetColortable (GROWTH_COLORTABLE), gif_filename, date_str, 255); } if (scen_GetDoingLanduseFlag ()) { grw_landuse (land1_ptr, num_growth_pix); } else { grw_non_landuse (z_ptr); } seed_ptr = igrid_GetUrbanGridPtr (__FILE__, func, __LINE__, 0); util_condition_gif (total_pixels, seed_ptr, GT, 0, z_ptr, PHASE0G); seed_ptr = igrid_GridRelease (__FILE__, func, __LINE__, seed_ptr); /* * * DO STATISTICS * */ stats_Update (num_growth_pix); /* * * DO SELF MODIFICATION * */ coeff_SelfModication (stats_GetGrowthRate (), stats_GetPercentUrban ()); coeff_WriteCurrentCoeff (); } timer_Stop (GRW_GROWTH); FUNC_END;}/*************************************************************************************************************************************************************** FUNCTION NAME: grw_landuse_init** PURPOSE: initial variables for doing landuse** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void grw_landuse_init (GRID_P deltatron_ptr, /* OUT */ GRID_P land1_ptr) /* OUT */{ char func[] = "grw_landuse_init"; int i; int total_pixels; GRID_P landuse0_ptr; GRID_P landuse1_ptr; FUNC_INIT; total_pixels = mem_GetTotalPixels (); assert (deltatron_ptr != NULL); assert (land1_ptr != NULL); assert (total_pixels > 0); /* * * INITIALIZE DELTATRON GRID TO ZERO * */ for (i = 0; i < total_pixels; i++) { deltatron_ptr[i] = 0; } /* * * IF PREDICTING USE LANDUSE 1 AS THE STARTING LANDUSE * ELSE USE LANDUSE 0 AS THE STARTING LANDUSE * */ if (proc_GetProcessingType () == PREDICTING) { landuse1_ptr = igrid_GetLanduseGridPtr (__FILE__, func, __LINE__, 1); assert (landuse1_ptr != NULL); for (i = 0; i < total_pixels; i++) { land1_ptr[i] = landuse1_ptr[i]; } landuse1_ptr = igrid_GridRelease (__FILE__, func, __LINE__, landuse1_ptr); } else { landuse0_ptr = igrid_GetLanduseGridPtr (__FILE__, func, __LINE__, 0); assert (landuse0_ptr != NULL); for (i = 0; i < total_pixels; i++) { land1_ptr[i] = landuse0_ptr[i]; } landuse0_ptr = igrid_GridRelease (__FILE__, func, __LINE__, landuse0_ptr); } FUNC_END;}/*************************************************************************************************************************************************************** FUNCTION NAME: grw_landuse** PURPOSE: routine for handling landuse type of processing** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -