📄 coeff_obj.c
字号:
LOG_INT (fp, step_coeff.diffusion); LOG_INT (fp, step_coeff.spread); LOG_INT (fp, step_coeff.breed); LOG_INT (fp, step_coeff.slope_resistance); LOG_INT (fp, step_coeff.road_gravity);}/*************************************************************************************************************************************************************** FUNCTION NAME: coeff_LogStart** PURPOSE: log values in start_coeff struct to file descriptor fp** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void coeff_LogStart (FILE * fp){ LOG_INT (fp, start_coeff.diffusion); LOG_INT (fp, start_coeff.spread); LOG_INT (fp, start_coeff.breed); LOG_INT (fp, start_coeff.slope_resistance); LOG_INT (fp, start_coeff.road_gravity);}/*************************************************************************************************************************************************************** FUNCTION NAME: coeff_LogStop** PURPOSE: log values in stop_coeff struct to file descriptor fp** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void coeff_LogStop (FILE * fp){ LOG_INT (fp, stop_coeff.diffusion); LOG_INT (fp, stop_coeff.spread); LOG_INT (fp, stop_coeff.breed); LOG_INT (fp, stop_coeff.slope_resistance); LOG_INT (fp, stop_coeff.road_gravity);}/*************************************************************************************************************************************************************** FUNCTION NAME: coeff_LogBestFit** PURPOSE: log values in best_fit_coeff struct to file descriptor fp** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void coeff_LogBestFit (FILE * fp){ LOG_INT (fp, best_fit_coeff.diffusion); LOG_INT (fp, best_fit_coeff.spread); LOG_INT (fp, best_fit_coeff.breed); LOG_INT (fp, best_fit_coeff.slope_resistance); LOG_INT (fp, best_fit_coeff.road_gravity);}/*****************************************************************************\********************************************************************************* **** OUTPUT FUNCTIONS **** *********************************************************************************\*****************************************************************************//*************************************************************************************************************************************************************** FUNCTION NAME: coeff_ConcatenateFiles** PURPOSE: concatenate coefficient files for a given run** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/#if 1void coeff_ConcatenateFiles ()#elsevoid coeff_ConcatenateFiles (int current_run)#endif{#if 1#define MAX_LINE_LEN 256 char func[] = "coeff_ConcatenateFiles"; char source_file[MAX_FILENAME_LEN]; char destination_file[MAX_FILENAME_LEN]; char command[2 * MAX_FILENAME_LEN + 20]; int i; FILE *fp; FILE *source_fp; int line_count; char line[MAX_LINE_LEN]; if (scen_GetWriteCoeffFileFlag ()) { /* * * create the destination coeff.log file by copying the zeroth * file onto coeff_log * */ sprintf (destination_file, "%scoeff.log", scen_GetOutputDir ()); sprintf (source_file, "%scoeff_run%u", scen_GetOutputDir (), 0); sprintf (command, "mv %s %s", source_file, destination_file); system (command); /* * * loop over all the files appending each to the destination file * */ for (i = 1; i < glb_npes; i++) { FILE_OPEN (fp, destination_file, "a"); sprintf (source_file, "%scoeff_run%u", scen_GetOutputDir (), i); FILE_OPEN (source_fp, source_file, "r"); line_count = 0; while (fgets (line, MAX_LINE_LEN, source_fp) != NULL) { line_count++; if (line_count <= 1) continue; fputs (line, fp); } fclose (source_fp); fclose (fp); sprintf (command, "rm %s", source_file); system (command); } }#else#define MAX_LINE_LEN 256 char func[] = "coeff_ConcatenateFiles"; char line[MAX_LINE_LEN]; char source_file[MAX_FILENAME_LEN]; char destination_file[MAX_FILENAME_LEN]; char command[2 * MAX_FILENAME_LEN + 20]; FILE *fp; FILE *source_fp; int line_count; if (scen_GetWriteCoeffFileFlag ()) { sprintf (destination_file, "%scoeff.log", scen_GetOutputDir ()); if (current_run == 0) { /* * * CURRENT_RUN == 0 SO THERE IS ONLY 1 FILE SO WE JUST MOVE IT TO * THE RIGHT LOCATION * */ sprintf (source_file, "%scoeff_run%u", scen_GetOutputDir (), 0); sprintf (command, "mv %s %s", source_file, destination_file); system (command); } else { /* * * CURRENT_RUN != 0 SO WE MUST OPEN THE DESTINATION FILE IN APPEND MODE * APPEND EACH LINE OF THE SOURCE FILE TO IT * */ FILE_OPEN (fp, destination_file, "a"); sprintf (source_file, "%scoeff_run%u", scen_GetOutputDir (), current_run); FILE_OPEN (source_fp, source_file, "r"); line_count = 0; while (fgets (line, MAX_LINE_LEN, source_fp) != NULL) { line_count++; if (line_count <= 1) continue; fputs (line, fp); } fclose (source_fp); fclose (fp); /* * * REMOVE THE NO LONGER NEEDED SOURCE FILE * */ sprintf (command, "rm %s", source_file); system (command); } }#endif}/*************************************************************************************************************************************************************** FUNCTION NAME: coeff_WriteCurrentCoeff** PURPOSE: write current coefficients to a coefficient file** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION: the coefficient file is initially created by** coeff_CreateCoeffFile () which initializes** the coeff_filename variable.*****/void coeff_WriteCurrentCoeff (){ char func[] = "coeff_WriteCurrentCoeff"; FILE *fp; if (scen_GetWriteCoeffFileFlag ()) { FILE_OPEN (fp, coeff_filename, "a"); fprintf (fp, "%5u %5u %4u %8.2f %8.2f %8.2f %8.2f %8.2f\n", proc_GetCurrentRun (), proc_GetCurrentMonteCarlo (), proc_GetCurrentYear (), current_coefficient.diffusion, current_coefficient.breed, current_coefficient.spread, current_coefficient.slope_resistance, current_coefficient.road_gravity); fclose (fp); }}/*************************************************************************************************************************************************************** FUNCTION NAME: coeff_CreateCoeffFile** PURPOSE: creates a coefficient file for the current run** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void coeff_CreateCoeffFile (){ char func[] = "coeff_CreateCoeffFile"; FILE *fp; if (scen_GetWriteCoeffFileFlag ()) {#if 1 sprintf (coeff_filename, "%scoeff_run%u", scen_GetOutputDir (), glb_mype);#else sprintf (coeff_filename, "%scoeff_run%u", scen_GetOutputDir (), proc_GetCurrentRun ());#endif FILE_OPEN (fp, coeff_filename, "w"); fprintf (fp, " Run MC Year Diffusion Breed Spread SlopeResist RoadGrav\n"); fclose (fp); }}/*****************************************************************************\********************************************************************************* **** MANIPULATIVE FUNCTIONS **** *********************************************************************************\*****************************************************************************//*************************************************************************************************************************************************************** FUNCTION NAME: coeff_SelfModication** PURPOSE: performs self modification of parameters** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void coeff_SelfModication (double growth_rate, double percent_urban){ char func[] = "coeff_SelfModication"; /* * * boom year * */ if (growth_rate > scen_GetCriticalHigh ()) { current_coefficient.slope_resistance -= (double) (percent_urban * scen_GetSlopeSensitivity ()); if (current_coefficient.slope_resistance <= MIN_SLOPE_RESISTANCE_VALUE) { current_coefficient.slope_resistance = 1.0; } current_coefficient.road_gravity += (double) (percent_urban * scen_GetRdGrvtySensitivity ()); if (current_coefficient.road_gravity > MAX_ROAD_GRAVITY_VALUE) { current_coefficient.road_gravity = MAX_ROAD_GRAVITY_VALUE; } if (current_coefficient.diffusion < MAX_DIFFUSION_VALUE) { current_coefficient.diffusion *= scen_GetBoom (); if (current_coefficient.diffusion > MAX_DIFFUSION_VALUE) { current_coefficient.diffusion = MAX_DIFFUSION_VALUE; } current_coefficient.breed *= scen_GetBoom (); if (current_coefficient.breed > MAX_BREED_VALUE) { current_coefficient.breed = MAX_BREED_VALUE; } current_coefficient.spread *= scen_GetBoom (); if (current_coefficient.spread > MAX_SPREAD_VALUE) { current_coefficient.spread = MAX_SPREAD_VALUE; } } } /* * * bust year * */ if (growth_rate < scen_GetCriticalLow ()) { current_coefficient.slope_resistance += (double) (percent_urban * scen_GetSlopeSensitivity ()); if (current_coefficient.slope_resistance > MAX_SLOPE_RESISTANCE_VALUE) { current_coefficient.slope_resistance = MAX_SLOPE_RESISTANCE_VALUE; } current_coefficient.road_gravity -= (double) (percent_urban * scen_GetRdGrvtySensitivity ()); if (current_coefficient.road_gravity <= MIN_ROAD_GRAVITY_VALUE) { current_coefficient.road_gravity = 1.0; } if ((growth_rate < scen_GetCriticalLow ()) && (current_coefficient.diffusion > 0)) { current_coefficient.diffusion *= scen_GetBust (); if (current_coefficient.diffusion <= MIN_DIFFUSION_VALUE) { current_coefficient.diffusion = 1.0; } current_coefficient.spread *= scen_GetBust (); if (current_coefficient.spread <= MIN_SPREAD_VALUE) { current_coefficient.spread = 1.0; } current_coefficient.breed *= scen_GetBust (); if (current_coefficient.breed <= MIN_BREED_VALUE) { current_coefficient.breed = 1.0; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -