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 branches/UKMO/dev_r4650_general_vert_coord_obsoper/NEMOGCM/NEMO/OPA_SRC/OBS – NEMO

source: branches/UKMO/dev_r4650_general_vert_coord_obsoper/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90 @ 6326

Last change on this file since 6326 was 6326, checked in by kingr, 8 years ago

Manually merged sst bias correction code from branches/2014/dev_r4650_UKMO14.5_SST_BIAS_CORRECTION@r4768. Had merge issues when using branch directly, possibly due to svn keywords not having been fully cleared.

File size: 62.9 KB
Line 
1MODULE diaobs
2   !!======================================================================
3   !!                       ***  MODULE diaobs  ***
4   !! Observation diagnostics: Computation of the misfit between data and
5   !!                          their model equivalent
6   !!======================================================================
7
8   !!----------------------------------------------------------------------
9   !!   'key_diaobs' : Switch on the observation diagnostic computation
10   !!----------------------------------------------------------------------
11   !!   dia_obs_init : Reading and prepare observations
12   !!   dia_obs      : Compute model equivalent to observations
13   !!   dia_obs_wri  : Write observational diagnostics
14   !!   ini_date     : Compute the initial date YYYYMMDD.HHMMSS
15   !!   fin_date     : Compute the final date YYYYMMDD.HHMMSS
16   !!----------------------------------------------------------------------
17   !! * Modules used   
18   USE wrk_nemo                 ! Memory Allocation
19   USE par_kind                 ! Precision variables
20   USE in_out_manager           ! I/O manager
21   USE par_oce
22   USE dom_oce                  ! Ocean space and time domain variables
23   USE obs_fbm, ONLY: ln_cl4    ! Class 4 diagnostic switch
24   USE obs_read_prof            ! Reading and allocation of observations (Coriolis)
25   USE obs_read_sla             ! Reading and allocation of SLA observations 
26   USE obs_read_sst             ! Reading and allocation of SST observations 
27   USE obs_sstbias              ! Bias correction routine for SST
28   USE obs_readmdt              ! Reading and allocation of MDT for SLA.
29   USE obs_read_seaice          ! Reading and allocation of Sea Ice observations 
30   USE obs_read_vel             ! Reading and allocation of velocity component observations
31   USE obs_prep                 ! Preparation of obs. (grid search etc).
32   USE obs_oper                 ! Observation operators
33   USE obs_write                ! Writing of observation related diagnostics
34   USE obs_grid                 ! Grid searching
35   USE obs_read_altbias         ! Bias treatment for altimeter
36   USE obs_profiles_def         ! Profile data definitions
37   USE obs_profiles             ! Profile data storage
38   USE obs_surf_def             ! Surface data definitions
39   USE obs_sla                  ! SLA data storage
40   USE obs_sst                  ! SST data storage
41   USE obs_seaice               ! Sea Ice data storage
42   USE obs_types                ! Definitions for observation types
43   USE mpp_map                  ! MPP mapping
44   USE lib_mpp                  ! For ctl_warn/stop
45
46   IMPLICIT NONE
47
48   !! * Routine accessibility
49   PRIVATE
50   PUBLIC dia_obs_init, &  ! Initialize and read observations
51      &   dia_obs,      &  ! Compute model equivalent to observations
52      &   dia_obs_wri,  &  ! Write model equivalent to observations
53      &   dia_obs_dealloc  ! Deallocate dia_obs data
54
55   !! * Shared Module variables
56   LOGICAL, PUBLIC, PARAMETER :: &
57#if defined key_diaobs
58      & lk_diaobs = .TRUE.   !: Logical switch for observation diangostics
59#else
60      & lk_diaobs = .FALSE.  !: Logical switch for observation diangostics
61#endif
62
63   !! * Module variables
64   LOGICAL, PUBLIC :: ln_t3d         !: Logical switch for temperature profiles
65   LOGICAL, PUBLIC :: ln_s3d         !: Logical switch for salinity profiles
66   LOGICAL, PUBLIC :: ln_ena         !: Logical switch for the ENACT data set
67   LOGICAL, PUBLIC :: ln_cor         !: Logical switch for the Coriolis data set
68   LOGICAL, PUBLIC :: ln_profb       !: Logical switch for profile feedback datafiles
69   LOGICAL, PUBLIC :: ln_sla         !: Logical switch for sea level anomalies
70   LOGICAL, PUBLIC :: ln_sladt       !: Logical switch for SLA from AVISO files
71   LOGICAL, PUBLIC :: ln_slafb       !: Logical switch for SLA from feedback files
72   LOGICAL, PUBLIC :: ln_sst         !: Logical switch for sea surface temperature
73   LOGICAL, PUBLIC :: ln_reysst      !: Logical switch for Reynolds sea surface temperature
74   LOGICAL, PUBLIC :: ln_ghrsst      !: Logical switch for GHRSST data
75   LOGICAL, PUBLIC :: ln_sstfb       !: Logical switch for SST from feedback files
76   LOGICAL, PUBLIC :: ln_seaice      !: Logical switch for sea ice concentration
77   LOGICAL, PUBLIC :: ln_vel3d       !: Logical switch for velocity component (u,v) observations
78   LOGICAL, PUBLIC :: ln_velavcur    !: Logical switch for raw daily averaged netCDF current meter vel. data
79   LOGICAL, PUBLIC :: ln_velhrcur    !: Logical switch for raw high freq netCDF current meter vel. data
80   LOGICAL, PUBLIC :: ln_velavadcp   !: Logical switch for raw daily averaged netCDF ADCP vel. data
81   LOGICAL, PUBLIC :: ln_velhradcp   !: Logical switch for raw high freq netCDF ADCP vel. data
82   LOGICAL, PUBLIC :: ln_velfb       !: Logical switch for velocities from feedback files
83   LOGICAL, PUBLIC :: ln_ssh         !: Logical switch for sea surface height
84   LOGICAL, PUBLIC :: ln_sss         !: Logical switch for sea surface salinity
85   LOGICAL, PUBLIC :: ln_sstnight    !: Logical switch for night mean SST observations
86   LOGICAL, PUBLIC :: ln_nea         !: Remove observations near land
87   LOGICAL, PUBLIC :: ln_altbias     !: Logical switch for altimeter bias 
88   LOGICAL, PUBLIC :: ln_ignmis      !: Logical switch for ignoring missing files
89   LOGICAL, PUBLIC :: ln_s_at_t      !: Logical switch to compute model S at T observations
90   LOGICAL, PUBLIC :: ln_sstbias     !: Logical switch for bias corection of SST
91
92   REAL(KIND=dp), PUBLIC :: dobsini   !: Observation window start date YYYYMMDD.HHMMSS
93   REAL(KIND=dp), PUBLIC :: dobsend   !: Observation window end date YYYYMMDD.HHMMSS
94 
95   INTEGER, PUBLIC :: n1dint       !: Vertical interpolation method
96   INTEGER, PUBLIC :: n2dint       !: Horizontal interpolation method
97
98   INTEGER, DIMENSION(imaxavtypes) :: &
99      & endailyavtypes !: ENACT data types which are daily average
100
101   INTEGER, PARAMETER :: MaxNumFiles = 1000
102   LOGICAL, DIMENSION(MaxNumFiles) :: &
103      & ln_profb_ena, & !: Is the feedback files from ENACT data ?
104   !                    !: If so use endailyavtypes
105      & ln_profb_enatim !: Change tim for 820 enact data set.
106   
107   INTEGER, DIMENSION(MaxNumFiles), PUBLIC :: sstbias_type !SST bias type
108
109   LOGICAL, DIMENSION(MaxNumFiles) :: &
110      & ln_velfb_av   !: Is the velocity feedback files daily average?
111   LOGICAL, DIMENSION(:), ALLOCATABLE :: &
112      & ld_enact     !: Profile data is ENACT so use endailyavtypes
113   LOGICAL, DIMENSION(:), ALLOCATABLE :: &
114      & ld_velav     !: Velocity data is daily averaged
115   LOGICAL, DIMENSION(:), ALLOCATABLE :: &
116      & ld_sstnight  !: SST observation corresponds to night mean
117
118   !!----------------------------------------------------------------------
119   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
120   !! $Id$
121   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
122   !!----------------------------------------------------------------------
123
124   !! * Substitutions
125#  include "domzgr_substitute.h90"
126CONTAINS
127
128   SUBROUTINE dia_obs_init
129      !!----------------------------------------------------------------------
130      !!                    ***  ROUTINE dia_obs_init  ***
131      !!         
132      !! ** Purpose : Initialize and read observations
133      !!
134      !! ** Method  : Read the namelist and call reading routines
135      !!
136      !! ** Action  : Read the namelist and call reading routines
137      !!
138      !! History :
139      !!        !  06-03  (K. Mogensen) Original code
140      !!        !  06-05  (A. Weaver) Reformatted
141      !!        !  06-10  (A. Weaver) Cleaning and add controls
142      !!        !  07-03  (K. Mogensen) General handling of profiles
143      !!        !  14-08  (J.While) Incorporated SST bias correction
144      !!----------------------------------------------------------------------
145
146      IMPLICIT NONE
147
148      !! * Local declarations
149      CHARACTER(len=128) :: enactfiles(MaxNumFiles)
150      CHARACTER(len=128) :: coriofiles(MaxNumFiles)
151      CHARACTER(len=128) :: profbfiles(MaxNumFiles)
152      CHARACTER(len=128) :: sstfiles(MaxNumFiles)     
153      CHARACTER(len=128) :: sstfbfiles(MaxNumFiles)
154      CHARACTER(len=128) :: sstbias_files(MaxNumFiles) 
155      CHARACTER(len=128) :: slafilesact(MaxNumFiles)     
156      CHARACTER(len=128) :: slafilespas(MaxNumFiles)     
157      CHARACTER(len=128) :: slafbfiles(MaxNumFiles)
158      CHARACTER(len=128) :: seaicefiles(MaxNumFiles)           
159      CHARACTER(len=128) :: velcurfiles(MaxNumFiles) 
160      CHARACTER(len=128) :: veladcpfiles(MaxNumFiles)   
161      CHARACTER(len=128) :: velavcurfiles(MaxNumFiles)
162      CHARACTER(len=128) :: velhrcurfiles(MaxNumFiles)
163      CHARACTER(len=128) :: velavadcpfiles(MaxNumFiles)
164      CHARACTER(len=128) :: velhradcpfiles(MaxNumFiles)
165      CHARACTER(len=128) :: velfbfiles(MaxNumFiles)
166      CHARACTER(LEN=128) :: reysstname
167      CHARACTER(LEN=12)  :: reysstfmt
168      CHARACTER(LEN=128) :: bias_file
169      CHARACTER(LEN=20)  :: datestr=" ", timestr=" "
170      NAMELIST/namobs/ln_ena, ln_cor, ln_profb, ln_t3d, ln_s3d,       &
171         &            ln_sla, ln_sladt, ln_slafb,                     &
172         &            ln_ssh, ln_sst, ln_sstfb, ln_sss, ln_nea,       &
173         &            enactfiles, coriofiles, profbfiles,             &
174         &            slafilesact, slafilespas, slafbfiles,           &
175         &            sstfiles, sstfbfiles,                           &
176         &            ln_seaice, seaicefiles,                         &
177         &            dobsini, dobsend, n1dint, n2dint,               &
178         &            nmsshc, mdtcorr, mdtcutoff,                     &
179         &            ln_reysst, ln_ghrsst, reysstname, reysstfmt,    &
180         &            ln_sstnight,                                    &
181         &            ln_grid_search_lookup,                          &
182         &            grid_search_file, grid_search_res,              &
183         &            ln_grid_global, bias_file, ln_altbias,          &
184         &            endailyavtypes, ln_s_at_t, ln_profb_ena,        &
185         &            ln_vel3d, ln_velavcur, velavcurfiles,           &
186         &            ln_velhrcur, velhrcurfiles,                     &
187         &            ln_velavadcp, velavadcpfiles,                   &
188         &            ln_velhradcp, velhradcpfiles,                   &
189         &            ln_velfb, velfbfiles, ln_velfb_av,              &
190         &            ln_profb_enatim, ln_ignmis, ln_cl4,             &
191         &            ln_sstbias, sstbias_files
192
193      INTEGER :: jprofset
194      INTEGER :: jveloset
195      INTEGER :: jvar
196      INTEGER :: jnumenact
197      INTEGER :: jnumcorio
198      INTEGER :: jnumprofb
199      INTEGER :: jnumslaact
200      INTEGER :: jnumslapas
201      INTEGER :: jnumslafb
202      INTEGER :: jnumsst
203      INTEGER :: jnumsstfb
204      INTEGER :: jnumsstbias
205      INTEGER :: jnumseaice
206      INTEGER :: jnumvelavcur
207      INTEGER :: jnumvelhrcur 
208      INTEGER :: jnumvelavadcp
209      INTEGER :: jnumvelhradcp   
210      INTEGER :: jnumvelfb
211      INTEGER :: ji
212      INTEGER :: jset
213      INTEGER :: ios                 ! Local integer output status for namelist read
214      LOGICAL :: lmask(MaxNumFiles), ll_u3d, ll_v3d
215
216      !-----------------------------------------------------------------------
217      ! Read namelist parameters
218      !-----------------------------------------------------------------------
219     
220      !Initalise all values in namelist arrays
221      enactfiles(:) = ''
222      coriofiles(:) = ''
223      profbfiles(:) = ''
224      slafilesact(:) = ''
225      slafilespas(:) = ''
226      slafbfiles(:) = ''
227      sstfiles(:)   = ''
228      sstfbfiles(:) = ''
229      seaicefiles(:) = ''
230      velcurfiles(:) = ''
231      veladcpfiles(:) = ''
232      velavcurfiles(:) = ''
233      velhrcurfiles(:) = ''
234      velavadcpfiles(:) = ''
235      velhradcpfiles(:) = ''
236      velfbfiles(:) = ''
237      velcurfiles(:) = ''
238      veladcpfiles(:) = ''
239      sstbias_files(:) = ''
240      endailyavtypes(:) = -1
241      endailyavtypes(1) = 820
242      ln_profb_ena(:) = .FALSE.
243      ln_profb_enatim(:) = .TRUE.
244      ln_velfb_av(:) = .FALSE.
245      ln_ignmis = .FALSE.
246
247      CALL ini_date( dobsini )
248      CALL fin_date( dobsend )
249 
250      ! Read Namelist namobs : control observation diagnostics
251      REWIND( numnam_ref )              ! Namelist namobs in reference namelist : Diagnostic: control observation
252      READ  ( numnam_ref, namobs, IOSTAT = ios, ERR = 901)
253901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namobs in reference namelist', lwp )
254
255      REWIND( numnam_cfg )              ! Namelist namobs in configuration namelist : Diagnostic: control observation
256      READ  ( numnam_cfg, namobs, IOSTAT = ios, ERR = 902 )
257902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namobs in configuration namelist', lwp )
258      IF(lwm) WRITE ( numond, namobs )
259
260      ! Count number of files for each type
261      IF (ln_ena) THEN
262         lmask(:) = .FALSE.
263         WHERE (enactfiles(:) /= '') lmask(:) = .TRUE.
264         jnumenact = COUNT(lmask)
265      ENDIF
266      IF (ln_cor) THEN
267         lmask(:) = .FALSE.
268         WHERE (coriofiles(:) /= '') lmask(:) = .TRUE.
269         jnumcorio = COUNT(lmask)
270      ENDIF
271      IF (ln_profb) THEN
272         lmask(:) = .FALSE.
273         WHERE (profbfiles(:) /= '') lmask(:) = .TRUE.
274         jnumprofb = COUNT(lmask)
275      ENDIF
276      IF (ln_sladt) THEN
277         lmask(:) = .FALSE.
278         WHERE (slafilesact(:) /= '') lmask(:) = .TRUE.
279         jnumslaact = COUNT(lmask)
280         lmask(:) = .FALSE.
281         WHERE (slafilespas(:) /= '') lmask(:) = .TRUE.
282         jnumslapas = COUNT(lmask)
283      ENDIF
284      IF (ln_slafb) THEN
285         lmask(:) = .FALSE.
286         WHERE (slafbfiles(:) /= '') lmask(:) = .TRUE.
287         jnumslafb = COUNT(lmask)
288         lmask(:) = .FALSE.
289      ENDIF
290      IF (ln_ghrsst) THEN
291         lmask(:) = .FALSE.
292         WHERE (sstfiles(:) /= '') lmask(:) = .TRUE.
293         jnumsst = COUNT(lmask)
294      ENDIF     
295      IF (ln_sstfb) THEN
296         lmask(:) = .FALSE.
297         WHERE (sstfbfiles(:) /= '') lmask(:) = .TRUE.
298         jnumsstfb = COUNT(lmask)
299         lmask(:) = .FALSE.
300      ENDIF
301      IF (ln_sstbias) THEN 
302         lmask(:) = .FALSE. 
303         WHERE (sstbias_files(:) /= '') lmask(:) = .TRUE. 
304         jnumsstbias = COUNT(lmask) 
305         lmask(:) = .FALSE. 
306      ENDIF       
307      IF (ln_seaice) THEN
308         lmask(:) = .FALSE.
309         WHERE (seaicefiles(:) /= '') lmask(:) = .TRUE.
310         jnumseaice = COUNT(lmask)
311      ENDIF
312      IF (ln_velavcur) THEN
313         lmask(:) = .FALSE.
314         WHERE (velavcurfiles(:) /= '') lmask(:) = .TRUE.
315         jnumvelavcur = COUNT(lmask)
316      ENDIF
317      IF (ln_velhrcur) THEN
318         lmask(:) = .FALSE.
319         WHERE (velhrcurfiles(:) /= '') lmask(:) = .TRUE.
320         jnumvelhrcur = COUNT(lmask)
321      ENDIF
322      IF (ln_velavadcp) THEN
323         lmask(:) = .FALSE.
324         WHERE (velavadcpfiles(:) /= '') lmask(:) = .TRUE.
325         jnumvelavadcp = COUNT(lmask)
326      ENDIF
327      IF (ln_velhradcp) THEN
328         lmask(:) = .FALSE.
329         WHERE (velhradcpfiles(:) /= '') lmask(:) = .TRUE.
330         jnumvelhradcp = COUNT(lmask)
331      ENDIF
332      IF (ln_velfb) THEN
333         lmask(:) = .FALSE.
334         WHERE (velfbfiles(:) /= '') lmask(:) = .TRUE.
335         jnumvelfb = COUNT(lmask)
336         lmask(:) = .FALSE.
337      ENDIF
338     
339      ! Control print
340      IF(lwp) THEN
341         WRITE(numout,*)
342         WRITE(numout,*) 'dia_obs_init : Observation diagnostic initialization'
343         WRITE(numout,*) '~~~~~~~~~~~~'
344         WRITE(numout,*) '          Namelist namobs : set observation diagnostic parameters' 
345         WRITE(numout,*) '             Logical switch for T profile observations          ln_t3d = ', ln_t3d
346         WRITE(numout,*) '             Logical switch for S profile observations          ln_s3d = ', ln_s3d
347         WRITE(numout,*) '             Logical switch for ENACT insitu data set           ln_ena = ', ln_ena
348         WRITE(numout,*) '             Logical switch for Coriolis insitu data set        ln_cor = ', ln_cor
349         WRITE(numout,*) '             Logical switch for feedback insitu data set      ln_profb = ', ln_profb
350         WRITE(numout,*) '             Logical switch for SLA observations                ln_sla = ', ln_sla
351         WRITE(numout,*) '             Logical switch for AVISO SLA data                ln_sladt = ', ln_sladt
352         WRITE(numout,*) '             Logical switch for feedback SLA data             ln_slafb = ', ln_slafb
353         WRITE(numout,*) '             Logical switch for SSH observations                ln_ssh = ', ln_ssh
354         WRITE(numout,*) '             Logical switch for SST observations                ln_sst = ', ln_sst
355         WRITE(numout,*) '             Logical switch for Reynolds observations        ln_reysst = ', ln_reysst   
356         WRITE(numout,*) '             Logical switch for GHRSST observations          ln_ghrsst = ', ln_ghrsst
357         WRITE(numout,*) '             Logical switch for feedback SST data             ln_sstfb = ', ln_sstfb
358         WRITE(numout,*) '             Logical switch for SST bias correction         ln_sstbias = ', ln_sstbias
359         WRITE(numout,*) '             Logical switch for night-time SST obs         ln_sstnight = ', ln_sstnight
360         WRITE(numout,*) '             Logical switch for SSS observations                ln_sss = ', ln_sss
361         WRITE(numout,*) '             Logical switch for Sea Ice observations         ln_seaice = ', ln_seaice
362         WRITE(numout,*) '             Logical switch for velocity observations         ln_vel3d = ', ln_vel3d
363         WRITE(numout,*) '             Logical switch for velocity daily av. cur.    ln_velavcur = ', ln_velavcur
364         WRITE(numout,*) '             Logical switch for velocity high freq. cur.   ln_velhrcur = ', ln_velhrcur
365         WRITE(numout,*) '             Logical switch for velocity daily av. ADCP   ln_velavadcp = ', ln_velavadcp
366         WRITE(numout,*) '             Logical switch for velocity high freq. ADCP  ln_velhradcp = ', ln_velhradcp
367         WRITE(numout,*) '             Logical switch for feedback velocity data        ln_velfb = ', ln_velfb
368         WRITE(numout,*) '             Global distribtion of observations         ln_grid_global = ',ln_grid_global
369         WRITE(numout,*) &
370   '             Logical switch for obs grid search w/lookup table  ln_grid_search_lookup = ',ln_grid_search_lookup
371         IF (ln_grid_search_lookup) &
372            WRITE(numout,*) '             Grid search lookup file header       grid_search_file = ', grid_search_file
373         IF (ln_ena) THEN
374            DO ji = 1, jnumenact
375               WRITE(numout,'(1X,2A)') '             ENACT input observation file name          enactfiles = ', &
376                  TRIM(enactfiles(ji))
377            END DO
378         ENDIF
379         IF (ln_cor) THEN
380            DO ji = 1, jnumcorio
381               WRITE(numout,'(1X,2A)') '             Coriolis input observation file name       coriofiles = ', &
382                  TRIM(coriofiles(ji))
383            END DO
384         ENDIF
385         IF (ln_profb) THEN
386            DO ji = 1, jnumprofb
387               IF (ln_profb_ena(ji)) THEN
388                  WRITE(numout,'(1X,2A)') '       Enact feedback input observation file name       profbfiles = ', &
389                     TRIM(profbfiles(ji))
390               ELSE
391                  WRITE(numout,'(1X,2A)') '             Feedback input observation file name       profbfiles = ', &
392                     TRIM(profbfiles(ji))
393               ENDIF
394               WRITE(numout,'(1X,2A)') '       Enact feedback input time setting switch    ln_profb_enatim = ', ln_profb_enatim(ji)
395            END DO
396         ENDIF
397         IF (ln_sladt) THEN
398            DO ji = 1, jnumslaact
399               WRITE(numout,'(1X,2A)') '             Active SLA input observation file name    slafilesact = ', &
400                  TRIM(slafilesact(ji))
401            END DO
402            DO ji = 1, jnumslapas
403               WRITE(numout,'(1X,2A)') '             Passive SLA input observation file name   slafilespas = ', &
404                  TRIM(slafilespas(ji))
405            END DO
406         ENDIF
407         IF (ln_slafb) THEN
408            DO ji = 1, jnumslafb
409               WRITE(numout,'(1X,2A)') '             Feedback SLA input observation file name   slafbfiles = ', &
410                  TRIM(slafbfiles(ji))
411            END DO
412         ENDIF
413         IF (ln_ghrsst) THEN
414            DO ji = 1, jnumsst
415               WRITE(numout,'(1X,2A)') '             GHRSST input observation file name           sstfiles = ', &
416                  TRIM(sstfiles(ji))
417            END DO
418         ENDIF
419         IF (ln_sstfb) THEN
420            DO ji = 1, jnumsstfb
421               WRITE(numout,'(1X,2A)') '             Feedback SST input observation file name   sstfbfiles = ', &
422                  TRIM(sstfbfiles(ji))
423            END DO
424         ENDIF
425         IF (ln_seaice) THEN
426            DO ji = 1, jnumseaice
427               WRITE(numout,'(1X,2A)') '             Sea Ice input observation file name       seaicefiles = ', &
428                  TRIM(seaicefiles(ji))
429            END DO
430         ENDIF
431         IF (ln_velavcur) THEN
432            DO ji = 1, jnumvelavcur
433               WRITE(numout,'(1X,2A)') '             Vel. cur. daily av. input file name     velavcurfiles = ', &
434                  TRIM(velavcurfiles(ji))
435            END DO
436         ENDIF
437         IF (ln_velhrcur) THEN
438            DO ji = 1, jnumvelhrcur
439               WRITE(numout,'(1X,2A)') '             Vel. cur. high freq. input file name    velhvcurfiles = ', &
440                  TRIM(velhrcurfiles(ji))
441            END DO
442         ENDIF
443         IF (ln_velavadcp) THEN
444            DO ji = 1, jnumvelavadcp
445               WRITE(numout,'(1X,2A)') '             Vel. ADCP daily av. input file name    velavadcpfiles = ', &
446                  TRIM(velavadcpfiles(ji))
447            END DO
448         ENDIF
449         IF (ln_velhradcp) THEN
450            DO ji = 1, jnumvelhradcp
451               WRITE(numout,'(1X,2A)') '             Vel. ADCP high freq. input file name   velhvadcpfiles = ', &
452                  TRIM(velhradcpfiles(ji))
453            END DO
454         ENDIF
455         IF (ln_velfb) THEN
456            DO ji = 1, jnumvelfb
457               IF (ln_velfb_av(ji)) THEN
458                  WRITE(numout,'(1X,2A)') '             Vel. feedback daily av. input file name    velfbfiles = ', &
459                     TRIM(velfbfiles(ji))
460               ELSE
461                  WRITE(numout,'(1X,2A)') '             Vel. feedback input observation file name  velfbfiles = ', &
462                     TRIM(velfbfiles(ji))
463               ENDIF
464            END DO
465         ENDIF
466         WRITE(numout,*) '             Initial date in window YYYYMMDD.HHMMSS        dobsini = ', dobsini
467         WRITE(numout,*) '             Final date in window YYYYMMDD.HHMMSS          dobsend = ', dobsend
468         WRITE(numout,*) '             Type of vertical interpolation method          n1dint = ', n1dint
469         WRITE(numout,*) '             Type of horizontal interpolation method        n2dint = ', n2dint
470         WRITE(numout,*) '             Rejection of observations near land swithch    ln_nea = ', ln_nea
471         WRITE(numout,*) '             MSSH correction scheme                         nmsshc = ', nmsshc
472         WRITE(numout,*) '             MDT  correction                               mdtcorr = ', mdtcorr
473         WRITE(numout,*) '             MDT cutoff for computed correction          mdtcutoff = ', mdtcutoff
474         WRITE(numout,*) '             Logical switch for alt bias                ln_altbias = ', ln_altbias
475         WRITE(numout,*) '             Logical switch for ignoring missing files   ln_ignmis = ', ln_ignmis
476         WRITE(numout,*) '             ENACT daily average types                             = ',endailyavtypes
477
478      ENDIF
479     
480      IF ( ln_vel3d .AND. ( .NOT. ln_grid_global ) ) THEN
481         CALL ctl_stop( 'Velocity data only works with ln_grid_global=.true.' )
482         RETURN
483      ENDIF
484
485      CALL obs_typ_init
486     
487      CALL mppmap_init
488     
489      ! Parameter control
490#if defined key_diaobs
491      IF ( ( .NOT. ln_t3d ).AND.( .NOT. ln_s3d ).AND.( .NOT. ln_sla ).AND. &
492         & ( .NOT. ln_vel3d ).AND.                                         &
493         & ( .NOT. ln_ssh ).AND.( .NOT. ln_sst ).AND.( .NOT. ln_sss ).AND. &
494         & ( .NOT. ln_seaice ).AND.( .NOT. ln_vel3d ) ) THEN
495         IF(lwp) WRITE(numout,cform_war)
496         IF(lwp) WRITE(numout,*) ' key_diaobs is activated but logical flags', &
497            &                    ' ln_t3d, ln_s3d, ln_sla, ln_ssh, ln_sst, ln_sss, ln_seaice, ln_vel3d are all set to .FALSE.'
498         nwarn = nwarn + 1
499      ENDIF
500#endif
501
502      CALL obs_grid_setup( )
503      IF ( ( n1dint < 0 ).OR.( n1dint > 1 ) ) THEN
504         CALL ctl_stop(' Choice of vertical (1D) interpolation method', &
505            &                    ' is not available')
506      ENDIF
507      IF ( ( n2dint < 0 ).OR.( n2dint > 4 ) ) THEN
508         CALL ctl_stop(' Choice of horizontal (2D) interpolation method', &
509            &                    ' is not available')
510      ENDIF
511
512      !-----------------------------------------------------------------------
513      ! Depending on switches read the various observation types
514      !-----------------------------------------------------------------------
515      !  - Temperature/salinity profiles
516
517      IF ( ln_t3d .OR. ln_s3d ) THEN
518
519         ! Set the number of variables for profiles to 2 (T and S)
520         nprofvars = 2
521         ! Set the number of extra variables for profiles to 1 (insitu temp).
522         nprofextr = 1
523
524         ! Count how may insitu data sets we have and allocate data.
525         jprofset = 0
526         IF ( ln_ena ) jprofset = jprofset + 1
527         IF ( ln_cor ) jprofset = jprofset + 1
528         IF ( ln_profb ) jprofset = jprofset + jnumprofb
529         nprofsets = jprofset
530         IF ( nprofsets > 0 ) THEN
531            ALLOCATE(ld_enact(nprofsets))
532            ALLOCATE(profdata(nprofsets))
533            ALLOCATE(prodatqc(nprofsets))
534         ENDIF
535
536         jprofset = 0
537         
538         ! ENACT insitu data
539
540         IF ( ln_ena ) THEN
541
542            jprofset = jprofset + 1
543           
544            ld_enact(jprofset) = .TRUE.
545
546            CALL obs_rea_pro_dri( 1, profdata(jprofset),          &
547               &                  jnumenact, enactfiles(1:jnumenact), &
548               &                  nprofvars, nprofextr,        &
549               &                  nitend-nit000+2,             &
550               &                  dobsini, dobsend, ln_t3d, ln_s3d, &
551               &                  ln_ignmis, ln_s_at_t, .TRUE., .FALSE., &
552               &                  kdailyavtypes = endailyavtypes )
553
554            DO jvar = 1, 2
555
556               CALL obs_prof_staend( profdata(jprofset), jvar )
557
558            END DO
559
560            CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
561               &              ln_t3d, ln_s3d, ln_nea, &
562               &              kdailyavtypes=endailyavtypes )
563           
564         ENDIF
565
566         ! Coriolis insitu data
567
568         IF ( ln_cor ) THEN
569           
570            jprofset = jprofset + 1
571
572            ld_enact(jprofset) = .FALSE.
573
574            CALL obs_rea_pro_dri( 2, profdata(jprofset),          &
575               &                  jnumcorio, coriofiles(1:jnumcorio), &
576               &                  nprofvars, nprofextr,        &
577               &                  nitend-nit000+2,             &
578               &                  dobsini, dobsend, ln_t3d, ln_s3d, &
579               &                  ln_ignmis, ln_s_at_t, .FALSE., .FALSE. )
580
581            DO jvar = 1, 2
582
583               CALL obs_prof_staend( profdata(jprofset), jvar )
584
585            END DO
586
587            CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
588                 &            ln_t3d, ln_s3d, ln_nea )
589           
590         ENDIF
591 
592         ! Feedback insitu data
593
594         IF ( ln_profb ) THEN
595           
596            DO jset = 1, jnumprofb
597               
598               jprofset = jprofset + 1
599               ld_enact (jprofset) = ln_profb_ena(jset)
600
601               CALL obs_rea_pro_dri( 0, profdata(jprofset),          &
602                  &                  1, profbfiles(jset:jset), &
603                  &                  nprofvars, nprofextr,        &
604                  &                  nitend-nit000+2,             &
605                  &                  dobsini, dobsend, ln_t3d, ln_s3d, &
606                  &                  ln_ignmis, ln_s_at_t, &
607                  &                  ld_enact(jprofset).AND.&
608                  &                  ln_profb_enatim(jset), &
609                  &                  .FALSE., kdailyavtypes = endailyavtypes )
610               
611               DO jvar = 1, 2
612                 
613                  CALL obs_prof_staend( profdata(jprofset), jvar )
614                 
615               END DO
616               
617               IF ( ld_enact(jprofset) ) THEN
618                  CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
619                     &              ln_t3d, ln_s3d, ln_nea, &
620                     &              kdailyavtypes = endailyavtypes )
621               ELSE
622                  CALL obs_pre_pro( profdata(jprofset), prodatqc(jprofset),   &
623                     &              ln_t3d, ln_s3d, ln_nea )
624               ENDIF
625               
626            END DO
627
628         ENDIF
629
630      ENDIF
631
632      !  - Sea level anomalies
633      IF ( ln_sla ) THEN
634        ! Set the number of variables for sla to 1
635         nslavars = 1
636
637         ! Set the number of extra variables for sla to 2
638         nslaextr = 2
639         
640         ! Set the number of sla data sets to 2
641         nslasets = 0
642         IF ( ln_sladt ) THEN
643            nslasets = nslasets + 2
644         ENDIF
645         IF ( ln_slafb ) THEN
646            nslasets = nslasets + jnumslafb
647         ENDIF
648         
649         ALLOCATE(sladata(nslasets))
650         ALLOCATE(sladatqc(nslasets))
651         sladata(:)%nsurf=0
652         sladatqc(:)%nsurf=0
653
654         nslasets = 0
655
656         ! AVISO SLA data
657
658         IF ( ln_sladt ) THEN
659
660            ! Active SLA observations
661           
662            nslasets = nslasets + 1
663           
664            CALL obs_rea_sla( 1, sladata(nslasets), jnumslaact, &
665               &              slafilesact(1:jnumslaact), &
666               &              nslavars, nslaextr, nitend-nit000+2, &
667               &              dobsini, dobsend, ln_ignmis, .FALSE. )
668            CALL obs_pre_sla( sladata(nslasets), sladatqc(nslasets), &
669               &              ln_sla, ln_nea )
670           
671            ! Passive SLA observations
672           
673            nslasets = nslasets + 1
674           
675            CALL obs_rea_sla( 1, sladata(nslasets), jnumslapas, &
676               &              slafilespas(1:jnumslapas), &
677               &              nslavars, nslaextr, nitend-nit000+2, &
678               &              dobsini, dobsend, ln_ignmis, .FALSE. )
679           
680            CALL obs_pre_sla( sladata(nslasets), sladatqc(nslasets), &
681               &              ln_sla, ln_nea )
682
683         ENDIF
684         
685         ! Feedback SLA data
686
687         IF ( ln_slafb ) THEN
688
689            DO jset = 1, jnumslafb
690           
691               nslasets = nslasets + 1
692           
693               CALL obs_rea_sla( 0, sladata(nslasets), 1, &
694                  &              slafbfiles(jset:jset), &
695                  &              nslavars, nslaextr, nitend-nit000+2, &
696                  &              dobsini, dobsend, ln_ignmis, .FALSE. )
697               CALL obs_pre_sla( sladata(nslasets), sladatqc(nslasets), &
698                  &              ln_sla, ln_nea )
699
700            END DO               
701
702         ENDIF
703         
704         CALL obs_rea_mdt( nslasets, sladatqc, n2dint )
705           
706         ! read in altimeter bias
707         
708         IF ( ln_altbias ) THEN     
709            CALL obs_rea_altbias ( nslasets, sladatqc, n2dint, bias_file )
710         ENDIF
711     
712      ENDIF
713
714      !  - Sea surface height
715      IF ( ln_ssh ) THEN
716         IF(lwp) WRITE(numout,*) ' SSH currently not available'
717      ENDIF
718
719      !  - Sea surface temperature
720      IF ( ln_sst ) THEN
721
722         ! Set the number of variables for sst to 1
723         nsstvars = 1
724
725         ! Set the number of extra variables for sst to 0
726         nsstextr = 0
727
728         nsstsets = 0
729
730         IF (ln_reysst) nsstsets = nsstsets + 1
731         IF (ln_ghrsst) nsstsets = nsstsets + 1
732         IF ( ln_sstfb ) THEN
733            nsstsets = nsstsets + jnumsstfb
734         ENDIF
735
736         ALLOCATE(sstdata(nsstsets))
737         ALLOCATE(sstdatqc(nsstsets))
738         ALLOCATE(ld_sstnight(nsstsets))
739         sstdata(:)%nsurf=0
740         sstdatqc(:)%nsurf=0   
741         ld_sstnight(:)=.false.
742
743         nsstsets = 0
744
745         IF (ln_reysst) THEN
746
747            nsstsets = nsstsets + 1
748
749            ld_sstnight(nsstsets) = ln_sstnight
750
751            CALL obs_rea_sst_rey( reysstname, reysstfmt, sstdata(nsstsets), &
752               &                  nsstvars, nsstextr, &
753               &                  nitend-nit000+2, dobsini, dobsend )
754            CALL obs_pre_sst( sstdata(nsstsets), sstdatqc(nsstsets), ln_sst, &
755               &              ln_nea )
756
757        ENDIF
758       
759        IF (ln_ghrsst) THEN
760       
761            nsstsets = nsstsets + 1
762
763            ld_sstnight(nsstsets) = ln_sstnight
764         
765            CALL obs_rea_sst( 1, sstdata(nsstsets), jnumsst, &
766               &              sstfiles(1:jnumsst), &
767               &              nsstvars, nsstextr, nitend-nit000+2, &
768               &              dobsini, dobsend, ln_ignmis, .FALSE. )
769            CALL obs_pre_sst( sstdata(nsstsets), sstdatqc(nsstsets), ln_sst, &
770               &              ln_nea )
771
772        ENDIF
773               
774         ! Feedback SST data
775
776         IF ( ln_sstfb ) THEN
777
778            DO jset = 1, jnumsstfb
779           
780               nsstsets = nsstsets + 1
781
782               ld_sstnight(nsstsets) = ln_sstnight
783           
784               CALL obs_rea_sst( 0, sstdata(nsstsets), 1, &
785                  &              sstfbfiles(jset:jset), &
786                  &              nsstvars, nsstextr, nitend-nit000+2, &
787                  &              dobsini, dobsend, ln_ignmis, .FALSE. )
788               CALL obs_pre_sst( sstdata(nsstsets), sstdatqc(nsstsets), &
789                  &              ln_sst, ln_nea )
790
791            END DO               
792
793         ENDIF
794         
795         !Read in bias field and correct SST.
796         IF ( ln_sstbias ) THEN
797            IF ( jnumsstbias == 0 ) CALL ctl_stop("ln_sstbias set,"// & 
798                                             "  but no bias"// & 
799                                             " files to read in")   
800            CALL obs_app_sstbias( nsstsets, sstdatqc, n2dint, & 
801                                  jnumsstbias, & 
802                                  sstbias_files(1:jnumsstbias) ) 
803         ENDIF
804
805      ENDIF
806
807      !  - Sea surface salinity
808      IF ( ln_sss ) THEN
809         IF(lwp) WRITE(numout,*) ' SSS currently not available'
810      ENDIF
811
812      !  - Sea Ice Concentration
813     
814      IF ( ln_seaice ) THEN
815
816         ! Set the number of variables for seaice to 1
817         nseaicevars = 1
818
819         ! Set the number of extra variables for seaice to 0
820         nseaiceextr = 0
821         
822         ! Set the number of data sets to 1
823         nseaicesets = 1
824
825         ALLOCATE(seaicedata(nseaicesets))
826         ALLOCATE(seaicedatqc(nseaicesets))
827         seaicedata(:)%nsurf=0
828         seaicedatqc(:)%nsurf=0
829
830         CALL obs_rea_seaice( 1, seaicedata(nseaicesets), jnumseaice, &
831            &                 seaicefiles(1:jnumseaice), &
832            &                 nseaicevars, nseaiceextr, nitend-nit000+2, &
833            &                 dobsini, dobsend, ln_ignmis, .FALSE. )
834
835         CALL obs_pre_seaice( seaicedata(nseaicesets), seaicedatqc(nseaicesets), &
836            &                 ln_seaice, ln_nea )
837 
838      ENDIF
839
840      IF (ln_vel3d) THEN
841
842         ! Set the number of variables for profiles to 2 (U and V)
843         nvelovars = 2
844
845         ! Set the number of extra variables for profiles to 2 to store
846         ! rotation parameters
847         nveloextr = 2
848
849         jveloset = 0
850         
851         IF ( ln_velavcur ) jveloset = jveloset + 1
852         IF ( ln_velhrcur ) jveloset = jveloset + 1
853         IF ( ln_velavadcp ) jveloset = jveloset + 1
854         IF ( ln_velhradcp ) jveloset = jveloset + 1
855         IF (ln_velfb) jveloset = jveloset + jnumvelfb
856
857         nvelosets = jveloset
858         IF ( nvelosets > 0 ) THEN
859            ALLOCATE( velodata(nvelosets) )
860            ALLOCATE( veldatqc(nvelosets) )
861            ALLOCATE( ld_velav(nvelosets) )
862         ENDIF
863         
864         jveloset = 0
865         
866         ! Daily averaged data
867
868         IF ( ln_velavcur ) THEN
869           
870            jveloset = jveloset + 1
871           
872            ld_velav(jveloset) = .TRUE.
873           
874            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelavcur, &
875               &                  velavcurfiles(1:jnumvelavcur), &
876               &                  nvelovars, nveloextr, &
877               &                  nitend-nit000+2,              &
878               &                  dobsini, dobsend, ln_ignmis, &
879               &                  ld_velav(jveloset), &
880               &                  .FALSE. )
881           
882            DO jvar = 1, 2
883               CALL obs_prof_staend( velodata(jveloset), jvar )
884            END DO
885           
886            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
887               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
888           
889         ENDIF
890
891         ! High frequency data
892
893         IF ( ln_velhrcur ) THEN
894           
895            jveloset = jveloset + 1
896           
897            ld_velav(jveloset) = .FALSE.
898               
899            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelhrcur, &
900               &                  velhrcurfiles(1:jnumvelhrcur), &
901               &                  nvelovars, nveloextr, &
902               &                  nitend-nit000+2,              &
903               &                  dobsini, dobsend, ln_ignmis, &
904               &                  ld_velav(jveloset), &
905               &                  .FALSE. )
906           
907            DO jvar = 1, 2
908               CALL obs_prof_staend( velodata(jveloset), jvar )
909            END DO
910           
911            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
912               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
913           
914         ENDIF
915
916         ! Daily averaged data
917
918         IF ( ln_velavadcp ) THEN
919           
920            jveloset = jveloset + 1
921           
922            ld_velav(jveloset) = .TRUE.
923           
924            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelavadcp, &
925               &                  velavadcpfiles(1:jnumvelavadcp), &
926               &                  nvelovars, nveloextr, &
927               &                  nitend-nit000+2,              &
928               &                  dobsini, dobsend, ln_ignmis, &
929               &                  ld_velav(jveloset), &
930               &                  .FALSE. )
931           
932            DO jvar = 1, 2
933               CALL obs_prof_staend( velodata(jveloset), jvar )
934            END DO
935           
936            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
937               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
938           
939         ENDIF
940
941         ! High frequency data
942
943         IF ( ln_velhradcp ) THEN
944           
945            jveloset = jveloset + 1
946           
947            ld_velav(jveloset) = .FALSE.
948               
949            CALL obs_rea_vel_dri( 1, velodata(jveloset), jnumvelhradcp, &
950               &                  velhradcpfiles(1:jnumvelhradcp), &
951               &                  nvelovars, nveloextr, &
952               &                  nitend-nit000+2,              &
953               &                  dobsini, dobsend, ln_ignmis, &
954               &                  ld_velav(jveloset), &
955               &                  .FALSE. )
956           
957            DO jvar = 1, 2
958               CALL obs_prof_staend( velodata(jveloset), jvar )
959            END DO
960           
961            CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
962               &              ln_vel3d, ln_nea, ld_velav(jveloset) )
963           
964         ENDIF
965
966         IF ( ln_velfb ) THEN
967
968            DO jset = 1, jnumvelfb
969           
970               jveloset = jveloset + 1
971
972               ld_velav(jveloset) = ln_velfb_av(jset)
973               
974               CALL obs_rea_vel_dri( 0, velodata(jveloset), 1, &
975                  &                  velfbfiles(jset:jset), &
976                  &                  nvelovars, nveloextr, &
977                  &                  nitend-nit000+2,              &
978                  &                  dobsini, dobsend, ln_ignmis, &
979                  &                  ld_velav(jveloset), &
980                  &                  .FALSE. )
981               
982               DO jvar = 1, 2
983                  CALL obs_prof_staend( velodata(jveloset), jvar )
984               END DO
985               
986               CALL obs_pre_vel( velodata(jveloset), veldatqc(jveloset), &
987                  &              ln_vel3d, ln_nea, ld_velav(jveloset) )
988
989
990            END DO
991           
992         ENDIF
993
994      ENDIF
995     
996   END SUBROUTINE dia_obs_init
997
998   SUBROUTINE dia_obs( kstp )
999      !!----------------------------------------------------------------------
1000      !!                    ***  ROUTINE dia_obs  ***
1001      !!         
1002      !! ** Purpose : Call the observation operators on each time step
1003      !!
1004      !! ** Method  : Call the observation operators on each time step to
1005      !!              compute the model equivalent of the following date:
1006      !!               - T profiles
1007      !!               - S profiles
1008      !!               - Sea surface height (referenced to a mean)
1009      !!               - Sea surface temperature
1010      !!               - Sea surface salinity
1011      !!               - Velocity component (U,V) profiles
1012      !!
1013      !! ** Action  :
1014      !!
1015      !! History :
1016      !!        !  06-03  (K. Mogensen) Original code
1017      !!        !  06-05  (K. Mogensen) Reformatted
1018      !!        !  06-10  (A. Weaver) Cleaning
1019      !!        !  07-03  (K. Mogensen) General handling of profiles
1020      !!        !  07-04  (G. Smith) Generalized surface operators
1021      !!        !  08-10  (M. Valdivieso) obs operator for velocity profiles
1022      !!        !  14-08  (J. While) observation operator for profiles in
1023      !!                             generalised vertical coordinates
1024      !!----------------------------------------------------------------------
1025      !! * Modules used
1026      USE dom_oce, ONLY : &             ! Ocean space and time domain variables
1027         & rdt,           &                       
1028         & gdept_1d,       &             
1029#if defined key_vvl 
1030         & gdept_n,       &
1031#else 
1032         & gdept_1d,      &
1033#endif                                       
1034         & tmask, umask, vmask                           
1035      USE phycst, ONLY : &              ! Physical constants
1036         & rday                         
1037      USE oce, ONLY : &                 ! Ocean dynamics and tracers variables
1038         & tsn,  &             
1039         & un, vn,  &
1040         & sshn
1041#if defined  key_lim3
1042      USE ice, ONLY : &                     ! LIM Ice model variables
1043         & frld
1044#endif
1045#if defined key_lim2
1046      USE ice_2, ONLY : &                     ! LIM Ice model variables
1047         & frld
1048#endif
1049      IMPLICIT NONE
1050
1051      !! * Arguments
1052      INTEGER, INTENT(IN) :: kstp                         ! Current timestep
1053      !! * Local declarations
1054      INTEGER :: idaystp                ! Number of timesteps per day
1055      INTEGER :: jprofset               ! Profile data set loop variable
1056      INTEGER :: jslaset                ! SLA data set loop variable
1057      INTEGER :: jsstset                ! SST data set loop variable
1058      INTEGER :: jseaiceset             ! sea ice data set loop variable
1059      INTEGER :: jveloset               ! velocity profile data loop variable
1060      INTEGER :: jvar                   ! Variable number   
1061#if ! defined key_lim2 && ! defined key_lim3
1062      REAL(wp), POINTER, DIMENSION(:,:) :: frld   
1063#endif
1064      CHARACTER(LEN=20) :: datestr=" ",timestr=" "
1065 
1066#if ! defined key_lim2 && ! defined key_lim3
1067      CALL wrk_alloc(jpi,jpj,frld) 
1068#endif
1069
1070      IF(lwp) THEN
1071         WRITE(numout,*)
1072         WRITE(numout,*) 'dia_obs : Call the observation operators', kstp
1073         WRITE(numout,*) '~~~~~~~'
1074      ENDIF
1075
1076      idaystp = NINT( rday / rdt )
1077
1078      !-----------------------------------------------------------------------
1079      ! No LIM => frld == 0.0_wp
1080      !-----------------------------------------------------------------------
1081#if ! defined key_lim2 && ! defined key_lim3
1082      frld(:,:) = 0.0_wp
1083#endif
1084      !-----------------------------------------------------------------------
1085      ! Depending on switches call various observation operators
1086      !-----------------------------------------------------------------------
1087
1088      !  - Temperature/salinity profiles
1089      IF ( ln_t3d .OR. ln_s3d ) THEN
1090         DO jprofset = 1, nprofsets
1091            IF( (.NOT. lk_vvl) .AND. (ln_zco .OR. ln_zps) ) THEN
1092               IF(lwp) THEN
1093                  WRITE(numout,*) 'dia_obs : calling obs_pro_opt'
1094               ENDIF
1095               IF ( ld_enact(jprofset) ) THEN
1096                  CALL obs_pro_opt( prodatqc(jprofset),                     & 
1097                     &              kstp, jpi, jpj, jpk, nit000, idaystp,   & 
1098                     &              tsn(:,:,:,jp_tem), tsn(:,:,:,jp_sal),   & 
1099                     &              gdept_1d, tmask, n1dint, n2dint,        & 
1100                     &              kdailyavtypes = endailyavtypes ) 
1101               ELSE
1102                  CALL obs_pro_opt( prodatqc(jprofset),                     & 
1103                     &              kstp, jpi, jpj, jpk, nit000, idaystp,   & 
1104                     &              tsn(:,:,:,jp_tem), tsn(:,:,:,jp_sal),   & 
1105                     &              gdept_1d, tmask, n1dint, n2dint               ) 
1106               ENDIF
1107            ELSE
1108               IF(lwp) THEN
1109                  WRITE(numout,*) 'dia_obs : calling obs_pro_sco_opt'
1110               ENDIF
1111               IF ( ld_enact(jprofset) ) THEN
1112                  CALL obs_pro_sco_opt( prodatqc(jprofset),                 & 
1113                     &              kstp, jpi, jpj, jpk, nit000, idaystp,   & 
1114                     &              tsn(:,:,:,jp_tem), tsn(:,:,:,jp_sal),   & 
1115                     &              fsdept(:,:,:), fsdepw(:,:,:),           & 
1116                     &              tmask, n1dint, n2dint,                  & 
1117                     &              kdailyavtypes = endailyavtypes ) 
1118               ELSE
1119                  CALL obs_pro_sco_opt( prodatqc(jprofset),                 & 
1120                     &              kstp, jpi, jpj, jpk, nit000, idaystp,   & 
1121                     &              tsn(:,:,:,jp_tem), tsn(:,:,:,jp_sal),   & 
1122                     &              fsdept(:,:,:), fsdepw(:,:,:),           &
1123                     &              tmask, n1dint, n2dint ) 
1124               ENDIF
1125            ENDIF
1126         END DO
1127      ENDIF
1128
1129      !  - Sea surface anomaly
1130      IF ( ln_sla ) THEN
1131         DO jslaset = 1, nslasets
1132            CALL obs_sla_opt( sladatqc(jslaset),            &
1133               &              kstp, jpi, jpj, nit000, sshn, &
1134               &              tmask(:,:,1), n2dint )
1135         END DO         
1136      ENDIF
1137
1138      !  - Sea surface temperature
1139      IF ( ln_sst ) THEN
1140         DO jsstset = 1, nsstsets
1141            CALL obs_sst_opt( sstdatqc(jsstset),                &
1142               &              kstp, jpi, jpj, nit000, idaystp,  &
1143               &              tsn(:,:,1,jp_tem), tmask(:,:,1),  &
1144               &              n2dint, ld_sstnight(jsstset) )
1145         END DO
1146      ENDIF
1147
1148      !  - Sea surface salinity
1149      IF ( ln_sss ) THEN
1150         IF(lwp) WRITE(numout,*) ' SSS currently not available'
1151      ENDIF
1152
1153#if defined key_lim2 || defined key_lim3
1154      IF ( ln_seaice ) THEN
1155         DO jseaiceset = 1, nseaicesets
1156            CALL obs_seaice_opt( seaicedatqc(jseaiceset),      &
1157               &              kstp, jpi, jpj, nit000, 1.-frld, &
1158               &              tmask(:,:,1), n2dint )
1159         END DO
1160      ENDIF     
1161#endif
1162
1163      !  - Velocity profiles
1164      IF ( ln_vel3d ) THEN
1165         DO jveloset = 1, nvelosets
1166           ! zonal component of velocity
1167           CALL obs_vel_opt( veldatqc(jveloset), kstp, jpi, jpj, jpk, &
1168              &              nit000, idaystp, un, vn, gdept_1d, umask, vmask, &
1169                             n1dint, n2dint, ld_velav(jveloset) )
1170         END DO
1171      ENDIF
1172
1173#if ! defined key_lim2 && ! defined key_lim3
1174      CALL wrk_dealloc(jpi,jpj,frld) 
1175#endif
1176
1177   END SUBROUTINE dia_obs
1178 
1179   SUBROUTINE dia_obs_wri 
1180      !!----------------------------------------------------------------------
1181      !!                    ***  ROUTINE dia_obs_wri  ***
1182      !!         
1183      !! ** Purpose : Call observation diagnostic output routines
1184      !!
1185      !! ** Method  : Call observation diagnostic output routines
1186      !!
1187      !! ** Action  :
1188      !!
1189      !! History :
1190      !!        !  06-03  (K. Mogensen) Original code
1191      !!        !  06-05  (K. Mogensen) Reformatted
1192      !!        !  06-10  (A. Weaver) Cleaning
1193      !!        !  07-03  (K. Mogensen) General handling of profiles
1194      !!        !  08-09  (M. Valdivieso) Velocity component (U,V) profiles
1195      !!----------------------------------------------------------------------
1196      IMPLICIT NONE
1197
1198      !! * Local declarations
1199
1200      INTEGER :: jprofset                 ! Profile data set loop variable
1201      INTEGER :: jveloset                 ! Velocity data set loop variable
1202      INTEGER :: jslaset                  ! SLA data set loop variable
1203      INTEGER :: jsstset                  ! SST data set loop variable
1204      INTEGER :: jseaiceset               ! Sea Ice data set loop variable
1205      INTEGER :: jset
1206      INTEGER :: jfbini
1207      CHARACTER(LEN=20) :: datestr=" ",timestr=" "
1208      CHARACTER(LEN=10) :: cdtmp
1209      !-----------------------------------------------------------------------
1210      ! Depending on switches call various observation output routines
1211      !-----------------------------------------------------------------------
1212
1213      !  - Temperature/salinity profiles
1214
1215      IF( ln_t3d .OR. ln_s3d ) THEN
1216
1217         ! Copy data from prodatqc to profdata structures
1218         DO jprofset = 1, nprofsets
1219
1220            CALL obs_prof_decompress( prodatqc(jprofset), &
1221                 &                    profdata(jprofset), .TRUE., numout )
1222
1223         END DO
1224
1225         ! Write the profiles.
1226
1227         jprofset = 0
1228
1229         ! ENACT insitu data
1230
1231         IF ( ln_ena ) THEN
1232           
1233            jprofset = jprofset + 1
1234
1235            CALL obs_wri_p3d( 'enact', profdata(jprofset) )
1236
1237         ENDIF
1238
1239         ! Coriolis insitu data
1240
1241         IF ( ln_cor ) THEN
1242           
1243            jprofset = jprofset + 1
1244
1245            CALL obs_wri_p3d( 'corio', profdata(jprofset) )
1246           
1247         ENDIF
1248         
1249         ! Feedback insitu data
1250
1251         IF ( ln_profb ) THEN
1252
1253            jfbini = jprofset + 1
1254
1255            DO jprofset = jfbini, nprofsets
1256               
1257               jset = jprofset - jfbini + 1
1258               WRITE(cdtmp,'(A,I2.2)')'profb_',jset
1259               CALL obs_wri_p3d( cdtmp, profdata(jprofset) )
1260
1261            END DO
1262
1263         ENDIF
1264
1265      ENDIF
1266
1267      !  - Sea surface anomaly
1268      IF ( ln_sla ) THEN
1269
1270         ! Copy data from sladatqc to sladata structures
1271         DO jslaset = 1, nslasets
1272
1273              CALL obs_surf_decompress( sladatqc(jslaset), &
1274                 &                    sladata(jslaset), .TRUE., numout )
1275
1276         END DO
1277
1278         jslaset = 0 
1279
1280         ! Write the AVISO SLA data
1281
1282         IF ( ln_sladt ) THEN
1283           
1284            jslaset = 1
1285            CALL obs_wri_sla( 'aviso_act', sladata(jslaset) )
1286            jslaset = 2
1287            CALL obs_wri_sla( 'aviso_pas', sladata(jslaset) )
1288
1289         ENDIF
1290
1291         IF ( ln_slafb ) THEN
1292           
1293            jfbini = jslaset + 1
1294
1295            DO jslaset = jfbini, nslasets
1296               
1297               jset = jslaset - jfbini + 1
1298               WRITE(cdtmp,'(A,I2.2)')'slafb_',jset
1299               CALL obs_wri_sla( cdtmp, sladata(jslaset) )
1300
1301            END DO
1302
1303         ENDIF
1304
1305      ENDIF
1306
1307      !  - Sea surface temperature
1308      IF ( ln_sst ) THEN
1309
1310         ! Copy data from sstdatqc to sstdata structures
1311         DO jsstset = 1, nsstsets
1312     
1313              CALL obs_surf_decompress( sstdatqc(jsstset), &
1314                 &                    sstdata(jsstset), .TRUE., numout )
1315
1316         END DO
1317
1318         jsstset = 0 
1319
1320         ! Write the AVISO SST data
1321
1322         IF ( ln_reysst ) THEN
1323           
1324            jsstset = jsstset + 1
1325            CALL obs_wri_sst( 'reynolds', sstdata(jsstset) )
1326
1327         ENDIF
1328
1329         IF ( ln_ghrsst ) THEN
1330           
1331            jsstset = jsstset + 1
1332            CALL obs_wri_sst( 'ghr', sstdata(jsstset) )
1333
1334         ENDIF
1335
1336         IF ( ln_sstfb ) THEN
1337           
1338            jfbini = jsstset + 1
1339
1340            DO jsstset = jfbini, nsstsets
1341               
1342               jset = jsstset - jfbini + 1
1343               WRITE(cdtmp,'(A,I2.2)')'sstfb_',jset
1344               CALL obs_wri_sst( cdtmp, sstdata(jsstset) )
1345
1346            END DO
1347
1348         ENDIF
1349
1350      ENDIF
1351
1352      !  - Sea surface salinity
1353      IF ( ln_sss ) THEN
1354         IF(lwp) WRITE(numout,*) ' SSS currently not available'
1355      ENDIF
1356
1357      !  - Sea Ice Concentration
1358      IF ( ln_seaice ) THEN
1359
1360         ! Copy data from seaicedatqc to seaicedata structures
1361         DO jseaiceset = 1, nseaicesets
1362
1363              CALL obs_surf_decompress( seaicedatqc(jseaiceset), &
1364                 &                    seaicedata(jseaiceset), .TRUE., numout )
1365
1366         END DO
1367
1368         ! Write the Sea Ice data
1369         DO jseaiceset = 1, nseaicesets
1370     
1371            WRITE(cdtmp,'(A,I2.2)')'seaicefb_',jseaiceset
1372            CALL obs_wri_seaice( cdtmp, seaicedata(jseaiceset) )
1373
1374         END DO
1375
1376      ENDIF
1377     
1378      ! Velocity data
1379      IF( ln_vel3d ) THEN
1380
1381         ! Copy data from veldatqc to velodata structures
1382         DO jveloset = 1, nvelosets
1383
1384            CALL obs_prof_decompress( veldatqc(jveloset), &
1385                 &                    velodata(jveloset), .TRUE., numout )
1386
1387         END DO
1388
1389         ! Write the profiles.
1390
1391         jveloset = 0
1392
1393         ! Daily averaged data
1394
1395         IF ( ln_velavcur ) THEN
1396           
1397            jveloset = jveloset + 1
1398
1399            CALL obs_wri_vel( 'velavcurr', velodata(jveloset), n2dint )
1400
1401         ENDIF
1402
1403         ! High frequency data
1404
1405         IF ( ln_velhrcur ) THEN
1406           
1407            jveloset = jveloset + 1
1408
1409            CALL obs_wri_vel( 'velhrcurr', velodata(jveloset), n2dint )
1410
1411         ENDIF
1412
1413         ! Daily averaged data
1414
1415         IF ( ln_velavadcp ) THEN
1416           
1417            jveloset = jveloset + 1
1418
1419            CALL obs_wri_vel( 'velavadcp', velodata(jveloset), n2dint )
1420
1421         ENDIF
1422
1423         ! High frequency data
1424
1425         IF ( ln_velhradcp ) THEN
1426           
1427            jveloset = jveloset + 1
1428           
1429            CALL obs_wri_vel( 'velhradcp', velodata(jveloset), n2dint )
1430               
1431         ENDIF
1432
1433         ! Feedback velocity data
1434
1435         IF ( ln_velfb ) THEN
1436
1437            jfbini = jveloset + 1
1438
1439            DO jveloset = jfbini, nvelosets
1440               
1441               jset = jveloset - jfbini + 1
1442               WRITE(cdtmp,'(A,I2.2)')'velfb_',jset
1443               CALL obs_wri_vel( cdtmp, velodata(jveloset), n2dint )
1444
1445            END DO
1446
1447         ENDIF
1448         
1449      ENDIF
1450
1451   END SUBROUTINE dia_obs_wri
1452
1453   SUBROUTINE dia_obs_dealloc
1454      IMPLICIT NONE
1455      !!----------------------------------------------------------------------
1456      !!                    *** ROUTINE dia_obs_dealloc ***
1457      !!
1458      !!  ** Purpose : To deallocate data to enable the obs_oper online loop.
1459      !!               Specifically: dia_obs_init --> dia_obs --> dia_obs_wri
1460      !!
1461      !!  ** Method : Clean up various arrays left behind by the obs_oper.
1462      !!
1463      !!  ** Action :
1464      !!
1465      !!----------------------------------------------------------------------
1466      !! obs_grid deallocation
1467      CALL obs_grid_deallocate
1468
1469      !! diaobs deallocation
1470      IF ( nprofsets > 0 ) THEN
1471          DEALLOCATE(ld_enact, &
1472                  &  profdata, &
1473                  &  prodatqc)
1474      END IF
1475      IF ( ln_sla ) THEN
1476          DEALLOCATE(sladata, &
1477                  &  sladatqc)
1478      END IF
1479      IF ( ln_seaice ) THEN
1480          DEALLOCATE(sladata, &
1481                  &  sladatqc)
1482      END IF
1483      IF ( ln_sst ) THEN
1484          DEALLOCATE(sstdata, &
1485                  &  sstdatqc)
1486      END IF
1487      IF ( ln_vel3d ) THEN
1488          DEALLOCATE(ld_velav, &
1489                  &  velodata, &
1490                  &  veldatqc)
1491      END IF
1492   END SUBROUTINE dia_obs_dealloc
1493
1494   SUBROUTINE ini_date( ddobsini )
1495      !!----------------------------------------------------------------------
1496      !!                    ***  ROUTINE ini_date  ***
1497      !!         
1498      !! ** Purpose : Get initial data in double precision YYYYMMDD.HHMMSS format
1499      !!
1500      !! ** Method  : Get initial data in double precision YYYYMMDD.HHMMSS format
1501      !!
1502      !! ** Action  : Get initial data in double precision YYYYMMDD.HHMMSS format
1503      !!
1504      !! History :
1505      !!        !  06-03  (K. Mogensen)  Original code
1506      !!        !  06-05  (K. Mogensen)  Reformatted
1507      !!        !  06-10  (A. Weaver) Cleaning
1508      !!        !  06-10  (G. Smith) Calculates initial date the same as method for final date
1509      !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
1510      !!----------------------------------------------------------------------
1511      USE phycst, ONLY : &            ! Physical constants
1512         & rday
1513!      USE daymod, ONLY : &            ! Time variables
1514!         & nmonth_len           
1515      USE dom_oce, ONLY : &           ! Ocean space and time domain variables
1516         & rdt
1517
1518      IMPLICIT NONE
1519
1520      !! * Arguments
1521      REAL(KIND=dp), INTENT(OUT) :: ddobsini                         ! Initial date in YYYYMMDD.HHMMSS
1522
1523      !! * Local declarations
1524      INTEGER :: iyea        ! date - (year, month, day, hour, minute)
1525      INTEGER :: imon
1526      INTEGER :: iday
1527      INTEGER :: ihou
1528      INTEGER :: imin
1529      INTEGER :: imday         ! Number of days in month.
1530      REAL(KIND=wp) :: zdayfrc ! Fraction of day
1531
1532      INTEGER, DIMENSION(12) ::   imonth_len    !: length in days of the months of the current year
1533
1534      !!----------------------------------------------------------------------
1535      !! Initial date initialization (year, month, day, hour, minute)
1536      !! (This assumes that the initial date is for 00z))
1537      !!----------------------------------------------------------------------
1538      iyea =   ndate0 / 10000
1539      imon = ( ndate0 - iyea * 10000 ) / 100
1540      iday =   ndate0 - iyea * 10000 - imon * 100
1541      ihou = 0
1542      imin = 0
1543
1544      !!----------------------------------------------------------------------
1545      !! Compute number of days + number of hours + min since initial time
1546      !!----------------------------------------------------------------------
1547      iday = iday + ( nit000 -1 ) * rdt / rday
1548      zdayfrc = ( nit000 -1 ) * rdt / rday
1549      zdayfrc = zdayfrc - aint(zdayfrc)
1550      ihou = int( zdayfrc * 24 )
1551      imin = int( (zdayfrc * 24 - ihou) * 60 )
1552
1553      !!-----------------------------------------------------------------------
1554      !! Convert number of days (iday) into a real date
1555      !!----------------------------------------------------------------------
1556
1557      CALL calc_month_len( iyea, imonth_len )
1558     
1559      DO WHILE ( iday > imonth_len(imon) )
1560         iday = iday - imonth_len(imon)
1561         imon = imon + 1 
1562         IF ( imon > 12 ) THEN
1563            imon = 1
1564            iyea = iyea + 1
1565            CALL calc_month_len( iyea, imonth_len )  ! update month lengths
1566         ENDIF
1567      END DO
1568
1569      !!----------------------------------------------------------------------
1570      !! Convert it into YYYYMMDD.HHMMSS format.
1571      !!----------------------------------------------------------------------
1572      ddobsini = iyea * 10000_dp + imon * 100_dp + &
1573         &       iday + ihou * 0.01_dp + imin * 0.0001_dp
1574
1575
1576   END SUBROUTINE ini_date
1577
1578   SUBROUTINE fin_date( ddobsfin )
1579      !!----------------------------------------------------------------------
1580      !!                    ***  ROUTINE fin_date  ***
1581      !!         
1582      !! ** Purpose : Get final data in double precision YYYYMMDD.HHMMSS format
1583      !!
1584      !! ** Method  : Get final data in double precision YYYYMMDD.HHMMSS format
1585      !!
1586      !! ** Action  : Get final data in double precision YYYYMMDD.HHMMSS format
1587      !!
1588      !! History :
1589      !!        !  06-03  (K. Mogensen)  Original code
1590      !!        !  06-05  (K. Mogensen)  Reformatted
1591      !!        !  06-10  (A. Weaver) Cleaning
1592      !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
1593      !!----------------------------------------------------------------------
1594      USE phycst, ONLY : &            ! Physical constants
1595         & rday
1596!      USE daymod, ONLY : &            ! Time variables
1597!         & nmonth_len               
1598      USE dom_oce, ONLY : &           ! Ocean space and time domain variables
1599         & rdt
1600
1601      IMPLICIT NONE
1602
1603      !! * Arguments
1604      REAL(KIND=dp), INTENT(OUT) :: ddobsfin                   ! Final date in YYYYMMDD.HHMMSS
1605
1606      !! * Local declarations
1607      INTEGER :: iyea        ! date - (year, month, day, hour, minute)
1608      INTEGER :: imon
1609      INTEGER :: iday
1610      INTEGER :: ihou
1611      INTEGER :: imin
1612      INTEGER :: imday         ! Number of days in month.
1613      REAL(KIND=wp) :: zdayfrc       ! Fraction of day
1614         
1615      INTEGER, DIMENSION(12) ::   imonth_len    !: length in days of the months of the current year
1616           
1617      !-----------------------------------------------------------------------
1618      ! Initial date initialization (year, month, day, hour, minute)
1619      ! (This assumes that the initial date is for 00z)
1620      !-----------------------------------------------------------------------
1621      iyea =   ndate0 / 10000
1622      imon = ( ndate0 - iyea * 10000 ) / 100
1623      iday =   ndate0 - iyea * 10000 - imon * 100
1624      ihou = 0
1625      imin = 0
1626     
1627      !-----------------------------------------------------------------------
1628      ! Compute number of days + number of hours + min since initial time
1629      !-----------------------------------------------------------------------
1630      iday    = iday +  nitend  * rdt / rday
1631      zdayfrc =  nitend  * rdt / rday
1632      zdayfrc = zdayfrc - AINT( zdayfrc )
1633      ihou    = INT( zdayfrc * 24 )
1634      imin    = INT( ( zdayfrc * 24 - ihou ) * 60 )
1635
1636      !-----------------------------------------------------------------------
1637      ! Convert number of days (iday) into a real date
1638      !----------------------------------------------------------------------
1639
1640      CALL calc_month_len( iyea, imonth_len )
1641     
1642      DO WHILE ( iday > imonth_len(imon) )
1643         iday = iday - imonth_len(imon)
1644         imon = imon + 1 
1645         IF ( imon > 12 ) THEN
1646            imon = 1
1647            iyea = iyea + 1
1648            CALL calc_month_len( iyea, imonth_len )  ! update month lengths
1649         ENDIF
1650      END DO
1651
1652      !-----------------------------------------------------------------------
1653      ! Convert it into YYYYMMDD.HHMMSS format
1654      !-----------------------------------------------------------------------
1655      ddobsfin = iyea * 10000_dp + imon * 100_dp    + iday &
1656         &     + ihou * 0.01_dp  + imin * 0.0001_dp
1657
1658    END SUBROUTINE fin_date
1659   
1660END MODULE diaobs
Note: See TracBrowser for help on using the repository browser.