New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
diaobs.F90 in NEMO/branches/2021/dev_r14273_HPC-02_Daley_Tiling/src/OCE/OBS – NEMO

source: NEMO/branches/2021/dev_r14273_HPC-02_Daley_Tiling/src/OCE/OBS/diaobs.F90 @ 14752

Last change on this file since 14752 was 14752, checked in by hadcv, 3 years ago

#2600: QCO-related changes

  • Property svn:keywords set to Id
File size: 52.6 KB
Line 
1MODULE diaobs
2   !!======================================================================
3   !!                       ***  MODULE diaobs  ***
4   !! Observation diagnostics: Computation of the misfit between data and
5   !!                          their model equivalent
6   !!======================================================================
7   !! History :  1.0  !  2006-03  (K. Mogensen) Original code
8   !!             -   !  2006-05  (K. Mogensen, A. Weaver) Reformatted
9   !!             -   !  2006-10  (A. Weaver) Cleaning and add controls
10   !!             -   !  2007-03  (K. Mogensen) General handling of profiles
11   !!             -   !  2007-04  (G. Smith) Generalized surface operators
12   !!            2.0  !  2008-10  (M. Valdivieso) obs operator for velocity profiles
13   !!            3.4  !  2014-08  (J. While) observation operator for profiles in all vertical coordinates
14   !!             -   !                      Incorporated SST bias correction 
15   !!            3.6  !  2015-02  (M. Martin) Simplification of namelist and code
16   !!             -   !  2015-08  (M. Martin) Combined surface/profile routines.
17   !!            4.0  !  2017-11  (G. Madec) style only
18   !!----------------------------------------------------------------------
19
20   !!----------------------------------------------------------------------
21   !!   dia_obs_init  : Reading and prepare observations
22   !!   dia_obs       : Compute model equivalent to observations
23   !!   dia_obs_wri   : Write observational diagnostics
24   !!   calc_date     : Compute the date of timestep in YYYYMMDD.HHMMSS format
25   !!   ini_date      : Compute the initial date YYYYMMDD.HHMMSS
26   !!   fin_date      : Compute the final date YYYYMMDD.HHMMSS
27   !!----------------------------------------------------------------------
28   USE par_kind       ! Precision variables
29   USE in_out_manager ! I/O manager
30   USE par_oce        ! ocean parameter
31   USE dom_oce        ! Ocean space and time domain variables
32   USE sbc_oce        ! Sea-ice fraction
33   !
34   USE obs_read_prof  ! Reading and allocation of profile obs
35   USE obs_read_surf  ! Reading and allocation of surface obs
36   USE obs_sstbias    ! Bias correction routine for SST
37   USE obs_readmdt    ! Reading and allocation of MDT for SLA.
38   USE obs_prep       ! Preparation of obs. (grid search etc).
39   USE obs_oper       ! Observation operators
40   USE obs_write      ! Writing of observation related diagnostics
41   USE obs_grid       ! Grid searching
42   USE obs_read_altbias ! Bias treatment for altimeter
43   USE obs_profiles_def ! Profile data definitions
44   USE obs_surf_def   ! Surface data definitions
45   USE obs_types      ! Definitions for observation types
46   !
47   USE mpp_map        ! MPP mapping
48   USE lib_mpp        ! For ctl_warn/stop
49
50   IMPLICIT NONE
51   PRIVATE
52
53   PUBLIC dia_obs_init     ! Initialize and read observations
54   PUBLIC dia_obs          ! Compute model equivalent to observations
55   PUBLIC dia_obs_wri      ! Write model equivalent to observations
56   PUBLIC dia_obs_dealloc  ! Deallocate dia_obs data
57   PUBLIC calc_date        ! Compute the date of a timestep
58
59   LOGICAL, PUBLIC :: ln_diaobs            !: Logical switch for the obs operator
60   LOGICAL         :: ln_sstnight          !  Logical switch for night mean SST obs
61   LOGICAL         :: ln_default_fp_indegs !  T=> Default obs footprint size specified in degrees, F=> in metres
62   LOGICAL         :: ln_sla_fp_indegs     !  T=> SLA obs footprint size specified in degrees, F=> in metres
63   LOGICAL         :: ln_sst_fp_indegs     !  T=> SST obs footprint size specified in degrees, F=> in metres
64   LOGICAL         :: ln_sss_fp_indegs     !  T=> SSS obs footprint size specified in degrees, F=> in metres
65   LOGICAL         :: ln_sic_fp_indegs     !  T=> sea-ice obs footprint size specified in degrees, F=> in metres
66
67   REAL(wp) ::   rn_default_avglamscl      ! E/W diameter of SLA observation footprint (metres)
68   REAL(wp) ::   rn_default_avgphiscl      ! N/S diameter of SLA observation footprint (metre
69   REAL(wp) ::   rn_sla_avglamscl          ! E/W diameter of SLA observation footprint (metres)
70   REAL(wp) ::   rn_sla_avgphiscl          ! N/S diameter of SLA observation footprint (metres)
71   REAL(wp) ::   rn_sst_avglamscl          ! E/W diameter of SST observation footprint (metres)
72   REAL(wp) ::   rn_sst_avgphiscl          ! N/S diameter of SST observation footprint (metres)
73   REAL(wp) ::   rn_sss_avglamscl          ! E/W diameter of SSS observation footprint (metres)
74   REAL(wp) ::   rn_sss_avgphiscl          ! N/S diameter of SSS observation footprint (metres)
75   REAL(wp) ::   rn_sic_avglamscl          ! E/W diameter of sea-ice observation footprint (metres)
76   REAL(wp) ::   rn_sic_avgphiscl          ! N/S diameter of sea-ice observation footprint (metres)
77
78   INTEGER :: nn_1dint                     ! Vertical interpolation method
79   INTEGER :: nn_2dint_default             ! Default horizontal interpolation method
80   INTEGER :: nn_2dint_sla                 ! SLA horizontal interpolation method
81   INTEGER :: nn_2dint_sst                 ! SST horizontal interpolation method
82   INTEGER :: nn_2dint_sss                 ! SSS horizontal interpolation method
83   INTEGER :: nn_2dint_sic                 ! Seaice horizontal interpolation method
84   INTEGER, DIMENSION(imaxavtypes) ::   nn_profdavtypes   ! Profile data types representing a daily average
85   INTEGER :: nproftypes     ! Number of profile obs types
86   INTEGER :: nsurftypes     ! Number of surface obs types
87   INTEGER , DIMENSION(:), ALLOCATABLE ::   nvarsprof, nvarssurf   ! Number of profile & surface variables
88   INTEGER , DIMENSION(:), ALLOCATABLE ::   nextrprof, nextrsurf   ! Number of profile & surface extra variables
89   INTEGER , DIMENSION(:), ALLOCATABLE ::   n2dintsurf             ! Interpolation option for surface variables
90   REAL(wp), DIMENSION(:), ALLOCATABLE ::   zavglamscl, zavgphiscl ! E/W & N/S diameter of averaging footprint for surface variables
91   LOGICAL , DIMENSION(:), ALLOCATABLE ::   lfpindegs              ! T=> surface obs footprint size specified in degrees, F=> in metres
92   LOGICAL , DIMENSION(:), ALLOCATABLE ::   llnightav              ! Logical for calculating night-time averages
93
94   TYPE(obs_surf), PUBLIC, POINTER, DIMENSION(:) ::   surfdata     !: Initial surface data
95   TYPE(obs_surf), PUBLIC, POINTER, DIMENSION(:) ::   surfdataqc   !: Surface data after quality control
96   TYPE(obs_prof), PUBLIC, POINTER, DIMENSION(:) ::   profdata     !: Initial profile data
97   TYPE(obs_prof), PUBLIC, POINTER, DIMENSION(:) ::   profdataqc   !: Profile data after quality control
98
99   CHARACTER(len=8), PUBLIC, DIMENSION(:), ALLOCATABLE ::   cobstypesprof, cobstypessurf   !: Profile & surface obs types
100
101#  include "domzgr_substitute.h90"
102   !!----------------------------------------------------------------------
103   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
104   !! $Id$
105   !! Software governed by the CeCILL license (see ./LICENSE)
106   !!----------------------------------------------------------------------
107CONTAINS
108
109   SUBROUTINE dia_obs_init( Kmm )
110      !!----------------------------------------------------------------------
111      !!                    ***  ROUTINE dia_obs_init  ***
112      !!         
113      !! ** Purpose : Initialize and read observations
114      !!
115      !! ** Method  : Read the namelist and call reading routines
116      !!
117      !! ** Action  : Read the namelist and call reading routines
118      !!
119      !!----------------------------------------------------------------------
120      INTEGER, INTENT(in)                ::   Kmm                      ! ocean time level indices
121      INTEGER, PARAMETER                 ::   jpmaxnfiles = 1000       ! Maximum number of files for each obs type
122      INTEGER, DIMENSION(:), ALLOCATABLE ::   ifilesprof, ifilessurf   ! Number of profile & surface files
123      INTEGER :: ios             ! Local integer output status for namelist read
124      INTEGER :: jtype           ! Counter for obs types
125      INTEGER :: jvar            ! Counter for variables
126      INTEGER :: jfile           ! Counter for files
127      INTEGER :: jnumsstbias     ! Number of SST bias files to read and apply
128      INTEGER :: n2dint_type     ! Local version of nn_2dint*
129      !
130      CHARACTER(len=128), DIMENSION(jpmaxnfiles) :: &
131         & cn_profbfiles, &      ! T/S profile input filenames
132         & cn_sstfbfiles, &      ! Sea surface temperature input filenames
133         & cn_sssfbfiles, &      ! Sea surface salinity input filenames
134         & cn_slafbfiles, &      ! Sea level anomaly input filenames
135         & cn_sicfbfiles, &      ! Seaice concentration input filenames
136         & cn_velfbfiles, &      ! Velocity profile input filenames
137         & cn_sstbiasfiles       ! SST bias input filenames
138      CHARACTER(LEN=128) :: &
139         & cn_altbiasfile        ! Altimeter bias input filename
140      CHARACTER(len=128), DIMENSION(:,:), ALLOCATABLE :: &
141         & clproffiles, &        ! Profile filenames
142         & clsurffiles           ! Surface filenames
143      CHARACTER(len=8), DIMENSION(:), ALLOCATABLE :: &
144         & clvars                ! Expected variable names
145         !
146      LOGICAL :: ln_t3d          ! Logical switch for temperature profiles
147      LOGICAL :: ln_s3d          ! Logical switch for salinity profiles
148      LOGICAL :: ln_sla          ! Logical switch for sea level anomalies
149      LOGICAL :: ln_sst          ! Logical switch for sea surface temperature
150      LOGICAL :: ln_sss          ! Logical switch for sea surface salinity
151      LOGICAL :: ln_sic          ! Logical switch for sea ice concentration
152      LOGICAL :: ln_vel3d        ! Logical switch for velocity (u,v) obs
153      LOGICAL :: ln_nea          ! Logical switch to remove obs near land
154      LOGICAL :: ln_altbias      ! Logical switch for altimeter bias
155      LOGICAL :: ln_sstbias      ! Logical switch for bias corection of SST
156      LOGICAL :: ln_ignmis       ! Logical switch for ignoring missing files
157      LOGICAL :: ln_s_at_t       ! Logical switch to compute model S at T obs
158      LOGICAL :: ln_bound_reject ! Logical to remove obs near boundaries in LAMs.
159      LOGICAL :: ltype_fp_indegs ! Local version of ln_*_fp_indegs
160      LOGICAL :: ltype_night     ! Local version of ln_sstnight (false for other variables)
161      LOGICAL, DIMENSION(:), ALLOCATABLE :: llvar   ! Logical for profile variable read
162      LOGICAL, DIMENSION(jpmaxnfiles) :: lmask ! Used for finding number of sstbias files
163      !
164      REAL(dp) :: rn_dobsini      ! Obs window start date YYYYMMDD.HHMMSS
165      REAL(dp) :: rn_dobsend      ! Obs window end date   YYYYMMDD.HHMMSS
166      REAL(wp) :: ztype_avglamscl ! Local version of rn_*_avglamscl
167      REAL(wp) :: ztype_avgphiscl ! Local version of rn_*_avgphiscl
168      REAL(wp), DIMENSION(:,:,:),   ALLOCATABLE :: zglam   ! Model longitudes for profile variables
169      REAL(wp), DIMENSION(:,:,:),   ALLOCATABLE :: zgphi   ! Model latitudes  for profile variables
170      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: zmask   ! Model land/sea mask associated with variables
171      !!
172      NAMELIST/namobs/ln_diaobs, ln_t3d, ln_s3d, ln_sla,              &
173         &            ln_sst, ln_sic, ln_sss, ln_vel3d,               &
174         &            ln_altbias, ln_sstbias, ln_nea,                 &
175         &            ln_grid_global, ln_grid_search_lookup,          &
176         &            ln_ignmis, ln_s_at_t, ln_bound_reject,          &
177         &            ln_sstnight, ln_default_fp_indegs,              &
178         &            ln_sla_fp_indegs, ln_sst_fp_indegs,             &
179         &            ln_sss_fp_indegs, ln_sic_fp_indegs,             &
180         &            cn_profbfiles, cn_slafbfiles,                   &
181         &            cn_sstfbfiles, cn_sicfbfiles,                   &
182         &            cn_velfbfiles, cn_sssfbfiles,                   &
183         &            cn_sstbiasfiles, cn_altbiasfile,                &
184         &            cn_gridsearchfile, rn_gridsearchres,            &
185         &            rn_dobsini, rn_dobsend,                         &
186         &            rn_default_avglamscl, rn_default_avgphiscl,     &
187         &            rn_sla_avglamscl, rn_sla_avgphiscl,             &
188         &            rn_sst_avglamscl, rn_sst_avgphiscl,             &
189         &            rn_sss_avglamscl, rn_sss_avgphiscl,             &
190         &            rn_sic_avglamscl, rn_sic_avgphiscl,             &
191         &            nn_1dint, nn_2dint_default,                     &
192         &            nn_2dint_sla, nn_2dint_sst,                     &
193         &            nn_2dint_sss, nn_2dint_sic,                     &
194         &            nn_msshc, rn_mdtcorr, rn_mdtcutoff,             &
195         &            nn_profdavtypes
196      !-----------------------------------------------------------------------
197
198      !-----------------------------------------------------------------------
199      ! Read namelist parameters
200      !-----------------------------------------------------------------------
201      ! Some namelist arrays need initialising
202      cn_profbfiles  (:) = ''
203      cn_slafbfiles  (:) = ''
204      cn_sstfbfiles  (:) = ''
205      cn_sicfbfiles  (:) = ''
206      cn_velfbfiles  (:) = ''
207      cn_sssfbfiles  (:) = ''
208      cn_sstbiasfiles(:) = ''
209      nn_profdavtypes(:) = -1
210
211      CALL ini_date( rn_dobsini )
212      CALL fin_date( rn_dobsend )
213
214      ! Read namelist namobs : control observation diagnostics
215      READ  ( numnam_ref, namobs, IOSTAT = ios, ERR = 901)
216901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namobs in reference namelist' )
217      READ  ( numnam_cfg, namobs, IOSTAT = ios, ERR = 902 )
218902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namobs in configuration namelist' )
219      IF(lwm) WRITE ( numond, namobs )
220
221      IF( .NOT.ln_diaobs ) THEN
222         IF(lwp) WRITE(numout,*)
223         IF(lwp) WRITE(numout,*) 'dia_obs_init : NO Observation diagnostic used'
224         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
225         RETURN
226      ENDIF
227
228      IF(lwp) THEN
229         WRITE(numout,*)
230         WRITE(numout,*) 'dia_obs_init : Observation diagnostic initialization'
231         WRITE(numout,*) '~~~~~~~~~~~~'
232         WRITE(numout,*) '   Namelist namobs : set observation diagnostic parameters' 
233         WRITE(numout,*) '      Logical switch for T profile observations                ln_t3d = ', ln_t3d
234         WRITE(numout,*) '      Logical switch for S profile observations                ln_s3d = ', ln_s3d
235         WRITE(numout,*) '      Logical switch for SLA observations                      ln_sla = ', ln_sla
236         WRITE(numout,*) '      Logical switch for SST observations                      ln_sst = ', ln_sst
237         WRITE(numout,*) '      Logical switch for Sea Ice observations                  ln_sic = ', ln_sic
238         WRITE(numout,*) '      Logical switch for velocity observations               ln_vel3d = ', ln_vel3d
239         WRITE(numout,*) '      Logical switch for SSS observations                      ln_sss = ', ln_sss
240         WRITE(numout,*) '      Global distribution of observations              ln_grid_global = ', ln_grid_global
241         WRITE(numout,*) '      Logical switch for obs grid search lookup ln_grid_search_lookup = ', ln_grid_search_lookup
242         IF (ln_grid_search_lookup) &
243            WRITE(numout,*) '      Grid search lookup file header                cn_gridsearchfile = ', cn_gridsearchfile
244         WRITE(numout,*) '      Initial date in window YYYYMMDD.HHMMSS               rn_dobsini = ', rn_dobsini
245         WRITE(numout,*) '      Final date in window YYYYMMDD.HHMMSS                 rn_dobsend = ', rn_dobsend
246         WRITE(numout,*) '      Type of vertical interpolation method                  nn_1dint = ', nn_1dint
247         WRITE(numout,*) '      Default horizontal interpolation method        nn_2dint_default = ', nn_2dint_default
248         WRITE(numout,*) '      Type of horizontal interpolation method for SLA    nn_2dint_sla = ', nn_2dint_sla
249         WRITE(numout,*) '      Type of horizontal interpolation method for SST    nn_2dint_sst = ', nn_2dint_sst
250         WRITE(numout,*) '      Type of horizontal interpolation method for SSS    nn_2dint_sss = ', nn_2dint_sss       
251         WRITE(numout,*) '      Type of horizontal interpolation method for SIC    nn_2dint_sic = ', nn_2dint_sic
252         WRITE(numout,*) '      Default E/W diameter of obs footprint      rn_default_avglamscl = ', rn_default_avglamscl
253         WRITE(numout,*) '      Default N/S diameter of obs footprint      rn_default_avgphiscl = ', rn_default_avgphiscl
254         WRITE(numout,*) '      Default obs footprint in deg [T] or m [F]  ln_default_fp_indegs = ', ln_default_fp_indegs
255         WRITE(numout,*) '      SLA E/W diameter of obs footprint              rn_sla_avglamscl = ', rn_sla_avglamscl
256         WRITE(numout,*) '      SLA N/S diameter of obs footprint              rn_sla_avgphiscl = ', rn_sla_avgphiscl
257         WRITE(numout,*) '      SLA obs footprint in deg [T] or m [F]          ln_sla_fp_indegs = ', ln_sla_fp_indegs
258         WRITE(numout,*) '      SST E/W diameter of obs footprint              rn_sst_avglamscl = ', rn_sst_avglamscl
259         WRITE(numout,*) '      SST N/S diameter of obs footprint              rn_sst_avgphiscl = ', rn_sst_avgphiscl
260         WRITE(numout,*) '      SST obs footprint in deg [T] or m [F]          ln_sst_fp_indegs = ', ln_sst_fp_indegs
261         WRITE(numout,*) '      SIC E/W diameter of obs footprint              rn_sic_avglamscl = ', rn_sic_avglamscl
262         WRITE(numout,*) '      SIC N/S diameter of obs footprint              rn_sic_avgphiscl = ', rn_sic_avgphiscl
263         WRITE(numout,*) '      SIC obs footprint in deg [T] or m [F]          ln_sic_fp_indegs = ', ln_sic_fp_indegs
264         WRITE(numout,*) '      Rejection of observations near land switch               ln_nea = ', ln_nea
265         WRITE(numout,*) '      Rejection of obs near open bdys                 ln_bound_reject = ', ln_bound_reject
266         WRITE(numout,*) '      MSSH correction scheme                                 nn_msshc = ', nn_msshc
267         WRITE(numout,*) '      MDT  correction                                      rn_mdtcorr = ', rn_mdtcorr
268         WRITE(numout,*) '      MDT cutoff for computed correction                 rn_mdtcutoff = ', rn_mdtcutoff
269         WRITE(numout,*) '      Logical switch for alt bias                          ln_altbias = ', ln_altbias
270         WRITE(numout,*) '      Logical switch for sst bias                          ln_sstbias = ', ln_sstbias
271         WRITE(numout,*) '      Logical switch for ignoring missing files             ln_ignmis = ', ln_ignmis
272         WRITE(numout,*) '      Daily average types                             nn_profdavtypes = ', nn_profdavtypes
273         WRITE(numout,*) '      Logical switch for night-time SST obs               ln_sstnight = ', ln_sstnight
274      ENDIF
275      !-----------------------------------------------------------------------
276      ! Set up list of observation types to be used
277      ! and the files associated with each type
278      !-----------------------------------------------------------------------
279
280      nproftypes = COUNT( (/ln_t3d .OR. ln_s3d, ln_vel3d /) )
281      nsurftypes = COUNT( (/ln_sla, ln_sst, ln_sic, ln_sss /) )
282
283      IF( ln_sstbias ) THEN
284         lmask(:) = .FALSE. 
285         WHERE( cn_sstbiasfiles(:) /= '' )   lmask(:) = .TRUE. 
286         jnumsstbias = COUNT(lmask) 
287         lmask(:) = .FALSE. 
288      ENDIF     
289
290      IF( nproftypes == 0 .AND. nsurftypes == 0 ) THEN
291         CALL ctl_warn( 'dia_obs_init: ln_diaobs is set to true, but all obs operator logical flags',   &
292            &           ' (ln_t3d, ln_s3d, ln_sla, ln_sst, ln_sic, ln_vel3d)',                          &
293            &           ' are set to .FALSE. so turning off calls to dia_obs'  )
294         ln_diaobs = .FALSE.
295         RETURN
296      ENDIF
297
298      IF( nproftypes > 0 ) THEN
299         !
300         ALLOCATE( cobstypesprof(nproftypes)             )
301         ALLOCATE( ifilesprof   (nproftypes)             )
302         ALLOCATE( clproffiles  (nproftypes,jpmaxnfiles) )
303         !
304         jtype = 0
305         IF( ln_t3d .OR. ln_s3d ) THEN
306            jtype = jtype + 1
307            cobstypesprof(jtype) = 'prof'
308            clproffiles(jtype,:) = cn_profbfiles
309         ENDIF
310         IF( ln_vel3d ) THEN
311            jtype = jtype + 1
312            cobstypesprof(jtype) = 'vel'
313            clproffiles(jtype,:) = cn_velfbfiles
314         ENDIF
315         !
316         CALL obs_settypefiles( nproftypes, jpmaxnfiles, ifilesprof, cobstypesprof, clproffiles )
317         !
318      ENDIF
319
320      IF( nsurftypes > 0 ) THEN
321         !
322         ALLOCATE( cobstypessurf(nsurftypes)             )
323         ALLOCATE( ifilessurf   (nsurftypes)             )
324         ALLOCATE( clsurffiles  (nsurftypes,jpmaxnfiles) )
325         ALLOCATE( n2dintsurf   (nsurftypes)             )
326         ALLOCATE( zavglamscl   (nsurftypes)             )
327         ALLOCATE( zavgphiscl   (nsurftypes)             )
328         ALLOCATE( lfpindegs    (nsurftypes)             )
329         ALLOCATE( llnightav    (nsurftypes)             )
330         !
331         jtype = 0
332         IF( ln_sla ) THEN
333            jtype = jtype + 1
334            cobstypessurf(jtype) = 'sla'
335            clsurffiles(jtype,:) = cn_slafbfiles
336         ENDIF
337         IF( ln_sst ) THEN
338            jtype = jtype + 1
339            cobstypessurf(jtype) = 'sst'
340            clsurffiles(jtype,:) = cn_sstfbfiles
341         ENDIF
342#if defined key_si3 || defined key_cice
343         IF( ln_sic ) THEN
344            jtype = jtype + 1
345            cobstypessurf(jtype) = 'sic'
346            clsurffiles(jtype,:) = cn_sicfbfiles
347         ENDIF
348#endif
349         IF( ln_sss ) THEN
350            jtype = jtype + 1
351            cobstypessurf(jtype) = 'sss'
352            clsurffiles(jtype,:) = cn_sssfbfiles
353         ENDIF
354         !
355         CALL obs_settypefiles( nsurftypes, jpmaxnfiles, ifilessurf, cobstypessurf, clsurffiles )
356
357         DO jtype = 1, nsurftypes
358
359            IF ( TRIM(cobstypessurf(jtype)) == 'sla' ) THEN
360               IF ( nn_2dint_sla == -1 ) THEN
361                  n2dint_type  = nn_2dint_default
362               ELSE
363                  n2dint_type  = nn_2dint_sla
364               ENDIF
365               ztype_avglamscl = rn_sla_avglamscl
366               ztype_avgphiscl = rn_sla_avgphiscl
367               ltype_fp_indegs = ln_sla_fp_indegs
368               ltype_night     = .FALSE.
369            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sst' ) THEN
370               IF ( nn_2dint_sst == -1 ) THEN
371                  n2dint_type  = nn_2dint_default
372               ELSE
373                  n2dint_type  = nn_2dint_sst
374               ENDIF
375               ztype_avglamscl = rn_sst_avglamscl
376               ztype_avgphiscl = rn_sst_avgphiscl
377               ltype_fp_indegs = ln_sst_fp_indegs
378               ltype_night     = ln_sstnight
379            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sic' ) THEN
380               IF ( nn_2dint_sic == -1 ) THEN
381                  n2dint_type  = nn_2dint_default
382               ELSE
383                  n2dint_type  = nn_2dint_sic
384               ENDIF
385               ztype_avglamscl = rn_sic_avglamscl
386               ztype_avgphiscl = rn_sic_avgphiscl
387               ltype_fp_indegs = ln_sic_fp_indegs
388               ltype_night     = .FALSE.
389            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sss' ) THEN
390               IF ( nn_2dint_sss == -1 ) THEN
391                  n2dint_type  = nn_2dint_default
392               ELSE
393                  n2dint_type  = nn_2dint_sss
394               ENDIF
395               ztype_avglamscl = rn_sss_avglamscl
396               ztype_avgphiscl = rn_sss_avgphiscl
397               ltype_fp_indegs = ln_sss_fp_indegs
398               ltype_night     = .FALSE.
399            ELSE
400               n2dint_type     = nn_2dint_default
401               ztype_avglamscl = rn_default_avglamscl
402               ztype_avgphiscl = rn_default_avgphiscl
403               ltype_fp_indegs = ln_default_fp_indegs
404               ltype_night     = .FALSE.
405            ENDIF
406           
407            CALL obs_setinterpopts( nsurftypes, jtype, TRIM(cobstypessurf(jtype)), &
408               &                    nn_2dint_default, n2dint_type,                 &
409               &                    ztype_avglamscl, ztype_avgphiscl,              &
410               &                    ltype_fp_indegs, ltype_night,                  &
411               &                    n2dintsurf, zavglamscl, zavgphiscl,            &
412               &                    lfpindegs, llnightav )
413
414         END DO
415         !
416      ENDIF
417
418
419      !-----------------------------------------------------------------------
420      ! Obs operator parameter checking and initialisations
421      !-----------------------------------------------------------------------
422      !
423      IF( ln_vel3d  .AND.  .NOT.ln_grid_global ) THEN
424         CALL ctl_stop( 'Velocity data only works with ln_grid_global=.true.' )
425         RETURN
426      ENDIF
427      !
428      IF( ln_grid_global ) THEN
429         CALL ctl_warn( 'dia_obs_init: ln_grid_global=T may cause memory issues when used with a large number of processors' )
430      ENDIF
431      !
432      IF( nn_1dint < 0  .OR.  nn_1dint > 1 ) THEN
433         CALL ctl_stop('dia_obs_init: Choice of vertical (1D) interpolation method is not available')
434      ENDIF
435      !
436      IF( nn_2dint_default < 0  .OR.  nn_2dint_default > 6  ) THEN
437         CALL ctl_stop('dia_obs_init: Choice of default horizontal (2D) interpolation method is not available')
438      ENDIF
439      !
440      CALL obs_typ_init
441      IF( ln_grid_global )   CALL mppmap_init
442      !
443      CALL obs_grid_setup( )
444
445      !-----------------------------------------------------------------------
446      ! Depending on switches read the various observation types
447      !-----------------------------------------------------------------------
448      !
449      IF( nproftypes > 0 ) THEN
450         !
451         ALLOCATE( profdata  (nproftypes) , nvarsprof (nproftypes) )
452         ALLOCATE( profdataqc(nproftypes) , nextrprof (nproftypes) )
453         !
454         DO jtype = 1, nproftypes
455            !
456            IF ( TRIM(cobstypesprof(jtype)) == 'prof' ) THEN
457               nvarsprof(jtype) = 2
458               nextrprof(jtype) = 1             
459               ALLOCATE( llvar (nvarsprof(jtype)) )
460               ALLOCATE( clvars(nvarsprof(jtype)) )
461               ALLOCATE( zglam(jpi, jpj,      nvarsprof(jtype)) )
462               ALLOCATE( zgphi(jpi, jpj,      nvarsprof(jtype)) )
463               ALLOCATE( zmask(jpi, jpj, jpk, nvarsprof(jtype)) )
464               llvar(1)       = ln_t3d
465               llvar(2)       = ln_s3d
466               clvars(1)      = 'POTM'
467               clvars(2)      = 'PSAL'
468               zglam(:,:,1)   = glamt(:,:)
469               zglam(:,:,2)   = glamt(:,:)
470               zgphi(:,:,1)   = gphit(:,:)
471               zgphi(:,:,2)   = gphit(:,:)
472               zmask(:,:,:,1) = tmask(:,:,:)
473               zmask(:,:,:,2) = tmask(:,:,:)
474            ELSE IF ( TRIM(cobstypesprof(jtype)) == 'vel' )  THEN
475               nvarsprof(jtype) = 2
476               nextrprof(jtype) = 2
477               ALLOCATE( llvar (nvarsprof(jtype)) )
478               ALLOCATE( clvars(nvarsprof(jtype)) )
479               ALLOCATE( zglam(jpi, jpj,      nvarsprof(jtype)) )
480               ALLOCATE( zgphi(jpi, jpj,      nvarsprof(jtype)) )
481               ALLOCATE( zmask(jpi, jpj, jpk, nvarsprof(jtype)) )
482               llvar(1)       = ln_vel3d
483               llvar(2)       = ln_vel3d
484               clvars(1)      = 'UVEL'
485               clvars(2)      = 'VVEL'
486               zglam(:,:,1)   = glamu(:,:)
487               zglam(:,:,2)   = glamv(:,:)
488               zgphi(:,:,1)   = gphiu(:,:)
489               zgphi(:,:,2)   = gphiv(:,:)
490               zmask(:,:,:,1) = umask(:,:,:)
491               zmask(:,:,:,2) = vmask(:,:,:)
492            ELSE
493               nvarsprof(jtype) = 1
494               nextrprof(jtype) = 0
495               ALLOCATE( llvar (nvarsprof(jtype)) )
496               ALLOCATE( clvars(nvarsprof(jtype)) )
497               ALLOCATE( zglam(jpi, jpj,      nvarsprof(jtype)) )
498               ALLOCATE( zgphi(jpi, jpj,      nvarsprof(jtype)) )
499               ALLOCATE( zmask(jpi, jpj, jpk, nvarsprof(jtype)) )
500               llvar(1)       = .TRUE.
501               zglam(:,:,1)   = glamt(:,:)
502               zgphi(:,:,1)   = gphit(:,:)
503               zmask(:,:,:,1) = tmask(:,:,:)
504            ENDIF
505            !
506            ! Read in profile or profile obs types
507            CALL obs_rea_prof( profdata(jtype), ifilesprof(jtype),       &
508               &               clproffiles(jtype,1:ifilesprof(jtype)), &
509               &               nvarsprof(jtype), nextrprof(jtype), nitend-nit000+2, &
510               &               rn_dobsini, rn_dobsend, llvar, &
511               &               ln_ignmis, ln_s_at_t, .FALSE., clvars, &
512               &               kdailyavtypes = nn_profdavtypes )
513               !
514            DO jvar = 1, nvarsprof(jtype)
515               CALL obs_prof_staend( profdata(jtype), jvar )
516            END DO
517            !
518            CALL obs_pre_prof( profdata(jtype), profdataqc(jtype), &
519               &               llvar, &
520               &               jpi, jpj, jpk, &
521               &               zmask, zglam, zgphi, &
522               &               ln_nea, ln_bound_reject, Kmm, &
523               &               kdailyavtypes = nn_profdavtypes )
524            !
525            DEALLOCATE( llvar, clvars, zglam, zgphi, zmask )
526            !
527         END DO
528         !
529         DEALLOCATE( ifilesprof, clproffiles )
530         !
531      ENDIF
532      !
533      IF( nsurftypes > 0 ) THEN
534         !
535         ALLOCATE( surfdata  (nsurftypes) , nvarssurf(nsurftypes) )
536         ALLOCATE( surfdataqc(nsurftypes) , nextrsurf(nsurftypes) )
537         !
538         DO jtype = 1, nsurftypes
539            !
540            nvarssurf(jtype) = 1
541            nextrsurf(jtype) = 0
542            llnightav(jtype) = .FALSE.
543            IF( TRIM(cobstypessurf(jtype)) == 'sla' )   nextrsurf(jtype) = 2
544            IF( TRIM(cobstypessurf(jtype)) == 'sst' )   llnightav(jtype) = ln_sstnight
545            !
546            ALLOCATE( clvars( nvarssurf(jtype) ) )
547            IF ( TRIM(cobstypessurf(jtype)) == 'sla' ) THEN
548               clvars(1) = 'SLA'
549            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sst' ) THEN
550               clvars(1) = 'SST'
551            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sic' ) THEN
552               clvars(1) = 'ICECONC'
553            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sss' ) THEN
554               clvars(1) = 'SSS'
555            ENDIF
556            !
557            ! Read in surface obs types
558            CALL obs_rea_surf( surfdata(jtype), ifilessurf(jtype), &
559               &               clsurffiles(jtype,1:ifilessurf(jtype)), &
560               &               nvarssurf(jtype), nextrsurf(jtype), nitend-nit000+2, &
561               &               rn_dobsini, rn_dobsend, ln_ignmis, .FALSE., llnightav(jtype), &
562               &               clvars )
563               !
564            CALL obs_pre_surf( surfdata(jtype), surfdataqc(jtype), ln_nea, ln_bound_reject )
565            !
566            IF( TRIM(cobstypessurf(jtype)) == 'sla' ) THEN
567               CALL obs_rea_mdt( surfdataqc(jtype), n2dintsurf(jtype), Kmm )
568               IF( ln_altbias )   &
569                  & CALL obs_rea_altbias ( surfdataqc(jtype), n2dintsurf(jtype), cn_altbiasfile )
570            ENDIF
571            !
572            IF( TRIM(cobstypessurf(jtype)) == 'sst' .AND. ln_sstbias ) THEN
573               jnumsstbias = 0
574               DO jfile = 1, jpmaxnfiles
575                  IF( TRIM(cn_sstbiasfiles(jfile)) /= '' )   jnumsstbias = jnumsstbias + 1
576               END DO
577               IF( jnumsstbias == 0 )   CALL ctl_stop("ln_sstbias set but no bias files to read in")   
578               !
579               CALL obs_app_sstbias( surfdataqc(jtype), n2dintsurf(jtype)             ,   & 
580                  &                  jnumsstbias      , cn_sstbiasfiles(1:jnumsstbias) ) 
581            ENDIF
582            !
583            DEALLOCATE( clvars )
584         END DO
585         !
586         DEALLOCATE( ifilessurf, clsurffiles )
587         !
588      ENDIF
589      !
590   END SUBROUTINE dia_obs_init
591
592
593   SUBROUTINE dia_obs( kstp, Kmm )
594      !!----------------------------------------------------------------------
595      !!                    ***  ROUTINE dia_obs  ***
596      !!         
597      !! ** Purpose : Call the observation operators on each time step
598      !!
599      !! ** Method  : Call the observation operators on each time step to
600      !!              compute the model equivalent of the following data:
601      !!               - Profile data, currently T/S or U/V
602      !!               - Surface data, currently SST, SLA or sea-ice concentration.
603      !!
604      !! ** Action  :
605      !!----------------------------------------------------------------------
606      USE dom_oce, ONLY : gdept, gdept_1d     ! Ocean space domain variables (Kmm time-level only)
607      USE phycst , ONLY : rday                ! Physical constants
608      USE oce    , ONLY : ts, uu, vv, ssh     ! Ocean dynamics and tracers variables (Kmm time-level only)
609      USE phycst , ONLY : rday                ! Physical constants
610#if defined  key_si3
611      USE ice    , ONLY : at_i                ! SI3 Ice model variables
612#endif
613#if defined key_cice
614      USE sbc_oce, ONLY : fr_i     ! ice fraction
615#endif
616
617      IMPLICIT NONE
618
619      !! * Arguments
620      INTEGER, INTENT(IN) :: kstp  ! Current timestep
621      INTEGER, INTENT(in) :: Kmm   ! ocean time level indices
622      !! * Local declarations
623      INTEGER :: idaystp           ! Number of timesteps per day
624      INTEGER :: jtype             ! Data loop variable
625      INTEGER :: jvar              ! Variable number
626      INTEGER :: ji, jj, jk        ! Loop counters
627      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: &
628         & zprofvar                ! Model values for variables in a prof ob
629      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: &
630         & zprofmask               ! Mask associated with zprofvar
631      REAL(wp), DIMENSION(jpi,jpj) :: &
632         & zsurfvar, &             ! Model values equivalent to surface ob.
633         & zsurfmask               ! Mask associated with surface variable
634      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
635         & zglam,    &             ! Model longitudes for prof variables
636         & zgphi                   ! Model latitudes for prof variables
637      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zdept, zdepw
638
639      !-----------------------------------------------------------------------
640
641      IF(lwp) THEN
642         WRITE(numout,*)
643         WRITE(numout,*) 'dia_obs : Call the observation operators', kstp
644         WRITE(numout,*) '~~~~~~~'
645      ENDIF
646
647      idaystp = NINT( rday / rn_Dt )
648
649      !-----------------------------------------------------------------------
650      ! Call the profile and surface observation operators
651      !-----------------------------------------------------------------------
652
653      IF ( nproftypes > 0 ) THEN
654
655         ALLOCATE( zdept(jpi,jpj,jpk), zdepw(jpi,jpj,jpk) )
656         DO jk = 1, jpk
657            zdept(:,:,jk) = gdept(:,:,jk,Kmm)
658            zdepw(:,:,jk) = gdepw(:,:,jk,Kmm)
659         END DO
660
661         DO jtype = 1, nproftypes
662
663            ! Allocate local work arrays
664            ALLOCATE( zprofvar (jpi, jpj, jpk, profdataqc(jtype)%nvar) )
665            ALLOCATE( zprofmask(jpi, jpj, jpk, profdataqc(jtype)%nvar) )
666            ALLOCATE( zglam    (jpi, jpj,      profdataqc(jtype)%nvar) )
667            ALLOCATE( zgphi    (jpi, jpj,      profdataqc(jtype)%nvar) ) 
668                             
669            ! Defaults which might change
670            DO jvar = 1, profdataqc(jtype)%nvar
671               zprofmask(:,:,:,jvar) = tmask(:,:,:)
672               zglam(:,:,jvar)       = glamt(:,:)
673               zgphi(:,:,jvar)       = gphit(:,:)
674            END DO
675
676            SELECT CASE ( TRIM(cobstypesprof(jtype)) )
677            CASE('prof')
678               zprofvar(:,:,:,1) = ts(:,:,:,jp_tem,Kmm)
679               zprofvar(:,:,:,2) = ts(:,:,:,jp_sal,Kmm)
680            CASE('vel')
681               zprofvar(:,:,:,1) = uu(:,:,:,Kmm)
682               zprofvar(:,:,:,2) = vv(:,:,:,Kmm)
683               zprofmask(:,:,:,1) = umask(:,:,:)
684               zprofmask(:,:,:,2) = vmask(:,:,:)
685               zglam(:,:,1) = glamu(:,:)
686               zglam(:,:,2) = glamv(:,:)
687               zgphi(:,:,1) = gphiu(:,:)
688               zgphi(:,:,2) = gphiv(:,:)
689            CASE DEFAULT
690               CALL ctl_stop( 'Unknown profile observation type '//TRIM(cobstypesprof(jtype))//' in dia_obs' )
691            END SELECT
692
693            DO jvar = 1, profdataqc(jtype)%nvar
694               CALL obs_prof_opt( profdataqc(jtype), kstp, jpi, jpj, jpk,  &
695                  &               nit000, idaystp, jvar,                   &
696                  &               zprofvar(:,:,:,jvar),                    &
697                  &               zdept(:,:,:), zdepw(:,:,:),      &
698                  &               zprofmask(:,:,:,jvar),                   &
699                  &               zglam(:,:,jvar), zgphi(:,:,jvar),        &
700                  &               nn_1dint, nn_2dint_default,              &
701                  &               kdailyavtypes = nn_profdavtypes )
702            END DO
703           
704            DEALLOCATE( zprofvar, zprofmask, zglam, zgphi )
705
706         END DO
707
708         DEALLOCATE( zdept, zdepw )
709
710      ENDIF
711
712      IF ( nsurftypes > 0 ) THEN
713
714         DO jtype = 1, nsurftypes
715
716            !Defaults which might be changed
717            zsurfmask(:,:) = tmask(:,:,1)
718
719            SELECT CASE ( TRIM(cobstypessurf(jtype)) )
720            CASE('sst')
721               zsurfvar(:,:) = ts(:,:,1,jp_tem,Kmm)
722            CASE('sla')
723               zsurfvar(:,:) = ssh(:,:,Kmm)
724            CASE('sss')
725               zsurfvar(:,:) = ts(:,:,1,jp_sal,Kmm)
726            CASE('sic')
727               IF ( kstp == 0 ) THEN
728                  IF ( lwp .AND. surfdataqc(jtype)%nsstpmpp(1) > 0 ) THEN
729                     CALL ctl_warn( 'Sea-ice not initialised on zeroth '// &
730                        &           'time-step but some obs are valid then.' )
731                     WRITE(numout,*)surfdataqc(jtype)%nsstpmpp(1), &
732                        &           ' sea-ice obs will be missed'
733                  ENDIF
734                  surfdataqc(jtype)%nsurfup = surfdataqc(jtype)%nsurfup + &
735                     &                        surfdataqc(jtype)%nsstp(1)
736                  CYCLE
737               ELSE
738#if defined key_cice || defined key_si3
739                  zsurfvar(:,:) = fr_i(:,:)
740#else
741                  CALL ctl_stop( ' Trying to run sea-ice observation operator', &
742                     &           ' but no sea-ice model appears to have been defined' )
743#endif
744               ENDIF
745
746            END SELECT
747
748            CALL obs_surf_opt( surfdataqc(jtype), kstp, jpi, jpj,       &
749               &               nit000, idaystp, zsurfvar, zsurfmask,    &
750               &               n2dintsurf(jtype), llnightav(jtype),     &
751               &               zavglamscl(jtype), zavgphiscl(jtype),     &
752               &               lfpindegs(jtype) )
753
754         END DO
755
756      ENDIF
757
758   END SUBROUTINE dia_obs
759
760   SUBROUTINE dia_obs_wri
761      !!----------------------------------------------------------------------
762      !!                    ***  ROUTINE dia_obs_wri  ***
763      !!         
764      !! ** Purpose : Call observation diagnostic output routines
765      !!
766      !! ** Method  : Call observation diagnostic output routines
767      !!
768      !! ** Action  :
769      !!
770      !! History :
771      !!        !  06-03  (K. Mogensen) Original code
772      !!        !  06-05  (K. Mogensen) Reformatted
773      !!        !  06-10  (A. Weaver) Cleaning
774      !!        !  07-03  (K. Mogensen) General handling of profiles
775      !!        !  08-09  (M. Valdivieso) Velocity component (U,V) profiles
776      !!        !  15-08  (M. Martin) Combined writing for prof and surf types
777      !!----------------------------------------------------------------------
778      !! * Modules used
779      USE obs_rot_vel          ! Rotation of velocities
780
781      IMPLICIT NONE
782
783      !! * Local declarations
784      INTEGER :: jtype                    ! Data set loop variable
785      INTEGER :: jo, jvar, jk
786      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
787         & zu, &
788         & zv
789
790      !-----------------------------------------------------------------------
791      ! Depending on switches call various observation output routines
792      !-----------------------------------------------------------------------
793
794      IF ( nproftypes > 0 ) THEN
795
796         DO jtype = 1, nproftypes
797
798            IF ( TRIM(cobstypesprof(jtype)) == 'vel' ) THEN
799
800               ! For velocity data, rotate the model velocities to N/S, E/W
801               ! using the compressed data structure.
802               ALLOCATE( &
803                  & zu(profdataqc(jtype)%nvprot(1)), &
804                  & zv(profdataqc(jtype)%nvprot(2))  &
805                  & )
806
807               CALL obs_rotvel( profdataqc(jtype), nn_2dint_default, zu, zv )
808
809               DO jo = 1, profdataqc(jtype)%nprof
810                  DO jvar = 1, 2
811                     DO jk = profdataqc(jtype)%npvsta(jo,jvar), profdataqc(jtype)%npvend(jo,jvar)
812
813                        IF ( jvar == 1 ) THEN
814                           profdataqc(jtype)%var(jvar)%vmod(jk) = zu(jk)
815                        ELSE
816                           profdataqc(jtype)%var(jvar)%vmod(jk) = zv(jk)
817                        ENDIF
818
819                     END DO
820                  END DO
821               END DO
822
823               DEALLOCATE( zu )
824               DEALLOCATE( zv )
825
826            END IF
827
828            CALL obs_prof_decompress( profdataqc(jtype), &
829               &                      profdata(jtype), .TRUE., numout )
830
831            CALL obs_wri_prof( profdata(jtype) )
832
833         END DO
834
835      ENDIF
836
837      IF ( nsurftypes > 0 ) THEN
838
839         DO jtype = 1, nsurftypes
840
841            CALL obs_surf_decompress( surfdataqc(jtype), &
842               &                      surfdata(jtype), .TRUE., numout )
843
844            CALL obs_wri_surf( surfdata(jtype) )
845
846         END DO
847
848      ENDIF
849
850   END SUBROUTINE dia_obs_wri
851
852   SUBROUTINE dia_obs_dealloc
853      IMPLICIT NONE
854      !!----------------------------------------------------------------------
855      !!                    *** ROUTINE dia_obs_dealloc ***
856      !!
857      !!  ** Purpose : To deallocate data to enable the obs_oper online loop.
858      !!               Specifically: dia_obs_init --> dia_obs --> dia_obs_wri
859      !!
860      !!  ** Method : Clean up various arrays left behind by the obs_oper.
861      !!
862      !!  ** Action :
863      !!
864      !!----------------------------------------------------------------------
865      ! obs_grid deallocation
866      CALL obs_grid_deallocate
867
868      ! diaobs deallocation
869      IF ( nproftypes > 0 ) &
870         &   DEALLOCATE( cobstypesprof, profdata, profdataqc, nvarsprof, nextrprof )
871
872      IF ( nsurftypes > 0 ) &
873         &   DEALLOCATE( cobstypessurf, surfdata, surfdataqc, nvarssurf, nextrsurf, &
874         &               n2dintsurf, zavglamscl, zavgphiscl, lfpindegs, llnightav )
875
876   END SUBROUTINE dia_obs_dealloc
877
878   SUBROUTINE calc_date( kstp, ddobs )
879      !!----------------------------------------------------------------------
880      !!                    ***  ROUTINE calc_date  ***
881      !!         
882      !! ** Purpose : Get date in double precision YYYYMMDD.HHMMSS format
883      !!
884      !! ** Method  : Get date in double precision YYYYMMDD.HHMMSS format
885      !!
886      !! ** Action  : Get date in double precision YYYYMMDD.HHMMSS format
887      !!
888      !! ** Action  : Get initial date in double precision YYYYMMDD.HHMMSS format
889      !!
890      !! History :
891      !!        !  06-03  (K. Mogensen)  Original code
892      !!        !  06-05  (K. Mogensen)  Reformatted
893      !!        !  06-10  (A. Weaver) Cleaning
894      !!        !  06-10  (G. Smith) Calculates initial date the same as method for final date
895      !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
896      !!        !  2014-09  (D. Lea) New generic routine now deals with arbitrary initial time of day
897      !!----------------------------------------------------------------------
898      USE phycst, ONLY : &            ! Physical constants
899         & rday
900      USE dom_oce, ONLY : &           ! Ocean space and time domain variables
901         & rn_Dt
902
903      IMPLICIT NONE
904
905      !! * Arguments
906      REAL(KIND=dp), INTENT(OUT) :: ddobs                        ! Date in YYYYMMDD.HHMMSS
907      INTEGER :: kstp
908
909      !! * Local declarations
910      INTEGER :: iyea        ! date - (year, month, day, hour, minute)
911      INTEGER :: imon
912      INTEGER :: iday
913      INTEGER :: ihou
914      INTEGER :: imin
915      INTEGER :: imday       ! Number of days in month.
916      REAL(wp) :: zdayfrc    ! Fraction of day
917
918      INTEGER, DIMENSION(12) ::   imonth_len    !: length in days of the months of the current year
919
920      !!----------------------------------------------------------------------
921      !! Initial date initialization (year, month, day, hour, minute)
922      !!----------------------------------------------------------------------
923      iyea =   ndate0 / 10000
924      imon = ( ndate0 - iyea * 10000 ) / 100
925      iday =   ndate0 - iyea * 10000 - imon * 100
926      ihou =   nn_time0 / 100
927      imin = ( nn_time0 - ihou * 100 ) 
928
929      !!----------------------------------------------------------------------
930      !! Compute number of days + number of hours + min since initial time
931      !!----------------------------------------------------------------------
932      zdayfrc = kstp * rn_Dt / rday
933      zdayfrc = zdayfrc - aint(zdayfrc)
934      imin = imin + int( zdayfrc * 24 * 60 ) 
935      DO WHILE (imin >= 60) 
936        imin=imin-60
937        ihou=ihou+1
938      END DO
939      DO WHILE (ihou >= 24)
940        ihou=ihou-24
941        iday=iday+1
942      END DO
943      iday = iday + kstp * rn_Dt / rday 
944
945      !-----------------------------------------------------------------------
946      ! Convert number of days (iday) into a real date
947      !----------------------------------------------------------------------
948
949      CALL calc_month_len( iyea, imonth_len )
950
951      DO WHILE ( iday > imonth_len(imon) )
952         iday = iday - imonth_len(imon)
953         imon = imon + 1 
954         IF ( imon > 12 ) THEN
955            imon = 1
956            iyea = iyea + 1
957            CALL calc_month_len( iyea, imonth_len )  ! update month lengths
958         ENDIF
959      END DO
960
961      !----------------------------------------------------------------------
962      ! Convert it into YYYYMMDD.HHMMSS format.
963      !----------------------------------------------------------------------
964      ddobs = iyea * 10000_dp + imon * 100_dp + &
965         &    iday + ihou * 0.01_dp + imin * 0.0001_dp
966
967   END SUBROUTINE calc_date
968
969   SUBROUTINE ini_date( ddobsini )
970      !!----------------------------------------------------------------------
971      !!                    ***  ROUTINE ini_date  ***
972      !!         
973      !! ** Purpose : Get initial date in double precision YYYYMMDD.HHMMSS format
974      !!
975      !! ** Method  :
976      !!
977      !! ** Action  :
978      !!
979      !! History :
980      !!        !  06-03  (K. Mogensen)  Original code
981      !!        !  06-05  (K. Mogensen)  Reformatted
982      !!        !  06-10  (A. Weaver) Cleaning
983      !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
984      !!        !  2014-09  (D. Lea) Change to call generic routine calc_date
985      !!----------------------------------------------------------------------
986
987      IMPLICIT NONE
988
989      !! * Arguments
990      REAL(KIND=dp), INTENT(OUT) :: ddobsini                   ! Initial date in YYYYMMDD.HHMMSS
991
992      CALL calc_date( nit000 - 1, ddobsini )
993
994   END SUBROUTINE ini_date
995
996   SUBROUTINE fin_date( ddobsfin )
997      !!----------------------------------------------------------------------
998      !!                    ***  ROUTINE fin_date  ***
999      !!         
1000      !! ** Purpose : Get final date in double precision YYYYMMDD.HHMMSS format
1001      !!
1002      !! ** Method  :
1003      !!
1004      !! ** Action  :
1005      !!
1006      !! History :
1007      !!        !  06-03  (K. Mogensen)  Original code
1008      !!        !  06-05  (K. Mogensen)  Reformatted
1009      !!        !  06-10  (A. Weaver) Cleaning
1010      !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
1011      !!        !  2014-09  (D. Lea) Change to call generic routine calc_date
1012      !!----------------------------------------------------------------------
1013
1014      IMPLICIT NONE
1015
1016      !! * Arguments
1017      REAL(dp), INTENT(OUT) :: ddobsfin ! Final date in YYYYMMDD.HHMMSS
1018
1019      CALL calc_date( nitend, ddobsfin )
1020
1021   END SUBROUTINE fin_date
1022   
1023   SUBROUTINE obs_settypefiles( ntypes, jpmaxnfiles, ifiles, cobstypes, cfiles )
1024
1025      INTEGER, INTENT(IN) :: ntypes      ! Total number of obs types
1026      INTEGER, INTENT(IN) :: jpmaxnfiles ! Maximum number of files allowed for each type
1027      INTEGER, DIMENSION(ntypes), INTENT(OUT) :: &
1028         &                   ifiles      ! Out number of files for each type
1029      CHARACTER(len=8), DIMENSION(ntypes), INTENT(IN) :: &
1030         &                   cobstypes   ! List of obs types
1031      CHARACTER(len=128), DIMENSION(ntypes, jpmaxnfiles), INTENT(IN) :: &
1032         &                   cfiles      ! List of files for all types
1033
1034      !Local variables
1035      INTEGER :: jfile
1036      INTEGER :: jtype
1037
1038      DO jtype = 1, ntypes
1039
1040         ifiles(jtype) = 0
1041         DO jfile = 1, jpmaxnfiles
1042            IF ( trim(cfiles(jtype,jfile)) /= '' ) &
1043                      ifiles(jtype) = ifiles(jtype) + 1
1044         END DO
1045
1046         IF ( ifiles(jtype) == 0 ) THEN
1047              CALL ctl_stop( 'Logical for observation type '//TRIM(cobstypes(jtype))//   &
1048                 &           ' set to true but no files available to read' )
1049         ENDIF
1050
1051         IF(lwp) THEN   
1052            WRITE(numout,*) '             '//cobstypes(jtype)//' input observation file names:'
1053            DO jfile = 1, ifiles(jtype)
1054               WRITE(numout,*) '                '//TRIM(cfiles(jtype,jfile))
1055            END DO
1056         ENDIF
1057
1058      END DO
1059
1060   END SUBROUTINE obs_settypefiles
1061
1062   SUBROUTINE obs_setinterpopts( ntypes, jtype, ctypein,             &
1063              &                  n2dint_default, n2dint_type,        &
1064              &                  ravglamscl_type, ravgphiscl_type,   &
1065              &                  lfp_indegs_type, lavnight_type,     &
1066              &                  n2dint, ravglamscl, ravgphiscl,     &
1067              &                  lfpindegs, lavnight )
1068
1069      INTEGER, INTENT(IN)  :: ntypes             ! Total number of obs types
1070      INTEGER, INTENT(IN)  :: jtype              ! Index of the current type of obs
1071      INTEGER, INTENT(IN)  :: n2dint_default     ! Default option for interpolation type
1072      INTEGER, INTENT(IN)  :: n2dint_type        ! Option for interpolation type
1073      REAL(wp), INTENT(IN) :: &
1074         &                    ravglamscl_type, & !E/W diameter of obs footprint for this type
1075         &                    ravgphiscl_type    !N/S diameter of obs footprint for this type
1076      LOGICAL, INTENT(IN)  :: lfp_indegs_type    !T=> footprint in degrees, F=> in metres
1077      LOGICAL, INTENT(IN)  :: lavnight_type      !T=> obs represent night time average
1078      CHARACTER(len=8), INTENT(IN) :: ctypein 
1079
1080      INTEGER, DIMENSION(ntypes), INTENT(INOUT) :: &
1081         &                    n2dint 
1082      REAL(wp), DIMENSION(ntypes), INTENT(INOUT) :: &
1083         &                    ravglamscl, ravgphiscl
1084      LOGICAL, DIMENSION(ntypes), INTENT(INOUT) :: &
1085         &                    lfpindegs, lavnight
1086
1087      lavnight(jtype) = lavnight_type
1088
1089      IF ( (n2dint_type >= 0) .AND. (n2dint_type <= 6) ) THEN
1090         n2dint(jtype) = n2dint_type
1091      ELSE IF ( n2dint_type == -1 ) THEN
1092         n2dint(jtype) = n2dint_default
1093      ELSE
1094         CALL ctl_stop(' Choice of '//TRIM(ctypein)//' horizontal (2D) interpolation method', &
1095           &                    ' is not available')
1096      ENDIF
1097
1098      ! For averaging observation footprints set options for size of footprint
1099      IF ( (n2dint(jtype) > 4) .AND. (n2dint(jtype) <= 6) ) THEN
1100         IF ( ravglamscl_type > 0._wp ) THEN
1101            ravglamscl(jtype) = ravglamscl_type
1102         ELSE
1103            CALL ctl_stop( 'Incorrect value set for averaging footprint '// &
1104                           'scale (ravglamscl) for observation type '//TRIM(ctypein) )     
1105         ENDIF
1106
1107         IF ( ravgphiscl_type > 0._wp ) THEN
1108            ravgphiscl(jtype) = ravgphiscl_type
1109         ELSE
1110            CALL ctl_stop( 'Incorrect value set for averaging footprint '// &
1111                           'scale (ravgphiscl) for observation type '//TRIM(ctypein) )     
1112         ENDIF
1113
1114         lfpindegs(jtype) = lfp_indegs_type 
1115
1116      ENDIF
1117
1118      ! Write out info
1119      IF(lwp) THEN
1120         IF ( n2dint(jtype) <= 4 ) THEN
1121            WRITE(numout,*) '             '//TRIM(ctypein)// &
1122               &            ' model counterparts will be interpolated horizontally'
1123         ELSE IF ( n2dint(jtype) <= 6 ) THEN
1124            WRITE(numout,*) '             '//TRIM(ctypein)// &
1125               &            ' model counterparts will be averaged horizontally'
1126            WRITE(numout,*) '             '//'    with E/W scale: ',ravglamscl(jtype)
1127            WRITE(numout,*) '             '//'    with N/S scale: ',ravgphiscl(jtype)
1128            IF ( lfpindegs(jtype) ) THEN
1129                WRITE(numout,*) '             '//'    (in degrees)'
1130            ELSE
1131                WRITE(numout,*) '             '//'    (in metres)'
1132            ENDIF
1133         ENDIF
1134      ENDIF
1135
1136   END SUBROUTINE obs_setinterpopts
1137
1138END MODULE diaobs
Note: See TracBrowser for help on using the repository browser.