stats_obj.c
来自「CA仿真模型中SLEUTH模型」· C语言 代码 · 共 2,212 行 · 第 1/5 页
C
2,212 行
/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/double stats_GetMeanClusterSize (){ return record.this_year.mean_cluster_size;}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void stats_ComputeThisYearStats (){ char func[] = "stats_ComputeThisYearStats"; int total_pixels; GRID_P z_ptr; GRID_P slope_ptr; GRID_P stats_workspace1; GRID_P stats_workspace2; double area; double edges; double clusters; double pop; double xmean; double ymean; double slope; double rad; double mean_cluster_size; total_pixels = mem_GetTotalPixels (); assert (total_pixels > 0); z_ptr = pgrid_GetZPtr (); assert (z_ptr != NULL); slope_ptr = igrid_GetSlopeGridPtr (__FILE__, func, __LINE__); stats_workspace1 = mem_GetWGridPtr (__FILE__, func, __LINE__); stats_workspace2 = mem_GetWGridPtr (__FILE__, func, __LINE__); stats_compute_stats (z_ptr, /* IN */ slope_ptr, /* IN */ &area, /* OUT */ &edges, /* OUT */ &clusters, /* OUT */ &pop, /* OUT */ &xmean, /* OUT */ &ymean, /* OUT */ &slope, /* OUT */ &rad, /* OUT */ &mean_cluster_size, /* OUT */ stats_workspace1, /* MOD */ stats_workspace2); /* MOD */ record.this_year.area = area; record.this_year.edges = edges; record.this_year.clusters = clusters; record.this_year.pop = pop; record.this_year.xmean = xmean; record.this_year.ymean = ymean; record.this_year.slope = slope; record.this_year.rad = rad; record.this_year.mean_cluster_size = mean_cluster_size; record.this_year.diffusion = coeff_GetCurrentDiffusion (); record.this_year.spread = coeff_GetCurrentSpread (); record.this_year.breed = coeff_GetCurrentBreed (); record.this_year.slope_resistance = coeff_GetCurrentSlopeResist (); record.this_year.road_gravity = coeff_GetCurrentRoadGravity (); slope_ptr = igrid_GridRelease (__FILE__, func, __LINE__, slope_ptr); stats_workspace1 = mem_GetWGridFree (__FILE__, func, __LINE__, stats_workspace1); stats_workspace2 = mem_GetWGridFree (__FILE__, func, __LINE__, stats_workspace2);}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void stats_CreateControlFile (char *filename){ char func[] = "stats_CreateControlFile"; FILE *fp; FILE_OPEN (fp, filename, "w"); stats_LogControlStatsHdr (fp); fclose (fp);}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void stats_CreateStatsValFile (char *filename){ char func[] = "stats_CreateStatsValFile"; FILE *fp; FILE_OPEN (fp, filename, "w"); stats_LogStatValHdr (fp); fclose (fp);}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void stats_WriteStatsValLine (char *filename, int run, int year, stats_val_t * stats_ptr, int index){ char func[] = "stats_WriteStatsValLine"; FILE *fp; FILE_OPEN (fp, filename, "a"); stats_LogStatVal (run, year, index, &(stats_ptr[index]), fp); fclose (fp);}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void stats_LogStatInfoHdr (FILE * fp){ fprintf (fp, " run year index area edges clusters pop xmean"); fprintf (fp, " ymean rad slope cluster_size %%urban\n");}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void stats_LogStatValHdr (FILE * fp){#if 1 int i; int num_elements; num_elements = sizeof (stats_val_t) / sizeof (double); fprintf (fp, " run year index"); for (i = 0; i < num_elements; i++) { fprintf (fp, "%8s ", stats_val_t_names[i]); } fprintf (fp, "\n");#else fprintf (fp, "\n"); fprintf (fp, " run year index area edges clusters pop xmean"); fprintf (fp, " ymean rad slope cluster_size sng sdg"); fprintf (fp, " sdc og rt pop\n");#endif}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void stats_LogStatInfo (int run, int year, int index, stats_info * stats_ptr, FILE * fp){ fprintf (fp, "%5u %4u %2u ", run, year, index); fprintf (fp, "%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n", stats_ptr->area, stats_ptr->edges, stats_ptr->clusters, stats_ptr->pop, stats_ptr->xmean, stats_ptr->ymean, stats_ptr->rad, stats_ptr->average_slope, stats_ptr->mean_cluster_size, stats_ptr->percent_urban );}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void stats_LogStatVal (int run, int year, int index, stats_val_t * stats_ptr, FILE * fp){ int i; int num_elements; double *ptr; /*num_elements = sizeof(struct stats_val_t)/sizeof(double); */ num_elements = sizeof (stats_val_t) / sizeof (double); ptr = (double *) stats_ptr; fprintf (fp, "%5u %4u %2u ", run, year, index);#if 1 for (i = 0; i < num_elements; i++) { fprintf (fp, "%8.2f ", *ptr); ptr++; } fprintf (fp, "\n");#else fprintf (fp, "%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f ", stats_ptr->area, stats_ptr->edges, stats_ptr->clusters, stats_ptr->pop, stats_ptr->xmean, stats_ptr->ymean, stats_ptr->rad, stats_ptr->slope ); fprintf (fp, "%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f \n", stats_ptr->mean_cluster_size, stats_ptr->sng, stats_ptr->sdg, stats_ptr->sdc, stats_ptr->og, stats_ptr->rt, stats_ptr->pop );#endif}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void stats_LogAverages (int index, FILE * fp){ LOG_INT (fp, index); LOG_FLOAT (fp, average[index].area); LOG_FLOAT (fp, average[index].edges); LOG_FLOAT (fp, average[index].clusters); LOG_FLOAT (fp, average[index].pop); LOG_FLOAT (fp, average[index].xmean); LOG_FLOAT (fp, average[index].ymean); LOG_FLOAT (fp, average[index].rad); LOG_FLOAT (fp, average[index].slope); LOG_FLOAT (fp, average[index].mean_cluster_size); LOG_FLOAT (fp, average[index].sng); LOG_FLOAT (fp, average[index].sdg); LOG_FLOAT (fp, average[index].sdc); LOG_FLOAT (fp, average[index].og); LOG_FLOAT (fp, average[index].rt); LOG_FLOAT (fp, average[index].pop);}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void stats_LogThisYearStats (FILE * fp){ LOG_FLOAT (fp, record.this_year.area); LOG_FLOAT (fp, record.this_year.edges); LOG_FLOAT (fp, record.this_year.clusters); LOG_FLOAT (fp, record.this_year.pop); LOG_FLOAT (fp, record.this_year.xmean); LOG_FLOAT (fp, record.this_year.ymean); LOG_FLOAT (fp, record.this_year.rad); LOG_FLOAT (fp, record.this_year.slope); LOG_FLOAT (fp, record.this_year.mean_cluster_size); LOG_FLOAT (fp, record.this_year.sng); LOG_FLOAT (fp, record.this_year.sdg); LOG_FLOAT (fp, record.this_year.sdc); LOG_FLOAT (fp, record.this_year.og); LOG_FLOAT (fp, record.this_year.rt); LOG_FLOAT (fp, record.this_year.pop);}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void stats_LogRecord (FILE * fp){ LOG_INT (fp, record.run); LOG_INT (fp, record.monte_carlo); LOG_INT (fp, record.year); stats_LogThisYearStats (fp);}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void stats_compute_leesalee (GRID_P Z, /* IN */ GRID_P urban, /* IN */ double *leesalee) /* OUT */{ char func[] = "stats_compute_leesalee"; int i; int the_union; int intersection; FUNC_INIT; assert (Z != NULL); assert (urban != NULL); assert (leesalee != NULL); the_union = 0; intersection = 0; for (i = 0; i < mem_GetTotalPixels (); i++) { if ((Z[i] != 0) || (urban[i] != 0)) { the_union++; } if ((Z[i] != 0) && (urban[i] != 0)) { intersection++; } } *leesalee = (double) intersection / the_union; FUNC_END;}/*************************************************************************************************************************************************************** FUNCTION NAME: ** PURPOSE: ** AUTHOR: Keith Clarke** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void stats_Analysis (double fmatch){#if 1 char func[] = "stats_Analysis";#endif char std_filename[MAX_FILENAME_LEN]; char avg_filename[MAX_FILENAME_LEN]; char cntrl_filename[MAX_FILENAME_LEN]; char *output_dir; int yr; int i; int run; static int avg_log_created = 0; static int std_dev_log_created = 0; static int control_stats_log_created = 0; output_dir = scen_GetOutputDir ();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?