TNO Intern

Commit 14dddfa1 authored by Arjo Segers's avatar Arjo Segers
Browse files

Keep fill-values when unpacking 2D real variable.

parent dcb64c35
Loading
Loading
Loading
Loading
+33 −8
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@
!   Renamed 'start' and 'count' arguments to 'vstart' and 'vcount' 
!   to avoid that compiler gets confused with 'count()' function ...
!
! 2026-07, Arjo Segers
!   Keep fill-values when unpacking 2D real variable.
!
!
!###############################################################################
!
@@ -3524,6 +3527,8 @@ contains
    integer                 ::  varid
    integer, allocatable    ::  dimids(:)
    real                    ::  add_offset, scale_factor
    real                    ::  fill_value__packed
    real                    ::  fill_value

    ! --- begin ----------------------------------

@@ -3627,17 +3632,37 @@ contains

    ! packed?
    call self%Inq_VarPacking( varid, add_offset, scale_factor, status )
    IF_ERROR_RETURN(status=1)
    if ( status == 0 ) then
      ! unpack:

      ! default fill value:
      fill_value = - huge(real(1.0))

      ! missing value attribute? status<0 if not defined:
      call self%Inq_VarMissing( varid, fill_value__packed, status )
      if ( status < 0 ) then
        ! unpack, no fill values:
        values = add_offset + scale_factor * values
      else
        ! unpack, take care of fill values:
        where ( values /= fill_value__packed )
          values = add_offset + scale_factor * values
        elsewhere
          values = fill_value
        endwhere
      end if

    ! Missing value?
    if ( present( missing_value ) ) then
      call self%Inq_VarMissing( varid, missing_value, status )
    else if ( status == 0 ) then

      ! missing value attribute? status<0 if not defined:
      call self%Inq_VarMissing( varid, fill_value, status )
      IF_ERROR_RETURN(status=1)
    end if

    else
      TRACEBACK; status=1; return
    end if ! packed?

    ! return missing value?
    if ( present( missing_value ) ) missing_value = fill_value

    ! get units:
    call self%Inq_VarUnits( varid, description, units, status )