Commit 2188e1f6 authored by Lefebvre, Jordan's avatar Lefebvre, Jordan
Browse files

#13. Fixing issues reveal by darwin gitlab-ci.

parent 90eccc1e
Pipeline #10631 passed with stage
in 3 minutes and 52 seconds
......@@ -28,6 +28,9 @@ IF (NOT TRIBITS_PROCESSING_PACKAGE)
IF(DEBUG_OUTPUT)
ADD_DEFINITIONS("-DDEBUG_OUTPUT=${DEBUG_OUTPUT}")
ENDIF()
IF(RADIX_DBC)
ADD_DEFINITIONS("-DRADIX_DBC=${RADIX_DBC}")
ENDIF()
#
# For windows with BUILD_SHARED_LIBS we must use CMAKE_RUNTIME_OUTPUT_DIRECTORY
# to place all *dll and *exe in the same directory so unit tests will work
......
......@@ -582,8 +582,8 @@ int eafstream::readHeader()
void eafstream::writeHeader(int header)
{
writeInt(header);
// don't count header in bytes written
mBytesWritten -= int_size;
// reset bytes written
mBytesWritten = 0;
}
int eafstream::header() const
......@@ -596,7 +596,7 @@ int eafstream::readFooter()
if (mBytesRead < mHeader)
{
skipBytes(mHeader - mBytesRead);
radix_line("skypped " << (mHeader-mBytesRead) << " bytes");
radix_line("skipped " << (mHeader-mBytesRead) << " bytes");
}
mFooter = readInt();
return mFooter;
......
......@@ -71,6 +71,7 @@ void HysplitCDump::addLocation(int year, int month, int day, int hour, float lat
loc.lat = lat;
loc.lon = lon;
loc.z = z;
mStartLocations.push_back(loc);
}
int HysplitCDump::numLat() const
......
......@@ -38,6 +38,7 @@ bool HysplitCDumpStream<data_type>::read_from(const std::string& file)
>> numLocations
>> packing;
fstr.readFooter();
radix_ensure(fstr.header() == fstr.footer());
mData->setDateTime(year, month, day, hour);
mData->setForecastHour(forecastHour);
......@@ -57,6 +58,7 @@ bool HysplitCDumpStream<data_type>::read_from(const std::string& file)
>> minutes;
mData->addLocation(year, month, day, hour, lat, lon, z, minutes);
fstr.readFooter();
radix_ensure(fstr.header() == fstr.footer());
}
int numLat, numLon;
......@@ -69,6 +71,7 @@ bool HysplitCDumpStream<data_type>::read_from(const std::string& file)
>> cLat
>> cLon;
fstr.readFooter();
radix_ensure(fstr.header() == fstr.footer());
mData->setNumLat(numLat);
mData->setNumLon(numLon);
mData->setDeltaLat(deltaLat);
......@@ -86,6 +89,7 @@ bool HysplitCDumpStream<data_type>::read_from(const std::string& file)
mData->addLevel(level);
}
fstr.readFooter();
radix_ensure(fstr.header() == fstr.footer());
fstr.readHeader();
int numPollutants;
......@@ -97,6 +101,7 @@ bool HysplitCDumpStream<data_type>::read_from(const std::string& file)
mData->addPollutant(pol);
}
fstr.readFooter();
radix_ensure(fstr.header() == fstr.footer());
// infinite loop over observation times
......@@ -111,6 +116,7 @@ bool HysplitCDumpStream<data_type>::read_from(const std::string& file)
>> minutes
>> forecastHour;
fstr.readFooter();
radix_ensure(fstr.header() == fstr.footer());
mData->addStartTime(year, month, day, hour, minutes, forecastHour);
fstr.readHeader();
......@@ -121,6 +127,7 @@ bool HysplitCDumpStream<data_type>::read_from(const std::string& file)
>> minutes
>> forecastHour;
fstr.readFooter();
radix_ensure(fstr.header() == fstr.footer());
mData->addEndTime(year, month, day, hour, minutes, forecastHour);
for(int i = 0; i < numPollutants; ++i)
......@@ -145,6 +152,7 @@ bool HysplitCDumpStream<data_type>::read_from(const std::string& file)
}
} // if packing is enabled
fstr.readFooter();
radix_ensure(fstr.header() == fstr.footer());
fstr.peek(); // peek ahead to check file integrity
} // loop over num levels
} // loop num pollutants
......@@ -194,8 +202,10 @@ bool HysplitCDumpStream<data_type>::write_to(const std::string& file) const
{
mData->location(i, year, month, day, hour, lat, lon, z, minutes);
record_length = sizeof(int) * 5 + sizeof(float)*3;
radix_tagged_line("record_length=" << record_length);
fstr.writeHeader(record_length);
fstr << year << month << day << hour << lat << lon << z << minutes;
radix_tagged_line("bytes_written=" << fstr.bytesWritten());
fstr.writeFooter(record_length);
}
int numLat, numLon;
......@@ -208,8 +218,10 @@ bool HysplitCDumpStream<data_type>::write_to(const std::string& file) const
cLon = mData->cornerLon();
record_length = sizeof(int)*2+sizeof(float)*4;
radix_tagged_line("record_length=" << record_length);
fstr.writeHeader(record_length);
fstr << numLat << numLon << deltaLat << deltaLon << cLat << cLon;
radix_tagged_line("bytes_written=" << fstr.bytesWritten());
fstr.writeFooter(record_length);
int numLevels = mData->numLevels();
......@@ -233,13 +245,14 @@ bool HysplitCDumpStream<data_type>::write_to(const std::string& file) const
for(int i = 0; i < numPollutants; ++i)
{
std::string pol = mData->pollutant(i);
radix_tagged_line("pollutant=" << pol);
// force string to be only 4 characters
char cid[5];
sprintf(cid, "%4s", pol.c_str());
cid[4] = '\0'; // null terminate
pol = cid;
fstr.writeString(pol);
local_pols.push_back(pol);
cid[4] = '\0';
std::string tmp = cid;
fstr.writeString(tmp);
local_pols.push_back(tmp);
}
radix_tagged_line("bytes_written=" << fstr.bytesWritten());
fstr.writeFooter(record_length);
......
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