FMS 2025.01-dev
Flexible Modeling System
Loading...
Searching...
No Matches
horiz_interp_bilinear.F90
1!***********************************************************************
2!* GNU Lesser General Public License
3!*
4!* This file is part of the GFDL Flexible Modeling System (FMS).
5!*
6!* FMS is free software: you can redistribute it and/or modify it under
7!* the terms of the GNU Lesser General Public License as published by
8!* the Free Software Foundation, either version 3 of the License, or (at
9!* your option) any later version.
10!*
11!* FMS is distributed in the hope that it will be useful, but WITHOUT
12!* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13!* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14!* for more details.
15!*
16!* You should have received a copy of the GNU Lesser General Public
17!* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
18!***********************************************************************
19!> @defgroup horiz_interp_bilinear_mod horiz_interp_bilinear_mod
20!> @ingroup horiz_interp
21!> @brief Performs spatial interpolation between grids using bilinear interpolation
22!!
23!> @author Zhi Liang <Zhi.Liang@noaa.gov>
24!> This module can interpolate data from regular rectangular grid
25!! to rectangular/tripolar grid. The interpolation scheme is bilinear interpolation.
26!! There is an optional mask field for missing input data.
27!! An optional output mask field may be used in conjunction with
28!! the input mask to show where output data exists.
29
30module horiz_interp_bilinear_mod
31
32 use mpp_mod, only: mpp_error, fatal, stdout, mpp_pe, mpp_root_pe
33 use fms_mod, only: write_version_number
34 use constants_mod, only: pi
35 use horiz_interp_type_mod, only: horiz_interp_type, stats, bilinear
36 use platform_mod, only: r4_kind, r8_kind
37 use axis_utils2_mod, only: nearest_index
38 use fms2_io_mod, only: open_file, close_file, read_data, fmsnetcdffile_t, get_dimension_size
39 use fms_string_utils_mod, only: string
40
41 implicit none
42 private
43
44
47
48 !> Creates a @ref horiz_interp_type for bilinear interpolation.
49 !> @ingroup horiz_interp_bilinear_mod
51 module procedure horiz_interp_bilinear_new_1d_r4
52 module procedure horiz_interp_bilinear_new_1d_r8
53 module procedure horiz_interp_bilinear_new_2d_r4
54 module procedure horiz_interp_bilinear_new_2d_r8
55 end interface
56
57 !> Subroutines for reading in weight files and using that to fill in the horiz_interp type instead
58 !! calculating it
59 !> @ingroup horiz_interp_bilinear_mod
61 module procedure horiz_interp_read_weights_bilinear_r4
62 module procedure horiz_interp_read_weights_bilinear_r8
63 end interface
64
66 module procedure horiz_interp_bilinear_r4
67 module procedure horiz_interp_bilinear_r8
68 end interface
69
70!> @addtogroup horiz_interp_bilinear_mod
71!> @{
72
73 real(r8_kind), parameter :: epsln=1.e-10_r8_kind
74 integer, parameter :: DUMMY = -999
75
76!! Private helper routines, interfaces for mixed real precision support
77 interface intersect
78 module procedure intersect_r4
79 module procedure intersect_r8
80 end interface
81
82 !-----------------------------------------------------------------------
83! Include variable "version" to be written to log file.
84#include<file_version.h>
85 logical :: module_is_initialized = .false.
86
87contains
88
89 !> Initialize this module and writes version number to logfile.
91
92 if(module_is_initialized) return
93 call write_version_number("HORIZ_INTERP_BILINEAR_MOD", version)
94 module_is_initialized = .true.
95
96 end subroutine horiz_interp_bilinear_init
97
98 !> @brief Deallocates memory used by "horiz_interp_type" variables.
99 !!
100 !> Must be called before reinitializing with horiz_interp_bilinear_new.
101 subroutine horiz_interp_bilinear_del( Interp )
102
103 type (horiz_interp_type), intent(inout) :: interp!< A derived-type variable returned by previous
104 !! call to horiz_interp_bilinear_new. The input variable must
105 !! have allocated arrays. The returned variable will contain
106 !! deallocated arrays
107
108 if( interp%horizInterpReals4_type%is_allocated) then
109 if(allocated(interp%horizInterpReals4_type%wti)) deallocate(interp%horizInterpReals4_type%wti)
110 if(allocated(interp%horizInterpReals4_type%wtj)) deallocate(interp%horizInterpReals4_type%wtj)
111 else if (interp%horizInterpReals8_type%is_allocated) then
112 if(allocated(interp%horizInterpReals8_type%wti)) deallocate(interp%horizInterpReals8_type%wti)
113 if(allocated(interp%horizInterpReals8_type%wtj)) deallocate(interp%horizInterpReals8_type%wtj)
114 endif
115 if(allocated(interp%i_lon)) deallocate(interp%i_lon)
116 if(allocated(interp%j_lat)) deallocate(interp%j_lat)
117
118 interp%horizInterpReals4_type%is_allocated = .false.
119 interp%horizInterpReals8_type%is_allocated = .false.
120
121 end subroutine horiz_interp_bilinear_del
122
123#include "horiz_interp_bilinear_r4.fh"
124#include "horiz_interp_bilinear_r8.fh"
125
126end module horiz_interp_bilinear_mod
127!> @}
128! close documentation grouping
Close a netcdf or domain file opened with open_file or open_virtual_file.
Definition fms2_io.F90:166
Opens a given netcdf or domain file.
Definition fms2_io.F90:122
Read data from a defined field in a file.
Definition fms2_io.F90:292
character(:) function, allocatable, public string(v, fmt)
Converts a number or a Boolean value to a string.
subroutine, public horiz_interp_bilinear_del(interp)
Deallocates memory used by "horiz_interp_type" variables.
subroutine, public horiz_interp_bilinear_init
Initialize this module and writes version number to logfile.
Creates a horiz_interp_type for bilinear interpolation.
Subroutines for reading in weight files and using that to fill in the horiz_interp type instead calcu...
Holds data pointers and metadata for horizontal interpolations, passed between the horiz_interp modul...
Error handler.
Definition mpp.F90:382