- Timestamp:
- 2019-10-01T15:07:45+02:00 (5 years ago)
- 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 32 32 !! ctl_opn : Open file and check if required file is available. 33 33 !! 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 34 35 !!---------------------------------------------------------------------- 35 36 !!---------------------------------------------------------------------- … … 57 58 PRIVATE 58 59 ! 59 PUBLIC ctl_stop, ctl_warn, ctl_opn, ctl_nam 60 PUBLIC ctl_stop, ctl_warn, ctl_opn, ctl_nam, load_nml 60 61 PUBLIC mpp_start, mppstop, mppsync, mpp_comm_free 61 62 PUBLIC mpp_ini_north … … 1068 1069 1069 1070 !!---------------------------------------------------------------------- 1070 !! ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam routines1071 !! ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam, load_nml routines 1071 1072 !!---------------------------------------------------------------------- 1072 1073 … … 1279 1280 END FUNCTION get_unit 1280 1281 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 1281 1349 !!---------------------------------------------------------------------- 1282 1350 END MODULE lib_mpp
Note: See TracChangeset
for help on using the changeset viewer.