From d0d8af406af78f2063f858b52d0bf6dc5c17f2c6 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Tue, 22 Sep 2015 09:48:00 +0200
Subject: [PATCH] lfi2cdf: BUG corrections: uninitialised variables + incorrect
 conversion

---
 tools/lfi2cdf/src/fieldtype.f90    | 3 +--
 tools/lfi2cdf/src/lfi2cdf.f90      | 1 +
 tools/lfi2cdf/src/mode_dimlist.f90 | 1 +
 tools/lfi2cdf/src/newmain.c        | 5 ++++-
 4 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/lfi2cdf/src/fieldtype.f90 b/tools/lfi2cdf/src/fieldtype.f90
index daa8cbb9a..62a1b73a8 100644
--- a/tools/lfi2cdf/src/fieldtype.f90
+++ b/tools/lfi2cdf/src/fieldtype.f90
@@ -297,8 +297,6 @@ END SUBROUTINE init_sysfield
        END IF
     END DO
 
-    write(clevel,'(I4.4)') level
-
     IF (.NOT. found) THEN
        ! Next, search in user field tab
        IF (ALLOCATED(userfield)) THEN
@@ -331,6 +329,7 @@ END SUBROUTINE init_sysfield
                 ELSE IF (level>-1) THEN
                   !Maybe it is a z-level splitted field
                   !Warning: false positives are possible (but should be rare)
+                  write(clevel,'(I4.4)') level
                   iposx = INDEX(hfname,clevel)
                   IF (iposx /= 0) THEN
                     IF (hfname(:iposx-1)==sysfield(ji)%name) THEN
diff --git a/tools/lfi2cdf/src/lfi2cdf.f90 b/tools/lfi2cdf/src/lfi2cdf.f90
index ca153fb22..b4039b446 100644
--- a/tools/lfi2cdf/src/lfi2cdf.f90
+++ b/tools/lfi2cdf/src/lfi2cdf.f90
@@ -59,6 +59,7 @@ subroutine  LFI2CDFMAIN(hinfile,iiflen,ooutname,houtfile,ioflen,hvarlist,ivlen,o
         ! by counting commas, = and +
         nbvar_tbr  = 0
         nbvar_calc = 0
+        nbvar_tbw = 0
         DO ji=1,ivlen
            IF (hvarlist(ji:ji) == ',' .OR.hvarlist(ji:ji) == '+') THEN
               nbvar_tbr = nbvar_tbr+1
diff --git a/tools/lfi2cdf/src/mode_dimlist.f90 b/tools/lfi2cdf/src/mode_dimlist.f90
index 6c6ffe3c0..d4977136d 100644
--- a/tools/lfi2cdf/src/mode_dimlist.f90
+++ b/tools/lfi2cdf/src/mode_dimlist.f90
@@ -72,6 +72,7 @@ CONTAINS
     !
     IF (len /= 1) THEN 
        IF (gforce) THEN
+         count = 0
          NULLIFY(tmp)
        ELSE 
          count = 1
diff --git a/tools/lfi2cdf/src/newmain.c b/tools/lfi2cdf/src/newmain.c
index 5eba51d4c..6f56531fb 100644
--- a/tools/lfi2cdf/src/newmain.c
+++ b/tools/lfi2cdf/src/newmain.c
@@ -53,10 +53,13 @@ int main(int argc, char **argv)
     cmd++;
   l2c_flag = strcmp(cmd, "lfi2cdf") == 0 ? 1 : 0;
 
+  compress_flag = 0;
   list_flag = 0;
   hdf5_flag = 0;
+  help_flag = 0;
+  outname_flag = 0;
   reduceprecision_flag = 0;
-  compress_flag = 0;
+  split_flag = 0;
   p = buff;
   *p = '\0';
 
-- 
GitLab