main.c

来自「CA仿真模型中SLEUTH模型」· C语言 代码 · 共 854 行 · 第 1/2 页

C
854
字号
   */  proc_SetTotalRuns ();  if (scen_GetLogFlag ())  {    if (proc_GetProcessingType () == CALIBRATING)    {      scen_Append2Log ();      fprintf (scen_GetLogFP (), "%s %u Total Number of Runs = %u\n",               __FILE__, __LINE__, proc_GetTotalRuns ());      scen_CloseLog ();    }  }  proc_SetLastMonteCarlo (scen_GetMonteCarloIterations () - 1);  /*   *   * COMPUTE THE TRANSITION MATRIX   *   */  if (scen_GetDoingLanduseFlag ())  {    trans_Init ();    if (scen_GetLogFlag ())    {      if (scen_GetLogTransitionMatrixFlag ())      {        scen_Append2Log ();        trans_LogTransition (scen_GetLogFP ());        scen_CloseLog ();      }    }  }  /*   *   * COMPUTE THE BASE STATISTICS AGAINST WHICH CALIBRATION WILL TAKE PLACE   *   */  stats_Init ();  if (scen_GetLogFlag ())  {    if (scen_GetLogBaseStatsFlag ())    {      scen_Append2Log ();      stats_LogBaseStats (scen_GetLogFP ());      scen_CloseLog ();    }  }  if (scen_GetLogFlag ())  {    if (scen_GetLogDebugFlag ())    {      scen_Append2Log ();      igrid_Debug (scen_GetLogFP (), __FILE__, __LINE__);      scen_CloseLog ();    }  }  proc_SetNumRunsExecThisCPU (0);  if (proc_GetCurrentRun () == 0 && glb_mype == 0)  {    if (proc_GetProcessingType () != PREDICTING)    {      sprintf (fname, "%scontrol_stats.log", scen_GetOutputDir ());      stats_CreateControlFile (fname);    }    if (scen_GetWriteStdDevFileFlag ())    {      sprintf (fname, "%sstd_dev.log", scen_GetOutputDir ());      stats_CreateStatsValFile (fname);    }    if (scen_GetWriteAvgFileFlag ())    {      sprintf (fname, "%savg.log", scen_GetOutputDir ());      stats_CreateStatsValFile (fname);    }  }  coeff_CreateCoeffFile ();#ifdef MPI  MPI_Barrier (MPI_COMM_WORLD);#endif  if (proc_GetProcessingType () == PREDICTING)  {    /*     *     * PREDICTION RUNS     *     */    proc_SetStopYear (scen_GetPredictionStopDate ());    InitRandom (scen_GetRandomSeed ());    coeff_SetCurrentDiffusion ((double) coeff_GetBestFitDiffusion ());    coeff_SetCurrentSpread ((double) coeff_GetBestFitSpread ());    coeff_SetCurrentBreed ((double) coeff_GetBestFitBreed ());    coeff_SetCurrentSlopeResist ((double) coeff_GetBestFitSlopeResist ());    coeff_SetCurrentRoadGravity ((double) coeff_GetBestFitRoadGravity ());    if (glb_mype == 0)    {      drv_driver ();      proc_IncrementNumRunsExecThisCPU ();    }    if (scen_GetLogFlag ())    {      if (scen_GetLogTimingsFlag () > 1)      {        scen_Append2Log ();        timer_LogIt (scen_GetLogFP ());        scen_CloseLog ();      }    }  }  else  {    /*     *     * CALIBRATION AND TEST RUNS     *     */    proc_SetStopYear (igrid_GetUrbanYear (igrid_GetUrbanCount () - 1));    for (diffusion_coeff = coeff_GetStartDiffusion ();         diffusion_coeff <= coeff_GetStopDiffusion ();         diffusion_coeff += coeff_GetStepDiffusion ())    {      for (breed_coeff = coeff_GetStartBreed ();           breed_coeff <= coeff_GetStopBreed ();           breed_coeff += coeff_GetStepBreed ())      {        for (spread_coeff = coeff_GetStartSpread ();             spread_coeff <= coeff_GetStopSpread ();             spread_coeff += coeff_GetStepSpread ())        {          for (slope_resistance = coeff_GetStartSlopeResist ();               slope_resistance <= coeff_GetStopSlopeResist ();               slope_resistance += coeff_GetStepSlopeResist ())          {            for (road_gravity = coeff_GetStartRoadGravity ();                 road_gravity <= coeff_GetStopRoadGravity ();                 road_gravity += coeff_GetStepRoadGravity ())            {              sprintf (fname, "%s%s%u", scen_GetOutputDir (),                       RESTART_FILE, glb_mype);              out_write_restart_data (fname,                                      diffusion_coeff,                                      breed_coeff,                                      spread_coeff,                                      slope_resistance,                                      road_gravity,                                      scen_GetRandomSeed (),                                      restart_run);              InitRandom (scen_GetRandomSeed ());              restart_run++;              coeff_SetCurrentDiffusion ((double) diffusion_coeff);              coeff_SetCurrentSpread ((double) spread_coeff);              coeff_SetCurrentBreed ((double) breed_coeff);              coeff_SetCurrentSlopeResist ((double) slope_resistance);              coeff_SetCurrentRoadGravity ((double) road_gravity);#ifdef MPI              if (proc_GetCurrentRun () % glb_npes == glb_mype)              {                drv_driver ();                proc_IncrementNumRunsExecThisCPU ();                if (scen_GetLogFlag ())                {                  if (scen_GetLogTimingsFlag () > 1)                  {                    scen_Append2Log ();                    timer_LogIt (scen_GetLogFP ());                    scen_CloseLog ();                  }                }              }#else              drv_driver ();              proc_IncrementNumRunsExecThisCPU ();              if (scen_GetLogFlag ())              {                if (scen_GetLogTimingsFlag () > 1)                {                  scen_Append2Log ();                  timer_LogIt (scen_GetLogFP ());                  scen_CloseLog ();                }              }#endif              proc_IncrementCurrentRun ();              if (proc_GetProcessingType () == TESTING)              {                stats_ConcatenateControlFiles ();                if (scen_GetWriteCoeffFileFlag ())                {                  coeff_ConcatenateFiles ();                }                if (scen_GetWriteAvgFileFlag ())                {                  stats_ConcatenateAvgFiles ();                }                if (scen_GetWriteStdDevFileFlag ())                {                  stats_ConcatenateStdDevFiles ();                }                timer_Stop (TOTAL_TIME);                if (scen_GetLogFlag ())                {                  scen_Append2Log ();                  if (scen_GetLogTimingsFlag () > 0)                  {                    timer_LogIt (scen_GetLogFP ());                  }                  mem_LogMinFreeWGrids (scen_GetLogFP ());                  scen_CloseLog ();                }                EXIT (0);              }            }          }        }      }    }  }#ifdef MPI  MPI_Barrier (MPI_COMM_WORLD);#endif  if (glb_mype == 0)  {    if (scen_GetWriteCoeffFileFlag ())    {      coeff_ConcatenateFiles ();    }    if (scen_GetWriteAvgFileFlag ())    {      stats_ConcatenateAvgFiles ();    }    if (scen_GetWriteStdDevFileFlag ())    {      stats_ConcatenateStdDevFiles ();    }    if (proc_GetProcessingType () != PREDICTING)    {      stats_ConcatenateControlFiles ();    }  }  if (scen_GetPostprocessingFlag ())  {#ifdef MPI    MPI_Barrier (MPI_COMM_WORLD);#endif    if (glb_mype == 0)    {      if (strlen (scen_GetWhirlgifBinary ()) > 0)      {        if (scen_GetViewDeltatronAgingFlag ())        {          sprintf (command,            "%s -time 100 -o %sanimated_deltatron.gif %sdeltatron_*.gif",                   scen_GetWhirlgifBinary (), scen_GetOutputDir (),                   scen_GetOutputDir ());          system (command);        }        if (scen_GetViewGrowthTypesFlag ())        {          sprintf (command,                   "%s -time 100 -o %sanimated_z_growth.gif %sz_growth_types_*.gif",                   scen_GetWhirlgifBinary (), scen_GetOutputDir (),                   scen_GetOutputDir ());          system (command);        }        if (proc_GetProcessingType () != CALIBRATING)        {          if (scen_GetDoingLanduseFlag ())          {            sprintf (command,                     "%s -time 100 -o %sanimated_land_n_urban.gif %s*_land_n_urban*.gif",                     scen_GetWhirlgifBinary (), scen_GetOutputDir (),                     scen_GetOutputDir ());            system (command);          }          else          {            sprintf (command,                  "%s -time 100 -o %sanimated_urban.gif %s*_urban_*.gif",                     scen_GetWhirlgifBinary (),                     scen_GetOutputDir (), scen_GetOutputDir ());            system (command);          }        }      }    }  }#ifdef MPI  MPI_Finalize ();#endif  timer_Stop (TOTAL_TIME);  if (scen_GetLogFlag ())  {    scen_Append2Log ();    if (scen_GetLogTimingsFlag () > 0)    {      timer_LogIt (scen_GetLogFP ());    }    mem_LogMinFreeWGrids (scen_GetLogFP ());    scen_CloseLog ();  }  return (0);}/*************************************************************************************************************************************************************** FUNCTION NAME: print_usage** PURPOSE:       help the user** AUTHOR:        Keith Clarke** PROGRAMMER:    Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void  print_usage (char *binary){  printf ("Usage:\n");  printf ("%s <mode> <scenario file>\n", binary);  printf ("Allowable modes are:\n");  printf ("  calibrate\n");  printf ("  restart\n");  printf ("  test\n");  printf ("  predict\n");  EXIT (1);}#ifdef CATCH_SIGNALS/*************************************************************************************************************************************************************** FUNCTION NAME: catch** PURPOSE:       catch signals** AUTHOR:        Keith Clarke** PROGRAMMER:    Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void  catch (int signo){  int i;  if (tracer < 2)  {    printf ("%s %u pe: %u %s\n", __FILE__, __LINE__, glb_mype,            "Please make sure the following env variables are defined");    printf ("%s %u pe: %u %s\n", __FILE__, __LINE__, glb_mype,            "USER -- set to your username");    printf ("%s %u pe: %u %s\n", __FILE__, __LINE__, glb_mype,            "HOST -- set to your machines's name = uname -n");    printf ("%s %u pe: %u %s\n", __FILE__, __LINE__, glb_mype,          "HOSTTYPE -- set to your machines's type such as Sparc, Cray");    printf ("%s %u pe: %u %s\n", __FILE__, __LINE__, glb_mype,          "OSTYPE -- set to your machines's OS type such as Solaris2.7");    printf ("%s %u pe: %u %s\n", __FILE__, __LINE__, glb_mype,            "PWD -- set to your current working directory");  }  if (signo == SIGBUS)  {    printf ("%s %u caught signo SIGBUS : bus error\n",            __FILE__, __LINE__);    printf ("Currently executing function: %s\n",            glb_call_stack[glb_call_stack_index]);    for (i = glb_call_stack_index; i >= 0; i--)    {      printf ("glb_call_stack[%d]= %s\n", i, glb_call_stack[i]);    }    EXIT (1);  }  if (signo == SIGSEGV)  {    printf ("%s %u pe: %u caught signo SIGSEGV : Invalid storage access\n",            __FILE__, __LINE__, glb_mype);    printf ("Currently executing function: %s\n",            glb_call_stack[glb_call_stack_index]);    for (i = glb_call_stack_index; i >= 0; i--)    {      printf ("glb_call_stack[%d]= %s\n", i, glb_call_stack[i]);    }    EXIT (1);  }  if (signo == SIGINT)  {    printf ("%s %u caught signo SIGINT : Interrupt\n",            __FILE__, __LINE__);    printf ("Currently executing function: %s\n",            glb_call_stack[glb_call_stack_index]);    for (i = glb_call_stack_index; i >= 0; i--)    {      printf ("glb_call_stack[%d]= %s\n", i, glb_call_stack[i]);    }    EXIT (1);  }  if (signo == SIGFPE)  {    printf ("%s %u caught signo SIGFPE : Floating-point exception\n",            __FILE__, __LINE__);    printf ("Currently executing function: %s\n",            glb_call_stack[glb_call_stack_index]);    for (i = glb_call_stack_index; i >= 0; i--)    {      printf ("glb_call_stack[%d]= %s\n", i, glb_call_stack[i]);    }    EXIT (1);  }  printf ("%s %u caught signo %d\n", __FILE__, __LINE__, signo);  EXIT (1);}#endif

⌨️ 快捷键说明

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