midas_sstTrial sourceΒΆ

  1program midas_sstTrial
  2  !
  3  !:Purpose: Main program to compute SST background state.
  4  !
  5  !          ---
  6  !
  7  !:Algorithm: The background state of SST is computed from the previous SST analysis field
  8  !            using a relaxation towards climatology as follows:
  9  !            :math:`X_{b}(t) = (X_{a}(t-1) - X_{clim}(t-1)) * \alpha + X_{clim}(t)`,
 10  !            where :math:`X_{b}(t)` is a resulting background state at time :math:`t`,
 11  !            :math:`X_{a}(t-1)` is analysis state at time :math:`t-1`,
 12  !            :math:`\alpha` is a relaxation coefficient, 
 13  !            :math:`X_{clim}(t)` is a climatology state at time :math:`t`,
 14  !            computed as an interpolation in time 
 15  !            between climatological field of the current and the following month
 16  !            for the current day of the month. 
 17  !           
 18  !            --
 19  ! 
 20  !=========================================================== ======================================================
 21  ! Input and Output Files                                     Description of file
 22  !=========================================================== ======================================================
 23  ! ``analysis``                                               In - SST analysis field
 24  ! ``climatology``                                            In - 12 monthly climatological SST fields 
 25  ! ``trial``                                                  Out - SST background (trial) field
 26  !=========================================================== ======================================================
 27  !
 28  !            --
 29  !
 30  !:Synopsis: Below is a summary of the ``SSTtrial`` program calling sequence:
 31  !
 32  !            - **Initial setups:**
 33  !
 34  !             - Setup horizontal and vertical grid objects for "analysis
 35  !               grid" from ``analysis``.
 36  !
 37  !             - Setup ``gridStateVector`` modules.
 38  !
 39  !             - Initialize a time objects ``tim_setup``
 40  !
 41  !             - Initialize datastamps from climatology file
 42  !
 43  !            - **Computation**
 44  !
 45  !             - ``obgd_getClimatology`` to read SST climatological fields from a standard file,
 46  !               to interpolate the field in time fot the current day :math:`t` in current month :math:`m` as follows   
 47  !               :math:`X_{clim}(t) = X_{clim}(m) + (t - 1) /(N - 1) * (X_{clim}(m+1) - X_{clim}(m))`,
 48  !               where :math:`N` is a number of days in the current month         
 49  !
 50  !             - ``obgd_computeSSTrial`` to compute the background field and save it into a standard file
 51  !
 52  !            --
 53  !
 54  !:Options: `List of namelist blocks <../namelists_in_each_program.html#ssttrial>`_
 55  !          that can affect the ``SSTtrial`` program.
 56  !
 57  !            * The use of ``SSTtrial`` program is controlled by the namelist block
 58  !              ``&NAMSSTTRIAL`` read by the ``SSTtrial`` program.
 59  !                * ``etiketAnalysis`` etiket to put into output standard file
 60  !
 61  !                * ``datestampClim`` list of twelve datestamps of climatological fields
 62  !                  in the ``climatology`` file
 63  !
 64  !                * ``alphaClim`` a parameter defining the relaxation towards climatology.
 65  !
 66  !            --
 67  !
 68  use version_mod
 69  use ramDisk_mod
 70  use utilities_mod
 71  use midasMpi_mod
 72  use horizontalCoord_mod
 73  use verticalCoord_mod
 74  use timeCoord_mod
 75  use gridStateVector_mod
 76  use oceanBackground_mod
 77  
 78  implicit none
 79
 80  integer, external :: exdb, exfin, fnom, fclos, get_max_rss
 81  integer :: ierr, istamp, nulnam
 82
 83  type(struct_hco), pointer :: hco_anl => null()
 84  type(struct_vco), pointer :: vco_anl => null()
 85  integer                   :: trialDateStamp    ! output: datestamp for the trial field
 86  integer                   :: analysisDateStamp !  input: datastamp of the latest analysis
 87  integer, parameter        :: nmonthsClim = 12  ! number of climatological fields
 88
 89  ! namelist variables
 90  character(len=10) :: etiketAnalysis    ! etiket in the analysis file for grid setup
 91  integer           :: datestampClim(12) ! datestamps of input climatology fields 
 92  real(4)           :: alphaClim         ! scaling factor to relax towards climatology
 93  
 94  istamp = exdb('SSTTRIAL','DEBUT','NON')
 95
 96  call ver_printNameAndVersion('SSTtrial','SST trial preparation')
 97
 98  ! MPI initialization
 99  call mmpi_initialize
100
101  call tmg_init(mmpi_myid, 'TMG_INFO')
102  call utl_tmg_start(0,'Main')
103  
104  ! 1. Top level setup
105
106  call ram_setup()
107 
108  ! Do initial set up
109  call SSTtrial_setup(trialDateStamp, analysisDateStamp)
110  
111  call obgd_computeSSTrial(hco_anl, vco_anl, trialDateStamp, analysisDateStamp, &
112                           nmonthsClim, datestampClim, alphaClim, etiketAnalysis)
113			 
114  ! 3. Job termination
115
116  istamp = exfin('SSTTRIAL','FIN','NON')
117  call utl_tmg_stop(0)
118  call tmg_terminate(mmpi_myid, 'TMG_INFO')
119  call rpn_comm_finalize(ierr) 
120
121  contains
122  
123  !----------------------------------------------------------------------------------------
124  ! SSTtrial_setup
125  !----------------------------------------------------------------------------------------
126  subroutine SSTtrial_setup(trialDateStamp, analysisDateStamp)
127    !
128    ! :Purpose:  Control of the preprocessing of trial
129    !
130    implicit none
131    
132    ! Arguments:
133    integer, intent(out) :: trialDateStamp
134    integer, intent(out) :: analysisDateStamp
135    
136    ! Locals:	
137    character(len=*), parameter :: gridFile = './analysis'
138    integer                     :: prntdate, prnttime, imode, newdate, indexMonth
139    namelist /namSSTtrial/ etiketAnalysis, datestampClim, alphaClim
140        
141    write(*,*) ''
142    write(*,*) '-------------------------------------------------'
143    write(*,*) '-- Starting subroutine SSTtrial_setup --'
144    write(*,*) '-------------------------------------------------'
145 
146    ! namelist variables default values
147    etiketAnalysis = ''
148    datestampClim(:) = 0
149    alphaClim = 0.983
150    
151    ! Read the namelist
152    nulnam = 0
153    ierr = fnom( nulnam, './flnml', 'FTN+SEQ+R/O', 0 )
154    read( nulnam, nml = namSSTtrial, iostat = ierr )
155    if ( ierr /= 0) call utl_abort( 'SSTtrial_setup: Error reading namelist')
156    if ( mmpi_myid == 0 ) write(*, nml = namSSTtrial )
157    ierr = fclos(nulnam)
158
159    if(mmpi_myid == 0) then
160      write(*,'(1X,"***********************************")')
161      write(*,'(1X," datestamps for climatology file:",/)')
162      write(*,'(1X,"***********************************")')
163      do indexMonth =1, nmonthsClim
164        write(*,*) indexMonth, datestampClim(indexMonth)
165      end do
166      write(*,'(1X,"***********************************")')
167    end if  
168
169    !
170    !- Initialize the Temporal grid and set dateStamp from gridFile
171    !
172    call tim_setup(fileNameForDate_opt = gridFile)
173    analysisDateStamp = tim_getDateStamp()
174    write(*,*) 'SSTtrial_setup: analysis datestamp  = ', analysisDateStamp
175    write(*,*) 'SSTtrial_setup:          windowsize = ', tim_windowsize
176    
177    call incdatr(trialDateStamp, analysisDateStamp, tim_windowsize)
178    write(*,*) 'SSTtrial_setup:    trial datestamp  = ', trialDateStamp
179    
180    imode = -3 ! stamp to printable
181    ierr = newdate(trialDateStamp, prntdate, prnttime, imode)
182    write(*,*) 'SSTtrial_setup: trial date = ', prntdate
183    write(*,*) 'SSTtrial_setup: trial time = ', prnttime
184    !
185    !- Initialize variables of the model states
186    !
187    call gsv_setup
188    write(*,*) 'SSTtrial_setup: memory Used: ',get_max_rss()/1024,'Mb'
189
190    !
191    !- Initialize the Analysis grid
192    !
193    if(mmpi_myid == 0) write(*,*)''
194    if(mmpi_myid == 0) write(*,*) 'SSTtrial_setup: Set hco parameters for analysis grid'
195    call hco_SetupFromFile(hco_anl, gridFile, trim(etiketAnalysis)) ! IN
196
197    !     
198    !- Initialisation of the analysis grid vertical coordinate from analysisgrid file
199    !
200    call vco_SetupFromFile( vco_anl, & ! OUT
201                            gridFile ) ! IN
202
203    if(mmpi_myid == 0) write(*,*) 'SSTtrial_setup: done.'
204
205  end subroutine SSTtrial_setup
206
207end program midas_sstTrial