From c252689830da65b3298d0b3d95da4c58c1e2df77 Mon Sep 17 00:00:00 2001
From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de>
Date: Thu, 23 Oct 2014 08:52:59 +0000
Subject: [PATCH] cgribexVarCompare: exclude TimeRangeIndicator 0 and 10

---
 src/stream_cgribex.c | 18 ++++++++++++------
 src/stream_gribapi.c | 18 ++++++++++++------
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/src/stream_cgribex.c b/src/stream_cgribex.c
index 40293649b..32901b0c2 100644
--- a/src/stream_cgribex.c
+++ b/src/stream_cgribex.c
@@ -531,7 +531,7 @@ compvar_t cgribexVarSet(int param, int level1, int level2, int leveltype, int tr
 }
 
 static
-int cgribexVarCompare(compvar_t compVar, record_t record)
+int cgribexVarCompare(compvar_t compVar, record_t record, int flag)
 {
   compvar_t compVar0;
 
@@ -541,6 +541,12 @@ int cgribexVarCompare(compvar_t compVar, record_t record)
   compVar0.ltype     = record.ltype;
   compVar0.tsteptype = record.tsteptype;
 
+  if ( flag == 0 )
+    {
+      if ( compVar0.tsteptype == TSTEP_INSTANT  && compVar.tsteptype == TSTEP_INSTANT3 ) compVar0.tsteptype = TSTEP_INSTANT3;
+      if ( compVar0.tsteptype == TSTEP_INSTANT3 && compVar.tsteptype == TSTEP_INSTANT  ) compVar0.tsteptype = TSTEP_INSTANT;
+    }
+
   int rstatus = memcmp(&compVar0, &compVar, sizeof(compvar_t));
 
   return (rstatus);
@@ -683,7 +689,7 @@ int cgribexScanTimestep1(stream_t * streamptr)
 
 	  for ( recID = 0; recID < nrecs; recID++ )
 	    {
-	      if ( cgribexVarCompare(compVar, streamptr->tsteps[0].records[recID]) == 0 ) break;
+	      if ( cgribexVarCompare(compVar, streamptr->tsteps[0].records[recID], 1) == 0 ) break;
 	    }
 
 	  if ( cdiInventoryMode == 1 )
@@ -962,7 +968,7 @@ int cgribexScanTimestep2(stream_t * streamptr)
 
       for ( recID = 0; recID < nrecords; recID++ )
 	{
-	  if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) == 0 ) break;
+	  if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) == 0 ) break;
 	}
 
       if ( recID == nrecords )
@@ -1004,7 +1010,7 @@ int cgribexScanTimestep2(stream_t * streamptr)
 
       streamptr->tsteps[tsID].records[recID].size = (size_t)recsize;
 
-      if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) != 0 )
+      if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) != 0 )
 	{
 	  Message("tsID = %d recID = %d param = %3d new %3d  level = %3d new %3d",
 		  tsID, recID,
@@ -1232,7 +1238,7 @@ int cgribexScanTimestep(stream_t * streamptr)
 	  for ( vrecID = 0; vrecID < nrecs; vrecID++ )
 	    {
 	      recID   = streamptr->tsteps[1].recIDs[vrecID];
-	      if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) == 0 ) break;
+	      if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) == 0 ) break;
 	    }
 
 	  if ( vrecID == nrecs )
@@ -1274,7 +1280,7 @@ int cgribexScanTimestep(stream_t * streamptr)
 	  if ( CDI_Debug )
             Message("Read record %2d (id=%s lev1=%d lev2=%d) %8d %6d", nrecs_scanned, paramstr, level1, level2, vdate, vtime);
 
-	  if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) != 0 )
+	  if ( cgribexVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) != 0 )
 	    {
 	      Message("tsID = %d recID = %d param = %3d new %3d  level = %3d new %3d",
 		      tsID, recID,
diff --git a/src/stream_gribapi.c b/src/stream_gribapi.c
index b5ae7ec3e..2cb1ea2ae 100644
--- a/src/stream_gribapi.c
+++ b/src/stream_gribapi.c
@@ -1117,7 +1117,7 @@ compvar2_t gribapiVarSet(int param, int level1, int level2, int leveltype, int t
 }
 
 static
-int gribapiVarCompare(compvar2_t compVar, record_t record)
+int gribapiVarCompare(compvar2_t compVar, record_t record, int flag)
 {
   compvar2_t compVar0;
   size_t maxlen = sizeof(compVar.name);
@@ -1129,6 +1129,12 @@ int gribapiVarCompare(compvar2_t compVar, record_t record)
   compVar0.tsteptype = record.tsteptype;
   memcpy(compVar0.name, record.varname, maxlen);
 
+  if ( flag == 0 )
+    {
+      if ( compVar0.tsteptype == TSTEP_INSTANT  && compVar.tsteptype == TSTEP_INSTANT3 ) compVar0.tsteptype = TSTEP_INSTANT3;
+      if ( compVar0.tsteptype == TSTEP_INSTANT3 && compVar.tsteptype == TSTEP_INSTANT  ) compVar0.tsteptype = TSTEP_INSTANT;
+    }
+
   int rstatus = memcmp(&compVar0, &compVar, sizeof(compvar2_t));
 
   return (rstatus);
@@ -1314,7 +1320,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
 	  compVar = gribapiVarSet(param, level1, level2, leveltype1, tsteptype, varname);
 
 	  for ( recID = 0; recID < nrecs; recID++ )
-            if ( gribapiVarCompare(compVar, streamptr->tsteps[0].records[recID]) == 0 ) break;
+            if ( gribapiVarCompare(compVar, streamptr->tsteps[0].records[recID], 1) == 0 ) break;
 
 	  if ( cdiInventoryMode == 1 )
 	    {
@@ -1626,7 +1632,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
       compVar = gribapiVarSet(param, level1, level2, leveltype1, tsteptype, varname);
 
       for ( recID = 0; recID < nrecords; recID++ )
-        if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) == 0 ) break;
+        if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) == 0 ) break;
 
       if ( recID == nrecords )
 	{
@@ -1655,7 +1661,7 @@ int gribapiScanTimestep2(stream_t * streamptr)
 
       streamptr->tsteps[tsID].records[recID].size = recsize;
 
-      if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) != 0 )
+      if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) != 0 )
 	{
 	  Message("tsID = %d recID = %d param = %3d new %3d  level = %3d new %3d",
 		  tsID, recID,
@@ -1906,7 +1912,7 @@ int gribapiScanTimestep(stream_t * streamptr)
 	  for ( vrecID = 0; vrecID < nrecs; vrecID++ )
 	    {
 	      recID   = streamptr->tsteps[1].recIDs[vrecID];
-	      if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) == 0 ) break;
+	      if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) == 0 ) break;
 	    }
 
 	  if ( vrecID == nrecs )
@@ -1938,7 +1944,7 @@ int gribapiScanTimestep(stream_t * streamptr)
 	  if ( CDI_Debug )
 	    Message("%4d %8d %4d %8d %8d %6d", rindex+1, (int)recpos, param, level1, vdate, vtime);
 
-	  if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID]) != 0 )
+	  if ( gribapiVarCompare(compVar, streamptr->tsteps[tsID].records[recID], 0) != 0 )
 	    {
 	      Message("tsID = %d recID = %d param = %3d new %3d  level = %3d new %3d",
 		      tsID, recID,
-- 
GitLab