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.
asmbkg.F90 in branches/UKMO/dev_r8183_ICEMODEL_svn_removed/NEMOGCM/NEMO/OPA_SRC/ASM – NEMO

source: branches/UKMO/dev_r8183_ICEMODEL_svn_removed/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90 @ 8738

Last change on this file since 8738 was 8738, checked in by dancopsey, 6 years ago

Merged in main ICEMODEL branch (branches/2017/dev_r8183_ICEMODEL) up to revision 8588

File size: 7.9 KB
Line 
1MODULE asmbkg
2   !!======================================================================
3   !!                       ***  MODULE asmtrj -> asmbkg  ***
4   !! Assimilation trajectory interface: Write to file the background state and the model state trajectory
5   !!======================================================================
6   !! History :       ! 2007-03 (M. Martin)  Met. Office version
7   !!                 ! 2007-04 (A. Weaver)  asm_trj_wri, original code
8   !!                 ! 2007-03 (K. Mogensen)  Adapt to NEMOVAR and use IOM instead of IOIPSL
9   !!                 ! 2007-04 (A. Weaver)  Name change (formally asmbkg.F90). Distinguish
10   !!                                        background states in Jb term and at analysis time.
11   !!                                        Include state trajectory routine (currently empty)
12   !!                 ! 2007-07 (A. Weaver)  Add tke_rst and flt_rst for case nitbkg=0
13   !!                 ! 2009-03 (F. Vigilant)  Add hmlp (zdfmxl) for no tracer nmldp=2
14   !!                 ! 2009-06 (F. Vigilant) asm_trj_wri: special case when kt=nit000-1
15   !!                 ! 2009-07 (F. Vigilant) asm_trj_wri: add computation of eiv at restart
16   !!                 ! 2010-01 (A. Vidard) split asm_trj_wri into tam_trj_wri and asm_bkg_wri
17   !!----------------------------------------------------------------------
18
19   !!----------------------------------------------------------------------
20   !!   asm_bkg_wri  : Write out the background state
21   !!   asm_trj_wri  : Write out the model state trajectory (used with 4D-Var)
22   !!----------------------------------------------------------------------
23   USE oce                ! Dynamics and active tracers defined in memory
24   USE sbc_oce            ! Ocean surface boundary conditions
25   USE zdf_oce            ! Vertical mixing variables
26   USE zdfddm             ! Double diffusion mixing parameterization
27   USE ldftra             ! Lateral diffusion: eddy diffusivity coefficients
28   USE ldfslp             ! Lateral diffusion: slopes of neutral surfaces
29   USE tradmp             ! Tracer damping
30#if defined key_zdftke
31   USE zdftke             ! TKE vertical physics
32#endif
33   USE eosbn2             ! Equation of state (eos_bn2 routine)
34   USE zdfmxl             ! Mixed layer depth
35   USE dom_oce     , ONLY :   ndastp
36   USE in_out_manager     ! I/O manager
37   USE iom                ! I/O module
38   USE asmpar             ! Parameters for the assmilation interface
39   USE zdfmxl             ! mixed layer depth
40#if defined key_lim3
41   USE ice
42#endif
43
44   IMPLICIT NONE
45   PRIVATE
46   
47   PUBLIC   asm_bkg_wri   !: Write out the background state
48
49   !!----------------------------------------------------------------------
50   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
51   !! $Id$
52   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
53   !!----------------------------------------------------------------------
54CONTAINS
55
56   SUBROUTINE asm_bkg_wri( kt )
57      !!-----------------------------------------------------------------------
58      !!                  ***  ROUTINE asm_bkg_wri ***
59      !!
60      !! ** Purpose : Write to file the background state for later use in the
61      !!              inner loop of data assimilation or for direct initialization
62      !!              in the outer loop.
63      !!
64      !! ** Method  : Write out the background state for use in the Jb term
65      !!              in the cost function and for use with direct initialization
66      !!              at analysis time.
67      !!-----------------------------------------------------------------------
68      INTEGER, INTENT( IN ) :: kt               ! Current time-step
69      !
70      CHARACTER (LEN=50) :: cl_asmbkg
71      CHARACTER (LEN=50) :: cl_asmdin
72      LOGICAL :: llok          ! Check if file exists
73      INTEGER :: inum          ! File unit number
74      REAL(wp) :: zdate        ! Date
75      !!-----------------------------------------------------------------------
76
77      !                                !-------------------------------------------
78      IF( kt == nitbkg_r ) THEN        ! Write out background at time step nitbkg_r
79         !                             !-----------------------------------========
80         !
81         WRITE(cl_asmbkg, FMT='(A,".nc")' ) TRIM( c_asmbkg )
82         cl_asmbkg = TRIM( cl_asmbkg )
83         INQUIRE( FILE = cl_asmbkg, EXIST = llok )
84         !
85         IF( .NOT. llok ) THEN
86            IF(lwp) WRITE(numout,*) ' Setting up assimilation background file '// TRIM( c_asmbkg )
87            !
88            !                                      ! Define the output file       
89            CALL iom_open( c_asmbkg, inum, ldwrt = .TRUE., kiolib = jprstlib)
90            !
91            IF( nitbkg_r == nit000 - 1 ) THEN      ! Treat special case when nitbkg = 0
92               zdate = REAL( ndastp )
93#if defined key_zdftke
94               ! lk_zdftke=T :   Read turbulent kinetic energy ( en )
95               IF(lwp) WRITE(numout,*) ' Reading TKE (en) from restart...'
96               CALL tke_rst( nit000, 'READ' )               ! lk_zdftke=T :   Read turbulent kinetic energy ( en )
97
98#endif
99            ELSE
100               zdate = REAL( ndastp )
101            ENDIF
102            !
103            !                                      ! Write the information
104            CALL iom_rstput( kt, nitbkg_r, inum, 'rdastp' , zdate             )
105            CALL iom_rstput( kt, nitbkg_r, inum, 'un'     , un                )
106            CALL iom_rstput( kt, nitbkg_r, inum, 'vn'     , vn                )
107            CALL iom_rstput( kt, nitbkg_r, inum, 'tn'     , tsn(:,:,:,jp_tem) )
108            CALL iom_rstput( kt, nitbkg_r, inum, 'sn'     , tsn(:,:,:,jp_sal) )
109            CALL iom_rstput( kt, nitbkg_r, inum, 'sshn'   , sshn              )
110#if defined key_zdftke
111            CALL iom_rstput( kt, nitbkg_r, inum, 'en'     , en                )
112#endif
113            !
114            CALL iom_close( inum )
115         ENDIF
116         !
117      ENDIF
118
119      !                                !-------------------------------------------
120      IF( kt == nitdin_r ) THEN        ! Write out background at time step nitdin_r
121         !                             !-----------------------------------========
122         !
123         WRITE(cl_asmdin, FMT='(A,".nc")' ) TRIM( c_asmdin )
124         cl_asmdin = TRIM( cl_asmdin )
125         INQUIRE( FILE = cl_asmdin, EXIST = llok )
126         !
127         IF( .NOT. llok ) THEN
128            IF(lwp) WRITE(numout,*) ' Setting up assimilation background file '// TRIM( c_asmdin )
129            !
130            !                                      ! Define the output file       
131            CALL iom_open( c_asmdin, inum, ldwrt = .TRUE., kiolib = jprstlib)
132            !
133            IF( nitdin_r == nit000 - 1 ) THEN      ! Treat special case when nitbkg = 0
134
135               zdate = REAL( ndastp )
136            ELSE
137               zdate = REAL( ndastp )
138            ENDIF
139            !
140            !                                      ! Write the information
141            CALL iom_rstput( kt, nitdin_r, inum, 'rdastp' , zdate             )
142            CALL iom_rstput( kt, nitdin_r, inum, 'un'     , un                )
143            CALL iom_rstput( kt, nitdin_r, inum, 'vn'     , vn                )
144            CALL iom_rstput( kt, nitdin_r, inum, 'tn'     , tsn(:,:,:,jp_tem) )
145            CALL iom_rstput( kt, nitdin_r, inum, 'sn'     , tsn(:,:,:,jp_sal) )
146            CALL iom_rstput( kt, nitdin_r, inum, 'sshn'   , sshn              )
147#if defined key_lim3
148            IF( nn_ice == 2 ) THEN
149               IF( ALLOCATED(at_i) ) THEN
150                  CALL iom_rstput( kt, nitdin_r, inum, 'iceconc', at_i(:,:)   )
151               ELSE
152                  CALL ctl_warn('Ice concentration not written to background as ice variable at_i not allocated on this timestep')
153               ENDIF
154            ENDIF
155#endif
156            !
157            CALL iom_close( inum )
158         ENDIF
159         !
160      ENDIF
161      !                   
162   END SUBROUTINE asm_bkg_wri
163
164   !!======================================================================
165END MODULE asmbkg
Note: See TracBrowser for help on using the repository browser.