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 branches/UKMO/r6232_collate_bgc_diagnostics/NEMOGCM/NEMO/TOP_SRC/FABM – NEMO

source: branches/UKMO/r6232_collate_bgc_diagnostics/NEMOGCM/NEMO/TOP_SRC/FABM/trcini_fabm.F90 @ 11137

Last change on this file since 11137 was 11137, checked in by jcastill, 5 years ago

Add missing files

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