23 module interpolator_mod
48 use fms2_io_mod,
only : fmsnetcdffile_t, fms2_io_file_exist => file_exists, dimension_exists, &
50 variable_exists, get_variable_num_dimensions, &
51 get_num_variables, get_dimension_size, &
52 get_variable_units, get_variable_names, &
54 get_variable_dimension_names, get_variable_sense
56 use horiz_interp_mod,
only : horiz_interp_type, &
71 get_date_julian, set_date_no_leap, &
72 set_date_julian, get_date_no_leap, &
82 use constants_mod,
only : grav, pi, seconds_per_day
83 use platform_mod,
only : r4_kind, r8_kind, r16_kind, fms_path_len, fms_file_len
155 module procedure interpolator_4d_r4, interpolator_4d_r8
156 module procedure interpolator_3d_r4, interpolator_3d_r8
157 module procedure interpolator_2d_r4, interpolator_2d_r8
158 module procedure interpolator_4d_no_time_axis_r4, interpolator_4d_no_time_axis_r8
159 module procedure interpolator_3d_no_time_axis_r4, interpolator_3d_no_time_axis_r8
160 module procedure interpolator_2d_no_time_axis_r4, interpolator_2d_no_time_axis_r8
165 interface assignment(=)
170 module procedure interpolator_init_r4
171 module procedure interpolator_init_r8
175 module procedure get_axis_latlon_data_r4
176 module procedure get_axis_latlon_data_r8
180 module procedure get_axis_level_data_r4
181 module procedure get_axis_level_data_r8
185 module procedure cell_center2_r4
186 module procedure cell_center2_r8
190 module procedure cart_to_latlon_r4
191 module procedure cart_to_latlon_r8
195 module procedure latlon2xyz_r4
196 module procedure latlon2xyz_r8
200 module procedure diag_read_data_r4
201 module procedure diag_read_data_r8
205 module procedure read_data_r4
206 module procedure read_data_r8
210 module procedure read_data_no_time_axis_r4
211 module procedure read_data_no_time_axis_r8
215 module procedure interp_linear_r4
216 module procedure interp_linear_r8
233 module procedure interp_weighted_scalar_1d_r4, interp_weighted_scalar_1d_r8
234 module procedure interp_weighted_scalar_2d_r4, interp_weighted_scalar_2d_r8
241 #include<file_version.h>
247 logical :: is_allocated = .false.
248 real(r4_kind),
allocatable :: lat(:)
249 real(r4_kind),
allocatable :: lon(:)
250 real(r4_kind),
allocatable :: latb(:)
251 real(r4_kind),
allocatable :: lonb(:)
252 real(r4_kind),
allocatable :: levs(:)
253 real(r4_kind),
allocatable :: halflevs(:)
254 real(r4_kind),
allocatable :: data5d(:,:,:,:,:)
255 real(r4_kind),
allocatable :: pmon_pyear(:,:,:,:)
256 real(r4_kind),
allocatable :: pmon_nyear(:,:,:,:)
257 real(r4_kind),
allocatable :: nmon_nyear(:,:,:,:)
258 real(r4_kind),
allocatable :: nmon_pyear(:,:,:,:)
259 real(r4_kind) :: tweight
260 real(r4_kind) :: tweight1
261 real(r4_kind) :: tweight2
262 real(r4_kind) :: tweight3
266 logical :: is_allocated = .false.
267 real(r8_kind),
allocatable :: lat(:)
268 real(r8_kind),
allocatable :: lon(:)
269 real(r8_kind),
allocatable :: latb(:)
270 real(r8_kind),
allocatable :: lonb(:)
271 real(r8_kind),
allocatable :: levs(:)
272 real(r8_kind),
allocatable :: halflevs(:)
273 real(r8_kind),
allocatable :: data5d(:,:,:,:,:)
274 real(r8_kind),
allocatable :: pmon_pyear(:,:,:,:)
275 real(r8_kind),
allocatable :: pmon_nyear(:,:,:,:)
276 real(r8_kind),
allocatable :: nmon_nyear(:,:,:,:)
277 real(r8_kind),
allocatable :: nmon_pyear(:,:,:,:)
278 real(r8_kind) :: tweight
279 real(r8_kind) :: tweight1
280 real(r8_kind) :: tweight2
281 real(r8_kind) :: tweight3
288 type(interpolate_r4_type) :: r4_type
289 type(interpolate_r8_type) :: r8_type
290 type(horiz_interp_type) :: interph
292 type(fmsnetcdffile_t) :: fileobj
293 character(len=FMS_PATH_LEN) :: file_name
295 integer :: level_type
296 integer :: is,ie,js,je
297 integer :: vertical_indices
299 logical :: climatological_year
302 character(len=64),
allocatable :: field_name(:)
303 logical,
allocatable :: has_level(:)
304 integer,
allocatable :: time_init(:,:)
306 integer,
allocatable :: mr(:)
307 integer,
allocatable :: out_of_bounds(:)
309 integer,
allocatable :: vert_interp(:)
312 integer,
dimension(:),
allocatable :: indexm
313 integer,
dimension(:),
allocatable :: indexp
314 integer,
dimension(:),
allocatable :: climatology
317 logical :: separate_time_vary_calc
326 logical :: module_is_initialized = .false.
327 logical :: clim_diag_initialized = .false.
354 integer,
parameter :: linear = 1, seasonal = 2, bilinear = 3,
notime = 4
361 integer,
parameter :: pressure = 1,
sigma = 2
366 integer,
parameter :: no_conv = 1,
kg_m2 = 2
372 integer,
parameter,
public :: constant = 1,
zero = 2
376 integer,
parameter,
public :: interp_weighted_p = 10, interp_linear_p = 20,
interp_log_p = 30
380 real(r8_kind),
parameter :: tpi = (2.0_r8_kind*pi)
381 real(r8_kind),
parameter :: dtr = tpi/360._r8_kind
391 #ifdef ENABLE_QUAD_PRECISION
393 integer,
parameter::
f_p = r16_kind
396 integer,
parameter::
f_p = r8_kind
405 namelist /interpolator_nml/ &
417 if(in%r4_type%is_allocated)
then
418 if (
allocated(in%r4_type%lat)) out%r4_type%lat = in%r4_type%lat
419 if (
allocated(in%r4_type%lon)) out%r4_type%lon = in%r4_type%lon
420 if (
allocated(in%r4_type%latb)) out%r4_type%latb = in%r4_type%latb
421 if (
allocated(in%r4_type%lonb)) out%r4_type%lonb = in%r4_type%lonb
422 if (
allocated(in%r4_type%levs)) out%r4_type%levs = in%r4_type%levs
423 if (
allocated(in%r4_type%halflevs)) out%r4_type%halflevs = in%r4_type%halflevs
424 else if(in%r8_type%is_allocated)
then
425 if (
allocated(in%r8_type%lat)) out%r8_type%lat = in%r8_type%lat
426 if (
allocated(in%r8_type%lon)) out%r8_type%lon = in%r8_type%lon
427 if (
allocated(in%r8_type%latb)) out%r8_type%latb = in%r8_type%latb
428 if (
allocated(in%r8_type%lonb)) out%r8_type%lonb = in%r8_type%lonb
429 if (
allocated(in%r8_type%levs)) out%r8_type%levs = in%r8_type%levs
430 if (
allocated(in%r8_type%halflevs)) out%r8_type%halflevs = in%r8_type%halflevs
433 out%interph = in%interph
434 if (
allocated(in%time_slice)) out%time_slice = in%time_slice
435 out%file_name = in%file_name
436 out%time_flag = in%time_flag
437 out%level_type = in%level_type
442 out%vertical_indices = in%vertical_indices
443 out%climatological_year = in%climatological_year
444 if (
allocated(in%has_level )) out%has_level = in%has_level
445 if (
allocated(in%field_name )) out%field_name = in%field_name
446 if (
allocated(in%time_init )) out%time_init = in%time_init
447 if (
allocated(in%mr )) out%mr = in%mr
448 if (
allocated(in%out_of_bounds)) out%out_of_bounds = in%out_of_bounds
449 if (
allocated(in%vert_interp )) out%vert_interp = in%vert_interp
450 if(in%r4_type%is_allocated)
then
451 if (
allocated(in%r4_type%data5d )) out%r4_type%data5d = in%r4_type%data5d
452 if (
allocated(in%r4_type%pmon_pyear )) out%r4_type%pmon_pyear = in%r4_type%pmon_pyear
453 if (
allocated(in%r4_type%pmon_nyear )) out%r4_type%pmon_nyear = in%r4_type%pmon_nyear
454 if (
allocated(in%r4_type%nmon_nyear )) out%r4_type%nmon_nyear = in%r4_type%nmon_nyear
455 if (
allocated(in%r4_type%nmon_pyear )) out%r4_type%nmon_pyear = in%r4_type%nmon_pyear
456 else if(in%r8_type%is_allocated)
then
457 if (
allocated(in%r8_type%data5d )) out%r8_type%data5d = in%r8_type%data5d
458 if (
allocated(in%r8_type%pmon_pyear )) out%r8_type%pmon_pyear = in%r8_type%pmon_pyear
459 if (
allocated(in%r8_type%pmon_nyear )) out%r8_type%pmon_nyear = in%r8_type%pmon_nyear
460 if (
allocated(in%r8_type%nmon_nyear )) out%r8_type%nmon_nyear = in%r8_type%nmon_nyear
461 if (
allocated(in%r8_type%nmon_pyear )) out%r8_type%nmon_pyear = in%r8_type%nmon_pyear
463 if (
allocated(in%indexm )) out%indexm = in%indexm
464 if (
allocated(in%indexp )) out%indexp = in%indexp
465 if (
allocated(in%climatology )) out%climatology = in%climatology
466 if (
allocated(in%clim_times )) out%clim_times = in%clim_times
467 out%separate_time_vary_calc = in%separate_time_vary_calc
468 if(in%r4_type%is_allocated)
then
469 out%r4_type%tweight = in%r4_type%tweight
470 out%r4_type%tweight1 = in%r4_type%tweight1
471 out%r4_type%tweight2 = in%r4_type%tweight2
472 out%r4_type%tweight3 = in%r4_type%tweight3
473 else if(in%r8_type%is_allocated)
then
474 out%r8_type%tweight = in%r8_type%tweight
475 out%r8_type%tweight1 = in%r8_type%tweight1
476 out%r8_type%tweight2 = in%r8_type%tweight2
477 out%r8_type%tweight3 = in%r8_type%tweight3
482 out%r4_type%is_allocated = in%r4_type%is_allocated
483 out%r8_type%is_allocated = out%r8_type%is_allocated
508 character(len=*),
intent(in) ::
units
514 case(
'kg/m2',
'kg/m^2',
'kg/m**2',
'kg m^-2',
'kg m**-2')
516 case(
'molecules/cm2/s',
'molecule/cm2/s',
'molec/cm2/s')
558 integer ,
intent(in) :: mod_axes(:)
559 type(
time_type) ,
intent(in) :: init_time
561 integer :: axes(2),nxd,nyd,ndivs,i
563 integer :: domain_layout(2), iscomp, iecomp,jscomp,jecomp
565 if(clim_type%r4_type%is_allocated)
call init_clim_diag_r4(clim_type, mod_axes, init_time)
566 if(clim_type%r8_type%is_allocated)
call init_clim_diag_r8(clim_type, mod_axes, init_time)
604 integer :: taum, taup
605 integer :: modyear, modmonth, modday, modhour, modminute, modsecond
606 integer :: climyear, climmonth, climday, climhour, climminute, climsecond
607 integer :: year1, month1, day, hour, minute, second
608 integer :: climatology, m
611 integer :: indexm, indexp, yearm, yearp
613 character(len=256) :: err_msg
615 if(clim_type%r4_type%is_allocated)
call obtain_interpolator_time_slices_r4(clim_type, time)
616 if(clim_type%r8_type%is_allocated)
call obtain_interpolator_time_slices_r8(clim_type, time)
634 clim_type%separate_time_vary_calc = .false.
657 if (
mpp_pe() == mpp_root_pe() )
then
658 write (logunit,
'(/,(a))')
'Exiting interpolator, have a nice day ...'
661 if(clim_type%r4_type%is_allocated)
then
662 if (
allocated (clim_type%r4_type%lat ))
deallocate(clim_type%r4_type%lat)
663 if (
allocated (clim_type%r4_type%lon ))
deallocate(clim_type%r4_type%lon)
664 if (
allocated (clim_type%r4_type%latb ))
deallocate(clim_type%r4_type%latb)
665 if (
allocated (clim_type%r4_type%lonb ))
deallocate(clim_type%r4_type%lonb)
666 if (
allocated (clim_type%r4_type%levs ))
deallocate(clim_type%r4_type%levs)
667 if (
allocated (clim_type%r4_type%halflevs))
deallocate(clim_type%r4_type%halflevs)
668 if (
allocated (clim_type%r4_type%data5d ))
deallocate(clim_type%r4_type%data5d)
669 else if(clim_type%r8_type%is_allocated)
then
670 if (
allocated (clim_type%r8_type%lat ))
deallocate(clim_type%r8_type%lat)
671 if (
allocated (clim_type%r8_type%lon ))
deallocate(clim_type%r8_type%lon)
672 if (
allocated (clim_type%r8_type%latb ))
deallocate(clim_type%r8_type%latb)
673 if (
allocated (clim_type%r8_type%lonb ))
deallocate(clim_type%r8_type%lonb)
674 if (
allocated (clim_type%r8_type%levs ))
deallocate(clim_type%r8_type%levs)
675 if (
allocated (clim_type%r8_type%halflevs))
deallocate(clim_type%r8_type%halflevs)
676 if (
allocated (clim_type%r8_type%data5d))
deallocate(clim_type%r8_type%data5d)
679 if (
allocated (clim_type%time_slice))
deallocate(clim_type%time_slice)
680 if (
allocated (clim_type%field_name))
deallocate(clim_type%field_name)
681 if (
allocated (clim_type%time_init ))
deallocate(clim_type%time_init)
682 if (
allocated (clim_type%has_level))
deallocate(clim_type%has_level)
683 if (
allocated (clim_type%mr ))
deallocate(clim_type%mr)
684 if (
allocated (clim_type%out_of_bounds ))
deallocate(clim_type%out_of_bounds)
685 if (
allocated (clim_type%vert_interp ))
deallocate(clim_type%vert_interp)
686 if (
allocated(clim_type%indexm))
deallocate(clim_type%indexm)
687 if (
allocated(clim_type%indexp))
deallocate(clim_type%indexp)
688 if (
allocated(clim_type%clim_times))
deallocate(clim_type%clim_times)
689 if (
allocated(clim_type%climatology))
deallocate(clim_type%climatology)
693 if(clim_type%r4_type%is_allocated)
then
694 if (
allocated(clim_type%r4_type%pmon_pyear))
then
695 deallocate(clim_type%r4_type%pmon_pyear)
696 deallocate(clim_type%r4_type%pmon_nyear)
697 deallocate(clim_type%r4_type%nmon_nyear)
698 deallocate(clim_type%r4_type%nmon_pyear)
700 else if(clim_type%r8_type%is_allocated)
then
701 if (
allocated(clim_type%r8_type%pmon_pyear))
then
702 deallocate(clim_type%r8_type%pmon_pyear)
703 deallocate(clim_type%r8_type%pmon_nyear)
704 deallocate(clim_type%r8_type%nmon_nyear)
705 deallocate(clim_type%r8_type%nmon_pyear)
709 clim_type%r4_type%is_allocated=.false.
710 clim_type%r8_type%is_allocated=.false.
714 .and. (clim_type%TIME_FLAG.ne.
notime) )
then
720 module_is_initialized = .false.
740 integer,
intent(out),
optional :: nfields
741 character(len=*),
dimension(:),
intent(out),
optional :: field_names
743 if(
present( nfields ) ) nfields =
SIZE( clim_type%field_name(:) )
744 if(
present( field_names ) ) field_names = clim_type%field_name
760 character(len=*),
intent(in) :: string
761 character(len=64) ::
chomp
765 len = len_trim(string)
766 if (string(len:len) == char(0)) len = len -1
774 #include "interpolator_r4.fh"
775 #include "interpolator_r8.fh"
777 end module interpolator_mod
subroutine, public diag_manager_init(diag_model_subset, time_init, err_msg)
Initialize Diagnostics Manager.
Register a diagnostic field for a given module.
Send data over to output fields.
Close a netcdf or domain file opened with open_file or open_virtual_file.
Opens a given netcdf or domain file.
integer function, public check_nml_error(IOSTAT, NML_NAME)
Checks the iostat argument that is returned after reading a namelist and determines if the error code...
subroutine, public write_version_number(version, tag, unit)
Prints to the log file (or a specified unit) the version id string and tag name.
subroutine, public fms_init(localcomm, alt_input_nml_path)
Initializes the FMS module and also calls the initialization routines for all modules in the MPP pack...
subroutine, public horiz_interp_del(Interp)
Deallocates memory used by "horiz_interp_type" variables. Must be called before reinitializing with h...
subroutine, public horiz_interp_init
Initialize module and writes version number to logfile.out.
Subroutine for performing the horizontal interpolation between two grids.
integer nlat
No description.
subroutine, public query_interpolator(clim_type, nfields, field_names)
query_interpolator receives an interpolate type as input and returns the number of fields and field n...
subroutine, public init_clim_diag(clim_type, mod_axes, init_time)
init_clim_diag is a routine to register diagnostic fields for the climatology file....
integer, parameter increasing_upward
Flags to indicate direction of vertical axis in data file.
subroutine, public interpolate_type_eq(Out, In)
Assignment overload routine for interpolate_type, to be used through the assignment interface.
character(len=64) units
No description.
integer ndim
No description.
integer, parameter f_p
64-bit precision (kind=8)
integer ntime
No description.
integer, parameter sigma
Flags to indicate where climatology pressure levels are pressure or sigma levels.
integer, parameter, public zero
Flags to indicate what to do when the model surface pressure exceeds the climatology surface pressure...
integer, dimension(max_diag_fields) hinterp_id
No description.
integer nlev
No description.
logical use_mpp_io
Set to true to use mpp_io, otherwise fms2io is used.
integer, parameter max_diag_fields
No description.
character(len=64), dimension(max_diag_fields) climo_diag_name
No description.
integer nlon
No description.
subroutine, public unset_interpolator_time_flag(clim_type)
unset_interpolator_time_flag sets a flag in clim_type to false.
integer, parameter kg_m2
Flags to indicate whether the climatology units are mixing ratio (kg/kg) or column integral (kg/m2)....
subroutine, public interpolator_end(clim_type)
interpolator_end receives interpolate data as input and deallocates its memory.
integer sense
No description.
integer nvar
No description.
integer function check_climo_units(units)
check_climo_units checks the units that the climatology data is using. This is needed to allow for co...
logical retain_cm3_bug
No description.
integer verbose
No description.
character(len=64) function chomp(string)
chomp receives a string from NetCDF files and removes CHAR(0) from the end of this string.
logical read_all_on_init
No description.
integer nlatb
No description.
integer, parameter, public interp_log_p
Flags to indicate the type of vertical interpolation.
integer nlonb
No description.
integer nlevh
No description.
integer num_fields
No description.
integer num_clim_diag
No description.
real(r8_kind) missing_value
No description.
integer, parameter notime
Flags to indicate whether the time interpolation should be linear or some other scheme for seasonal d...
logical conservative_interp
No description.
subroutine, public obtain_interpolator_time_slices(clim_type, Time)
obtain_interpolator_time_slices makes sure that the appropriate time slices are available for interpo...
Private interface for weighted scalar interpolation.
Interpolates a field to a model grid.
subroutine mpp_domains_init(flags)
Initialize domain decomp package.
Set up a domain decomposition.
Retrieve layout associated with a domain decomposition. Given a global 2D domain and the number of di...
These routines retrieve the axis specifications associated with the compute domains....
Fill in a global array from domain-decomposed arrays.
Performs halo updates for a given domain.
The domain2D type contains all the necessary information to define the global, compute and data domai...
subroutine mpp_init(flags, localcomm, test_level, alt_input_nml_path)
Initialize the mpp_mod module. Must be called before any usage.
subroutine mpp_exit()
Finalizes process termination. To be called at the end of a run. Certain mpi implementations(openmpi)...
integer function stdlog()
This function returns the current standard fortran unit numbers for log messages. Log messages,...
integer function mpp_npes()
Returns processor count for current pelist.
integer function mpp_pe()
Returns processor ID.
Returns a weight and dates or indices for interpolating between two dates. The interface fraction_of_...
logical function, public leap_year(Time, err_msg)
Returns true if the year corresponding to the input time is a leap year (for default calendar)....
type(time_type) function, public decrement_time(Time, seconds, days, ticks, err_msg, allow_neg_inc)
Decrements a time by seconds and days.
subroutine, public get_date(time, year, month, day, hour, minute, second, tick, err_msg)
Gets the date for different calendar types. Given a time_interval, returns the corresponding date und...
integer function, public days_in_year(Time)
Returns the number of days in the calendar year corresponding to the date represented by time for the...
subroutine, public print_date(Time, str, unit)
Prints the time to standard output (or optional unit) as a date.
real(kind=r8_kind) function, public time_type_to_real(time)
Converts time to seconds and returns it as a real number.
integer function, public get_calendar_type()
Returns default calendar type for mapping from time to date.
Given an input date in year, month, days, etc., creates a time_type that represents this time interva...
Given some number of seconds and days, returns the corresponding time_type.
Type to represent amounts of time. Implemented as seconds and days to allow for larger intervals.
Allocates space and initializes a derived-type variable that contains pre-computed interpolation indi...
Redundant climatology data between fields.