Skip to content

Commit

Permalink
replace Duration with RelativeTimestamp
Browse files Browse the repository at this point in the history
few modifications and corrections
  • Loading branch information
vcloarec committed Dec 13, 2019
1 parent 4823890 commit 33e8ecb
Show file tree
Hide file tree
Showing 33 changed files with 195 additions and 9,052 deletions.
2 changes: 1 addition & 1 deletion mdal/frmts/mdal_3di.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void MDAL::Driver3Di::addBedElevation( MemoryMesh *mesh )
group->setIsScalar( true );

std::shared_ptr<MDAL::MemoryDataset2D> dataset = std::make_shared< MemoryDataset2D >( group.get() );
dataset->setTime( MDAL::Duration() );
dataset->setTime( MDAL::RelativeTimestamp() );
for ( size_t i = 0; i < faceCount; ++i )
{
dataset->setScalarValue( i, MDAL::safeValue( coordZ[i], fillZ ) );
Expand Down
10 changes: 5 additions & 5 deletions mdal/frmts/mdal_ascii_dat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void MDAL::DriverAsciiDat::loadOldFormat( std::ifstream &in,
else if ( cardType == "TS" && items.size() >= 2 )
{
double rawTime = toDouble( items[ 1 ] );
MDAL::Duration t( rawTime, MDAL::Duration::hours );
MDAL::RelativeTimestamp t( rawTime, MDAL::RelativeTimestamp::hours );
readVertexTimestep( mesh, group, t, isVector, false, in );
}
else
Expand Down Expand Up @@ -247,7 +247,7 @@ void MDAL::DriverAsciiDat::loadNewFormat(
else if ( cardType == "TS" && items.size() >= 3 )
{
double rawTime = toDouble( items[2] );
MDAL::Duration t( rawTime, MDAL::parseDurationTimeUnit( group->getMetadata( "TIMEUNITS" ) ) );
MDAL::RelativeTimestamp t( rawTime, MDAL::parseDurationTimeUnit( group->getMetadata( "TIMEUNITS" ) ) );

if ( faceCentered )
{
Expand Down Expand Up @@ -330,7 +330,7 @@ void MDAL::DriverAsciiDat::load( const std::string &datFile, MDAL::Mesh *mesh, M
void MDAL::DriverAsciiDat::readVertexTimestep(
const MDAL::Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
MDAL::Duration t,
MDAL::RelativeTimestamp t,
bool isVector,
bool hasStatus,
std::ifstream &stream ) const
Expand Down Expand Up @@ -399,7 +399,7 @@ void MDAL::DriverAsciiDat::readVertexTimestep(
void MDAL::DriverAsciiDat::readFaceTimestep(
const MDAL::Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
MDAL::Duration t,
MDAL::RelativeTimestamp t,
bool isVector,
std::ifstream &stream ) const
{
Expand Down Expand Up @@ -493,7 +493,7 @@ bool MDAL::DriverAsciiDat::persist( MDAL::DatasetGroup *group )
= std::dynamic_pointer_cast<MDAL::MemoryDataset2D>( group->datasets[time_index] );

bool hasActiveStatus = isOnVertices && dataset->supportsActiveFlag();
out << "TS " << hasActiveStatus << " " << std::to_string( dataset->time( Duration::hours ) ) << "\n";
out << "TS " << hasActiveStatus << " " << std::to_string( dataset->time( RelativeTimestamp::hours ) ) << "\n";

if ( hasActiveStatus )
{
Expand Down
4 changes: 2 additions & 2 deletions mdal/frmts/mdal_ascii_dat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ namespace MDAL

void readVertexTimestep( const Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
Duration t,
RelativeTimestamp t,
bool isVector,
bool hasStatus,
std::ifstream &stream ) const;

void readFaceTimestep( const Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
Duration t,
RelativeTimestamp t,
bool isVector,
std::ifstream &stream ) const;

Expand Down
8 changes: 4 additions & 4 deletions mdal/frmts/mdal_binary_dat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void MDAL::DriverBinaryDat::load( const std::string &datFile, MDAL::Mesh *mesh,
return exit_with_error( status, MDAL_Status::Err_UnknownFormat, "Invalid time step" );

double rawTime = static_cast<double>( time );
MDAL::Duration t( rawTime, MDAL::parseDurationTimeUnit( timeUnitStr ) );
MDAL::RelativeTimestamp t( rawTime, MDAL::parseDurationTimeUnit( timeUnitStr ) );

if ( readVertexTimestep( mesh, group, groupMax, t, istat, sflg, in ) )
return exit_with_error( status, MDAL_Status::Err_UnknownFormat, "Unable to read vertex timestep" );
Expand All @@ -315,7 +315,7 @@ bool MDAL::DriverBinaryDat::readVertexTimestep(
const MDAL::Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
std::shared_ptr<DatasetGroup> groupMax,
MDAL::Duration time,
MDAL::RelativeTimestamp time,
bool hasStatus,
int sflg,
std::ifstream &in )
Expand Down Expand Up @@ -364,7 +364,7 @@ bool MDAL::DriverBinaryDat::readVertexTimestep(
}
}

if ( MDAL::equals( time.value( MDAL::Duration::hours ), 99999.0 ) ) // Special TUFLOW dataset with maximus
if ( MDAL::equals( time.value( MDAL::RelativeTimestamp::hours ), 99999.0 ) ) // Special TUFLOW dataset with maximus
{
dataset->setTime( time );
dataset->setStatistics( MDAL::calculateStatistics( dataset ) );
Expand Down Expand Up @@ -458,7 +458,7 @@ bool MDAL::DriverBinaryDat::persist( MDAL::DatasetGroup *group )

writeRawData( out, reinterpret_cast< const char * >( &CT_TS ), 4 );
writeRawData( out, reinterpret_cast< const char * >( &istat ), 1 );
float ftime = static_cast<float>( dataset->time( Duration::hours ) );
float ftime = static_cast<float>( dataset->time( RelativeTimestamp::hours ) );
writeRawData( out, reinterpret_cast< const char * >( &ftime ), 4 );

if ( istat )
Expand Down
2 changes: 1 addition & 1 deletion mdal/frmts/mdal_binary_dat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace MDAL
bool readVertexTimestep( const Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
std::shared_ptr<DatasetGroup> groupMax,
Duration time,
RelativeTimestamp time,
bool hasStatus,
int sflg,
std::ifstream &in );
Expand Down
14 changes: 7 additions & 7 deletions mdal/frmts/mdal_cf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static void populate_vals( bool is_vector, double *vals, size_t i,
}
}

void MDAL::DriverCF::addDatasetGroups( MDAL::Mesh *mesh, const std::vector<Duration> &times, const MDAL::cfdataset_info_map &dsinfo_map, const MDAL::DateTime &referenceTime )
void MDAL::DriverCF::addDatasetGroups( MDAL::Mesh *mesh, const std::vector<RelativeTimestamp> &times, const MDAL::cfdataset_info_map &dsinfo_map, const MDAL::DateTime &referenceTime )
{
/* PHASE 2 - add dataset groups */
for ( const auto &it : dsinfo_map )
Expand Down Expand Up @@ -237,15 +237,15 @@ void MDAL::DriverCF::addDatasetGroups( MDAL::Mesh *mesh, const std::vector<Durat
}
}

MDAL::DateTime MDAL::DriverCF::parseTime( std::vector<Duration> &times )
MDAL::DateTime MDAL::DriverCF::parseTime( std::vector<RelativeTimestamp> &times )
{

size_t nTimesteps = mDimensions.size( CFDimensions::Time );
if ( 0 == nTimesteps )
{
//if no time dimension is present creates only one time step to store the potential time-independent variable
nTimesteps = 1;
times = std::vector<Duration>( 1, Duration() );
times = std::vector<RelativeTimestamp>( 1, RelativeTimestamp() );
return MDAL::DateTime();
}
const std::string timeArrName = getTimeVariableName();
Expand All @@ -254,12 +254,12 @@ MDAL::DateTime MDAL::DriverCF::parseTime( std::vector<Duration> &times )
std::string timeUnitInformation = mNcFile->getAttrStr( timeArrName, "units" );
std::string calendar = mNcFile->getAttrStr( timeArrName, "calendar" );
MDAL::DateTime referenceTime = parseCFReferenceTime( timeUnitInformation, calendar );
MDAL::Duration::Unit unit = parseCFTimeUnit( timeUnitInformation );
MDAL::RelativeTimestamp::Unit unit = parseCFTimeUnit( timeUnitInformation );

times = std::vector<Duration>( nTimesteps );
times = std::vector<RelativeTimestamp>( nTimesteps );
for ( size_t i = 0; i < nTimesteps; ++i )
{
times[i] = Duration( rawTimes[i], unit );
times[i] = RelativeTimestamp( rawTimes[i], unit );
}

return referenceTime;
Expand Down Expand Up @@ -378,7 +378,7 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverCF::load( const std::string &fileName,
if ( status ) *status = MDAL_Status::None;

//Dimensions dims;
std::vector<MDAL::Duration> times;
std::vector<MDAL::RelativeTimestamp> times;

try
{
Expand Down
4 changes: 2 additions & 2 deletions mdal/frmts/mdal_cf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ namespace MDAL

void setProjection( MDAL::Mesh *m );
cfdataset_info_map parseDatasetGroupInfo();
DateTime parseTime( std::vector<Duration> &times ); //Return the reference time
DateTime parseTime( std::vector<RelativeTimestamp> &times ); //Return the reference time
void addDatasetGroups( Mesh *mesh,
const std::vector<Duration> &times,
const std::vector<RelativeTimestamp> &times,
const cfdataset_info_map &dsinfo_map, const DateTime &referenceTime );

std::string mFileName;
Expand Down
2 changes: 1 addition & 1 deletion mdal/frmts/mdal_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void MDAL::Driver::createDatasetGroup( MDAL::Mesh *mesh, const std::string &grou
mesh->datasetGroups.push_back( grp );
}

void MDAL::Driver::createDataset( MDAL::DatasetGroup *group, MDAL::Duration time, const double *values, const int *active )
void MDAL::Driver::createDataset( MDAL::DatasetGroup *group, MDAL::RelativeTimestamp time, const double *values, const int *active )
{
bool supportsActiveFlag = ( active != nullptr );
std::shared_ptr<MDAL::MemoryDataset2D> dataset = std::make_shared< MemoryDataset2D >( group, supportsActiveFlag );
Expand Down
2 changes: 1 addition & 1 deletion mdal/frmts/mdal_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace MDAL

// create new dataset from array
virtual void createDataset( DatasetGroup *group,
Duration time,
RelativeTimestamp time,
const double *values,
const int *active );

Expand Down
8 changes: 4 additions & 4 deletions mdal/frmts/mdal_flo2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void MDAL::DriverFlo2D::addStaticDataset(

std::shared_ptr<MDAL::MemoryDataset2D> dataset = std::make_shared< MemoryDataset2D >( group.get() );
assert( vals.size() == dataset->valuesCount() );
dataset->setTime( MDAL::Duration() );
dataset->setTime( MDAL::RelativeTimestamp() );
double *values = dataset->values();
memcpy( values, vals.data(), vals.size() * sizeof( double ) );
dataset->setStatistics( MDAL::calculateStatistics( dataset ) );
Expand Down Expand Up @@ -187,7 +187,7 @@ void MDAL::DriverFlo2D::parseTIMDEPFile( const std::string &datFileName, const s
size_t nVertexs = mMesh->verticesCount();
size_t ntimes = 0;

Duration time = Duration();
RelativeTimestamp time = RelativeTimestamp();
size_t face_idx = 0;

std::shared_ptr<DatasetGroup> depthDsGroup = std::make_shared< DatasetGroup >(
Expand Down Expand Up @@ -228,7 +228,7 @@ void MDAL::DriverFlo2D::parseTIMDEPFile( const std::string &datFileName, const s
std::vector<std::string> lineParts = MDAL::split( line, ' ' );
if ( lineParts.size() == 1 )
{
time = Duration( MDAL::toDouble( line ), Duration::hours );
time = RelativeTimestamp( MDAL::toDouble( line ), RelativeTimestamp::hours );
ntimes++;

if ( depthDataset ) addDatasetToGroup( depthDsGroup, depthDataset );
Expand Down Expand Up @@ -822,7 +822,7 @@ bool MDAL::DriverFlo2D::appendGroup( HdfFile &file, MDAL::DatasetGroup *dsGroup,
const Statistics st = dataset->statistics();
maximums[i] = static_cast<float>( st.maximum );
minimums[i] = static_cast<float>( st.minimum );
times.push_back( dataset->time( Duration::hours ) );
times.push_back( dataset->time( RelativeTimestamp::hours ) );
}

// store data
Expand Down
2 changes: 1 addition & 1 deletion mdal/frmts/mdal_gdal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void MDAL::DriverGdal::parseRasterBands( const MDAL::GdalDataset *cfGDALDataset
metadata_hash metadata = parseMetadata( gdalBand );

std::string band_name;
MDAL::Duration time;
MDAL::RelativeTimestamp time;
bool is_vector;
bool is_x;
if ( parseBandInfo( cfGDALDataset, metadata, band_name, &time, &is_vector, &is_x ) )
Expand Down
4 changes: 2 additions & 2 deletions mdal/frmts/mdal_gdal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ namespace MDAL

/* return true on failure */
virtual bool parseBandInfo( const GdalDataset *cfGDALDataset,
const metadata_hash &metadata, std::string &band_name, MDAL::Duration *time, bool *is_vector, bool *is_x ) = 0;
const metadata_hash &metadata, std::string &band_name, MDAL::RelativeTimestamp *time, bool *is_vector, bool *is_x ) = 0;
virtual double parseMetadataTime( const std::string &time_s );
virtual std::string GDALFileName( const std::string &fileName ); /* some formats require e.g. adding driver name at the beginning */
virtual std::vector<std::string> parseDatasetNames( const std::string &fileName );
virtual void parseGlobals( const metadata_hash &metadata ) {MDAL_UNUSED( metadata );}
virtual void parseBandIsVector( std::string &band_name, bool *is_vector, bool *is_x );

private:
typedef std::map<MDAL::Duration, std::vector<GDALRasterBandH> > timestep_map; //TIME (sorted), [X, Y]
typedef std::map<MDAL::RelativeTimestamp, std::vector<GDALRasterBandH> > timestep_map; //TIME (sorted), [X, Y]
typedef std::map<std::string, timestep_map > data_hash; //Data Type, TIME (sorted), [X, Y]
typedef std::vector<std::shared_ptr<GdalDataset>> gdal_datasets_vector; //GDAL (Sub)Datasets,

Expand Down
2 changes: 1 addition & 1 deletion mdal/frmts/mdal_gdal_grib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ MDAL::DriverGdalGrib::~DriverGdalGrib() = default;

bool MDAL::DriverGdalGrib::parseBandInfo( const MDAL::GdalDataset *cfGDALDataset,
const metadata_hash &metadata, std::string &band_name,
MDAL::Duration *time, bool *is_vector, bool *is_x
MDAL::RelativeTimestamp *time, bool *is_vector, bool *is_x
)
{
MDAL_UNUSED( cfGDALDataset );
Expand Down
2 changes: 1 addition & 1 deletion mdal/frmts/mdal_gdal_grib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace MDAL
private:
bool parseBandInfo( const MDAL::GdalDataset *cfGDALDataset,
const metadata_hash &metadata, std::string &band_name,
Duration *time, bool *is_vector, bool *is_x
RelativeTimestamp *time, bool *is_vector, bool *is_x
) override;

MDAL::DateTime referenceTime() const override;
Expand Down
4 changes: 2 additions & 2 deletions mdal/frmts/mdal_gdal_netcdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ std::string MDAL::DriverGdalNetCDF::GDALFileName( const std::string &fileName )
#endif
}

bool MDAL::DriverGdalNetCDF::parseBandInfo( const MDAL::GdalDataset *cfGDALDataset, const MDAL::DriverGdal::metadata_hash &metadata, std::string &band_name, Duration *time, bool *is_vector, bool *is_x )
bool MDAL::DriverGdalNetCDF::parseBandInfo( const MDAL::GdalDataset *cfGDALDataset, const MDAL::DriverGdal::metadata_hash &metadata, std::string &band_name, RelativeTimestamp *time, bool *is_vector, bool *is_x )
{
MDAL_UNUSED( cfGDALDataset );

metadata_hash::const_iterator iter;

iter = metadata.find( "netcdf_dim_time" );
if ( iter == metadata.end() ) return true; //FAILURE, skip no-time bands
*time = MDAL::Duration( parseMetadataTime( iter->second ), mTimeUnit );
*time = MDAL::RelativeTimestamp( parseMetadataTime( iter->second ), mTimeUnit );

// NAME
iter = metadata.find( "long_name" );
Expand Down
4 changes: 2 additions & 2 deletions mdal/frmts/mdal_gdal_netcdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ namespace MDAL
std::string GDALFileName( const std::string &fileName ) override;
bool parseBandInfo( const MDAL::GdalDataset *cfGDALDataset,
const metadata_hash &metadata, std::string &band_name,
MDAL::Duration *time, bool *is_vector, bool *is_x
MDAL::RelativeTimestamp *time, bool *is_vector, bool *is_x
) override;
void parseGlobals( const metadata_hash &metadata ) override;

MDAL::DateTime referenceTime() const override;

Duration::Unit mTimeUnit;
RelativeTimestamp::Unit mTimeUnit;
//! Take the first reference time parsed
DateTime mRefTime;
};
Expand Down
21 changes: 10 additions & 11 deletions mdal/frmts/mdal_hec2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ static std::string getDataTimeUnit( HdfDataset &dsTime )
return dataTimeUnit;
}

static std::vector<MDAL::Duration> convertTimeData( std::vector<float> &times, const std::string &originalTimeDataUnit )
static std::vector<MDAL::RelativeTimestamp> convertTimeData( std::vector<float> &times, const std::string &originalTimeDataUnit )
{
std::vector<MDAL::Duration> convertedTime( times.size() );
std::vector<MDAL::RelativeTimestamp> convertedTime( times.size() );

MDAL::Duration::Unit unit = MDAL::parseDurationTimeUnit( originalTimeDataUnit );
MDAL::RelativeTimestamp::Unit unit = MDAL::parseDurationTimeUnit( originalTimeDataUnit );

for ( size_t i = 0; i < times.size(); i++ )
{
convertedTime[i] = MDAL::Duration( double( times[i] ), unit );
convertedTime[i] = MDAL::RelativeTimestamp( double( times[i] ), unit );
}
return convertedTime;
}
Expand All @@ -133,7 +133,6 @@ static MDAL::DateTime convertToDateTime( const std::string strDateTime )
std::string monthStr = dateStr.substr( 2, 3 );
year = MDAL::toInt( dateStr.substr( 5, 4 ) );

///TODO : verify if month name are always in English language
if ( monthStr == "JAN" )
month = 1;
else if ( monthStr == "FEB" )
Expand Down Expand Up @@ -192,7 +191,7 @@ static MDAL::DateTime readReferenceDateTime( const HdfFile &hdfFile )
return MDAL::DateTime();
}

static std::vector<MDAL::Duration> readTimes( const HdfFile &hdfFile )
static std::vector<MDAL::RelativeTimestamp> readTimes( const HdfFile &hdfFile )
{
HdfGroup gBaseO = getBaseOutputGroup( hdfFile );
HdfGroup gUnsteadTS = openHdfGroup( gBaseO, "Unsteady Time Series" );
Expand Down Expand Up @@ -223,7 +222,7 @@ void MDAL::DriverHec2D::readFaceOutput( const HdfFile &hdfFile,
const std::vector<std::string> &flowAreaNames,
const std::string rawDatasetName,
const std::string datasetName,
const std::vector<Duration> &times,
const std::vector<RelativeTimestamp> &times,
const DateTime &referenceTime )
{
double eps = std::numeric_limits<double>::min();
Expand Down Expand Up @@ -307,7 +306,7 @@ void MDAL::DriverHec2D::readFaceResults( const HdfFile &hdfFile,

// SUMMARY
flowGroup = get2DFlowAreasGroup( hdfFile, "Summary Output" );
std::vector<MDAL::Duration> dummyTimes( 1, MDAL::Duration() );
std::vector<MDAL::RelativeTimestamp> dummyTimes( 1, MDAL::RelativeTimestamp() );

readFaceOutput( hdfFile, flowGroup, areaElemStartIndex, flowAreaNames, "Maximum Face Shear Stress", "Face Shear Stress/Maximums", dummyTimes, referenceDateTime );
readFaceOutput( hdfFile, flowGroup, areaElemStartIndex, flowAreaNames, "Maximum Face Velocity", "Face Velocity/Maximums", dummyTimes, referenceDateTime );
Expand All @@ -319,7 +318,7 @@ std::shared_ptr<MDAL::MemoryDataset2D> MDAL::DriverHec2D::readElemOutput( const
const std::vector<std::string> &flowAreaNames,
const std::string rawDatasetName,
const std::string datasetName,
const std::vector<Duration> &times,
const std::vector<RelativeTimestamp> &times,
std::shared_ptr<MDAL::MemoryDataset2D> bed_elevation,
const DateTime &referenceTime )
{
Expand Down Expand Up @@ -410,7 +409,7 @@ std::shared_ptr<MDAL::MemoryDataset2D> MDAL::DriverHec2D::readBedElevation(
const std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames )
{
std::vector<MDAL::Duration> times( 1 );
std::vector<MDAL::RelativeTimestamp> times( 1 );
DateTime referenceTime;

return readElemOutput(
Expand Down Expand Up @@ -456,7 +455,7 @@ void MDAL::DriverHec2D::readElemResults(
// SUMMARY
flowGroup = get2DFlowAreasGroup( hdfFile, "Summary Output" );

std::vector<Duration> dummyTimes( 1, MDAL::Duration() );
std::vector<RelativeTimestamp> dummyTimes( 1, MDAL::RelativeTimestamp() );

readElemOutput(
flowGroup,
Expand Down
Loading

0 comments on commit 33e8ecb

Please sign in to comment.