Changeset 1073


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.

Location:
trunk/LMDZ.MARS/util
Files:
4 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)
  • trunk/LMDZ.MARS/util/localtime.F90

    r410 r1073  
    3535integer :: varid
    3636! varid: [netcdf] variable ID #
    37 real, dimension(:), allocatable:: lat,lon,alt,time
     37real, dimension(:), allocatable:: lat,lon,alt,ctl,time
    3838! lat(): array, stores latitude coordinates
    3939! lon(): array, stores longitude coordinates
    4040! alt(): array, stores altitude coordinates
     41! ctl(): array, stores controle array
    4142! time(): array, stores time coordinates
    4243integer :: nbvar,nbvarfile,ndim
     
    4546! nbvarfile: total # of variables in an input file
    4647! ndim: [netcdf] # (3 or 4) of dimensions (for variables)
    47 integer :: latdim,londim,altdim,timedim
     48integer :: latdim,londim,altdim,ctldim,timedim
    4849! latdim: [netcdf] "latitude" dim ID
    4950! londim: [netcdf] "longitude" dim ID
    5051! altdim: [netcdf] "altdim" dim ID
     52! ctldim: [netcdf] "controle" dim ID
    5153! timedim: [netcdf] "timedim" dim ID
    52 integer :: latvar,lonvar,altvar,timevar
     54integer :: latvar,lonvar,altvar,ctlvar,timevar
    5355! latvar: [netcdf] ID of "latitude" variable
    5456! lonvar: [netcdf] ID of "longitude" variable
    5557! altvar: [netcdf] ID of "altitude" variable
     58! ctlvar: [netcdf] ID of "controle" variable
    5659! timevar: [netcdf] ID of "Time" variable
    57 integer :: latlen,lonlen,altlen,timelen,timelen_lt,timelen_tot
     60integer :: latlen,lonlen,altlen,ctllen,timelen,timelen_lt,timelen_tot
    5861integer :: ilat,ilon,ialt,it
    5962! latlen: # of elements of lat() array
    6063! lonlen: # of elements of lon() array
    6164! altvar: # of elements of alt() array
     65! ctlvar: # of elements of ctl() array
    6266! timelen: # of elemnets of time() array
    6367! timelen_tot:# =timelen or timelen+1 (if 1 more time to interpolate needed)
     
    246250!  write(*,*) "altlen: ",altlen
    247251
     252   ierr=NF_INQ_DIMID(nid,"index",ctldim)
     253   ierr=NF_INQ_VARID(nid,"controle",ctlvar)
     254   if (ierr.NE.NF_NOERR) then
     255      write(*,*) 'Field <controle> is missing in file'//file
     256      ctllen=0
     257      !stop ""
     258   else
     259      ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen)
     260   endif
     261!  write(*,*) "controle: ",controle
     262
    248263!==============================================================================
    249264! 2.3. Read (and check compatibility of) dimensions of
     
    255270      allocate(lon(lonlen))
    256271      allocate(alt(altlen))
     272      allocate(ctl(ctllen))
    257273#ifdef NC_DOUBLE
    258274      ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat)
    259275      ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon)
    260276      ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt)
     277      if (ctllen .ne. -1) ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)
    261278#else
    262279      ierr = NF_GET_VAR_REAL(nid,latvar,lat)
    263280      ierr = NF_GET_VAR_REAL(nid,lonvar,lon)
    264281      ierr = NF_GET_VAR_REAL(nid,altvar,alt)
     282      if (ctllen .ne. -1) ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)
    265283#endif
    266284!==============================================================================
     
    351369
    352370   ! Initialize output file's lat,lon,alt and time dimensions
    353       call initiate (filename,lat,lon,alt,nout,&
     371      call initiate (filename,lat,lon,alt,ctl,nout,&
    354372           latdimout,londimout,altdimout,timedimout,timevarout)
    355373   ! Initialize output file's aps,bps and phisinit variables
     
    561579
    562580!******************************************************************************
    563 Subroutine initiate (filename,lat,lon,alt,&
     581Subroutine initiate (filename,lat,lon,alt,ctl,&
    564582                     nout,latdimout,londimout,altdimout,timedimout,timevarout)
    565583!==============================================================================
     
    586604real, dimension(:), intent(in):: alt
    587605! alt(): altitude
     606real, dimension(:), intent(in):: ctl
     607! ctl(): controle
    588608integer, intent(out):: nout
    589609! nout: [netcdf] file ID
     
    604624!integer :: latdim,londim,altdim,timedim
    605625integer :: nvarid,ierr
     626integer :: ctldimout
    606627! nvarid: [netcdf] ID of a variable
    607628! ierr: [netcdf]  return error code (from called subroutines)
     
    625646ierr = NF_DEF_DIM(nout, "longitude", size(lon), londimout)
    626647ierr = NF_DEF_DIM(nout, "altitude", size(alt), altdimout)
     648if (size(ctl).ne.0) ierr = NF_DEF_DIM(nout, "index", size(ctl), ctldimout)
    627649ierr = NF_DEF_DIM(nout, "Time", NF_UNLIMITED, timedimout)
    628650
     
    664686
    665687!==============================================================================
    666 ! 4. Write "altitude" (data and attributes)
     688! 5. Write "altitude" (data and attributes)
    667689!==============================================================================
    668690
     
    688710ierr = NF_PUT_VAR_REAL (nout,nvarid,alt)
    689711#endif
     712
     713!==============================================================================
     714! 6. Write "controle" (data and attributes)
     715!==============================================================================
     716
     717if (size(ctl).ne.0) then
     718   ! Switch to netcdf define mode
     719   ierr = NF_REDEF (nout)
     720
     721   #ifdef NC_DOUBLE
     722   ierr = NF_DEF_VAR (nout,"controle",NF_DOUBLE,1,ctldimout,nvarid)
     723   #else
     724   ierr = NF_DEF_VAR (nout,"controle",NF_FLOAT,1,ctldimout,nvarid)
     725   #endif
     726
     727   ierr = NF_PUT_ATT_TEXT (nout,nvarid,"title",18,"Control parameters")
     728
     729   ! End netcdf define mode
     730   ierr = NF_ENDDEF(nout)
     731
     732   #ifdef NC_DOUBLE
     733   ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,ctl)
     734   #else
     735   ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl)
     736   #endif
     737endif
    690738
    691739end Subroutine initiate
  • trunk/LMDZ.MARS/util/lslin.F90

    r410 r1073  
    1010! Modified by Ehouarn Millour 10/2007 (changed evaluation of 'start_var'
    1111! from hard-coded values to a computed value)
     12! Read controle field, if available TN, October 2013
     13
    1214
    1315implicit none
     
    109111read(*,'(a50)') infile
    110112
    111 write(*,*) "Is it a concatnc file? (y/n)?"
     113!write(*,*) "Is it a concatnc file? (y/n)?"
     114write(*,*) "Do you want to specify the beginning day of the file"
     115write(*,*) "in case the controle field is not present ? (y/n)?"
    112116read(*,*) answer
    113117if ((answer=="y").or.(answer=="Y")) then
    114    write(*,*) "Beginning day of the concatnc file?"
     118   write(*,*) "Beginning day of the file?"
    115119   read(*,*) reptime
    116120!   start_var=8 ! 'concatnc' type of file
     
    311315   endif
    312316
    313    day_ini = tab_cntrl(4)                                                     
     317   day_ini = tab_cntrl(4)                                               
     318   day_ini = modulo(day_ini,669)                                                   
    314319   write(*,*) 'day_ini', day_ini
    315320else
  • trunk/LMDZ.MARS/util/zrecast.F90

    r909 r1073  
    6060!              constants (radius, R, etc.) are now read from file
    6161! TN 01/2013 : Adapted for large output files with at least 2 variables > 2 GiB
     62! TN 10/2013 : Read and write controle field, if available
    6263!
    6364implicit none
     
    8081integer nbvar4dinfile ! # of 4D (lon,lat,alt,time) variables in input file
    8182integer outfid ! NetCDF output file ID
    82 integer lon_dimid,lat_dimid,alt_dimid,time_dimid ! NetCDF dimension IDs
    83 integer lon_varid,lat_varid,alt_varid,time_varid
     83integer lon_dimid,lat_dimid,alt_dimid,time_dimid,ctl_dimid ! NetCDF dimension IDs
     84integer lon_varid,lat_varid,alt_varid,time_varid,ctl_varid
    8485integer gcm_layers_dimid ! NetCDF dimension ID for # of layers in GCM
    8586integer sigma_varid,aps_varid,bps_varid
     
    103104integer latlength ! # of grid points along latitude
    104105integer altlength ! # of grid point along altitude (of input datasets)
     106real,dimension(:),allocatable :: ctl ! controle
     107integer ctllength ! # of grid points along controle
    105108real,dimension(:),allocatable :: time ! time
    106109integer timelength ! # of points along time
     
    439442  if (ierr.ne.NF_NOERR) then
    440443      stop "Error: Failed to get altitude length"
     444  endif
     445endif
     446
     447! controle
     448ierr=NF_INQ_DIMID(infid,"index",tmpdimid)
     449if (ierr.ne.NF_NOERR) then
     450  write(*,*) "Could not get controle dimension ID"
     451  ctllength = 0
     452else
     453  ierr=NF_INQ_VARID(infid,"controle",tmpvarid)
     454  if (ierr.ne.NF_NOERR) then
     455    stop "Error: Failed to get controle ID"
     456  else
     457    ierr=NF_INQ_DIMLEN(infid,tmpdimid,ctllength)
     458    if (ierr.ne.NF_NOERR) then
     459      stop "Error: Failed to get controle length"
     460    else
     461      allocate(ctl(ctllength),stat=ierr)
     462      if (ierr.ne.0) then
     463        write(*,*) "Error: Failed to allocate ctl(ctllength)"
     464        write(*,*) "     ctllength=",ctllength
     465        stop
     466      endif
     467      ierr=NF_GET_VAR_REAL(infid,tmpvarid,ctl)
     468      if (ierr.ne.NF_NOERR) then
     469        stop "Error: Failed reading controle"
     470      endif
     471    endif
    441472  endif
    442473endif
     
    10301061endif
    10311062
     1063! controle
     1064if (ctllength .ne. 0) then
     1065  ierr=NF_DEF_DIM(outfid,"index",ctllength,ctl_dimid)
     1066  if (ierr.ne.NF_NOERR) then
     1067    write(*,*) "Error: Could not define controle dimension"
     1068    write(*,*) NF_STRERROR(ierr)
     1069    stop
     1070  endif
     1071endif
     1072
    10321073! GCM layers (for sigma or aps and bps)
    10331074ierr=NF_DEF_DIM(outfid,"GCM_layers",altlength,gcm_layers_dimid)
     
    11621203  endif
    11631204endif ! of if (have_sigma)
     1205
     1206! controle
     1207if (ctllength .ne. 0) then
     1208  ierr=NF_DEF_VAR(outfid,"controle",NF_REAL,1,ctl_dimid,ctl_varid)
     1209  if (ierr.ne.NF_NOERR) then
     1210    write(*,*) "Error: Could not define controle variable"
     1211    write(*,*) NF_STRERROR(ierr)
     1212    stop
     1213  endif
     1214
     1215  ! controle attributes
     1216  text='Control parameters'
     1217  ierr=NF_PUT_ATT_TEXT(outfid,ctl_varid,'title',len_trim(text),text)
     1218  if (ierr.ne.NF_NOERR) then
     1219    stop "Error: Problem writing title for controle"
     1220  endif
     1221endif
    11641222
    11651223! GCM_layers
     
    15091567endif
    15101568
     1569! Write controle
     1570if (ctllength .ne. 0) then
     1571  ierr=NF_PUT_VAR_REAL(outfid,ctl_varid,ctl)
     1572  if (ierr.ne.NF_NOERR) then
     1573    write(*,*) "Error: Could not write controle data to output file"
     1574    write(*,*) NF_STRERROR(ierr)
     1575    stop
     1576  endif
     1577endif
     1578
    15111579! Write time
    15121580ierr=NF_PUT_VARA_REAL(outfid,time_varid,1,timelength,time)
     
    17711839subroutine init_planet_const(infid)
    17721840! initialize planetary constants using the "controle" array in the file
    1773 ! if "cointrole" array not found in file, look for it in "diagfi.nc"
     1841! if "controle" array not found in file, look for it in "diagfi.nc"
    17741842use planet_const
    17751843use netcdf
Note: See TracChangeset for help on using the changeset viewer.