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

source: trunk/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90 @ 2760

Last change on this file since 2760 was 2733, checked in by rblod, 13 years ago

Agrif can now work with observation operator

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