New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 11624 for NEMO/branches/2019/dev_r11613_ENHANCE-04_namelists_as_internalfiles/src/OCE/LBC – NEMO

Ignore:
Timestamp:
2019-10-01T15:07:45+02:00 (5 years ago)
Author:
acc
Message:

Branch 2019/dev_r11613_ENHANCE-04_namelists_as_internalfiles. Substantive changes required to replace all namelists with internal files. These are the key changes only; to compile and run tests all REWIND and CLOSE operations on the (no longer) units have to be removed. These changes affect many more files but can be scripted so are not included here in order to make a later merge easier. The scripts used to prepare code for testing are included on: wiki:2019WP/ENHANCE-04_AndrewC-reporting/Internal_Namelists. With these additional changes this code passes most SETTE tests but the AGRIF preprocessor does not currently accept the new allocatable character strings. To be investigated.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • NEMO/branches/2019/dev_r11613_ENHANCE-04_namelists_as_internalfiles/src/OCE/LBC/lib_mpp.F90

    r11536 r11624  
    3232   !!   ctl_opn       : Open file and check if required file is available. 
    3333   !!   ctl_nam       : Prints informations when an error occurs while reading a namelist 
     34   !!   load_nml      : Read, condense and buffer namelist file into character array for use as an internal file 
    3435   !!---------------------------------------------------------------------- 
    3536   !!---------------------------------------------------------------------- 
     
    5758   PRIVATE 
    5859   ! 
    59    PUBLIC   ctl_stop, ctl_warn, ctl_opn, ctl_nam 
     60   PUBLIC   ctl_stop, ctl_warn, ctl_opn, ctl_nam, load_nml 
    6061   PUBLIC   mpp_start, mppstop, mppsync, mpp_comm_free 
    6162   PUBLIC   mpp_ini_north 
     
    10681069 
    10691070   !!---------------------------------------------------------------------- 
    1070    !!   ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam   routines 
     1071   !!   ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam, load_nml   routines 
    10711072   !!---------------------------------------------------------------------- 
    10721073 
     
    12791280   END FUNCTION get_unit 
    12801281 
     1282   SUBROUTINE load_nml( cdnambuff , cdnamfile, kout, ldwp) 
     1283      CHARACTER(LEN=:)    , ALLOCATABLE, INTENT(INOUT) :: cdnambuff 
     1284      CHARACTER(LEN=*), INTENT(IN )                :: cdnamfile 
     1285      CHARACTER(LEN=256)                           :: chline 
     1286      INTEGER, INTENT(IN)                          :: kout 
     1287      LOGICAL, INTENT(IN)                          :: ldwp 
     1288      INTEGER                                      :: itot, iun, iltc, inl, ios 
     1289      ! 
     1290      ! Check if the namelist buffer has already been allocated. Return if it has. 
     1291      ! 
     1292      IF ( ALLOCATED( cdnambuff ) ) RETURN 
     1293      ! 
     1294      ! Open namelist file 
     1295      ! 
     1296      CALL ctl_opn( iun, cdnamfile, 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, kout, ldwp ) 
     1297      ! 
     1298      ! First pass: count characters excluding comments and trimable white space 
     1299      ! 
     1300      itot=0 
     1301  10  READ(iun,'(A256)',END=20,ERR=20) chline 
     1302      iltc = LEN_TRIM(chline) 
     1303      IF ( iltc.GT.0 ) THEN 
     1304       inl = INDEX(chline, '!')  
     1305       IF( inl.eq.0 ) THEN 
     1306        itot = itot + iltc + 1                                ! +1 for the newline character 
     1307       ELSEIF( inl.GT.0 .AND. LEN_TRIM( chline(1:inl-1) ).GT.0 ) THEN 
     1308        itot = itot + inl                                  !  includes +1 for the newline character 
     1309       ENDIF 
     1310      ENDIF 
     1311      GOTO 10 
     1312  20  CONTINUE 
     1313      ! 
     1314      ! Allocate text cdnambuff for condensed namelist 
     1315      ! 
     1316      ALLOCATE( CHARACTER(LEN=itot) :: cdnambuff ) 
     1317      WRITE(*,*) 'ALLOCATED ', itot 
     1318      ! 
     1319      ! Second pass: read and transfer pruned characters into cdnambuff 
     1320      ! 
     1321      REWIND(iun) 
     1322      itot=1 
     1323  30  READ(iun,'(A256)',END=40,ERR=40) chline 
     1324      iltc = LEN_TRIM(chline) 
     1325      IF ( iltc.GT.0 ) THEN 
     1326       inl = INDEX(chline, '!') 
     1327       IF( inl.eq.0 ) THEN 
     1328        inl = iltc 
     1329       ELSE 
     1330        inl = inl - 1 
     1331       ENDIF 
     1332       IF( inl.GT.0 .AND. LEN_TRIM( chline(1:inl) ).GT.0 ) THEN 
     1333          cdnambuff(itot:itot+inl-1) = chline(1:inl) 
     1334          WRITE( cdnambuff(itot+inl:itot+inl), '(a)' ) NEW_LINE('A') 
     1335          itot = itot + inl + 1 
     1336       ENDIF 
     1337      ENDIF 
     1338      GOTO 30 
     1339  40  CONTINUE 
     1340      WRITE(*,*) 'ASSIGNED ',itot - 1 
     1341      ! 
     1342      ! Close namelist file 
     1343      ! 
     1344      CLOSE(iun) 
     1345      !write(*,'(32A)') cdnambuff 
     1346  END SUBROUTINE load_nml 
     1347 
     1348 
    12811349   !!---------------------------------------------------------------------- 
    12821350END MODULE lib_mpp 
Note: See TracChangeset for help on using the changeset viewer.