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.
trcini_fabm.F90 in NEMO/branches/UKMO/AMM15_v3_6_STABLE_new_ersem/NEMOGCM/NEMO/TOP_SRC/FABM – NEMO

source: NEMO/branches/UKMO/AMM15_v3_6_STABLE_new_ersem/NEMOGCM/NEMO/TOP_SRC/FABM/trcini_fabm.F90 @ 15508

Last change on this file since 15508 was 15508, checked in by jcastill, 8 months ago

Corrections for FABM 1.0

File size: 25.7 KB
Line 
1MODULE trcini_fabm
2   !!======================================================================
3   !!                         ***  MODULE trcini_fabm  ***
4   !! TOP :   initialisation of the FABM tracers
5   !!======================================================================
6   !! History :   1.0  !  2015-04  (PML) Original code
7   !! History :   1.1  !  2020-06  (PML) Update to FABM 1.0, improved performance
8   !!----------------------------------------------------------------------
9#if defined key_fabm
10   !!----------------------------------------------------------------------
11   !!   'key_fabm'                                               FABM tracers
12   !!----------------------------------------------------------------------
13   !! trc_ini_fabm   : FABM model initialisation
14   !!----------------------------------------------------------------------
15   USE par_trc         ! TOP parameters
16   USE oce_trc
17   USE trc
18   USE par_fabm
19   USE trcsms_fabm
20   USE fabm, only: fabm_create_model, type_fabm_variable
21   USE fabm_driver
22   USE inputs_fabm,ONLY: initialize_inputs, link_inputs, &
23     type_input_variable,type_input_data,type_river_data, &
24     first_input_data,first_river_data
25#if defined key_git_version
26   USE fabm_version,ONLY: fabm_commit_id=>git_commit_id, &
27                          fabm_branch_name=>git_branch_name
28   USE fabm_types,ONLY: type_version,first_module_version
29#endif
30
31   IMPLICIT NONE
32   PRIVATE
33
34#if defined key_git_version
35#include "gitversion.h90"
36   CHARACTER(len=*),parameter :: git_commit_id = _NEMO_COMMIT_ID_
37   CHARACTER(len=*),parameter :: git_branch_name = _NEMO_BRANCH_
38#endif
39
40   PUBLIC   trc_ini_fabm   ! called by trcini.F90 module
41   PUBLIC   nemo_fabm_configure
42
43   TYPE,extends(type_base_driver) :: type_nemo_fabm_driver
44   contains
45      procedure :: fatal_error => nemo_fabm_driver_fatal_error
46      procedure :: log_message => nemo_fabm_driver_log_message
47   end type
48
49   !!----------------------------------------------------------------------
50   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
51   !! $Id$
52   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
53   !!----------------------------------------------------------------------
54CONTAINS
55
56   SUBROUTINE nemo_fabm_configure()
57      INTEGER :: jn
58      INTEGER, PARAMETER :: xml_unit = 1979
59      TYPE (type_input_data),POINTER :: input_data
60      TYPE (type_river_data),POINTER :: river_data
61      CLASS (type_input_variable),POINTER :: input_pointer
62
63      ALLOCATE(type_nemo_fabm_driver::driver)
64
65      ! Allow FABM to parse fabm.yaml. This ensures numbers of variables are known.
66      model => fabm_create_model()
67
68      jp_fabm = size(model%interior_state_variables)
69      jp_fabm_bottom = size(model%bottom_state_variables)
70      jp_fabm_surface = size(model%surface_state_variables)
71      jp_fabm0 = jptra + 1
72      jp_fabm1 = jptra + jp_fabm
73      jp_fabm_m1=jptra
74      jptra = jptra + jp_fabm
75      jpdia2d = jpdia2d + size(model%horizontal_diagnostic_variables)
76      jpdia3d = jpdia3d + size(model%interior_diagnostic_variables)
77      jpdiabio = jpdiabio + jp_fabm
78
79      ! Read inputs (river and additional 2D forcing) from fabm_input.nml
80      ! This must be done before writing field_def_fabm.xml, as that file
81      ! also describes the additional input variables.
82      call initialize_inputs
83
84      ! Get indexes for select state variables
85      jp_fabm_chl1 = fabm_state_index( 'P1_Chl' )
86      jp_fabm_chl2 = fabm_state_index( 'P2_Chl' )
87      jp_fabm_chl3 = fabm_state_index( 'P3_Chl' )
88      jp_fabm_chl4 = fabm_state_index( 'P4_Chl' )
89      jp_fabm_p1c  = fabm_state_index( 'P1_c' )
90      jp_fabm_p1n  = fabm_state_index( 'P1_n' )
91      jp_fabm_p1p  = fabm_state_index( 'P1_p' )
92      jp_fabm_p1s  = fabm_state_index( 'P1_s' )
93      jp_fabm_p2c  = fabm_state_index( 'P2_c' )
94      jp_fabm_p2n  = fabm_state_index( 'P2_n' )
95      jp_fabm_p2p  = fabm_state_index( 'P2_p' )
96      jp_fabm_p3c  = fabm_state_index( 'P3_c' )
97      jp_fabm_p3n  = fabm_state_index( 'P3_n' )
98      jp_fabm_p3p  = fabm_state_index( 'P3_p' )
99      jp_fabm_p4c  = fabm_state_index( 'P4_c' )
100      jp_fabm_p4n  = fabm_state_index( 'P4_n' )
101      jp_fabm_p4p  = fabm_state_index( 'P4_p' )
102      jp_fabm_z4c  = fabm_state_index( 'Z4_c' )
103      jp_fabm_z5c  = fabm_state_index( 'Z5_c' )
104      jp_fabm_z5n  = fabm_state_index( 'Z5_n' )
105      jp_fabm_z5p  = fabm_state_index( 'Z5_p' )
106      jp_fabm_z6c  = fabm_state_index( 'Z6_c' )
107      jp_fabm_z6n  = fabm_state_index( 'Z6_n' )
108      jp_fabm_z6p  = fabm_state_index( 'Z6_p' )
109      jp_fabm_n1p  = fabm_state_index( 'N1_p' )
110      jp_fabm_n3n  = fabm_state_index( 'N3_n' )
111      jp_fabm_n4n  = fabm_state_index( 'N4_n' )
112      jp_fabm_n5s  = fabm_state_index( 'N5_s' )
113      jp_fabm_o2o  = fabm_state_index( 'O2_o' )
114      jp_fabm_o3c  = fabm_state_index( 'O3_c' )
115      jp_fabm_o3ba = fabm_state_index( 'O3_bioalk' )
116      jp_fabm_r4n  = fabm_state_index( 'R4_n' )
117      jp_fabm_r4c  = fabm_state_index( 'R4_c' )
118      jp_fabm_r4p  = fabm_state_index( 'R4_p' )
119      jp_fabm_r6n  = fabm_state_index( 'R6_n' )
120      jp_fabm_r6c  = fabm_state_index( 'R6_c' )
121      jp_fabm_r6p  = fabm_state_index( 'R6_p' )
122      jp_fabm_r6s  = fabm_state_index( 'R6_s' )
123      jp_fabm_r8n  = fabm_state_index( 'R8_n' )
124      jp_fabm_r8c  = fabm_state_index( 'R8_c' )
125      jp_fabm_r8p  = fabm_state_index( 'R8_p' )
126      jp_fabm_r8s  = fabm_state_index( 'R8_s' )
127
128      ! Get indexes for select diagnostic variables
129      jp_fabm_o3ta  = fabm_diag_index( 'O3_TA' )
130      jp_fabm_o3ph  = fabm_diag_index( 'O3_pH' )
131      jp_fabm_o3pc  = fabm_diag_index( 'O3_pCO2' )
132      jp_fabm_pgrow = fabm_diag_index( 'p_grow_sum_result' )
133      jp_fabm_ploss = fabm_diag_index( 'p_loss_sum_result' )
134     
135      MLD_MAX(:,:)   = 0.0
136      PGROW_AVG(:,:) = 0.0
137      PLOSS_AVG(:,:) = 0.0
138      PHYT_AVG(:,:)  = 0.0
139
140      IF (lwp) THEN
141         ! write field_def_fabm.xml on lead process
142         OPEN(UNIT=xml_unit,FILE='field_def_fabm.xml',ACTION='WRITE',STATUS='REPLACE')
143
144         WRITE (xml_unit,1000) '<field_definition level="1" prec="4" operation="average" enabled=".TRUE." default_value="1.e20" >'
145
146         WRITE (xml_unit,1000) ' <field_group id="ptrc_T" grid_ref="grid_T_3D">'
147         DO jn=1,jp_fabm
148            CALL write_variable_xml(xml_unit,model%interior_state_variables(jn))
149#if defined key_trdtrc
150            CALL write_trends_xml(xml_unit,model%interior_state_variables(jn))
151#endif
152            CALL write_25hourm_xml(xml_unit,model%interior_state_variables(jn))
153            CALL write_tmb_xml(xml_unit,model%interior_state_variables(jn))
154         END DO
155         WRITE (xml_unit,1000) ' </field_group>'
156
157         WRITE (xml_unit,1000) ' <field_group id="sf_T" grid_ref="grid_T_2D">'
158         DO jn=1,jp_fabm_surface
159            CALL write_variable_xml(xml_unit,model%surface_state_variables(jn))
160            CALL write_25hourm_xml(xml_unit,model%surface_state_variables(jn))
161         END DO
162         DO jn=1,jp_fabm_bottom
163            CALL write_variable_xml(xml_unit,model%bottom_state_variables(jn))
164            CALL write_25hourm_xml(xml_unit,model%bottom_state_variables(jn))
165         END DO
166         WRITE (xml_unit,1000) ' </field_group>'
167
168         WRITE (xml_unit,1000) ' <field_group id="diad_T" grid_ref="grid_T_2D">'
169         DO jn=1,size(model%interior_diagnostic_variables)
170            CALL write_variable_xml(xml_unit,model%interior_diagnostic_variables(jn),3)
171            CALL write_25hourm_xml(xml_unit,model%interior_diagnostic_variables(jn),3)
172            CALL write_tmb_xml(xml_unit,model%interior_diagnostic_variables(jn))
173         END DO
174         DO jn=1,size(model%horizontal_diagnostic_variables)
175            CALL write_variable_xml(xml_unit,model%horizontal_diagnostic_variables(jn))
176            CALL write_25hourm_xml(xml_unit,model%horizontal_diagnostic_variables(jn))
177         END DO
178         DO jn=1,size(model%interior_state_variables)
179            WRITE (xml_unit,'(A)') '  <field id="'//TRIM(model%interior_state_variables(jn)%name)// &
180                      '_VINT"long_name="depth-integrated '//TRIM(model%interior_state_variables(jn)%long_name) &
181                      //'" unit="'//TRIM(model%interior_state_variables(jn)%units)//'*m" default_value="0.0" />'
182         END DO
183         DO jn=1,size(model%interior_diagnostic_variables)
184            WRITE (xml_unit,'(A)') '  <field id="'//TRIM(model%interior_diagnostic_variables(jn)%name)// &
185                      '_VINT"long_name="depth-integrated '//TRIM(model%interior_diagnostic_variables(jn)%long_name) &
186                      //'" unit="'//TRIM(model%interior_diagnostic_variables(jn)%units)//'*m" default_value="0.0" />'
187         END DO
188         WRITE (xml_unit,1000) ' </field_group>'
189
190         WRITE (xml_unit,1000) ' <field_group id="fabm_scalar" grid_ref="grid_0">'
191         DO jn=1,size(model%conserved_quantities)
192            CALL write_variable_xml(xml_unit,model%conserved_quantities(jn))
193         END DO
194         WRITE (xml_unit,1000) ' </field_group>'
195
196         WRITE (xml_unit,1000) ' <field_group id="fabm_input" grid_ref="grid_T_2D">'
197         input_data => first_input_data
198         DO WHILE (ASSOCIATED(input_data))
199           input_pointer => input_data
200           CALL write_input_xml(xml_unit,input_pointer)
201            input_data => input_data%next
202         END DO
203         river_data => first_river_data
204         DO WHILE (ASSOCIATED(river_data))
205           input_pointer => river_data
206           CALL write_input_xml(xml_unit,input_pointer,3)
207            river_data => river_data%next
208         END DO
209         WRITE (xml_unit,1000) ' </field_group>'
210
211         WRITE (xml_unit,1000) '</field_definition>'
212
213         CLOSE(xml_unit)
214      END IF
215      IF( lk_mpp )   CALL mppsync !Ensure field_def_fabm is ready.
216
2171000 FORMAT (A)
218
219   END SUBROUTINE nemo_fabm_configure
220
221   SUBROUTINE write_variable_xml(xml_unit,variable,flag_grid_ref)
222      INTEGER,INTENT(IN) :: xml_unit
223      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
224      CLASS (type_fabm_variable),INTENT(IN) :: variable
225
226      CHARACTER(LEN=20) :: missing_value,string_dimensions
227      INTEGER :: number_dimensions
228
229      ! Check variable dimension for grid_ref specificaiton.
230      ! Default is to not specify the grid_ref in the field definition.
231      IF (present(flag_grid_ref)) THEN
232          number_dimensions=flag_grid_ref
233      ELSE
234          number_dimensions=-1 !default, don't specify grid_ref
235      ENDIF
236
237      WRITE (missing_value,'(E9.3)') variable%missing_value
238      WRITE (string_dimensions,'(I1)') number_dimensions
239      SELECT CASE (number_dimensions)
240      CASE (3)
241         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'" long_name="'//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
242      CASE (2)
243         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'" long_name="'//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
244      CASE (0)
245         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'" long_name="'//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="1point"/>'
246      CASE (-1)
247         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'" long_name="'//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" />'
248      CASE default
249         IF(lwp) WRITE(numout,*) ' trc_ini_fabm: Failing to initialise output of variable '//TRIM(variable%name)//': Output of '//TRIM(ADJUSTL(string_dimensions))//'-dimensional variables not supported!!!'
250      END SELECT
251
252   END SUBROUTINE write_variable_xml
253
254   SUBROUTINE write_25hourm_xml(xml_unit,variable,flag_grid_ref)
255      INTEGER,INTENT(IN) :: xml_unit
256      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
257      CLASS (type_fabm_variable),INTENT(IN) :: variable
258
259      CHARACTER(LEN=20) :: missing_value,string_dimensions
260      INTEGER :: number_dimensions
261
262      ! Check variable dimension for grid_ref specificaiton.
263      ! Default is to not specify the grid_ref in the field definition.
264      IF (present(flag_grid_ref)) THEN
265          number_dimensions=flag_grid_ref
266      ELSE
267          number_dimensions=-1 !default, don't specify grid_ref
268      ENDIF
269
270      WRITE (missing_value,'(E9.3)') 1.e+20
271      WRITE (string_dimensions,'(I1)') number_dimensions
272      SELECT CASE (number_dimensions)
273      CASE (3)
274         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
275      CASE (2)
276         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
277      CASE (0)
278         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="1point"/>'
279      CASE (-1)
280         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" />'
281      CASE default
282         IF(lwp) WRITE(numout,*) ' trc_ini_fabm: Failing to initialise output of variable '//TRIM(variable%name)//'25h'//': Output of '//TRIM(ADJUSTL(string_dimensions))//'-dimensional variables not supported!!!'
283      END SELECT
284
285   END SUBROUTINE write_25hourm_xml
286
287   SUBROUTINE write_tmb_xml(xml_unit,variable)
288      INTEGER,INTENT(IN) :: xml_unit
289      CLASS (type_fabm_variable),INTENT(IN) :: variable
290
291      CHARACTER(LEN=20) :: missing_value
292
293      WRITE (missing_value,'(E9.3)') 1.e+20
294      WRITE (xml_unit,'(A)') '  <field id="top_'//TRIM(variable%name)//'" long_name="Top-level '//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
295      WRITE (xml_unit,'(A)') '  <field id="mid_'//TRIM(variable%name)//'" long_name="Middle-level '//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
296      WRITE (xml_unit,'(A)') '  <field id="bot_'//TRIM(variable%name)//'" long_name="Bottom-level '//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
297
298   END SUBROUTINE write_tmb_xml
299
300   SUBROUTINE write_trends_xml(xml_unit,variable,flag_grid_ref)
301      INTEGER,INTENT(IN) :: xml_unit
302      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
303      CLASS (type_fabm_variable),INTENT(IN) :: variable
304
305      INTEGER :: number_dimensions,i
306      CHARACTER(LEN=20) :: missing_value,string_dimensions
307#if defined key_tracer_budget
308      CHARACTER(LEN=3),DIMENSION(10),PARAMETER :: trd_tags = (/ &
309        'LDF','BBL','FOR','ZDF','DMP','SMS','ATF', &
310        'RDB','RDN','VMV' /)
311      CHARACTER(LEN=3),DIMENSION(3),PARAMETER :: trd_e3t_tags = (/ &
312        'XAD','YAD','ZAD' /)
313#else
314      CHARACTER(LEN=3),DIMENSION(13),PARAMETER :: trd_tags = (/ &
315        'XAD','YAD','ZAD','LDF','BBL','FOR','ZDF','DMP','SMS','ATF', &
316        'RDB','RDN','VMV' /)
317#endif
318
319      ! Check variable dimension for grid_ref specificaiton.
320      ! Default is to not specify the grid_ref in the field definition.
321      IF (present(flag_grid_ref)) THEN
322          number_dimensions=flag_grid_ref
323      ELSE
324          number_dimensions=-1 !default, don't specify grid_ref
325      ENDIF
326
327      WRITE (missing_value,'(E9.3)') -2.E20
328      WRITE (string_dimensions,'(I1)') number_dimensions
329      SELECT CASE (number_dimensions)
330      CASE (3)
331        DO i=1,size(trd_tags)
332         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_tags(i))//'_'//TRIM(variable%name)//'" long_name="'// &
333            &                   TRIM(variable%long_name)//' '//TRIM(trd_tags(i))//' trend" unit="'//            &
334            &                   TRIM(variable%units)//'/s" default_value="'//                                   &
335            &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
336        END DO
337#if defined key_tracer_budget
338        DO i=1,size(trd_e3t_tags)
339         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_e3t_tags(i))//'_'//TRIM(variable%name)//                     &
340            &                   '_e3t" long_name="'//TRIM(variable%long_name)//' cell depth integrated '//             &
341            &                   TRIM(trd_e3t_tags(i))//' trend" unit="'//TRIM(variable%units)//'/s" default_value="'// &
342            &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
343        END DO
344        WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'_e3t" long_name="'//TRIM(variable%long_name)// &
345           &                   ' cell depth integrated" unit="'//TRIM(variable%units)//'*m" default_value="'//       &
346           &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
347#endif
348      CASE (-1)
349        DO i=1,size(trd_tags)
350         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_tags(i))//'_'//TRIM(variable%name)//'" long_name="'//   &
351            &                   TRIM(variable%long_name)//' '//TRIM(trd_tags(i))//' trend" unit="'//              &
352            &                   TRIM(variable%units)//'/s" default_value="'//TRIM(ADJUSTL(missing_value))//'" />'
353        END DO
354#if defined key_tracer_budget
355        DO i=1,size(trd_e3t_tags)
356         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_e3t_tags(i))//'_'//TRIM(variable%name)//                     &
357            &                   '_e3t" long_name="'//TRIM(variable%long_name)//' cell depth integrated '//             &
358            &                   TRIM(trd_e3t_tags(i))//' trend" unit="'//TRIM(variable%units)//'/s" default_value="'// &
359            &                   TRIM(ADJUSTL(missing_value))//'" />'
360        END DO
361        WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'_e3t" long_name="'//TRIM(variable%long_name)// &
362           &                   ' cell depth integrated" unit="'//TRIM(variable%units)//'*m" default_value="'//       &
363           &                   TRIM(ADJUSTL(missing_value))//'" />'
364#endif
365      CASE default
366         IF(lwp) WRITE(numout,*) ' trc_ini_fabm: Failing to initialise trends of variable '//TRIM(variable%name)// &
367            &                    ': Output of '//TRIM(ADJUSTL(string_dimensions))//'-dimensional trends not supported!!!'
368      END SELECT
369
370   END SUBROUTINE write_trends_xml
371
372   SUBROUTINE write_input_xml(xml_unit,variable,flag_grid_ref)
373      INTEGER,INTENT(IN) :: xml_unit
374      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
375      CLASS(type_input_variable),POINTER,INTENT(IN) :: variable
376
377      INTEGER :: number_dimensions,i
378      CHARACTER(LEN=20) :: missing_value,string_dimensions
379
380      ! Check variable dimension for grid_ref specificaiton.
381      ! Default is to not specify the grid_ref in the field definition.
382      IF (present(flag_grid_ref)) THEN
383          number_dimensions=flag_grid_ref
384      ELSE
385          number_dimensions=-1 !default, don't specify grid_ref
386      ENDIF
387
388      WRITE (missing_value,'(E9.3)') -2.E20
389      WRITE (string_dimensions,'(I1)') number_dimensions
390      SELECT CASE (number_dimensions)
391      CASE (3)
392        WRITE (xml_unit,'(A)') '  <field id="'//'INP_'//TRIM(variable%sf(1)%clvar)//'" long_name="'//TRIM(variable%sf(1)%clvar)//' input" unit="" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
393      CASE (-1)
394        WRITE (xml_unit,'(A)') '  <field id="'//'INP_'//TRIM(variable%sf(1)%clvar)//'" long_name="'//TRIM(variable%sf(1)%clvar)//' input" unit="" default_value="'//TRIM(ADJUSTL(missing_value))//'" />'
395      CASE default
396         IF(lwp) WRITE(numout,*) ' trc_ini_fabm: Failing to initialise input diagnostic of variable '//TRIM(variable%sf(1)%clvar)//': Output of '//TRIM(ADJUSTL(string_dimensions))//'-dimensional diagnostic not supported!!!'
397      END SELECT
398
399   END SUBROUTINE write_input_xml
400
401   SUBROUTINE trc_ini_fabm
402      !!----------------------------------------------------------------------
403      !!                     ***  trc_ini_fabm  ***
404      !!
405      !! ** Purpose :   initialization for FABM model
406      !!
407      !! ** Method  : - Allocate FABM arrays, configure domain, send data
408      !!----------------------------------------------------------------------
409#if defined key_git_version
410      TYPE (type_version),POINTER :: version
411#endif
412      INTEGER :: jn
413
414      !                       ! Allocate FABM arrays
415      IF( trc_sms_fabm_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'trc_ini_fabm: unable to allocate FABM arrays' )
416
417      IF(lwp) WRITE(numout,*)
418      IF(lwp) WRITE(numout,*) ' trc_ini_fabm: initialisation of FABM model'
419      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
420#if defined key_git_version
421      IF(lwp) WRITE(numout,*) ' NEMO version:   ',git_commit_id,' (',git_branch_name,' branch)'
422      IF(lwp) WRITE(numout,*) ' FABM version:   ',fabm_commit_id,' (',fabm_branch_name,' branch)'
423#endif
424
425      call fabm_initialize_library()
426#if defined key_git_version
427      version => first_module_version
428
429      do while (associated(version))
430         IF(lwp) WRITE(numout,*)  ' '//trim(version%module_name)//' version:   ',trim(version%version_string)
431         version => version%next
432      end do
433#endif
434
435      ! Log mapping of FABM states:
436      IF (lwp) THEN
437         IF (jp_fabm > 0) WRITE(numout,*) " FABM tracers:"
438         DO jn=1,jp_fabm
439            WRITE(numout,*) "   State",jn,":",trim(model%interior_state_variables(jn)%name), &
440               " (",trim(model%interior_state_variables(jn)%long_name), &
441               ") [",trim(model%interior_state_variables(jn)%units),"]"
442         ENDDO
443         IF (jp_fabm_surface > 0) WRITE(numout,*) "FABM seasurface states:"
444         DO jn=1,jp_fabm_surface
445            WRITE(numout,*) "   State",jn,":",trim(model%surface_state_variables(jn)%name), &
446               " (",trim(model%surface_state_variables(jn)%long_name), &
447               ") [",trim(model%surface_state_variables(jn)%units),"]"
448         ENDDO
449         IF (jp_fabm_bottom > 0) WRITE(numout,*) "FABM seafloor states:"
450         DO jn=1,jp_fabm_bottom
451            WRITE(numout,*) "   State",jn,":",trim(model%bottom_state_variables(jn)%name), &
452               " (",trim(model%bottom_state_variables(jn)%long_name), &
453               ") [",trim(model%bottom_state_variables(jn)%units),"]"
454         ENDDO
455      ENDIF
456
457   END SUBROUTINE trc_ini_fabm
458
459   SUBROUTINE nemo_fabm_driver_fatal_error(self, location, message)
460      CLASS (type_nemo_fabm_driver), INTENT(INOUT) :: self
461      CHARACTER(len=*),              INTENT(IN)    :: location, message
462
463      CALL ctl_stop('STOP', TRIM(location)//': '//TRIM(message))
464      STOP
465   END SUBROUTINE
466
467   SUBROUTINE nemo_fabm_driver_log_message(self, message)
468      CLASS (type_nemo_fabm_driver), INTENT(INOUT) :: self
469      CHARACTER(len=*),              INTENT(IN)    :: message
470
471      IF(lwp) WRITE (numout,*) TRIM(message)
472   END SUBROUTINE
473
474   INTEGER FUNCTION fabm_state_index( state_name )
475      !!----------------------------------------------------------------------
476      !!                     ***  fabm_state_index  *** 
477      !!
478      !! ** Purpose :   return index of a given FABM state variable
479      !!
480      !! ** Method  : - loop through state variables until found
481      !!----------------------------------------------------------------------
482     
483      IMPLICIT NONE
484     
485      CHARACTER(LEN=256), INTENT(IN) :: state_name
486     
487      INTEGER                        :: jn
488
489      !!----------------------------------------------------------------------
490     
491      fabm_state_index = -1
492      DO jn=1,jp_fabm
493         IF (TRIM(model%interior_state_variables(jn)%name) == TRIM(state_name)) THEN
494            fabm_state_index = jn
495            EXIT
496         ENDIF
497      END DO
498      IF (fabm_state_index == -1) THEN
499         CALL ctl_warn( 'Could not find '//TRIM(state_name)//' state variable' )
500      ELSE
501         IF (lwp) WRITE(numout,*) 'Index for '//TRIM(state_name)//' is: ', fabm_state_index
502      ENDIF
503   
504   END FUNCTION fabm_state_index
505
506   INTEGER FUNCTION fabm_diag_index( diag_name )
507      !!----------------------------------------------------------------------
508      !!                     ***  fabm_state_index  *** 
509      !!
510      !! ** Purpose :   return index of a given FABM diagnostic variable
511      !!
512      !! ** Method  : - loop through diagnostic variables until found
513      !!----------------------------------------------------------------------
514     
515      IMPLICIT NONE
516     
517      CHARACTER(LEN=256), INTENT(IN) :: diag_name
518     
519      INTEGER                        :: jn
520
521      !!----------------------------------------------------------------------
522     
523      fabm_diag_index = -1
524      DO jn = 1, SIZE(model%interior_diagnostic_variables)
525         IF (TRIM(model%interior_diagnostic_variables(jn)%name) == TRIM(diag_name)) THEN
526            fabm_diag_index = jn
527            EXIT
528         ENDIF
529      END DO
530      IF (fabm_diag_index == -1) THEN
531         CALL ctl_warn( 'Could not find '//TRIM(diag_name)//' diagnostic' )
532      ELSE
533         IF (lwp) WRITE(numout,*) 'Index for '//TRIM(diag_name)//' is: ', fabm_diag_index
534      ENDIF
535   
536   END FUNCTION fabm_diag_index
537
538#else
539   !!----------------------------------------------------------------------
540   !!   Dummy module                                        No FABM model
541   !!----------------------------------------------------------------------
542CONTAINS
543   SUBROUTINE nemo_fabm_configure
544   END SUBROUTINE nemo_fabm_configure
545
546   SUBROUTINE trc_ini_fabm            ! Empty routine
547   END SUBROUTINE trc_ini_fabm
548#endif
549
550   !!======================================================================
551END MODULE trcini_fabm
Note: See TracBrowser for help on using the repository browser.