- Timestamp:
- 2018-12-14T17:27:24+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/IOM/iom_nf90.F90
r10380 r10397 30 30 31 31 PUBLIC iom_nf90_open , iom_nf90_close, iom_nf90_varid, iom_nf90_get, iom_nf90_gettime, iom_nf90_rstput 32 PUBLIC iom_nf90_ getatt, iom_nf90_putatt32 PUBLIC iom_nf90_chkatt, iom_nf90_getatt, iom_nf90_putatt 33 33 34 34 INTERFACE iom_nf90_get … … 321 321 322 322 323 SUBROUTINE iom_nf90_chkatt( kiomid, cdatt, llok, ksize, cdvar ) 324 !!----------------------------------------------------------------------- 325 !! *** ROUTINE iom_nf90_chkatt *** 326 !! 327 !! ** Purpose : check existence of attribute with NF90 328 !! (either a global attribute (default) or a variable 329 !! attribute if optional variable name is supplied (cdvar)) 330 !!----------------------------------------------------------------------- 331 INTEGER , INTENT(in ) :: kiomid ! Identifier of the file 332 CHARACTER(len=*), INTENT(in ) :: cdatt ! attribute name 333 LOGICAL , INTENT( out) :: llok ! error code 334 INTEGER , INTENT( out), OPTIONAL & 335 & :: ksize ! attribute size 336 CHARACTER(len=*), INTENT(in ), OPTIONAL & 337 & :: cdvar ! name of the variable 338 ! 339 INTEGER :: if90id ! temporary integer 340 INTEGER :: isize ! temporary integer 341 INTEGER :: ivarid ! NetCDF variable Id 342 !--------------------------------------------------------------------- 343 ! 344 if90id = iom_file(kiomid)%nfid 345 IF( PRESENT(cdvar) ) THEN 346 ! check the variable exists in the file 347 llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr 348 IF( llok ) & 349 ! check the variable has the attribute required 350 llok = NF90_Inquire_attribute(if90id, ivarid, cdatt, len=isize ) == nf90_noerr 351 ELSE 352 llok = NF90_Inquire_attribute(if90id, NF90_GLOBAL, cdatt, len=isize ) == nf90_noerr 353 ENDIF 354 ! 355 IF( PRESENT(ksize) ) ksize = isize 356 ! 357 IF( .not. llok) & 358 CALL ctl_warn('iom_nf90_chkatt: no attribute '//cdatt//' found') 359 ! 360 END SUBROUTINE iom_nf90_chkatt 361 362 363 !!---------------------------------------------------------------------- 364 !! INTERFACE iom_nf90_getatt 365 !!---------------------------------------------------------------------- 366 323 367 SUBROUTINE iom_nf90_getatt( kiomid, cdatt, katt0d, katt1d, patt0d, patt1d, cdatt0d, cdvar) 324 368 !!----------------------------------------------------------------------- … … 397 441 INTEGER :: if90id ! temporary integer 398 442 INTEGER :: ivarid ! NetCDF variable Id 443 INTEGER :: isize ! Attribute size 444 INTEGER :: itype ! Attribute type 399 445 LOGICAL :: llok ! temporary logical 400 LOGICAL :: lenddef ! temporary logical 446 LOGICAL :: llatt ! temporary logical 447 LOGICAL :: lldata ! temporary logical 401 448 CHARACTER(LEN=100) :: clinfo ! info character 402 449 !--------------------------------------------------------------------- 403 450 ! 404 451 if90id = iom_file(kiomid)%nfid 405 lenddef = .false.406 452 IF( PRESENT(cdvar) ) THEN 407 ! check the variable exists in the file 408 llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr 453 llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr ! is the variable in the file? 409 454 IF( .NOT. llok ) THEN 410 CALL ctl_warn('iom_nf90_putatt: no variable '//TRIM(cdvar)//' found') 455 CALL ctl_warn('iom_nf90_putatt: no variable '//TRIM(cdvar)//' found' & 456 & , ' no attribute '//cdatt//' written' ) 457 RETURN 411 458 ENDIF 412 459 ELSE 413 llok = .true.414 460 ivarid = NF90_GLOBAL 415 461 ENDIF 416 ! 417 IF( llok) THEN 418 clinfo = 'iom_nf90_putatt, file: '//TRIM(iom_file(kiomid)%name)//', att: '//TRIM(cdatt) 419 IF( iom_file(kiomid)%irec /= -1 ) THEN 420 ! trick: irec used to know if the file is in define mode or not 421 ! if it is not then temporarily put it into define mode 422 CALL iom_nf90_check(NF90_REDEF( if90id ), clinfo) 423 lenddef = .true. 424 ENDIF 462 llatt = NF90_Inquire_attribute(if90id, ivarid, cdatt, len = isize, xtype = itype ) == nf90_noerr 463 ! 464 ! trick: irec used to know if the file is in define mode or not 465 lldata = iom_file(kiomid)%irec /= -1 ! default: go back in define mode if in data mode 466 IF( lldata .AND. llatt ) THEN ! attribute already there. Do we really need to go back in define mode? 467 ! do we have the appropriate type? 468 IF(PRESENT( katt0d) .OR. PRESENT( katt1d)) llok = itype == NF90_INT 469 IF(PRESENT( patt0d) .OR. PRESENT( patt1d)) llok = itype == NF90_DOUBLE 470 IF(PRESENT(cdatt0d) ) llok = itype == NF90_CHAR 471 ! and do we have the appropriate size? 472 IF(PRESENT( katt0d)) llok = llok .AND. isize == 1 473 IF(PRESENT( katt1d)) llok = llok .AND. isize == SIZE(katt1d) 474 IF(PRESENT( patt0d)) llok = llok .AND. isize == 1 475 IF(PRESENT( patt1d)) llok = llok .AND. isize == SIZE(patt1d) 476 IF(PRESENT(cdatt0d)) llok = llok .AND. isize == LEN_TRIM(cdatt0d) 425 477 ! 426 IF(PRESENT( katt0d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = katt0d), clinfo) 427 IF(PRESENT( katt1d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = katt1d), clinfo) 428 IF(PRESENT( patt0d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = patt0d), clinfo) 429 IF(PRESENT( patt1d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = patt1d), clinfo) 430 IF(PRESENT(cdatt0d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = cdatt0d), clinfo) 431 ! 432 IF( lenddef ) THEN ! file was in data mode on entry; put it back in that mode 433 CALL iom_nf90_check(NF90_ENDDEF( if90id ), clinfo) 434 ENDIF 435 ELSE 436 CALL ctl_warn('iom_nf90_putatt: no attribute '//TRIM(cdatt)//' written') 437 ENDIF 478 lldata = .NOT. llok 479 ENDIF 480 ! 481 clinfo = 'iom_nf90_putatt, file: '//TRIM(iom_file(kiomid)%name)//', att: '//TRIM(cdatt) 482 IF(lldata) CALL iom_nf90_check(NF90_REDEF( if90id ), clinfo) ! leave data mode to define mode 483 ! 484 IF(PRESENT( katt0d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = katt0d) , clinfo) 485 IF(PRESENT( katt1d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = katt1d) , clinfo) 486 IF(PRESENT( patt0d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = patt0d) , clinfo) 487 IF(PRESENT( patt1d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = patt1d) , clinfo) 488 IF(PRESENT(cdatt0d)) CALL iom_nf90_check(NF90_PUT_ATT(if90id, ivarid, cdatt, values = trim(cdatt0d)), clinfo) 489 ! 490 IF(lldata) CALL iom_nf90_check(NF90_ENDDEF( if90id ), clinfo) ! leave define mode to data mode 438 491 ! 439 492 END SUBROUTINE iom_nf90_putatt
Note: See TracChangeset
for help on using the changeset viewer.