23 module interpolator_mod
49 use fms2_io_mod,
only : fmsnetcdffile_t, fms2_io_file_exist => file_exists, dimension_exists, &
51 variable_exists, get_variable_num_dimensions, &
52 get_num_variables, get_dimension_size, &
53 get_variable_units, get_variable_names, &
55 get_variable_dimension_names, get_variable_sense
57 use horiz_interp_mod,
only : horiz_interp_type, &
72 get_date_julian, set_date_no_leap, &
73 set_date_julian, get_date_no_leap, &
83 use constants_mod,
only : grav, pi, seconds_per_day
84 use platform_mod,
only : r4_kind, r8_kind, r16_kind, fms_path_len, fms_file_len
156 module procedure interpolator_4d_r4, interpolator_4d_r8
157 module procedure interpolator_3d_r4, interpolator_3d_r8
158 module procedure interpolator_2d_r4, interpolator_2d_r8
159 module procedure interpolator_4d_no_time_axis_r4, interpolator_4d_no_time_axis_r8
160 module procedure interpolator_3d_no_time_axis_r4, interpolator_3d_no_time_axis_r8
161 module procedure interpolator_2d_no_time_axis_r4, interpolator_2d_no_time_axis_r8
166 interface assignment(=)
171 module procedure interpolator_init_r4
172 module procedure interpolator_init_r8
176 module procedure get_axis_latlon_data_r4
177 module procedure get_axis_latlon_data_r8
181 module procedure get_axis_level_data_r4
182 module procedure get_axis_level_data_r8
186 module procedure cell_center2_r4
187 module procedure cell_center2_r8
191 module procedure cart_to_latlon_r4
192 module procedure cart_to_latlon_r8
196 module procedure latlon2xyz_r4
197 module procedure latlon2xyz_r8
201 module procedure diag_read_data_r4
202 module procedure diag_read_data_r8
206 module procedure read_data_r4
207 module procedure read_data_r8
211 module procedure read_data_no_time_axis_r4
212 module procedure read_data_no_time_axis_r8
216 module procedure interp_linear_r4
217 module procedure interp_linear_r8
234 module procedure interp_weighted_scalar_1d_r4, interp_weighted_scalar_1d_r8
235 module procedure interp_weighted_scalar_2d_r4, interp_weighted_scalar_2d_r8
242 #include<file_version.h>
248 logical :: is_allocated = .false.
249 real(r4_kind),
allocatable :: lat(:)
250 real(r4_kind),
allocatable :: lon(:)
251 real(r4_kind),
allocatable :: latb(:)
252 real(r4_kind),
allocatable :: lonb(:)
253 real(r4_kind),
allocatable :: levs(:)
254 real(r4_kind),
allocatable :: halflevs(:)
255 real(r4_kind),
allocatable :: data5d(:,:,:,:,:)
256 real(r4_kind),
allocatable :: pmon_pyear(:,:,:,:)
257 real(r4_kind),
allocatable :: pmon_nyear(:,:,:,:)
258 real(r4_kind),
allocatable :: nmon_nyear(:,:,:,:)
259 real(r4_kind),
allocatable :: nmon_pyear(:,:,:,:)
260 real(r4_kind) :: tweight
261 real(r4_kind) :: tweight1
262 real(r4_kind) :: tweight2
263 real(r4_kind) :: tweight3
267 logical :: is_allocated = .false.
268 real(r8_kind),
allocatable :: lat(:)
269 real(r8_kind),
allocatable :: lon(:)
270 real(r8_kind),
allocatable :: latb(:)
271 real(r8_kind),
allocatable :: lonb(:)
272 real(r8_kind),
allocatable :: levs(:)
273 real(r8_kind),
allocatable :: halflevs(:)
274 real(r8_kind),
allocatable :: data5d(:,:,:,:,:)
275 real(r8_kind),
allocatable :: pmon_pyear(:,:,:,:)
276 real(r8_kind),
allocatable :: pmon_nyear(:,:,:,:)
277 real(r8_kind),
allocatable :: nmon_nyear(:,:,:,:)
278 real(r8_kind),
allocatable :: nmon_pyear(:,:,:,:)
279 real(r8_kind) :: tweight
280 real(r8_kind) :: tweight1
281 real(r8_kind) :: tweight2
282 real(r8_kind) :: tweight3
289 type(interpolate_r4_type) :: r4_type
290 type(interpolate_r8_type) :: r8_type
291 type(horiz_interp_type) :: interph
293 type(fmsnetcdffile_t) :: fileobj
294 character(len=FMS_PATH_LEN) :: file_name
296 integer :: level_type
297 integer :: is,ie,js,je
298 integer :: vertical_indices
300 logical :: climatological_year
303 character(len=64),
allocatable :: field_name(:)
304 logical,
allocatable :: has_level(:)
305 integer,
allocatable :: time_init(:,:)
307 integer,
allocatable :: mr(:)
308 integer,
allocatable :: out_of_bounds(:)
310 integer,
allocatable :: vert_interp(:)
313 integer,
dimension(:),
allocatable :: indexm
314 integer,
dimension(:),
allocatable :: indexp
315 integer,
dimension(:),
allocatable :: climatology
318 logical :: separate_time_vary_calc
327 logical :: module_is_initialized = .false.
328 logical :: clim_diag_initialized = .false.
355 integer,
parameter :: linear = 1, seasonal = 2, bilinear = 3,
notime = 4
362 integer,
parameter :: pressure = 1,
sigma = 2
367 integer,
parameter :: no_conv = 1,
kg_m2 = 2
373 integer,
parameter,
public :: constant = 1,
zero = 2
377 integer,
parameter,
public :: interp_weighted_p = 10, interp_linear_p = 20,
interp_log_p = 30
381 real(r8_kind),
parameter :: tpi = (2.0_r8_kind*pi)
382 real(r8_kind),
parameter :: dtr = tpi/360._r8_kind
392 #ifdef ENABLE_QUAD_PRECISION
394 integer,
parameter::
f_p = r16_kind
397 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 NetCDF dataset on disk and initializes the file object.
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)
subroutine, public horiz_interp_init
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.
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 inverse_permutation(x, y)
Produce an inverse permutation. For example, transform [2, 3, 1, 4] to [3, 1, 2, 4].
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.
Redundant climatology data between fields.