Commit 9c7c08b1 authored by Fabian Wachsmann's avatar Fabian Wachsmann
Browse files

Set time values for subdaily frequency if t_axis=cmip

parent 18cf6df1
......@@ -4617,9 +4617,9 @@ get_tunitsec(int tunit)
}
static juldate_t
get_cmor_time_val(list_t *kvl, int taxisID, juldate_t ref_date, int tunitsec, int calendar, char *frequency, int ts_id)
get_cmor_time_val(list_t *kvl, int taxisID, juldate_t ref_date, int tunitsec, int calendar, char *frequency, int ts_id, int time_axis)
{
int year, month, day;
int year, month, day, hour, min, sec;
cdiDecodeDate(taxisInqVdate(taxisID), &year, &month, &day);
juldate_t juldate = juldate_encode(calendar, taxisInqVdate(taxisID), taxisInqVtime(taxisID));
......@@ -4709,7 +4709,66 @@ get_cmor_time_val(list_t *kvl, int taxisID, juldate_t ref_date, int tunitsec, in
}
}
}
if ( time_axis == 1 && strcmp(kv_get_a_val(kvl, "ta", "n"), "cmip") == 0 )
{
long int vdate;
int vtime;
juldate_decode(calendar, juldate, &vdate, &vtime);
cdiDecodeTime(vtime, &hour, &min, &sec);
if (strcmp(frequency, "6hr") == 0)
{
int iv[]= {0,6,12,18,24};
size_t ivsize = sizeof(iv)/sizeof(iv[0]);
int minid = 0;
double diff = juldate_to_seconds(juldate_sub(juldate, juldate_encode(calendar, vdate, cdiEncodeTime(0, 0, 0))));
for ( size_t loopid = 1; loopid < ivsize; loopid++ )
{
if ( std::fabs(juldate_to_seconds(juldate_sub(juldate, juldate_encode(calendar, vdate, cdiEncodeTime(iv[loopid], 0, 0))))) < diff )
{
minid = loopid;
diff = std::fabs(juldate_to_seconds(juldate_sub(juldate, juldate_encode(calendar, vdate, cdiEncodeTime(iv[minid], 0, 0)))));
}
}
juldate = juldate_encode(calendar, taxisInqVdate(taxisID), cdiEncodeTime(iv[minid], 0, 0));
}
else if (strcmp(frequency, "3hr") == 0)
{
int iv[]= {0,3,6,9,12,15,18,21,24};
size_t ivsize = sizeof(iv)/sizeof(iv[0]);
int minid = 0;
double diff = juldate_to_seconds(juldate_sub(juldate, juldate_encode(calendar, vdate, cdiEncodeTime(0, 0, 0))));
for ( size_t loopid = 1; loopid < ivsize; loopid++ )
{
if ( std::fabs(juldate_to_seconds(juldate_sub(juldate, juldate_encode(calendar, vdate, cdiEncodeTime(iv[loopid], 0, 0))))) < diff )
{
minid = loopid;
diff = std::fabs(juldate_to_seconds(juldate_sub(juldate, juldate_encode(calendar, vdate, cdiEncodeTime(iv[minid], 0, 0)))));
}
}
juldate = juldate_encode(calendar, taxisInqVdate(taxisID), cdiEncodeTime(iv[minid], 0, 0));
}
else if (strcmp(frequency, "1hr") == 0)
{
size_t ivsize = 25;
int minid = 0;
double diff = juldate_to_seconds(juldate_sub(juldate, juldate_encode(calendar, vdate, cdiEncodeTime(0, 0, 0))));
for ( size_t loopid = 1; loopid < ivsize; loopid++ )
{
if ( std::fabs(juldate_to_seconds(juldate_sub(juldate, juldate_encode(calendar, vdate, cdiEncodeTime(loopid, 0, 0))))) < diff )
{
minid = loopid;
diff = std::fabs(juldate_to_seconds(juldate_sub(juldate, juldate_encode(calendar, vdate, cdiEncodeTime(minid, 0, 0)))));
}
}
juldate = juldate_encode(calendar, vdate, cdiEncodeTime(minid, 0, 0));
}
}
return juldate;
}
......@@ -4719,7 +4778,8 @@ get_time_bounds(list_t *kvl, int taxisID, int ifreq, juldate_t ref_date, juldate
{
double time_val = juldate_to_seconds(juldate_sub(jtime_val, ref_date)) / tunitsec;
int vtime0b, vtime1b, vtimecorr;
int64_t vdatecorr, vdate0b, vdate1b;
int64_t vdatecorr = taxisInqVdate(taxisID);
int64_t vdate0b, vdate1b;
int year, month, day;
int hour, min, sec;
cdiDecodeDate(taxisInqVdate(taxisID), &year, &month, &day);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment