# HG changeset patch # User Forrest Hoffman # Date 1191265934 14400 # Node ID 2ce4ee911439af3727f8fa9d10c3f278bb7d9855 # Parent 3c02cce30be8fddfe7ca1a28dc959cc5bc330f8d Fixed h1_summary and h1_summary2 to correctly construct time_bounds values. h1_summary and h1_summary2 previously used the time_bounds from the last time value from the last input file when summarizing, suggesting that the field values were appropriate only over that short time range instead of the complete time period over which the statistics were calculated. C-LAMP Experiment 1 runs used the previous code, so the time_bounds were incorrect in the statistical summaries produced. C-LAMP Experiment 2 runs will use this new code for production of statistical summaries. diff -r 3c02cce30be8 -r 2ce4ee911439 Makefile --- a/Makefile Wed Sep 26 17:16:40 2007 -0400 +++ b/Makefile Mon Oct 01 15:12:14 2007 -0400 @@ -3,12 +3,12 @@ # robin1 and phoenix LIBS=-L$(NETCDF)/lib -lnetcdf -lm # Penguins -#LIBS=-L/usr/local/netcdf/netcdf-3.6.1-gcc+pgi/lib -lnetcdf -lm +#LIBS=-L/usr/lib64/netcdf-3 -lnetcdf -lm # # robin1 and phoenix CPPFLAGS=-I$(NETCDF)/include # Penguins -#CPPFLAGS=-I/usr/local/netcdf/netcdf-3.6.1-gcc+pgi/include +#CPPFLAGS=-I/usr/include/netcdf-3 # phoenix #CC=cc #CFLAGS=-O -h list=m $(CPPFLAGS) diff -r 3c02cce30be8 -r 2ce4ee911439 h1_summary.c --- a/h1_summary.c Wed Sep 26 17:16:40 2007 -0400 +++ b/h1_summary.c Mon Oct 01 15:12:14 2007 -0400 @@ -82,6 +82,7 @@ }; static char *time_name = "time"; +static char *time_bounds_name = "time_bounds"; static char *mcsec_name = "mcsec"; static char *history_name = "history"; static char *nsamples_name = "nsamples"; @@ -783,7 +784,8 @@ } void copy_metadata(int in_ncid, struct var *in_var_head, - struct dim **in_dim_idx, int out_ncid, struct var *out_var_head) + struct dim **in_dim_idx, int out_ncid, struct var *out_var_head, + double *tbounds) { int i, j; float hr[HOURS_PER_DAY]; @@ -819,7 +821,10 @@ time-based metadata variable %s\n", in_vnode->name); #endif /* DEBUG */ val = read_timeslice(in_ncid, in_vnode->ncvarid, in_vnode->nctype, in_vnode->ndims, in_vnode->dimids, in_dim_idx, ((input_dim_idx[in_vnode->dimids[0]])->len - 1)); - write_timeslice(out_ncid, out_vnode->ncvarid, out_vnode->nctype, in_vnode->ndims, in_vnode->dimids, in_dim_idx, val, 0); + if (!strcmp(in_vnode->name, time_bounds_name)) + write_timeslice(out_ncid, out_vnode->ncvarid, out_vnode->nctype, in_vnode->ndims, in_vnode->dimids, in_dim_idx, tbounds, 0); + else + write_timeslice(out_ncid, out_vnode->ncvarid, out_vnode->nctype, in_vnode->ndims, in_vnode->dimids, in_dim_idx, val, 0); } free(val); /* @@ -845,11 +850,63 @@ return; } -void open_inout(char *input_fname, char *mean_fname, char *stddev_fname, char *flist, size_t nsamples) +void get_time_bounds(char *first_fname, char *last_fname, double *tbounds) +{ + int time_dimid, time_bounds_varid; + size_t time_len, time_bounds_index[2]; + double bnd1, bnd2; + + /* Open first input file */ + wrap_nc(nc_open(first_fname, NC_NOWRITE, &input_ncid)); + /* Get dimension ID of the time dimension */ + wrap_nc(nc_inq_dimid(input_ncid, time_name, &time_dimid)); + /* Get length of time dimension */ + wrap_nc(nc_inq_dimlen(input_ncid, time_dimid, &time_len)); + /* Get variable ID of time_bounds variable */ + wrap_nc(nc_inq_varid(input_ncid, time_bounds_name, &time_bounds_varid)); + /* Set index for reading the first value of time_bounds from the + * first timeslice of the first file */ + time_bounds_index[0] = time_bounds_index[1] = 0; + /* Read the value */ + wrap_nc(nc_get_var1_double(input_ncid, time_bounds_varid, + time_bounds_index, &bnd1)); + /* If the first and last file are not the same, close the first one and + * open the second one */ + if (strcmp(first_fname, last_fname)) { + /* Close the first input file */ + wrap_nc(nc_close(input_ncid)); + /* Open the last input file */ + wrap_nc(nc_open(last_fname, NC_NOWRITE, &input_ncid)); + /* Get dimension ID of the time dimension */ + wrap_nc(nc_inq_dimid(input_ncid, time_name, &time_dimid)); + /* Get length of time dimension */ + wrap_nc(nc_inq_dimlen(input_ncid, time_dimid, &time_len)); + /* Get variable ID of time_bounds variable */ + wrap_nc(nc_inq_varid(input_ncid, time_bounds_name, + &time_bounds_varid)); + } + /* Set index for reading the second value of time_bounds from the + * last timeslice of the last file */ + time_bounds_index[0] = time_len - 1; time_bounds_index[1] = 1; + /* Read the value */ + wrap_nc(nc_get_var1_double(input_ncid, time_bounds_varid, + time_bounds_index, &bnd2)); + + /* Close the last input file */ + wrap_nc(nc_close(input_ncid)); + + tbounds[0] = bnd1; + tbounds[1] = bnd2; + + return; +} + +void open_inout(char *first_fname, char *last_fname, char *mean_fname, char *stddev_fname, char *flist, size_t nsamples) { char *mean_history_gatt, *stddev_history_gatt, *mean_prefix="Statistical means from history files:", *stddev_prefix="Statistical standard deviations from history files:"; + double tbounds[2]; /* * Construct strings for history global attributes for the two output @@ -866,8 +923,16 @@ sprintf(mean_history_gatt, "%s%s", mean_prefix, flist); sprintf(stddev_history_gatt, "%s%s", stddev_prefix, flist); - /* Open input file */ - wrap_nc(nc_open(input_fname, NC_NOWRITE, &input_ncid)); + /* The two time_bounds values must be handled explicitly by obtaining + * the first one from the first file and the last one from the last + * file. These are then passed to copy_metadata() below. */ + get_time_bounds(first_fname, last_fname, tbounds); +#ifdef DEBUG + fprintf(stderr, "Got back tbounds=%lf,%lf\n", tbounds[0], tbounds[1]); +#endif /* DEBUG */ + + /* Open last input file */ + wrap_nc(nc_open(last_fname, NC_NOWRITE, &input_ncid)); /* Inquire about number of dimensions, variables, global attributes * and the ID of the unlimited dimension */ @@ -909,9 +974,9 @@ wrap_nc(nc_enddef(stddev_ncid)); /* Write out metdata variables that do not depend on "time" */ copy_metadata(input_ncid, input_var_head, input_dim_idx, mean_ncid, - mean_var_head); + mean_var_head, tbounds); copy_metadata(input_ncid, input_var_head, input_dim_idx, stddev_ncid, - stddev_var_head); + stddev_var_head, tbounds); wrap_nc(nc_close(input_ncid)); @@ -1513,7 +1578,8 @@ * only values from the last time slice from the period over which * the statistics are computed. */ - open_inout(ifnames[(nifnames-1)], mfname, sfname, flist, nsamples); + open_inout(ifnames[0], ifnames[(nifnames-1)], mfname, sfname, flist, + nsamples); compute_stats(nifnames, ifnames, nsamples); diff -r 3c02cce30be8 -r 2ce4ee911439 h1_summary2.c --- a/h1_summary2.c Wed Sep 26 17:16:40 2007 -0400 +++ b/h1_summary2.c Mon Oct 01 15:12:14 2007 -0400 @@ -82,6 +82,7 @@ }; static char *time_name = "time"; +static char *time_bounds_name = "time_bounds"; static char *mcsec_name = "mcsec"; static char *history_name = "history"; static char *nsamples_name = "nsamples"; @@ -783,7 +784,8 @@ } void copy_metadata(int in_ncid, struct var *in_var_head, - struct dim **in_dim_idx, int out_ncid, struct var *out_var_head) + struct dim **in_dim_idx, int out_ncid, struct var *out_var_head, + double *tbounds) { int i, j; float hr[HOURS_PER_DAY]; @@ -819,7 +821,10 @@ time-based metadata variable %s\n", in_vnode->name); #endif /* DEBUG */ val = read_timeslice(in_ncid, in_vnode->ncvarid, in_vnode->nctype, in_vnode->ndims, in_vnode->dimids, in_dim_idx, ((input_dim_idx[in_vnode->dimids[0]])->len - 1)); - write_timeslice(out_ncid, out_vnode->ncvarid, out_vnode->nctype, in_vnode->ndims, in_vnode->dimids, in_dim_idx, val, 0); + if (!strcmp(in_vnode->name, time_bounds_name)) + write_timeslice(out_ncid, out_vnode->ncvarid, out_vnode->nctype, in_vnode->ndims, in_vnode->dimids, in_dim_idx, tbounds, 0); + else + write_timeslice(out_ncid, out_vnode->ncvarid, out_vnode->nctype, in_vnode->ndims, in_vnode->dimids, in_dim_idx, val, 0); } free(val); /* @@ -845,11 +850,63 @@ return; } -void open_inout(char *input_fname, char *mean_fname, char *stddev_fname, char *flist, size_t nsamples) +void get_time_bounds(char *first_fname, char *last_fname, double *tbounds) +{ + int time_dimid, time_bounds_varid; + size_t time_len, time_bounds_index[2]; + double bnd1, bnd2; + + /* Open first input file */ + wrap_nc(nc_open(first_fname, NC_NOWRITE, &input_ncid)); + /* Get dimension ID of the time dimension */ + wrap_nc(nc_inq_dimid(input_ncid, time_name, &time_dimid)); + /* Get length of time dimension */ + wrap_nc(nc_inq_dimlen(input_ncid, time_dimid, &time_len)); + /* Get variable ID of time_bounds variable */ + wrap_nc(nc_inq_varid(input_ncid, time_bounds_name, &time_bounds_varid)); + /* Set index for reading the first value of time_bounds from the + * first timeslice of the first file */ + time_bounds_index[0] = time_bounds_index[1] = 0; + /* Read the value */ + wrap_nc(nc_get_var1_double(input_ncid, time_bounds_varid, + time_bounds_index, &bnd1)); + /* If the first and last file are not the same, close the first one and + * open the second one */ + if (strcmp(first_fname, last_fname)) { + /* Close the first input file */ + wrap_nc(nc_close(input_ncid)); + /* Open the last input file */ + wrap_nc(nc_open(last_fname, NC_NOWRITE, &input_ncid)); + /* Get dimension ID of the time dimension */ + wrap_nc(nc_inq_dimid(input_ncid, time_name, &time_dimid)); + /* Get length of time dimension */ + wrap_nc(nc_inq_dimlen(input_ncid, time_dimid, &time_len)); + /* Get variable ID of time_bounds variable */ + wrap_nc(nc_inq_varid(input_ncid, time_bounds_name, + &time_bounds_varid)); + } + /* Set index for reading the second value of time_bounds from the + * last timeslice of the last file */ + time_bounds_index[0] = time_len - 1; time_bounds_index[1] = 1; + /* Read the value */ + wrap_nc(nc_get_var1_double(input_ncid, time_bounds_varid, + time_bounds_index, &bnd2)); + + /* Close the last input file */ + wrap_nc(nc_close(input_ncid)); + + tbounds[0] = bnd1; + tbounds[1] = bnd2; + + return; +} + +void open_inout(char *first_fname, char *last_fname, char *mean_fname, char *stddev_fname, char *flist, size_t nsamples) { char *mean_history_gatt, *stddev_history_gatt, *mean_prefix="Statistical means from history files:", *stddev_prefix="Statistical standard deviations from history files:"; + double tbounds[2]; /* * Construct strings for history global attributes for the two output @@ -866,8 +923,16 @@ sprintf(mean_history_gatt, "%s%s", mean_prefix, flist); sprintf(stddev_history_gatt, "%s%s", stddev_prefix, flist); - /* Open input file */ - wrap_nc(nc_open(input_fname, NC_NOWRITE, &input_ncid)); + /* The two time_bounds values must be handled explicitly by obtaining + * the first one from the first file and the last one from the last + * file. These are then passed to copy_metadata() below. */ + get_time_bounds(first_fname, last_fname, tbounds); +#ifdef DEBUG + fprintf(stderr, "Got back tbounds=%lf,%lf\n", tbounds[0], tbounds[1]); +#endif /* DEBUG */ + + /* Open last input file */ + wrap_nc(nc_open(last_fname, NC_NOWRITE, &input_ncid)); /* Inquire about number of dimensions, variables, global attributes * and the ID of the unlimited dimension */ @@ -909,9 +974,9 @@ wrap_nc(nc_enddef(stddev_ncid)); /* Write out metdata variables that do not depend on "time" */ copy_metadata(input_ncid, input_var_head, input_dim_idx, mean_ncid, - mean_var_head); + mean_var_head, tbounds); copy_metadata(input_ncid, input_var_head, input_dim_idx, stddev_ncid, - stddev_var_head); + stddev_var_head, tbounds); wrap_nc(nc_close(input_ncid)); @@ -1602,7 +1667,8 @@ * only values from the last time slice from the period over which * the statistics are computed. */ - open_inout(ifnames[(nifnames-1)], mfname, sfname, flist, nsamples); + open_inout(ifnames[0], ifnames[(nifnames-1)], mfname, sfname, flist, + nsamples); compute_stats(nifnames, ifnames, nsamples);