From 9efb7558fad6a998d439548e3c346919e9b4398b Mon Sep 17 00:00:00 2001 From: Mindo Choi Date: Fri, 1 Dec 2023 19:28:41 +0000 Subject: [PATCH 1/7] fix reference mismatch --- utils/obsproc/IcecAmsr2Ioda.h | 7 ++++++- utils/obsproc/Smap2Ioda.h | 6 ++++++ utils/test/testref/icecamsr2ioda.test | 6 +++--- utils/test/testref/rads2ioda.test | 2 +- utils/test/testref/smap2ioda.test | 6 +++--- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/utils/obsproc/IcecAmsr2Ioda.h b/utils/obsproc/IcecAmsr2Ioda.h index 61bacfade..5aebe0be8 100644 --- a/utils/obsproc/IcecAmsr2Ioda.h +++ b/utils/obsproc/IcecAmsr2Ioda.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -65,6 +66,10 @@ namespace gdasapp { ncFile.getVar("Scan_Time").getVar(oneTmpdateTimeVal.data()); iodaVars.referenceDate_ = "seconds since 1970-01-01T00:00:00Z"; + // Set the time zone (UTC) + putenv("TZ=UTC"); + tzset(); + size_t index = 0; std::tm timeinfo = {}; for (int i = 0; i < ntimes; i += dimTimeSize) { @@ -73,7 +78,7 @@ namespace gdasapp { timeinfo.tm_mday = oneTmpdateTimeVal[i + 2]; timeinfo.tm_hour = oneTmpdateTimeVal[i + 3]; timeinfo.tm_min = oneTmpdateTimeVal[i + 4]; - timeinfo.tm_sec = oneTmpdateTimeVal[i + 5]; + timeinfo.tm_sec = static_cast(oneTmpdateTimeVal[i + 5]); // Calculate and store the seconds since the Unix epoch time_t epochtime = std::mktime(&timeinfo); diff --git a/utils/obsproc/Smap2Ioda.h b/utils/obsproc/Smap2Ioda.h index be3c2d8e3..3c045a2d7 100644 --- a/utils/obsproc/Smap2Ioda.h +++ b/utils/obsproc/Smap2Ioda.h @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include // NOLINT (using C API) #include @@ -70,6 +72,10 @@ namespace gdasapp { iodaVars.referenceDate_ = "seconds since 1970-01-01T00:00:00Z"; + // Set the time zone (UTC) + putenv("TZ=UTC"); + tzset(); + // calculate the seconds of Jan 1 of startyear since unix epoch std::tm tm{}; // defaults are zero, Jan is zero diff --git a/utils/test/testref/icecamsr2ioda.test b/utils/test/testref/icecamsr2ioda.test index a8ef1c959..da4819145 100644 --- a/utils/test/testref/icecamsr2ioda.test +++ b/utils/test/testref/icecamsr2ioda.test @@ -21,6 +21,6 @@ latitude: Max: 86.8975 Sum: 1346.66 datetime: - Min: 1625066557 - Max: 1625126209 - Sum: 27626797699 + Min: 1625048557 + Max: 1625108209 + Sum: 27626462899 diff --git a/utils/test/testref/rads2ioda.test b/utils/test/testref/rads2ioda.test index f6e0283ce..479a672ed 100644 --- a/utils/test/testref/rads2ioda.test +++ b/utils/test/testref/rads2ioda.test @@ -1,4 +1,4 @@ -iReading: [rads_adt_3a_2021181.nc4,rads_adt_3b_2021181.nc4] +Reading: [rads_adt_3a_2021181.nc4,rads_adt_3b_2021181.nc4] seconds since 1858-11-17T00:00:00Z obsVal: Min: 0.1671 diff --git a/utils/test/testref/smap2ioda.test b/utils/test/testref/smap2ioda.test index c644a5324..bc8916f2f 100644 --- a/utils/test/testref/smap2ioda.test +++ b/utils/test/testref/smap2ioda.test @@ -21,6 +21,6 @@ latitude: Max: 40.8618 Sum: -370.853 datetime: - Min: 1625197568 - Max: 1625204736 - Sum: 48756048640 + Min: 1625175936 + Max: 1625183104 + Sum: 48755399680 From c576e922e9f31c885a247d5f2b8dfd651721c715 Mon Sep 17 00:00:00 2001 From: Mindo Choi Date: Thu, 7 Dec 2023 15:02:11 +0000 Subject: [PATCH 2/7] avoid to set TZ time --- utils/obsproc/IcecAmsr2Ioda.h | 55 +++++++++++++++++++++++++---------- utils/obsproc/Smap2Ioda.h | 42 +++++++++++++++++--------- 2 files changed, 68 insertions(+), 29 deletions(-) diff --git a/utils/obsproc/IcecAmsr2Ioda.h b/utils/obsproc/IcecAmsr2Ioda.h index 5aebe0be8..ba9b3bab7 100644 --- a/utils/obsproc/IcecAmsr2Ioda.h +++ b/utils/obsproc/IcecAmsr2Ioda.h @@ -1,10 +1,12 @@ #pragma once -#include +#include #include +#include #include #include #include // NOLINT (using C API) +#include #include #include @@ -66,23 +68,44 @@ namespace gdasapp { ncFile.getVar("Scan_Time").getVar(oneTmpdateTimeVal.data()); iodaVars.referenceDate_ = "seconds since 1970-01-01T00:00:00Z"; - // Set the time zone (UTC) - putenv("TZ=UTC"); - tzset(); - size_t index = 0; - std::tm timeinfo = {}; for (int i = 0; i < ntimes; i += dimTimeSize) { - timeinfo.tm_year = oneTmpdateTimeVal[i] - 1900; // Year since 1900 - timeinfo.tm_mon = oneTmpdateTimeVal[i + 1] - 1; // 0-based; 8 represents Sep - timeinfo.tm_mday = oneTmpdateTimeVal[i + 2]; - timeinfo.tm_hour = oneTmpdateTimeVal[i + 3]; - timeinfo.tm_min = oneTmpdateTimeVal[i + 4]; - timeinfo.tm_sec = static_cast(oneTmpdateTimeVal[i + 5]); - - // Calculate and store the seconds since the Unix epoch - time_t epochtime = std::mktime(&timeinfo); - iodaVars.datetime_(index) = static_cast(epochtime); + std::ostringstream timeinfo; + timeinfo << std::setfill('0'); + timeinfo << std::setw(4) << oneTmpdateTimeVal[i] << '-'; + timeinfo << std::setw(2) << oneTmpdateTimeVal[i+1] << '-'; + timeinfo << std::setw(2) << oneTmpdateTimeVal[i+2] << ' '; + timeinfo << std::setw(2) << oneTmpdateTimeVal[i+3] << ':'; + timeinfo << std::setw(2) << oneTmpdateTimeVal[i+4] << ':'; + timeinfo << std::setw(2) << oneTmpdateTimeVal[i+5]; + + // Print out the formatted time + oops::Log::info() << "Converted and Formatted time: " << timeinfo.str() << std::endl; + + // Parse the formatted string from the product + std::tm t2 = {}; + std::istringstream ss(timeinfo.str()); + ss >> std::get_time(&t2, "%Y-%m-%d %H:%M:%S"); + + auto time_point2 = std::chrono::system_clock::from_time_t(std::mktime(&t2)); + + // Print out the formatted time in seconds + oops::Log::info() << "time point2: " << std::chrono::system_clock::to_time_t(time_point2) + << std::endl; + + // Convert the formatted string from iso8601_string + std::tm t1 = {}; + std::istringstream epoch("1970-01-01 00:00:00"); + epoch >> std::get_time(&t1, "%Y-%m-%d %H:%M:%S"); + + auto time_point1 = std::chrono::system_clock::from_time_t(std::mktime(&t1)); + + // Calculate the duration between the two time points + auto duration = time_point2 - time_point1; + auto seconds = std::chrono::duration_cast(duration).count(); + + // Write the duration in seconds to IODA since the Unix epoch + iodaVars.datetime_(index) = seconds; index++; } diff --git a/utils/obsproc/Smap2Ioda.h b/utils/obsproc/Smap2Ioda.h index 3c045a2d7..64231449e 100644 --- a/utils/obsproc/Smap2Ioda.h +++ b/utils/obsproc/Smap2Ioda.h @@ -1,7 +1,5 @@ #pragma once -#include -#include #include #include // NOLINT (using C API) #include @@ -72,18 +70,36 @@ namespace gdasapp { iodaVars.referenceDate_ = "seconds since 1970-01-01T00:00:00Z"; - // Set the time zone (UTC) - putenv("TZ=UTC"); - tzset(); - // calculate the seconds of Jan 1 of startyear since unix epoch - std::tm tm{}; - // defaults are zero, Jan is zero - tm.tm_year = startYear - 1900; - tm.tm_mday = 1; - time_t unixStartYear = mktime(&tm); - - int unixStartDay = unixStartYear + startDay * 86400; + std::ostringstream timeinfo; + timeinfo << std::setfill('0'); + timeinfo << std::setw(4) << startYear << '-'; + timeinfo << std::setw(2) << 1 << '-'; + timeinfo << std::setw(2) << 1 << ' '; + timeinfo << std::setw(2) << 0 << ':'; + timeinfo << std::setw(2) << 0 << ':'; + timeinfo << std::setw(2) << 0; + + // Print out the formatted time + oops::Log::info() << "Converted and Formatted time: " << timeinfo.str() << std::endl; + + std::tm t2 = {}; + std::istringstream ss(timeinfo.str()); + ss >> std::get_time(&t2, "%Y-%m-%d %H:%M:%S"); + + auto time_point2 = std::chrono::system_clock::from_time_t(std::mktime(&t2)); + // Print out the formatted time in seconds + oops::Log::info() << "time point2: " << std::chrono::system_clock::to_time_t(time_point2) + << std::endl; + // Convert the formatted string from iso8601_string + std::tm t1 = {}; + std::istringstream epoch("1970-01-01 00:00:00"); + epoch >> std::get_time(&t1, "%Y-%m-%d %H:%M:%S"); + auto time_point1 = std::chrono::system_clock::from_time_t(std::mktime(&t1)); + // Calculate the duration between the two time points + auto duration = time_point2 - time_point1; + auto seconds = std::chrono::duration_cast(duration).count(); + int unixStartDay = seconds + (startDay * 86400); int loc; for (int i = 0; i < dim0; i++) { From 37f6ec810ecf635b606705fefabd023a99318ac6 Mon Sep 17 00:00:00 2001 From: Mindo Choi Date: Thu, 7 Dec 2023 15:27:57 +0000 Subject: [PATCH 3/7] remove chrono from the head --- utils/obsproc/IcecAmsr2Ioda.h | 1 - utils/obsproc/Smap2Ioda.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/obsproc/IcecAmsr2Ioda.h b/utils/obsproc/IcecAmsr2Ioda.h index ba9b3bab7..808aac9e2 100644 --- a/utils/obsproc/IcecAmsr2Ioda.h +++ b/utils/obsproc/IcecAmsr2Ioda.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include diff --git a/utils/obsproc/Smap2Ioda.h b/utils/obsproc/Smap2Ioda.h index 64231449e..c368ddabd 100644 --- a/utils/obsproc/Smap2Ioda.h +++ b/utils/obsproc/Smap2Ioda.h @@ -1,7 +1,10 @@ #pragma once +#include +#include #include #include // NOLINT (using C API) +#include #include #include From ef0934536b59dc1134120af7bdd263f3af505eea Mon Sep 17 00:00:00 2001 From: Mindo Choi Date: Thu, 7 Dec 2023 15:35:19 +0000 Subject: [PATCH 4/7] Turn on all ctests --- utils/test/CMakeLists.txt | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/utils/test/CMakeLists.txt b/utils/test/CMakeLists.txt index a53c92c2e..96aff4631 100644 --- a/utils/test/CMakeLists.txt +++ b/utils/test/CMakeLists.txt @@ -62,12 +62,11 @@ ecbuild_add_test( TARGET test_gdasapp_util_ghrsst2ioda WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/obsproc) # Test the SMAP to IODA converter -# TODO(Mindo): Turn back on when date is fixed -#ecbuild_add_test( TARGET test_gdasapp_util_smap2ioda -# COMMAND ${CMAKE_BINARY_DIR}/bin/gdas_obsprovider2ioda.x -# ARGS "../testinput/gdas_smap2ioda.yaml" -# LIBS gdas-utils -# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/obsproc) +ecbuild_add_test( TARGET test_gdasapp_util_smap2ioda + COMMAND ${CMAKE_BINARY_DIR}/bin/gdas_obsprovider2ioda.x + ARGS "../testinput/gdas_smap2ioda.yaml" + LIBS gdas-utils + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/obsproc) # Test the SMOS to IODA converter ecbuild_add_test( TARGET test_gdasapp_util_smos2ioda @@ -77,9 +76,8 @@ ecbuild_add_test( TARGET test_gdasapp_util_smos2ioda WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/obsproc) # Test the AMSR2 to IODA converter -# TODO(Mindo): Turn back on when date is fixed -#ecbuild_add_test( TARGET test_gdasapp_util_icecamsr2ioda -# COMMAND ${CMAKE_BINARY_DIR}/bin/gdas_obsprovider2ioda.x -# ARGS "../testinput/gdas_icecamsr2ioda.yaml" -# LIBS gdas-utils -# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/obsproc) +ecbuild_add_test( TARGET test_gdasapp_util_icecamsr2ioda + COMMAND ${CMAKE_BINARY_DIR}/bin/gdas_obsprovider2ioda.x + ARGS "../testinput/gdas_icecamsr2ioda.yaml" + LIBS gdas-utils + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/obsproc) From dff22afa2f5c8d6636dff6cf8fde3a6cf8ff7c56 Mon Sep 17 00:00:00 2001 From: Mindo Choi Date: Mon, 18 Dec 2023 13:04:48 -0600 Subject: [PATCH 5/7] adapted oops/util --- utils/obsproc/IcecAmsr2Ioda.h | 61 ++++++++++++++--------------------- utils/obsproc/Smap2Ioda.h | 48 +++++++++++---------------- 2 files changed, 43 insertions(+), 66 deletions(-) diff --git a/utils/obsproc/IcecAmsr2Ioda.h b/utils/obsproc/IcecAmsr2Ioda.h index 808aac9e2..affbcf71a 100644 --- a/utils/obsproc/IcecAmsr2Ioda.h +++ b/utils/obsproc/IcecAmsr2Ioda.h @@ -15,6 +15,7 @@ #include "ioda/Group.h" #include "ioda/ObsGroup.h" +#include "oops/util/dateFunctions.h" #include "NetCDFToIodaConverter.h" @@ -69,42 +70,30 @@ namespace gdasapp { size_t index = 0; for (int i = 0; i < ntimes; i += dimTimeSize) { - std::ostringstream timeinfo; - timeinfo << std::setfill('0'); - timeinfo << std::setw(4) << oneTmpdateTimeVal[i] << '-'; - timeinfo << std::setw(2) << oneTmpdateTimeVal[i+1] << '-'; - timeinfo << std::setw(2) << oneTmpdateTimeVal[i+2] << ' '; - timeinfo << std::setw(2) << oneTmpdateTimeVal[i+3] << ':'; - timeinfo << std::setw(2) << oneTmpdateTimeVal[i+4] << ':'; - timeinfo << std::setw(2) << oneTmpdateTimeVal[i+5]; - - // Print out the formatted time - oops::Log::info() << "Converted and Formatted time: " << timeinfo.str() << std::endl; - - // Parse the formatted string from the product - std::tm t2 = {}; - std::istringstream ss(timeinfo.str()); - ss >> std::get_time(&t2, "%Y-%m-%d %H:%M:%S"); - - auto time_point2 = std::chrono::system_clock::from_time_t(std::mktime(&t2)); - - // Print out the formatted time in seconds - oops::Log::info() << "time point2: " << std::chrono::system_clock::to_time_t(time_point2) - << std::endl; - - // Convert the formatted string from iso8601_string - std::tm t1 = {}; - std::istringstream epoch("1970-01-01 00:00:00"); - epoch >> std::get_time(&t1, "%Y-%m-%d %H:%M:%S"); - - auto time_point1 = std::chrono::system_clock::from_time_t(std::mktime(&t1)); - - // Calculate the duration between the two time points - auto duration = time_point2 - time_point1; - auto seconds = std::chrono::duration_cast(duration).count(); - - // Write the duration in seconds to IODA since the Unix epoch - iodaVars.datetime_(index) = seconds; + int year = oneTmpdateTimeVal[i]; + int month = oneTmpdateTimeVal[i+1]; + int day = oneTmpdateTimeVal[i+2]; + int hour = oneTmpdateTimeVal[i+3]; + int minute = oneTmpdateTimeVal[i+4]; + int second = static_cast(oneTmpdateTimeVal[i+5]); + + // Bypassing validYYYYMMDD function within dateToJulian + if (year == -9999 && month == -9999 && day == -9999 && + hour == -9999 && minute == -9999 && second == -9999) { + year = 0, month = 0, day = 0; + hour = 0, minute = 0, second = 0; + } + + uint64_t julianDate = util::datefunctions::dateToJulian(year, month, day); + + // Convert a date to Julian date + // Subtract Julian date for January 1, 1970 (epoch) + int daysSinceEpoch = julianDate - 2440588; + + // Calculate seconds only from HHMMSS + int secondsOffset = util::datefunctions::hmsToSeconds(hour, minute, second); + + iodaVars.datetime_(index) = static_cast(daysSinceEpoch*86400.0f) + secondsOffset; index++; } diff --git a/utils/obsproc/Smap2Ioda.h b/utils/obsproc/Smap2Ioda.h index c368ddabd..106ddb373 100644 --- a/utils/obsproc/Smap2Ioda.h +++ b/utils/obsproc/Smap2Ioda.h @@ -14,6 +14,7 @@ #include "ioda/Group.h" #include "ioda/ObsGroup.h" +#include "oops/util/dateFunctions.h" #include "oops/util/DateTime.h" #include "NetCDFToIodaConverter.h" @@ -73,36 +74,23 @@ namespace gdasapp { iodaVars.referenceDate_ = "seconds since 1970-01-01T00:00:00Z"; - // calculate the seconds of Jan 1 of startyear since unix epoch - std::ostringstream timeinfo; - timeinfo << std::setfill('0'); - timeinfo << std::setw(4) << startYear << '-'; - timeinfo << std::setw(2) << 1 << '-'; - timeinfo << std::setw(2) << 1 << ' '; - timeinfo << std::setw(2) << 0 << ':'; - timeinfo << std::setw(2) << 0 << ':'; - timeinfo << std::setw(2) << 0; - - // Print out the formatted time - oops::Log::info() << "Converted and Formatted time: " << timeinfo.str() << std::endl; - - std::tm t2 = {}; - std::istringstream ss(timeinfo.str()); - ss >> std::get_time(&t2, "%Y-%m-%d %H:%M:%S"); - - auto time_point2 = std::chrono::system_clock::from_time_t(std::mktime(&t2)); - // Print out the formatted time in seconds - oops::Log::info() << "time point2: " << std::chrono::system_clock::to_time_t(time_point2) - << std::endl; - // Convert the formatted string from iso8601_string - std::tm t1 = {}; - std::istringstream epoch("1970-01-01 00:00:00"); - epoch >> std::get_time(&t1, "%Y-%m-%d %H:%M:%S"); - auto time_point1 = std::chrono::system_clock::from_time_t(std::mktime(&t1)); - // Calculate the duration between the two time points - auto duration = time_point2 - time_point1; - auto seconds = std::chrono::duration_cast(duration).count(); - int unixStartDay = seconds + (startDay * 86400); + int year = startYear; + int month = 1; + int day = 1; + + // Bypassing validYYYYMMDD function within dateToJulian + if (year == -9999) { + year = 1970; + } + + uint64_t julianDate = util::datefunctions::dateToJulian(year, month, day); + + // Convert a date to Julian date + // Subtract Julian date for January 1, 1970 (epoch) + int daysSinceEpoch = julianDate - 2440588; + + // Calculate seconds + int unixStartDay = (daysSinceEpoch + startDay) * 86400; int loc; for (int i = 0; i < dim0; i++) { From 162bd123c3fcec27a8646682fd9bac3f660b55a1 Mon Sep 17 00:00:00 2001 From: Mindo Choi Date: Tue, 19 Dec 2023 11:34:59 -0600 Subject: [PATCH 6/7] address minor comments --- utils/obsproc/IcecAmsr2Ioda.h | 6 +++--- utils/obsproc/Smap2Ioda.h | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/utils/obsproc/IcecAmsr2Ioda.h b/utils/obsproc/IcecAmsr2Ioda.h index affbcf71a..ccc9c1e9d 100644 --- a/utils/obsproc/IcecAmsr2Ioda.h +++ b/utils/obsproc/IcecAmsr2Ioda.h @@ -77,17 +77,17 @@ namespace gdasapp { int minute = oneTmpdateTimeVal[i+4]; int second = static_cast(oneTmpdateTimeVal[i+5]); - // Bypassing validYYYYMMDD function within dateToJulian + // Replace Fillvalue -9999 to 0 to avoid crash in dateToJulian if (year == -9999 && month == -9999 && day == -9999 && hour == -9999 && minute == -9999 && second == -9999) { year = 0, month = 0, day = 0; hour = 0, minute = 0, second = 0; } + // Convert a date to Julian date uint64_t julianDate = util::datefunctions::dateToJulian(year, month, day); - // Convert a date to Julian date - // Subtract Julian date for January 1, 1970 (epoch) + // Subtract Julian day from January 1, 1970 (convert to epoch) int daysSinceEpoch = julianDate - 2440588; // Calculate seconds only from HHMMSS diff --git a/utils/obsproc/Smap2Ioda.h b/utils/obsproc/Smap2Ioda.h index 106ddb373..cb8fb52fe 100644 --- a/utils/obsproc/Smap2Ioda.h +++ b/utils/obsproc/Smap2Ioda.h @@ -78,19 +78,19 @@ namespace gdasapp { int month = 1; int day = 1; - // Bypassing validYYYYMMDD function within dateToJulian + // Replace Fillvalue -9999 to 0 to avoid crash in dateToJulian if (year == -9999) { - year = 1970; + year = 0; } + // Convert a date to Julian date uint64_t julianDate = util::datefunctions::dateToJulian(year, month, day); - // Convert a date to Julian date - // Subtract Julian date for January 1, 1970 (epoch) + // Subtract Julian day from January 1, 1970 (convert to epoch) int daysSinceEpoch = julianDate - 2440588; // Calculate seconds - int unixStartDay = (daysSinceEpoch + startDay) * 86400; + int secondsSinceEpoch = (daysSinceEpoch + startDay) * 86400; int loc; for (int i = 0; i < dim0; i++) { @@ -101,7 +101,7 @@ namespace gdasapp { iodaVars.obsVal_(loc) = sss[i][j]; iodaVars.obsError_(loc) = sss_error[i][j]; iodaVars.preQc_(loc) = sss_qc[i][j]; - iodaVars.datetime_(loc) = static_cast(obsTime[j] + unixStartDay); + iodaVars.datetime_(loc) = static_cast(obsTime[j] + secondsSinceEpoch); } } From 3f7cbaeb7c06017e05748bb0ad654a4bfb453401 Mon Sep 17 00:00:00 2001 From: Mindo Choi Date: Tue, 19 Dec 2023 11:34:59 -0600 Subject: [PATCH 7/7] address minor comments --- utils/obsproc/IcecAmsr2Ioda.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/utils/obsproc/IcecAmsr2Ioda.h b/utils/obsproc/IcecAmsr2Ioda.h index ccc9c1e9d..e2d0b2e5d 100644 --- a/utils/obsproc/IcecAmsr2Ioda.h +++ b/utils/obsproc/IcecAmsr2Ioda.h @@ -78,10 +78,9 @@ namespace gdasapp { int second = static_cast(oneTmpdateTimeVal[i+5]); // Replace Fillvalue -9999 to 0 to avoid crash in dateToJulian - if (year == -9999 && month == -9999 && day == -9999 && - hour == -9999 && minute == -9999 && second == -9999) { - year = 0, month = 0, day = 0; - hour = 0, minute = 0, second = 0; + if (year == -9999 || month == -9999 || day == -9999 || + hour == -9999 || minute == -9999 || second == -9999) { + year = month = day = hour = minute = second = 0; } // Convert a date to Julian date