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/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/OBS – NEMO

source: branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90 @ 5984

Last change on this file since 5984 was 5984, checked in by timgraham, 8 years ago

Clear svn keywords to allow use with fcm make

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