Skip to content
Snippets Groups Projects
Commit 6855506c authored by Thomas Jahns's avatar Thomas Jahns :cartwheel: Committed by Sergey Kosukhin
Browse files

Extract calendar test 1.

parent 0261c65b
No related branches found
No related tags found
No related merge requests found
......@@ -102,6 +102,7 @@ Makefile
/examples/pio/collectData2003
/examples/pio/collectDataNStreams
/examples/pio/compareResourcesArray
/tests/calendar_test1
/tests/cksum_read
/tests/cksum_verify
/tests/cksum_write
......
......@@ -232,100 +232,6 @@ julianDate_to_seconds(JulianDate julianDate)
return julianDate.julianDay * 86400.0 + julianDate.secondOfDay;
}
#ifdef TEST
int
main(void)
{
int calendar = CALENDAR_STANDARD;
int j = 0;
// 1 - Check valid range of years
{
int nmin = 11000;
int vdate0 = -80001201;
int vtime0 = 120500;
printf("start time: %8d %4d\n", vdate0, vtime0);
CdiDateTime dt = cdiDateTime_set(vdate0, vtime0);
for (int i = 0; i < nmin; i++)
{
JulianDate julianDate = julianDate_encode(calendar, dt);
dt = julianDate_decode(calendar, julianDate);
int vdate = (int) cdiDate_get(dt.date);
int vtime = cdiTime_get(dt.time);
if (vdate0 != vdate || vtime0 != vtime)
printf("%4d %8d %4d %8d %4d %9d %g\n", ++j, vdate0, vtime0, vdate, vtime, (int) julianDate.julianDay,
julianDate.secondOfDay);
dt.date.year++;
julianDate = julianDate_encode(calendar, dt);
dt = julianDate_decode(calendar, julianDate);
vdate0 = (int) cdiDate_get(dt.date);
vtime0 = cdiTime_get(dt.time);
}
printf("stop time: %8d %4d\n", vdate0, vtime0);
}
// 2 - Check time increment of one minute
{
int nmin = 120000;
int ijulinc = 60;
int vdate0 = 20001201;
int vtime0 = 0;
printf("start time: %8d %4d\n", vdate0, vtime0);
CdiDateTime dt = cdiDateTime_set(vdate0, vtime0);
JulianDate julianDate = julianDate_encode(calendar, dt);
for (int i = 0; i < nmin; i++)
{
int year, mon, day, hour, minute, second;
cdiDecodeDate(vdate0, &year, &mon, &day);
cdiDecodeTime(vtime0, &hour, &minute, &second);
if (++minute >= 60)
{
minute = 0;
if (++hour >= 24)
{
hour = 0;
if (++day >= 32)
{
day = 1;
if (++mon >= 13)
{
mon = 1;
year++;
}
}
}
}
vdate0 = cdiEncodeDate(year, mon, day);
vtime0 = cdiEncodeTime(hour, minute, second);
julianDate = julianDate_add_seconds(julianDate, ijulinc);
dt = julianDate_decode(calendar, julianDate);
int vdate = (int) cdiDate_get(dt.date);
int vtime = cdiTime_get(dt.time);
if (vdate0 != vdate || vtime0 != vtime)
printf("%4d %8d %4d %8d %4d %9d %g\n", ++j, vdate0, vtime0, vdate, vtime, (int) julianDate.julianDay,
julianDate.secondOfDay);
}
printf("stop time: %8d %4d\n", vdate0, vtime0);
}
return 0;
}
#endif
#ifdef TEST2
int
main(void)
......
......@@ -7,6 +7,7 @@ TESTS = cksum_verify \
test_cksum_nc test_cksum_extra \
test_cksum_service test_cksum_nc2 test_cksum_nc4 test_cksum_ieg \
test_chunk_cksum \
calendar_test1 \
pio_write_run pio_cksum_mpinonb pio_cksum_fpguard \
pio_cksum_asynch pio_cksum_writer \
pio_cksum_cdf \
......@@ -20,7 +21,9 @@ TESTS = cksum_verify \
#test_cdf_const: deactivated (depends on app/cdi)
check_PROGRAMS = cksum_verify test_grib cksum_write cksum_read pio_write \
check_PROGRAMS = cksum_verify test_grib cksum_write cksum_read \
calendar_test1 \
pio_write \
test_resource_copy cksum_write_chunk pio_write_deco2d test_table \
test_byteswap
......@@ -37,6 +40,7 @@ cksum_read_SOURCES = cksum_read.c \
var_cksum.c var_cksum.h \
stream_cksum.c stream_cksum.h \
ensure_array_size.h ensure_array_size.c
calendar_test1_SOURCES = calendar_test1.c
pio_write_SOURCES = pio_write.c pio_write.h simple_model.c \
simple_model_helper.h simple_model_helper.c \
pio_write_setup_grid.h pio_write_setup_grid.c
......
#include <stdio.h>
#include <stdlib.h>
#include "cdi.h"
#include "julian_date.h"
int
main(void)
{
int calendar = CALENDAR_STANDARD;
int j = 0;
// 1 - Check valid range of years
{
int nmin = 11000;
int vdate0 = -80001201;
int vtime0 = 120500;
// printf("start time: %8d %4d\n", vdate0, vtime0);
CdiDateTime dt = cdiDateTime_set(vdate0, vtime0);
for (int i = 0; i < nmin; i++)
{
JulianDate julianDate = julianDate_encode(calendar, dt);
dt = julianDate_decode(calendar, julianDate);
int vdate = (int) cdiDate_get(dt.date);
int vtime = cdiTime_get(dt.time);
if (vdate0 != vdate || vtime0 != vtime)
fprintf(stderr, "%4d %8d %4d %8d %4d %9d %g\n", ++j, vdate0, vtime0, vdate, vtime, (int) julianDate.julianDay,
julianDate.secondOfDay);
dt.date.year++;
julianDate = julianDate_encode(calendar, dt);
dt = julianDate_decode(calendar, julianDate);
vdate0 = (int) cdiDate_get(dt.date);
vtime0 = cdiTime_get(dt.time);
}
// printf("stop time: %8d %4d\n", vdate0, vtime0);
}
// 2 - Check time increment of one minute
{
int nmin = 120000;
int ijulinc = 60;
int vdate0 = 20001201;
int vtime0 = 0;
// printf("start time: %8d %4d\n", vdate0, vtime0);
CdiDateTime dt = cdiDateTime_set(vdate0, vtime0);
JulianDate julianDate = julianDate_encode(calendar, dt);
for (int i = 0; i < nmin; i++)
{
int year, mon, day, hour, minute, second;
cdiDecodeDate(vdate0, &year, &mon, &day);
cdiDecodeTime(vtime0, &hour, &minute, &second);
if (++minute >= 60)
{
minute = 0;
if (++hour >= 24)
{
hour = 0;
if (++day >= 32)
{
day = 1;
if (++mon >= 13)
{
mon = 1;
year++;
}
}
}
}
vdate0 = cdiEncodeDate(year, mon, day);
vtime0 = cdiEncodeTime(hour, minute, second);
julianDate = julianDate_add_seconds(julianDate, ijulinc);
dt = julianDate_decode(calendar, julianDate);
int vdate = (int) cdiDate_get(dt.date);
int vtime = cdiTime_get(dt.time);
if (vdate0 != vdate || vtime0 != vtime)
fprintf(stderr, "%4d %8d %4d %8d %4d %9d %g\n", ++j, vdate0, vtime0, vdate, vtime, (int) julianDate.julianDay,
julianDate.secondOfDay);
}
// printf("stop time: %8d %4d\n", vdate0, vtime0);
}
return j == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment