📄 main.c
字号:
#define MAIN_MODULE#define MAIN#ifdef MPI#include <mpi.h>#endif#define CATCH_SIGNALS#ifdef CATCH_SIGNALS#include <signal.h>#endif#include <stddef.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <assert.h>#include <time.h>#include "coeff_obj.h"#include "igrid_obj.h"#include "landclass_obj.h"#include "globals.h"#include "output.h"#include "utilities.h"#include "random.h"#include "driver.h"#include "input.h"#include "scenario_obj.h"#include "proc_obj.h"#include "timer_obj.h"#include "landclass_obj.h"#include "pgrid_obj.h"#include "color_obj.h"#include "memory_obj.h"#include "color_obj.h"#include "stats_obj.h"#include "transition_obj.h"#include "ugm_macros.h"/*****************************************************************************\********************************************************************************* **** STATIC FUNCTION PROTOTYPES **** *********************************************************************************\*****************************************************************************/static void print_usage (char *binary);#ifdef CATCH_SIGNALSvoid catch (int signo);#endif/*****************************************************************************\********************************************************************************* **** STATIC MEMORY FOR THIS OBJECT **** *********************************************************************************\*****************************************************************************/static int tracer;/*****************************************************************************\********************************************************************************* **** SCCS ID **** *********************************************************************************\*****************************************************************************/char main_c_sccs_id[] = "@(#)main.c 1.629 12/4/00";/*************************************************************************************************************************************************************** FUNCTION NAME: main** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/int main (int argc, char *argv[]){ char func[] = "main"; char fname[MAX_FILENAME_LEN]; char command[5 * MAX_FILENAME_LEN]; int restart_run = 0; RANDOM_SEED_TYPE random_seed; int diffusion_coeff; int breed_coeff; int spread_coeff; int slope_resistance; int road_gravity; int restart_diffusion; int restart_breed; int restart_spread; int restart_slope_resistance; int restart_road_gravity; time_t tp; char processing_str[MAX_FILENAME_LEN]; int i;#ifdef CATCH_SIGNALS struct sigaction act, oact; tracer = 1; act.sa_handler = catch; sigemptyset (&act.sa_mask); act.sa_flags = 0; sigaction (SIGFPE, &act, &oact); sigaction (SIGINT, &act, &oact); sigaction (SIGSEGV, &act, &oact); sigaction (SIGBUS, &act, &oact);#endif#ifdef MPI MPI_Init (&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &glb_mype); MPI_Comm_size (MPI_COMM_WORLD, &glb_npes);#else glb_mype = 0; glb_npes = 1;#endif timer_Init (); timer_Start (TOTAL_TIME); glb_call_stack_index = -1; FUNC_INIT; /* * * PARSE COMMAND LINE * */ if (argc != 3) { print_usage (argv[0]); } if ((strcmp (argv[1], "predict")) && (strcmp (argv[1], "restart")) && (strcmp (argv[1], "test")) && (strcmp (argv[1], "calibrate"))) { print_usage (argv[0]); } if (strcmp (argv[1], "predict") == 0) { proc_SetProcessingType (PREDICTING); strcpy (processing_str, "PREDICTING"); } if (strcmp (argv[1], "restart") == 0) { proc_SetProcessingType (CALIBRATING); proc_SetRestartFlag (TRUE); strcpy (processing_str, "restart CALIBRATING"); } if (strcmp (argv[1], "test") == 0) { proc_SetProcessingType (TESTING); strcpy (processing_str, "TESTING"); } if (strcmp (argv[1], "calibrate") == 0) { proc_SetProcessingType (CALIBRATING); strcpy (processing_str, "CALIBRATING"); } scen_init (argv[2]); /* * * SET SOME VARIABLES * */ random_seed = scen_GetRandomSeed ();/* * void landclassSetGrayscale (int index, int val); * void landclassSetColor (int index, int val); * void landclassSetType (int index, char* string); * void landclassSetName (int index, char* string); * void landclassSetNumClasses (int val); * int scen_GetNumLanduseClasses (); * char* scen_GetLanduseClassName (int); * char* scen_GetLanduseClassType (int); * int scen_GetLanduseClassColor (int); * int scen_GetLanduseClassGrayscale (int i); * */ landclassSetNumClasses (scen_GetNumLanduseClasses ()); for (i = 0; i < scen_GetNumLanduseClasses (); i++) { landclassSetGrayscale (i, scen_GetLanduseClassGrayscale (i)); landclassSetName (i, scen_GetLanduseClassName (i)); landclassSetType (i, scen_GetLanduseClassType (i)); landclassSetColor (i, scen_GetLanduseClassColor (i)); } /* * * SET UP COEFFICIENTS * */ if (strcmp (argv[1], "restart") == 0) { if (scen_GetLogFlag ()) { scen_Append2Log (); if (scen_GetLogFP ()) { fprintf (scen_GetLogFP (), "%s %u Reading restart file\n", __FILE__, __LINE__); } scen_CloseLog (); } inp_read_restart_file (&restart_diffusion, &restart_breed, &restart_spread, &restart_slope_resistance, &restart_road_gravity, &random_seed, &restart_run); proc_SetCurrentRun (restart_run); } else { proc_SetCurrentRun (0); } coeff_SetStartDiffusion (scen_GetCoeffDiffusionStart ()); coeff_SetStartSpread (scen_GetCoeffSpreadStart ()); coeff_SetStartBreed (scen_GetCoeffBreedStart ()); coeff_SetStartSlopeResist (scen_GetCoeffSlopeResistStart ()); coeff_SetStartRoadGravity (scen_GetCoeffRoadGravityStart ()); coeff_SetStopDiffusion (scen_GetCoeffDiffusionStop ()); coeff_SetStopSpread (scen_GetCoeffSpreadStop ()); coeff_SetStopBreed (scen_GetCoeffBreedStop ()); coeff_SetStopSlopeResist (scen_GetCoeffSlopeResistStop ()); coeff_SetStopRoadGravity (scen_GetCoeffRoadGravityStop ()); coeff_SetStepDiffusion (scen_GetCoeffDiffusionStep ()); coeff_SetStepSpread (scen_GetCoeffSpreadStep ()); coeff_SetStepBreed (scen_GetCoeffBreedStep ()); coeff_SetStepSlopeResist (scen_GetCoeffSlopeResistStep ()); coeff_SetStepRoadGravity (scen_GetCoeffRoadGravityStep ()); coeff_SetBestFitDiffusion (scen_GetCoeffDiffusionBestFit ()); coeff_SetBestFitSpread (scen_GetCoeffSpreadBestFit ()); coeff_SetBestFitBreed (scen_GetCoeffBreedBestFit ()); coeff_SetBestFitSlopeResist (scen_GetCoeffSlopeResistBestFit ()); coeff_SetBestFitRoadGravity (scen_GetCoeffRoadGravityBestFit ()); /* * * INITIALIZE IGRID * */ igrid_init (); /* * * PRINT BANNER * */ if (scen_GetEchoFlag ()) { out_banner (stdout); } if (scen_GetLogFlag ()) { scen_Append2Log (); out_banner (scen_GetLogFP ()); scen_CloseLog (); } /* * * LOG SOME STUFF * */ if (scen_GetLogFlag ()) { scen_Append2Log (); time (&tp); fprintf (scen_GetLogFP (), "DATE OF RUN: %s\n", asctime (localtime (&tp))); fprintf (scen_GetLogFP (), "USER: %s\n", getenv ("USER")); fprintf (scen_GetLogFP (), "HOST: %s\n", getenv ("HOST")); fprintf (scen_GetLogFP (), "HOSTTYPE: %s\n", getenv ("HOSTTYPE")); fprintf (scen_GetLogFP (), "OSTYPE: %s\n", getenv ("OSTYPE")); fprintf (scen_GetLogFP (), "Type of architecture: %u bit\n\n", BYTES_PER_WORD*8); fprintf (scen_GetLogFP (), "Number of CPUs %u \n\n", glb_npes); fprintf (scen_GetLogFP (), "PWD: %s\n", getenv ("PWD")); fprintf (scen_GetLogFP (), "Scenario File: %s\n", scen_GetScenarioFilename ()); fprintf (scen_GetLogFP (), "Type of Processing: %s\n", processing_str); fprintf (scen_GetLogFP (), "\n\n"); scen_echo (scen_GetLogFP ()); coeff_LogStart (scen_GetLogFP ()); coeff_LogStop (scen_GetLogFP ()); coeff_LogStep (scen_GetLogFP ()); coeff_LogBestFit (scen_GetLogFP ()); scen_CloseLog (); tracer = 2; } /* * * SET UP FLAT MEMORY * */#ifdef MPI MPI_Barrier (MPI_COMM_WORLD);#endif mem_Init (); if (scen_GetLogFlag ()) { scen_Append2Log (); mem_LogPartition (scen_GetLogFP ()); mem_CheckMemory (scen_GetLogFP (), __FILE__, func, __LINE__); scen_CloseLog (); }#ifdef MPI MPI_Barrier (MPI_COMM_WORLD);#endif /* * * INITIALIZE LANDUSE * */ if (scen_GetDoingLanduseFlag ()) { landclass_Init (); if (scen_GetLogLandclassSummaryFlag ()) { if (scen_GetLogFlag ()) { scen_Append2Log (); landclass_LogIt (scen_GetLogFP ()); scen_CloseLog (); } } } /* * * INITIALIZE COLORTABLES * */ color_Init (); /* * * WRITE MEMORY MAPS * */ if (scen_GetLogMemoryMapFlag ()) { color_MemoryLog (mem_GetLogFP ()); coeff_MemoryLog (mem_GetLogFP ()); timer_MemoryLog (mem_GetLogFP ()); igrid_MemoryLog (mem_GetLogFP ()); pgrid_MemoryLog (mem_GetLogFP ()); stats_MemoryLog (mem_GetLogFP ()); mem_MemoryLog (mem_GetLogFP ()); proc_MemoryLog (mem_GetLogFP ()); landclass_MemoryLog (mem_GetLogFP ()); scen_MemoryLog (mem_GetLogFP ()); trans_MemoryLog (mem_GetLogFP ()); mem_CloseLog (); } /* * * READ INPUT DATA FILES * */ igrid_ReadFiles (); if (scen_GetLogFlag ()) { scen_Append2Log (); igrid_ValidateGrids (scen_GetLogFP ()); scen_CloseLog (); } else { igrid_ValidateGrids (NULL); } igrid_NormalizeRoads (); if (scen_GetLogFlag ()) { scen_Append2Log (); igrid_LogIt (scen_GetLogFP ()); igrid_VerifyInputs (scen_GetLogFP ()); scen_CloseLog (); } else { igrid_VerifyInputs (NULL); } /* * * INITIALIZE THE PGRID GRIDS * */ pgrid_Init (); if (scen_GetLogFlag ()) { if (scen_GetLogColortablesFlag ()) { scen_Append2Log (); color_LogIt (scen_GetLogFP ()); scen_CloseLog (); } } /* * * COUNT THE NUMBER OF RUNS *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -