Skip to content

Commit 737c0d5

Browse files
committed
Lots of streamlining of error-trapping.
Continuing development. Framework is incomplete. IN 2017/06/20
1 parent 497889b commit 737c0d5

2 files changed

Lines changed: 99 additions & 35 deletions

File tree

‎intecplot.cpp‎

Lines changed: 97 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern "C" {
1212

1313

1414
enum inTecFile_Component {
15-
Unknown = 0,
15+
Unknown = -1,
1616

1717
Title = 11,
1818
Filetype = 12,
@@ -58,6 +58,7 @@ inTec_Zone::inTec_Zone( inTec_File* file_ )
5858
istate = 0;
5959
ipos = 0;
6060
ipos_data = 0;
61+
ipos_conn = 0;
6162

6263
// keyword-based variables
6364
tkey = NULL;
@@ -452,7 +453,7 @@ int inTec_Zone::ParseKeywords( char *buf )
452453
// provide some output
453454
if( iparse == 1 ) {
454455
printf(" (parsing now)");
455-
data[n+0] = '\0';//HACK HERE
456+
data[n+0] = '\0';//HACK
456457

457458
int iret = HandleKeyword( s );
458459
// allow for the possibility of dealiing with this differently...
@@ -660,7 +661,7 @@ int inTec_Zone::ManageInternals( void )
660661
#endif
661662
int ierror=0,iret;
662663

663-
//HERE
664+
//HERE0
664665
// processing individual keywords
665666
const char *string=NULL,*string2=NULL;
666667
size_t is;
@@ -699,15 +700,15 @@ int inTec_Zone::ManageInternals( void )
699700
if( iret != 0 ) ierror += 1;
700701
}
701702
if( strncasecmp( string, "F", 1 ) == 0 ) {
702-
// will deal with this later
703+
// will deal with this later...
703704
// iret = HandleKeyword_F( string2 );
704705
if( iret != 0 ) ierror += 1;
705706
}
706707
}
707708

708709
if( is == 2 ) {
709710
if( strncasecmp( string, "DT", 2 ) == 0 ) {
710-
// will do this later
711+
// will do this later...
711712
}
712713

713714
if( strncasecmp( string, "ET", 2 ) == 0 ) {
@@ -716,7 +717,7 @@ int inTec_Zone::ManageInternals( void )
716717
}
717718

718719
if( strncasecmp( string, "NV", 2 ) == 0 ) {
719-
// will do this later
720+
// will do this later...
720721
}
721722

722723
}
@@ -864,7 +865,6 @@ int inTec_Zone::HandleKeyword_Varlocation( const char *string )
864865
}
865866
}
866867

867-
//HERE2
868868
// the case where variables are individualluy separated
869869
int ierror=0;
870870
if( iret != 0 && is >= 15 ) { // the check may be different...
@@ -889,7 +889,7 @@ int inTec_Zone::HandleKeyword_Varlocation( const char *string )
889889
token = strtok_r( buf, delim, &sr );
890890
if( token == NULL ) {
891891
// this is in error
892-
printf("CANNOT HAVE NULL TOKEN HERE!!! FILL IN ERROR-TRAPPING.\n");
892+
printf(" e Malformed varlocation line!\n");
893893
ierror = 1;
894894
}
895895
#ifdef _DEBUG3_
@@ -1206,7 +1206,7 @@ int inTec_Zone::ConsistencyCheck (void )
12061206
#ifdef _DEBUG_
12071207
printf(" i Inside ConsistencyCheck() \n");
12081208
#endif
1209-
int iret=0;
1209+
int iret=0,ierror;
12101210

12111211
#ifdef _DEBUG_
12121212
// display all stored keywords as they were found after sanitized parsing
@@ -1216,25 +1216,30 @@ int inTec_Zone::ConsistencyCheck (void )
12161216
for( imap = keywords.begin(); imap != keywords.end(); ++imap ) {
12171217
printf(" %d ", i++ );
12181218
string = (*imap).first.c_str();
1219-
printf(" %s ", string );
1219+
printf(" %16s ", string );
12201220
string2 = (*imap).second.c_str();
1221-
printf(" \"%s\"\n", string2 );
1221+
printf("= \"%s\"\n", string2 );
12221222
}
12231223
#endif
12241224

1225+
//HERE1 (consistency checks not fully tested)
12251226
//
12261227
// first check for old-style variables
12271228
// (possibly set a variable indicating that OLD switches are present)
12281229
//
12291230
#ifdef _DEBUG_
1230-
printf("iold_n: %ld \n", iold_n);
1231-
printf("iold_e: %ld \n", iold_e);
1232-
printf("iold_et: %d \n", iold_et);
1231+
printf(" --- Old variables: \n");
1232+
printf(" iold_n: %ld \n", iold_n);
1233+
printf(" iold_e: %ld \n", iold_e);
1234+
printf(" iold_et: %d \n", iold_et);
12331235
#endif
1234-
/// give precedence of old switches... (incomplete)
1236+
/// give precedence to old switches... (incomplete)
12351237
if( iold_n > 0 ) nodes = iold_n;
12361238
if( iold_e > 0 ) elems = iold_e;
12371239
if( iold_et > -1 ) {
1240+
#ifdef _DEBUG_
1241+
printf(" --- Overriding ZONETYPE keyword; the ET keyword exists \n");
1242+
#endif
12381243
if( iold_et == FEBRICK ) {
12391244
ietype = FEBRICK;
12401245
}
@@ -1253,24 +1258,62 @@ int inTec_Zone::ConsistencyCheck (void )
12531258
//
12541259
// check for consistency in "sanitized" state
12551260
//
1261+
ierror = 0;
12561262
if( im > 0 && nodes > 0 ) {
12571263
printf(" e Specified both \"im/jm/km\" and \"nodes\" in zone \n");
1264+
ierror = 1;
12581265
iret += 1;
1266+
} else {
1267+
#ifdef _DEBUG_
1268+
printf(" --- Either I/J/K or N/NODES specified exclusively; good \n");
1269+
#endif
12591270
}
12601271

1261-
if( im > 0 && ietype != ORDERED ) {
1262-
printf(" e Conflicting specification of ZONETYPE and data provided\n");
1263-
iret += 1;
1272+
ierror = 0;
1273+
if( im > 0 ) {
1274+
if( ietype != ORDERED ) {
1275+
printf(" e Conflicting specification of ZONETYPE and data provided\n");
1276+
ierror = 1;
1277+
iret += 1;
1278+
} else {
1279+
#ifdef _DEBUG_
1280+
printf(" --- ZONETYPE is ORDERED and I is non-zero; good \n");
1281+
#endif
1282+
}
12641283
}
12651284

1285+
ierror = 0;
12661286
if( nodes > 0 && ietype == ORDERED ) {
12671287
printf(" e Number of nodes provided for an ordered zone \n");
1288+
ierror = 1;
12681289
iret += 1;
1290+
} else {
1291+
#ifdef _DEBUG_
1292+
printf(" --- ZONETYPE is not ORDERED while NODES is non-zero; good \n");
1293+
#endif
12691294
}
12701295

12711296

12721297
// loop over all variable locations and if there are cell-centered values
12731298
// the sanity check is that data cannot be point (only block)
1299+
ierror = 0;
1300+
std::map< int, int > :: iterator it;
1301+
for( it = ivar_loc.begin(); it != ivar_loc.end(); ++it ) {
1302+
if( (*it).second == 2 && idatapack != 2 ) ierror += 1;
1303+
}
1304+
if( ierror != 0 ) {
1305+
printf(" e VARLOCATION is cell-centered for %d variables...\n", ierror );
1306+
printf(" ...but DATAPACKING specified as POINT (must be BLOCK)\n");
1307+
iret += 1;
1308+
} else {
1309+
#ifdef _DEBUG_
1310+
printf(" --- VARLOCATION is compatible with DATAPACKING ");
1311+
if( idatapack == 1 ) printf("(POINT)\n");
1312+
if( idatapack == 2 ) printf("(BLOCK)\n");
1313+
#endif
1314+
}
1315+
1316+
12741317

12751318

12761319
#ifdef _DEBUG_
@@ -1282,10 +1325,10 @@ int inTec_Zone::ConsistencyCheck (void )
12821325

12831326

12841327

1285-
int inTec_Zone::ParseData( char *buf )
1328+
int inTec_Zone::ParseNumericData( char *buf )
12861329
{
12871330
#ifdef _DEBUG_
1288-
printf(" i Parsing zone data \n");
1331+
printf(" i Parsing numeric data \n");
12891332
#endif
12901333
#ifdef _DEBUG2_
12911334
printf(" STRING: --->|%s|<---\n", buf );
@@ -1375,10 +1418,15 @@ int inTec_File::OpenRead()
13751418
printf(" i Opening file object \"%s\" \n", name );
13761419
#endif
13771420

1421+
if( istate != 0 ) {
1422+
printf(" e File object is not in the right state (%d)\n", istate);
1423+
return(1);
1424+
}
1425+
13781426
fp = fopen( name, "r" );
13791427
if( fp == NULL ) {
13801428
printf(" e Could not open file \"%s\"\n", name );
1381-
return(1);
1429+
return(2);
13821430
}
13831431

13841432
istate = 1;
@@ -1392,9 +1440,14 @@ int inTec_File::Close()
13921440
#ifdef _DEBUG_
13931441
printf(" i Closing file object \"%s\" \n", name );
13941442
#endif
1443+
1444+
if( istate == 0 || istate == 1000 ) {
1445+
return(0);
1446+
}
1447+
13951448
fclose( fp );
13961449

1397-
istate = 0;
1450+
istate = 1000;
13981451
iline = 0;
13991452
ipos = 0;
14001453

@@ -1430,7 +1483,9 @@ int inTec_File::Parse()
14301483

14311484
int iret = ParseLoop();
14321485

1433-
1486+
if( iret != 0 ) {
1487+
return(2);
1488+
}
14341489

14351490
return(0);
14361491
}
@@ -1533,12 +1588,12 @@ int inTec_File::IdentifyComponent( char *buf )
15331588
{
15341589
#ifdef _DEBUG_
15351590
printf(" i Inside \"IdentifyComponent()\" \n");
1536-
#ifdef _DEBUG3_
1537-
printf("BUF: -->|%s", buf );
1538-
#endif
15391591
#endif
15401592

15411593
if( buf == NULL ) return(-1);
1594+
#ifdef _DEBUG3_
1595+
printf("BUF: -->|%s", buf );
1596+
#endif
15421597

15431598
size_t isize=0;
15441599
while( buf[isize] != '\n' && buf[isize] != '\0' ) ++isize;
@@ -1591,15 +1646,17 @@ int inTec_File::ParseComponent_Header( int iop, char *buf )
15911646
#endif
15921647

15931648
switch( iop ) {
1594-
case(1):
1649+
case(1): // title
15951650

1651+
printf(" i Parsing header \"title\" line \n");
15961652

15971653
break;
1598-
case(2):
1654+
case(2): // filetype
15991655

1656+
printf(" i Parsing header \"filetype\" line \n");
16001657

16011658
break;
1602-
case(3):
1659+
case(3): // variables
16031660

16041661
printf(" i Parsing header \"variables\" line \n");
16051662
return( ParseComponent_HeaderVariables( buf ) );
@@ -1704,7 +1761,11 @@ int inTec_File::ParseComponent_Zone()
17041761

17051762
// instantiate a zone object
17061763
inTec_Zone *zone = new inTec_Zone( this );
1707-
// check for allocation error... return(-1)
1764+
// check for allocation error
1765+
if( zone == NULL ) {
1766+
printf(" e Could not allocate zone! \n");
1767+
return(-1);
1768+
}
17081769

17091770
// set the position in the file for this zone
17101771
int iret = zone->SetPositionInFile( ipos );
@@ -1734,7 +1795,6 @@ int inTec_File::ParseComponent_Zone()
17341795
// N= NODES=
17351796
// E= ELEMENTS=
17361797

1737-
17381798
// The idea here is to keep ingesting in lines until we find a new component
17391799
// We ingest comments that can interrupt the geometry component
17401800
// Once a new component is detected, we wrap up the process
@@ -1758,6 +1818,10 @@ int inTec_File::ParseComponent_Zone()
17581818
// read a line of data; get count of bytes read
17591819
ic = inUtils_ReadTextline( &ibuf_size, &buf, fp );
17601820
// check error code
1821+
if( ic < 0 ) {
1822+
printf(" e There was an external library error (inUtils): %d\n", ic);
1823+
return(-2); // this error code may have to change
1824+
}
17611825

17621826
++iline;
17631827

@@ -1856,7 +1920,7 @@ printf("FOUND iret=%d idone_zone=%d \n", iret,idone_zone);//HACK
18561920
// (here we must put the zone in data-reading particular state)
18571921
if( zone->SetState_Reading() != 0 ) {
18581922
// respond to the possibility of the zone being mis-used...
1859-
1923+
return(5); // this error code may change
18601924
}
18611925

18621926
} else if( np < 0 ) {
@@ -1873,7 +1937,7 @@ printf("FOUND iret=%d idone_zone=%d \n", iret,idone_zone);//HACK
18731937
#endif
18741938
// push the buffer to the zone for data extraction
18751939
// (we must have set the zone to a data-reading state earlier)
1876-
iret = zone->ParseData( buf );
1940+
iret = zone->ParseNumericData( buf );
18771941
// possibly respond to errors returned by the zone...
18781942
if( iret < 0 ) {
18791943
printf(" e Error parsing zone data \n");

‎intecplot.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class inTec_Zone {
3333
int ParseKeywords( char *buf );
3434
int HandleKeyword( char *buf );
3535
int SetState_Reading( void );
36-
int ParseData( char *buf );
36+
int ParseNumericData( char *buf );
3737

3838
protected:
3939
void InitKeywords();
@@ -50,7 +50,7 @@ class inTec_Zone {
5050

5151
private:
5252
inTec_File *file;
53-
long ipos,ipos_data;
53+
long ipos,ipos_data,ipos_conn;
5454
std::map< std::string, std::string > keywords;
5555

5656
int CheckCharForNum( char c ) const;

0 commit comments

Comments
 (0)