Skip to content
Snippets Groups Projects
write_diachro.f90 93.6 KiB
Newer Older
  • Learn to ignore specific revisions
  •     return
      else
        cmnhmsg(1) = 'attribute ' // hattname // ' has changed for ' // Trim( hlevel )
        Write( cmnhmsg(2), '( I0, " -> ", I0 )' ) iatt, kdata
        call Print_msg( NVERB_WARNING, 'IO', 'Write_diachro_nc4' )
      end if
    
    end if
    
    
    istatus = NF90_PUT_ATT( kgrpid, NF90_GLOBAL, hattname, kdata )
    if (istatus /= NF90_NOERR ) &
    
     call IO_Err_handle_nc4( istatus, 'Write_diachro_nc4', 'NF90_PUT_ATT', Trim( hattname ) // ' for '// Trim( hlevel ) // ' group' )
    
    subroutine Att_write_x0( hlevel, kgrpid, hattname, pdata )
    use NETCDF,            only: NF90_GET_ATT, NF90_INQUIRE_ATTRIBUTE, NF90_PUT_ATT, NF90_GLOBAL, NF90_NOERR
    
    use modd_precision,    only: CDFINT, MNHREAL_NF90
    
    
    use mode_io_tools_nc4, only: IO_Err_handle_nc4
    
    
    integer(kind=CDFINT), intent(in) :: kgrpid
    character(len=*),     intent(in) :: hattname
    real,                 intent(in) :: pdata
    
    
    integer(kind=CDFINT) :: itype
    real                 :: zatt
    
    istatus = NF90_INQUIRE_ATTRIBUTE( kgrpid, NF90_GLOBAL, hattname, xtype = itype, len = ilen )
    if (istatus == NF90_NOERR ) then
      call Print_msg( NVERB_DEBUG, 'IO', 'Write_diachro_nc4', 'attribute ' // hattname // ' already exists for ' // Trim( hlevel ) )
    
      if ( itype /= MNHREAL_NF90 ) then
        call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', 'type for attribute ' // hattname // &
                        ' has changed for ' // Trim( hlevel ) )
        return
      end if
    
      if ( ilen /= 1 ) then
        call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', 'size of attribute ' // hattname // &
                        ' has changed for ' // Trim( hlevel ) )
        return
      end if
    
      istatus = NF90_GET_ATT( kgrpid, NF90_GLOBAL, hattname, zatt )
      if ( zatt == pdata ) then
        call Print_msg( NVERB_DEBUG, 'IO', 'Write_diachro_nc4', 'attribute ' // hattname // ' is unchanged for ' // Trim( hlevel ) )
        !If unchanged, no need to write it again => return
        return
      else
        cmnhmsg(1) = 'attribute ' // hattname // ' has changed for ' // Trim( hlevel )
        Write( cmnhmsg(2), '( F15.7, " -> ", F15.7 )' ) zatt, pdata
        call Print_msg( NVERB_WARNING, 'IO', 'Write_diachro_nc4' )
      end if
    
    end if
    
    
    istatus = NF90_PUT_ATT( kgrpid, NF90_GLOBAL, hattname, pdata )
    if (istatus /= NF90_NOERR ) &
    
     call IO_Err_handle_nc4( istatus, 'Write_diachro_nc4', 'NF90_PUT_ATT', Trim( hattname ) // ' for '// Trim( hlevel ) // ' group' )
    
    
    
    subroutine Move_to_next_level( kpreviouslevelid, gpreviousleveldefined, oleveluse, hlevelname, gleveldefined, klevelid )
    use NETCDF,            only: NF90_DEF_GRP, NF90_INQ_NCID, NF90_NOERR
    
    use modd_precision,    only: CDFINT
    
    use mode_io_tools_nc4, only: IO_Err_handle_nc4
    
    integer(kind=CDFINT), intent(in)    :: kpreviouslevelid
    logical,              intent(in)    :: gpreviousleveldefined
    logical,              intent(in)    :: oleveluse
    character(len=*),     intent(inout) :: hlevelname
    logical,              intent(out)   :: gleveldefined
    integer(kind=CDFINT), intent(out)   :: klevelid
    
    integer(kind=CDFINT) :: istatus
    
    
    if ( oleveluse ) then
      istatus = NF90_INQ_NCID( kpreviouslevelid, Trim( hlevelname ), klevelid )
      if ( istatus == NF90_NOERR ) then
        gleveldefined = .true.
      else
        gleveldefined = .false.
        istatus = NF90_DEF_GRP( kpreviouslevelid, Trim( hlevelname ), klevelid )
        if ( istatus /= NF90_NOERR ) &
          call IO_Err_handle_nc4( istatus, 'Move_to_next_level', 'NF90_DEF_GRP', 'for ' // Trim( hlevelname ) )
      end if
    else
      gleveldefined = gpreviousleveldefined
      if ( Len_trim( hlevelname ) == 0 ) hlevelname = '(unused)'
      klevelid = kpreviouslevelid
    end if
    
    end subroutine Move_to_next_level