SURFEX v8.1
General documentation of Surfex
read_surf_field2d.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 ! #########
6  SUBROUTINE read_surf_field2d( HPROGRAM,PFIELD2D,HFIELDNAME,HCOMMENT,HDIR,KRESP)
7 ! #####################################
8 !
9 !!**** *READ_SURF_FIELD2D* - reads surfex field in input file using READ_SURF,
10 !! patch by patch if needed in MESONH
11 !! with Z-parallel IO in MESO-NH, we force surfex to write 2D fields
12 !! because Z-parallel IO are not supported for 2D SURFEX fields.
13 !!
14 !!
15 !! PURPOSE
16 !! -------
17 !! reads surfex field in output file using WRITE_SURF,
18 !! patch by patch if needed in MESONH
19 !! and NB_PROCIO_R > 1
20 !! examples of HFIELDNAME : 'TG', 'soil depth from ecoclimap'
21 !! with Z-parallel IO in MESO-NH, we force surfex to write 2D fields
22 !! because Z-parallel IO are not supported for 2D SURFEX fields.
23 !!
24 !!** METHOD
25 !! ------
26 !!
27 !! EXTERNAL
28 !! --------
29 !!
30 !!
31 !! IMPLICIT ARGUMENTS
32 !! ------------------
33 !!
34 !! REFERENCE
35 !! ---------
36 !!
37 !!
38 !! AUTHOR
39 !! ------
40 !! M.Moge *LA - UPS*
41 !!
42 !! MODIFICATIONS
43 !! -------------
44 !! Original 08/01/2016
45 !! J.Escobar : 20/04/2016 : Pb IOZ/NETCDF , add optional KRESP error code
46 !!
47 !-------------------------------------------------------------------------------
48 !
49 !* 0. DECLARATIONS
50 ! ------------
51 !
52 USE modd_surf_par, ONLY : nundef
53 !
55 #ifdef SFX_MNH
56 USE modi_get_nb_procio_read_mnh
57 #endif
58 !
59 !
60 USE yomhook ,ONLY : lhook, dr_hook
61 USE parkind1 ,ONLY : jprb
62 !
63 IMPLICIT NONE
64 !
65 !* 0.1 Declarations of arguments
66 ! -------------------------
67 !
68  CHARACTER(LEN=6), INTENT(IN) :: HPROGRAM ! calling program
69 REAL, DIMENSION(:,:), INTENT(INOUT) :: PFIELD2D ! 2D field to be read
70  CHARACTER(LEN=12), INTENT(IN) :: HFIELDNAME ! name of the field PFIELD2D. Example : 'X_Y_TG'
71  CHARACTER(LEN=*), OPTIONAL, INTENT(OUT) :: HCOMMENT !comment string
72  CHARACTER(LEN=1),OPTIONAL, INTENT(IN) :: HDIR ! type of field :
73 ! ! 'H' : field with
74 ! ! horizontal spatial dim.
75 ! ! '-' : no horizontal dim.
76 INTEGER,OPTIONAL, INTENT(OUT) :: KRESP
77 !
78 !* 0.2 Declarations of local variables
79 ! -------------------------------
80 !
81 REAL, DIMENSION(SIZE(PFIELD2D,1)) :: ZWORK
82 INTEGER :: IRESP ! IRESP : return-code if a problem appears
83 INTEGER :: IPATCH ! number of patches in PFIELD2D
84  CHARACTER(LEN=100):: YCOMMENT ! Comment string
85  CHARACTER(LEN=16) :: YRECFM ! Name of the article to be read
86  CHARACTER(LEN=4 ) :: YPATCH ! current patch
87 INTEGER :: INB_PROCIO ! number of processes used for Z-parallel IO with MESO-NH
88 !
89  CHARACTER(LEN=1) :: YDIR
90 INTEGER :: JPATCH ! loop counter on patches
91 REAL(KIND=JPRB) :: ZHOOK_HANDLE
92 !
93 !------------------------------------------------------------------------------
94 !
95 IF (PRESENT(kresp)) kresp = -1
96 !
97 IF (lhook) CALL dr_hook('READ_SURF_FIELD2D',0,zhook_handle)
98 !
99 ydir = 'H'
100 IF (PRESENT(hdir)) ydir = hdir
101 !
102 ipatch = SIZE( pfield2d, 2 )
103 !
104 inb_procio = 1
105 #ifdef SFX_MNH
106 IF (hprogram=='MESONH') THEN
107  CALL get_nb_procio_read_mnh( inb_procio, iresp )
108 ENDIF
109 #endif
110 !
111 IF ( inb_procio > 1 ) THEN
112 !
113  DO jpatch=1,ipatch
114  yrecfm=adjustl(hfieldname(:len_trim(hfieldname)))
115  WRITE(ypatch,'(I4.4)') jpatch
116  IF ( ipatch > 1 ) THEN
117  yrecfm=adjustl(yrecfm(:len_trim(yrecfm)))//ypatch
118  ENDIF
119  CALL read_surf(hprogram,yrecfm,pfield2d(:,jpatch),iresp,hcomment=ycomment,hdir=ydir)
120  ENDDO
121 !
122 ELSE
123 !
124  yrecfm=adjustl(hfieldname(:len_trim(hfieldname)))
125  CALL read_surf(hprogram,yrecfm,pfield2d(:,:),iresp,hcomment=ycomment,hdir=ydir)
126 !
127 ENDIF
128 !
129 IF (PRESENT(hdir)) hcomment = ycomment
130 !
131 IF (lhook) CALL dr_hook('READ_SURF_FIELD2D',1,zhook_handle)
132 !
133 IF (PRESENT(kresp)) kresp = iresp
134 !-------------------------------------------------------------------------------
135 !
136  END SUBROUTINE read_surf_field2d
integer, parameter jprb
Definition: parkind1.F90:32
integer, parameter nundef
logical lhook
Definition: yomhook.F90:15
subroutine read_surf_field2d(HPROGRAM, PFIELD2D, HFIELDNAME, HCOMMEN