Ignore:
Timestamp:
Oct 17, 2013, 4:19:26 PM (11 years ago)
Author:
tnavarro
Message:

Better handling of the first date of the file : Read and write the controle field, if possible, for zrecast, localtime and concatnc + cosmetic change in lslin. This is retrocompatible with previous versions.

File:
1 edited

Legend:

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

    r632 r1073  
    1818! + handle absence of ap() and bp() if aps and bps are available
    1919!    (case of stats file) FF, November 2011
     20! + read and write controle field, if available. TN, October 2013
    2021! ********************************************************
    2122
     
    5455! memolonlen: # of elements of lon(), read from the first input file
    5556! memoaltlen: # of elements of alt(), read from the first input file
    56 real, dimension(:), allocatable:: lat,lon,alt,time
     57real, dimension(:), allocatable:: lat,lon,alt,ctl,time
    5758! lat(): array, stores latitude coordinates
    5859! lon(): array, stores longitude coordinates
    5960! alt(): array, stores altitude coordinates
     61! ctl(): array, stores controle coordinates
    6062! time(): array, stores time coordinates
    6163integer :: nbvar,nbfile,nbvarfile,ndim
     
    6466! nbvarfile: total # of variables in an input file
    6567! ndim: [netcdf] # (3 or 4) of dimensions (for variables)
    66 integer :: latdim,londim,altdim,timedim
     68integer :: latdim,londim,altdim,ctldim,timedim
    6769! latdim: [netcdf] "latitude" dim ID
    6870! londim: [netcdf] "longitude" dim ID
    6971! altdim: [netcdf] "altdim" dim ID
     72! ctldim: [netcdf] "ctldim" dim ID
    7073! timedim: [netcdf] "timedim" dim ID
    7174integer :: gcmlayerdim ! NetCDF dimension ID for # of layers in GCM
    72 integer :: latvar,lonvar,altvar,timevar
     75integer :: latvar,lonvar,altvar,ctlvar,timevar
    7376! latvar: [netcdf] ID of "latitude" variable
    7477! lonvar: [netcdf] ID of "longitude" variable
    7578! altvar: [netcdf] ID of "altitude" variable
     79! ctlvar: [netcdf] ID of "controle" variable
    7680! timevar: [netcdf] ID of "Time" variable
    77 integer :: latlen,lonlen,altlen,timelen
     81integer :: latlen,lonlen,altlen,ctllen,timelen
    7882! latlen: # of elements of lat() array
    7983! lonlen: # of elements of lon() array
    80 ! altvar: # of elements of alt() array
     84! altlen: # of elements of alt() array
     85! ctllen: # of elements of ctl() array
    8186! timelen: # of elemnets of time() array
    8287integer :: GCM_layers ! number of GCM atmospheric layers (may not be
     
    141146!write(*,*) "Beginning day of the first specified file?"
    142147write(*,*) "Starting day of the run stored in the first input file?"
     148write(*,*) " (Obsolete if the controle field is present, answer any number)"
    143149write(*,*) "(e.g.: 100 if that run started at time=100 sols)"
    144150read(*,*) memotime
     
    320326!  write(*,*) "altlen: ",altlen
    321327
     328   ierr=NF_INQ_DIMID(nid,"index",ctldim)
     329   ierr=NF_INQ_VARID(nid,"controle",ctlvar)
     330   if (ierr.NE.NF_NOERR) then
     331      write(*,*) 'Field <controle> is missing in file'//file
     332      ctllen=0
     333      !stop ""
     334   else
     335      ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen)
     336   endif
     337!  write(*,*) "controle: ",controle
     338
    322339! load size of aps() or sigma() (in case it is not altlen)
    323340   ! default is that GCM_layers=altlen
     
    345362      allocate(lon(lonlen))
    346363      allocate(alt(altlen))
     364      allocate(ctl(ctllen))
    347365#ifdef NC_DOUBLE
    348366      ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat)
    349367      ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon)
    350368      ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt)
     369      if (ctllen .ne. -1) ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)
    351370#else
    352371      ierr = NF_GET_VAR_REAL(nid,latvar,lat)
    353372      ierr = NF_GET_VAR_REAL(nid,lonvar,lon)
    354373      ierr = NF_GET_VAR_REAL(nid,altvar,alt)
    355 #endif
     374      if (ctllen .ne. -1) ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)
     375#endif
     376      if (ctllen .ne. -1) then
     377         if (modulo(int(memotime),669)/=modulo(int(ctl(4)),669)) then
     378           write(*,'(2(A,I4),A)') "WARNING: Starting day of the run is not ",&
     379                                modulo(int(memotime),669)," but ",modulo(int(ctl(4)),669),"!!"
     380           write(*,*) "Starting day of the run has been corrected."
     381           memotime=float(modulo(int(ctl(4)),669))
     382         endif
     383      endif
    356384   ! Initialize output file's lat,lon,alt and time dimensions
    357       call initiate (filename,lat,lon,alt,GCM_layers,nout,&
     385      call initiate (filename,lat,lon,alt,ctl,GCM_layers,nout,&
    358386       latdimout,londimout,altdimout,timedimout,&
    359387       layerdimout,interlayerdimout,timevarout)
     
    570598
    571599!******************************************************************************
    572 subroutine initiate (filename,lat,lon,alt,GCM_layers,nout,&
     600subroutine initiate (filename,lat,lon,alt,ctl,GCM_layers,nout,&
    573601         latdimout,londimout,altdimout,timedimout,&
    574602         layerdimout,interlayerdimout,timevarout)
     
    596624real, dimension(:), intent(in):: alt
    597625! alt(): altitude
     626real, dimension(:), intent(in):: ctl
     627! ctl(): controle
    598628integer,intent(in) :: GCM_layers ! number of GCM layers
    599629integer, intent(out):: nout
     
    619649!integer :: latdim,londim,altdim,timedim
    620650integer :: nvarid,ierr
     651integer :: ctldimout
    621652! nvarid: [netcdf] ID of a variable
    622653! ierr: [netcdf]  return error code (from called subroutines)
     
    640671ierr = NF_DEF_DIM(nout, "longitude", size(lon), londimout)
    641672ierr = NF_DEF_DIM(nout, "altitude", size(alt), altdimout)
     673if (size(ctl).ne.0) ierr = NF_DEF_DIM(nout, "index", size(ctl), ctldimout)
    642674ierr = NF_DEF_DIM(nout, "Time", NF_UNLIMITED, timedimout)
    643675ierr = NF_DEF_DIM(nout, "GCM_layers", GCM_layers, layerdimout)
     
    681713
    682714!==============================================================================
    683 ! 4. Write "altitude" (data and attributes)
     715! 5. Write "altitude" (data and attributes)
    684716!==============================================================================
    685717
     
    704736#else
    705737ierr = NF_PUT_VAR_REAL (nout,nvarid,alt)
    706 #endif
     738#endif
     739
     740!==============================================================================
     741! 6. Write "controle" (data and attributes)
     742!==============================================================================
     743
     744if (size(ctl).ne.0) then
     745   ! Switch to netcdf define mode
     746   ierr = NF_REDEF (nout)
     747
     748   #ifdef NC_DOUBLE
     749   ierr = NF_DEF_VAR (nout,"controle",NF_DOUBLE,1,ctldimout,nvarid)
     750   #else
     751   ierr = NF_DEF_VAR (nout,"controle",NF_FLOAT,1,ctldimout,nvarid)
     752   #endif
     753
     754   ierr = NF_PUT_ATT_TEXT (nout,nvarid,"title",18,"Control parameters")
     755
     756   ! End netcdf define mode
     757   ierr = NF_ENDDEF(nout)
     758
     759   #ifdef NC_DOUBLE
     760   ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,ctl)
     761   #else
     762   ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl)
     763   #endif
     764endif
    707765
    708766end Subroutine initiate
     
    11621220do i=1,timelen-1
    11631221   if ((ls(i+1)-ls(i)) > 350) then
    1164        write(*,*) "+ 360° Ls jump solved:", ls(i), ls(i+1), "at timestep", i
     1222       write(*,*) "+ 360 deg Ls jump solved:", ls(i), ls(i+1), "at timestep", i
    11651223      ls(i+1) = ls(i+1) - 360
    11661224       write(*,*) " corrected to now be:", ls(i), ls(i+1)
    11671225   else if ((ls(i)-ls(i+1)) > 350) then
    1168        write(*,*) "- 360° Ls jump solved:", ls(i), ls(i+1), "at timestep", i
     1226       write(*,*) "- 360 deg Ls jump solved:", ls(i), ls(i+1), "at timestep", i
    11691227      ls(i+1) = ls(i+1) + 360
    11701228       write(*,*) " corrected to now be:", ls(i), ls(i+1)
Note: See TracChangeset for help on using the changeset viewer.