From 6fed3e86d608d07ee979678c44aee2db56305828 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Mon, 27 Nov 2017 11:00:28 +0100
Subject: [PATCH] Philippe 27/11/2017: IO: remove FD_ll structures

---
 src/LIB/SURCOUCHE/src/mode_fd.f90 | 118 ------------------------------
 src/LIB/SURCOUCHE/src/mode_fm.f90 |  16 +---
 src/LIB/SURCOUCHE/src/mode_io.f90 |  72 +-----------------
 3 files changed, 3 insertions(+), 203 deletions(-)
 delete mode 100644 src/LIB/SURCOUCHE/src/mode_fd.f90

diff --git a/src/LIB/SURCOUCHE/src/mode_fd.f90 b/src/LIB/SURCOUCHE/src/mode_fd.f90
deleted file mode 100644
index 364377986..000000000
--- a/src/LIB/SURCOUCHE/src/mode_fd.f90
+++ /dev/null
@@ -1,118 +0,0 @@
-!MNH_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
-!MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
-!MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt  
-!MNH_LIC for details. version 1.
-!-----------------------------------------------------------------
-!--------------- special set of characters for CVS information
-!-----------------------------------------------------------------
-! $Source$
-! $Name$ 
-! $Revision$ 
-! $Date$
-!-----------------------------------------------------------------
-!-----------------------------------------------------------------
-
-MODULE MODE_FD_ll
-USE MODD_NETCDF, ONLY : IOCDF
-
-IMPLICIT NONE 
-
-PRIVATE
-
-INTEGER, PARAMETER :: JPFINL = 32 ! File name length
-
-TYPE FD_ll
-  CHARACTER(LEN=JPFINL)    :: NAME  ! File name 
-  INTEGER                  :: FLU   ! Fortran logical unit
-  TYPE(FD_ll),     POINTER :: NEXT
-END TYPE FD_ll
-
-TYPE(FD_ll), POINTER, SAVE :: TFDLIST
-
-INTERFACE GETFD
-  MODULE PROCEDURE GETFD_FILE
-END INTERFACE
-
-PUBLIC JPFINL,FD_ll,GETFD,INITFD,NEWFD,DELFD,DISPLAY_FDLIST
-
-CONTAINS 
-
-SUBROUTINE INITFD()
-
-NULLIFY(TFDLIST)
-END SUBROUTINE INITFD
-
-FUNCTION GETFD_FILE(HFILE)
-
-TYPE(FD_ll), POINTER :: GETFD_FILE
-CHARACTER(LEN=*)     :: HFILE
-
-TYPE(FD_ll), POINTER :: TZFD
-
-TZFD=>TFDLIST 
-DO WHILE(ASSOCIATED(TZFD))
-  IF (TZFD%NAME == HFILE) EXIT
-  TZFD=>TZFD%NEXT
-END DO
-
-GETFD_FILE=>TZFD
-
-END FUNCTION GETFD_FILE
-
-FUNCTION NEWFD()
-
-TYPE(FD_ll), POINTER :: NEWFD
-TYPE(FD_ll), POINTER :: TZFD
-INTEGER              :: IRESP
-
-ALLOCATE(TZFD,STAT=IRESP)
-IF (IRESP > 0) THEN 
-  !       CALL ABORT()
-  PRINT *, 'NEWFD : Erreur d"allocation memoire...'
-END IF
-
-!! Add TZFD to top of list TPFDLIST
-TZFD%NEXT=>TFDLIST
-TFDLIST=>TZFD
-
-NEWFD=>TZFD
-END FUNCTION NEWFD
-
-SUBROUTINE DELFD(TPFD)
-
-TYPE(FD_ll), POINTER :: TPFD
-
-TYPE(FD_ll), POINTER :: TZPREV
-
-!! BEWARE: TPFD must exist in TPFDLIST
-
-
-IF (ASSOCIATED(TPFD,TFDLIST)) THEN
-  !! TPFD is the first element of TPFDLIST
-  TFDLIST=>TFDLIST%NEXT
-ELSE
-  TZPREV=>TFDLIST
-  DO WHILE(.NOT. ASSOCIATED(TZPREV%NEXT,TPFD))
-    TZPREV=>TZPREV%NEXT
-  END DO
-  TZPREV%NEXT=>TPFD%NEXT
-END IF
-
-!    PRINT *,'Desallocation de ', TRIM(TPFD%NAME),' realisee...'
-DEALLOCATE(TPFD)
-
-END SUBROUTINE DELFD
-
-SUBROUTINE DISPLAY_FDLIST()
-
-TYPE(FD_ll), POINTER :: TZFD
-
-TZFD=>TFDLIST
-DO WHILE(ASSOCIATED(TZFD))
-  PRINT *, TZFD%NAME, ': ',TZFD%FLU
-  TZFD=>TZFD%NEXT
-END DO
-
-END SUBROUTINE DISPLAY_FDLIST
-
-END MODULE MODE_FD_ll
diff --git a/src/LIB/SURCOUCHE/src/mode_fm.f90 b/src/LIB/SURCOUCHE/src/mode_fm.f90
index 54d85bbc7..3a5bc9b96 100644
--- a/src/LIB/SURCOUCHE/src/mode_fm.f90
+++ b/src/LIB/SURCOUCHE/src/mode_fm.f90
@@ -89,7 +89,6 @@ SUBROUTINE IO_FILE_OPEN_ll(TPFILE,KRESP,OPARALLELIO,HPOSITION,HSTATUS)
 !
 USE MODD_CONF,  ONLY: NMNHVERSION
 USE MODD_IO_ll, ONLY: LIOCDF4,LLFIOUT,LLFIREAD,TFILEDATA
-USE MODE_FD_ll, ONLY: FD_ll,GETFD
 USE MODE_FIELD, ONLY: TFIELDDATA,TYPEINT
 USE MODE_FMREAD
 USE MODE_IO_ll, ONLY : OPEN_ll
@@ -258,7 +257,6 @@ END SUBROUTINE IO_FILE_OPEN_ll
 
 SUBROUTINE FMOPEN_ll(TPFILE,KRESP,OPARALLELIO)
 USE MODD_IO_ll, ONLY : ISTDOUT,LIOCDF4,LLFIOUT,LLFIREAD,TFILEDATA
-USE MODE_FD_ll, ONLY : JPFINL
 USE MODE_IO_ll, ONLY : OPEN_ll,GCONFIO
 !JUANZ
 USE MODD_CONFZ,ONLY  : NB_PROCIO_R,NB_PROCIO_W
@@ -274,7 +272,7 @@ LOGICAL,         INTENT(IN),  OPTIONAL :: OPARALLELIO
 !   Local variables
 !
 INTEGER                 :: IFTYPE  ! type of FM-file
-INTEGER                 :: IROWF,IRESP,IFMFNL
+INTEGER                 :: IROWF,IRESP
 CHARACTER(LEN=7)        :: YACTION ! Action upon the file ('READ' or 'WRITE')
 CHARACTER(LEN=28)       :: YFILEM  ! name of the file
 CHARACTER(LEN=8)        :: YRESP
@@ -330,15 +328,11 @@ CASE(10:)
   IMELEV=2
 END SELECT
 
-IFMFNL=JPFINL-4
 IROWF=LEN_TRIM(YFILEM)
 
 IF (IROWF.EQ.0) THEN
   IRESP=-45
   GOTO 1000
-ELSEIF (IROWF.GT.IFMFNL) THEN
-  IRESP=-49
-  GOTO 1000
 ENDIF
 
  SELECT CASE (YACTION)
@@ -587,7 +581,6 @@ SUBROUTINE FMCLOS_ll(TPFILE,HSTATU,KRESP,OPARALLELIO)
 !!      J.Escobar   18/10/10   bug with PGI compiler on ADJUSTL
 !-------------------------------------------------------------------------------
 USE MODD_IO_ll, ONLY : TFILEDATA
-USE MODE_FD_ll, ONLY : JPFINL
 USE MODE_IO_ll, ONLY : CLOSE_ll,UPCASE
 #if !defined(MNH_SGI)
 USE MODI_SYSTEM_MNH
@@ -600,7 +593,7 @@ CHARACTER(LEN=*),     INTENT(IN) :: HSTATU ! status for the closed file
 INTEGER,              INTENT(OUT), OPTIONAL :: KRESP   ! return-code if problems araised
 LOGICAL,              INTENT(IN),  OPTIONAL :: OPARALLELIO
 
-INTEGER              ::IRESP,IROWF,IFMFNL
+INTEGER              ::IRESP,IROWF
 CHARACTER(LEN=28)    :: YFILEM  ! name of the file
 CHARACTER(LEN=7)     ::YSTATU
 LOGICAL              ::GSTATU
@@ -626,16 +619,11 @@ ENDIF
 IRESP  = 0
 IROWF  = 0
 
-IFMFNL=JPFINL-4
-
 IROWF=LEN_TRIM(YFILEM)
 
 IF (IROWF.EQ.0) THEN
   IRESP=-59
   GOTO 1000
-ELSEIF (IROWF.GT.IFMFNL) THEN
-  IRESP=-60
-  GOTO 1000
 ENDIF
 
 IF (LEN(HSTATU).LE.0) THEN
diff --git a/src/LIB/SURCOUCHE/src/mode_io.f90 b/src/LIB/SURCOUCHE/src/mode_io.f90
index 4ee081183..9cb6bee5a 100644
--- a/src/LIB/SURCOUCHE/src/mode_io.f90
+++ b/src/LIB/SURCOUCHE/src/mode_io.f90
@@ -27,19 +27,15 @@
 MODULE MODE_IO_ll
 
   USE MODD_ERRCODES
-  USE MODE_FD_ll
   USE MODD_MPIF
-  !JUANZ
   USE MODD_VAR_ll, ONLY : NMNH_COMM_WORLD
-  !JUANZ
+
   USE MODE_MSG
 
   IMPLICIT NONE 
 
   PRIVATE
 
-  !INCLUDE 'mpif.h'
-
   INTEGER, PARAMETER :: JPFNULL = 9       !! /dev/null fortran unit
   INTEGER, PARAMETER :: JPRESERVED_UNIT   = 11
   INTEGER, PARAMETER :: JPMAX_UNIT_NUMBER = JPRESERVED_UNIT+300
@@ -52,9 +48,7 @@ MODULE MODE_IO_ll
 
   PUBLIC IONEWFLU,UPCASE,INITIO_ll,OPEN_ll,CLOSE_ll
   PUBLIC SET_CONFIO_ll,GCONFIO
-  !JUANZ
   PUBLIC  io_file,IO_RANK
-  !JUANZ
 
 CONTAINS 
 
@@ -170,8 +164,6 @@ CONTAINS
     END IF
     !! Now MPI is initialized for sure
 
-    CALL INITFD()
-
     !! Default number for Processor I/O
     ISIOP = 1
 
@@ -247,7 +239,6 @@ CONTAINS
     !JUANZ
     CHARACTER(len=5)                      :: CFILE
     INTEGER                               :: IFILE, IRANK_PROCIO
-    TYPE(FD_ll), POINTER                  :: TZFD_IOZ  
     CHARACTER(len=128)                    :: YFILE_IOZ
     INTEGER(KIND=LFI_INT)                 :: IRESOU,IMELEV,INPRAR
     INTEGER(KIND=LFI_INT)                 :: ININAR8
@@ -272,13 +263,10 @@ CONTAINS
     INTEGER(KIND=IDCDF_KIND) :: IOSCDF
     INTEGER              :: ICOMM
     INTEGER              :: ICMPRES
-    TYPE(FD_ll), POINTER :: TZFD, TZFDTEMP
     ! didier
     LOGICAL :: GEXISTS,GOPENED
     INTEGER :: IUNIT
     ! didier
-    !JUAN SX5 : probleme function retournant un pointer
-    TYPE(FD_ll), POINTER :: TZJUAN
     LOGICAL               :: GPARALLELIO
     TYPE(TFILEDATA),POINTER :: TZSPLITFILE
 
@@ -330,34 +318,6 @@ CONTAINS
        RETURN
     END IF
 
-    !JUAN SX5 : probleme function retournant un pointer
-    !IF (.NOT. ASSOCIATED(GETFD(TPFILE%CNAME))) THEN
-    TZJUAN=>GETFD(TPFILE%CNAME)
-    IF (.NOT. ASSOCIATED(TZJUAN)) THEN 
-       !JUAN SX5 : probleme function retournant un pointer
-       !! File is not already opened : GOOD
-       !! Add a new FD element
-       TZFD=>NEWFD()
-    ELSE 
-       !! Error : File already opened
-       IOSTAT = 99
-       TPFILE%NLU = -1
-       WRITE(ISTDERR,*) 'OPEN_ll error : File', TPFILE%CNAME, 'already opened'
-       RETURN
-    END IF
-
-!!$    CALL MPI_ALLREDUCE(ILOCALERR, IGLOBALERR, 1, MPI_INTEGER, MPI_BOR,&
-!!$         & ICOMM, IERR)
-!!$    IF (IGLOBALERR /= NOERROR) THEN 
-!!$       IOSTAT = GLOBALERR
-!!$       TPFILE%NLU = -1
-!!$       RETURN 
-!!$    END IF
-
-
-
-    TZFD%NAME = TPFILE%CNAME
-
 #if defined(MNH_SX5) || defined(MNH_SP4) || defined(NAGf95) || defined(MNH_LINUX)
     !JUAN
     IF (PRESENT(STATUS)) THEN
@@ -531,7 +491,6 @@ CONTAINS
           TPFILE%NLU = JPFNULL
        END IF
 
-      TZFD%FLU = TPFILE%NLU
 
     CASE('SPECIFIC')
        TPFILE%NLU = IONEWFLU()
@@ -611,7 +570,6 @@ CONTAINS
 
 #endif
 
-       TZFD%FLU = TPFILE%NLU
 
 
     CASE('DISTRIBUTED')
@@ -628,7 +586,6 @@ CONTAINS
           TPFILE%NLU = -1
        END IF
 
-       TZFD%FLU = TPFILE%NLU
 
 
     CASE('IO_ZSPLIT')
@@ -642,7 +599,6 @@ CONTAINS
          END IF
        END IF
 
-       TZFD%NAME  = TRIM(TPFILE%CNAME)//".lfi"
 #if defined(MNH_IOCDF4)
        IF (TPFILE%LMASTER .AND. (.NOT. LIOCDF4 .OR. (YACTION=='WRITE' .AND. LLFIOUT) &
             &                    .OR. (YACTION=='READ'  .AND. LLFIREAD))) THEN
@@ -656,8 +612,6 @@ CONTAINS
           TPFILE%NLFIFLU = -1
        END IF
 
-       TZFD%FLU = TPFILE%NLFIFLU
-
        IF (TPFILE%NSUBFILES_IOZ > 0) THEN
           IF (.NOT.ALLOCATED(TPFILE%TFILES_IOZ)) THEN
             ALLOCATE(TPFILE%TFILES_IOZ(TPFILE%NSUBFILES_IOZ))
@@ -668,9 +622,6 @@ CONTAINS
              IRANK_PROCIO = 1 + IO_RANK(IFILE-1,ISNPROC,TPFILE%NSUBFILES_IOZ)
              WRITE(CFILE ,'(".Z",i3.3)') IFILE
              YFILE_IOZ           = TRIM(TPFILE%CNAME)//CFILE//".lfi"
-             TZFD_IOZ           =>NEWFD()
-             TZFD_IOZ%NAME      = YFILE_IOZ
-             TZFD_IOZ%FLU       = -1
 
              CALL IO_FILE_FIND_BYNAME(TRIM(TPFILE%CNAME)//TRIM(CFILE),TZSPLITFILE,IRESP,OOLD=.FALSE.)
 
@@ -726,7 +677,6 @@ CONTAINS
                    ! Open LFI File for reading
                    !this proc must write on this file open it ...    
                    TZSPLITFILE%NLFIFLU = IONEWFLU()
-                   TZFD_IOZ%FLU = TZSPLITFILE%NLFIFLU
                    !! LFI-File case
                    IRESOU = 0
                    GNAMFI8 = .TRUE.
@@ -792,13 +742,10 @@ CONTAINS
     CHARACTER(LEN=*), INTENT(IN),  OPTIONAL :: STATUS
     LOGICAL,          INTENT(IN),  OPTIONAL :: OPARALLELIO
 
-    TYPE(FD_ll), POINTER :: TZFD
-
     INTEGER :: IERR, IGLOBALERR, IGLOBALERR2, IRESP, IRESP2
 
     CHARACTER(LEN=100)                    :: STATUSL
     INTEGER                               :: IFILE
-    TYPE(FD_ll), POINTER                  :: TZFD_IOZ  
     INTEGER(KIND=LFI_INT)                 :: IRESP8
     CHARACTER(LEN=7)                      :: YSTATU  
     LOGICAL                               :: GPARALLELIO
@@ -813,21 +760,6 @@ CONTAINS
     ENDIF
     !JUANZ
 
-    TZFD => NULL()
-    TZFD => GETFD(TPFILE%CNAME)
-
-    !Temporary fix: try with a .lfi extension
-    IF (.NOT. ASSOCIATED(TZFD)) THEN
-      TZFD => GETFD(TRIM(TPFILE%CNAME)//'.lfi')
-    END IF
-
-    IF (.NOT. ASSOCIATED(TZFD)) THEN
-       WRITE(ISTDOUT,*) 'Erreur CLOSE_ll : Fichier : ', TPFILE%CNAME, ' non&
-            & present...'
-       IF (PRESENT(IOSTAT)) IOSTAT = BADVALUE
-       RETURN
-    END IF
-
     IRESP       = 0
     IRESP2      = 0
     IGLOBALERR  = 0
@@ -863,8 +795,6 @@ CONTAINS
     !
     CALL MPI_ALLREDUCE(IRESP, IGLOBALERR, 1,MPI_INTEGER,MPI_BOR,TPFILE%NMPICOMM,IERR)
 
-    CALL DELFD(TZFD)
-
     IF (PRESENT(IOSTAT)) THEN
       IF (IGLOBALERR/=0) THEN
         IOSTAT = IGLOBALERR
-- 
GitLab