Changeset 2308 for trunk/LMDZ.MARS/util


Ignore:
Timestamp:
May 4, 2020, 11:07:20 PM (5 years ago)
Author:
abierjon
Message:

Mars GCM:
Following r2303 (concatenate concat files) and truly resolving Ticket #46 :
1) little bugs fixed from the previous revision ; 2) add the possibility to change the
offset of the output file time axis by asking the user the new offset and the level of
priority to put on it over the starting day stored in the first input file
(NB: this last point also implies a change in concatnc.def, but retrocompatibility
with old concatnc.def files has been ensured)

AB

Location:
trunk/LMDZ.MARS/util
Files:
2 edited

Legend:

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

    r2303 r2308  
    2020! + read and write controle field, if available. TN, October 2013
    2121! + possibility to concatenate concat files with a coherent
    22 !   time axis in the output. AB, April 2020
     22!   time axis in the output, and to redistribute the time axis
     23!   from an offset given by the user. AB, April 2020
    2324! ********************************************************
    2425
     
    116117real :: memotime
    117118! memotime: (cumulative) time value, in martian days (sols)
     119real :: starttimeoffset
     120! starttimeoffset: offset given by the user for the output time axis
     121character (len=1) :: firstsol
     122! firstsol: =[y/n], to know whether the user offset or the first file's starting day must be used in the output
    118123real :: missing
    119124!PARAMETER(missing=1E+20)
     
    126131!==============================================================================
    127132write(*,*)
    128 write(*,*) "-- Program written specifically for NetCDF 'diagfi'/'concat' files from the martian GCM --"
     133write(*,*) "-- Program written specifically for NetCDF 'diagfi'/'concat' files"
     134write(*,*) "                     from the martian GCM --"
    129135write(*,*)
    130136write(*,*) "which files do you want to use?"
     
    145151
    146152!==============================================================================
    147 ! 1.2. Ask for starting day value (memotime)
     153! 1.2. Ask for starting day value (starttimeoffset)
    148154!==============================================================================
    149155
    150156write(*,*)
    151 !write(*,*) "Beginning day of the first specified file?"
    152 write(*,*) "Starting day of the run stored in the first input file?"
    153 write(*,*) " (Obsolete if the controle field is present, answer any number)"
    154 write(*,*) "(e.g.: 100 if that run started at time=100 sols)"
    155 read(*,*) memotime
     157write(*,*) "Starting day to be stored in the output file time axis?"
     158write(*,*) "(e.g.: 100 if you want the output file to start at time=100 sols)"
     159read(*,*) starttimeoffset
    156160
    157161!==============================================================================
     
    174178!==============================================================================
    175179
     180write(*,*)
    176181write(*,*) "Warning: to read the result with grads, choose sol"
    177182write(*,*) "Warning: use ferret to read the non linear scale ls"
     
    322327! 2.2. Read (and check) dimensions of variables from input file
    323328!==============================================================================
    324 
     329!==============================================================================
     330! 2.2.1 Lat, lon, alt, GCM_layers
     331!==============================================================================
    325332   ierr=NF_INQ_DIMID(nid,"latitude",latdim)
    326333   ierr=NF_INQ_VARID(nid,"latitude",latvar)
     
    349356   ierr=NF_INQ_DIMLEN(nid,altdim,altlen)
    350357!  write(*,*) "altlen: ",altlen
    351 
    352    ierr=NF_INQ_DIMID(nid,"index",ctldim)
    353    ierr=NF_INQ_VARID(nid,"controle",ctlvar)
    354    if (ierr.NE.NF_NOERR) then
    355       write(*,*) 'Field <controle> is missing in file '//file(i)
    356       ctllen=0
    357       !stop ""
    358    else
    359       ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen)
    360    endif
    361 !  write(*,*) "controle: ",controle
    362358
    363359! load size of aps() or sigma() (in case it is not altlen)
     
    375371
    376372!==============================================================================
     373! 2.2.1 Check presence and read "controle" dimension & variable from input file
     374!==============================================================================
     375   ierr=NF_INQ_DIMID(nid,"index",ctldim)
     376   if (ierr.NE.NF_NOERR) then
     377      write(*,*) 'Dimension <index> is missing in file '//file(i)
     378      write(*,*) "The program continues..."
     379      ctllen=0
     380      !stop ""
     381   else
     382      ierr=NF_INQ_VARID(nid,"controle",ctlvar)
     383      if (ierr.NE.NF_NOERR) then
     384         write(*,*) 'Field <controle> is missing in file '//file(i)
     385         write(*,*) "The program continues..."
     386         ctllen=0
     387         !stop ""
     388      else
     389         ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen)
     390      endif
     391   endif
     392!  write(*,*) "controle: ",controle
     393
     394   if (ctllen .ne. 0) then ! variable controle
     395      allocate(ctl(ctllen))
     396#ifdef NC_DOUBLE
     397      ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)
     398#else
     399      ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)
     400#endif
     401      ctlsol = ctl(4)
     402   endif
     403
     404!==============================================================================
     405! 2.3 Read "Time" dimension & variable from input file
     406!==============================================================================
     407   ierr=NF_INQ_DIMID(nid,"Time",timedim)
     408   if (ierr.NE.NF_NOERR) then
     409      write(*,*) 'ERROR: Dimension <Time> is missing in file '//file(i)
     410      stop ""
     411   endif
     412   ierr=NF_INQ_VARID(nid,"Time",timevar)
     413   if (ierr.NE.NF_NOERR) then
     414      write(*,*) 'ERROR: Field <Time> is missing in file '//file(i)
     415      stop ""
     416   endif
     417   ierr=NF_INQ_DIMLEN(nid,timedim,timelen)
     418!  write(*,*) "timelen: ",timelen
     419
     420   ! allocate time() array and fill it with values from input file
     421   allocate(time(timelen))
     422
     423#ifdef NC_DOUBLE
     424   ierr = NF_GET_VAR_DOUBLE(nid,timevar,time)
     425#else
     426   ierr = NF_GET_VAR_REAL(nid,timevar,time)
     427#endif
     428
     429
     430!==============================================================================
    377431! 2.3. Read (and check compatibility of) dimensions of
    378432!       variables from input file
    379433!==============================================================================
    380 
    381    if (ctllen .ne. 0) then ! variable controle
    382       allocate(ctl(ctllen))
    383 #ifdef NC_DOUBLE
    384       ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)
    385 #else
    386       ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)
    387 #endif
    388       ctlsol = ctl(4)
    389    endif
    390434
    391435   if (i==1) then ! First call; initialize/allocate
     
    406450      ierr = NF_GET_VAR_REAL(nid,altvar,alt)
    407451#endif
     452      firstsol = 'n' ! defaut value
     453      write(*,*)
    408454      if (ctllen .ne. 0) then
    409          if (modulo(int(memotime),669)/=modulo(int(ctlsol),669)) then
    410            write(*,*) "WARNING: Starting day of the run is not ",&
    411                                 modulo(int(memotime),669)," but ",modulo(int(ctlsol),669),"!!"
    412            write(*,*) "Starting day of the run has been corrected."
    413 !           memotime=float(modulo(int(ctl(4)),669)) + ctl(27)
    414            memotime=float(int(ctlsol)) + ctl(27)
    415            ctl(4) = 0.  ! values written in the output
    416            ctl(27) = 0. ! file controle variable (resp. day_ini and hour_ini)
     455         if (int(starttimeoffset) .ne. (int(ctlsol)+int(time(1))) ) then
     456           write(*,*) "WARNING: Starting day of the first file is not ",&
     457                                int(starttimeoffset)," but ",int(ctlsol)+int(time(1)),"!"
     458           write(*,*) "Answer:"
     459           write(*,*) " y to use the starting day you have inputted"
     460           write(*,*) " n to keep the starting day of the first file"
     461           write(*,*) "as the starting day of the output file"
     462           read(*,*) firstsol
    417463         endif
     464         
     465         if (firstsol.eq.'y') then
     466           write(*,*) "The day given by the user is used as the starting day of the ouput file"
     467           starttimeoffset = float(int(ctlsol)+int(time(1))) + ctl(27) - starttimeoffset
     468         else ! if firstsol.eq.'n' or other (default case, for retrocompatibility with previous concatnc.def)
     469           write(*,*) "The starting day of the 1st file is used as the starting day of the ouput file"
     470           starttimeoffset = 0
     471         endif
     472         
     473         memotime=float(int(ctlsol)+int(time(1))) + ctl(27)
     474         ctl(4) = 0.  ! values written in the output
     475         ctl(27) = 0. ! file controle variable (resp. day_ini and hour_ini)
     476         
     477      else ! if no variable "controle"
     478         if (int(starttimeoffset) .ne. (int(time(1))) ) then
     479           write(*,*) "WARNING: Starting day of the first file is not ",&
     480                                int(starttimeoffset)," but ",int(time(1)),"!"
     481           write(*,*) "Answer:"
     482           write(*,*) " y to use the starting day you have inputted"
     483           write(*,*) " n to keep the starting day of the first file"
     484           write(*,*) "as the starting day of the output file"
     485           read(*,*) firstsol
     486         endif
     487         
     488         if (firstsol.eq.'y') then
     489           write(*,*) "The day given by the user is used as the starting day of the ouput file"
     490           starttimeoffset = int(time(1)) - starttimeoffset
     491         else ! if firstsol.eq.'n' or other (default case, for retrocompatibility with previous concatnc.def)
     492           write(*,*) "The starting day of the 1st file is used as the starting day of the ouput file"
     493           starttimeoffset = 0
     494         endif
     495
     496         memotime=float(int(time(1)))
    418497      endif
     498       
    419499   ! Initialize output file's lat,lon,alt and time dimensions
     500      write(*,*)
    420501      call initiate (filename,lat,lon,alt,ctl,GCM_layers,nout,&
    421502       latdimout,londimout,altdimout,timedimout,&
     
    429510   ! Check that latitude,longitude and altitude of current input file
    430511   ! are identical to those of the output file
     512   ! and that either all the files or no file contain the controle variable
    431513      if (memolatlen/=latlen) then
    432514           write(*,*) "ERROR: Not the same latitude axis"
     
    444526   endif ! of if (i==1)
    445527
    446 !==============================================================================
    447 ! 2.4. Handle "Time" dimension from input file
    448 !==============================================================================
    449 
    450 !==============================================================================
    451 ! 2.4.1 Read "Time" dimension from input file
    452 !==============================================================================
    453    ierr=NF_INQ_DIMID(nid,"Time",timedim)
    454    if (ierr.NE.NF_NOERR) then
    455       write(*,*) 'ERROR: Dimension <Time> is missing in file '//file(i)
    456       stop ""
    457    endif
    458    ierr=NF_INQ_VARID(nid,"Time",timevar)
    459    if (ierr.NE.NF_NOERR) then
    460       write(*,*) 'ERROR: Field <Time> is missing in file '//file(i)
    461       stop ""
    462    endif
    463    ierr=NF_INQ_DIMLEN(nid,timedim,timelen)
    464 !  write(*,*) "timelen: ",timelen
    465 
    466    ! allocate time() array and fill it with values from input file
    467    allocate(time(timelen))
    468 
    469 #ifdef NC_DOUBLE
    470    ierr = NF_GET_VAR_DOUBLE(nid,timevar,time)
    471 #else
    472    ierr = NF_GET_VAR_REAL(nid,timevar,time)
    473 #endif
    474 
    475 !==============================================================================
    476 ! 2.4.2 Write/extend "Time" dimension/values in output file
     528
     529!==============================================================================
     530! 2.4 Write/extend "Time" dimension/values in output file
    477531!==============================================================================
    478532
    479533   rep=0
    480534   write(*,*)
    481    write(*,'(a3,1x,f6.1)') "Sol",memotime
     535   write(*,'(a3,1x,f6.1)') "Sol",memotime-starttimeoffset
    482536!   if (ctllen.ne.0) write(*,'(a30,1x,f6.1)') "In the current file's ctl: Sol",ctlsol
    483537
     
    486540     do k=reptime+1,reptime+timelen
    487541       rep=rep+1
    488        if ((time(rep)+ctlsol).le.memotime)then
     542       if ((time(rep)+ctlsol).le.memotime) then
    489543         write(*,*) "ERROR : the time intervals of the files are not dissociated"
    490544         stop ""
    491545       endif
    492546#ifdef NC_DOUBLE
    493        ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,k,1,ctlsol+time(rep))
    494 #else
    495        ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,ctlsol+time(rep))
    496 #endif
     547       ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,k,1,ctlsol+time(rep)-starttimeoffset)
     548#else
     549       ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,ctlsol+time(rep)-starttimeoffset)
     550#endif
     551       !
    497552     enddo
    498553
    499    else
     554   ! Compute new time offset (for further concatenations)
     555   memotime=ctlsol+time(timelen) ! the actual last day of the current file
     556                                 ! becomes the reference time for next file
     557                                 ! leaving potential "time holes" in the output time axis
     558                                 ! at the junction of two files' time axes
     559   
     560   else ! if no variable "controle"
     561   
    500562     do k=reptime+1,reptime+timelen
    501563        rep=rep+1
    502564#ifdef NC_DOUBLE
    503         ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,k,1,memotime+time(rep))
    504 #else
    505         ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,memotime+time(rep))
     565        ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,k,1,memotime+time(rep)-int(time(1))-starttimeoffset)
     566#else
     567        ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,memotime+time(rep)-int(time(1))-starttimeoffset)
    506568#endif
    507569     enddo
     570     
     571   ! Compute new time offset (for further concatenations)
     572   memotime=memotime+time(timelen)-time(1) ! files are concatenated one after another
     573                                           ! even if their time axes normally don't
     574                                           ! directly follow each other
    508575   endif ! if ctllen.ne.0
    509 
    510    ! Compute new time offset (for further concatenations)
    511    memotime=memotime+time(timelen)
    512576
    513577!==============================================================================
     
    648712
    649713if (axis=="ls") then
     714   write(*,*);write(*,*) "Converting the time axis from sol to Ls..."
    650715   call change_time_axis(nout,ierr)
    651716endif
     
    654719ierr=NF_CLOSE(nout)
    655720
     721write(*,*);write(*,*) "Program concatnc completed !"
    656722contains
    657723
  • trunk/LMDZ.MARS/util/concatnc.def

    r2147 r2308  
    33diagfi12.nc       
    44
    5 515              ! Starting sol of the run stored in the first input file?
     5515              ! Starting sol to use in the output file?
    66sol              ! output timescale ("sol" or "ls")
    77tsurf           
    88ps
    99
    10 
     10n
    1111
    1212-----------------------------------------------------------------------
    13 ABOVE is the list of inputs to be fed to "concatnc.e" if you don t want
     13ABOVE is the list of inputs to be fed to "concatnc.e" if you don't want
    1414to reply directly to the program:
    1515
     
    17172) blank line at the end
    18183) Starting sol of the run stored in the first input file?
    19 4) List of X variables to be kept (X lines) or 'all'
    20 5) blank line at the end
     194) Output timescale ("sol" or "ls")
     205) List of X variables to be kept (X lines) or 'all'
     216) blank line at the end
     227) Use:
     23  - the sol given in 3) (answer "y")
     24  - or the starting sol of the first input file (answer "n") (default)
     25  as the starting sol of the output file ?
    2126
    2227The use is :
Note: See TracChangeset for help on using the changeset viewer.