Commit ea157239 authored by Norby, Tom's avatar Norby, Tom

Update haemsnd2arl to fix DST update to time.

parent 53f22492
Pipeline #112021 canceled with stages
in 5 minutes and 17 seconds
......@@ -23,11 +23,18 @@ using namespace radix;
void addHour(struct tm *time, int hours)
{
#ifdef _WIN32
// Windows doesn't like anything less than 1970
time->tm_year = time->tm_year + 400;
#endif // _WIN32
int seconds = hours * 60 * 60;
time_t date_seconds = mktime(time) + seconds;
*time = *localtime(&date_seconds);
#ifdef _WIN32
time->tm_year = time->tm_year - 400;
#endif
}
int main(int argc, char **argv)
......@@ -105,11 +112,18 @@ int main(int argc, char **argv)
int day = from_string(startTime.substr(6, 2), 19);
int hour = from_string(startTime.substr(8, 2), 17);
struct tm metTime = {0, 0, 0};
struct tm metTime = {0, 0, 0, 0, 0, 0, 0, 0, 0};
metTime.tm_year = year - 1900;
metTime.tm_mon = month - 1;
metTime.tm_mday = day;
metTime.tm_hour = hour;
metTime.tm_mday = day;
addHour(&metTime, 0); // <- initializes to local time - due to DST this can
// change hour etc.
// now we reset relevant fields.
metTime.tm_year = year - 1900;
metTime.tm_mon = month - 1;
metTime.tm_hour = hour;
metTime.tm_mday = day;
std::cout << "Creating ARL-formatted met file with parameters:" << std::endl;
std::cout << " " << extent << " by " << extent << " km grid centred on ("
......@@ -511,8 +525,8 @@ int main(int argc, char **argv)
for (int timestep = 0; timestep < numberTimesteps; ++timestep)
{
// Write index header section
std::cout << " Writing index headers for timestep " << timestep << "..."
<< std::endl;
radix_tagged_line(" Writing index headers for timestep " << timestep
<< "...");
ARLRecordHeader thisRecordHeader;
thisRecordHeader.year = metTime.tm_year;
thisRecordHeader.month = metTime.tm_mon + 1;
......@@ -568,13 +582,13 @@ int main(int argc, char **argv)
// Write the headers
outputStream.write_record_header(thisRecordHeader);
outputStream.write_index_header(thisRecordHeader, thisIndexHeader);
std::cout << " Headers written" << std::endl;
radix_tagged_line(" Headers written");
// Write meteorological variables for each level
for (int level = 0; level < inputPressures.size(); ++level)
{
std::cout << " Writing meteorological data for timestep " << timestep
<< ", level " << level << "..." << std::endl;
radix_tagged_line(" Writing meteorological data for timestep "
<< timestep << ", level " << level << "..." <<);
thisRecordHeader.il = level;
......@@ -587,11 +601,11 @@ int main(int argc, char **argv)
std::vector<std::vector<float>> thisData(
numberGridCells,
std::vector<float>(numberGridCells, groundPressure));
std::cout << " pressure...";
// std::cout << " pressure...";
outputStream.write_record_header(thisRecordHeader);
outputStream.write_record(thisRecordHeader, thisIndexHeader,
thisData);
std::cout << "written" << std::endl;
// std::cout << "written" << std::endl;
}
else
{
......@@ -600,11 +614,11 @@ int main(int argc, char **argv)
thisRecordHeader.var1 = thisHeight;
std::vector<std::vector<float>> thisData(
numberGridCells, std::vector<float>(numberGridCells, thisHeight));
std::cout << " height...";
// std::cout << " height...";
outputStream.write_record_header(thisRecordHeader);
outputStream.write_record(thisRecordHeader, thisIndexHeader,
thisData);
std::cout << "written" << std::endl;
// std::cout << "written" << std::endl;
}
}
......@@ -615,10 +629,10 @@ int main(int argc, char **argv)
std::vector<std::vector<float>> thisData(
numberGridCells,
std::vector<float>(numberGridCells, inputTemps[level]));
std::cout << " temperature...";
// std::cout << " temperature...";
outputStream.write_record_header(thisRecordHeader);
outputStream.write_record(thisRecordHeader, thisIndexHeader, thisData);
std::cout << "written" << std::endl;
// std::cout << "written" << std::endl;
}
// Write relative humidity levels
......@@ -638,10 +652,10 @@ int main(int argc, char **argv)
thisRecordHeader.var1 = thisVar;
std::vector<std::vector<float>> thisData(
numberGridCells, std::vector<float>(numberGridCells, thisVar));
std::cout << " relative humidity...";
// std::cout << " relative humidity...";
outputStream.write_record_header(thisRecordHeader);
outputStream.write_record(thisRecordHeader, thisIndexHeader, thisData);
std::cout << "written" << std::endl;
// std::cout << "written" << std::endl;
}
// Write wind data
......@@ -652,44 +666,38 @@ int main(int argc, char **argv)
float thisWindV =
(inputWSpds[level] * 0.5144444444) *
cos(toRadians(fmod((inputWDirs[level] + 180.0), 360.0)));
std::cout << " Initial wspd = " << inputWSpds[level]
<< " knots, wdir: " << inputWDirs[level] << " degrees"
<< std::endl;
std::cout << " Converted wind components: u = " << thisWindU
<< " m/s, v = " << thisWindV << "m/s" << std::endl;
radix_tagged_line(" Initial wspd = "
<< inputWSpds[level]
<< " knots, wdir: " << inputWDirs[level] << " degrees");
radix_tagged_line(" Converted wind components: u = "
<< thisWindU << " m/s, v = " << thisWindV << "m/s");
{
thisRecordHeader.kvar = "UWND";
thisRecordHeader.var1 = thisWindU;
std::vector<std::vector<float>> thisData(
numberGridCells, std::vector<float>(numberGridCells, thisWindU));
std::cout << " wind (u component)...";
// std::cout << " wind (u component)...";
outputStream.write_record_header(thisRecordHeader);
outputStream.write_record(thisRecordHeader, thisIndexHeader, thisData);
std::cout << "written" << std::endl;
// std::cout << "written" << std::endl;
}
{
thisRecordHeader.kvar = "VWND";
thisRecordHeader.var1 = thisWindV;
std::vector<std::vector<float>> thisData(
numberGridCells, std::vector<float>(numberGridCells, thisWindV));
std::cout << " wind (v component)...";
// std::cout << " wind (v component)...";
outputStream.write_record_header(thisRecordHeader);
outputStream.write_record(thisRecordHeader, thisIndexHeader, thisData);
std::cout << "written" << std::endl;
// std::cout << "written" << std::endl;
}
}
std::cout << " Written timestep " << timestep << std::endl;
radix_tagged_line(" Written timestep ");
printf("%d-%02d-%02d %02d:%02d\n", metTime.tm_year, (metTime.tm_mon + 1),
metTime.tm_mday, metTime.tm_hour, metTime.tm_min);
// Add an hour to time for next timestep
#ifdef _WIN32
metTime.tm_year = metTime.tm_year + 400;
#endif // _WIN32
addHour(&metTime, 1);
printf("%d%02d%02d:%02d\n", metTime.tm_year, (metTime.tm_mon + 1),
metTime.tm_mday, metTime.tm_hour);
#ifdef _WIN32
metTime.tm_year = metTime.tm_year - 400;
#endif
}
std::cout << "File write complete!" << std::endl;
......
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