Skip to content

Commit

Permalink
fix #196 support timeunits for old ASCII dat format
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Jan 9, 2020
1 parent 65c45b4 commit 77abcfe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
11 changes: 8 additions & 3 deletions mdal/frmts/mdal_ascii_dat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ bool MDAL::DriverAsciiDat::canReadOldFormat( const std::string &line ) const
{
return MDAL::contains( line, "SCALAR" ) ||
MDAL::contains( line, "VECTOR" ) ||
MDAL::contains( line, "TS" );
MDAL::contains( line, "TS" ) ||
MDAL::contains( line, "TIMEUNITS" );
}

bool MDAL::DriverAsciiDat::canReadNewFormat( const std::string &line ) const
Expand Down Expand Up @@ -85,7 +86,7 @@ void MDAL::DriverAsciiDat::loadOldFormat( std::ifstream &in,
);
group->setIsScalar( !isVector );
group->setDataLocation( MDAL_DataLocation::DataOnVertices2D );

MDAL::RelativeTimestamp::Unit timeUnits = MDAL::RelativeTimestamp::hours;
do
{
// Replace tabs by spaces,
Expand Down Expand Up @@ -114,10 +115,14 @@ void MDAL::DriverAsciiDat::loadOldFormat( std::ifstream &in,
{
// just ignore - we know the type from earlier...
}
else if ( cardType == "TIMEUNITS" && items.size() >= 2 )
{
timeUnits = MDAL::parseDurationTimeUnit( items[1] );
}
else if ( cardType == "TS" && items.size() >= 2 )
{
double rawTime = toDouble( items[ 1 ] );
MDAL::RelativeTimestamp t( rawTime, MDAL::RelativeTimestamp::hours );
MDAL::RelativeTimestamp t( rawTime, timeUnits );
readVertexTimestep( mesh, group, t, isVector, false, in );
}
else
Expand Down
15 changes: 15 additions & 0 deletions tests/data/ascii_dat/quad_and_triangle_vertex_scalar_old3.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SCALAR
TIMEUNITS Seconds
ND 5
TS 0
1
2
3
4
5
TS 3600
6
7
8
9
10
15 changes: 14 additions & 1 deletion tests/test_ascii_dat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ TEST( MeshAsciiDatTest, QuadAndTriangleVertexScalarFile )

TEST( MeshAsciiDatTest, QuadAndTriangleVertexScalarOldFile )
{
for ( int i = 0; i < 3; ++i )
for ( int i = 0; i < 4; ++i )
{
std::string name = "quad_and_triangle_vertex_scalar_old" + std::to_string( i );
MeshH m = mesh();
Expand Down Expand Up @@ -361,6 +361,19 @@ TEST( MeshAsciiDatTest, QuadAndTriangleVertexScalarOldFile )
value = getValue( ds, 1 );
EXPECT_DOUBLE_EQ( 2, value );

ds = MDAL_G_dataset( g, 1 );
double time = MDAL_D_time( ds );
if ( i == 3 )
{
// With timeunits
EXPECT_DOUBLE_EQ( time, 1.0 );
}
else
{
// default timeunits
EXPECT_DOUBLE_EQ( time, 3600.0 );
}

MDAL_CloseMesh( m );
}
}
Expand Down

0 comments on commit 77abcfe

Please sign in to comment.