SURFEX v8.1
General documentation of Surfex
interpol_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 interpol_field2d (UG, U, &
7  HPROGRAM,KLUOUT,KCODE,PFIELD,HFIELD,PDEF,KNPTS)
8 ! ################################################
9 !
10 !!**** *INTERPOL_FIELD* initializes coordinate system for spline interpolation
11 !!
12 !! PURPOSE
13 !! -------
14 !!
15 !! The points are all on only one grid (defined with the coordinates
16 !! of all the points). The code to apply for each point is:
17 !!
18 !! KCODE>0 : data point (with field valid for interpolation)
19 !! KCODE=-1: point to ignore
20 !! KCODE=0 : point to interpolate
21 !!
22 !!
23 !!
24 !! AUTHOR
25 !! ------
26 !!
27 !! V. Masson Meteo-France
28 !!
29 !! MODIFICATION
30 !! ------------
31 !!
32 !! Original 01/2004
33 !! Modification
34 !! A. Alias 07/2013 add MODI_ABOR1_SFX
35 !----------------------------------------------------------------------------
36 !
37 !* 0. DECLARATION
38 ! -----------
39 !
40 USE modd_surfex_mpi, ONLY : nrank, npio
41 !
43 USE modd_surf_atm_n, ONLY : surf_atm_t
44 !
45 USE modd_surf_par, ONLY : xundef
46 !
47 USE modi_get_grid_coord
48 USE modi_interpol_npts
49 USE modi_sum_on_all_procs
50 USE modi_abor1_sfx
51 USE modi_get_interp_halo
52 !
53 USE yomhook ,ONLY : lhook, dr_hook
54 USE parkind1 ,ONLY : jprb
55 !
56 IMPLICIT NONE
57 !
58 !* 0.1 Declaration of arguments
59 ! ------------------------
60 !
61 !
62 TYPE(surf_atm_grid_t), INTENT(INOUT) :: UG
63 TYPE(surf_atm_t), INTENT(INOUT) :: U
64 !
65  CHARACTER(LEN=6), INTENT(IN) :: HPROGRAM ! host program
66 INTEGER, INTENT(IN) :: KLUOUT ! output listing
67 INTEGER,DIMENSION(:), INTENT(INOUT) :: KCODE ! code for each point
68  ! >0 point used for interpolation
69  ! 0 point to interpolate
70  ! -1 point not used
71  ! -2 point not used
72 ! ! -3 if spline is no computed
73 ! ! for this point
74 REAL, DIMENSION(:,:),INTENT(INOUT) :: PFIELD ! pgd field on grid mesh.
75  CHARACTER(LEN=*), INTENT(IN) :: HFIELD ! name of the field for prints
76 REAL,DIMENSION(:),OPTIONAL, INTENT(IN):: PDEF ! default value if not enough data
77 INTEGER, OPTIONAL, INTENT(IN) :: KNPTS ! number of points to interpolate with
78 
79 !
80 !* 0.2 Declaration of local variables
81 ! ------------------------------
82 !
83 REAL, DIMENSION(U%NDIM_FULL) :: ZX ! coordinate used for
84 REAL, DIMENSION(U%NDIM_FULL) :: ZY ! splines interpolation
85 REAL, DIMENSION(SIZE(PFIELD,2)):: ZDEF ! default value for field
86 INTEGER :: INPTS ! number of points to interpolate with
87 INTEGER :: IHALO, INEAR_NBR
88 !
89 INTEGER :: JLOOP ! loop counter
90 !
91 INTEGER :: IERR0
92 INTEGER :: IERR1 ! number of points interpolated
93 INTEGER :: IERR2 ! number of points not interpolated in the end
94 !
95 REAL(KIND=JPRB) :: ZHOOK_HANDLE
96 !-------------------------------------------------------------------------------
97 !
98 IF (lhook) CALL dr_hook('INTERPOL_FIELD:INTERPOL_FIELD2D',0,zhook_handle)
99 !
100 inpts = 3
101 IF (PRESENT(knpts)) inpts = knpts
102 !
103 zdef = xundef
104 IF (PRESENT(pdef)) zdef = pdef
105 !
106 !* 2. Miscellaneous Initializations
107 ! -----------------------------
108 !
109  CALL get_grid_coord(ug%G%CGRID, ug%G%NGRID_PAR, ug%G%XGRID_PAR, u%NSIZE_FULL, &
110  kluout,kl=u%NDIM_FULL,hgrid=ug%G%CGRID,pgrid_par=ug%XGRID_FULL_PAR,&
111  px=zx,py=zy)
112 !
113 !-------------------------------------------------------------------------------
114 !
115 !* 5. Interpolation with 3 nearest points
116 ! -----------------------------------
117 !
118 ierr0 = sum_on_all_procs(hprogram,ug%G%CGRID,kcode(:)==0)
119 !
120  CALL get_interp_halo(hprogram,ug%G%CGRID,ihalo)
121 !
122 IF (ihalo/=0) THEN
123  inear_nbr = (2*ihalo+1)**2
124 ELSE
125  inear_nbr = u%NDIM_FULL
126 ENDIF
127 !
128  CALL interpol_npts(ug, u, &
129  hprogram,kluout,inpts,kcode,zx,zy,pfield,inear_nbr)
130 !
131 !-------------------------------------------------------------------------------
132 !
133 !* 6. Final check
134 ! -----------
135 !
136 ierr1 = sum_on_all_procs(hprogram,ug%G%CGRID,kcode(:)==0)
137 ierr2 = sum_on_all_procs(hprogram,ug%G%CGRID,kcode(:)==-4)
138 !
139 IF (nrank==npio) THEN
140  !
141  IF (ierr1>0 .OR. ierr2>0) THEN
142  !
143  WRITE(kluout,*) ' '
144  WRITE(kluout,*) ' Interpolation of field : ',hfield
145  WRITE(kluout,*) ' ----------------------'
146  WRITE(kluout,*) ' '
147  WRITE(kluout,*) ' Number of points interpolated with ',inpts,' nearest points: ', &
148  ierr1
149  !
150  !
151  IF (ierr2>0) THEN
152  WRITE(kluout,*) ' Number of points that could not be interpolated : ', &
153  ierr2
154  !if all points were scanned or if no point could be interpolated
155  IF (PRESENT(pdef) .AND. (inear_nbr>=u%NDIM_FULL .OR. ierr2==ierr0)) THEN
156  DO jloop=1,SIZE(pfield,2)
157  WRITE(kluout,*) ' For these points, the default value (',zdef(jloop),') is set.'
158  ENDDO
159  ELSE
160  WRITE(kluout,*) ' Please provide data with better resolution'
161  WRITE(kluout,*) ' Or define a higher halo value '
162  END IF
163  END IF
164  !
165  END IF
166  !
167 END IF
168 !
169 IF (ierr2>0) THEN
170  !
171  IF (.NOT.PRESENT(pdef) .OR. (inear_nbr<u%NDIM_FULL .AND. ierr2/=ierr0)) &
172  CALL abor1_sfx('Some points lack data and are too far away from other points. &
173  Please define a higher halo value in NAM_IO_OFFLINE.')
174  !
175 ENDIF
176 !
177 IF (count(kcode(:)==-4)>0) THEN
178  !
179  DO jloop=1,SIZE(pfield,2)
180  IF (zdef(jloop)/=xundef) THEN
181  WHERE(kcode(:)==-4)
182  pfield(:,jloop)=zdef(jloop)
183  END WHERE
184  ENDIF
185  END DO
186  !
187 END IF
188 !
189 IF (lhook) CALL dr_hook('INTERPOL_FIELD:INTERPOL_FIELD2D',1,zhook_handle)
190 !-------------------------------------------------------------------------------
191 !
192 END SUBROUTINE interpol_field2d
subroutine interpol_npts(UG, U, HPROGRAM, KLUOUT, KNPTS, KCODE, PX, PY
integer function sum_on_all_procs(HPROGRAM, HGRID, OIN, HNAME)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
real, parameter xundef
integer, parameter jprb
Definition: parkind1.F90:32
subroutine get_grid_coord(HGRID_IN, KGRID_PAR_IN, PGRID_PAR_IN, K
logical lhook
Definition: yomhook.F90:15
subroutine interpol_field2d(UG, U, HPROGRAM, KLUOUT, KCODE, PFIELD, HFIELD, P
subroutine get_interp_halo(HPROGRAM, HGRID, KHALO)
static int count
Definition: memory_hook.c:21