SURFEX v8.1
General documentation of Surfex
read_pgd_netcdf.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_pgd_netcdf (UG, U, USS, &
7  HPROGRAM,HSCHEME,HSUBROUTINE,HFILENAME,HFIELD,PFIELD)
8 !#################################################################################
9 !
10 !!**** *READ_PGD_NETCDF* - read data from NETCDF files during PGD (altitude)
11 !!
12 !! PURPOSE
13 !! -------
14 !
15 !!** METHOD
16 !! ------
17 !!
18 !! REFERENCE
19 !! ---------
20 !!
21 !!
22 !! AUTHOR
23 !! ------
24 !! M. Lafaysse
25 !!
26 !! MODIFICATIONS
27 !! -------------
28 !! Original 11/2012
29 !!------------------------------------------------------------------
30 !
31 !
33 USE modd_surf_atm_n, ONLY : surf_atm_t
34 USE modd_sso_n, ONLY : sso_t
35 !
36 USE modi_abor1_sfx
37 
40 ! USE MODD_PGD_GRID, ONLY : NL ! grid dimension length
41 USE modi_pt_by_pt_treatment
42 USE modi_get_luout
43 
44 USE yomhook ,ONLY : lhook, dr_hook
45 USE parkind1 ,ONLY : jprb
46 !
47 USE netcdf
48 !
49 IMPLICIT NONE
50 
51 !
52 !* 0.1 declarations of arguments
53 !
54 !
55 TYPE(surf_atm_grid_t), INTENT(INOUT) :: UG
56 TYPE(surf_atm_t), INTENT(INOUT) :: U
57 TYPE(sso_t), INTENT(INOUT) :: USS
58 !
59  CHARACTER(LEN=6), INTENT(IN) :: HPROGRAM ! Type of program
60  CHARACTER(LEN=6), INTENT(IN) :: HSCHEME ! Scheme treated
61  CHARACTER(LEN=6), INTENT(IN) :: HSUBROUTINE ! Name of the subroutine to call
62  CHARACTER(LEN=28), INTENT(IN) :: HFILENAME ! Name of the field file.
63  CHARACTER(LEN=20), INTENT(IN) :: HFIELD ! name of variable
64 REAL,DIMENSION(:),INTENT(OUT),OPTIONAL :: PFIELD ! output a variable
65 
66 REAL,DIMENSION(:),POINTER :: ZLAT,ZLON
67 REAL,DIMENSION(:),POINTER :: ZLAT2D,ZLON2D
68 REAL,DIMENSION(:),POINTER,SAVE :: ZFIELD ! field to read
69 !
70 REAL, DIMENSION(:), ALLOCATABLE :: ZFIELD0
71 !
72 !* 0.2 declarations of local variables
73 !
74 ! CHARACTER(LEN=28) :: YNCVAR
75 !
76 INTEGER::IERROR !error status
77 INTEGER::ID_FILE ! id of netcdf file
78 INTEGER::INFIELD,INLAT,INLON ! dimension lengths
79 INTEGER::ILUOUT
80 INTEGER::JPOINT !loop counter
81 !
82 REAL(KIND=JPRB) :: ZHOOK_HANDLE
83 !
84 IF (lhook) CALL dr_hook('READ_PGD_NETCDF',0,zhook_handle)
85 !
86  CALL get_luout(hprogram,iluout)
87 !
88 SELECT CASE (trim(hfield))
89  CASE ('ZS','slope')
90  CASE DEFAULT
91  CALL abor1_sfx('READ_PGD_NETCDF: '//trim(hfield)//" initialization not implemented !")
92 END SELECT
93 
94 !------------------------------------------------------------------------------------
95 ! ---------
96 
97 !
98 !* 2. Reading of field
99 ! ----------------
100 
101 ! Open netcdf file
102 ierror=nf90_open(hfilename,nf90_nowrite,id_file)
103  CALL handle_err_cdf(ierror,"can't open file "//trim(hfilename))
104 
105  CALL read_field_netcdf(id_file,'LAT ',zlat,inlat)
106  CALL read_field_netcdf(id_file,'LON ',zlon,inlon)
107  CALL read_field_netcdf(id_file,hfield,zfield,infield)
108 
109 ! Close netcdf file
110 ierror=nf90_close(id_file)
111 
112 IF (PRESENT(pfield)) THEN
113 
114  ALLOCATE(zfield0(u%NDIM_FULL))
115  !
116  DO jpoint=1,infield
117 
118 ! On pourrait faire un controle des coordonnées ?
119 ! IF ((ABS(ZLAT(JPOINT)-????XLAT???)<0.001) .AND. (ABS(ZLON(JPOINT)-????XLON???)<0.001)) THEN
120 
121  zfield0(jpoint)=zfield(jpoint)
122 
123 ! END IF
124  END DO
125  !
126  CALL read_and_send_mpi(zfield0,pfield)
127  !
128  DEALLOCATE(zfield0)
129  !
130 ELSE
131 
132  ALLOCATE(zlat2d(infield))
133  ALLOCATE(zlon2d(infield))
134 
135  IF (inlat*inlon==infield) THEN
136  CALL abor1_sfx('READ_PGD_NETCDF: 1D LAT and LON not implemented')
137  ELSEIF ((inlat==infield) .AND. (infield==inlon)) THEN
138  zlat2d(:)=zlat(:)
139  zlon2d(:)=zlon(:)
140  ELSE
141  CALL abor1_sfx('READ_PGD_NETCDF: problem with dimensions lengths between LAT LON and FIELD')
142  END IF
143 
144  DO jpoint=1,infield
145  !* 5. Call to the adequate subroutine (point by point treatment)
146  ! ----------------------------------------------------------
147  !
148  CALL pt_by_pt_treatment(ug, u, uss, &
149  iluout, (/ zlat2d(jpoint)/) , (/zlon2d(jpoint)/) , (/ zfield(jpoint)/) , &
150  hsubroutine )
151 
152  ENDDO
153 
154  DEALLOCATE(zlat2d)
155  DEALLOCATE(zlon2d)
156 
157 END IF
158 
159 DEALLOCATE(zlat)
160 DEALLOCATE(zlon)
161 
162 DEALLOCATE(zfield)
163 
164 IF (lhook) CALL dr_hook('READ_PGD_NETCDF',1,zhook_handle)
165 !-------------------------------------------------------------------------------------
166 
167 CONTAINS
168 
169 SUBROUTINE read_field_netcdf(ID_FILE,HFIELD,PFIELD,ILENDIM)
171 USE mode_read_cdf, ONLY :handle_err_cdf
172 
173 USE netcdf
174 !
175 IMPLICIT NONE
176 
177 
178 INTEGER,INTENT(IN)::ID_FILE
179  CHARACTER(LEN=20), INTENT(IN) :: HFIELD ! name of variable
180 REAL,DIMENSION(:),POINTER::PFIELD
181 
182 INTEGER::ID_VAR ! Netcdf IDs for file and variable
183 INTEGER::INVARDIMS !number of dimensions of netcdf input variable
184 INTEGER,DIMENSION(:),ALLOCATABLE::IVARDIMSID
185 INTEGER::ILENDIM1,ILENDIM2
186 INTEGER,INTENT(OUT)::ILENDIM
187 INTEGER::IERROR !error status
188 INTEGER::ITYPE
189 
190 ! Look for variable ID for HFIELD
191 ierror=nf90_inq_varid(id_file,trim(hfield),id_var)
192  CALL handle_err_cdf(ierror,"can't find variable "//trim(hfield))
193 
194 ! Number of dimensions
195 ierror=nf90_inquire_variable(id_file,id_var,ndims=invardims)
196 if (ierror/=nf90_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions number")
197 
198 ! Id of dimensions
199 ALLOCATE(ivardimsid(invardims))
200 
201 ierror=nf90_inquire_variable(id_file,id_var,dimids=ivardimsid)
202 if (ierror/=nf90_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions ids")
203 
204 
205 SELECT CASE (invardims)
206  CASE (1)
207  ! Check dimension length
208  ierror=nf90_inquire_dimension(id_file,ivardimsid(1),len=ilendim)
209  if (ierror/=nf90_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
210 
211  CASE (2)
212  ierror=nf90_inquire_dimension(id_file,ivardimsid(1),len=ilendim1)
213  if (ierror/=nf90_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
214  ierror=nf90_inquire_dimension(id_file,ivardimsid(2),len=ilendim2)
215  if (ierror/=nf90_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
216 
217  ilendim=ilendim1*ilendim2
218 
219  CASE DEFAULT
220  CALL abor1_sfx('READ_PGD_NETCDF: incorrect number of dimensions for variable '//trim(hfield))
221 
222 END SELECT
223 
224 DEALLOCATE(ivardimsid)
225 
226 ! IF(ILENDIM/=NL) CALL ABOR1_SFX('READ_PGD_NETCDF: incorrect number of points &
227 ! & in netcdf file for variable '//TRIM(HFIELD))
228 
229 ALLOCATE(pfield(ilendim))
230 
231 ierror=nf90_inquire_variable(id_file,id_var,xtype=itype)
232 IF (itype/=nf90_double) THEN
233  CALL abor1_sfx('READ_PGD_NETCDF: incorrect type for variable '//trim(hfield))
234 END IF
235 
236 ! Read 1D variable
237 ierror=nf90_get_var(id_file,id_var,pfield)
238 
239  CALL handle_err_cdf(ierror,"can't read variable "//trim(hfield))
240 
241 END SUBROUTINE read_field_netcdf
242 
243 
244 END SUBROUTINE read_pgd_netcdf
static const char * trim(const char *name, int *n)
Definition: drhook.c:2383
subroutine read_pgd_netcdf(UG, U, USS, HPROGRAM, HSCHEME, HSUBROUTINE, HFILENAME, HFIELD, PFIELD)
subroutine handle_err_cdf(status, line)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
integer, parameter jprb
Definition: parkind1.F90:32
subroutine pt_by_pt_treatment(UG, U, USS, KLUOUT, PLAT, PLON, PVALUE, HSUBROUTINE
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:7
logical lhook
Definition: yomhook.F90:15
subroutine read_field_netcdf(ID_FILE, HFIELD, PFIELD, ILENDIM)