Commit 09442fbe authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

use always decode_date and encode_date to decode/encode date

parent acad26f7
2007-09-?? Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* use always decode_date and encode_date to decode/encode date
* Version 1.0.8 released
2007-06-15 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* using EXSE library version 1.0.2
......
......@@ -17,6 +17,9 @@
#define DBL_IS_EQUAL(x,y) (!(fabs(x - y) > 0))
#endif
void decode_date(int date, int *year, int *month, int *day);
void decode_time(int time, int *hour, int *minute);
int getopt(int argc, char *const argv[], const char *optstring);
......@@ -76,21 +79,6 @@ static void usage(void)
}
static void decodeDate(int date, int *year, int *month, int *day)
{
*year = date / 10000;
*month = (date - *year*10000) / 100;
*day = date - *year*10000 - *month*100;
}
static void decodeTime(int time, int *hour, int *minute)
{
*hour = time / 100;
*minute = time - *hour*100;
}
static void printInfo(int gridtype, int date, int time, int code, double level,
int datasize, int nmiss, double missval, const double *data)
{
......@@ -106,8 +94,8 @@ static void printInfo(int gridtype, int date, int time, int code, double level,
/* ----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+ */
}
decodeDate(date, &year, &month, &day);
decodeTime(time, &hour, &minute);
decode_date(date, &year, &month, &day);
decode_time(time, &hour, &minute);
fprintf(stdout, "%6d : %4.4d-%2.2d-%2.2d %2.2d:%2.2d %3d %7g ",
++rec, year, month, day, hour, minute, code, level);
......@@ -232,21 +220,6 @@ void printFiletype(int streamID)
}
void decode_date(int date, int *year, int *month, int *day)
{
*year = date / 10000;
*month = (date - *year*10000) / 100;
*day = date - *year*10000 - *month*100;
}
void decode_time(int time, int *hour, int *minute)
{
*hour = time / 100;
*minute = time - *hour*100;
}
static void printShortinfo(int streamID, int vlistID, int vardis)
{
int varID;
......
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.59 for cdi 1.0.7.
# Generated by GNU Autoconf 2.59 for cdi 1.0.8.
#
# Report bugs to <Uwe.Schulzweida@zmaw.de>.
#
......@@ -269,8 +269,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME='cdi'
PACKAGE_TARNAME='cdi'
PACKAGE_VERSION='1.0.7'
PACKAGE_STRING='cdi 1.0.7'
PACKAGE_VERSION='1.0.8'
PACKAGE_STRING='cdi 1.0.8'
PACKAGE_BUGREPORT='Uwe.Schulzweida@zmaw.de'
# Factoring default headers for most tests.
......@@ -795,7 +795,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures cdi 1.0.7 to adapt to many kinds of systems.
\`configure' configures cdi 1.0.8 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
......@@ -862,7 +862,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of cdi 1.0.7:";;
short | recursive ) echo "Configuration of cdi 1.0.8:";;
esac
cat <<\_ACEOF
......@@ -996,7 +996,7 @@ fi
test -n "$ac_init_help" && exit 0
if $ac_init_version; then
cat <<\_ACEOF
cdi configure 1.0.7
cdi configure 1.0.8
generated by GNU Autoconf 2.59
Copyright (C) 2003 Free Software Foundation, Inc.
......@@ -1010,7 +1010,7 @@ cat >&5 <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by cdi $as_me 1.0.7, which was
It was created by cdi $as_me 1.0.8, which was
generated by GNU Autoconf 2.59. Invocation command line was
$ $0 $@
......@@ -1697,7 +1697,7 @@ fi
# Define the identity of the package.
PACKAGE=cdi
VERSION=1.0.7
VERSION=1.0.8
cat >>confdefs.h <<_ACEOF
......@@ -5821,7 +5821,7 @@ _ASBOX
} >&5
cat >&5 <<_CSEOF
This file was extended by cdi $as_me 1.0.7, which was
This file was extended by cdi $as_me 1.0.8, which was
generated by GNU Autoconf 2.59. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
......@@ -5884,7 +5884,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
cdi config.status 1.0.7
cdi config.status 1.0.8
configured by $0, generated by GNU Autoconf 2.59,
with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
......
# Process this file with autoconf to produce a configure script.
AC_INIT(cdi, 1.0.7, Uwe.Schulzweida@zmaw.de)
AC_INIT(cdi, 1.0.8, Uwe.Schulzweida@zmaw.de)
CONFIG_ABORT=yes
......
......@@ -12,6 +12,11 @@ streamWriteVar stream
streamReadVar stream
streamWriteVarSlice stream
streamReadVarSlice stream
streamDefRecord stream_record
streamInqRecord stream_record
streamWriteRecord stream_record
streamReadRecord stream_record
streamCopyRecord stream_record
vlistCreate vlist
vlistDestroy vlist
vlistCopy vlist
......@@ -33,6 +38,8 @@ vlistDefVarName vlist_var
vlistInqVarName vlist_var
vlistDefVarLongname vlist_var
vlistInqVarLongname vlist_var
vlistDefVarStdname vlist_var
vlistInqVarStdname vlist_var
vlistDefVarUnits vlist_var
vlistInqVarUnits vlist_var
vlistDefVarDatatype vlist_var
......@@ -42,6 +49,8 @@ vlistInqVarMissval vlist_var
gridCreate grid
gridDestroy grid
gridDuplicate grid
gridIsCyclic grid
gridIsRotated grid
gridInqType grid
gridInqSize grid
gridDefXsize grid
......@@ -56,6 +65,8 @@ gridDefXbounds grid
gridInqXbounds grid
gridDefYbounds grid
gridInqYbounds grid
gridDefXpole grid
gridInqXpole grid
gridDefXname grid
gridInqXname grid
gridDefXlongname grid
......@@ -70,11 +81,19 @@ gridDefYunits grid
gridInqYunits grid
zaxisCreate zaxis
zaxisDestroy zaxis
zaxisDuplicate zaxis
zaxisInqType zaxis
zaxisInqSize zaxis
zaxisDefLevels zaxis
zaxisInqLevels zaxis
zaxisInqLevel zaxis
zaxisDefLbounds zaxis
zaxisDefUbounds zaxis
zaxisInqLbounds zaxis
zaxisInqUbounds zaxis
zaxisDefVct zaxis
zaxisInqVctSize zaxis
zaxisInqVct zaxis
zaxisDefName zaxis
zaxisInqName zaxis
zaxisDefLongname zaxis
......@@ -83,6 +102,7 @@ zaxisDefUnits zaxis
zaxisInqUnits zaxis
taxisCreate taxis
taxisDestroy taxis
taxisDuplicate taxis
taxisDefRdate taxis
taxisInqRdate taxis
taxisDefRtime taxis
......
......@@ -185,8 +185,8 @@ static int splitBasetime(char *timeunits, TAXIS *taxis)
}
}
rdate = year*10000 + month*100 + day;
rtime = hour*100 + minute;
rdate = encode_date(year, month, day);
rtime = encode_time(hour, minute);
(*taxis).rdate = rdate;
(*taxis).rtime = rtime;
}
......@@ -673,11 +673,10 @@ void cdfDefTime(int streamID)
rdate = taxis->vdate;
rtime = taxis->vtime;
}
year = rdate / 10000;
month = (rdate - year*10000) / 100;
day = rdate - year*10000 - month*100;
hour = rtime / 100;
minute = rtime - hour*100;
decode_date(rdate, &year, &month, &day);
decode_time(rtime, &hour, &minute);
sprintf(unitstr, "%s since %d-%02d-%02d %02d:%02d",
tunitNamePtr(timeunit), year, month, day, hour, minute);
}
......@@ -4798,7 +4797,6 @@ int cdfInqTimestep(int streamID, int tsID)
decode_timeval(timevalue, taxis, &taxis->vdate_ub, &taxis->vtime_ub);
}
}
}
......
......@@ -1679,11 +1679,8 @@ void grbDefTime(int *isec1, int date, int time, int numavg, int timeID)
rdate = taxisInqRdate(timeID);
rtime = taxisInqRtime(timeID);
year = rdate / 10000;
month = (rdate - year*10000) / 100;
day = rdate - year*10000 - month*100;
hour = rtime / 100;
minute = rtime - hour*100;
decode_date(rdate, &year, &month, &day);
decode_time(rtime, &hour, &minute);
century = year / 100;
ISEC1_Year = year - century*100;
......@@ -1703,11 +1700,8 @@ void grbDefTime(int *isec1, int date, int time, int numavg, int timeID)
case TUNIT_DAY: tunit.factor = 86400; ISEC1_TimeUnit = ISEC1_TABLE4_DAY; break;
default: tunit.factor = 3600; ISEC1_TimeUnit = ISEC1_TABLE4_HOUR; break;
}
year = date / 10000;
month = (date - year*10000) / 100;
day = date - year*10000 - month*100;
hour = time / 100;
minute = time - hour*100;
decode_date(date, &year, &month, &day);
decode_time(time, &hour, &minute);
/*
printf("date time %d %d %g\n", date, time, value);
printf("year %d, month %d, day %d, hour %d, minute %d\n", year, month, day, hour, minute);
......@@ -1722,11 +1716,8 @@ void grbDefTime(int *isec1, int date, int time, int numavg, int timeID)
if ( timetype == TAXIS_ABSOLUTE )
{
year = date / 10000;
month = (date - year*10000) / 100;
day = date - year*10000 - month*100;
hour = time / 100;
minute = time - hour*100;
decode_date(date, &year, &month, &day);
decode_time(time, &hour, &minute);
century = year / 100;
ISEC1_Year = year - century*100;
......
......@@ -217,11 +217,8 @@ void iegDefTime(int *pdb, int date, int time, int timeID)
if ( timetype == TAXIS_ABSOLUTE || timetype == TAXIS_RELATIVE )
{
year = date / 10000;
month = (date - year*10000) / 100;
day = date - year*10000 - month*100;
hour = time / 100;
minute = time - hour*100;
decode_date(date, &year, &month, &day);
decode_time(time, &hour, &minute);
IEG_P_Year(pdb) = year;
IEG_P_Month(pdb) = month;
......@@ -756,8 +753,8 @@ void iegDateTime(int *pdb, int *date, int *time)
if ( rminute == -1 ) rminute = 0;
*date = ryear*10000 + rmonth*100 + rday;
*time = rhour*100 + rminute;
*date = encode_date(ryear, rmonth, rday);
*time = encode_time(rhour, rminute);
}
......
......@@ -281,4 +281,10 @@ int streamInqDimgroupID(int streamID);
int getByteswap(int byteorder);
void decode_date(int date, int *year, int *month, int *day);
int encode_date(int year, int month, int day);
void decode_time(int time, int *hour, int *minute);
int encode_time(int hour, int minute);
#endif /* _STREAM_INT_H */
......@@ -25,6 +25,49 @@ char *Timeunits[] = {
};
void decode_date(int date, int *year, int *month, int *day)
{
int idate;
*year = date / 10000;
idate = date - *year*10000;
if ( idate < 0 ) idate = -idate;
*month = idate / 100;
*day = idate - *month*100;
}
int encode_date(int year, int month, int day)
{
int date;
int iyear;
iyear = year;
if ( iyear < 0 ) iyear = -iyear;
date = iyear*10000 + month*100 + day;
if ( year < 0 ) date = -date;
return (date);
}
void decode_time(int time, int *hour, int *minute)
{
*hour = time / 100;
*minute = time - *hour*100;
}
int encode_time(int hour, int minute)
{
int time;
time = hour*100 + minute;
return (time);
}
char *tunitNamePtr(int unitID)
{
char *name;
......@@ -839,11 +882,8 @@ void timeval2vtime(double timevalue, TAXIS *taxis, int *vdate, int *vtime)
rdate = (*taxis).rdate;
rtime = (*taxis).rtime;
year = rdate / 10000;
month = (rdate - year*10000) / 100;
day = rdate - year*10000 - month*100;
hour = rtime / 100;
minute = rtime - hour*100;
decode_date(rdate, &year, &month, &day);
decode_time(rtime, &hour, &minute);
if ( timeunit == TUNIT_MONTH || timeunit == TUNIT_YEAR )
{
......@@ -883,8 +923,8 @@ void timeval2vtime(double timevalue, TAXIS *taxis, int *vdate, int *vtime)
cdiCalendar(dpy, timevalue, tunit, &year, &month, &day, &hour, &minute, &second);
}
*vdate = year*10000 + month*100 + day;
*vtime = hour*100 + minute /* + (int) (second/60+0.5)*/;
*vdate = encode_date(year, month, day);
*vtime = encode_time(hour, minute);
}
......@@ -903,34 +943,28 @@ double vtime2timeval(int vdate, int vtime, TAXIS *taxis)
timeunit = (*taxis).unit;
calendar = (*taxis).calendar;
if ( calendar == CALENDAR_360DAYS ) dpy = 360;
else if ( calendar == CALENDAR_365DAYS ) dpy = 365;
else if ( calendar == CALENDAR_366DAYS ) dpy = 366;
if ( calendar == CALENDAR_360DAYS ) dpy = 360;
else if ( calendar == CALENDAR_365DAYS ) dpy = 365;
else if ( calendar == CALENDAR_366DAYS ) dpy = 366;
else if ( calendar == CALENDAR_PROLEPTIC ) dpy = -1;
rdate = (*taxis).rdate;
rtime = (*taxis).rtime;
rdate = (*taxis).rdate;
rtime = (*taxis).rtime;
if ( rdate == -1 )
{
rdate = (*taxis).vdate;
rtime = (*taxis).vtime;
}
ryear = rdate / 10000;
rmonth = (rdate - ryear*10000) / 100;
day = rdate - ryear*10000 - rmonth*100;
hour = rtime / 100;
minute = rtime - hour*100;
decode_date(rdate, &ryear, &rmonth, &day);
decode_time(rtime, &hour, &minute);
cdiInvCalendar(dpy, ryear, rmonth, day, hour, minute, 0.0, tunit, &value);
tunit.origin = value;
tunit.factor = 60.0;
year = vdate / 10000;
month = (vdate - year*10000) / 100;
day = vdate - year*10000 - month*100;
hour = vtime / 100;
minute = vtime - hour*100;
decode_date(vdate, &year, &month, &day);
decode_time(vtime, &hour, &minute);
if ( timeunit == TUNIT_MONTH || timeunit == TUNIT_YEAR )
{
......
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