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 @ 15480

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

Changes as in the git branch NEMO-FABMv1-ERSEM

File size: 25.6 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%state_variables(jn))
153            CALL write_tmb_xml(xml_unit,model%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)//'_VINT" &
180            long_name="depth-integrated '//TRIM(model%interior_state_variables(jn)%long_name)//'" unit="'//TRIM(model%interior_state_variables(jn)%units)//'*m" default_value="0.0" />'
181         END DO
182         DO jn=1,size(model%interior_diagnostic_variables)
183            WRITE (xml_unit,'(A)') '  <field id="'//TRIM(model%interior_diagnostic_variables(jn)%name)//'_VINT" &
184            long_name="depth-integrated '//TRIM(model%interior_diagnostic_variables(jn)%long_name)//'" unit="'//TRIM(model%interior_diagnostic_variables(jn)%units)//'*m" default_value="0.0" />'
185         END DO
186         WRITE (xml_unit,1000) ' </field_group>'
187
188         WRITE (xml_unit,1000) ' <field_group id="fabm_scalar" grid_ref="grid_0">'
189         DO jn=1,size(model%conserved_quantities)
190            CALL write_variable_xml(xml_unit,model%conserved_quantities(jn))
191         END DO
192         WRITE (xml_unit,1000) ' </field_group>'
193
194         WRITE (xml_unit,1000) ' <field_group id="fabm_input" grid_ref="grid_T_2D">'
195         input_data => first_input_data
196         DO WHILE (ASSOCIATED(input_data))
197           input_pointer => input_data
198           CALL write_input_xml(xml_unit,input_pointer)
199            input_data => input_data%next
200         END DO
201         river_data => first_river_data
202         DO WHILE (ASSOCIATED(river_data))
203           input_pointer => river_data
204           CALL write_input_xml(xml_unit,input_pointer,3)
205            river_data => river_data%next
206         END DO
207         WRITE (xml_unit,1000) ' </field_group>'
208
209         WRITE (xml_unit,1000) '</field_definition>'
210
211         CLOSE(xml_unit)
212      END IF
213      IF( lk_mpp )   CALL mppsync !Ensure field_def_fabm is ready.
214
2151000 FORMAT (A)
216
217   END SUBROUTINE nemo_fabm_configure
218
219   SUBROUTINE write_variable_xml(xml_unit,variable,flag_grid_ref)
220      INTEGER,INTENT(IN) :: xml_unit
221      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
222      CLASS (type_fabm_variable),INTENT(IN) :: variable
223
224      CHARACTER(LEN=20) :: missing_value,string_dimensions
225      INTEGER :: number_dimensions
226
227      ! Check variable dimension for grid_ref specificaiton.
228      ! Default is to not specify the grid_ref in the field definition.
229      IF (present(flag_grid_ref)) THEN
230          number_dimensions=flag_grid_ref
231      ELSE
232          number_dimensions=-1 !default, don't specify grid_ref
233      ENDIF
234
235      WRITE (missing_value,'(E9.3)') variable%missing_value
236      WRITE (string_dimensions,'(I1)') number_dimensions
237      SELECT CASE (number_dimensions)
238      CASE (3)
239         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" />'
240      CASE (2)
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_2D"/>'
242      CASE (0)
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="1point"/>'
244      CASE (-1)
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))//'" />'
246      CASE default
247         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!!!'
248      END SELECT
249
250   END SUBROUTINE write_variable_xml
251
252   SUBROUTINE write_25hourm_xml(xml_unit,variable,flag_grid_ref)
253      INTEGER,INTENT(IN) :: xml_unit
254      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
255      CLASS (type_external_variable),INTENT(IN) :: variable
256
257      CHARACTER(LEN=20) :: missing_value,string_dimensions
258      INTEGER :: number_dimensions
259
260      ! Check variable dimension for grid_ref specificaiton.
261      ! Default is to not specify the grid_ref in the field definition.
262      IF (present(flag_grid_ref)) THEN
263          number_dimensions=flag_grid_ref
264      ELSE
265          number_dimensions=-1 !default, don't specify grid_ref
266      ENDIF
267
268      WRITE (missing_value,'(E9.3)') 1.e+20
269      WRITE (string_dimensions,'(I1)') number_dimensions
270      SELECT CASE (number_dimensions)
271      CASE (3)
272         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" />'
273      CASE (2)
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_2D"/>'
275      CASE (0)
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="1point"/>'
277      CASE (-1)
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))//'" />'
279      CASE default
280         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!!!'
281      END SELECT
282
283   END SUBROUTINE write_25hourm_xml
284
285   SUBROUTINE write_tmb_xml(xml_unit,variable)
286      INTEGER,INTENT(IN) :: xml_unit
287      CLASS (type_external_variable),INTENT(IN) :: variable
288
289      CHARACTER(LEN=20) :: missing_value
290
291      WRITE (missing_value,'(E9.3)') 1.e+20
292      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"/>'
293      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"/>'
294      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"/>'
295
296   END SUBROUTINE write_tmb_xml
297
298   SUBROUTINE write_trends_xml(xml_unit,variable,flag_grid_ref)
299      INTEGER,INTENT(IN) :: xml_unit
300      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
301      CLASS (type_fabm_variable),INTENT(IN) :: variable
302
303      INTEGER :: number_dimensions,i
304      CHARACTER(LEN=20) :: missing_value,string_dimensions
305#if defined key_tracer_budget
306      CHARACTER(LEN=3),DIMENSION(10),PARAMETER :: trd_tags = (/ &
307        'LDF','BBL','FOR','ZDF','DMP','SMS','ATF', &
308        'RDB','RDN','VMV' /)
309      CHARACTER(LEN=3),DIMENSION(3),PARAMETER :: trd_e3t_tags = (/ &
310        'XAD','YAD','ZAD' /)
311#else
312      CHARACTER(LEN=3),DIMENSION(13),PARAMETER :: trd_tags = (/ &
313        'XAD','YAD','ZAD','LDF','BBL','FOR','ZDF','DMP','SMS','ATF', &
314        'RDB','RDN','VMV' /)
315#endif
316
317      ! Check variable dimension for grid_ref specificaiton.
318      ! Default is to not specify the grid_ref in the field definition.
319      IF (present(flag_grid_ref)) THEN
320          number_dimensions=flag_grid_ref
321      ELSE
322          number_dimensions=-1 !default, don't specify grid_ref
323      ENDIF
324
325      WRITE (missing_value,'(E9.3)') -2.E20
326      WRITE (string_dimensions,'(I1)') number_dimensions
327      SELECT CASE (number_dimensions)
328      CASE (3)
329        DO i=1,size(trd_tags)
330         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_tags(i))//'_'//TRIM(variable%name)//'" long_name="'// &
331            &                   TRIM(variable%long_name)//' '//TRIM(trd_tags(i))//' trend" unit="'//            &
332            &                   TRIM(variable%units)//'/s" default_value="'//                                   &
333            &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
334        END DO
335#if defined key_tracer_budget
336        DO i=1,size(trd_e3t_tags)
337         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_e3t_tags(i))//'_'//TRIM(variable%name)//                     &
338            &                   '_e3t" long_name="'//TRIM(variable%long_name)//' cell depth integrated '//             &
339            &                   TRIM(trd_e3t_tags(i))//' trend" unit="'//TRIM(variable%units)//'/s" default_value="'// &
340            &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
341        END DO
342        WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'_e3t" long_name="'//TRIM(variable%long_name)// &
343           &                   ' cell depth integrated" unit="'//TRIM(variable%units)//'*m" default_value="'//       &
344           &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
345#endif
346      CASE (-1)
347        DO i=1,size(trd_tags)
348         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_tags(i))//'_'//TRIM(variable%name)//'" long_name="'//   &
349            &                   TRIM(variable%long_name)//' '//TRIM(trd_tags(i))//' trend" unit="'//              &
350            &                   TRIM(variable%units)//'/s" default_value="'//TRIM(ADJUSTL(missing_value))//'" />'
351        END DO
352#if defined key_tracer_budget
353        DO i=1,size(trd_e3t_tags)
354         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_e3t_tags(i))//'_'//TRIM(variable%name)//                     &
355            &                   '_e3t" long_name="'//TRIM(variable%long_name)//' cell depth integrated '//             &
356            &                   TRIM(trd_e3t_tags(i))//' trend" unit="'//TRIM(variable%units)//'/s" default_value="'// &
357            &                   TRIM(ADJUSTL(missing_value))//'" />'
358        END DO
359        WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'_e3t" long_name="'//TRIM(variable%long_name)// &
360           &                   ' cell depth integrated" unit="'//TRIM(variable%units)//'*m" default_value="'//       &
361           &                   TRIM(ADJUSTL(missing_value))//'" />'
362#endif
363      CASE default
364         IF(lwp) WRITE(numout,*) ' trc_ini_fabm: Failing to initialise trends of variable '//TRIM(variable%name)// &
365            &                    ': Output of '//TRIM(ADJUSTL(string_dimensions))//'-dimensional trends not supported!!!'
366      END SELECT
367
368   END SUBROUTINE write_trends_xml
369
370   SUBROUTINE write_input_xml(xml_unit,variable,flag_grid_ref)
371      INTEGER,INTENT(IN) :: xml_unit
372      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
373      CLASS(type_input_variable),POINTER,INTENT(IN) :: variable
374
375      INTEGER :: number_dimensions,i
376      CHARACTER(LEN=20) :: missing_value,string_dimensions
377
378      ! Check variable dimension for grid_ref specificaiton.
379      ! Default is to not specify the grid_ref in the field definition.
380      IF (present(flag_grid_ref)) THEN
381          number_dimensions=flag_grid_ref
382      ELSE
383          number_dimensions=-1 !default, don't specify grid_ref
384      ENDIF
385
386      WRITE (missing_value,'(E9.3)') -2.E20
387      WRITE (string_dimensions,'(I1)') number_dimensions
388      SELECT CASE (number_dimensions)
389      CASE (3)
390        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" />'
391      CASE (-1)
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))//'" />'
393      CASE default
394         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!!!'
395      END SELECT
396
397   END SUBROUTINE write_input_xml
398
399   SUBROUTINE trc_ini_fabm
400      !!----------------------------------------------------------------------
401      !!                     ***  trc_ini_fabm  ***
402      !!
403      !! ** Purpose :   initialization for FABM model
404      !!
405      !! ** Method  : - Allocate FABM arrays, configure domain, send data
406      !!----------------------------------------------------------------------
407#if defined key_git_version
408      TYPE (type_version),POINTER :: version
409#endif
410      INTEGER :: jn
411
412      !                       ! Allocate FABM arrays
413      IF( trc_sms_fabm_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'trc_ini_fabm: unable to allocate FABM arrays' )
414
415      IF(lwp) WRITE(numout,*)
416      IF(lwp) WRITE(numout,*) ' trc_ini_fabm: initialisation of FABM model'
417      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
418#if defined key_git_version
419      IF(lwp) WRITE(numout,*) ' NEMO version:   ',git_commit_id,' (',git_branch_name,' branch)'
420      IF(lwp) WRITE(numout,*) ' FABM version:   ',fabm_commit_id,' (',fabm_branch_name,' branch)'
421#endif
422
423      call fabm_initialize_library()
424#if defined key_git_version
425      version => first_module_version
426
427      do while (associated(version))
428         IF(lwp) WRITE(numout,*)  ' '//trim(version%module_name)//' version:   ',trim(version%version_string)
429         version => version%next
430      end do
431#endif
432
433      ! Log mapping of FABM states:
434      IF (lwp) THEN
435         IF (jp_fabm > 0) WRITE(numout,*) " FABM tracers:"
436         DO jn=1,jp_fabm
437            WRITE(numout,*) "   State",jn,":",trim(model%interior_state_variables(jn)%name), &
438               " (",trim(model%interior_state_variables(jn)%long_name), &
439               ") [",trim(model%interior_state_variables(jn)%units),"]"
440         ENDDO
441         IF (jp_fabm_surface > 0) WRITE(numout,*) "FABM seasurface states:"
442         DO jn=1,jp_fabm_surface
443            WRITE(numout,*) "   State",jn,":",trim(model%surface_state_variables(jn)%name), &
444               " (",trim(model%surface_state_variables(jn)%long_name), &
445               ") [",trim(model%surface_state_variables(jn)%units),"]"
446         ENDDO
447         IF (jp_fabm_bottom > 0) WRITE(numout,*) "FABM seafloor states:"
448         DO jn=1,jp_fabm_bottom
449            WRITE(numout,*) "   State",jn,":",trim(model%bottom_state_variables(jn)%name), &
450               " (",trim(model%bottom_state_variables(jn)%long_name), &
451               ") [",trim(model%bottom_state_variables(jn)%units),"]"
452         ENDDO
453      ENDIF
454
455   END SUBROUTINE trc_ini_fabm
456
457   SUBROUTINE nemo_fabm_driver_fatal_error(self, location, message)
458      CLASS (type_nemo_fabm_driver), INTENT(INOUT) :: self
459      CHARACTER(len=*),              INTENT(IN)    :: location, message
460
461      CALL ctl_stop('STOP', TRIM(location)//': '//TRIM(message))
462      STOP
463   END SUBROUTINE
464
465   SUBROUTINE nemo_fabm_driver_log_message(self, message)
466      CLASS (type_nemo_fabm_driver), INTENT(INOUT) :: self
467      CHARACTER(len=*),              INTENT(IN)    :: message
468
469      IF(lwp) WRITE (numout,*) TRIM(message)
470   END SUBROUTINE
471
472   INTEGER FUNCTION fabm_state_index( state_name )
473      !!----------------------------------------------------------------------
474      !!                     ***  fabm_state_index  *** 
475      !!
476      !! ** Purpose :   return index of a given FABM state variable
477      !!
478      !! ** Method  : - loop through state variables until found
479      !!----------------------------------------------------------------------
480     
481      IMPLICIT NONE
482     
483      CHARACTER(LEN=256), INTENT(IN) :: state_name
484     
485      INTEGER                        :: jn
486
487      !!----------------------------------------------------------------------
488     
489      fabm_state_index = -1
490      DO jn=1,jp_fabm
491         IF (TRIM(model%state_variables(jn)%name) == TRIM(state_name)) THEN
492            fabm_state_index = jn
493            EXIT
494         ENDIF
495      END DO
496      IF (fabm_state_index == -1) THEN
497         CALL ctl_warn( 'Could not find '//TRIM(state_name)//' state variable' )
498      ELSE
499         IF (lwp) WRITE(numout,*) 'Index for '//TRIM(state_name)//' is: ', fabm_state_index
500      ENDIF
501   
502   END FUNCTION fabm_state_index
503
504   INTEGER FUNCTION fabm_diag_index( diag_name )
505      !!----------------------------------------------------------------------
506      !!                     ***  fabm_state_index  *** 
507      !!
508      !! ** Purpose :   return index of a given FABM diagnostic variable
509      !!
510      !! ** Method  : - loop through diagnostic variables until found
511      !!----------------------------------------------------------------------
512     
513      IMPLICIT NONE
514     
515      CHARACTER(LEN=256), INTENT(IN) :: diag_name
516     
517      INTEGER                        :: jn
518
519      !!----------------------------------------------------------------------
520     
521      fabm_diag_index = -1
522      DO jn = 1, SIZE(model%diagnostic_variables)
523         IF (TRIM(model%diagnostic_variables(jn)%name) == TRIM(diag_name)) THEN
524            fabm_diag_index = jn
525            EXIT
526         ENDIF
527      END DO
528      IF (fabm_diag_index == -1) THEN
529         CALL ctl_warn( 'Could not find '//TRIM(diag_name)//' diagnostic' )
530      ELSE
531         IF (lwp) WRITE(numout,*) 'Index for '//TRIM(diag_name)//' is: ', fabm_diag_index
532      ENDIF
533   
534   END FUNCTION fabm_diag_index
535
536#else
537   !!----------------------------------------------------------------------
538   !!   Dummy module                                        No FABM model
539   !!----------------------------------------------------------------------
540CONTAINS
541   SUBROUTINE nemo_fabm_configure
542   END SUBROUTINE nemo_fabm_configure
543
544   SUBROUTINE trc_ini_fabm            ! Empty routine
545   END SUBROUTINE trc_ini_fabm
546#endif
547
548   !!======================================================================
549END MODULE trcini_fabm
Note: See TracBrowser for help on using the repository browser.