Changeset 2227 for trunk/LMDZ.MARS/util


Ignore:
Timestamp:
Jan 27, 2020, 7:40:05 PM (5 years ago)
Author:
abierjon
Message:

Mars GCM:
Bug fixes in localtime.F90 : 1) Following of the correction by EM (r2215), separation of the "valid_range" and "missing_value" indicators, which prevented localtime to write the missing_value attribute in the output file and was making r2215 useless ; 2) Altitude attributes written in the output file are no more specified by default but are read in input file (important for zrecasted files).
AB+EM

File:
1 edited

Legend:

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

    r2215 r2227  
    2727!character (len=1) :: ccopy
    2828! ccpy: 'y' or 'n' answer
    29 integer :: nid,ierr,miss
     29
     30character (len=50) :: altlong_name,altunits,altpositive
     31! altlong_name(): [netcdf] altitude "long_name" attribute
     32! altunits(): [netcdf] altitude "units" attribute
     33! altpositive(): [netcdf] altitude "positive" attribute
     34
     35integer :: nid,ierr,miss,validr
    3036! nid: [netcdf] file ID #
    3137! ierr: [netcdf] subroutine returned error code
     
    346352        stop
    347353      endif
     354! Get altitude attributes to handle files with any altitude type
     355ierr=nf_get_att_text(nid,altvar,'long_name',altlong_name)
     356ierr=nf_get_att_text(nid,altvar,'units',altunits)
     357ierr=nf_get_att_text(nid,altvar,'positive',altpositive)
    348358
    349359      if (ctllen .ne. 0) then
     
    489499   ! Initialize output file's lat,lon,alt and time dimensions
    490500     call initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen,&
     501           altlong_name,altunits,altpositive,&
    491502           nout,latdimout,londimout,altdimout,timedimout,timevarout)
    492503
     
    602613      ierr = NF_GET_VAR_DOUBLE(nid,varid,var3d)
    603614      miss=NF_GET_ATT_DOUBLE(nid,varid,"missing_value",missing)
    604       miss=NF_GET_ATT_DOUBLE(nid,varid,"valid_range",valid_range)
     615      validr=NF_GET_ATT_DOUBLE(nid,varid,"valid_range",valid_range)
    605616#else
    606617      ierr = NF_GET_VAR_REAL(nid,varid,var3d)
    607618      miss=NF_GET_ATT_REAL(nid,varid,"missing_value",missing)
    608       miss=NF_GET_ATT_REAL(nid,varid,"valid_range",valid_range)
     619      validr=NF_GET_ATT_REAL(nid,varid,"valid_range",valid_range)
    609620#endif
    610621
     
    679690      ! Write "valid_range" and "missing_value" attributes in output file
    680691      if (miss.eq.NF_NOERR) then
    681          call missing_value(nout,varidout,valid_range,missing)
     692         call missing_value(nout,varidout,validr,miss,valid_range,missing)
    682693      endif
    683694
     
    704715!******************************************************************************
    705716Subroutine initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen,&
     717                     altlong_name,altunits,altpositive,&
    706718                     nout,latdimout,londimout,altdimout,timedimout,timevarout)
    707719!==============================================================================
     
    731743real, intent(in):: ctl(ctllen)
    732744! ctl(): controle
     745character (len=*), intent(in) :: altlong_name
     746! altlong_name(): [netcdf] altitude "long_name" attribute
     747character (len=*), intent(in) :: altunits
     748! altunits(): [netcdf] altitude "units" attribute
     749character (len=*), intent(in) :: altpositive
     750! altpositive(): [netcdf] altitude "positive" attribute
    733751integer, intent(out):: nout
    734752! nout: [netcdf] file ID
     
    866884#endif
    867885
    868 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"long_name",8,"altitude")
    869 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'units',2,"km")
    870 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',2,"up")
     886ierr = NF_PUT_ATT_TEXT (nout,nvarid,'long_name',len_trim(adjustl(altlong_name)),adjustl(altlong_name))
     887ierr = NF_PUT_ATT_TEXT (nout,nvarid,'units',len_trim(adjustl(altunits)),adjustl(altunits))
     888ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',len_trim(adjustl(altpositive)),adjustl(altpositive))
    871889
    872890! End netcdf define mode
     
    921939!==============================================================================
    922940! Purpose:
    923 ! Copy aps(), bps() and phisinit() from input file to outpout file
     941! Copy aps(), bps() and phisinit() from input file to output file
    924942!==============================================================================
    925943! Remarks:
     
    11641182end subroutine def_var
    11651183!******************************************************************************
    1166 subroutine  missing_value(nout,nvarid,valid_range,missing)
     1184subroutine  missing_value(nout,nvarid,validr,miss,valid_range,missing)
    11671185!==============================================================================
    11681186! Purpose:
     
    11861204integer, intent(in) :: nvarid
    11871205! varid: [netcdf] variable ID #
     1206integer, intent(in) :: validr
     1207! validr : [netcdf] routines return code for "valid_range" attribute
     1208integer, intent(in) :: miss
     1209! miss : [netcdf] routines return code for "missing_value" attribute
    11881210real, dimension(2), intent(in) :: valid_range
    11891211! valid_range(2): [netcdf] "valid_range" attribute (min and max)
     
    12081230
    12091231! Write valid_range() attribute
    1210 #ifdef NC_DOUBLE
    1211 ierr=NF_PUT_ATT_DOUBLE(nout,nvarid,'valid_range',NF_DOUBLE,2,valid_range)
    1212 #else
    1213 ierr=NF_PUT_ATT_REAL(nout,nvarid,'valid_range',NF_FLOAT,2,valid_range)
    1214 #endif
    1215 
    1216 if (ierr.ne.NF_NOERR) then
    1217    print*,'missing_value: valid_range attribution failed'
    1218    print*, NF_STRERROR(ierr)
    1219    !write(*,*) 'NF_NOERR', NF_NOERR
    1220    !CALL abort
    1221    stop ""
     1232if (validr.eq.NF_NOERR) then
     1233#ifdef NC_DOUBLE
     1234  ierr=NF_PUT_ATT_DOUBLE(nout,nvarid,'valid_range',NF_DOUBLE,2,valid_range)
     1235#else
     1236  ierr=NF_PUT_ATT_REAL(nout,nvarid,'valid_range',NF_FLOAT,2,valid_range)
     1237#endif
     1238
     1239  if (ierr.ne.NF_NOERR) then
     1240     print*,'missing_value: valid_range attribution failed'
     1241     print*, NF_STRERROR(ierr)
     1242     !write(*,*) 'NF_NOERR', NF_NOERR
     1243     !CALL abort
     1244     stop ""
     1245  endif
    12221246endif
    12231247
    12241248! Write "missing_value" attribute
    1225 #ifdef NC_DOUBLE
    1226 ierr= NF_PUT_ATT_DOUBLE(nout,nvarid,'missing_value',NF_DOUBLE,1,missing)
    1227 #else
    1228 ierr= NF_PUT_ATT_REAL(nout,nvarid,'missing_value',NF_FLOAT,1,missing)
    1229 #endif
    1230 
    1231 if (ierr.NE.NF_NOERR) then
    1232    print*, 'missing_value: missing value attribution failed'
    1233    print*, NF_STRERROR(ierr)
    1234 !    WRITE(*,*) 'NF_NOERR', NF_NOERR
    1235 !    CALL abort
    1236    stop ""
     1249if (miss.eq.NF_NOERR) then
     1250#ifdef NC_DOUBLE
     1251  ierr= NF_PUT_ATT_DOUBLE(nout,nvarid,'missing_value',NF_DOUBLE,1,missing)
     1252#else
     1253  ierr= NF_PUT_ATT_REAL(nout,nvarid,'missing_value',NF_FLOAT,1,missing)
     1254#endif
     1255
     1256  if (ierr.NE.NF_NOERR) then
     1257     print*, 'missing_value: missing value attribution failed'
     1258     print*, NF_STRERROR(ierr)
     1259  !    WRITE(*,*) 'NF_NOERR', NF_NOERR
     1260  !    CALL abort
     1261     stop ""
     1262  endif
    12371263endif
    12381264
Note: See TracChangeset for help on using the changeset viewer.