NCEPLIBS-ip  4.1.0
ipolates.F90
Go to the documentation of this file.
1 
4 
17  use ip_grid_mod
18  implicit none
19 
20  private
22 
23  interface ipolates
24  module procedure ipolates_grib1
25  module procedure ipolates_grib1_single_field
26  module procedure ipolates_grib2
27  module procedure ipolates_grib2_single_field
28  end interface ipolates
29 
30 contains
31 
63  subroutine ipolates_grid(ip, ipopt, grid_in, grid_out, mi, mo, km,&
64  & ibi, li, gi, no, rlat, rlon, ibo, lo, go, iret)
65  class(ip_grid), intent(in) :: grid_in, grid_out
66  INTEGER, INTENT(IN ) :: IP, IPOPT(20), KM, MI, MO
67  INTEGER, INTENT(IN ) :: IBI(KM)
68  INTEGER, INTENT(INOUT) :: NO
69  INTEGER, INTENT( OUT) :: IRET, IBO(KM)
70  !
71  LOGICAL*1, INTENT(IN ) :: LI(MI,KM)
72  LOGICAL*1, INTENT( OUT) :: LO(MO,KM)
73  !
74  REAL, INTENT(IN ) :: GI(MI,KM)
75  REAL, INTENT(INOUT) :: RLAT(MO),RLON(MO)
76  REAL, INTENT( OUT) :: GO(MO,KM)
77  !
78 
79  select case(ip)
80  case(bilinear_interp_id)
81  CALL interpolate_bilinear(ipopt,grid_in,grid_out,mi,mo,km,ibi&
82  &,li,gi,no,rlat,rlon,ibo,lo,go,iret)
83  case(bicubic_interp_id)
84  CALL interpolate_bicubic(ipopt,grid_in,grid_out,mi,mo,km,ibi&
85  &,li,gi,no,rlat,rlon,ibo,lo,go,iret)
86  case(neighbor_interp_id)
87  CALL interpolate_neighbor(ipopt,grid_in,grid_out,mi,mo,km,ibi&
88  &,li,gi,no,rlat,rlon,ibo,lo,go,iret)
89  case(budget_interp_id)
90  CALL interpolate_budget(ipopt,grid_in,grid_out,mi,mo,km,ibi,li&
91  &,gi,no,rlat,rlon,ibo,lo,go,iret)
92  case(spectral_interp_id)
93  CALL interpolate_spectral(ipopt,grid_in,grid_out,mi,mo,km,ibi&
94  &,gi,no,rlat,rlon,ibo,lo,go,iret)
96  CALL interpolate_neighbor_budget(ipopt,grid_in,grid_out,mi,mo&
97  &,km,ibi,li,gi,no,rlat,rlon,ibo,lo,go,iret)
98  case default
99  ! IF(KGDSO(1).GE.0) NO=0
100  ! DO K=1,KM
101  ! IBO(K)=1
102  ! DO N=1,NO
103  ! LO(N,K)=.FALSE.
104  ! GO(N,K)=0.
105  ! ENDDO
106  ! ENDDO
107  iret=1
108  print *, "Unrecognized interp option: ", ip
109  error stop
110  end select
111 
112  end subroutine ipolates_grid
113 
158  subroutine ipolates_grib1_single_field(ip,ipopt,kgdsi,kgdso,mi,mo,km,ibi,li,gi, &
159  no,rlat,rlon,ibo,lo,go,iret) bind(c)
160  !
161  USE iso_c_binding, ONLY: c_int, c_float, c_double, c_bool
162  INTEGER(C_INT), INTENT(IN ) :: IP, IPOPT(20), KM, MI, MO
163  INTEGER(C_INT), INTENT(IN ) :: IBI, KGDSI(200), KGDSO(200)
164  INTEGER(C_INT), INTENT(INOUT) :: NO
165  INTEGER(C_INT), INTENT( OUT) :: IRET, IBO
166  !
167  LOGICAL(C_BOOL), INTENT(IN ) :: LI(MI)
168  LOGICAL(C_BOOL), INTENT( OUT) :: LO(MO)
169  !
170 #if (LSIZE==D)
171  REAL(C_DOUBLE), INTENT(IN ) :: GI(MI)
172  REAL(C_DOUBLE), INTENT(INOUT) :: RLAT(MO),RLON(MO)
173  REAL(C_DOUBLE), INTENT( OUT) :: GO(MO)
174 #elif (LSIZE==4)
175  REAL(C_FLOAT), INTENT(IN ) :: GI(MI)
176  REAL(C_FLOAT), INTENT(INOUT) :: RLAT(MO),RLON(MO)
177  REAL(C_FLOAT), INTENT( OUT) :: GO(MO)
178 #endif
179  !
180 
181  type(grib1_descriptor) :: desc_in, desc_out
182  class(ip_grid), allocatable :: grid_in, grid_out
183  integer :: ibo_array(1)
184 
185  desc_in = init_descriptor(kgdsi)
186  desc_out = init_descriptor(kgdso)
187 
188  call init_grid(grid_in, desc_in)
189  call init_grid(grid_out, desc_out)
190 
191  ! Can't pass expression (e.g. [ibo]) to intent(out) argument.
192  ! Initialize placeholder array of size 1 to make rank match.
193  ibo_array(1) = ibo
194 
195  call ipolates_grid(ip, ipopt, grid_in, grid_out, mi, mo, km, [ibi], li, gi, no, rlat, rlon, ibo_array, lo, go, iret)
196 
197  ibo = ibo_array(1)
198 
199  END SUBROUTINE ipolates_grib1_single_field
200 
286  subroutine ipolates_grib1(ip,ipopt,kgdsi,kgdso,mi,mo,km,ibi,li,gi, &
287  no,rlat,rlon,ibo,lo,go,iret) bind(c)
288  !
289  USE iso_c_binding, ONLY: c_int, c_float, c_double, c_bool
290  INTEGER(C_INT), INTENT(IN ) :: IP, IPOPT(20), KM, MI, MO
291  INTEGER(C_INT), INTENT(IN ) :: IBI(KM), KGDSI(200), KGDSO(200)
292  INTEGER(C_INT), INTENT(INOUT) :: NO
293  INTEGER(C_INT), INTENT( OUT) :: IRET, IBO(KM)
294  !
295  LOGICAL(C_BOOL), INTENT(IN ) :: LI(MI,KM)
296  LOGICAL(C_BOOL), INTENT( OUT) :: LO(MO,KM)
297  !
298 #if (LSIZE==D)
299  REAL(C_DOUBLE), INTENT(IN ) :: GI(MI,KM)
300  REAL(C_DOUBLE), INTENT(INOUT) :: RLAT(MO),RLON(MO)
301  REAL(C_DOUBLE), INTENT( OUT) :: GO(MO,KM)
302 #elif (LSIZE==4)
303  REAL(C_FLOAT), INTENT(IN ) :: GI(MI,KM)
304  REAL(C_FLOAT), INTENT(INOUT) :: RLAT(MO),RLON(MO)
305  REAL(C_FLOAT), INTENT( OUT) :: GO(MO,KM)
306 #endif
307  !
308 
309  type(grib1_descriptor) :: desc_in, desc_out
310  class(ip_grid), allocatable :: grid_in, grid_out
311 
312  desc_in = init_descriptor(kgdsi)
313  desc_out = init_descriptor(kgdso)
314 
315  call init_grid(grid_in, desc_in)
316  call init_grid(grid_out, desc_out)
317 
318  call ipolates_grid(ip, ipopt, grid_in, grid_out, mi, mo, km, ibi, li, gi, no, rlat, rlon, ibo, lo, go, iret)
319 
320  END SUBROUTINE ipolates_grib1
321 
573  SUBROUTINE ipolates_grib2(IP,IPOPT,IGDTNUMI,IGDTMPLI,IGDTLENI, &
574  IGDTNUMO,IGDTMPLO,IGDTLENO, &
575  MI,MO,KM,IBI,LI,GI, &
576  NO,RLAT,RLON,IBO,LO,GO,IRET) bind(C)
577  USE iso_c_binding, ONLY: c_int, c_float, c_double, c_bool
578  INTEGER(C_INT), INTENT(IN ) :: IP, IPOPT(20), KM, MI, MO
579  INTEGER(C_INT), INTENT(IN ) :: IBI(KM)
580  INTEGER(C_INT), INTENT(IN ) :: IGDTNUMI, IGDTLENI
581  INTEGER(C_INT), INTENT(IN ) :: IGDTMPLI(IGDTLENI)
582  INTEGER(C_INT), INTENT(IN ) :: IGDTNUMO, IGDTLENO
583  INTEGER(C_INT), INTENT(IN ) :: IGDTMPLO(IGDTLENO)
584  INTEGER(C_INT), INTENT( OUT) :: NO
585  INTEGER(C_INT), INTENT( OUT) :: IRET, IBO(KM)
586  !
587  LOGICAL(C_BOOL), INTENT(IN ) :: LI(MI,KM)
588  LOGICAL(C_BOOL), INTENT( OUT) :: LO(MO,KM)
589  !
590 #if (LSIZE==D)
591  REAL(C_DOUBLE), INTENT(IN ) :: GI(MI,KM)
592  REAL(C_DOUBLE), INTENT(INOUT) :: RLAT(MO),RLON(MO)
593  REAL(C_DOUBLE), INTENT( OUT) :: GO(MO,KM)
594 #elif (LSIZE==4)
595  REAL(C_FLOAT), INTENT(IN ) :: GI(MI,KM)
596  REAL(C_FLOAT), INTENT(INOUT) :: RLAT(MO),RLON(MO)
597  REAL(C_FLOAT), INTENT( OUT) :: GO(MO,KM)
598 #endif
599 
600  type(grib2_descriptor) :: desc_in, desc_out
601  class(ip_grid), allocatable :: grid_in, grid_out
602 
603  desc_in = init_descriptor(igdtnumi, igdtleni, igdtmpli)
604  desc_out = init_descriptor(igdtnumo, igdtleno, igdtmplo)
605 
606  call init_grid(grid_in, desc_in)
607  call init_grid(grid_out, desc_out)
608 
609  CALL ipolates_grid(ip,ipopt,grid_in,grid_out,mi,mo,km,ibi,li,gi,no,rlat,rlon,ibo,lo,go,iret)
610 
611  END SUBROUTINE ipolates_grib2
612 
783  SUBROUTINE ipolates_grib2_single_field(IP,IPOPT,IGDTNUMI,IGDTMPLI,IGDTLENI, &
784  IGDTNUMO,IGDTMPLO,IGDTLENO, &
785  MI,MO,KM,IBI,LI,GI, &
786  NO,RLAT,RLON,IBO,LO,GO,IRET) bind(C)
787  USE iso_c_binding, ONLY: c_int, c_float, c_double, c_bool
788  INTEGER(C_INT), INTENT(IN ) :: IP, IPOPT(20), KM, MI, MO
789  INTEGER(C_INT), INTENT(IN ) :: IBI
790  INTEGER(C_INT), INTENT(IN ) :: IGDTNUMI, IGDTLENI
791  INTEGER(C_INT), INTENT(IN ) :: IGDTMPLI(IGDTLENI)
792  INTEGER(C_INT), INTENT(IN ) :: IGDTNUMO, IGDTLENO
793  INTEGER(C_INT), INTENT(IN ) :: IGDTMPLO(IGDTLENO)
794  INTEGER(C_INT), INTENT( OUT) :: NO
795  INTEGER(C_INT), INTENT( OUT) :: IRET, IBO
796  !
797  LOGICAL(C_BOOL), INTENT(IN ) :: LI(MI)
798  LOGICAL(C_BOOL), INTENT( OUT) :: LO(MO)
799  !
800 #if (LSIZE==D)
801  REAL(C_DOUBLE), INTENT(IN ) :: GI(MI)
802  REAL(C_DOUBLE), INTENT(INOUT) :: RLAT(MO),RLON(MO)
803  REAL(C_DOUBLE), INTENT( OUT) :: GO(MO)
804 #elif (LSIZE==4)
805  REAL(C_FLOAT), INTENT(IN ) :: GI(MI)
806  REAL(C_FLOAT), INTENT(INOUT) :: RLAT(MO),RLON(MO)
807  REAL(C_FLOAT), INTENT( OUT) :: GO(MO)
808 #endif
809 
810  type(grib2_descriptor) :: desc_in, desc_out
811  class(ip_grid), allocatable :: grid_in, grid_out
812  integer :: ibo_array(1)
813 
814  desc_in = init_descriptor(igdtnumi, igdtleni, igdtmpli)
815  desc_out = init_descriptor(igdtnumo, igdtleno, igdtmplo)
816 
817  call init_grid(grid_in, desc_in)
818  call init_grid(grid_out, desc_out)
819 
820  ! Can't pass expression (e.g. [ibo]) to intent(out) argument.
821  ! Initialize placeholder array of size 1 to make rank match.
822  ibo_array(1) = ibo
823 
824  call ipolates_grid(ip,ipopt,grid_in,grid_out,mi,mo,km,[ibi],li,gi,no,rlat,rlon,ibo_array,lo,go,iret)
825 
826  ibo = ibo_array(1)
827 
828  END SUBROUTINE ipolates_grib2_single_field
829 
830 end module ipolates_mod
831 
Users derived type grid descriptor objects to abstract away the raw GRIB1 and GRIB2 grid definitions.
Routines for creating an ip_grid given a Grib descriptor.
Abstract ip_grid type.
Definition: ip_grid_mod.F90:10
Top-level module to export interpolation routines and constants.
integer, parameter, public neighbor_interp_id
integer, parameter, public bilinear_interp_id
integer, parameter, public budget_interp_id
integer, parameter, public spectral_interp_id
integer, parameter, public bicubic_interp_id
integer, parameter, public neighbor_budget_interp_id
Top-level driver for scalar interpolation interpolation routine ipolates().
Definition: ipolates.F90:12
subroutine ipolates_grid(ip, ipopt, grid_in, grid_out, mi, mo, km, ibi, li, gi, no, rlat, rlon, ibo, lo, go, iret)
Interpolates scalar fields between grids given ip_grid objects.
Definition: ipolates.F90:65
subroutine, public ipolates_grib2_single_field(IP, IPOPT, IGDTNUMI, IGDTMPLI, IGDTLENI, IGDTNUMO, IGDTMPLO, IGDTLENO, MI, MO, KM, IBI, LI, GI, NO, RLAT, RLON, IBO, LO, GO, IRET)
Special case of ipolates_grib2 when interpolating a single field.
Definition: ipolates.F90:787
subroutine, public ipolates_grib2(IP, IPOPT, IGDTNUMI, IGDTMPLI, IGDTLENI, IGDTNUMO, IGDTMPLO, IGDTLENO, MI, MO, KM, IBI, LI, GI, NO, RLAT, RLON, IBO, LO, GO, IRET)
This subprogram interpolates scalar field from any grid to any grid given a grib2 descriptor.
Definition: ipolates.F90:577
subroutine, public ipolates_grib1(ip, ipopt, kgdsi, kgdso, mi, mo, km, ibi, li, gi, no, rlat, rlon, ibo, lo, go, iret)
This subprogram interpolates scalar field from any grid to any grid given a grib1 Grid Descriptor Sec...
Definition: ipolates.F90:288
subroutine, public ipolates_grib1_single_field(ip, ipopt, kgdsi, kgdso, mi, mo, km, ibi, li, gi, no, rlat, rlon, ibo, lo, go, iret)
Special case of ipolates_grib1 when interpolating a single field.
Definition: ipolates.F90:160
Descriptor representing a grib1 grib descriptor section (GDS) with an integer array.
Grib-2 descriptor containing a grib2 GDT represented by an integer array.
Abstract grid that holds fields and methods common to all grids.
Definition: ip_grid_mod.F90:52