from e-support OYW-455599.

Problem was that in nctime.c#CDMonthDay, it was setting up
the month -> #days table correctly, but it did not use it
because it forgot to check for Cd366, it only checked for Cd365.
This commit is contained in:
Dennis Heimbigner 2017-07-24 18:59:16 -06:00
parent d18378c69b
commit 9e2d6faaf6
3 changed files with 29 additions and 8 deletions

View File

@ -7,6 +7,9 @@
#ifndef _NCTIME_H
#define _NCTIME_H
#define CU_FATAL 1 /* Exit immediately on fatal error */
#define CU_VERBOSE 2 /* Report errors */
struct bounds_node{
int ncid; /* group (or file) in which variable with associated
* bounds variable resides */
@ -152,12 +155,14 @@ MSC_NCTIME_EXTRA extern void cdChar2Comp(cdCalenType timetype, char* chartime, c
MSC_NCTIME_EXTRA extern void Cdh2e(CdTime *htime, double *etime);
MSC_NCTIME_EXTRA extern void Cde2h(double etime, CdTimeType timeType, long baseYear, CdTime *htime);
MSC_NCTIME_EXTRA extern int cdParseRelunits(cdCalenType timetype, char* relunits, cdUnitTime* unit, cdCompTime* base_comptime);
MSC_NCTIME_EXTRA extern int cdSetErrOpts(int opts);
#else
extern void cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, char* chartime);
extern void cdChar2Comp(cdCalenType timetype, char* chartime, cdCompTime* comptime);
extern void Cdh2e(CdTime *htime, double *etime);
extern void Cde2h(double etime, CdTimeType timeType, long baseYear, CdTime *htime);
extern int cdParseRelunits(cdCalenType timetype, char* relunits, cdUnitTime* unit, cdCompTime* base_comptime);
extern int cdSetErrOpts(int opts);
#endif /* DLL Considerations. */

View File

@ -28,9 +28,6 @@
static int cuErrOpts; /* Error options */
static int cuErrorOccurred = 0; /* True iff cdError was called */
#define CU_FATAL 1 /* Exit immediately on fatal error */
#define CU_VERBOSE 2 /* Report errors */
#define CD_DEFAULT_BASEYEAR "1979" /* Default base year for relative time (no 'since' clause) */
#define VALCMP(a,b) ((a)<(b)?-1:(b)<(a)?1:0)
@ -57,8 +54,9 @@ cdTrim(char* s, int n)
return;
}
static
void cdError(char *fmt, ...){
static void
cdError(char *fmt, ...)
{
va_list args;
cuErrorOccurred = 1;
@ -75,6 +73,7 @@ void cdError(char *fmt, ...){
}
#define ISLEAP(year,timeType) ((timeType & Cd366) || (((timeType) & CdHasLeap) && (!((year) % 4) && (((timeType) & CdJulianType) || (((year) % 100) || !((year) % 400))))))
static int mon_day_cnt[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
static int days_sum[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
@ -120,11 +119,13 @@ CdMonthDay(int *doy, CdTime *date)
}
date->month = 0;
for (i = 0; i < 12; i++) {
int delta;
(date->month)++;
date->day = (short)idoy;
if ((idoy -= ((date->timeType & Cd365) ? (mon_day_cnt[date->month-1]) : 30)) <= 0) {
return;
}
delta = ((date->timeType & Cd365) || (date->timeType & Cd366) ? (mon_day_cnt[date->month-1]) : 30);
idoy -= delta;
if(idoy <= 0)
return;
}
return;
}
@ -1173,3 +1174,11 @@ cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, c
return;
}
int
cdSetErrOpts(int opts)
{
int old = cuErrOpts;
cuErrOpts = opts;
return old;
}

View File

@ -1313,9 +1313,16 @@ nctime_val_tostring(const ncvar_t *varp, safebuf_t *sfbf, const void *valp) {
double vv = to_double(varp, valp);
int separator = formatting_specs.iso_separator ? 'T' : ' ';
if(isfinite(vv)) {
int oldopts = 0;
int newopts = 0;
int res;
sout[0]='"';
/* Make nctime dump error messages */
oldopts = cdSetErrOpts(0);
newopts = oldopts | CU_VERBOSE;
cdSetErrOpts(newopts);
cdRel2Iso(varp->timeinfo->calendar, varp->timeinfo->units, separator, vv, &sout[1]);
cdSetErrOpts(oldopts);
res = strlen(sout);
sout[res++] = '"';
sout[res] = '\0';