Ignore:
Timestamp:
Sep 27, 2023, 8:42:36 PM (14 months ago)
Author:
abierjon
Message:

Mars GCM:
Fix ticket #141 : when doing a log interpolation in zrecast (e.g. for density),
negative and null values are changed into a very small positive value (below
the numerical precision) so that the log interpolation yields a null value.

+ add '_FillValue' attribute (redundant with 'missing_value') checks and
outputs in zrecast to comply with newest NCO versions (part of ticket #152)

YL+AB

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.MARS/util/zrecast.F90

    r2567 r3057  
    15671567    stop
    15681568  endif
     1569  ierr=NF_PUT_ATT_REAL(outfid,za_varid,'_FillValue',NF_REAL,1,miss_val) ! redundant attribute for newer NCO versions
     1570  if (ierr.ne.NF_NOERR) then
     1571    write(*,*) "Error: Problem writing _FillValue for zareoid"
     1572    stop
     1573  endif
    15691574else ! above areoid or above local surface vertical coordinate
    15701575  ! pressure dataset
     
    15921597  if (ierr.ne.NF_NOERR) then
    15931598    write(*,*) "Error: Problem writing missing_value for pressure"
     1599    stop
     1600  endif
     1601  ierr=NF_PUT_ATT_REAL(outfid,p_varid,'_FillValue',NF_REAL,1,miss_val) ! redundant attribute for newer NCO versions
     1602  if (ierr.ne.NF_NOERR) then
     1603    write(*,*) "Error: Problem writing _FillValue for pressure"
    15941604    stop
    15951605  endif
     
    17121722    write(*,*) "Found missing_value ",miss_val
    17131723    j=j+1
    1714   else ! no 'missing_value' attribute, set miss_val to default
    1715     miss_val=miss_val_def
     1724  else ! no 'missing_value' attribute, look for '_FillValue' attribute
     1725    ierr=NF_GET_ATT_REAL(infid,tmpvarid,"_FillValue",miss_val)
     1726    if (ierr.eq.NF_NOERR) then ! found '_FillValue' attribute
     1727      write(*,*) "Found missing_value ",miss_val
     1728      j=j+1
     1729    else ! no 'missing_value' attribute, set miss_val to default
     1730      miss_val=miss_val_def
     1731    endif
    17161732  endif
    17171733 
     
    17201736  if (ierr.ne.NF_NOERR) then
    17211737    write(*,*) "Error, failed to write missing_value attribute"
     1738    stop
     1739  endif
     1740  ierr=NF_PUT_ATT_REAL(outfid,var_id(i),'_FillValue',NF_REAL,1,miss_val) ! redundant attribute for newer NCO versions
     1741  if (ierr.ne.NF_NOERR) then
     1742    write(*,*) "Error, failed to write _FillValue attribute"
    17221743    stop
    17231744  endif
     
    28642885        za(kloop)=z_gcm(iloop,jloop,kloop,tloop)
    28652886        ! store log values along altitude
    2866         logq(kloop)=log(gcmdata(iloop,jloop,kloop,tloop))
     2887        if (gcmdata(iloop,jloop,kloop,tloop).gt.0) then ! sanity check to handle small negative or null values
     2888          logq(kloop)=log(gcmdata(iloop,jloop,kloop,tloop))
     2889        else ! gcmdata<=0
     2890          logq(kloop)=-1000 ! yields a value of 1e-435 for q that is well below the numerical precision => 0
     2891        endif ! gcmdata>0
    28672892      enddo !kloop
    28682893     
     
    30283053        z(kloop)=z_gcm(iloop,jloop,kloop,tloop)
    30293054        ! store log values along altitude
    3030         logq(kloop)=log(gcmdata(iloop,jloop,kloop,tloop))
     3055        if (gcmdata(iloop,jloop,kloop,tloop).gt.0) then ! sanity check to handle small negative or null values
     3056          logq(kloop)=log(gcmdata(iloop,jloop,kloop,tloop))
     3057        else ! gcmdata<=0
     3058          logq(kloop)=-1000 ! yields a value of 1e-435 for q that is well below the numerical precision => 0
     3059        endif ! gcmdata>0
    30313060      enddo !kloop
    30323061     
Note: See TracChangeset for help on using the changeset viewer.