📄 stats_obj.c
字号:
#include <assert.h>#include <stdlib.h>#include <string.h>#include <stdio.h>#include <errno.h>#include <math.h>#include "ugm_defines.h"#include "pgrid_obj.h"#include "proc_obj.h"#include "igrid_obj.h"#include "memory_obj.h"#include "scenario_obj.h"#include "ugm_macros.h"#include "stats_obj.h"#include "coeff_obj.h"#include "utilities.h"/*****************************************************************************\********************************************************************************* **** SCCS ID **** *********************************************************************************\*****************************************************************************/char stats_obj_c_sccs_id[] = "@(#)stats_obj.c 1.72 12/4/00";/*****************************************************************************\********************************************************************************* **** MACROS **** *********************************************************************************\*****************************************************************************/#define MAX_LINE_LEN 256#define SIZE_CIR_Q 1000#define Q_STORE(R,C) \ if((sidx+1==ridx)||((sidx+1==SIZE_CIR_Q)&&!ridx)){ \ printf("Error Circular Queue Full\n"); \ printf("Increase SIZE_CIR_Q and recompile\n"); \ printf("sidx=%d ridx=%d SIZE_CIR_Q=%d\n",sidx,ridx,SIZE_CIR_Q); \ EXIT(1);} \ cir_q[sidx].row = R; \ cir_q[sidx].col = C; \ sidx++; \ depth++; \ sidx %= SIZE_CIR_Q#define Q_RETREIVE(R,C) \ ridx = ridx%SIZE_CIR_Q; \ R = cir_q[ridx].row; \ C = cir_q[ridx].col; \ ridx++; \ depth--/*****************************************************************************\********************************************************************************* **** STATIC MEMORY FOR THIS OBJECT **** *********************************************************************************\*****************************************************************************/static char *stats_val_t_names[] = { "sng", "sdg", "sdc", "og", "rt", "pop", "area", "edges", "clusters", "xmean", "ymean", "rad", "slope", "cl_size", "diffus", "spread", "breed", "slp_res", "rd_grav", "%urban", "%road", "grw_rate", "leesalee", "grw_pix"};static stats_info stats_actual[MAX_URBAN_YEARS];static stats_info regression;static stats_val_t average[MAX_URBAN_YEARS];static stats_val_t std_dev[MAX_URBAN_YEARS];static stats_val_t running_total[MAX_URBAN_YEARS];static struct{ int run; int monte_carlo; int year; stats_val_t this_year;}record;static struct{ double fmatch; double actual; double simulated; double compare; double leesalee; double product;}aggregate;static struct{ long successes; long z_failure; long delta_failure; long slope_failure; long excluded_failure;}urbanization_attempt;static int sidx;static int ridx;/* link element for Cluster routine */typedef struct ugm_link{ int row; int col;}ugm_link;static struct ugm_link cir_q[SIZE_CIR_Q];/*****************************************************************************\********************************************************************************* **** STATIC FUNCTION PROTOTYPES **** *********************************************************************************\*****************************************************************************/static void stats_Save (char *filename);static void stats_LogThisYearStats (FILE * fp);static void stats_CalGrowthRate ();static void stats_CalPercentUrban (int, int, int);static void stats_CalAverages (int index);static void stats_WriteControlStats (char *filename);static void stats_WriteStatsValLine (char *filename, int run, int year, stats_val_t * stats_ptr, int index);static void stats_LogStatInfoHdr (FILE * fp);static void stats_LogStatInfo (int run, int year, int index, stats_info * stats_ptr, FILE * fp);static void stats_LogStatVal (int run, int year, int index, stats_val_t * stats_ptr, FILE * fp);static void stats_LogStatValHdr (FILE * fp);static void stats_ComputeThisYearStats ();static void stats_SetNumGrowthPixels (int val);static void stats_CalLeesalee ();static void stats_ProcessGrowLog (int run, int year);static void stats_DoAggregate (double fmatch);static void stats_DoRegressions ();static double stats_linefit (double *dependent, double *independent, int number_of_observations);static void stats_LogControlStats (FILE * fp);static void stats_LogControlStatsHdr (FILE * fp);static void stats_compute_stats (GRID_P Z, /* IN */ GRID_P slp, /* IN */ double *stats_area, /* OUT */ double *stats_edges, /* OUT */ double *stats_clusters, /* OUT */ double *stats_pop, /* OUT */ double *stats_xmean, /* OUT */ double *stats_ymean, /* OUT */ double *stats_average_slope, /* OUT */ double *stats_rad, /* OUT */ double *stats_mean_cluster_size, /* OUT */ GRID_P scratch_gif1, /* MOD */ GRID_P scratch_gif2); /* MOD */static void stats_edge (GRID_P Z, /* IN */ double *stats_area, /* OUT */ double *stats_edges); /* OUT */static void stats_circle (GRID_P Z, /* IN */ GRID_P slp, /* IN */ int stats_area, /* IN */ double *stats_xmean, /* OUT */ double *stats_ymean, /* OUT */ double *stats_average_slope, /* OUT */ double *stats_rad); /* OUT */static void stats_cluster (GRID_P Z, /* IN */ double *stats_clusters, /* OUT */ double *stats_pop, /* OUT */ double *stats_mean_cluster_size, /* OUT */ GRID_P scratch_gif1, /* MOD */ GRID_P scratch_gif2); /* MOD */static void stats_ClearStatsValArrays ();static void stats_ComputeBaseStats ();static void stats_CalStdDev (int index);static void stats_compute_leesalee (GRID_P Z, /* IN */ GRID_P urban, /* IN */ double *leesalee); /* OUT *//*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/#if 1void stats_ConcatenateControlFiles (){ char func[] = "stats_ConcatenateControlFiles"; 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; int i; sprintf (destination_file, "%scontrol_stats.log", scen_GetOutputDir ()); sprintf (source_file, "%scontrol_stats_pe_%u.log", scen_GetOutputDir (), 0); sprintf (command, "mv %s %s", source_file, destination_file); system (command); FILE_OPEN (fp, destination_file, "a"); for (i = 1; i < glb_npes; i++) { sprintf (source_file, "%scontrol_stats_pe_%u.log", 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 <= 2) continue; fputs (line, fp); } fclose (source_fp); sprintf (command, "rm %s", source_file); printf ("%s %u command: %s\n", __FILE__, __LINE__, command); system (command); } fclose (fp);}#elsevoid stats_ConcatenateControlFiles (int current_run){ char func[] = "stats_ConcatenateControlFiles"; 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; sprintf (destination_file, "%scontrol_stats.log", scen_GetOutputDir ()); sprintf (source_file, "%scontrol_stats_pe_%u.log", scen_GetOutputDir (), 0); FILE_OPEN (fp, destination_file, "a"); sprintf (source_file, "%scontrol_stats_pe_%u.log", 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 <= 2) continue; fputs (line, fp); } fclose (source_fp); fclose (fp); sprintf (command, "rm %s", source_file); system (command);}#endif/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/#if 1void stats_ConcatenateStdDevFiles (){ char func[] = "stats_ConcatenateStdDevFiles"; 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; int i; sprintf (destination_file, "%sstd_dev.log", scen_GetOutputDir ()); sprintf (source_file, "%sstd_dev_pe_%u.log", scen_GetOutputDir (), 0); sprintf (command, "mv %s %s", source_file, destination_file); system (command); FILE_OPEN (fp, destination_file, "a"); for (i = 1; i < glb_npes; i++) { sprintf (source_file, "%sstd_dev_pe_%u.log", 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); sprintf (command, "rm %s", source_file); printf ("%s %u command: %s\n", __FILE__, __LINE__, command); system (command); } fclose (fp);#elsevoid stats_ConcatenateStdDevFiles (int current_run){ char func[] = "stats_ConcatenateStdDevFiles"; 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; sprintf (destination_file, "%sstd_dev.log", scen_GetOutputDir ()); sprintf (source_file, "%sstd_dev_pe_%u.log", scen_GetOutputDir (), 0); FILE_OPEN (fp, destination_file, "a"); sprintf (source_file, "%sstd_dev_pe_%u.log", 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); sprintf (command, "rm %s", source_file); system (command);#endif}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/#if 1void stats_ConcatenateAvgFiles (){ char func[] = "stats_ConcatenateAvgFiles"; 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; int i; sprintf (destination_file, "%savg.log", scen_GetOutputDir ()); sprintf (source_file, "%savg_pe_%u.log", scen_GetOutputDir (), 0); sprintf (command, "mv %s %s", source_file, destination_file); system (command); FILE_OPEN (fp, destination_file, "a"); for (i = 1; i < glb_npes; i++) { sprintf (source_file, "%savg_pe_%u.log", 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); sprintf (command, "rm %s", source_file); printf ("%s %u command: %s\n", __FILE__, __LINE__, command); system (command);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -