Changeset 2204


Ignore:
Timestamp:
Jan 6, 2020, 11:17:44 AM (5 years ago)
Author:
emillour
Message:

Mars GCM utility:
Bug fix for when input file of the localtime utility is the ouput of zrecast and has aps()/bps() arrays which may not be of the same size as number of vertical layers.
EM+AD

File:
1 edited

Legend:

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

    r2147 r2204  
    115115
    116116!==============================================================================
    117 ! 1.3. Open the first input file
     117! 1.3. Open the input file
    118118!==============================================================================
    119119
    120120ierr = NF_OPEN(file,NF_NOWRITE,nid)
    121121if (ierr.NE.NF_NOERR) then
    122    write(*,*) 'ERROR: Pb opening file '//file
     122   write(*,*) 'ERROR: Pb opening file '//trim(file)
     123   write(*,*) NF_STRERROR(ierr)
    123124   stop ""
    124125endif
     
    126127ierr=NF_INQ_NVARS(nid,nbvarfile)
    127128! nbvarfile now set to be the (total) number of variables in file
    128 
    129 !==============================================================================
    130 ! 1.4. Ask for (output) "Time" axis type
     129if (ierr.NE.NF_NOERR) then
     130   write(*,*) 'ERROR: Pb with NF_INQ_NVARS'
     131   write(*,*) NF_STRERROR(ierr)
     132   stop ""
     133endif
     134
     135!==============================================================================
     136! 1.4. List of variables that should not be processed
    131137!==============================================================================
    132138
     
    148154
    149155!==============================================================================
    150 ! 1.5. Get (and check) list of variables to concatenate
     156! 1.5. Get (and check) list of variables to process
    151157!==============================================================================
    152158write(*,*)
     
    165171enddo
    166172
    167 ! Nnotconcat: # of variables that won't be concatenated
     173! Nnotconcat: # of variables that won't be processed
    168174! nbvarfile: total # of variables in file
    169 allocate(var(nbvarfile-Nnotconcat))
     175allocate(var(nbvarfile-Nnotconcat),stat=ierr)
     176if (ierr.ne.0) then
     177  write(*,*) "Error: failed allocation of var(nbvarfile-Nnotconcat)"
     178  write(*,*) "  nbvarfile=",nbvarfile
     179  write(*,*) "  Nnotconcat=",Nnotconcat
     180  stop
     181endif
    170182
    171183
     
    187199            ierr=nf_inq_varname(nid,j,var(j-Nnotconcat))
    188200         enddo
    189 ! Variables names from the file are catched
     201! Variables names from the file are stored in var()
    190202   nbvar=nbvarfile-Nnotconcat
    191203   do i=1,nbvar
     
    202214!==============================================================================
    203215 filename=file(1:len_trim(file)-3)//"_LT.nc"
    204  write(*,*) filename
     216 write(*,*) trim(filename)
    205217
    206218!==============================================================================
     
    208220!==============================================================================
    209221
    210    if (i/=1) then
    211222      write(*,*)
    212223      write(*,*) "opening "//trim(file)//"..."
    213224      ierr = NF_OPEN(file,NF_NOWRITE,nid)
    214225      if (ierr.NE.NF_NOERR) then
    215          write(*,*) 'ERROR: Pb opening file '//file
     226         write(*,*) 'ERROR: Pb opening file '//trim(file)
    216227         write(*,*) NF_STRERROR(ierr)
    217228         stop ""
    218229      endif
    219    endif
    220230
    221231!==============================================================================
     
    224234
    225235   ierr=NF_INQ_DIMID(nid,"latitude",latdim)
     236   if (ierr.NE.NF_NOERR) then
     237      write(*,*) 'ERROR: Dimension <latitude> is missing in file '//trim(file)
     238      stop "" 
     239   endif
    226240   ierr=NF_INQ_VARID(nid,"latitude",latvar)
    227241   if (ierr.NE.NF_NOERR) then
    228       write(*,*) 'ERROR: Field <latitude> is missing in file'//file
     242      write(*,*) 'ERROR: Field <latitude> is missing in file '//trim(file)
    229243      stop "" 
    230244   endif
     
    233247
    234248   ierr=NF_INQ_DIMID(nid,"longitude",londim)
     249   if (ierr.NE.NF_NOERR) then
     250      write(*,*) 'ERROR: Dimension <longitude> is missing in file '//trim(file)
     251      stop "" 
     252   endif
    235253   ierr=NF_INQ_VARID(nid,"longitude",lonvar)
    236254   if (ierr.NE.NF_NOERR) then
    237       write(*,*) 'ERROR: Field <longitude> is missing in file'//file
     255      write(*,*) 'ERROR: Field <longitude> is missing in file'//trim(file)
    238256      stop ""
    239257   endif
     
    242260
    243261   ierr=NF_INQ_DIMID(nid,"altitude",altdim)
     262   if (ierr.NE.NF_NOERR) then
     263      write(*,*) 'ERROR: Dimension <altitude> is missing in file '//trim(file)
     264      stop "" 
     265   endif
    244266   ierr=NF_INQ_VARID(nid,"altitude",altvar)
    245267   if (ierr.NE.NF_NOERR) then
    246       write(*,*) 'ERROR: Field <altitude> is missing in file'//file
     268      write(*,*) 'ERROR: Field <altitude> is missing in file'//trim(file)
    247269      stop ""
    248270   endif
     
    251273
    252274   ierr=NF_INQ_DIMID(nid,"index",ctldim)
     275   if (ierr.NE.NF_NOERR) then
     276      write(*,*) 'ERROR: Dimension <index> is missing in file '//trim(file)
     277      stop "" 
     278   endif
    253279   ierr=NF_INQ_VARID(nid,"controle",ctlvar)
    254280   if (ierr.NE.NF_NOERR) then
    255       write(*,*) 'Field <controle> is missing in file'//file
     281      write(*,*) 'Field <controle> is missing in file'//trim(file)
    256282      ctllen=0
    257283      !stop ""
     
    267293
    268294! First call; initialize/allocate
    269       allocate(lat(latlen))
    270       allocate(lon(lonlen))
    271       allocate(alt(altlen))
    272       allocate(ctl(ctllen))
     295      allocate(lat(latlen),stat=ierr)
     296      if (ierr.ne.0) then
     297        write(*,*) "Error: failed to allocate lat(latlen)"
     298        stop
     299      endif
     300      allocate(lon(lonlen),stat=ierr)
     301      if (ierr.ne.0) then
     302        write(*,*) "Error: failed to allocate lon(lonlen)"
     303        stop
     304      endif
     305      allocate(alt(altlen),stat=ierr)
     306      if (ierr.ne.0) then
     307        write(*,*) "Error: failed to allocate alt(altlen)"
     308        stop
     309      endif
     310      allocate(ctl(ctllen),stat=ierr)
     311      if (ierr.ne.0) then
     312        write(*,*) "Error: failed to allocate ctl(ctllen)"
     313        stop
     314      endif
     315
    273316#ifdef NC_DOUBLE
    274317      ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat)
     318#else
     319      ierr = NF_GET_VAR_REAL(nid,latvar,lat)
     320#endif
     321      if (ierr.ne.0) then
     322        write(*,*) "Error: failed to load latitude"
     323        write(*,*) NF_STRERROR(ierr)
     324        stop
     325      endif
     326
     327#ifdef NC_DOUBLE
    275328      ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon)
     329#else
     330      ierr = NF_GET_VAR_REAL(nid,lonvar,lon)
     331#endif
     332      if (ierr.ne.0) then
     333        write(*,*) "Error: failed to load longitude"
     334        write(*,*) NF_STRERROR(ierr)
     335        stop
     336      endif
     337
     338#ifdef NC_DOUBLE
    276339      ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt)
    277       if (ctllen .ne. -1) ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)
    278 #else
    279       ierr = NF_GET_VAR_REAL(nid,latvar,lat)
    280       ierr = NF_GET_VAR_REAL(nid,lonvar,lon)
     340#else
    281341      ierr = NF_GET_VAR_REAL(nid,altvar,alt)
    282       if (ctllen .ne. -1) ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)
    283 #endif
     342#endif
     343      if (ierr.ne.0) then
     344        write(*,*) "Error: failed to load altitude"
     345        write(*,*) NF_STRERROR(ierr)
     346        stop
     347      endif
     348
     349      if (ctllen .ne. 0) then
     350#ifdef NC_DOUBLE
     351        ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)
     352#else
     353        ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)
     354#endif
     355        if (ierr.ne.0) then
     356          write(*,*) "Error: failed to load controle"
     357          write(*,*) NF_STRERROR(ierr)
     358          stop
     359        endif
     360      endif ! of if (ctllen .ne. 0)
     361
    284362!==============================================================================
    285363! 2.4. Handle "Time" dimension from input file
     
    291369   ierr=NF_INQ_DIMID(nid,"Time",timedim)
    292370   if (ierr.NE.NF_NOERR) then
    293       write(*,*) 'ERROR: Dimension <Time> is missing in file'//file
     371      write(*,*) 'ERROR: Dimension <Time> is missing in file'//trim(file)
    294372      stop ""
    295373   endif
    296374   ierr=NF_INQ_VARID(nid,"Time",timevar)
    297375   if (ierr.NE.NF_NOERR) then
    298       write(*,*) 'ERROR: Field <Time> is missing in file'//file
     376      write(*,*) 'ERROR: Field <Time> is missing in file'//trim(file)
    299377      stop ""
    300378   endif
     
    313391
    314392   ! allocate time() array and fill it with values from input file
    315    allocate(time(timelen))
     393   allocate(time(timelen),stat=ierr)
     394   if (ierr.ne.0) then
     395     write(*,*) "Error: failed to allocate time(timelen)"
     396     stop
     397   endif
    316398
    317399#ifdef NC_DOUBLE
     
    322404   if (ierr.NE.NF_NOERR) then
    323405     write(*,*) "Error , failed to load Time"
     406     write(*,*) NF_STRERROR(ierr)
    324407     stop
    325408   endif
     
    331414      write(*,*) 'number of local time to be used ?'
    332415      read(*,*) nhour
    333       allocate(lt_hour(nhour))
     416      allocate(lt_hour(nhour),stat=ierr)
     417      if (ierr.ne.0) then
     418        write(*,*) "Error: failed to allocate lt_hour(nhour)"
     419        stop
     420      endif
    334421      write(*,*) 'list of selected local time (0<t<24)'
    335422      do it=1,nhour
     
    341428         stats=.true.
    342429         timelen_lt=nhour
    343          allocate(lt_out(timelen_lt))
     430         allocate(lt_out(timelen_lt),stat=ierr)
     431         if (ierr.ne.0) then
     432           write(*,*) "Error: failed to allocate lt_hour(nhour)"
     433           stop
     434         endif
    344435         do it=1,nhour
    345436           lt_out(it)=lt_hour(it)/24.
     
    355446        nsol = int(time(timelen)) - int(time(1))
    356447        timelen_lt=nhour*nsol
    357         allocate(lt_out(timelen_lt))
     448        allocate(lt_out(timelen_lt),stat=ierr)
     449        if (ierr.ne.0) then
     450           write(*,*) "Error: failed to allocate lt_hour(nhour)"
     451           stop
     452         endif
    358453        i=0
    359454        do k=1,nsol
     
    371466         timelen_tot=timelen+1
    372467      endif     
    373       allocate(lt_gcm(timelen_tot))
    374       allocate(var_gcm(timelen_tot))
    375 
    376       allocate(lt_outc(timelen_lt))
    377          
     468      allocate(lt_gcm(timelen_tot),stat=ierr)
     469      if (ierr.ne.0) then
     470        write(*,*) "Error: failed to allocate lt_gcm(timelen_tot)"
     471        stop
     472      endif
     473      allocate(var_gcm(timelen_tot),stat=ierr)
     474      if (ierr.ne.0) then
     475        write(*,*) "Error: failed to allocate var_gcm(timelen_tot)"
     476        stop
     477      endif
     478      allocate(lt_outc(timelen_lt),stat=ierr)
     479      if (ierr.ne.0) then
     480        write(*,*) "Error: failed to allocate lt_outc(timelen_lt)"
     481        stop
     482      endif
    378483
    379484!==============================================================================
     
    383488
    384489   ! Initialize output file's lat,lon,alt and time dimensions
    385       call initiate (filename,lat,lon,alt,ctl,nout,&
    386            latdimout,londimout,altdimout,timedimout,timevarout)
     490     call initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen,&
     491           nout,latdimout,londimout,altdimout,timedimout,timevarout)
     492
    387493   ! Initialize output file's aps,bps and phisinit variables
    388      call init2(nid,lonlen,latlen,altlen,&
     494     call init2(nid,lonlen,latlen,altlen,altdim,&
    389495                nout,londimout,latdimout,altdimout)
    390496
     
    454560         corner(4)=1
    455561
    456         ! length (along dimensions) of block of data to be written
     562        ! length (along dimensions) of block of data to be written
    457563         edges(1)=lonlen
    458564         edges(2)=latlen
     
    474580         corner(4)=1
    475581
    476         ! length (along dimensions) of block of data to be written
     582        ! length (along dimensions) of block of data to be written
    477583         edges(1)=lonlen
    478584         edges(2)=latlen
     
    481587      endif
    482588
    483          units="                                                    "
    484          title="                                                    "
     589         units=" "
     590         title=" "
    485591         ierr=nf_get_att_text(nid,varid,"title",title)
    486592         ierr=nf_get_att_text(nid,varid,"units",units)
     
    597703
    598704!******************************************************************************
    599 Subroutine initiate (filename,lat,lon,alt,ctl,&
     705Subroutine initiate(filename,lat,lon,alt,ctl,latlen,lonlen,altlen,ctllen,&
    600706                     nout,latdimout,londimout,altdimout,timedimout,timevarout)
    601707!==============================================================================
     
    616722character (len=*), intent(in):: filename
    617723! filename(): the file's name
    618 real, dimension(:), intent(in):: lat
     724real, intent(in):: lat(latlen)
    619725! lat(): latitude
    620 real, dimension(:), intent(in):: lon
     726real, intent(in):: lon(lonlen)
    621727! lon(): longitude
    622 real, dimension(:), intent(in):: alt
     728real, intent(in):: alt(altlen)
    623729! alt(): altitude
    624 real, dimension(:), intent(in):: ctl
     730real, intent(in):: ctl(ctllen)
    625731! ctl(): controle
     732integer,intent(in) ::latlen,lonlen,altlen,ctllen
    626733integer, intent(out):: nout
    627734! nout: [netcdf] file ID
     
    653760! NB: setting NF_CLOBBER mode means that it's OK to overwrite an existing file
    654761if (ierr.NE.NF_NOERR) then
    655    WRITE(*,*)'ERROR: Impossible to create the file.'
     762   WRITE(*,*)'ERROR: Impossible to create the file ',trim(filename)
     763   write(*,*) NF_STRERROR(ierr)
    656764   stop ""
    657765endif
     
    661769!==============================================================================
    662770
    663 ierr = NF_DEF_DIM(nout, "latitude", size(lat), latdimout)
    664 ierr = NF_DEF_DIM(nout, "longitude", size(lon), londimout)
    665 ierr = NF_DEF_DIM(nout, "altitude", size(alt), altdimout)
    666 if (size(ctl).ne.0) ierr = NF_DEF_DIM(nout, "index", size(ctl), ctldimout)
     771ierr = NF_DEF_DIM(nout, "latitude", latlen, latdimout)
     772if (ierr.NE.NF_NOERR) then
     773   WRITE(*,*)'initiate: error failed to define dimension <latitude>'
     774   write(*,*) NF_STRERROR(ierr)
     775   stop ""
     776endif
     777ierr = NF_DEF_DIM(nout, "longitude", lonlen, londimout)
     778if (ierr.NE.NF_NOERR) then
     779   WRITE(*,*)'initiate: error failed to define dimension <longitude>'
     780   write(*,*) NF_STRERROR(ierr)
     781   stop ""
     782endif
     783ierr = NF_DEF_DIM(nout, "altitude", altlen, altdimout)
     784if (ierr.NE.NF_NOERR) then
     785   WRITE(*,*)'initiate: error failed to define dimension <altitude>'
     786   write(*,*) NF_STRERROR(ierr)
     787   stop ""
     788endif
     789if (size(ctl).ne.0) then
     790  ierr = NF_DEF_DIM(nout, "index", ctllen, ctldimout)
     791  if (ierr.NE.NF_NOERR) then
     792    WRITE(*,*)'initiate: error failed to define dimension <index>'
     793    write(*,*) NF_STRERROR(ierr)
     794    stop ""
     795  endif
     796endif
    667797ierr = NF_DEF_DIM(nout, "Time", NF_UNLIMITED, timedimout)
     798if (ierr.NE.NF_NOERR) then
     799   WRITE(*,*)'initiate: error failed to define dimension <Time>'
     800   write(*,*) NF_STRERROR(ierr)
     801   stop ""
     802endif
    668803
    669804! End netcdf define mode
    670805ierr = NF_ENDDEF(nout)
     806if (ierr.NE.NF_NOERR) then
     807   WRITE(*,*)'initiate: error failed to switch out of define mode'
     808   write(*,*) NF_STRERROR(ierr)
     809   stop ""
     810endif
    671811
    672812!==============================================================================
     
    689829ierr = NF_PUT_VAR_REAL (nout,nvarid,lat)
    690830#endif
     831if (ierr.NE.NF_NOERR) then
     832   WRITE(*,*)'initiate: error failed writing variable <latitude>'
     833   write(*,*) NF_STRERROR(ierr)
     834   stop ""
     835endif
    691836
    692837!==============================================================================
     
    702847ierr = NF_PUT_VAR_REAL (nout,nvarid,lon)
    703848#endif
     849if (ierr.NE.NF_NOERR) then
     850   WRITE(*,*)'initiate: error failed writing variable <longitude>'
     851   write(*,*) NF_STRERROR(ierr)
     852   stop ""
     853endif
    704854
    705855!==============================================================================
     
    728878ierr = NF_PUT_VAR_REAL (nout,nvarid,alt)
    729879#endif
     880if (ierr.NE.NF_NOERR) then
     881   WRITE(*,*)'initiate: error failed writing variable <altitude>'
     882   write(*,*) NF_STRERROR(ierr)
     883   stop ""
     884endif
    730885
    731886!==============================================================================
     
    753908   ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl)
    754909#endif
     910   if (ierr.NE.NF_NOERR) then
     911      WRITE(*,*)'initiate: error failed writing variable <controle>'
     912      write(*,*) NF_STRERROR(ierr)
     913      stop ""
     914   endif
    755915endif
    756916
    757917end Subroutine initiate
    758918!******************************************************************************
    759 subroutine init2(infid,lonlen,latlen,altlen, &
     919subroutine init2(infid,lonlen,latlen,altlen,altdimid, &
    760920                 outfid,londimout,latdimout,altdimout)
    761921!==============================================================================
     
    777937integer, intent(in) :: lonlen ! # of grid points along longitude
    778938integer, intent(in) :: latlen ! # of grid points along latitude
    779 integer, intent(in) :: altlen ! # of grid points along latitude
     939integer, intent(in) :: altlen ! # of grid points along altitude
     940integer, intent(in) :: altdimid ! ID of altitude dimension
    780941integer, intent(in) :: outfid ! NetCDF output file ID
    781942integer, intent(in) :: londimout ! longitude dimension ID
     
    789950integer :: apsid,bpsid,phisinitid
    790951integer :: ierr
     952integer :: tmpdimid ! temporary dimension ID
    791953integer :: tmpvarid ! temporary variable ID
    792954logical :: phis, aps_ok, bps_ok ! are "phisinit" "aps" "bps" available ?
     
    798960
    799961! hybrid coordinate aps
    800   allocate(aps(altlen))
     962  allocate(aps(altlen),stat=ierr)
     963  if (ierr.ne.0) then
     964    write(*,*) "init2: failed to allocate aps(altlen)"
     965    stop
     966  endif
     967
    801968ierr=NF_INQ_VARID(infid,"aps",tmpvarid)
    802969if (ierr.ne.NF_NOERR) then
     
    804971  aps_ok=.false.
    805972else
    806   ierr=NF_GET_VAR_REAL(infid,tmpvarid,aps)
    807   if (ierr.ne.NF_NOERR) then
    808    stop "error: Failed reading aps"
     973  ! Check that aps() is the right size (it most likely won't be if
     974  ! zrecast has be used to generate the input file)
     975  ierr=NF_INQ_VARDIMID(infid,tmpvarid,tmpdimid)
     976  if (tmpdimid.ne.altdimid) then
     977    write(*,*) "init2: wrong dimension size for aps(), skipping it ..."
     978    aps_ok=.false.
     979  else
     980    ierr=NF_GET_VAR_REAL(infid,tmpvarid,aps)
     981    if (ierr.ne.NF_NOERR) then
     982     stop "init2 error: Failed reading aps"
     983    endif
     984    aps_ok=.true.
    809985  endif
    810   aps_ok=.true.
    811986endif
    812987
    813988! hybrid coordinate bps
    814   allocate(bps(altlen))
     989  allocate(bps(altlen),stat=ierr)
     990  if (ierr.ne.0) then
     991    write(*,*) "init2: failed to allocate bps(altlen)"
     992    stop
     993  endif
     994
    815995ierr=NF_INQ_VARID(infid,"bps",tmpvarid)
    816996if (ierr.ne.NF_NOERR) then
     
    818998  bps_ok=.false.
    819999else
    820   ierr=NF_GET_VAR_REAL(infid,tmpvarid,bps)
    821   if (ierr.ne.NF_NOERR) then
    822     stop "Error: Failed reading bps"
     1000  ! Check that bps() is the right size
     1001  ierr=NF_INQ_VARDIMID(infid,tmpvarid,tmpdimid)
     1002  if (tmpdimid.ne.altdimid) then
     1003    write(*,*) "init2: wrong dimension size for bps(), skipping it ..."
     1004    bps_ok=.false.
     1005  else
     1006    ierr=NF_GET_VAR_REAL(infid,tmpvarid,bps)
     1007    if (ierr.ne.NF_NOERR) then
     1008      stop "init2 Error: Failed reading bps"
     1009    endif
     1010    bps_ok=.true.
    8231011  endif
    824   bps_ok=.true.
    8251012endif
    8261013
    8271014! ground geopotential phisinit
     1015allocate(phisinit(lonlen,latlen),stat=ierr)
     1016if (ierr.ne.0) then
     1017  write(*,*) "init2: failed to allocate phisinit(lonlen,latlen)"
     1018  stop
     1019endif
    8281020ierr=NF_INQ_VARID(infid,"phisinit",tmpvarid)
    829 allocate(phisinit(lonlen,latlen))
    8301021if (ierr.ne.NF_NOERR) then
    8311022  write(*,*) "Failed to get phisinit ID. OK"
     
    8351026  ierr=NF_GET_VAR_REAL(infid,tmpvarid,phisinit)
    8361027  if (ierr.ne.NF_NOERR) then
    837     stop "Error: Failed reading phisinit"
     1028    stop "init2 Error: Failed reading phisinit"
    8381029  endif
    8391030  phis = .true.
     
    8501041
    8511042IF (aps_ok) then
    852 ! define aps
    853 call def_var(nout,"aps","hybrid pressure at midlayers"," ",1,&
    854              (/altdimout/),apsid,ierr)
    855 if (ierr.ne.NF_NOERR) then
    856   stop "Error: Failed to def_var aps"
    857 endif
    858 
    859 ! write aps
    860 #ifdef NC_DOUBLE
    861 ierr=NF_PUT_VAR_DOUBLE(outfid,apsid,aps)
    862 #else
    863 ierr=NF_PUT_VAR_REAL(outfid,apsid,aps)
    864 #endif
    865 if (ierr.ne.NF_NOERR) then
    866   stop "Error: Failed to write aps"
    867 endif
    868 ENDIF
     1043  ! define aps
     1044  call def_var(outfid,"aps","hybrid pressure at midlayers"," ",1,&
     1045               (/altdimout/),apsid,ierr)
     1046  if (ierr.ne.NF_NOERR) then
     1047    stop "Error: Failed to def_var aps"
     1048  endif
     1049
     1050  ! write aps
     1051#ifdef NC_DOUBLE
     1052  ierr=NF_PUT_VAR_DOUBLE(outfid,apsid,aps)
     1053#else
     1054  ierr=NF_PUT_VAR_REAL(outfid,apsid,aps)
     1055#endif
     1056  if (ierr.ne.NF_NOERR) then
     1057    stop "Error: Failed to write aps"
     1058  endif
     1059ENDIF ! of IF (aps_ok)
    8691060
    8701061IF (bps_ok) then
    871 ! define bps
    872 call def_var(nout,"bps","hybrid sigma at midlayers"," ",1,&
    873              (/altdimout/),bpsid,ierr)
    874 if (ierr.ne.NF_NOERR) then
    875   stop "Error: Failed to def_var bps"
    876 endif
    877 
    878 ! write bps
    879 #ifdef NC_DOUBLE
    880 ierr=NF_PUT_VAR_DOUBLE(outfid,bpsid,bps)
    881 #else
    882 ierr=NF_PUT_VAR_REAL(outfid,bpsid,bps)
    883 #endif
    884 if (ierr.ne.NF_NOERR) then
    885   stop "Error: Failed to write bps"
    886 endif
    887 ENDIF
     1062  ! define bps
     1063  call def_var(outfid,"bps","hybrid sigma at midlayers"," ",1,&
     1064               (/altdimout/),bpsid,ierr)
     1065  if (ierr.ne.NF_NOERR) then
     1066    stop "Error: Failed to def_var bps"
     1067  endif
     1068
     1069  ! write bps
     1070#ifdef NC_DOUBLE
     1071  ierr=NF_PUT_VAR_DOUBLE(outfid,bpsid,bps)
     1072#else
     1073  ierr=NF_PUT_VAR_REAL(outfid,bpsid,bps)
     1074#endif
     1075  if (ierr.ne.NF_NOERR) then
     1076    stop "Error: Failed to write bps"
     1077  endif
     1078ENDIF ! of IF (bps_ok)
    8881079
    8891080!==============================================================================
     
    8911082!==============================================================================
    8921083
    893 
    8941084IF (phis) THEN
    8951085
    896 !define phisinit
    897  call def_var(nout,"phisinit","Ground level geopotential"," ",2,&
    898             (/londimout,latdimout/),phisinitid,ierr)
    899  if (ierr.ne.NF_NOERR) then
     1086  !define phisinit
     1087  call def_var(outfid,"phisinit","Ground level geopotential"," ",2,&
     1088              (/londimout,latdimout/),phisinitid,ierr)
     1089  if (ierr.ne.NF_NOERR) then
    9001090     stop "Error: Failed to def_var phisinit"
    9011091  endif
    9021092
    903 ! write phisinit
    904 #ifdef NC_DOUBLE
    905 ierr=NF_PUT_VAR_DOUBLE(outfid,phisinitid,phisinit)
    906 #else
    907 ierr=NF_PUT_VAR_REAL(outfid,phisinitid,phisinit)
    908 #endif
    909 if (ierr.ne.NF_NOERR) then
    910   stop "Error: Failed to write phisinit"
    911 endif
    912 
    913 END IF
     1093  ! write phisinit
     1094#ifdef NC_DOUBLE
     1095  ierr=NF_PUT_VAR_DOUBLE(outfid,phisinitid,phisinit)
     1096#else
     1097  ierr=NF_PUT_VAR_REAL(outfid,phisinitid,phisinit)
     1098#endif
     1099  if (ierr.ne.NF_NOERR) then
     1100    stop "Error: Failed to write phisinit"
     1101  endif
     1102
     1103ENDIF ! of IF (phis)
    9141104
    9151105
     
    10511241
    10521242end subroutine  missing_value
    1053 !******************************************************************************
    1054 
    1055 end program localtime
    10561243
    10571244!*****************************************************************************
     
    10961283end subroutine interpolf
    10971284
     1285!******************************************************************************
     1286
     1287end program localtime
     1288
Note: See TracChangeset for help on using the changeset viewer.