From bb24bf2745c432cb9d6cc143492405111d624884 Mon Sep 17 00:00:00 2001
From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de>
Date: Tue, 14 Jan 2025 21:02:23 +0100
Subject: [PATCH] Changed type of record_t::ltype to short

---
 src/cdi_int.h        |  4 ++--
 src/stream_cgribex.c | 12 ++++++------
 src/stream_grb.c     |  4 +---
 src/stream_gribapi.c | 20 ++++++++++----------
 src/stream_ieg.c     |  2 +-
 5 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/src/cdi_int.h b/src/cdi_int.h
index c06e34979..d8f73f5b1 100644
--- a/src/cdi_int.h
+++ b/src/cdi_int.h
@@ -180,11 +180,11 @@ typedef struct
   int param;
   int ilevel;
   int ilevel2;
-  int ltype;
+  short ltype;
   short tsteptype;
   short varID;
-  int levelID;
   short used;
+  int levelID;
   char varname[32];  // needed for grib decoding with GRIB_API
   VarScanKeys scanKeys;
   var_tile_t tiles;  // tile-related meta-data, currently for GRIB-API only.
diff --git a/src/stream_cgribex.c b/src/stream_cgribex.c
index a2c73b7f0..ec012fbb9 100644
--- a/src/stream_cgribex.c
+++ b/src/stream_cgribex.c
@@ -32,12 +32,12 @@ typedef struct
 
 typedef struct
 {
+  size_t gridsize;
   int param;
   int level1;
   int level2;
-  int ltype;
-  int tsteptype;
-  size_t gridsize;
+  short ltype;
+  short tsteptype;
 } compvar_t;
 
 typedef struct
@@ -562,7 +562,7 @@ cgribexAddRecord(stream_t *streamptr, cgribexrec_t *cgribexp, int param, size_t
   record->param = param;
   record->ilevel = level1;
   record->ilevel2 = level2;
-  record->ltype = leveltype;
+  record->ltype = (short) leveltype;
   record->tsteptype = (short) tsteptype;
   record->gridsize = cgribexGetGridsize(cgribexp->sec4);
 
@@ -717,8 +717,8 @@ cgribexVarSet(int param, int level1, int level2, int leveltype, int trange, size
   compVar.param = param;
   compVar.level1 = level1;
   compVar.level2 = level2;
-  compVar.ltype = leveltype;
-  compVar.tsteptype = tsteptype;
+  compVar.ltype = (short) leveltype;
+  compVar.tsteptype = (short) tsteptype;
   compVar.gridsize = gridsize;
 
   return compVar;
diff --git a/src/stream_grb.c b/src/stream_grb.c
index 9441a53e3..7e3e70891 100644
--- a/src/stream_grb.c
+++ b/src/stream_grb.c
@@ -407,9 +407,7 @@ streamInqGRIBinfo(int streamID, int *intnum, float *fltnum, off_t *bignum)
 {
   stream_t *streamptr = stream_to_pointer(streamID);
 
-  int filetype = streamptr->filetype;
-
-  if (filetype == CDI_FILETYPE_GRB)
+  if (streamptr->filetype == CDI_FILETYPE_GRB)
     {
       int tsID = streamptr->curTsID;
       int vrecID = streamptr->tsteps[tsID].curRecID;
diff --git a/src/stream_gribapi.c b/src/stream_gribapi.c
index 30c14eba1..7d895bb91 100644
--- a/src/stream_gribapi.c
+++ b/src/stream_gribapi.c
@@ -28,12 +28,12 @@ static const var_tile_t dummy_tiles = { 0, -1, -1, -1, -1, -1 };
 
 typedef struct
 {
+  size_t gridsize;
   int param;
   int level1;
   int level2;
-  int ltype;
-  int tsteptype;
-  size_t gridsize;
+  short ltype;
+  short tsteptype;
   char name[32];
   VarScanKeys scanKeys;
   var_tile_t tiles;
@@ -721,7 +721,7 @@ gribapiAddRecord(stream_t *streamptr, int param, grib_handle *gh, size_t recsize
   record->param = param;
   record->ilevel = level1;
   record->ilevel2 = level2;
-  record->ltype = leveltype1;
+  record->ltype = (short) leveltype1;
   record->tsteptype = (short) tsteptype;
   record->gridsize = gribapiGetGridsize(gh);
   record->scanKeys = *scanKeys;
@@ -910,8 +910,8 @@ gribapiVarCompare(const compvar2_t *compVar, const record_t *record, int flag)
   compVar0.param = record->param;
   compVar0.level1 = record->ilevel;
   compVar0.level2 = record->ilevel2;
-  compVar0.ltype = record->ltype;
-  compVar0.tsteptype = record->tsteptype;
+  compVar0.ltype = (short) record->ltype;
+  compVar0.tsteptype = (short) record->tsteptype;
   compVar0.gridsize = record->gridsize;
   memcpy(compVar0.name, record->varname, sizeof(compVar->name));
 
@@ -2749,7 +2749,7 @@ gribapiDefLevel(int editionNumber, grib_handle *gh, int zaxisID, int levelID, in
   }
   long grib_ltype2 = (ltype != ltype2 && ltype2 != -1) ? ltype2 : grib_ltype;
 
-  void (*defLevel)(grib_handle * gh, int gcinit, long leveltype1, long leveltype2, bool hasBounds, double level, double dlevel1,
+  void (*defLevel)(grib_handle *gh, int gcinit, long leveltype1, long leveltype2, bool hasBounds, double level, double dlevel1,
                    double dlevel2)
       = (editionNumber <= 1) ? grib1DefLevel : grib2DefLevel;
 
@@ -3176,7 +3176,7 @@ convertDataScanningMode(int scanModeIN, int scanModeOUT, double *data, size_t gr
               // printf(".\n");
             }
         }  // end if (scanModeOUT==96)
-    }      // end if (scanModeIN==64)
+    }  // end if (scanModeIN==64)
 
   if (scanModeIN
       == 00)  // Scanning Mode (00 dec)  +i, -j; i direction consecutive (row-major    order West->East   & South->North )
@@ -3206,7 +3206,7 @@ convertDataScanningMode(int scanModeIN, int scanModeOUT, double *data, size_t gr
               for (size_t i = 0; i < iDim; i++) data[j + i * jDim] = dataCopy[i + jInv * iDim];  // source data has -j
             }
         }  // end if (scanModeOUT==96)
-    }      // end if (scanModeIN==00)
+    }  // end if (scanModeIN==00)
 
   if (scanModeIN
       == 96)  // Scanning Mode (00 dec)  +i, -j; i direction consecutive (row-major    order West->East   & South->North )
@@ -3239,7 +3239,7 @@ convertDataScanningMode(int scanModeIN, int scanModeOUT, double *data, size_t gr
                 data[i + jXiDim] = dataCopy[jInv + i * jDim];  // target data has -j
             }
         }  // end if (scanModeOUT==00)
-    }      // end if (scanModeIN==96)
+    }  // end if (scanModeIN==96)
 
   if (cdiDebugExt >= 100)
     {
diff --git a/src/stream_ieg.c b/src/stream_ieg.c
index 4194ed037..072544bfb 100644
--- a/src/stream_ieg.c
+++ b/src/stream_ieg.c
@@ -541,7 +541,7 @@ iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vct, si
   record->param = param;
   record->ilevel = level1;
   record->ilevel2 = level2;
-  record->ltype = IEG_P_LevelType(pdb);
+  record->ltype = (short) IEG_P_LevelType(pdb);
 
   int gridtype = (IEG_G_GridType(gdb) == 0)    ? GRID_LONLAT
                  : (IEG_G_GridType(gdb) == 10) ? GRID_PROJECTION
-- 
GitLab