repo_name
stringlengths 7
81
| path
stringlengths 4
224
| copies
stringclasses 221
values | size
stringlengths 4
7
| content
stringlengths 975
1.04M
| license
stringclasses 15
values |
---|---|---|---|---|---|
marshallward/mom | src/shared/oda_tools/oda_core_ecda.F90 | 6 | 153794 | ! -*- f90 -*-
module oda_core_ecda_mod
! FMS Shared modules
use fms_mod, only : file_exist, read_data
use fms_mod, only : open_namelist_file, check_nml_error, close_file
use fms_mod, only : error_mesg, FATAL, NOTE
#ifdef INTERNAL_FILE_NML
USE mpp_mod, ONLY: input_nml_file
#endif
use mpp_mod, only : mpp_sum, stdout, stdlog, mpp_sync_self
use mpp_mod, only : mpp_pe, mpp_root_pe
use mpp_io_mod, only : mpp_open, mpp_close, MPP_ASCII, MPP_RDONLY, MPP_MULTI, MPP_SINGLE, MPP_NETCDF
use mpp_io_mod, only : mpp_get_atts, mpp_get_info, mpp_get_fields, mpp_read, axistype, fieldtype, mpp_get_axes
use mpp_io_mod, only : mpp_get_axis_data, mpp_get_field_name
use mpp_domains_mod, only : mpp_get_compute_domain, mpp_get_data_domain
use mpp_domains_mod, only : domain2d, mpp_get_global_domain, mpp_update_domains
use mpp_domains_mod, only : mpp_global_field
use mpp_memutils_mod, only : mpp_print_memuse_stats
use time_manager_mod, only : time_type, set_time, set_date, get_date, get_time
use time_manager_mod, only : operator( <= ), operator( - ), operator( > ), operator ( < )
use get_cal_time_mod, only : get_cal_time
use axis_utils_mod, only : frac_index
use horiz_interp_type_mod, only: horiz_interp_type
use horiz_interp_bilinear_mod, only : horiz_interp_bilinear_new
use constants_mod, only : DEG_TO_RAD
! ODA_tools modules
use oda_types_mod, only : ocean_profile_type, ocn_obs_flag_type, grid_type, obs_clim_type
use oda_types_mod, only : DROP_PROFILER, MOORING, SATELLITE, DRIFTER, SHIP, TEMP_ID, SALT_ID, MISSING_VALUE
use oda_types_mod, only : UNKNOWN, TAO
use xbt_adjust, only : xbt_drop_rate_adjust
implicit none
private
public :: copy_obs, oda_core_init, open_profile_dataset, &
get_obs, get_obs_woa05t, get_obs_woa05s, get_obs_sst, get_obs_suv, &
get_obs_eta, open_profile_dataset_sst, ocn_obs, ssh_td, max_profiles
! Parameters
integer, parameter :: PROFILE_FILE = 1
integer, parameter :: SFC_FILE = 2
! oda_core_nml variables
real :: max_misfit = 5.0 !< used to inflate observation errors where the difference from the first guess is large
real :: ass_start_lat = -87.0 !< set obs domain
real :: ass_end_lat = 87.0 !< set obs domain
integer :: max_profiles = 50000
namelist /oda_core_nml/ max_misfit, ass_start_lat, ass_end_lat, max_profiles
! Shared ocean_obs_nml namelist variables
real :: eta_obs_start_lat = -80.0 !< set obs domain
real :: eta_obs_end_lat = 85.0 !< set obs domain
real :: sst_obs_start_lat = -82.0 !< set obs domain
real :: sst_obs_end_lat = 89.0 !< set obs domain
integer :: max_prflvs = 200 ! for vd test
type(ocean_profile_type), target, dimension(:), allocatable :: profiles
integer :: num_profiles, no_sst, no_prf, no_temp, no_salt, no_suv, no_eta ! total number of observations
integer :: no_woa05
integer :: isc, iec, jsc, jec, isd, ied, jsd, jed ! indices for local domain on model grid
integer :: isg, ieg, jsg, jeg
integer :: isd_filt, ied_filt, jsd_filt, jed_filt
integer :: isd_flt0, ied_flt0, jsd_flt0, jed_flt0
integer :: nk
real, dimension(:,:), allocatable, save :: mask_tao
! sst obs grid information
real, allocatable :: woa05_lon(:), woa05_lat(:), woa05_z(:)
real, allocatable :: sst_lon(:), sst_lat(:), obs_sst(:,:)
real, allocatable, save :: obs_woa05t(:,:,:), obs_woa05s(:,:,:)
integer :: nlon, nlat, nlev
integer :: nlon_woa, nlat_woa, nlev_woa
! time window for DROP, MOORING and SATELLITE data respectively
type(time_type) , dimension(0:100), public :: time_window
type(grid_type), pointer :: Grd
type(horiz_interp_type), save :: Interp
real, allocatable, dimension(:, :) :: x_grid, y_grid, x_grid_uv, y_grid_uv
real :: lon_out(1, 1), lat_out(1, 1)
type(ocn_obs_flag_type) :: ocn_obs
integer :: ssh_td
type obs_entry_type
character(len=128) :: filename
character(len=16) :: file_type
end type obs_entry_type
contains
subroutine init_observations(time_s, time_e, filt_domain, localize)
type(time_type), intent(in) :: time_s, time_e
type(domain2d), intent(in) :: filt_domain
logical, intent(in), optional :: localize
integer, parameter :: SUV_ID = 4, ETA_ID = 5, WOAT_ID = 11, WOAS_ID = 12
! ocean_obs_nml variables
integer :: mooring_window = 5
integer :: satellite_window = 10
integer :: drop_window = 30
integer :: drifter_window = 30
integer :: ship_window = 30
integer :: unknown_window = 30
logical :: prfs_obs, salt_obs, sst_obs, eta_obs, suv_obs
logical :: temp_obs_argo, salt_obs_argo, temp_obs_gtspp
logical :: temp_obs_woa05, salt_obs_woa05
integer :: eta_obs_td = 10
integer :: max_files = 30
integer :: max_files_argo = 10
integer :: max_files_gtspp = 10
namelist /ocean_obs_nml/ mooring_window, satellite_window, drop_window,&
& drifter_window, ship_window, unknown_window,&
& prfs_obs, salt_obs, sst_obs, eta_obs, suv_obs,&
& temp_obs_argo, salt_obs_argo, temp_obs_gtspp,&
& temp_obs_woa05, salt_obs_woa05, eta_obs_td,&
& sst_obs_start_lat, sst_obs_end_lat, eta_obs_start_lat, eta_obs_end_lat,&
& max_files, max_files_argo, max_files_gtspp
integer :: i, j, n, obs_variable
integer :: ioun, io_status, ierr
integer :: stdout_unit, stdlog_unit
integer :: nfiles, nrecs, unit
integer :: nfiles_argo, nrecs_argo, unit_argo
integer :: nfiles_gtspp, nrecs_gtspp, unit_gtspp
integer, dimension(:), allocatable :: filetype
integer, dimension(:), allocatable :: filetype_argo
integer, dimension(:), allocatable :: filetype_gtspp
character(len=128) :: input_files_woa05t, input_files_woa05s
character(len=256) :: record
character(len=128), dimension(:), allocatable :: input_files
character(len=128), dimension(:), allocatable :: input_files_argo
character(len=128), dimension(:), allocatable :: input_files_gtspp
type(obs_entry_type) :: tbl_entry
stdout_unit = stdout()
stdlog_unit = stdlog()
#ifdef INTERNAL_FILE_NML
read (input_nml_file, ocean_obs_nml, iostat=io_status)
#else
ioun = open_namelist_file()
read(UNIT=ioun, NML=ocean_obs_nml, IOSTAT=io_status)
ierr = check_nml_error(io_status,'ocean_obs_nml')
call close_file(ioun)
#endif
write (UNIT=stdlog_unit, NML=ocean_obs_nml)
! Allocate filetype* and input_files* variables
allocate(filetype(max_files), input_files(max_files))
allocate(filetype_argo(max_files_argo), input_files_argo(max_files_argo))
allocate(filetype_gtspp(max_files_gtspp), input_files_gtspp(max_files_gtspp))
filetype = -1
filetype_argo = -1
filetype_gtspp = -1
input_files = ''
input_files_argo = ''
input_files_gtspp = ''
if ( prfs_obs .or. salt_obs .or. temp_obs_argo .or. temp_obs_gtspp .or. salt_obs_argo ) then
ocn_obs%use_prf_as_obs = .true.
end if
ocn_obs%use_sst_as_obs = sst_obs
ocn_obs%use_ssh_as_obs = eta_obs
ocn_obs%use_suv_as_obs = suv_obs
ocn_obs%use_woa05_t = temp_obs_woa05
ocn_obs%use_woa05_s = salt_obs_woa05
ssh_td = eta_obs_td
! time window for DROP, MOORING and SATELLITE data respectively
! will be available from namelist
time_window(:) = set_time(0,unknown_window)
time_window(DROP_PROFILER:DROP_PROFILER+9) = set_time(0,drop_window)
time_window(MOORING:MOORING+9) = set_time(0,mooring_window)
time_window(SATELLITE:SATELLITE+9) = set_time(0,satellite_window)
time_window(DRIFTER:DRIFTER+9) = set_time(0,drifter_window)
time_window(SHIP:SHIP+9) = set_time(0,ship_window)
nfiles = 0
nrecs=0
call mpp_open(unit, 'ocean_obs_table', action=MPP_RDONLY)
read_obs: do while ( nfiles <= max_files )
read (UNIT=unit, FMT='(A)', IOSTAT=io_status) record
if ( io_status < 0 ) then
exit read_obs
else if ( io_status > 0 ) then
cycle read_obs
else
nrecs = nrecs + 1
if ( record(1:1) == '#' ) cycle read_obs
read ( UNIT=record, FMT=*, IOSTAT=io_status ) tbl_entry
if ( io_status < 0 ) then
exit read_obs
else if ( io_status > 0 ) then
cycle read_obs
else
nfiles = nfiles + 1
input_files(nfiles) = tbl_entry%filename
select case ( trim(tbl_entry%file_type) )
case ('profiles')
filetype(nfiles) = PROFILE_FILE
case ('sfc')
filetype(nfiles) = SFC_FILE
case default
call error_mesg('oda_core_mod::init_observations', 'error in obs_table entry format', FATAL)
end select
end if
end if
end do read_obs
if ( nfiles > max_files ) then
call error_mesg('oda_core_mod::init_observations', 'number of obs files exceeds max_files parameter', FATAL)
end if
CALL mpp_close(unit)
nfiles_argo = 0
nrecs_argo = 0
call mpp_open(unit_argo, 'ocean_obs_argo_table', action=MPP_RDONLY)
read_obs_argo: do while ( nfiles_argo <= max_files_argo )
read (UNIT=unit_argo, FMT='(A)', IOSTAT=io_status) record
if ( io_status < 0 ) then
exit read_obs_argo
else if ( io_status > 0 ) then
cycle read_obs_argo
else
nrecs_argo = nrecs_argo + 1
if ( record(1:1) == '#' ) cycle read_obs_argo
read (UNIT=record, FMT=*, IOSTAT=io_status) tbl_entry
if ( io_status < 0 ) then
exit read_obs_argo
else if ( io_status > 0 ) then
cycle read_obs_argo
else
nfiles_argo = nfiles_argo + 1
input_files_argo(nfiles_argo) = tbl_entry%filename
select case ( trim(tbl_entry%file_type) )
case ('profiles')
filetype_argo(nfiles_argo) = PROFILE_FILE
case ('sfc')
filetype_argo(nfiles_argo) = SFC_FILE
case default
call error_mesg('oda_core_mod::init_observations', 'error in obs_table entry format for argo', FATAL)
end select
end if
end if
end do read_obs_argo
if ( nfiles_argo > max_files_argo ) then
call error_mesg('oda_core_mod::init_observations', 'number of obs files exceeds max_files_argo parameter', FATAL)
end if
call mpp_close(unit_argo)
nfiles_gtspp = 0
nrecs_gtspp = 0
call mpp_open(unit_gtspp, 'ocean_obs_gtspp_table', action=MPP_RDONLY)
read_obs_gtspp: do while ( nfiles_gtspp <= max_files_gtspp )
read (UNIT=unit_gtspp, FMT='(A)', IOSTAT=io_status) record
if ( io_status < 0 ) then
exit read_obs_gtspp
else if ( io_status > 0 ) then
cycle read_obs_gtspp
else
nrecs_gtspp = nrecs_gtspp + 1
if ( record(1:1) == '#' ) cycle read_obs_gtspp
read (UNIT=record, FMT=*, IOSTAT=io_status) tbl_entry
if ( io_status < 0 ) then
exit read_obs_gtspp
else if ( io_status > 0 ) then
cycle read_obs_gtspp
else
nfiles_gtspp = nfiles_gtspp + 1
input_files_gtspp(nfiles_gtspp) = tbl_entry%filename
select case ( trim(tbl_entry%file_type) )
case ('profiles')
filetype_gtspp(nfiles_gtspp) = PROFILE_FILE
case ('sfc')
filetype_gtspp(nfiles_gtspp) = SFC_FILE
case default
call error_mesg('oda_core_mod::init_observations', 'error in obs_table entry format for gtspp', FATAL)
end select
end if
end if
end do read_obs_gtspp
if ( nfiles_gtspp > max_files_gtspp ) then
call error_mesg('oda_core_mod::init_observations', 'number of obs files exceeds max_files_gtspp parameter', FATAL)
end if
CALL mpp_close(unit_gtspp)
num_profiles = 0
no_prf = 0
no_sst = 0
no_temp = 0
no_salt = 0
no_suv = 0
no_eta = 0
no_woa05 = 0
! get local indices for Model grid
allocate(x_grid(isg:ieg,jsg:jeg), x_grid_uv(isg:ieg,jsg:jeg))
allocate(y_grid(isg:ieg,jsg:jeg), y_grid_uv(isg:ieg,jsg:jeg))
call mpp_global_field(filt_domain, Grd%x(:,:), x_grid(:,:))
call mpp_global_field(filt_domain, Grd%y(:,:), y_grid(:,:))
! Allocate profiles
allocate(profiles(max_profiles))
do j=jsg, jeg
do i=isg, ieg
if ( x_grid(i,j) .lt. 80.0 ) x_grid(i,j) = x_grid(i,j) + 360.0
end do
end do
! uv grid may not be precise, need to be carefully checked
x_grid_uv(:,:) = x_grid(:,:) + 0.5
do j=jsg, jeg-1
do i=isg, ieg
y_grid_uv(i,j) = y_grid(i,j) + 0.5*(y_grid(i,j+1)-y_grid(i,j))
end do
end do
do i=isg, ieg
y_grid_uv(i,jeg) = 90.0
end do
if ( prfs_obs ) then
obs_variable = TEMP_ID
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("TEMP_ID = ",I5)') TEMP_ID
end if
do n=1, nfiles
select case ( filetype(n) )
case (PROFILE_FILE)
call open_profile_dataset(trim(input_files(n)), time_s, time_e, obs_variable, localize)
case default
call error_mesg('oda_core_mod::init_observations', 'filetype not currently supported for prfs_obs', FATAL)
end select
end do
end if
if ( salt_obs ) then
obs_variable = SALT_ID
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("SALT_ID = ",I5)') SALT_ID
end if
do n=1, nfiles
select case ( filetype(n) )
case (PROFILE_FILE)
call open_profile_dataset(trim(input_files(n)), time_s, time_e, obs_variable, localize)
case default
call error_mesg('oda_core_mod::init_observations', 'filetype not currently supported for salt_obs', FATAL)
end select
end do
end if
if ( temp_obs_gtspp ) then
obs_variable = TEMP_ID
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("TEMP_ID = ",I5)') TEMP_ID
end if
do n=1, nfiles_gtspp
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("f_typ_gtspp = ",I8)') filetype_gtspp(n)
write (UNIT=stdout_unit, FMT='("i_f_gtspp = ",A)') input_files_gtspp(n)
end if
select case ( filetype_gtspp(n) )
case (PROFILE_FILE)
call open_profile_dataset_gtspp()
case default
call error_mesg('oda_core_mod::init_observations', 'filetype_gtspp not currently supported', FATAL)
end select
end do
end if
if ( temp_obs_argo ) then
obs_variable = TEMP_ID
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("TEMP_ID = ",I5)') TEMP_ID
end if
do n=1, nfiles_argo
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("f_typ_argo = ",I8)') filetype_argo(n)
write (UNIT=stdout_unit, FMT='("i_f_argo = ",A)') input_files_argo(n)
end if
select case ( filetype_argo(n) )
case (PROFILE_FILE)
call open_profile_dataset_argo(trim(input_files_argo(n)), time_s, time_e, obs_variable, localize)
case default
call error_mesg('oda_core_mod::init_observations', 'filetype_argo not currently supported', FATAL)
end select
end do
end if
if ( salt_obs_argo ) then
obs_variable = SALT_ID
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("SALT_ID = ",I5)') SALT_ID
end if
do n=1, nfiles_argo
select case ( filetype_argo(n) )
case (PROFILE_FILE)
call open_profile_dataset_argo(trim(input_files_argo(n)), time_s, time_e, obs_variable, localize)
case default
call error_mesg('oda_core_mod::init_observations', 'filetype_argo not currently supported', FATAL)
end select
end do
end if
if ( temp_obs_woa05 ) then
obs_variable = WOAT_ID
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("WOAT_ID = ",I5)') WOAT_ID
end if
input_files_woa05t = "INPUT/woa05_temp.nc"
call open_profile_dataset_woa05t(trim(input_files_woa05t), obs_variable, localize)
end if
if ( salt_obs_woa05 ) then
obs_variable = WOAS_ID
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("WOAS_ID = ",I5)') WOAS_ID
end if
input_files_woa05s = "INPUT/woa05_salt.nc"
call open_profile_dataset_woa05s(trim(input_files_woa05s), obs_variable, localize)
end if
if ( sst_obs ) then
obs_variable = TEMP_ID
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("TEMP_ID for sst = ",I5)') TEMP_ID
end if
nfiles = 1
nrecs = 0
input_files(nfiles) = "INPUT/sst_daily.nc"
filetype(nfiles) = PROFILE_FILE
!!$ call open_profile_dataset_sst(trim(input_files(nfiles)), obs_variable, localize)
end if
if ( eta_obs ) then
obs_variable = ETA_ID
nfiles = 1
nrecs = 0
input_files(nfiles) = "INPUT/ocean.19760101-20001231.eta_t.nc"
filetype(nfiles) = PROFILE_FILE
call open_profile_dataset_eta(trim(input_files(nfiles)), obs_variable, localize)
end if
if ( suv_obs ) then
obs_variable = SUV_ID
nfiles = 1
nrecs = 0
input_files(nfiles) = "INPUT/sfc_current.197601-200012.nc"
filetype(nfiles) = PROFILE_FILE
call open_profile_dataset_suv(trim(input_files(nfiles)), obs_variable, localize)
end if
! Deallocate before exiting routine
deallocate(filetype, input_files)
deallocate(filetype_argo, input_files_argo)
deallocate(filetype_gtspp, input_files_gtspp)
end subroutine init_observations
subroutine open_profile_dataset(filename, time_start, time_end, obs_variable, localize)
character(len=*), intent(in) :: filename
type(time_type), intent(in) :: time_start, time_end
integer, intent(in) :: obs_variable
logical, intent(in), optional :: localize
integer, parameter :: MAX_LEVELS = 1000
integer, parameter :: MAX_LNKS = 500
real :: lon, lat, time, profile_error, rlink, flag_t, flag_s, fix_depth
real :: ri0, rj0
real, dimension(MAX_LEVELS) :: depth, data, t_flag, s_flag
real, dimension(MAX_LNKS, MAX_LEVELS) :: data_bfr, depth_bfr, t_flag_bfr, s_flag_bfr
integer :: unit, ndim, nvar, natt, nstation
integer :: stdout_unit
integer :: inst_type, var_id
integer :: num_levs, k, kk, i, i0, j0, k0, nlevs, a, nn, ii, nlinks
integer :: nprof_in_filt_domain
integer :: bad_point, bad_point_g, out_bound_point
logical :: data_is_local, localize_data, cont
logical :: data_in_period
logical :: prof_in_filt_domain
logical, dimension(MAX_LEVELS) :: flag
logical, dimension(MAX_LNKS, MAX_LEVELS) :: flag_bfr
character(len=32) :: fldname, axisname, anal_fldname, time_units
character(len=138) :: emsg_local
type(time_type) :: profile_time
type(axistype), pointer :: depth_axis, station_axis
type(axistype), allocatable, dimension(:), target :: axes
type(fieldtype), allocatable, dimension(:), target :: fields
type(fieldtype), pointer :: field_lon, field_lat, field_flag, field_time, field_depth, field_data
type(fieldtype), pointer :: field_error, field_link, field_t_flag, field_s_flag, field_fix_depth ! snz drop rate
! NOTE: fields are restricted to be in separate files
if ( PRESENT(localize) ) then
localize_data = localize
else
localize_data = .true.
end if
nprof_in_filt_domain = 0
stdout_unit = stdout()
anal_fldname = 'none'
var_id=-1
if ( obs_variable == TEMP_ID ) then
anal_fldname = 'temp'
var_id = TEMP_ID
else if ( obs_variable == SALT_ID ) then
anal_fldname = 'salt'
var_id = SALT_ID
end if
! call mpp_print_memuse_stats('open_profile_dataset Start')
call mpp_open(unit, filename, form=MPP_NETCDF, fileset=MPP_SINGLE, threading=MPP_MULTI, action=MPP_RDONLY)
call mpp_get_info(unit, ndim, nvar, natt, nstation)
if ( mpp_pe() .eq. mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("Opened profile dataset: ",A)') trim(filename)
end if
! get axis information
allocate(axes(ndim))
call mpp_get_axes(unit, axes)
do i=1, ndim
call mpp_get_atts(axes(i), name=axisname)
select case ( trim(axisname) )
case ('depth_index')
depth_axis => axes(i)
case ('station_index')
station_axis => axes(i)
end select
end do
! get field information
allocate(fields(nvar))
call mpp_get_fields(unit, fields)
do i=1, nvar
call mpp_get_atts(fields(i), name=fldname)
if( var_id .eq. TEMP_ID ) then
select case (trim(fldname))
case ('longitude')
field_lon => fields(i)
case ('latitude')
field_lat => fields(i)
case ('profile_flag')
field_flag => fields(i)
case ('time')
field_time => fields(i)
case ('temp')
field_data => fields(i)
case ('depth')
field_depth => fields(i)
case ('link')
field_link => fields(i)
case ('temp_error')
field_error => fields(i)
case ('temp_flag')
field_t_flag => fields(i)
case ('fix_depth') ! snz drop rate
field_fix_depth => fields(i)
end select
else if( var_id .eq. SALT_ID ) then
select case (trim(fldname))
case ('longitude')
field_lon => fields(i)
case ('latitude')
field_lat => fields(i)
case ('profile_flag_s')
field_flag => fields(i)
case ('time')
field_time => fields(i)
case ('salt')
field_data => fields(i)
case ('depth')
field_depth => fields(i)
case ('link')
field_link => fields(i)
case ('salt_error')
field_error => fields(i)
case ('salt_flag')
field_s_flag => fields(i)
case ('fix_depth') ! snz drop rate
field_fix_depth => fields(i)
end select
end if
end do
call mpp_get_atts(depth_axis, len=nlevs)
if ( nlevs > MAX_LEVELS ) then
call error_mesg('oda_core_mod::open_profile_dataset', 'increase parameter MAX_LEVELS', FATAL)
else if (nlevs < 1) then
call error_mesg('oda_core_mod::open_profile_dataset', 'Value of nlevs is less than 1.', FATAL)
end if
if ( .NOT.ASSOCIATED(field_data) ) then
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'profile dataset not used because data not needed for Analysis', NOTE)
return
end if
write(UNIT=stdout_unit, FMT='("There are ",I8," records in this dataset.")') nstation
write(UNIT=stdout_unit, FMT='("Searching for profiles . . .")')
call mpp_get_atts(field_time, units=time_units)
bad_point = 0
out_bound_point = 0
i = 1
cont = .true.
do while ( cont )
prof_in_filt_domain = .false.
depth = missing_value ! snz add
data = missing_value ! snz add
call mpp_read(unit, field_lon, lon, tindex=i)
call mpp_read(unit, field_lat, lat, tindex=i)
call mpp_read(unit, field_time, time, tindex=i)
call mpp_read(unit, field_depth, depth(1:nlevs), tindex=i)
call mpp_read(unit, field_data, data(1:nlevs), tindex=i)
call mpp_read(unit, field_error, profile_error, tindex=i)
call mpp_read(unit, field_fix_depth, fix_depth, tindex=i) ! snz drop rate
if ( var_id == TEMP_ID ) then
call mpp_read(unit, field_t_flag, t_flag(1:nlevs), tindex=i)
call mpp_read(unit, field_flag, flag_t, tindex=i)
else if ( var_id == SALT_ID ) then
call mpp_read(unit, field_s_flag, s_flag(1:nlevs), tindex=i)
call mpp_read(unit, field_flag, flag_s, tindex=i)
end if
call mpp_read(unit, field_link, rlink, tindex=i)
inst_type = 20 ! snz change one line
!!$ inst_type = DRIFTER + ARGO
data_is_local = .false.
data_in_period = .false.
if ( lon .lt. 0.0 ) lon = lon + 360.0
if ( lon .gt. 360.0 ) lon = lon - 360.0
if ( lon .lt. 80.0 ) lon = lon + 360.0
if ( lat > ass_start_lat .and. lat < ass_end_lat ) data_is_local = .true.
profile_time = get_cal_time(time, time_units, 'julian')
if ( profile_time > time_start .and. profile_time < time_end ) data_in_period = .true.
if ( (data_in_period .and. data_is_local) .and. (.NOT.localize_data) ) then ! localize
if (isd_filt < 1 .and. ied_filt > ieg) then
! filter domain is a full x band
if (lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ieg-1,jsd_flt0)) then
prof_in_filt_domain = .true.
end if
else if (isd_filt >= 1 .and. ied_filt <= ieg) then
! Interior filter domain
if (lon >= x_grid(isd_filt,jsd_flt0) .and. lon <= x_grid(ied_filt-1,jsd_flt0) .and.&
& lat >= y_grid(isd_filt,jsd_flt0) .and. lat <= y_grid(ied_filt-1,jed_flt0-1)) then
prof_in_filt_domain = .true.
end if
else if (isd_filt < 1 .and. ied_filt <= ieg) then
! lhs filter domain
isd_flt0 = isd_filt + ieg
if ((lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ied_filt-1,jsd_flt0) .and.&
& lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ied_filt-1,jed_flt0-1)).or.&
& (lon >= x_grid(isd_flt0,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
& lat >= y_grid(isd_flt0,jsd_flt0) .and. lat <= y_grid(ieg-1,jed_flt0-1))) then
prof_in_filt_domain = .true.
end if
else if (isd_filt >= 1 .and. ied_filt > ieg) then
! rhs filter domain
ied_flt0 = ied_filt - ieg
if ( lon >= x_grid(isd_filt,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
& lat >= y_grid(isd_filt,jsd_flt0) .and. lat <= y_grid(ieg-1,jed_flt0-1) ) then
prof_in_filt_domain = .true.
end if
if (ied_flt0-1 > 1) then
if ( lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ied_flt0-1,jsd_flt0) .and.&
& lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ied_flt0-1,jed_flt0-1) ) then
prof_in_filt_domain = .true.
end if
end if
end if
if ( var_id == TEMP_ID .and. flag_t == 0.0 ) then
num_profiles = num_profiles + 1
no_temp = no_temp + 1
no_prf = no_prf + 1
end if
if ( var_id == SALT_ID .and. flag_s == 0.0 ) then
num_profiles = num_profiles + 1
no_salt = no_salt + 1
no_prf = no_prf + 1
end if
if ( num_profiles > max_profiles ) then
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'maximum number of profiles exceeded, increase max_profiles in oda_core_nml', FATAL)
end if
num_levs = 0
do k=1, MAX_LEVELS
flag(k) = .true.
if ( depth(k) > 2000.0 ) depth(k) = missing_value ! snz add for rdat-hybn
if ( var_id == TEMP_ID ) then
if ( data(k) .eq. missing_value .or.&
& depth(k) .eq. missing_value .or. t_flag(k) .ne. 0.0 ) then
flag(k) = .false.
else
num_levs = num_levs + 1
end if
else if ( var_id == SALT_ID ) then
if ( data(k) .eq. missing_value .or.&
& depth(k) .eq. missing_value .or. s_flag(k) .ne. 0.0 ) then
flag(k) = .false.
else
num_levs = num_levs+1
end if
end if
end do
! large profile are stored externally in separate records
! read linked records and combine profile
ii = i + 1
nlinks = 0
do while ( rlink > 0.0 )
nlinks = nlinks + 1
if ( nlinks > MAX_LNKS ) then
write (emsg_local, '("nlinks (",I6,") > MAX_LNKS (",I6,")")')&
& nlinks, MAX_LNKS
call error_mesg('oda_core_mod::open_profile_dataset',&
& trim(emsg_local)//' in file "'//trim(filename)//&
& '". Increase parameter MAX_LNKS', FATAL)
end if
depth_bfr(nlinks,:) = missing_value
data_bfr(nlinks,:) = missing_value
call mpp_read(unit, field_depth, depth_bfr(nlinks,1:nlevs), tindex=ii)
call mpp_read(unit, field_data, data_bfr(nlinks,1:nlevs), tindex=ii)
if ( var_id == TEMP_ID ) then
call mpp_read(unit, field_t_flag, t_flag_bfr(nlinks,1:nlevs), tindex=ii)
else if ( var_id == SALT_ID ) then
call mpp_read(unit, field_s_flag, s_flag_bfr(nlinks,1:nlevs), tindex=ii)
end if
call mpp_read(unit, field_link, rlink, tindex=ii)
ii = ii + 1
end do
i = ii ! set record counter to start of next profile
if ( nlinks > 0 ) then
do nn=1, nlinks
do k=1, MAX_LEVELS
flag_bfr(nn,k) = .true.
if ( depth_bfr(nn,k) > 2000.0 ) depth_bfr(nn,k) = missing_value ! snz add for rdat-hybn
if ( var_id == TEMP_ID ) then
if ( data_bfr(nn,k) .eq. missing_value .or.&
& depth_bfr(nn,k) .eq. missing_value .or.&
& t_flag_bfr(nn,k) .ne. 0.0 ) then
flag_bfr(nn,k) = .false.
else
num_levs = num_levs+1
end if
else if (var_id == SALT_ID) then
if ( data_bfr(nn,k) .eq. missing_value .or.&
& depth_bfr(nn,k) .eq. missing_value .or.&
& s_flag_bfr(nn,k) .ne. 0.0 ) then
flag_bfr(nn,k) = .false.
else
num_levs = num_levs+1
end if
end if
end do
end do
end if
! mh2 asks to change from [if (num_levs == 0) cycle]
if ( num_levs == 0 ) then
if ( i .gt. nstation ) cont = .false.
cycle
end if
if ( num_profiles > 0 .and. prof_in_filt_domain ) then ! snz - 05 Nov 2012
allocate(profiles(num_profiles)%depth(num_levs))
allocate(profiles(num_profiles)%data(num_levs))
allocate(profiles(num_profiles)%flag(num_levs))
profiles(num_profiles)%variable = var_id
if ( inst_type < 1 ) inst_type = UNKNOWN
profiles(num_profiles)%inst_type = inst_type
profiles(num_profiles)%levels = num_levs
profiles(num_profiles)%lat = lat
profiles(num_profiles)%lon = lon
! allocate(profiles(num_profiles)%ms(num_levs))
! allocate(profiles(num_profiles)%ms_inv(num_levs))
! profiles(num_profiles)%ms(:) = 0.5
kk = 1
do k=1, MAX_LEVELS
if ( flag(k) ) then
if ( kk > profiles(num_profiles)%levels ) then
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'Loop value "kk" is greater than profile levels', FATAL)
end if
profiles(num_profiles)%depth(kk) = depth(k)
profiles(num_profiles)%data(kk) = data(k)
! profiles(num_profiles)%ms_inv(kk) = 1./profiles(num_profiles)%ms(kk)
kk = kk + 1
end if
end do
do nn=1, nlinks
do k=1, MAX_LEVELS
if ( flag_bfr(nn,k) ) then
if ( kk > profiles(num_profiles)%levels ) then
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'Loop value "kk" is greater than profile levels (bfr loop)', FATAL)
end if
profiles(num_profiles)%depth(kk) = depth_bfr(nn,k)
profiles(num_profiles)%data(kk) = data_bfr(nn,k)
! profiles(num_profiles)%ms_inv(kk) = 1./profiles(num_profiles)%ms(kk)
kk = kk + 1
end if
end do
end do
profiles(num_profiles)%time = profile_time
! calculate interpolation coefficients (make sure to account for grid offsets here!)
if ( lat < 65.0 ) then ! regular grids
ri0 = frac_index(lon, x_grid(:,1))
rj0 = frac_index(lat, y_grid(90,:))
i0 = floor(ri0)
j0 = floor(rj0)
if ( i0 > ieg .or. j0 > jeg ) then
write (UNIT=emsg_local, FMT='("i0 = ",I8,", j0 = ",I8)') mpp_pe(), i0, j0
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'For regular grids, either i0 > ieg or j0 > jeg. '//trim(emsg_local), FATAL)
end if
if ( isd_filt >= 1 .and. ied_filt <= ieg ) then
if ( i0 < isd_filt .or. i0 > ied_filt .or. j0 < jsd_filt .or. j0 > jed_filt ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in prfs01. '//trim(emsg_local), FATAL)
end if
end if
if ( isd_filt < 1 .and. i0 > ied_filt-1 .and. i0 < isd_filt + ieg ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in prfs02. '//trim(emsg_local), FATAL)
end if
if ( ied_filt > ieg .and. i0 > ied_filt-ieg-1 .and. ied_filt < isd_filt ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in prfs03. '//trim(emsg_local), FATAL)
end if
Profiles(num_profiles)%i_index = ri0
Profiles(num_profiles)%j_index = rj0
else ! tripolar grids
lon_out(1,1) = (lon-360.0)*DEG_TO_RAD
lat_out(1,1) = lat*DEG_TO_RAD
call horiz_interp_bilinear_new (Interp, (x_grid-360.0)*DEG_TO_RAD, y_grid*DEG_TO_RAD,&
& lon_out, lat_out, new_search=.true., no_crash_when_not_found=.true.)
if ( Interp%i_lon(1,1,1) == -999. ) bad_point = bad_point + 1
if ( Interp%wti(1,1,2) < 1.0 ) then
i0 = Interp%i_lon(1,1,1)
else
i0 = Interp%i_lon(1,1,2)
end if
if ( Interp%wtj(1,1,2) < 1.0 ) then
j0 = Interp%j_lat(1,1,1)
else
j0 = Interp%j_lat(1,1,2)
end if
if ( i0 > ieg .or. j0 > jeg ) then
write (UNIT=emsg_local, FMT='("i0 = ",I6,", j0 = ",I6)') mpp_pe(), i0, j0
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'For tripolar grids, either i0 > ieg or j0 > jeg', FATAL)
end if
if( i0 < isd_filt .or. i0 > ied_filt .or. j0 < jsd_filt .or. j0 > jed_filt ) then
!!$ print*,'prfs.pe,i0,j0= ',mpp_pe(), i0, j0,&
!!$ & 'isd_filt,ied_filt,jsd_filt,jed_filt= ',isd_filt,ied_filt,jsd_filt,jed_filt
!!$ print*,'pe,lon,lat=',mpp_pe(),lon,lat,'x_grid(i0+-1)',x_grid(i0-1:i0+1,j0),&
!!$ & 'y_grid(i0,j0+-1)=',y_grid(i0,j0-1:j0+1)
!!$ print*,'lono11,lato11=',x_grid(i0,j0),y_grid(i0,j0),'lono21,lato21=',x_grid(i0+1,j0),y_grid(i0+1,j0)
!!$ print*,'lono12,lato12=',x_grid(i0,j0+1),y_grid(i0,j0+1),'lono22,lato22=',x_grid(i0+1,j0+1),y_grid(i0+1,j0+1)
!!$ print*,'lonm11,latm11=',x_grid(isd_filt,jsd_filt),y_grid(isd_filt,jsd_filt),&
!!$ & 'lonm21,latm21=',x_grid(ied_filt,jsd_filt),y_grid(ied_filt,jsd_filt)
!!$ print*,'lonm12,latm12=',x_grid(isd_filt,jed_filt),y_grid(isd_filt,jed_filt),&
!!$ & 'lonm22,latm22=',x_grid(ied_filt,jed_filt),y_grid(ied_filt,jed_filt)
!!$ print*,'wti(1:2)=',Interp%wti(1,1,:),'wtj(1:2)=',Interp%wtj(1,1,:)
out_bound_point = out_bound_point + 1
end if
if ( Interp%wti(1,1,2) < 1.0 ) then
Profiles(num_profiles)%i_index =Interp%i_lon(1,1,1) + Interp%wti(1,1,2)
else
Profiles(num_profiles)%i_index =Interp%i_lon(1,1,2)
end if
if (Interp%wtj(1,1,2) < 1.0) then
Profiles(num_profiles)%j_index =Interp%j_lat(1,1,1) + Interp%wtj(1,1,2)
else
Profiles(num_profiles)%j_index =Interp%j_lat(1,1,2)
end if
end if ! grids
Profiles(num_profiles)%accepted = .true.
if ( var_id == TEMP_ID .and. flag_t /= 0.0 ) Profiles(num_profiles)%accepted = .false.
if ( var_id == SALT_ID .and. flag_s /= 0.0 ) Profiles(num_profiles)%accepted = .false.
if (i0 < 1 .or. j0 < 1) then
Profiles(num_profiles)%accepted = .false.
end if
if( i0 < isd_filt .or. i0 >= ied_filt .or. j0 < jsd_filt .or. j0 >= jed_filt ) then
Profiles(num_profiles)%accepted = .false.
end if
if ( Profiles(num_profiles)%accepted ) then ! here
if ( i0 /= ieg .and. j0 /= jeg ) then
if (Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(i0+1,j0,1) == 0.0 .or.&
& Grd%mask(i0,j0+1,1) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
else if ( i0 == ieg .and. j0 /= jeg ) then
if (Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(1,j0,1) == 0.0 .or.&
& Grd%mask(i0,j0+1,1) == 0.0 .or.&
& Grd%mask(1,j0+1,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if ( Grd%mask(i0,j0,1) == 0.0 .or. Grd%mask(i0+1,j0,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
else
if ( Grd%mask(i0,j0,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
end if
end if ! here
if ( Profiles(num_profiles)%accepted .and.&
& Profiles(num_profiles)%inst_type == MOORING+TAO ) then
if ( allocated(mask_tao) ) then
if ( mask_tao(i0,j0) < 1.0 ) then
Profiles(num_profiles)%accepted = .false.
write (UNIT=stdout_unit,&
& FMT='("Rejecting tao mooring at (lat,lon) = (",F10.5,",",F10.5,") based on user-specified mask.")')&
& Profiles(num_profiles)%lat,&
& Profiles(num_profiles)%lon
end if
end if
end if
if ( Profiles(num_profiles)%accepted ) then ! accepted
Profiles(num_profiles)%flag(:) = .true.
allocate(Profiles(num_profiles)%k_index(Profiles(num_profiles)%levels))
do k=1, Profiles(num_profiles)%levels
if (Profiles(num_profiles)%depth(k) < Grd%z(1)) then
Profiles(num_profiles)%k_index(k) = 1.0
else
Profiles(num_profiles)%k_index(k) = frac_index(Profiles(num_profiles)%depth(k), (/0.,Grd%z(:)/))! - 1 snz modify to v3.2 JAN3012
end if
if ( Profiles(num_profiles)%k_index(k) < 1.0 ) then
if ( Profiles(num_profiles)%depth(k) < 0.0 ) then
Profiles(num_profiles)%k_index(k) = 0.0
else if ( Profiles(num_profiles)%depth(k) > Grd%z(size(Grd%z,1)) ) then
Profiles(num_profiles)%k_index(k) = real(nk)
end if
else
Profiles(num_profiles)%k_index(k) = Profiles(num_profiles)%k_index(k) - 1.0
end if
if ( Profiles(num_profiles)%k_index(k) > real(nk) ) then
call error_mesg('oda_core_mod::open_profile_dataset', 'Profile k_index is greater than nk', FATAL)
else if ( Profiles(num_profiles)%k_index(k) < 0.0 ) then
call error_mesg('oda_core_mod::open_profile_dataset', 'Profile k_index is less than 0', FATAL)
end if
k0 = floor(Profiles(num_profiles)%k_index(k))
IF ( k0 >= 1 ) THEN ! snz add
if ( Profiles(num_profiles)%flag(k) ) then ! flag
if ( i0 /= ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 == ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(1,j0,k0) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0) == 0.0 .or.&
& Grd%mask(1,j0+1,k0) == 0.0) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0) == 0.0) then
Profiles(num_profiles)%flag(k) = .false.
end if
else
if ( Grd%mask(i0,j0,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if
if ( i0 /= ieg .and. j0 /= jeg) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 == ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(1,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0+1) == 0.0 .or.&
& Grd%mask(1,j0+1,k0+1) == 0.0) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0+1) == 0.0) then
Profiles(num_profiles)%flag(k) = .false.
end if
else
if ( Grd%mask(i0,j0,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if
if ( abs(Profiles(num_profiles)%data(k)) > 1.e4 &
& .or. abs(Profiles(num_profiles)%depth(k)) > 1.e4 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if ! flag
end if ! snz add
end do
end if ! accepted
endif ! 05 Nov 2012
else ! localize
i = i+1
end if ! localize
if ( var_id == TEMP_ID .and. num_profiles > 0 ) call xbt_drop_rate_adjust(Profiles(num_profiles))
if ( i .gt. nstation ) cont = .false.
end do
a = nprof_in_filt_domain
bad_point_g = bad_point
call mpp_sum(a)
call mpp_sum(bad_point_g)
call mpp_sum(out_bound_point)
if ( no_prf /= num_profiles ) then
write(UNIT=stdout_unit, FMT='("PE: ",I6," no_prf = ",I8,", num_profiles = ",I8)') mpp_pe(), no_prf, num_profiles
end if
if ( var_id == TEMP_ID ) then
write(UNIT=stdout_unit, FMT='("A grand total of ",I8," temp prfs within global domain")') no_temp
write(UNIT=stdout_unit, FMT='("The total of bad_point temp ",I8," within global domain")') bad_point_g
write(UNIT=stdout_unit, FMT='("The total out_bound_point temp ",I8)') out_bound_point
else if ( var_id == SALT_ID ) then
write(UNIT=stdout_unit, FMT='("A grand total of ",I8," salt prfs within global domain")') no_salt
write(UNIT=stdout_unit, FMT='("The total of bad_point salt",I8," within global domain")') bad_point_g
write(UNIT=stdout_unit, FMT='("A grand total of ",I8," prfs within global domain")') no_prf
write(UNIT=stdout_unit, FMT='("A grand total of ",I8," prfs within current PEs computer domain")') a
write(UNIT=stdout_unit, FMT='("The total out_bound_point salt ",I8)') out_bound_point
end if
call mpp_sync_self()
call mpp_close(unit)
deallocate(axes)
deallocate(fields)
! call mpp_print_memuse_stats('open_profile_dataset End')
end subroutine open_profile_dataset
subroutine open_profile_dataset_gtspp()
return
end subroutine open_profile_dataset_gtspp
subroutine open_profile_dataset_argo(filename, time_start, time_end, obs_variable, localize)
character(len=*), intent(in) :: filename
type(time_type), intent(in) :: time_start, time_end
integer, intent(in) :: obs_variable
logical, intent(in), optional :: localize
integer, parameter :: MAX_LEVELS = 1000
integer, parameter :: MAX_LNKS = 500
real :: lon, lat, time, rlink, prf_type
real :: ri0, rj0
real, dimension(MAX_LEVELS) :: depth, data
real, dimension(MAX_LNKS, MAX_LEVELS) :: data_bfr, depth_bfr
integer :: unit, ndim, nvar, natt, nstation
integer :: stdout_unit
integer :: inst_type, var_id
integer :: num_levs, k, kk, i, i0, j0, k0, nlevs, a, nn, ii, nlinks
integer :: nprof_in_filt_domain, out_bound_point
character(len=32) :: fldname, axisname, anal_fldname, time_units
character(len=128) :: emsg_local
logical :: data_is_local, localize_data, cont
logical :: data_in_period
logical :: prof_in_filt_domain
logical, dimension(MAX_LEVELS) :: flag
logical, dimension(MAX_LNKS, MAX_LEVELS) :: flag_bfr
type(time_type) :: profile_time
type(axistype), pointer :: depth_axis, station_axis
type(axistype), allocatable, dimension(:), target :: axes
type(fieldtype), allocatable, dimension(:), target :: fields
type(fieldtype), pointer :: field_lon, field_lat, field_flag, field_time
type(fieldtype), pointer :: field_depth, field_data, field_link, field_var_type
! NOTE: fields are restricted to be in separate files
stdout_unit = stdout()
if ( PRESENT(localize) ) then
localize_data = localize
else
localize_data = .true.
end if
nprof_in_filt_domain = 0
anal_fldname = 'none'
var_id=-1
if ( obs_variable == TEMP_ID ) then
anal_fldname = 'temp'
var_id = TEMP_ID
else if ( obs_variable == SALT_ID ) then
anal_fldname = 'salt'
var_id = SALT_ID
end if
! call mpp_print_memuse_stats('open_profile_dataset_argo Start')
call mpp_open(unit, filename, form=MPP_NETCDF, fileset=MPP_SINGLE, threading=MPP_MULTI, action=MPP_RDONLY)
call mpp_get_info(unit, ndim, nvar, natt, nstation)
write (UNIT=stdout_unit, FMT='("Opened profile dataset: ",A)') trim(filename)
! get axis information
allocate(axes(ndim))
call mpp_get_axes(unit, axes)
do i=1, ndim
call mpp_get_atts(axes(i), name=axisname)
select case (trim(axisname))
case ('depth_index')
depth_axis => axes(i)
case ('station_index')
station_axis => axes(i)
end select
end do
! get field information
allocate(fields(nvar))
call mpp_get_fields(unit, fields)
do i=1, nvar
call mpp_get_atts(fields(i), name=fldname)
if( var_id .eq. TEMP_ID ) then
select case (trim(fldname))
case ('longitude')
field_lon => fields(i)
case ('latitude')
field_lat => fields(i)
case ('dens_flag')
field_flag => fields(i)
case ('time')
field_time => fields(i)
case ('temp')
field_data => fields(i)
case ('depth')
field_depth => fields(i)
case ('link')
field_link => fields(i)
case ('var_type')
field_var_type => fields(i)
end select
else if( var_id .eq. SALT_ID ) then
select case (trim(fldname))
case ('longitude')
field_lon => fields(i)
case ('latitude')
field_lat => fields(i)
case ('dens_flag')
field_flag => fields(i)
case ('time')
field_time => fields(i)
case ('salt')
field_data => fields(i)
case ('depth')
field_depth => fields(i)
case ('link')
field_link => fields(i)
case ('var_type')
field_var_type => fields(i)
end select
end if
end do
call mpp_get_atts(depth_axis, len=nlevs)
if ( nlevs > MAX_LEVELS ) then
call error_mesg('oda_core_mod::open_profile_dataset_argo', 'increase parameter MAX_LEVELS', FATAL)
else if (nlevs < 1) then
call error_mesg('oda_core_mod::open_profile_dataset_argo', 'nlevs less than 1.', FATAL)
end if
if ( .NOT.ASSOCIATED(field_data) ) then
call error_mesg('oda_core_mod::open_profile_dataset_argo',&
& 'profile dataset not used because data not needed for Analysis', NOTE)
return
end if
write (UNIT=stdout_unit, FMT='("There are ",I8," records in this dataset")') nstation
write (UNIT=stdout_unit, FMT='("Searching for profiles . . .")')
call mpp_get_atts(field_time, units=time_units)
out_bound_point = 0
i=1
cont=.true.
do while (cont)
prof_in_filt_domain = .false.
depth = missing_value ! snz add
data = missing_value ! snz add
call mpp_read(unit, field_lon, lon, tindex=i)
call mpp_read(unit, field_lat, lat, tindex=i)
call mpp_read(unit, field_time, time, tindex=i)
call mpp_read(unit, field_depth, depth(1:nlevs), tindex=i)
call mpp_read(unit, field_data, data(1:nlevs), tindex=i)
call mpp_read(unit, field_var_type, prf_type, tindex=i)
call mpp_read(unit, field_link, rlink, tindex=i)
!!$ inst_type = DRIFTER + ARGO
inst_type = 20 ! snz change one line
data_is_local = .false.
data_in_period = .false.
if ( lon .lt. 0.0 ) lon = lon + 360.0
if ( lon .gt. 360.0 ) lon = lon - 360.0
if ( lon .lt. 80.0 ) lon = lon + 360.0
if ( lat > ass_start_lat .and. lat < ass_end_lat ) data_is_local = .true.
profile_time = get_cal_time(time, time_units, 'NOLEAP')
if ( profile_time > time_start .and. profile_time < time_end ) data_in_period = .true.
if ( (data_in_period .and. data_is_local) .and. (.NOT.localize_data) ) then
if (isd_filt < 1 .and. ied_filt > ieg) then
! filter domain is a full x band
if (lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ieg-1,jsd_flt0)) then
prof_in_filt_domain = .true.
end if
else if (isd_filt >= 1 .and. ied_filt <= ieg) then
! Interior filter domain
if (lon >= x_grid(isd_filt,jsd_flt0) .and. lon <= x_grid(ied_filt-1,jsd_flt0) .and.&
& lat >= y_grid(isd_filt,jsd_flt0) .and. lat <= y_grid(ied_filt-1,jed_flt0-1)) then
prof_in_filt_domain = .true.
end if
else if (isd_filt < 1 .and. ied_filt <= ieg) then
! lhs filter domain
isd_flt0 = isd_filt + ieg
if ((lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ied_filt-1,jsd_flt0) .and.&
& lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ied_filt-1,jed_flt0-1)).or.&
& (lon >= x_grid(isd_flt0,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
& lat >= y_grid(isd_flt0,jsd_flt0) .and. lat <= y_grid(ieg-1,jed_flt0-1))) then
prof_in_filt_domain = .true.
end if
else if (isd_filt >= 1 .and. ied_filt > ieg) then
! rhs filter domain
ied_flt0 = ied_filt - ieg
if ( lon >= x_grid(isd_filt,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
& lat >= y_grid(isd_filt,jsd_flt0) .and. lat <= y_grid(ieg-1,jed_flt0-1) ) then
prof_in_filt_domain = .true.
end if
if (ied_flt0-1 > 1) then
if ( lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ied_flt0-1,jsd_flt0) .and.&
& lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ied_flt0-1,jed_flt0-1) ) then
prof_in_filt_domain = .true.
end if
end if
end if
if ( var_id == TEMP_ID ) then
num_profiles = num_profiles + 1
no_temp = no_temp + 1
no_prf = no_prf + 1
else if ( var_id == SALT_ID .and. prf_type == 2.0 ) then
num_profiles =num_profiles + 1
no_salt = no_salt + 1
no_prf = no_prf + 1
end if
if ( num_profiles > max_profiles ) then
call error_mesg('oda_core_mod::open_profile_dataset_argo',&
& 'maximum number of profiles exceeded, increase max_profiles in oda_core_nml', FATAL)
end if
num_levs = 0
do k=1, MAX_LEVELS
flag(k) = .true.
if ( depth(k) > 2000.0 ) depth(k) = missing_value ! snz add for rdat-hybn
if ( var_id == TEMP_ID ) then
if ( data(k) .eq. missing_value .or. depth(k) .eq. missing_value ) then
flag(k) = .false.
else
num_levs = num_levs+1
end if
else if ( var_id == SALT_ID ) then
if ( data(k) .eq. missing_value .or. depth(k) .eq. missing_value ) then
flag(k) = .false.
else
num_levs = num_levs+1
end if
end if
end do
! large profile are stored externally in separate records
! read linked records and combine profile
ii=i+1
nlinks = 0
do while ( rlink > 0.0 )
nlinks = nlinks + 1
if ( nlinks > MAX_LNKS ) then
write (emsg_local, '("nlinks (",I6,") > MAX_LNKS (",I6,")")')&
& nlinks, MAX_LNKS
call error_mesg('oda_core_mod::open_profile_dataset_argo',&
& trim(emsg_local)//' in file "'//trim(filename)//&
& '". Increase parameter MAX_LNKS', FATAL)
end if
depth_bfr(nlinks,:) = missing_value
data_bfr(nlinks,:) = missing_value
call mpp_read(unit,field_depth,depth_bfr(nlinks,1:nlevs),tindex=ii)
call mpp_read(unit,field_data,data_bfr(nlinks,1:nlevs),tindex=ii)
call mpp_read(unit,field_link,rlink,tindex=ii)
ii=ii+1
end do
i=ii ! set record counter to start of next profile
if ( nlinks > 0 ) then
do nn=1, nlinks
do k=1, MAX_LEVELS
flag_bfr(nn,k) = .true.
if ( depth_bfr(nn,k) > 2000.0 ) depth_bfr(nn,k) = missing_value ! snz add for rdat-hybn
if ( var_id == TEMP_ID ) then
if ( data_bfr(nn,k) .eq. missing_value .or. depth_bfr(nn,k) .eq. missing_value ) then
flag_bfr(nn,k) = .false.
else
num_levs = num_levs+1
end if
else if ( var_id == SALT_ID ) then
if ( data_bfr(nn,k) .eq. missing_value .or. depth_bfr(nn,k) .eq. missing_value ) then
flag_bfr(nn,k) = .false.
else
num_levs = num_levs+1
end if
end if
end do
end do
end if
! mh2 asks to change from [if (num_levs == 0) cycle]
if ( num_levs == 0 ) then
if ( i .gt. nstation ) cont = .false.
cycle
end if
if (nprof_in_filt_domain > 0 .and. prof_in_filt_domain) then ! snz 05 Nov 2012
allocate(profiles(num_profiles)%depth(num_levs))
allocate(profiles(num_profiles)%data(num_levs))
allocate(profiles(num_profiles)%flag(num_levs))
profiles(num_profiles)%variable = var_id
if ( inst_type < 1 ) inst_type = UNKNOWN
profiles(num_profiles)%inst_type = inst_type
profiles(num_profiles)%levels = num_levs
profiles(num_profiles)%lat = lat
profiles(num_profiles)%lon = lon
! allocate(profiles(num_profiles)%ms(num_levs))
! allocate(profiles(num_profiles)%ms_inv(num_levs))
! profiles(num_profiles)%ms(:) = 0.5
kk= 1
do k=1, MAX_LEVELS
if ( flag(k) ) then
if ( kk > profiles(num_profiles)%levels ) then
call error_mesg('oda_core_mod::open_profile_dataset_argo',&
& 'Loop variable "kk" is greater than profile levels', FATAL)
end if
profiles(num_profiles)%depth(kk) = depth(k)
profiles(num_profiles)%data(kk) = data(k)
! profiles(num_profiles)%ms_inv(kk) = 1./profiles(num_profiles)%ms(kk)
kk = kk + 1
end if
end do
do nn=1, nlinks
do k=1, MAX_LEVELS
if ( flag_bfr(nn,k) ) then
if ( kk > profiles(num_profiles)%levels ) then
call error_mesg('oda_core_mod::open_profile_dataset_argo',&
& 'Loop variable "kk" is greater than profile levels (bfr loop)', FATAL)
end if
profiles(num_profiles)%depth(kk) = depth_bfr(nn,k)
profiles(num_profiles)%data(kk) = data_bfr(nn,k)
! profiles(num_profiles)%ms_inv(kk) = 1./profiles(num_profiles)%ms(kk)
kk = kk + 1
end if
end do
end do
profiles(num_profiles)%time = profile_time
! snz uses the following to test excluding the coast area salt profiles
! if (profiles(num_profiles)%variable == SALT_ID .and. &
! profiles(num_profiles)%depth(num_levs) < 900.0) profiles(num_profiles)%accepted = .false.
! calculate interpolation coefficients (make sure to account for grid offsets here!)
! note that this only works for lat/lon grids
if ( lat < 65.0 ) then ! regular grids
ri0 = frac_index(lon, x_grid(:,1))
rj0 = frac_index(lat, y_grid(90,:))
i0 = floor(ri0)
j0 = floor(rj0)
if ( i0 > ieg .or. j0 > jeg ) then
write (UNIT=emsg_local, FMT='("i0 = ",I6,", j0 = ",I6)') mpp_pe(), i0, j0
call error_mesg('oda_core_mod::open_profile_dataset_argo',&
& 'For regular grids, either i0 > ieg or j0 > jeg. '//trim(emsg_local), FATAL)
end if
if ( isd_filt >= 1 .and. ied_filt <= ieg ) then
if ( i0 < isd_filt .or. i0 > ied_filt .or. j0 < jsd_filt .or. j0 > jed_filt ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in argo01. '//trim(emsg_local), FATAL)
end if
end if
if ( isd_filt < 1 .and. i0 > ied_filt-1 .and. i0 < isd_filt + ieg ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in argo02. '//trim(emsg_local), FATAL)
end if
if ( ied_filt > ieg .and. i0 > ied_filt-ieg-1 .and. ied_filt < isd_filt ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in argo03. '//trim(emsg_local), FATAL)
end if
Profiles(num_profiles)%i_index = ri0
Profiles(num_profiles)%j_index = rj0
else ! tripolar grids
lon_out(1,1) = lon*DEG_TO_RAD
lat_out(1,1) = lat*DEG_TO_RAD
call horiz_interp_bilinear_new (Interp, x_grid*DEG_TO_RAD, y_grid*DEG_TO_RAD, lon_out, lat_out)
if(Interp%wti(1,1,2) < 1.0) then
i0 = Interp%i_lon(1,1,1)
else
i0 = Interp%i_lon(1,1,2)
end if
if ( Interp%wtj(1,1,2) < 1.0 ) then
j0 = Interp%j_lat(1,1,1)
else
j0 = Interp%j_lat(1,1,2)
end if
if ( i0 > ieg .or. j0 > jeg ) then
write (UNIT=emsg_local, FMT='("i0 = ",I6,", j0 = ",I6)') mpp_pe(), i0, j0
call error_mesg('oda_core_mod::open_profile_dataset_argo',&
& 'For tirpolar grids, either i0 > ieg or j0 > jeg. '//trim(emsg_local), FATAL)
end if
if ( i0 < isd_filt .or. i0 > ied_filt .or. j0 < jsd_filt .or. j0 > jed_filt ) then
!!$ print*,'argo.pe,i0,j0= ',mpp_pe(), i0, j0,&
!!$ & 'isd_filt,ied_filt,jsd_filt,jed_filt= ',isd_filt,ied_filt,jsd_filt,jed_filt
!!$ print*,'pe,lon,lat=',mpp_pe(),lon,lat,'x_grid(i0+-1)',x_grid(i0-1:i0+1,j0),&
!!$ & 'y_grid(i0,j0+-1)=',y_grid(i0,j0-1:j0+1)
!!$ print*,'lono11,lato11=',x_grid(i0,j0),y_grid(i0,j0),'lono21,lato21=',x_grid(i0+1,j0),y_grid(i0+1,j0)
!!$ print*,'lono12,lato12=',x_grid(i0,j0+1),y_grid(i0,j0+1),'lono22,lato22=',x_grid(i0+1,j0+1),y_grid(i0+1,j0+1)
!!$ print*,'lonm11,latm11=',x_grid(isd_filt,jsd_filt),y_grid(isd_filt,jsd_filt),&
!!$ & 'lonm21,latm21=',x_grid(ied_filt,jsd_filt),y_grid(ied_filt,jsd_filt)
!!$ print*,'lonm12,latm12=',x_grid(isd_filt,jed_filt),y_grid(isd_filt,jed_filt),&
!!$ & 'lonm22,latm22=',x_grid(ied_filt,jed_filt),y_grid(ied_filt,jed_filt)
!!$ print*,'wti(1:2)=',Interp%wti(1,1,:),'wtj(1:2)=',Interp%wtj(1,1,:)
out_bound_point = out_bound_point + 1
end if
if ( Interp%wti(1,1,2) < 1.0 ) then
Profiles(num_profiles)%i_index =Interp%i_lon(1,1,1) + Interp%wti(1,1,2)
else
Profiles(num_profiles)%i_index =Interp%i_lon(1,1,2)
end if
if ( Interp%wtj(1,1,2) < 1.0 ) then
Profiles(num_profiles)%j_index =Interp%j_lat(1,1,1) + Interp%wtj(1,1,2)
else
Profiles(num_profiles)%j_index =Interp%j_lat(1,1,2)
end if
end if ! grids
Profiles(num_profiles)%accepted = .true.
if ( i0 < 1 .or. j0 < 1 ) then
Profiles(num_profiles)%accepted = .false.
end if
if ( i0 < isd_filt .or. i0 >= ied_filt .or. j0 < jsd_filt .or. j0 >= jed_filt ) then
Profiles(num_profiles)%accepted = .false.
end if
if ( Profiles(num_profiles)%accepted ) then ! here
if ( i0 /= ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(i0+1,j0,1) == 0.0 .or.&
& Grd%mask(i0,j0+1,1) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,1) == 0.0) then
Profiles(num_profiles)%accepted = .false.
end if
else if ( i0 == ieg .and. j0 /= jeg ) then
if (Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(1,j0,1) == 0.0 .or.&
& Grd%mask(i0,j0+1,1) == 0.0 .or.&
& Grd%mask(1,j0+1,1) == 0.0) then
Profiles(num_profiles)%accepted = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if (Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(i0+1,j0,1) == 0.0) then
Profiles(num_profiles)%accepted = .false.
end if
else
if ( Grd%mask(i0,j0,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
end if
end if ! here
if ( Profiles(num_profiles)%accepted .and. Profiles(num_profiles)%inst_type == MOORING+TAO) then
if ( allocated(mask_tao) ) then
if ( mask_tao(i0,j0) < 1.0 ) then
Profiles(num_profiles)%accepted = .false.
write (UNIT=stdout_unit,&
& FMT='("Rejecting tao mooring at (lat,lon) = (",F10.5,",",F10.5,") based on user-specified mask.")')&
& Profiles(num_profiles)%lat,&
& Profiles(num_profiles)%lon
end if
end if
end if
if ( Profiles(num_profiles)%accepted ) then
Profiles(num_profiles)%flag(:) = .true.
allocate(Profiles(num_profiles)%k_index(Profiles(num_profiles)%levels))
do k=1, Profiles(num_profiles)%levels
if (Profiles(num_profiles)%depth(k) < Grd%z(1)) then
Profiles(num_profiles)%k_index(k) = 1.0
else
Profiles(num_profiles)%k_index(k) = frac_index(Profiles(num_profiles)%depth(k), (/0.,Grd%z(:)/))! - 1 snz modify to v3.2 JAN3012
end if
if ( Profiles(num_profiles)%k_index(k) < 1 ) then
if ( Profiles(num_profiles)%depth(k) < 0 ) then
Profiles(num_profiles)%k_index(k) = 0
else if ( Profiles(num_profiles)%depth(k) > Grd%z(size(Grd%z,1)) ) then
Profiles(num_profiles)%k_index(k) = nk
end if
else
Profiles(num_profiles)%k_index(k) = Profiles(num_profiles)%k_index(k) - 1
end if
if ( Profiles(num_profiles)%k_index(k) > nk ) then
call error_mesg('oda_core_mod::open_profile_dataset_argo', 'Profile k_index is greater than nk', FATAL)
else if ( Profiles(num_profiles)%k_index(k) < 0 ) then
call error_mesg('oda_core_mod::open_profile_dataset_argo', 'Profile k_index is less than 0', FATAL)
end if
k0 = floor(Profiles(num_profiles)%k_index(k))
if ( k0 >= 1 ) then ! snz add
if ( Profiles(num_profiles)%flag(k) ) then ! flag
if ( i0 /= ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 == ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(1,j0,k0) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0) == 0.0 .or.&
& Grd%mask(1,j0+1,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else
if ( Grd%mask(i0,j0,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if
if ( i0 /= ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 == ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(1,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0+1) == 0.0 .or.&
& Grd%mask(1,j0+1,k0+1) == 0.0) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else
if ( Grd%mask(i0,j0,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if
if ( abs(Profiles(num_profiles)%data(k)) > 1.e4 &
& .or. abs(Profiles(num_profiles)%depth(k)) > 1.e4 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if ! flag
end if ! snz add
end do
end if ! accepted
end if ! 05 Nov 2012
else ! localize
i = i+1
end if ! localize
if ( i .gt. nstation ) cont = .false.
end do
a = nprof_in_filt_domain
call mpp_sum(a)
call mpp_sum(out_bound_point)
if ( no_prf /= num_profiles ) then
write(UNIT=stdout_unit, FMT='("PE: ",I6," no_prf = ",I8,", num_profiles = ",I8)') mpp_pe(), no_prf, num_profiles
end if
if ( var_id == TEMP_ID ) then
write(UNIT=stdout_unit, FMT='("A grand total of ",I8," argo temp prfs within global domain")') no_temp
write(UNIT=stdout_unit, FMT='("A total out of bound points",I8," argo temp within global domain")') out_bound_point
else if ( var_id == SALT_ID ) then
write(UNIT=stdout_unit, FMT='("A grand total of ",I8," argo salt prfs within global domain")') no_salt
write(UNIT=stdout_unit, FMT='("A grand total of ",I8," argo prfs within global domain")') no_prf
write(UNIT=stdout_unit, FMT='("A grand total of ",I8," argo prfs within current PEs computer domain")') a
write(UNIT=stdout_unit, FMT='("A total out of bound points",I8," argo salt within global domain")') out_bound_point
end if
call mpp_sync_self()
call mpp_close(unit)
deallocate(axes)
deallocate(fields)
! call mpp_print_memuse_stats('open_profile_dataset_argo End')
end subroutine open_profile_dataset_argo
! get profiles and sfc
! obs relevant to current analysis interval
subroutine get_obs(model_time, Prof, nprof)
type(time_type), intent(in) :: model_time
type(ocean_profile_type), dimension(:), intent(inout) :: Prof
integer, intent(inout) :: nprof
integer :: i, k, kk, k_interval
integer :: yr, mon, day, hr, min, sec
integer :: stdout_unit
type(time_type) :: tdiff
nprof = 0
stdout_unit = stdout()
write (UNIT=stdout_unit, FMT='("Gathering profiles for current analysis time")')
call get_date(model_time, yr, mon, day, hr, min, sec)
write (UNIT=stdout_unit, FMT='("Current YYYY/MM/DD = ",I4,"/",I2,"/",I2)') yr, mon, day
do i=1, no_prf
if ( Profiles(i)%time <= model_time ) then
tdiff = model_time - Profiles(i)%time
else
tdiff = Profiles(i)%time - model_time
end if
! no tdiff criteria for monthly mean data like
! but tdiff criteria has to be set for daily data
if ( tdiff <= time_window(Profiles(i)%inst_type) .and. Profiles(i)%accepted ) then
! for single profile test
nprof = nprof + 1
if ( nprof > size(Prof,1) ) then
call error_mesg('oda_core_mod::get_obs',&
& 'Passed in array "Prof" is smaller than number of profiles, increase size of Prof before call.',&
& FATAL)
end if
call copy_obs(Profiles(i:i), Prof(nprof:nprof))
Prof(nprof)%tdiff = tdiff
! snz add the following few lines for increasing deep water data
if ( Prof(nprof)%levels > max_prflvs ) then
k_interval = (Prof(nprof)%levels-max_prflvs+50)/50 + 1
kk = max_prflvs - 50
do k=max_prflvs-50+1, Prof(nprof)%levels, k_interval
kk = kk + 1
Prof(nprof)%depth(kk) = Prof(nprof)%depth(k)
Prof(nprof)%k_index(kk) = Prof(nprof)%k_index(k)
Prof(nprof)%data(kk) = Prof(nprof)%data(k)
Prof(nprof)%flag(kk) = Prof(nprof)%flag(k)
end do
Prof(nprof)%levels = kk
end if
! snz end the adding lines
end if
end do
write (UNIT=stdout_unit,&
& FMT='("A total of ",I8," profiles are being used for the current analysis step.")') nprof
return
end subroutine get_obs
subroutine oda_core_init(Domain, Grid, time_s, time_e, filt_domain, localize)
type(domain2d), intent(inout) :: Domain
type(grid_type), target, intent(in) :: Grid
logical, intent(in), optional :: localize
type(time_type), intent(in) :: time_s, time_e
type(domain2d), intent(in) :: filt_domain
integer :: ioun, ierr, io_status
integer :: stdlog_unit
stdlog_unit = stdlog()
! Read in the namelist file
#ifdef INTERNAL_FILE_NML
read (input_nml_file, oda_core_nml, iostat=io_status)
#else
ioun = open_namelist_file()
read(ioun, NML=oda_core_nml, IOSTAT=io_status)
ierr = check_nml_error(io_status, 'oda_core_nml')
call close_file(ioun)
#endif
write(stdlog_unit, NML=oda_core_nml)
Grd => Grid
call mpp_get_compute_domain(Domain, isc, iec, jsc, jec)
call mpp_get_data_domain(Domain, isd, ied, jsd, jed)
call mpp_get_global_domain(Domain, isg, ieg, jsg, jeg)
call mpp_get_data_domain(filt_domain, isd_filt, ied_filt, jsd_filt, jed_filt)
jsd_flt0 = jsd_filt
jed_flt0 = jed_filt
if (jsd_filt < 1) jsd_flt0 = 1
if (jed_filt > jeg) jed_flt0 = jeg
nk = size(Grid%z)
call init_observations(time_s, time_e, filt_domain, localize)
end subroutine oda_core_init
subroutine copy_obs(obs_in, obs_out)
type(ocean_profile_type), dimension(:), intent(in) :: obs_in
type(ocean_profile_type), dimension(:), intent(inout) :: obs_out
integer :: n
if ( size(obs_in) .ne. size(obs_out) ) then
call error_mesg('oda_core_mod::copy_obs', 'Size of in and out obs variables are not equal.', FATAL)
end if
do n=1, size(obs_in)
Obs_out(n)%variable = Obs_in(n)%variable
Obs_out(n)%inst_type = Obs_in(n)%inst_type
Obs_out(n)%levels = Obs_in(n)%levels
Obs_out(n)%lon = Obs_in(n)%lon
Obs_out(n)%lat = Obs_in(n)%lat
Obs_out(n)%accepted = Obs_in(n)%accepted
if ( associated(Obs_out(n)%depth) ) then
deallocate(Obs_out(n)%depth)
nullify(Obs_out(n)%depth)
end if
allocate(Obs_out(n)%depth(Obs_in(n)%levels))
Obs_out(n)%depth(:) = Obs_in(n)%depth(:)
if ( associated(Obs_out(n)%data) ) then
deallocate(Obs_out(n)%data)
nullify(Obs_out(n)%data)
end if
allocate(Obs_out(n)%data(Obs_in(n)%levels))
Obs_out(n)%data(:) = Obs_in(n)%data(:)
if ( associated(Obs_out(n)%flag) ) then
deallocate(Obs_out(n)%flag)
nullify(Obs_out(n)%flag)
end if
allocate(Obs_out(n)%flag(Obs_in(n)%levels))
Obs_out(n)%flag(:) = Obs_in(n)%flag(:)
Obs_out(n)%time = Obs_in(n)%time
Obs_out(n)%yyyy = Obs_in(n)%yyyy
Obs_out(n)%mmdd = Obs_in(n)%mmdd
Obs_out(n)%i_index = Obs_in(n)%i_index
Obs_out(n)%j_index = Obs_in(n)%j_index
if ( associated(Obs_out(n)%k_index) ) then
deallocate(Obs_out(n)%k_index)
nullify(Obs_out(n)%k_index)
end if
allocate(Obs_out(n)%k_index(Obs_in(n)%levels))
Obs_out(n)%k_index = Obs_in(n)%k_index
! if ( associated(Obs_out(n)%ms) ) then
! deallocate(Obs_out(n)%ms)
! nullify(Obs_out(n)%ms)
! end if
! allocate(Obs_out(n)%ms(Obs_in(n)%levels))
! Obs_out(n)%ms = Obs_in(n)%ms
! if ( associated(Obs_out(n)%ms_inv) ) then
! deallocate(Obs_out(n)%ms_inv)
! nullify(Obs_out(n)%ms_inv)
! end if
! allocate(Obs_out(n)%ms_inv(Obs_in(n)%levels))
! Obs_out(n)%ms_inv = 1./Obs_in(n)%ms
Obs_out(n)%tdiff = Obs_in(n)%tdiff
if ( associated(Obs_out(n)%Forward_model%wgt) ) then
deallocate(Obs_out(n)%Forward_model%wgt)
nullify(Obs_out(n)%Forward_model%wgt)
end if
end do
end subroutine copy_obs
subroutine open_profile_dataset_sst(filename, obs_variable, localize)
character(len=*), intent(in) :: filename
integer, intent(in) :: obs_variable
logical, intent(in), optional :: localize
integer, parameter :: MAX_LEVELS = 1
real :: lon, lat, rms_err
real :: ri0, rj0
real, dimension(MAX_LEVELS) :: depth, data
integer :: unit, ndim, nvar, natt, ntime
integer :: var_id, inst_type
integer :: num_levs, k, kk, i, j, i0, j0
integer :: stdout_unit
logical :: data_is_local, localize_data
logical, dimension(MAX_LEVELS) :: flag
character(len=32) :: axisname, anal_fldname
character(len=128) :: emsg_local
type(axistype), dimension(:), allocatable, target :: axes
type(axistype), pointer :: lon_axis, lat_axis
if ( PRESENT(localize) ) then
localize_data = localize
else
localize_data = .true.
end if
stdout_unit = stdout()
anal_fldname = 'temp'
var_id = obs_variable
call mpp_open(unit, trim(filename), MPP_RDONLY, MPP_NETCDF, threading=MPP_MULTI, fileset=MPP_SINGLE)
call mpp_get_info(unit, ndim, nvar, natt, ntime)
allocate(axes(ndim))
call mpp_get_axes(unit, axes)
do i=1, ndim
call mpp_get_atts(axes(i),name=axisname)
select case (trim(axisname))
!!$ case ('GRIDLON_T') ! cm2 grids
!!$ case ('gridlon_t') ! cm2 grids
case ('XT_OCEAN') ! cm2.5 grids
!!$ case ('lon') ! after 2008
lon_axis => axes(i)
!!$ case ('GRIDLAT_T') ! cm2 grids
!!$ case ('gridlat_t') ! cm2 grids
case ('YT_OCEAN') ! cm2 grids
!!$ case ('lat') ! for after 2008
lat_axis => axes(i)
end select
end do
call mpp_get_atts(lon_axis,len=nlon)
call mpp_get_atts(lat_axis,len=nlat)
if ( nlon /= 1440 .or. nlat /= 1070 ) then ! after 2008
write (UNIT=emsg_local, FMT='("sst obs dim is not same as in file. nlon = ",I5,", nlat = ",I5)') nlon, nlat
call error_mesg('oda_core_mod::open_profile_dataset_sst', trim(emsg_local), FATAL)
end if
! idealized
do j=1, nlat
do i=1, nlon
lon = x_grid(i,j)
lat = y_grid(i,j)
rms_err = 0.5
inst_type = 20
data_is_local = .true.
if ( lon .lt. 0.0 ) lon = lon + 360.0
if ( lon .gt. 360.0 ) lon = lon - 360.0
if ( lon .lt. 80.0 ) lon = lon + 360.0
if ( lat < sst_obs_start_lat .or. lat > sst_obs_end_lat ) data_is_local = .false. ! at the final test
if ( Grd%mask(i,j,1) == 0 ) data_is_local = .false.
if ( abs(lat) < 40.0 ) then
if ( i/4*4 /= i .or. j/4*4 /= j ) data_is_local = .false.
else if ( abs(lat) < 60.0 ) then
if ( i/8*8 /= i .or. j/6*6 /= j ) data_is_local = .false.
else
if ( i/16*16 /= i .or. j/8*8 /= j ) data_is_local = .false.
end if
if ( data_is_local .and. (.NOT.localize_data) ) then
if ( lat < 60.0 ) then ! regular grids
ri0 = frac_index(lon, x_grid(:,nlat/2))
rj0 = frac_index(lat, y_grid(nlon/4,:))
i0 = floor(ri0)
j0 = floor(rj0)
else ! tripolar grids
lon_out(1,1) = lon*DEG_TO_RAD
lat_out(1,1) = lat*DEG_TO_RAD
call horiz_interp_bilinear_new (Interp, x_grid*DEG_TO_RAD, y_grid*DEG_TO_RAD, lon_out, lat_out)
if ( Interp%wti(1,1,2) < 1.0 ) then
i0 = Interp%i_lon(1,1,1)
else
i0 = Interp%i_lon(1,1,2)
end if
if ( Interp%wtj(1,1,2) < 1.0 ) then
j0 = Interp%j_lat(1,1,1)
else
j0 = Interp%j_lat(1,1,2)
end if
if ( i0 > ieg .or. j0 > jeg ) then
write (UNIT=emsg_local, FMT='("i0 = ",I8,", j0 = ",I8)') i0, j0
call error_mesg('oda_core_mod::open_profile_dataset_sst',&
& 'For tripolar grids, either i0 > ieg or j0 > jeg. '//trim(emsg_local), FATAL)
end if
end if
if ( i0 /= ieg .and. j0 /= jeg ) then ! exclude SSTs at ieg and jeg
if ( Grd%mask(i0,j0,1) /= 0.0 .and. Grd%mask(i0+1,j0,1) /= 0.0 .and.&
& Grd%mask(i0,j0+1,1) /= 0.0 .and. Grd%mask(i0+1,j0+1,1) /= 0.0 ) then
no_sst = no_sst+1
num_profiles=num_profiles+1
if ( num_profiles > max_profiles ) then
call error_mesg('oda_core_mod::open_profile_dataset_sst',&
& 'Maximum number of profiles exceeded, increase max_profiles in oda_core_nml', FATAL)
end if
num_levs = 0
flag = .false.
do k=1, 1
flag(k) = .true.
data(k) = 0.0
depth(k) = 0.0
num_levs = num_levs + 1
end do
if ( num_levs == 0 ) cycle
allocate(profiles(num_profiles)%depth(num_levs))
allocate(profiles(num_profiles)%data(num_levs))
allocate(profiles(num_profiles)%flag(num_levs))
allocate(profiles(num_profiles)%ms(num_levs))
allocate(profiles(num_profiles)%ms_inv(num_levs))
profiles(num_profiles)%variable = var_id
profiles(num_profiles)%inst_type = inst_type
profiles(num_profiles)%levels = num_levs
profiles(num_profiles)%lat = lat
profiles(num_profiles)%lon = lon
kk = 1
do k=1, 1
if ( flag(k) ) then
profiles(num_profiles)%depth(kk) = depth(k)
profiles(num_profiles)%data(kk) = data(k)
profiles(num_profiles)%ms(kk) = 1.0
profiles(num_profiles)%ms_inv(kk) = 1.0
kk=kk+1
end if
end do
! calculate interpolation coefficients (make sure to account for grid offsets here!)
if ( lat < 60.0 ) then ! for regular grids
Profiles(num_profiles)%i_index = ri0
Profiles(num_profiles)%j_index = rj0
else ! for tripolar grids
lon_out(1,1) = lon*DEG_TO_RAD
lat_out(1,1) = lat*DEG_TO_RAD
call horiz_interp_bilinear_new (Interp, x_grid*DEG_TO_RAD, y_grid*DEG_TO_RAD, lon_out, lat_out)
if ( Interp%wti(1,1,2) < 1.0 ) then
Profiles(num_profiles)%i_index =Interp%i_lon(1,1,1) + Interp%wti(1,1,2)
else
Profiles(num_profiles)%i_index =Interp%i_lon(1,1,2)
end if
if ( Interp%wtj(1,1,2) < 1.0 ) then
Profiles(num_profiles)%j_index =Interp%j_lat(1,1,1) + Interp%wtj(1,1,2)
else
Profiles(num_profiles)%j_index =Interp%j_lat(1,1,2)
end if
end if
Profiles(num_profiles)%accepted = .true.
if ( i0 < 1 .or. j0 < 1 ) then
Profiles(num_profiles)%accepted = .false.
end if
if ( Profiles(num_profiles)%accepted ) then
if ( Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(i0+1,j0,1) == 0.0 .or.&
& Grd%mask(i0,j0+1,1) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
end if
if ( Profiles(num_profiles)%accepted ) then
Profiles(num_profiles)%flag(:) = .true.
allocate(Profiles(num_profiles)%k_index(Profiles(num_profiles)%levels))
do k=1, Profiles(num_profiles)%levels
Profiles(num_profiles)%k_index(k) = frac_index(depth(k), (/0.,Grd%z(:)/)) - 1
!::sdu:: Do we need the same out-of-range check here?
end do
end if
end if ! exclude SSTs at ieg and jeg
end if
end if
end do
end do
call mpp_close(unit)
deallocate(axes)
write (UNIT=stdout_unit, FMT='("A grand total of ",I8," sst points within global domain")') no_sst
write (UNIT=stdout_unit, FMT='("A final total @sst of ",I8," prfs within global domain")') num_profiles
end subroutine open_profile_dataset_sst
subroutine open_profile_dataset_woa05t(filename, obs_variable, localize)
character(len=*), intent(in) :: filename
integer, intent(in) :: obs_variable
logical, intent(in), optional :: localize
integer, parameter :: MAX_LEVELS = 24
real :: lon, lat, rms_err
real :: ri0, rj0
real, dimension(MAX_LEVELS) :: depth, data
integer :: unit, ndim, nvar, natt, ntime
integer :: var_id, inst_type
integer :: num_levs, k, kk, i, j, i0, j0, k0
integer :: stdout_unit, istat
integer :: out_bound_point
logical :: data_is_local, localize_data
logical :: prof_in_filt_domain
logical, dimension(MAX_LEVELS) :: flag
character(len=32) :: axisname, anal_fldname
character(len=128) :: emsg_local
type(axistype), dimension(:), allocatable, target :: axes
type(axistype), pointer :: lon_axis, lat_axis, z_axis, t_axis
if ( PRESENT(localize) ) then
localize_data = localize
else
localize_data = .true.
end if
stdout_unit = stdout()
anal_fldname = 'temp'
var_id = obs_variable
! call mpp_print_memuse_stats('open_profile_dataset_woa05t Start')
call mpp_open(unit, trim(filename), MPP_RDONLY, MPP_NETCDF, threading=MPP_MULTI, fileset=MPP_SINGLE)
write (UNIT=stdout_unit, FMT='("Opened profile woa05t dataset: ",A)') trim(filename)
call mpp_get_info(unit, ndim, nvar, natt, ntime)
allocate(axes(ndim))
call mpp_get_axes(unit,axes)
do i=1, ndim
call mpp_get_atts(axes(i), name=axisname)
select case (trim(axisname))
case ('lon')
lon_axis => axes(i)
case ('lat')
lat_axis => axes(i)
case ('depth')
z_axis => axes(i)
end select
end do
call mpp_get_atts(lon_axis, len=nlon_woa)
call mpp_get_atts(lat_axis, len=nlat_woa)
call mpp_get_atts(z_axis, len=nlev_woa)
if ( nlon_woa /= 360 .or. nlat_woa /= 180 ) then
write (UNIT=emsg_local, FMT='("woa05 obs dim is not same as in file. nlon_woa = ",I8,", nlat_woa = ",I8)') nlon_woa, nlat_woa
call error_mesg('oda_core_mod::open_profile_dataset_woa05t', trim(emsg_local), FATAL)
end if
allocate(woa05_lon(nlon_woa), woa05_lat(nlat_woa), woa05_z(nlev_woa))
call mpp_get_axis_data(lon_axis, woa05_lon)
call mpp_get_axis_data(lat_axis, woa05_lat)
call mpp_get_axis_data(z_axis, woa05_z)
out_bound_point = 0
! idealized
do j=1, nlat_woa
do i=1, nlon_woa
lon = woa05_lon(i)
lat = woa05_lat(j)
rms_err = 5
inst_type = 20
data_is_local = .true.
prof_in_filt_domain = .false.
if ( lon .lt. 0.0 ) lon = lon + 360.0
if ( lon .gt. 360.0 ) lon = lon - 360.0
if ( lon .lt. 80.0 ) lon = lon + 360.0
if ( lat < -80.0 .or. lat > 80.0 ) data_is_local = .false.
if ( abs(lat) < 20.0 .and. (mod(i,2) /= 0 .or. mod(j,2) /= 0) ) data_is_local = .false.
if ( abs(lat) >= 20.0 .and. (mod(i,4) /= 0 .or. mod(j,4) /= 0) ) data_is_local = .false.
if ( abs(lat) >= 60.0 .and. (mod(i,6) /= 0 .or. mod(j,6) /= 0) ) data_is_local = .false.
if (isd_filt < 1 .and. ied_filt > ieg) then
! filter domain is a full x band
if (lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ieg-1,jsd_flt0)) then
prof_in_filt_domain = .true.
end if
else if (isd_filt >= 1 .and. ied_filt <= ieg) then
! Interior filter domain
if (lon >= x_grid(isd_filt,jsd_flt0) .and. lon <= x_grid(ied_filt-1,jsd_flt0) .and.&
& lat >= y_grid(isd_filt,jsd_flt0) .and. lat <= y_grid(ied_filt-1,jed_flt0-1)) then
prof_in_filt_domain = .true.
end if
else if (isd_filt < 1 .and. ied_filt <= ieg) then
! lhs filter domain
isd_flt0 = isd_filt + ieg
if ((lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ied_filt-1,jsd_flt0) .and.&
& lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ied_filt-1,jed_flt0-1)).or.&
& (lon >= x_grid(isd_flt0,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
& lat >= y_grid(isd_flt0,jsd_flt0) .and. lat <= y_grid(ieg-1,jed_flt0-1))) then
prof_in_filt_domain = .true.
end if
else if (isd_filt >= 1 .and. ied_filt > ieg) then
! rhs filter domain
ied_flt0 = ied_filt - ieg
if ( lon >= x_grid(isd_filt,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
& lat >= y_grid(isd_filt,jsd_flt0) .and. lat <= y_grid(ieg-1,jed_flt0-1) ) then
prof_in_filt_domain = .true.
end if
if (ied_flt0-1 > 1) then
if ( lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ied_flt0-1,jsd_flt0) .and.&
& lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ied_flt0-1,jed_flt0-1) ) then
prof_in_filt_domain = .true.
end if
end if
end if
if ( data_is_local .and. (.NOT.localize_data) ) then ! global index
no_woa05 = no_woa05 + 1
num_profiles = num_profiles + 1
if ( num_profiles > max_profiles ) then
call error_mesg('oda_core_mod::open_profile_dataset_woa05t',&
& 'Maximum number of profiles exceeded, increase max_profiles in oda_core_nml', FATAL)
end if
num_levs = 0
flag = .false.
do k=1, nlev
flag(k) = .true.
data(k) = 0.0
depth(k) = woa05_z(k)
num_levs = num_levs+1
end do
if ( num_levs == 0 ) cycle
if ( prof_in_filt_domain ) then ! localize
allocate(profiles(num_profiles)%depth(num_levs))
allocate(profiles(num_profiles)%data(num_levs))
allocate(profiles(num_profiles)%flag(num_levs))
! allocate(profiles(num_profiles)%ms(num_levs))
! allocate(profiles(num_profiles)%ms_inv(num_levs))
profiles(num_profiles)%variable = var_id
profiles(num_profiles)%inst_type = inst_type
profiles(num_profiles)%levels = num_levs
profiles(num_profiles)%lat = lat
profiles(num_profiles)%lon = lon
kk = 1
do k=1, nlev
if ( flag(k) ) then
profiles(num_profiles)%depth(kk) = depth(k)
profiles(num_profiles)%data(kk) = data(k)
! profiles(num_profiles)%ms(kk) = 1.0
! profiles(num_profiles)%ms_inv(kk) = 1.0
kk = kk + 1
end if
end do
! calculate interpolation coefficients (make sure to account for grid offsets here!)
if ( lat < 65.0 ) then ! regular grids
ri0 = frac_index(lon, x_grid(:,1))
rj0 = frac_index(lat, y_grid(90,:))
i0 = floor(ri0)
j0 = floor(rj0)
if ( i0 > ieg .or. j0 > jeg ) then
write (UNIT=emsg_local, FMT='("i0 = ",I8,", j0 = ",I8)') i0, j0
call error_mesg('oda_core_mod::open_profile_dataset_woa05t',&
& 'For regular grids, either i0 > ieg or j0 > jeg. '//trim(emsg_local), FATAL)
end if
if ( isd_filt >= 1 .and. ied_filt <= ieg ) then
if ( i0 < isd_filt .or. i0 > ied_filt .or. j0 < jsd_filt .or. j0 > jed_filt ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in woat01. '//trim(emsg_local), FATAL)
end if
end if
if ( isd_filt < 1 .and. i0 > ied_filt-1 .and. i0 < isd_filt + ieg ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in woat02. '//trim(emsg_local), FATAL)
end if
if ( ied_filt > ieg .and. i0 > ied_filt-ieg-1 .and. ied_filt < isd_filt ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in woat03. '//trim(emsg_local), FATAL)
end if
Profiles(num_profiles)%i_index = ri0
Profiles(num_profiles)%j_index = rj0
else ! tripolar grids
lon_out(1,1) = lon*DEG_TO_RAD
lat_out(1,1) = lat*DEG_TO_RAD
call horiz_interp_bilinear_new (Interp, x_grid*DEG_TO_RAD, y_grid*DEG_TO_RAD, lon_out, lat_out)
if ( Interp%wti(1,1,2) < 1.0 ) then
i0 = Interp%i_lon(1,1,1)
else
i0 = Interp%i_lon(1,1,2)
end if
if ( Interp%wtj(1,1,2) < 1.0 ) then
j0 = Interp%j_lat(1,1,1)
else
j0 = Interp%j_lat(1,1,2)
end if
if ( i0 > ieg .or. j0 > jeg ) then
write (UNIT=emsg_local, FMT='("i0 = ",I8,", j0 = ",I8)') i0, j0
call error_mesg('oda_core_mod::open_profile_dataset_woa05t',&
& 'For tripolar grids, either i0 > ieg or j0 > jeg. '//trim(emsg_local), FATAL)
end if
if ( i0 < isd_filt .or. i0 > ied_filt .or. j0 < jsd_filt .or. j0 > jed_filt ) then
write (UNIT=stdout_unit, FMT='("woat.pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(),i0, j0,isd_filt,ied_filt,jsd_filt,jed_filt
out_bound_point = out_bound_point + 1
end if
if ( Interp%wti(1,1,2) < 1.0 ) then
Profiles(num_profiles)%i_index =Interp%i_lon(1,1,1) + Interp%wti(1,1,2)
else
Profiles(num_profiles)%i_index =Interp%i_lon(1,1,2)
end if
if ( Interp%wtj(1,1,2) < 1.0 ) then
Profiles(num_profiles)%j_index =Interp%j_lat(1,1,1) + Interp%wtj(1,1,2)
else
Profiles(num_profiles)%j_index =Interp%j_lat(1,1,2)
end if
end if ! grids
Profiles(num_profiles)%accepted = .true.
if ( i0 < 1 .or. j0 < 1 ) then
Profiles(num_profiles)%accepted = .false.
end if
if ( i0 < isd_filt .or. i0 >= ied_filt .or. j0 < jsd_filt .or. j0 >= jed_filt ) then
Profiles(num_profiles)%accepted = .false.
end if
if ( Profiles(num_profiles)%accepted ) then ! here
if ( i0 /= ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(i0+1,j0,1) == 0.0 .or.&
& Grd%mask(i0,j0+1,1) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
else if ( i0 == ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(1,j0,1) == 0.0 .or.&
& Grd%mask(i0,j0+1,1) == 0.0 .or.&
& Grd%mask(1,j0+1,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if ( Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(i0+1,j0,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
else
if ( Grd%mask(i0,j0,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
end if
end if ! here
if ( Profiles(num_profiles)%accepted ) then ! accepted
Profiles(num_profiles)%flag(:) = .true.
allocate(Profiles(num_profiles)%k_index(Profiles(num_profiles)%levels))
do k=1, Profiles(num_profiles)%levels
if (depth(k) < Grd%z(1)) then
Profiles(num_profiles)%k_index(k) = 0.0
else
Profiles(num_profiles)%k_index(k) = frac_index(depth(k), (/0.,Grd%z(:)/)) - 1.0 ! snz modify to v3.2 JAN3012
end if
if ( Profiles(num_profiles)%k_index(k) > nk ) then
call error_mesg('oda_core_mod::open_profile_dataset_woa05t',&
& 'Profile k_index is greater than nk', FATAL)
end if
k0 = floor(Profiles(num_profiles)%k_index(k))
if ( k0 >= 1 ) then ! snz add
if ( Profiles(num_profiles)%flag(k) ) then ! flag
if ( i0 /= ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 == ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(1,j0,k0) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0) == 0.0 .or.&
& Grd%mask(1,j0+1,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else
if ( Grd%mask(i0,j0,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if
if ( i0 /= ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 == ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(1,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0+1) == 0.0 .or.&
& Grd%mask(1,j0+1,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0+1) == 0.0) then
Profiles(num_profiles)%flag(k) = .false.
end if
else
if ( Grd%mask(i0,j0,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if
if ( abs(Profiles(num_profiles)%data(k)) > 1.e4 &
& .or. abs(Profiles(num_profiles)%depth(k)) > 1.e4 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if ! flag
end if ! snz add
end do
end if ! accepted
end if ! localize
end if ! global index
end do
end do
call mpp_close(unit)
deallocate(axes)
write (UNIT=stdout_unit, FMT='("A grand total of ",I8," woa05t points within global domain")') no_woa05
write (UNIT=stdout_unit, FMT='("A final total @woa05t of ",I8," prfs within global domain")') num_profiles
! call mpp_print_memuse_stats('open_profile_dataset_woa05t End')
end subroutine open_profile_dataset_woa05t
subroutine open_profile_dataset_woa05s(filename, obs_variable, localize)
character(len=*), intent(in) :: filename
integer, intent(in) :: obs_variable
logical, intent(in), optional :: localize
integer, parameter :: MAX_LEVELS = 24
real :: lon, lat, rms_err
real :: ri0, rj0
real, dimension(MAX_LEVELS) :: depth, data
integer :: unit, ndim, nvar, natt, ntime
integer :: var_id, inst_type
integer :: num_levs, k, kk, i, j, i0, j0, k0
integer :: stdout_unit
integer :: out_bound_point
logical :: data_is_local, localize_data
logical :: prof_in_filt_domain
logical, dimension(MAX_LEVELS) :: flag
character(len=32) :: axisname, anal_fldname
character(len=128) :: emsg_local
type(axistype), dimension(:), allocatable, target :: axes
type(axistype), pointer :: lon_axis, lat_axis, z_axis
if ( present(localize) ) then
localize_data = localize
else
localize_data = .true.
end if
stdout_unit = stdout()
anal_fldname = 'salt'
var_id = obs_variable
! call mpp_print_memuse_stats('open_profile_dataset_woa05s Start')
call mpp_open(unit, trim(filename), MPP_RDONLY, MPP_NETCDF, threading=MPP_MULTI, fileset=MPP_SINGLE)
write (UNIT=stdout_unit, FMT='("Opened profile woa05s dataset: ",A)') trim(filename)
call mpp_get_info(unit, ndim, nvar, natt, ntime)
allocate(axes(ndim))
call mpp_get_axes(unit, axes)
do i=1, ndim
call mpp_get_atts(axes(i), name=axisname)
select case ( trim(axisname) )
case ('lon')
lon_axis => axes(i)
case ('lat')
lat_axis => axes(i)
case ('depth')
z_axis => axes(i)
end select
end do
call mpp_get_atts(lon_axis, len=nlon_woa)
call mpp_get_atts(lat_axis, len=nlat_woa)
call mpp_get_atts(z_axis, len=nlev_woa)
if ( nlon_woa /= 360 .or. nlat_woa /= 180 ) then
write (UNIT=emsg_local, FMT='("woa05 obs dim is not same as in file nlon_woa = ",I8,", nlat_woa = ",I8)') nlon_woa, nlat_woa
call error_mesg('oda_core_mod::open_profile_dataset_woa05s', trim(emsg_local), FATAL)
end if
out_bound_point = 0
! idealized
do j=1, nlat_woa
do i=1, nlon_woa
lon = woa05_lon(i)
lat = woa05_lat(j)
rms_err = 5
inst_type = 20
data_is_local = .true.
prof_in_filt_domain = .false.
if ( lon .lt. 0.0 ) lon = lon + 360.0
if ( lon .gt. 360.0 ) lon = lon - 360.0
if ( lon .lt. 80.0 ) lon = lon + 360.0
if ( lat < -80.0 .or. lat > 80.0 ) data_is_local = .false.
if ( abs(lat) < 20.0 .and. (mod(i,2) /= 0 .or. mod(j,2) /= 0) ) data_is_local = .false.
if ( abs(lat) >= 20.0 .and. (mod(i,4) /= 0 .or. mod(j,4) /= 0) ) data_is_local = .false.
if ( abs(lat) >= 60.0 .and. (mod(i,6) /= 0 .or. mod(j,6) /= 0) ) data_is_local = .false.
if (isd_filt < 1 .and. ied_filt > ieg) then
! filter domain is a full x band
if (lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ieg-1,jsd_flt0)) then
prof_in_filt_domain = .true.
end if
else if (isd_filt >= 1 .and. ied_filt <= ieg) then
! Interior filter domain
if (lon >= x_grid(isd_filt,jsd_flt0) .and. lon <= x_grid(ied_filt-1,jsd_flt0) .and.&
& lat >= y_grid(isd_filt,jsd_flt0) .and. lat <= y_grid(ied_filt-1,jed_flt0-1)) then
prof_in_filt_domain = .true.
end if
else if (isd_filt < 1 .and. ied_filt <= ieg) then
! lhs filter domain
isd_flt0 = isd_filt + ieg
if ((lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ied_filt-1,jsd_flt0) .and.&
& lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ied_filt-1,jed_flt0-1)).or.&
& (lon >= x_grid(isd_flt0,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
& lat >= y_grid(isd_flt0,jsd_flt0) .and. lat <= y_grid(ieg-1,jed_flt0-1))) then
prof_in_filt_domain = .true.
end if
else if (isd_filt >= 1 .and. ied_filt > ieg) then
! rhs filter domain
ied_flt0 = ied_filt - ieg
if ( lon >= x_grid(isd_filt,jsd_flt0) .and. lon <= x_grid(ieg-1,jsd_flt0) .and.&
& lat >= y_grid(isd_filt,jsd_flt0) .and. lat <= y_grid(ieg-1,jed_flt0-1) ) then
prof_in_filt_domain = .true.
end if
if (ied_flt0-1 > 1) then
if ( lon >= x_grid(1,jsd_flt0) .and. lon <= x_grid(ied_flt0-1,jsd_flt0) .and.&
& lat >= y_grid(1,jsd_flt0) .and. lat <= y_grid(ied_flt0-1,jed_flt0-1) ) then
prof_in_filt_domain = .true.
end if
end if
end if
if ( data_is_local .and. (.NOT.localize_data) ) then ! global index
no_woa05 = no_woa05 + 1
num_profiles=num_profiles + 1
if ( num_profiles > max_profiles ) then
call error_mesg('oda_core_mod::open_profile_dataset_woa05s',&
& 'Maximum number of profiles exceeded, increase max_profiles in oda_core_nml.', FATAL)
end if
num_levs = 0
flag = .false.
do k=1, nlev_woa
flag(k) = .true.
data(k) = 0.0
depth(k) = woa05_z(k)
num_levs = num_levs + 1
end do
if ( num_levs == 0 ) cycle
if ( prof_in_filt_domain ) then ! localize
allocate(profiles(num_profiles)%depth(num_levs))
allocate(profiles(num_profiles)%data(num_levs))
allocate(profiles(num_profiles)%flag(num_levs))
! allocate(profiles(num_profiles)%ms(num_levs))
! allocate(profiles(num_profiles)%ms_inv(num_levs))
profiles(num_profiles)%variable = var_id
profiles(num_profiles)%inst_type = inst_type
profiles(num_profiles)%levels = num_levs
profiles(num_profiles)%lat = lat
profiles(num_profiles)%lon = lon
kk = 1
do k=1, nlev_woa
if ( flag(k) ) then
profiles(num_profiles)%depth(kk) = depth(k)
profiles(num_profiles)%data(kk) = data(k)
! profiles(num_profiles)%ms(kk) = 1.0
! profiles(num_profiles)%ms_inv(kk) = 1.0
kk = kk + 1
end if
end do
! calculate interpolation coefficients (make sure to account for grid offsets here!)
if ( lat < 65.0 ) then ! regular grids
ri0 = frac_index(lon, x_grid(:,1))
rj0 = frac_index(lat, y_grid(90,:))
i0 = floor(ri0)
j0 = floor(rj0)
if ( i0 > ieg .or. j0 > jeg ) then
write (UNIT=emsg_local, FMT='("i0 = ",I8,", j0 = ",I8)') i0, j0
call error_mesg('oda_core_mod::open_profile_dataset_woa05s',&
& 'For regular grids, either i0 > ieg or j0 > jeg. '//trim(emsg_local), FATAL)
end if
if ( isd_filt >= 1 .and. ied_filt <= ieg ) then
if ( i0 < isd_filt .or. i0 > ied_filt .or. j0 < jsd_filt .or. j0 > jed_filt ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in woas01. '//trim(emsg_local), FATAL)
end if
end if
if ( isd_filt < 1 .and. i0 > ied_filt-1 .and. i0 < isd_filt + ieg ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in woas02. '//trim(emsg_local), FATAL)
end if
if ( ied_filt > ieg .and. i0 > ied_filt-ieg-1 .and. ied_filt < isd_filt ) then
write (UNIT=emsg_local, FMT='("pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(), i0, j0, isd_filt,ied_filt,jsd_filt,jed_filt
call error_mesg('oda_core_mod::open_profile_dataset',&
& 'i0,j0 out of bounds in woas03. '//trim(emsg_local), FATAL)
end if
Profiles(num_profiles)%i_index = ri0
Profiles(num_profiles)%j_index = rj0
else ! tripolar grids
lon_out(1,1) = lon*DEG_TO_RAD
lat_out(1,1) = lat*DEG_TO_RAD
call horiz_interp_bilinear_new (Interp, x_grid*DEG_TO_RAD, y_grid*DEG_TO_RAD, lon_out, lat_out)
if ( Interp%wti(1,1,2) < 1.0 ) then
i0 = Interp%i_lon(1,1,1)
else
i0 = Interp%i_lon(1,1,2)
end if
if ( Interp%wtj(1,1,2) < 1.0 ) then
j0 = Interp%j_lat(1,1,1)
else
j0 = Interp%j_lat(1,1,2)
end if
if ( i0 > ieg .or. j0 > jeg ) then
write (UNIT=emsg_local, FMT='("i0 = ",I8,", j0 = ",I8)') i0, j0
call error_mesg('oda_core_mod::open_profile_dataset_woa05s',&
& 'For tripolar grids, either i0 > ieg or j0 > jeg. '//trim(emsg_local), FATAL)
end if
if ( i0 < isd_filt .or. i0 > ied_filt .or. j0 < jsd_filt .or. j0 > jed_filt ) then
write (UNIT=stdout_unit, FMT='("woas.pe,i0,j0= ",3I8,"isd_filt,ied_filt,jsd_filt,jed_filt= ",4I8)')&
& mpp_pe(),i0, j0,isd_filt,ied_filt,jsd_filt,jed_filt
out_bound_point = out_bound_point + 1
end if
if ( Interp%wti(1,1,2) < 1.0 ) then
Profiles(num_profiles)%i_index =Interp%i_lon(1,1,1) + Interp%wti(1,1,2)
else
Profiles(num_profiles)%i_index =Interp%i_lon(1,1,2)
end if
if ( Interp%wtj(1,1,2) < 1.0 ) then
Profiles(num_profiles)%j_index =Interp%j_lat(1,1,1) + Interp%wtj(1,1,2)
else
Profiles(num_profiles)%j_index =Interp%j_lat(1,1,2)
end if
end if ! grids
Profiles(num_profiles)%accepted = .true.
if ( i0 < 1 .or. j0 < 1 ) then
Profiles(num_profiles)%accepted = .false.
end if
if ( i0 < isd_filt .or. i0 >= ied_filt .or. j0 < jsd_filt .or. j0 >= jed_filt ) then
Profiles(num_profiles)%accepted = .false.
end if
if ( Profiles(num_profiles)%accepted ) then ! here
if ( i0 /= ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(i0+1,j0,1) == 0.0 .or.&
& Grd%mask(i0,j0+1,1) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
else if ( i0 == ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(1,j0,1) == 0.0 .or.&
& Grd%mask(i0,j0+1,1) == 0.0 .or.&
& Grd%mask(1,j0+1,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if ( Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(i0+1,j0,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
else
if ( Grd%mask(i0,j0,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
end if
end if ! here
if ( Profiles(num_profiles)%accepted ) then ! accepted
Profiles(num_profiles)%flag(:) = .true.
allocate(Profiles(num_profiles)%k_index(Profiles(num_profiles)%levels))
do k=1, Profiles(num_profiles)%levels
if (depth(k) < Grd%z(1)) then
Profiles(num_profiles)%k_index(k) = 0.0
else
Profiles(num_profiles)%k_index(k) = frac_index(depth(k), (/0.,Grd%z(:)/)) - 1.0 ! snz modify to v3.2 JAN3012
end if
if ( Profiles(num_profiles)%k_index(k) > nk ) then
call error_mesg('oda_core_mod::open_profile_dataset_woa05s',&
& 'Profile k_index is greater than nk', FATAL)
end if
k0 = floor(Profiles(num_profiles)%k_index(k))
if ( k0 >= 1 ) then ! snz add
if ( Profiles(num_profiles)%flag(k) ) then ! flag
if ( i0 /= ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 == ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(1,j0,k0) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0) == 0.0 .or.&
& Grd%mask(1,j0+1,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if ( Grd%mask(i0,j0,k0) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else
if ( Grd%mask(i0,j0,k0) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if
if ( i0 /= ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
elseif ( i0 == ieg .and. j0 /= jeg ) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(1,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0,j0+1,k0+1) == 0.0 .or.&
& Grd%mask(1,j0+1,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else if ( i0 /= ieg .and. j0 == jeg ) then
if ( Grd%mask(i0,j0,k0+1) == 0.0 .or.&
& Grd%mask(i0+1,j0,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
else
if ( Grd%mask(i0,j0,k0+1) == 0.0 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if
if ( abs(Profiles(num_profiles)%data(k)) > 1.e4 &
& .or. abs(Profiles(num_profiles)%depth(k)) > 1.e4 ) then
Profiles(num_profiles)%flag(k) = .false.
end if
end if ! flag
end if ! snz add
end do
end if ! accepted
end if ! localize
end if ! global index
end do
end do
call mpp_close(unit)
deallocate(axes)
write (UNIT=stdout_unit, FMT='("A grand total of ",I8," woa05s points within global domain")') no_woa05
write (UNIT=stdout_unit, FMT='("A final total @woa05s of ",I8," prfs within global domain")') num_profiles
! call mpp_print_memuse_stats('open_profile_dataset_woa05s Ens')
end subroutine open_profile_dataset_woa05s
subroutine get_obs_sst(model_time, Prof, nprof, no_prf0, sst_climo, Filter_domain)
type(time_type), intent(in) :: model_time
type(ocean_profile_type), dimension(:), intent(inout) :: Prof
integer, intent(inout) :: nprof
integer, intent(in) :: no_prf0
type(obs_clim_type), intent(inout) :: sst_climo
type(domain2d), intent(in) :: Filter_domain
integer :: i0, j0, i, days, seconds, days1, seconds1
integer :: unit, ndim, nvar, natt, ntime, time_idx
integer :: iy0, in0, id0, ih0, im0, is0, i_m
integer :: stdout_unit, istat
integer, dimension(12) :: n_days
integer, save :: year_on_first_read = 0 !< Year on first read of file during
!! module run
character(len=128) :: sst_filename, emsg_local
type(fieldtype), dimension(:), allocatable :: fields
type(time_type) :: tdiff, sst_time0, time1
n_days = (/31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/)
nprof = 0
stdout_unit = stdout()
call get_time(model_time, seconds, days)
call get_date(model_time, iy0, in0, id0, ih0, im0, is0)
if ( year_on_first_read == 0 ) then
year_on_first_read = iy0
end if
time1=set_date(year_on_first_read, 1, 1, 0, 0, 0)
call get_time(time1, seconds1, days1)
time_idx = days-days1+1
! daily data
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("time_idx = ",I8)') time_idx
end if
sst_filename = "INPUT/sst_daily.nc"
call mpp_open(unit, trim(sst_filename), MPP_RDONLY, MPP_NETCDF, threading=MPP_MULTI, fileset=MPP_SINGLE)
call mpp_get_info(unit, ndim, nvar, natt, ntime)
allocate(fields(nvar), STAT=istat)
if ( istat .ne. 0 ) then
call error_mesg('oda_core_mod::get_obs_sst', 'Unable to allocate fields', FATAL)
end if
call mpp_get_fields(unit, fields)
do i=1, nvar
select case ( mpp_get_field_name(fields(i)) )
case ('SST1') ! for AVHRR daily SST
call mpp_read(unit, fields(i), Filter_domain, sst_climo%sst_obs, tindex=time_idx)
end select
end do
! get profiles and sst
! obs relevant to current analysis interval
sst_time0 = set_date(iy0, in0, id0, ih0, im0, is0)
if ( no_sst > 1 ) then
do i=no_prf+no_woa05+1, no_prf+no_woa05+no_sst
Profiles(i)%time = sst_time0
tdiff = model_time - Profiles(i)%time
i0 = floor(Profiles(i)%i_index)
if ( i0 < 1 .or. i0 > 1440 ) then
write (UNIT=emsg_local, FMT='("Profiles(",I8,")%lon = ",I4,", i0 = ",I8)') i, Profiles(i)%lon, i0
call error_mesg('oda_core_mod::get_obs_sst',&
& 'Profile longitude index outside range [1,1440]. '//trim(emsg_local), FATAL)
end if
j0 = floor(Profiles(i)%j_index)
if ( j0 < 1 .or. j0 > 1070 ) then
write (UNIT=emsg_local, FMT='("Profiles(",I8,")%lat = ",I4,", j0 = ",I8)') i, Profiles(i)%lon, j0
call error_mesg('oda_core_mod::get_obs_sst',&
& 'Profile latitude index outside range [1,1070]. '//trim(emsg_local), FATAL)
end if
if ( Profiles(i)%accepted ) then
nprof = nprof + 1
if ( nprof > size(Prof,1) ) then
call error_mesg('oda_core_mod::get_obs_sst',&
& 'Passed in array "Prof" is smaller than number of profiles, increase size of Prof before call.',&
& FATAL)
end if
call copy_obs(Profiles(i:i), Prof(no_prf0+nprof:no_prf0+nprof))
Prof(nprof+no_prf0)%tdiff = tdiff
end if
end do
end if ! for no_sst > 1
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("no of sst records: ",I8)') nprof
end if
deallocate(fields)
call mpp_close(unit)
end subroutine get_obs_sst
subroutine get_obs_woa05t(model_time, Prof, nprof, no_prf0)
type(time_type), intent(in) :: model_time
type(ocean_profile_type), dimension(:), intent(inout) :: Prof
integer, intent(inout) :: nprof
integer, intent(in) :: no_prf0
real :: ri0, rj0, lon_woa05
integer :: i0, j0
integer :: i, k, unit, time_idx
integer :: iy0, in0, id0, ih0, im0, is0
integer :: ndim, nvar, natt, ntime
integer :: stdout_unit, istat
character(len=32) :: axisname
character(len=128) :: woa05t_filename
type(fieldtype), dimension(:), allocatable :: fields
type(time_type) :: tdiff, woa05_time0
nprof = 0
stdout_unit = stdout()
call get_date(model_time, iy0, in0, id0, ih0, im0, is0)
time_idx = in0
! daily data
woa05t_filename = "INPUT/woa05_temp.nc"
call mpp_open(unit, trim(woa05t_filename), MPP_RDONLY, MPP_NETCDF, threading=MPP_MULTI, fileset=MPP_SINGLE)
call mpp_get_info(unit, ndim, nvar, natt, ntime)
allocate(fields(nvar), STAT=istat)
if ( istat .ne. 0 ) then
call error_mesg('oda_core_mod::get_obs_woa05t', 'Unable to allocate fields', FATAL)
end if
call mpp_get_fields(unit, fields)
allocate(obs_woa05t(nlon_woa,nlat_woa,nlev_woa))
do i=1, nvar
select case ( mpp_get_field_name(fields(i)) )
case ('t0112an1')
call mpp_read(unit, fields(i), obs_woa05t, tindex=time_idx)
end select
end do
woa05_time0 = set_date(iy0, in0, id0, ih0, im0, is0)
do i=no_prf+1, no_prf+no_woa05/2
Profiles(i)%time = woa05_time0
tdiff = model_time - Profiles(i)%time
lon_woa05 = Profiles(i)%lon
if ( lon_woa05 < 0.0 ) lon_woa05 = lon_woa05 + 360.0
if ( lon_woa05 > 360.0 ) lon_woa05 = lon_woa05 - 360.0
ri0 = frac_index(lon_woa05, woa05_lon)
i0 = floor(ri0)
if ( i0 < 1 ) i0 = 1
if ( i0 > nlon_woa ) i0 = nlon_woa
rj0 = frac_index(Profiles(i)%lat, woa05_lat)
j0 = floor(rj0)
if(j0 < 1 ) j0 = 1
if(j0 > nlat_woa) j0 = nlat_woa
if ( Profiles(i)%accepted ) then
nprof = nprof + 1
if ( nprof > size(Prof,1) ) then
call error_mesg('oda_core_mod::get_obs_woa05t',&
& 'Passed in array "Prof" is smaller than number of profiles, increase size of Prof before call.',&
& FATAL)
end if
Profiles(i)%data(1:nlev_woa) = obs_woa05t(i0,j0,1:nlev_woa)
do k=1, nlev_woa
if ( abs(Profiles(i)%data(k)) > 1.e3 .or.&
& abs(Profiles(i)%depth(k)) > 1.e5 ) then
Profiles(i)%flag(k) = .false.
end if
end do
call copy_obs(Profiles(i:i), Prof(no_prf0+nprof:no_prf0+nprof))
Prof(no_prf0+nprof)%tdiff = tdiff
end if
end do
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("no of woa05t records: ",I8)') nprof
end if
deallocate(fields, obs_woa05t)
call mpp_close(unit)
end subroutine get_obs_woa05t
subroutine get_obs_woa05s(model_time, Prof, nprof, no_prf0)
type(time_type), intent(in) :: model_time
type(ocean_profile_type), dimension(:), intent(inout) :: Prof
integer, intent(inout) :: nprof
integer, intent(in) :: no_prf0
real :: ri0, rj0, lon_woa05
integer :: i0, j0
integer :: i, k, unit, time_idx
integer :: iy0, in0, id0, ih0, im0, is0
integer :: ndim, nvar, natt, ntime
integer :: stdout_unit, istat
character(len=128) :: woa05s_filename
type(fieldtype), dimension(:), allocatable :: fields
type(time_type) :: tdiff, woa05_time0
nprof = 0
stdout_unit = stdout()
call get_date(model_time, iy0,in0,id0,ih0,im0,is0)
time_idx = in0
! climatological data
woa05s_filename = "INPUT/woa05_salt.nc"
call mpp_open(unit, trim(woa05s_filename), MPP_RDONLY, MPP_NETCDF, threading=MPP_MULTI, fileset=MPP_SINGLE)
call mpp_get_info(unit, ndim, nvar, natt, ntime)
allocate(fields(nvar), STAT=istat)
if ( istat .ne. 0 ) then
call error_mesg('oda_core_mod::get_obs_woa05s', 'Unable to allocate fields', FATAL)
end if
call mpp_get_fields(unit, fields)
allocate(obs_woa05s(nlon_woa,nlat_woa,nlev_woa))
do i=1, nvar
select case ( mpp_get_field_name(fields(i)) )
case ('s0112an1')
call mpp_read(unit, fields(i), obs_woa05s, tindex=time_idx)
end select
end do
woa05_time0 = set_date(iy0, in0, id0, ih0, im0, is0)
do i=no_prf+no_woa05/2+1, no_prf+no_woa05
Profiles(i)%time = woa05_time0
tdiff = model_time - Profiles(i)%time
lon_woa05 = Profiles(i)%lon
if ( lon_woa05 < 0.0 ) lon_woa05 = lon_woa05 + 360.0
if ( lon_woa05 > 360.0 ) lon_woa05 = lon_woa05 - 360.0
ri0 = frac_index(lon_woa05, woa05_lon)
i0 = floor(ri0)
if ( i0 < 1 ) i0 = 1
if ( i0 > nlon_woa ) i0 = nlon_woa
rj0 = frac_index(Profiles(i)%lat, woa05_lat)
j0 = floor(rj0)
if ( j0 < 1 ) j0 = 1
if ( j0 > nlat_woa ) j0 = nlat_woa
if ( Profiles(i)%accepted ) then
nprof = nprof + 1
if ( nprof > size(Prof,1) ) then
call error_mesg('oda_core_mod::get_obs_woa05s',&
& 'Passed in array "Prof" is smaller than number of profiles, increase size of Prof before call',&
& FATAL)
end if
Profiles(i)%data(1:nlev_woa) = obs_woa05s(i0,j0,1:nlev_woa)
do k=1, nlev_woa
if ( abs(Profiles(i)%data(k)) > 1.e3 .or.&
& abs(Profiles(i)%depth(k)) > 1.e5 ) then
Profiles(i)%flag(k) = .false.
end if
end do
call copy_obs(Profiles(i:i),Prof(no_prf0+nprof:no_prf0+nprof))
Prof(no_prf0+nprof)%tdiff = tdiff
end if
end do
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("no of woa05t records: ",I8)') nprof
end if
deallocate(fields, obs_woa05s)
call mpp_close(unit)
end subroutine get_obs_woa05s
subroutine open_profile_dataset_eta(filename, obs_variable, localize)
character(len=*), intent(in) :: filename
integer, intent(in) :: obs_variable
logical, intent(in), optional :: localize
integer, parameter :: MAX_LEVELS = 1000
real :: lon, lat, rms_err
real :: ri0, rj0
real, dimension(MAX_LEVELS) :: depth, data
integer :: inst_type, var_id
integer :: num_levs, k, kk, i, j, i0, j0
integer :: stdout_unit
logical :: data_is_local, localize_data
logical, dimension(MAX_LEVELS) :: flag
character(len=32) :: anal_fldname
if ( PRESENT(localize) ) then
localize_data = localize
else
localize_data = .true.
end if
stdout_unit = stdout()
anal_fldname = 'eta'
var_id = obs_variable
!snz idealized
do j=1, size(x_grid, dim=1)
do i=1, size(x_grid, dim=2)
lon = x_grid(i,j)
lat = y_grid(i,j)
rms_err = 0.5
inst_type = 20
data_is_local = .true.
if ( lon .lt. 0.0 ) lon = lon + 360.0
if ( lon .gt. 360.0 ) lon = lon - 360.0
if ( lon .lt. 80.0 ) lon = lon + 360.0
if ( lat < eta_obs_start_lat .or. lat > eta_obs_end_lat ) data_is_local = .false.
if ( abs(lat) < 20.0 .and.&
& (mod(floor(lon),2) /= 0 .or. mod(floor(lat),2) /= 0) ) data_is_local = .false.
if ( (abs(lat) >= 20.0 .and. abs(lat) < 40.0) .and.&
& (mod(floor(lon),4) /= 0 .or. mod(floor(lat),4) /= 0) ) data_is_local = .false.
if ( (abs(lat) >= 40.0) .and.&
& (mod(floor(lon),6) /= 0 .or. mod(floor(lat),6) /= 0) ) data_is_local = .false.
if ( data_is_local .and. (.NOT.localize_data) ) then
ri0 = frac_index(lon, x_grid(:,1))
rj0 = frac_index(lat, y_grid(90,:))
i0 = floor(ri0)
j0 = floor(rj0)
if ( Grd%mask(i0,j0,1) /= 0.0 .and. Grd%mask(i0+1,j0,1) /= 0.0 .and.&
& Grd%mask(i0,j0+1,1) /= 0.0 .and. Grd%mask(i0+1,j0+1,1) /= 0.0 ) then
no_eta = no_eta+1
num_profiles=num_profiles+1
if ( num_profiles > max_profiles ) then
call error_mesg('oda_core_mod::open_profile_dataset_eta',&
& 'Maximum number of profiles exceeded, increase max_profiles in oda_core_nml.', FATAL)
end if
num_levs = 0
flag = .false.
do k=1, 1
flag(k) = .true.
data(k) = 0.0
depth(k) = 0.0
num_levs = num_levs+1
end do
if ( num_levs == 0 ) cycle
allocate(profiles(num_profiles)%depth(num_levs))
allocate(profiles(num_profiles)%data(num_levs))
allocate(profiles(num_profiles)%flag(num_levs))
allocate(profiles(num_profiles)%ms(num_levs))
allocate(profiles(num_profiles)%ms_inv(num_levs))
profiles(num_profiles)%variable = var_id
profiles(num_profiles)%inst_type = inst_type
profiles(num_profiles)%levels = num_levs
profiles(num_profiles)%lat = lat
profiles(num_profiles)%lon = lon
kk = 1
do k=1, 1
if ( flag(k) ) then
profiles(num_profiles)%depth(kk) = depth(k)
profiles(num_profiles)%data(kk) = data(k)
profiles(num_profiles)%ms(kk) = 1.0
profiles(num_profiles)%ms_inv(kk) = 1.0
kk = kk + 1
end if
end do
! calculate interpolation coefficients (make sure to account for grid offsets here!)
Profiles(num_profiles)%i_index = ri0
Profiles(num_profiles)%j_index = rj0
Profiles(num_profiles)%accepted = .true.
if ( i0 < 1 .or. j0 < 1 ) then
Profiles(num_profiles)%accepted = .false.
end if
if ( Profiles(num_profiles)%accepted ) then
if ( Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(i0+1,j0,1) == 0.0 .or.&
& Grd%mask(i0,j0+1,1) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
end if
if ( Profiles(num_profiles)%accepted ) then
Profiles(num_profiles)%flag(:) = .true.
allocate(Profiles(num_profiles)%k_index(Profiles(num_profiles)%levels))
do k=1, Profiles(num_profiles)%levels
if (depth(k) < Grd%z(1)) then
Profiles(num_profiles)%k_index(k) = 0.0
else
Profiles(num_profiles)%k_index(k) = frac_index(depth(k), (/0.,Grd%z(:)/)) - 1
end if
if ( Profiles(num_profiles)%k_index(k) < 1.0 ) Profiles(num_profiles)%flag(k) = .false.
end do
end if
end if
end if
end do
end do
write (UNIT=stdout_unit, FMT='("A grand total of ",I8," eta points within global domain")') no_eta
write (UNIT=stdout_unit, FMT='("A final total @eta of ",I8," prfs within global domain")') num_profiles
end subroutine open_profile_dataset_eta
subroutine open_profile_dataset_suv(filename, obs_variable, localize)
character(len=*), intent(in) :: filename
integer, intent(in) :: obs_variable
logical, intent(in), optional :: localize
integer, parameter :: MAX_LEVELS = 1000
real :: ri0, rj0
real :: lon, lat, rms_err
real, dimension(MAX_LEVELS) :: depth, data
integer :: inst_type, var_id
integer :: num_levs, k, kk, i, j, i0, j0
integer :: stdout_unit
logical :: data_is_local, localize_data
logical, dimension(MAX_LEVELS) :: flag
character(len=32) :: anal_fldname
if ( PRESENT(localize) ) then
localize_data = localize
else
localize_data = .true.
end if
stdout_unit = stdout()
anal_fldname = 'suv'
var_id = obs_variable
!snz idealized
do j=1, size(x_grid_uv,dim=1)
do i=1, size(x_grid_uv,dim=2)
lon = x_grid_uv(i,j)
lat = y_grid_uv(i,j)
rms_err = 0.5
inst_type = 20
data_is_local = .true.
if ( lon .lt. 0.0 ) lon = lon + 360.0
if ( lon .gt. 360.0 ) lon = lon - 360.0
if ( lon .lt. 80.0 ) lon = lon + 360.0
if ( lat < -40.0 .or. lat > 40.0 ) data_is_local = .false.
if ( abs(lat) < 20.0 .and.&
& (mod(floor(lon),2) /= 0 .or. mod(floor(lat),2) /= 0) ) data_is_local = .false.
if ( (abs(lat) >= 20.0 .and. abs(lat) < 40.0) .and.&
& (mod(floor(lon),4) /= 0 .or. mod(floor(lat),4) /= 0) ) data_is_local = .false.
if ( (abs(lat) >= 40.0) .and.&
& (mod(floor(lon),6) /= 0 .or. mod(floor(lat),6) /= 0) ) data_is_local = .false.
if ( data_is_local .and. (.NOT.localize_data) ) then
ri0 = frac_index(lon, x_grid_uv(:,1))
rj0 = frac_index(lat, y_grid_uv(90,:))
i0 = floor(ri0)
j0 = floor(rj0)
if ( Grd%mask(i0,j0,1) /= 0.0 .and. Grd%mask(i0+1,j0,1) /= 0.0 .and.&
& Grd%mask(i0,j0+1,1) /= 0.0 .and. Grd%mask(i0+1,j0+1,1) /= 0.0 ) then
no_suv = no_suv+1
num_profiles = num_profiles + 1
if ( num_profiles > max_profiles ) then
call error_mesg('oda_core_mod::open_profile_dataset_suv',&
& 'Maximum number of profiles exceeded, increase max_profiles in oda_core_nml.', FATAL)
end if
num_levs = 0
flag = .false.
do k=1, 2
flag(k) = .true.
data(k) = 0.0
depth(k) = 0.0
num_levs = num_levs + 1
end do
if ( num_levs == 0 ) cycle
allocate(profiles(num_profiles)%depth(num_levs))
allocate(profiles(num_profiles)%data(num_levs))
allocate(profiles(num_profiles)%flag(num_levs))
allocate(profiles(num_profiles)%ms(num_levs))
allocate(profiles(num_profiles)%ms_inv(num_levs))
profiles(num_profiles)%variable = var_id
profiles(num_profiles)%inst_type = inst_type
profiles(num_profiles)%levels = num_levs
profiles(num_profiles)%lat = lat
profiles(num_profiles)%lon = lon
kk = 1
do k=1, 2
if ( flag(k) ) then
profiles(num_profiles)%depth(kk) = depth(k)
profiles(num_profiles)%data(kk) = data(k)
profiles(num_profiles)%ms(kk) = 1.0
profiles(num_profiles)%ms_inv(kk) = 1.0
kk = kk + 1
end if
end do
! calculate interpolation coefficients (make sure to account for grid offsets here!)
Profiles(num_profiles)%i_index = ri0
Profiles(num_profiles)%j_index = rj0
Profiles(num_profiles)%accepted = .true.
if ( i0 < 1 .or. j0 < 1 ) then
Profiles(num_profiles)%accepted = .false.
end if
if ( Profiles(num_profiles)%accepted ) then
if ( Grd%mask(i0,j0,1) == 0.0 .or.&
& Grd%mask(i0+1,j0,1) == 0.0 .or.&
& Grd%mask(i0,j0+1,1) == 0.0 .or.&
& Grd%mask(i0+1,j0+1,1) == 0.0 ) then
Profiles(num_profiles)%accepted = .false.
end if
end if
if ( Profiles(num_profiles)%accepted ) then
Profiles(num_profiles)%flag(:) = .true.
allocate(Profiles(num_profiles)%k_index(Profiles(num_profiles)%levels))
do k=1, Profiles(num_profiles)%levels
if (depth(k) < Grd%z(1)) then
Profiles(num_profiles)%k_index(k) = 0.0
else
Profiles(num_profiles)%k_index(k) = frac_index(depth(k), (/0.,Grd%z(:)/)) - 1.0 ! snz modify to v3.2 JAN3012
end if
if ( Profiles(num_profiles)%k_index(k) < 1.0 ) Profiles(num_profiles)%flag(k) = .false.
end do
end if
end if
end if
end do
end do
write (UNIT=stdout_unit, FMT='("A grand total of ",I8," suv points within global domain")') no_suv
write (UNIT=stdout_unit, FMT='("A final total @suv of ",I8," prfs within global domain")') num_profiles
end subroutine open_profile_dataset_suv
subroutine get_obs_suv(model_time, Prof, nprof, no_prf0)
type(time_type), intent(in) :: model_time
type(ocean_profile_type), dimension(:), intent(inout) :: Prof
integer, intent(inout) :: nprof
integer, intent(in) :: no_prf0
! get sst data and put into profiles
! only current day
real :: sfc_lon, sfc_lat, ri0, rj0
real, dimension(1440,1070,1) :: sfc_u, sfc_v
integer :: i, k, i_m, i0, j0
integer :: unit, time_idx, ndim, nvar, natt, ntime
integer :: iy0, in0, id0, ih0, im0, is0
integer :: stdout_unit, istat
integer, dimension(12) :: n_days
character(len=80) :: sfc_filename
character(len=256) :: emsg_local
type(fieldtype), dimension(:), allocatable :: fields
type(time_type) :: tdiff, sfc_time0
n_days = (/31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/)
nprof = 0
stdout_unit = stdout()
call get_date(model_time, iy0, in0, id0, ih0, im0, is0)
!monthly
!!$ time_idx = (iy0-1984)*12+in0
! daily
if ( in0 == 1 ) then
time_idx = (iy0-1984)*365 + id0
else
time_idx = 0
do i_m=1, in0-1
time_idx = time_idx + (iy0-1984)*365 + n_days(i_m)
end do
time_idx = time_idx + id0
end if
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("time_idx = ",I8)') time_idx
end if
sfc_time0 = set_date(iy0, in0, id0, ih0, im0, is0)
sfc_filename = "INPUT/sfc_current.198401-198412.nc"
call mpp_open(unit, trim(sfc_filename), MPP_RDONLY, MPP_NETCDF, threading=MPP_MULTI, fileset=MPP_SINGLE)
call mpp_get_info(unit, ndim, nvar, natt, ntime)
allocate(fields(nvar), STAT=istat)
if ( istat .ne. 0 ) then
call error_mesg('oda_core_mod::get_obs_sst', 'Unable to allocate fields', FATAL)
end if
call mpp_get_fields(unit, fields)
do i=1, nvar
select case ( mpp_get_field_name(fields(i)) )
case ('U_SFC')
call mpp_read(unit, fields(i), sfc_u, tindex=time_idx)
case ('V_SFC')
call mpp_read(unit, fields(i), sfc_v, tindex=time_idx)
end select
end do
do i=no_prf+no_sst+no_eta+1, no_prf+no_sst+no_eta+no_suv
Profiles(i)%time = sfc_time0
tdiff = model_time - Profiles(i)%time
sfc_lon = Profiles(i)%lon
ri0 = frac_index(sfc_lon, x_grid_uv(:,1))
i0 = floor(ri0)
if ( i0 < 1 .or. i0 > 1440 ) then
write (UNIT=emsg_local, FMT='("Profiles(",I8,")%lon = ",I4,", i0 = ",I8)') i, Profiles(i)%lon, i0
call error_mesg('oda_core_mod::get_obs_suv',&
& 'Profile longitude index outside range [1,1440]. '//trim(emsg_local), FATAL)
end if
sfc_lat = Profiles(i)%lat
rj0 = frac_index(sfc_lat, y_grid_uv(90,:))
j0 = floor(rj0)
if ( j0 < 1 .or. j0 > 1070 ) then
write (UNIT=emsg_local, FMT='("Profiles(",I8,")%lat = ",I4,", j0 = ",I8)') i, Profiles(i)%lon, j0
call error_mesg('oda_core_mod::get_obs_suv',&
& 'Profile latitude index outside range [1,1070]. '//trim(emsg_local), FATAL)
end if
if ( Profiles(i)%accepted ) then
nprof = nprof + 1
if ( nprof > size(Prof,1) ) then
call error_mesg('oda_core_mod::get_obs_suv',&
& 'Passed in array "Prof" is smaller than number of profiles, increase size of Prof before call',&
& FATAL)
end if
Profiles(i)%data(1) = sfc_u(i0,j0,1)
Profiles(i)%data(2) = sfc_v(i0,j0,1)
call copy_obs(Profiles(i:i),Prof(nprof+no_prf0:nprof+no_prf0))
Prof(nprof+no_prf0)%tdiff = tdiff
end if
end do
deallocate(fields)
call mpp_close(unit)
end subroutine get_obs_suv
subroutine get_obs_eta(model_time, Prof, nprof, no_prf0)
type(time_type), intent(in) :: model_time
type(ocean_profile_type), dimension(:), intent(inout) :: Prof
integer, intent(inout) :: nprof
integer, intent(in) :: no_prf0
! get sst data and put into profiles
! only current day
real :: eta_lon, eta_lat, ri0, rj0
real, dimension(1440,1070) :: eta_t
integer :: i, i0, j0, i_m
integer :: iy0, in0, id0, ih0, im0, is0
integer :: unit, time_idx, ndim, nvar, natt, ntime
integer :: stdout_unit, istat
integer, dimension(12) :: n_days
character(len=80) :: eta_filename
character(len=256) :: emsg_local
type(fieldtype), dimension(:), allocatable :: fields
type(time_type) :: tdiff, sfc_time0
n_days = (/31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/)
nprof = 0
stdout_unit = stdout()
call get_date(model_time, iy0, in0, id0, ih0, im0, is0)
!monthly
!!$ time_idx = (iy0-1984)*12+in0
! daily
if ( in0 == 1 ) then
time_idx = (iy0-1976)*365 + id0 - 1
else
time_idx = 0
do i_m=1, in0-1
time_idx = time_idx + n_days(i_m)
end do
time_idx = (iy0-1976)*365 + time_idx + id0 - 1
end if
if ( mpp_pe() == mpp_root_pe() ) then
write (UNIT=stdout_unit, FMT='("time_idx = ",I8)') time_idx
end if
sfc_time0 = set_date(iy0, in0, id0, ih0, im0, is0)
eta_filename='INPUT/ocean.19760101-20001231.eta_t.nc'
call mpp_open(unit, trim(eta_filename), MPP_RDONLY, MPP_NETCDF, threading=MPP_MULTI, fileset=MPP_SINGLE)
call mpp_get_info(unit, ndim, nvar, natt, ntime)
allocate(fields(nvar), STAT=istat)
if ( istat .ne. 0 ) then
call error_mesg('oda_core_mod::get_obs_sst', 'Unable to allocate fields', FATAL)
end if
call mpp_get_fields(unit, fields)
do i=1, nvar
select case ( mpp_get_field_name(fields(i)) )
case ('eta_t')
call mpp_read(unit, fields(i), eta_t, tindex=time_idx)
end select
end do
do i=no_prf+no_sst+1, no_prf+no_sst+no_eta
Profiles(i)%time = sfc_time0
tdiff = model_time - Profiles(i)%time
eta_lon = Profiles(i)%lon
ri0 = frac_index(eta_lon, x_grid(:,1))
i0 = floor(ri0)
if ( i0 < 1 .or. i0 > 1440 ) then
write (UNIT=emsg_local, FMT='("Profiles(",I8,")%lon = ",I4,", i0 = ",I8)') i, Profiles(i)%lon, i0
call error_mesg('oda_core_mod::get_obs_eta',&
& 'Profile longitude index outside range [1,1440]. '//trim(emsg_local), FATAL)
end if
eta_lat = Profiles(i)%lat
rj0 = frac_index(eta_lat, y_grid(90,:))
j0 = floor(rj0)
if ( j0 < 1 .or. j0 > 1070 ) then
write (UNIT=emsg_local, FMT='("Profiles(",I8,")%lat = ",I4,", j0 = ",I8)') i, Profiles(i)%lon, j0
call error_mesg('oda_core_mod::get_obs_suv',&
& 'Profile latitude index outside range [1,1070]. '//trim(emsg_local), FATAL)
end if
if ( Profiles(i)%accepted ) then
if ( eta_t(i0,j0) > -9.9 ) then !!! excluding missing values
nprof = nprof + 1
if ( nprof > size(Prof,1) ) then
call error_mesg('oda_core_mod::get_obs_eta',&
& 'Passed in array "Prof" is smaller than number of profiles, increase size of Prof before call.',&
& FATAL)
end if
Profiles(i)%data(1) = eta_t(i0,j0)
call copy_obs(Profiles(i:i),Prof(nprof+no_prf0:nprof+no_prf0))
Prof(nprof+no_prf0)%tdiff = tdiff
end if
end if
end do
deallocate(fields)
call mpp_close(unit)
end subroutine get_obs_eta
end module oda_core_ecda_mod
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/spotri.f | 2 | 2646 | SUBROUTINE SPOTRI( UPLO, N, A, LDA, INFO )
*
* -- LAPACK routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* March 31, 1993
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, LDA, N
* ..
* .. Array Arguments ..
REAL A( LDA, * )
* ..
*
* Purpose
* =======
*
* SPOTRI computes the inverse of a real symmetric positive definite
* matrix A using the Cholesky factorization A = U**T*U or A = L*L**T
* computed by SPOTRF.
*
* Arguments
* =========
*
* UPLO (input) CHARACTER*1
* = 'U': Upper triangle of A is stored;
* = 'L': Lower triangle of A is stored.
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* A (input/output) REAL array, dimension (LDA,N)
* On entry, the triangular factor U or L from the Cholesky
* factorization A = U**T*U or A = L*L**T, as computed by
* SPOTRF.
* On exit, the upper or lower triangle of the (symmetric)
* inverse of A, overwriting the input factor U or L.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,N).
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
* > 0: if INFO = i, the (i,i) element of the factor U or L is
* zero, and the inverse could not be computed.
*
* =====================================================================
*
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL SLAUUM, STRTRI, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -4
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'SPOTRI', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
* Invert the triangular Cholesky factor U or L.
*
CALL STRTRI( UPLO, 'Non-unit', N, A, LDA, INFO )
IF( INFO.GT.0 )
$ RETURN
*
* Form inv(U)*inv(U)' or inv(L)'*inv(L).
*
CALL SLAUUM( UPLO, N, A, LDA, INFO )
*
RETURN
*
* End of SPOTRI
*
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ngmath/src/lib/gridpack/cssgrid/csleft.f | 1 | 1656 | C
C $Id: csleft.f,v 1.5 2008-07-27 03:10:07 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
LOGICAL FUNCTION CSLEFT (X1,Y1,Z1,X2,Y2,Z2,X0,Y0,Z0)
DOUBLE PRECISION X1, Y1, Z1, X2, Y2, Z2, X0, Y0, Z0
C
C***********************************************************
C
C From STRIPACK
C Robert J. Renka
C Dept. of Computer Science
C Univ. of North Texas
C renka@cs.unt.edu
C 07/15/96
C
C This function determines whether node N0 is in the
C (closed) left hemisphere defined by the plane containing
C N1, N2, and the origin, where left is defined relative to
C an observer at N1 facing N2.
C
C
C On input:
C
C X1,Y1,Z1 = Coordinates of N1.
C
C X2,Y2,Z2 = Coordinates of N2.
C
C X0,Y0,Z0 = Coordinates of N0.
C
C Input parameters are not altered by this function.
C
C On output:
C
C CSLEFT = TRUE if and only if N0 is in the closed
C left hemisphere.
C
C Modules required by CSLEFT: None
C
C***********************************************************
C
C CSLEFT = TRUE iff <N0,N1 X N2> = det(N0,N1,N2) .GE. 0.
C
CSLEFT = X0*(Y1*Z2-Y2*Z1) - Y0*(X1*Z2-X2*Z1) +
. Z0*(X1*Y2-X2*Y1) .GE. 0.D0
RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg/wmap/wmlgfa.f | 1 | 1579 | C
C $Id: wmlgfa.f,v 1.4 2008-07-27 00:17:37 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE WMLGFA(XXC,YYC,NNC)
C
C Subroutine for processing polygons generated by calls to PPINPO.
C
DIMENSION XXC(NNC),YYC(NNC)
C
C IDRFLG = -1 means draw a polyline only.
C = 0 means draw a filled area only.
C = 1 draws a filled area and a representative line for
C showers.
C = 2 draws a filled area and a representative line for
C t-storms.
C = 3 draws a filled area for showers.
C
COMMON /WMLGCM/IDRFLG
C
IF (IDRFLG .EQ. -1) THEN
CALL GPL(NNC,XXC,YYC)
ELSE IF (IDRFLG .EQ. 0) THEN
CALL GFA(NNC,XXC,YYC)
ELSE IF (IDRFLG .EQ. 1) THEN
CALL GFA(NNC,XXC,YYC)
CALL GQLWSC(IER,SCLO)
CALL GSLWSC(.5)
CALL GPL(2,XXC(2),YYC(2))
CALL GSLWSC(SCLO)
ELSE IF (IDRFLG .EQ. 2) THEN
CALL GFA(NNC,XXC,YYC)
CALL GQLWSC(IER,SCLO)
CALL GSLWSC(.5)
CALL GPL(4,XXC,YYC)
CALL GSLWSC(SCLO)
ELSE IF (IDRFLG .EQ. 3) THEN
CALL GFA(NNC,XXC,YYC)
ELSE IF (IDRFLG .EQ. 4) THEN
CALL GFA(NNC,XXC,YYC)
CALL GQLWSC(IER,SCLO)
CALL GSLWSC(.5)
CALL GPL(2,XXC,YYC)
CALL GSLWSC(SCLO)
ENDIF
C
RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ni/src/lib/nfpfort/ocean.f | 1 | 3777 | C NCLFORTSTART
subroutine wgt_area_smooth (field,area,field_ret,
& nx,ny,no,fill_value,icyclic)
double precision field(nx,ny,no), area(nx,ny)
double precision field_ret(nx,ny,no), fill_value
integer icyclic
C NCLEND
C
C write(*,*) nx,ny,no,fill_value
C
do i = 1,nx
do n = 1, no
field_ret(i,1,n) = fill_value
field_ret(i,ny,n) = fill_value
end do
end do
C
if (icyclic .eq. 1) then
ibeg = 1
iend = nx
else
ibeg = 2
iend = nx - 1
do j = 2, ny - 1
do n = 1, no
field_ret(1,j,n) = fill_value
field_ret(nx,j,n) = fill_value
end do
end do
end if
C
do j = 2, ny-1
do i = ibeg, iend
im1 = i-1
ip1 = i+1
if ( i .eq. 1 ) then
im1 = nx
end if
if ( i .eq. nx ) then
ip1 = 1
end if
C
cc = area(i ,j )
ce = area(ip1,j )
cw = area(im1,j )
cn = area(i ,j+1)
cs = area(i ,j-1)
sum = cc + ce + cw + cn + cs
C
cc = cc / sum
ce = ce / sum
cw = cw / sum
cn = cn / sum
cs = cs / sum
do n = 1, no
field_ret(i,j,n) = fill_value
end do
if ( field(i,j,1) .ne. fill_value ) then
if ( field(ip1,j,1) .eq. fill_value ) then
cc = cc + ce
ce = 0.
end if
if ( field(im1,j,1) .eq. fill_value ) then
cc = cc + cw
cw = 0.
end if
if ( field(i ,j+1,1) .eq. fill_value ) then
cc = cc + cn
cn = 0.
end if
if ( field(i ,j-1,1) .eq. fill_value ) then
cc = cc + cs
cs = 0.
end if
C
do n = 1, no
field_ret(i,j,n) = cc * field(i ,j,n)
& + ce * field(ip1,j, n)
& + cw * field(im1,j, n)
& + cn * field(i, j+1,n)
& + cs * field(i, j-1,n)
end do
end if
end do
end do
C
return
end
C
C NCLFORTSTART
subroutine mixed_layer_depth(field,kmt,ht,depth,field_ret,
& nx,ny,nz,offset,fill_value)
integer kmt(nx,ny)
double precision field(nx,ny,nz)
double precision field_ret(nx,ny), fill_value
double precision offset
double precision depth(nz)
double precision ht(nx,ny)
C NCLEND
C
do j=1,ny
do i=1,nx
k_max = kmt(i,j)
if ( k_max .eq. 0 ) then
field_ret(i,j) = fill_value
else
field_ret(i,j) = ht(i,j)
target_density = field(i,j,1) + offset
do k=1, k_max-1
if ((target_density .gt. field(i,j,k))
& .and.
& (target_density .le. field(i,j,k+1))) then
C
field_ret(i,j) = depth(k)
& + (target_density - field(i,j,k))
& * ((depth(k+1) - depth(k))
& / (field(i,j,k+1) - field(i,j,k)))
go to 100
end if
end do
100 continue
end if
end do
end do
return
end
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/claswp.f | 3 | 3309 | SUBROUTINE CLASWP( N, A, LDA, K1, K2, IPIV, INCX )
*
* -- LAPACK auxiliary routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* June 30, 1999
*
* .. Scalar Arguments ..
INTEGER INCX, K1, K2, LDA, N
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
COMPLEX A( LDA, * )
* ..
*
* Purpose
* =======
*
* CLASWP performs a series of row interchanges on the matrix A.
* One row interchange is initiated for each of rows K1 through K2 of A.
*
* Arguments
* =========
*
* N (input) INTEGER
* The number of columns of the matrix A.
*
* A (input/output) COMPLEX array, dimension (LDA,N)
* On entry, the matrix of column dimension N to which the row
* interchanges will be applied.
* On exit, the permuted matrix.
*
* LDA (input) INTEGER
* The leading dimension of the array A.
*
* K1 (input) INTEGER
* The first element of IPIV for which a row interchange will
* be done.
*
* K2 (input) INTEGER
* The last element of IPIV for which a row interchange will
* be done.
*
* IPIV (input) INTEGER array, dimension (M*abs(INCX))
* The vector of pivot indices. Only the elements in positions
* K1 through K2 of IPIV are accessed.
* IPIV(K) = L implies rows K and L are to be interchanged.
*
* INCX (input) INTEGER
* The increment between successive values of IPIV. If IPIV
* is negative, the pivots are applied in reverse order.
*
* Further Details
* ===============
*
* Modified by
* R. C. Whaley, Computer Science Dept., Univ. of Tenn., Knoxville, USA
*
* =====================================================================
*
* .. Local Scalars ..
INTEGER I, I1, I2, INC, IP, IX, IX0, J, K, N32
COMPLEX TEMP
* ..
* .. Executable Statements ..
*
* Interchange row I with row IPIV(I) for each of rows K1 through K2.
*
IF( INCX.GT.0 ) THEN
IX0 = K1
I1 = K1
I2 = K2
INC = 1
ELSE IF( INCX.LT.0 ) THEN
IX0 = 1 + ( 1-K2 )*INCX
I1 = K2
I2 = K1
INC = -1
ELSE
RETURN
END IF
*
N32 = ( N / 32 )*32
IF( N32.NE.0 ) THEN
DO 30 J = 1, N32, 32
IX = IX0
DO 20 I = I1, I2, INC
IP = IPIV( IX )
IF( IP.NE.I ) THEN
DO 10 K = J, J + 31
TEMP = A( I, K )
A( I, K ) = A( IP, K )
A( IP, K ) = TEMP
10 CONTINUE
END IF
IX = IX + INCX
20 CONTINUE
30 CONTINUE
END IF
IF( N32.NE.N ) THEN
N32 = N32 + 1
IX = IX0
DO 50 I = I1, I2, INC
IP = IPIV( IX )
IF( IP.NE.I ) THEN
DO 40 K = N32, N
TEMP = A( I, K )
A( I, K ) = A( IP, K )
A( IP, K ) = TEMP
40 CONTINUE
END IF
IX = IX + INCX
50 CONTINUE
END IF
*
RETURN
*
* End of CLASWP
*
END
| gpl-2.0 |
jcarlson23/lammps | lib/linalg/dgemv.f | 4 | 7429 | SUBROUTINE DGEMV(TRANS,M,N,ALPHA,A,LDA,X,INCX,BETA,Y,INCY)
* .. Scalar Arguments ..
DOUBLE PRECISION ALPHA,BETA
INTEGER INCX,INCY,LDA,M,N
CHARACTER TRANS
* ..
* .. Array Arguments ..
DOUBLE PRECISION A(LDA,*),X(*),Y(*)
* ..
*
* Purpose
* =======
*
* DGEMV performs one of the matrix-vector operations
*
* y := alpha*A*x + beta*y, or y := alpha*A'*x + beta*y,
*
* where alpha and beta are scalars, x and y are vectors and A is an
* m by n matrix.
*
* Arguments
* ==========
*
* TRANS - CHARACTER*1.
* On entry, TRANS specifies the operation to be performed as
* follows:
*
* TRANS = 'N' or 'n' y := alpha*A*x + beta*y.
*
* TRANS = 'T' or 't' y := alpha*A'*x + beta*y.
*
* TRANS = 'C' or 'c' y := alpha*A'*x + beta*y.
*
* Unchanged on exit.
*
* M - INTEGER.
* On entry, M specifies the number of rows of the matrix A.
* M must be at least zero.
* Unchanged on exit.
*
* N - INTEGER.
* On entry, N specifies the number of columns of the matrix A.
* N must be at least zero.
* Unchanged on exit.
*
* ALPHA - DOUBLE PRECISION.
* On entry, ALPHA specifies the scalar alpha.
* Unchanged on exit.
*
* A - DOUBLE PRECISION array of DIMENSION ( LDA, n ).
* Before entry, the leading m by n part of the array A must
* contain the matrix of coefficients.
* Unchanged on exit.
*
* LDA - INTEGER.
* On entry, LDA specifies the first dimension of A as declared
* in the calling (sub) program. LDA must be at least
* max( 1, m ).
* Unchanged on exit.
*
* X - DOUBLE PRECISION array of DIMENSION at least
* ( 1 + ( n - 1 )*abs( INCX ) ) when TRANS = 'N' or 'n'
* and at least
* ( 1 + ( m - 1 )*abs( INCX ) ) otherwise.
* Before entry, the incremented array X must contain the
* vector x.
* Unchanged on exit.
*
* INCX - INTEGER.
* On entry, INCX specifies the increment for the elements of
* X. INCX must not be zero.
* Unchanged on exit.
*
* BETA - DOUBLE PRECISION.
* On entry, BETA specifies the scalar beta. When BETA is
* supplied as zero then Y need not be set on input.
* Unchanged on exit.
*
* Y - DOUBLE PRECISION array of DIMENSION at least
* ( 1 + ( m - 1 )*abs( INCY ) ) when TRANS = 'N' or 'n'
* and at least
* ( 1 + ( n - 1 )*abs( INCY ) ) otherwise.
* Before entry with BETA non-zero, the incremented array Y
* must contain the vector y. On exit, Y is overwritten by the
* updated vector y.
*
* INCY - INTEGER.
* On entry, INCY specifies the increment for the elements of
* Y. INCY must not be zero.
* Unchanged on exit.
*
* Further Details
* ===============
*
* Level 2 Blas routine.
*
* -- Written on 22-October-1986.
* Jack Dongarra, Argonne National Lab.
* Jeremy Du Croz, Nag Central Office.
* Sven Hammarling, Nag Central Office.
* Richard Hanson, Sandia National Labs.
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE,ZERO
PARAMETER (ONE=1.0D+0,ZERO=0.0D+0)
* ..
* .. Local Scalars ..
DOUBLE PRECISION TEMP
INTEGER I,INFO,IX,IY,J,JX,JY,KX,KY,LENX,LENY
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
*
* Test the input parameters.
*
INFO = 0
IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND.
+ .NOT.LSAME(TRANS,'C')) THEN
INFO = 1
ELSE IF (M.LT.0) THEN
INFO = 2
ELSE IF (N.LT.0) THEN
INFO = 3
ELSE IF (LDA.LT.MAX(1,M)) THEN
INFO = 6
ELSE IF (INCX.EQ.0) THEN
INFO = 8
ELSE IF (INCY.EQ.0) THEN
INFO = 11
END IF
IF (INFO.NE.0) THEN
CALL XERBLA('DGEMV ',INFO)
RETURN
END IF
*
* Quick return if possible.
*
IF ((M.EQ.0) .OR. (N.EQ.0) .OR.
+ ((ALPHA.EQ.ZERO).AND. (BETA.EQ.ONE))) RETURN
*
* Set LENX and LENY, the lengths of the vectors x and y, and set
* up the start points in X and Y.
*
IF (LSAME(TRANS,'N')) THEN
LENX = N
LENY = M
ELSE
LENX = M
LENY = N
END IF
IF (INCX.GT.0) THEN
KX = 1
ELSE
KX = 1 - (LENX-1)*INCX
END IF
IF (INCY.GT.0) THEN
KY = 1
ELSE
KY = 1 - (LENY-1)*INCY
END IF
*
* Start the operations. In this version the elements of A are
* accessed sequentially with one pass through A.
*
* First form y := beta*y.
*
IF (BETA.NE.ONE) THEN
IF (INCY.EQ.1) THEN
IF (BETA.EQ.ZERO) THEN
DO 10 I = 1,LENY
Y(I) = ZERO
10 CONTINUE
ELSE
DO 20 I = 1,LENY
Y(I) = BETA*Y(I)
20 CONTINUE
END IF
ELSE
IY = KY
IF (BETA.EQ.ZERO) THEN
DO 30 I = 1,LENY
Y(IY) = ZERO
IY = IY + INCY
30 CONTINUE
ELSE
DO 40 I = 1,LENY
Y(IY) = BETA*Y(IY)
IY = IY + INCY
40 CONTINUE
END IF
END IF
END IF
IF (ALPHA.EQ.ZERO) RETURN
IF (LSAME(TRANS,'N')) THEN
*
* Form y := alpha*A*x + y.
*
JX = KX
IF (INCY.EQ.1) THEN
DO 60 J = 1,N
IF (X(JX).NE.ZERO) THEN
TEMP = ALPHA*X(JX)
DO 50 I = 1,M
Y(I) = Y(I) + TEMP*A(I,J)
50 CONTINUE
END IF
JX = JX + INCX
60 CONTINUE
ELSE
DO 80 J = 1,N
IF (X(JX).NE.ZERO) THEN
TEMP = ALPHA*X(JX)
IY = KY
DO 70 I = 1,M
Y(IY) = Y(IY) + TEMP*A(I,J)
IY = IY + INCY
70 CONTINUE
END IF
JX = JX + INCX
80 CONTINUE
END IF
ELSE
*
* Form y := alpha*A'*x + y.
*
JY = KY
IF (INCX.EQ.1) THEN
DO 100 J = 1,N
TEMP = ZERO
DO 90 I = 1,M
TEMP = TEMP + A(I,J)*X(I)
90 CONTINUE
Y(JY) = Y(JY) + ALPHA*TEMP
JY = JY + INCY
100 CONTINUE
ELSE
DO 120 J = 1,N
TEMP = ZERO
IX = KX
DO 110 I = 1,M
TEMP = TEMP + A(I,J)*X(IX)
IX = IX + INCX
110 CONTINUE
Y(JY) = Y(JY) + ALPHA*TEMP
JY = JY + INCY
120 CONTINUE
END IF
END IF
*
RETURN
*
* End of DGEMV .
*
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ni/src/examples/mapplot/mp02f.f | 1 | 8810 | C
C $Id: mp02f.f,v 1.15 2010-03-15 22:49:24 haley Exp $
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C C
C Copyright (C) 1995 C
C University Corporation for Atmospheric Research C
C All Rights Reserved C
C C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C File: mp02f.f
C
C Author: Dave Brown (converted to Fortran by Mary Haley)
C National Center for Atmospheric Research
C PO 3000, Boulder, Colorado
C
C Date: Tue Jan 24 10:08:49 MST 1995
C
C Description: Demonstrates individual control of MapPlot areas
C
external NhlFAppClass
external NhlFNcgmWorkstationClass
external NhlFPSWorkstationClass
external NhlFPDFWorkstationClass
external NhlFCairoPSPDFWorkstationClass
external NhlFCairoImageWorkstationClass
external NhlFCairoWindowWorkstationClass
external NhlFMapPlotClass
integer appid,wid,mapid
integer rlist
C
C String arrays for specifying areas
C
character*10 fill_specs(7)
data fill_specs/'mexico','bolivia','brazil','nicaragua',
1 'cuba','haiti','canada'/
character*11 outline_specs(6)
data outline_specs/'argentina','paraguay','colombia',
1 'us-colorado','us-texas','us-kentucky'/
character*11 mask_specs(7)
data mask_specs/'us-colorado','us-texas','us-kentucky',
1 'bolivia','paraguay','nicaragua','oceans'/
character*7 wks_type
C
C Default is to display output to an X workstation
C
wks_type = "x11"
C
C Initialize the high level utility library
C
call NhlFInitialize
C
C Create an application context. Set the app dir to the current
C directory so the application looks for a resource file in the
C working directory. The resource file sets most of the Contour
C resources that remain fixed throughout the life of the Contour
C object.
C
call NhlFRLCreate(rlist,'SETRL')
call NhlFRLClear(rlist)
call NhlFRLSetstring(rlist,'appUsrDir','./',ierr)
call NhlFCreate(appid,'mp02',NhlFAppClass,0,rlist,ierr)
if (wks_type.eq."ncgm".or.wks_type.eq."NCGM") then
C
C Create an NCGM workstation.
C
call NhlFRLClear(rlist)
call NhlFRLSetstring(rlist,'wkMetaName','./mp02f.ncgm',ierr)
call NhlFCreate(wid,'mp02Work',NhlFNcgmWorkstationClass,0,
1 rlist,ierr)
else if (wks_type.eq."x11".or.wks_type.eq."X11") then
C
C Create an X workstation
C
call NhlFRLClear(rlist)
call NhlFRLSetinteger(rlist,'wkPause',1,ierr)
call NhlFCreate(wid,'mp02Work',
+ NhlFCairoWindowWorkstationClass,0,
1 rlist,ierr)
else if (wks_type.eq."oldps".or.wks_type.eq."OLDPS") then
C
C Create an older-style PostScript workstation.
C
call NhlFRLClear(rlist)
call NhlFRLSetstring(rlist,'wkPSFileName','./mp02f.ps',ierr)
call NhlFCreate(wid,'mp02Work',NhlFPSWorkstationClass,0,
1 rlist,ierr)
else if (wks_type.eq."oldpdf".or.wks_type.eq."OLDPDF") then
C
C Create an older-style PDF workstation.
C
call NhlFRLClear(rlist)
call NhlFRLSetstring(rlist,'wkPDFFileName','./mp02f.pdf',ierr)
call NhlFCreate(wid,'mp02Work',NhlFPDFWorkstationClass,0,
1 rlist,ierr)
else if (wks_type.eq."pdf".or.wks_type.eq."PDF".or.
+ wks_type.eq."ps".or.wks_type.eq."PS") then
C
C Create a cairo PS/PDF object.
C
call NhlFRLClear(rlist)
call NhlFRLSetString(rlist,'wkFormat',wks_type,ierr)
call NhlFRLSetstring(rlist,'wkFileName','./mp02f',ierr)
call NhlFCreate(wid,'mp02Work',
1 NhlFCairoPSPDFWorkstationClass,0,rlist,ierr)
else if (wks_type.eq."png".or.wks_type.eq."PNG") then
C
C Create a cairo PNG object.
C
call NhlFRLClear(rlist)
call NhlFRLSetString(rlist,'wkFormat',wks_type,ierr)
call NhlFRLSetstring(rlist,'wkFileName','./mp02f',ierr)
call NhlFCreate(wid,'mp02Work',
1 NhlFCairoImageWorkstationClass,0,rlist,ierr)
endif
C
C Create a plot focusing on North and South America
C Outlines are on by default turn fill on.
C By default the geophysical boundary set is used both for outline and
C fill.
C
call NhlFRLClear(rlist)
call NhlFRLSetstring(rlist,'pmTitleDisplayMode','always',ierr)
call NhlFRLSetstring(rlist,'tiMainString','mp02f - Frame 1',
1 ierr)
call NhlFRLSetstring(rlist,'mpFillOn','TRUE',ierr)
call NhlFRLSetstring(rlist,'mpProjection','orthographic',ierr)
call NhlFRLSetString(rlist,'mpPerimOn','true',ierr)
call NhlFRLSetfloat(rlist,'mpCenterLatF',10.0,ierr)
call NhlFRLSetfloat(rlist,'mpCenterLonF',-90.0,ierr)
call NhlFRLSetfloat(rlist,'mpCenterRotF',45.0,ierr)
call NhlFRLSetstring(rlist,'mpLimitMode','latlon',ierr)
call NhlFRLSetfloat(rlist,'mpMinLatF',-60.0,ierr)
call NhlFRLSetfloat(rlist,'mpMaxLatF',60.0,ierr)
call NhlFRLSetfloat(rlist,'mpMinLonF',-135.0,ierr)
call NhlFRLSetfloat(rlist,'mpMaxLonF',-45.0,ierr)
C
C Highlight selected countries using their "political" color.
C
call NhlFRLSetstringarray(rlist,'mpFillAreaSpecifiers',
1 fill_specs,7,ierr)
call NhlFCreate(mapid,'Map0',NhlFMapPlotClass,wid,rlist,ierr)
call NhlFDraw(mapid,ierr)
call NhlFFrame(wid,ierr)
C
C Individually outline some other countries and some US states.
C
call NhlFRLClear(rlist)
call NhlFRLSetstring(rlist,'tiMainString','mp02f - Frame 2',ierr)
call NhlFRLSetstringarray(rlist,'mpOutlineSpecifiers',
1 outline_specs,6,ierr)
call NhlFSetValues(mapid,rlist,ierr)
call NhlFDraw(mapid,ierr)
call NhlFFrame(wid,ierr)
C
C Turn off the base geophysical set for outlines and fill, leaving only
C the specified areas.
C Also change the specification, 'canada' to 'canada*',
C in order to draw all areas belonging to Canada.
C Note that another color, mpDefaultFillColor, is used for all areas
C within the map projection that are otherwise not drawn, including the
C oceans. If you look closely, you will see that the Canadian lakes
C are not drawn in the color used in the previous frame for the ocean.
C The wild card specification, 'canada*', picks up all the lakes of
C Canada Lakes are drawn using mpInlandWaterFillColor, which is, by
C default, set to the same color as mpOceanFillColor.
C
fill_specs(5) = 'canada*'
call NhlFRLClear(rlist)
call NhlFRLSetstring(rlist,'tiMainString','mp02f - Frame 3',ierr)
call NhlFRLSetstring(rlist,'mpFillBoundarySets','noBoundaries',
* ierr)
call NhlFRLSetstring(rlist,'mpOutlineBoundarySets','noBoundaries',
1 ierr)
call NhlFRLSetstringarray(rlist,'mpFillAreaSpecifiers',
1 fill_specs,7,ierr)
call NhlFSetValues(mapid,rlist,ierr)
call NhlFDraw(mapid,ierr)
call NhlFFrame(wid,ierr)
C
C You can also specify area groupings using certain predefined
C string constants: set 'continents' on to demonstrate.
C Masking an area is different from not explicitly drawing it. In order
C to mask a region you must explicitly include it on in the Mask
C specification list. There is an order of precedence for fill and
C masking. Explicitly named areas take precedence over area groupings,
C and small areas take precedence over enclosing larger areas.
C Otherwise masking takes precedence over filling.
C >>> Masking or filling individual US states causes processing time
C >>> and memory requirements to increase substantially. Hopefully the
C >>> performance can be improved before the release.
C
fill_specs(1) = 'continents'
fill_specs(2) = 'us'
call NhlFRLClear(rlist)
call NhlFRLSetstring(rlist,'tiMainString','mp02f - Frame 4',ierr)
call NhlFRLSetstring(rlist,'mpFillBoundarySets','NoBoundaries',
1 ierr)
call NhlFRLSetstringarray(rlist,'mpFillAreaSpecifiers',
1 fill_specs,7,ierr)
call NhlFRLSetString(rlist,'mpAreaMaskingOn','True',ierr)
call NhlFRLSetstringarray(rlist,'mpMaskAreaSpecifiers',
1 mask_specs,7,ierr)
call NhlFSetValues(mapid,rlist,ierr)
call NhlFDraw(mapid,ierr)
call NhlFFrame(wid,ierr)
C
C Destroy the objects created, close the HLU library and exit.
C
call NhlFDestroy(mapid,ierr)
call NhlFDestroy(wid,ierr)
call NhlFDestroy(appid,ierr)
call NhlFClose
stop
end
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg_gks/wiss/gwelod.f | 1 | 2403 | C
C $Id: gwelod.f,v 1.4 2008-07-27 00:21:07 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE GWELOD(GKSERR)
C
C This routine loads the current instruction into the segment.
C The current instruction includes the opcode class and id,
C and the size filled which may be short or long.
C
C OUTPUT
C GKSERR -- The error status flag.
C
C
C All data is type INTEGER unless otherwise indicated.
C
IMPLICIT INTEGER (A-Z)
C
C COMMON for communication of instruction and length.
C
include 'gwiins.h'
include 'gwiio.h'
C
SAVE
C
C Define the ALLOK status and the opcode class and id lengths.
C
DATA ALLOK,OPCLLN,OPIDLN/0,4,7/
C
C Define the short format length, short format count, long format flag,
C continue flag on, continue flag off, continue length, long format
C length.
C
DATA SHFMLN,SHTFMT,LFMFLG,CONON,CONOFF,CFMLNG,LFMLNG
1 / 5, 30, 31, 1, 0, 1, 15/
DATA SHORT/0/, LONG/1/
C
GKSERR = ALLOK
C
C Make sure the instruction starts on a 16 bit boundry.
C
TEMP = MOD(WBFPOS,16)
IF (TEMP .NE. 0) WBFPOS = WBFPOS + (16-TEMP)
C
C Load the opcode class and id into the buffer.
C
CALL GWILOD(MCOPCL,OPCLLN,1,GKSERR)
IF (GKSERR .NE. ALLOK) RETURN
CALL GWILOD(MCOPID,OPIDLN,1,GKSERR)
IF (GKSERR .NE. ALLOK) RETURN
C
C Determine if a long format or short format instruction.
C
IF (MCCBYT .LE. SHTFMT) THEN
C
C Short format instruction.
C
MSLFMT = SHORT
CALL GWILOD (MCCBYT,SHFMLN,1,GKSERR)
IF (GKSERR .NE. ALLOK) RETURN
ELSE
C
C Long format instruction, set the long format flag.
C
MSLFMT = LONG
CALL GWILOD (LFMFLG,SHFMLN,1,GKSERR)
IF (GKSERR .NE. ALLOK) RETURN
C
C Set the continue flag.
C
IF (MCNBYT .NE. 0) THEN
C
C There is another partition.
C
CALL GWILOD(CONON,CFMLNG,1,GKSERR)
ELSE
C
C Last partition.
C
CALL GWILOD(CONOFF,CFMLNG,1,GKSERR)
END IF
C
IF (GKSERR .NE. ALLOK) RETURN
C
C Set the long format operand list size.
C
CALL GWILOD(MCCBYT,LFMLNG,1,GKSERR)
END IF
C
RETURN
END
| gpl-2.0 |
marshallward/mom | src/atmos_param/donner_deep/fms_donner.F90 | 7 | 172498 | module fms_donner_mod
use time_manager_mod, only: time_type, set_time, &
set_date, get_time, &
get_calendar_type, &
operator(-), &
operator(>=), operator (<)
use diag_manager_mod, only: register_diag_field, send_data, &
diag_axis_init
use field_manager_mod, only: MODEL_ATMOS, field_manager_init, &
fm_query_method, get_field_info, &
parse
use tracer_manager_mod, only: get_tracer_names,get_number_tracers, &
get_tracer_indices, &
!++lwh
query_method
use atmos_tracer_utilities_mod, only : get_wetdep_param
use sat_vapor_pres_mod,only : sat_vapor_pres_init
!--lwh
use fms_mod, only: mpp_pe, mpp_root_pe, &
file_exist, check_nml_error, &
error_mesg, FATAL, WARNING, NOTE, &
close_file, open_namelist_file, &
stdout, stdlog, write_version_number, &
field_size, &
read_data, write_data, lowercase
use fms_io_mod, only: register_restart_field, restart_file_type, &
save_restart, restore_state, get_mosaic_tile_file
use mpp_mod, only: input_nml_file
use mpp_io_mod, only: mpp_open, mpp_close, fieldtype, &
mpp_read_meta, mpp_get_info, &
mpp_get_fields, mpp_read, &
MPP_NETCDF, MPP_SINGLE, &
MPP_SEQUENTIAL, MPP_RDONLY, MPP_NATIVE, &
mpp_get_field_name
use constants_mod, only: DENS_H2O, RDGAS, GRAV, CP_AIR, &
pie=>PI, KAPPA, RVGAS, &
SECONDS_PER_DAY, HLV, HLF, HLS, KELVIN
use column_diagnostics_mod, only: initialize_diagnostic_columns, &
column_diagnostics_header, &
close_column_diagnostics_units
use donner_types_mod, only: donner_initialized_type, &
donner_save_type, donner_rad_type, &
donner_nml_type, donner_param_type, &
donner_budgets_type, &
donner_column_diag_type, &
MAXMAG, MAXVAL, MINMAG, MINVAL, &
DET_MASS_FLUX, MASS_FLUX, &
CELL_UPWARD_MASS_FLUX, TEMP_FORCING, &
MOIST_FORCING, PRECIP, FREEZING, &
RADON_TEND, &
donner_conv_type, donner_cape_type, &
donner_cem_type
implicit none
private
!--------------------------------------------------------------------
! donner_deep_mod diagnoses the location and computes the
! effects of deep convection on the model atmosphere
!--------------------------------------------------------------------
!---------------------------------------------------------------------
!----------- ****** VERSION NUMBER ******* ---------------------------
character(len=128) :: version = '$Id: fms_donner.F90,v 20.0 2013/12/13 23:17:30 fms Exp $'
character(len=128) :: tagname = '$Name: tikal $'
!--------------------------------------------------------------------
!---interfaces------
public &
fms_donner_process_nml, &
fms_donner_process_tracers, &
fms_donner_activate_diagnostics, fms_donner_read_restart, &
fms_donner_col_diag, fms_donner_write_restart, &
fms_donner_column_control, &
fms_sat_vapor_pres, &
fms_get_pe_number, fms_error_mesg, fms_constants, &
fms_close_col_diag_units, &
fms_deallocate_variables, &
fms_donner_deep_netcdf, fms_donner_process_monitors
private &
! module subroutines called by donner_deep_init:
register_fields, read_restart_nc, &
process_coldstart,&
! module subroutines called by donner_deep:
donner_deep_netcdf, donner_column_control, &
! module subroutines called from donner_deep_end:
write_restart
!---------------------------------------------------------------------
!---namelist----
# include "donner_nml.h"
!--------------------------------------------------------------------
!--- public data ----------
!--------------------------------------------------------------------
!----private data-----------
!--- for restart file
type(restart_file_type), pointer, save :: Don_restart => NULL()
type(restart_file_type), pointer, save :: Til_restart => NULL()
logical :: in_different_file = .false.
!---------------------------------------------------------------------
! parameters stored in the donner_param derived type variable to facili-
! tate passage to kernel subroutines:
!
!--------------------------------------------------------------------
! list of native mode restart versions usable by this module:
!
! NOTE: none of the earlier versions of restart files can be used to
! initiate an experiment with this code version due to a change
! in the calculation algorithm. experiments begun with this code
! must be coldstarted, or use a native mode restart file gener-
! ated by an experiment using this code version (restart version
! #8), or a netcdf restart file.
!
! version 8 has the lag temp, vapor and pressure fields needed to cal-
! culate the lag time value of cape. tempbl and ratpbl
! removed.
!
! version 9 is reserved for the native mode restart file version cor-
! responding to the current netcdf restart file. it is up to
! the user to generate the code needed to read and write this
! version, if needed, using the subroutines read_restart and
! write_restart that are provided as starting points, since
! only netcdf restarts are currently supported.
!
! version 10 contains donner_humidity_factor rather than
! donner_humidity_ratio, a change necessitated by the intro-
! duction of the uw_conv shallow convection scheme.
integer, dimension(3) :: restart_versions = (/ 8, 9, 10 /)
!--------------------------------------------------------------------
! variables associated with netcdf diagnostic output from this module:
!
! id_xxxx indices associated with each potential netcdf
! diagnostic field:
! missing value value used by netcdf routines if data not present
! mod_name module name associated with these diagnostics; used
! to connect these diagnostics to the diag_table
!
integer :: id_leff
integer :: id_cemetf_deep, id_ceefc_deep, id_cecon_deep, &
id_cemfc_deep, id_cememf_deep, id_cememf_mod_deep, &
id_cual_deep, id_fre_deep, id_elt_deep, &
id_cmus_deep, id_ecds_deep, id_eces_deep, &
id_emds_deep, id_emes_deep, id_qmes_deep,&
id_wmps_deep, id_wmms_deep, id_tmes_deep,&
id_dmeml_deep, id_uceml_deep, id_umeml_deep, &
id_xice_deep, id_dgeice_deep, id_dgeliq_deep, &
id_xliq_deep, &
id_cuqi_deep, id_cuql_deep, &
id_plcl_deep, id_plfc_deep, id_plzb_deep, &
id_xcape_deep, id_coin_deep, &
id_dcape_deep, id_qint_deep, id_a1_deep, &
id_amax_deep, id_amos_deep, &
id_tprea1_deep, id_ampta1_deep, &
id_omint_deep, id_rcoa1_deep, id_detmfl_deep
integer :: id_pfull_cem, id_phalf_cem, &
id_zfull_cem, id_zhalf_cem, &
id_temp_cem, id_mixing_ratio_cem
integer, dimension(:), allocatable :: id_cpre_cem, id_pb_cem, id_ptma_cem, &
id_h1_cem, id_qlw_cem, id_cfi_cem, &
id_wv_cem, id_rcl_cem
integer :: id_a1_cem, id_cual_cem, id_tfrc_cem, &
id_mpre_cem
integer, dimension(:), allocatable :: id_qtren1, id_qtmes1, &
id_wtp1, id_qtceme, &
id_total_wet_dep, &
id_meso_wet_dep, id_cell_wet_dep
integer, dimension(:), allocatable :: id_qtren1_col, id_qtmes1_col, &
id_wtp1_col, id_qtceme_col, &
id_total_wet_dep_col, &
id_meso_wet_dep_col, &
id_cell_wet_dep_col
integer, dimension(:), allocatable :: id_extremes, id_hits
integer, dimension(:), allocatable :: id_water_budget, &
id_ci_water_budget
integer, dimension(:), allocatable :: id_enthalpy_budget, &
id_ci_enthalpy_budget
integer, dimension (:,:), allocatable :: &
id_precip_budget, &
id_ci_precip_budget
integer :: id_ci_prcp_heat_liq_cell, id_ci_prcp_heat_frz_cell, &
id_ci_prcp_heat_liq_meso, id_ci_prcp_heat_frz_meso, &
id_ci_prcp_heat_total, id_ci_prcp_total
real :: missing_value = -999.
character(len=16) :: mod_name = 'donner_deep'
integer :: donner_axes(5)
!--------------------------------------------------------------------
! variables for column diagnostics option
!
! arrays containing information for all requested diagnostic columns
! (1:num_diag_pts):
! col_diag_unit unit numbers for each column's output file
! col_diag_lon each column's longitude
! [ degrees, 0 < lon < 360 ]
! col_diag_lat each column's latitude
! [degrees, -90 < lat < 90 ]
! col_diag_j each column's j index (processor coordinates)
! col_diag_i each column's i index (processor coordinates)
!
! Time_col_diagnostics time in model simulation at which to activate
! column diagnostics
!
integer, dimension(:), allocatable :: col_diag_unit
real , dimension(:), allocatable :: col_diag_lon, col_diag_lat
integer, dimension(:), allocatable :: col_diag_j, col_diag_i
type(time_type) :: Time_col_diagnostics
!-----------------------------------------------------------------------
! miscellaneous variables
!
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------
contains
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!
! PUBLIC SUBROUTINES
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!#####################################################################
subroutine fms_donner_process_nml (Nml, kpar)
!---------------------------------------------------------------------
! fms_donner_process_nml processes the donner_deep_nml file.
!---------------------------------------------------------------------
!--------------------------------------------------------------------
type(donner_nml_type), intent(inout) :: Nml
integer, intent(in) :: kpar
!---------------------------------------------------------------------
! intent(in) variables:
!
!
!-------------------------------------------------------------------
!-------------------------------------------------------------------
! local variables:
integer :: unit, ierr, io, logunit
!-------------------------------------------------------------------
! local variables:
!
! unit unit number for nml file
! ierr error return flag
! io error return code
!
!-------------------------------------------------------------------
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!
! 1. READ NAMELIST AND WRITE IT TO LOG FILE.
!
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!---------------------------------------------------------------------
! read namelist.
!---------------------------------------------------------------------
#ifdef INTERNAL_FILE_NML
read (input_nml_file, nml=donner_deep_nml, iostat=io)
ierr = check_nml_error(io,'donner_deep_nml')
#else
if (file_exist('input.nml')) then
unit = open_namelist_file ()
ierr=1; do while (ierr /= 0)
read (unit, nml=donner_deep_nml, iostat=io, end=10)
ierr = check_nml_error (io, 'donner_deep_nml')
enddo
10 call close_file (unit)
endif
#endif
!---------------------------------------------------------------------
! write version number and namelist to logfile.
!---------------------------------------------------------------------
call write_version_number(version, tagname)
logunit = stdlog()
if (mpp_pe() == mpp_root_pe() ) &
write (logunit, nml=donner_deep_nml)
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!
! 8. STORE THE NAMELIST VARIABLES THAT NEED TO BE MADE AVAILABLE
! OUTSIDE OF THIS MODULE INTO THE DONNER_NML_TYPE VARIABLE.
!
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Nml%parcel_launch_level = parcel_launch_level
Nml%allow_mesoscale_circulation = allow_mesoscale_circulation
Nml%do_hires_cape_for_closure = do_hires_cape_for_closure
Nml%do_donner_cape = do_donner_cape !miz
Nml%do_donner_plume = do_donner_plume !miz
Nml%do_donner_closure = do_donner_closure !miz
Nml%do_dcape = do_dcape !miz
Nml%do_lands = do_lands !miz
Nml%tau = tau !miz
Nml%cape0 = cape0 !miz
Nml%rhavg0 = rhavg0 !miz
Nml%plev0 = plev0 !miz
Nml%do_rh_trig = do_rh_trig !miz
Nml%do_capetau_land = do_capetau_land !miz
Nml%pblht0 = pblht0 !miz
Nml%tke0 = tke0 !miz
Nml%lofactor0 = lofactor0 !miz
Nml%deephgt0 = deephgt0 !miz
Nml%lochoice = lochoice !miz
Nml%deep_closure = deep_closure !miz
Nml%gama = gama !miz
Nml%do_ice = do_ice !miz
Nml%atopevap = atopevap !miz
Nml%do_donner_lscloud = do_donner_lscloud !miz
Nml%auto_rate = auto_rate !miz
Nml%auto_th = auto_th !miz
Nml%frac = frac !miz
Nml%ttend_max = ttend_max !miz
Nml%mesofactor = mesofactor !miz
Nml%use_llift_criteria = use_llift_criteria
Nml%use_pdeep_cv = use_pdeep_cv
Nml%entrainment_constant_source = entrainment_constant_source
Nml%donner_deep_freq = donner_deep_freq
Nml%model_levels_in_sfcbl = model_levels_in_sfcbl
Nml%cell_liquid_size_type = cell_liquid_size_type
Nml%cell_ice_size_type = cell_ice_size_type
Nml%cell_liquid_eff_diam_input = cell_liquid_eff_diam_input
Nml%cell_ice_geneff_diam_input = cell_ice_geneff_diam_input
Nml%meso_liquid_eff_diam_input = meso_liquid_eff_diam_input
Nml%do_average = do_average
Nml%use_memphis_size_limits = use_memphis_size_limits
Nml%wmin_ratio = wmin_ratio
Nml%do_freezing_for_cape = do_freezing_for_cape
Nml%tfre_for_cape = tfre_for_cape
Nml%dfre_for_cape = dfre_for_cape
Nml%rmuz_for_cape = rmuz_for_cape
Nml%do_freezing_for_closure = do_freezing_for_closure
Nml%tfre_for_closure = tfre_for_closure
Nml%dfre_for_closure = dfre_for_closure
Nml%rmuz_for_closure = rmuz_for_closure
Nml%do_budget_analysis = do_budget_analysis
Nml%frc_internal_enthalpy_conserv = &
frc_internal_enthalpy_conserv
Nml%do_ensemble_diagnostics = do_ensemble_diagnostics
Nml%limit_pztm_to_tropo = limit_pztm_to_tropo
Nml%entrainment_scheme_for_closure = &
entrainment_scheme_for_closure
Nml%modify_closure_plume_condensate = &
modify_closure_plume_condensate
Nml%closure_plume_condensate = closure_plume_condensate
Nml%evap_in_downdrafts = evap_in_downdrafts
Nml%evap_in_environ = evap_in_environ
Nml%entrained_into_meso = entrained_into_meso
Nml%anvil_precip_efficiency = anvil_precip_efficiency
Nml%meso_down_evap_fraction = meso_down_evap_fraction
Nml%meso_up_evap_fraction = meso_up_evap_fraction
Nml%cdeep_cv = cdeep_cv
allocate (Nml%arat(kpar))
allocate (Nml%ensemble_entrain_factors_gate(kpar))
if ( arat_erat_option /= 0 ) then
call define_arat_erat (arat_erat_option, kpar, eratb, erat0, &
erat_min, erat_max, erat, arat)
if (mpp_pe() == mpp_root_pe() ) then
print *,'donner_deep_nml: redefined arat and erat using &
&arat_erat_option == ', arat_erat_option
print *,'donner_deep_nml: arat = ',arat
print *,'donner_deep_nml: erat = ',erat
end if
endif
Nml%arat = arat
Nml%ensemble_entrain_factors_gate = erat
end subroutine fms_donner_process_nml
!#####################################################################
subroutine fms_donner_process_tracers (Initialized, tracers_in_donner,&
Don_save)
type(donner_initialized_type), intent(inout) :: Initialized
logical, dimension(:), intent(in) :: tracers_in_donner
type(donner_save_type), intent(inout) :: Don_save
integer :: nn, n
logical :: flag
character(len=200) :: method_name, method_control
real :: frac_junk, frac_junk2
Initialized%do_donner_tracer = .true.
nn = 1
do n=1,size(tracers_in_donner(:))
if (tracers_in_donner(n)) then
call get_tracer_names (MODEL_ATMOS, n, &
name = Don_save%tracername(nn), &
units = Don_save%tracer_units(nn))
!++lwh
Initialized%wetdep(nn)%units = Don_save%tracer_units(nn)
flag = query_method( 'wet_deposition', MODEL_ATMOS, n, &
method_name, method_control )
call get_wetdep_param( method_name, method_control, &
Initialized%wetdep(nn)%scheme, &
Initialized%wetdep(nn)%Henry_constant, &
Initialized%wetdep(nn)%Henry_variable, &
frac_junk, frac_junk2, &
Initialized%wetdep(nn)%alpha_r, &
Initialized%wetdep(nn)%alpha_s , &
Initialized%wetdep(nn)%Lwetdep, &
Initialized%wetdep(nn)%Lgas, &
Initialized%wetdep(nn)%Laerosol, &
Initialized%wetdep(nn)%Lice, &
frac_in_cloud_donner=Initialized%wetdep(nn)%frac_in_cloud)
Initialized%wetdep(nn)%scheme = lowercase( Initialized%wetdep(nn)%scheme )
!-lwh
nn = nn + 1
endif
end do
end subroutine fms_donner_process_tracers
!#####################################################################
subroutine fms_donner_activate_diagnostics (secs, days, axes, &
Don_save, Nml, n_water_budget, &
n_enthalpy_budget, n_precip_paths, &
n_precip_types, nlev_hires, kpar)
integer, intent(in) :: secs, days, n_water_budget, &
n_enthalpy_budget, n_precip_paths, &
n_precip_types, nlev_hires, kpar
integer, dimension(4), intent(in) :: axes
type(donner_save_type), intent(inout) :: Don_save
type(donner_nml_type), intent(inout) :: Nml
type(time_type) :: Time
Time = set_time (secs, days)
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!
! 4. INITIALIZE THE NETCDF OUTPUT VARIABLES.
!
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!--------------------------------------------------------------------
! activate the netcdf diagnostic fields.
!-------------------------------------------------------------------
call register_fields (Time, axes, Don_save, Nml, &
n_water_budget, &
n_enthalpy_budget, n_precip_paths, &
n_precip_types, nlev_hires, kpar)
end subroutine fms_donner_activate_diagnostics
!#####################################################################
subroutine fms_donner_read_restart (Initialized, ntracers, &
secs, days, Don_save, Nml)
type(donner_initialized_type), intent(inout) :: Initialized
type(donner_save_type), intent(inout) :: Don_save
type(donner_nml_type), intent(inout) :: Nml
integer, intent(in) :: secs, days, ntracers
type(time_type) :: Time
integer :: outunit
Time = set_time (secs, days)
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!
! 5. PROCESS THE RESTART FILE.
!
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!--------------------------------------------------------------------
! if a netcdf restart file is present, call read_restart_nc to read
! it.
!--------------------------------------------------------------------
!--- register restart field to be ready to be written out.
call fms_donner_register_restart('donner_deep.res.nc', Initialized, ntracers, Don_save, Nml)
if (file_exist ('INPUT/donner_deep.res.nc') ) then
Initialized%coldstart= .false.
! call read_restart_nc (ntracers, Initialized,Nml, Don_save)
call restore_state(Don_restart)
if (in_different_file) call restore_state(Til_restart)
!--------------------------------------------------------------------
! if a native mode restart file is present, call read_restart
! to read it.
!--------------------------------------------------------------------
else if (file_exist ('INPUT/donner_deep.res') ) then
Initialized%coldstart= .false.
call error_mesg ( 'fms_donner_mod', 'Native restart capability has been removed.', &
FATAL)
!--------------------------------------------------------------------
! if no restart file is present, call subroutine process_coldstart
! to define the needed variables.
!--------------------------------------------------------------------
else
call process_coldstart (Time, Initialized, Nml, Don_save)
endif
end subroutine fms_donner_read_restart
!#####################################################################
subroutine fms_donner_col_diag (lonb, latb, Col_diag, pref)
real, dimension(:,:), intent(in) :: lonb, latb
type(donner_column_diag_type), intent(inout) :: Col_diag
real, dimension(:), intent(in) :: pref
logical, dimension(size(latb,1)-1, size(latb,2)-1) :: &
do_column_diagnostics
integer :: k, n
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!
! 6. INITIALIZE VARIABLES NEEDED FOR COLUMN_DIAGNOSTICS_MOD OUTPUT.
!
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!---------------------------------------------------------------------
! define the total number of columns for which diagnostics
! are desired.
!---------------------------------------------------------------------
Col_diag%num_diag_pts = num_diag_pts_ij + num_diag_pts_latlon
!---------------------------------------------------------------------
! initialize the value of the k index associated with diagnostics
! cutoff.
!---------------------------------------------------------------------
Col_diag%kstart = -99
!---------------------------------------------------------------------
! if any diagnostics are requested, perform various consistency
! checks.
!---------------------------------------------------------------------
if (Col_diag%num_diag_pts > 0) then
!---------------------------------------------------------------------
! check that array dimensions are sufficiently large for the number
! of columns requested.
!---------------------------------------------------------------------
if (Col_diag%num_diag_pts > MAX_PTS) then
call error_mesg ('donner_deep_mod', 'donner_deep_init: &
&must reset MAX_PTS or reduce number of diagnostic points', &
FATAL)
endif
!---------------------------------------------------------------------
! check that the specified time at which diagnostics are to be
! activated has been specified.
!---------------------------------------------------------------------
do n=1,3
if (diagnostics_start_time(n) == 0) then
call error_mesg ('donner_deep_mod', 'donner_deep_init:&
&year, month and/or day invalidly specified for column '//&
'diagnostics starting time', FATAL)
endif
end do
!---------------------------------------------------------------------
! define a time_type variable indicating the requested time to begin
! outputting diagnostics.
!---------------------------------------------------------------------
Time_col_diagnostics = set_date (diagnostics_start_time(1), &
diagnostics_start_time(2), &
diagnostics_start_time(3), &
diagnostics_start_time(4), &
diagnostics_start_time(5), &
diagnostics_start_time(6) )
!---------------------------------------------------------------------
! allocate space for the arrays used to specify the diagnostics
! columns and the output units. initialize the arrays with bogus
! values.
!---------------------------------------------------------------------
allocate (col_diag_unit (Col_diag%num_diag_pts) )
allocate (col_diag_lon (Col_diag%num_diag_pts) )
allocate (col_diag_lat (Col_diag%num_diag_pts) )
allocate (col_diag_i (Col_diag%num_diag_pts) )
allocate (col_diag_j (Col_diag%num_diag_pts) )
col_diag_unit = -1
col_diag_lon = -1.0
col_diag_lat = -1.0
col_diag_i = -1
col_diag_j = -1
!---------------------------------------------------------------------
! call initialize_diagnostic_columns to determine the locations
! (i,j,lat and lon) of any diagnostic columns in this processor's
! space and to open output files for the diagnostics.
!---------------------------------------------------------------------
call initialize_diagnostic_columns &
(mod_name, num_diag_pts_latlon, num_diag_pts_ij, &
i_coords_gl, j_coords_gl, lat_coords_gl, &
lon_coords_gl, lonb(:,:), latb(:,:), &
do_column_diagnostics, &
col_diag_lon, col_diag_lat, col_diag_i, &
col_diag_j, col_diag_unit)
!---------------------------------------------------------------------
! verify that requested pressure cutoff for column diagnostics output
! is valid. define the model k index which corresponds (kstart).
!---------------------------------------------------------------------
do k=1,size(pref(:))
if (pref(k) >= diagnostics_pressure_cutoff) then
Col_diag%kstart = k
exit
endif
end do
!----------------------------------------------------------------------
! if the specified pressure is larger than any pressure level in the
! model grid, write an error message.
!----------------------------------------------------------------------
if (Col_diag%kstart == -99) then
call error_mesg ( 'donner_deep_mod', 'donner_deep_init: &
&diagnostics_pressure_cutoff is higher than pressure at '//&
'any model level', FATAL)
endif
!----------------------------------------------------------------------
! if column diagnostics is not requested, define the components of
! Col_diag that will be needed.
!----------------------------------------------------------------------
else
Col_diag%in_diagnostics_window = .false.
Col_diag%ncols_in_window = 0
endif
!----------------------------------------------------------------------
! allocate space for the array elements of the donner_column_diag_type
! variable Col_diag. These arrays remain for the life of the job and
! will be defined for each physics window as it is entered.
!----------------------------------------------------------------------
allocate (Col_diag%i_dc(Col_diag%num_diag_pts))
allocate (Col_diag%j_dc(Col_diag%num_diag_pts))
allocate (Col_diag%unit_dc(Col_diag%num_diag_pts))
allocate (Col_diag%igl_dc(Col_diag%num_diag_pts))
allocate (Col_diag%jgl_dc(Col_diag%num_diag_pts))
end subroutine fms_donner_col_diag
!#####################################################################
! <SUBROUTINE NAME="fms_donner_write_restart">
!
! <DESCRIPTION>
! write out restart file.
! Arguments:
! timestamp (optional, intent(in)) : A character string that represents the model time,
! used for writing restart. timestamp will append to
! the any restart file name as a prefix.
! </DESCRIPTION>
!
subroutine fms_donner_write_restart (Initialized, timestamp)
type(donner_initialized_type), intent(in) :: Initialized
character(len=*), intent(in), optional :: timestamp
!-------------------------------------------------------------------
! call subroutine to write restart file. NOTE: only the netcdf
! restart file is currently supported.
!-------------------------------------------------------------------
if (mpp_pe() == mpp_root_pe() ) then
if (.not. (write_reduced_restart_file) ) then
call error_mesg ('donner_deep_mod', 'write_restart_nc: &
&Writing FULL netCDF formatted restart file as requested: &
&RESTART/donner_deep.res.nc', NOTE)
else
if (Initialized%conv_alarm >= Initialized%physics_dt) then
call error_mesg ('donner_deep_mod', 'write_restart_nc: &
&Writing FULL netCDF formatted restart file; it is needed &
&to allow seamless restart because next step is not a &
&donner calculation step: RESTART/donner_deep.res.nc', NOTE)
else
call error_mesg ('donner_deep_mod', 'write_restart_nc: &
&Writing REDUCED netCDF formatted restart file as &
&requested: RESTART/donner_deep.res.nc', NOTE)
endif
endif
endif
call save_restart(Don_restart, timestamp)
if(in_different_file) call save_restart(Til_restart, timestamp)
end subroutine fms_donner_write_restart
!#####################################################################
subroutine fms_get_pe_number (me, root_pe)
integer, intent(out) :: me, root_pe
me = mpp_pe()
root_pe = mpp_root_pe()
end subroutine fms_get_pe_number
!#####################################################################
subroutine fms_close_col_diag_units
call close_column_diagnostics_units (col_diag_unit)
end subroutine fms_close_col_diag_units
!#####################################################################
subroutine fms_deallocate_variables (Col_diag)
type(donner_column_diag_type), intent(inout) :: Col_diag
if (Col_diag%num_diag_pts > 0) then
deallocate (Col_diag%i_dc )
deallocate (Col_diag%j_dc )
deallocate (Col_diag%unit_dc )
deallocate (Col_diag%igl_dc )
deallocate (Col_diag%jgl_dc )
endif
if (allocated(col_diag_unit)) then
deallocate (col_diag_unit )
deallocate (col_diag_lon )
deallocate (col_diag_lat )
deallocate (col_diag_i )
deallocate (col_diag_j )
endif
if (allocated (id_qtren1)) then
deallocate (id_qtren1)
deallocate (id_qtmes1)
deallocate (id_wtp1 )
deallocate (id_qtceme)
deallocate (id_total_wet_dep)
deallocate (id_meso_wet_dep)
deallocate (id_cell_wet_dep)
deallocate (id_qtren1_col)
deallocate (id_qtmes1_col)
deallocate (id_wtp1_col )
deallocate (id_qtceme_col)
deallocate (id_total_wet_dep_col)
deallocate (id_meso_wet_dep_col)
deallocate (id_cell_wet_dep_col)
endif
if (allocated (id_extremes)) then
deallocate (id_extremes)
deallocate (id_hits)
endif
end subroutine fms_deallocate_variables
!#####################################################################
subroutine fms_sat_vapor_pres
call sat_vapor_pres_init
end subroutine fms_sat_vapor_pres
!#####################################################################
subroutine fms_error_mesg (ermesg)
character(len=*), intent(in) :: ermesg
call error_mesg ('donner_deep_mod', ermesg, FATAL)
end subroutine fms_error_mesg
!######################################################################
subroutine fms_donner_deep_netcdf (is, ie, js, je, Nml, secs, days, &
Param, Initialized, Don_conv, Don_cape,&
Don_cem,parcel_rise, pmass, total_precip, &
Don_budgets, &
temperature_forcing, moisture_forcing)
!---------------------------------------------------------------------
! subroutine donner_deep_netcdf sends the fields requested in the
! diag_table to diag_manager_mod so that they may be appropriately
! processed for output.
!---------------------------------------------------------------------
integer, intent(in) :: is, ie, js, je
integer, intent(in) :: secs, days
type(donner_nml_type), intent(in) :: Nml
type(donner_param_type), intent(in) :: Param
type(donner_initialized_type), intent(inout) :: Initialized
type(donner_conv_type), intent(in) :: Don_conv
type(donner_budgets_type), intent(in) :: Don_budgets
type(donner_cape_type), intent(in) :: Don_cape
type(donner_cem_type), intent(in) :: Don_cem
real, dimension(:,:,:), intent(in) :: pmass, temperature_forcing,&
moisture_forcing
real, dimension(:,:), intent(in) :: parcel_rise, total_precip
!---------------------------------------------------------------------
! intent(in) variables:
!
! is, ie first and last values of i index values of points
! in this physics window (processor coordinates)
! js, je first and last values of j index values of points
! in this physics window (processor coordinates)
! Time current time (time_type)
! Don_conv donner_convection_type derived type variable con-
! taining diagnostics describing the nature of the
! convection produced by the donner parameterization
! Don_cape donner_cape type derived type variable containing
! diagnostics related to the cape calculation assoc-
! iated with the donner convection parameterization
! Don_cem donner_cem_type derived type variable containing
! Donner cumulus ensemble member diagnostics
! temperature_forcing
! temperature tendency due to donner convection
! [ deg K / sec ]
! moisture_forcing
! vapor mixing ratio tendency due to donner
! convection [ kg(h2o) / (kg(dry air) sec ) ]
! pmass mass per unit area within the grid box
! [ kg (air) / (m**2) ]
! parcel_rise accumulated vertical displacement of a near-surface
! parcel as a result of the lowest model level omega
! field [ Pa ]
! total_precip total precipitation rate produced by the
! donner parameterization [ mm / day ]
!
!---------------------------------------------------------------------
!---------------------------------------------------------------------
! local variables:
type(time_type) :: Time
Time = set_time (secs, days)
call donner_deep_netcdf (is, ie, js, je, Nml, Time, Param, &
Initialized, Don_conv, Don_cape,&
Don_cem,parcel_rise, pmass, total_precip, &
Don_budgets, &
temperature_forcing, moisture_forcing)
!----------------------------------------------------------------------
end subroutine fms_donner_deep_netcdf
!###################################################################
subroutine fms_donner_process_monitors (idf, jdf, nlev, &
ntracers, axes, secs, days, Initialized,&
Don_save)
integer, intent(in) :: idf, jdf, nlev, ntracers, secs, days
integer, dimension(4), intent(in) :: axes
type(donner_save_type), intent(inout) :: Don_save
type(donner_initialized_type), intent(inout) :: Initialized
type(time_type) :: Time
Time = set_time (secs,days)
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!
! 9. SET UP CODE TO MONITOR SELECTED OUTPUT VARIABLES.
!
!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
call process_monitors (idf, jdf, nlev, ntracers, axes, Time, &
Initialized, Don_save)
end subroutine fms_donner_process_monitors
!###################################################################
subroutine fms_donner_column_control (is, ie, js, je, secs, days, Col_diag)
!---------------------------------------------------------------------
! subroutine fms_donner_column_control returns the number, location
! (processor and window indices) and output units associated with
! any diagnostic columns requested within the current physics window.
!---------------------------------------------------------------------
integer, intent(in) :: is, ie, js, je
integer, intent(in) :: secs, days
type(donner_column_diag_type), intent(inout) :: Col_diag
type(time_type) :: Time
Time = set_time(secs, days)
call donner_column_control (is, ie, js, je, Time, Col_diag)
end subroutine fms_donner_column_control
!####################################################################
subroutine fms_constants (Param)
type(donner_param_type), intent(inout) :: Param
!----------------------------------------------------------------------
! define the components of Param that come from constants_mod. see
! donner_types.h for their definitions.
!----------------------------------------------------------------------
Param%dens_h2o = DENS_H2O
Param%rdgas = RDGAS
Param%grav = GRAV
Param%cp_air = CP_AIR
Param%pie = PIE
Param%kappa = KAPPA
Param%rvgas = RVGAS
Param%seconds_per_day = SECONDS_PER_DAY
Param%hlv = HLV
Param%hlf = HLF
Param%hls = HLS
Param%kelvin = KELVIN
!----------------------------------------------------------------------
end subroutine fms_constants
!####################################################################
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!
! PRIVATE SUBROUTINES
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!
! 1. ROUTINES CALLED BY DONNER_DEEP_INIT
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!#####################################################################
subroutine register_fields (Time, axes, Don_save, Nml, &
n_water_budget, &
n_enthalpy_budget, n_precip_paths, &
n_precip_types, nlev_hires, kpar)
!----------------------------------------------------------------------
! subroutine register_fields registers all of the potential diagnos-
! tics written by this module with diag_manager_mod.
!----------------------------------------------------------------------
type(time_type), intent(in) :: Time
integer, intent(in) :: n_water_budget, &
n_enthalpy_budget, n_precip_paths, &
n_precip_types, nlev_hires, kpar
integer, dimension(4), intent(in) :: axes
type(donner_save_type), intent(inout) :: Don_save
type(donner_nml_type), intent(inout) :: Nml
!----------------------------------------------------------------------
! intent(in) variables:
!
! Time current time [ time_type ]
! axes data axes for diagnostics
!
!---------------------------------------------------------------------
!---------------------------------------------------------------------
! local variables:
integer :: ntracers ! number of tracers transported by the
! donner deep convection parameterization
integer :: nn ! do-loop index
integer :: ncem ! number of cumulus ensemble members in
! the donner deep convection parameter-
! ization
character(len=2) :: chvers ! character representation of cumulus
! ensemble member number
! define a variable for telling "register_fields" to put output on
! "half-levels" (Reference: Chris Golaz's subroutine "diag_field_init"
! in /home/cjg/FMS/nalanda/nnew3/m45_am2p14_nnew3/src/atmos_param/
! moist_processes/moist_processes.F90)
integer, dimension(3) :: half = (/1,2,4/)
integer, dimension(3) :: cldindices = (/1,2,5/)
integer :: id_cldmodel
real :: cldvindx(NLEV_HIRES)
integer :: k
ncem = kpar
!---------------------------------------------------------------------
! define the axes for the donner cloud model.
!---------------------------------------------------------------------
donner_axes(1:4) = axes(1:4)
if (Nml%do_donner_plume) then
do k=1, NLEV_HIRES
cldvindx(k) = real(k)
end do
id_cldmodel = diag_axis_init('cldvindx', cldvindx, 'level#', &
'z', 'cld model vertical index', &
set_name=mod_name )
donner_axes(5) = id_cldmodel
endif
!----------------------------------------------------------------------
! define the number of tracers that are to be transported by the
! donner deep convection parameterization.
!-------------------------------------------------------------------
ntracers = size(Don_save%tracername(:))
!---------------------------------------------------------------------
! register the various diagnostic fields.
!---------------------------------------------------------------------
if (Nml%do_budget_analysis) then
allocate (id_water_budget (n_water_budget))
allocate (id_ci_water_budget (n_water_budget))
allocate (id_enthalpy_budget (n_enthalpy_budget))
allocate (id_ci_enthalpy_budget (n_enthalpy_budget))
allocate (id_precip_budget (n_precip_paths, n_precip_types))
allocate (id_ci_precip_budget (n_precip_paths, n_precip_types))
id_water_budget(1) = register_diag_field &
(mod_name, 'vapor_net_tend', axes(1:3), &
Time, 'net water vapor tendency', &
'g(h2o) / kg(air) / day', &
missing_value=missing_value)
id_water_budget(2) = register_diag_field &
(mod_name, 'vapor_cell_dynam', axes(1:3), &
Time, 'vapor tendency due to cell dynamics', &
' g(h2o) / kg(air) / day', &
missing_value=missing_value)
id_water_budget(3) = register_diag_field &
(mod_name, 'vapor_meso_depo', axes(1:3), &
Time, 'vapor tendency from mesoscale deposition', &
' g(h2o) / kg(air) / day', &
missing_value=missing_value)
id_water_budget(4) = register_diag_field &
(mod_name, 'vapor_meso_cd', axes(1:3), &
Time, 'vapor tendency from mesoscale condensation', &
' g(h2o) / kg(air) / day', &
missing_value=missing_value)
id_water_budget(5) = register_diag_field &
(mod_name, 'vapor_cell_evap', axes(1:3), &
Time, 'vapor tendency from cell evaporation', &
' g(h2o) / kg(air) / day', &
missing_value=missing_value)
id_water_budget(6) = register_diag_field &
(mod_name, 'vapor_cell_meso_trans', axes(1:3), &
Time, 'vapor tendency from cell to mesoscale transfer', &
' g(h2o) / kg(air) / day', &
missing_value=missing_value)
id_water_budget(7) = register_diag_field &
(mod_name, 'vapor_meso_evap', axes(1:3), &
Time, 'vapor tendency from mesoscale evaporation', &
' g(h2o) / kg(air) / day', &
missing_value=missing_value)
id_water_budget(8) = register_diag_field &
(mod_name, 'vapor_meso_dynam_up', axes(1:3), &
Time, 'vapor tendency from mesoscale updrafts', &
' g(h2o) / kg(air) / day', &
missing_value=missing_value)
id_water_budget(9) = register_diag_field &
(mod_name, 'vapor_meso_dynam_dn', axes(1:3), &
Time, 'vapor tendency from mesoscale downdrafts', &
' g(h2o) / kg(air) / day', &
missing_value=missing_value)
id_enthalpy_budget(1) = register_diag_field &
(mod_name, 'enth_net_tend', axes(1:3), &
Time, 'net temp tendency', 'deg K /day', &
missing_value=missing_value)
id_enthalpy_budget(2) = register_diag_field &
(mod_name, 'enth_cell_dynam', axes(1:3), &
Time, 'temp tendency due to cell dynamics', &
'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(3) = register_diag_field &
(mod_name, 'enth_meso_depo_liq', axes(1:3), Time, &
'temp tendency from mesoscale deposition on liquid&
& condensate', 'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(4) = register_diag_field &
(mod_name, 'enth_meso_cd_liq', axes(1:3), Time, &
' temp tendency from mesoscale liquid condensation', &
'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(5) = register_diag_field &
(mod_name, 'enth_cell_evap_liq', axes(1:3), &
Time, 'temp tendency from evap of liquid condensate', &
'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(6) = register_diag_field &
(mod_name, 'enth_meso_evap_liq_up', axes(1:3), &
Time, 'temp tendency from evaporation of liquid &
&condensate in mesoscale updrafts', &
'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(7) = register_diag_field &
(mod_name, 'enth_meso_evap_liq_dn', axes(1:3), &
Time, 'temp tendency from evaporation of liquid &
&condensate in mesoscale downdrafts', &
'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(8) = register_diag_field &
(mod_name, 'enth_meso_depo_ice', axes(1:3), &
Time, ' temp tendency from mesoscale deposition on &
&ice condensate', 'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(9) = register_diag_field &
(mod_name, 'enth_meso_cd_ice', axes(1:3), &
Time, 'temp tendency from mesoscale ice condensation', &
'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(10) = register_diag_field &
(mod_name, 'enth_cell_evap_ice', axes(1:3), &
Time, 'temp tendency from evap of ice condensate', &
'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(11) = register_diag_field &
(mod_name, 'enth_meso_evap_ice_up', axes(1:3), &
Time, 'temp tendency from evaporation of ice condensate &
&in mesoscale updrafts', 'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(12) = register_diag_field &
(mod_name, 'enth_meso_evap_ice_dn', axes(1:3), &
Time, 'temp tendency from evaporation of ice &
&condensate in mesoscale downdrafts', 'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(13) = register_diag_field &
(mod_name, 'enth_meso_freeze', axes(1:3), &
Time, 'temp tendency from the freezing of liquid &
&condensate when it enters the mesoscale circulation', &
'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(14) = register_diag_field &
(mod_name, 'enth_cell_freeze', axes(1:3), &
Time, 'temp tendency from the freezing of liquid &
&cell condensate', 'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(15) = register_diag_field &
(mod_name, 'enth_cell_precip_melt', axes(1:3), &
Time, 'temp tendency from the melting of cell frozen &
&liquid and ice that is precipitating out', 'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(16) = register_diag_field &
(mod_name, 'enth_meso_melt', axes(1:3), Time, &
'temp tendency from melting bogus frozen condensate', &
'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(17) = register_diag_field &
(mod_name, 'enth_meso_precip_melt', axes(1:3), &
Time, 'temp tendency from the melting of frozen &
&mesoscale precipitation', 'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(18) = register_diag_field &
(mod_name, 'enth_meso_dynam_up', axes(1:3), &
Time, 'temp tendency from mesoscale updraft', &
'deg K / day', &
missing_value=missing_value)
id_enthalpy_budget(19) = register_diag_field &
(mod_name, 'enth_meso_dynam_dn', axes(1:3), &
Time, 'temp tendency from mesoscale downdraft', &
'deg K / day', &
missing_value=missing_value)
id_precip_budget(1,1) = register_diag_field &
(mod_name, 'precip_cell_liq', axes(1:3), &
Time, 'precip from cell liquid condensate', &
'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(2,1) = register_diag_field &
(mod_name, 'precip_cell_liq_frz', axes(1:3), &
Time, 'precip from cell liquid condensate which froze', &
'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(3,1) = register_diag_field &
(mod_name, 'precip_cell_liq_frz_melt', axes(1:3), Time, &
'precip from cell liquid condensate which froze &
&and remelted', 'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(4,1) = register_diag_field &
(mod_name, 'precip_cell_ice', axes(1:3), &
Time, 'precip from cell ice condensate', &
'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(5,1) = register_diag_field &
(mod_name, 'precip_cell_ice_melt', axes(1:3), &
Time, 'precip from cell ice condensate which melted', &
'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(1,2) = register_diag_field &
(mod_name, 'precip_trans_liq', axes(1:3), &
Time, 'precip from cell liquid transferred to meso', &
'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(2,2) = register_diag_field &
(mod_name, 'precip_trans_liq_frz', axes(1:3), &
Time, 'precip from cell liquid transferred to meso &
&which froze', 'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(3,2) = register_diag_field &
(mod_name, 'precip_trans_liq_frz_melt', axes(1:3), Time, &
'precip from cell liquid transferred to meso which &
&froze and remelted', 'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(4,2) = register_diag_field &
(mod_name, 'precip_trans_ice', axes(1:3), &
Time, 'precip from cell ice transferred to meso', &
'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(5,2) = register_diag_field &
(mod_name, 'precip_trans_ice_melt', axes(1:3), &
Time, 'precip from cell ice transferred to meso &
&which melted', 'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(1,3) = register_diag_field &
(mod_name, 'precip_meso_liq', axes(1:3), &
Time, 'precip from meso liq condensate', &
'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(2,3) = register_diag_field &
(mod_name, 'precip_meso_liq_frz', axes(1:3), &
Time, 'precip from meso liq condensate which froze', &
'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(3,3) = register_diag_field &
(mod_name, 'precip_meso_liq_frz_melt', axes(1:3), Time, &
'precip from meso condensate liq which froze and &
&remelted', 'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(4,3) = register_diag_field &
(mod_name, 'precip_meso_ice', axes(1:3), &
Time, 'precip from meso ice condensate', &
'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_precip_budget(5,3) = register_diag_field &
(mod_name, 'precip_meso_ice_melt', axes(1:3), &
Time, 'precip from meso ice condensate which melted', &
'kg(h2o) / kg(air) / day', &
missing_value=missing_value)
id_ci_precip_budget(1,1) = register_diag_field &
(mod_name, 'ci_precip_cell_liq', axes(1:2), &
Time, 'col intg precip from cell liquid condensate', &
'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(2,1) = register_diag_field &
(mod_name, 'ci_precip_cell_liq_frz', axes(1:2), &
Time, 'col intg precip from cell liquid condensate &
&which froze', 'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(3,1) = register_diag_field &
(mod_name, 'ci_precip_cell_liq_frz_melt', axes(1:2), Time, &
'col intg precip from cell liquid condensate which &
&froze and remelted', 'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(4,1) = register_diag_field &
(mod_name, 'ci_precip_cell_ice', axes(1:2), &
Time, 'col intg precip from cell ice condensate', &
'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(5,1) = register_diag_field &
(mod_name, 'ci_precip_cell_ice_melt', axes(1:2), &
Time, 'col intg precip from cell ice condensate &
&which melted', 'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(1,2) = register_diag_field &
(mod_name, 'ci_precip_trans_liq', axes(1:2), &
Time, 'col intg precip from cell liquid transferred &
&to meso', 'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(2,2) = register_diag_field &
(mod_name, 'ci_precip_trans_liq_frz', axes(1:2), &
Time, 'col intg precip from cell liquid transferred &
&to meso which froze', 'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(3,2) = register_diag_field &
(mod_name, 'ci_precip_trans_liq_frz_melt', axes(1:2), &
Time, 'col intg precip from cell liquid transferred &
&to meso which froze and remelted', 'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(4,2) = register_diag_field &
(mod_name, 'ci_precip_trans_ice', axes(1:2), &
Time, 'col intg precip from cell ice transferred &
&to meso', 'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(5,2) = register_diag_field &
(mod_name, 'ci_precip_trans_ice_melt', axes(1:2), &
Time, 'col intg precip from cell ice transferred to &
&meso which melted', 'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(1,3) = register_diag_field &
(mod_name, 'ci_precip_meso_liq', axes(1:2), &
Time, 'col intg precip from meso liq condensate', &
'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(2,3) = register_diag_field &
(mod_name, 'ci_precip_meso_liq_frz', axes(1:2), &
Time, 'col intg precip from meso liq condensate &
&which froze', 'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(3,3) = register_diag_field &
(mod_name, 'ci_precip_meso_liq_frz_melt', axes(1:2), Time, &
'col intg precip from meso condensate liq which froze &
&and remelted', 'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(4,3) = register_diag_field &
(mod_name, 'ci_precip_meso_ice', axes(1:2), &
Time, 'col intg precip from meso ice condensate', &
'mm / day', &
missing_value=missing_value)
id_ci_precip_budget(5,3) = register_diag_field &
(mod_name, 'ci_precip_meso_ice_melt', axes(1:2), &
Time, 'col intg precip from meso ice condensate &
&which melted', 'mm / day', &
missing_value=missing_value)
id_ci_water_budget(1) = register_diag_field &
(mod_name, 'ci_vapor_net_tend', axes(1:2), &
Time, 'col intg net water vapor tendency', 'mm / day', &
missing_value=missing_value)
id_ci_water_budget(2) = register_diag_field &
(mod_name, 'ci_vapor_cell_dynam', axes(1:2), &
Time, 'col intg vapor tendency due to cell dynamics', &
'mm / day', &
missing_value=missing_value)
id_ci_water_budget(3) = register_diag_field &
(mod_name, 'ci_vapor_meso_depo', axes(1:2), &
Time, 'col intg vapor tendency from mesoscale deposition',&
'mm / day', &
missing_value=missing_value)
id_ci_water_budget(4) = register_diag_field &
(mod_name, 'ci_vapor_meso_cd', axes(1:2), &
Time, 'col intg vapor tendency from mesoscale &
&condensation', 'mm / day', &
missing_value=missing_value)
id_ci_water_budget(5) = register_diag_field &
(mod_name, 'ci_vapor_cell_evap', axes(1:2), &
Time, 'col intg vapor tendency from cell evaporation', &
'mm / day', missing_value=missing_value)
id_ci_water_budget(6) = register_diag_field &
(mod_name, 'ci_vapor_cell_meso_trans', axes(1:2), &
Time, 'col intg vapor tendency from cell to mesoscale &
&transfer', 'mm / day', &
missing_value=missing_value)
id_ci_water_budget(7) = register_diag_field &
(mod_name, 'ci_vapor_meso_evap', axes(1:2), &
Time, 'col intg vapor tendency from mesoscale &
&evaporation', 'mm / day', &
missing_value=missing_value)
id_ci_water_budget(8) = register_diag_field &
(mod_name, 'ci_vapor_meso_dynam_up', axes(1:2), &
Time, 'col intg vapor tendency from mesoscale updrafts', &
'mm / day', &
missing_value=missing_value)
id_ci_water_budget(9) = register_diag_field &
(mod_name, 'ci_vapor_meso_dynam_dn', axes(1:2), &
Time, 'col intg vapor tendency from mesoscale downdrafts',&
'mm / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(1) = register_diag_field &
(mod_name, 'ci_enth_net_tend', axes(1:2), &
Time, 'col intg net enthalpy tendency', 'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(2) = register_diag_field &
(mod_name, 'ci_enth_cell_dynam', axes(1:2), &
Time, 'col intg enthalpy tendency due to cell dynamics', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(3) = register_diag_field &
(mod_name, 'ci_enth_meso_depo_liq', axes(1:2), &
Time, 'col intg enthalpy tendency from mesoscale &
&deposition on liquid condensate', 'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(4) = register_diag_field &
(mod_name, 'ci_enth_meso_cd_liq', axes(1:2), &
Time, 'col intg enthalpy tendency from mesoscale &
&liquid condensation', 'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(5) = register_diag_field &
(mod_name, 'ci_enth_cell_evap_liq', axes(1:2), &
Time, 'col intg enthalpy tendency from evap of liquid &
&condensate', 'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(6) = register_diag_field &
(mod_name, 'ci_enth_meso_evap_liq_up', axes(1:2), &
Time, 'col intg enthalpy tendency from evaporation of &
&liquid condensate in mesoscale updrafts', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(7) = register_diag_field &
(mod_name, 'ci_enth_meso_evap_liq_dn', axes(1:2), &
Time, 'col intg enthalpy tendency from evaporation &
&of liquid condensate in mesoscale downdrafts', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(8) = register_diag_field &
(mod_name, 'ci_enth_meso_depo_ice', axes(1:2), &
Time, 'col intg enthalpy tendency from mesoscale &
&deposition on ice condensate', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(9) = register_diag_field &
(mod_name, 'ci_enth_meso_cd_ice', axes(1:2), &
Time, 'col intg enthalpy tendency from mesoscale ice &
&condensation', 'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(10) = register_diag_field &
(mod_name, 'ci_enth_cell_evap_ice', axes(1:2), &
Time, 'col intg enthalpy tendency from evap of ice &
&condensate', 'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(11) = register_diag_field &
(mod_name, 'ci_enth_meso_evap_ice_up', axes(1:2), &
Time, 'col intg enthalpy tendency from evaporation of &
&ice condensate in mesoscale updrafts', 'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(12) = register_diag_field &
(mod_name, 'ci_enth_meso_evap_ice_dn', axes(1:2), &
Time, 'col intg enthalpy tendency from evaporation of &
&ice condensate in mesoscale downdrafts', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(13) = register_diag_field &
(mod_name, 'ci_enth_meso_freeze', axes(1:2), &
Time, 'col intg enthalpy tendency from the freezing of &
&liquid condensate when it enters the mesoscale &
&circulation', 'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(14) = register_diag_field &
(mod_name, 'ci_enth_cell_freeze', axes(1:2), &
Time, 'col intg enthalpy tendency from the freezing of &
&liquid cell condensate', 'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(15) = register_diag_field &
(mod_name, 'ci_enth_cell_precip_melt', axes(1:2), &
Time, 'col intg enthalpy tendency from the melting of &
&cell frozen liquid and ice that is precipitating out', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(16) = register_diag_field &
(mod_name, 'ci_enth_meso_melt', axes(1:2), &
Time, 'col intg enthalpy tendency from melting bogus &
&frozen condensate', 'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(17) = register_diag_field &
(mod_name, 'ci_enth_meso_precip_melt', axes(1:2), &
Time, 'col intg enthalpy tendency from the melting of &
&frozen mesoscale precipitation', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(18) = register_diag_field &
(mod_name, 'ci_enth_meso_dynam_up', axes(1:2), &
Time, 'col intg enthalpy tendency from mesoscale updraft',&
'J/m**2 / day', &
missing_value=missing_value)
id_ci_enthalpy_budget(19) = register_diag_field &
(mod_name, 'ci_enth_meso_dynam_dn', axes(1:2), &
Time, 'col intg enthalpy tendency from mesoscale &
&downdraft', 'J/m**2 / day', &
missing_value=missing_value)
id_ci_prcp_heat_frz_cell = register_diag_field &
(mod_name, 'ci_prcp_heat_frz_cell', axes(1:2), &
Time, 'col intg heat removed by frozen cell precip', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_prcp_heat_liq_cell = register_diag_field &
(mod_name, 'ci_prcp_heat_liq_cell', axes(1:2), &
Time, 'col intg heat removed by liquid cell precip', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_prcp_heat_frz_meso = register_diag_field &
(mod_name, 'ci_prcp_heat_frz_meso', axes(1:2), &
Time, 'col intg heat removed by frozen meso precip', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_prcp_heat_liq_meso = register_diag_field &
(mod_name, 'ci_prcp_heat_liq_meso', axes(1:2), &
Time, 'col intg heat removed by liquid meso precip', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_prcp_heat_total = register_diag_field &
(mod_name, 'ci_prcp_heat_total', axes(1:2), &
Time, 'col intg total heat removed by precip', &
'J/m**2 / day', &
missing_value=missing_value)
id_ci_prcp_total = register_diag_field &
(mod_name, 'ci_prcp_total', axes(1:2), &
Time, 'col intg total precip', &
'mm / day', &
missing_value=missing_value)
endif
id_leff = register_diag_field &
(mod_name, 'leff_don', axes(1:2), &
Time, 'effective latent heat with donner precip ', &
'J/kg(h2o)', missing_value=missing_value)
! heating rate:
id_cemetf_deep = register_diag_field &
(mod_name, 'cemetf_deep', axes(1:3), &
Time, 'heating rate, c + m ', 'K/s', &
missing_value=missing_value)
! cell entropy flux convergence:
id_ceefc_deep = register_diag_field &
(mod_name, 'ceefc_deep', axes(1:3), &
Time, 'cell entrpy flx cnvrgnc', 'K/s', &
missing_value=missing_value)
! cell condensation / evaporation:
id_cecon_deep = register_diag_field &
(mod_name, 'cecon_deep', axes(1:3), &
Time, 'cell cond/evap ', 'K/s', &
missing_value=missing_value)
! cell moisture flux convergence:
id_cemfc_deep = register_diag_field &
(mod_name, 'cemfc_deep', axes(1:3), &
Time, 'cell moist flx cnvgnc', 'kg(h2o)/kg/s', &
missing_value=missing_value)
! moistening rate:
id_cememf_deep = register_diag_field &
(mod_name, 'cememf_deep', axes(1:3), &
Time, 'moistening rate, c + m ', 'kg(h2o)/kg/s', &
missing_value=missing_value)
! moistening rate after adjustment for negative vapor mixing ratio:
id_cememf_mod_deep = register_diag_field &
(mod_name, 'cememf_mod_deep', axes(1:3),&
Time, 'mod cememf due to negative q ', 'kg(h2o)/kg/s', &
missing_value=missing_value)
! cell + mesoscale cloud fraction:
id_cual_deep = register_diag_field &
(mod_name, 'cual_deep', axes(1:3), &
Time, 'c + m cld frac ', 'percent', &
missing_value=missing_value)
! heating rate due to freezing:
id_fre_deep = register_diag_field &
(mod_name, 'fre_deep', axes(1:3), &
Time, 'freezing ', 'K/sec', &
missing_value=missing_value)
! heating rate due to melting:
id_elt_deep = register_diag_field &
(mod_name, 'elt_deep', axes(1:3), &
Time, 'melting', 'K/sec', &
missing_value=missing_value)
! deposition in mesoscale updraft:
id_cmus_deep = register_diag_field &
(mod_name, 'cmus_deep', axes(1:3), &
Time, 'meso-up deposition', 'kg(h2o)/kg/sec)', &
missing_value=missing_value)
! evaporation in convective downdraft:
id_ecds_deep = register_diag_field &
(mod_name, 'ecds_deep', axes(1:3), &
Time, 'convective dwndrft evap ', 'kg(h2o)/kg/sec', &
missing_value=missing_value)
! evaporation / sublimation in convective updraft:
id_eces_deep = register_diag_field &
(mod_name, 'eces_deep', axes(1:3), &
Time, 'convective updrft evap/subl ', 'kg(h2o)/kg/sec', &
missing_value=missing_value)
! sublimation in mesoscale downdraft:
id_emds_deep = register_diag_field &
(mod_name, 'emds_deep', axes(1:3), &
Time, 'meso-dwn subl ', 'kg(h2o)/kg/sec', &
missing_value=missing_value)
! sublimation in mesoscale updraft:
id_emes_deep = register_diag_field &
(mod_name, 'emes_deep', axes(1:3), &
Time, 'meso-up subl ', 'kg(h2o)/kg/sec', &
missing_value=missing_value)
! mesoscale moisture flux convergence:
id_qmes_deep = register_diag_field &
(mod_name, 'qmes_deep', axes(1:3), &
Time, 'meso moist flux conv', 'kg(h2o)/kg/sec', &
missing_value=missing_value)
! transfer of vapor from cells to mesoscale:
id_wmps_deep = register_diag_field &
(mod_name, 'wmps_deep', axes(1:3), &
Time, 'meso redistrib of vapor from cells', &
'kg(h2o)/kg/sec', missing_value=missing_value)
! deposition of vapor from cells to mesoscale:
id_wmms_deep = register_diag_field &
(mod_name, 'wmms_deep', axes(1:3), &
Time, 'meso depo of vapor from cells', &
'kg(h2o)/kg/sec', missing_value=missing_value)
! mesoscale entropy flux convergesnce:
id_tmes_deep = register_diag_field &
(mod_name, 'tmes_deep', axes(1:3), &
Time, 'meso entropy flux conv', 'K/sec', &
missing_value=missing_value)
! mass flux in mesoscale downdrafts:
id_dmeml_deep = register_diag_field &
(mod_name, 'dmeml_deep', axes(1:3), &
Time, 'mass flux meso dwndrfts', 'kg/((m**2) s)', &
missing_value=missing_value)
! mass flux in cell updrafts:
id_uceml_deep = register_diag_field &
(mod_name, 'uceml_deep', axes(1:3), &
Time, 'mass flux cell updrfts', 'kg/((m**2) s)', &
missing_value=missing_value)
! mass flux in mesoscale updrafts:
id_umeml_deep = register_diag_field &
(mod_name, 'umeml_deep', axes(1:3), &
Time, 'mass flux meso updrfts', 'kg/((m**2) s)', &
missing_value=missing_value)
! mesoscale ice mass mixing ratio:
id_xice_deep = register_diag_field &
(mod_name, 'xice_deep', axes(1:3), &
Time, 'meso ice mass mixing ratio ', 'kg(ice)/kg', &
missing_value=missing_value)
! mesoscale liquid mass mixing ratio:
id_xliq_deep = register_diag_field &
(mod_name, 'xliq_deep', axes(1:3), &
Time, 'meso liq mass mixing ratio ', 'kg(liq)/kg', &
missing_value=missing_value)
! detrained mass flux:
id_detmfl_deep = register_diag_field &
(mod_name, 'detmfl_deep', axes(1:3), &
Time, 'detrained mass flux ', 'kg/((m**2) s)', &
missing_value=missing_value)
!---------------------------------------------------------------------
! if tracers are being transported by donner_deep_mod, allocate diag-
! nostic indices for each tracer and register their diagnostics.
!---------------------------------------------------------------------
if (ntracers > 0) then
allocate (id_qtren1 (ntracers))
allocate (id_qtmes1 (ntracers))
allocate (id_wtp1 (ntracers))
allocate (id_qtceme (ntracers))
allocate (id_total_wet_dep (ntracers))
allocate (id_meso_wet_dep (ntracers))
allocate (id_cell_wet_dep (ntracers))
allocate (id_qtren1_col (ntracers))
allocate (id_qtmes1_col (ntracers))
allocate (id_wtp1_col (ntracers))
allocate (id_qtceme_col (ntracers))
allocate (id_total_wet_dep_col (ntracers))
allocate (id_meso_wet_dep_col (ntracers))
allocate (id_cell_wet_dep_col (ntracers))
do nn=1,ntracers
! tracer tendency due to cells:
id_qtren1(nn) = register_diag_field &
(mod_name, trim(Don_save%tracername(nn)) // '_qtren1', &
axes(1:3), Time, &
trim(Don_save%tracername(nn)) // ' cell tendency ', &
trim(Don_save%tracer_units(nn))//'/s', &
missing_value=missing_value)
! tracer tendency due to mesoscale circulation:
id_qtmes1(nn) = register_diag_field &
(mod_name, trim(Don_save%tracername(nn)) // '_qtmes1', &
axes(1:3), Time, &
trim(Don_save%tracername(nn)) //' mesoscale tendency',&
trim(Don_save%tracer_units(nn))//'/s', &
missing_value=missing_value)
! tracer tendency due to mesoscale redistribution:
id_wtp1(nn) = register_diag_field &
(mod_name, trim(Don_save%tracername(nn)) // '_wtp1', &
axes(1:3), Time, &
trim(Don_save%tracername(nn)) //' mesoscale redist',&
trim(Don_save%tracer_units(nn))//'/s', &
missing_value=missing_value)
! tracer tendency due to deep convective wet deposition:
id_total_wet_dep(nn) = register_diag_field &
(mod_name, trim(Don_save%tracername(nn)) // '_totwdep', &
axes(1:3), Time, &
trim(Don_save%tracername(nn)) //' deep conv wet depo',&
trim(Don_save%tracer_units(nn))//'/s', &
missing_value=missing_value)
! tracer tendency due to wet deposition in mesoscale updrafts:
id_meso_wet_dep(nn) = register_diag_field &
(mod_name, trim(Don_save%tracername(nn)) // '_mwdep', &
axes(1:3), Time, &
trim(Don_save%tracername(nn)) //' mesoscale wet depo',&
trim(Don_save%tracer_units(nn))//'/s', &
missing_value=missing_value)
! tracer tendency due to wet deposition in cells:
id_cell_wet_dep(nn) = register_diag_field &
(mod_name, trim(Don_save%tracername(nn)) // '_cwdep', &
axes(1:3), Time, &
trim(Don_save%tracername(nn)) //' cell wet depo',&
trim(Don_save%tracer_units(nn))//'/s', &
missing_value=missing_value)
! total tracer tendency:
id_qtceme(nn) = register_diag_field &
(mod_name, trim(Don_save%tracername(nn)) // '_qtceme', &
axes(1:3), Time, &
trim(Don_save%tracername(nn)) // ' total tendency ',&
trim(Don_save%tracer_units(nn))//'/s', &
missing_value=missing_value)
! column-integrated tracer tendency due to cells:
id_qtren1_col(nn) = register_diag_field &
(mod_name, &
trim(Don_save%tracername(nn)) // '_qtren1_col', &
axes(1:2), Time, &
'column integrated ' //trim(Don_save%tracername(nn)) //&
' cell tendency ', &
trim(Don_save%tracer_units(nn)) // '* kg/(m**2 s) ', &
missing_value=missing_value)
! column-integrated tracer tendency due to mesoscale circulation:
id_qtmes1_col(nn) = register_diag_field &
(mod_name, &
trim(Don_save%tracername(nn)) // '_qtmes1_col', &
axes(1:2), Time, &
'column integrated ' //trim(Don_save%tracername(nn)) //&
' mesoscale tendency',&
trim(Don_save%tracer_units(nn)) // '* kg/(m**2 s) ', &
missing_value=missing_value)
! column-integrated tracer tendency due to mesoscale redistribution:
id_wtp1_col(nn) = register_diag_field &
(mod_name, &
trim(Don_save%tracername(nn)) // '_wtp1_col', &
axes(1:2), Time, &
'column integrated '//trim(Don_save%tracername(nn)) // &
' mesoscale redist',&
trim(Don_save%tracer_units(nn)) // '* kg/(m**2 s) ', &
missing_value=missing_value)
! column-integrated tracer tendency due to deep convective wet
! deposition:
id_total_wet_dep_col(nn) = register_diag_field &
(mod_name, &
trim(Don_save%tracername(nn)) // '_totwdep_col', &
axes(1:2), Time, &
'column integrated '//trim(Don_save%tracername(nn)) // &
' deep convective wet depo',&
trim(Don_save%tracer_units(nn)) // '* kg/(m**2 s) ', &
missing_value=missing_value)
! column-integrated tracer tendency due to mesocscale updraft wet
! deposition:
id_meso_wet_dep_col(nn) = register_diag_field &
(mod_name, &
trim(Don_save%tracername(nn)) // '_mwdep_col', &
axes(1:2), Time, &
'column integrated '//trim(Don_save%tracername(nn)) // &
' meso updraft wet depo',&
trim(Don_save%tracer_units(nn)) // '* kg/(m**2 s) ', &
missing_value=missing_value)
! column-integrated tracer tendency due to wet deposition in cells:
id_cell_wet_dep_col(nn) = register_diag_field &
(mod_name, &
trim(Don_save%tracername(nn)) // '_cwdep_col', &
axes(1:2), Time, &
'column integrated '//trim(Don_save%tracername(nn)) // &
' cell wet depo',&
trim(Don_save%tracer_units(nn)) // '* kg/(m**2 s) ', &
missing_value=missing_value)
! column-integrated total tracer tendency:
id_qtceme_col(nn) = register_diag_field &
(mod_name, &
trim(Don_save%tracername(nn)) // '_qtceme_col', &
axes(1:2), Time, &
'column integrated ' //trim(Don_save%tracername(nn)) //&
' total tendency ', &
trim(Don_save%tracer_units(nn)) // '* kg/(m**2 s) ', &
missing_value=missing_value)
end do
endif
! mesoscale ice generalized effective size:
id_dgeice_deep = register_diag_field &
(mod_name, 'dgeice_deep', axes(1:3), &
Time, 'meso ice gen eff size ', 'micrometers', &
missing_value=missing_value)
! cell ice mixing ratio:
id_cuqi_deep = register_diag_field &
(mod_name, 'cuqi_deep', axes(1:3), &
Time, 'cell ice ', 'kg(H2O)/kg', &
missing_value=missing_value)
! cell liquid mixing ratio:
id_cuql_deep = register_diag_field &
(mod_name, 'cuql_deep', axes(1:3), &
Time, 'cell liquid ', 'kg(H2O)/kg', &
missing_value=missing_value)
! cell liquid generalized effective size:
id_dgeliq_deep = register_diag_field &
(mod_name, 'dgeliq_deep', axes(1:3), &
Time, 'cell liq gen eff size ', 'micrometers', &
missing_value=missing_value)
! pressure at lifting condensation level:
id_plcl_deep = register_diag_field &
(mod_name, 'plcl_deep', axes(1:2), &
Time, 'pressure at lcl ', 'Pa ', &
missing_value=missing_value)
! pressure at level of free convection:
id_plfc_deep = register_diag_field &
(mod_name, 'plfc_deep', axes(1:2), &
Time, 'pressure at lfc ', 'Pa ', &
missing_value=missing_value)
! pressure at level of zero buoyancy:
id_plzb_deep = register_diag_field &
(mod_name, 'plzb_deep', axes(1:2), &
Time, 'pressure at lzb ', 'Pa ', &
missing_value=missing_value)
! convective available potential energy (cape):
id_xcape_deep = register_diag_field &
(mod_name, 'xcape_deep', axes(1:2), &
Time, 'cape', 'J/kg', &
missing_value=missing_value)
! convective inhibition:
id_coin_deep = register_diag_field &
(mod_name, 'coin_deep', axes(1:2), &
Time, 'convective inhibition ', 'J/kg', &
missing_value=missing_value)
! time tendency of cape:
id_dcape_deep = register_diag_field &
(mod_name, 'dcape_deep', axes(1:2), &
Time, 'time tendency of cape ', 'J/kg/sec', &
missing_value=missing_value)
! column integrated water vapor:
id_qint_deep = register_diag_field &
(mod_name, 'qint_deep', axes(1:2), &
Time, 'column moisture ', 'kg(h2o)/m**2', &
missing_value=missing_value)
! fractional area of cumulus ensemble member:
id_a1_deep = register_diag_field &
(mod_name, 'a1_deep', axes(1:2), &
Time, 'fractional area of cu subensemble ', 'percent', &
missing_value=missing_value)
! fractional area of largest cumulus ensemble member:
id_amax_deep = register_diag_field &
(mod_name, 'amax_deep', axes(1:2), &
Time, 'fractional area of largest cu subensemble ', &
'percent', missing_value=missing_value)
! upper limit onfractional area based on moisture constraint:
id_amos_deep = register_diag_field &
(mod_name, 'amos_deep', axes(1:2), &
Time, 'uppr lmt on frac area from moisture', 'percent', &
missing_value=missing_value)
! area-weighted total precipitation:
id_tprea1_deep = register_diag_field &
(mod_name, 'tprea1_deep', axes(1:2), &
Time, 'area wtd total precip ', 'mm/day', &
missing_value=missing_value)
! mesoscale cloud fraction:
id_ampta1_deep = register_diag_field &
(mod_name, 'ampta1_deep', axes(1:2), &
Time, 'meso cld frac', 'percent', &
missing_value=missing_value)
! accumulated low-level vertical displacement:
id_omint_deep = register_diag_field &
(mod_name, 'omint_deep', axes(1:2), &
Time, 'accumulated low-lvl displ', 'Pa ', &
missing_value=missing_value)
! area-weighted convective precipitation:
id_rcoa1_deep = register_diag_field &
(mod_name, 'rcoa1_deep', axes(1:2), &
Time, 'area wtd cnvctv precip ', 'mm/day', &
missing_value=missing_value)
!----------------------------------------------------------------------
if (do_ensemble_diagnostics) then
!
allocate ( id_cpre_cem(ncem))
allocate ( id_pb_cem(ncem))
allocate ( id_ptma_cem(ncem))
allocate ( id_h1_cem(ncem))
allocate ( id_qlw_cem(ncem))
allocate ( id_cfi_cem(ncem))
allocate ( id_wv_cem(ncem))
allocate ( id_rcl_cem(ncem))
! Donner cumulus ensemble member diagnostics
!
! GCM model pressure field on full levels:
id_pfull_cem = register_diag_field &
(mod_name, 'p_full', axes(1:3), &
Time, 'GCM model pressure on full levels (lo-res)', 'Pa', &
missing_value=missing_value)
! GCM model pressure field on half levels:
id_phalf_cem = register_diag_field &
(mod_name, 'p_half', axes(half), &
Time, 'GCM model pressure on half levels (lo-res)', 'Pa', &
missing_value=missing_value)
! GCM model height field on full levels:
id_zfull_cem = register_diag_field &
(mod_name, 'z_full', axes(1:3), &
Time, 'GCM model height on full levels (lo-res)', 'm', &
missing_value=missing_value)
! GCM model height field on half levels:
id_zhalf_cem = register_diag_field &
(mod_name, 'z_half', axes(half), &
Time, 'GCM model height on half levels (lo-res)', 'm', &
missing_value=missing_value)
! GCM model temperature field on full levels:
id_temp_cem = register_diag_field &
(mod_name, 'temp', axes(1:3), &
Time, 'GCM model temperature on full levels (lo-res)', 'K', &
missing_value=missing_value)
! GCM model mixing ratio field on full levels:
id_mixing_ratio_cem = register_diag_field &
(mod_name, 'mixing_ratio', axes(1:3), &
Time, 'GCM model mixing ratio on full levels (lo-res)', &
'kg(h2o)/kg(dry air)', &
missing_value=missing_value)
do nn=1,ncem
if( nn <= 9 )then
write( chvers, '(i1)' ) nn
else if( nn <= 99 )then
write( chvers, '(i2)' ) nn
else
print *, 'Error in subroutine register_fields:'
print *, ' number of specified cumulus ensemble members = ',ncem
print *, ' is more than current limit of 99.'
! stop
call error_mesg ('fms_donner_mod', 'register_fields: &
&Error in subroutine register_fields : number of specified &
&cumulus ensemble members is more than current limit of 99.',&
FATAL)
endif
! area-weighted convective precipitation rate:
id_cpre_cem(nn) = register_diag_field &
(mod_name, 'cpre_cem'//TRIM(chvers), axes(1:2), &
Time, 'area wtd cnvctv precip rate - member '//TRIM(chvers), &
'mm/day', &
missing_value=missing_value)
! pressure at cloud base:
id_pb_cem(nn) = register_diag_field &
(mod_name, 'pb_cem'//TRIM(chvers), axes(1:2), &
Time, 'pressure at cloud base - member '//TRIM(chvers), &
'Pa', &
missing_value=missing_value)
! pressure at cloud top:
id_ptma_cem(nn) = register_diag_field &
(mod_name, 'ptma_cem'//TRIM(chvers), axes(1:2), &
Time, 'pressure at cloud top - member '//TRIM(chvers), &
'Pa', &
missing_value=missing_value)
! condensation rate profile on lo-res grid:
id_h1_cem(nn) = register_diag_field &
(mod_name, 'h1_cem'//TRIM(chvers), axes(1:3), &
Time, 'condensation rate profile - member '//TRIM(chvers), &
'kg(h2o)/(kg(dry air) sec)', &
missing_value=missing_value)
! IF LOOP HERE:
if (.not. do_donner_plume) then
! cloud water profile on lo-res grid:
id_qlw_cem(nn) = register_diag_field &
(mod_name, 'qlw_cem'//TRIM(chvers), axes(1:3), &
Time, 'cloud water profile - member '//TRIM(chvers), &
'kg(h2o)/kg(air)', &
missing_value=missing_value)
! fraction of condensate that is ice on lo-res grid:
id_cfi_cem(nn) = register_diag_field &
(mod_name, 'cfi_cem'//TRIM(chvers), axes(1:3), &
Time, 'condensate ice fraction - member '//TRIM(chvers), &
'fraction', &
missing_value=missing_value)
! vertical velocity profile in plume on lo-res grid:
id_wv_cem(nn) = register_diag_field &
(mod_name, 'wv_cem'//TRIM(chvers), axes(1:3), &
Time, 'plume vertical velocity - member '//TRIM(chvers), &
'm / s', &
missing_value=missing_value)
! cloud radius profile in plume on lo-res grid:
id_rcl_cem(nn) = register_diag_field &
(mod_name, 'rcl_cem'//TRIM(chvers), axes(1:3), &
Time, 'plume cloud radius - member '//TRIM(chvers), &
'm', &
missing_value=missing_value)
else
! cloud water profile on hi-res grid:
id_qlw_cem(nn) = register_diag_field &
(mod_name, 'qlw_cem'//TRIM(chvers), donner_axes(cldindices), &
Time, 'cloud water profile - member '//TRIM(chvers), &
'kg(h2o)/kg(air)', &
missing_value=missing_value)
! fraction of condensate that is ice on hi-res grid:
id_cfi_cem(nn) = register_diag_field &
(mod_name, 'cfi_cem'//TRIM(chvers), donner_axes(cldindices), &
Time, 'condensate ice fraction - member '//TRIM(chvers), &
'fraction', &
missing_value=missing_value)
! vertical velocity profile in plume on hi-res grid:
id_wv_cem(nn) = register_diag_field &
(mod_name, 'wv_cem'//TRIM(chvers), donner_axes(cldindices), &
Time, 'plume vertical velocity - member '//TRIM(chvers), &
'm / s', &
missing_value=missing_value)
! cloud radius profile in plume on hi-res grid:
id_rcl_cem(nn) = register_diag_field &
(mod_name, 'rcl_cem'//TRIM(chvers), donner_axes(cldindices), &
Time, 'plume cloud radius - member '//TRIM(chvers), &
'm', &
missing_value=missing_value)
endif
enddo
! area-weighted mesoscale precipitation rate:
id_mpre_cem = register_diag_field &
(mod_name, 'mpre_cem', axes(1:2), &
Time, 'area wtd mesoscale precip rate ', &
'mm/day', &
missing_value=missing_value)
! fractional area sum:
id_a1_cem = register_diag_field &
(mod_name, 'a1_cem', axes(1:2), &
Time, 'fractional area sum', 'fraction', &
missing_value=missing_value)
! cloud fraction, cells+meso, normalized by a(1,p_b) on lo-res grid:
id_cual_cem = register_diag_field &
(mod_name, 'cual_cem', axes(1:3), &
Time, 'cloud fraction, cells+meso, normalized by a(1,p_b)', &
'fraction', &
missing_value=missing_value)
! time tendency of temperature due to deep convection on lo-res grid:
id_tfrc_cem = register_diag_field &
(mod_name, 'tfrc_cem', axes(1:3), &
Time, 'temperature tendency due to deep convection (lo-res)', &
'K/sec', missing_value=missing_value)
endif ! (do_ensemble_diagnostics)
end subroutine register_fields
!#####################################################################
subroutine process_coldstart (Time, Initialized, Nml, Don_save)
!-----------------------------------------------------------------------
! subroutine process_coldstart provides initialization that is needed
! when the job is a donner_deep coldstart, or if the user-supplied
! restart file is not usable for a restart with the current code
! version.
!-----------------------------------------------------------------------
type(time_type), intent(in) :: Time
type(donner_initialized_type), intent(inout) :: Initialized
type(donner_save_type), intent(inout) :: Don_save
type(donner_nml_type), intent(inout) :: Nml
!---------------------------------------------------------------------
! intent(in) variables:
!
! Time current time [ time_type, secs and days ]
!
!----------------------------------------------------------------------
!----------------------------------------------------------------------
! local variables:
integer :: days, secs ! components of current time
!---------------------------------------------------------------------
! set the coldstart flag to .true.. set the time until the first cal-
! culation call to donner_deep_mod, donner_deep calculation calls will
! be every donner_deep_freq seconds after the start of the day.
!---------------------------------------------------------------------
Initialized%coldstart = .true.
call get_time (Time, secs, days)
if (secs == 0) then ! i.e., 00Z
Initialized%conv_alarm = Nml%donner_deep_freq
else
Initialized%conv_alarm = Nml%donner_deep_freq - &
MOD (secs, Nml%donner_deep_freq)
endif
!----------------------------------------------------------------------
! initialize the variables which must be returned from donner_deep_mod
! on the first step when coldstarting.
!----------------------------------------------------------------------
Don_save%cemetf = 0.
Don_save%cememf = 0.
Don_save%tracer_tends = 0.
Don_save%mass_flux = 0.
Don_save%mflux_up = 0.
Don_save%cell_up_mass_flux = 0.
Don_save%det_mass_flux = 0.
Don_save%dql_strat = 0.
Don_save%dqi_strat = 0.
Don_save%dqa_strat = 0.
Don_save%humidity_area = 0.
Don_save%humidity_factor = 0.
Don_save%tprea1 = 0.
Don_save%parcel_disp = 0.
!----------------------------------------------------------------------
end subroutine process_coldstart
!#####################################################################
! register restart field to be written to restart file.
subroutine fms_donner_register_restart(fname, Initialized, ntracers, Don_save, Nml)
character(len=*), intent(in) :: fname
type(donner_initialized_type), intent(inout) :: Initialized
integer, intent(in) :: ntracers
type(donner_save_type), intent(inout) :: Don_save
type(donner_nml_type), intent(inout) :: Nml
character(len=64) :: fname2
integer :: id_restart, n
call get_mosaic_tile_file(fname, fname2, .false. )
allocate(Don_restart)
if(trim(fname2) == trim(fname)) then
Til_restart => Don_restart
in_different_file = .false.
else
in_different_file = .true.
allocate(Til_restart)
endif
id_restart = register_restart_field(Don_restart, fname, 'conv_alarm', Initialized%conv_alarm, no_domain = .true.)
id_restart = register_restart_field(Don_restart, fname, 'donner_deep_freq', Nml%donner_deep_freq, no_domain = .true.)
if (.not. (write_reduced_restart_file) .or. &
Initialized%conv_alarm > Initialized%physics_dt) then
id_restart = register_restart_field(Til_restart, fname, 'cemetf', Don_save%cemetf)
id_restart = register_restart_field(Til_restart, fname, 'cememf', Don_save%cememf)
id_restart = register_restart_field(Til_restart, fname, 'mass_flux', Don_save%mass_flux)
id_restart = register_restart_field(Til_restart, fname, 'cell_up_mass_flux', Don_save%cell_up_mass_flux)
id_restart = register_restart_field(Til_restart, fname, 'det_mass_flux', Don_save%det_mass_flux)
id_restart = register_restart_field(Til_restart, fname, 'dql_strat', Don_save%dql_strat)
id_restart = register_restart_field(Til_restart, fname, 'dqi_strat', Don_save%dqi_strat)
id_restart = register_restart_field(Til_restart, fname, 'dqa_strat', Don_save%dqa_strat)
id_restart = register_restart_field(Til_restart, fname, 'tprea1', Don_save%tprea1)
id_restart = register_restart_field(Til_restart, fname, 'humidity_area', Don_save%humidity_area)
id_restart = register_restart_field(Til_restart, fname, 'humidity_factor', Don_save%humidity_factor)
if (Initialized%do_donner_tracer) then
do n=1,ntracers
id_restart = register_restart_field(Til_restart, fname, 'tracer_tends_'// trim(Don_save%tracername(n)), &
Don_save%tracer_tends(:,:,:,n))
end do
endif
endif
id_restart = register_restart_field(Til_restart, fname, 'parcel_disp', Don_save%parcel_disp)
id_restart = register_restart_field(Til_restart, fname, 'lag_temp', Don_save%lag_temp)
id_restart = register_restart_field(Til_restart, fname, 'lag_vapor', Don_save%lag_vapor)
id_restart = register_restart_field(Til_restart, fname, 'lag_press', Don_save%lag_press)
end subroutine fms_donner_register_restart
!#####################################################################
! <SUBROUTINE NAME="read_restart_nc">
! <OVERVIEW>
! read_restart_nc reads a netcdf restart file containing donner_deep
! restart information.
! </OVERVIEW>
! <DESCRIPTION>
! read_restart_nc reads a netcdf restart file containing donner_deep
! restart information.
! </DESCRIPTION>
! <TEMPLATE>
! call read_restart_nc
! </TEMPLATE>
! </SUBROUTINE>
!
subroutine read_restart_nc (ntracers, Initialized, Nml, Don_save)
!-----------------------------------------------------------------------
! subroutine read_restart_nc reads a netcdf restart file to obtain
! the variables needed upon experiment restart.
!-----------------------------------------------------------------------
integer, intent(in) :: ntracers
type(donner_initialized_type), intent(inout) :: Initialized
type(donner_save_type), intent(inout) :: Don_save
type(donner_nml_type), intent(inout) :: Nml
!----------------------------------------------------------------------
! intent(in) variables:
!
! ntracers number of tracers being transported by the
! donner deep convection parameterization in this job
!
!---------------------------------------------------------------------
!---------------------------------------------------------------------
! local variables:
logical, dimension(ntracers) :: success
integer, dimension(:), allocatable :: ntindices
type(fieldtype), dimension(:), allocatable :: tracer_fields
character(len=64) :: fname2='INPUT/donner_deep.res.tile1'
character(len=64) :: fname='INPUT/donner_deep.res.nc'
character(len=128) :: tname
integer :: ndim, natt, nvar, ntime
integer :: old_freq
integer :: n_alltracers, iuic
logical :: is_tracer_in_restart_file
integer, dimension(4) :: siz
logical :: field_found, field_found2, &
field_found4
integer :: it, jn, nn
!---------------------------------------------------------------------
! local variables:
!
! success logical indicating if needed data for tracer n
! was obtained from restart file
! ntindices array of all tracer indices
! tracer_fields field_type variable containing information on
! all restart file variables
! fname2 restart file name without ".nc" appended,
! needed as argument in call to mpp_open
! fname restart file name
! tname contains successive variable names from
! restart file
! ndim number of dimensions in restart file
! natt number of attributes in restart file
! nvar number of variables in restart file
! ntime number of time levels in restart file
! old_freq donner_deep_freq as read from restart file;
! value used during previous job
! n_alltracers number of tracers registered with
! tracer_manager_mod
! iuic unit number assigned to restart file
! is_tracer_in_restart_file
! should we stop searching the restart file
! for the current tracer name because it has
! been found ?
! siz sizes (each dimension) of netcdf variable
! field_found is the requested variable in the restart file ?
! if it is not, then this is a reduced restart
! file
! field_found2 is the requested variable in the restart file ?
! if it is not, then Don_save%det_mass_flux and
! Don_save%cell_up_mass_flux must be initialized
! it, jn, nn do-loop indices
!
!----------------------------------------------------------------------
!--------------------------------------------------------------------
! output a message indicating entrance into this routine.
!--------------------------------------------------------------------
if (mpp_pe() == mpp_root_pe() ) then
call error_mesg ('donner_deep_mod', 'read_restart_nc:&
&Reading netCDF formatted restart file: &
&INPUT/donner_deep.res.nc', NOTE)
endif
!-------------------------------------------------------------------
! read the values of conv_alarm when the restart file was written and
! the frequency of calculating donner deep convection effects in the
! job which wrote the file.
!-------------------------------------------------------------------
call read_data(fname, 'conv_alarm', Initialized%conv_alarm, &
no_domain=.true.)
call read_data(fname, 'donner_deep_freq', old_freq, &
no_domain=.true.)
!----------------------------------------------------------------------
! call field_size to determine if variable cemetf is present in the
! restart file.
!----------------------------------------------------------------------
call field_size(fname, 'cemetf', siz, field_found=field_found)
!---------------------------------------------------------------------
! if the frequency of calculating deep convection has changed,
! redefine the time remaining until the next calculation.
!---------------------------------------------------------------------
if (Nml%donner_deep_freq /= old_freq) then
Initialized%conv_alarm = Initialized%conv_alarm - old_freq + &
Nml%donner_deep_freq
if (mpp_pe() == mpp_root_pe()) then
call error_mesg ('donner_deep_mod', 'read_restart_nc: &
&donner_deep time step has changed', NOTE)
endif
!----------------------------------------------------------------------
! if cemetf is not present, then this is a reduced restart file. it
! is not safe to change the frequency of calculating donner
! effects when reading a reduced restart file, so a fatal error is
! generated.
!----------------------------------------------------------------------
if (.not. field_found) then
call error_mesg ('donner_deep_mod', 'read_restart_nc: &
& cannot use reduced restart file and change donner_deep_freq&
& within experiment and guarantee restart reproducibility', &
FATAL)
endif
endif !(donner_deep_freq /= old_freq)
!---------------------------------------------------------------------
! read the restart data that is present in a full restart but absent
! in a reduced restart.
!---------------------------------------------------------------------
if (field_found) then
call read_data (fname, 'cemetf', Don_save%cemetf)
call read_data (fname, 'cememf', Don_save%cememf)
call read_data (fname, 'mass_flux', Don_save%mass_flux)
call read_data (fname, 'dql_strat', Don_save%dql_strat)
call read_data (fname, 'dqi_strat', Don_save%dqi_strat)
call read_data (fname, 'dqa_strat', Don_save%dqa_strat)
call read_data (fname, 'tprea1', Don_save%tprea1)
call read_data (fname, 'humidity_area', Don_save%humidity_area)
!---------------------------------------------------------------------
! determine if humidity_factor is in file. if it is, read the values
! into Don_Save%humidity_factor. if it is not (it is an older file),
! it is only required if donner_deep will not be called on the first
! step of this job.
! if that is the case, stop with a fatal error; otherwise, continue on,
! since humidity_factor will be calculated before it is used.
!---------------------------------------------------------------------
call field_size(fname, 'humidity_factor', siz, &
field_found=field_found4)
if (field_found4) then
call read_data (fname, 'humidity_factor', &
Don_save%humidity_factor)
else if (Initialized%conv_alarm > 0.0) then
call error_mesg ('donner_deep_mod', &
'cannot restart with this restart file unless donner_deep &
&calculated on first step', FATAL)
endif
!----------------------------------------------------------------------
! determine if det_mass_flux is present in the file.
!----------------------------------------------------------------------
call field_size(fname, 'det_mass_flux', siz, &
field_found=field_found2)
!----------------------------------------------------------------------
! if it is present, then read det_mass_flux and cell_up_mass_flux.
!----------------------------------------------------------------------
if (field_found2) then
call read_data (fname, 'det_mass_flux', Don_save%det_mass_flux)
call read_data (fname, 'cell_up_mass_flux', &
Don_save%cell_up_mass_flux)
!----------------------------------------------------------------------
! if it is not present (an earlier version of this file), set
! det_mass_flux and cell_up_mass_flux to default values.
!----------------------------------------------------------------------
else
Don_save%det_mass_flux = 0.0
Don_save%cell_up_mass_flux = 0.0
endif
!------------------------------------------------------------------
! if tracers are to be transported, see if tendencies are available
! in the restart file.
!------------------------------------------------------------------
if (Initialized%do_donner_tracer) then
!---------------------------------------------------------------------
! initialize a logical array indicating whether the data for each
! tracer is available.
!---------------------------------------------------------------------
success = .false.
!---------------------------------------------------------------------
! open the restart file with mpp_open so that the unit number is
! available. obtain needed file characteristics by calling
! mpp_read_meta and mpp_get_info.
!---------------------------------------------------------------------
call mpp_open(iuic, fname2, &
action=MPP_RDONLY, form=MPP_NETCDF, threading=MPP_SINGLE )
call mpp_read_meta (iuic)
call mpp_get_info (iuic, ndim, nvar, natt, ntime)
!---------------------------------------------------------------------
! obtain information on the file variables by calling mpp_get_fields.
! it is returned in a field_type variable tracer_fields; the specific
! information needed is the variable name.
!---------------------------------------------------------------------
allocate (tracer_fields(nvar))
if (mpp_pe() == mpp_root_pe()) then
call mpp_get_fields (iuic, tracer_fields)
endif
!---------------------------------------------------------------------
! call get_number_tracers to determine how many tracers are registered
! with tracer manager. allocate an array to hold their tracer indices.
! call get_tracer_indices to retrieve the tracer indices.
!---------------------------------------------------------------------
call get_number_tracers (MODEL_ATMOS, num_tracers=n_alltracers)
allocate (ntindices(n_alltracers))
call get_tracer_indices (MODEL_ATMOS, ind=ntindices)
!----------------------------------------------------------------------
! loop over the tracers, obtaining their names via a call to
! get_tracer_names. bypass those tracers known to not be transported
! by donner convection.
!----------------------------------------------------------------------
do it=1,n_alltracers
call get_tracer_names (MODEL_ATMOS, ntindices(it), tname)
if (tname == "sphum" ) cycle
if (tname == "liq_wat") cycle
if (tname == "ice_wat") cycle
if (tname == "cld_amt") cycle
!--------------------------------------------------------------------
! initialize a logical indicating whether this tracer is in the
! restart file.
!--------------------------------------------------------------------
is_tracer_in_restart_file = .FALSE.
!---------------------------------------------------------------------
! loop over the variables in the restart file to determine if the
! current tracer's time tendency field is present.
!---------------------------------------------------------------------
do jn=1,nvar
if (lowercase (trim(mpp_get_field_name(tracer_fields(jn)))) == &
lowercase ('tracer_tends_' // trim(tname)) ) then
!---------------------------------------------------------------------
! if tracer tendency is in restart file, write a message. set the
! logical flag indicating such to .true..
!---------------------------------------------------------------------
if (mpp_pe() == mpp_root_pe() ) then
print *,'tracer_tends_' // trim(tname), ' found!'
endif
is_tracer_in_restart_file = .TRUE.
!---------------------------------------------------------------------
! loop over the tracers being transported by donner convection in this
! job to determine if this tracer is one of those being transported.
! determine the tracer index in tracername array corresponding to
! this tracer.
!---------------------------------------------------------------------
do nn=1,ntracers
if (lowercase( 'tracer_tends_' // trim(tname) ) == &
'tracer_tends_' // Don_save%tracername(nn) ) then
!---------------------------------------------------------------------
! if data for this tracer is needed, read data into proper section of
! array tracer_tends. set the logical flag for this tracer indicating
! successful retrieval. exit this loop.
!---------------------------------------------------------------------
call read_data (fname, &
'tracer_tends_' // trim(tname), &
Don_save%tracer_tends(:,:,:,nn))
success(nn) = .true.
exit
endif
end do ! (nn)
endif
!---------------------------------------------------------------------
! if desired tracer has been found, stop searching the restart file
! variables for this tracer and cycle to begin searching the restart
! file for the next field_table tracer.
!---------------------------------------------------------------------
if (is_tracer_in_restart_file) exit
end do ! (jn)
end do ! (it)
!---------------------------------------------------------------------
! initialize the time tendencies to 0.0 for any tracers that are to
! be transported and whose time tendencies were not found on the
! restart file. enter a message in the output file.
!---------------------------------------------------------------------
do nn=1,ntracers
if (success(nn) ) then
else
call error_mesg ('donner_deep_mod', 'read_restart_nc: &
&did not find tracer restart data for ' // &
trim(Don_save%tracername(nn)) // &
'; am initializing tendency to 0.0', NOTE)
Don_save%tracer_tends(:,:,:,nn) = 0.0
endif
end do
!----------------------------------------------------------------------
! deallocate local variables.
!----------------------------------------------------------------------
deallocate (ntindices)
deallocate (tracer_fields)
endif ! (do_donner_tracer)
endif ! (field_found)
!---------------------------------------------------------------------
! read the restart data that is present in both full and reduced
! restart files.
!---------------------------------------------------------------------
call read_data (fname, 'parcel_disp', Don_save%parcel_disp)
call read_data (fname, 'lag_temp', Don_save%lag_temp)
call read_data (fname, 'lag_vapor', Don_save%lag_vapor)
call read_data (fname, 'lag_press', Don_save%lag_press)
!---------------------------------------------------------------------
end subroutine read_restart_nc
!#####################################################################
subroutine process_monitors (idf, jdf, nlev, ntracers, axes, Time, &
Initialized, Don_save)
integer, intent(in) :: idf, jdf, nlev, ntracers
integer, dimension(4), intent(in) :: axes
type(time_type), intent(in) :: Time
type(donner_initialized_type), intent(inout) :: Initialized
type(donner_save_type), intent(inout) :: Don_save
!-------------------------------------------------------------------
! local variables:
integer :: n, nx, nc
logical :: flag, success
integer :: nfields, model, num_methods
character(len=200) :: method_name, field_type, method_control,&
field_name, list_name
character(len=32) :: path_name = '/atmos_mod/don_deep_monitor/'
!---------------------------------------------------------------------
! determine if and how many output variables are to be monitored.
! set a flag indicating if monitoring is activated.
!---------------------------------------------------------------------
call field_manager_init (nfields)
nx = 0
do n=1,nfields
call get_field_info (n, field_type, field_name, model, &
num_methods)
if (trim(field_type) == 'don_deep_monitor') then
nx = nx + 1
endif
end do
if (nx > 0) then
Initialized%monitor_output = .true.
else
Initialized%monitor_output = .false.
endif
!---------------------------------------------------------------------
! allocate arrays needed for each monitored variable.
!---------------------------------------------------------------------
if (Initialized%monitor_output) then
allocate (Initialized%Don_monitor(nx))
allocate (id_extremes(nx))
allocate (id_hits(nx))
!---------------------------------------------------------------------
! read the field_table to determine the nature of the monitors
! requested.
!---------------------------------------------------------------------
nx = 1
do n = 1,nfields
call get_field_info (n, field_type, field_name, model, &
num_methods)
!---------------------------------------------------------------------
! define the list name used by field_manager_mod to point to
! monitored variables.
!---------------------------------------------------------------------
if (trim(field_type) == 'don_deep_monitor') then
list_name = trim(path_name) // trim(field_name) // '/'
!--------------------------------------------------------------------
! place name of field in don_monitor_type variable.
!--------------------------------------------------------------------
Initialized%Don_monitor(nx)%name = trim(field_name)
!--------------------------------------------------------------------
! map the field name to the list of acceptable field names. store
! the index of this field name in the don_monitor_type variable.
! note that any tracer variables need to have 'tr_' as the first
! three characters in their name to allow proper processing. store
! the appropriate tracer index for any tracer arrays.
!--------------------------------------------------------------------
if (trim(field_name(1:3)) == 'tr_') then
select case (trim(field_name(4:9)))
case ('rn_ten')
Initialized%Don_monitor(nx)%index = RADON_TEND
success = .false.
do nc=1,ntracers
if (trim(Don_save%tracername(nc)) == 'radon') then
Initialized%Don_monitor(nx)%tracer_index = nc
success = .true.
exit
endif
end do
if (.not. success) then
call error_mesg ('donner_deep_mod', &
'not able to find "radon" tracer index', FATAL)
endif
case default
call error_mesg ('donner_deep_mod', &
'tracer variable name in field_table don_deep_monitor &
&type is invalid', FATAL)
end select
!---------------------------------------------------------------------
! for non-tracer variables, set the tracer index to an arbitrary
! value.
!---------------------------------------------------------------------
else
Initialized%Don_monitor(nx)%tracer_index = 0
select case (trim(field_name(1:6)))
case ('det_ma')
Initialized%Don_monitor(nx)%index = DET_MASS_FLUX
case ('mass_f')
Initialized%Don_monitor(nx)%index = MASS_FLUX
case ('cell_u')
Initialized%Don_monitor(nx)%index = &
CELL_UPWARD_MASS_FLUX
case ('temp_f')
Initialized%Don_monitor(nx)%index = TEMP_FORCING
case ('moistu')
Initialized%Don_monitor(nx)%index = MOIST_FORCING
case ('precip')
Initialized%Don_monitor(nx)%index = PRECIP
case ('freeze')
Initialized%Don_monitor(nx)%index = FREEZING
case default
call error_mesg ('donner_deep_mod', &
'variable name in field_table don_deep_monitor &
&type is invalid', FATAL)
end select
endif
!---------------------------------------------------------------------
! read the units for this variable from the field_table entry.
! if the units method is missing, set units to be 'missing'.
!---------------------------------------------------------------------
flag = fm_query_method (trim(list_name) // 'units', &
method_name, method_control)
if (flag) then
Initialized%Don_monitor(nx)%units = trim(method_name)
else
Initialized%Don_monitor(nx)%units = 'missing'
endif
!---------------------------------------------------------------------
! determine the type of limit being imposed for this variable from
! the field_table entry.
!---------------------------------------------------------------------
flag = fm_query_method (trim(list_name) // 'limit_type', &
method_name, method_control)
!----------------------------------------------------------------------
! include the limit_type for this variable in its don_monitor type
! variable.
! register diagnostics associated with the monitored output fields
! (extreme values and number of times threshold was exceeeded).
!----------------------------------------------------------------------
if ( flag) then
if (trim(method_name) == 'maxmag') then
Initialized%Don_monitor(nx)%initial_value = 0.0
Initialized%Don_monitor(nx)%limit_type = MAXMAG
id_extremes(nx) = register_diag_field (mod_name, &
'maxmag_'// trim(Initialized%Don_monitor(nx)%name), &
axes(1:3), Time, 'maxmag values of ' // &
trim(Initialized%Don_monitor(nx)%name), &
Initialized%Don_monitor(nx)%units, &
mask_variant = .true., missing_value=missing_value)
id_hits(nx) = register_diag_field (mod_name, &
'num_maxmag_'// &
trim(Initialized%Don_monitor(nx)%name) , &
axes(1:3), Time, &
'# of times that magnitude of '&
// trim(Initialized%Don_monitor(nx)%name) // &
' > ' // trim(method_control(2:)) // ' ' // &
trim(Initialized%Don_monitor(nx)%units) , &
'number', mask_variant = .true., &
missing_value=missing_value)
else if (trim(method_name) == 'minmag') then
Initialized%Don_monitor(nx)%initial_value = 1.0e30
Initialized%Don_monitor(nx)%limit_type = MINMAG
id_extremes(nx) = register_diag_field (mod_name, &
'minmag_'// trim(Initialized%Don_monitor(nx)%name), &
axes(1:3), Time, 'minmag values of ' // &
trim(Initialized%Don_monitor(nx)%name), &
Initialized%Don_monitor(nx)%units, &
mask_variant = .true., missing_value=missing_value)
id_hits(nx) = register_diag_field (mod_name, &
'num_minmag_'// &
trim(Initialized%Don_monitor(nx)%name) , &
axes(1:3), Time, &
'# of times that magnitude of '&
// trim(Initialized%Don_monitor(nx)%name) // &
' < ' // trim(method_control(2:)) // ' ' // &
trim(Initialized%Don_monitor(nx)%units) , &
'number', mask_variant = .true., &
missing_value=missing_value)
else if (trim(method_name) == 'minval') then
Initialized%Don_monitor(nx)%initial_value = 1.0e30
Initialized%Don_monitor(nx)%limit_type = MINVAL
id_extremes(nx) = register_diag_field (mod_name, &
'minval_'// trim(Initialized%Don_monitor(nx)%name), &
axes(1:3), Time, 'minimum values of ' // &
trim(Initialized%Don_monitor(nx)%name), &
Initialized%Don_monitor(nx)%units, &
mask_variant = .true., missing_value=missing_value)
id_hits(nx) = register_diag_field (mod_name, &
'num_minval_'// &
trim(Initialized%Don_monitor(nx)%name) , &
axes(1:3), Time, &
'# of times that value of '&
// trim(Initialized%Don_monitor(nx)%name) // &
' < ' // trim(method_control(2:)) // ' ' // &
trim(Initialized%Don_monitor(nx)%units) , &
'number', mask_variant = .true., &
missing_value=missing_value)
else if (trim(method_name) == 'maxval') then
Initialized%Don_monitor(nx)%initial_value = -1.0e30
Initialized%Don_monitor(nx)%limit_type = MAXVAL
id_extremes(nx) = register_diag_field (mod_name, &
'maxval_'// trim(Initialized%Don_monitor(nx)%name), &
axes(1:3), Time, 'maximum values of ' // &
trim(Initialized%Don_monitor(nx)%name), &
Initialized%Don_monitor(nx)%units, &
mask_variant = .true., missing_value=missing_value)
id_hits(nx) = register_diag_field (mod_name, &
'num_maxval_'// &
trim(Initialized%Don_monitor(nx)%name) , &
axes(1:3), Time, &
'# of times that value of '&
// trim(Initialized%Don_monitor(nx)%name) // &
' > ' // trim(method_control(2:)) // ' ' // &
trim(Initialized%Don_monitor(nx)%units) , &
'number', mask_variant = .true., &
missing_value=missing_value)
else
call error_mesg ('donner_deep_mod', &
'invalid limit_type for monitored variable', FATAL)
endif
!----------------------------------------------------------------------
! if limit_type not in field_table, set it to look for maximum
! magnitude.
!----------------------------------------------------------------------
else
Initialized%Don_monitor(nx)%initial_value = 0.0
Initialized%Don_monitor(nx)%limit_type = MAXMAG
id_extremes(nx) = register_diag_field (mod_name, &
'maxmag_'// trim(Initialized%Don_monitor(nx)%name), &
axes(1:3), Time, 'maxmag values of ' // &
trim(Initialized%Don_monitor(nx)%name), &
Initialized%Don_monitor(nx)%units, &
mask_variant = .true., missing_value=missing_value)
id_hits(nx) = register_diag_field (mod_name, &
'num_maxmag_'// &
trim(Initialized%Don_monitor(nx)%name) , &
axes(1:3), Time, &
'# of times that magnitude of '&
// trim(Initialized%Don_monitor(nx)%name) // &
' > ' // trim(method_control(2:)) // ' ' // &
trim(Initialized%Don_monitor(nx)%units) , &
'number', mask_variant = .true., &
missing_value=missing_value)
endif
!----------------------------------------------------------------------
! obtain the magnitude of the limit being monitored for this
! variable from the field_table.
!----------------------------------------------------------------------
flag = parse (method_control, 'value', &
Initialized%Don_monitor(nx)%threshold ) > 0
!----------------------------------------------------------------------
! if no limit_type and / or value has been given, the
! field will be flagged for magnitudes > 0.0, i.e., if deep
! convection has affected the point.
!----------------------------------------------------------------------
if ( .not. flag) then
Initialized%Don_monitor(nx)%threshold = 0.0
endif
!-------------------------------------------------------------------
! allocate and initialize arrays to hold the extrema and a count of
! times the threshold was exceeded at each point.
!-------------------------------------------------------------------
allocate (Initialized%Don_monitor(nx)%extrema(idf,jdf,nlev))
Initialized%Don_monitor(nx)%extrema(:,:,:) = &
Initialized%Don_monitor(nx)%initial_value
allocate (Initialized%Don_monitor(nx)%hits(idf,jdf,nlev))
Initialized%Don_monitor(nx)%hits(:,:,:) = 0.0
nx = nx + 1
endif
end do
endif
end subroutine process_monitors
!#####################################################################
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!
! 2. ROUTINES CALLED BY DONNER_DEEP
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!#######################################################################
subroutine donner_column_control (is, ie, js, je, Time, Col_diag)
!---------------------------------------------------------------------
! subroutine donner_column_control returns the number, location
! (processor and window indices) and output units associated with
! any diagnostic columns requested within the current physics window.
!---------------------------------------------------------------------
integer, intent(in) :: is, ie, js, je
type(time_type), intent(in) :: Time
type (donner_column_diag_type), intent(inout) :: Col_diag
!---------------------------------------------------------------------
! intent(in) variables:
!
! is, ie first and last values of i index values of points
! in this physics window (processor coordinates)
! js, je first and last values of j index values of points
! in this physics window (processor coordinates)
! Time current model time [ time_type, days, seconds ]
!
!----------------------------------------------------------------------
!---------------------------------------------------------------------
! local variables:
integer :: isize ! i-dimension of physics window
integer :: jsize ! j-dimension of physics window
integer :: nn, j, i ! do-loop indices
!--------------------------------------------------------------------
! define the sizes of the current physics window's horizontal
! dimensions.
!--------------------------------------------------------------------
isize = ie - is + 1
jsize = je - js + 1
!-------------------------------------------------------------------
! initialize the output variables.
!-------------------------------------------------------------------
Col_diag%i_dc(:) = -99
Col_diag%j_dc(:) = -99
Col_diag%unit_dc(:) = -1
Col_diag%jgl_dc(:) = -99
Col_diag%igl_dc(:) = -99
Col_diag%ncols_in_window = 0
!--------------------------------------------------------------------
! if any requested diagnostic columns are present within the current
! physics window, and if it is at or past the time to start output-
! ting column diagnostics, save the relevant variables describing
! those diagnostic columns in arrays to be returned to the calling
! routine. call column_diagnostics_header to write the file header
! for the diagnostic columns in this window.
!--------------------------------------------------------------------
if (Col_diag%num_diag_pts > 0) then
if (Time >= Time_col_diagnostics) then
do nn=1,Col_diag%num_diag_pts
do j=1,jsize
if (js + j - 1 == col_diag_j(nn)) then
do i=1,isize
if (is + i - 1 == col_diag_i(nn)) then
Col_diag%ncols_in_window = &
Col_diag%ncols_in_window + 1
Col_diag%i_dc(Col_diag%ncols_in_window) = i
Col_diag%j_dc(Col_diag%ncols_in_window) = j
Col_diag%igl_dc(COl_diag%ncols_in_window) = &
col_diag_i(nn)
Col_diag%jgl_dc(Col_diag%ncols_in_window) = &
col_diag_j(nn)
Col_diag%unit_dc(Col_diag%ncols_in_window) = &
col_diag_unit(nn)
call column_diagnostics_header &
(mod_name, col_diag_unit(nn), Time, nn, &
col_diag_lon, col_diag_lat, col_diag_i, &
col_diag_j)
endif
end do ! (i loop)
endif
end do ! (j loop)
end do ! (num_diag_pts loop)
endif ! (Time >= starting time)
endif ! (num_diag_pts > 0)
!---------------------------------------------------------------------
end subroutine donner_column_control
!######################################################################
subroutine donner_deep_netcdf (is, ie, js, je, Nml, Time, Param, &
Initialized, Don_conv, Don_cape,&
Don_cem,parcel_rise, pmass, total_precip, &
Don_budgets, &
temperature_forcing, moisture_forcing)
!---------------------------------------------------------------------
! subroutine donner_deep_netcdf sends the fields requested in the
! diag_table to diag_manager_mod so that they may be appropriately
! processed for output.
!---------------------------------------------------------------------
integer, intent(in) :: is, ie, js, je
type(time_type), intent(in) :: Time
type(donner_param_type), intent(in) :: Param
type(donner_initialized_type), intent(inout) :: Initialized
type(donner_nml_type), intent(in) :: Nml
type(donner_conv_type), intent(in) :: Don_conv
type(donner_budgets_type), intent(in) :: Don_budgets
type(donner_cape_type), intent(in) :: Don_cape
type(donner_cem_type), intent(in) :: Don_cem
real, dimension(:,:,:), intent(in) :: pmass, temperature_forcing,&
moisture_forcing
real, dimension(:,:), intent(in) :: parcel_rise, total_precip
!---------------------------------------------------------------------
! intent(in) variables:
!
! is, ie first and last values of i index values of points
! in this physics window (processor coordinates)
! js, je first and last values of j index values of points
! in this physics window (processor coordinates)
! Time current time (time_type)
! Don_conv donner_convection_type derived type variable con-
! taining diagnostics describing the nature of the
! convection produced by the donner parameterization
! Don_cape donner_cape type derived type variable containing
! diagnostics related to the cape calculation assoc-
! iated with the donner convection parameterization
! Don_cem donner_cem_type derived type variable containing
! Donner cumulus ensemble member diagnostics
! temperature_forcing
! temperature tendency due to donner convection
! [ deg K / sec ]
! moisture_forcing
! vapor mixing ratio tendency due to donner
! convection [ kg(h2o) / (kg(dry air) sec ) ]
! pmass mass per unit area within the grid box
! [ kg (air) / (m**2) ]
! parcel_rise accumulated vertical displacement of a near-surface
! parcel as a result of the lowest model level omega
! field [ Pa ]
! total_precip total precipitation rate produced by the
! donner parameterization [ mm / day ]
!
!---------------------------------------------------------------------
!---------------------------------------------------------------------
! local variables:
real, dimension (ie-is+1, je-js+1) :: tempdiag, tempdiag2, tempdiag3
! array used to hold various data fields being
! sent to diag_manager_mod
logical :: used ! logical indicating data has been received
! by diag_manager_mod
integer :: nlev ! number of large-scale model layers
integer :: ntr ! number of tracers transported by the
! donner deep convection parameterization
integer :: k, n, nn ! do-loop indices
integer :: ncem ! number of cumulus ensemble members in the
! donner deep convection parameterization
!----------------------------------------------------------------------
! define the number of model layers (nlev) and number of transported
! tracers (ntr).
!----------------------------------------------------------------------
nlev = size (pmass,3)
ntr = size (Don_conv%qtren1,4)
!----------------------------------------------------------------------
! define the number of cumulus ensemble members in the
! donner deep convection parameterization.
!----------------------------------------------------------------------
ncem = size (Don_cem%cell_precip,3)
!---------------------------------------------------------------------
! send the 3D convective output variables to diag_manager_mod.
!! NOTE: effective with code mod lima_donnermod3_rsh (7-19-05) the
!! temperature and moisture forcing fields passed to diag_manager
!! (id_cemetf_deep, id_cememf_deep) are the total convective
!! forcings calculated by the donner parameterization. Previous
!! code versions run in models in which strat_cloud_mod was
!! activated output the forcing fields less the terms related to
!! the flux convergence of the large-scale condensate and the
!! mesoscale detrainment.
!---------------------------------------------------------------------
! total convective temperature forcing:
used = send_data (id_cemetf_deep, Don_conv%conv_temp_forcing, &
Time, is, js, 1)
! cell entropy flux convergence:
used = send_data (id_ceefc_deep, Don_conv%ceefc, Time, is, js, 1)
! cell condensation / evaporation:
used = send_data (id_cecon_deep, Don_conv%cecon, Time, is, js, 1)
! cell moisture flux convergence:
used = send_data (id_cemfc_deep, Don_conv%cemfc, Time, is, js, 1)
! total convective moistening forcing:
used = send_data (id_cememf_deep, Don_conv%conv_moist_forcing, &
Time, is, js, 1)
! total convective moistening rate after adjustnment for negative
! vapor mixing ratio:
used = send_data (id_cememf_mod_deep, Don_conv%cememf_mod, &
Time, is, js, 1)
! cell + mesoscale cloud fraction:
used = send_data (id_cual_deep, Don_conv%cual, Time, is, js, 1)
! heating rate due to freezing:
used = send_data (id_fre_deep, Don_conv%fre, Time, is, js, 1)
! heating rate due to melting:
used = send_data (id_elt_deep, Don_conv%elt, Time, is, js, 1)
! deposition in mesoscale updraft:
used = send_data (id_cmus_deep, Don_conv%cmus, Time, is, js, 1)
! evaporation in convective downdrafts:
used = send_data (id_ecds_deep, Don_conv%ecds, Time, is, js, 1)
! evaporation / sublimation in convective updrafts:
used = send_data (id_eces_deep, Don_conv%eces, Time, is, js, 1)
! sublimation in mesoscale downdrafts:
used = send_data (id_emds_deep, Don_conv%emds, Time, is, js, 1)
! sublimation in mesoscale updrafts:
used = send_data (id_emes_deep, Don_conv%emes, Time, is, js, 1)
! mesoscale moisture flux convergence:
used = send_data (id_qmes_deep, Don_conv%mrmes, Time, is, js, 1)
! transfer of vapor from cells to mesoscale:
used = send_data (id_wmps_deep, Don_conv%wmps, Time, is, js, 1)
! deposition of vapor from cells to mesoscale:
used = send_data (id_wmms_deep, Don_conv%wmms, Time, is, js, 1)
! mesoscale entropy flux convergence:
used = send_data (id_tmes_deep, Don_conv%tmes, Time, is, js, 1)
! mass flux in mesoscale downdrafts:
used = send_data (id_dmeml_deep, Don_conv%dmeml, Time, is, js, 1)
! mass flux in cell updrafts:
used = send_data (id_uceml_deep, Don_conv%uceml, Time, is, js, 1)
! detrained mass flux:
used = send_data (id_detmfl_deep, Don_conv%detmfl, Time, is, js, 1)
! mass flux in mesoscale updrafts:
used = send_data (id_umeml_deep, Don_conv%umeml, Time, is, js, 1)
! mesoscale ice mixing ratio:
used = send_data (id_xice_deep, Don_conv%xice, Time, is, js, 1)
! mesoscale liquid mass mixing ratio
used = send_data (id_xliq_deep, Don_conv%xliq, Time, is, js, 1)
! mesoscale ice generalized effective size:
used = send_data (id_dgeice_deep, Don_conv%dgeice, &
Time, is, js, 1)
! cell ice mixing ratio:
used = send_data (id_cuqi_deep, Don_conv%cuqi, Time, is, js, 1)
! cell liquid mixing ratio:
used = send_data (id_cuql_deep, Don_conv%cuql, Time, is, js, 1)
! cell liquid generalized effective size:
used = send_data (id_dgeliq_deep, Don_conv%cell_liquid_eff_diam, &
Time, is, js, 1)
if (Nml%do_budget_analysis) then
do n=1,Don_budgets%N_WATER_BUDGET
if (id_water_budget(n) > 0) then
used = send_data (id_water_budget(n), &
Don_budgets%water_budget(:,:,:,n), &
Time, is, js, 1)
endif
end do
do n=1,Don_budgets%N_PRECIP_TYPES
do nn=1,Don_budgets%N_PRECIP_PATHS
if (id_precip_budget(nn,n) > 0) then
used = send_data (id_precip_budget(nn,n), &
Don_budgets%precip_budget(:,:,:,nn,n), &
Time, is, js, 1)
endif
end do
end do
do n=1,Don_budgets%N_ENTHALPY_BUDGET
if (id_enthalpy_budget(n) > 0) then
used = send_data (id_enthalpy_budget(n), &
Don_budgets%enthalpy_budget(:,:,:,n), &
Time, is, js, 1)
endif
end do
do n=1,Don_budgets%N_WATER_BUDGET
tempdiag(:,:) = 0.
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + &
Don_budgets%water_budget(:,:,k,n)* &
pmass(:,:,k)/1000.
end do
if (id_ci_water_budget(n) > 0) then
used = send_data (id_ci_water_budget(n), tempdiag, &
Time, is, js)
endif
end do
tempdiag3(:,:) = 0.
do n=1,Don_budgets%N_PRECIP_TYPES
do nn=1,Don_budgets%N_PRECIP_PATHS
tempdiag(:,:) = 0.
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + &
Don_budgets%precip_budget(:,:,k,nn,n)* &
pmass(:,:,k)
end do
if (id_ci_precip_budget(nn,n) > 0) then
used = send_data (id_ci_precip_budget(nn,n), tempdiag, &
Time, is, js)
endif
tempdiag3(:,:) = tempdiag3(:,:) + tempdiag(:,:)
end do
end do
do n=1,Don_budgets%N_ENTHALPY_BUDGET
tempdiag(:,:) = 0.
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + &
Don_budgets%enthalpy_budget(:,:,k,n)* &
pmass(:,:,k)*CP_AIR
end do
if (id_ci_enthalpy_budget(n) > 0) then
used = send_data (id_ci_enthalpy_budget(n), tempdiag, &
Time, is, js)
endif
end do
tempdiag2(:,:) = 0.
tempdiag(:,:) = 0.
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + &
(Don_budgets%precip_budget(:,:,k,2,1) + &
Don_budgets%precip_budget(:,:,k,4,1))* &
Param%hls*pmass(:,:,k)
end do
if (id_ci_prcp_heat_frz_cell > 0) then
used = send_data (id_ci_prcp_heat_frz_cell, tempdiag, &
Time, is, js)
endif
tempdiag2 = tempdiag2 + tempdiag
tempdiag(:,:) = 0.
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + &
(Don_budgets%precip_budget(:,:,k,1,1) + &
Don_budgets%precip_budget(:,:,k,3,1) + &
Don_budgets%precip_budget(:,:,k,5,1))* &
Param%hlv*pmass(:,:,k)
end do
if (id_ci_prcp_heat_liq_cell > 0) then
used = send_data (id_ci_prcp_heat_liq_cell, tempdiag, &
Time, is, js)
endif
tempdiag2 = tempdiag2 + tempdiag
tempdiag(:,:) = 0.
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + &
(Don_budgets%precip_budget(:,:,k,2,2) + &
Don_budgets%precip_budget(:,:,k,4,2) + &
Don_budgets%precip_budget(:,:,k,2,3) + &
Don_budgets%precip_budget(:,:,k,4,3))* &
Param%hls*pmass(:,:,k)
end do
if (id_ci_prcp_heat_frz_meso > 0) then
used = send_data (id_ci_prcp_heat_frz_meso, tempdiag, &
Time, is, js)
endif
tempdiag2 = tempdiag2 + tempdiag
tempdiag(:,:) = 0.
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + &
(Don_budgets%precip_budget(:,:,k,1,2) + &
Don_budgets%precip_budget(:,:,k,3,2) + &
Don_budgets%precip_budget(:,:,k,5,2) + &
Don_budgets%precip_budget(:,:,k,1,3) + &
Don_budgets%precip_budget(:,:,k,3,3) + &
Don_budgets%precip_budget(:,:,k,5,3))* &
Param%hlv*pmass(:,:,k)
end do
if (id_ci_prcp_heat_liq_meso > 0) then
used = send_data (id_ci_prcp_heat_liq_meso, tempdiag, &
Time, is, js)
endif
tempdiag2 = tempdiag2 + tempdiag
if ( id_ci_prcp_heat_total > 0) then
used = send_data (id_ci_prcp_heat_total, tempdiag2, &
Time, is, js)
endif
if (id_ci_prcp_total > 0) then
used = send_data (id_ci_prcp_total, tempdiag3, &
Time, is, js)
endif
if ( id_leff > 0) then
used = send_data(id_leff, tempdiag2/(tempdiag3+1.0e-40), &
Time, is, js)
endif
endif
!--------------------------------------------------------------------
! send the tracer-related arrays to diag_manager_mod.
!--------------------------------------------------------------------
do n=1,ntr
! tracer tendency due to cells:
if (id_qtren1(n) > 0) then
used = send_data (id_qtren1(n), Don_conv%qtren1(:,:,:,n), &
Time, is, js, 1)
endif
! tracer tendency due to mesoscale:
if (id_qtmes1(n) > 0) then
used = send_data (id_qtmes1(n), Don_conv%qtmes1(:,:,:,n), &
Time, is, js, 1)
endif
! tracer tendency due to mesoscale redistribution:
if (id_wtp1(n) > 0) then
used = send_data (id_wtp1(n), Don_conv%wtp1(:,:,:,n), &
Time, is, js, 1)
endif
! tracer tendency due to deep convective wet deposition:
if (id_total_wet_dep(n) > 0) then
used = send_data (id_total_wet_dep(n), Don_conv%wetdept(:,:,:,n), &
Time, is, js, 1)
endif
! tracer tendency due to wet deposition in mesoscale updrafts:
if ( id_meso_wet_dep(n) > 0) then
used = send_data (id_meso_wet_dep(n), Don_conv%wetdepm(:,:,:,n), &
Time, is, js, 1)
endif
! tracer tendency due to wet deposition in cells:
if (id_cell_wet_dep(n) > 0) then
used = send_data (id_cell_wet_dep(n), Don_conv%wetdepc(:,:,:,n), &
Time, is, js, 1)
endif
! total tracer tendency:
if (id_qtceme(n) > 0) then
used = send_data (id_qtceme(n), Don_conv%qtceme(:,:,:,n), &
Time, is, js, 1)
endif
!---------------------------------------------------------------------
! define the column-integrated tracer tendency due to convective
! cells, in units of kg (tracer) / (m**2 sec). send it to
! diag_manager_mod.
!---------------------------------------------------------------------
tempdiag = 0.0
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + Don_conv%qtren1(:,:,k,n)* &
pmass(:,:,k)
end do
if (id_qtren1_col(n) > 0) then
used = send_data (id_qtren1_col(n), tempdiag, Time, is, js)
endif
!---------------------------------------------------------------------
! define the column-integrated tracer tendency due to mesoscale circ-
! ulation, in units of kg (tracer) / (m**2 sec). send it to
! diag_manager_mod.
!---------------------------------------------------------------------
tempdiag = 0.0
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + Don_conv%qtmes1(:,:,k,n)* &
pmass(:,:,k)
end do
if (id_qtmes1_col(n) > 0) then
used = send_data (id_qtmes1_col(n), tempdiag, Time, is, js)
endif
!---------------------------------------------------------------------
! define the column-integrated tracer redistribution due to meso-
! scale circulation, in units of kg (tracer) / (m**2 sec). send it
! to diag_manager_mod.
!---------------------------------------------------------------------
tempdiag = 0.0
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + Don_conv%wtp1(:,:,k,n)* &
pmass(:,:,k)
end do
if (id_wtp1_col(n) > 0) then
used = send_data (id_wtp1_col(n), tempdiag, Time, is, js)
endif
!---------------------------------------------------------------------
! define the column-integrated tracer change due to wet deposition in
! deep convection (cells and mesoscale) in units of kg (tracer) /
! (m**2 sec). send it to diag_manager_mod.
!---------------------------------------------------------------------
tempdiag = 0.0
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + Don_conv%wetdept(:,:,k,n)* &
pmass(:,:,k)
end do
if (id_total_wet_dep_col(n) > 0) then
used = send_data (id_total_wet_dep_col(n), tempdiag, Time, &
is, js)
endif
!---------------------------------------------------------------------
! define the column-integrated tracer change due to wet deposition in
! mesoscale updrafts, in units of kg (tracer) / (m**2 sec). send it
! to diag_manager_mod.
!---------------------------------------------------------------------
tempdiag = 0.0
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + Don_conv%wetdepm(:,:,k,n)* &
pmass(:,:,k)
end do
if (id_meso_wet_dep_col(n) > 0) then
used = send_data (id_meso_wet_dep_col(n), tempdiag, Time, &
is, js)
endif
!---------------------------------------------------------------------
! define the column-integrated tracer change due to wet deposition
! by convective cells, in units of kg (tracer) / (m**2 sec). send it
! to diag_manager_mod.
!---------------------------------------------------------------------
tempdiag = 0.0
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + Don_conv%wetdepc(:,:,k,n)* &
pmass(:,:,k)
end do
if (id_cell_wet_dep_col(n) > 0) then
used = send_data (id_cell_wet_dep_col(n), tempdiag, Time, &
is, js)
endif
!-----------------------------------------------------------------
! define the column-integrated total tracer tendency, in units of
! kg (tracer) / (m**2 sec). send it to diag_manager_mod.
!---------------------------------------------------------------------
tempdiag = 0.0
do k=1,nlev
tempdiag(:,:) = tempdiag(:,:) + Don_conv%qtceme(:,:,k,n)* &
pmass(:,:,k)
end do
if (id_qtceme_col(n) > 0) then
used = send_data (id_qtceme_col(n), tempdiag, Time, is, js)
endif
end do
!---------------------------------------------------------------------
! send the 2D convection-related diagnostics to diag_manager_mod.
!---------------------------------------------------------------------
! pressure at lifting condensation level:
if (id_plcl_deep > 0) then
used = send_data (id_plcl_deep, Don_cape%plcl, Time, is, js)
endif
! pressure at level of free convection:
if (id_plfc_deep > 0) then
used = send_data (id_plfc_deep, Don_cape%plfc, Time, is, js)
endif
! pressure at level of zero buoyancy:
if (id_plzb_deep > 0) then
used = send_data (id_plzb_deep, Don_cape%plzb, Time, is, js)
endif
! convective available potential energy:
if (id_xcape_deep > 0) then
used = send_data (id_xcape_deep, Don_cape%xcape_lag, Time, is, js)
endif
! convective inhibition:
if (id_coin_deep > 0) then
used = send_data (id_coin_deep, Don_cape%coin, Time, is, js)
endif
! time tendency of cape:
if (id_dcape_deep > 0) then
used = send_data (id_dcape_deep, Don_conv%dcape, Time, is, js)
endif
! column integrated water vapor:
if (id_qint_deep > 0) then
used = send_data (id_qint_deep, Don_cape%qint_lag, Time, is, js)
endif
! fractional area of cumulus ensemble members:
if (id_a1_deep > 0) then
used = send_data (id_a1_deep, Don_conv%a1, Time, is, js)
endif
! fractional area of largest cumulus ensemble member:
if (id_amax_deep > 0) then
used = send_data (id_amax_deep, Don_conv%amax, Time, is, js)
endif
! upper limit of fractional area based on moisture constraint:
if (id_amos_deep > 0) then
used = send_data (id_amos_deep, Don_conv%amos, Time, is, js)
endif
! area-weighted total precipitation:
if (id_tprea1_deep > 0) then
used = send_data (id_tprea1_deep, total_precip, Time, is, js)
endif
! mesoscale cloud fraction:
if (id_ampta1_deep > 0) then
used = send_data (id_ampta1_deep, Don_conv%ampta1, Time, is, js)
endif
! accumulated low-level parcel displacement:
if (id_omint_deep > 0) then
used = send_data (id_omint_deep, parcel_rise, Time, is, js)
endif
! area weighted convective precipitation:
if (id_rcoa1_deep > 0) then
used = send_data (id_rcoa1_deep, Don_conv%cell_precip, &
Time, is, js)
endif
if (Nml%do_ensemble_diagnostics) then
!---------------------------------------------------------------------
! Donner cumulus ensemble member diagnostics
!---------------------------------------------------------------------
! GCM model pressure field on full levels:
used = send_data (id_pfull_cem, Don_cem%pfull, &
Time, is, js, 1)
! GCM model pressure field on half levels:
used = send_data (id_phalf_cem, Don_cem%phalf, &
Time, is, js, 1)
! GCM model height field on full levels:
used = send_data (id_zfull_cem, Don_cem%zfull, &
Time, is, js, 1)
! GCM model height field on half levels:
used = send_data (id_zhalf_cem, Don_cem%zhalf, &
Time, is, js, 1)
! GCM model temperature field on full levels:
used = send_data (id_temp_cem, Don_cem%temp, &
Time, is, js, 1)
! GCM model mixing ratio field on full levels:
used = send_data (id_mixing_ratio_cem, Don_cem%mixing_ratio, &
Time, is, js, 1)
do n=1,ncem ! ensemble member number
! area-weighted convective precipitation rate:
used = send_data (id_cpre_cem(n), Don_cem%cell_precip(:,:,n), &
Time, is, js)
! pressure at cloud base:
used = send_data (id_pb_cem(n), Don_cem%pb(:,:,n), &
Time, is, js)
! pressure at cloud top:
used = send_data (id_ptma_cem(n), Don_cem%ptma(:,:,n), &
Time, is, js)
! condensation rate profile on lo-res grid:
used = send_data (id_h1_cem(n), Don_cem%h1(:,:,:,n), &
Time, is, js, 1)
! cloud water profile on lo- or hi-res grid:
used = send_data (id_qlw_cem(n), Don_cem%qlw(:,:,:,n), &
Time, is, js, 1)
! fraction of condensate that is ice on lo- or hi-res grid:
used = send_data (id_cfi_cem(n), Don_cem%cfracice(:,:,:,n), &
Time, is, js, 1)
! plume vertical velocity profile on lo- or hi-res grid:
used = send_data (id_wv_cem(n), Don_cem%wv(:,:,:,n), &
Time, is, js, 1)
! plume cloud radius profile on lo- or hi-res grid:
used = send_data (id_rcl_cem(n), Don_cem%rcl(:,:,:,n), &
Time, is, js, 1)
enddo
! fractional area sum:
used = send_data (id_a1_cem, Don_cem%a1, &
Time, is, js)
! area-weighted mesoscale precipitation rate:
used = send_data (id_mpre_cem, Don_cem%meso_precip, &
Time, is, js)
! cloud fraction, cells+meso, normalized by a(1,p_b) on lo-res grid:
used = send_data (id_cual_cem, Don_cem%cual, &
Time, is, js, 1)
! time tendency of temperature due to deep convection on lo-res grid:
used = send_data (id_tfrc_cem, Don_cem%temperature_forcing, &
Time, is, js, 1)
endif ! (do_ensemble_diagnostics)
!----------------------------------------------------------------------
! send diagnostics associated with the monitored output fields.
!----------------------------------------------------------------------
if (Initialized%monitor_output) then
do n=1,size(Initialized%Don_monitor,1)
if (id_extremes(n) > 0) then
used = send_data (id_extremes(n), &
Initialized%Don_monitor(n)%extrema(is:ie,js:je,:), &
Time, is, js,1, mask = &
Initialized%Don_monitor(n)%extrema(is:ie,js:je,:) /= &
Initialized%Don_monitor(n)%initial_value )
endif
if (id_hits(n) > 0) then
used = send_data (id_hits(n), &
Initialized%Don_monitor(n)%hits(is:ie,js:je,:), &
Time, is, js,1, mask = &
Initialized%Don_monitor(n)%extrema(is:ie,js:je,:) /= &
Initialized%Don_monitor(n)%initial_value )
endif
end do
endif
!----------------------------------------------------------------------
end subroutine donner_deep_netcdf
!######################################################################
!#####################################################################
subroutine write_restart (ntracers, Don_save, Initialized, Nml)
!--------------------------------------------------------------------
! subroutine write_restart is a template to be used if a native mode
! restart file MUST be generated. currently, if a native mode file is
! requested, a netcdf file will be witten instead, and an informative
! message provided.
!--------------------------------------------------------------------
integer, intent(in) :: ntracers
type(donner_initialized_type), intent(inout) :: Initialized
type(donner_save_type), intent(inout) :: Don_save
type(donner_nml_type), intent(inout) :: Nml
!----------------------------------------------------------------------
! intent(in) variables:
!
! ntracers number of tracers to be transported by
! the donner deep convection parameterization
!
!--------------------------------------------------------------------
!--------------------------------------------------------------------
! local variables:
! integer :: unit ! unit number for restart file
! integer :: n ! do-loop index
!-------------------------------------------------------------------
! currently code is provided only for writing netcdf restart files.
! if a non-netcdf restart file has been requested, this routine will
! issue a message, and then call the routine to write the netcdf file.
! if the user is insistent on a native mode restart file, the code to
! read and write such files (subroutines write_restart and
! read_restart_file) must be updated to be compatible with the cur-
! rent versions of write_restart_nc and read_restart_nc, and the
! code immediately below eliminated. the commented code below repres-
! ents a starting point for the write_restart routine; it is not
! kept up-to-date as far as the variables which must be written.
!-------------------------------------------------------------------
call error_mesg ('donner_deep_mod', 'write_restart: &
&writing a netcdf restart despite request for native &
&format (not currently supported); if you must have native &
&mode, then you must update the source code and remove &
&this if loop.', NOTE)
! call write_restart_nc (ntracers, Don_save, Initialized, Nml)
!-------------------------------------------------------------------
! open unit for restart file.
!-------------------------------------------------------------------
! unit = open_restart_file ('RESTART/donner_deep.res', 'write')
!-------------------------------------------------------------------
! file writing is currently single-threaded. write out restart
! version, time remaining until next call to donner_deep_mod and
! the frequency of calculating donner_deep convection.
!-------------------------------------------------------------------
! if (mpp_pe() == mpp_root_pe()) then
! write (unit) restart_versions(size(restart_versions(:)))
! write (unit) Initialized%conv_alarm, donner_deep_freq
! endif
!-------------------------------------------------------------------
! write out the donner_deep restart variables.
! cemetf - heating rate due to donner_deep
! cememf - moistening rate due to donner_deep
! xcape_lag - cape value which will be used on next step in
! calculation od dcape/dt
!-------------------------------------------------------------------
! call write_data (unit, Don_save%cemetf)
! call write_data (unit, Don_save%cememf)
!--------------------------------------------------------------------
! the following variables are needed when a prognostic cloud scheme
! is being used. they are always present in the restart file, having
! been initialized to zero, if prognostic clouds are not active.
!--------------------------------------------------------------------
! call write_data (unit, Don_save%mass_flux)
! call write_data (unit, Don_save%dql_strat )
! call write_data (unit, Don_save%dqi_strat )
! call write_data (unit, Don_save%dqa_strat )
!----------------------------------------------------------------------
!
!-------------------------------------------------------------------
! write out more donner_deep restart variables.
! qint_lag - column integrated water vapor mixing ratio
! parcel_disp - time-integrated low-level vertical displacement
! tprea1 - precipitation due to donner_deep_mod
!----------------------------------------------------------------------
! call write_data (unit, Don_save%parcel_disp)
! call write_data (unit, Don_save%tprea1)
! call write_data (unit, Don_save%lag_temp)
! call write_data (unit, Don_save%lag_vapor)
! call write_data (unit, Don_save%lag_press)
! call write_data (unit, Don_save%humidity_area)
! call write_data (unit, Don_save%humidity_ratio)
!---------------------------------------------------------------------
! write out the number of tracers that are being transported by
! donner_deep_mod.
!---------------------------------------------------------------------
! if (mpp_pe() == mpp_root_pe()) then
! write (unit) ntracers
! endif
!----------------------------------------------------------------------
! if tracers are being transported, write out their names and
! current time tendencies.
!----------------------------------------------------------------------
! if (Initialized%do_donner_tracer) then
! do n=1,ntracers
! if (mpp_pe() == mpp_root_pe()) then
! write (unit) Don_save%tracername(n)
! endif
! call write_data(unit, Don_save%tracer_tends(:,:,:,n))
! end do
! endif
!-------------------------------------------------------------------
! close restart file unit.
!------------------------------------------------------------------
! call close_file (unit)
!---------------------------------------------------------------------
end subroutine write_restart
!######################################################################
!######################################################################
end module fms_donner_mod
| gpl-2.0 |
LeChuck42/or1k-gcc | gcc/testsuite/gfortran.dg/transpose_optimization_1.f90 | 103 | 3369 | ! { dg-do compile }
! { dg-options "-Warray-temporaries -fdump-tree-original" }
!
! PR fortran/45648
! Non-copying descriptor transpose optimization (for function call args).
!
! Contributed by Richard Sandiford <richard@codesourcery.com>
module foo
interface
subroutine ext1 (a, b)
real, intent (in), dimension (:, :) :: a, b
end subroutine ext1
subroutine ext2 (a, b)
real, intent (in), dimension (:, :) :: a
real, intent (out), dimension (:, :) :: b
end subroutine ext2
subroutine ext3 (a, b)
real, dimension (:, :) :: a, b
end subroutine ext3
end interface
contains
! No temporary needed here.
subroutine test1 (n, a, b, c)
integer :: n
real, dimension (n, n) :: a, b, c
a = matmul (transpose (b), c)
end subroutine test1
! No temporary either, as we know the arguments to matmul are intent(in)
subroutine test2 (n, a, b)
integer :: n
real, dimension (n, n) :: a, b
a = matmul (transpose (b), b)
end subroutine test2
! No temporary needed.
subroutine test3 (n, a, b, c)
integer :: n
real, dimension (n, n) :: a, c
real, dimension (n+4, n+4) :: b
a = matmul (transpose (b (2:n+1, 3:n+2)), c)
end subroutine test3
! A temporary is needed for the result of either the transpose or matmul.
subroutine test4 (n, a, b)
integer :: n
real, dimension (n, n) :: a, b
a = matmul (transpose (a), b) ! { dg-warning "Creating array temporary" }
end subroutine test4
! The temporary is needed here since the second argument to imp1
! has unknown intent.
subroutine test5 (n, a)
integer :: n
real, dimension (n, n) :: a
call imp1 (transpose (a), a) ! { dg-warning "Creating array temporary" }
end subroutine test5
! No temporaries are needed here; imp1 can't modify either argument.
! We have to pack the arguments, however.
subroutine test6 (n, a, b)
integer :: n
real, dimension (n, n) :: a, b
call imp1 (transpose (a), transpose (b)) ! { dg-warning "Creating array temporary" }
end subroutine test6
! No temporaries are needed here; imp1 can't modify either argument.
! We don't have to pack the arguments.
subroutine test6_bis (n, a, b)
integer :: n
real, dimension (n, n) :: a, b
call ext3 (transpose (a), transpose (b))
end subroutine test6_bis
! No temporary is neede here; the second argument is intent(in).
subroutine test7 (n, a)
integer :: n
real, dimension (n, n) :: a
call ext1 (transpose (a), a)
end subroutine test7
! The temporary is needed here though.
subroutine test8 (n, a)
integer :: n
real, dimension (n, n) :: a
call ext2 (transpose (a), a) ! { dg-warning "Creating array temporary" }
end subroutine test8
! Silly, but we don't need any temporaries here.
subroutine test9 (n, a)
integer :: n
real, dimension (n, n) :: a
call ext1 (transpose (transpose (a)), a)
end subroutine test9
! The outer transpose needs a temporary; the inner one doesn't.
subroutine test10 (n, a)
integer :: n
real, dimension (n, n) :: a
call ext2 (transpose (transpose (a)), a) ! { dg-warning "Creating array temporary" }
end subroutine test10
end module foo
! { dg-final { scan-tree-dump-times "struct\[^\\n\]*atmp" 4 "original" } }
! { dg-final { cleanup-tree-dump "original" } }
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg/dashpack/dprset.f | 1 | 1331 | C
C $Id: dprset.f,v 1.5 2008-07-27 00:16:59 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE DPRSET
C
C This routine restores the default values of DASHPACK parameters.
C
C Declare the character common block.
C
COMMON /DPCMCH/ CHDP,CHRB,CHRG,CHRS
CHARACTER*256 CHDP
CHARACTER*1 CHRB,CHRG,CHRS
SAVE /DPCMCH/
C
C Declare the real/integer common block.
C
COMMON /DPCMRI/ ANGF,DBPI,EPSI,IDPI,IDPS,ILTL,INDP,IPCF,ISBF,
+ ISCF,LCDP,RLS1,RLS2,RMFS,TENS,WCHR,WGAP,WSLD
SAVE /DPCMRI/
C
C Set all values. For descriptions of the parameters being set, see
C the BLOCK DATA routine DPBLDAX.
C
ANGF=360.
CHDP='$$$$$$$$$$$$$$$$'
CHRB='|'
CHRG='_'
CHRS='$'
DBPI=.01
EPSI=.000001
IDPI=0
IDPS=0
ILTL=0
INDP=65535
IPCF=0
ISBF=1
ISCF=0
LCDP=16
RLS1=.5
RLS2=0.
RMFS=1.
TENS=-1.
WCHR=.01
WGAP=.005
WSLD=.005
C
C Done.
C
RETURN
C
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/fftpack5_dp/c1fm1f.f | 1 | 1815 | CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C FFTPACK 5.0
C Copyright (C) 1995-2004, Scientific Computing Division,
C University Corporation for Atmospheric Research
C Licensed under the GNU General Public License (GPL)
C
C Authors: Paul N. Swarztrauber and Richard A. Valent
C
C $Id: c1fm1f.f,v 1.2 2006-11-21 01:10:15 haley Exp $
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
SUBROUTINE DC1FM1F(N,INC,C,CH,WA,FNF,FAC)
DOUBLE PRECISION FNF
DOUBLE COMPLEX C(*)
DOUBLE PRECISION CH(*),WA(*),FAC(*)
C
C FFTPACK 5.0 auxiliary routine
C
INC2 = INC + INC
NF = FNF
NA = 0
L1 = 1
IW = 1
DO 125 K1 = 1,NF
IP = FAC(K1)
L2 = IP*L1
IDO = N/L2
LID = L1*IDO
NBR = 1 + NA + 2*MIN(IP-2,4)
WRITE (*,FMT=*) WA(IW),WA(IW+1)
GO TO (52,62,53,63,54,64,55,65,56,66) NBR
52 CALL DC1F2KF(IDO,L1,NA,C,INC2,CH,2,WA(IW))
GO TO 120
62 CALL DC1F2KF(IDO,L1,NA,CH,2,C,INC2,WA(IW))
GO TO 120
53 CALL DC1F3KF(IDO,L1,NA,C,INC2,CH,2,WA(IW))
GO TO 120
63 CALL DC1F3KF(IDO,L1,NA,CH,2,C,INC2,WA(IW))
GO TO 120
54 CALL DC1F4KF(IDO,L1,NA,C,INC2,CH,2,WA(IW))
GO TO 120
64 CALL DC1F4KF(IDO,L1,NA,CH,2,C,INC2,WA(IW))
GO TO 120
55 CALL DC1F5KF(IDO,L1,NA,C,INC2,CH,2,WA(IW))
GO TO 120
65 CALL DC1F5KF(IDO,L1,NA,CH,2,C,INC2,WA(IW))
GO TO 120
56 CALL DC1FGKF(IDO,IP,L1,LID,NA,C,C,INC2,CH,CH,1,WA(IW))
GO TO 120
66 CALL DC1FGKF(IDO,IP,L1,LID,NA,CH,CH,2,C,C,INC2,WA(IW))
120 L1 = L2
IW = IW + (IP-1)* (IDO+IDO)
IF (IP.LE.5) NA = 1 - NA
125 CONTINUE
RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg/ezmap/supmap.f | 1 | 3612 | C
C $Id: supmap.f,v 1.26 2008-10-22 20:14:55 kennison Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE SUPMAP (JPRJ,PLAT,PLON,ROTA,PLM1,PLM2,PLM3,PLM4,JLTS,
+ JGRD,IOUT,IDOT,IERR)
C
INTEGER JPRJ,JLTS,JGRD,IOUT,IDOT,IERR
REAL PLAT,PLON,ROTA,PLM1(2),PLM2(2),PLM3(2),PLM4(2)
C
C Declare required common blocks. See MAPBDX for descriptions of these
C common blocks and the variables in them.
C
COMMON /MAPCM5/ DDCT(5),DDCL(5),LDCT(6),LDCL(6),PDCT(19),
+ PDCL(19)
CHARACTER*2 DDCT,DDCL,LDCT,LDCL,PDCT,PDCL
SAVE /MAPCM5/
C
C Declare local variables.
C
INTEGER I,INTF,LLTS(6),LPRJ(18)
C
DATA LPRJ / 2,3,1,4,5,6,16,7,8,9,10,18,11,12,13,14,15,17 /
C
DATA LLTS / 1,2,5,4,3,6 /
C
C Set the error flag to indicate an error; if all goes well, this flag
C will be cleared.
C
IERR=1
C
C Check for an uncleared prior error.
C
IF (ICFELL('SUPMAP - UNCLEARED PRIOR ERROR',1).NE.0) RETURN
C
C Set EZMAP's grid-spacing parameter.
C
CALL MDSETI ('GR',MOD(ABS(JGRD),1000))
IF (ICFELL('SUPMAP',2).NE.0) RETURN
C
C Set EZMAP's outline-selection parameter.
C
IF (ABS(IOUT).EQ.0.OR.ABS(IOUT).EQ.1) THEN
I=1+2*ABS(IOUT)+(1+SIGN(1,JPRJ))/2
ELSE
I=MAX(1,MIN(6,IOUT))
END IF
C
IF (I.LE.5) THEN
CALL MDSETC ('OU',DDCT(I))
IF (ICFELL('SUPMAP',3).NE.0) RETURN
END IF
C
C Set EZMAP's perimeter-drawing flag.
C
CALL MDSETL ('PE',JGRD.GE.0)
IF (ICFELL('SUPMAP',4).NE.0) RETURN
C
C Set EZMAP's grid-line-labelling flag.
C
CALL MDSETL ('LA',MOD(ABS(JGRD),1000).NE.0)
IF (ICFELL('SUPMAP',5).NE.0) RETURN
C
C Set EZMAP's dotted-outline flag.
C
CALL MDSETI ('DO',MAX(0,MIN(1,IDOT)))
IF (ICFELL('SUPMAP',6).NE.0) RETURN
C
C Set EZMAP's projection-selection parameters.
C
I=MAX(1,MIN(18,ABS(JPRJ)))
CALL MAPROJ (PDCT(LPRJ(I)+1),PLAT,PLON,ROTA)
IF (ICFELL('SUPMAP',7).NE.0) RETURN
C
C Set EZMAP's rectangular-limits-selection parameters.
C
I=LLTS(MAX(1,MIN(6,ABS(JLTS))))
CALL MAPSET (LDCT(I),PLM1,PLM2,PLM3,PLM4)
IF (ICFELL('SUPMAP',8).NE.0) RETURN
C
C Draw the map.
C
CALL MDGETI ('IN',INTF)
C
IF (INTF.NE.0) THEN
CALL MDPINT
IF (ICFELL('SUPMAP',9).NE.0) RETURN
END IF
C
CALL MDPGRD
IF (ICFELL('SUPMAP',10).NE.0) RETURN
C
CALL MDPLBL
IF (ICFELL('SUPMAP',11).NE.0) RETURN
C
IF (IOUT.LT.100) THEN
CALL MDPLOT
IF (ICFELL('SUPMAP',12).NE.0) RETURN
ELSE IF (IOUT.LT.200) THEN
CALL MDLNDR ('Earth..1',MAX(1,MIN(5,MOD(IOUT,100))))
IF (ICFELL('SUPMAP',13).NE.0) RETURN
ELSE IF (IOUT.LT.300) THEN
CALL MDLNDR ('Earth..2',MAX(1,MIN(5,MOD(IOUT,100))))
IF (ICFELL('SUPMAP',14).NE.0) RETURN
ELSE IF (IOUT.LT.400) THEN
CALL MDLNDR ('Earth..3',MAX(1,MIN(5,MOD(IOUT,100))))
IF (ICFELL('SUPMAP',15).NE.0) RETURN
ELSE IF (IOUT.LT.500) THEN
CALL MDLNDR ('Earth..4',MAX(1,MIN(5,MOD(IOUT,100))))
IF (ICFELL('SUPMAP',16).NE.0) RETURN
ELSE
CALL MDPLOT
IF (ICFELL('SUPMAP',17).NE.0) RETURN
END IF
C
C All seems to have gone well - turn off the error flag.
C
IERR=0
C
C Done.
C
RETURN
C
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/fftpack5_dp/mradf3.f | 1 | 4241 | CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C FFTPACK 5.0
C Copyright (C) 1995-2004, Scientific Computing Division,
C University Corporation for Atmospheric Research
C Licensed under the GNU General Public License (GPL)
C
C Authors: Paul N. Swarztrauber and Richard A. Valent
C
C $Id: mradf3.f,v 1.2 2006-11-21 01:10:18 haley Exp $
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
SUBROUTINE DMRADF3(M,IDO,L1,CC,IM1,IN1,CH,IM2,IN2,WA1,WA2)
DOUBLE PRECISION ARG
DOUBLE PRECISION TAUR
DOUBLE PRECISION TAUI
DOUBLE PRECISION CH(IN2,IDO,3,L1),CC(IN1,IDO,L1,3),WA1(IDO),
+ WA2(IDO)
C
M1D = (M-1)*IM1 + 1
M2S = 1 - IM2
ARG = 2.D0*4.D0*ATAN(1.0D0)/3.D0
TAUR = COS(ARG)
TAUI = SIN(ARG)
DO 101 K = 1,L1
M2 = M2S
DO 1001 M1 = 1,M1D,IM1
M2 = M2 + IM2
CH(M2,1,1,K) = CC(M1,1,K,1) + (CC(M1,1,K,2)+CC(M1,1,K,3))
CH(M2,1,3,K) = TAUI* (CC(M1,1,K,3)-CC(M1,1,K,2))
CH(M2,IDO,2,K) = CC(M1,1,K,1) +
+ TA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+ 2)-WA1(I-1)*CC(M1,I-1,K,
+ 2))+ (WA2(I-2)*CC(M1,I,K,
+ 3)-WA2(I-1)*CC(M1,I-1,K,3)))) +
+ (TAUI* ((WA2(I-2)*CC(M1,I-1,K,
+ 3)+WA2(I-1)*CC(M1,I,K,
+ 3))- (WA1(I-2)*CC(M1,I-1,K,
+ 2)+WA1(I-1)*CC(M1,I,K,2))))
CH(M2,IC,2,K) = (TAUI* ((WA2(I-2)*CC(M1,I-1,K,
+ 3)+WA2(I-1)*CC(M1,I,K,
+ 3))- (WA1(I-2)*CC(M1,I-1,K,
+ 2)+WA1(I-1)*CC(M1,I,K,2)))) -
+ (CC(M1,I,K,1)+TAUR*
+ ((WA1(I-2)*CC(M1,I,K,
+ 2)-WA1(I-1)*CC(M1,I-1,K,
+ 2))+ (WA2(I-2)*CC(M1,I,K,
+ 3)-WA2(I-1)*CC(M1,I-1,K,3))))
1002 CONTINUE
102 CONTINUE
103 CONTINUE
RETURN
END
| gpl-2.0 |
wilfeli/DMGameBasic | ExternalTools/Eigen/blas/testing/cblat3.f | 198 | 130271 | PROGRAM CBLAT3
*
* Test program for the COMPLEX Level 3 Blas.
*
* The program must be driven by a short data file. The first 14 records
* of the file are read using list-directed input, the last 9 records
* are read using the format ( A6, L2 ). An annotated example of a data
* file can be obtained by deleting the first 3 characters from the
* following 23 lines:
* 'CBLAT3.SUMM' NAME OF SUMMARY OUTPUT FILE
* 6 UNIT NUMBER OF SUMMARY FILE
* 'CBLAT3.SNAP' NAME OF SNAPSHOT OUTPUT FILE
* -1 UNIT NUMBER OF SNAPSHOT FILE (NOT USED IF .LT. 0)
* F LOGICAL FLAG, T TO REWIND SNAPSHOT FILE AFTER EACH RECORD.
* F LOGICAL FLAG, T TO STOP ON FAILURES.
* T LOGICAL FLAG, T TO TEST ERROR EXITS.
* 16.0 THRESHOLD VALUE OF TEST RATIO
* 6 NUMBER OF VALUES OF N
* 0 1 2 3 5 9 VALUES OF N
* 3 NUMBER OF VALUES OF ALPHA
* (0.0,0.0) (1.0,0.0) (0.7,-0.9) VALUES OF ALPHA
* 3 NUMBER OF VALUES OF BETA
* (0.0,0.0) (1.0,0.0) (1.3,-1.1) VALUES OF BETA
* CGEMM T PUT F FOR NO TEST. SAME COLUMNS.
* CHEMM T PUT F FOR NO TEST. SAME COLUMNS.
* CSYMM T PUT F FOR NO TEST. SAME COLUMNS.
* CTRMM T PUT F FOR NO TEST. SAME COLUMNS.
* CTRSM T PUT F FOR NO TEST. SAME COLUMNS.
* CHERK T PUT F FOR NO TEST. SAME COLUMNS.
* CSYRK T PUT F FOR NO TEST. SAME COLUMNS.
* CHER2K T PUT F FOR NO TEST. SAME COLUMNS.
* CSYR2K T PUT F FOR NO TEST. SAME COLUMNS.
*
* See:
*
* Dongarra J. J., Du Croz J. J., Duff I. S. and Hammarling S.
* A Set of Level 3 Basic Linear Algebra Subprograms.
*
* Technical Memorandum No.88 (Revision 1), Mathematics and
* Computer Science Division, Argonne National Laboratory, 9700
* South Cass Avenue, Argonne, Illinois 60439, US.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
INTEGER NIN
PARAMETER ( NIN = 5 )
INTEGER NSUBS
PARAMETER ( NSUBS = 9 )
COMPLEX ZERO, ONE
PARAMETER ( ZERO = ( 0.0, 0.0 ), ONE = ( 1.0, 0.0 ) )
REAL RZERO, RHALF, RONE
PARAMETER ( RZERO = 0.0, RHALF = 0.5, RONE = 1.0 )
INTEGER NMAX
PARAMETER ( NMAX = 65 )
INTEGER NIDMAX, NALMAX, NBEMAX
PARAMETER ( NIDMAX = 9, NALMAX = 7, NBEMAX = 7 )
* .. Local Scalars ..
REAL EPS, ERR, THRESH
INTEGER I, ISNUM, J, N, NALF, NBET, NIDIM, NOUT, NTRA
LOGICAL FATAL, LTESTT, REWI, SAME, SFATAL, TRACE,
$ TSTERR
CHARACTER*1 TRANSA, TRANSB
CHARACTER*6 SNAMET
CHARACTER*32 SNAPS, SUMMRY
* .. Local Arrays ..
COMPLEX AA( NMAX*NMAX ), AB( NMAX, 2*NMAX ),
$ ALF( NALMAX ), AS( NMAX*NMAX ),
$ BB( NMAX*NMAX ), BET( NBEMAX ),
$ BS( NMAX*NMAX ), C( NMAX, NMAX ),
$ CC( NMAX*NMAX ), CS( NMAX*NMAX ), CT( NMAX ),
$ W( 2*NMAX )
REAL G( NMAX )
INTEGER IDIM( NIDMAX )
LOGICAL LTEST( NSUBS )
CHARACTER*6 SNAMES( NSUBS )
* .. External Functions ..
REAL SDIFF
LOGICAL LCE
EXTERNAL SDIFF, LCE
* .. External Subroutines ..
EXTERNAL CCHK1, CCHK2, CCHK3, CCHK4, CCHK5, CCHKE, CMMCH
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
CHARACTER*6 SRNAMT
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
COMMON /SRNAMC/SRNAMT
* .. Data statements ..
DATA SNAMES/'CGEMM ', 'CHEMM ', 'CSYMM ', 'CTRMM ',
$ 'CTRSM ', 'CHERK ', 'CSYRK ', 'CHER2K',
$ 'CSYR2K'/
* .. Executable Statements ..
*
* Read name and unit number for summary output file and open file.
*
READ( NIN, FMT = * )SUMMRY
READ( NIN, FMT = * )NOUT
OPEN( NOUT, FILE = SUMMRY, STATUS = 'NEW' )
NOUTC = NOUT
*
* Read name and unit number for snapshot output file and open file.
*
READ( NIN, FMT = * )SNAPS
READ( NIN, FMT = * )NTRA
TRACE = NTRA.GE.0
IF( TRACE )THEN
OPEN( NTRA, FILE = SNAPS, STATUS = 'NEW' )
END IF
* Read the flag that directs rewinding of the snapshot file.
READ( NIN, FMT = * )REWI
REWI = REWI.AND.TRACE
* Read the flag that directs stopping on any failure.
READ( NIN, FMT = * )SFATAL
* Read the flag that indicates whether error exits are to be tested.
READ( NIN, FMT = * )TSTERR
* Read the threshold value of the test ratio
READ( NIN, FMT = * )THRESH
*
* Read and check the parameter values for the tests.
*
* Values of N
READ( NIN, FMT = * )NIDIM
IF( NIDIM.LT.1.OR.NIDIM.GT.NIDMAX )THEN
WRITE( NOUT, FMT = 9997 )'N', NIDMAX
GO TO 220
END IF
READ( NIN, FMT = * )( IDIM( I ), I = 1, NIDIM )
DO 10 I = 1, NIDIM
IF( IDIM( I ).LT.0.OR.IDIM( I ).GT.NMAX )THEN
WRITE( NOUT, FMT = 9996 )NMAX
GO TO 220
END IF
10 CONTINUE
* Values of ALPHA
READ( NIN, FMT = * )NALF
IF( NALF.LT.1.OR.NALF.GT.NALMAX )THEN
WRITE( NOUT, FMT = 9997 )'ALPHA', NALMAX
GO TO 220
END IF
READ( NIN, FMT = * )( ALF( I ), I = 1, NALF )
* Values of BETA
READ( NIN, FMT = * )NBET
IF( NBET.LT.1.OR.NBET.GT.NBEMAX )THEN
WRITE( NOUT, FMT = 9997 )'BETA', NBEMAX
GO TO 220
END IF
READ( NIN, FMT = * )( BET( I ), I = 1, NBET )
*
* Report values of parameters.
*
WRITE( NOUT, FMT = 9995 )
WRITE( NOUT, FMT = 9994 )( IDIM( I ), I = 1, NIDIM )
WRITE( NOUT, FMT = 9993 )( ALF( I ), I = 1, NALF )
WRITE( NOUT, FMT = 9992 )( BET( I ), I = 1, NBET )
IF( .NOT.TSTERR )THEN
WRITE( NOUT, FMT = * )
WRITE( NOUT, FMT = 9984 )
END IF
WRITE( NOUT, FMT = * )
WRITE( NOUT, FMT = 9999 )THRESH
WRITE( NOUT, FMT = * )
*
* Read names of subroutines and flags which indicate
* whether they are to be tested.
*
DO 20 I = 1, NSUBS
LTEST( I ) = .FALSE.
20 CONTINUE
30 READ( NIN, FMT = 9988, END = 60 )SNAMET, LTESTT
DO 40 I = 1, NSUBS
IF( SNAMET.EQ.SNAMES( I ) )
$ GO TO 50
40 CONTINUE
WRITE( NOUT, FMT = 9990 )SNAMET
STOP
50 LTEST( I ) = LTESTT
GO TO 30
*
60 CONTINUE
CLOSE ( NIN )
*
* Compute EPS (the machine precision).
*
EPS = RONE
70 CONTINUE
IF( SDIFF( RONE + EPS, RONE ).EQ.RZERO )
$ GO TO 80
EPS = RHALF*EPS
GO TO 70
80 CONTINUE
EPS = EPS + EPS
WRITE( NOUT, FMT = 9998 )EPS
*
* Check the reliability of CMMCH using exact data.
*
N = MIN( 32, NMAX )
DO 100 J = 1, N
DO 90 I = 1, N
AB( I, J ) = MAX( I - J + 1, 0 )
90 CONTINUE
AB( J, NMAX + 1 ) = J
AB( 1, NMAX + J ) = J
C( J, 1 ) = ZERO
100 CONTINUE
DO 110 J = 1, N
CC( J ) = J*( ( J + 1 )*J )/2 - ( ( J + 1 )*J*( J - 1 ) )/3
110 CONTINUE
* CC holds the exact result. On exit from CMMCH CT holds
* the result computed by CMMCH.
TRANSA = 'N'
TRANSB = 'N'
CALL CMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LCE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.RZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
TRANSB = 'C'
CALL CMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LCE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.RZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
DO 120 J = 1, N
AB( J, NMAX + 1 ) = N - J + 1
AB( 1, NMAX + J ) = N - J + 1
120 CONTINUE
DO 130 J = 1, N
CC( N - J + 1 ) = J*( ( J + 1 )*J )/2 -
$ ( ( J + 1 )*J*( J - 1 ) )/3
130 CONTINUE
TRANSA = 'C'
TRANSB = 'N'
CALL CMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LCE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.RZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
TRANSB = 'C'
CALL CMMCH( TRANSA, TRANSB, N, 1, N, ONE, AB, NMAX,
$ AB( 1, NMAX + 1 ), NMAX, ZERO, C, NMAX, CT, G, CC,
$ NMAX, EPS, ERR, FATAL, NOUT, .TRUE. )
SAME = LCE( CC, CT, N )
IF( .NOT.SAME.OR.ERR.NE.RZERO )THEN
WRITE( NOUT, FMT = 9989 )TRANSA, TRANSB, SAME, ERR
STOP
END IF
*
* Test each subroutine in turn.
*
DO 200 ISNUM = 1, NSUBS
WRITE( NOUT, FMT = * )
IF( .NOT.LTEST( ISNUM ) )THEN
* Subprogram is not to be tested.
WRITE( NOUT, FMT = 9987 )SNAMES( ISNUM )
ELSE
SRNAMT = SNAMES( ISNUM )
* Test error exits.
IF( TSTERR )THEN
CALL CCHKE( ISNUM, SNAMES( ISNUM ), NOUT )
WRITE( NOUT, FMT = * )
END IF
* Test computations.
INFOT = 0
OK = .TRUE.
FATAL = .FALSE.
GO TO ( 140, 150, 150, 160, 160, 170, 170,
$ 180, 180 )ISNUM
* Test CGEMM, 01.
140 CALL CCHK1( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C,
$ CC, CS, CT, G )
GO TO 190
* Test CHEMM, 02, CSYMM, 03.
150 CALL CCHK2( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C,
$ CC, CS, CT, G )
GO TO 190
* Test CTRMM, 04, CTRSM, 05.
160 CALL CCHK3( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NMAX, AB,
$ AA, AS, AB( 1, NMAX + 1 ), BB, BS, CT, G, C )
GO TO 190
* Test CHERK, 06, CSYRK, 07.
170 CALL CCHK4( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, AB( 1, NMAX + 1 ), BB, BS, C,
$ CC, CS, CT, G )
GO TO 190
* Test CHER2K, 08, CSYR2K, 09.
180 CALL CCHK5( SNAMES( ISNUM ), EPS, THRESH, NOUT, NTRA, TRACE,
$ REWI, FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET,
$ NMAX, AB, AA, AS, BB, BS, C, CC, CS, CT, G, W )
GO TO 190
*
190 IF( FATAL.AND.SFATAL )
$ GO TO 210
END IF
200 CONTINUE
WRITE( NOUT, FMT = 9986 )
GO TO 230
*
210 CONTINUE
WRITE( NOUT, FMT = 9985 )
GO TO 230
*
220 CONTINUE
WRITE( NOUT, FMT = 9991 )
*
230 CONTINUE
IF( TRACE )
$ CLOSE ( NTRA )
CLOSE ( NOUT )
STOP
*
9999 FORMAT( ' ROUTINES PASS COMPUTATIONAL TESTS IF TEST RATIO IS LES',
$ 'S THAN', F8.2 )
9998 FORMAT( ' RELATIVE MACHINE PRECISION IS TAKEN TO BE', 1P, E9.1 )
9997 FORMAT( ' NUMBER OF VALUES OF ', A, ' IS LESS THAN 1 OR GREATER ',
$ 'THAN ', I2 )
9996 FORMAT( ' VALUE OF N IS LESS THAN 0 OR GREATER THAN ', I2 )
9995 FORMAT( ' TESTS OF THE COMPLEX LEVEL 3 BLAS', //' THE F',
$ 'OLLOWING PARAMETER VALUES WILL BE USED:' )
9994 FORMAT( ' FOR N ', 9I6 )
9993 FORMAT( ' FOR ALPHA ',
$ 7( '(', F4.1, ',', F4.1, ') ', : ) )
9992 FORMAT( ' FOR BETA ',
$ 7( '(', F4.1, ',', F4.1, ') ', : ) )
9991 FORMAT( ' AMEND DATA FILE OR INCREASE ARRAY SIZES IN PROGRAM',
$ /' ******* TESTS ABANDONED *******' )
9990 FORMAT( ' SUBPROGRAM NAME ', A6, ' NOT RECOGNIZED', /' ******* T',
$ 'ESTS ABANDONED *******' )
9989 FORMAT( ' ERROR IN CMMCH - IN-LINE DOT PRODUCTS ARE BEING EVALU',
$ 'ATED WRONGLY.', /' CMMCH WAS CALLED WITH TRANSA = ', A1,
$ ' AND TRANSB = ', A1, /' AND RETURNED SAME = ', L1, ' AND ',
$ 'ERR = ', F12.3, '.', /' THIS MAY BE DUE TO FAULTS IN THE ',
$ 'ARITHMETIC OR THE COMPILER.', /' ******* TESTS ABANDONED ',
$ '*******' )
9988 FORMAT( A6, L2 )
9987 FORMAT( 1X, A6, ' WAS NOT TESTED' )
9986 FORMAT( /' END OF TESTS' )
9985 FORMAT( /' ******* FATAL ERROR - TESTS ABANDONED *******' )
9984 FORMAT( ' ERROR-EXITS WILL NOT BE TESTED' )
*
* End of CBLAT3.
*
END
SUBROUTINE CCHK1( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ A, AA, AS, B, BB, BS, C, CC, CS, CT, G )
*
* Tests CGEMM.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
COMPLEX ZERO
PARAMETER ( ZERO = ( 0.0, 0.0 ) )
REAL RZERO
PARAMETER ( RZERO = 0.0 )
* .. Scalar Arguments ..
REAL EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
COMPLEX A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CC( NMAX*NMAX ),
$ CS( NMAX*NMAX ), CT( NMAX )
REAL G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
COMPLEX ALPHA, ALS, BETA, BLS
REAL ERR, ERRMAX
INTEGER I, IA, IB, ICA, ICB, IK, IM, IN, K, KS, LAA,
$ LBB, LCC, LDA, LDAS, LDB, LDBS, LDC, LDCS, M,
$ MA, MB, MS, N, NA, NARGS, NB, NC, NS
LOGICAL NULL, RESET, SAME, TRANA, TRANB
CHARACTER*1 TRANAS, TRANBS, TRANSA, TRANSB
CHARACTER*3 ICH
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LCE, LCERES
EXTERNAL LCE, LCERES
* .. External Subroutines ..
EXTERNAL CGEMM, CMAKE, CMMCH
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICH/'NTC'/
* .. Executable Statements ..
*
NARGS = 13
NC = 0
RESET = .TRUE.
ERRMAX = RZERO
*
DO 110 IM = 1, NIDIM
M = IDIM( IM )
*
DO 100 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = M
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 100
LCC = LDC*N
NULL = N.LE.0.OR.M.LE.0
*
DO 90 IK = 1, NIDIM
K = IDIM( IK )
*
DO 80 ICA = 1, 3
TRANSA = ICH( ICA: ICA )
TRANA = TRANSA.EQ.'T'.OR.TRANSA.EQ.'C'
*
IF( TRANA )THEN
MA = K
NA = M
ELSE
MA = M
NA = K
END IF
* Set LDA to 1 more than minimum value if room.
LDA = MA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 80
LAA = LDA*NA
*
* Generate the matrix A.
*
CALL CMAKE( 'GE', ' ', ' ', MA, NA, A, NMAX, AA, LDA,
$ RESET, ZERO )
*
DO 70 ICB = 1, 3
TRANSB = ICH( ICB: ICB )
TRANB = TRANSB.EQ.'T'.OR.TRANSB.EQ.'C'
*
IF( TRANB )THEN
MB = N
NB = K
ELSE
MB = K
NB = N
END IF
* Set LDB to 1 more than minimum value if room.
LDB = MB
IF( LDB.LT.NMAX )
$ LDB = LDB + 1
* Skip tests if not enough room.
IF( LDB.GT.NMAX )
$ GO TO 70
LBB = LDB*NB
*
* Generate the matrix B.
*
CALL CMAKE( 'GE', ' ', ' ', MB, NB, B, NMAX, BB,
$ LDB, RESET, ZERO )
*
DO 60 IA = 1, NALF
ALPHA = ALF( IA )
*
DO 50 IB = 1, NBET
BETA = BET( IB )
*
* Generate the matrix C.
*
CALL CMAKE( 'GE', ' ', ' ', M, N, C, NMAX,
$ CC, LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the
* subroutine.
*
TRANAS = TRANSA
TRANBS = TRANSB
MS = M
NS = N
KS = K
ALS = ALPHA
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
DO 20 I = 1, LBB
BS( I ) = BB( I )
20 CONTINUE
LDBS = LDB
BLS = BETA
DO 30 I = 1, LCC
CS( I ) = CC( I )
30 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME,
$ TRANSA, TRANSB, M, N, K, ALPHA, LDA, LDB,
$ BETA, LDC
IF( REWI )
$ REWIND NTRA
CALL CGEMM( TRANSA, TRANSB, M, N, K, ALPHA,
$ AA, LDA, BB, LDB, BETA, CC, LDC )
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9994 )
FATAL = .TRUE.
GO TO 120
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = TRANSA.EQ.TRANAS
ISAME( 2 ) = TRANSB.EQ.TRANBS
ISAME( 3 ) = MS.EQ.M
ISAME( 4 ) = NS.EQ.N
ISAME( 5 ) = KS.EQ.K
ISAME( 6 ) = ALS.EQ.ALPHA
ISAME( 7 ) = LCE( AS, AA, LAA )
ISAME( 8 ) = LDAS.EQ.LDA
ISAME( 9 ) = LCE( BS, BB, LBB )
ISAME( 10 ) = LDBS.EQ.LDB
ISAME( 11 ) = BLS.EQ.BETA
IF( NULL )THEN
ISAME( 12 ) = LCE( CS, CC, LCC )
ELSE
ISAME( 12 ) = LCERES( 'GE', ' ', M, N, CS,
$ CC, LDC )
END IF
ISAME( 13 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report
* and return.
*
SAME = .TRUE.
DO 40 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
40 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 120
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result.
*
CALL CMMCH( TRANSA, TRANSB, M, N, K,
$ ALPHA, A, NMAX, B, NMAX, BETA,
$ C, NMAX, CT, G, CC, LDC, EPS,
$ ERR, FATAL, NOUT, .TRUE. )
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 120
END IF
*
50 CONTINUE
*
60 CONTINUE
*
70 CONTINUE
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
110 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 130
*
120 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9995 )NC, SNAME, TRANSA, TRANSB, M, N, K,
$ ALPHA, LDA, LDB, BETA, LDC
*
130 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( 1X, I6, ': ', A6, '(''', A1, ''',''', A1, ''',',
$ 3( I3, ',' ), '(', F4.1, ',', F4.1, '), A,', I3, ', B,', I3,
$ ',(', F4.1, ',', F4.1, '), C,', I3, ').' )
9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of CCHK1.
*
END
SUBROUTINE CCHK2( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ A, AA, AS, B, BB, BS, C, CC, CS, CT, G )
*
* Tests CHEMM and CSYMM.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
COMPLEX ZERO
PARAMETER ( ZERO = ( 0.0, 0.0 ) )
REAL RZERO
PARAMETER ( RZERO = 0.0 )
* .. Scalar Arguments ..
REAL EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
COMPLEX A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CC( NMAX*NMAX ),
$ CS( NMAX*NMAX ), CT( NMAX )
REAL G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
COMPLEX ALPHA, ALS, BETA, BLS
REAL ERR, ERRMAX
INTEGER I, IA, IB, ICS, ICU, IM, IN, LAA, LBB, LCC,
$ LDA, LDAS, LDB, LDBS, LDC, LDCS, M, MS, N, NA,
$ NARGS, NC, NS
LOGICAL CONJ, LEFT, NULL, RESET, SAME
CHARACTER*1 SIDE, SIDES, UPLO, UPLOS
CHARACTER*2 ICHS, ICHU
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LCE, LCERES
EXTERNAL LCE, LCERES
* .. External Subroutines ..
EXTERNAL CHEMM, CMAKE, CMMCH, CSYMM
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHS/'LR'/, ICHU/'UL'/
* .. Executable Statements ..
CONJ = SNAME( 2: 3 ).EQ.'HE'
*
NARGS = 12
NC = 0
RESET = .TRUE.
ERRMAX = RZERO
*
DO 100 IM = 1, NIDIM
M = IDIM( IM )
*
DO 90 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = M
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 90
LCC = LDC*N
NULL = N.LE.0.OR.M.LE.0
* Set LDB to 1 more than minimum value if room.
LDB = M
IF( LDB.LT.NMAX )
$ LDB = LDB + 1
* Skip tests if not enough room.
IF( LDB.GT.NMAX )
$ GO TO 90
LBB = LDB*N
*
* Generate the matrix B.
*
CALL CMAKE( 'GE', ' ', ' ', M, N, B, NMAX, BB, LDB, RESET,
$ ZERO )
*
DO 80 ICS = 1, 2
SIDE = ICHS( ICS: ICS )
LEFT = SIDE.EQ.'L'
*
IF( LEFT )THEN
NA = M
ELSE
NA = N
END IF
* Set LDA to 1 more than minimum value if room.
LDA = NA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 80
LAA = LDA*NA
*
DO 70 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
*
* Generate the hermitian or symmetric matrix A.
*
CALL CMAKE( SNAME( 2: 3 ), UPLO, ' ', NA, NA, A, NMAX,
$ AA, LDA, RESET, ZERO )
*
DO 60 IA = 1, NALF
ALPHA = ALF( IA )
*
DO 50 IB = 1, NBET
BETA = BET( IB )
*
* Generate the matrix C.
*
CALL CMAKE( 'GE', ' ', ' ', M, N, C, NMAX, CC,
$ LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the
* subroutine.
*
SIDES = SIDE
UPLOS = UPLO
MS = M
NS = N
ALS = ALPHA
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
DO 20 I = 1, LBB
BS( I ) = BB( I )
20 CONTINUE
LDBS = LDB
BLS = BETA
DO 30 I = 1, LCC
CS( I ) = CC( I )
30 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME, SIDE,
$ UPLO, M, N, ALPHA, LDA, LDB, BETA, LDC
IF( REWI )
$ REWIND NTRA
IF( CONJ )THEN
CALL CHEMM( SIDE, UPLO, M, N, ALPHA, AA, LDA,
$ BB, LDB, BETA, CC, LDC )
ELSE
CALL CSYMM( SIDE, UPLO, M, N, ALPHA, AA, LDA,
$ BB, LDB, BETA, CC, LDC )
END IF
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9994 )
FATAL = .TRUE.
GO TO 110
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = SIDES.EQ.SIDE
ISAME( 2 ) = UPLOS.EQ.UPLO
ISAME( 3 ) = MS.EQ.M
ISAME( 4 ) = NS.EQ.N
ISAME( 5 ) = ALS.EQ.ALPHA
ISAME( 6 ) = LCE( AS, AA, LAA )
ISAME( 7 ) = LDAS.EQ.LDA
ISAME( 8 ) = LCE( BS, BB, LBB )
ISAME( 9 ) = LDBS.EQ.LDB
ISAME( 10 ) = BLS.EQ.BETA
IF( NULL )THEN
ISAME( 11 ) = LCE( CS, CC, LCC )
ELSE
ISAME( 11 ) = LCERES( 'GE', ' ', M, N, CS,
$ CC, LDC )
END IF
ISAME( 12 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 40 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
40 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 110
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result.
*
IF( LEFT )THEN
CALL CMMCH( 'N', 'N', M, N, M, ALPHA, A,
$ NMAX, B, NMAX, BETA, C, NMAX,
$ CT, G, CC, LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
ELSE
CALL CMMCH( 'N', 'N', M, N, N, ALPHA, B,
$ NMAX, A, NMAX, BETA, C, NMAX,
$ CT, G, CC, LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 110
END IF
*
50 CONTINUE
*
60 CONTINUE
*
70 CONTINUE
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 120
*
110 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9995 )NC, SNAME, SIDE, UPLO, M, N, ALPHA, LDA,
$ LDB, BETA, LDC
*
120 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ),
$ '(', F4.1, ',', F4.1, '), A,', I3, ', B,', I3, ',(', F4.1,
$ ',', F4.1, '), C,', I3, ') .' )
9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of CCHK2.
*
END
SUBROUTINE CCHK3( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NMAX, A, AA, AS,
$ B, BB, BS, CT, G, C )
*
* Tests CTRMM and CTRSM.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
COMPLEX ZERO, ONE
PARAMETER ( ZERO = ( 0.0, 0.0 ), ONE = ( 1.0, 0.0 ) )
REAL RZERO
PARAMETER ( RZERO = 0.0 )
* .. Scalar Arguments ..
REAL EPS, THRESH
INTEGER NALF, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
COMPLEX A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CT( NMAX )
REAL G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
COMPLEX ALPHA, ALS
REAL ERR, ERRMAX
INTEGER I, IA, ICD, ICS, ICT, ICU, IM, IN, J, LAA, LBB,
$ LDA, LDAS, LDB, LDBS, M, MS, N, NA, NARGS, NC,
$ NS
LOGICAL LEFT, NULL, RESET, SAME
CHARACTER*1 DIAG, DIAGS, SIDE, SIDES, TRANAS, TRANSA, UPLO,
$ UPLOS
CHARACTER*2 ICHD, ICHS, ICHU
CHARACTER*3 ICHT
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LCE, LCERES
EXTERNAL LCE, LCERES
* .. External Subroutines ..
EXTERNAL CMAKE, CMMCH, CTRMM, CTRSM
* .. Intrinsic Functions ..
INTRINSIC MAX
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHU/'UL'/, ICHT/'NTC'/, ICHD/'UN'/, ICHS/'LR'/
* .. Executable Statements ..
*
NARGS = 11
NC = 0
RESET = .TRUE.
ERRMAX = RZERO
* Set up zero matrix for CMMCH.
DO 20 J = 1, NMAX
DO 10 I = 1, NMAX
C( I, J ) = ZERO
10 CONTINUE
20 CONTINUE
*
DO 140 IM = 1, NIDIM
M = IDIM( IM )
*
DO 130 IN = 1, NIDIM
N = IDIM( IN )
* Set LDB to 1 more than minimum value if room.
LDB = M
IF( LDB.LT.NMAX )
$ LDB = LDB + 1
* Skip tests if not enough room.
IF( LDB.GT.NMAX )
$ GO TO 130
LBB = LDB*N
NULL = M.LE.0.OR.N.LE.0
*
DO 120 ICS = 1, 2
SIDE = ICHS( ICS: ICS )
LEFT = SIDE.EQ.'L'
IF( LEFT )THEN
NA = M
ELSE
NA = N
END IF
* Set LDA to 1 more than minimum value if room.
LDA = NA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 130
LAA = LDA*NA
*
DO 110 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
*
DO 100 ICT = 1, 3
TRANSA = ICHT( ICT: ICT )
*
DO 90 ICD = 1, 2
DIAG = ICHD( ICD: ICD )
*
DO 80 IA = 1, NALF
ALPHA = ALF( IA )
*
* Generate the matrix A.
*
CALL CMAKE( 'TR', UPLO, DIAG, NA, NA, A,
$ NMAX, AA, LDA, RESET, ZERO )
*
* Generate the matrix B.
*
CALL CMAKE( 'GE', ' ', ' ', M, N, B, NMAX,
$ BB, LDB, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the
* subroutine.
*
SIDES = SIDE
UPLOS = UPLO
TRANAS = TRANSA
DIAGS = DIAG
MS = M
NS = N
ALS = ALPHA
DO 30 I = 1, LAA
AS( I ) = AA( I )
30 CONTINUE
LDAS = LDA
DO 40 I = 1, LBB
BS( I ) = BB( I )
40 CONTINUE
LDBS = LDB
*
* Call the subroutine.
*
IF( SNAME( 4: 5 ).EQ.'MM' )THEN
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME,
$ SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA,
$ LDA, LDB
IF( REWI )
$ REWIND NTRA
CALL CTRMM( SIDE, UPLO, TRANSA, DIAG, M,
$ N, ALPHA, AA, LDA, BB, LDB )
ELSE IF( SNAME( 4: 5 ).EQ.'SM' )THEN
IF( TRACE )
$ WRITE( NTRA, FMT = 9995 )NC, SNAME,
$ SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA,
$ LDA, LDB
IF( REWI )
$ REWIND NTRA
CALL CTRSM( SIDE, UPLO, TRANSA, DIAG, M,
$ N, ALPHA, AA, LDA, BB, LDB )
END IF
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9994 )
FATAL = .TRUE.
GO TO 150
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = SIDES.EQ.SIDE
ISAME( 2 ) = UPLOS.EQ.UPLO
ISAME( 3 ) = TRANAS.EQ.TRANSA
ISAME( 4 ) = DIAGS.EQ.DIAG
ISAME( 5 ) = MS.EQ.M
ISAME( 6 ) = NS.EQ.N
ISAME( 7 ) = ALS.EQ.ALPHA
ISAME( 8 ) = LCE( AS, AA, LAA )
ISAME( 9 ) = LDAS.EQ.LDA
IF( NULL )THEN
ISAME( 10 ) = LCE( BS, BB, LBB )
ELSE
ISAME( 10 ) = LCERES( 'GE', ' ', M, N, BS,
$ BB, LDB )
END IF
ISAME( 11 ) = LDBS.EQ.LDB
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 50 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
50 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 150
END IF
*
IF( .NOT.NULL )THEN
IF( SNAME( 4: 5 ).EQ.'MM' )THEN
*
* Check the result.
*
IF( LEFT )THEN
CALL CMMCH( TRANSA, 'N', M, N, M,
$ ALPHA, A, NMAX, B, NMAX,
$ ZERO, C, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
ELSE
CALL CMMCH( 'N', TRANSA, M, N, N,
$ ALPHA, B, NMAX, A, NMAX,
$ ZERO, C, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
END IF
ELSE IF( SNAME( 4: 5 ).EQ.'SM' )THEN
*
* Compute approximation to original
* matrix.
*
DO 70 J = 1, N
DO 60 I = 1, M
C( I, J ) = BB( I + ( J - 1 )*
$ LDB )
BB( I + ( J - 1 )*LDB ) = ALPHA*
$ B( I, J )
60 CONTINUE
70 CONTINUE
*
IF( LEFT )THEN
CALL CMMCH( TRANSA, 'N', M, N, M,
$ ONE, A, NMAX, C, NMAX,
$ ZERO, B, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .FALSE. )
ELSE
CALL CMMCH( 'N', TRANSA, M, N, N,
$ ONE, C, NMAX, A, NMAX,
$ ZERO, B, NMAX, CT, G,
$ BB, LDB, EPS, ERR,
$ FATAL, NOUT, .FALSE. )
END IF
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 150
END IF
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
110 CONTINUE
*
120 CONTINUE
*
130 CONTINUE
*
140 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 160
*
150 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
WRITE( NOUT, FMT = 9995 )NC, SNAME, SIDE, UPLO, TRANSA, DIAG, M,
$ N, ALPHA, LDA, LDB
*
160 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( 1X, I6, ': ', A6, '(', 4( '''', A1, ''',' ), 2( I3, ',' ),
$ '(', F4.1, ',', F4.1, '), A,', I3, ', B,', I3, ') ',
$ ' .' )
9994 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of CCHK3.
*
END
SUBROUTINE CCHK4( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ A, AA, AS, B, BB, BS, C, CC, CS, CT, G )
*
* Tests CHERK and CSYRK.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
COMPLEX ZERO
PARAMETER ( ZERO = ( 0.0, 0.0 ) )
REAL RONE, RZERO
PARAMETER ( RONE = 1.0, RZERO = 0.0 )
* .. Scalar Arguments ..
REAL EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
COMPLEX A( NMAX, NMAX ), AA( NMAX*NMAX ), ALF( NALF ),
$ AS( NMAX*NMAX ), B( NMAX, NMAX ),
$ BB( NMAX*NMAX ), BET( NBET ), BS( NMAX*NMAX ),
$ C( NMAX, NMAX ), CC( NMAX*NMAX ),
$ CS( NMAX*NMAX ), CT( NMAX )
REAL G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
COMPLEX ALPHA, ALS, BETA, BETS
REAL ERR, ERRMAX, RALPHA, RALS, RBETA, RBETS
INTEGER I, IA, IB, ICT, ICU, IK, IN, J, JC, JJ, K, KS,
$ LAA, LCC, LDA, LDAS, LDC, LDCS, LJ, MA, N, NA,
$ NARGS, NC, NS
LOGICAL CONJ, NULL, RESET, SAME, TRAN, UPPER
CHARACTER*1 TRANS, TRANSS, TRANST, UPLO, UPLOS
CHARACTER*2 ICHT, ICHU
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LCE, LCERES
EXTERNAL LCE, LCERES
* .. External Subroutines ..
EXTERNAL CHERK, CMAKE, CMMCH, CSYRK
* .. Intrinsic Functions ..
INTRINSIC CMPLX, MAX, REAL
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHT/'NC'/, ICHU/'UL'/
* .. Executable Statements ..
CONJ = SNAME( 2: 3 ).EQ.'HE'
*
NARGS = 10
NC = 0
RESET = .TRUE.
ERRMAX = RZERO
*
DO 100 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = N
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 100
LCC = LDC*N
*
DO 90 IK = 1, NIDIM
K = IDIM( IK )
*
DO 80 ICT = 1, 2
TRANS = ICHT( ICT: ICT )
TRAN = TRANS.EQ.'C'
IF( TRAN.AND..NOT.CONJ )
$ TRANS = 'T'
IF( TRAN )THEN
MA = K
NA = N
ELSE
MA = N
NA = K
END IF
* Set LDA to 1 more than minimum value if room.
LDA = MA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 80
LAA = LDA*NA
*
* Generate the matrix A.
*
CALL CMAKE( 'GE', ' ', ' ', MA, NA, A, NMAX, AA, LDA,
$ RESET, ZERO )
*
DO 70 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
UPPER = UPLO.EQ.'U'
*
DO 60 IA = 1, NALF
ALPHA = ALF( IA )
IF( CONJ )THEN
RALPHA = REAL( ALPHA )
ALPHA = CMPLX( RALPHA, RZERO )
END IF
*
DO 50 IB = 1, NBET
BETA = BET( IB )
IF( CONJ )THEN
RBETA = REAL( BETA )
BETA = CMPLX( RBETA, RZERO )
END IF
NULL = N.LE.0
IF( CONJ )
$ NULL = NULL.OR.( ( K.LE.0.OR.RALPHA.EQ.
$ RZERO ).AND.RBETA.EQ.RONE )
*
* Generate the matrix C.
*
CALL CMAKE( SNAME( 2: 3 ), UPLO, ' ', N, N, C,
$ NMAX, CC, LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the subroutine.
*
UPLOS = UPLO
TRANSS = TRANS
NS = N
KS = K
IF( CONJ )THEN
RALS = RALPHA
ELSE
ALS = ALPHA
END IF
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
IF( CONJ )THEN
RBETS = RBETA
ELSE
BETS = BETA
END IF
DO 20 I = 1, LCC
CS( I ) = CC( I )
20 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( CONJ )THEN
IF( TRACE )
$ WRITE( NTRA, FMT = 9994 )NC, SNAME, UPLO,
$ TRANS, N, K, RALPHA, LDA, RBETA, LDC
IF( REWI )
$ REWIND NTRA
CALL CHERK( UPLO, TRANS, N, K, RALPHA, AA,
$ LDA, RBETA, CC, LDC )
ELSE
IF( TRACE )
$ WRITE( NTRA, FMT = 9993 )NC, SNAME, UPLO,
$ TRANS, N, K, ALPHA, LDA, BETA, LDC
IF( REWI )
$ REWIND NTRA
CALL CSYRK( UPLO, TRANS, N, K, ALPHA, AA,
$ LDA, BETA, CC, LDC )
END IF
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9992 )
FATAL = .TRUE.
GO TO 120
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = UPLOS.EQ.UPLO
ISAME( 2 ) = TRANSS.EQ.TRANS
ISAME( 3 ) = NS.EQ.N
ISAME( 4 ) = KS.EQ.K
IF( CONJ )THEN
ISAME( 5 ) = RALS.EQ.RALPHA
ELSE
ISAME( 5 ) = ALS.EQ.ALPHA
END IF
ISAME( 6 ) = LCE( AS, AA, LAA )
ISAME( 7 ) = LDAS.EQ.LDA
IF( CONJ )THEN
ISAME( 8 ) = RBETS.EQ.RBETA
ELSE
ISAME( 8 ) = BETS.EQ.BETA
END IF
IF( NULL )THEN
ISAME( 9 ) = LCE( CS, CC, LCC )
ELSE
ISAME( 9 ) = LCERES( SNAME( 2: 3 ), UPLO, N,
$ N, CS, CC, LDC )
END IF
ISAME( 10 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 30 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
30 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 120
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result column by column.
*
IF( CONJ )THEN
TRANST = 'C'
ELSE
TRANST = 'T'
END IF
JC = 1
DO 40 J = 1, N
IF( UPPER )THEN
JJ = 1
LJ = J
ELSE
JJ = J
LJ = N - J + 1
END IF
IF( TRAN )THEN
CALL CMMCH( TRANST, 'N', LJ, 1, K,
$ ALPHA, A( 1, JJ ), NMAX,
$ A( 1, J ), NMAX, BETA,
$ C( JJ, J ), NMAX, CT, G,
$ CC( JC ), LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
ELSE
CALL CMMCH( 'N', TRANST, LJ, 1, K,
$ ALPHA, A( JJ, 1 ), NMAX,
$ A( J, 1 ), NMAX, BETA,
$ C( JJ, J ), NMAX, CT, G,
$ CC( JC ), LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
END IF
IF( UPPER )THEN
JC = JC + LDC
ELSE
JC = JC + LDC + 1
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 110
40 CONTINUE
END IF
*
50 CONTINUE
*
60 CONTINUE
*
70 CONTINUE
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 130
*
110 CONTINUE
IF( N.GT.1 )
$ WRITE( NOUT, FMT = 9995 )J
*
120 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
IF( CONJ )THEN
WRITE( NOUT, FMT = 9994 )NC, SNAME, UPLO, TRANS, N, K, RALPHA,
$ LDA, RBETA, LDC
ELSE
WRITE( NOUT, FMT = 9993 )NC, SNAME, UPLO, TRANS, N, K, ALPHA,
$ LDA, BETA, LDC
END IF
*
130 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 )
9994 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ),
$ F4.1, ', A,', I3, ',', F4.1, ', C,', I3, ') ',
$ ' .' )
9993 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ),
$ '(', F4.1, ',', F4.1, ') , A,', I3, ',(', F4.1, ',', F4.1,
$ '), C,', I3, ') .' )
9992 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of CCHK4.
*
END
SUBROUTINE CCHK5( SNAME, EPS, THRESH, NOUT, NTRA, TRACE, REWI,
$ FATAL, NIDIM, IDIM, NALF, ALF, NBET, BET, NMAX,
$ AB, AA, AS, BB, BS, C, CC, CS, CT, G, W )
*
* Tests CHER2K and CSYR2K.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
COMPLEX ZERO, ONE
PARAMETER ( ZERO = ( 0.0, 0.0 ), ONE = ( 1.0, 0.0 ) )
REAL RONE, RZERO
PARAMETER ( RONE = 1.0, RZERO = 0.0 )
* .. Scalar Arguments ..
REAL EPS, THRESH
INTEGER NALF, NBET, NIDIM, NMAX, NOUT, NTRA
LOGICAL FATAL, REWI, TRACE
CHARACTER*6 SNAME
* .. Array Arguments ..
COMPLEX AA( NMAX*NMAX ), AB( 2*NMAX*NMAX ),
$ ALF( NALF ), AS( NMAX*NMAX ), BB( NMAX*NMAX ),
$ BET( NBET ), BS( NMAX*NMAX ), C( NMAX, NMAX ),
$ CC( NMAX*NMAX ), CS( NMAX*NMAX ), CT( NMAX ),
$ W( 2*NMAX )
REAL G( NMAX )
INTEGER IDIM( NIDIM )
* .. Local Scalars ..
COMPLEX ALPHA, ALS, BETA, BETS
REAL ERR, ERRMAX, RBETA, RBETS
INTEGER I, IA, IB, ICT, ICU, IK, IN, J, JC, JJ, JJAB,
$ K, KS, LAA, LBB, LCC, LDA, LDAS, LDB, LDBS,
$ LDC, LDCS, LJ, MA, N, NA, NARGS, NC, NS
LOGICAL CONJ, NULL, RESET, SAME, TRAN, UPPER
CHARACTER*1 TRANS, TRANSS, TRANST, UPLO, UPLOS
CHARACTER*2 ICHT, ICHU
* .. Local Arrays ..
LOGICAL ISAME( 13 )
* .. External Functions ..
LOGICAL LCE, LCERES
EXTERNAL LCE, LCERES
* .. External Subroutines ..
EXTERNAL CHER2K, CMAKE, CMMCH, CSYR2K
* .. Intrinsic Functions ..
INTRINSIC CMPLX, CONJG, MAX, REAL
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Data statements ..
DATA ICHT/'NC'/, ICHU/'UL'/
* .. Executable Statements ..
CONJ = SNAME( 2: 3 ).EQ.'HE'
*
NARGS = 12
NC = 0
RESET = .TRUE.
ERRMAX = RZERO
*
DO 130 IN = 1, NIDIM
N = IDIM( IN )
* Set LDC to 1 more than minimum value if room.
LDC = N
IF( LDC.LT.NMAX )
$ LDC = LDC + 1
* Skip tests if not enough room.
IF( LDC.GT.NMAX )
$ GO TO 130
LCC = LDC*N
*
DO 120 IK = 1, NIDIM
K = IDIM( IK )
*
DO 110 ICT = 1, 2
TRANS = ICHT( ICT: ICT )
TRAN = TRANS.EQ.'C'
IF( TRAN.AND..NOT.CONJ )
$ TRANS = 'T'
IF( TRAN )THEN
MA = K
NA = N
ELSE
MA = N
NA = K
END IF
* Set LDA to 1 more than minimum value if room.
LDA = MA
IF( LDA.LT.NMAX )
$ LDA = LDA + 1
* Skip tests if not enough room.
IF( LDA.GT.NMAX )
$ GO TO 110
LAA = LDA*NA
*
* Generate the matrix A.
*
IF( TRAN )THEN
CALL CMAKE( 'GE', ' ', ' ', MA, NA, AB, 2*NMAX, AA,
$ LDA, RESET, ZERO )
ELSE
CALL CMAKE( 'GE', ' ', ' ', MA, NA, AB, NMAX, AA, LDA,
$ RESET, ZERO )
END IF
*
* Generate the matrix B.
*
LDB = LDA
LBB = LAA
IF( TRAN )THEN
CALL CMAKE( 'GE', ' ', ' ', MA, NA, AB( K + 1 ),
$ 2*NMAX, BB, LDB, RESET, ZERO )
ELSE
CALL CMAKE( 'GE', ' ', ' ', MA, NA, AB( K*NMAX + 1 ),
$ NMAX, BB, LDB, RESET, ZERO )
END IF
*
DO 100 ICU = 1, 2
UPLO = ICHU( ICU: ICU )
UPPER = UPLO.EQ.'U'
*
DO 90 IA = 1, NALF
ALPHA = ALF( IA )
*
DO 80 IB = 1, NBET
BETA = BET( IB )
IF( CONJ )THEN
RBETA = REAL( BETA )
BETA = CMPLX( RBETA, RZERO )
END IF
NULL = N.LE.0
IF( CONJ )
$ NULL = NULL.OR.( ( K.LE.0.OR.ALPHA.EQ.
$ ZERO ).AND.RBETA.EQ.RONE )
*
* Generate the matrix C.
*
CALL CMAKE( SNAME( 2: 3 ), UPLO, ' ', N, N, C,
$ NMAX, CC, LDC, RESET, ZERO )
*
NC = NC + 1
*
* Save every datum before calling the subroutine.
*
UPLOS = UPLO
TRANSS = TRANS
NS = N
KS = K
ALS = ALPHA
DO 10 I = 1, LAA
AS( I ) = AA( I )
10 CONTINUE
LDAS = LDA
DO 20 I = 1, LBB
BS( I ) = BB( I )
20 CONTINUE
LDBS = LDB
IF( CONJ )THEN
RBETS = RBETA
ELSE
BETS = BETA
END IF
DO 30 I = 1, LCC
CS( I ) = CC( I )
30 CONTINUE
LDCS = LDC
*
* Call the subroutine.
*
IF( CONJ )THEN
IF( TRACE )
$ WRITE( NTRA, FMT = 9994 )NC, SNAME, UPLO,
$ TRANS, N, K, ALPHA, LDA, LDB, RBETA, LDC
IF( REWI )
$ REWIND NTRA
CALL CHER2K( UPLO, TRANS, N, K, ALPHA, AA,
$ LDA, BB, LDB, RBETA, CC, LDC )
ELSE
IF( TRACE )
$ WRITE( NTRA, FMT = 9993 )NC, SNAME, UPLO,
$ TRANS, N, K, ALPHA, LDA, LDB, BETA, LDC
IF( REWI )
$ REWIND NTRA
CALL CSYR2K( UPLO, TRANS, N, K, ALPHA, AA,
$ LDA, BB, LDB, BETA, CC, LDC )
END IF
*
* Check if error-exit was taken incorrectly.
*
IF( .NOT.OK )THEN
WRITE( NOUT, FMT = 9992 )
FATAL = .TRUE.
GO TO 150
END IF
*
* See what data changed inside subroutines.
*
ISAME( 1 ) = UPLOS.EQ.UPLO
ISAME( 2 ) = TRANSS.EQ.TRANS
ISAME( 3 ) = NS.EQ.N
ISAME( 4 ) = KS.EQ.K
ISAME( 5 ) = ALS.EQ.ALPHA
ISAME( 6 ) = LCE( AS, AA, LAA )
ISAME( 7 ) = LDAS.EQ.LDA
ISAME( 8 ) = LCE( BS, BB, LBB )
ISAME( 9 ) = LDBS.EQ.LDB
IF( CONJ )THEN
ISAME( 10 ) = RBETS.EQ.RBETA
ELSE
ISAME( 10 ) = BETS.EQ.BETA
END IF
IF( NULL )THEN
ISAME( 11 ) = LCE( CS, CC, LCC )
ELSE
ISAME( 11 ) = LCERES( 'HE', UPLO, N, N, CS,
$ CC, LDC )
END IF
ISAME( 12 ) = LDCS.EQ.LDC
*
* If data was incorrectly changed, report and
* return.
*
SAME = .TRUE.
DO 40 I = 1, NARGS
SAME = SAME.AND.ISAME( I )
IF( .NOT.ISAME( I ) )
$ WRITE( NOUT, FMT = 9998 )I
40 CONTINUE
IF( .NOT.SAME )THEN
FATAL = .TRUE.
GO TO 150
END IF
*
IF( .NOT.NULL )THEN
*
* Check the result column by column.
*
IF( CONJ )THEN
TRANST = 'C'
ELSE
TRANST = 'T'
END IF
JJAB = 1
JC = 1
DO 70 J = 1, N
IF( UPPER )THEN
JJ = 1
LJ = J
ELSE
JJ = J
LJ = N - J + 1
END IF
IF( TRAN )THEN
DO 50 I = 1, K
W( I ) = ALPHA*AB( ( J - 1 )*2*
$ NMAX + K + I )
IF( CONJ )THEN
W( K + I ) = CONJG( ALPHA )*
$ AB( ( J - 1 )*2*
$ NMAX + I )
ELSE
W( K + I ) = ALPHA*
$ AB( ( J - 1 )*2*
$ NMAX + I )
END IF
50 CONTINUE
CALL CMMCH( TRANST, 'N', LJ, 1, 2*K,
$ ONE, AB( JJAB ), 2*NMAX, W,
$ 2*NMAX, BETA, C( JJ, J ),
$ NMAX, CT, G, CC( JC ), LDC,
$ EPS, ERR, FATAL, NOUT,
$ .TRUE. )
ELSE
DO 60 I = 1, K
IF( CONJ )THEN
W( I ) = ALPHA*CONJG( AB( ( K +
$ I - 1 )*NMAX + J ) )
W( K + I ) = CONJG( ALPHA*
$ AB( ( I - 1 )*NMAX +
$ J ) )
ELSE
W( I ) = ALPHA*AB( ( K + I - 1 )*
$ NMAX + J )
W( K + I ) = ALPHA*
$ AB( ( I - 1 )*NMAX +
$ J )
END IF
60 CONTINUE
CALL CMMCH( 'N', 'N', LJ, 1, 2*K, ONE,
$ AB( JJ ), NMAX, W, 2*NMAX,
$ BETA, C( JJ, J ), NMAX, CT,
$ G, CC( JC ), LDC, EPS, ERR,
$ FATAL, NOUT, .TRUE. )
END IF
IF( UPPER )THEN
JC = JC + LDC
ELSE
JC = JC + LDC + 1
IF( TRAN )
$ JJAB = JJAB + 2*NMAX
END IF
ERRMAX = MAX( ERRMAX, ERR )
* If got really bad answer, report and
* return.
IF( FATAL )
$ GO TO 140
70 CONTINUE
END IF
*
80 CONTINUE
*
90 CONTINUE
*
100 CONTINUE
*
110 CONTINUE
*
120 CONTINUE
*
130 CONTINUE
*
* Report result.
*
IF( ERRMAX.LT.THRESH )THEN
WRITE( NOUT, FMT = 9999 )SNAME, NC
ELSE
WRITE( NOUT, FMT = 9997 )SNAME, NC, ERRMAX
END IF
GO TO 160
*
140 CONTINUE
IF( N.GT.1 )
$ WRITE( NOUT, FMT = 9995 )J
*
150 CONTINUE
WRITE( NOUT, FMT = 9996 )SNAME
IF( CONJ )THEN
WRITE( NOUT, FMT = 9994 )NC, SNAME, UPLO, TRANS, N, K, ALPHA,
$ LDA, LDB, RBETA, LDC
ELSE
WRITE( NOUT, FMT = 9993 )NC, SNAME, UPLO, TRANS, N, K, ALPHA,
$ LDA, LDB, BETA, LDC
END IF
*
160 CONTINUE
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE COMPUTATIONAL TESTS (', I6, ' CALL',
$ 'S)' )
9998 FORMAT( ' ******* FATAL ERROR - PARAMETER NUMBER ', I2, ' WAS CH',
$ 'ANGED INCORRECTLY *******' )
9997 FORMAT( ' ', A6, ' COMPLETED THE COMPUTATIONAL TESTS (', I6, ' C',
$ 'ALLS)', /' ******* BUT WITH MAXIMUM TEST RATIO', F8.2,
$ ' - SUSPECT *******' )
9996 FORMAT( ' ******* ', A6, ' FAILED ON CALL NUMBER:' )
9995 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 )
9994 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ),
$ '(', F4.1, ',', F4.1, '), A,', I3, ', B,', I3, ',', F4.1,
$ ', C,', I3, ') .' )
9993 FORMAT( 1X, I6, ': ', A6, '(', 2( '''', A1, ''',' ), 2( I3, ',' ),
$ '(', F4.1, ',', F4.1, '), A,', I3, ', B,', I3, ',(', F4.1,
$ ',', F4.1, '), C,', I3, ') .' )
9992 FORMAT( ' ******* FATAL ERROR - ERROR-EXIT TAKEN ON VALID CALL *',
$ '******' )
*
* End of CCHK5.
*
END
SUBROUTINE CCHKE( ISNUM, SRNAMT, NOUT )
*
* Tests the error exits from the Level 3 Blas.
* Requires a special version of the error-handling routine XERBLA.
* ALPHA, RALPHA, BETA, RBETA, A, B and C should not need to be defined.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER ISNUM, NOUT
CHARACTER*6 SRNAMT
* .. Scalars in Common ..
INTEGER INFOT, NOUTC
LOGICAL LERR, OK
* .. Local Scalars ..
COMPLEX ALPHA, BETA
REAL RALPHA, RBETA
* .. Local Arrays ..
COMPLEX A( 2, 1 ), B( 2, 1 ), C( 2, 1 )
* .. External Subroutines ..
EXTERNAL CGEMM, CHEMM, CHER2K, CHERK, CHKXER, CSYMM,
$ CSYR2K, CSYRK, CTRMM, CTRSM
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUTC, OK, LERR
* .. Executable Statements ..
* OK is set to .FALSE. by the special version of XERBLA or by CHKXER
* if anything is wrong.
OK = .TRUE.
* LERR is set to .TRUE. by the special version of XERBLA each time
* it is called, and is then tested and re-set by CHKXER.
LERR = .FALSE.
GO TO ( 10, 20, 30, 40, 50, 60, 70, 80,
$ 90 )ISNUM
10 INFOT = 1
CALL CGEMM( '/', 'N', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 1
CALL CGEMM( '/', 'C', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 1
CALL CGEMM( '/', 'T', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL CGEMM( 'N', '/', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL CGEMM( 'C', '/', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL CGEMM( 'T', '/', 0, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CGEMM( 'N', 'N', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CGEMM( 'N', 'C', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CGEMM( 'N', 'T', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CGEMM( 'C', 'N', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CGEMM( 'C', 'C', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CGEMM( 'C', 'T', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CGEMM( 'T', 'N', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CGEMM( 'T', 'C', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CGEMM( 'T', 'T', -1, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CGEMM( 'N', 'N', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CGEMM( 'N', 'C', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CGEMM( 'N', 'T', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CGEMM( 'C', 'N', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CGEMM( 'C', 'C', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CGEMM( 'C', 'T', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CGEMM( 'T', 'N', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CGEMM( 'T', 'C', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CGEMM( 'T', 'T', 0, -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CGEMM( 'N', 'N', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CGEMM( 'N', 'C', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CGEMM( 'N', 'T', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CGEMM( 'C', 'N', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CGEMM( 'C', 'C', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CGEMM( 'C', 'T', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CGEMM( 'T', 'N', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CGEMM( 'T', 'C', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CGEMM( 'T', 'T', 0, 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL CGEMM( 'N', 'N', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL CGEMM( 'N', 'C', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL CGEMM( 'N', 'T', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL CGEMM( 'C', 'N', 0, 0, 2, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL CGEMM( 'C', 'C', 0, 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL CGEMM( 'C', 'T', 0, 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL CGEMM( 'T', 'N', 0, 0, 2, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL CGEMM( 'T', 'C', 0, 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 8
CALL CGEMM( 'T', 'T', 0, 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CGEMM( 'N', 'N', 0, 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CGEMM( 'C', 'N', 0, 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CGEMM( 'T', 'N', 0, 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CGEMM( 'N', 'C', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CGEMM( 'C', 'C', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CGEMM( 'T', 'C', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CGEMM( 'N', 'T', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CGEMM( 'C', 'T', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CGEMM( 'T', 'T', 0, 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL CGEMM( 'N', 'N', 2, 0, 0, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL CGEMM( 'N', 'C', 2, 0, 0, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL CGEMM( 'N', 'T', 2, 0, 0, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL CGEMM( 'C', 'N', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL CGEMM( 'C', 'C', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL CGEMM( 'C', 'T', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL CGEMM( 'T', 'N', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL CGEMM( 'T', 'C', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 13
CALL CGEMM( 'T', 'T', 2, 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 100
20 INFOT = 1
CALL CHEMM( '/', 'U', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL CHEMM( 'L', '/', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHEMM( 'L', 'U', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHEMM( 'R', 'U', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHEMM( 'L', 'L', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHEMM( 'R', 'L', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHEMM( 'L', 'U', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHEMM( 'R', 'U', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHEMM( 'L', 'L', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHEMM( 'R', 'L', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHEMM( 'L', 'U', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHEMM( 'R', 'U', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHEMM( 'L', 'L', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHEMM( 'R', 'L', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CHEMM( 'L', 'U', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CHEMM( 'R', 'U', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CHEMM( 'L', 'L', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CHEMM( 'R', 'L', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CHEMM( 'L', 'U', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CHEMM( 'R', 'U', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CHEMM( 'L', 'L', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CHEMM( 'R', 'L', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 100
30 INFOT = 1
CALL CSYMM( '/', 'U', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL CSYMM( 'L', '/', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYMM( 'L', 'U', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYMM( 'R', 'U', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYMM( 'L', 'L', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYMM( 'R', 'L', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYMM( 'L', 'U', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYMM( 'R', 'U', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYMM( 'L', 'L', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYMM( 'R', 'L', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYMM( 'L', 'U', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYMM( 'R', 'U', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYMM( 'L', 'L', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYMM( 'R', 'L', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CSYMM( 'L', 'U', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CSYMM( 'R', 'U', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CSYMM( 'L', 'L', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CSYMM( 'R', 'L', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CSYMM( 'L', 'U', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CSYMM( 'R', 'U', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CSYMM( 'L', 'L', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CSYMM( 'R', 'L', 2, 0, ALPHA, A, 1, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 100
40 INFOT = 1
CALL CTRMM( '/', 'U', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL CTRMM( 'L', '/', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CTRMM( 'L', 'U', '/', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CTRMM( 'L', 'U', 'N', '/', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'L', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'L', 'U', 'C', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'L', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'R', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'R', 'U', 'C', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'R', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'L', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'L', 'L', 'C', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'L', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'R', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'R', 'L', 'C', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRMM( 'R', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'L', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'L', 'U', 'C', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'L', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'R', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'R', 'U', 'C', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'R', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'L', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'L', 'L', 'C', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'L', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'R', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'R', 'L', 'C', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRMM( 'R', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'L', 'U', 'C', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'R', 'U', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'R', 'U', 'C', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'R', 'U', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'L', 'L', 'C', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'R', 'L', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'R', 'L', 'C', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRMM( 'R', 'L', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'L', 'U', 'C', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'R', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'R', 'U', 'C', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'R', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'L', 'L', 'C', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'R', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'R', 'L', 'C', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRMM( 'R', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 100
50 INFOT = 1
CALL CTRSM( '/', 'U', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL CTRSM( 'L', '/', 'N', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CTRSM( 'L', 'U', '/', 'N', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CTRSM( 'L', 'U', 'N', '/', 0, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'L', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'L', 'U', 'C', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'L', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'R', 'U', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'R', 'U', 'C', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'R', 'U', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'L', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'L', 'L', 'C', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'L', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'R', 'L', 'N', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'R', 'L', 'C', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 5
CALL CTRSM( 'R', 'L', 'T', 'N', -1, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'L', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'L', 'U', 'C', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'L', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'R', 'U', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'R', 'U', 'C', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'R', 'U', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'L', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'L', 'L', 'C', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'L', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'R', 'L', 'N', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'R', 'L', 'C', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 6
CALL CTRSM( 'R', 'L', 'T', 'N', 0, -1, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'L', 'U', 'C', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'R', 'U', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'R', 'U', 'C', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'R', 'U', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'L', 'L', 'C', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'R', 'L', 'N', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'R', 'L', 'C', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CTRSM( 'R', 'L', 'T', 'N', 0, 2, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'L', 'U', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'L', 'U', 'C', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'L', 'U', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'R', 'U', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'R', 'U', 'C', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'R', 'U', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'L', 'L', 'N', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'L', 'L', 'C', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'L', 'L', 'T', 'N', 2, 0, ALPHA, A, 2, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'R', 'L', 'N', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'R', 'L', 'C', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 11
CALL CTRSM( 'R', 'L', 'T', 'N', 2, 0, ALPHA, A, 1, B, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 100
60 INFOT = 1
CALL CHERK( '/', 'N', 0, 0, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL CHERK( 'U', 'T', 0, 0, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHERK( 'U', 'N', -1, 0, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHERK( 'U', 'C', -1, 0, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHERK( 'L', 'N', -1, 0, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHERK( 'L', 'C', -1, 0, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHERK( 'U', 'N', 0, -1, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHERK( 'U', 'C', 0, -1, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHERK( 'L', 'N', 0, -1, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHERK( 'L', 'C', 0, -1, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHERK( 'U', 'N', 2, 0, RALPHA, A, 1, RBETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHERK( 'U', 'C', 0, 2, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHERK( 'L', 'N', 2, 0, RALPHA, A, 1, RBETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHERK( 'L', 'C', 0, 2, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CHERK( 'U', 'N', 2, 0, RALPHA, A, 2, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CHERK( 'U', 'C', 2, 0, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CHERK( 'L', 'N', 2, 0, RALPHA, A, 2, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CHERK( 'L', 'C', 2, 0, RALPHA, A, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 100
70 INFOT = 1
CALL CSYRK( '/', 'N', 0, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL CSYRK( 'U', 'C', 0, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYRK( 'U', 'N', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYRK( 'U', 'T', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYRK( 'L', 'N', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYRK( 'L', 'T', -1, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYRK( 'U', 'N', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYRK( 'U', 'T', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYRK( 'L', 'N', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYRK( 'L', 'T', 0, -1, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYRK( 'U', 'N', 2, 0, ALPHA, A, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYRK( 'U', 'T', 0, 2, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYRK( 'L', 'N', 2, 0, ALPHA, A, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYRK( 'L', 'T', 0, 2, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CSYRK( 'U', 'N', 2, 0, ALPHA, A, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CSYRK( 'U', 'T', 2, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CSYRK( 'L', 'N', 2, 0, ALPHA, A, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 10
CALL CSYRK( 'L', 'T', 2, 0, ALPHA, A, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 100
80 INFOT = 1
CALL CHER2K( '/', 'N', 0, 0, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL CHER2K( 'U', 'T', 0, 0, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHER2K( 'U', 'N', -1, 0, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHER2K( 'U', 'C', -1, 0, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHER2K( 'L', 'N', -1, 0, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CHER2K( 'L', 'C', -1, 0, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHER2K( 'U', 'N', 0, -1, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHER2K( 'U', 'C', 0, -1, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHER2K( 'L', 'N', 0, -1, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CHER2K( 'L', 'C', 0, -1, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHER2K( 'U', 'N', 2, 0, ALPHA, A, 1, B, 1, RBETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHER2K( 'U', 'C', 0, 2, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHER2K( 'L', 'N', 2, 0, ALPHA, A, 1, B, 1, RBETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CHER2K( 'L', 'C', 0, 2, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CHER2K( 'U', 'N', 2, 0, ALPHA, A, 2, B, 1, RBETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CHER2K( 'U', 'C', 0, 2, ALPHA, A, 2, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CHER2K( 'L', 'N', 2, 0, ALPHA, A, 2, B, 1, RBETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CHER2K( 'L', 'C', 0, 2, ALPHA, A, 2, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CHER2K( 'U', 'N', 2, 0, ALPHA, A, 2, B, 2, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CHER2K( 'U', 'C', 2, 0, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CHER2K( 'L', 'N', 2, 0, ALPHA, A, 2, B, 2, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CHER2K( 'L', 'C', 2, 0, ALPHA, A, 1, B, 1, RBETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
GO TO 100
90 INFOT = 1
CALL CSYR2K( '/', 'N', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 2
CALL CSYR2K( 'U', 'C', 0, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYR2K( 'U', 'N', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYR2K( 'U', 'T', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYR2K( 'L', 'N', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 3
CALL CSYR2K( 'L', 'T', -1, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYR2K( 'U', 'N', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYR2K( 'U', 'T', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYR2K( 'L', 'N', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 4
CALL CSYR2K( 'L', 'T', 0, -1, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYR2K( 'U', 'N', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYR2K( 'U', 'T', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYR2K( 'L', 'N', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 7
CALL CSYR2K( 'L', 'T', 0, 2, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CSYR2K( 'U', 'N', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CSYR2K( 'U', 'T', 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CSYR2K( 'L', 'N', 2, 0, ALPHA, A, 2, B, 1, BETA, C, 2 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 9
CALL CSYR2K( 'L', 'T', 0, 2, ALPHA, A, 2, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CSYR2K( 'U', 'N', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CSYR2K( 'U', 'T', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CSYR2K( 'L', 'N', 2, 0, ALPHA, A, 2, B, 2, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
INFOT = 12
CALL CSYR2K( 'L', 'T', 2, 0, ALPHA, A, 1, B, 1, BETA, C, 1 )
CALL CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
*
100 IF( OK )THEN
WRITE( NOUT, FMT = 9999 )SRNAMT
ELSE
WRITE( NOUT, FMT = 9998 )SRNAMT
END IF
RETURN
*
9999 FORMAT( ' ', A6, ' PASSED THE TESTS OF ERROR-EXITS' )
9998 FORMAT( ' ******* ', A6, ' FAILED THE TESTS OF ERROR-EXITS *****',
$ '**' )
*
* End of CCHKE.
*
END
SUBROUTINE CMAKE( TYPE, UPLO, DIAG, M, N, A, NMAX, AA, LDA, RESET,
$ TRANSL )
*
* Generates values for an M by N matrix A.
* Stores the values in the array AA in the data structure required
* by the routine, with unwanted elements set to rogue value.
*
* TYPE is 'GE', 'HE', 'SY' or 'TR'.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
COMPLEX ZERO, ONE
PARAMETER ( ZERO = ( 0.0, 0.0 ), ONE = ( 1.0, 0.0 ) )
COMPLEX ROGUE
PARAMETER ( ROGUE = ( -1.0E10, 1.0E10 ) )
REAL RZERO
PARAMETER ( RZERO = 0.0 )
REAL RROGUE
PARAMETER ( RROGUE = -1.0E10 )
* .. Scalar Arguments ..
COMPLEX TRANSL
INTEGER LDA, M, N, NMAX
LOGICAL RESET
CHARACTER*1 DIAG, UPLO
CHARACTER*2 TYPE
* .. Array Arguments ..
COMPLEX A( NMAX, * ), AA( * )
* .. Local Scalars ..
INTEGER I, IBEG, IEND, J, JJ
LOGICAL GEN, HER, LOWER, SYM, TRI, UNIT, UPPER
* .. External Functions ..
COMPLEX CBEG
EXTERNAL CBEG
* .. Intrinsic Functions ..
INTRINSIC CMPLX, CONJG, REAL
* .. Executable Statements ..
GEN = TYPE.EQ.'GE'
HER = TYPE.EQ.'HE'
SYM = TYPE.EQ.'SY'
TRI = TYPE.EQ.'TR'
UPPER = ( HER.OR.SYM.OR.TRI ).AND.UPLO.EQ.'U'
LOWER = ( HER.OR.SYM.OR.TRI ).AND.UPLO.EQ.'L'
UNIT = TRI.AND.DIAG.EQ.'U'
*
* Generate data in array A.
*
DO 20 J = 1, N
DO 10 I = 1, M
IF( GEN.OR.( UPPER.AND.I.LE.J ).OR.( LOWER.AND.I.GE.J ) )
$ THEN
A( I, J ) = CBEG( RESET ) + TRANSL
IF( I.NE.J )THEN
* Set some elements to zero
IF( N.GT.3.AND.J.EQ.N/2 )
$ A( I, J ) = ZERO
IF( HER )THEN
A( J, I ) = CONJG( A( I, J ) )
ELSE IF( SYM )THEN
A( J, I ) = A( I, J )
ELSE IF( TRI )THEN
A( J, I ) = ZERO
END IF
END IF
END IF
10 CONTINUE
IF( HER )
$ A( J, J ) = CMPLX( REAL( A( J, J ) ), RZERO )
IF( TRI )
$ A( J, J ) = A( J, J ) + ONE
IF( UNIT )
$ A( J, J ) = ONE
20 CONTINUE
*
* Store elements in array AS in data structure required by routine.
*
IF( TYPE.EQ.'GE' )THEN
DO 50 J = 1, N
DO 30 I = 1, M
AA( I + ( J - 1 )*LDA ) = A( I, J )
30 CONTINUE
DO 40 I = M + 1, LDA
AA( I + ( J - 1 )*LDA ) = ROGUE
40 CONTINUE
50 CONTINUE
ELSE IF( TYPE.EQ.'HE'.OR.TYPE.EQ.'SY'.OR.TYPE.EQ.'TR' )THEN
DO 90 J = 1, N
IF( UPPER )THEN
IBEG = 1
IF( UNIT )THEN
IEND = J - 1
ELSE
IEND = J
END IF
ELSE
IF( UNIT )THEN
IBEG = J + 1
ELSE
IBEG = J
END IF
IEND = N
END IF
DO 60 I = 1, IBEG - 1
AA( I + ( J - 1 )*LDA ) = ROGUE
60 CONTINUE
DO 70 I = IBEG, IEND
AA( I + ( J - 1 )*LDA ) = A( I, J )
70 CONTINUE
DO 80 I = IEND + 1, LDA
AA( I + ( J - 1 )*LDA ) = ROGUE
80 CONTINUE
IF( HER )THEN
JJ = J + ( J - 1 )*LDA
AA( JJ ) = CMPLX( REAL( AA( JJ ) ), RROGUE )
END IF
90 CONTINUE
END IF
RETURN
*
* End of CMAKE.
*
END
SUBROUTINE CMMCH( TRANSA, TRANSB, M, N, KK, ALPHA, A, LDA, B, LDB,
$ BETA, C, LDC, CT, G, CC, LDCC, EPS, ERR, FATAL,
$ NOUT, MV )
*
* Checks the results of the computational tests.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Parameters ..
COMPLEX ZERO
PARAMETER ( ZERO = ( 0.0, 0.0 ) )
REAL RZERO, RONE
PARAMETER ( RZERO = 0.0, RONE = 1.0 )
* .. Scalar Arguments ..
COMPLEX ALPHA, BETA
REAL EPS, ERR
INTEGER KK, LDA, LDB, LDC, LDCC, M, N, NOUT
LOGICAL FATAL, MV
CHARACTER*1 TRANSA, TRANSB
* .. Array Arguments ..
COMPLEX A( LDA, * ), B( LDB, * ), C( LDC, * ),
$ CC( LDCC, * ), CT( * )
REAL G( * )
* .. Local Scalars ..
COMPLEX CL
REAL ERRI
INTEGER I, J, K
LOGICAL CTRANA, CTRANB, TRANA, TRANB
* .. Intrinsic Functions ..
INTRINSIC ABS, AIMAG, CONJG, MAX, REAL, SQRT
* .. Statement Functions ..
REAL ABS1
* .. Statement Function definitions ..
ABS1( CL ) = ABS( REAL( CL ) ) + ABS( AIMAG( CL ) )
* .. Executable Statements ..
TRANA = TRANSA.EQ.'T'.OR.TRANSA.EQ.'C'
TRANB = TRANSB.EQ.'T'.OR.TRANSB.EQ.'C'
CTRANA = TRANSA.EQ.'C'
CTRANB = TRANSB.EQ.'C'
*
* Compute expected result, one column at a time, in CT using data
* in A, B and C.
* Compute gauges in G.
*
DO 220 J = 1, N
*
DO 10 I = 1, M
CT( I ) = ZERO
G( I ) = RZERO
10 CONTINUE
IF( .NOT.TRANA.AND..NOT.TRANB )THEN
DO 30 K = 1, KK
DO 20 I = 1, M
CT( I ) = CT( I ) + A( I, K )*B( K, J )
G( I ) = G( I ) + ABS1( A( I, K ) )*ABS1( B( K, J ) )
20 CONTINUE
30 CONTINUE
ELSE IF( TRANA.AND..NOT.TRANB )THEN
IF( CTRANA )THEN
DO 50 K = 1, KK
DO 40 I = 1, M
CT( I ) = CT( I ) + CONJG( A( K, I ) )*B( K, J )
G( I ) = G( I ) + ABS1( A( K, I ) )*
$ ABS1( B( K, J ) )
40 CONTINUE
50 CONTINUE
ELSE
DO 70 K = 1, KK
DO 60 I = 1, M
CT( I ) = CT( I ) + A( K, I )*B( K, J )
G( I ) = G( I ) + ABS1( A( K, I ) )*
$ ABS1( B( K, J ) )
60 CONTINUE
70 CONTINUE
END IF
ELSE IF( .NOT.TRANA.AND.TRANB )THEN
IF( CTRANB )THEN
DO 90 K = 1, KK
DO 80 I = 1, M
CT( I ) = CT( I ) + A( I, K )*CONJG( B( J, K ) )
G( I ) = G( I ) + ABS1( A( I, K ) )*
$ ABS1( B( J, K ) )
80 CONTINUE
90 CONTINUE
ELSE
DO 110 K = 1, KK
DO 100 I = 1, M
CT( I ) = CT( I ) + A( I, K )*B( J, K )
G( I ) = G( I ) + ABS1( A( I, K ) )*
$ ABS1( B( J, K ) )
100 CONTINUE
110 CONTINUE
END IF
ELSE IF( TRANA.AND.TRANB )THEN
IF( CTRANA )THEN
IF( CTRANB )THEN
DO 130 K = 1, KK
DO 120 I = 1, M
CT( I ) = CT( I ) + CONJG( A( K, I ) )*
$ CONJG( B( J, K ) )
G( I ) = G( I ) + ABS1( A( K, I ) )*
$ ABS1( B( J, K ) )
120 CONTINUE
130 CONTINUE
ELSE
DO 150 K = 1, KK
DO 140 I = 1, M
CT( I ) = CT( I ) + CONJG( A( K, I ) )*B( J, K )
G( I ) = G( I ) + ABS1( A( K, I ) )*
$ ABS1( B( J, K ) )
140 CONTINUE
150 CONTINUE
END IF
ELSE
IF( CTRANB )THEN
DO 170 K = 1, KK
DO 160 I = 1, M
CT( I ) = CT( I ) + A( K, I )*CONJG( B( J, K ) )
G( I ) = G( I ) + ABS1( A( K, I ) )*
$ ABS1( B( J, K ) )
160 CONTINUE
170 CONTINUE
ELSE
DO 190 K = 1, KK
DO 180 I = 1, M
CT( I ) = CT( I ) + A( K, I )*B( J, K )
G( I ) = G( I ) + ABS1( A( K, I ) )*
$ ABS1( B( J, K ) )
180 CONTINUE
190 CONTINUE
END IF
END IF
END IF
DO 200 I = 1, M
CT( I ) = ALPHA*CT( I ) + BETA*C( I, J )
G( I ) = ABS1( ALPHA )*G( I ) +
$ ABS1( BETA )*ABS1( C( I, J ) )
200 CONTINUE
*
* Compute the error ratio for this result.
*
ERR = ZERO
DO 210 I = 1, M
ERRI = ABS1( CT( I ) - CC( I, J ) )/EPS
IF( G( I ).NE.RZERO )
$ ERRI = ERRI/G( I )
ERR = MAX( ERR, ERRI )
IF( ERR*SQRT( EPS ).GE.RONE )
$ GO TO 230
210 CONTINUE
*
220 CONTINUE
*
* If the loop completes, all results are at least half accurate.
GO TO 250
*
* Report fatal error.
*
230 FATAL = .TRUE.
WRITE( NOUT, FMT = 9999 )
DO 240 I = 1, M
IF( MV )THEN
WRITE( NOUT, FMT = 9998 )I, CT( I ), CC( I, J )
ELSE
WRITE( NOUT, FMT = 9998 )I, CC( I, J ), CT( I )
END IF
240 CONTINUE
IF( N.GT.1 )
$ WRITE( NOUT, FMT = 9997 )J
*
250 CONTINUE
RETURN
*
9999 FORMAT( ' ******* FATAL ERROR - COMPUTED RESULT IS LESS THAN HAL',
$ 'F ACCURATE *******', /' EXPECTED RE',
$ 'SULT COMPUTED RESULT' )
9998 FORMAT( 1X, I7, 2( ' (', G15.6, ',', G15.6, ')' ) )
9997 FORMAT( ' THESE ARE THE RESULTS FOR COLUMN ', I3 )
*
* End of CMMCH.
*
END
LOGICAL FUNCTION LCE( RI, RJ, LR )
*
* Tests if two arrays are identical.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER LR
* .. Array Arguments ..
COMPLEX RI( * ), RJ( * )
* .. Local Scalars ..
INTEGER I
* .. Executable Statements ..
DO 10 I = 1, LR
IF( RI( I ).NE.RJ( I ) )
$ GO TO 20
10 CONTINUE
LCE = .TRUE.
GO TO 30
20 CONTINUE
LCE = .FALSE.
30 RETURN
*
* End of LCE.
*
END
LOGICAL FUNCTION LCERES( TYPE, UPLO, M, N, AA, AS, LDA )
*
* Tests if selected elements in two arrays are equal.
*
* TYPE is 'GE' or 'HE' or 'SY'.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER LDA, M, N
CHARACTER*1 UPLO
CHARACTER*2 TYPE
* .. Array Arguments ..
COMPLEX AA( LDA, * ), AS( LDA, * )
* .. Local Scalars ..
INTEGER I, IBEG, IEND, J
LOGICAL UPPER
* .. Executable Statements ..
UPPER = UPLO.EQ.'U'
IF( TYPE.EQ.'GE' )THEN
DO 20 J = 1, N
DO 10 I = M + 1, LDA
IF( AA( I, J ).NE.AS( I, J ) )
$ GO TO 70
10 CONTINUE
20 CONTINUE
ELSE IF( TYPE.EQ.'HE'.OR.TYPE.EQ.'SY' )THEN
DO 50 J = 1, N
IF( UPPER )THEN
IBEG = 1
IEND = J
ELSE
IBEG = J
IEND = N
END IF
DO 30 I = 1, IBEG - 1
IF( AA( I, J ).NE.AS( I, J ) )
$ GO TO 70
30 CONTINUE
DO 40 I = IEND + 1, LDA
IF( AA( I, J ).NE.AS( I, J ) )
$ GO TO 70
40 CONTINUE
50 CONTINUE
END IF
*
60 CONTINUE
LCERES = .TRUE.
GO TO 80
70 CONTINUE
LCERES = .FALSE.
80 RETURN
*
* End of LCERES.
*
END
COMPLEX FUNCTION CBEG( RESET )
*
* Generates complex numbers as pairs of random numbers uniformly
* distributed between -0.5 and 0.5.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
LOGICAL RESET
* .. Local Scalars ..
INTEGER I, IC, J, MI, MJ
* .. Save statement ..
SAVE I, IC, J, MI, MJ
* .. Intrinsic Functions ..
INTRINSIC CMPLX
* .. Executable Statements ..
IF( RESET )THEN
* Initialize local variables.
MI = 891
MJ = 457
I = 7
J = 7
IC = 0
RESET = .FALSE.
END IF
*
* The sequence of values of I or J is bounded between 1 and 999.
* If initial I or J = 1,2,3,6,7 or 9, the period will be 50.
* If initial I or J = 4 or 8, the period will be 25.
* If initial I or J = 5, the period will be 10.
* IC is used to break up the period by skipping 1 value of I or J
* in 6.
*
IC = IC + 1
10 I = I*MI
J = J*MJ
I = I - 1000*( I/1000 )
J = J - 1000*( J/1000 )
IF( IC.GE.5 )THEN
IC = 0
GO TO 10
END IF
CBEG = CMPLX( ( I - 500 )/1001.0, ( J - 500 )/1001.0 )
RETURN
*
* End of CBEG.
*
END
REAL FUNCTION SDIFF( X, Y )
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
REAL X, Y
* .. Executable Statements ..
SDIFF = X - Y
RETURN
*
* End of SDIFF.
*
END
SUBROUTINE CHKXER( SRNAMT, INFOT, NOUT, LERR, OK )
*
* Tests whether XERBLA has detected an error when it should.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER INFOT, NOUT
LOGICAL LERR, OK
CHARACTER*6 SRNAMT
* .. Executable Statements ..
IF( .NOT.LERR )THEN
WRITE( NOUT, FMT = 9999 )INFOT, SRNAMT
OK = .FALSE.
END IF
LERR = .FALSE.
RETURN
*
9999 FORMAT( ' ***** ILLEGAL VALUE OF PARAMETER NUMBER ', I2, ' NOT D',
$ 'ETECTED BY ', A6, ' *****' )
*
* End of CHKXER.
*
END
SUBROUTINE XERBLA( SRNAME, INFO )
*
* This is a special version of XERBLA to be used only as part of
* the test program for testing error exits from the Level 3 BLAS
* routines.
*
* XERBLA is an error handler for the Level 3 BLAS routines.
*
* It is called by the Level 3 BLAS routines if an input parameter is
* invalid.
*
* Auxiliary routine for test program for Level 3 Blas.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* .. Scalar Arguments ..
INTEGER INFO
CHARACTER*6 SRNAME
* .. Scalars in Common ..
INTEGER INFOT, NOUT
LOGICAL LERR, OK
CHARACTER*6 SRNAMT
* .. Common blocks ..
COMMON /INFOC/INFOT, NOUT, OK, LERR
COMMON /SRNAMC/SRNAMT
* .. Executable Statements ..
LERR = .TRUE.
IF( INFO.NE.INFOT )THEN
IF( INFOT.NE.0 )THEN
WRITE( NOUT, FMT = 9999 )INFO, INFOT
ELSE
WRITE( NOUT, FMT = 9997 )INFO
END IF
OK = .FALSE.
END IF
IF( SRNAME.NE.SRNAMT )THEN
WRITE( NOUT, FMT = 9998 )SRNAME, SRNAMT
OK = .FALSE.
END IF
RETURN
*
9999 FORMAT( ' ******* XERBLA WAS CALLED WITH INFO = ', I6, ' INSTEAD',
$ ' OF ', I2, ' *******' )
9998 FORMAT( ' ******* XERBLA WAS CALLED WITH SRNAME = ', A6, ' INSTE',
$ 'AD OF ', A6, ' *******' )
9997 FORMAT( ' ******* XERBLA WAS CALLED WITH INFO = ', I6,
$ ' *******' )
*
* End of XERBLA
*
END
| mit |
mtrbean/scipy | scipy/linalg/src/id_dist/src/idzp_rid.f | 133 | 10131 | c this file contains the following user-callable routines:
c
c
c routine idzp_rid computes the ID, to a specified precision,
c of a matrix specified by a routine for applying its adjoint
c to arbitrary vectors. This routine is randomized.
c
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c
c
c
subroutine idzp_rid(lproj,eps,m,n,matveca,p1,p2,p3,p4,
1 krank,list,proj,ier)
c
c computes the ID of a, i.e., lists in list the indices
c of krank columns of a such that
c
c a(j,list(k)) = a(j,list(k))
c
c for all j = 1, ..., m; k = 1, ..., krank, and
c
c krank
c a(j,list(k)) = Sigma a(j,list(l)) * proj(l,k-krank) (*)
c l=1
c
c + epsilon(j,k-krank)
c
c for all j = 1, ..., m; k = krank+1, ..., n,
c
c for some matrix epsilon dimensioned epsilon(m,n-krank)
c such that the greatest singular value of epsilon
c <= the greatest singular value of a * eps.
c
c input:
c lproj -- maximum usable length (in complex*16 elements)
c of the array proj
c eps -- precision to which the ID is to be computed
c m -- first dimension of a
c n -- second dimension of a
c matveca -- routine which applies the adjoint
c of the matrix to be ID'd to an arbitrary vector;
c this routine must have a calling sequence
c of the form
c
c matveca(m,x,n,y,p1,p2,p3,p4),
c
c where m is the length of x,
c x is the vector to which the adjoint
c of the matrix is to be applied,
c n is the length of y,
c y is the product of the adjoint of the matrix and x,
c and p1, p2, p3, and p4 are user-specified parameters
c p1 -- parameter to be passed to routine matveca
c p2 -- parameter to be passed to routine matveca
c p3 -- parameter to be passed to routine matveca
c p4 -- parameter to be passed to routine matveca
c
c output:
c krank -- numerical rank
c list -- indices of the columns in the ID
c proj -- matrix of coefficients needed to interpolate
c from the selected columns to the other columns
c in the original matrix being ID'd;
c the present routine uses proj as a work array, too, so
c proj must be at least m+1 + 2*n*(krank+1) complex*16
c elements long, where krank is the rank output
c by the present routine
c ier -- 0 when the routine terminates successfully;
c -1000 when lproj is too small
c
c _N.B._: The algorithm used by this routine is randomized.
c proj must be at least m+1 + 2*n*(krank+1) complex*16
c elements long, where krank is the rank output
c by the present routine.
c
c reference:
c Halko, Martinsson, Tropp, "Finding structure with randomness:
c probabilistic algorithms for constructing approximate
c matrix decompositions," SIAM Review, 53 (2): 217-288,
c 2011.
c
implicit none
integer m,n,list(n),krank,lw,iwork,lwork,ira,kranki,lproj,
1 lra,ier,k
real*8 eps
complex*16 p1,p2,p3,p4,proj(*)
external matveca
c
c
ier = 0
c
c
c Allocate memory in proj.
c
lw = 0
c
iwork = lw+1
lwork = m+2*n+1
lw = lw+lwork
c
ira = lw+1
c
c
c Find the rank of a.
c
lra = lproj-lwork
call idz_findrank(lra,eps,m,n,matveca,p1,p2,p3,p4,
1 kranki,proj(ira),ier,proj(iwork))
if(ier .ne. 0) return
c
c
if(lproj .lt. lwork+2*kranki*n) then
ier = -1000
return
endif
c
c
c Take the adjoint of ra.
c
call idz_adjointer(n,kranki,proj(ira),proj(ira+kranki*n))
c
c
c Move the adjoint thus obtained to the beginning of proj.
c
do k = 1,kranki*n
proj(k) = proj(ira+kranki*n+k-1)
enddo ! k
c
c
c ID the adjoint.
c
call idzp_id(eps,kranki,n,proj,krank,list,proj(1+kranki*n))
c
c
return
end
c
c
c
c
subroutine idz_findrank(lra,eps,m,n,matveca,p1,p2,p3,p4,
1 krank,ra,ier,w)
c
c estimates the numerical rank krank of a matrix a to precision
c eps, where the routine matveca applies the adjoint of a
c to an arbitrary vector. This routine applies the adjoint of a
c to krank random vectors, and returns the resulting vectors
c as the columns of ra.
c
c input:
c lra -- maximum usable length (in complex*16 elements)
c of array ra
c eps -- precision defining the numerical rank
c m -- first dimension of a
c n -- second dimension of a
c matveca -- routine which applies the adjoint
c of the matrix whose rank is to be estimated
c to an arbitrary vector; this routine must have
c a calling sequence of the form
c
c matveca(m,x,n,y,p1,p2,p3,p4),
c
c where m is the length of x,
c x is the vector to which the adjoint
c of the matrix is to be applied,
c n is the length of y,
c y is the product of the adjoint of the matrix and x,
c and p1, p2, p3, and p4 are user-specified parameters
c p1 -- parameter to be passed to routine matveca
c p2 -- parameter to be passed to routine matveca
c p3 -- parameter to be passed to routine matveca
c p4 -- parameter to be passed to routine matveca
c
c output:
c krank -- estimate of the numerical rank of a
c ra -- product of the adjoint of a and a matrix whose entries
c are pseudorandom realizations of i.i.d. random numbers,
c uniformly distributed on [0,1];
c ra must be at least 2*n*krank complex*16 elements long
c ier -- 0 when the routine terminates successfully;
c -1000 when lra is too small
c
c work:
c w -- must be at least m+2*n+1 complex*16 elements long
c
c _N.B._: ra must be at least 2*n*krank complex*16 elements long.
c Also, the algorithm used by this routine is randomized.
c
implicit none
integer m,n,lw,krank,ix,lx,iy,ly,iscal,lscal,lra,ier
real*8 eps
complex*16 p1,p2,p3,p4,ra(n,*),w(m+2*n+1)
external matveca
c
c
lw = 0
c
ix = lw+1
lx = m
lw = lw+lx
c
iy = lw+1
ly = n
lw = lw+ly
c
iscal = lw+1
lscal = n+1
lw = lw+lscal
c
c
call idz_findrank0(lra,eps,m,n,matveca,p1,p2,p3,p4,
1 krank,ra,ier,w(ix),w(iy),w(iscal))
c
c
return
end
c
c
c
c
subroutine idz_findrank0(lra,eps,m,n,matveca,p1,p2,p3,p4,
1 krank,ra,ier,x,y,scal)
c
c routine idz_findrank serves as a memory wrapper
c for the present routine. (Please see routine idz_findrank
c for further documentation.)
c
implicit none
integer m,n,krank,ifrescal,k,lra,ier,m2
real*8 eps,enorm
complex*16 x(m),ra(n,2,*),p1,p2,p3,p4,scal(n+1),y(n),residual
external matveca
c
c
ier = 0
c
c
krank = 0
c
c
c Loop until the relative residual is greater than eps,
c or krank = m or krank = n.
c
1000 continue
c
c
if(lra .lt. n*2*(krank+1)) then
ier = -1000
return
endif
c
c
c Apply the adjoint of a to a random vector.
c
m2 = m*2
call id_srand(m2,x)
call matveca(m,x,n,ra(1,1,krank+1),p1,p2,p3,p4)
c
do k = 1,n
y(k) = ra(k,1,krank+1)
enddo ! k
c
c
if(krank .eq. 0) then
c
c Compute the Euclidean norm of y.
c
enorm = 0
c
do k = 1,n
enorm = enorm + y(k)*conjg(y(k))
enddo ! k
c
enorm = sqrt(enorm)
c
endif ! krank .eq. 0
c
c
if(krank .gt. 0) then
c
c Apply the previous Householder transformations to y.
c
ifrescal = 0
c
do k = 1,krank
call idz_houseapp(n-k+1,ra(1,2,k),y(k),
1 ifrescal,scal(k),y(k))
enddo ! k
c
endif ! krank .gt. 0
c
c
c Compute the Householder vector associated with y.
c
call idz_house(n-krank,y(krank+1),
1 residual,ra(1,2,krank+1),scal(krank+1))
c
c
krank = krank+1
c
c
if(abs(residual) .gt. eps*enorm
1 .and. krank .lt. m .and. krank .lt. n)
2 goto 1000
c
c
c Delete the Householder vectors from the array ra.
c
call idz_crunch(n,krank,ra)
c
c
return
end
c
c
c
c
subroutine idz_crunch(n,l,a)
c
c removes every other block of n entries from a vector.
c
c input:
c n -- length of each block to remove
c l -- half of the total number of blocks
c a -- original array
c
c output:
c a -- array with every other block of n entries removed
c
implicit none
integer j,k,n,l
complex*16 a(n,2*l)
c
c
do j = 2,l
do k = 1,n
c
a(k,j) = a(k,2*j-1)
c
enddo ! k
enddo ! j
c
c
return
end
c
c
c
c
subroutine idz_adjointer(m,n,a,aa)
c
c forms the adjoint aa of a.
c
c input:
c m -- first dimension of a, and second dimension of aa
c n -- second dimension of a, and first dimension of aa
c a -- matrix whose adjoint is to be taken
c
c output:
c aa -- adjoint of a
c
implicit none
integer m,n,j,k
complex*16 a(m,n),aa(n,m)
c
c
do k = 1,n
do j = 1,m
c
aa(k,j) = conjg(a(j,k))
c
enddo ! j
enddo ! k
c
c
return
end
| bsd-3-clause |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg/ezmap/mdpsav.f | 1 | 3080 | C
C $Id: mdpsav.f,v 1.10 2008-09-18 12:19:11 kennison Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE MDPSAV (IFNO)
C
INTEGER IFNO
C
C Declare required common blocks. See MAPBDX for descriptions of these
C common blocks and the variables in them.
C
COMMON /MAPCM3/ ITPN,NOUT,NPTS,IGID,IDLS,IDRS,BLAG,SLAG,BLOG,
+ SLOG,PNTS(200),IDOS(4)
INTEGER ITPN,NOUT,NPTS,IGID,IDLS,IDRS,IDOS
REAL BLAG,SLAG,BLOG,SLOG,PNTS
SAVE /MAPCM3/
C
COMMON /MAPCM4/ GRDR,GRID,GRLA,GRLO,GRPO,OTOL,PDRE,PLA1,PLA2,
+ PLA3,PLA4,PLB1,PLB2,PLB3,PLB4,PLNO,PLTO,ROTA,
+ SRCH,XLOW,XROW,YBOW,YTOW,IDOT,IDSH,IDTL,ILCW,
+ ILTS,JPRJ,ELPF,INTF,LBLF,PRMF
DOUBLE PRECISION GRDR,GRID,GRLA,GRLO,GRPO,OTOL,PDRE,PLA1,PLA2,
+ PLA3,PLA4,PLB1,PLB2,PLB3,PLB4,PLNO,PLTO,ROTA,
+ SRCH,XLOW,XROW,YBOW,YTOW
INTEGER IDOT,IDSH,IDTL,ILCW,ILTS,JPRJ
LOGICAL ELPF,INTF,LBLF,PRMF
SAVE /MAPCM4/
C
COMMON /MAPCMA/ DATL,DBTD,DDTS,DPLT,DPSQ,DSCA,DSSQ
DOUBLE PRECISION DATL,DBTD,DDTS,DPLT,DPSQ,DSCA,DSSQ
SAVE /MAPCMA/
C
COMMON /MAPCMC/ IGI1,IGI2,NCRA,NOVS,XCRA(100),YCRA(100)
INTEGER IGI1,IGI2,NCRA,NOVS
REAL XCRA,YCRA
SAVE /MAPCMC/
C
COMMON /MAPCMQ/ ICIN(8)
INTEGER ICIN
SAVE /MAPCMQ/
C
COMMON /MAPCMW/ CSLS,CSLT,SLTD,ISLT
DOUBLE PRECISION CSLS,CSLT,SLTD
INTEGER ISLT
SAVE /MAPCMW/
C
COMMON /MAPRGD/ ICOL(5),ICSF(5),IDPF,LCRA,NILN,NILT,OLAT,OLON
INTEGER ICOL,ICSF,IDPF,LCRA,NILN,NILT
REAL OLAT,OLON
SAVE /MAPRGD/
C
COMMON /MAPSAT/ ALFA,BETA,DCSA,DCSB,DSNA,DSNB,SALT,SSMO,SRSS
DOUBLE PRECISION ALFA,BETA,DCSA,DCSB,DSNA,DSNB,SALT,SSMO,SRSS
SAVE /MAPSAT/
C
C Check for an uncleared prior error.
C
IF (ICFELL('MDPSAV - UNCLEARED PRIOR ERROR',1).NE.0) RETURN
C
C Write a record containing all the user-settable parameters.
C
WRITE (IFNO,ERR=901) NOUT,GRDR,GRID,GRLA,GRLO,GRPO,OTOL,
+ PLTO,PLNO,PLA1,PLA2,PLA3,PLA4,PLB1,
+ PLB2,PLB3,PLB4,PDRE,ROTA,SRCH,XLOW,
+ XROW,YBOW,YTOW,IDOT,IDSH,IDTL,ILCW,
+ ILTS,JPRJ,ELPF,LBLF,PRMF,DDTS,DPLT,
+ IGI1,IGI2,NOVS,ICIN,ALFA,BETA,DCSA,
+ DCSB,DSNA,DSNB,SALT,SSMO,SRSS,ICOL,
+ ICSF,NILN,NILT,IDPF,CSLT,CSLS,SLTD,
+ ISLT
C
C Done.
C
RETURN
C
C Error exits.
C
901 CALL SETER ('MDPSAV - ERROR ON WRITE',2,1)
RETURN
C
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/cpprfs.f | 2 | 10782 | SUBROUTINE CPPRFS( UPLO, N, NRHS, AP, AFP, B, LDB, X, LDX, FERR,
$ BERR, WORK, RWORK, INFO )
*
* -- LAPACK routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* September 30, 1994
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, LDB, LDX, N, NRHS
* ..
* .. Array Arguments ..
REAL BERR( * ), FERR( * ), RWORK( * )
COMPLEX AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
$ X( LDX, * )
* ..
*
* Purpose
* =======
*
* CPPRFS improves the computed solution to a system of linear
* equations when the coefficient matrix is Hermitian positive definite
* and packed, and provides error bounds and backward error estimates
* for the solution.
*
* Arguments
* =========
*
* UPLO (input) CHARACTER*1
* = 'U': Upper triangle of A is stored;
* = 'L': Lower triangle of A is stored.
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* NRHS (input) INTEGER
* The number of right hand sides, i.e., the number of columns
* of the matrices B and X. NRHS >= 0.
*
* AP (input) COMPLEX array, dimension (N*(N+1)/2)
* The upper or lower triangle of the Hermitian matrix A, packed
* columnwise in a linear array. The j-th column of A is stored
* in the array AP as follows:
* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
*
* AFP (input) COMPLEX array, dimension (N*(N+1)/2)
* The triangular factor U or L from the Cholesky factorization
* A = U**H*U or A = L*L**H, as computed by SPPTRF/CPPTRF,
* packed columnwise in a linear array in the same format as A
* (see AP).
*
* B (input) COMPLEX array, dimension (LDB,NRHS)
* The right hand side matrix B.
*
* LDB (input) INTEGER
* The leading dimension of the array B. LDB >= max(1,N).
*
* X (input/output) COMPLEX array, dimension (LDX,NRHS)
* On entry, the solution matrix X, as computed by CPPTRS.
* On exit, the improved solution matrix X.
*
* LDX (input) INTEGER
* The leading dimension of the array X. LDX >= max(1,N).
*
* FERR (output) REAL array, dimension (NRHS)
* The estimated forward error bound for each solution vector
* X(j) (the j-th column of the solution matrix X).
* If XTRUE is the true solution corresponding to X(j), FERR(j)
* is an estimated upper bound for the magnitude of the largest
* element in (X(j) - XTRUE) divided by the magnitude of the
* largest element in X(j). The estimate is as reliable as
* the estimate for RCOND, and is almost always a slight
* overestimate of the true error.
*
* BERR (output) REAL array, dimension (NRHS)
* The componentwise relative backward error of each solution
* vector X(j) (i.e., the smallest relative change in
* any element of A or B that makes X(j) an exact solution).
*
* WORK (workspace) COMPLEX array, dimension (2*N)
*
* RWORK (workspace) REAL array, dimension (N)
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
*
* Internal Parameters
* ===================
*
* ITMAX is the maximum number of steps of iterative refinement.
*
* ====================================================================
*
* .. Parameters ..
INTEGER ITMAX
PARAMETER ( ITMAX = 5 )
REAL ZERO
PARAMETER ( ZERO = 0.0E+0 )
COMPLEX CONE
PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) )
REAL TWO
PARAMETER ( TWO = 2.0E+0 )
REAL THREE
PARAMETER ( THREE = 3.0E+0 )
* ..
* .. Local Scalars ..
LOGICAL UPPER
INTEGER COUNT, I, IK, J, K, KASE, KK, NZ
REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
COMPLEX ZDUM
* ..
* .. External Subroutines ..
EXTERNAL CAXPY, CCOPY, CHPMV, CLACON, CPPTRS, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, AIMAG, MAX, REAL
* ..
* .. External Functions ..
LOGICAL LSAME
REAL SLAMCH
EXTERNAL LSAME, SLAMCH
* ..
* .. Statement Functions ..
REAL CABS1
* ..
* .. Statement Function definitions ..
CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
UPPER = LSAME( UPLO, 'U' )
IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( NRHS.LT.0 ) THEN
INFO = -3
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -7
ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
INFO = -9
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CPPRFS', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
DO 10 J = 1, NRHS
FERR( J ) = ZERO
BERR( J ) = ZERO
10 CONTINUE
RETURN
END IF
*
* NZ = maximum number of nonzero elements in each row of A, plus 1
*
NZ = N + 1
EPS = SLAMCH( 'Epsilon' )
SAFMIN = SLAMCH( 'Safe minimum' )
SAFE1 = NZ*SAFMIN
SAFE2 = SAFE1 / EPS
*
* Do for each right hand side
*
DO 140 J = 1, NRHS
*
COUNT = 1
LSTRES = THREE
20 CONTINUE
*
* Loop until stopping criterion is satisfied.
*
* Compute residual R = B - A * X
*
CALL CCOPY( N, B( 1, J ), 1, WORK, 1 )
CALL CHPMV( UPLO, N, -CONE, AP, X( 1, J ), 1, CONE, WORK, 1 )
*
* Compute componentwise relative backward error from formula
*
* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
*
* where abs(Z) is the componentwise absolute value of the matrix
* or vector Z. If the i-th component of the denominator is less
* than SAFE2, then SAFE1 is added to the i-th components of the
* numerator and denominator before dividing.
*
DO 30 I = 1, N
RWORK( I ) = CABS1( B( I, J ) )
30 CONTINUE
*
* Compute abs(A)*abs(X) + abs(B).
*
KK = 1
IF( UPPER ) THEN
DO 50 K = 1, N
S = ZERO
XK = CABS1( X( K, J ) )
IK = KK
DO 40 I = 1, K - 1
RWORK( I ) = RWORK( I ) + CABS1( AP( IK ) )*XK
S = S + CABS1( AP( IK ) )*CABS1( X( I, J ) )
IK = IK + 1
40 CONTINUE
RWORK( K ) = RWORK( K ) + ABS( REAL( AP( KK+K-1 ) ) )*
$ XK + S
KK = KK + K
50 CONTINUE
ELSE
DO 70 K = 1, N
S = ZERO
XK = CABS1( X( K, J ) )
RWORK( K ) = RWORK( K ) + ABS( REAL( AP( KK ) ) )*XK
IK = KK + 1
DO 60 I = K + 1, N
RWORK( I ) = RWORK( I ) + CABS1( AP( IK ) )*XK
S = S + CABS1( AP( IK ) )*CABS1( X( I, J ) )
IK = IK + 1
60 CONTINUE
RWORK( K ) = RWORK( K ) + S
KK = KK + ( N-K+1 )
70 CONTINUE
END IF
S = ZERO
DO 80 I = 1, N
IF( RWORK( I ).GT.SAFE2 ) THEN
S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
ELSE
S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
$ ( RWORK( I )+SAFE1 ) )
END IF
80 CONTINUE
BERR( J ) = S
*
* Test stopping criterion. Continue iterating if
* 1) The residual BERR(J) is larger than machine epsilon, and
* 2) BERR(J) decreased by at least a factor of 2 during the
* last iteration, and
* 3) At most ITMAX iterations tried.
*
IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
$ COUNT.LE.ITMAX ) THEN
*
* Update solution and try again.
*
CALL CPPTRS( UPLO, N, 1, AFP, WORK, N, INFO )
CALL CAXPY( N, CONE, WORK, 1, X( 1, J ), 1 )
LSTRES = BERR( J )
COUNT = COUNT + 1
GO TO 20
END IF
*
* Bound error from formula
*
* norm(X - XTRUE) / norm(X) .le. FERR =
* norm( abs(inv(A))*
* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
*
* where
* norm(Z) is the magnitude of the largest component of Z
* inv(A) is the inverse of A
* abs(Z) is the componentwise absolute value of the matrix or
* vector Z
* NZ is the maximum number of nonzeros in any row of A, plus 1
* EPS is machine epsilon
*
* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
* is incremented by SAFE1 if the i-th component of
* abs(A)*abs(X) + abs(B) is less than SAFE2.
*
* Use CLACON to estimate the infinity-norm of the matrix
* inv(A) * diag(W),
* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
*
DO 90 I = 1, N
IF( RWORK( I ).GT.SAFE2 ) THEN
RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
ELSE
RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
$ SAFE1
END IF
90 CONTINUE
*
KASE = 0
100 CONTINUE
CALL CLACON( N, WORK( N+1 ), WORK, FERR( J ), KASE )
IF( KASE.NE.0 ) THEN
IF( KASE.EQ.1 ) THEN
*
* Multiply by diag(W)*inv(A').
*
CALL CPPTRS( UPLO, N, 1, AFP, WORK, N, INFO )
DO 110 I = 1, N
WORK( I ) = RWORK( I )*WORK( I )
110 CONTINUE
ELSE IF( KASE.EQ.2 ) THEN
*
* Multiply by inv(A)*diag(W).
*
DO 120 I = 1, N
WORK( I ) = RWORK( I )*WORK( I )
120 CONTINUE
CALL CPPTRS( UPLO, N, 1, AFP, WORK, N, INFO )
END IF
GO TO 100
END IF
*
* Normalize error.
*
LSTRES = ZERO
DO 130 I = 1, N
LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
130 CONTINUE
IF( LSTRES.NE.ZERO )
$ FERR( J ) = FERR( J ) / LSTRES
*
140 CONTINUE
*
RETURN
*
* End of CPPRFS
*
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ncarg2d/src/libncarg_gks/bwi/gputni.f | 1 | 1545 | C
C $Id: gputni.f,v 1.5 2008-07-27 00:21:06 haley Exp $
C
C Copyright (C) 2000
C University Corporation for Atmospheric Research
C All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
SUBROUTINE GPUTNI(OPCL, OPID, NBYTES, GKSERR)
C
C This routine sets up the next instruction to be placed in
C the metafile.
C
C After this call the GPUTPR or GPUTPS routines are called to load
C the operand list.
C
C
C INPUT
C OPCL -- The opcode CLASS of the element.
C OPID -- The opcode ID of the element.
C NBYTES -- The number of bytes in the operand list.
C
C OUTPUT
C GKSERR -- An error status return.
C
C All data is type intege unless otherwise indicated.
C
IMPLICIT INTEGER (A-Z)
C
include 'g01prm.h'
include 'g01ins.h'
C
C Set the CGM data element partition size. The partition size
C should be a multiple of 256 in order to make the arithmetic
C in other parts of the code come out right.
C
DATA PARSIZ/32256/
C
C Load the current opcode CLASS and ID into common.
C
MCOPCL = OPCL
MCOPID = OPID
C
C Set the current partition byte count and the remainder byte count.
C
IF (NBYTES .GT. PARSIZ) THEN
MCCBYT = PARSIZ
MCNBYT = NBYTES - PARSIZ
ELSE
MCCBYT = NBYTES
MCNBYT = 0
END IF
C
C Ready the current partition for the operand list.
C
CALL GINLOD(GKSERR)
C
RETURN
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/blas/ctpmv.f | 11 | 11126 | SUBROUTINE CTPMV ( UPLO, TRANS, DIAG, N, AP, X, INCX )
* .. Scalar Arguments ..
INTEGER INCX, N
CHARACTER*1 DIAG, TRANS, UPLO
* .. Array Arguments ..
COMPLEX AP( * ), X( * )
* ..
*
* Purpose
* =======
*
* CTPMV performs one of the matrix-vector operations
*
* x := A*x, or x := A'*x, or x := conjg( A' )*x,
*
* where x is an n element vector and A is an n by n unit, or non-unit,
* upper or lower triangular matrix, supplied in packed form.
*
* Parameters
* ==========
*
* UPLO - CHARACTER*1.
* On entry, UPLO specifies whether the matrix is an upper or
* lower triangular matrix as follows:
*
* UPLO = 'U' or 'u' A is an upper triangular matrix.
*
* UPLO = 'L' or 'l' A is a lower triangular matrix.
*
* Unchanged on exit.
*
* TRANS - CHARACTER*1.
* On entry, TRANS specifies the operation to be performed as
* follows:
*
* TRANS = 'N' or 'n' x := A*x.
*
* TRANS = 'T' or 't' x := A'*x.
*
* TRANS = 'C' or 'c' x := conjg( A' )*x.
*
* Unchanged on exit.
*
* DIAG - CHARACTER*1.
* On entry, DIAG specifies whether or not A is unit
* triangular as follows:
*
* DIAG = 'U' or 'u' A is assumed to be unit triangular.
*
* DIAG = 'N' or 'n' A is not assumed to be unit
* triangular.
*
* Unchanged on exit.
*
* N - INTEGER.
* On entry, N specifies the order of the matrix A.
* N must be at least zero.
* Unchanged on exit.
*
* AP - COMPLEX array of DIMENSION at least
* ( ( n*( n + 1 ) )/2 ).
* Before entry with UPLO = 'U' or 'u', the array AP must
* contain the upper triangular matrix packed sequentially,
* column by column, so that AP( 1 ) contains a( 1, 1 ),
* AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 )
* respectively, and so on.
* Before entry with UPLO = 'L' or 'l', the array AP must
* contain the lower triangular matrix packed sequentially,
* column by column, so that AP( 1 ) contains a( 1, 1 ),
* AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 )
* respectively, and so on.
* Note that when DIAG = 'U' or 'u', the diagonal elements of
* A are not referenced, but are assumed to be unity.
* Unchanged on exit.
*
* X - COMPLEX array of dimension at least
* ( 1 + ( n - 1 )*abs( INCX ) ).
* Before entry, the incremented array X must contain the n
* element vector x. On exit, X is overwritten with the
* tranformed vector x.
*
* INCX - INTEGER.
* On entry, INCX specifies the increment for the elements of
* X. INCX must not be zero.
* Unchanged on exit.
*
*
* Level 2 Blas routine.
*
* -- Written on 22-October-1986.
* Jack Dongarra, Argonne National Lab.
* Jeremy Du Croz, Nag Central Office.
* Sven Hammarling, Nag Central Office.
* Richard Hanson, Sandia National Labs.
*
*
* .. Parameters ..
COMPLEX ZERO
PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )
* .. Local Scalars ..
COMPLEX TEMP
INTEGER I, INFO, IX, J, JX, K, KK, KX
LOGICAL NOCONJ, NOUNIT
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* .. External Subroutines ..
EXTERNAL XERBLA
* .. Intrinsic Functions ..
INTRINSIC CONJG
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
IF ( .NOT.LSAME( UPLO , 'U' ).AND.
$ .NOT.LSAME( UPLO , 'L' ) )THEN
INFO = 1
ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND.
$ .NOT.LSAME( TRANS, 'T' ).AND.
$ .NOT.LSAME( TRANS, 'C' ) )THEN
INFO = 2
ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND.
$ .NOT.LSAME( DIAG , 'N' ) )THEN
INFO = 3
ELSE IF( N.LT.0 )THEN
INFO = 4
ELSE IF( INCX.EQ.0 )THEN
INFO = 7
END IF
IF( INFO.NE.0 )THEN
CALL XERBLA( 'CTPMV ', INFO )
RETURN
END IF
*
* Quick return if possible.
*
IF( N.EQ.0 )
$ RETURN
*
NOCONJ = LSAME( TRANS, 'T' )
NOUNIT = LSAME( DIAG , 'N' )
*
* Set up the start point in X if the increment is not unity. This
* will be ( N - 1 )*INCX too small for descending loops.
*
IF( INCX.LE.0 )THEN
KX = 1 - ( N - 1 )*INCX
ELSE IF( INCX.NE.1 )THEN
KX = 1
END IF
*
* Start the operations. In this version the elements of AP are
* accessed sequentially with one pass through AP.
*
IF( LSAME( TRANS, 'N' ) )THEN
*
* Form x:= A*x.
*
IF( LSAME( UPLO, 'U' ) )THEN
KK = 1
IF( INCX.EQ.1 )THEN
DO 20, J = 1, N
IF( X( J ).NE.ZERO )THEN
TEMP = X( J )
K = KK
DO 10, I = 1, J - 1
X( I ) = X( I ) + TEMP*AP( K )
K = K + 1
10 CONTINUE
IF( NOUNIT )
$ X( J ) = X( J )*AP( KK + J - 1 )
END IF
KK = KK + J
20 CONTINUE
ELSE
JX = KX
DO 40, J = 1, N
IF( X( JX ).NE.ZERO )THEN
TEMP = X( JX )
IX = KX
DO 30, K = KK, KK + J - 2
X( IX ) = X( IX ) + TEMP*AP( K )
IX = IX + INCX
30 CONTINUE
IF( NOUNIT )
$ X( JX ) = X( JX )*AP( KK + J - 1 )
END IF
JX = JX + INCX
KK = KK + J
40 CONTINUE
END IF
ELSE
KK = ( N*( N + 1 ) )/2
IF( INCX.EQ.1 )THEN
DO 60, J = N, 1, -1
IF( X( J ).NE.ZERO )THEN
TEMP = X( J )
K = KK
DO 50, I = N, J + 1, -1
X( I ) = X( I ) + TEMP*AP( K )
K = K - 1
50 CONTINUE
IF( NOUNIT )
$ X( J ) = X( J )*AP( KK - N + J )
END IF
KK = KK - ( N - J + 1 )
60 CONTINUE
ELSE
KX = KX + ( N - 1 )*INCX
JX = KX
DO 80, J = N, 1, -1
IF( X( JX ).NE.ZERO )THEN
TEMP = X( JX )
IX = KX
DO 70, K = KK, KK - ( N - ( J + 1 ) ), -1
X( IX ) = X( IX ) + TEMP*AP( K )
IX = IX - INCX
70 CONTINUE
IF( NOUNIT )
$ X( JX ) = X( JX )*AP( KK - N + J )
END IF
JX = JX - INCX
KK = KK - ( N - J + 1 )
80 CONTINUE
END IF
END IF
ELSE
*
* Form x := A'*x or x := conjg( A' )*x.
*
IF( LSAME( UPLO, 'U' ) )THEN
KK = ( N*( N + 1 ) )/2
IF( INCX.EQ.1 )THEN
DO 110, J = N, 1, -1
TEMP = X( J )
K = KK - 1
IF( NOCONJ )THEN
IF( NOUNIT )
$ TEMP = TEMP*AP( KK )
DO 90, I = J - 1, 1, -1
TEMP = TEMP + AP( K )*X( I )
K = K - 1
90 CONTINUE
ELSE
IF( NOUNIT )
$ TEMP = TEMP*CONJG( AP( KK ) )
DO 100, I = J - 1, 1, -1
TEMP = TEMP + CONJG( AP( K ) )*X( I )
K = K - 1
100 CONTINUE
END IF
X( J ) = TEMP
KK = KK - J
110 CONTINUE
ELSE
JX = KX + ( N - 1 )*INCX
DO 140, J = N, 1, -1
TEMP = X( JX )
IX = JX
IF( NOCONJ )THEN
IF( NOUNIT )
$ TEMP = TEMP*AP( KK )
DO 120, K = KK - 1, KK - J + 1, -1
IX = IX - INCX
TEMP = TEMP + AP( K )*X( IX )
120 CONTINUE
ELSE
IF( NOUNIT )
$ TEMP = TEMP*CONJG( AP( KK ) )
DO 130, K = KK - 1, KK - J + 1, -1
IX = IX - INCX
TEMP = TEMP + CONJG( AP( K ) )*X( IX )
130 CONTINUE
END IF
X( JX ) = TEMP
JX = JX - INCX
KK = KK - J
140 CONTINUE
END IF
ELSE
KK = 1
IF( INCX.EQ.1 )THEN
DO 170, J = 1, N
TEMP = X( J )
K = KK + 1
IF( NOCONJ )THEN
IF( NOUNIT )
$ TEMP = TEMP*AP( KK )
DO 150, I = J + 1, N
TEMP = TEMP + AP( K )*X( I )
K = K + 1
150 CONTINUE
ELSE
IF( NOUNIT )
$ TEMP = TEMP*CONJG( AP( KK ) )
DO 160, I = J + 1, N
TEMP = TEMP + CONJG( AP( K ) )*X( I )
K = K + 1
160 CONTINUE
END IF
X( J ) = TEMP
KK = KK + ( N - J + 1 )
170 CONTINUE
ELSE
JX = KX
DO 200, J = 1, N
TEMP = X( JX )
IX = JX
IF( NOCONJ )THEN
IF( NOUNIT )
$ TEMP = TEMP*AP( KK )
DO 180, K = KK + 1, KK + N - J
IX = IX + INCX
TEMP = TEMP + AP( K )*X( IX )
180 CONTINUE
ELSE
IF( NOUNIT )
$ TEMP = TEMP*CONJG( AP( KK ) )
DO 190, K = KK + 1, KK + N - J
IX = IX + INCX
TEMP = TEMP + CONJG( AP( K ) )*X( IX )
190 CONTINUE
END IF
X( JX ) = TEMP
JX = JX + INCX
KK = KK + ( N - J + 1 )
200 CONTINUE
END IF
END IF
END IF
*
RETURN
*
* End of CTPMV .
*
END
| gpl-2.0 |
marshallward/mom | src/mom5/ocean_param/lateral/ocean_mixdownslope.F90 | 5 | 54969 | module ocean_mixdownslope_mod
#define COMP isc:iec,jsc:jec
!
!<CONTACT EMAIL="GFDL.Climate.Model.Info@noaa.gov"> S.M. Griffies
!</CONTACT>
!
!<OVERVIEW>
! Mixing of tracer between dense shallow parcel and
! deeper parcels downslope.
!</OVERVIEW>
!
!<DESCRIPTION>
! Mixing of tracer properties as dense shallow parcel is discharged
! into deeper water to approach the parcel's depth of neutral buoyancy.
! This module can be characterized as a mixture of the approach from
! Campin and Goosse (1999) and slope convection.
!</DESCRIPTION>
!
! <INFO>
!
! <REFERENCE>
! Campin and Goosse (1999): Parameterization of density-driven downsloping flow
! for a coarse-resolution model in z-coordinate", Tellus 51A, pages 412-430
! </REFERENCE>
!
! <REFERENCE>
! S.M. Griffies: Elements of MOM (2012)
! NOAA/Geophysical Fluid Dynamics Laboratory
! </REFERENCE>
!
! </INFO>
!
!<NAMELIST NAME="ocean_mixdownslope_nml">
! <DATA NAME="use_this_module" TYPE="logical">
! For using this module. Default use_this_module=.false.
! </DATA>
! <DATA NAME="debug_this_module" TYPE="logical">
! For debugging
! </DATA>
! <DATA NAME="do_bitwise_exact_sum" TYPE="logical">
! Set true to do bitwise exact global sum. When it is false, the global
! sum will be non-bitwise_exact, but will significantly increase efficiency.
! The default value is false.
! </DATA>
!
! <DATA NAME="mixdownslope_npts" TYPE="integer">
! Number of horizontally distant points used in search downslope.
! Note: it is not possible to have
! mixdownslope_npts greater than or equal to the computational domain
! extents, as this would require updates across multiple processors.
! Default mixdownslope_npts=1.
! </DATA>
! <DATA NAME="mixdownslope_frac_central" TYPE="real">
! Fraction of the central cell that participates in downslope mixing
! in any particular direction. Default mixdownslope_frac_central=0.25
! </DATA>
!
! <DATA NAME="mixdownslope_weight_far" TYPE="logical">
! To place more weight on points further from central point. This may
! be done to enhance properties getting downslope. Default is
! mixdownslope_weight_far=.false.
! </DATA>
! <DATA NAME="mixdownslope_width" TYPE="integer">
! Width of the re-weighting function used to emphasize points further
! along in the search for exchange points. Default mixdownslope_width=1.
! </DATA>
!
! <DATA NAME="read_mixdownslope_mask" TYPE="logical">
! For reading in a mask that selects regions of the domain
! where mixdownslope is allowed to function (mask=1) or not
! to function (mask=0). Default read_mixdownslope_mask=.false.,
! whereby mixdownslope_mask is set to tmask(k=1).
! </DATA>
! <DATA NAME="mixdownslope_mask_gfdl" TYPE="logical">
! For modifying the mixdownslope mask based on reading in
! the GFDL regional mask. Default mixdownslope_mask_gfdl=.false.
! </DATA>
!
!</NAMELIST>
!
use constants_mod, only: epsln
use diag_manager_mod, only: register_diag_field, register_static_field
use fms_mod, only: write_version_number, error_mesg, read_data, FATAL, NOTE
use fms_mod, only: open_namelist_file, check_nml_error, close_file, stdout, stdlog
use mpp_domains_mod, only: mpp_update_domains, CGRID_NE
use mpp_domains_mod, only: mpp_global_sum, BITWISE_EXACT_SUM, NON_BITWISE_EXACT_SUM
use mpp_mod, only: input_nml_file, mpp_error
use ocean_density_mod, only: density
use ocean_domains_mod, only: get_local_indices, set_ocean_domain
use ocean_parameters_mod, only: missing_value, rho0, rho0r
use ocean_parameters_mod, only: TERRAIN_FOLLOWING
use ocean_types_mod, only: ocean_domain_type, ocean_grid_type, ocean_time_type, ocean_options_type
use ocean_types_mod, only: ocean_prog_tracer_type, ocean_density_type, ocean_thickness_type
use ocean_util_mod, only: write_timestamp, diagnose_2d, diagnose_3d, diagnose_sum
use ocean_util_mod, only: write_chksum_2d, write_chksum_3d, write_chksum_2d_int
use ocean_tracer_util_mod, only: diagnose_3d_rho
use ocean_workspace_mod, only: wrk1, wrk2, wrk3, wrk4, wrk5, wrk1_v
implicit none
private
public ocean_mixdownslope_init
public mixdownslope
private watermass_diag_init
private watermass_diag
type(ocean_domain_type), pointer :: Dom => NULL()
type(ocean_grid_type), pointer :: Grd => NULL()
#include <ocean_memory.h>
integer, dimension(:,:), allocatable :: ip ! shifting in i-direction
integer, dimension(:,:), allocatable :: jq ! shifting in j-direction
real, dimension(:,:), allocatable :: data ! for reading in mask information
real, dimension(:,:), allocatable :: area_k ! area on k-level, including tmask
real, dimension(:,:), allocatable :: slope_x ! topog slope (dimensionless) in the i-direction
real, dimension(:,:), allocatable :: slope_y ! topog slope (dimensionless) in the j-direction
real, dimension(:,:), allocatable :: mixdownslope_mask ! mask=1 when apply mixdownslope, 0 otherwise
real, dimension(:,:,:), allocatable :: topog_step ! where downslope flow is topgraphically possible
real, dimension(:,:,:), allocatable :: tend_mix ! (rho*dzt*tracer) tendency
real, dimension(:,:,:,:), allocatable :: mixdownslope_frac ! fraction of mixing occurring between two cells
! fields with extended halos
integer, dimension(:,:), allocatable :: kmt_ex
integer, dimension(:,:,:), allocatable :: kup_ex
integer, dimension(:,:,:,:), allocatable :: kdw_ex
real, dimension(:,:,:), allocatable :: topog_slope_ex
real, dimension(:,:,:), allocatable :: topog_step_ex
real, dimension(:,:,:), allocatable :: tracer_ex
real, dimension(:,:,:), allocatable :: temp_ex
real, dimension(:,:,:), allocatable :: salt_ex
real, dimension(:,:,:), allocatable :: press_ex
real, dimension(:,:,:), allocatable :: mass_ex
real, dimension(:,:,:), allocatable :: rho_ex
! domain for mixdownslope
type(ocean_domain_type), save :: Mixdownslope_domain
! work array for eta_tend
real, dimension(:,:,:), allocatable :: theta_tend
real, dimension(:,:,:), allocatable :: salt_tend
! internally set for computing watermass diagnstics
logical :: compute_watermass_diag = .false.
! for global area normalization
real :: cellarea_r
! for diagnostic manager
logical :: used
integer :: id_slope_x=-1
integer :: id_slope_y=-1
integer :: id_topog_step_1 =-1
integer :: id_topog_step_2 =-1
integer :: id_topog_step_3 =-1
integer :: id_topog_step_4 =-1
integer :: id_mixdownslope_mask =-1
integer :: id_neut_rho_mixdown =-1
integer :: id_wdian_rho_mixdown =-1
integer :: id_tform_rho_mixdown =-1
integer :: id_neut_rho_mixdown_on_nrho =-1
integer :: id_wdian_rho_mixdown_on_nrho =-1
integer :: id_tform_rho_mixdown_on_nrho =-1
integer :: id_eta_tend_mixdown =-1
integer :: id_eta_tend_mixdown_glob=-1
integer :: id_neut_temp_mixdown =-1
integer :: id_wdian_temp_mixdown =-1
integer :: id_tform_temp_mixdown =-1
integer :: id_neut_temp_mixdown_on_nrho =-1
integer :: id_wdian_temp_mixdown_on_nrho =-1
integer :: id_tform_temp_mixdown_on_nrho =-1
integer :: id_neut_salt_mixdown =-1
integer :: id_wdian_salt_mixdown =-1
integer :: id_tform_salt_mixdown =-1
integer :: id_neut_salt_mixdown_on_nrho =-1
integer :: id_wdian_salt_mixdown_on_nrho =-1
integer :: id_tform_salt_mixdown_on_nrho =-1
integer, dimension(:), allocatable :: id_mixdownslope
integer, dimension(:), allocatable :: id_mixdownslope_on_nrho
character(len=128) :: version=&
'=>Using: ocean_mixdownslope.f90 ($Id: ocean_mixdownslope.F90,v 20.0 2013/12/14 00:14:28 fms Exp $)'
character (len=128) :: tagname=&
'$Name: tikal $'
! number of prognostic tracers
integer :: num_prog_tracers=0
! processor zero writes to unit 6
integer :: unit=6
! initialization flag
logical :: module_is_initialized=.false.
! flag for mpp_global_sum
integer :: global_sum_flag
! halo
integer :: ijhalo=1
! time step
real :: dtime
real :: dtimer
! set from nml
logical :: use_this_module = .false. ! must be set .true. in nml to enable this scheme
logical :: debug_this_module = .false. ! for debugging
logical :: do_bitwise_exact_sum = .false. ! set true to get slower sum that is same for all PEs.
logical :: mixdownslope_weight_far= .false. ! to place more weight on points further from central point
logical :: read_mixdownslope_mask = .false. ! for applying a mask where do not apply mixdownslope
logical :: mixdownslope_mask_gfdl = .false. ! for case when applying GFDL regional mask
integer :: mixdownslope_npts = 1 ! number horizontal points searched for the downslope mixing
integer :: mixdownslope_width = 1 ! width for exponential that damps points near to central point
real :: mixdownslope_frac_central =0.25 ! fraction of central cell participating in downslope mixing
namelist /ocean_mixdownslope_nml/ use_this_module, debug_this_module, mixdownslope_npts, &
mixdownslope_width, mixdownslope_weight_far, &
mixdownslope_frac_central, do_bitwise_exact_sum, &
read_mixdownslope_mask, mixdownslope_mask_gfdl
contains
!#######################################################################
! <SUBROUTINE NAME="ocean_mixdownslope_init">
!
! <DESCRIPTION>
! Initial set up for mixing of tracers into the abyss next to topography.
! </DESCRIPTION>
!
subroutine ocean_mixdownslope_init(Grid, Domain, Time, Dens, T_prog, Ocean_options, &
vert_coordinate_type, dtim, debug)
type(ocean_grid_type), intent(in), target :: Grid
type(ocean_domain_type), intent(in), target :: Domain
type(ocean_time_type), intent(in), target :: Time
type(ocean_density_type), intent(in) :: Dens
type(ocean_prog_tracer_type), intent(inout) :: T_prog(:)
type(ocean_options_type), intent(inout) :: Ocean_options
integer, intent(in) :: vert_coordinate_type
real, intent(in) :: dtim
logical, intent(in), optional :: debug
integer :: io_status, ioun, ierr
integer :: i,j,m,n,kbot
integer :: stdoutunit,stdlogunit
stdoutunit=stdout();stdlogunit=stdlog()
if ( module_is_initialized ) then
call mpp_error(FATAL, &
'==>Error from ocean_mixdownslope_mod (ocean_mixdownslope_init): module already initialized')
endif
module_is_initialized = .TRUE.
call write_version_number(version, tagname)
#ifndef MOM_STATIC_ARRAYS
call get_local_indices(Domain,isd,ied,jsd,jed,isc,iec,jsc,jec)
nk = Grid%nk
#endif
Dom => Domain
Grd => Grid
dtime = dtim
dtimer = 1.0/dtime
cellarea_r = 1.0/(epsln + Grd%tcellsurf)
num_prog_tracers = size(T_prog(:))
! provide for namelist over-ride of default values
#ifdef INTERNAL_FILE_NML
read (input_nml_file, nml=ocean_mixdownslope_nml, iostat=io_status)
ierr = check_nml_error(io_status,'ocean_mixdownslope_nml')
#else
ioun = open_namelist_file()
read (ioun,ocean_mixdownslope_nml,IOSTAT=io_status)
ierr = check_nml_error(io_status,'ocean_mixdownslope_nml')
call close_file (ioun)
#endif
write (stdlogunit,ocean_mixdownslope_nml)
write (stdoutunit,'(/)')
write (stdoutunit,ocean_mixdownslope_nml)
if(do_bitwise_exact_sum) then
global_sum_flag = BITWISE_EXACT_SUM
else
global_sum_flag = NON_BITWISE_EXACT_SUM
endif
if (PRESENT(debug) .and. .not. debug_this_module) then
debug_this_module = debug
endif
if(debug_this_module) then
write(stdoutunit,'(a)') '==>Note: running ocean_mixdownslope_mod with debug_this_module=.true.'
endif
if(.not. use_this_module) then
call mpp_error(NOTE,&
'==>From ocean_mixdownslope_mod: NOT using downslope mixing scheme.')
Ocean_options%mixdownslope = 'Did NOT use downslope mixing scheme.'
return
else
if(vert_coordinate_type == TERRAIN_FOLLOWING) then
call mpp_error(FATAL, &
'==>ocean_mixdownslope_mod: this module is NOT for use with TERRAIN_FOLLOWING vert coodinates.')
endif
Ocean_options%mixdownslope = 'Used the downslope mixing scheme. This scheme is experimental!'
call mpp_error(NOTE,&
'==>From ocean_mixdownslope_mod: USING downslope mixing scheme.')
endif
if(debug_this_module) then
call mpp_error(NOTE,'==>From ocean_mixdownslope_mod: USING debug_this_module')
endif
! allocate for tracer tendency array
allocate(tend_mix(isd:ied,jsd:jed,nk))
tend_mix(:,:,:) = 0.0
if(mixdownslope_npts<1) then
call mpp_error(FATAL, &
'==>ocean_mixdownslope_mod: mixdownslope_npts < 1 not allowed. In nml, set mixdownslope_npts>=1.')
endif
write(stdoutunit,'(a,i3)')' In ocean_mixdownslope_mod: mixdownslope_npts = ',mixdownslope_npts
write(stdoutunit,'(a)') ' Be sure this number is smaller than dimensions of computational domain.'
! set mixdownslope_mask=0.0 in those regions where mixdownslope is NOT applied
! and mixdownslope_mask=1.0 in regions where mixdownslope is applied. Default is
! mixdownslope everywhere (mixdownslope_mask(:,:) = Grd%tmask(:,:,1)).
allocate(mixdownslope_mask(isd:ied,jsd:jed))
mixdownslope_mask(:,:) = Grd%tmask(:,:,1)
if(read_mixdownslope_mask) then
allocate(data(isd:ied,jsd:jed))
call read_data('INPUT/mixdownslope_mask','mixdownslope_mask',data,Domain%domain2d)
do j=jsc,jec
do i=isc,iec
mixdownslope_mask(i,j) = data(i,j)
enddo
enddo
! the following is specific to the mask used at GFDL for
! the OM3 ocean model configuration.
! here, remove the Black Sea (labelled with 7.0), as this
! region contains some odd water masses which cause instabilities
! with the mixdownslope scheme.
if(mixdownslope_mask_gfdl) then
do j=jsc,jec
do i=isc,iec
if(mixdownslope_mask(i,j)==0.0 .or. mixdownslope_mask(i,j)==7.0) then
mixdownslope_mask(i,j)=0.0
else
mixdownslope_mask(i,j)=1.0
endif
enddo
enddo
endif
call mpp_update_domains(mixdownslope_mask(:,:), Dom%domain2d)
endif
! halo size for extended domain and larger arrays
ijhalo=mixdownslope_npts
! k-level of central point in search
allocate(kup_ex(isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo,4))
kup_ex(:,:,:) = 0
! k-level of deeper points in horizontally adjacent columns
allocate(kdw_ex(isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo,ijhalo,4))
kdw_ex(:,:,:,:) = 0
! fraction of a cell participating in mixing
allocate(mixdownslope_frac(isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo,ijhalo,4))
mixdownslope_frac(:,:,:,:) = 0.0
! define extended domain
call set_ocean_domain(Mixdownslope_domain,Grd,xhalo=ijhalo,yhalo=ijhalo,&
name='mixdownslope',maskmap=Dom%maskmap)
! time independent arrays defined over Mixdownslope_domain
allocate(kmt_ex (isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo))
kmt_ex(:,:) = 0
kmt_ex (isc:iec,jsc:jec) = Grd%kmt (isc:iec,jsc:jec)
call mpp_update_domains (kmt_ex(:,:), Mixdownslope_domain%domain2d)
! time dependent arrays defined over Mixdownslope_domain
allocate(temp_ex (isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo,nk))
allocate(salt_ex (isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo,nk))
allocate(tracer_ex (isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo,nk))
allocate(press_ex (isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo,nk))
allocate(rho_ex (isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo,nk))
allocate(mass_ex (isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo,nk))
temp_ex(:,:,:) = 0.0
salt_ex(:,:,:) = 0.0
tracer_ex(:,:,:) = 0.0
press_ex(:,:,:) = 0.0
rho_ex(:,:,:) = 0.0
mass_ex(:,:,:) = 0.0
! area of cells on k-level, including tmask
allocate (area_k(isd:ied,jsd:jed))
area_k(:,:) = 0.0
! compute topographic slope arrays for the i-slope and j-slope
! slopes are centered on the i-face and j-face of tracer cells
allocate (slope_x(isd:ied,jsd:jed))
allocate (slope_y(isd:ied,jsd:jed))
slope_x = 0.0
slope_y = 0.0
do j=jsc,jec
do i=isc,iec
slope_x(i,j) = (Grd%ht(i+1,j)-Grd%ht(i,j))*Grd%dxter(i,j)*Grd%tmask(i,j,1)*Grd%tmask(i+1,j,1)
slope_y(i,j) = (Grd%ht(i,j+1)-Grd%ht(i,j))*Grd%dytnr(i,j)*Grd%tmask(i,j,1)*Grd%tmask(i,j+1,1)
slope_x(i,j) = abs(slope_x(i,j))
slope_y(i,j) = abs(slope_y(i,j))
enddo
enddo
call mpp_update_domains(slope_x(:,:),Dom%domain2d)
call mpp_update_domains(slope_y(:,:),Dom%domain2d)
! topographic slope for the four surrounding directions
allocate (topog_slope_ex(isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo,4))
topog_slope_ex(:,:,:) = 0.0
do j=jsc,jec
do i=isc,iec
m=1 ; topog_slope_ex(i,j,m) = slope_x(i,j)
m=2 ; topog_slope_ex(i,j,m) = slope_y(i,j)
m=3 ; topog_slope_ex(i,j,m) = slope_x(i-1,j)
m=4 ; topog_slope_ex(i,j,m) = slope_y(i,j-1)
enddo
enddo
call mpp_update_domains (topog_slope_ex(:,:,:), Mixdownslope_domain%domain2d)
! compute directions from an (i,j) point where topography deepens.
! these directions may potentially have downslope mixing.
! insist that downslope mixing occurs only when there are more
! kmt cells in the adjacent column. also insist that downslope
! mixing does not involve k=1 cells.
allocate (topog_step(isd:ied,jsd:jed,4))
topog_step(:,:,:) = 0.0
do j=jsc,jec
do i=isc,iec
kbot = Grd%kmt(i,j)
if(kbot > 1) then
if(Grd%kmt(i+1,j) > kbot) topog_step(i,j,1)=1.0
if(Grd%kmt(i,j+1) > kbot) topog_step(i,j,2)=1.0
if(Grd%kmt(i-1,j) > kbot) topog_step(i,j,3)=1.0
if(Grd%kmt(i,j-1) > kbot) topog_step(i,j,4)=1.0
endif
enddo
enddo
! block out the bipolar fold in order to ensure tracer conservation.
! The reason we do so is related to how the algorithm reaches between
! adjacent columns of tracer points. When the column straddles
! the bipolar fold, the code logic is not general and so it actually
! attempts to reach to a non-adjacent column. Shy of generalizing
! the logic, we simply do not consider mixdownslope for points along fold.
if(jec+Dom%joff==Dom%jeg) then
topog_step(:,jec,:) = 0.0
endif
! fill the larger array
allocate (topog_step_ex(isc-ijhalo:iec+ijhalo,jsc-ijhalo:jec+ijhalo,4))
topog_step_ex(:,:,:) = 0.0
topog_step_ex(isc:iec,jsc:jec,:) = topog_step(isc:iec,jsc:jec,:)
call mpp_update_domains (topog_step_ex(:,:,:), Mixdownslope_domain%domain2d)
! labels for the four quadranats surrounding a
! central tracer cell (moving counter-clockwise)
allocate(ip(0:ijhalo,4))
allocate(jq(0:ijhalo,4))
do n=0,ijhalo
m=1
ip(n,m) = 1+(n-1)
jq(n,m) = 0
m=2
ip(n,m) = 0
jq(n,m) = 1+(n-1)
m=3
ip(n,m) = -1-(n-1)
jq(n,m) = 0
m=4
ip(n,m) = 0
jq(n,m) = -1-(n-1)
enddo
! register/send diagnostics
id_mixdownslope_mask = register_static_field ('ocean_model', 'mixdownslope_mask', &
Grd%tracer_axes(1:2), &
'mixdownslope mask', 'dimensionless', missing_value=missing_value, range=(/-1.0,1e4/))
call diagnose_2d(Time, Grd, id_mixdownslope_mask, mixdownslope_mask(:,:))
id_slope_x = register_static_field ('ocean_model', 'slope_x', Grd%tracer_axes_flux_x(1:2), &
'|d(ht)/dx| on T-cell face', 'm/m', missing_value=missing_value, range=(/-1.e9,1.e9/))
call diagnose_2d(Time, Grd, id_slope_x, slope_x(:,:))
id_slope_y = register_static_field ('ocean_model', 'slope_y', Grd%tracer_axes_flux_y(1:2), &
'|d(ht)/dy| on T-cell face', 'm/m', missing_value=missing_value, range=(/-1.e9,1.e9/))
call diagnose_2d(Time, Grd, id_slope_y, slope_y(:,:))
id_topog_step_1 = register_static_field ('ocean_model', 'topog_step_1', Grd%tracer_axes(1:2), &
'topog_step_1', 'dimensionless', missing_value=missing_value, range=(/-1.0,1.0/))
call diagnose_2d(Time, Grd, id_topog_step_1, topog_step(:,:,1))
id_topog_step_2 = register_static_field ('ocean_model', 'topog_step_2', Grd%tracer_axes(1:2), &
'topog_step_2', 'dimensionless', missing_value=missing_value, range=(/-1.0,1.0/))
call diagnose_2d(Time, Grd, id_topog_step_2, topog_step(:,:,2))
id_topog_step_3 = register_static_field ('ocean_model', 'topog_step_3', Grd%tracer_axes(1:2), &
'topog_step_3', 'dimensionless', missing_value=missing_value, range=(/-1.0,1.0/))
call diagnose_2d(Time, Grd, id_topog_step_3, topog_step(:,:,3))
id_topog_step_4 = register_static_field ('ocean_model', 'topog_step_4', Grd%tracer_axes(1:2), &
'topog_step_4', 'dimensionless', missing_value=missing_value, range=(/-1.0,1.0/))
call diagnose_2d(Time, Grd, id_topog_step_4, topog_step(:,:,4))
allocate (id_mixdownslope(num_prog_tracers))
allocate (id_mixdownslope_on_nrho(num_prog_tracers))
id_mixdownslope_on_nrho = -1
id_mixdownslope = -1
do n=1,num_prog_tracers
if(T_prog(n)%name == 'temp') then
id_mixdownslope(n) = register_diag_field ('ocean_model', &
'mixdownslope_'//trim(T_prog(n)%name), &
Grd%tracer_axes(1:3), Time%model_time, &
'cp*mixdownslope*rho*dzt*temp', &
'Watt/m^2', missing_value=missing_value, range=(/-1.e9,1.e9/))
id_mixdownslope_on_nrho(n) = register_diag_field ('ocean_model', &
'mixdownslope_'//trim(T_prog(n)%name)//'_on_nrho', &
Dens%neutralrho_axes(1:3), Time%model_time, &
'cp*mixdownslope*rho*dzt*temp binned to neutral density', &
'Watt/m^2', missing_value=missing_value, range=(/-1.e20,1.e20/))
else
id_mixdownslope(n) = register_diag_field ('ocean_model', 'mixdownslope_'//trim(T_prog(n)%name), &
Grd%tracer_axes(1:3), Time%model_time, &
'mixdownslope*rho*dzt*tracer for '//trim(T_prog(n)%name), &
trim(T_prog(n)%flux_units), missing_value=missing_value, range=(/-1.e9,1.e9/))
id_mixdownslope_on_nrho(n) = register_diag_field ('ocean_model', &
'mixdownslope_'//trim(T_prog(n)%name)//'_on_nrho', &
Dens%neutralrho_axes(1:3), Time%model_time, &
'mixdownslope*rho*dzt*tracer for '//trim(T_prog(n)%name)//' binned to neutral density', &
trim(T_prog(n)%flux_units), missing_value=missing_value, range=(/-1.e20,1.e20/))
endif
enddo
call watermass_diag_init(Time,Dens)
if (debug_this_module) then
write(stdoutunit,*) ' '
write(stdoutunit,*) '==Global sums from initialization of ocean_mixdownslope_mod== '
call write_timestamp(Time%model_time)
write(stdoutunit,'(a,es24.17)') &
'slope_x = ',mpp_global_sum(Dom%domain2d,slope_x(:,:), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'slope_y = ',mpp_global_sum(Dom%domain2d,slope_y(:,:), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_slope_ex(1)= ',mpp_global_sum(Mixdownslope_domain%domain2d,topog_slope_ex(:,:,1), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_slope_ex(2)= ',mpp_global_sum(Mixdownslope_domain%domain2d,topog_slope_ex(:,:,2), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_slope_ex(3)= ',mpp_global_sum(Mixdownslope_domain%domain2d,topog_slope_ex(:,:,3), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_slope_ex(4)= ',mpp_global_sum(Mixdownslope_domain%domain2d,topog_slope_ex(:,:,4), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_step(1) = ',mpp_global_sum(Dom%domain2d,topog_step(:,:,1), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_step(2) = ',mpp_global_sum(Dom%domain2d,topog_step(:,:,2), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_step(3) = ',mpp_global_sum(Dom%domain2d,topog_step(:,:,3), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_step(4) = ',mpp_global_sum(Dom%domain2d,topog_step(:,:,4), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_step_ex(1) = ',mpp_global_sum(Mixdownslope_domain%domain2d,topog_step_ex(:,:,1), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_step_ex(2) = ',mpp_global_sum(Mixdownslope_domain%domain2d,topog_step_ex(:,:,2), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_step_ex(3) = ',mpp_global_sum(Mixdownslope_domain%domain2d,topog_step_ex(:,:,3), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'topog_step_ex(4) = ',mpp_global_sum(Mixdownslope_domain%domain2d,topog_step_ex(:,:,4), global_sum_flag)
endif
end subroutine ocean_mixdownslope_init
! </SUBROUTINE> NAME="ocean_mixdownslope_init"
!#######################################################################
! <SUBROUTINE NAME="mixdownslope">
!
! <DESCRIPTION>
! Compute thickness and density weighted tracer tendency [tracer*rho*m/s]
! due to exchange of tracer properties in regions where density-driven
! downslope transport is favorable.
!
! Allow for exchanges to occur over horizontally
! distant points, so long as the dense shallow parcel finds that it
! will sit on the bottom of the horizontally adjacent columns. Doing
! so requires a search algorithm, which requires some if-test logic
! as well as extended halos. Note that the halos cannot be extended
! to larger than the size of the computational domain on a processor.
! This restriction limits the extent that we can search horizontally.
!
! The rates for the exchange are functions of the topographic slope
! and the density differences between parcels.
!
! This scheme can be characterized as a slope convection based on
! logic incorporated into the overflow and overexchange schemes.
!
! </DESCRIPTION>
!
subroutine mixdownslope (Time, Thickness, T_prog, Dens, index_temp, index_salt)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(in) :: Thickness
type(ocean_prog_tracer_type), intent(inout) :: T_prog(:)
type(ocean_density_type), intent(in) :: Dens
integer, intent(in) :: index_temp
integer, intent(in) :: index_salt
integer :: tau, taum1
integer :: i, j, k, m, n, nt, npts
integer :: kmtij, ku, kd
integer :: iip0, iip1, jjq0, jjq1
integer :: iip1r, jjq1r
integer :: nm1
real :: temp_so, salt_so, press, density_check
real :: weight, arg
real :: delta, delta_rho(ijhalo)
real :: mass_sum, tmix
real :: mixdownslope_total, mixdownslope_total_r
real :: tendency
integer :: stdoutunit
stdoutunit=stdout()
if(.not. use_this_module) return
if(.not. module_is_initialized ) then
call mpp_error(FATAL, &
'==>Error from ocean_mixdownslope_mod (mixdownslope): module must be initialized')
endif
tau = Time%tau
taum1 = Time%taum1
delta_rho(:) = 0.0
! extend some fields to extended domain
rho_ex = 0.0
mass_ex = 0.0
press_ex = 0.0
temp_ex = 0.0
salt_ex = 0.0
do k=1,nk
do j=jsc,jec
do i=isc,iec
rho_ex(i,j,k) = Dens%rho(i,j,k,tau)
mass_ex(i,j,k) = Thickness%rho_dzt(i,j,k,tau)*Grd%dat(i,j)
press_ex(i,j,k) = Dens%pressure_at_depth(i,j,k)
temp_ex(i,j,k) = T_prog(index_temp)%field(i,j,k,tau)
salt_ex(i,j,k) = T_prog(index_salt)%field(i,j,k,tau)
enddo
enddo
enddo
call mpp_update_domains(rho_ex(:,:,:), Mixdownslope_domain%domain2d, complete=.false.)
call mpp_update_domains(mass_ex(:,:,:), Mixdownslope_domain%domain2d, complete=.false.)
call mpp_update_domains(press_ex(:,:,:), Mixdownslope_domain%domain2d, complete=.false.)
call mpp_update_domains(temp_ex(:,:,:), Mixdownslope_domain%domain2d, complete=.false.)
call mpp_update_domains(salt_ex(:,:,:), Mixdownslope_domain%domain2d, complete=.true.)
! compute details for cells participating in downslope mixing
! note: "so" = "shallow ocean" cell...the central point
! note: "do" = cells within "deep ocean" columns
! this part of the compuatation is independent of the tracer
kup_ex(:,:,:) = 0
kdw_ex(:,:,:,:) = 0
mixdownslope_frac(:,:,:,:) = 0.0
do j=jsc,jec
do i=isc,iec
kmtij = max(1,kmt_ex(i,j))
temp_so = temp_ex(i,j,kmtij)
salt_so = Dens%rho_salinity(i,j,kmtij,tau)
! 4-directions surrounding each cell
do m=1,4
! search for density favorable mixing
npts=0
nloop1_npts: do n=1,mixdownslope_npts
iip0 = i+ip(n-1,m)
jjq0 = j+jq(n-1,m)
iip1 = i+ip(n,m)
jjq1 = j+jq(n,m)
! check if downslope mixing is topographically possible
if(topog_step_ex(iip0,jjq0,m)==1.0) then
! check if density of shallow ocean cell > density of deep ocean cell
if(rho_ex(i,j,kmtij) > rho_ex(iip1,jjq1,kmtij)) then
! kdw = k-level in do-column where central cell is neutrally buoyant (or at bottom)
kdw_ex(i,j,n,m) = 0
kloop1 : do k=kmtij+1,kmt_ex(iip1,jjq1)
press = press_ex(iip1,jjq1,k)
density_check = density(salt_so,temp_so,press)
if(density_check > rho_ex(iip1,jjq1,k)) then
kdw_ex(i,j,n,m) = k
delta_rho(n) = density_check-rho_ex(iip1,jjq1,k)
else
exit kloop1
endif
enddo kloop1
! check that the n-parcel has a k-level greater than the n-1 parcel.
! if not, then do not mix with the n-column.
nm1 = max(n-1,1)
if(n > 1) then
if(kdw_ex(i,j,n,m) <= kdw_ex(i,j,nm1,m)) then
kdw_ex(i,j,n,m) = 0
endif
endif
! set strength of downslope mixing between central cell and n-parcel
if(kdw_ex(i,j,n,m) > 0) then
! add this cell to the number of cells participating in mixing
npts=npts+1
if(n==1) then
kup_ex(i,j,m) = kmtij
delta = rho_ex(i,j,kmtij)-rho_ex(iip1,jjq1,kmtij)
else
delta = delta_rho(n)
endif
! compute mixing weight as product of slope and density difference
mixdownslope_frac(i,j,n,m) = topog_slope_ex(iip0,jjq0,m)*delta
endif ! kdw_ex(i,j,n,m) > 0 if-test
endif ! rho_ex(i,j,k) > rho_ex(iip1,jjq1,k) if-test
endif ! topog_step_ex(iip0,jjq0,m)==1.0 if-test
! if kdw is not on the bottom, then exit n-loop since finished with search
if(kdw_ex(i,j,n,m) < kmt_ex(iip1,jjq1)) then
exit nloop1_npts
endif
enddo nloop1_npts ! n-loop for horizontal search reaching out from central point
! place more weight on the farther points to
! encourage tracer exchange further downslope.
if(mixdownslope_weight_far .and. npts > 0) then
weight = mixdownslope_frac(i,j,1,m)
do n=1,npts
arg = float((n-npts)/mixdownslope_width)
mixdownslope_frac(i,j,n,m) = weight*exp(arg)
enddo
endif
! normalize mixdownslope_frac to set fraction of
! a cell that is being mixed with central cell.
if(npts > 0) then
mixdownslope_total=0.0
do n=1,npts
mixdownslope_total = mixdownslope_total + mixdownslope_frac(i,j,n,m)
enddo
mixdownslope_total_r = 1.0/(mixdownslope_total+epsln)
do n=1,npts
mixdownslope_frac(i,j,n,m) = mixdownslope_frac(i,j,n,m)*mixdownslope_total_r
enddo
endif
! if no exchange points
if(npts==0) then
mixdownslope_frac(i,j,:,m) = 0.0
endif
enddo ! m-loop
enddo ! i-loop
enddo ! j-loop
! extend arrays to wide halos
call mpp_update_domains(kup_ex(:,:,:), Mixdownslope_domain%domain2d)
call mpp_update_domains(kdw_ex(:,:,:,:), Mixdownslope_domain%domain2d)
call mpp_update_domains(mixdownslope_frac(:,:,:,:), Mixdownslope_domain%domain2d)
! compute tracer tendency for cells participating in downslope mixing
do nt=1,num_prog_tracers
! place tracer concentration in the wider array tracer_ex
if(nt==index_temp) then
do k=1,nk
do j=jsc-ijhalo,jec+ijhalo
do i=isc-ijhalo,iec+ijhalo
tracer_ex(i,j,k) = temp_ex(i,j,k)
enddo
enddo
enddo
elseif(nt==index_salt) then
do k=1,nk
do j=jsc-ijhalo,jec+ijhalo
do i=isc-ijhalo,iec+ijhalo
tracer_ex(i,j,k) = salt_ex(i,j,k)
enddo
enddo
enddo
else
do k=1,nk
do j=jsc,jec
do i=isc,iec
tracer_ex(i,j,k) = T_prog(nt)%field(i,j,k,tau)
enddo
enddo
enddo
call mpp_update_domains (tracer_ex(:,:,:), Mixdownslope_domain%domain2d)
endif
! compute tendency, noting that each (i,j,k) cell can generally be part
! of mixing as either a central shallow cell (n=0), or as one of the deep cells (n>0).
! for the tendency, we compute a mixing tracer concentration between two cells,
! and then back-out a tendency which is placed in tend_mix.
tend_mix(:,:,:) = 0.0
do j=jsc,jec
do i=isc,iec
do m=1,4
do n=1,mixdownslope_npts
! i,j is central cell at k=ku
iip1 = i+ip(n,m)
jjq1 = j+jq(n,m)
ku = kup_ex(i,j,m)
kd = kdw_ex(i,j,n,m)
if(ku > 0 .and. kd > ku) then
mass_sum = mixdownslope_frac_central*mass_ex(i,j,ku) &
+mixdownslope_frac(i,j,n,m)*mass_ex(iip1,jjq1,kd)
tmix = (mixdownslope_frac_central*mass_ex(i,j,ku)*tracer_ex(i,j,ku) &
+mixdownslope_frac(i,j,n,m)*mass_ex(iip1,jjq1,kd)*tracer_ex(iip1,jjq1,kd)) &
/mass_sum
tendency = dtimer*mixdownslope_frac_central*mass_ex(i,j,ku)/Grd%dat(i,j) &
*(tmix-tracer_ex(i,j,ku))
tend_mix(i,j,ku) = tend_mix(i,j,ku) + tendency
endif
! i,j is deep cell at k=kd
iip1r = i-ip(n,m)
jjq1r = j-jq(n,m)
ku = kup_ex(iip1r,jjq1r,m)
kd = kdw_ex(iip1r,jjq1r,n,m)
if(ku > 0 .and. kd > ku) then
mass_sum = mixdownslope_frac_central*mass_ex(iip1r,jjq1r,ku) &
+mixdownslope_frac(iip1r,jjq1r,n,m)*mass_ex(i,j,kd)
tmix = (mixdownslope_frac_central &
*mass_ex(iip1r,jjq1r,ku)*tracer_ex(iip1r,jjq1r,ku) &
+mixdownslope_frac(iip1r,jjq1r,n,m) &
*mass_ex(i,j,kd)*tracer_ex(i,j,kd)) &
/mass_sum
tendency = dtimer*mixdownslope_frac(iip1r,jjq1r,n,m)*mass_ex(i,j,kd)/Grd%dat(i,j) &
*(tmix-tracer_ex(i,j,kd))
tend_mix(i,j,kd) = tend_mix(i,j,kd) + tendency
endif
enddo ! n-loop
enddo ! m-loop
enddo ! i-loop
enddo ! j-loop
! fill tracer tendency array
do k=1,nk
do j=jsc,jec
do i=isc,iec
T_prog(nt)%th_tendency(i,j,k) = T_prog(nt)%th_tendency(i,j,k) &
+tend_mix(i,j,k)*mixdownslope_mask(i,j)
enddo
enddo
enddo
if(id_mixdownslope(nt) > 0 .or. id_mixdownslope_on_nrho(nt) > 0) then
wrk1(:,:,:) = 0.0
do k=1,nk
do j=jsc,jec
do i=isc,iec
wrk1(i,j,k) = tend_mix(i,j,k)*mixdownslope_mask(i,j)*T_prog(nt)%conversion
enddo
enddo
enddo
if (id_mixdownslope(nt) > 0) then
call diagnose_3d(Time, Grd, id_mixdownslope(nt), wrk1(:,:,:))
endif
if (id_mixdownslope_on_nrho(nt) > 0) then
call diagnose_3d_rho(Time, Dens, id_mixdownslope_on_nrho(nt), wrk1)
endif
endif
if(nt==index_temp) then
theta_tend(:,:,:) = 0.0
do k=1,nk
do j=jsc,jec
do i=isc,iec
theta_tend(i,j,k) = tend_mix(i,j,k)*mixdownslope_mask(i,j)
enddo
enddo
enddo
endif
if(nt==index_salt) then
salt_tend(:,:,:) = 0.0
do k=1,nk
do j=jsc,jec
do i=isc,iec
salt_tend(i,j,k) = tend_mix(i,j,k)*mixdownslope_mask(i,j)
enddo
enddo
enddo
endif
if(debug_this_module) then
write(stdoutunit,*) ' '
write(stdoutunit,*) '==Global sums for tendency from ocean_mixdownslope_mod== '
call write_timestamp(Time%model_time)
do k=1,nk
area_k(:,:) = Grd%dat(:,:)*Grd%tmask(:,:,k)
tend_mix(:,:,k) = dtime*tend_mix(:,:,k)*area_k(:,:)*T_prog(nt)%conversion
write(stdoutunit,'(a,i2,a,i2,a,es24.17)') 'tend_mix(',nt,',',k,') = ',&
mpp_global_sum(Dom%domain2d,tend_mix(:,:,k))
enddo
write(stdoutunit,'(a,i2,a,es24.17)') &
'tend_mix(',nt,') = ',&
mpp_global_sum(Dom%domain2d,tend_mix(:,:,:), global_sum_flag)
endif
enddo ! nt-end for num_prog_tracers
call watermass_diag(Time, Dens)
if (debug_this_module) then
write(stdoutunit,*) ' '
write(stdoutunit,*) '==Global sums from ocean_mixdownslope_mod== '
call write_timestamp(Time%model_time)
write(stdoutunit,'(a,es24.17)') &
'rho_ex = ',&
mpp_global_sum(Mixdownslope_domain%domain2d,rho_ex(:,:,:), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'mass_ex = ',&
mpp_global_sum(Mixdownslope_domain%domain2d,mass_ex(:,:,:), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'press_ex = ',&
mpp_global_sum(Mixdownslope_domain%domain2d,press_ex(:,:,:), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'temp_ex = ',&
mpp_global_sum(Mixdownslope_domain%domain2d,temp_ex(:,:,:), global_sum_flag)
write(stdoutunit,'(a,es24.17)') &
'salt_ex = ',&
mpp_global_sum(Mixdownslope_domain%domain2d,salt_ex(:,:,:), global_sum_flag)
write(stdoutunit,'(a,i24)') &
'kmt_ex = ',&
mpp_global_sum(Mixdownslope_domain%domain2d,kmt_ex(:,:), global_sum_flag)
do m=1,4
write(stdoutunit,'(a,i24)') &
'kup_ex = ', &
mpp_global_sum(Mixdownslope_domain%domain2d,kup_ex(:,:,m), global_sum_flag)
do n=1,mixdownslope_npts
write(stdoutunit,'(a,es24.17)') &
'mixdownslope_frac = ', &
mpp_global_sum(Mixdownslope_domain%domain2d,mixdownslope_frac(:,:,n,m), global_sum_flag)
write(stdoutunit,'(a,i24)') &
'kdw_ex = ', &
mpp_global_sum(Mixdownslope_domain%domain2d,kdw_ex(:,:,n,m), global_sum_flag)
enddo
enddo
write(stdoutunit,*) ' '
write(stdoutunit,*) '==Global check sums from ocean_mixdownslope_mod== '
call write_timestamp(Time%model_time)
call write_chksum_3d('rho_ex', rho_ex(COMP,:))
call write_chksum_3d('mass_ex', mass_ex(COMP,:))
call write_chksum_3d('press_ex', press_ex(COMP,:))
call write_chksum_3d('temp_ex', temp_ex(COMP,:))
call write_chksum_3d('salt_ex', salt_ex(COMP,:))
call write_chksum_2d_int('kmt_ex', kmt_ex(COMP))
do m=1,4
call write_chksum_2d_int('kup_ex', kup_ex(COMP,m))
do n=1,mixdownslope_npts
call write_chksum_2d_int('kdw_ex', kdw_ex(COMP,n,m))
call write_chksum_2d('mixdownslope_frac', mixdownslope_frac(COMP,n,m))
enddo
enddo
endif
end subroutine mixdownslope
! </SUBROUTINE> NAME="mixdownslope"
!#######################################################################
! <SUBROUTINE NAME="watermass_diag_init">
!
! <DESCRIPTION>
! Initialization of watermass diagnostic output files.
! </DESCRIPTION>
!
subroutine watermass_diag_init(Time, Dens)
type(ocean_time_type), intent(in) :: Time
type(ocean_density_type), intent(in) :: Dens
integer :: stdoutunit
stdoutunit=stdout()
compute_watermass_diag = .false.
id_neut_rho_mixdown = register_diag_field ('ocean_model', 'neut_rho_mixdown',&
Grd%tracer_axes(1:3), Time%model_time, &
'update of locally referenced potential density from mixdowslope', &
'(kg/m^3)/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_neut_rho_mixdown > 0) compute_watermass_diag = .true.
id_wdian_rho_mixdown = register_diag_field ('ocean_model', 'wdian_rho_mixdown',&
Grd%tracer_axes(1:3), Time%model_time, &
'dianeutral mass transport due to mixdowslope', &
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_wdian_rho_mixdown > 0) compute_watermass_diag = .true.
id_tform_rho_mixdown = register_diag_field ('ocean_model', 'tform_rho_mixdown',&
Grd%tracer_axes(1:3), Time%model_time, &
'watermass transform due to mixdowslope on levels (pre-layer binning)', &
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_tform_rho_mixdown > 0) compute_watermass_diag = .true.
id_neut_rho_mixdown_on_nrho = register_diag_field ('ocean_model', &
'neut_rho_mixdown_on_nrho', Dens%neutralrho_axes(1:3), Time%model_time, &
'update of local ref potrho from mixdownslope as binned to neutral density layers',&
'(kg/m^3)/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_neut_rho_mixdown_on_nrho > 0) compute_watermass_diag = .true.
id_wdian_rho_mixdown_on_nrho = register_diag_field ('ocean_model', &
'wdian_rho_mixdown_on_nrho', Dens%neutralrho_axes(1:3), Time%model_time, &
'dianeutral mass transport due to mixdowslope as binned to neutral density layers',&
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_wdian_rho_mixdown_on_nrho > 0) compute_watermass_diag = .true.
id_tform_rho_mixdown_on_nrho = register_diag_field ('ocean_model', &
'tform_rho_mixdown_on_nrho', Dens%neutralrho_axes(1:3), Time%model_time, &
'watermass transform due to mixdowslope as binned to neutral density layers',&
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_tform_rho_mixdown_on_nrho > 0) compute_watermass_diag = .true.
id_eta_tend_mixdown= -1
id_eta_tend_mixdown= register_diag_field ('ocean_model','eta_tend_mixdown',&
Grd%tracer_axes(1:2), Time%model_time, &
'non-Bouss steric sea level tendency from mixdown tendency', 'm/s', &
missing_value=missing_value, range=(/-1e10,1.e10/))
if(id_eta_tend_mixdown > 0) compute_watermass_diag=.true.
id_eta_tend_mixdown_glob= -1
id_eta_tend_mixdown_glob= register_diag_field ('ocean_model', 'eta_tend_mixdown_glob',&
Time%model_time, &
'global mean non-bouss steric sea level tendency from mixdown tendency', &
'm/s', missing_value=missing_value, range=(/-1e10,1.e10/))
if(id_eta_tend_mixdown_glob > 0) compute_watermass_diag=.true.
! temp contributions
id_neut_temp_mixdown = register_diag_field ('ocean_model', 'neut_temp_mixdown', &
Grd%tracer_axes(1:3), Time%model_time, &
'temp related update of locally referenced potential density from mixdowslope',&
'(kg/m^3)/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_neut_temp_mixdown > 0) compute_watermass_diag = .true.
id_wdian_temp_mixdown = register_diag_field ('ocean_model', 'wdian_temp_mixdown',&
Grd%tracer_axes(1:3), Time%model_time, &
'temp related dianeutral mass transport due to mixdowslope', &
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_wdian_temp_mixdown > 0) compute_watermass_diag = .true.
id_tform_temp_mixdown = register_diag_field ('ocean_model', 'tform_temp_mixdown', &
Grd%tracer_axes(1:3), Time%model_time, &
'temp related watermass transform due to mixdowslope on levels (pre-layer binning)',&
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_tform_temp_mixdown > 0) compute_watermass_diag = .true.
id_neut_temp_mixdown_on_nrho = register_diag_field ('ocean_model', &
'neut_temp_mixdown_on_nrho', Dens%neutralrho_axes(1:3), Time%model_time, &
'temp related update of local ref potrho from mixdownslope as binned to neutral density layers',&
'(kg/m^3)/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_neut_temp_mixdown_on_nrho > 0) compute_watermass_diag = .true.
id_wdian_temp_mixdown_on_nrho = register_diag_field ('ocean_model', &
'wdian_temp_mixdown_on_nrho', Dens%neutralrho_axes(1:3), Time%model_time, &
'temp related dianeutral mass transport due to mixdowslope as binned to neutral density layers',&
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_wdian_temp_mixdown_on_nrho > 0) compute_watermass_diag = .true.
id_tform_temp_mixdown_on_nrho = register_diag_field ('ocean_model', &
'tform_temp_mixdown_on_nrho', Dens%neutralrho_axes(1:3), Time%model_time, &
'temp related watermass transform due to mixdowslope as binned to neutral density layers',&
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_tform_temp_mixdown_on_nrho > 0) compute_watermass_diag = .true.
! salt contributions
id_neut_salt_mixdown = register_diag_field ('ocean_model', 'neut_salt_mixdown', &
Grd%tracer_axes(1:3), Time%model_time, &
'salt related update of locally referenced potential density from mixdowslope',&
'(kg/m^3)/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_neut_salt_mixdown > 0) compute_watermass_diag = .true.
id_wdian_salt_mixdown = register_diag_field ('ocean_model', 'wdian_salt_mixdown',&
Grd%tracer_axes(1:3), Time%model_time, &
'salt related dianeutral mass transport due to mixdowslope', &
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_wdian_salt_mixdown > 0) compute_watermass_diag = .true.
id_tform_salt_mixdown = register_diag_field ('ocean_model', 'tform_salt_mixdown', &
Grd%tracer_axes(1:3), Time%model_time, &
'salt related watermass transform due to mixdowslope on levels (pre-layer binning)',&
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_tform_salt_mixdown > 0) compute_watermass_diag = .true.
id_neut_salt_mixdown_on_nrho = register_diag_field ('ocean_model', &
'neut_salt_mixdown_on_nrho', Dens%neutralrho_axes(1:3), Time%model_time, &
'salt related update of local ref potrho from mixdownslope as binned to neutral density layers',&
'(kg/m^3)/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_neut_salt_mixdown_on_nrho > 0) compute_watermass_diag = .true.
id_wdian_salt_mixdown_on_nrho = register_diag_field ('ocean_model', &
'wdian_salt_mixdown_on_nrho', Dens%neutralrho_axes(1:3), Time%model_time, &
'salt related dianeutral mass transport due to mixdowslope as binned to neutral density layers',&
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_wdian_salt_mixdown_on_nrho > 0) compute_watermass_diag = .true.
id_tform_salt_mixdown_on_nrho = register_diag_field ('ocean_model', &
'tform_salt_mixdown_on_nrho', Dens%neutralrho_axes(1:3), Time%model_time, &
'salt related watermass transform due to mixdowslope as binned to neutral density layers',&
'kg/sec', missing_value=missing_value, range=(/-1.e10,1.e10/))
if(id_tform_salt_mixdown_on_nrho > 0) compute_watermass_diag = .true.
allocate(theta_tend(isd:ied,jsd:jed,nk))
allocate(salt_tend(isd:ied,jsd:jed,nk))
theta_tend(:,:,:) = 0.0
salt_tend(:,:,:) = 0.0
if(compute_watermass_diag) then
write(stdoutunit,'(/a/)') &
'==>Note: running ocean_mixdownslope_mod w/ compute_watermass_diag=.true. to compute some watermass diagnostics.'
endif
end subroutine watermass_diag_init
! </SUBROUTINE> NAME="watermass_diag_init"
!#######################################################################
! <SUBROUTINE NAME="watermass_diag">
!
! <DESCRIPTION>
! Diagnose effects from mixdownslope on the watermass transformation.
! </DESCRIPTION>
!
subroutine watermass_diag(Time, Dens)
type(ocean_time_type), intent(in) :: Time
type(ocean_density_type), intent(in) :: Dens
integer :: i,j,k,tau
real, dimension(isd:ied,jsd:jed) :: eta_tend
if (.not. module_is_initialized) then
call mpp_error(FATAL, &
'==>Error from ocean_mixdownslope (watermass_diag): module needs initialization ')
endif
if(.not. compute_watermass_diag) return
tau = Time%tau
! rho diagnostics = sum of temp + salt contributions
wrk1(:,:,:) = 0.0
wrk2(:,:,:) = 0.0
wrk3(:,:,:) = 0.0
wrk4(:,:,:) = 0.0
wrk5(:,:,:) = 0.0
do k=1,nk
do j=jsc,jec
do i=isc,iec
wrk1(i,j,k) = Grd%tmask(i,j,k)* &
(Dens%drhodT(i,j,k)*theta_tend(i,j,k)+Dens%drhodS(i,j,k)*salt_tend(i,j,k))
wrk2(i,j,k) = wrk1(i,j,k)*Dens%rho_dztr_tau(i,j,k)
wrk3(i,j,k) = wrk2(i,j,k)*Dens%stratification_factor(i,j,k)
wrk4(i,j,k) = wrk1(i,j,k)*Grd%dat(i,j)*Dens%watermass_factor(i,j,k)
wrk5(i,j,k) =-wrk1(i,j,k)/(epsln+Dens%rho(i,j,k,tau)**2) ! for eta_tend
enddo
enddo
enddo
call diagnose_3d(Time, Grd, id_neut_rho_mixdown, wrk2(:,:,:))
call diagnose_3d(Time, Grd, id_wdian_rho_mixdown, wrk3(:,:,:))
call diagnose_3d(Time, Grd, id_tform_rho_mixdown, wrk4(:,:,:))
call diagnose_3d_rho(Time, Dens, id_neut_rho_mixdown_on_nrho, wrk2)
call diagnose_3d_rho(Time, Dens, id_wdian_rho_mixdown_on_nrho, wrk3)
call diagnose_3d_rho(Time, Dens, id_tform_rho_mixdown_on_nrho, wrk4)
if(id_eta_tend_mixdown > 0 .or. id_eta_tend_mixdown_glob > 0) then
eta_tend(:,:) = 0.0
do k=1,nk
do j=jsc,jec
do i=isc,iec
eta_tend(i,j) = eta_tend(i,j) + wrk5(i,j,k)
enddo
enddo
enddo
call diagnose_2d(Time, Grd, id_eta_tend_mixdown, eta_tend(:,:))
call diagnose_sum(Time, Grd, Dom, id_eta_tend_mixdown_glob, eta_tend, cellarea_r)
endif
! temp contributions
wrk1(:,:,:) = 0.0
wrk2(:,:,:) = 0.0
wrk3(:,:,:) = 0.0
wrk4(:,:,:) = 0.0
do k=1,nk
do j=jsc,jec
do i=isc,iec
wrk1(i,j,k) = Grd%tmask(i,j,k)*Dens%drhodT(i,j,k)*theta_tend(i,j,k)
wrk2(i,j,k) = wrk1(i,j,k)*Dens%rho_dztr_tau(i,j,k)
wrk3(i,j,k) = wrk2(i,j,k)*Dens%stratification_factor(i,j,k)
wrk4(i,j,k) = wrk1(i,j,k)*Grd%dat(i,j)*Dens%watermass_factor(i,j,k)
enddo
enddo
enddo
call diagnose_3d(Time, Grd, id_neut_temp_mixdown, wrk2(:,:,:))
call diagnose_3d(Time, Grd, id_wdian_temp_mixdown, wrk3(:,:,:))
call diagnose_3d(Time, Grd, id_tform_temp_mixdown, wrk4(:,:,:))
call diagnose_3d_rho(Time, Dens, id_neut_temp_mixdown_on_nrho, wrk2)
call diagnose_3d_rho(Time, Dens, id_wdian_temp_mixdown_on_nrho, wrk3)
call diagnose_3d_rho(Time, Dens, id_tform_temp_mixdown_on_nrho, wrk4)
! salinity contributions
wrk1(:,:,:) = 0.0
wrk2(:,:,:) = 0.0
wrk3(:,:,:) = 0.0
wrk4(:,:,:) = 0.0
do k=1,nk
do j=jsc,jec
do i=isc,iec
wrk1(i,j,k) = Grd%tmask(i,j,k)*Dens%drhodS(i,j,k)*salt_tend(i,j,k)
wrk2(i,j,k) = wrk1(i,j,k)*Dens%rho_dztr_tau(i,j,k)
wrk3(i,j,k) = wrk2(i,j,k)*Dens%stratification_factor(i,j,k)
wrk4(i,j,k) = wrk1(i,j,k)*Grd%dat(i,j)*Dens%watermass_factor(i,j,k)
enddo
enddo
enddo
call diagnose_3d(Time, Grd, id_neut_salt_mixdown, wrk2(:,:,:))
call diagnose_3d(Time, Grd, id_wdian_salt_mixdown, wrk3(:,:,:))
call diagnose_3d(Time, Grd, id_tform_salt_mixdown, wrk4(:,:,:))
call diagnose_3d_rho(Time, Dens, id_neut_salt_mixdown_on_nrho, wrk2)
call diagnose_3d_rho(Time, Dens, id_wdian_salt_mixdown_on_nrho, wrk3)
call diagnose_3d_rho(Time, Dens, id_tform_salt_mixdown_on_nrho, wrk4)
end subroutine watermass_diag
! </SUBROUTINE> NAME="watermass_diag"
end module ocean_mixdownslope_mod
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ngmath/src/examples/enatgrid/nnplotf.f | 1 | 7176 |
SUBROUTINE DRWCON(NX,NY,XI,YI,ZDAT)
C
C Use the NCAR Graphics CONPACK package to draw a color contour
C plot of the data in ZDAT.
C
C Define the error file, the Fortran unit number, the workstation type,
C and the workstation ID to be used in calls to GKS routines.
C
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1) ! NCGM
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=8, IWKID=1) ! X Windows
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=11, IWKID=1) ! PDF
C PARAMETER (IERRF=6, LUNIT=2, IWTYPE=20, IWKID=1) ! PostScript
C
PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1)
C
DIMENSION ZDAT(NX,NY)
DIMENSION RWRK(2000),IWRK(1000),IAMA(20000)
DIMENSION XCRA(1000),YCRA(1000),IAIA(10),IGIA(10)
C
EXTERNAL CPCOLR,CPDRPL
C
C Open GKS if not open; open and activate a workstation; define
C some colors.
C
JTYPE = IWTYPE
CALL GQOPS(ISTATE)
IF (ISTATE .EQ. 0) THEN
CALL GOPKS (IERRF, ISZDM)
IF (JTYPE .EQ. 1) THEN
CALL NGSETC('ME','con.ncgm')
ELSE IF ( (JTYPE .GE. 20) .AND. (JTYPE .LE. 31) ) THEN
CALL NGSETC('ME','con.ps')
ENDIF
CALL GOPWK (IWKID, LUNIT, JTYPE)
CALL GACWK (IWKID)
CALL GSCR(IWKID, 0, 1.00, 1.00, 1.00)
CALL GSCR(IWKID, 1, 0.00, 0.00, 0.00)
CALL GSCR(IWKID, 2, 0.00, 1.00, 1.00)
CALL GSCR(IWKID, 3, 0.00, 1.00, 0.00)
CALL GSCR(IWKID, 4, 0.70, 1.00, 0.00)
CALL GSCR(IWKID, 5, 1.00, 1.00, 0.00)
CALL GSCR(IWKID, 6, 1.00, 0.75, 0.00)
CALL GSCR(IWKID, 7, 1.00, 0.50, 0.50)
CALL GSCR(IWKID, 8, 1.00, 0.00, 0.00)
ENDIF
C
IERR = 0
C
CALL CPSETI('CLS - CONTOUR LEVEL SELECTOR',0)
CALL CPSETI('NCL - NUMBER OF CONTOUR LEVELS',7)
C
DO 103 I=1,7
CALL CPSETI('PAI - parameter array index',I)
CALL CPSETR('CLV - contour level',10.*REAL(I))
CALL CPSETI('CLU - contour level use',3)
CALL CPSETI('LLC - contour label color',1)
103 CONTINUE
C
C Initialize the drawing of the contour plot.
C
CALL CPSETR('VPL - viewport left',0.05)
CALL CPSETR('VPR - viewport right',0.95)
CALL CPSETR('VPB - viewport bottom',0.05)
CALL CPSETR('VPT - viewport top',0.95)
CALL PCSETI('FN - font number (Helvetica bold)' ,22)
CALL PCSETI('CC - font color',1)
CALL CPSETR('T2D - tension of 2D splines',4.)
CALL CPSETI('LLP - line label positioning, penalty scheme',3)
CALL CPSETI('LLO - line label orientation',1)
CALL CPSETC('LOT - low labels off',' ')
CALL CPSETR('CWM - character width multiplier',2.5)
CALL CPSETC('ILT - informational label off',' ')
CALL CPRECT(ZDAT,NX,NX,NY,RWRK,2000,IWRK,1000)
C
C Initialize the area map and put the contour lines into it.
C
CALL ARINAM (IAMA,20000)
CALL CPCLAM (ZDAT,RWRK,IWRK,IAMA)
CALL CPLBAM (ZDAT,RWRK,IWRK,IAMA)
C
C Color the map.
C
CALL ARSCAM (IAMA,XCRA,YCRA,1000,IAIA,IGIA,7,CPCOLR)
C
C Put black contour lines over the colored map.
C
CALL GSPLCI (1)
CALL CPCLDM (ZDAT,RWRK,IWRK,IAMA,CPDRPL)
CALL CPLBDR (ZDAT,RWRK,IWRK)
CALL PERIM(1,0,1,0)
C
CALL FRAME
C
C Close down GKS.
C
IF (ISTATE .EQ. 0) THEN
CALL GDAWK (IWKID)
CALL GCLWK (IWKID)
CALL GCLKS
ENDIF
C
RETURN
END
SUBROUTINE CPCOLR (XCRA,YCRA,NCRA,IAIA,IGIA,NAIA)
C
DIMENSION XCRA(*),YCRA(*),IAIA(*),IGIA(*)
C
DO 102 I=1,NAIA
IF (IGIA(I) .EQ. 3) IFLL = IAIA(I)
102 CONTINUE
IF (IFLL.GE.1 .AND. IFLL.LE.8) THEN
CALL GSFACI (IFLL+1)
CALL GFA (NCRA-1,XCRA,YCRA)
END IF
C
RETURN
END
SUBROUTINE DRWSRF(NX,NY,X,Y,Z,S1,S2,S3,IWK)
C
C Procedure DRWSRF uses the NCAR Graphics function SRFACE to
C draw a surface plot of the data values in Z.
C
C The point of observation is calculated from the 3D coordinate
C (S1, S2, S3); the point looked at is the center of the surface.
C
C NX - Dimension of the X-axis variable X.
C NY - Dimension of the Y-axis variable Y.
C X - An array of X-axis values.
C Y - An array of Y-axis values.
C Z - An array dimensioned for NX x NY containing data
C values for each (X,Y) coordinate.
C S1 - X value for the eye position.
C S2 - Y value for the eye position.
C S3 - Z value for the eye position.
C IWK - Work space dimensioned for at least 2*NX*NY.
C
C
DIMENSION X(NX),Y(NY),Z(NX,NY),IWK(*)
C
PARAMETER (IERRF=6, LUNIT=2, IWKID=1, IWTYPE=8)
DIMENSION S(6)
C
C Open GKS, open and activate a workstation.
C
JTYPE = IWTYPE
CALL GQOPS(ISTATE)
IF (ISTATE .EQ. 0) THEN
CALL GOPKS (IERRF, ISZDM)
IF (JTYPE .EQ. 1) THEN
CALL NGSETC('ME','srf.ncgm')
ELSE IF ( (JTYPE .GE. 20) .AND. (JTYPE .LE. 31) ) THEN
CALL NGSETC('ME','srf.ps')
ENDIF
CALL GOPWK (IWKID, LUNIT, JTYPE)
CALL GSCR(IWKID,0,1.,1.,1.)
CALL GSCR(IWKID,1,0.,0.,0.)
CALL GACWK (IWKID)
ENDIF
C
C Find the extreme values.
C
XMN = X(1)
XMX = X(1)
YMN = Y(1)
YMX = Y(1)
ZMN = Z(1,1)
ZMX = Z(1,1)
C
DO 10 I=2,NX
XMN = MIN(XMN,X(I))
XMX = MAX(XMX,X(I))
10 CONTINUE
C
DO 11 I=1,NY
YMN = MIN(YMN,Y(I))
YMX = MAX(YMX,Y(I))
11 CONTINUE
C
DO 12 I=1,NX
DO 13 J=1,NY
ZMN = MIN(ZMN,Z(I,J))
ZMX = MAX(ZMX,Z(I,J))
13 CONTINUE
12 CONTINUE
C
IF (S1.EQ.0. .AND. S2.EQ.0. .AND. S3.EQ.0.) THEN
ST1 = -3.
ST2 = -1.5
ST3 = 0.75
ELSE
ST1 = S1
ST2 = S2
ST3 = S3
ENDIF
S(1) = 5.*ST1*(XMX-XMN)
S(2) = 5.*ST2*(YMX-YMN)
S(3) = 5.*ST3*(ZMX-ZMN)
S(4) = 0.5*(XMX-XMN)
S(5) = 0.5*(YMX-YMN)
S(6) = 0.5*(ZMX-ZMN)
C
CALL SRFACE (X,Y,Z,IWK,NX,NX,NY,S,0.)
C
C Close down GKS.
C
IF (ISTATE .EQ. 0) THEN
CALL GDAWK (IWKID)
CALL GCLWK (IWKID)
CALL GCLKS
ENDIF
C
RETURN
END
SUBROUTINE DRWVCT(LX,LY,U,V)
C
C Where U and V are 2D arrays, this subroutine uses NCAR Graphics to
C draw a vector plot of the vectors (U(I,J),V(I,J))
C for I=1,LX and J=1,LY.
C
DIMENSION U(LX,LY),V(LX,LY)
PARAMETER (IERRF=6, LUNIT=2, IWKID=1, IWTYPE=8)
C
JTYPE = IWTYPE
CALL GQOPS(ISTATE)
IF (ISTATE .EQ. 0) THEN
CALL GOPKS (IERRF, ISZDM)
IF (JTYPE .EQ. 1) THEN
CALL NGSETC('ME','vec.ncgm')
ELSE IF ( (JTYPE .GE. 20) .AND. (JTYPE .LE. 31) ) THEN
CALL NGSETC('ME','vec.ps')
ENDIF
CALL GOPWK (IWKID, LUNIT, JTYPE)
CALL GACWK (IWKID)
CALL GSCR(IWKID, 0, 1.00, 1.00, 1.00)
CALL GSCR(IWKID, 1, 0.00, 0.00, 0.00)
ENDIF
C
CALL VVINIT(U,LX,V,LY,PDUM,1,LX,LY,WRK,1)
CALL VVSETC('MNT',' ')
CALL VVSETC('MXT',' ')
CALL VVECTR(U,V,P,IAM,VVMSKD,WRK)
CALL FRAME
C
IF (ISTATE .EQ. 0) THEN
CALL GDAWK (IWKID)
CALL GCLWK (IWKID)
CALL GCLKS
ENDIF
C
RETURN
END
| gpl-2.0 |
TApplencourt/quantum_package | src/davidson/davidson_parallel.irp.f | 1 | 16170 | use bitmasks
use f77_zmq
subroutine davidson_slave_inproc(i)
implicit none
integer, intent(in) :: i
call davidson_run_slave(1,i)
end
subroutine davidson_slave_tcp(i)
implicit none
integer, intent(in) :: i
call davidson_run_slave(0,i)
end
subroutine davidson_run_slave(thread,iproc)
use f77_zmq
implicit none
BEGIN_DOC
! Slave routine for Davidson's diagonalization.
END_DOC
integer, intent(in) :: thread, iproc
integer :: worker_id, task_id, blockb
integer(ZMQ_PTR),external :: new_zmq_to_qp_run_socket
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
integer(ZMQ_PTR), external :: new_zmq_push_socket
integer(ZMQ_PTR) :: zmq_socket_push
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
integer, external :: connect_to_taskserver
if (connect_to_taskserver(zmq_to_qp_run_socket,worker_id,thread) == -1) then
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
endif
zmq_socket_push = new_zmq_push_socket(thread)
call davidson_slave_work(zmq_to_qp_run_socket, zmq_socket_push, N_states_diag, N_det, worker_id)
integer, external :: disconnect_from_taskserver
if (disconnect_from_taskserver(zmq_to_qp_run_socket,worker_id) == -1) then
continue
endif
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
call end_zmq_push_socket(zmq_socket_push,thread)
end subroutine
subroutine davidson_slave_work(zmq_to_qp_run_socket, zmq_socket_push, N_st, sze, worker_id)
use f77_zmq
implicit none
integer(ZMQ_PTR),intent(in) :: zmq_to_qp_run_socket
integer(ZMQ_PTR),intent(in) :: zmq_socket_push
integer,intent(in) :: worker_id, N_st, sze
integer :: task_id
character*(512) :: msg
integer :: imin, imax, ishift, istep
integer, allocatable :: psi_det_read(:,:,:)
double precision, allocatable :: v_t(:,:), s_t(:,:), u_t(:,:)
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: u_t, v_t, s_t
! Get wave function (u_t)
! -----------------------
integer :: rc, ni, nj
integer*8 :: rc8
integer :: N_states_read, N_det_read, psi_det_size_read
integer :: N_det_selectors_read, N_det_generators_read
double precision, allocatable :: energy(:)
integer, external :: zmq_get_dvector
integer, external :: zmq_get_dmatrix
PROVIDE psi_det_beta_unique psi_bilinear_matrix_order_transp_reverse psi_det_alpha_unique
PROVIDE psi_bilinear_matrix_transp_values psi_bilinear_matrix_values psi_bilinear_matrix_columns_loc
PROVIDE ref_bitmask_energy nproc
PROVIDE mpi_initialized
allocate(u_t(N_st,N_det))
allocate (energy(N_st))
! Warning : dimensions are modified for efficiency, It is OK since we get the
! full matrix
if (size(u_t,kind=8) < 8388608_8) then
ni = size(u_t)
nj = 1
else
ni = 8388608
nj = int(size(u_t,kind=8)/8388608_8,4) + 1
endif
do while (zmq_get_dmatrix(zmq_to_qp_run_socket, worker_id, 'u_t', u_t, ni, nj, size(u_t,kind=8)) == -1)
call sleep(1)
print *, irp_here, ': waiting for u_t...'
enddo
if (zmq_get_dvector(zmq_to_qp_run_socket, worker_id, 'energy', energy, size(energy)) == -1) then
print *, irp_here, ': Unable to get energy'
deallocate(u_t,energy)
return
endif
IRP_IF MPI
include 'mpif.h'
integer :: ierr
call broadcast_chunks_double(u_t,size(u_t,kind=8))
IRP_ENDIF
! Run tasks
! ---------
allocate(v_t(N_st,N_det), s_t(N_st,N_det))
do
integer, external :: get_task_from_taskserver
integer, external :: task_done_to_taskserver
if (get_task_from_taskserver(zmq_to_qp_run_socket,worker_id, task_id, msg) == -1) then
exit
endif
if(task_id == 0) exit
read (msg,*) imin, imax, ishift, istep
integer :: k
do k=imin,imax
v_t(:,k) = 0.d0
s_t(:,k) = 0.d0
enddo
call H_S2_u_0_nstates_openmp_work(v_t,s_t,u_t,N_st,N_det,imin,imax,ishift,istep)
if (task_done_to_taskserver(zmq_to_qp_run_socket,worker_id,task_id) == -1) then
print *, irp_here, 'Unable to send task_done'
endif
call davidson_push_results(zmq_socket_push, v_t, s_t, imin, imax, task_id)
end do
deallocate(u_t,v_t, s_t)
end subroutine
subroutine davidson_push_results(zmq_socket_push, v_t, s_t, imin, imax, task_id)
use f77_zmq
implicit none
BEGIN_DOC
! Push the results of $H|U \rangle$ from a worker to the master.
END_DOC
integer(ZMQ_PTR) ,intent(in) :: zmq_socket_push
integer ,intent(in) :: task_id, imin, imax
double precision ,intent(in) :: v_t(N_states_diag,N_det)
double precision ,intent(in) :: s_t(N_states_diag,N_det)
integer :: rc, sz
integer*8 :: rc8
sz = (imax-imin+1)*N_states_diag
rc = f77_zmq_send( zmq_socket_push, task_id, 4, ZMQ_SNDMORE)
if(rc /= 4) stop 'davidson_push_results failed to push task_id'
rc = f77_zmq_send( zmq_socket_push, imin, 4, ZMQ_SNDMORE)
if(rc /= 4) stop 'davidson_push_results failed to push imin'
rc = f77_zmq_send( zmq_socket_push, imax, 4, ZMQ_SNDMORE)
if(rc /= 4) stop 'davidson_push_results failed to push imax'
rc8 = f77_zmq_send8( zmq_socket_push, v_t(1,imin), 8_8*sz, ZMQ_SNDMORE)
if(rc8 /= 8_8*sz) stop 'davidson_push_results failed to push vt'
rc8 = f77_zmq_send8( zmq_socket_push, s_t(1,imin), 8_8*sz, 0)
if(rc8 /= 8_8*sz) stop 'davidson_push_results failed to push st'
! Activate is zmq_socket_push is a REQ
IRP_IF ZMQ_PUSH
IRP_ELSE
character*(2) :: ok
rc = f77_zmq_recv( zmq_socket_push, ok, 2, 0)
if ((rc /= 2).and.(ok(1:2)/='ok')) then
print *, irp_here, ': f77_zmq_recv( zmq_socket_push, ok, 2, 0)'
stop -1
endif
IRP_ENDIF
end subroutine
subroutine davidson_pull_results(zmq_socket_pull, v_t, s_t, imin, imax, task_id)
use f77_zmq
implicit none
BEGIN_DOC
! Pull the results of $H|U \rangle$ on the master.
END_DOC
integer(ZMQ_PTR) ,intent(in) :: zmq_socket_pull
integer ,intent(out) :: task_id, imin, imax
double precision ,intent(out) :: v_t(N_states_diag,N_det)
double precision ,intent(out) :: s_t(N_states_diag,N_det)
integer :: rc, sz
integer*8 :: rc8
rc = f77_zmq_recv( zmq_socket_pull, task_id, 4, 0)
if(rc /= 4) stop 'davidson_pull_results failed to pull task_id'
rc = f77_zmq_recv( zmq_socket_pull, imin, 4, 0)
if(rc /= 4) stop 'davidson_pull_results failed to pull imin'
rc = f77_zmq_recv( zmq_socket_pull, imax, 4, 0)
if(rc /= 4) stop 'davidson_pull_results failed to pull imax'
sz = (imax-imin+1)*N_states_diag
rc8 = f77_zmq_recv8( zmq_socket_pull, v_t(1,imin), 8_8*sz, 0)
if(rc8 /= 8*sz) stop 'davidson_pull_results failed to pull v_t'
rc8 = f77_zmq_recv8( zmq_socket_pull, s_t(1,imin), 8_8*sz, 0)
if(rc8 /= 8*sz) stop 'davidson_pull_results failed to pull s_t'
! Activate if zmq_socket_pull is a REP
IRP_IF ZMQ_PUSH
IRP_ELSE
rc = f77_zmq_send( zmq_socket_pull, 'ok', 2, 0)
if (rc /= 2) then
print *, irp_here, ' : f77_zmq_send (zmq_socket_pull,...'
stop -1
endif
IRP_ENDIF
end subroutine
subroutine davidson_collector(zmq_to_qp_run_socket, zmq_socket_pull, v0, s0, sze, N_st)
use f77_zmq
implicit none
BEGIN_DOC
! Routine collecting the results of the workers in Davidson's algorithm.
END_DOC
integer(ZMQ_PTR), intent(in) :: zmq_socket_pull
integer, intent(in) :: sze, N_st
integer(ZMQ_PTR), intent(in) :: zmq_to_qp_run_socket
double precision ,intent(inout) :: v0(sze, N_st)
double precision ,intent(inout) :: s0(sze, N_st)
integer :: more, task_id, imin, imax
double precision, allocatable :: v_t(:,:), s_t(:,:)
integer :: i,j
allocate(v_t(N_st,N_det), s_t(N_st,N_det))
v0 = 0.d0
s0 = 0.d0
more = 1
do while (more == 1)
call davidson_pull_results(zmq_socket_pull, v_t, s_t, imin, imax, task_id)
do j=1,N_st
do i=imin,imax
v0(i,j) = v0(i,j) + v_t(j,i)
s0(i,j) = s0(i,j) + s_t(j,i)
enddo
enddo
integer, external :: zmq_delete_task
if (zmq_delete_task(zmq_to_qp_run_socket,zmq_socket_pull,task_id,more) == -1) then
stop 'Unable to delete task'
endif
end do
deallocate(v_t,s_t)
end subroutine
subroutine H_S2_u_0_nstates_zmq(v_0,s_0,u_0,N_st,sze)
use omp_lib
use bitmasks
use f77_zmq
implicit none
BEGIN_DOC
! Computes $v_0 = H|u_0\rangle$ and $s_0 = S^2 |u_0\rangle$
!
! n : number of determinants
!
! H_jj : array of $\langle j|H|j \rangle$
!
! S2_jj : array of $\langle j|S^2|j \rangle$
END_DOC
integer, intent(in) :: N_st, sze
double precision, intent(out) :: v_0(sze,N_st), s_0(sze,N_st)
double precision, intent(inout):: u_0(sze,N_st)
integer :: i,j,k
integer :: ithread
double precision, allocatable :: u_t(:,:)
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: u_t
integer(ZMQ_PTR) :: zmq_to_qp_run_socket, zmq_socket_pull
PROVIDE psi_det_beta_unique psi_bilinear_matrix_order_transp_reverse psi_det_alpha_unique
PROVIDE psi_bilinear_matrix_transp_values psi_bilinear_matrix_values psi_bilinear_matrix_columns_loc
PROVIDE ref_bitmask_energy nproc
PROVIDE mpi_initialized
call new_parallel_job(zmq_to_qp_run_socket,zmq_socket_pull,'davidson')
integer :: N_states_diag_save
N_states_diag_save = N_states_diag
N_states_diag = N_st
if (zmq_put_N_states_diag(zmq_to_qp_run_socket, 1) == -1) then
stop 'Unable to put N_states_diag on ZMQ server'
endif
N_states_diag = N_states_diag_save
if (zmq_put_psi(zmq_to_qp_run_socket,1) == -1) then
stop 'Unable to put psi on ZMQ server'
endif
energy = 0.d0
if (zmq_put_dvector(zmq_to_qp_run_socket,1,'energy',energy,size(energy)) == -1) then
stop 'Unable to put energy on ZMQ server'
endif
! Create tasks
! ============
integer :: istep, imin, imax, ishift, ipos
integer, external :: add_task_to_taskserver
integer, parameter :: tasksize=40000
character*(100000) :: task
istep=1
ishift=0
imin=1
ipos=1
do imin=1,N_det,tasksize
imax = min(N_det,imin-1+tasksize)
do ishift=0,istep-1
write(task(ipos:ipos+50),'(4(I11,1X),1X,1A)') imin, imax, ishift, istep, '|'
ipos = ipos+50
if (ipos > 100000-50) then
if (add_task_to_taskserver(zmq_to_qp_run_socket,trim(task(1:ipos))) == -1) then
stop 'Unable to add task'
endif
ipos=1
endif
enddo
enddo
if (ipos > 1) then
if (add_task_to_taskserver(zmq_to_qp_run_socket,trim(task(1:ipos))) == -1) then
stop 'Unable to add task'
endif
ipos=1
endif
allocate(u_t(N_st,N_det))
do k=1,N_st
call dset_order(u_0(1,k),psi_bilinear_matrix_order,N_det)
enddo
call dtranspose( &
u_0, &
size(u_0, 1), &
u_t, &
size(u_t, 1), &
N_det, N_st)
ASSERT (N_st == N_states_diag)
ASSERT (sze >= N_det)
integer :: rc, ni, nj
integer*8 :: rc8
double precision :: energy(N_st)
integer, external :: zmq_put_dvector, zmq_put_psi, zmq_put_N_states_diag
integer, external :: zmq_put_dmatrix
if (size(u_t) < 8388608) then
ni = size(u_t)
nj = 1
else
ni = 8388608
nj = size(u_t)/8388608 + 1
endif
! Warning : dimensions are modified for efficiency, It is OK since we get the
! full matrix
if (zmq_put_dmatrix(zmq_to_qp_run_socket, 1, 'u_t', u_t, ni, nj, size(u_t,kind=8)) == -1) then
stop 'Unable to put u_t on ZMQ server'
endif
deallocate(u_t)
integer, external :: zmq_set_running
if (zmq_set_running(zmq_to_qp_run_socket) == -1) then
print *, irp_here, ': Failed in zmq_set_running'
endif
v_0 = 0.d0
s_0 = 0.d0
call omp_set_nested(.True.)
!$OMP PARALLEL NUM_THREADS(2) PRIVATE(ithread)
ithread = omp_get_thread_num()
if (ithread == 0 ) then
call davidson_collector(zmq_to_qp_run_socket, zmq_socket_pull, v_0, s_0, N_det, N_st)
else
call davidson_slave_inproc(1)
endif
!$OMP END PARALLEL
call end_parallel_job(zmq_to_qp_run_socket, zmq_socket_pull, 'davidson')
!$OMP PARALLEL
!$OMP SINGLE
do k=1,N_st
!$OMP TASK DEFAULT(SHARED) FIRSTPRIVATE(k,N_det)
call dset_order(v_0(1,k),psi_bilinear_matrix_order_reverse,N_det)
!$OMP END TASK
!$OMP TASK DEFAULT(SHARED) FIRSTPRIVATE(k,N_det)
call dset_order(s_0(1,k),psi_bilinear_matrix_order_reverse,N_det)
!$OMP END TASK
!$OMP TASK DEFAULT(SHARED) FIRSTPRIVATE(k,N_det)
call dset_order(u_0(1,k),psi_bilinear_matrix_order_reverse,N_det)
!$OMP END TASK
enddo
!$OMP END SINGLE
!$OMP TASKWAIT
!$OMP END PARALLEL
end
BEGIN_PROVIDER [ integer, nthreads_davidson ]
implicit none
BEGIN_DOC
! Number of threads for Davidson
END_DOC
nthreads_davidson = nproc
character*(32) :: env
call getenv('QP_NTHREADS_DAVIDSON',env)
if (trim(env) /= '') then
read(env,*) nthreads_davidson
call write_int(6,nthreads_davidson,'Target number of threads for <Psi|H|Psi>')
endif
END_PROVIDER
integer function zmq_put_N_states_diag(zmq_to_qp_run_socket,worker_id)
use f77_zmq
implicit none
BEGIN_DOC
! Put N_states_diag on the qp_run scheduler
END_DOC
integer(ZMQ_PTR), intent(in) :: zmq_to_qp_run_socket
integer, intent(in) :: worker_id
integer :: rc
character*(256) :: msg
zmq_put_N_states_diag = 0
write(msg,'(A,1X,I8,1X,A200)') 'put_data '//trim(zmq_state), worker_id, 'N_states_diag'
rc = f77_zmq_send(zmq_to_qp_run_socket,trim(msg),len(trim(msg)),ZMQ_SNDMORE)
if (rc /= len(trim(msg))) then
zmq_put_N_states_diag = -1
return
endif
rc = f77_zmq_send(zmq_to_qp_run_socket,N_states_diag,4,0)
if (rc /= 4) then
zmq_put_N_states_diag = -1
return
endif
rc = f77_zmq_recv(zmq_to_qp_run_socket,msg,len(msg),0)
if (msg(1:rc) /= 'put_data_reply ok') then
zmq_put_N_states_diag = -1
return
endif
end
integer function zmq_get_N_states_diag(zmq_to_qp_run_socket, worker_id)
use f77_zmq
implicit none
BEGIN_DOC
! Get N_states_diag from the qp_run scheduler
END_DOC
integer(ZMQ_PTR), intent(in) :: zmq_to_qp_run_socket
integer, intent(in) :: worker_id
integer :: rc
character*(256) :: msg
zmq_get_N_states_diag = 0
if (mpi_master) then
write(msg,'(A,1X,I8,1X,A200)') 'get_data '//trim(zmq_state), worker_id, 'N_states_diag'
rc = f77_zmq_send(zmq_to_qp_run_socket,trim(msg),len(trim(msg)),0)
if (rc /= len(trim(msg))) go to 10
rc = f77_zmq_recv(zmq_to_qp_run_socket,msg,len(msg),0)
if (msg(1:14) /= 'get_data_reply') go to 10
rc = f77_zmq_recv(zmq_to_qp_run_socket,N_states_diag,4,0)
if (rc /= 4) go to 10
endif
IRP_IF MPI_DEBUG
print *, irp_here, mpi_rank
call MPI_BARRIER(MPI_COMM_WORLD, ierr)
IRP_ENDIF
IRP_IF MPI
include 'mpif.h'
integer :: ierr
call MPI_BCAST (zmq_get_N_states_diag, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
if (ierr /= MPI_SUCCESS) then
print *, irp_here//': Unable to broadcast N_states'
stop -1
endif
if (zmq_get_N_states_diag == 0) then
call MPI_BCAST (N_states_diag, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
if (ierr /= MPI_SUCCESS) then
print *, irp_here//': Unable to broadcast N_states'
stop -1
endif
endif
IRP_ENDIF
TOUCH N_states_diag
return
! Exception
10 continue
zmq_get_N_states_diag = -1
IRP_IF MPI
call MPI_BCAST (zmq_get_N_states_diag, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
if (ierr /= MPI_SUCCESS) then
print *, irp_here//': Unable to broadcast N_states'
stop -1
endif
IRP_ENDIF
end
| gpl-3.0 |
mtrbean/scipy | scipy/optimize/minpack/chkder.f | 127 | 4892 | subroutine chkder(m,n,x,fvec,fjac,ldfjac,xp,fvecp,mode,err)
integer m,n,ldfjac,mode
double precision x(n),fvec(m),fjac(ldfjac,n),xp(n),fvecp(m),
* err(m)
c **********
c
c subroutine chkder
c
c this subroutine checks the gradients of m nonlinear functions
c in n variables, evaluated at a point x, for consistency with
c the functions themselves. the user must call chkder twice,
c first with mode = 1 and then with mode = 2.
c
c mode = 1. on input, x must contain the point of evaluation.
c on output, xp is set to a neighboring point.
c
c mode = 2. on input, fvec must contain the functions and the
c rows of fjac must contain the gradients
c of the respective functions each evaluated
c at x, and fvecp must contain the functions
c evaluated at xp.
c on output, err contains measures of correctness of
c the respective gradients.
c
c the subroutine does not perform reliably if cancellation or
c rounding errors cause a severe loss of significance in the
c evaluation of a function. therefore, none of the components
c of x should be unusually small (in particular, zero) or any
c other value which may cause loss of significance.
c
c the subroutine statement is
c
c subroutine chkder(m,n,x,fvec,fjac,ldfjac,xp,fvecp,mode,err)
c
c where
c
c m is a positive integer input variable set to the number
c of functions.
c
c n is a positive integer input variable set to the number
c of variables.
c
c x is an input array of length n.
c
c fvec is an array of length m. on input when mode = 2,
c fvec must contain the functions evaluated at x.
c
c fjac is an m by n array. on input when mode = 2,
c the rows of fjac must contain the gradients of
c the respective functions evaluated at x.
c
c ldfjac is a positive integer input parameter not less than m
c which specifies the leading dimension of the array fjac.
c
c xp is an array of length n. on output when mode = 1,
c xp is set to a neighboring point of x.
c
c fvecp is an array of length m. on input when mode = 2,
c fvecp must contain the functions evaluated at xp.
c
c mode is an integer input variable set to 1 on the first call
c and 2 on the second. other values of mode are equivalent
c to mode = 1.
c
c err is an array of length m. on output when mode = 2,
c err contains measures of correctness of the respective
c gradients. if there is no severe loss of significance,
c then if err(i) is 1.0 the i-th gradient is correct,
c while if err(i) is 0.0 the i-th gradient is incorrect.
c for values of err between 0.0 and 1.0, the categorization
c is less certain. in general, a value of err(i) greater
c than 0.5 indicates that the i-th gradient is probably
c correct, while a value of err(i) less than 0.5 indicates
c that the i-th gradient is probably incorrect.
c
c subprograms called
c
c minpack supplied ... dpmpar
c
c fortran supplied ... dabs,dlog10,dsqrt
c
c argonne national laboratory. minpack project. march 1980.
c burton s. garbow, kenneth e. hillstrom, jorge j. more
c
c **********
integer i,j
double precision eps,epsf,epslog,epsmch,factor,one,temp,zero
double precision dpmpar
data factor,one,zero /1.0d2,1.0d0,0.0d0/
c
c epsmch is the machine precision.
c
epsmch = dpmpar(1)
c
eps = dsqrt(epsmch)
c
if (mode .eq. 2) go to 20
c
c mode = 1.
c
do 10 j = 1, n
temp = eps*dabs(x(j))
if (temp .eq. zero) temp = eps
xp(j) = x(j) + temp
10 continue
go to 70
20 continue
c
c mode = 2.
c
epsf = factor*epsmch
epslog = dlog10(eps)
do 30 i = 1, m
err(i) = zero
30 continue
do 50 j = 1, n
temp = dabs(x(j))
if (temp .eq. zero) temp = one
do 40 i = 1, m
err(i) = err(i) + temp*fjac(i,j)
40 continue
50 continue
do 60 i = 1, m
temp = one
if (fvec(i) .ne. zero .and. fvecp(i) .ne. zero
* .and. dabs(fvecp(i)-fvec(i)) .ge. epsf*dabs(fvec(i)))
* temp = eps*dabs((fvecp(i)-fvec(i))/eps-err(i))
* /(dabs(fvec(i)) + dabs(fvecp(i)))
err(i) = one
if (temp .gt. epsmch .and. temp .lt. eps)
* err(i) = (dlog10(temp) - epslog)/epslog
if (temp .ge. eps) err(i) = zero
60 continue
70 continue
c
return
c
c last card of subroutine chkder.
c
end
| bsd-3-clause |
pravisankar/origin | vendor/github.com/gonum/lapack/internal/testdata/dlasqtest/lsame.f | 204 | 3170 | *> \brief \b LSAME
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
* Definition:
* ===========
*
* LOGICAL FUNCTION LSAME( CA, CB )
*
* .. Scalar Arguments ..
* CHARACTER CA, CB
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> LSAME returns .TRUE. if CA is the same letter as CB regardless of
*> case.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] CA
*> \verbatim
*> \endverbatim
*>
*> \param[in] CB
*> \verbatim
*> CA and CB specify the single characters to be compared.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup auxOTHERauxiliary
*
* =====================================================================
LOGICAL FUNCTION LSAME( CA, CB )
*
* -- LAPACK auxiliary routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
CHARACTER CA, CB
* ..
*
* =====================================================================
*
* .. Intrinsic Functions ..
INTRINSIC ICHAR
* ..
* .. Local Scalars ..
INTEGER INTA, INTB, ZCODE
* ..
* .. Executable Statements ..
*
* Test if the characters are equal
*
LSAME = CA.EQ.CB
IF( LSAME )
$ RETURN
*
* Now test for equivalence if both characters are alphabetic.
*
ZCODE = ICHAR( 'Z' )
*
* Use 'Z' rather than 'A' so that ASCII can be detected on Prime
* machines, on which ICHAR returns a value with bit 8 set.
* ICHAR('A') on Prime machines returns 193 which is the same as
* ICHAR('A') on an EBCDIC machine.
*
INTA = ICHAR( CA )
INTB = ICHAR( CB )
*
IF( ZCODE.EQ.90 .OR. ZCODE.EQ.122 ) THEN
*
* ASCII is assumed - ZCODE is the ASCII code of either lower or
* upper case 'Z'.
*
IF( INTA.GE.97 .AND. INTA.LE.122 ) INTA = INTA - 32
IF( INTB.GE.97 .AND. INTB.LE.122 ) INTB = INTB - 32
*
ELSE IF( ZCODE.EQ.233 .OR. ZCODE.EQ.169 ) THEN
*
* EBCDIC is assumed - ZCODE is the EBCDIC code of either lower or
* upper case 'Z'.
*
IF( INTA.GE.129 .AND. INTA.LE.137 .OR.
$ INTA.GE.145 .AND. INTA.LE.153 .OR.
$ INTA.GE.162 .AND. INTA.LE.169 ) INTA = INTA + 64
IF( INTB.GE.129 .AND. INTB.LE.137 .OR.
$ INTB.GE.145 .AND. INTB.LE.153 .OR.
$ INTB.GE.162 .AND. INTB.LE.169 ) INTB = INTB + 64
*
ELSE IF( ZCODE.EQ.218 .OR. ZCODE.EQ.250 ) THEN
*
* ASCII is assumed, on Prime machines - ZCODE is the ASCII code
* plus 128 of either lower or upper case 'Z'.
*
IF( INTA.GE.225 .AND. INTA.LE.250 ) INTA = INTA - 32
IF( INTB.GE.225 .AND. INTB.LE.250 ) INTB = INTB - 32
END IF
LSAME = INTA.EQ.INTB
*
* RETURN
*
* End of LSAME
*
END
| apache-2.0 |
likev/ncl | ncl_ncarg_src/ni/src/examples/basic/basic06f.f | 1 | 10556 | CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C C
C Copyright (C) 1995 C
C University Corporation for Atmospheric Research C
C All Rights Reserved C
C C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C File: basic06f.f
C
C Author: Fred Clare
C National Center for Atmospheric Research
C PO 3000, Boulder, Colorado
C
C
C Date: Wed May 24 12:54:47 MDT 1995
C
C Description: This Fortran program demonstrates how to position
C objects on an output device and how to change
C their sizes. A simple color table is also defined
C and used for changing the color of a curve in an
C XyPlot. The script begins with two procedures -
C one for drawing plot objects and one for drawing
C text objects.
C
program basic06
implicit none
external NhlFAppClass
external NhlFNcgmWorkstationClass
external NhlFPSWorkstationClass
external NhlFPDFWorkstationClass
external NhlFCairoPSPDFWorkstationClass
external NhlFCairoImageWorkstationClass
external NhlFCairoWindowWorkstationClass
external NhlFXyPlotClass
external NhlFCoordArraysClass
external NhlFTickMarkClass
external NhlFTextItemClass
integer appid,rlist
integer xwork_id,text_id,box_id,data_id
integer dataspec
CHARACTER*7 wks_type
integer i,ierr
character*5 text
data text /'Box '/
real xdra(9),ydra(9)
real xpos,ypos
data xdra / 0.0, 0.1, 0.5, 0.9, 1.0, 0.9, 0.5, 0.1, 0.0 /
data ydra / 0.5, 0.9, 1.0, 0.9, 0.5, 0.1, 0.0, 0.1, 0.5 /
C
C Define a simple color map (index 0 defines the background color).
C
real cmap(3,4)
data cmap / 1.0, 1.0, 1.0,
1 0.0, 0.0, 1.0,
2 0.0, 1.0, 0.0,
3 1.0, 0.0, 0.0 /
integer dims(2)
data dims / 3,4 /
C
C Define the workstation type
C
wks_type = "x11"
C
C Initialize the high level utility library and create application.
C
call NhlFInitialize
call NhlFRLCreate(rlist,'SETRL')
call NhlFRLClear(rlist)
call NhlFRLSetString(rlist,'appUsrDir','./',ierr)
call NhlFCreate(appid,'basic06',NhlFappClass,0,rlist,ierr)
if (wks_type.eq."ncgm".or.wks_type.eq."NCGM") then
C
C Create a meta file workstation.
C
call NhlFRLClear(rlist)
call NhlFRLSetString(rlist,'wkMetaName',
1 './basic06f.ncgm',ierr)
call NhlFRLSetMDFloatArray(rlist,'wkColorMap',
1 cmap,2,dims,ierr)
call NhlFCreate(xwork_id,'simple',
1 NhlFncgmWorkstationClass,0,rlist,ierr)
else if (wks_type.eq."x11".or.wks_type.eq."X11") then
C
C Create an X workstation.
C
call NhlFRLClear(rlist)
call NhlFRLSetString(rlist,'wkPause','True',ierr)
call NhlFRLSetMDFloatArray(rlist,'wkColorMap',
1 cmap,2,dims,ierr)
call NhlFCreate(xwork_id,'simple',
1 NhlFCairoWindowWorkstationClass,
1 0,rlist,ierr)
else if (wks_type.eq."oldps".or.wks_type.eq."OLDPS") then
C
C Create an older-style PostScript workstation.
C
call NhlFRLClear(rlist)
call NhlFRLSetstring(rlist,'wkPSFileName','./basic06f.ps',ierr)
call NhlFRLSetMDFloatArray(rlist,'wkColorMap',
1 cmap,2,dims,ierr)
call NhlFCreate(xwork_id,'simple',
1 NhlFPSWorkstationClass,0,rlist,ierr)
else if (wks_type.eq."oldpdf".or.wks_type.eq."OLDPDF") then
C
C Create an older-style PDF workstation.
C
call NhlFRLClear(rlist)
call NhlFRLSetstring(rlist,'wkPDFFileName','./basic06f.pdf',
1 ierr)
call NhlFRLSetMDFloatArray(rlist,'wkColorMap',
1 cmap,2,dims,ierr)
call NhlFCreate(xwork_id,'simple',
1 NhlFPDFWorkstationClass,0,rlist,ierr)
endif
if (wks_type.eq."pdf".or.wks_type.eq."PDF".or.
& wks_type.eq."ps".or.wks_type.eq."PS") then
C
C Create a cairo PS/PDF workstation.
C
call NhlFRLClear(rlist)
call NhlFRLSetString(rlist,'wkFileName',
& './basic06f',ierr)
call NhlFRLSetString(rlist,'wkFormat',wks_type,ierr)
call NhlFRLSetMDFloatArray(rlist,'wkColorMap',
1 cmap,2,dims,ierr)
call NhlFCreate(xwork_id,'simple',
& NhlFCairoPSPDFWorkstationClass,0,rlist,ierr)
endif
if (wks_type.eq."png".or.wks_type.eq."PNG") then
C
C Create a cairo PNG workstation.
C
call NhlFRLClear(rlist)
call NhlFRLSetString(rlist,'wkFileName',
& './basic06f',ierr)
call NhlFRLSetString(rlist,'wkFormat',wks_type,ierr)
call NhlFRLSetMDFloatArray(rlist,'wkColorMap',
1 cmap,2,dims,ierr)
call NhlFCreate(xwork_id,'simple',
& NhlFCairoImageWorkstationClass,0,rlist,ierr)
endif
C
C Create data object for an XyPlot
C
call NhlFRLClear(rlist)
call NhlFRLSetFloatArray(rlist,'caXArray',xdra,
1 9,ierr)
call NhlFRLSetFloatArray(rlist,'caYArray',ydra,
1 9,ierr)
call NhlFCreate(data_id,'xyData',NhlFcoordArraysClass,
1 0,rlist,ierr)
C
C Create a simple XyPlot object with no labels or borders. The
C parent for this object is xwork_id, hence it will be sent to
C the workstation identified by xwork_id when the draw procedure
C is invoked on it.
C
call NhlFRLClear(rlist)
call NhlFRLSetString(rlist,'tmXBBorderOn','False',ierr)
call NhlFRLSetString(rlist,'tmXTBorderOn','False',ierr)
call NhlFRLSetString(rlist,'tmYLBorderOn','False',ierr)
call NhlFRLSetString(rlist,'tmYRBorderOn','False',ierr)
call NhlFRLSetString(rlist,'tmXBOn','False',ierr)
call NhlFRLSetString(rlist,'tmXTOn','False',ierr)
call NhlFRLSetString(rlist,'tmYLOn','False',ierr)
call NhlFRLSetString(rlist,'tmYROn','False',ierr)
call NhlFRLSetFloat(rlist,'vpXF',0.0,ierr)
call NhlFRLSetFloat(rlist,'vpYF',1.0,ierr)
call NhlFRLSetFloat(rlist,'vpWidthF',1.0,ierr)
call NhlFRLSetFloat(rlist,'vpHeightF',1.0,ierr)
call NhlFCreate(box_id,'Box',NhlFxyPlotClass,xwork_id,
1 rlist,ierr)
C
C Create a TextItem object.
C
call NhlFRLClear(rlist)
call NhlFRLSetFloat(rlist,'txPosXF',0.5,ierr)
call NhlFRLSetFloat(rlist,'txPosYF',0.5,ierr)
call NhlFRLSetInteger(rlist,'txFont',26,ierr)
call NhlFCreate(text_id,'Text',NhlFtextItemClass,xwork_id,
1 rlist,ierr)
C
C Add the data identified by data_id to the XyPlot.
C
call NhlFAddData(box_id,'xyCoordData',data_id,dataspec)
C
C Draw three labeled boxes at different sizes and in different positions
C and with different colors.
C
do 10 i=1,3
xpos = -0.05*i*i + 0.5*i - 0.20
ypos = 1.0-xpos
text(5:5) = char(ichar('1')+i-1)
C
C Specify a text string and its color.
C
call NhlFRLClear(rlist)
call NhlFRLSetString(rlist,'txString',text,ierr)
call NhlFRLSetInteger(rlist,'txFontColor',4-i,ierr)
call NhlFSetValues(text_id,rlist,ierr)
C
C Set the XyPlot curve color.
C
call NhlFRLClear(rlist)
call NhlFRLSetString(rlist,'xyMonoLineColor','True',ierr)
call NhlFRLSetInteger(rlist,'xyLineColor',i,ierr)
call NhlFSetValues(dataspec,rlist,ierr)
C
C Draw box and text.
C
call draw_plot(box_id, xpos, ypos, 0.36-0.09*(i-1),ierr)
call draw_text(text_id, xpos, ypos, 0.08-0.02*(i-1),ierr)
10 continue
call NhlFFrame(xwork_id,ierr)
call NhlFDestroy(xwork_id,ierr)
call NhlFClose
stop
end
subroutine draw_plot(id,x,y,scale,ierr)
C
C This procedure takes the plot object with identifier 'id' and
C draws it centered at coordinate (x,y) and scaled by 'scale'.
C The original plot object is returned unchanged.
C
integer id
real x,y,scale
integer rlist,grlist,ierr
real x_ref,y_ref,width_ref,height_ref
call NhlFRLCreate(rlist,'SETRL')
call NhlFRLCreate(grlist,'GETRL')
call NhlFRLClear(grlist)
call NhlFRLGetFloat(grlist,'vpXF',x_ref,ierr)
call NhlFRLGetFloat(grlist,'vpYF',y_ref,ierr)
call NhlFRLGetFloat(grlist,'vpWidthF',width_ref,ierr)
call NhlFRLGetFloat(grlist,'vpHeightF',height_ref,ierr)
call NhlFGetValues(id,grlist,ierr)
call NhlFRLClear(rlist)
call NhlFRLSetFloat(rlist,'vpXF',x - 0.5*width_ref*scale,ierr)
call NhlFRLSetFloat(rlist,'vpYF',y + 0.5*height_ref*scale,ierr)
call NhlFRLSetFloat(rlist,'vpWidthF',width_ref*scale,ierr)
call NhlFRLSetFloat(rlist,'vpHeightF',height_ref*scale,ierr)
call NhlFSetValues(id,rlist,ierr)
call NhlFDraw(id,ierr)
call NhlFRLClear(rlist)
call NhlFRLSetFloat(rlist,'vpXF',x_ref,ierr)
call NhlFRLSetFloat(rlist,'vpYF',y_ref,ierr)
call NhlFRLSetFloat(rlist,'vpWidthF',width_ref,ierr)
call NhlFRLSetFloat(rlist,'vpHeightF',height_ref,ierr)
call NhlFSetValues(id,rlist,ierr)
return
end
subroutine draw_text(id,x,y,height,ierr)
C
C This procedure takes the text string in the object identified by 'id'
C and draws it centered at coordinate (x,y) with a height of 'height'.
C
integer id
real x,y,height
integer rlist,grlist,ierr
real xpos,ypos,fheight
call NhlFRLCreate(rlist,'SETRL')
call NhlFRLCreate(grlist,'GETRL')
call NhlFRLClear(grlist)
call NhlFRLGetFloat(grlist,'txPosXF',xpos,ierr)
call NhlFRLGetFloat(grlist,'txPosYF',ypos,ierr)
call NhlFRLGetFloat(grlist,'txFontHeightF',fheight,ierr)
call NhlFGetValues(id,grlist,ierr)
call NhlFRLClear(rlist)
call NhlFRLSetFloat(rlist,'txPosXF',x,ierr)
call NhlFRLSetFloat(rlist,'txPosYF',y,ierr)
call NhlFRLSetFloat(rlist,'txFontHeightF',height,ierr)
call NhlFSetValues(id,rlist,ierr)
call NhlFDraw(id,ierr)
call NhlFRLClear(rlist)
call NhlFRLSetFloat(rlist,'txPosXF',xpos,ierr)
call NhlFRLSetFloat(rlist,'txPosYF',ypos,ierr)
call NhlFRLSetFloat(rlist,'txFontHeightF',fheight,ierr)
call NhlFSetValues(id,rlist,ierr)
return
end
| gpl-2.0 |
DmitryLyakh/GFC | gfc_dictionary.F90 | 1 | 88365 | !Generic Fortran Containers (GFC): Dictionary (ordered map), AVL BST
!AUTHOR: Dmitry I. Lyakh (Liakh): quant4me@gmail.com, liakhdi@ornl.gov
!REVISION: 2017/12/20 (recycling my old dictionary implementation)
!Copyright (C) 2014-2017 Dmitry I. Lyakh (Liakh)
!Copyright (C) 2014-2017 Oak Ridge National Laboratory (UT-Battelle)
!This file is part of ExaTensor.
!ExaTensor is free software: you can redistribute it and/or modify
!it under the terms of the GNU Lesser General Public License as published
!by the Free Software Foundation, either version 3 of the License, or
!(at your option) any later version.
!ExaTensor is distributed in the hope that it will be useful,
!but WITHOUT ANY WARRANTY; without even the implied warranty of
!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!GNU Lesser General Public License for more details.
!You should have received a copy of the GNU Lesser General Public License
!along with ExaTensor. If not, see <http://www.gnu.org/licenses/>.
!FOR DEVELOPERS ONLY:
module gfc_dictionary
use gfc_base
use gfc_list
use gfc_vector
use timers
implicit none
private
!PARAMETERS:
!Basic:
integer(INTD), private:: CONS_OUT=6 !output device
logical, private:: VERBOSE=.TRUE. !verbosity for errors
integer(INTD), private:: DEBUG=0 !debugging level (0:none)
!Directions:
logical, parameter, public:: GFC_DICT_LEFT=.FALSE.
logical, parameter, public:: GFC_DICT_RIGHT=.TRUE.
logical, parameter, public:: GFC_DICT_SUCCESSOR=.TRUE.
logical, parameter, public:: GFC_DICT_PREDECESSOR=.FALSE.
!Search:
integer(INTD), parameter, public:: GFC_DICT_JUST_FIND=0 !action: just find the key in the dictionary, if it is there
integer(INTD), parameter, public:: GFC_DICT_DELETE_IF_FOUND=1 !action: delete the dictionary element, if key found
integer(INTD), parameter, public:: GFC_DICT_REPLACE_IF_FOUND=2 !action: replace the value of the dictionary element, if key found
integer(INTD), parameter, public:: GFC_DICT_ADD_IF_NOT_FOUND=3 !action: create a new dictionary element, if key not found
integer(INTD), parameter, public:: GFC_DICT_ADD_OR_MODIFY=4 !action: combines ADD_IF_NOT_FOUND and REPLACE_IF_FOUND
integer(INTD), parameter, public:: GFC_DICT_FETCH_IF_FOUND=5 !action: simply fetch the dictionary element value, if key found
!TYPES:
!Dictionary element:
type, extends(gfc_cont_elem_t), public:: dict_elem_t
class(*), pointer, private:: key=>NULL() !dictionary element key
class(dict_elem_t), pointer, private:: child_lt=>NULL() !lesser child element
class(dict_elem_t), pointer, private:: child_gt=>NULL() !greater child element
class(dict_elem_t), pointer, private:: parent=>NULL() !parent element
integer(INTD), private:: balance_fac !balance factor (for AVL BST)
contains
procedure, private:: DictElemConstruct
generic, public:: dict_elem_ctor=>DictElemConstruct !constructs a dictionary element from a key-value pair
procedure, public:: destruct_keyval=>DictElemDestruct !destructs a dictionary element (both key and value)
procedure, non_overridable, public:: is_root=>DictElemIsRoot !returns GFC_TRUE if the element is the root of the dictionary binary search tree
procedure, non_overridable, public:: is_leaf=>DictElemIsLeaf !returns GFC_TRUE if the element is a leaf of the dictionary binary search tree
procedure, public:: get_key=>DictElemGetKey !returns an unlimited polymorphic pointer to the element key
procedure, public:: predicate_key=>DictElemPredicateKey !returns the result of predication on the element key
procedure, public:: compare_key=>DictElemCompareKey !compares the element key with another key
procedure, public:: print_key=>DictElemPrintKey !prints the dictionary element key
procedure, public:: print_it=>DictElemPrintIt !prints the dictionary elemet (key,value)
end type dict_elem_t
!Dictionary (all operations on the dictionary are performed via an iterator):
type, extends(gfc_container_t), public:: dictionary_t
class(dict_elem_t), pointer, private:: root=>NULL() !root of the AVL binary search tree (boundary element)
! class(dict_elem_t), pointer, private:: first=>NULL() !first element (boundary element) `Do I need this?
! class(dict_elem_t), pointer, private:: last=>NULL() !last element (boundary element) `Do I need this?
logical, private:: key_storage=GFC_BY_VAL !dictionary key storage policy
contains
procedure, public:: is_empty=>DictionaryIsEmpty !returns GFC_TRUE if the dictionary is empty, GFC_FALSE otherwise (or error code)
procedure, public:: is_subdictionary=>DictionaryIsSubdictionary !returns TRUE if the dictionary is subdictionary, FALSE otherwise
procedure, public:: set_key_storage=>DictionarySetKeyStorage !sets the key storage policy (by value or by reference), the dictionary must be empty
procedure, private:: reroot_=>DictionaryReroot !PRIVATE: changes the root of the dictionary
end type dictionary_t
!Dictionary iterator:
type, extends(gfc_iter_t), public:: dictionary_iter_t
class(dict_elem_t), pointer, private:: current=>NULL() !currently pointed element of the container
class(dictionary_t), pointer, private:: container=>NULL() !container
contains
procedure, private:: jump_=>DictionaryIterJump !PRIVATE: moves the iterator to an arbitrary position
procedure, public:: init=>DictionaryIterInit !associates the iterator with a container and positions it to the root element
procedure, public:: reset=>DictionaryIterReset !resets the iterator to the beginning of the container (root element)
procedure, public:: release=>DictionaryIterRelease !dissociates the iterator from its container
procedure, public:: pointee=>DictionaryIterPointee !returns a pointer to the container element currently in focus
procedure, public:: next=>DictionaryIterNext !moves the iterator to the "next" element, if any (not necessarily in order)
procedure, public:: previous=>DictionaryIterPrevious !moves the iterator to the "previous" element, if any (not necessarily in order)
procedure, public:: next_in_order=>DictionaryIterNextInOrder !moves the iterator to the next-in-order element, if any
procedure, public:: prev_in_order=>DictionaryIterPrevInOrder !moves the iterator to the previous-in-order element, if any
procedure, public:: move_in_order=>DictionaryIterMoveInOrder !moves the iterator to either the next-in-order or previous-in-order element
procedure, public:: move_to_min=>DictionaryIterMoveToMin !moves the iterator to the minimal element
procedure, public:: move_to_max=>DictionaryIterMoveToMax !moves the iterator to the maximal element
procedure, public:: move_up=>DictionaryIterMoveUp !moves the iterator up the binary search tree (to the parent element)
procedure, public:: move_down=>DictionaryIterMoveDown !moves the iterator down the binary search tree, either left or right
procedure, public:: get_key=>DictionaryIterGetKey !returns a pointer to the key in the current iterator position
procedure, public:: delete_all=>DictionaryIterDeleteAll !deletes all elements of the dictionary
procedure, public:: search=>DictionaryIterSearch !performs a key-based search in the dictionary
procedure, public:: sort_to_list=>DictionaryIterSortToList !returns a list of references to dictionary elements in a sorted (by key) order
procedure, public:: sort_to_vector=>DictionaryIterSortToVector !returns a vector of references to dictionary elements in a sorted (by key) order
end type dictionary_iter_t
!INTERFACES:
!VISIBILITY:
!dict_elem_t:
private DictElemConstruct
private DictElemDestruct
private DictElemIsRoot
private DictElemIsLeaf
private DictElemGetKey
private DictElemPredicateKey
private DictElemCompareKey
private DictElemPrintKey
private DictElemPrintIt
!dictionary_t:
private DictionaryIsEmpty
private DictionaryIsSubdictionary
private DictionarySetKeyStorage
private DictionaryReroot
!dictionary_iter_t:
private DictionaryIterJump
private DictionaryIterInit
private DictionaryIterReset
private DictionaryIterRelease
private DictionaryIterPointee
private DictionaryIterNext
private DictionaryIterPrevious
private DictionaryIterNextInOrder
private DictionaryIterPrevInOrder
private DictionaryIterMoveInOrder
private DictionaryIterMoveToMin
private DictionaryIterMoveToMax
private DictionaryIterMoveUp
private DictionaryIterMoveDown
private DictionaryIterGetKey
private DictionaryIterDeleteAll
private DictionaryIterSearch
private DictionaryIterSortToList
private DictionaryIterSortToVector
!DEFINITIONS:
contains
![dict_elem_t]=============================================================================================
#if !(defined(__GNUC__) && __GNUC__ < 9)
subroutine DictElemConstruct(this,key,val,ierr,assoc_key,assoc_val,key_copy_ctor_f,val_copy_ctor_f)
#else
subroutine DictElemConstruct(this,key,val,ierr,assoc_key,assoc_val)
#endif
!Given a key-value pair, constructs an element of a dictionary. Note
!that if construction fails, the element may be left underconstructed,
!requiring a separate call to the destructor after return.
implicit none
class(dict_elem_t), intent(inout):: this !inout: element of the dictionary
class(*), target, intent(in):: key !in: key to be stored
class(*), target, intent(in):: val !in: value to be stored (either by value or by reference)
integer(INTD), intent(out), optional:: ierr !out: error code
logical, intent(in), optional:: assoc_key !in: if TRUE, <key> will be stored by reference, otherwise by value (default)
logical, intent(in), optional:: assoc_val !in: if TRUE, <val> will be stored by reference, otherwise by value (default)
#if !(defined(__GNUC__) && __GNUC__ < 9)
procedure(gfc_copy_i), optional:: key_copy_ctor_f !in: user-defined generic copy constructor for the key (by value)
procedure(gfc_copy_i), optional:: val_copy_ctor_f !in: user-defined generic copy constructor for the value (by value)
#endif
integer(INTD):: errc
integer:: ier
logical:: assk,assv
errc=GFC_SUCCESS
if(present(assoc_key)) then; assk=assoc_key; else; assk=.FALSE.; endif
if(present(assoc_val)) then; assv=assoc_val; else; assv=.FALSE.; endif
if(this%in_use(errc,set_lock=.TRUE.,report_refs=.FALSE.).eq.GFC_FALSE) then
if(this%is_empty()) then
#if !(defined(__GNUC__) && __GNUC__ < 9)
if(present(val_copy_ctor_f)) then
call this%construct_base(val,errc,assoc_only=assv,copy_ctor_f=val_copy_ctor_f,locked=.TRUE.)
else
#endif
call this%construct_base(val,errc,assoc_only=assv,locked=.TRUE.)
#if !(defined(__GNUC__) && __GNUC__ < 9)
endif
#endif
if(errc.eq.GFC_SUCCESS) then !base constructor succeeded
if(assk) then
this%key=>key
else
#if !(defined(__GNUC__) && __GNUC__ < 9)
if(present(key_copy_ctor_f)) then
this%key=>key_copy_ctor_f(key,errc)
else
#endif
allocate(this%key,SOURCE=key,STAT=ier)
if(ier.ne.0) errc=GFC_MEM_ALLOC_FAILED
#if !(defined(__GNUC__) && __GNUC__ < 9)
endif
#endif
endif
endif
else
errc=GFC_ELEM_NOT_EMPTY
endif
if(errc.eq.GFC_SUCCESS) then
call this%release_lock(errc)
else
call this%release_lock()
endif
else
errc=GFC_IN_USE
endif
if(present(ierr)) ierr=errc
return
end subroutine DictElemConstruct
!---------------------------------------------------------------------
subroutine DictElemDestruct(this,ierr,key_assoc,dtor_f,locked)
!Destructs the key-value pair inside the dictionary element.
!<dtor_f> provides an optional explicit destructor for the dictionary
!element value, if needed. Alternatively, the value may have the final
!subroutine defined. In contrast, the dictionary element key must
!have the final subroutine defined if it requires a non-trivial destruction.
implicit none
class(dict_elem_t), intent(inout):: this !inout: element of a dictionary
integer(INTD), intent(out), optional:: ierr !out: error code
logical, intent(in), optional:: key_assoc !in: if TRUE, the key will be assumed stored by reference
procedure(gfc_destruct_i), optional:: dtor_f !in: explicit destructor for the value
logical, intent(in), optional:: locked !in: if TRUE, the dictionary element will be assumed already locked (defaults to FALSE)
integer(INTD):: errc
logical:: assk,lckd,lck
integer:: ier
errc=GFC_SUCCESS
if(present(key_assoc)) then; assk=key_assoc; else; assk=.FALSE.; endif
if(present(locked)) then; lckd=locked; else; lckd=.FALSE.; endif; lck=lckd
if(.not.lck) lck=(this%in_use(errc,set_lock=.TRUE.,report_refs=.FALSE.).eq.GFC_FALSE)
if(lck) then
if(errc.eq.GFC_SUCCESS) then
if(associated(this%key)) then
if(.not.assk) then
if(present(dtor_f)) then
call this%gfc_cont_elem_t%destruct(errc,dtor_f=dtor_f,locked=.TRUE.)
else
call this%gfc_cont_elem_t%destruct(errc,locked=.TRUE.)
endif
deallocate(this%key,STAT=ier)
if(ier.ne.0.and.errc.eq.GFC_SUCCESS) errc=GFC_MEM_FREE_FAILED
endif
this%key=>NULL()
else
errc=GFC_CORRUPTED_CONT
endif
endif
if(.not.lckd) then
if(errc.eq.GFC_SUCCESS) then
call this%release_lock(errc)
else
call this%release_lock()
endif
endif
else
if(errc.eq.GFC_SUCCESS) errc=GFC_IN_USE
endif
if(present(ierr)) ierr=errc
return
end subroutine DictElemDestruct
!------------------------------------------------
function DictElemIsRoot(this) result(res)
implicit none
integer(INTD):: res !out: answer {GFC_TRUE,GFC_FALSE,GFC_ERROR}
class(dict_elem_t), intent(in):: this !in: dictionary element
if(associated(this%parent)) then
res=GFC_FALSE
else
res=GFC_TRUE
endif
return
end function DictElemIsRoot
!------------------------------------------------
function DictElemIsLeaf(this) result(res)
implicit none
integer(INTD):: res !out: answer {GFC_TRUE,GFC_FALSE,GFC_ERROR}
class(dict_elem_t), intent(in):: this !in: dictionary element
if(associated(this%child_lt).or.associated(this%child_gt)) then
res=GFC_FALSE
else
res=GFC_TRUE
endif
return
end function DictElemIsLeaf
!-------------------------------------------------------
function DictElemGetKey(this,ierr) result(key_p)
implicit none
class(*), pointer:: key_p !out: pointer to the element key
class(dict_elem_t), intent(in):: this !in: dictionary element
integer(INTD), intent(out), optional:: ierr !out: error code
integer(INTD):: errc
errc=GFC_SUCCESS; key_p=>NULL()
if(.not.this%is_empty()) then
if(associated(this%key)) then
key_p=>this%key
else
errc=GFC_CORRUPTED_CONT
endif
else
errc=GFC_ELEM_EMPTY
endif
if(present(ierr)) ierr=errc
return
end function DictElemGetKey
!-----------------------------------------------------------------------
function DictElemPredicateKey(this,predicat_f,ierr) result(pred)
!Evaluates a user-defined predicate on the key of a given dictionary element.
implicit none
integer(INTD):: pred !out: evaluated predicate value {GFC_TRUE,GFC_FALSE,GFC_ERROR}
class(dict_elem_t), intent(in):: this !in: element of a dictionary
procedure(gfc_predicate_i):: predicat_f !in: user-defined predicate
integer(INTD), intent(out), optional:: ierr !out: error code
integer(INTD):: errc
errc=GFC_SUCCESS; pred=GFC_ERROR
if(.not.this%is_empty()) then
pred=predicat_f(this%key); if(pred.eq.GFC_ERROR) errc=GFC_ERROR
else
errc=GFC_ELEM_EMPTY
endif
if(present(ierr)) ierr=errc
return
end function DictElemPredicateKey
!-------------------------------------------------------------------------
function DictElemCompareKey(this,other_key,cmp_f,ierr) result(cmp)
!Compares the dictionary element key (on the left) with another key (on the right).
implicit none
integer(INTD):: cmp !out: result of the comparison (see GFC_CMP_XXX in gfc_base.F90)
class(dict_elem_t), intent(in):: this !in: element of a dictionary whose key is being compared
class(*), intent(in):: other_key !in: the other value to be compared with
procedure(gfc_cmp_i):: cmp_f !in: user-defined comparison function
integer(INTD), intent(out), optional:: ierr !out: error code
integer(INTD):: errc
errc=GFC_SUCCESS; cmp=GFC_CMP_NA
if(.not.this%is_empty()) then
cmp=cmp_f(this%key,other_key); if(cmp.eq.GFC_ERROR) errc=GFC_ERROR
else
errc=GFC_ELEM_EMPTY
endif
if(present(ierr)) ierr=errc
return
end function DictElemCompareKey
!------------------------------------------------------------
subroutine DictElemPrintKey(this,print_f,ierr,dev_id)
!Prints the key of a dictionary element using a user-defined print function.
implicit none
class(dict_elem_t), intent(in):: this !in: element of a dictionary
procedure(gfc_print_i):: print_f !in: user-defined printing function
integer(INTD), intent(out), optional:: ierr !out: error code
integer(INTD), intent(in), optional:: dev_id !in: output device (default to screen, 6)
integer(INTD):: dev,errc
errc=GFC_SUCCESS
if(.not.this%is_empty()) then
if(present(dev_id)) then; dev=dev_id; else; dev=6; endif !defaults to screen
write(dev,'("#GFC container element key:")')
errc=print_f(this%key,dev); if(errc.ne.0) errc=GFC_ACTION_FAILED
else
errc=GFC_ELEM_EMPTY
endif
if(present(ierr)) ierr=errc
return
end subroutine DictElemPrintKey
!---------------------------------------------------------------------------
subroutine DictElemPrintIt(this,print_key_f,print_val_f,ierr,dev_id)
!Prints the dictionary element (key,value).
implicit none
class(dict_elem_t), intent(in):: this !in: dictionary element
procedure(gfc_print_i):: print_key_f !in: key printing function
procedure(gfc_print_i):: print_val_f !in: value printing function
integer(INTD), intent(out), optional:: ierr !out: error code
integer(INTD), intent(in), optional:: dev_id !in: output device (defaults to screen, 6)
integer(INTD):: dev,errc
errc=GFC_SUCCESS
if(.not.this%is_empty()) then
if(present(dev_id)) then; dev=dev_id; else; dev=6; endif !defaults to screen
write(dev,'("#GFC dictionary element (key,value):")')
call this%print_key(print_key_f,errc,dev)
if(errc.eq.GFC_SUCCESS) call this%print_value(print_val_f,errc,dev)
else
errc=GFC_ELEM_EMPTY
endif
if(present(ierr)) ierr=errc
return
end subroutine DictElemPrintIt
![dictionary_t]=====================================
function DictionaryIsEmpty(this) result(res)
!Returns GFC_TRUE if the dictionary is empty, GFC_FALSE otherwise (or error code).
implicit none
integer(INTD):: res !out: result of query
class(dictionary_t), intent(in):: this !in: dictionary
if(associated(this%root)) then
res=GFC_FALSE
else
res=GFC_TRUE
endif
return
end function DictionaryIsEmpty
!----------------------------------------------------------------
function DictionaryIsSubdictionary(this,ierr) result(res)
!Returns TRUE if the dictionary is a subdictionary of a larger dictionary.
implicit none
logical:: res !out: result
class(dictionary_t), intent(in):: this !in: dictionary
integer(INTD), intent(out), optional:: ierr !out: error code
integer(INTD):: errc
errc=GFC_SUCCESS; res=.FALSE.
if(associated(this%root)) then
res=associated(this%root%parent)
else
errc=GFC_EMPTY_CONT
endif
if(present(ierr)) ierr=errc
return
end function DictionaryIsSubdictionary
!-----------------------------------------------------------
subroutine DictionarySetKeyStorage(this,policy,ierr)
!Sets the key storage policy.
implicit none
class(dictionary_t), intent(inout):: this !inout: dictionary (must be empty)
logical, intent(in):: policy !in: storage policy: {GFC_BY_VAL,GFC_BY_REF}
integer(INTD), intent(out), optional:: ierr !out: error code
integer(INTD):: errc
errc=GFC_SUCCESS
if(.not.associated(this%root)) then
this%key_storage=policy
else
errc=GFC_INVALID_REQUEST
endif
if(present(ierr)) ierr=errc
return
end subroutine DictionarySetKeyStorage
!-------------------------------------------------
subroutine DictionaryReroot(this,new_root)
!Changes the root of the dictionary.
implicit none
class(dictionary_t), intent(inout):: this !inout: dictionary
class(dict_elem_t), pointer, intent(inout):: new_root !in: pointer to the new root or NULL()
if(associated(this%root)) call this%root%decr_ref_()
this%root=>new_root
if(associated(this%root)) call this%root%incr_ref_()
return
end subroutine DictionaryReroot
![dictionary_iter_t]================================
subroutine DictionaryIterJump(this,new_elem)
!Moves the iterator to an arbitrary specified position.
implicit none
class(dictionary_iter_t), intent(inout):: this !inout: dictionary iterator
class(dict_elem_t), pointer, intent(inout):: new_elem !in: pointer to the new element or NULL()
integer(INTD):: errc,sts
if(associated(this%current)) call this%current%decr_ref_()
this%current=>new_elem
if(associated(this%current)) then
call this%current%incr_ref_()
errc=this%set_status_(GFC_IT_ACTIVE)
else
if(associated(this%container%root)) then
errc=this%set_status_(GFC_IT_DONE)
else
errc=this%set_status_(GFC_IT_EMPTY)
endif
endif
return
end subroutine DictionaryIterJump
!----------------------------------------------------------
function DictionaryIterInit(this,cont) result(ierr)
!Initializes an iterator and resets it to the beginning of the container.
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
class(gfc_container_t), target, intent(in):: cont !in: container
ierr=GFC_SUCCESS
select type(cont)
class is (dictionary_t)
this%container=>cont
ierr=this%reset()
class default
ierr=GFC_INVALID_ARGS
end select
return
end function DictionaryIterInit
!------------------------------------------------------
function DictionaryIterReset(this) result(ierr)
!Resets the iterator to the beginning (root element).
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
ierr=GFC_SUCCESS
if(associated(this%container)) then
if(associated(this%current)) call this%current%decr_ref_()
this%current=>this%container%root
if(associated(this%current)) then
call this%current%incr_ref_()
ierr=this%set_status_(GFC_IT_ACTIVE) !non-empty iterator/container
else
ierr=this%set_status_(GFC_IT_EMPTY) !empty iterator/container
endif
call this%reset_count() !reset all iteration counters
else
ierr=this%set_status_(GFC_IT_NULL)
ierr=GFC_IT_NULL
endif
return
end function DictionaryIterReset
!--------------------------------------------------------
function DictionaryIterRelease(this) result(ierr)
!Dissociates the iterator from its container.
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
if(associated(this%current)) call this%current%decr_ref_()
this%current=>NULL(); this%container=>NULL()
call this%reset_count(); ierr=this%set_status_(GFC_IT_NULL)
return
end function DictionaryIterRelease
!--------------------------------------------------------------
function DictionaryIterPointee(this,ierr) result(pntee)
!Returns the container element the iterator is currently pointing to.
implicit none
class(gfc_cont_elem_t), pointer:: pntee !out: container element currently pointed to by the iterator
class(dictionary_iter_t), intent(in):: this !in: iterator
integer(INTD), intent(out), optional:: ierr !out: error code
integer(INTD):: errc
errc=this%get_status()
if(errc.eq.GFC_IT_ACTIVE) then
pntee=>this%current; errc=GFC_SUCCESS
else
pntee=>NULL()
endif
if(present(ierr)) ierr=errc
return
end function DictionaryIterPointee
!------------------------------------------------------------
function DictionaryIterNext(this,elem_p) result(ierr)
!Moves the iterator position to the next element (in some sense).
!If <elem_p> is absent, the iterator moves to the next element, if any.
!If <elem_p> is present, the iterator simply returns the next element in <elem_p> without moving.
!Complexity: O(1)...O(logN). No additional memory is used.
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
class(gfc_cont_elem_t), pointer, intent(out), optional:: elem_p !out: pointer to the container element
class(dict_elem_t), pointer:: dp
ierr=this%get_status()
if(ierr.eq.GFC_IT_ACTIVE) then
if(associated(this%current)) then
ierr=GFC_SUCCESS
dp=>this%current%child_lt
if(.not.associated(dp)) then
dp=>this%current%child_gt
if(.not.associated(dp)) then
dp=>this%current
do while(associated(dp))
if(.not.associated(dp,this%container%root)) then !root of a subdictionary may have a parent
if(associated(dp,dp%parent%child_lt)) then !moving up from the left
if(associated(dp%parent%child_gt)) then
dp=>dp%parent%child_gt; exit
endif
endif
dp=>dp%parent
else
dp=>NULL()
endif
enddo
endif
endif
if(present(elem_p)) then
elem_p=>dp
else
call this%current%decr_ref_()
this%current=>dp
if(associated(this%current)) then
call this%current%incr_ref_()
else
ierr=this%set_status_(GFC_IT_DONE)
endif
endif
if(.not.associated(dp)) ierr=GFC_NO_MOVE
dp=>NULL()
else
ierr=GFC_CORRUPTED_CONT
endif
endif
return
end function DictionaryIterNext
!----------------------------------------------------------------
function DictionaryIterPrevious(this,elem_p) result(ierr)
!Moves the iterator position to the previous element (in some sense).
!If <elem_p> is absent, the iterator moves to the previous element, if any.
!If <elem_p> is present, the iterator simply returns the previous element in <elem_p> without moving.
!Complexity: O(1)...O(logN). No additional memory is used.
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
class(gfc_cont_elem_t), pointer, intent(out), optional:: elem_p !out: pointer to the container element
class(dict_elem_t), pointer:: dp
ierr=this%get_status()
if(ierr.eq.GFC_IT_ACTIVE) then
if(associated(this%current)) then
ierr=GFC_SUCCESS
if(associated(this%current,this%container%root)) then
dp=>NULL()
else
dp=>this%current%parent
if(associated(this%current,dp%child_gt).and.associated(dp%child_lt)) then
dp=>dp%child_lt
do
if(associated(dp%child_gt)) then
dp=>dp%child_gt
else
if(associated(dp%child_lt)) then
dp=>dp%child_lt
else
exit
endif
endif
enddo
endif
endif
if(present(elem_p)) then
elem_p=>dp
else
call this%current%decr_ref_()
this%current=>dp
if(associated(this%current)) then
call this%current%incr_ref_()
else
ierr=this%set_status_(GFC_IT_DONE)
endif
endif
if(.not.associated(dp)) ierr=GFC_NO_MOVE
dp=>NULL()
else
ierr=GFC_CORRUPTED_CONT
endif
endif
return
end function DictionaryIterPrevious
!-------------------------------------------------------------------
function DictionaryIterNextInOrder(this,elem_p) result(ierr)
!Moves the iterator position to the next-in-order element.
!If <elem_p> is absent, the iterator moves to the next-in-order element, if any.
!If <elem_p> is present, the iterator simply returns the next-in-order element in <elem_p> without moving.
!Complexity: O(1)...O(logN). No additional memory is used.
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
class(gfc_cont_elem_t), pointer, intent(out), optional:: elem_p !out: pointer to the container element
class(dict_elem_t), pointer:: dp
ierr=this%get_status()
if(ierr.eq.GFC_IT_ACTIVE) then
if(associated(this%current)) then
ierr=GFC_SUCCESS
if(associated(this%current%child_gt)) then
dp=>this%current%child_gt
do while(associated(dp%child_lt)); dp=>dp%child_lt; enddo
else
ierr=GFC_NO_MOVE; dp=>this%current
do while(associated(dp%parent).and.(.not.associated(dp,this%container%root)))
if(associated(dp,dp%parent%child_lt)) then
dp=>dp%parent; ierr=GFC_SUCCESS; exit
else
dp=>dp%parent
endif
enddo
if(ierr.eq.GFC_NO_MOVE) dp=>NULL()
endif
if(present(elem_p)) then
elem_p=>dp
else
call this%current%decr_ref_()
this%current=>dp
if(associated(this%current)) then
call this%current%incr_ref_()
else
ierr=this%set_status_(GFC_IT_DONE)
endif
endif
if(.not.associated(dp)) ierr=GFC_NO_MOVE
dp=>NULL()
else
ierr=GFC_CORRUPTED_CONT
endif
endif
return
end function DictionaryIterNextInOrder
!-------------------------------------------------------------------
function DictionaryIterPrevInOrder(this,elem_p) result(ierr)
!Moves the iterator position to the previous-in-order element.
!If <elem_p> is absent, the iterator moves to the previous-in-order element, if any.
!If <elem_p> is present, the iterator simply returns the previous-in-order element in <elem_p> without moving.
!Complexity: O(1)...O(logN). No additional memory is used.
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
class(gfc_cont_elem_t), pointer, intent(out), optional:: elem_p !out: pointer to the container element
class(dict_elem_t), pointer:: dp
ierr=this%get_status()
if(ierr.eq.GFC_IT_ACTIVE) then
if(associated(this%current)) then
ierr=GFC_SUCCESS
if(associated(this%current%child_lt)) then
dp=>this%current%child_lt
do while(associated(dp%child_gt)); dp=>dp%child_gt; enddo
else
ierr=GFC_NO_MOVE; dp=>this%current
do while(associated(dp%parent).and.(.not.associated(dp,this%container%root)))
if(associated(dp,dp%parent%child_gt)) then
dp=>dp%parent; ierr=GFC_SUCCESS; exit
else
dp=>dp%parent
endif
enddo
if(ierr.eq.GFC_NO_MOVE) dp=>NULL()
endif
if(present(elem_p)) then
elem_p=>dp
else
call this%current%decr_ref_()
this%current=>dp
if(associated(this%current)) then
call this%current%incr_ref_()
else
ierr=this%set_status_(GFC_IT_DONE)
endif
endif
if(.not.associated(dp)) ierr=GFC_NO_MOVE
dp=>NULL()
else
ierr=GFC_CORRUPTED_CONT
endif
endif
return
end function DictionaryIterPrevInOrder
!-----------------------------------------------------------------------------
function DictionaryIterMoveInOrder(this,direction,elem_p) result(ierr)
!Moves the iterator position either to the next-in-order or previous-in-order element.
!If <elem_p> is absent, the iterator moves to the corresponding in-order element, if any.
!If <elem_p> is present, the iterator simply returns the corresponding in-order element
!in <elem_p> without moving. Complexity: O(1)...O(logN). No additional memory is used.
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
logical, intent(in):: direction !direction: {GFC_DICT_SUCCESSOR,GFC_DICT_PREDECESSOR}
class(gfc_cont_elem_t), pointer, intent(out), optional:: elem_p !out: pointer to the container element
if(present(elem_p)) then
if(direction.eqv.GFC_DICT_SUCCESSOR) then
ierr=this%next_in_order(elem_p)
else
ierr=this%prev_in_order(elem_p)
endif
else
if(direction.eqv.GFC_DICT_SUCCESSOR) then
ierr=this%next_in_order()
else
ierr=this%prev_in_order()
endif
endif
return
end function DictionaryIterMoveInOrder
!-----------------------------------------------------------------
function DictionaryIterMoveToMin(this,elem_p) result(ierr)
!Moves the iterator position to the minimal element.
!If <elem_p> is absent, the iterator moves to the minimal element.
!If <elem_p> is present, the iterator simply returns the minimal element in <elem_p> without moving.
!Complexity: O(logN). No additional memory is used.
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
class(gfc_cont_elem_t), pointer, intent(out), optional:: elem_p !out: pointer to the container element
class(dict_elem_t), pointer:: dp
ierr=this%get_status()
if(ierr.eq.GFC_IT_ACTIVE) then
if(associated(this%container%root)) then
ierr=GFC_SUCCESS; dp=>this%container%root
do while(associated(dp%child_lt)); dp=>dp%child_lt; enddo
if(present(elem_p)) then
elem_p=>dp
else
call this%current%decr_ref_()
this%current=>dp
call this%current%incr_ref_()
endif
dp=>NULL()
else
ierr=GFC_CORRUPTED_CONT
endif
endif
return
end function DictionaryIterMoveToMin
!-----------------------------------------------------------------
function DictionaryIterMoveToMax(this,elem_p) result(ierr)
!Moves the iterator position to the maximal element.
!If <elem_p> is absent, the iterator moves to the maximal element.
!If <elem_p> is present, the iterator simply returns the maximal element in <elem_p> without moving.
!Complexity: O(logN). No additional memory is used.
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
class(gfc_cont_elem_t), pointer, intent(out), optional:: elem_p !out: pointer to the container element
class(dict_elem_t), pointer:: dp
ierr=this%get_status()
if(ierr.eq.GFC_IT_ACTIVE) then
if(associated(this%container%root)) then
ierr=GFC_SUCCESS; dp=>this%container%root
do while(associated(dp%child_gt)); dp=>dp%child_gt; enddo
if(present(elem_p)) then
elem_p=>dp
else
call this%current%decr_ref_()
this%current=>dp
call this%current%incr_ref_()
endif
dp=>NULL()
else
ierr=GFC_CORRUPTED_CONT
endif
endif
return
end function DictionaryIterMoveToMax
!--------------------------------------------------------------
function DictionaryIterMoveUp(this,elem_p) result(ierr)
!Moves the iterator position up the binary search tree (to the parental element).
!If <elem_p> is absent, the iterator moves up.
!If <elem_p> is present, the iterator simply returns the corresponding element in <elem_p> without moving.
!Complexity: O(1). No additional memory is used.
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
class(gfc_cont_elem_t), pointer, intent(out), optional:: elem_p !out: pointer to the container element
class(dict_elem_t), pointer:: dp
ierr=this%get_status()
if(ierr.eq.GFC_IT_ACTIVE) then
if(associated(this%current)) then
ierr=GFC_SUCCESS; dp=>NULL()
if(associated(this%current%parent)) then
dp=>this%current%parent
else
ierr=GFC_NO_MOVE
endif
if(present(elem_p)) then
elem_p=>dp
else
if(ierr.eq.GFC_SUCCESS) then
call this%current%decr_ref_()
this%current=>dp
call this%current%incr_ref_()
endif
endif
dp=>NULL()
else
ierr=GFC_CORRUPTED_CONT
endif
endif
return
end function DictionaryIterMoveUp
!--------------------------------------------------------------------------
function DictionaryIterMoveDown(this,elem_p,direction) result(ierr)
!Moves the iterator position down the binary search tree, either left or right.
!If <elem_p> is absent, the iterator moves down.
!If <elem_p> is present, the iterator simply returns the corresponding element in <elem_p> without moving.
!Complexity: O(1). No additional memory is used.
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: iterator
class(gfc_cont_elem_t), pointer, intent(out), optional:: elem_p !out: pointer to the container element
logical, intent(in), optional:: direction !in: direction: {GFC_DICT_LEFT,GFC_DICT_RIGHT}
class(dict_elem_t), pointer:: dp
ierr=this%get_status()
if(ierr.eq.GFC_IT_ACTIVE) then
if(associated(this%current)) then
ierr=GFC_SUCCESS; dp=>NULL()
if(present(direction)) then
if(direction.eqv.GFC_DICT_LEFT) then !move down left
if(associated(this%current%child_lt)) then
dp=>this%current%child_lt
else
ierr=GFC_NO_MOVE
endif
else !move down right
if(associated(this%current%child_gt)) then
dp=>this%current%child_gt
else
ierr=GFC_NO_MOVE
endif
endif
else !move left, if not left, move right
if(associated(this%current%child_lt)) then
dp=>this%current%child_lt
else
if(associated(this%current%child_gt)) then
dp=>this%current%child_gt
else
ierr=GFC_NO_MOVE
endif
endif
endif
if(present(elem_p)) then
elem_p=>dp
else
if(ierr.eq.GFC_SUCCESS) then
call this%current%decr_ref_()
this%current=>dp
call this%current%incr_ref_()
endif
endif
dp=>NULL()
else
ierr=GFC_CORRUPTED_CONT
endif
endif
return
end function DictionaryIterMoveDown
!-------------------------------------------------------------
function DictionaryIterGetKey(this,ierr) result(key_p)
!Returns a pointer to the key in the current iterator position.
implicit none
class(*), pointer:: key_p !out: pointer to the current position key
class(dictionary_iter_t), intent(in):: this !in: dictionary iterator
integer(INTD), intent(out), optional:: ierr !out: error code
integer(INTD):: errc
key_p=>NULL(); errc=this%get_status()
if(errc.eq.GFC_IT_ACTIVE) then
if(associated(this%current)) then
key_p=>this%current%get_key(errc)
else
errc=GFC_ERROR
endif
endif
if(present(ierr)) ierr=errc
return
end function DictionaryIterGetKey
!-----------------------------------------------------------------
function DictionaryIterDeleteAll(this,dtor_f) result(ierr)
!Deletes all dictionary elements, leaving dictionary empty at the end.
!Complexity: O(NLogN)
implicit none
integer(INTD):: ierr !out: error code
class(dictionary_iter_t), intent(inout):: this !inout: dictionary iterator
procedure(gfc_destruct_i), optional:: dtor_f !in: explicit destructor for the dictionary element value
integer(INTD):: errc
class(dict_elem_t), pointer:: dp
integer:: ier
ierr=this%get_status()
if(ierr.eq.GFC_IT_ACTIVE) then
ierr=this%reset()
if(ierr.eq.GFC_SUCCESS) then
dloop: do
do while(ierr.eq.GFC_SUCCESS); ierr=this%move_down(); enddo
if(ierr.eq.GFC_NO_MOVE.and.associated(this%current)) then
if(present(dtor_f)) then
call this%current%destruct_keyval(ierr,key_assoc=this%container%key_storage,dtor_f=dtor_f)
else
call this%current%destruct_keyval(ierr,key_assoc=this%container%key_storage)
endif
if(ierr.eq.GFC_SUCCESS) then
if(associated(this%current,this%container%root)) then !last element (root)
if(associated(this%current%parent)) then
if(associated(this%current,this%current%parent%child_lt)) then
this%current%parent%child_lt=>NULL()
elseif(associated(this%current,this%current%parent%child_gt)) then
this%current%parent%child_gt=>NULL()
else
ierr=GFC_CORRUPTED_CONT; exit dloop
endif
endif
call this%current%decr_ref_()
deallocate(this%current,STAT=ier)
if(ier.ne.0) ierr=GFC_MEM_FREE_FAILED
this%current=>NULL(); errc=this%set_status_(GFC_IT_EMPTY)
if(ierr.eq.GFC_SUCCESS) ierr=errc
exit dloop
else
dp=>this%current
call this%current%decr_ref_()
this%current=>this%current%parent
call this%current%incr_ref_()
if(associated(this%current%child_lt,dp)) then
this%current%child_lt=>NULL()
elseif(associated(this%current%child_gt,dp)) then
this%current%child_gt=>NULL()
else
ierr=GFC_CORRUPTED_CONT; exit dloop
endif
dp%parent=>NULL()
deallocate(dp,STAT=ier)
if(ier.ne.0) then; ierr=GFC_MEM_FREE_FAILED; exit dloop; endif
endif
else
exit dloop
endif
else
ierr=GFC_ERROR; exit dloop
endif
enddo dloop
else
ierr=GFC_ERROR
endif
elseif(ierr.eq.GFC_IT_EMPTY) then
ierr=GFC_EMPTY_CONT
else
ierr=GFC_NULL_CONT
endif
return
end function DictionaryIterDeleteAll
!-----------------------------------------------------------------------------------------------------------------------
#if !(defined(__GNUC__) && __GNUC__ < 9)
function DictionaryIterSearch(this,action,cmp_key_f,key,value_in,store_by,value_out,copy_ctor_val_f,dtor_val_f)&
&result(dict_search)
#else
function DictionaryIterSearch(this,action,cmp_key_f,key,value_in,store_by,value_out,dtor_val_f)&
&result(dict_search)
#endif
!Looks up a given key in the dictionary with optional actions. If the key is found (and not deleted)
!or newly added, then the current iterator position will point to that item, otherwise it will not change.
!The incoming iterator must have been initialized (either ACTIVE or EMPTY).
implicit none
integer(INTD):: dict_search !out: result: {GFC_FOUND,GFC_NOT_FOUND,specific errors}
class(dictionary_iter_t), intent(inout):: this !inout: dictionary iterator
integer, intent(in):: action !in: requested action (see action parameters at the top of this module)
procedure(gfc_cmp_i):: cmp_key_f !in: key comparison function, returns: {GFC_CMP_LT,GFC_CMP_GT,GFC_CMP_EQ,GFC_CMP_ERR}
class(*), intent(in), target:: key !in: key being searched for
class(*), intent(in), target, optional:: value_in !in: an optional value to be stored with the key
logical, intent(in), optional:: store_by !in: storage type for newly added values: {GFC_BY_VAL,GFC_BY_REF}, defaults to GFC_BY_VAL
class(*), pointer, intent(out), optional:: value_out !out: when fetching, this will point to the value found by the key (NULL otherwise)
#if !(defined(__GNUC__) && __GNUC__ < 9)
procedure(gfc_copy_i), optional:: copy_ctor_val_f !in: explicit copy constructor for the element value, if needed
#endif
procedure(gfc_destruct_i), optional:: dtor_val_f !in: explicit destructor for the dictionary element value, if needed
class(dict_elem_t), pointer:: curr,old_cdp,leave,term,nullptr
class(dictionary_t), pointer:: dict
integer(INTD):: i,j,act,lev_p,grow,ierr
dict_search=this%get_status()
if(dict_search.eq.GFC_IT_DONE) then
dict_search=this%reset(); if(dict_search.ne.GFC_SUCCESS) return
dict_search=this%get_status()
endif
if(dict_search.ne.GFC_IT_ACTIVE.and.dict_search.ne.GFC_IT_EMPTY) return
dict_search=GFC_NOT_FOUND; if(present(value_out)) value_out=>NULL(); nullptr=>NULL()
if(associated(this%container)) then; dict=>this%container; else; dict_search=GFC_CORRUPTED_CONT; return; endif
!Look up the key:
if(associated(dict%root)) then
curr=>dict%root; lev_p=0
sloop: do
i=cmp_key_f(key,curr%key)
if(i.eq.GFC_CMP_LT) then
if(associated(curr%child_lt)) then; curr=>curr%child_lt; lev_p=lev_p+1; else; exit sloop; endif
elseif(i.eq.GFC_CMP_GT) then
if(associated(curr%child_gt)) then; curr=>curr%child_gt; lev_p=lev_p+1; else; exit sloop; endif
elseif(i.eq.GFC_CMP_EQ) then
dict_search=GFC_FOUND; exit sloop
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): key comparison failed: error ",i11)') i
dict_search=GFC_CMP_ERR; curr=>NULL(); return
endif
enddo sloop
else
i=0; curr=>NULL(); lev_p=-1 !empty dictionary
endif
!Action:
if(action.eq.GFC_DICT_ADD_OR_MODIFY) then
if(dict_search.eq.GFC_NOT_FOUND) then
act=GFC_DICT_ADD_IF_NOT_FOUND
elseif(dict_search.eq.GFC_FOUND) then
act=GFC_DICT_REPLACE_IF_FOUND
endif
else
act=action
endif
select case(act) !process the action
case(GFC_DICT_JUST_FIND) !no action, no return of the found value
if(dict_search.eq.GFC_FOUND) call this%jump_(curr)
case(GFC_DICT_FETCH_IF_FOUND) !return the pointer to the stored <value> if found
if(dict_search.eq.GFC_FOUND) then
if(present(value_out)) then
value_out=>curr%get_value(ierr)
if(ierr.eq.GFC_SUCCESS) then; call this%jump_(curr); else; dict_search=ierr; endif
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): fetch: absent value return pointer!")')
dict_search=GFC_INVALID_ARGS; curr=>NULL(); return
endif
endif
case(GFC_DICT_REPLACE_IF_FOUND) !replace the stored <value> if found
if(dict_search.eq.GFC_FOUND) then
if(present(dtor_val_f)) then
call curr%gfc_cont_elem_t%destruct(ierr,dtor_f=dtor_val_f)
else
call curr%gfc_cont_elem_t%destruct(ierr)
endif
if(ierr.ne.GFC_SUCCESS) then
if(VERBOSE)&
&write(CONS_OUT,'("#ERROR(gfc::dictionary::search): replace: dictionary element value destruction failed!")')
dict_search=GFC_MEM_FREE_FAILED; curr=>NULL(); return
endif
if(present(value_in)) then
if(present(store_by)) then
call curr%gfc_cont_elem_t%construct_base(value_in,ierr,assoc_only=store_by)
else
call curr%gfc_cont_elem_t%construct_base(value_in,ierr)
endif
if(ierr.ne.GFC_SUCCESS) then
if(VERBOSE)&
&write(CONS_OUT,'("#ERROR(gfc::dictionary::search): replace: dictionary element value construction failed!")')
dict_search=GFC_MEM_ALLOC_FAILED; curr=>NULL(); return
endif
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): replace: absent input value!")')
dict_search=GFC_INVALID_ARGS; curr=>NULL(); return
endif
if(present(value_out)) then; value_out=>curr%get_value(ierr); else; ierr=GFC_SUCCESS; endif
if(ierr.eq.GFC_SUCCESS) then; call this%jump_(curr); else; dict_search=ierr; endif
endif
case(GFC_DICT_DELETE_IF_FOUND) !delete the item if found
if(dict_search.eq.GFC_FOUND) then
if(associated(this%current)) then
if(associated(this%current,curr)) then; old_cdp=>NULL(); else; old_cdp=>this%current; endif
else
old_cdp=>NULL()
endif
call this%jump_(curr)
if(associated(curr%child_lt).and.associated(curr%child_gt)) then !both subtrees are present
if(curr%balance_fac.le.0) then !right subtree is taller or equal
grow=-1; j=this%move_in_order(GFC_DICT_SUCCESSOR) !find in-order successor
if(j.eq.GFC_SUCCESS) then
if(associated(this%current%child_gt)) then
leave=>this%current%child_gt
else
leave=>NULL()
endif
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: next in-order not found!")')
dict_search=GFC_CORRUPTED_CONT
endif
else !left subtree is taller
grow=+1; j=this%move_in_order(GFC_DICT_PREDECESSOR) !find in-order predecessor
if(j.eq.GFC_SUCCESS) then
if(associated(this%current%child_lt)) then
leave=>this%current%child_lt
else
leave=>NULL()
endif
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: previous in-order not found!")')
dict_search=GFC_CORRUPTED_CONT
endif
endif
if(dict_search.eq.GFC_FOUND) then
if(associated(this%current%parent,curr)) then
term=>NULL()
else
term=>this%current%parent
endif
if(associated(curr%parent)) then
if(associated(curr%parent%child_lt,curr)) then
curr%parent%child_lt=>this%current
elseif(associated(curr%parent%child_gt,curr)) then
curr%parent%child_gt=>this%current
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: lost parent!")')
dict_search=GFC_CORRUPTED_CONT
endif
else
if(associated(dict%root,curr)) then
call dict%reroot_(this%current)
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: lost root!")')
dict_search=GFC_CORRUPTED_CONT
endif
endif
if(dict_search.eq.GFC_FOUND) then
if(grow.gt.0) then !reducing the left subtree
if(associated(term)) then
curr%child_lt%parent=>this%current
this%current%child_lt=>curr%child_lt
if(associated(leave)) then
term%child_gt=>leave; leave%parent=>term
else
term%child_gt=>NULL()
endif
endif
curr%child_gt%parent=>this%current
this%current%child_gt=>curr%child_gt
elseif(grow.lt.0) then !reducing the right subtree
if(associated(term)) then
curr%child_gt%parent=>this%current
this%current%child_gt=>curr%child_gt
if(associated(leave)) then
term%child_lt=>leave; leave%parent=>term
else
term%child_lt=>NULL()
endif
endif
curr%child_lt%parent=>this%current
this%current%child_lt=>curr%child_lt
endif
if(associated(curr%parent)) then
this%current%parent=>curr%parent
else
this%current%parent=>NULL()
endif
this%current%balance_fac=curr%balance_fac
if(associated(term)) then
call this%jump_(term); grow=-grow; term=>NULL()
endif
if(associated(leave)) leave=>NULL()
endif
endif
else !at least one subtree is absent
if(associated(curr%child_lt)) then !left subtree is present (a leave)
if(associated(curr%parent)) then
if(associated(curr%parent%child_lt,curr)) then
curr%parent%child_lt=>curr%child_lt; call this%jump_(curr%parent); grow=+1
elseif(associated(curr%parent%child_gt,curr)) then
curr%parent%child_gt=>curr%child_lt; call this%jump_(curr%parent); grow=-1
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: lost parent!")')
dict_search=GFC_CORRUPTED_CONT
endif
curr%child_lt%parent=>curr%parent
else
if(associated(dict%root,curr)) then
call dict%reroot_(curr%child_lt)
dict%root%parent=>NULL(); grow=0
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: lost root!")')
dict_search=GFc_CORRUPTED_CONT
endif
endif
elseif(associated(curr%child_gt)) then !right subtree is present (a leave)
if(associated(curr%parent)) then
if(associated(curr%parent%child_lt,curr)) then
curr%parent%child_lt=>curr%child_gt; call this%jump_(curr%parent); grow=+1
elseif(associated(curr%parent%child_gt,curr)) then
curr%parent%child_gt=>curr%child_gt; call this%jump_(curr%parent); grow=-1
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: lost parent!")')
dict_search=GFC_CORRUPTED_CONT
endif
curr%child_gt%parent=>curr%parent
else
if(associated(dict%root,curr)) then
call dict%reroot_(curr%child_gt)
dict%root%parent=>NULL(); grow=0
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: lost root!")')
dict_search=GFC_CORRUPTED_CONT
endif
endif
else !both subtrees are absent
if(associated(curr%parent)) then
if(associated(curr%parent%child_lt,curr)) then
curr%parent%child_lt=>NULL(); call this%jump_(curr%parent); grow=+1
elseif(associated(curr%parent%child_gt,curr)) then
curr%parent%child_gt=>NULL(); call this%jump_(curr%parent); grow=-1
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: lost parent!")')
dict_search=GFC_CORRUPTED_CONT
endif
else
if(associated(dict%root,curr)) then
call dict%reroot_(nullptr)
call this%jump_(nullptr); grow=0
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: lost root!")')
dict_search=GFC_CORRUPTED_CONT
endif
endif
endif
endif
if(present(dtor_val_f)) then
call curr%destruct_keyval(j,key_assoc=dict%key_storage,dtor_f=dtor_val_f)
else
call curr%destruct_keyval(j,key_assoc=dict%key_storage)
endif
if(j.ne.GFC_SUCCESS) then
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: dictionary element destruction failed!")')
dict_search=GFC_MEM_FREE_FAILED
endif
if(associated(this%current,curr)) this%current=>NULL()
deallocate(curr,STAT=j)
if(j.ne.0) then
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: dictionary element deallocation failed!")')
dict_search=GFC_MEM_FREE_FAILED
endif
if(dict_search.eq.GFC_FOUND.and.grow.ne.0) then
ierr=-1; call rebalance(this%current,grow,ierr)
if(ierr.ne.0) then
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): delete: rebalancing failed: ",i11)') ierr
dict_search=GFC_CORRUPTED_CONT
endif
endif
if(associated(old_cdp)) then
call this%jump_(old_cdp); old_cdp=>NULL()
else
call this%jump_(nullptr)
endif
endif
case(GFC_DICT_ADD_IF_NOT_FOUND) !add a new item if the key is not found
if(dict_search.eq.GFC_NOT_FOUND) then
if(lev_p.ge.0) then
if(i.eq.GFC_CMP_LT) then
allocate(curr%child_lt,STAT=j)
if(j.ne.0) then
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): add: dictionary element allocation failed!")')
dict_search=GFC_MEM_ALLOC_FAILED; curr=>NULL(); return
endif
curr%child_lt%parent=>curr
grow=+1; curr=>curr%child_lt
elseif(i.eq.GFC_CMP_GT) then
allocate(curr%child_gt,STAT=j)
if(j.ne.0) then
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): add: dictionary element allocation failed!")')
dict_search=GFC_MEM_ALLOC_FAILED; curr=>NULL(); return
endif
curr%child_gt%parent=>curr
grow=-1; curr=>curr%child_gt
endif
curr%child_lt=>NULL(); curr%child_gt=>NULL(); curr%balance_fac=0
ierr=+1; call rebalance(curr%parent,grow,ierr)
if(ierr.ne.0) then
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): add: rebalancing failed: ",i11)') ierr
dict_search=GFC_CORRUPTED_CONT; curr=>NULL(); return
endif
if(present(value_in)) then
if(present(store_by)) then
#if !(defined(__GNUC__) && __GNUC__ < 9)
if(present(copy_ctor_val_f)) then
call curr%dict_elem_ctor(key,value_in,j,assoc_key=dict%key_storage,assoc_val=store_by,&
&val_copy_ctor_f=copy_ctor_val_f)
else
#endif
call curr%dict_elem_ctor(key,value_in,j,assoc_key=dict%key_storage,assoc_val=store_by)
#if !(defined(__GNUC__) && __GNUC__ < 9)
endif
#endif
else
#if !(defined(__GNUC__) && __GNUC__ < 9)
if(present(copy_ctor_val_f)) then
call curr%dict_elem_ctor(key,value_in,j,assoc_key=dict%key_storage,val_copy_ctor_f=copy_ctor_val_f)
else
#endif
call curr%dict_elem_ctor(key,value_in,j,assoc_key=dict%key_storage)
#if !(defined(__GNUC__) && __GNUC__ < 9)
endif
#endif
endif
if(j.ne.GFC_SUCCESS) then
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): add: dictionary element construction failed!")')
dict_search=GFC_MEM_ALLOC_FAILED; curr=>NULL(); return
endif
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): add: absent input value!")')
dict_search=GFC_INVALID_ARGS; curr=>NULL(); return
endif
if(present(value_out)) then; value_out=>curr%get_value(ierr); else; ierr=GFC_SUCCESS; endif
if(ierr.eq.GFC_SUCCESS) then; call this%jump_(curr); else; dict_search=ierr; endif
else !empty dictionary
allocate(curr,STAT=j)
if(j.ne.0) then
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): add: dictionary root allocation failed!")')
dict_search=GFC_MEM_ALLOC_FAILED; curr=>NULL(); return
endif
curr%parent=>NULL(); curr%child_lt=>NULL(); curr%child_gt=>NULL(); curr%balance_fac=0
if(present(value_in)) then
if(present(store_by)) then
#if !(defined(__GNUC__) && __GNUC__ < 9)
if(present(copy_ctor_val_f)) then
call curr%dict_elem_ctor(key,value_in,j,assoc_key=dict%key_storage,assoc_val=store_by,&
&val_copy_ctor_f=copy_ctor_val_f)
else
#endif
call curr%dict_elem_ctor(key,value_in,j,assoc_key=dict%key_storage,assoc_val=store_by)
#if !(defined(__GNUC__) && __GNUC__ < 9)
endif
#endif
else
#if !(defined(__GNUC__) && __GNUC__ < 9)
if(present(copy_ctor_val_f)) then
call curr%dict_elem_ctor(key,value_in,j,assoc_key=dict%key_storage,val_copy_ctor_f=copy_ctor_val_f)
else
#endif
call curr%dict_elem_ctor(key,value_in,j,assoc_key=dict%key_storage)
#if !(defined(__GNUC__) && __GNUC__ < 9)
endif
#endif
endif
if(j.ne.GFC_SUCCESS) then
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): add: dictionary root construction failed!")')
dict_search=GFC_MEM_ALLOC_FAILED; curr=>NULL(); return
endif
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): add: absent input value for root!")')
dict_search=GFC_INVALID_ARGS; curr=>NULL(); return
endif
call dict%reroot_(curr); ierr=this%reset()
if(ierr.eq.GFC_SUCCESS) then
if(present(value_out)) then; value_out=>curr%get_value(ierr); if(ierr.ne.GFC_SUCCESS) dict_search=ierr; endif
else
dict_search=ierr
endif
endif
elseif(dict_search.eq.GFC_FOUND) then !return the found entry value (just in case)
if(present(value_out)) then; value_out=>curr%get_value(ierr); else; ierr=GFC_SUCCESS; endif
if(ierr.eq.GFC_SUCCESS) then; call this%jump_(curr); else; dict_search=ierr; endif
endif
case default
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search): unknown search action request: ",i11)') action
dict_search=GFC_UNKNOWN_REQUEST; curr=>NULL(); return
end select
curr=>NULL()
return
contains
subroutine rebalance(cr,gr,ier)
class(dict_elem_t), pointer:: cr !intermediate element on the way back to root
integer(INTD), intent(in):: gr !in(right/left subtree change): {-1;+1}
integer(INTD), intent(inout):: ier !in(height decrease/increase): {-1;+1}; out: {0;{error_codes}}
class(dict_elem_t), pointer:: cr_ptr
integer(INTD):: jb,jc,jg,jd
! if(DEBUG) write(CONS_OUT,'("Entered rebalance:")') !debug
jd=ier; jg=gr; cr_ptr=>cr
do while(jg.ne.0)
! if(DEBUG) write(CONS_OUT,'(" Rebalance at level ",i3)') lev_p !debug
cr_ptr%balance_fac=cr_ptr%balance_fac+jg*jd
if(iabs(cr_ptr%balance_fac).ge.2) then !rotations needed
if(cr_ptr%balance_fac.eq.-2) then
jb=cr_ptr%child_gt%balance_fac
if(jb.gt.0) then !{+1}
jc=cr_ptr%child_gt%child_lt%balance_fac
call rotate_double_left(cr_ptr)
if(dict_search.ne.GFC_FOUND.and.dict_search.ne.GFC_NOT_FOUND) then; cr_ptr=>NULL(); ier=1; return; endif
cr_ptr%parent%balance_fac=0; if(jd.gt.0) jg=0
if(jc.gt.0) then
cr_ptr%balance_fac=0; cr_ptr%parent%child_gt%balance_fac=-1
elseif(jc.lt.0) then
cr_ptr%balance_fac=1; cr_ptr%parent%child_gt%balance_fac=0
else !jc=0
cr_ptr%balance_fac=0; cr_ptr%parent%child_gt%balance_fac=0
endif
else !{-1;0}
call rotate_simple_left(cr_ptr)
if(dict_search.ne.GFC_FOUND.and.dict_search.ne.GFC_NOT_FOUND) then; cr_ptr=>NULL(); ier=2; return; endif
if(jb.eq.0) then
cr_ptr%balance_fac=-1; cr_ptr%parent%balance_fac=1; if(jd.lt.0) jg=0
else
cr_ptr%balance_fac=0; cr_ptr%parent%balance_fac=0; if(jd.gt.0) jg=0
endif
endif
cr_ptr=>cr_ptr%parent
elseif(cr_ptr%balance_fac.eq.2) then
jb=cr_ptr%child_lt%balance_fac
if(jb.lt.0) then !{-1}
jc=cr_ptr%child_lt%child_gt%balance_fac
call rotate_double_right(cr_ptr)
if(dict_search.ne.GFC_FOUND.and.dict_search.ne.GFC_NOT_FOUND) then; cr_ptr=>NULL(); ier=3; return; endif
cr_ptr%parent%balance_fac=0; if(jd.gt.0) jg=0
if(jc.lt.0) then
cr_ptr%balance_fac=0; cr_ptr%parent%child_lt%balance_fac=1
elseif(jc.gt.0) then
cr_ptr%balance_fac=-1; cr_ptr%parent%child_lt%balance_fac=0
else !jc=0
cr_ptr%balance_fac=0; cr_ptr%parent%child_lt%balance_fac=0
endif
else !{0;+1}
call rotate_simple_right(cr_ptr)
if(dict_search.ne.GFC_FOUND.and.dict_search.ne.GFC_NOT_FOUND) then; cr_ptr=>NULL(); ier=4; return; endif
if(jb.eq.0) then
cr_ptr%balance_fac=+1; cr_ptr%parent%balance_fac=-1; if(jd.lt.0) jg=0
else
cr_ptr%balance_fac=0; cr_ptr%parent%balance_fac=0; if(jd.gt.0) jg=0
endif
endif
cr_ptr=>cr_ptr%parent
else
if(VERBOSE)&
&write(CONS_OUT,'("#ERROR(gfc::dictionary::search): rebalance: invalid balance factor: ",i11)') cr_ptr%balance_fac
cr_ptr=>NULL(); ier=5; return
endif
else !node balance factor changed to {-1;0;+1}
if(jd.gt.0) then
if(cr_ptr%balance_fac.eq.0) jg=0
elseif(jd.lt.0) then
if(cr_ptr%balance_fac.ne.0) jg=0
endif
endif
if(associated(cr_ptr%parent)) then
jg=iabs(jg); if(associated(cr_ptr%parent%child_gt,cr_ptr)) jg=-jg
cr_ptr=>cr_ptr%parent; lev_p=lev_p-1
else
call dict%reroot_(cr_ptr)
exit
endif
enddo
ier=0; cr_ptr=>NULL()
! if(DEBUG) write(CONS_OUT,'("Exited rebalance.")') !debug
return
end subroutine rebalance
subroutine rotate_double_left(cr)
class(dict_elem_t), pointer:: cr
call rotate_simple_right(cr%child_gt)
if(dict_search.ne.GFC_FOUND.and.dict_search.ne.GFC_NOT_FOUND) return
call rotate_simple_left(cr)
return
end subroutine rotate_double_left
subroutine rotate_double_right(cr)
class(dict_elem_t), pointer:: cr
call rotate_simple_left(cr%child_lt)
if(dict_search.ne.GFC_FOUND.and.dict_search.ne.GFC_NOT_FOUND) return
call rotate_simple_right(cr)
return
end subroutine rotate_double_right
subroutine rotate_simple_left(cr)
class(dict_elem_t), pointer:: cr
class(dict_elem_t), pointer:: jp,jq,js
! if(DEBUG) write(CONS_OUT,'(" Rotating left")') !debug
jp=>cr; jq=>cr%child_gt; js=>jq%child_lt !js may be null
jq%child_lt=>jp
if(associated(jp%parent)) then
if(associated(jp%parent%child_lt,jp)) then
jp%parent%child_lt=>jq
elseif(associated(jp%parent%child_gt,jp)) then
jp%parent%child_gt=>jq
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search:rotate_simple_left): broken parental link!")')
dict_search=GFC_CORRUPTED_CONT; return
endif
jq%parent=>jp%parent
else
jq%parent=>NULL()
endif
jp%parent=>jq
jp%child_gt=>js; if(associated(js)) js%parent=>jp
return
end subroutine rotate_simple_left
subroutine rotate_simple_right(cr)
class(dict_elem_t), pointer:: cr
class(dict_elem_t), pointer:: jp,jq,js
! if(DEBUG) write(CONS_OUT,'(" Rotating right")') !debug
jp=>cr; jq=>cr%child_lt; js=>jq%child_gt !js may be null
jq%child_gt=>jp
if(associated(jp%parent)) then
if(associated(jp%parent%child_lt,jp)) then
jp%parent%child_lt=>jq
elseif(associated(jp%parent%child_gt,jp)) then
jp%parent%child_gt=>jq
else
if(VERBOSE) write(CONS_OUT,'("#ERROR(gfc::dictionary::search:rotate_simple_right): broken parental link!")')
dict_search=GFC_CORRUPTED_CONT; return
endif
jq%parent=>jp%parent
else
jq%parent=>NULL()
endif
jp%parent=>jq
jp%child_lt=>js; if(associated(js)) js%parent=>jp
return
end subroutine rotate_simple_right
end function DictionaryIterSearch
!---------------------------------------------------------------------
subroutine DictionaryIterSortToList(this,list_refs,ierr,order)
!Returns a bidirectional linked list of references to dictionary elements in a sorted order.
!The input dictionary iterator is allowed to be a subdictionary iterator.
!The current dictionary iterator position is kept intact, unless the
!iterator in the GFC_IT_DONE state, in which case it will be reset.
!The bidirectional linked list must be empty on entrance.
implicit none
class(dictionary_iter_t), intent(inout):: this !in: dictionary (or subdictionary) iterator
class(list_bi_t), intent(inout):: list_refs !out: bidirectional list of references to dictionary elements (in:empty,out:filled)
integer(INTD), intent(out), optional:: ierr !out: error code
integer(INTD), intent(in), optional:: order !in: sorting order: {GFC_ASCEND_ORDER,GFC_DESCEND_ORDER}, defaults to GFC_ASCEND_ORDER
integer(INTD):: errc,ier,ord
logical:: dir
type(list_iter_t):: list_it
class(dict_elem_t), pointer:: orig
errc=list_it%init(list_refs)
if(errc.eq.GFC_SUCCESS) then
if(list_it%get_status().eq.GFC_IT_EMPTY) then
errc=this%get_status()
if(errc.eq.GFC_IT_DONE) then; errc=this%reset(); errc=this%get_status(); endif
if(errc.eq.GFC_IT_ACTIVE) then
if(present(order)) then; ord=order; else; ord=GFC_ASCEND_ORDER; endif
orig=>this%current !save the original iterator position
if(ord.eq.GFC_ASCEND_ORDER) then
errc=this%move_to_min(); dir=GFC_DICT_SUCCESSOR
else
errc=this%move_to_max(); dir=GFC_DICT_PREDECESSOR
endif
if(errc.eq.GFC_SUCCESS) then
sloop: do while(errc.eq.GFC_SUCCESS)
errc=list_it%append(this%current,assoc_only=.TRUE.)
if(errc.ne.GFC_SUCCESS) exit sloop
errc=this%move_in_order(dir)
enddo sloop
if(errc.eq.GFC_NO_MOVE) errc=this%reset()
else
errc=GFC_CORRUPTED_CONT
endif
call this%jump_(orig) !return to the original iterator position
else
if(errc.ne.GFC_IT_EMPTY) errc=GFC_NULL_CONT
endif
else
errc=GFC_INVALID_ARGS
endif
ier=list_it%release()
if(errc.eq.GFC_SUCCESS.and.ier.ne.GFC_SUCCESS) errc=ier
endif
if(present(ierr)) ierr=errc
return
end subroutine DictionaryIterSortToList
!----------------------------------------------------------------------
subroutine DictionaryIterSortToVector(this,vec_refs,ierr,order)
!Returns a vector of references to dictionary elements in a sorted order.
!The input dictionary iterator is allowed to be a subdictionary iterator.
!The current dictionary iterator position is kept intact, unless the
!iterator in the GFC_IT_DONE state, in which case it will be reset.
!The vector must be empty on entrance.
implicit none
class(dictionary_iter_t), intent(inout):: this !in: dictionary (or subdictionary) iterator
class(vector_t), intent(inout):: vec_refs !out: vector of references to dictionary elements (in:empty,out:filled)
integer(INTD), intent(out), optional:: ierr !out: error code
integer(INTD), intent(in), optional:: order !in: sorting order: {GFC_ASCEND_ORDER,GFC_DESCEND_ORDER}, defaults to GFC_ASCEND_ORDER
integer(INTD):: errc,ier,ord
logical:: dir
type(vector_iter_t):: vec_it
class(dict_elem_t), pointer:: orig
errc=vec_it%init(vec_refs)
if(errc.eq.GFC_SUCCESS) then
if(vec_it%get_status().eq.GFC_IT_EMPTY) then
errc=this%get_status()
if(errc.eq.GFC_IT_DONE) then; errc=this%reset(); errc=this%get_status(); endif
if(errc.eq.GFC_IT_ACTIVE) then
if(present(order)) then; ord=order; else; ord=GFC_ASCEND_ORDER; endif
orig=>this%current !save the original iterator position
if(ord.eq.GFC_ASCEND_ORDER) then
errc=this%move_to_min(); dir=GFC_DICT_SUCCESSOR
else
errc=this%move_to_max(); dir=GFC_DICT_PREDECESSOR
endif
if(errc.eq.GFC_SUCCESS) then
sloop: do while(errc.eq.GFC_SUCCESS)
errc=vec_it%append(this%current,assoc_only=.TRUE.)
if(errc.ne.GFC_SUCCESS) exit sloop
errc=this%move_in_order(dir)
enddo sloop
if(errc.eq.GFC_NO_MOVE) errc=this%reset()
else
errc=GFC_CORRUPTED_CONT
endif
call this%jump_(orig) !return to the original iterator position
else
if(errc.ne.GFC_IT_EMPTY) errc=GFC_NULL_CONT
endif
else
errc=GFC_INVALID_ARGS
endif
ier=vec_it%release()
if(errc.eq.GFC_SUCCESS.and.ier.ne.GFC_SUCCESS) errc=ier
endif
if(present(ierr)) ierr=errc
return
end subroutine DictionaryIterSortToVector
end module gfc_dictionary
!===============================
!TESTING:
!--------------------------------
module gfc_dictionary_test
use gfc_base
use gfc_list
use gfc_dictionary
use timers, only: thread_wtime
implicit none
private
!PARAMETERS:
integer(INTD), parameter, private:: KEY_LEN=6
integer(INTD), parameter, private:: MAX_IND_VAL=7
!TYPES:
!Key:
type, private:: key_t
integer(INTD):: rank=KEY_LEN
integer(INTD):: dims(1:KEY_LEN)
end type key_t
!Value:
type, private:: val_t
real(8):: my_array(1:KEY_LEN)
type(key_t):: key_stored
end type val_t
!VISIBILITY:
private cmp_key_test
public test_gfc_dictionary
contains
!-------------------------------------------------
function cmp_key_test(up1,up2) result(cmp)
implicit none
integer(INTD):: cmp
class(*), intent(in), target:: up1,up2
integer(INTD):: i
cmp=GFC_CMP_ERR
select type(up1)
class is(key_t)
select type(up2)
class is(key_t)
if(up1%rank.lt.up2%rank) then
cmp=GFC_CMP_LT
elseif(up1%rank.gt.up2%rank) then
cmp=GFC_CMP_GT
else
cmp=GFC_CMP_EQ
do i=1,up1%rank
if(up1%dims(i).lt.up2%dims(i)) then
cmp=GFC_CMP_LT; exit
elseif(up1%dims(i).gt.up2%dims(i)) then
cmp=GFC_CMP_GT; exit
endif
enddo
endif
end select
end select
return
end function cmp_key_test
!----------------------------------------------------
function print_key(obj,dev_id) result(ierr)
implicit none
integer(INTD):: ierr
class(*), intent(in):: obj
integer(INTD), intent(in), optional:: dev_id
integer(INTD):: dev
ierr=GFC_SUCCESS
if(present(dev_id)) then; dev=dev_id; else; dev=6; endif
select type(obj)
class is(key_t)
write(dev,'(32(1x,i9))') obj%dims(1:obj%rank)
class default
ierr=GFC_ACTION_FAILED
end select
return
end function print_key
!----------------------------------------------------
function print_value(obj,dev_id) result(ierr)
implicit none
integer(INTD):: ierr
class(*), intent(in):: obj
integer(INTD), intent(in), optional:: dev_id
integer(INTD):: dev
ierr=GFC_SUCCESS
if(present(dev_id)) then; dev=dev_id; else; dev=6; endif
select type(obj)
class is(val_t)
write(dev,'(32(1x,D15.7))') obj%my_array(1:obj%key_stored%rank)
class default
ierr=GFC_ACTION_FAILED
end select
return
end function print_value
!--------------------------------------------------------------
function test_gfc_dictionary(perf,dev_out) result(ierr)
implicit none
integer(INTD):: ierr !out: error code (0:success)
real(8), intent(out):: perf !out: performance index
integer(INTD), intent(in), optional:: dev_out !in: default output device
!------------------------------------------------------
integer(INTD), parameter:: MAX_ACTIONS=1000000
!------------------------------------------------------
integer(INTD):: jo,i,j,nadd,ndel,nidl
type(key_t):: key
type(val_t):: val
type(dictionary_t), target:: some_dict
type(dictionary_iter_t):: dict_it
type(list_bi_t):: list_refs
type(list_iter_t):: list_it
class(gfc_cont_elem_t), pointer:: pntee
class(*), pointer:: uptr
real(8):: tms,tm
logical:: del
ierr=GFC_SUCCESS; perf=0d0; uptr=>NULL()
if(present(dev_out)) then; jo=dev_out; else; jo=6; endif
!Lookups/insertions:
tms=thread_wtime()
nadd=0; ndel=0; nidl=0
j=dict_it%init(some_dict); if(j.ne.GFC_SUCCESS) then; call test_quit(1); return; endif
do i=1,MAX_ACTIONS
del=(mod(i,4).eq.3) !every fourth action will be a deletion
key%rank=KEY_LEN; call get_rnd_key(key) !random key
if(del) then !deletion (if found)
j=dict_it%search(GFC_DICT_DELETE_IF_FOUND,cmp_key_test,key)
else !insertion (if not found)
val%my_array(1:KEY_LEN)=13.777d0; val%key_stored=key !value
j=dict_it%search(GFC_DICT_ADD_IF_NOT_FOUND,cmp_key_test,key,val,GFC_BY_VAL,uptr)
endif
if(j.eq.GFC_FOUND) then
if(del) then
ndel=ndel+1
else
nidl=nidl+1
if(.not.(associated(uptr))) then; call test_quit(2); return; endif
endif
elseif(j.eq.GFC_NOT_FOUND) then
if(del) then
nidl=nidl+1
else
nadd=nadd+1
if(.not.(associated(uptr))) then; call test_quit(3); return; endif
endif
else
write(jo,'("#DEBUG(gfc::dictionary:test): Dictionary search failed with error ",i11)') j !debug
call test_quit(4); return
endif
enddo
tm=thread_wtime(tms)
perf=dble(MAX_ACTIONS)/tm
!write(jo,'("Added ",i11,"; Deleted ",i11,"; Idle ",i11)') nadd,ndel,nidl !debug
!Traversing the final dictionary as a sorted list:
tms=thread_wtime()
call dict_it%sort_to_list(list_refs,j); if(j.ne.GFC_SUCCESS) then; call test_quit(5); return; endif
j=list_it%init(list_refs); pntee=>NULL(); uptr=>NULL(); i=0
do while(j.eq.GFC_SUCCESS)
pntee=>list_it%pointee(); uptr=>pntee%get_value()
select type(uptr)
class is(dict_elem_t)
i=i+1
!call uptr%print_key(print_key,j,jo); if(j.ne.0) then; call test_quit(6); return; endif
class default
call test_quit(7); return
end select
j=list_it%next()
enddo
if(j.ne.GFC_NO_MOVE) then; call test_quit(8); return; endif
j=list_it%reset(); if(j.ne.GFC_SUCCESS) then; call test_quit(9); return; endif
j=list_it%delete_all(); if(j.ne.GFC_SUCCESS) then; call test_quit(10); return; endif
j=list_it%release(); if(j.ne.GFC_SUCCESS) then; call test_quit(11); return; endif
tm=thread_wtime(tms)
!write(jo,'("Traversing time for ",i11," elements is ",F10.4," sec")') i,tm !debug
!Success:
call test_quit(0)
return
contains
subroutine get_rnd_key(akey)
type(key_t), intent(inout):: akey
integer(INTD):: jj
real(8):: jv(1:KEY_LEN)
call random_number(jv(1:KEY_LEN))
do jj=1,akey%rank
akey%dims(jj)=nint(jv(jj)*dble(MAX_IND_VAL))
enddo
return
end subroutine get_rnd_key
subroutine test_quit(jerr)
integer(INTD), intent(in):: jerr
integer(INTD):: jj
ierr=jerr
if(ierr.ne.GFC_SUCCESS) then
write(jo,'("#ERROR(gfc::dictionary::test): Test failed: Error code ",i13)') ierr
write(jo,'("Please contact the developer at QUANT4ME@GMAIL.COM")')
endif
jj=dict_it%delete_all(); if(ierr.eq.GFC_SUCCESS.and.jj.ne.GFC_SUCCESS) ierr=10
if(jj.ne.GFC_SUCCESS) write(jo,'("#ERROR(gfc::dictionary::test): Dictionary destruction failed: Error code ",i13)') jj
jj=dict_it%release(); if(ierr.eq.GFC_SUCCESS.and.jj.ne.GFC_SUCCESS) ierr=11
if(jj.ne.GFC_SUCCESS) write(jo,'("#ERROR(gfc::dictionary::test): Dictionary iterator release failed: Error code ",i13)')&
&jj
return
end subroutine test_quit
end function test_gfc_dictionary
end module gfc_dictionary_test
| lgpl-3.0 |
likev/ncl | ncl_ncarg_src/external/blas/zher2k.f | 24 | 13292 | SUBROUTINE ZHER2K( UPLO, TRANS, N, K, ALPHA, A, LDA, B, LDB, BETA,
$ C, LDC )
* .. Scalar Arguments ..
CHARACTER TRANS, UPLO
INTEGER K, LDA, LDB, LDC, N
DOUBLE PRECISION BETA
COMPLEX*16 ALPHA
* ..
* .. Array Arguments ..
COMPLEX*16 A( LDA, * ), B( LDB, * ), C( LDC, * )
* ..
*
* Purpose
* =======
*
* ZHER2K performs one of the hermitian rank 2k operations
*
* C := alpha*A*conjg( B' ) + conjg( alpha )*B*conjg( A' ) + beta*C,
*
* or
*
* C := alpha*conjg( A' )*B + conjg( alpha )*conjg( B' )*A + beta*C,
*
* where alpha and beta are scalars with beta real, C is an n by n
* hermitian matrix and A and B are n by k matrices in the first case
* and k by n matrices in the second case.
*
* Parameters
* ==========
*
* UPLO - CHARACTER*1.
* On entry, UPLO specifies whether the upper or lower
* triangular part of the array C is to be referenced as
* follows:
*
* UPLO = 'U' or 'u' Only the upper triangular part of C
* is to be referenced.
*
* UPLO = 'L' or 'l' Only the lower triangular part of C
* is to be referenced.
*
* Unchanged on exit.
*
* TRANS - CHARACTER*1.
* On entry, TRANS specifies the operation to be performed as
* follows:
*
* TRANS = 'N' or 'n' C := alpha*A*conjg( B' ) +
* conjg( alpha )*B*conjg( A' ) +
* beta*C.
*
* TRANS = 'C' or 'c' C := alpha*conjg( A' )*B +
* conjg( alpha )*conjg( B' )*A +
* beta*C.
*
* Unchanged on exit.
*
* N - INTEGER.
* On entry, N specifies the order of the matrix C. N must be
* at least zero.
* Unchanged on exit.
*
* K - INTEGER.
* On entry with TRANS = 'N' or 'n', K specifies the number
* of columns of the matrices A and B, and on entry with
* TRANS = 'C' or 'c', K specifies the number of rows of the
* matrices A and B. K must be at least zero.
* Unchanged on exit.
*
* ALPHA - COMPLEX*16 .
* On entry, ALPHA specifies the scalar alpha.
* Unchanged on exit.
*
* A - COMPLEX*16 array of DIMENSION ( LDA, ka ), where ka is
* k when TRANS = 'N' or 'n', and is n otherwise.
* Before entry with TRANS = 'N' or 'n', the leading n by k
* part of the array A must contain the matrix A, otherwise
* the leading k by n part of the array A must contain the
* matrix A.
* Unchanged on exit.
*
* LDA - INTEGER.
* On entry, LDA specifies the first dimension of A as declared
* in the calling (sub) program. When TRANS = 'N' or 'n'
* then LDA must be at least max( 1, n ), otherwise LDA must
* be at least max( 1, k ).
* Unchanged on exit.
*
* B - COMPLEX*16 array of DIMENSION ( LDB, kb ), where kb is
* k when TRANS = 'N' or 'n', and is n otherwise.
* Before entry with TRANS = 'N' or 'n', the leading n by k
* part of the array B must contain the matrix B, otherwise
* the leading k by n part of the array B must contain the
* matrix B.
* Unchanged on exit.
*
* LDB - INTEGER.
* On entry, LDB specifies the first dimension of B as declared
* in the calling (sub) program. When TRANS = 'N' or 'n'
* then LDB must be at least max( 1, n ), otherwise LDB must
* be at least max( 1, k ).
* Unchanged on exit.
*
* BETA - DOUBLE PRECISION .
* On entry, BETA specifies the scalar beta.
* Unchanged on exit.
*
* C - COMPLEX*16 array of DIMENSION ( LDC, n ).
* Before entry with UPLO = 'U' or 'u', the leading n by n
* upper triangular part of the array C must contain the upper
* triangular part of the hermitian matrix and the strictly
* lower triangular part of C is not referenced. On exit, the
* upper triangular part of the array C is overwritten by the
* upper triangular part of the updated matrix.
* Before entry with UPLO = 'L' or 'l', the leading n by n
* lower triangular part of the array C must contain the lower
* triangular part of the hermitian matrix and the strictly
* upper triangular part of C is not referenced. On exit, the
* lower triangular part of the array C is overwritten by the
* lower triangular part of the updated matrix.
* Note that the imaginary parts of the diagonal elements need
* not be set, they are assumed to be zero, and on exit they
* are set to zero.
*
* LDC - INTEGER.
* On entry, LDC specifies the first dimension of C as declared
* in the calling (sub) program. LDC must be at least
* max( 1, n ).
* Unchanged on exit.
*
*
* Level 3 Blas routine.
*
* -- Written on 8-February-1989.
* Jack Dongarra, Argonne National Laboratory.
* Iain Duff, AERE Harwell.
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
* Sven Hammarling, Numerical Algorithms Group Ltd.
*
* -- Modified 8-Nov-93 to set C(J,J) to DBLE( C(J,J) ) when BETA = 1.
* Ed Anderson, Cray Research Inc.
*
*
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC DBLE, DCONJG, MAX
* ..
* .. Local Scalars ..
LOGICAL UPPER
INTEGER I, INFO, J, L, NROWA
COMPLEX*16 TEMP1, TEMP2
* ..
* .. Parameters ..
DOUBLE PRECISION ONE
PARAMETER ( ONE = 1.0D+0 )
COMPLEX*16 ZERO
PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
IF( LSAME( TRANS, 'N' ) ) THEN
NROWA = N
ELSE
NROWA = K
END IF
UPPER = LSAME( UPLO, 'U' )
*
INFO = 0
IF( ( .NOT.UPPER ) .AND. ( .NOT.LSAME( UPLO, 'L' ) ) ) THEN
INFO = 1
ELSE IF( ( .NOT.LSAME( TRANS, 'N' ) ) .AND.
$ ( .NOT.LSAME( TRANS, 'C' ) ) ) THEN
INFO = 2
ELSE IF( N.LT.0 ) THEN
INFO = 3
ELSE IF( K.LT.0 ) THEN
INFO = 4
ELSE IF( LDA.LT.MAX( 1, NROWA ) ) THEN
INFO = 7
ELSE IF( LDB.LT.MAX( 1, NROWA ) ) THEN
INFO = 9
ELSE IF( LDC.LT.MAX( 1, N ) ) THEN
INFO = 12
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZHER2K', INFO )
RETURN
END IF
*
* Quick return if possible.
*
IF( ( N.EQ.0 ) .OR. ( ( ( ALPHA.EQ.ZERO ) .OR. ( K.EQ.0 ) ) .AND.
$ ( BETA.EQ.ONE ) ) )RETURN
*
* And when alpha.eq.zero.
*
IF( ALPHA.EQ.ZERO ) THEN
IF( UPPER ) THEN
IF( BETA.EQ.DBLE( ZERO ) ) THEN
DO 20 J = 1, N
DO 10 I = 1, J
C( I, J ) = ZERO
10 CONTINUE
20 CONTINUE
ELSE
DO 40 J = 1, N
DO 30 I = 1, J - 1
C( I, J ) = BETA*C( I, J )
30 CONTINUE
C( J, J ) = BETA*DBLE( C( J, J ) )
40 CONTINUE
END IF
ELSE
IF( BETA.EQ.DBLE( ZERO ) ) THEN
DO 60 J = 1, N
DO 50 I = J, N
C( I, J ) = ZERO
50 CONTINUE
60 CONTINUE
ELSE
DO 80 J = 1, N
C( J, J ) = BETA*DBLE( C( J, J ) )
DO 70 I = J + 1, N
C( I, J ) = BETA*C( I, J )
70 CONTINUE
80 CONTINUE
END IF
END IF
RETURN
END IF
*
* Start the operations.
*
IF( LSAME( TRANS, 'N' ) ) THEN
*
* Form C := alpha*A*conjg( B' ) + conjg( alpha )*B*conjg( A' ) +
* C.
*
IF( UPPER ) THEN
DO 130 J = 1, N
IF( BETA.EQ.DBLE( ZERO ) ) THEN
DO 90 I = 1, J
C( I, J ) = ZERO
90 CONTINUE
ELSE IF( BETA.NE.ONE ) THEN
DO 100 I = 1, J - 1
C( I, J ) = BETA*C( I, J )
100 CONTINUE
C( J, J ) = BETA*DBLE( C( J, J ) )
ELSE
C( J, J ) = DBLE( C( J, J ) )
END IF
DO 120 L = 1, K
IF( ( A( J, L ).NE.ZERO ) .OR. ( B( J, L ).NE.ZERO ) )
$ THEN
TEMP1 = ALPHA*DCONJG( B( J, L ) )
TEMP2 = DCONJG( ALPHA*A( J, L ) )
DO 110 I = 1, J - 1
C( I, J ) = C( I, J ) + A( I, L )*TEMP1 +
$ B( I, L )*TEMP2
110 CONTINUE
C( J, J ) = DBLE( C( J, J ) ) +
$ DBLE( A( J, L )*TEMP1+B( J, L )*TEMP2 )
END IF
120 CONTINUE
130 CONTINUE
ELSE
DO 180 J = 1, N
IF( BETA.EQ.DBLE( ZERO ) ) THEN
DO 140 I = J, N
C( I, J ) = ZERO
140 CONTINUE
ELSE IF( BETA.NE.ONE ) THEN
DO 150 I = J + 1, N
C( I, J ) = BETA*C( I, J )
150 CONTINUE
C( J, J ) = BETA*DBLE( C( J, J ) )
ELSE
C( J, J ) = DBLE( C( J, J ) )
END IF
DO 170 L = 1, K
IF( ( A( J, L ).NE.ZERO ) .OR. ( B( J, L ).NE.ZERO ) )
$ THEN
TEMP1 = ALPHA*DCONJG( B( J, L ) )
TEMP2 = DCONJG( ALPHA*A( J, L ) )
DO 160 I = J + 1, N
C( I, J ) = C( I, J ) + A( I, L )*TEMP1 +
$ B( I, L )*TEMP2
160 CONTINUE
C( J, J ) = DBLE( C( J, J ) ) +
$ DBLE( A( J, L )*TEMP1+B( J, L )*TEMP2 )
END IF
170 CONTINUE
180 CONTINUE
END IF
ELSE
*
* Form C := alpha*conjg( A' )*B + conjg( alpha )*conjg( B' )*A +
* C.
*
IF( UPPER ) THEN
DO 210 J = 1, N
DO 200 I = 1, J
TEMP1 = ZERO
TEMP2 = ZERO
DO 190 L = 1, K
TEMP1 = TEMP1 + DCONJG( A( L, I ) )*B( L, J )
TEMP2 = TEMP2 + DCONJG( B( L, I ) )*A( L, J )
190 CONTINUE
IF( I.EQ.J ) THEN
IF( BETA.EQ.DBLE( ZERO ) ) THEN
C( J, J ) = DBLE( ALPHA*TEMP1+DCONJG( ALPHA )*
$ TEMP2 )
ELSE
C( J, J ) = BETA*DBLE( C( J, J ) ) +
$ DBLE( ALPHA*TEMP1+DCONJG( ALPHA )*
$ TEMP2 )
END IF
ELSE
IF( BETA.EQ.DBLE( ZERO ) ) THEN
C( I, J ) = ALPHA*TEMP1 + DCONJG( ALPHA )*TEMP2
ELSE
C( I, J ) = BETA*C( I, J ) + ALPHA*TEMP1 +
$ DCONJG( ALPHA )*TEMP2
END IF
END IF
200 CONTINUE
210 CONTINUE
ELSE
DO 240 J = 1, N
DO 230 I = J, N
TEMP1 = ZERO
TEMP2 = ZERO
DO 220 L = 1, K
TEMP1 = TEMP1 + DCONJG( A( L, I ) )*B( L, J )
TEMP2 = TEMP2 + DCONJG( B( L, I ) )*A( L, J )
220 CONTINUE
IF( I.EQ.J ) THEN
IF( BETA.EQ.DBLE( ZERO ) ) THEN
C( J, J ) = DBLE( ALPHA*TEMP1+DCONJG( ALPHA )*
$ TEMP2 )
ELSE
C( J, J ) = BETA*DBLE( C( J, J ) ) +
$ DBLE( ALPHA*TEMP1+DCONJG( ALPHA )*
$ TEMP2 )
END IF
ELSE
IF( BETA.EQ.DBLE( ZERO ) ) THEN
C( I, J ) = ALPHA*TEMP1 + DCONJG( ALPHA )*TEMP2
ELSE
C( I, J ) = BETA*C( I, J ) + ALPHA*TEMP1 +
$ DCONJG( ALPHA )*TEMP2
END IF
END IF
230 CONTINUE
240 CONTINUE
END IF
END IF
*
RETURN
*
* End of ZHER2K.
*
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/external/lapack/dsytrs.f | 3 | 10617 | SUBROUTINE DSYTRS( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
*
* -- LAPACK routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* March 31, 1993
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, LDA, LDB, N, NRHS
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
DOUBLE PRECISION A( LDA, * ), B( LDB, * )
* ..
*
* Purpose
* =======
*
* DSYTRS solves a system of linear equations A*X = B with a real
* symmetric matrix A using the factorization A = U*D*U**T or
* A = L*D*L**T computed by DSYTRF.
*
* Arguments
* =========
*
* UPLO (input) CHARACTER*1
* Specifies whether the details of the factorization are stored
* as an upper or lower triangular matrix.
* = 'U': Upper triangular, form is A = U*D*U**T;
* = 'L': Lower triangular, form is A = L*D*L**T.
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* NRHS (input) INTEGER
* The number of right hand sides, i.e., the number of columns
* of the matrix B. NRHS >= 0.
*
* A (input) DOUBLE PRECISION array, dimension (LDA,N)
* The block diagonal matrix D and the multipliers used to
* obtain the factor U or L as computed by DSYTRF.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,N).
*
* IPIV (input) INTEGER array, dimension (N)
* Details of the interchanges and the block structure of D
* as determined by DSYTRF.
*
* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
* On entry, the right hand side matrix B.
* On exit, the solution matrix X.
*
* LDB (input) INTEGER
* The leading dimension of the array B. LDB >= max(1,N).
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE
PARAMETER ( ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL UPPER
INTEGER J, K, KP
DOUBLE PRECISION AK, AKM1, AKM1K, BK, BKM1, DENOM
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL DGEMV, DGER, DSCAL, DSWAP, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
INFO = 0
UPPER = LSAME( UPLO, 'U' )
IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( NRHS.LT.0 ) THEN
INFO = -3
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -5
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -8
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DSYTRS', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 .OR. NRHS.EQ.0 )
$ RETURN
*
IF( UPPER ) THEN
*
* Solve A*X = B, where A = U*D*U'.
*
* First solve U*D*X = B, overwriting B with X.
*
* K is the main loop index, decreasing from N to 1 in steps of
* 1 or 2, depending on the size of the diagonal blocks.
*
K = N
10 CONTINUE
*
* If K < 1, exit from loop.
*
IF( K.LT.1 )
$ GO TO 30
*
IF( IPIV( K ).GT.0 ) THEN
*
* 1 x 1 diagonal block
*
* Interchange rows K and IPIV(K).
*
KP = IPIV( K )
IF( KP.NE.K )
$ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
*
* Multiply by inv(U(K)), where U(K) is the transformation
* stored in column K of A.
*
CALL DGER( K-1, NRHS, -ONE, A( 1, K ), 1, B( K, 1 ), LDB,
$ B( 1, 1 ), LDB )
*
* Multiply by the inverse of the diagonal block.
*
CALL DSCAL( NRHS, ONE / A( K, K ), B( K, 1 ), LDB )
K = K - 1
ELSE
*
* 2 x 2 diagonal block
*
* Interchange rows K-1 and -IPIV(K).
*
KP = -IPIV( K )
IF( KP.NE.K-1 )
$ CALL DSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ), LDB )
*
* Multiply by inv(U(K)), where U(K) is the transformation
* stored in columns K-1 and K of A.
*
CALL DGER( K-2, NRHS, -ONE, A( 1, K ), 1, B( K, 1 ), LDB,
$ B( 1, 1 ), LDB )
CALL DGER( K-2, NRHS, -ONE, A( 1, K-1 ), 1, B( K-1, 1 ),
$ LDB, B( 1, 1 ), LDB )
*
* Multiply by the inverse of the diagonal block.
*
AKM1K = A( K-1, K )
AKM1 = A( K-1, K-1 ) / AKM1K
AK = A( K, K ) / AKM1K
DENOM = AKM1*AK - ONE
DO 20 J = 1, NRHS
BKM1 = B( K-1, J ) / AKM1K
BK = B( K, J ) / AKM1K
B( K-1, J ) = ( AK*BKM1-BK ) / DENOM
B( K, J ) = ( AKM1*BK-BKM1 ) / DENOM
20 CONTINUE
K = K - 2
END IF
*
GO TO 10
30 CONTINUE
*
* Next solve U'*X = B, overwriting B with X.
*
* K is the main loop index, increasing from 1 to N in steps of
* 1 or 2, depending on the size of the diagonal blocks.
*
K = 1
40 CONTINUE
*
* If K > N, exit from loop.
*
IF( K.GT.N )
$ GO TO 50
*
IF( IPIV( K ).GT.0 ) THEN
*
* 1 x 1 diagonal block
*
* Multiply by inv(U'(K)), where U(K) is the transformation
* stored in column K of A.
*
CALL DGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB, A( 1, K ),
$ 1, ONE, B( K, 1 ), LDB )
*
* Interchange rows K and IPIV(K).
*
KP = IPIV( K )
IF( KP.NE.K )
$ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
K = K + 1
ELSE
*
* 2 x 2 diagonal block
*
* Multiply by inv(U'(K+1)), where U(K+1) is the transformation
* stored in columns K and K+1 of A.
*
CALL DGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB, A( 1, K ),
$ 1, ONE, B( K, 1 ), LDB )
CALL DGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB,
$ A( 1, K+1 ), 1, ONE, B( K+1, 1 ), LDB )
*
* Interchange rows K and -IPIV(K).
*
KP = -IPIV( K )
IF( KP.NE.K )
$ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
K = K + 2
END IF
*
GO TO 40
50 CONTINUE
*
ELSE
*
* Solve A*X = B, where A = L*D*L'.
*
* First solve L*D*X = B, overwriting B with X.
*
* K is the main loop index, increasing from 1 to N in steps of
* 1 or 2, depending on the size of the diagonal blocks.
*
K = 1
60 CONTINUE
*
* If K > N, exit from loop.
*
IF( K.GT.N )
$ GO TO 80
*
IF( IPIV( K ).GT.0 ) THEN
*
* 1 x 1 diagonal block
*
* Interchange rows K and IPIV(K).
*
KP = IPIV( K )
IF( KP.NE.K )
$ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
*
* Multiply by inv(L(K)), where L(K) is the transformation
* stored in column K of A.
*
IF( K.LT.N )
$ CALL DGER( N-K, NRHS, -ONE, A( K+1, K ), 1, B( K, 1 ),
$ LDB, B( K+1, 1 ), LDB )
*
* Multiply by the inverse of the diagonal block.
*
CALL DSCAL( NRHS, ONE / A( K, K ), B( K, 1 ), LDB )
K = K + 1
ELSE
*
* 2 x 2 diagonal block
*
* Interchange rows K+1 and -IPIV(K).
*
KP = -IPIV( K )
IF( KP.NE.K+1 )
$ CALL DSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ), LDB )
*
* Multiply by inv(L(K)), where L(K) is the transformation
* stored in columns K and K+1 of A.
*
IF( K.LT.N-1 ) THEN
CALL DGER( N-K-1, NRHS, -ONE, A( K+2, K ), 1, B( K, 1 ),
$ LDB, B( K+2, 1 ), LDB )
CALL DGER( N-K-1, NRHS, -ONE, A( K+2, K+1 ), 1,
$ B( K+1, 1 ), LDB, B( K+2, 1 ), LDB )
END IF
*
* Multiply by the inverse of the diagonal block.
*
AKM1K = A( K+1, K )
AKM1 = A( K, K ) / AKM1K
AK = A( K+1, K+1 ) / AKM1K
DENOM = AKM1*AK - ONE
DO 70 J = 1, NRHS
BKM1 = B( K, J ) / AKM1K
BK = B( K+1, J ) / AKM1K
B( K, J ) = ( AK*BKM1-BK ) / DENOM
B( K+1, J ) = ( AKM1*BK-BKM1 ) / DENOM
70 CONTINUE
K = K + 2
END IF
*
GO TO 60
80 CONTINUE
*
* Next solve L'*X = B, overwriting B with X.
*
* K is the main loop index, decreasing from N to 1 in steps of
* 1 or 2, depending on the size of the diagonal blocks.
*
K = N
90 CONTINUE
*
* If K < 1, exit from loop.
*
IF( K.LT.1 )
$ GO TO 100
*
IF( IPIV( K ).GT.0 ) THEN
*
* 1 x 1 diagonal block
*
* Multiply by inv(L'(K)), where L(K) is the transformation
* stored in column K of A.
*
IF( K.LT.N )
$ CALL DGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
$ LDB, A( K+1, K ), 1, ONE, B( K, 1 ), LDB )
*
* Interchange rows K and IPIV(K).
*
KP = IPIV( K )
IF( KP.NE.K )
$ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
K = K - 1
ELSE
*
* 2 x 2 diagonal block
*
* Multiply by inv(L'(K-1)), where L(K-1) is the transformation
* stored in columns K-1 and K of A.
*
IF( K.LT.N ) THEN
CALL DGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
$ LDB, A( K+1, K ), 1, ONE, B( K, 1 ), LDB )
CALL DGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
$ LDB, A( K+1, K-1 ), 1, ONE, B( K-1, 1 ),
$ LDB )
END IF
*
* Interchange rows K and -IPIV(K).
*
KP = -IPIV( K )
IF( KP.NE.K )
$ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
K = K - 2
END IF
*
GO TO 90
100 CONTINUE
END IF
*
RETURN
*
* End of DSYTRS
*
END
| gpl-2.0 |
likev/ncl | ncl_ncarg_src/ni/src/lib/nfpfort/KolmSmir2.f | 1 | 5731 |
C ....................SSP...........................................
C
C SUBROUTINE KOLM2
C
C PURPOSE
C
C TESTS THE DIFFERENCE BETWEEN TWO SAMPLE DISTRIBUTION
C FUNCTIONS USING THE KOLMOGOROV-SMIRNOV TEST
C
C USAGE
C CALL KOLM2(X,Y,N,M,Z,PROB)
C CALL KOLM2(X,Y,N,M,Z,PROB,D) <== NCL
C
C DESCRIPTION OF PARAMETERS
C X - INPUT VECTOR OF N INDEPENDENT OBSERVATIONS. ON
C RETURN FROM KOLM2, X HAS BEEN SORTED INTO A
C MONOTONIC NON-DECREASING SEQUENCE.
C Y - INPUT VECTOR OF M INDEPENDENT OBSERVATIONS. ON
C RETURN FROM KOLM2, Y HAS BEEN SORTED INTO A
C MONOTONIC NON-DECREASING SEQUENCE.
C N - NUMBER OF OBSERVATIONS IN X
C M - NUMBER OF OBSERVATIONS IN Y
C Z - OUTPUT VARIABLE CONTAINING THE GREATEST VALUE WITH
C RESPECT TO THE SPECTRUM OF X AND Y OF
C SQRT((M*N)/(M+N))*ABS(FN(X)-GM(Y)) WHERE
C FN(X) IS THE EMPIRICAL DISTRIBUTION FUNCTION OF THE
C SET (X) AND GM(Y) IS THE EMPIRICAL DISTRIBUTION
C FUNCTION OF THE SET (Y).
C PROB - OUTPUT VARIABLE CONTAINING THE PROBABILITY OF
C THE STATISTIC BEING GREATER THAN OR EQUAL TO Z IF
C THE HYPOTHESIS THAT X AND Y ARE FROM THE SAME PDF IS
C TRUE. E.G., PROB= 0.05 IMPLIES THAT ONE CAN REJECT
C THE NULL HYPOTHESIS THAT THE SETS X AND Y ARE FROM
C THE SAME DENSITY WITH 5 PER CENT PROBABILITY OF BEING
C INCORRECT. PROB = 1. - SMIRN(Z).
C
C REMARKS
C N AND M SHOULD BE GREATER THAN OR EQUAL TO 100. (SEE THE
C MATHEMATICAL DESCRIPTION FOR THIS SUBROUTINE AND FOR THE
C SUBROUTINE SMIRN, CONCERNING ASYMPTOTIC FORMULAE).
C
C DOUBLE PRECISION USAGE---IT IS DOUBTFUL THAT THE USER WILL
C WISH TO PERFORM THIS TEST USING DOUBLE PRECISION ACCURACY.
C IF ONE WISHES TO COMMUNICATE WITH KOLM2 IN A DOUBLE
C PRECISION PROGRAM, HE SHOULD CALL THE FORTRAN SUPPLIED
C PROGRAM SNGL(X) PRIOR TO CALLING KOLM2, AND CALL THE
C FORTRAN SUPPLIED PROGRAM DBLE(X) AFTER EXITING FROM KOLM2.
C (NOTE THAT SUBROUTINE SMIRN DOES HAVE DOUBLE PRECISION
C CAPABILITY AS SUPPLIED BY THIS PACKAGE.)
C
C
C SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C SMIRN
C
C METHOD
C FOR REFERENCE, SEE (1) W. FELLER--ON THE KOLMOGOROV-SMIRNOV
C LIMIT THEOREMS FOR EMPIRICAL DISTRIBUTIONS--
C ANNALS OF MATH. STAT., 19, 1948. 177-189,
C (2) N. SMIRNOV--TABLE FOR ESTIMATING THE GOODNESS OF FIT
C OF EMPIRICAL DISTRIBUTIONS--ANNALS OF MATH. STAT., 19,
C 1948. 279-281.
C (3) R. VON MISES--MATHEMATICAL THEORY OF PROBABILITY AND
C STATISTICS--ACADEMIC PRESS, NEW YORK, 1964. 490-493,
C (4) B.V. GNEDENKO--THE THEORY OF PROBABILITY--CHELSEA
C PUBLISHING COMPANY, NEW YORK, 1962. 384-401.
C
C ..................................................................
C
C C C SUBOUTINE KOLM2(X,Y,N,M,Z,PROB,D)
C NCLFORTSTART
SUBROUTINE KOLM2(X,Y,N,M,IFLAG,Z,PROB,D)
C INPUT
INTEGER N,M, IFLAG
DOUBLE PRECISION X(N),Y(M)
C OUTPUT
DOUBLE PRECISION Z, PROB, D
C NCLEND
DOUBLE PRECISION TEMP, XN, XN1, XM, XM1
IF (IFLAG.EQ.0) THEN
C
C SORT X INTO ASCENDING SEQUENCE
C
DO 5 I=2,N
IF(X(I)-X(I-1))1,5,5
1 TEMP=X(I)
IM=I-1
DO 3 J=1,IM
L=I-J
IF(TEMP-X(L))2,4,4
2 X(L+1)=X(L)
3 CONTINUE
X(1)=TEMP
GO TO 5
4 X(L+1)=TEMP
5 CONTINUE
C
C SORT Y INTO ASCENDING SEQUENCE
C
DO 10 I=2,M
IF(Y(I)-Y(I-1))6,10,10
6 TEMP=Y(I)
IM=I-1
DO 8 J=1,IM
L=I-J
IF(TEMP-Y(L))7,9,9
7 Y(L+1)=Y(L)
8 CONTINUE
Y(1)=TEMP
GO TO 10
9 Y(L+1)=TEMP
10 CONTINUE
END IF
C
C CALCULATE D = ABS(FN-GM) OVER THE SPECTRUM OF X AND Y
C
XN =DBLE(N)
XN1=1.0D0/XN
XM =DBLE(M)
XM1=1.0D0/XM
D=0.0D0
I=0
J=0
K=0
L=0
11 IF(X(I+1)-Y(J+1))12,13,18
12 K=1
GO TO 14
13 K=0
14 I=I+1
IF(I-N)15,21,21
15 IF(X(I+1)-X(I))14,14,16
16 IF(K)17,18,17
C
C CHOOSE THE MAXIMUM DIFFERENCE, D
C
17 D=AMAX1(D,ABS(DBLE(I)*XN1-DBLE(J)*XM1))
IF(L)22,11,22
18 J=J+1
IF(J-M)19,20,20
19 IF(Y(J+1)-Y(J))18,18,17
20 L=1
GO TO 17
21 L=1
GO TO 16
C
C CALCULATE THE STATISTIC Z
C
22 Z=D*SQRT((XN*XM)/(XN+XM))
C
C CALCULATE THE PROBABILITY ASSOCIATED WITH Z
C
CALL SMIRN(Z,PROB)
PROB = 1.0D0-PROB
RETURN
END
C---
SUBROUTINE SMIRN(X,Y)
DOUBLE PRECISION X, Y
DOUBLE PRECISION Q1, Q2, Q4, Q8
IF(X-0.27D0)1,1,2
1 Y=0.0D0
GO TO 9
2 IF(X-1.0D0)3,6,6
3 Q1=EXP(-1.233701D0/X**2)
Q2=Q1*Q1
Q4=Q2*Q2
Q8=Q4*Q4
IF(Q8-1D-25)4,5,5
4 Q8=0.0D0
5 Y=(2.506628D0/X)*Q1*(1.0D0+Q8*(1.0D0+Q8*Q8))
GO TO 9
6 IF(X-3.1D0)8,7,7
7 Y=1.0D0
GO TO 9
8 Q1=EXP(-2.0D0*X*X)
Q2=Q1*Q1
Q4=Q2*Q2
Q8=Q4*Q4
Y=1.0D0-2.0D0*(Q1-Q4+Q8*(Q1-Q8))
9 RETURN
END
| gpl-2.0 |
LeChuck42/or1k-gcc | gcc/testsuite/gfortran.dg/coarray/this_image_1.f90 | 147 | 5796 | ! { dg-do run }
!
! PR fortran/18918
!
! this_image(coarray) run test,
! expecially for num_images > 1
!
! Tested are values up to num_images == 8,
! higher values are OK, but not tested for
!
implicit none
integer :: a(1)[2:2, 3:4, 7:*]
integer :: b(:)[:, :,:]
allocatable :: b
integer :: i
if (this_image(A, dim=1) /= 2) call abort()
i = 1
if (this_image(A, dim=i) /= 2) call abort()
select case (this_image())
case (1)
if (this_image(A, dim=2) /= 3) call abort()
if (this_image(A, dim=3) /= 7) call abort()
i = 2
if (this_image(A, dim=i) /= 3) call abort()
i = 3
if (this_image(A, dim=i) /= 7) call abort()
if (any (this_image(A) /= [2,3,7])) call abort()
case (2)
if (this_image(A, dim=2) /= 4) call abort()
if (this_image(A, dim=3) /= 7) call abort()
i = 2
if (this_image(A, dim=i) /= 4) call abort()
i = 3
if (this_image(A, dim=i) /= 7) call abort()
if (any (this_image(A) /= [2,4,7])) call abort()
case (3)
if (this_image(A, dim=2) /= 3) call abort()
if (this_image(A, dim=3) /= 8) call abort()
i = 2
if (this_image(A, dim=i) /= 3) call abort()
i = 3
if (this_image(A, dim=i) /= 8) call abort()
if (any (this_image(A) /= [2,3,8])) call abort()
case (4)
if (this_image(A, dim=2) /= 4) call abort()
if (this_image(A, dim=3) /= 8) call abort()
i = 2
if (this_image(A, dim=i) /= 4) call abort()
i = 3
if (this_image(A, dim=i) /= 8) call abort()
if (any (this_image(A) /= [2,4,8])) call abort()
case (5)
if (this_image(A, dim=2) /= 3) call abort()
if (this_image(A, dim=3) /= 9) call abort()
i = 2
if (this_image(A, dim=i) /= 3) call abort()
i = 3
if (this_image(A, dim=i) /= 9) call abort()
if (any (this_image(A) /= [2,3,9])) call abort()
case (6)
if (this_image(A, dim=2) /= 4) call abort()
if (this_image(A, dim=3) /= 9) call abort()
i = 2
if (this_image(A, dim=i) /= 4) call abort()
i = 3
if (this_image(A, dim=i) /= 9) call abort()
if (any (this_image(A) /= [2,4,9])) call abort()
case (7)
if (this_image(A, dim=2) /= 3) call abort()
if (this_image(A, dim=3) /= 10) call abort()
i = 2
if (this_image(A, dim=i) /= 3) call abort()
i = 3
if (this_image(A, dim=i) /= 10) call abort()
if (any (this_image(A) /= [2,3,10])) call abort()
case (8)
if (this_image(A, dim=2) /= 4) call abort()
if (this_image(A, dim=3) /= 10) call abort()
i = 2
if (this_image(A, dim=i) /= 4) call abort()
i = 3
if (this_image(A, dim=i) /= 10) call abort()
if (any (this_image(A) /= [2,4,10])) call abort()
end select
allocate (b(3)[-1:0,2:4,*])
select case (this_image())
case (1)
if (this_image(B, dim=1) /= -1) call abort()
if (this_image(B, dim=2) /= 2) call abort()
if (this_image(B, dim=3) /= 1) call abort()
i = 1
if (this_image(B, dim=i) /= -1) call abort()
i = 2
if (this_image(B, dim=i) /= 2) call abort()
i = 3
if (this_image(B, dim=i) /= 1) call abort()
if (any (this_image(B) /= [-1,2,1])) call abort()
case (2)
if (this_image(B, dim=1) /= 0) call abort()
if (this_image(B, dim=2) /= 2) call abort()
if (this_image(B, dim=3) /= 1) call abort()
i = 1
if (this_image(B, dim=i) /= 0) call abort()
i = 2
if (this_image(B, dim=i) /= 2) call abort()
i = 3
if (this_image(B, dim=i) /= 1) call abort()
if (any (this_image(B) /= [0,2,1])) call abort()
case (3)
if (this_image(B, dim=1) /= -1) call abort()
if (this_image(B, dim=2) /= 3) call abort()
if (this_image(B, dim=3) /= 1) call abort()
i = 1
if (this_image(B, dim=i) /= -1) call abort()
i = 2
if (this_image(B, dim=i) /= 3) call abort()
i = 3
if (this_image(B, dim=i) /= 1) call abort()
if (any (this_image(B) /= [-1,3,1])) call abort()
case (4)
if (this_image(B, dim=1) /= 0) call abort()
if (this_image(B, dim=2) /= 3) call abort()
if (this_image(B, dim=3) /= 1) call abort()
i = 1
if (this_image(B, dim=i) /= 0) call abort()
i = 2
if (this_image(B, dim=i) /= 3) call abort()
i = 3
if (this_image(B, dim=i) /= 1) call abort()
if (any (this_image(B) /= [0,3,1])) call abort()
case (5)
if (this_image(B, dim=1) /= -1) call abort()
if (this_image(B, dim=2) /= 4) call abort()
if (this_image(B, dim=3) /= 1) call abort()
i = 1
if (this_image(B, dim=i) /= -1) call abort()
i = 2
if (this_image(B, dim=i) /= 4) call abort()
i = 3
if (this_image(B, dim=i) /= 1) call abort()
if (any (this_image(B) /= [-1,4,1])) call abort()
case (6)
if (this_image(B, dim=1) /= 0) call abort()
if (this_image(B, dim=2) /= 4) call abort()
if (this_image(B, dim=3) /= 1) call abort()
i = 1
if (this_image(B, dim=i) /= 0) call abort()
i = 2
if (this_image(B, dim=i) /= 4) call abort()
i = 3
if (this_image(B, dim=i) /= 1) call abort()
if (any (this_image(B) /= [0,4,1])) call abort()
case (7)
if (this_image(B, dim=1) /= -1) call abort()
if (this_image(B, dim=2) /= 2) call abort()
if (this_image(B, dim=3) /= 2) call abort()
i = 1
if (this_image(B, dim=i) /= -1) call abort()
i = 2
if (this_image(B, dim=i) /= 2) call abort()
i = 3
if (this_image(B, dim=i) /= 2) call abort()
if (any (this_image(B) /= [-1,2,2])) call abort()
case (8)
if (this_image(B, dim=1) /= 0) call abort()
if (this_image(B, dim=2) /= 2) call abort()
if (this_image(B, dim=3) /= 2) call abort()
i = 1
if (this_image(B, dim=i) /= 0) call abort()
i = 2
if (this_image(B, dim=i) /= 2) call abort()
i = 3
if (this_image(B, dim=i) /= 2) call abort()
if (any (this_image(B) /= [0,2,2])) call abort()
end select
end
| gpl-2.0 |
marshallward/mom | src/mom5/ocean_blobs/ocean_blob_dynamic_free.F90 | 8 | 124082 | module ocean_blob_dynamic_free_mod
!
!<CONTACT EMAIL="m.bates@student.unsw.edu.au"> Michael L. Bates
!</CONTACT>
!
!<CONTACT EMAIL="GFDL.Climate.Model.Info@noaa.gov"> Stephen M. Griffies
!</CONTACT>
!
!<OVERVIEW>
! This module runs the dynamic free blob implementation of the embedded
! Lagrangian blob framework. The module forms new dynamic free blobs,
! integrates the properties of existing blobs, and handles the transfer
! of bottom blobs to free blobs.
!</OVERVIEW>
!
!<DESCRIPTION>
! Free blobs are formed using the subroutine blob_dynamic_free_implicit,
! which is called from the blob driver module. Free blobs must be formed
! implicitly in time so that the surface forcing has already been applied.
!
! The properties of free blobs are also integrated in this module, that is,
! position, velocity, mass and tracer content. Position and velocity are
! integrated using an adaptive step Runge-Kutta scheme. There are several
! schemes available of varying order.
!
! The module also receives blobs that are transferring from the bottom
! blob dynamic regime to the free blob regime (i.e. they have separated
! from the bottom boundary).
!</DESCRIPTION>
!
!<INFO>
!
! <REFERENCE>
! Bogacki, P., Shampine, L.F., (1989) A 3(2) pair of Runge-Kutta formulas.
! Applied Mathematical Letters 2(4), 321-325.
! </REFERENCE>
!
! <REFERENCE>
! Cash, J.R., Karp, A.H. (1990) A variable order Runge-Kutta method for
! initial value problems with rapidly varying right-hand sides.
! ACM Transactions on Mathematical Software 16(3), 201-222.
! </REFERENCE>
!
! <REFERENCE>
! Griffies, S.M., Harrison, M.J., Pacanowski, R.C., Rosati, A. (2004)
! A Technical Guide to MOM4. GFDL Ocean Group Technical Report No. 5.
! NOAA/Geophysical Fluid Dynamics Laboratory.
! </REFERENCE>
!
! <REFERENCE>
! Marshall, J., Schott, F. (1999) Open-ocean convection: Observations, theory,
! and models. Reviews of Geophysics 37(1), 1-64.
! </REFERENCE>
!
!<NAMELIST NAME="ocean_blob_dynamic_free_nml">
!
! <DATA NAME="use_this_module" TYPE="logical">
! Must be true to use this module.
! Default is use_this_module=.false.
! </DATA>
!
! <DATA NAME="rayleigh_drag_new" TYPE="real">
! Rayleigh drag coefficient (1/s) for new blobs that
! are formed due to the vertical instability
! criterion. Corresponds to alpha in the notes.
! Default is rayleigh_drag_new=1.0e-5
! </DATA>
!
! <DATA NAME="rayleigh_drag_bot" TYPE="real">
! Rayleigh drag coefficient (1/s) for bottom blobs
! that become free blobs. Corresponds to alpha in
! the notes.
! Default is rayleigh_drag_bot=1.0e-7
! </DATA>
!
! <DATA NAME="update_method" TYPE="character">
! Decide which method to use to integrate the
! blobs. Choices are 'BS_RK3(2)' or 'CK_RK5(4)'
! for the Bogaki-Shampine or Cash-Karp methods
! respectively.
! Default is update_method='CK_RK5(4)
! </DATA>
!
! <DATA NAME="rel_error" TYPE="real">
! Relative error for the RK scheme (dimensionless).
! A smaller number is more accurate, but,
! is more computationally expensive. Corresponds to
! zeta* in the notes.
! Must be 0<rel_error<=1.0
! Default is rel_error=0.01
! </DATA>
!
! <DATA NAME="safety_factor" TYPE="real">
! Safety factor for the RK scheme (dimensionless).
! A smaller number should reduce the number
! of rejected steps, but, decreases the locally
! extrapolated step. Corresponds to varrho in
! the notes.
! Must be 0<safety_factor<=1.0
! Default is safety_factor=0.8
! </DATA>
!
! <DATA NAME="minstep" TYPE="real">
! Minimum step size (in seconds) for a blob.
! Default is minstep=9.0
! </DATA>
!
! <DATA NAME="size_fact" TYPE="real">
! An Adjustment for blob size, 0<size_fact<=1.0
! Corresponds to Lambda in the notes.
! Default is size_fact=1.0
! </DATA>
!
! <DATA NAME="det_param" TYPE="real">
! The detrainment parameter (kg m^2/s).
! Corresponds to Gamma in the notes.
! Default is det_param=5.0e-8
! </DATA>
!
! <DATA NAME="max_detrainment" TYPE="real">
! The Maximum allowable detrainment velocity (m/s).
! Default is max_detrainment=1.0e-3
! </DATA>
!
! <DATA NAME="bv_freq_threshold" TYPE="real">
! The buoyancy frequency threshold at which
! the scheme will start to create blobs, i.e.
! blobs will be formed when N^2<bv_freq_threshold
! Default is bv_freq_threshold=-1.0e-15
! </DATA>
!
! <DATA NAME="full_N2" TYPE="logical">
! Whether to use the buoyancy frequency calculated
! from the combined E and L system (true) or, from
! the E system only (false).
! Default is full_N2=.true.
! </DATA>
!
! <DATA NAME="large_speed" TYPE="real">
! A value for error checking. If the speed of a
! blob exceeds large_speed in any of x,y,z then
! a warning flag is raised.
! Default is large_speed=10.0
! </DATA>
!
!</NAMELIST>
!</INFO>
!
use constants_mod, only: deg_to_rad, epsln, pi
use diag_manager_mod, only: register_diag_field, send_data
use fms_mod, only: stdout, stdlog, open_namelist_file, WARNING, FATAL
use fms_mod, only: mpp_error, check_nml_error, close_file
use mpp_mod, only: mpp_send, mpp_recv, NULL_PE, mpp_sum, mpp_sync_self
use mpp_mod, only: mpp_set_current_pelist
use mpp_mod, only: CLOCK_LOOP, CLOCK_ROUTINE, mpp_clock_id, mpp_clock_begin, mpp_clock_end
use mpp_domains_mod, only: mpp_update_domains, mpp_global_sum
use ocean_blob_util_mod, only: E_and_L_totals, count_blob, reallocate_interaction_memory
use ocean_blob_util_mod, only: insert_blob, allocate_interaction_memory, interp_tcoeff, interp_ucoeff
use ocean_blob_util_mod, only: check_ijcell, check_kcell, kill_blob, free_blob_memory
use ocean_blob_util_mod, only: blob_delete, unlink_blob, check_cyclic
use ocean_density_mod, only: density, buoyfreq2
use ocean_parameters_mod, only: rho0, rho0r, grav, omega_earth
use ocean_parameters_mod, only: PRESSURE_BASED, DEPTH_BASED, onehalf, onethird, twothirds, onefourth
use ocean_types_mod, only: ocean_time_type, ocean_grid_type, ocean_domain_type
use ocean_types_mod, only: ocean_lagrangian_type, ocean_thickness_type
use ocean_types_mod, only: ocean_blob_type, ocean_prog_tracer_type
use ocean_types_mod, only: ocean_density_type, ocean_velocity_type, blob_diag_type
use ocean_types_mod, only: ocean_external_mode_type, blob_grid_type, ocean_adv_vel_type
use ocean_util_mod, only: write_timestamp
use ocean_workspace_mod, only: wrk1, wrk2, wrk3
implicit none
private
type(ocean_grid_type), pointer :: Grd => NULL()
type(ocean_domain_type), pointer :: Dom => NULL()
type(ocean_domain_type), pointer :: Bdom => NULL() !A domain variable with halo=2
type(blob_grid_type), pointer :: Info => NULL()
! Module wide variables that are inherited/derived from the main model
real, allocatable, dimension(:,:,:) :: umask !umask, but, halo=2
real, allocatable, dimension(:,:,:) :: tmask !tmask, but, halo=2
real, allocatable, dimension(:,:) :: datdtime !Grd%dat*dtime
integer :: vert_coordinate_class
integer :: vert_coordinate
real :: dtime
real :: dtime_yr
! Useful variables
real :: two_omega
real :: p5_dtime
real :: grav_dtime
real :: det_factor
!RK coefficients
real, dimension(:,:), allocatable :: beta
real, dimension(:), allocatable :: lgamma
real, dimension(:), allocatable :: hgamma
real :: order
real :: orderp1_r
!Useful indexes
integer :: num_prog_tracers=0
integer :: index_temp=-1
integer :: index_salt=-1
integer :: isd,ied,jsd,jed
integer :: isc,iec,jsc,jec
integer :: isg,ieg,jsg,jeg
integer :: nk
integer :: isbd, iebd, jsbd, jebd
integer :: method
integer :: iq(4), jq(4)
integer :: ns, nsp1, total_ns, total_nsp1, total_nsp2
integer :: id_clock_dyn_update
integer :: id_clock_part_cycle
integer :: id_clock_rk
integer :: id_clock_updatevars
integer :: id_clock_findEvars
!Diagnostics
integer, allocatable, dimension(:) :: id_tracer_new
logical :: used
integer :: id_bot_to_free
integer :: id_new_blobs
!Buffers, for sending blobs between compute domains
type, private :: blob_buffer_type
integer :: numblobs
integer :: size
integer :: pe
integer, allocatable, dimension(:,:) :: integer_buff
real, allocatable, dimension(:,:) :: real_buff
integer, allocatable, dimension(:,:,:) :: history_integer_buff
real, allocatable, dimension(:,:,:) :: history_real_buff
end type blob_buffer_type
integer :: rea_buff_size !size of the real buffer
integer :: int_buff_size !size of the integer buffer
integer :: hist_rea_buff_size !size of the real history buffer
integer :: hist_int_buff_size !size of the integer history buffer
!The buffers themselves
type(blob_buffer_type), pointer :: Ebuffer_out, Ebuffer_in
type(blob_buffer_type), pointer :: Wbuffer_out, Wbuffer_in
type(blob_buffer_type), pointer :: Nbuffer_out, Nbuffer_in
type(blob_buffer_type), pointer :: Sbuffer_out, Sbuffer_in
type(blob_buffer_type), pointer :: NEbuffer_out, NEbuffer_in
type(blob_buffer_type), pointer :: NWbuffer_out, NWbuffer_in
type(blob_buffer_type), pointer :: SEbuffer_out, SEbuffer_in
type(blob_buffer_type), pointer :: SWbuffer_out, SWbuffer_in
integer, parameter :: delta_buffer = 25 ! Size by which to increment the buffer
public blob_dynamic_free_init
public blob_dynamic_free_implicit
public blob_dynamic_free_update
public transfer_bottom_to_free
public blob_dynamic_free_end
! Module wide variables that are controlled by the ocean_blob_nml and ocean_blob_diag_nml
logical :: debug_this_module
logical :: really_debug
logical :: bitwise_reproduction
logical :: module_is_initialized=.false.
logical :: blob_diag
real :: small_mass
! namelist defaults
logical :: use_this_module = .false.
real :: rayleigh_drag_new = 1.0e-5 ! Rayleigh drag coefficient (1/s) for newly formed blobs
real :: rayleigh_drag_bot = 1.0e-7 ! Rayleigh drag coefficient (1/s) for bottom blobs that become free blobs
character(len=10) :: update_method = 'CK_RK5(4)'
real :: rel_error = 0.01 ! Relative error for the RK scheme (non-dimensional, 0<rel_error<=1.0)
real :: safety_factor = 0.8 ! Safety factor for the RK scheme (non-dimensional, 0<safety_factor<=1.0)
real :: minstep = 9.0 ! Minimum step for a blob (seconds)
real :: first_step = 50.0 ! Size of first step of a blob
real :: size_fact = 1.0 ! Adjustment for blob size (non-dimensional, 0<size_fact<=1.0)
real :: det_param = 5.e-8 ! Detrainment parameter (Gamma; kg m**2 / s)
real :: max_detrainment = 1.e-3 ! Maximum detrainment velocity (m/s)
real :: bv_freq_threshold = -1.e-15 ! The stability threshold at which to form blobs (1/s**2)
logical :: full_N2 =.true.
real :: large_speed = 10.0 ! For stability checking (m/s)
namelist /ocean_blob_dynamic_free_nml/ use_this_module, rayleigh_drag_new, &
rayleigh_drag_bot, update_method, rel_error, safety_factor, minstep, &
first_step, size_fact, det_param, max_detrainment, bv_freq_threshold, &
full_N2, large_speed
contains
!#######################################################################
! <SUBROUTINE NAME="blob_dynamic_free_init">
!
! <DESCRIPTION>
! Initialises the dynamic free blobs by checking the namelist and also
! inherited namelists (from ocean_blob_nml). Also sets up some useful
! constants, allocates memory to special halo=2 masks and sets up
! the blob buffers for sending blobs from one PE to another.
! </DESCRIPTION>
!
subroutine blob_dynamic_free_init(Grid, Domain, Time, T_prog, Blob_domain, &
PE_info, debug, big_debug, bitwise, num_tracers, &
itemp, isalt, dtimein, ver_coord_class, &
ver_coord, blob_diagnostics, free_minstep, &
free_total_ns, smallmass, use_dyn_fre)
type(ocean_grid_type), intent(in), target :: Grid
type(ocean_domain_type), intent(in), target :: Domain
type(ocean_time_type), intent(in) :: Time
type(ocean_prog_tracer_type), intent(in) :: T_prog(:)
type(ocean_domain_type), intent(in), target :: Blob_domain
type(blob_grid_type), intent(in), target :: PE_info
logical, intent(in) :: debug
logical, intent(in) :: big_debug
logical, intent(in) :: bitwise
integer, intent(in) :: num_tracers
integer, intent(in) :: itemp
integer, intent(in) :: isalt
real, intent(in) :: dtimein
integer, intent(in) :: ver_coord_class
integer, intent(in) :: ver_coord
logical, intent(in) :: blob_diagnostics
real, intent(out) :: free_minstep
integer, intent(out) :: free_total_ns
real, intent(in) :: smallmass
logical, intent(out) :: use_dyn_fre
real, parameter :: secs_in_year_r = 1.0 / (86400.0 * 365.25)
integer :: n
integer :: ioun, ierr, io_status
integer :: stdoutunit,stdlogunit
character(32) :: myname, myunit
stdoutunit=stdout();stdlogunit=stdlog()
if ( module_is_initialized ) then
call mpp_error(FATAL,&
'==>Error in ocean_blob_dynamic_free_mod (ocean_blob_dynamic_free_init):' &
//' module already initialized')
endif
! provide for namelist over-ride of default values
ioun = open_namelist_file()
read (ioun,ocean_blob_dynamic_free_nml,IOSTAT=io_status)
write (stdoutunit,'(/)')
write (stdoutunit,ocean_blob_dynamic_free_nml)
write (stdlogunit,ocean_blob_dynamic_free_nml)
ierr = check_nml_error(io_status,'ocean_blob_dynamic_free_nml')
call close_file (ioun)
module_is_initialized = .true.
! The way things are formulated, we cannot run the bottom blobs
! without running free blobs. But, we can stop free blobs being
! formed by the vertical instability condition. So, if dynamic
! bottom blos are selected, we overwrite use_this_module for
! the dynamic free blobs, however, we ensure that the formation
! of free blobs by vertical instabily is not invoked.
use_dyn_fre = use_this_module
id_bot_to_free = register_diag_field('ocean_model', 'bot_to_free', Time%model_time, &
'blobs separating from the bottom', 'number of blobs')
if (.not. use_this_module) return
id_new_blobs = register_diag_field('ocean_model', 'new_free_blobs', Time%model_time, &
'new free blobs', 'number of blobs')
blob_diag = blob_diagnostics
free_minstep = minstep
index_temp = itemp
index_salt = isalt
num_prog_tracers = num_tracers
debug_this_module = debug
really_debug = big_debug
bitwise_reproduction = bitwise
small_mass = smallmass
vert_coordinate_class = ver_coord_class
vert_coordinate = ver_coord
Grd => Grid
Dom => Domain
Bdom => Blob_domain
Info => PE_info
isd=Dom%isd; ied=Dom%ied; jsd=Dom%jsd; jed=Dom%jed
isc=Dom%isc; iec=Dom%iec; jsc=Dom%jsc; jec=Dom%jec
isg=Dom%isg; ieg=Dom%ieg; jsg=Dom%jsg; jeg=Dom%jeg
nk = Grd%nk
isbd=Bdom%isd; iebd=Bdom%ied; jsbd=Bdom%jsd; jebd=Bdom%jed
!1: (i-1,j-1), 2:(i-1,j), 3:(i,j), 4:(i,j-1)
iq(1)=-1; jq(1)=-1
iq(2)=-1; jq(2)= 0
iq(3)= 0; jq(3)= 0
iq(4)= 0; jq(4)=-1
allocate(umask(isbd:iebd,jsbd:jebd,1:nk))
allocate(tmask(isbd:iebd,jsbd:jebd,0:nk)) !we need tmask(0:nk) for the W grid
umask(isc:iec,jsc:jec,1:nk) = Grd%umask(isc:iec,jsc:jec, 1:nk)
tmask(isc:iec,jsc:jec,1:nk) = Grd%tmask(isc:iec,jsc:jec, 1:nk)
tmask(isc:iec,jsc:jec,0) = Grd%tmask(isc:iec,jsc:jec, 1)
call mpp_update_domains(umask(:,:,:), Bdom%domain2d)
call mpp_update_domains(tmask(:,:,:), Bdom%domain2d)
! special treatment for boundaries if they are NULL_PEs.
! Make sure that umask==0 and tmask==0
if (Info%pe_S==NULL_PE) then
umask(:,jsbd:jsd,:) = 0.0
tmask(:,jsbd:jsd,:) = 0.0
endif
if (Info%pe_N==NULL_PE) then
umask(:,jed:jebd,:) = 0.0
tmask(:,jed:jebd,:) = 0.0
endif
if (Info%pe_E==NULL_PE) then
umask(ied:iebd,:,:) = 0.0
tmask(ied:iebd,:,:) = 0.0
endif
if (Info%pe_W==NULL_PE) then
umask(isbd:isd,:,:) = 0.0
tmask(isbd:isd,:,:) = 0.0
endif
allocate( datdtime(isd:ied,jsd:jed) )
datdtime(:,:) = Grd%dat(:,:)*dtimein
dtime = dtimein
dtime_yr = dtime*secs_in_year_r
grav_dtime = grav*dtime
p5_dtime = onehalf*dtime !for convenience
two_omega = 2.0*omega_earth
solver_method: select case(trim(update_method))
case('BS_RK3(2)')
method = 1
allocate(beta(1:3,0:2)); beta(:,:) = 0.
allocate(lgamma(0:3)); lgamma(:) = 0. !2nd order coefficients
allocate(hgamma(0:3)); hgamma(:) = 0. !3rd order coefficients
beta(1,0) = 1/2.
beta(2,0:1) = (/ 0., 3/4. /)
beta(3,0:2) = (/ 2/9., 1/3., 4/9. /)
hgamma(0:3) = (/ 2/9., 1/3., 4/9., 0. /)
lgamma(0:3) = (/ 7/24., 1/4., 1/3., 1/8. /)
order = 2.
orderp1_r = 1/(order + 1.)
case('CK_RK5(4)')
method = 3
allocate(beta(1:5,0:4)); beta(:,:) = 0.
allocate(lgamma(0:5)); lgamma(:) = 0. !4th order coefficients
allocate(hgamma(0:5)); hgamma(:) = 0. !5th order coefficients
beta(1,0) = 1/5.
beta(2,0:1) = (/ 3/40. , 9/40. /)
beta(3,0:2) = (/ 3/10. , -9/10. , 6/5. /)
beta(4,0:3) = (/ -11/54. , 5/2. , -70/27. , 35/27. /)
beta(5,0:4) = (/ 1631/55296., 175/512., 575/13824., 44275/110592., 253/4096. /)
hgamma(0:5) = (/ 37/378. , 0., 250/621. , 125/594. , 0. , 512/1771. /)
lgamma(0:5) = (/ 2825/27648., 0., 18575/48384., 13525/55296., 277/14336., 1/4. /)
order = 4.
orderp1_r = 1/(order + 1.)
case default
write(stdoutunit,'(a)')&
'==>Error in ocean_blob_dynamic_free_mod (ocean_blob_dynamic_free_init):' &
//' invalid solver chosen ('//update_method//'). Check update_method in namelist.'
call mpp_error(FATAL,&
'==>Error in ocean_blob_dynamic_free_mod (ocean_blob_dynamic_free_init):' &
//' invalid solver chosen ('//update_method//'). Check update_method in namelist.')
endselect solver_method
if (method==0) minstep=dtime
ns = ubound(lgamma,1) !number of partial steps in a fractional step
nsp1 = ns+1 !number of partial steps in a fractional step+1
total_ns = ceiling(dtime/minstep)
total_nsp1 = total_ns+1
total_nsp2 = total_nsp1+1
free_total_ns = total_ns
! This collects all the constant terms together in the expression
! for the rate of change of mass.
! dm/dt = rhoL A D (A=blob surface area, D=detrainment rate)
! = -rhoL A Gamma/|rhoL - rhoE|
! = -m**2/3 Gamma rhoL (36pi)**1/3 / (rhoL**2/3 |rhoL-rhoE|)
!
! In the Boussinesq case rhoL=rho0 (outside |rhoL-rhoE|)
! we also need to take into account that this is done for each PARTIAL step.
if (vert_coordinate_class==DEPTH_BASED) then
! here: det_factor = Gamma (rho0*36pi)**1/3 / number of partial steps
det_factor = det_param*( (rho0*36*pi)**onethird )
else !PRESSURE_BASED
! here: det_factor = Gamma (36pi)**1/3
det_factor = det_param*( (36*pi)**onethird )
endif
! Allocate the buffers
! Things that dictate the size of the real buffer are:
! tracer content (num_prog_tracer), change in mass (1),
! change in tracer (num_prog_tracer; only needed for bitwise_reproduction),
! velocity(3), position (3),
! step size (1), blob time (1), mass (1), stretching function (2)
! drag (1), dmass(1), gprime (1) and age (1).
rea_buff_size = 2*num_prog_tracers+15
! Integer buffer is: ijk (3), model_steps (1), hash (1), number (1),
! nfrac_steps (1), nsteps (1)
int_buff_size = 8
if (bitwise_reproduction) then
! History real buffer is: entrainment (num_prog_tracers+1), detrainment (num_prog_tracers+1)
! mass in/out (2).
hist_rea_buff_size = 2*num_prog_tracers+3 !it is not 2*(num_prog_tracers+1)+2 because the dimension goes from 0
! History integer buffer is: ijk (3)
hist_int_buff_size = 3
else
! History real buffer is: entrainment (num_prog_tracers+1), detrainment (num_prog_tracers+1)
hist_rea_buff_size = 2*num_prog_tracers + 1 !it is not 2*(num_prog_tracers+1) because the dimension goes from 0
endif
call allocate_buffer(Ebuffer_out, Info%pe_E); call allocate_buffer(Ebuffer_in, Info%pe_E)
call allocate_buffer(Wbuffer_out, Info%pe_W); call allocate_buffer(Wbuffer_in, Info%pe_W)
call allocate_buffer(Nbuffer_out, Info%pe_N); call allocate_buffer(Nbuffer_in, Info%pe_N)
call allocate_buffer(Sbuffer_out, Info%pe_S); call allocate_buffer(Sbuffer_in, Info%pe_S)
call allocate_buffer(NEbuffer_out, Info%pe_NE); call allocate_buffer(NEbuffer_in, Info%pe_NE)
call allocate_buffer(NWbuffer_out, Info%pe_NW); call allocate_buffer(NWbuffer_in, Info%pe_NW)
call allocate_buffer(SEbuffer_out, Info%pe_SE); call allocate_buffer(SEbuffer_in, Info%pe_SE)
call allocate_buffer(SWbuffer_out, Info%pe_SW); call allocate_buffer(SWbuffer_in, Info%pe_SW)
id_clock_dyn_update = mpp_clock_id('(Ocean dyn. free blob: update) ',grain=CLOCK_ROUTINE)
id_clock_part_cycle = mpp_clock_id('(Ocean dyn. free blob: part step) ',grain=CLOCK_LOOP)
id_clock_rk = mpp_clock_id('(Ocean dyn. free blob: RK scheme) ',grain=CLOCK_LOOP)
id_clock_updatevars = mpp_clock_id('(Ocean dyn. free blob: updatevars)',grain=CLOCK_LOOP)
id_clock_findEvars = mpp_clock_id('(Ocean dyn. free blob: findEvars) ',grain=CLOCK_LOOP)
allocate(id_tracer_new(num_prog_tracers))
do n=1,num_prog_tracers
if (n==index_temp) then
myname = 'heat'
myunit = 'J'
else
myname = T_prog(n)%name
myunit = 'kg'
endif
id_tracer_new(n) = register_diag_field('ocean_model', 'new_free_blob_'//trim(myname), &
Grd%tracer_axes(1:3), Time%model_time, trim(myname)//' transferred from the E to the L system via new free blobs', myunit)
enddo
contains
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! This is a nested subroutine that deallocates memory from a buffer !
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine allocate_buffer(buffer, pe)
type(blob_buffer_type), pointer :: buffer
integer, intent(in) :: pe
allocate(buffer)
buffer%pe = pe
buffer%numblobs = 0
if (buffer%pe /= NULL_PE) then
buffer%size = delta_buffer
allocate(buffer%integer_buff(int_buff_size, delta_buffer))
allocate(buffer%real_buff( rea_buff_size, delta_buffer))
if (bitwise_reproduction) then
allocate(buffer%history_integer_buff(hist_int_buff_size, 0:total_nsp1, delta_buffer))
allocate(buffer%history_real_buff( 0:hist_rea_buff_size, 0:total_nsp1, delta_buffer))
else
allocate(buffer%history_real_buff(0:hist_rea_buff_size, 1, delta_buffer))
endif
endif
end subroutine allocate_buffer
end subroutine blob_dynamic_free_init
! </SUBROUTINE> NAME="blob_dynamic_free_init"
!#######################################################################
! <SUBROUTINE NAME="blob_dynamic_free_implicit">
!
! <DESCRIPTION>
! Initialises dynamic blobs in vertical statically unstable regions.
! Due to the instability condition, blobs should be formed after the
! surface forcing has been applied (which is a major source of
! instability in the water column). The surface forcing is applied
! implicitly in time in MOM, therefore, we must form blobs implicitly
! in time.
!
! If N^2<bv_freq_threshold, then, two blobs are formed. One rising
! and one sinking. The rising blobs is destroyed immediately (after
! it has been moved up one cell) and its properties returned to the E
! system. The sinking blob is added to a linked list, and its
! properties integrated at a later time step.
! </DESCRIPTION>
!
subroutine blob_dynamic_free_implicit(Time, Thickness, T_prog, Dens, Adv_vel, &
Velocity, head, blob_counter, EL_diag)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(inout) :: Thickness
type(ocean_prog_tracer_type), intent(inout) :: T_prog(:)
type(ocean_density_type), intent(in) :: Dens
type(ocean_adv_vel_type), intent(in) :: Adv_vel
type(ocean_velocity_type), intent(in) :: Velocity
type(ocean_blob_type), pointer :: head
integer, dimension(isc:iec,jsc:jec,nk), intent(inout) :: blob_counter
type(blob_diag_type), dimension(0:num_prog_tracers), intent(inout) :: EL_diag
real, dimension(isd:ied,jsd:jed,nk) :: bvfreq2
integer :: i, j, k, kp1, tau, taup1, n, nblobs
real :: mass_blob, rhodzt_blob, rhodztk, rhodztkp1
real :: rho_dzt_old, rho_dzt_dat_r
real :: small
real :: wE
type(ocean_blob_type), pointer :: sink
type(ocean_blob_type), pointer :: rise
small = 1e-3
nblobs = 0
! No need for use_this_module test, as we test for
! use_dyn_fre in ocean_blob_implicit
if (.not. module_is_initialized ) then
call mpp_error(FATAL, &
'==>Error in ocean_blob_static_free_mod (Lagrangian blob model): '&
//'module needs to be initialized')
endif
taup1 = Time%taup1
tau = Time%tau
! Begin by computing the square of the Brunt-Vaisalla Frequency
if (full_N2) then
! Use the combied L and E system for calculating N**2
do k=1,nk
wrk1(:,:,k) = ( Thickness%rho_dzt(:,:,k,taup1)*T_prog(index_salt)%field(:,:,k,taup1) &
+ Grd%datr(:,:)*T_prog(index_salt)%sum_blob(:,:,k,taup1) )/Thickness%rho_dztT(:,:,k,taup1)
wrk2(:,:,k) = ( Thickness%rho_dzt(:,:,k,taup1)*T_prog(index_temp)%field(:,:,k,taup1) &
+ Grd%datr(:,:)*T_prog(index_temp)%sum_blob(:,:,k,taup1) )/Thickness%rho_dztT(:,:,k,taup1)
enddo
wrk3(:,:,:) = density(wrk1(:,:,:), wrk2(:,:,:), Dens%pressure_at_depth(:,:,:))
bvfreq2(:,:,:) = buoyfreq2(Time, Thickness, Dens, wrk1(:,:,:), wrk2(:,:,:), wrk3(:,:,:), use_this_module)
! We need the E system density for calculations below
wrk3(:,:,:) = density(T_prog(index_salt)%field(:,:,:,taup1), T_prog(index_temp)%field(:,:,:,taup1), Dens%pressure_at_depth(:,:,:))
else
! Only use the E system for calculating N**2
wrk3(:,:,:) = density(T_prog(index_salt)%field(:,:,:,taup1), T_prog(index_temp)%field(:,:,:,taup1), Dens%pressure_at_depth(:,:,:))
bvfreq2(:,:,:) = buoyfreq2(Time, Thickness, Dens, T_prog(index_salt)%field(:,:,:,taup1), &
T_prog(index_temp)%field(:,:,:,taup1), wrk3(:,:,:), use_this_module)
endif
do k=1,nk-1
kp1 = k+1
do j=jsc,jec
do i=isc,iec
if (bvfreq2(i,j,k) < bv_freq_threshold) then
! some shorthand variables for convenience
rhodztk = Thickness%rho_dzt(i,j,k, taup1)
rhodztkp1 = Thickness%rho_dzt(i,j,kp1,taup1)
! compute the mass per unit of the two blobs. Note that
! dat is the same for both k and kp1;
! mass=(dat*rhodztk * dat*rhodztkp1)/(dat(rhodztk + rhodztkp1))
! =dat*rhodztk*rhodztkp1/(rhodztk + rhodztkp1)
! mass per unit area = rhodztk*rhodztkp1/(rhodztk + rhodztkp1)
! size_fact is a non-dimensional namelist parameter that is
! scales the size of the blob. 0.0<size_fact<=1.0
rhodzt_blob = size_fact*(rhodztk * rhodztkp1)/(rhodztk + rhodztkp1)
mass_blob = rhodzt_blob * Grd%dat(i,j)
! form the sinking dynamic blob
allocate(sink)
allocate(sink%tracer(num_prog_tracers))
allocate(sink%field(num_prog_tracers))
sink%i = i
sink%j = j
sink%k = k
sink%blob_time = 0.0
sink%mass = mass_blob
! Assign tracer content and tracer concentration to the blob
do n=1,num_prog_tracers
! sink%tracer is blob_mass*[concentration]
sink%tracer(n) = sink%mass*T_prog(n)%field(i,j,k,taup1)
! even though sink%field is initially the concentration of the grid cell
! we need to calculate it like this to maintain bitwise agreement
sink%field(n) = sink%tracer(n)/sink%mass
enddo
! Calculate the density of the blob at kp1
sink%density = density(sink%field(index_salt), &
sink%field(index_temp), &
Dens%pressure_at_depth(i,j,kp1))
sink%densityr = 1.0/sink%density
! the intial vertical velocity
! We use rho0r whether it is depth or pressure based coordinates to calculate
! the E system vertical velocity. This represents an error of about 2% in
! pressure based coordinates.
wE = rho0r * Adv_vel%wrho_bt(i,j,k)
sink%v(3) = wE - grav_dtime*(sink%density-wrk3(i,j,kp1))*sink%densityr
if (sink%v(3) > 0.0) then
! the vertical velocity is positive and therefore the blob will want to
! rise instead of sink. this can be because of either
! 1/ the pseudo-non-hydrostatic term is positive (i.e. sink%density<rhoE)
! 2/ wE > abs(pseudo-non-hydrostatic term).
! If a blob does not want to sink, then it wants to stay in the original
! grid cell, and there is thus no point in forming it, so
! we dont bother forming it and accept that the water column will remain
! unstable.
call free_blob_memory(sink)
cycle
endif
! count the blob
call count_blob(sink, blob_counter)
! insert the blob into the linked list
call insert_blob(sink, head)
nblobs = nblobs+1
sink%age = 0.0
! take the sink blob away from the E systems rho_dzt
Thickness%rho_dzt(i,j,k,taup1) = Thickness%rho_dzt(i,j,k,taup1) &
- sink%mass * Grd%datr(i,j)
! update rho_dztr
Thickness%rho_dztr(i,j,k) = 1.0/(Thickness%rho_dzt(i,j,k,taup1)+epsln)
! We do not need to adjust the E system field for the k grid cell at this
! stage.
! we take the average of the four surrounding velocity grid cells for the
! initial horizontal velocity of sink
sink%v(1) = ( Velocity%u(i ,j ,k,1,tau) + Velocity%u(i-1,j ,k,1,tau) &
+ Velocity%u(i ,j-1,k,1,tau) + Velocity%u(i-1,j-1,k,1,tau) &
)*onefourth
sink%v(2) = ( Velocity%u(i ,j ,k,2,tau) + Velocity%u(i-1,j ,k,2,tau) &
+ Velocity%u(i ,j-1,k,2,tau) + Velocity%u(i-1,j-1,k,2,tau) &
)*onefourth
! find the intial longitude and latitude
sink%lon = Grd%xt(i,j) + dtime*sink%v(1)/Grd%h1t(i,j)
sink%lat = Grd%yt(i,j) + dtime*sink%v(2)/Grd%h2t(i,j)
sink%new = .true.
sink%step = first_step
sink%model_steps = 0
sink%nsteps = 0
sink%drag = rayleigh_drag_new
! Now create the rising blob
allocate(rise)
allocate(rise%tracer(num_prog_tracers))
rise%mass = mass_blob
! Assign tracer content and tracer concentration to the blob
do n=1,num_prog_tracers
! rise%tracer is blob_mass*[concentration]
rise%tracer(n) = rise%mass*T_prog(n)%field(i,j,kp1,taup1)
enddo
! take the rise blob away from the E systems rho_dzt
Thickness%rho_dzt(i,j,kp1,taup1) = Thickness%rho_dzt(i,j,kp1,taup1) &
- rise%mass * Grd%datr(i,j)
! update rho_dztr
Thickness%rho_dztr(i,j,kp1) = 1.0/(Thickness%rho_dzt(i,j,kp1,taup1)+epsln)
! Now we swap the two blobs. sink goes to the kp1 cell and rise goes to the
! k cell.
rise%k = k
sink%k = kp1
! Calculate the depth and position the native vertical coordinate of sink.
! We recall that z and depth have opposite signs.
sink%depth = Thickness%depth_zwt(i,j,k) - p5_dtime*sink%v(3)
! If the initial position of the blob is calculated to be deeper than
! the bottom of the kp1 cell (in coordinate space), we adjust the initial
! position to ensure that the blob remains in the kp1 cell. We also adjust
! the initial velocity to reflect the new imposed position.
! Also calculate the volume
if (vert_coordinate_class == DEPTH_BASED) then
sink%st = -( Thickness%depth_swt(i,j,k) + (sink%depth-Thickness%depth_zwt(i,j,k))/Thickness%dzt_dst(i,j,kp1) )
if (sink%st <= -Thickness%depth_swt(i,j,kp1)) then
sink%st = -Thickness%depth_swt(i,j,kp1) + small
sink%depth = Thickness%depth_zwt(i,j,kp1) - small*Thickness%dzt_dst(i,j,kp1)
sink%v(3) = -( sink%depth-Thickness%depth_zwt(i,j,k) )/dtime
endif
sink%volume = sink%mass * rho0r
else !PRESSURE_BASED
sink%st = Thickness%depth_swt(i,j,k) - (sink%depth-Thickness%depth_zwt(i,j,k))/Thickness%dzt_dst(i,j,kp1)
if (sink%st >= Thickness%depth_swt(i,j,kp1)) then
sink%st = Thickness%depth_swt(i,j,kp1) - small
sink%depth = Thickness%depth_zwt(i,j,kp1) + small*Thickness%dzt_dst(i,j,kp1)
sink%v(3) = -( sink%depth-Thickness%depth_zwt(i,j,k) )/dtime
endif
sink%volume = sink%mass * sink%densityr
endif
! Add the blob tracer content to the total blob tracer content
do n=1,num_prog_tracers
T_prog(n)%sum_blob(i,j,kp1,taup1) = T_prog(n)%sum_blob(i,j,kp1,taup1) + sink%tracer(n)
enddo
! Now we take care of rise, returning its properties to the E system.
! Transfer mass from the Lagrangian system to the Eulerian System
rho_dzt_old = Thickness%rho_dzt(i,j,k,taup1)
Thickness%rho_dzt(i,j,k,taup1) = Thickness%rho_dzt(i,j,k,taup1)&
+ rise%mass*Grd%datr(i,j)
Thickness%rho_dztr(i,j,k) = 1.0/(Thickness%rho_dzt(i,j,k,taup1)+epsln)
rise%mass = rise%mass - rise%mass
! transfer tracer from the Lagrangian system to the Eulerian System
rho_dzt_dat_r = Grd%datr(i,j)*Thickness%rho_dztr(i,j,k)
do n=1,num_prog_tracers
T_prog(n)%field(i,j,k,taup1) = rho_dzt_old*Thickness%rho_dztr(i,j,k)*T_prog(n)%field(i,j,k,taup1) &
+ rise%tracer(n)*rho_dzt_dat_r
rise%tracer(n) = rise%tracer(n) - rise%tracer(n)
enddo
call free_blob_memory(rise)
! Add in some more structure to the sinking blob. The structure is required
! for the E-L system interaction.
call allocate_interaction_memory(sink, total_ns)
! Diagnostics
EL_diag(0)%new(i,j,k) = EL_diag(0)%new(i,j,k) + sink%mass
do n=1,num_prog_tracers
EL_diag(n)%new(i,j,k) = EL_diag(n)%new(i,j,k) + sink%tracer(n)
enddo
! Need to set this to zero for diagnostics
sink%ent = 0.0
nullify(sink)
endif !bv frequency small?
enddo !i
enddo !j
enddo!k
call mpp_sum(nblobs)
if (id_new_blobs>0) used = send_data(id_new_blobs, real(nblobs), Time%model_time)
end subroutine blob_dynamic_free_implicit
! </SUBROUTINE> NAME="blob_dynamic_free_implicit"
!######################################################################
! <SUBROUTINE NAME="blob_dynamic_free_update">
!
! <DESCRIPTION>
! This routine calls the routine to update blob positions. When
! bitwise_reproduction=.false., it also figures out when to continue
! the integration of blobs that have changed PE's.
! </DESCRIPTION>
!
subroutine blob_dynamic_free_update(Time, Thickness, T_prog, Ext_mode, Dens, &
L_system, tend_blob, blob_source, press_grad, &
u, w, model_rho, free_head, bottom, &
mass_in, mass_out, EL_diag, ngrnd, nsfc, ndetrn)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(inout) :: Thickness
type(ocean_prog_tracer_type), intent(inout) :: T_prog(:)
type(ocean_external_mode_type), intent(inout) :: Ext_mode
type(ocean_density_type), intent(in) :: Dens
type(ocean_lagrangian_type), intent(inout) :: L_system
real,dimension(num_prog_tracers,isd:ied,jsd:jed,nk), intent(inout) :: tend_blob
real,dimension(isd:ied,jsd:jed), intent(inout) :: blob_source
real, dimension(isbd:iebd,jsbd:jebd,1:nk,1:2), intent(in) :: press_grad
real, dimension(isbd:iebd,jsbd:jebd,1:nk,1:2), intent(in) :: u
real, dimension(isbd:iebd,jsbd:jebd,1:nk), intent(in) :: w
real, dimension(isbd:iebd,jsbd:jebd,1:nk), intent(in) :: model_rho
type(ocean_blob_type), pointer :: free_head
type(ocean_blob_type), pointer :: bottom
real, dimension(isd:ied,jsd:jed,1:nk), intent(inout) :: mass_in
real, dimension(isd:ied,jsd:jed,1:nk), intent(inout) :: mass_out
type(blob_diag_type), dimension(0:num_prog_tracers), intent(inout) :: EL_diag
integer, intent(inout) :: ngrnd
integer, intent(inout) :: nsfc
integer, intent(inout) :: ndetrn
type(ocean_blob_type), pointer :: prev, this, next, buffer_head
integer :: check_buffers
integer :: i,j,k,n
integer :: stdoutunit
if (.not. use_this_module) return
nullify(bottom)
nullify(this)
! Clear buffers for sending and receiving free blobs
call clear_buffer(Ebuffer_out); call clear_buffer( Ebuffer_in)
call clear_buffer(Wbuffer_out); call clear_buffer( Wbuffer_in)
call clear_buffer(Nbuffer_out); call clear_buffer( Nbuffer_in)
call clear_buffer(Sbuffer_out); call clear_buffer( Sbuffer_in)
call clear_buffer(NEbuffer_out); call clear_buffer(NEbuffer_in)
call clear_buffer(NWbuffer_out); call clear_buffer(NWbuffer_in)
call clear_buffer(SEbuffer_out); call clear_buffer(SEbuffer_in)
call clear_buffer(SWbuffer_out); call clear_buffer(SWbuffer_in)
if (debug_this_module) then
stdoutunit = stdout()
write(stdoutunit, '(a)') ' '
call write_timestamp(Time%model_time)
write(stdoutunit,'(a)') 'From ocean_blob_dynamic_free_mod'
write(stdoutunit,'(a)') 'Totals before free dynamic blob update (tau)'
call E_and_L_totals(L_system,Thickness,T_prog(:),Time%tau)
write(stdoutunit,'(a)') ' '
endif
! Reset the blob time to zero for the beginning of the Eulerian time step
if (associated(free_head)) then
this=>free_head
timecycle: do
this%blob_time = 0.0
this=>this%next
if(.not.associated(this)) exit timecycle
enddo timecycle
endif
call mpp_clock_begin(id_clock_dyn_update)
call dynamic_update(Time, Thickness, Ext_mode, L_system, Dens, &
T_prog(:), tend_blob, blob_source, press_grad, &
u, w, model_rho, free_head, bottom, &
mass_in, mass_out, EL_diag(:), ngrnd, nsfc, ndetrn)
call mpp_clock_end(id_clock_dyn_update)
if (bitwise_reproduction) then
! Send, receive and unpack buffers for free blobs
call send_buffer( Ebuffer_out)
call send_buffer( Wbuffer_out)
call send_buffer( Sbuffer_out)
call send_buffer( Nbuffer_out)
call send_buffer(NEbuffer_out)
call send_buffer(NWbuffer_out)
call send_buffer(SEbuffer_out)
call send_buffer(SWbuffer_out)
call receive_buffer( Wbuffer_in); call unpackbuffer(Time, Wbuffer_in, free_head, Dens)
call receive_buffer( Ebuffer_in); call unpackbuffer(Time, Ebuffer_in, free_head, Dens)
call receive_buffer( Nbuffer_in); call unpackbuffer(Time, Nbuffer_in, free_head, Dens)
call receive_buffer( Sbuffer_in); call unpackbuffer(Time, Sbuffer_in, free_head, Dens)
call receive_buffer(SWbuffer_in); call unpackbuffer(Time, SWbuffer_in, free_head, Dens)
call receive_buffer(SEbuffer_in); call unpackbuffer(Time, SEbuffer_in, free_head, Dens)
call receive_buffer(NWbuffer_in); call unpackbuffer(Time, NWbuffer_in, free_head, Dens)
call receive_buffer(NEbuffer_in); call unpackbuffer(Time, NEbuffer_in, free_head, Dens)
call mpp_sync_self()
else
! When bitwise reproduction is not necessary, blobs can be packed into
! buffers and sent to other PE's before they have finished a full E system
! step, i.e. this%blob_time < dtime.
! So, here, we unpack the blobs and continue to evolve them on the new PE.
! We need to take into account that a blob may traverse more than one PE
! in a given E system step, e.g.
! ------------------
! | | |
! | PE=2 +a PE=3 |
! | /| |
! | b | |
! ------+-----------
! | / | |
! | c | |
! | | |
! | PE=0 | PE=1 |
! ------------------
! So, we need to keep on checking buffers and evolving blobs until all received
! buffers are empty
! Send, receive and unpack buffers for free blobs
call send_buffer( Ebuffer_out)
call send_buffer( Wbuffer_out)
call send_buffer( Sbuffer_out)
call send_buffer( Nbuffer_out)
call send_buffer(NEbuffer_out)
call send_buffer(NWbuffer_out)
call send_buffer(SEbuffer_out)
call send_buffer(SWbuffer_out)
buffer_head=> NULL()
call receive_buffer( Wbuffer_in)
call unpackbuffer(Time, Wbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer( Ebuffer_in)
call unpackbuffer(Time, Ebuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer( Nbuffer_in)
call unpackbuffer(Time, Nbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer( Sbuffer_in)
call unpackbuffer(Time, Sbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(SWbuffer_in)
call unpackbuffer(Time, SWbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(SEbuffer_in)
call unpackbuffer(Time, SEbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(NWbuffer_in)
call unpackbuffer(Time, NWbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(NEbuffer_in)
call unpackbuffer(Time, NEbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call mpp_sync_self()
! Clear buffers for sending and receiving free blobs
call clear_buffer(Ebuffer_out); call clear_buffer( Ebuffer_in)
call clear_buffer(Wbuffer_out); call clear_buffer( Wbuffer_in)
call clear_buffer(Nbuffer_out); call clear_buffer( Nbuffer_in)
call clear_buffer(Sbuffer_out); call clear_buffer( Sbuffer_in)
call clear_buffer(NEbuffer_out); call clear_buffer(NEbuffer_in)
call clear_buffer(NWbuffer_out); call clear_buffer(NWbuffer_in)
call clear_buffer(SEbuffer_out); call clear_buffer(SEbuffer_in)
call clear_buffer(SWbuffer_out); call clear_buffer(SWbuffer_in)
check_buffers = 0
this=>buffer_head
if (associated(this)) then
buff_cycle0: do
if(this%blob_time == dtime) then
call unlink_blob(this, buffer_head, prev, next)
call insert_blob(this, free_head)
this=>next
else
check_buffers = check_buffers + 1
this=>this%next
endif
if (.not. associated(this)) exit buff_cycle0
enddo buff_cycle0
endif
call mpp_sum(check_buffers)
do while (check_buffers>0)
call dynamic_update(Time, Thickness, Ext_mode, L_system, Dens, &
T_prog(:), tend_blob, blob_source, press_grad, &
u, w, model_rho, buffer_head, bottom, &
mass_in, mass_out, EL_diag(:), ngrnd, nsfc, ndetrn)
call mpp_set_current_pelist()
! Send, receive and unpack buffers for free blobs
call send_buffer( Ebuffer_out)
call send_buffer( Wbuffer_out)
call send_buffer( Sbuffer_out)
call send_buffer( Nbuffer_out)
call send_buffer(NEbuffer_out)
call send_buffer(NWbuffer_out)
call send_buffer(SEbuffer_out)
call send_buffer(SWbuffer_out)
call receive_buffer( Wbuffer_in)
call unpackbuffer(Time, Wbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer( Ebuffer_in)
call unpackbuffer(Time, Ebuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer( Nbuffer_in)
call unpackbuffer(Time, Nbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer( Sbuffer_in)
call unpackbuffer(Time, Sbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(SWbuffer_in)
call unpackbuffer(Time, SWbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(SEbuffer_in)
call unpackbuffer(Time, SEbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(NWbuffer_in)
call unpackbuffer(Time, NWbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(NEbuffer_in)
call unpackbuffer(Time, NEbuffer_in, buffer_head, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call mpp_sync_self()
! Clear buffers for sending and receiving free blobs
call clear_buffer(Ebuffer_out); call clear_buffer( Ebuffer_in)
call clear_buffer(Wbuffer_out); call clear_buffer( Wbuffer_in)
call clear_buffer(Nbuffer_out); call clear_buffer( Nbuffer_in)
call clear_buffer(Sbuffer_out); call clear_buffer( Sbuffer_in)
call clear_buffer(NEbuffer_out); call clear_buffer(NEbuffer_in)
call clear_buffer(NWbuffer_out); call clear_buffer(NWbuffer_in)
call clear_buffer(SEbuffer_out); call clear_buffer(SEbuffer_in)
call clear_buffer(SWbuffer_out); call clear_buffer(SWbuffer_in)
check_buffers = 0
if (associated(buffer_head)) then
this => buffer_head
timecheck: do
if(this%blob_time == dtime) then
call unlink_blob(this, buffer_head, prev, next)
call insert_blob(this, free_head)
this=>next
else
check_buffers = check_buffers + 1
this=>this%next
endif
if(.not. associated(this)) exit timecheck
enddo timecheck
endif
call mpp_sum(check_buffers)
enddo
endif!bitwise_reproduction
! Pack and send buffers for free blobs that have become bottom blobs
! Clear buffers for sending and receiving bottom blobs
call clear_buffer(Ebuffer_out); call clear_buffer( Ebuffer_in)
call clear_buffer(Wbuffer_out); call clear_buffer( Wbuffer_in)
call clear_buffer(Nbuffer_out); call clear_buffer( Nbuffer_in)
call clear_buffer(Sbuffer_out); call clear_buffer( Sbuffer_in)
call clear_buffer(NEbuffer_out); call clear_buffer(NEbuffer_in)
call clear_buffer(NWbuffer_out); call clear_buffer(NWbuffer_in)
call clear_buffer(SEbuffer_out); call clear_buffer(SEbuffer_in)
call clear_buffer(SWbuffer_out); call clear_buffer(SWbuffer_in)
if (associated(bottom)) then
this=>bottom
blobcycle: do
i = this%i
j = this%j
k = this%k
if (i>iec .and. j>jec) then
call packbottombuffer(NEbuffer_out)
elseif (i<isc .and. j>jec) then
call packbottombuffer(NWbuffer_out)
elseif (i>iec .and. j<jsc) then
call packbottombuffer(SEbuffer_out)
elseif (i<isc .and. j<jsc) then
call packbottombuffer(SWbuffer_out)
elseif (i>iec) then
call packbottombuffer(Ebuffer_out)
elseif (i<isc) then
call packbottombuffer(Wbuffer_out)
elseif (j>jec) then
call packbottombuffer(Nbuffer_out)
elseif (j<jsc) then
call packbottombuffer(Sbuffer_out)
endif
this=>this%next
if(.not.associated(this)) exit blobcycle
enddo blobcycle
endif
! Send buffers for free blobs that have become bottom blobs
call send_buffer( Ebuffer_out)
call send_buffer( Wbuffer_out)
call send_buffer( Sbuffer_out)
call send_buffer( Nbuffer_out)
call send_buffer(NEbuffer_out)
call send_buffer(NWbuffer_out)
call send_buffer(SEbuffer_out)
call send_buffer(SWbuffer_out)
! Receive and unpack free blobs that have become bottom blobs
if (bitwise_reproduction) then
call receive_buffer( Ebuffer_in); call unpackbuffer(Time, Ebuffer_in, bottom, Dens)
call receive_buffer( Wbuffer_in); call unpackbuffer(Time, Wbuffer_in, bottom, Dens)
call receive_buffer( Nbuffer_in); call unpackbuffer(Time, Nbuffer_in, bottom, Dens)
call receive_buffer( Sbuffer_in); call unpackbuffer(Time, Sbuffer_in, bottom, Dens)
call receive_buffer(NEbuffer_in); call unpackbuffer(Time, NEbuffer_in, bottom, Dens)
call receive_buffer(NWbuffer_in); call unpackbuffer(Time, NWbuffer_in, bottom, Dens)
call receive_buffer(SEbuffer_in); call unpackbuffer(Time, SEbuffer_in, bottom, Dens)
call receive_buffer(SWbuffer_in); call unpackbuffer(Time, SWbuffer_in, bottom, Dens)
else
call receive_buffer( Ebuffer_in); call unpackbuffer(Time, Ebuffer_in, bottom, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer( Wbuffer_in); call unpackbuffer(Time, Wbuffer_in, bottom, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer( Nbuffer_in); call unpackbuffer(Time, Nbuffer_in, bottom, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer( Sbuffer_in); call unpackbuffer(Time, Sbuffer_in, bottom, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(NEbuffer_in); call unpackbuffer(Time, NEbuffer_in, bottom, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(NWbuffer_in); call unpackbuffer(Time, NWbuffer_in, bottom, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(SEbuffer_in); call unpackbuffer(Time, SEbuffer_in, bottom, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
call receive_buffer(SWbuffer_in); call unpackbuffer(Time, SWbuffer_in, bottom, Dens, Ext_mode, L_system, blob_source, tend_blob, mass_in, EL_diag)
endif
call mpp_sync_self()
contains
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! This is a nested subroutine that packs the buffer for free blobs that!
! have interacted with topography to become bottom blobs and have !
! crossed a processor boundary. !
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine packbottombuffer(buffer)
type(blob_buffer_type), pointer :: buffer
real, dimension(num_prog_tracers) :: dtracer
real, dimension(0:num_prog_tracers) :: entrainment, detrainment
integer :: s
dtracer(:) = 0.0
if (buffer%pe == Info%pe_this) then
! We have a cyclic grid and the blob is just going to
! end up back on the same processor. So, we just adjust
! the (i,j) values for the blob.
call check_cyclic(this, this%i, this%j, .true.)
if (bitwise_reproduction) then
do s=0,this%nfrac_steps
call check_cyclic(this, this%di(s), this%dj(s), .false.)
enddo
endif
else !going to a different PE
if (bitwise_reproduction) then
call packbuffer(this,buffer)
else
entrainment(:) = 0.0
detrainment(:) = 0.0
call packbuffer(this,buffer, entrainment(:), detrainment(:))
endif
this%mass=0.
do n=1,num_prog_tracers
this%tracer(n) = 0.
enddo
endif
end subroutine packbottombuffer
end subroutine blob_dynamic_free_update
! </SUBROUTINE> NAME="blob_dynamic_free_update"
!######################################################################
! <SUBROUTINE NAME="dynamic_update">
!
! <DESCRIPTION>
! This routine contains the RK scheme used to integrate the position
! and velocity of blobs. It also does many checks for (and
! subsequently handles) things like grounding of blobs, blobs going to
! different PEs, blobs that interact with topography, blobs that
! detrain to less than small_mass and blobs going outside the compute
! domain.
!
! It also does the interpolation of E system variables to a blob.
! </DESCRIPTION>
!
subroutine dynamic_update(Time, Thickness, Ext_mode, L_system, Dens, T_prog, &
tend_blob, blob_source, press_grad, u, w, model_rho, &
head, bottom_head, mass_in, mass_out, EL_diag, &
ngrnd, nsfc, ndetrn)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(inout) :: Thickness
type(ocean_external_mode_type), intent(inout) :: Ext_mode
type(ocean_lagrangian_type), intent(inout) :: L_system
type(ocean_density_type), intent(in) :: Dens
type(ocean_prog_tracer_type), intent(in) :: T_prog(:)
real,dimension(num_prog_tracers,isd:ied,jsd:jed,nk), intent(inout) :: tend_blob
real,dimension(isd:ied,jsd:jed), intent(inout) :: blob_source
real,dimension(isbd:iebd,jsbd:jebd,1:nk,1:2), intent(in) :: press_grad
real,dimension(isbd:iebd,jsbd:jebd,1:nk,1:2), intent(in) :: u
real,dimension(isbd:iebd,jsbd:jebd,0:nk), intent(in) :: w
real,dimension(isbd:iebd,jsbd:jebd,1:nk), intent(in) :: model_rho
type(ocean_blob_type), pointer :: head
type(ocean_blob_type), pointer :: bottom_head
real,dimension(isd:ied,jsd:jed,1:nk), intent(inout) :: mass_in
real,dimension(isd:ied,jsd:jed,1:nk), intent(inout) :: mass_out
type(blob_diag_type), intent(inout) :: EL_diag(0:)
integer, intent(inout) :: ngrnd
integer, intent(inout) :: nsfc
integer, intent(inout) :: ndetrn
type(ocean_blob_type), pointer :: prev, this, next
real, dimension(1:6,0:ns) :: V
real, dimension(num_prog_tracers) :: tracer, field
real, dimension(0:num_prog_tracers) :: entrainment, detrainment
integer, dimension(3) :: old_ijk
real, dimension(3) :: old_lld, vel
real, dimension(2) :: h, old_h
real, dimension(6) :: Xn, update, Xnp1, Xnp1_hat
real, dimension(9) :: tdsq_r
real, dimension(4) :: udsq_r
real, dimension(0:2) :: px, py, uE, vE, wE, rhoE
logical :: go_e, go_ne, go_n, go_nw, go_w, go_sw, go_s, go_se
integer :: ii, iit, jjt, iiu, jju, dk, kdk
integer :: i,j,k,tau,mm,m,n,r,s
integer :: n_frac_steps
integer :: total_blobs, leaving_pe, tfer_bottom, detrn_zero, move_lateral, ngrounded
integer :: stdoutunit
logical :: accept_step, reached_end, off(3), grounded
logical :: change_pe, advance_blob, special
real :: rhoL, rhoLr, rho, rhor, mass, volume
real :: f, fs
real :: lon, lat, geodepth
real :: tstep, old_tstep, blob_time
real :: trunc, hstar, tstar
real :: dmdt_det, dmdt_ent
real :: ubigd, tbigd, dzwtT, dz(2), vcoeff(2)
tau = Time%tau
! Set debugging counters to zero
total_blobs = 0
leaving_pe = 0
tfer_bottom = 0
detrn_zero = 0
move_lateral = 0
ngrounded = 0
if(associated(head)) then
this=>head
blob_cycle: do
! time relative to the beginning of the time step
blob_time = this%blob_time
tstep = this%step
this%dmass = 0.0
this%dtracer(:) = 0.0
if(bitwise_reproduction) then
! initialise the values of the history arrays
this%di(:) = -1
this%dj(:) = -1
this%dk(:) = -1
this%nfrac_steps = 0
this%entrainment(:,:) = 0.0
this%detrainment(:,:) = 0.0
this%mass_in(:) = 0.0
this%mass_out(:) = 0.0
this%di(0) = this%i
this%dj(0) = this%j
this%dk(0) = this%k
endif
! Make adjustments to the lon-lat and i-j (if necessary)
! on a cyclic or tripolar grid.
call check_cyclic(this, this%i, this%j, .true.)
! We dont want to alter the blob properties until
! we have completed the full partial step. So, we save
! the variables into local variables in case we need
! to redo something.
! These variables get updated from one RK sub-step to
! the next, so, we need to save copies of them in case
! the step is rejected.
i = this%i
j = this%j
k = this%k
old_ijk = (/ i, j, k/)
lon = this%lon
lat = this%lat
geodepth = this%geodepth
old_lld = (/lon, lat, geodepth/)
h(:) = (/ this%h1, this%h2 /)
old_h = h
! These variables are only updated at the end
! of all the RK sub-steps, so, we do not need
! to save copies
vel(:) = this%v(:)
mass = this%mass
volume = this%volume
rhoL = this%density
rhoLr = this%densityr
if (vert_coordinate_class==DEPTH_BASED) then
rho = rho0
rhor = rho0r
else !PRESSURE_BASED
rho = rhoL
rhor = rhoLr
endif
do n=1,num_prog_tracers
tracer(n) = this%tracer(n)
field(n) = this%field(n)
enddo
n_frac_steps = 0
! Set flags to default values
reached_end = .false.
change_pe = .false.
advance_blob = .true.
off(:) = .false.
grounded = .false.
! Calculate the horizontal interpolation coefficients
call interp_tcoeff(i,j,h(:),lon,lat,tdsq_r(:))
call interp_ucoeff(i,j,h(:),lon,lat,udsq_r(:))
call mpp_clock_begin(id_clock_part_cycle)
partialstep: do while (.not. reached_end)
accept_step = .false.
! Interpolate the E system variables to the blobs
! Note, we treat the stretching function separately
! Also: the stretching function does not require vertical
! interpolation
! Figure out some stuff for the vertical interpolation
! for the T and U grids. The W grid is handled differently.
if (k==1 .and. geodepth<Thickness%geodepth_zt(i,j,k)) then
special = .true.
dzwtT = Thickness%dzwtT(i,j,k)
dk = +1
elseif(k==Grd%kmt(i,j) .and. geodepth>Thickness%geodepth_zt(i,j,k)) then
special = .true.
dzwtT = Thickness%dzwtT(i,j,k-1)
dk = -1
else
special = .false.
if(geodepth<Thickness%geodepth_zt(i,j,k)) then
dk = -1
dzwtT = Thickness%dzwtT(i,j,k-1)
else
dk = +1
dzwtT = Thickness%dzwtT(i,j,k)
endif
endif
kdk = k+dk
! Now do the horizontal interpolation at two levels, k and k+dk
ubigd = 0.0
px(:)=0.0; py(:)=0.0
uE(:)=0.0; vE(:)=0.0;
do mm=1,Info%uidx(0,i,j)
iiu=i+Info%iu(Info%uidx(mm,i,j))
jju=j+Info%ju(Info%uidx(mm,i,j))
! Land points are treated as zero for pressure gradient
! and velocity
px(1) = px(1) + umask(iiu,jju,k )*press_grad(iiu,jju,k ,1)*udsq_r(mm)
px(2) = px(2) + umask(iiu,jju,kdk)*press_grad(iiu,jju,kdk,1)*udsq_r(mm)
py(1) = py(1) + umask(iiu,jju,k )*press_grad(iiu,jju,k ,2)*udsq_r(mm)
py(2) = py(2) + umask(iiu,jju,kdk)*press_grad(iiu,jju,kdk,2)*udsq_r(mm)
uE(1) = uE(1) + umask(iiu,jju,k )*u(iiu,jju,k ,1)*udsq_r(mm)
uE(2) = uE(2) + umask(iiu,jju,kdk)*u(iiu,jju,kdk,1)*udsq_r(mm)
vE(1) = vE(1) + umask(iiu,jju,k )*u(iiu,jju,k ,2)*udsq_r(mm)
vE(2) = vE(2) + umask(iiu,jju,kdk)*u(iiu,jju,kdk,2)*udsq_r(mm)
ubigd = ubigd + udsq_r(mm)
enddo
ubigd = 1.0/ubigd
px(1) = px(1)*ubigd
px(2) = px(2)*ubigd
py(1) = py(1)*ubigd
py(2) = py(2)*ubigd
uE(1) = uE(1)*ubigd
uE(2) = uE(2)*ubigd
vE(1) = vE(1)*ubigd
vE(2) = vE(2)*ubigd
rhoE(:) = 0.0
tbigd = 0.0
do mm=1,Info%tidx(0,i,j)
iit=i+Info%it(Info%tidx(mm,i,j))
jjt=j+Info%jt(Info%tidx(mm,i,j))
! We ignore density for land points
if (tmask(iit,jjt,k ) /= 0.0) then
rhoE(1) = rhoE(1) + model_rho(iit,jjt,k )*tdsq_r(mm)
tbigd = tbigd + tdsq_r(mm)
endif
enddo
rhoE(1) = rhoE(1)/tbigd
tbigd = 0.0
do mm=1,Info%tidx(0,i,j)
iit=i+Info%it(Info%tidx(mm,i,j))
jjt=j+Info%jt(Info%tidx(mm,i,j))
! We ignore density for land points
if (tmask(iit,jjt,kdk) /= 0.0) then
rhoE(2) = rhoE(2) + model_rho(iit,jjt,kdk)*tdsq_r(mm)
tbigd = tbigd + tdsq_r(mm)
endif
enddo
rhoE(2) = rhoE(2)/tbigd
! Vertically interpolate the horizontally interpolated values
if (special) then
! The blob is either between the top tracer point and the surface
! or the lowest wet tracer point and the bottom
dz(1) = abs(geodepth - Thickness%geodepth_zt(i,j,k))
vcoeff(1) = (dzwtT+dz(1))/dzwtT
px(0) = px(2) + ( px(1)-px(2) )*vcoeff(1)
py(0) = py(2) + ( py(1)-py(2) )*vcoeff(1)
uE(0) = uE(2) + ( uE(1)-uE(2) )*vcoeff(1)
vE(0) = vE(2) + ( vE(1)-vE(2) )*vcoeff(1)
rhoE(0) = rhoE(2) + ( rhoE(1)-rhoE(2) )*vcoeff(1)
else
! The blob lies vertically between two tracer points
dz(1) = abs(geodepth - Thickness%geodepth_zt(i,j,k ))
dz(2) = abs(geodepth - Thickness%geodepth_zt(i,j,kdk))
vcoeff(1) = dz(1)/dzwtT
vcoeff(2) = dz(2)/dzwtT
px(0) = px(1)*vcoeff(2) + px(2)*vcoeff(1)
py(0) = py(1)*vcoeff(2) + py(2)*vcoeff(1)
uE(0) = uE(1)*vcoeff(2) + uE(2)*vcoeff(1)
vE(0) = vE(1)*vcoeff(2) + vE(2)*vcoeff(1)
rhoE(0) = rhoE(1)*vcoeff(2) + rhoE(2)*vcoeff(1)
endif
! Now handle the W grid
kdk = k-1
wE(:) = 0.0
tbigd = 0.0
do mm=1,Info%tidx(0,i,j)
iit=i+Info%it(Info%tidx(mm,i,j))
jjt=j+Info%jt(Info%tidx(mm,i,j))
! Vertical velocity is treated as zero for land points
! Note, this is actually the velocity of the fluid crossing
! coordinate surfaces, NOT the true velocity. Thus, we are assuming
! that the vertical velocity of coordinate surfaces is small compared to the
! true vertical velocity.
wE(1) = wE(1) + tmask(iit,jjt,k )*w(iit,jjt,k )*tdsq_r(mm)
wE(2) = wE(2) + tmask(iit,jjt,kdk)*w(iit,jjt,kdk)*tdsq_r(mm)
tbigd = tbigd + tdsq_r(mm)
enddo
tbigd = 1.0/tbigd
wE(1) = wE(1)*tbigd
wE(2) = wE(2)*tbigd
dz(1) = Thickness%geodepth_zwt(i,j,k) - geodepth
if (kdk==0) then
dz(2) = geodepth - Ext_mode%eta_t(i,j,tau)
else
dz(2) = geodepth - Thickness%geodepth_zwt(i,j,kdk)
endif
wE(0) = (wE(1)*dz(2) + wE(2)*dz(1))/Thickness%dztT(i,j,k,tau)
m=0
trystep: do while (.not. accept_step)
prev => NULL()
next => NULL()
! Load the old variables into some local variables that we will change.
! We want to keep the old variables in case the step is rejected.
i = old_ijk(1)
j = old_ijk(2)
k = old_ijk(3)
h(:) = old_h(:)
lon = old_lld(1)
lat = old_lld(2)
! Horizontal distances are calculated relative to the inital
! position for this partial step. Vertical distance is calculated
! relative to the initial geodepth of the step
Xn(1) = 0. ! x-position
Xn(2) = vel(1) ! u-velocity
Xn(3) = 0. ! y-position
Xn(4) = vel(2) ! v-velocity
Xn(5) = -old_lld(3) ! z-position (relative to z=0)
Xn(6) = vel(3) ! w-velocity
! Temporary variables for the RK scheme
Xnp1(:) = Xn(:)
Xnp1_hat(:) = Xn(:)
update(:) = Xn(:)
! Temporary variables for the entrainment/detrainment history
entrainment(:) = 0.
detrainment(:) = 0.
! rotation
f = two_omega*sin(deg_to_rad*lat)
fs = two_omega*cos(deg_to_rad*lat)
! Cycle through the RK sub-steps
call mpp_clock_begin(id_clock_rk)
do s=0,ns
! dx/dt and d2x/dt2
V(1,s) = update(2)
V(2,s) = - this%drag*update(2) + f*update(4) - fs*update(6) - px(0)*rhor + this%drag*uE(0)
! dy/dt and d2y/dt2
V(3,s) = update(4)
V(4,s) = - f*update(2) - this%drag*update(4) - py(0)*rhor + this%drag*vE(0)
! dz/dt and d2z/dt2
V(5,s) = update(6)
V(6,s) = fs*update(2) - this%drag*update(6) - grav*rhor*(rhoL - rhoE(0)) + this%drag*wE(0)
! calculate new update
if(s<ns) then
update(:) = Xn(:)
do r=0,s
update(:) = update(:) + tstep*beta(s+1,r)*V(:,r)
enddo
endif
! The high and low order estimates
Xnp1(:) = Xnp1(:) + tstep*hgamma(s)*V(:,s)
Xnp1_hat(:) = Xnp1_hat(:) + tstep*lgamma(s)*V(:,s)
enddo !s
call mpp_clock_end(id_clock_rk)
! Estimate the error using the difference in the high and low order schemes.
! We only use the position (not velocity) in the error estimate.
ii = maxloc(abs((Xnp1(:) - Xnp1_hat(:))/(Xnp1(:)+epsln)),1)
trunc = abs(Xnp1(ii) - Xnp1_hat(ii) + epsln)
tstar = rel_error*abs(Xnp1(ii))
hstar = tstep * (safety_factor*tstar/trunc)**(orderp1_r)
! Save the tstep so that we can update blob_time
old_tstep = tstep
! Reject the step if the accuracy condition is not met. Redo the
! trystep loop with an adjusted step.
! There are some caveats, listed below.
if(trunc > tstar) then
accept_step = .false.
if (hstar > minstep) then
!If the suggested step is not smaller than the minimum step,
!retry with the smaller step.
tstep = min(hstar, dtime - blob_time)
else
if (tstep<=minstep) then
!If the step is smaller than the minimum step and
!it is still rejected, we accept the step anyway.
accept_step = .true.
else
! Otherwise, set the step to the minimum step size.
accept_step = .false.
tstep = min(minstep, dtime - blob_time)
endif
endif
else !Accept the step
accept_step = .true.
! We want to impose some restrictions on the local extrapolation to ensure
! we maintain stability and minimise the number of rejected steps:
! 1/ only let the next step increase in size if the previous step was
! never rejected,
! 2/ we don't let the next step be any larger than twice this step.
if (m==0 .and. hstar>=tstep) then
tstep = min(2*tstep, hstar)
elseif (hstar<tstep) then
tstep = max(minstep, hstar)
endif
! 3/ We do not want tstep to be greater than dtime (the E system time step)
tstep = min(tstep, dtime)
! There may be more adjustments to tstep later on, depending on
! how close we are to reaching the Eulerian time step.
endif
if (accept_step) then
! Do some rudimentary stability checking
if (abs(Xnp1(2))>large_speed .or. abs(Xnp1(4))>large_speed .or. abs(Xnp1(6))>large_speed) then
if (tstep<=minstep) then
call mpp_error(WARNING,&
'==>Warning in ocean_blob_dynamic_free_mod (dynamic_update): It looks like a blob is becoming unstable'//&
' and the timestep is already as small as is permitted. Suggest reducing minstep in the namelist.')
endif
endif
! Update the grid stretching values
tbigd = 0.0
h(:) = 0.0
do mm=1,Info%tidx(0,i,j)
iit=i+Info%it(Info%tidx(mm,i,j))
jjt=j+Info%jt(Info%tidx(mm,i,j))
! Stretching function is defined over land points, so, we do
! not mask out land points.
h(:) = h(:) + Info%ht(iit,jjt,:)*tdsq_r(mm)
tbigd = tbigd + tdsq_r(mm)
enddo
h(:) = h(:)/tbigd
n_frac_steps = n_frac_steps+1
! Entrainment and detrainment calculations are based on the properties of the blob
! at the beginning of this blob step.
! Calculate the detrainment
if (vert_coordinate_class==DEPTH_BASED) then
!det_factor = Gamma * (rho0*36pi)**1/3
dmdt_det = -det_factor * (mass**twothirds) / abs(rhoL - rhoE(0) + epsln)
else !PRESSURE_BASED
!det_factor = Gamma * (36pi)**1/3
dmdt_det = -det_factor * (mass**twothirds) * (rho**onethird) / abs(rhoL - rhoE(0) + epsln)
endif
! Make sure we do not exceed the maximum detrainment
dmdt_det = sign(min(abs(dmdt_det),abs(max_detrainment)),dmdt_det)
! Entrainment
dmdt_ent = 0.0
detrainment(0) = dmdt_det*old_tstep
entrainment(0) = dmdt_ent*old_tstep
do n=1,num_prog_tracers
! Detrainment
detrainment(n) = detrainment(0)*field(n)
! Entrainment
entrainment(n) = entrainment(0)*T_prog(n)%field(i,j,k,tau)
enddo
! Check and see if the blob will detrain to zero mass during this step.
! If it does, just dump all its properties in the original cell.
if ((entrainment(0)+detrainment(0)+mass) < small_mass) then
entrainment(0) = 0.0
detrainment(0) = -mass
do n=1,num_prog_tracers
entrainment(n) = 0.0
detrainment(n) = -tracer(n)
enddo
! Update some counters
detrn_zero = detrn_zero + 1
! If a blob detrains to less than small mass, we no longer
! need to calculate its trajectory. So that it stops being
! processed, we set the time to the end of full step.
old_tstep = 0.0
blob_time = dtime
else
! Check if we have changed horizontal cells
call check_ijcell(Xnp1(1),Xnp1(3),i,j,h,old_lld(1:2),lon,lat,off(1:2))
endif
! Check to see if the blob has grounded on a land column
if (Grd%kmt(i,j)==0) then
! If the blob has grounded, we put it back in its previous cell
! It will have all its properties returned to the E system later
! Here, grounded means a blob has moved laterally into a zero
! depth (i.e. land) column, NOT that it has interacted with topography.
off(1:2) = .false.
grounded = .true.
ngrounded = ngrounded + 1
i = old_ijk(1)
j = old_ijk(2)
lon = old_lld(1)
lat = old_lld(2)
endif
if (any(off(1:2))) change_pe = .true.
! Check if we have changed vertical cells and whether we have interacted with
! the lower or upper boundary
if (.not. grounded) then
call check_kcell(Time, Ext_mode, Thickness,-Xnp1(5),Xnp1(6),i,j,k,off(3))
endif
if(change_pe .and. .not. bitwise_reproduction) then
! Check to see if the blob has left this pe
! If we are not enforcing bitwise reproduction, we pack
! the blob into a buffer immediately, as we do not need
! to worry about saving the histories and processing the
! blob histories in order.
Ext_mode%conv_blob(old_ijk(1),old_ijk(2)) = &
Ext_mode%conv_blob(old_ijk(1),old_ijk(2)) - mass
L_system%conv_blob(old_ijk(1),old_ijk(2),old_ijk(3)) = &
L_system%conv_blob(old_ijk(1),old_ijk(2),old_ijk(3)) - mass
mass_out(old_ijk(1),old_ijk(2),old_ijk(3)) = &
mass_out(old_ijk(1),old_ijk(2),old_ijk(3)) + mass
! Save some variables
do n=1,num_prog_tracers
this%tracer(n) = tracer(n)
enddo
this%v(1) = Xnp1(2)
this%v(2) = Xnp1(4)
this%v(3) = Xnp1(6)
this%lon = lon
this%lat = lat
this%geodepth = -Xnp1(5)
this%blob_time = blob_time + old_tstep
if (this%blob_time == dtime) then
this%step = max(tstep, minstep)
elseif ((this%blob_time + 1.1*tstep) > dtime) then
this%step = dtime - this%blob_time
else
this%step = max(tstep,minstep)
endif
this%mass = mass
this%i = i
this%j = j
this%k = k
! If the blob interacts with topography in the new cell, we need to put it in the bottom
! blob list. Later, it will be packed into a buffer and sent to a neighbouring PE.
if (off(3) .and. k==Grd%kmt(i,j)) then
this%age = this%age+dtime_yr
call unlink_blob(this, head, prev, next)
call insert_blob(this, bottom_head)
tfer_bottom = tfer_bottom + 1
this%nfrac_steps = n_frac_steps
else
if (i>iec .and. j>jec) then
call packbuffer(this, NEbuffer_out, entrainment(:), detrainment(:))
elseif (i<isc .and. j>jec) then
call packbuffer(this, NWbuffer_out, entrainment(:), detrainment(:))
elseif (i>iec .and. j<jsc) then
call packbuffer(this, SEbuffer_out, entrainment(:), detrainment(:))
elseif (i<isc .and. j<jsc) then
call packbuffer(this, SWbuffer_out, entrainment(:), detrainment(:))
elseif (i>iec) then
call packbuffer(this, Ebuffer_out, entrainment(:), detrainment(:))
elseif (i<isc) then
call packbuffer(this, Wbuffer_out, entrainment(:), detrainment(:))
elseif (j>jec) then
call packbuffer(this, Nbuffer_out, entrainment(:), detrainment(:))
elseif (j<jsc) then
call packbuffer(this, Sbuffer_out, entrainment(:), detrainment(:))
endif
call unlink_blob(this, head, prev, next)
call free_blob_memory(this)
endif
move_lateral = move_lateral + 1
leaving_pe = leaving_pe + 1
advance_blob=.false.
exit partialstep
endif!change_pe .and. .not. bitwise_reproduction
! A little about the following order of operations:
! Detrained mass and tracer is "given" to the cell that the blob is
! entering (i.e. the cell that the blob resides in at the end of
! a sub-cycle). The mass used for calculating convergence/divergence
! must therefore be the mass of the blob before detrainment occurs.
if (bitwise_reproduction) then
! If we detect that a blob changes cells, save the mass into the new
! water column and and out of the old water column.
! Note, the convention is that both are positive and we take care of
! the sign when calculating the convergence.
if (old_ijk(1)/=i .or. old_ijk(2)/=j .or. old_ijk(3)/=k) then
this%mass_out(n_frac_steps-1) = mass
this%mass_in( n_frac_steps ) = mass
endif
! Save the indices to history too (for divergence and ent/detrainment)
this%di(n_frac_steps) = i
this%dj(n_frac_steps) = j
this%dk(n_frac_steps) = k
! save mass
mass = mass + entrainment(0) + detrainment(0)
this%entrainment(n_frac_steps,0) = entrainment(0)
this%detrainment(n_frac_steps,0) = detrainment(0)
! save tracer
do n=1,num_prog_tracers
tracer(n) = tracer(n) + entrainment(n) + detrainment(n)
this%entrainment(n_frac_steps,n) = entrainment(n)
this%detrainment(n_frac_steps,n) = detrainment(n)
enddo
else!not bitwise_reproduction
! If we detect that a blob changes cells, save the mass into the new
! water column in to and out of the old water column.
! save mass
if (old_ijk(1)/=i .or. old_ijk(2)/=j .or. old_ijk(3)/=k) then
Ext_mode%conv_blob(old_ijk(1),old_ijk(2)) = &
Ext_mode%conv_blob(old_ijk(1),old_ijk(2)) - mass
Ext_mode%conv_blob(i,j) = &
Ext_mode%conv_blob(i,j) + mass
L_system%conv_blob(old_ijk(1),old_ijk(2),old_ijk(3)) = &
L_system%conv_blob(old_ijk(1),old_ijk(2),old_ijk(3)) - mass
L_system%conv_blob(i,j,k) = &
L_system%conv_blob(i,j,k) + mass
mass_out(old_ijk(1),old_ijk(2),old_ijk(3)) = mass_out(old_ijk(1),old_ijk(2),old_ijk(3)) + mass
mass_in( i, j, k) = mass_in( i, j, k) + mass
endif
mass = mass + entrainment(0) + detrainment(0)
blob_source(i,j) = blob_source(i,j) - entrainment(0) - detrainment(0)
! save tracer
do n=1,num_prog_tracers
tracer(n) = tracer(n) + entrainment(n) + detrainment(n)
tend_blob(n,i,j,k) = tend_blob(n,i,j,k) - entrainment(n) - detrainment(n)
enddo
do n=0,num_prog_tracers
EL_diag(n)%detrainment(i,j,k) = EL_diag(n)%detrainment(i,j,k) - detrainment(n)
EL_diag(n)%entrainment(i,j,k) = EL_diag(n)%entrainment(i,j,k) + entrainment(n)
enddo
endif!bitwise_reproduction
! save other variables
geodepth = -Xnp1(5)
old_lld = (/lon, lat, geodepth/)
old_ijk = (/i, j, k /)
old_h = h
vel(1) = Xnp1(2)
vel(2) = Xnp1(4)
vel(3) = Xnp1(6)
!Avoid crazy numbers if the blob has detrained to be less than small mass
if(mass>small_mass) then
do n=1,num_prog_tracers
field(n) = tracer(n)/mass
enddo
rhoL = density(field(index_salt), field(index_temp), Dens%pressure_at_depth(i,j,k))
rhoLr = 1./rhoL
if (vert_coordinate_class == PRESSURE_BASED) then
rho = rhoL
rhor = rhoLr
!else DEPTH_BASED; rho=rho0; rhor=rho0r
endif
endif
volume = mass*rhor
!Now we handle the blobs that have penetrated the surface or bottom boundaries
if (off(3) .or. grounded) then
! Update a counter
if (this%i /= i .or. this%j /= j) move_lateral = move_lateral + 1
if (.not. grounded .and. k==1) nsfc = nsfc+1
! Update the blob variables
this%step = max(tstep, minstep)
this%i = i
this%j = j
this%k = k
this%lon = lon
this%lat = lat
this%geodepth = geodepth
this%v(:) = vel(:)
this%h1 = h(1)
this%h2 = h(2)
this%mass = mass
this%volume = volume
this%density = rhoL
this%densityr = rhoLr
this%gprime = grav*(rhoE(0)-rhoL)/rhoE(0) !diagnostic
this%age = this%age + dtime_yr
do n=1,num_prog_tracers
if(T_prog(n)%name(1:3) =='age') then
! If it is an age tracer advance the age of the tracer
this%field(n) = field(n) + dtime_yr
this%tracer(n) = this%field(n)*mass
else
this%tracer(n) = tracer(n)
this%field(n) = field(n)
endif
enddo
this%model_steps = this%model_steps + 1
if (k>=Grd%kmt(i,j) .and. .not. grounded) then !the blob has penetrated the bottom boundary
! The geodepth and velocity will be adjusted in transfer_free_to_bottom
call unlink_blob(this, head, prev, next)
call insert_blob(this, bottom_head)
advance_blob=.false.
tfer_bottom = tfer_bottom + 1
this%nfrac_steps = n_frac_steps
exit partialstep
else !the blob has penetrated the free surface, or, the blob has grounded
n_frac_steps = n_frac_steps+1
! Diagnostics
EL_diag(0)%dstry(i,j,k) = EL_diag(0)%dstry(i,j,k) + mass
do n=1,num_prog_tracers
EL_diag(n)%dstry(i,j,k) = EL_diag(n)%dstry(i,j,k) + tracer(n)
enddo
if (bitwise_reproduction) then
this%nfrac_steps = n_frac_steps
this%di(n_frac_steps) = this%i
this%dj(n_frac_steps) = this%j
this%dk(n_frac_steps) = this%k
this%dmass = -mass
this%mass = 0.0
mass = 0.0
do n=1,num_prog_tracers
this%dtracer(n) = -tracer(n)
this%tracer(n) = 0.0
tracer(n) = 0.0
enddo
! If a blob changes PEs and it interacts with the surface boundary
! we still need it to be packed into a buffer and sent to
! the neighbouring PE for the history. So, we fool the
! algorithm into thinking that the blob has completed its
! full time step so that it will get packed into a buffer if necessary.
! We do not need to do this procedure for the blob interacting with
! the bottom boundary, because it is handled separately in its own
! linked list.
old_tstep = 0.0
blob_time = dtime
exit trystep
else!not bitwise_reproduction
this%nfrac_steps = n_frac_steps
blob_source(this%i,this%j) = blob_source(this%i,this%j) + mass
this%mass = 0.0
mass = 0.0
do n=1,num_prog_tracers
tend_blob(n,this%i,this%j,this%k) = tend_blob(n,this%i,this%j,this%k) + tracer(n)
this%tracer(n) = 0.0
tracer(n) = 0.0
enddo
! Diagnostics
EL_diag(0)%dstry(i,j,k) = EL_diag(0)%dstry(i,j,k) + mass
do n=1,num_prog_tracers
EL_diag(n)%dstry(i,j,k) = EL_diag(n)%dstry(i,j,k) + tracer(n)
enddo
! For bitwise_reproduction=.false. we do not need to worry about
! histories being stored in buffers, so, we just exit partialstep
!exit partialstep
old_tstep = 0.0
blob_time = dtime
exit trystep
endif!bitwise_reproduction
endif!k==kmt and not grounded
endif!off(3) or grounded
this%nfrac_steps = n_frac_steps
endif !accept_step
m=m+1
enddo trystep
! The step has been accepted. We now decide whether we need
! to conduct any more steps, and if we do, whether we need to
! adjust tstep to ensure the final step coincides with the Eulerian
! model time step.
blob_time = blob_time + old_tstep
this%blob_time = blob_time
if (blob_time == dtime) then
! no more steps required. Save all the new variables to the blob
reached_end = .true.
! Update a counter
if (this%i /= i .or. this%j /= j) move_lateral = move_lateral + 1
! Update the blob variables
this%step = max(tstep,minstep)
this%i = i
this%j = j
this%k = k
this%lon = lon
this%lat = lat
this%geodepth = geodepth
this%v(:) = vel(:)
this%h1 = h(1)
this%h2 = h(2)
this%mass = mass
this%volume = volume
this%density = rhoL
this%densityr = rhoLr
this%gprime = grav*(rhoE(0)-rhoL)/rhoE(0) !diagnostic
this%age = this%age + dtime_yr
do n=1,num_prog_tracers
if(T_prog(n)%name(1:3) =='age') then
! If it is an age tracer advance the age of the tracer
this%field(n) = field(n) + dtime_yr
this%tracer(n) = this%field(n)*mass
else
this%tracer(n) = tracer(n)
this%field(n) = field(n)
endif
enddo
this%model_steps = this%model_steps + 1
if (bitwise_reproduction) then
! check to see if the blob has left this pe
! NOTE: we assume the blob does not go beyond the halo, so, we
! don't pack them into buffers until the end of the time step
! We do this to maintain bitwise reproduction. If we are not
! maintaining bitwise reproduction, we pack a blob into a buffer
! as soon as a change in pe is detected.
!
! We also consider what happens when a blob traverses three
! PE's in a time step. e.g.
! ------------------
! | | |
! | PE=2 +a PE=3 |
! | /| |
! | b | |
! ------+-----------
! | / | |
! | c | |
! | | |
! | PE=0 | PE=1 |
! ------------------
! Maintaining bitwise reproducability requires that each
! PE knows about the history of the blob. In the instance
! depicted above, the blobs history must be processed on PE
! 3,2 and 0. We achieve this by keeping the history on
! 3, and sending the history to 2 and 0. When unpacking
! the buffer, the unpacking subroutine checks if the blob
! is on that PE. If it is not, it will set the blob%mass
! and blob%tracer(n) to zero.
if(change_pe) then
go_ne = .false.
go_nw = .false.
go_sw = .false.
go_se = .false.
go_e = .false.
go_n = .false.
go_w = .false.
go_s = .false.
do s=0,this%nfrac_steps
! If we are on a cyclic grid, and, there is only one
! processor in the cyclic direction, we want to avoid
! having the blob sent and received to the same list.
! (which means it can appear twice in the list).
! This can cause non-conservation.
call check_cyclic(this, this%di(s), this%dj(s), .false.)
if (iec<this%di(s) .and. jec<this%dj(s)) then
go_ne = .true.
elseif (this%di(s)<isc .and. jec<this%dj(s)) then
go_nw = .true.
elseif (this%di(s)<isc .and. this%dj(s)<jsc) then
go_sw = .true.
elseif (iec<this%di(s) .and. this%dj(s)<jsc) then
go_se = .true.
elseif (iec<this%di(s)) then
go_e = .true.
elseif (jec<this%dj(s)) then
go_n = .true.
elseif (this%di(s)<isc) then
go_w = .true.
elseif (this%dj(s)<jsc) then
go_s = .true.
endif
enddo
if (go_ne) call packbuffer(this, NEbuffer_out)
if (go_nw) call packbuffer(this, NWbuffer_out)
if (go_se) call packbuffer(this, SEbuffer_out)
if (go_sw) call packbuffer(this, SWbuffer_out)
if (go_e ) call packbuffer(this, Ebuffer_out)
if (go_w ) call packbuffer(this, Wbuffer_out)
if (go_n ) call packbuffer(this, Nbuffer_out)
if (go_s ) call packbuffer(this, Sbuffer_out)
if (.not. any((/go_ne, go_nw, go_se, go_sw, go_e, go_w, go_n, go_s/))) then
call check_cyclic(this, this%i, this%j, .true.)
i=this%i; j=this%j
endif
! We leave the blobs history in the linked list on this processor
! but, we remove its properties. It will be deleted next call
! to blob_delete, but, we need its history to be processed
! before it is deleted. The history is processed only after
! all blobs have been stepped.
! A blob may go from one PE and then back to the same PE within an
! E system time step, e.g.
! ------------------
! | PE=2 +a PE=3 |
! | /| |
! | b | |
! | \| |
! | +c |
! ------+-----------
! | | |
! | | |
! | | |
! | | |
! | PE=0 | PE=1 |
! ------------------
! So, we only set its properties to zero if it is no longer on this PE.
if (i<isc .or. iec<i .or. j<jsc .or. jec<j) then
this%mass=0.
do n=1,num_prog_tracers
this%tracer(n)=0.
enddo
endif
leaving_pe = leaving_pe + 1
endif
endif !bitwise_reproduction
elseif( (blob_time + 1.1*tstep) > dtime ) then
! If we are within 10% of dtime with the suggested tstep, then,
! we extend the step slightly to save having to take a really
! small step next time. We ensure that the step size is chosen
! so that blob_time coincides with the model step after the next blob step.
reached_end = .false.
tstep = dtime - blob_time
! Update the interpolation coefficients to reflect the new position
call interp_tcoeff(i,j,h(:),lon,lat,tdsq_r(:))
call interp_ucoeff(i,j,h(:),lon,lat,udsq_r(:))
else
! More step(s) required. No need to adjust the step size.
reached_end = .false.
! Update the interpolation coefficients to reflect the new position
call interp_tcoeff(i,j,h(:),lon,lat,tdsq_r(:))
call interp_ucoeff(i,j,h(:),lon,lat,udsq_r(:))
endif !blobtime==dtime
enddo partialstep
call mpp_clock_end(id_clock_part_cycle)
total_blobs = total_blobs + 1
if (advance_blob) then
this=>this%next
else
this=>next
endif
if (.not. associated(this)) exit blob_cycle
end do blob_cycle
endif !blob associated?
ngrnd = ngrnd + ngrounded
ndetrn = ndetrn + detrn_zero
if (debug_this_module .and. bitwise_reproduction) then
stdoutunit = stdout()
write (stdoutunit, '(/,a)') 'Dynamic Free Blob Statistics'
call write_timestamp(Time%model_time)
call mpp_sum(total_blobs)
write (stdoutunit, *) 'Total Free Dynamic Blobs =', total_blobs
call mpp_sum(leaving_pe)
write (stdoutunit, *) 'Free Dynamic Blobs Changing PEs =', leaving_pe
call mpp_sum(tfer_bottom)
write (stdoutunit, *) 'Free Dynamic Blob Transfer to bottom =', tfer_bottom
call mpp_sum(detrn_zero)
write (stdoutunit, *) 'Free Blobs detrained to zero mass =', detrn_zero
call mpp_sum(move_lateral)
write (stdoutunit, *) 'Free Blobs changing water columns =', move_lateral
call mpp_sum(ngrounded)
write (stdoutunit, *) 'Grounded Free Blobs =', ngrounded
endif
end subroutine dynamic_update
! </SUBROUTINE> NAME="dynamic_upate"
!######################################################################
! <SUBROUTINE NAME="transfer_bottom_to_free">
!
! <DESCRIPTION>
! Takes bottom blobs that have separated from the bottom boundary and
! turns it into a free blob.
! </DESCRIPTION>
!
subroutine transfer_bottom_to_free(Time, Thickness, T_prog, Dens, &
new_free, head, use_bottom, &
EL_diag)
type(ocean_time_type), intent(in) :: Time
type(ocean_thickness_type), intent(inout) :: Thickness
type(ocean_prog_tracer_type), intent(inout) :: T_prog(:)
type(ocean_density_type), intent(in) :: Dens
type(ocean_blob_type), pointer :: new_free
type(ocean_blob_type), pointer :: head
logical, intent(in) :: use_bottom
type(blob_diag_type), dimension(0:num_prog_tracers) :: EL_diag
type(ocean_blob_type), pointer :: this, next, prev
integer :: i,j,k,tau,nblobs,n
real, parameter :: small=1e-3
integer :: stdoutunit
tau = Time%tau
nblobs = 0
if (associated(new_free)) then
this => new_free
if (use_this_module) then
blobcycle: do
i = this%i
j = this%j
k = this%k
! Ensure that the blob is above the Eulerian topography
! so that the free blob module does not think that we have
! penetrated rock.
if (vert_coordinate_class==DEPTH_BASED) then
this%st = -Thickness%depth_swt(i,j,k) + small
this%geodepth = Thickness%geodepth_zwt(i,j,k) - small*Thickness%dzt_dst(i,j,k)
else!PRESSURE_BASED
this%st = Thickness%depth_swt(i,j,k) - small
this%geodepth = Thickness%geodepth_zwt(i,j,k) + small*Thickness%dzt_dst(i,j,k)
endif
! The drag coefficient
this%drag = rayleigh_drag_bot
! Enforce a positive or zero velocity on the blob, so that any downward inertia
! wont cause it to penetrate rock again straight away.
if (this%v(3)<0) this%v(3)=0.
! Update some of the blob variables
this%density = density(this%field(index_salt), &
this%field(index_temp), &
Dens%pressure_at_depth(i,j,k))
this%densityr = 1./this%density
if (vert_coordinate_class == DEPTH_BASED) then
this%volume = this%mass * rho0r
else
this%volume = this%mass * this%densityr
endif
call unlink_blob(this, new_free, prev, next)
call insert_blob(this, head)
call reallocate_interaction_memory(this,head,total_ns)
this=>next
nblobs = nblobs+1
if(.not.associated(this)) exit blobcycle
enddo blobcycle
else !not use_this_module
! If we are not using dynamic free blobs, return the
! transferred blbos properties to the E system.
blobcycle2: do
i = this%i
j = this%j
k = this%k
! Diagnostics
EL_diag(0)%dstry(i,j,k) = EL_diag(0)%dstry(i,j,k) + this%mass
do n=1,num_prog_tracers
EL_diag(n)%dstry(i,j,k) = EL_diag(n)%dstry(i,j,k) + this%tracer(n)
enddo
call kill_blob(Thickness, T_prog(:), this, i, j, k)
this=>this%next
nblobs=nblobs+1
if(.not.associated(this)) exit blobcycle2
enddo blobcycle2
endif !use_this_module
call blob_delete(Time, Thickness, T_prog(:), new_free)
endif!associated(new_free)
call mpp_sum(nblobs)
if (id_bot_to_free>0) used = send_data(id_bot_to_free, real(nblobs), Time%model_time)
if(debug_this_module .and. use_bottom) then
stdoutunit = stdout()
write(stdoutunit, '(/,a)') 'Bottom blobs separating from topograhy'
write(stdoutunit, *) 'Bottom blobs transferred to free blobs = ', nblobs
endif
end subroutine transfer_bottom_to_free
! </SUBROUTINE> NAME="transfer_bottom_to_free"
!######################################################################
! <SUBROUTINE NAME="blob_dynamic_free_end">
!
! <DESCRIPTION>
! Clears memory to give a nice clean ending to the run.
! </DESCRIPTION>
!
subroutine blob_dynamic_free_end()
if (.not. use_this_module) return
call deallocate_buffer(Ebuffer_out); call deallocate_buffer(Ebuffer_in)
call deallocate_buffer(Wbuffer_out); call deallocate_buffer(Wbuffer_in)
call deallocate_buffer(Nbuffer_out); call deallocate_buffer(Nbuffer_in)
call deallocate_buffer(Sbuffer_out); call deallocate_buffer(Sbuffer_in)
call deallocate_buffer(NEbuffer_out); call deallocate_buffer(NEbuffer_in)
call deallocate_buffer(NWbuffer_out); call deallocate_buffer(NWbuffer_in)
call deallocate_buffer(SEbuffer_out); call deallocate_buffer(SEbuffer_in)
call deallocate_buffer(SWbuffer_out); call deallocate_buffer(SWbuffer_in)
nullify(Dom)
nullify(Grd)
nullify(Info)
nullify(Bdom)
contains
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! This is a nested subroutine that deallocates memory from a buffer !
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine deallocate_buffer(buffer)
type(blob_buffer_type), pointer :: buffer
if (buffer%pe /= NULL_PE) deallocate(buffer)
end subroutine deallocate_buffer
end subroutine blob_dynamic_free_end
! </SUBROUTINE> NAME="blob_dynamic_free_end"
!######################################################################
! <SUBROUTINE NAME="packbuffer">
!
! <DESCRIPTION>
! Packs a buffer with all the information needed to send a blob from
! one PE to another.
! </DESCRIPTION>
!
subroutine packbuffer(blob,buffer,entrainment,detrainment)
type(ocean_blob_type), pointer :: blob
type(blob_buffer_type), pointer :: buffer
real, optional, intent(in) :: entrainment(0:)
real, optional, intent(in) :: detrainment(0:)
integer :: n, nb, s, npt
integer :: stdoutunit
stdoutunit = stdout()
if (buffer%pe == NULL_PE) then
write (stdoutunit, '(a)'), 'Error: Trying to send blob to a NULL_PE'
call mpp_error(FATAL, &
'==>Error in ocean_blob_static_bottom_mod (packbuffer): '&
//'Trying to send blob to a NULL_PE')
endif
buffer%numblobs = buffer%numblobs+1
if (buffer%numblobs>buffer%size) call increase_buffer(buffer,buffer%numblobs)
npt = num_prog_tracers
nb = buffer%numblobs
! Fill the real buffer
do n=1,num_prog_tracers
buffer%real_buff(2*n-1,nb) = blob%tracer(n)
buffer%real_buff(2*n ,nb) = blob%dtracer(n)
enddo
buffer%real_buff(2*npt+1 ,nb) = blob%v(1)
buffer%real_buff(2*npt+2 ,nb) = blob%v(2)
buffer%real_buff(2*npt+3 ,nb) = blob%v(3)
buffer%real_buff(2*npt+4 ,nb) = blob%lon
buffer%real_buff(2*npt+5 ,nb) = blob%lat
buffer%real_buff(2*npt+6 ,nb) = blob%geodepth
buffer%real_buff(2*npt+7 ,nb) = blob%step
buffer%real_buff(2*npt+8 ,nb) = blob%mass
buffer%real_buff(2*npt+9 ,nb) = blob%blob_time
buffer%real_buff(2*npt+10,nb) = blob%h1
buffer%real_buff(2*npt+11,nb) = blob%h2
buffer%real_buff(2*npt+12,nb) = blob%drag
buffer%real_buff(2*npt+13,nb) = blob%dmass
buffer%real_buff(2*npt+14,nb) = blob%gprime
buffer%real_buff(2*npt+15,nb) = blob%age
! Fill the integer buffer
buffer%integer_buff(1,nb) = blob%i
buffer%integer_buff(2,nb) = blob%j
buffer%integer_buff(3,nb) = blob%k
buffer%integer_buff(4,nb) = blob%model_steps
buffer%integer_buff(5,nb) = blob%hash
buffer%integer_buff(6,nb) = blob%number
buffer%integer_buff(7,nb) = blob%nfrac_steps
buffer%integer_buff(8,nb) = blob%nsteps
if (bitwise_reproduction) then
! History buffers
buffer%history_integer_buff(1,0,nb) = blob%di(0)
buffer%history_integer_buff(2,0,nb) = blob%dj(0)
buffer%history_integer_buff(3,0,nb) = blob%dk(0)
buffer%history_real_buff(npt+3,0,nb) = blob%mass_out(0)
if (blob%nfrac_steps>0) then
do s=1,blob%nfrac_steps
! Integer buffer
buffer%history_integer_buff(1,s,nb) = blob%di(s)
buffer%history_integer_buff(2,s,nb) = blob%dj(s)
buffer%history_integer_buff(3,s,nb) = blob%dk(s)
! Real buffer
do n=0,num_prog_tracers
buffer%history_real_buff(2*n ,s,nb) = blob%entrainment(s,n)
buffer%history_real_buff(2*n+1,s,nb) = blob%detrainment(s,n)
enddo
buffer%history_real_buff(npt+2,s,nb) = blob%mass_in(s)
buffer%history_real_buff(npt+3,s,nb) = blob%mass_out(s)
enddo
endif
else
do n=0,num_prog_tracers
buffer%history_real_buff(2*n ,1,nb) = entrainment(n)
buffer%history_real_buff(2*n+1,1,nb) = detrainment(n)
enddo
endif
end subroutine packbuffer
! </SUBROUTINE> NAME="packbuffer"
!######################################################################
! <SUBROUTINE NAME="unpackbuffer">
!
! <DESCRIPTION>
! Unpacks a received buffer.
! </DESCRIPTION>
!
subroutine unpackbuffer(Time, buffer, head, Dens, Ext_mode, L_system, &
blob_source, tend_blob, mass_in, EL_diag)
type(ocean_time_type), intent(in) :: Time
type(blob_buffer_type), pointer :: buffer
type(ocean_blob_type), pointer :: head
type(ocean_density_type), intent(in) :: Dens
type(ocean_external_mode_type), optional, intent(inout) :: Ext_mode
type(ocean_lagrangian_type), optional, intent(inout) :: L_system
type(blob_diag_type), optional, intent(inout) :: EL_diag(0:)
real, optional, dimension(num_prog_tracers,isd:ied,jsd:jed,nk), intent(inout) :: tend_blob
real, optional, dimension(isd:ied,jsd:jed), intent(inout) :: blob_source
real, optional, dimension(isd:ied,jsd:jed,1:nk), intent(inout) :: mass_in
type(ocean_blob_type), pointer :: blob
real, dimension(0:num_prog_tracers) :: entrainment, detrainment
integer :: n, nb, s, npt
integer :: i,j,k,tau
tau = Time%tau
if (buffer%pe /= NULL_PE .and. buffer%numblobs>0) then
npt = num_prog_tracers
do nb=1,buffer%numblobs
allocate(blob)
allocate(blob%tracer(num_prog_tracers))
allocate(blob%field(num_prog_tracers))
call allocate_interaction_memory(blob, total_ns)
! unpack the real buffer
do n=1,num_prog_tracers
blob%tracer(n) = buffer%real_buff(2*n-1,nb)
blob%dtracer(n) = buffer%real_buff(2*n ,nb)
enddo
blob%v(1) = buffer%real_buff(2*npt+ 1,nb)
blob%v(2) = buffer%real_buff(2*npt+ 2,nb)
blob%v(3) = buffer%real_buff(2*npt+ 3,nb)
blob%lon = buffer%real_buff(2*npt+ 4,nb)
blob%lat = buffer%real_buff(2*npt+ 5,nb)
blob%geodepth = buffer%real_buff(2*npt+ 6,nb)
blob%step = buffer%real_buff(2*npt+ 7,nb)
blob%mass = buffer%real_buff(2*npt+ 8,nb)
blob%blob_time= buffer%real_buff(2*npt+ 9,nb)
blob%h1 = buffer%real_buff(2*npt+10,nb)
blob%h2 = buffer%real_buff(2*npt+11,nb)
blob%drag = buffer%real_buff(2*npt+12,nb)
blob%dmass = buffer%real_buff(2*npt+13,nb)
blob%gprime = buffer%real_buff(2*npt+14,nb)
blob%age = buffer%real_buff(2*npt+15,nb)
! unpack the integer buffer
blob%i = buffer%integer_buff(1,nb)
blob%j = buffer%integer_buff(2,nb)
blob%k = buffer%integer_buff(3,nb)
blob%model_steps = buffer%integer_buff(4,nb)
blob%hash = buffer%integer_buff(5,nb)
blob%number = buffer%integer_buff(6,nb)
blob%nfrac_steps = buffer%integer_buff(7,nb)
blob%nsteps = buffer%integer_buff(8,nb)
call check_cyclic(blob, blob%i, blob%j, .true.)
i=blob%i; j=blob%j; k=blob%k
! If a blob has zero mass, we are only interested in its history arrays
! So, we don't need to bother with finding tracer concentration, density,
! or volume.
if (isc <= i .and. i<=iec .and. jsc<=j .and. j<=jec .and. blob%mass>0) then
! Derived variables
do n=1,num_prog_tracers
blob%field(n) = blob%tracer(n)/blob%mass
enddo
blob%density = density(blob%field(index_salt), &
blob%field(index_temp), &
Dens%pressure_at_depth(i,j,k))
blob%densityr = 1./blob%density
if (vert_coordinate_class == DEPTH_BASED) then
blob%volume = blob%mass * rho0r
else
blob%volume = blob%mass * blob%densityr
endif
else
blob%mass = 0.0
blob%tracer(:) = 0.0
endif
if (bitwise_reproduction) then
! History buffers
blob%di(:) = -1
blob%dj(:) = -1
blob%dk(:) = -1
blob%entrainment(:,:) = 0.0
blob%detrainment(:,:) = 0.0
blob%mass_in(:) = 0.0
blob%mass_out(:) = 0.0
s=0
blob%di(s) = buffer%history_integer_buff(1,s,nb)
blob%dj(s) = buffer%history_integer_buff(2,s,nb)
blob%dk(s) = buffer%history_integer_buff(3,s,nb)
blob%mass_out(s) = buffer%history_real_buff(npt+3,s,nb)
if (blob%nfrac_steps>0) then
do s=1,blob%nfrac_steps
! Integer buffer
blob%di(s) = buffer%history_integer_buff(1,s,nb)
blob%dj(s) = buffer%history_integer_buff(2,s,nb)
blob%dk(s) = buffer%history_integer_buff(3,s,nb)
! Real buffer
do n=1,num_prog_tracers
blob%entrainment(s,n) = buffer%history_real_buff(2*n ,s,nb)
blob%detrainment(s,n) = buffer%history_real_buff(2*n+1,s,nb)
enddo
blob%mass_in(s) = buffer%history_real_buff(npt+2,s,nb)
blob%mass_out(s) = buffer%history_real_buff(npt+3,s,nb)
enddo
endif
do s=0,blob%nfrac_steps
call check_cyclic(blob, blob%di(s), blob%dj(s), .false.)
enddo
call insert_blob(blob, head)
else !not bitwise_reproduction
! blob_source is not always parsed, so, we do
! not need to worry about it
if(present(blob_source)) then !if blob_source is present, so is tend_blob, L_system and EL_diag
Ext_mode%conv_blob(i,j) = Ext_mode%conv_blob(i,j) + blob%mass
L_system%conv_blob(i,j,k) = L_system%conv_blob(i,j,k) + blob%mass
mass_in(i,j,k) = mass_in(i,j,k) + blob%mass
do n=0,num_prog_tracers
entrainment(n) = buffer%history_real_buff(2*n ,1,nb)
detrainment(n) = buffer%history_real_buff(2*n+1,1,nb)
enddo
blob_source(i,j) = blob_source(i,j) - detrainment(0) - entrainment(0)
blob%mass = blob%mass + detrainment(0) + entrainment(0)
EL_diag(0)%detrainment(i,j,k) = EL_diag(0)%detrainment(i,j,k) - detrainment(0)
EL_diag(0)%entrainment(i,j,k) = EL_diag(0)%entrainment(i,j,k) + entrainment(0)
do n=1,num_prog_tracers
tend_blob(n,i,j,k) = tend_blob(n,i,j,k) - detrainment(n) - entrainment(n)
blob%tracer(n) = blob%tracer(n) + detrainment(n) + entrainment(n)
EL_diag(n)%detrainment(i,j,k) = EL_diag(n)%detrainment(i,j,k) - detrainment(n)
EL_diag(n)%entrainment(i,j,k) = EL_diag(n)%entrainment(i,j,k) + entrainment(n)
enddo
if (blob%mass>small_mass) then
do n=1,num_prog_tracers
blob%field(n) = blob%tracer(n)/blob%mass
enddo
blob%density = density(blob%field(index_salt), &
blob%field(index_temp), &
Dens%pressure_at_depth(i,j,k))
blob%densityr = 1./blob%density
if (vert_coordinate_class == DEPTH_BASED) then
blob%volume = blob%mass * rho0r
else
blob%volume = blob%mass * blob%densityr
endif
endif
! Check if the blob being received has penetrated the surface boundary.
! If so, return its properties to the E system and do not add it to
! the list.
if (blob%geodepth < -Ext_mode%eta_t(i,j,tau)) then
! Diagnostics
EL_diag(0)%dstry(i,j,k) = EL_diag(0)%dstry(i,j,k) + blob%mass
do n=1,num_prog_tracers
EL_diag(n)%dstry(i,j,k) = EL_diag(n)%dstry(i,j,k) + blob%tracer(n)
enddo
blob_source(i,j) = blob_source(i,j) + blob%mass
blob%mass = 0.0
do n=1,num_prog_tracers
tend_blob(n,i,j,k) = tend_blob(n,i,j,k) + blob%tracer(n)
blob%tracer(n) = 0.0
enddo
endif
endif
! If a blob is of zero mass, we are only interested in its detrainment
! properties. So, to stop any confusion, we kill it after its
! tendencies have been added to the gridded variables.
if (blob%mass>0.0) then
call insert_blob(blob, head)
else
call free_blob_memory(blob)
endif
endif
nullify(blob)
enddo
endif
end subroutine unpackbuffer
! </SUBROUTINE> NAME="unpackbuffer"
!######################################################################
! <SUBROUTINE NAME="increase_buffer">
!
! <DESCRIPTION>
! Increases the buffer size for sending blobs from one PE to another.
! </DESCRIPTION>
!
subroutine increase_buffer(buffer, newnum)
type(blob_buffer_type), pointer :: buffer
integer, intent(in) :: newnum
! local variables
type(blob_buffer_type), pointer :: new_buffer
integer :: newbuffsize, m
allocate(new_buffer)
m=1
do while (newnum>newbuffsize)
newbuffsize = buffer%size + m*delta_buffer
m=m+1
enddo
allocate(new_buffer%integer_buff(int_buff_size,newbuffsize))
allocate(new_buffer%real_buff( rea_buff_size,newbuffsize))
if (bitwise_reproduction) then
allocate(new_buffer%history_integer_buff(hist_int_buff_size, 0:total_nsp1, newbuffsize))
allocate(new_buffer%history_real_buff( 0:hist_rea_buff_size, 0:total_nsp1, newbuffsize))
else
allocate(new_buffer%history_real_buff( 0:hist_rea_buff_size, 1, newbuffsize))
endif
call clear_buffer(new_buffer)
new_buffer%integer_buff(:,1:buffer%size) = buffer%integer_buff(:,:)
new_buffer%real_buff( :,1:buffer%size) = buffer%real_buff(:,:)
if (bitwise_reproduction) new_buffer%history_integer_buff(:,:,1:buffer%size) = buffer%history_integer_buff(:,:,:)
new_buffer%history_real_buff(:,:,1:buffer%size) = buffer%history_real_buff(:,:,:)
new_buffer%pe = buffer%pe
new_buffer%size = newbuffsize
new_buffer%numblobs = buffer%numblobs
deallocate(buffer)
nullify(buffer)
buffer=>new_buffer
end subroutine increase_buffer
! </SUBROUTINE> NAME="increase_buffer"
!######################################################################
! <SUBROUTINE NAME="send_buffer">
!
! <DESCRIPTION>
! Sends a buffer to an adjoining PE
! </DESCRIPTION>
!
subroutine send_buffer(buffer)
type(blob_buffer_type), pointer :: buffer
integer :: nb, n_frac_steps
if (buffer%pe /= NULL_PE) then
call mpp_send(buffer%numblobs, plen=1, to_pe=buffer%pe)
if (buffer%numblobs>0) then
! We cycle through the blobs because sending them en-mass can cause the
! program to hang.
do nb=1,buffer%numblobs
call mpp_send(buffer%integer_buff(:,nb), int_buff_size, buffer%pe)
call mpp_send(buffer%real_buff(:,nb), rea_buff_size, buffer%pe)
n_frac_steps = buffer%integer_buff(7,nb)
if (bitwise_reproduction) then
call mpp_send(buffer%history_integer_buff(:,0:n_frac_steps,nb), hist_int_buff_size*(n_frac_steps+1), buffer%pe)
call mpp_send(buffer%history_real_buff(:,0:n_frac_steps,nb), (1+hist_rea_buff_size)*(n_frac_steps+1), buffer%pe)
else
call mpp_send(buffer%history_real_buff(:,1,nb), 1+hist_rea_buff_size, buffer%pe)
endif
enddo
endif
endif
end subroutine send_buffer
! </SUBROUTINE> NAME="send_buffer"
!######################################################################
! <SUBROUTINE NAME="receive_buffer">
!
! <DESCRIPTION>
! Receives a buffer from an adjoining PE
! </DESCRIPTION>
!
subroutine receive_buffer(buffer)
type(blob_buffer_type), pointer :: buffer
integer :: incoming, nb, n_frac_steps
if (buffer%pe /= NULL_PE) then
call mpp_recv(incoming, glen=1, from_pe=buffer%pe)
if (incoming>0) then
if (incoming>buffer%size) then
call increase_buffer(buffer,incoming)
endif
do nb=1,incoming
call mpp_recv(buffer%integer_buff(:,nb), int_buff_size, buffer%pe)
call mpp_recv(buffer%real_buff(:,nb), rea_buff_size, buffer%pe)
n_frac_steps = buffer%integer_buff(7,nb)
if (bitwise_reproduction) then
call mpp_recv(buffer%history_integer_buff(:,0:n_frac_steps,nb), hist_int_buff_size*(n_frac_steps+1), buffer%pe)
call mpp_recv(buffer%history_real_buff(:,0:n_frac_steps,nb), (1+hist_rea_buff_size)*(n_frac_steps+1), buffer%pe)
else
call mpp_recv(buffer%history_real_buff(:,1,nb), 1+hist_rea_buff_size, buffer%pe)
endif
enddo
endif
buffer%numblobs = incoming
endif
end subroutine receive_buffer
! </SUBROUTINE> NAME="receive_buffer"
!######################################################################
! <SUBROUTINE NAME="clear_buffer">
!
! <DESCRIPTION>
! Clears the contents of a buffer
! </DESCRIPTION>
!
subroutine clear_buffer(buffer)
type(blob_buffer_type), pointer :: buffer
buffer%numblobs = 0
if (buffer%pe /= NULL_PE) then
buffer%integer_buff(:,:) = 0
buffer%real_buff(:,:) = 0.0
if (bitwise_reproduction) then
buffer%history_integer_buff(:,:,:) = 0
buffer%history_real_buff(:,:,:) = 0.0
endif
endif
!note, we do not clear buffer%size
end subroutine clear_buffer
! </SUBROUTINE> NAME="clear_buffer"
end module ocean_blob_dynamic_free_mod
| gpl-2.0 |
LeChuck42/or1k-gcc | libgfortran/generated/_sin_r4.F90 | 35 | 1468 | ! Copyright (C) 2002-2014 Free Software Foundation, Inc.
! Contributed by Paul Brook <paul@nowt.org>
!
!This file is part of the GNU Fortran 95 runtime library (libgfortran).
!
!GNU libgfortran is free software; you can redistribute it and/or
!modify it under the terms of the GNU General Public
!License as published by the Free Software Foundation; either
!version 3 of the License, or (at your option) any later version.
!GNU libgfortran is distributed in the hope that it will be useful,
!but WITHOUT ANY WARRANTY; without even the implied warranty of
!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!GNU General Public License for more details.
!
!Under Section 7 of GPL version 3, you are granted additional
!permissions described in the GCC Runtime Library Exception, version
!3.1, as published by the Free Software Foundation.
!
!You should have received a copy of the GNU General Public License and
!a copy of the GCC Runtime Library Exception along with this program;
!see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
!<http://www.gnu.org/licenses/>.
!
!This file is machine generated.
#include "config.h"
#include "kinds.inc"
#include "c99_protos.inc"
#if defined (HAVE_GFC_REAL_4)
#ifdef HAVE_SINF
elemental function _gfortran_specific__sin_r4 (parm)
real (kind=4), intent (in) :: parm
real (kind=4) :: _gfortran_specific__sin_r4
_gfortran_specific__sin_r4 = sin (parm)
end function
#endif
#endif
| gpl-2.0 |
mverleg/1957 | lib/lapack/dlarzb.f | 24 | 9100 | *> \brief \b DLARZB applies a block reflector or its transpose to a general matrix.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DLARZB + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlarzb.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlarzb.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlarzb.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DLARZB( SIDE, TRANS, DIRECT, STOREV, M, N, K, L, V,
* LDV, T, LDT, C, LDC, WORK, LDWORK )
*
* .. Scalar Arguments ..
* CHARACTER DIRECT, SIDE, STOREV, TRANS
* INTEGER K, L, LDC, LDT, LDV, LDWORK, M, N
* ..
* .. Array Arguments ..
* DOUBLE PRECISION C( LDC, * ), T( LDT, * ), V( LDV, * ),
* $ WORK( LDWORK, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DLARZB applies a real block reflector H or its transpose H**T to
*> a real distributed M-by-N C from the left or the right.
*>
*> Currently, only STOREV = 'R' and DIRECT = 'B' are supported.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] SIDE
*> \verbatim
*> SIDE is CHARACTER*1
*> = 'L': apply H or H**T from the Left
*> = 'R': apply H or H**T from the Right
*> \endverbatim
*>
*> \param[in] TRANS
*> \verbatim
*> TRANS is CHARACTER*1
*> = 'N': apply H (No transpose)
*> = 'C': apply H**T (Transpose)
*> \endverbatim
*>
*> \param[in] DIRECT
*> \verbatim
*> DIRECT is CHARACTER*1
*> Indicates how H is formed from a product of elementary
*> reflectors
*> = 'F': H = H(1) H(2) . . . H(k) (Forward, not supported yet)
*> = 'B': H = H(k) . . . H(2) H(1) (Backward)
*> \endverbatim
*>
*> \param[in] STOREV
*> \verbatim
*> STOREV is CHARACTER*1
*> Indicates how the vectors which define the elementary
*> reflectors are stored:
*> = 'C': Columnwise (not supported yet)
*> = 'R': Rowwise
*> \endverbatim
*>
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of rows of the matrix C.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of columns of the matrix C.
*> \endverbatim
*>
*> \param[in] K
*> \verbatim
*> K is INTEGER
*> The order of the matrix T (= the number of elementary
*> reflectors whose product defines the block reflector).
*> \endverbatim
*>
*> \param[in] L
*> \verbatim
*> L is INTEGER
*> The number of columns of the matrix V containing the
*> meaningful part of the Householder reflectors.
*> If SIDE = 'L', M >= L >= 0, if SIDE = 'R', N >= L >= 0.
*> \endverbatim
*>
*> \param[in] V
*> \verbatim
*> V is DOUBLE PRECISION array, dimension (LDV,NV).
*> If STOREV = 'C', NV = K; if STOREV = 'R', NV = L.
*> \endverbatim
*>
*> \param[in] LDV
*> \verbatim
*> LDV is INTEGER
*> The leading dimension of the array V.
*> If STOREV = 'C', LDV >= L; if STOREV = 'R', LDV >= K.
*> \endverbatim
*>
*> \param[in] T
*> \verbatim
*> T is DOUBLE PRECISION array, dimension (LDT,K)
*> The triangular K-by-K matrix T in the representation of the
*> block reflector.
*> \endverbatim
*>
*> \param[in] LDT
*> \verbatim
*> LDT is INTEGER
*> The leading dimension of the array T. LDT >= K.
*> \endverbatim
*>
*> \param[in,out] C
*> \verbatim
*> C is DOUBLE PRECISION array, dimension (LDC,N)
*> On entry, the M-by-N matrix C.
*> On exit, C is overwritten by H*C or H**T*C or C*H or C*H**T.
*> \endverbatim
*>
*> \param[in] LDC
*> \verbatim
*> LDC is INTEGER
*> The leading dimension of the array C. LDC >= max(1,M).
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is DOUBLE PRECISION array, dimension (LDWORK,K)
*> \endverbatim
*>
*> \param[in] LDWORK
*> \verbatim
*> LDWORK is INTEGER
*> The leading dimension of the array WORK.
*> If SIDE = 'L', LDWORK >= max(1,N);
*> if SIDE = 'R', LDWORK >= max(1,M).
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date September 2012
*
*> \ingroup doubleOTHERcomputational
*
*> \par Contributors:
* ==================
*>
*> A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
*
*> \par Further Details:
* =====================
*>
*> \verbatim
*> \endverbatim
*>
* =====================================================================
SUBROUTINE DLARZB( SIDE, TRANS, DIRECT, STOREV, M, N, K, L, V,
$ LDV, T, LDT, C, LDC, WORK, LDWORK )
*
* -- LAPACK computational routine (version 3.4.2) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* September 2012
*
* .. Scalar Arguments ..
CHARACTER DIRECT, SIDE, STOREV, TRANS
INTEGER K, L, LDC, LDT, LDV, LDWORK, M, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION C( LDC, * ), T( LDT, * ), V( LDV, * ),
$ WORK( LDWORK, * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE
PARAMETER ( ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
CHARACTER TRANST
INTEGER I, INFO, J
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL DCOPY, DGEMM, DTRMM, XERBLA
* ..
* .. Executable Statements ..
*
* Quick return if possible
*
IF( M.LE.0 .OR. N.LE.0 )
$ RETURN
*
* Check for currently supported options
*
INFO = 0
IF( .NOT.LSAME( DIRECT, 'B' ) ) THEN
INFO = -3
ELSE IF( .NOT.LSAME( STOREV, 'R' ) ) THEN
INFO = -4
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DLARZB', -INFO )
RETURN
END IF
*
IF( LSAME( TRANS, 'N' ) ) THEN
TRANST = 'T'
ELSE
TRANST = 'N'
END IF
*
IF( LSAME( SIDE, 'L' ) ) THEN
*
* Form H * C or H**T * C
*
* W( 1:n, 1:k ) = C( 1:k, 1:n )**T
*
DO 10 J = 1, K
CALL DCOPY( N, C( J, 1 ), LDC, WORK( 1, J ), 1 )
10 CONTINUE
*
* W( 1:n, 1:k ) = W( 1:n, 1:k ) + ...
* C( m-l+1:m, 1:n )**T * V( 1:k, 1:l )**T
*
IF( L.GT.0 )
$ CALL DGEMM( 'Transpose', 'Transpose', N, K, L, ONE,
$ C( M-L+1, 1 ), LDC, V, LDV, ONE, WORK, LDWORK )
*
* W( 1:n, 1:k ) = W( 1:n, 1:k ) * T**T or W( 1:m, 1:k ) * T
*
CALL DTRMM( 'Right', 'Lower', TRANST, 'Non-unit', N, K, ONE, T,
$ LDT, WORK, LDWORK )
*
* C( 1:k, 1:n ) = C( 1:k, 1:n ) - W( 1:n, 1:k )**T
*
DO 30 J = 1, N
DO 20 I = 1, K
C( I, J ) = C( I, J ) - WORK( J, I )
20 CONTINUE
30 CONTINUE
*
* C( m-l+1:m, 1:n ) = C( m-l+1:m, 1:n ) - ...
* V( 1:k, 1:l )**T * W( 1:n, 1:k )**T
*
IF( L.GT.0 )
$ CALL DGEMM( 'Transpose', 'Transpose', L, N, K, -ONE, V, LDV,
$ WORK, LDWORK, ONE, C( M-L+1, 1 ), LDC )
*
ELSE IF( LSAME( SIDE, 'R' ) ) THEN
*
* Form C * H or C * H**T
*
* W( 1:m, 1:k ) = C( 1:m, 1:k )
*
DO 40 J = 1, K
CALL DCOPY( M, C( 1, J ), 1, WORK( 1, J ), 1 )
40 CONTINUE
*
* W( 1:m, 1:k ) = W( 1:m, 1:k ) + ...
* C( 1:m, n-l+1:n ) * V( 1:k, 1:l )**T
*
IF( L.GT.0 )
$ CALL DGEMM( 'No transpose', 'Transpose', M, K, L, ONE,
$ C( 1, N-L+1 ), LDC, V, LDV, ONE, WORK, LDWORK )
*
* W( 1:m, 1:k ) = W( 1:m, 1:k ) * T or W( 1:m, 1:k ) * T**T
*
CALL DTRMM( 'Right', 'Lower', TRANS, 'Non-unit', M, K, ONE, T,
$ LDT, WORK, LDWORK )
*
* C( 1:m, 1:k ) = C( 1:m, 1:k ) - W( 1:m, 1:k )
*
DO 60 J = 1, K
DO 50 I = 1, M
C( I, J ) = C( I, J ) - WORK( I, J )
50 CONTINUE
60 CONTINUE
*
* C( 1:m, n-l+1:n ) = C( 1:m, n-l+1:n ) - ...
* W( 1:m, 1:k ) * V( 1:k, 1:l )
*
IF( L.GT.0 )
$ CALL DGEMM( 'No transpose', 'No transpose', M, L, K, -ONE,
$ WORK, LDWORK, V, LDV, ONE, C( 1, N-L+1 ), LDC )
*
END IF
*
RETURN
*
* End of DLARZB
*
END
| bsd-3-clause |
mverleg/1957 | lib/lapack/dorm2r.f | 56 | 7396 | *> \brief \b DORM2R multiplies a general matrix by the orthogonal matrix from a QR factorization determined by sgeqrf (unblocked algorithm).
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DORM2R + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dorm2r.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dorm2r.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dorm2r.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DORM2R( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC,
* WORK, INFO )
*
* .. Scalar Arguments ..
* CHARACTER SIDE, TRANS
* INTEGER INFO, K, LDA, LDC, M, N
* ..
* .. Array Arguments ..
* DOUBLE PRECISION A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DORM2R overwrites the general real m by n matrix C with
*>
*> Q * C if SIDE = 'L' and TRANS = 'N', or
*>
*> Q**T* C if SIDE = 'L' and TRANS = 'T', or
*>
*> C * Q if SIDE = 'R' and TRANS = 'N', or
*>
*> C * Q**T if SIDE = 'R' and TRANS = 'T',
*>
*> where Q is a real orthogonal matrix defined as the product of k
*> elementary reflectors
*>
*> Q = H(1) H(2) . . . H(k)
*>
*> as returned by DGEQRF. Q is of order m if SIDE = 'L' and of order n
*> if SIDE = 'R'.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] SIDE
*> \verbatim
*> SIDE is CHARACTER*1
*> = 'L': apply Q or Q**T from the Left
*> = 'R': apply Q or Q**T from the Right
*> \endverbatim
*>
*> \param[in] TRANS
*> \verbatim
*> TRANS is CHARACTER*1
*> = 'N': apply Q (No transpose)
*> = 'T': apply Q**T (Transpose)
*> \endverbatim
*>
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of rows of the matrix C. M >= 0.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of columns of the matrix C. N >= 0.
*> \endverbatim
*>
*> \param[in] K
*> \verbatim
*> K is INTEGER
*> The number of elementary reflectors whose product defines
*> the matrix Q.
*> If SIDE = 'L', M >= K >= 0;
*> if SIDE = 'R', N >= K >= 0.
*> \endverbatim
*>
*> \param[in] A
*> \verbatim
*> A is DOUBLE PRECISION array, dimension (LDA,K)
*> The i-th column must contain the vector which defines the
*> elementary reflector H(i), for i = 1,2,...,k, as returned by
*> DGEQRF in the first k columns of its array argument A.
*> A is modified by the routine but restored on exit.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A.
*> If SIDE = 'L', LDA >= max(1,M);
*> if SIDE = 'R', LDA >= max(1,N).
*> \endverbatim
*>
*> \param[in] TAU
*> \verbatim
*> TAU is DOUBLE PRECISION array, dimension (K)
*> TAU(i) must contain the scalar factor of the elementary
*> reflector H(i), as returned by DGEQRF.
*> \endverbatim
*>
*> \param[in,out] C
*> \verbatim
*> C is DOUBLE PRECISION array, dimension (LDC,N)
*> On entry, the m by n matrix C.
*> On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
*> \endverbatim
*>
*> \param[in] LDC
*> \verbatim
*> LDC is INTEGER
*> The leading dimension of the array C. LDC >= max(1,M).
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is DOUBLE PRECISION array, dimension
*> (N) if SIDE = 'L',
*> (M) if SIDE = 'R'
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date September 2012
*
*> \ingroup doubleOTHERcomputational
*
* =====================================================================
SUBROUTINE DORM2R( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC,
$ WORK, INFO )
*
* -- LAPACK computational routine (version 3.4.2) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* September 2012
*
* .. Scalar Arguments ..
CHARACTER SIDE, TRANS
INTEGER INFO, K, LDA, LDC, M, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE
PARAMETER ( ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL LEFT, NOTRAN
INTEGER I, I1, I2, I3, IC, JC, MI, NI, NQ
DOUBLE PRECISION AII
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL DLARF, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
* Test the input arguments
*
INFO = 0
LEFT = LSAME( SIDE, 'L' )
NOTRAN = LSAME( TRANS, 'N' )
*
* NQ is the order of Q
*
IF( LEFT ) THEN
NQ = M
ELSE
NQ = N
END IF
IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN
INFO = -1
ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN
INFO = -2
ELSE IF( M.LT.0 ) THEN
INFO = -3
ELSE IF( N.LT.0 ) THEN
INFO = -4
ELSE IF( K.LT.0 .OR. K.GT.NQ ) THEN
INFO = -5
ELSE IF( LDA.LT.MAX( 1, NQ ) ) THEN
INFO = -7
ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
INFO = -10
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DORM2R', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( M.EQ.0 .OR. N.EQ.0 .OR. K.EQ.0 )
$ RETURN
*
IF( ( LEFT .AND. .NOT.NOTRAN ) .OR. ( .NOT.LEFT .AND. NOTRAN ) )
$ THEN
I1 = 1
I2 = K
I3 = 1
ELSE
I1 = K
I2 = 1
I3 = -1
END IF
*
IF( LEFT ) THEN
NI = N
JC = 1
ELSE
MI = M
IC = 1
END IF
*
DO 10 I = I1, I2, I3
IF( LEFT ) THEN
*
* H(i) is applied to C(i:m,1:n)
*
MI = M - I + 1
IC = I
ELSE
*
* H(i) is applied to C(1:m,i:n)
*
NI = N - I + 1
JC = I
END IF
*
* Apply H(i)
*
AII = A( I, I )
A( I, I ) = ONE
CALL DLARF( SIDE, MI, NI, A( I, I ), 1, TAU( I ), C( IC, JC ),
$ LDC, WORK )
A( I, I ) = AII
10 CONTINUE
RETURN
*
* End of DORM2R
*
END
| bsd-3-clause |
davidgiven/gcc-vc4 | gcc/testsuite/gfortran.dg/used_before_typed_1.f90 | 193 | 1320 | ! { dg-do compile }
! { dg-options "-std=f95" }
! PR fortran/32095
! PR fortran/34228
! Check that standards-conforming mode rejects uses of variables that
! are used before they are typed.
SUBROUTINE test1 (n, arr, m, arr2, k, arr3, a) ! { dg-error "has no IMPLICIT" }
IMPLICIT NONE
INTEGER :: arr(n) ! { dg-error "used before it is typed" }
INTEGER :: n
INTEGER :: m, arr2(m) ! { dg-bogus "used before it is typed" }
INTEGER, DIMENSION(k) :: arr3 ! { dg-error "used before it is typed" }
INTEGER :: k
CHARACTER(len=LEN(a)) :: a ! { dg-error "'a' is used before it is typed" }
REAL(KIND=l) :: x ! { dg-error "has no IMPLICIT type" }
REAL(KIND=KIND(y)) :: y ! { dg-error "has no IMPLICIT type" }
DATA str/'abc'/ ! { dg-error "used before it is typed" }
CHARACTER(len=3) :: str, str2
DATA str2/'abc'/ ! { dg-bogus "used before it is typed" }
END SUBROUTINE test1
SUBROUTINE test2 (n, arr, m, arr2)
IMPLICIT INTEGER(a-z)
INTEGER :: arr(n)
REAL :: n ! { dg-error "already has basic type" }
INTEGER :: m, arr2(m) ! { dg-bogus "already has an IMPLICIT type" }
END SUBROUTINE test2
SUBROUTINE test3 (n, arr, m, arr2)
IMPLICIT REAL(a-z)
INTEGER :: arr(n) ! { dg-error "must be of INTEGER type" }
INTEGER :: m, arr2(m) ! { dg-bogus "must be of INTEGER type" }
END SUBROUTINE test3
| gpl-2.0 |
anntzer/scipy | scipy/interpolate/fitpack/fpcosp.f | 10 | 11930 | recursive subroutine fpcosp(m,x,y,w,n,t,e,maxtr,maxbin,c,sq,sx,
* bind,nm,mb,a,
* b,const,z,zz,u,q,info,up,left,right,jbind,ibind,ier)
implicit none
c ..
c ..scalar arguments..
real*8 sq
integer m,n,maxtr,maxbin,nm,mb,ier
c ..array arguments..
real*8 x(m),y(m),w(m),t(n),e(n),c(n),sx(m),a(n,4),b(nm,maxbin),
* const(n),z(n),zz(n),u(maxbin),q(m,4)
integer info(maxtr),up(maxtr),left(maxtr),right(maxtr),jbind(mb),
* ibind(mb)
logical bind(n)
c ..local scalars..
integer count,i,i1,j,j1,j2,j3,k,kdim,k1,k2,k3,k4,k5,k6,
* l,lp1,l1,l2,l3,merk,nbind,number,n1,n4,n6
real*8 f,wi,xi
c ..local array..
real*8 h(4)
c ..subroutine references..
c fpbspl,fpadno,fpdeno,fpfrno,fpseno
c ..
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c if we use the b-spline representation of s(x) our approximation c
c problem results in a quadratic programming problem: c
c find the b-spline coefficients c(j),j=1,2,...n-4 such that c
c (1) sumi((wi*(yi-sumj(cj*nj(xi))))**2),i=1,2,...m is minimal c
c (2) sumj(cj*n''j(t(l+3)))*e(l) <= 0, l=1,2,...n-6. c
c to solve this problem we use the theil-van de panne procedure. c
c if the inequality constraints (2) are numbered from 1 to n-6, c
c this algorithm finds a subset of constraints ibind(1)..ibind(nbind) c
c such that the solution of the minimization problem (1) with these c
c constraints in equality form, satisfies all constraints. such a c
c feasible solution is optimal if the lagrange parameters associated c
c with that problem with equality constraints, are all positive. c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c determine n6, the number of inequality constraints.
n6 = n-6
c fix the parameters which determine these constraints.
do 10 i=1,n6
const(i) = e(i)*(t(i+4)-t(i+1))/(t(i+5)-t(i+2))
10 continue
c initialize the triply linked tree which is used to find the subset
c of constraints ibind(1),...ibind(nbind).
count = 1
info(1) = 0
left(1) = 0
right(1) = 0
up(1) = 1
merk = 1
c set up the normal equations n'nc=n'y where n denotes the m x (n-4)
c observation matrix with elements ni,j = wi*nj(xi) and y is the
c column vector with elements yi*wi.
c from the properties of the b-splines nj(x),j=1,2,...n-4, it follows
c that n'n is a (n-4) x (n-4) positive definite bandmatrix of
c bandwidth 7. the matrices n'n and n'y are built up in a and z.
n4 = n-4
c initialization
do 20 i=1,n4
z(i) = 0.
do 20 j=1,4
a(i,j) = 0.
20 continue
l = 4
lp1 = l+1
do 70 i=1,m
c fetch the current row of the observation matrix.
xi = x(i)
wi = w(i)**2
c search for knot interval t(l) <= xi < t(l+1)
30 if(xi.lt.t(lp1) .or. l.eq.n4) go to 40
l = lp1
lp1 = l+1
go to 30
c evaluate the four non-zero cubic b-splines nj(xi),j=l-3,...l.
40 call fpbspl(t,n,3,xi,l,h)
c store in q these values h(1),h(2),...h(4).
do 50 j=1,4
q(i,j) = h(j)
50 continue
c add the contribution of the current row of the observation matrix
c n to the normal equations.
l3 = l-3
k1 = 0
do 60 j1 = l3,l
k1 = k1+1
f = h(k1)
z(j1) = z(j1)+f*wi*y(i)
k2 = k1
j2 = 4
do 60 j3 = j1,l
a(j3,j2) = a(j3,j2)+f*wi*h(k2)
k2 = k2+1
j2 = j2-1
60 continue
70 continue
c since n'n is a symmetric matrix it can be factorized as
c (3) n'n = (r1)'(d1)(r1)
c with d1 a diagonal matrix and r1 an (n-4) x (n-4) unit upper
c triangular matrix of bandwidth 4. the matrices r1 and d1 are built
c up in a. at the same time we solve the systems of equations
c (4) (r1)'(z2) = n'y
c (5) (d1) (z1) = (z2)
c the vectors z2 and z1 are kept in zz and z.
do 140 i=1,n4
k1 = 1
if(i.lt.4) k1 = 5-i
k2 = i-4+k1
k3 = k2
do 100 j=k1,4
k4 = j-1
k5 = 4-j+k1
f = a(i,j)
if(k1.gt.k4) go to 90
k6 = k2
do 80 k=k1,k4
f = f-a(i,k)*a(k3,k5)*a(k6,4)
k5 = k5+1
k6 = k6+1
80 continue
90 if(j.eq.4) go to 110
a(i,j) = f/a(k3,4)
k3 = k3+1
100 continue
110 a(i,4) = f
f = z(i)
if(i.eq.1) go to 130
k4 = i
do 120 j=k1,3
k = k1+3-j
k4 = k4-1
f = f-a(i,k)*z(k4)*a(k4,4)
120 continue
130 z(i) = f/a(i,4)
zz(i) = f
140 continue
c start computing the least-squares cubic spline without taking account
c of any constraint.
nbind = 0
n1 = 1
ibind(1) = 0
c main loop for the least-squares problems with different subsets of
c the constraints (2) in equality form. the resulting b-spline coeff.
c c and lagrange parameters u are the solution of the system
c ! n'n b' ! ! c ! ! n'y !
c (6) ! ! ! ! = ! !
c ! b 0 ! ! u ! ! 0 !
c z1 is stored into array c.
150 do 160 i=1,n4
c(i) = z(i)
160 continue
c if there are no equality constraints, compute the coeff. c directly.
if(nbind.eq.0) go to 370
c initialization
kdim = n4+nbind
do 170 i=1,nbind
do 170 j=1,kdim
b(j,i) = 0.
170 continue
c matrix b is built up,expressing that the constraints nrs ibind(1),...
c ibind(nbind) must be satisfied in equality form.
do 180 i=1,nbind
l = ibind(i)
b(l,i) = e(l)
b(l+1,i) = -(e(l)+const(l))
b(l+2,i) = const(l)
180 continue
c find the matrix (b1) as the solution of the system of equations
c (7) (r1)'(d1)(b1) = b'
c (b1) is built up in the upper part of the array b(rows 1,...n-4).
do 220 k1=1,nbind
l = ibind(k1)
do 210 i=l,n4
f = b(i,k1)
if(i.eq.1) go to 200
k2 = 3
if(i.lt.4) k2 = i-1
do 190 k3=1,k2
l1 = i-k3
l2 = 4-k3
f = f-b(l1,k1)*a(i,l2)*a(l1,4)
190 continue
200 b(i,k1) = f/a(i,4)
210 continue
220 continue
c factorization of the symmetric matrix -(b1)'(d1)(b1)
c (8) -(b1)'(d1)(b1) = (r2)'(d2)(r2)
c with (d2) a diagonal matrix and (r2) an nbind x nbind unit upper
c triangular matrix. the matrices r2 and d2 are built up in the lower
c part of the array b (rows n-3,n-2,...n-4+nbind).
do 270 i=1,nbind
i1 = i-1
do 260 j=i,nbind
f = 0.
do 230 k=1,n4
f = f+b(k,i)*b(k,j)*a(k,4)
230 continue
k1 = n4+1
if(i1.eq.0) go to 250
do 240 k=1,i1
f = f+b(k1,i)*b(k1,j)*b(k1,k)
k1 = k1+1
240 continue
250 b(k1,j) = -f
if(j.eq.i) go to 260
b(k1,j) = b(k1,j)/b(k1,i)
260 continue
270 continue
c according to (3),(7) and (8) the system of equations (6) becomes
c ! (r1)' 0 ! ! (d1) 0 ! ! (r1) (b1) ! ! c ! ! n'y !
c (9) ! ! ! ! ! ! ! ! = ! !
c ! (b1)' (r2)'! ! 0 (d2) ! ! 0 (r2) ! ! u ! ! 0 !
c backward substitution to obtain the b-spline coefficients c(j),j=1,..
c n-4 and the lagrange parameters u(j),j=1,2,...nbind.
c first step of the backward substitution: solve the system
c ! (r1)'(d1) 0 ! ! (c1) ! ! n'y !
c (10) ! ! ! ! = ! !
c ! (b1)'(d1) (r2)'(d2) ! ! (u1) ! ! 0 !
c from (4) and (5) we know that this is equivalent to
c (11) (c1) = (z1)
c (12) (r2)'(d2)(u1) = -(b1)'(z2)
do 310 i=1,nbind
f = 0.
do 280 j=1,n4
f = f+b(j,i)*zz(j)
280 continue
i1 = i-1
k1 = n4+1
if(i1.eq.0) go to 300
do 290 j=1,i1
f = f+u(j)*b(k1,i)*b(k1,j)
k1 = k1+1
290 continue
300 u(i) = -f/b(k1,i)
310 continue
c second step of the backward substitution: solve the system
c ! (r1) (b1) ! ! c ! ! c1 !
c (13) ! ! ! ! = ! !
c ! 0 (r2) ! ! u ! ! u1 !
k1 = nbind
k2 = kdim
c find the lagrange parameters u.
do 340 i=1,nbind
f = u(k1)
if(i.eq.1) go to 330
k3 = k1+1
do 320 j=k3,nbind
f = f-u(j)*b(k2,j)
320 continue
330 u(k1) = f
k1 = k1-1
k2 = k2-1
340 continue
c find the b-spline coefficients c.
do 360 i=1,n4
f = c(i)
do 350 j=1,nbind
f = f-u(j)*b(i,j)
350 continue
c(i) = f
360 continue
370 k1 = n4
do 390 i=2,n4
k1 = k1-1
f = c(k1)
k2 = 1
if(i.lt.5) k2 = 5-i
k3 = k1
l = 3
do 380 j=k2,3
k3 = k3+1
f = f-a(k3,l)*c(k3)
l = l-1
380 continue
c(k1) = f
390 continue
c test whether the solution of the least-squares problem with the
c constraints ibind(1),...ibind(nbind) in equality form, satisfies
c all of the constraints (2).
k = 1
c number counts the number of violated inequality constraints.
number = 0
do 440 j=1,n6
l = ibind(k)
k = k+1
if(j.eq.l) go to 440
k = k-1
c test whether constraint j is satisfied
f = e(j)*(c(j)-c(j+1))+const(j)*(c(j+2)-c(j+1))
if(f.le.0.) go to 440
c if constraint j is not satisfied, add a branch of length nbind+1
c to the tree. the nodes of this branch contain in their information
c field the number of the constraints ibind(1),...ibind(nbind) and j,
c arranged in increasing order.
number = number+1
k1 = k-1
if(k1.eq.0) go to 410
do 400 i=1,k1
jbind(i) = ibind(i)
400 continue
410 jbind(k) = j
if(l.eq.0) go to 430
do 420 i=k,nbind
jbind(i+1) = ibind(i)
420 continue
430 call fpadno(maxtr,up,left,right,info,count,merk,jbind,n1,ier)
c test whether the storage space which is required for the tree,exceeds
c the available storage space.
if(ier.ne.0) go to 560
440 continue
c test whether the solution of the least-squares problem with equality
c constraints is a feasible solution.
if(number.eq.0) go to 470
c test whether there are still cases with nbind constraints in
c equality form to be considered.
450 if(merk.gt.1) go to 460
nbind = n1
c test whether the number of knots where s''(x)=0 exceeds maxbin.
if(nbind.gt.maxbin) go to 550
n1 = n1+1
ibind(n1) = 0
c search which cases with nbind constraints in equality form
c are going to be considered.
call fpdeno(maxtr,up,left,right,nbind,merk)
c test whether the quadratic programming problem has a solution.
if(merk.eq.1) go to 570
c find a new case with nbind constraints in equality form.
460 call fpseno(maxtr,up,left,right,info,merk,ibind,nbind)
go to 150
c test whether the feasible solution is optimal.
470 ier = 0
do 480 i=1,n6
bind(i) = .false.
480 continue
if(nbind.eq.0) go to 500
do 490 i=1,nbind
if(u(i).le.0.) go to 450
j = ibind(i)
bind(j) = .true.
490 continue
c evaluate s(x) at the data points x(i) and calculate the weighted
c sum of squared residual right hand sides sq.
500 sq = 0.
l = 4
lp1 = 5
do 530 i=1,m
510 if(x(i).lt.t(lp1) .or. l.eq.n4) go to 520
l = lp1
lp1 = l+1
go to 510
520 sx(i) = c(l-3)*q(i,1)+c(l-2)*q(i,2)+c(l-1)*q(i,3)+c(l)*q(i,4)
sq = sq+(w(i)*(y(i)-sx(i)))**2
530 continue
go to 600
c error codes and messages.
550 ier = 1
go to 600
560 ier = 2
go to 600
570 ier = 3
600 return
end
| bsd-3-clause |
davidgiven/gcc-vc4 | gcc/testsuite/gfortran.dg/g77/980519-2.f | 209 | 1605 | c { dg-do compile }
* Date: Fri, 17 Apr 1998 14:12:51 +0200
* From: Jean-Paul Jeannot <jeannot@gx-tech.fr>
* Organization: GX Technology France
* To: egcs-bugs@cygnus.com
* Subject: identified bug in g77 on Alpha
*
* Dear Sir,
*
* You will find below the assembly code of a simple Fortran routine which
* crashes with segmentation fault when storing the first element
* in( jT_f-hd_T ) = Xsp
* whereas everything is fine when commenting this line.
*
* The assembly code (generated with
* -ffast-math -fexpensive-optimizations -fomit-frame-pointer -fno-inline
* or with -O5)
* uses a zapnot instruction to copy an address.
* BUT the zapnot parameter is 15 (copuing 4 bytes) instead of 255 (to copy
* 8 bytes).
*
* I guess this is typically a 64 bit issue. As, from my understanding,
* zapnots are used a lot to copy registers, this may create problems
* elsewhere.
*
* Thanks for your help
*
* Jean-Paul Jeannot
*
subroutine simul_trace( in, Xsp, Ysp, Xrcv, Yrcv )
c Next declaration added on transfer to gfortran testsuite
integer hd_S, hd_Z, hd_T
common /Idim/ jT_f, jT_l, nT, nT_dim
common /Idim/ jZ_f, jZ_l, nZ, nZ_dim
common /Idim/ jZ2_f, jZ2_l, nZ2, nZ2_dim
common /Idim/ jzs_f, jzs_l, nzs, nzs_dim, l_amp
common /Idim/ hd_S, hd_Z, hd_T
common /Idim/ nlay, nlayz
common /Idim/ n_work
common /Idim/ nb_calls
real Xsp, Ysp, Xrcv, Yrcv
real in( jT_f-hd_T : jT_l )
in( jT_f-hd_T ) = Xsp
in( jT_f-hd_T + 1 ) = Ysp
in( jT_f-hd_T + 2 ) = Xrcv
in( jT_f-hd_T + 3 ) = Yrcv
end
| gpl-2.0 |
mverleg/1957 | lib/lapack/dormr3.f | 24 | 7907 | *> \brief \b DORMR3 multiplies a general matrix by the orthogonal matrix from a RZ factorization determined by stzrzf (unblocked algorithm).
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DORMR3 + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dormr3.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dormr3.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dormr3.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DORMR3( SIDE, TRANS, M, N, K, L, A, LDA, TAU, C, LDC,
* WORK, INFO )
*
* .. Scalar Arguments ..
* CHARACTER SIDE, TRANS
* INTEGER INFO, K, L, LDA, LDC, M, N
* ..
* .. Array Arguments ..
* DOUBLE PRECISION A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DORMR3 overwrites the general real m by n matrix C with
*>
*> Q * C if SIDE = 'L' and TRANS = 'N', or
*>
*> Q**T* C if SIDE = 'L' and TRANS = 'C', or
*>
*> C * Q if SIDE = 'R' and TRANS = 'N', or
*>
*> C * Q**T if SIDE = 'R' and TRANS = 'C',
*>
*> where Q is a real orthogonal matrix defined as the product of k
*> elementary reflectors
*>
*> Q = H(1) H(2) . . . H(k)
*>
*> as returned by DTZRZF. Q is of order m if SIDE = 'L' and of order n
*> if SIDE = 'R'.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] SIDE
*> \verbatim
*> SIDE is CHARACTER*1
*> = 'L': apply Q or Q**T from the Left
*> = 'R': apply Q or Q**T from the Right
*> \endverbatim
*>
*> \param[in] TRANS
*> \verbatim
*> TRANS is CHARACTER*1
*> = 'N': apply Q (No transpose)
*> = 'T': apply Q**T (Transpose)
*> \endverbatim
*>
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of rows of the matrix C. M >= 0.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of columns of the matrix C. N >= 0.
*> \endverbatim
*>
*> \param[in] K
*> \verbatim
*> K is INTEGER
*> The number of elementary reflectors whose product defines
*> the matrix Q.
*> If SIDE = 'L', M >= K >= 0;
*> if SIDE = 'R', N >= K >= 0.
*> \endverbatim
*>
*> \param[in] L
*> \verbatim
*> L is INTEGER
*> The number of columns of the matrix A containing
*> the meaningful part of the Householder reflectors.
*> If SIDE = 'L', M >= L >= 0, if SIDE = 'R', N >= L >= 0.
*> \endverbatim
*>
*> \param[in] A
*> \verbatim
*> A is DOUBLE PRECISION array, dimension
*> (LDA,M) if SIDE = 'L',
*> (LDA,N) if SIDE = 'R'
*> The i-th row must contain the vector which defines the
*> elementary reflector H(i), for i = 1,2,...,k, as returned by
*> DTZRZF in the last k rows of its array argument A.
*> A is modified by the routine but restored on exit.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,K).
*> \endverbatim
*>
*> \param[in] TAU
*> \verbatim
*> TAU is DOUBLE PRECISION array, dimension (K)
*> TAU(i) must contain the scalar factor of the elementary
*> reflector H(i), as returned by DTZRZF.
*> \endverbatim
*>
*> \param[in,out] C
*> \verbatim
*> C is DOUBLE PRECISION array, dimension (LDC,N)
*> On entry, the m-by-n matrix C.
*> On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
*> \endverbatim
*>
*> \param[in] LDC
*> \verbatim
*> LDC is INTEGER
*> The leading dimension of the array C. LDC >= max(1,M).
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is DOUBLE PRECISION array, dimension
*> (N) if SIDE = 'L',
*> (M) if SIDE = 'R'
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date September 2012
*
*> \ingroup doubleOTHERcomputational
*
*> \par Contributors:
* ==================
*>
*> A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
*
*> \par Further Details:
* =====================
*>
*> \verbatim
*> \endverbatim
*>
* =====================================================================
SUBROUTINE DORMR3( SIDE, TRANS, M, N, K, L, A, LDA, TAU, C, LDC,
$ WORK, INFO )
*
* -- LAPACK computational routine (version 3.4.2) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* September 2012
*
* .. Scalar Arguments ..
CHARACTER SIDE, TRANS
INTEGER INFO, K, L, LDA, LDC, M, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
* ..
*
* =====================================================================
*
* .. Local Scalars ..
LOGICAL LEFT, NOTRAN
INTEGER I, I1, I2, I3, IC, JA, JC, MI, NI, NQ
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL DLARZ, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
* Test the input arguments
*
INFO = 0
LEFT = LSAME( SIDE, 'L' )
NOTRAN = LSAME( TRANS, 'N' )
*
* NQ is the order of Q
*
IF( LEFT ) THEN
NQ = M
ELSE
NQ = N
END IF
IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN
INFO = -1
ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN
INFO = -2
ELSE IF( M.LT.0 ) THEN
INFO = -3
ELSE IF( N.LT.0 ) THEN
INFO = -4
ELSE IF( K.LT.0 .OR. K.GT.NQ ) THEN
INFO = -5
ELSE IF( L.LT.0 .OR. ( LEFT .AND. ( L.GT.M ) ) .OR.
$ ( .NOT.LEFT .AND. ( L.GT.N ) ) ) THEN
INFO = -6
ELSE IF( LDA.LT.MAX( 1, K ) ) THEN
INFO = -8
ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
INFO = -11
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DORMR3', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( M.EQ.0 .OR. N.EQ.0 .OR. K.EQ.0 )
$ RETURN
*
IF( ( LEFT .AND. .NOT.NOTRAN .OR. .NOT.LEFT .AND. NOTRAN ) ) THEN
I1 = 1
I2 = K
I3 = 1
ELSE
I1 = K
I2 = 1
I3 = -1
END IF
*
IF( LEFT ) THEN
NI = N
JA = M - L + 1
JC = 1
ELSE
MI = M
JA = N - L + 1
IC = 1
END IF
*
DO 10 I = I1, I2, I3
IF( LEFT ) THEN
*
* H(i) or H(i)**T is applied to C(i:m,1:n)
*
MI = M - I + 1
IC = I
ELSE
*
* H(i) or H(i)**T is applied to C(1:m,i:n)
*
NI = N - I + 1
JC = I
END IF
*
* Apply H(i) or H(i)**T
*
CALL DLARZ( SIDE, MI, NI, L, A( I, JA ), LDA, TAU( I ),
$ C( IC, JC ), LDC, WORK )
*
10 CONTINUE
*
RETURN
*
* End of DORMR3
*
END
| bsd-3-clause |
maxhutch/magma | testing/lin/sgbt01.f | 9 | 5137 | SUBROUTINE SGBT01( M, N, KL, KU, A, LDA, AFAC, LDAFAC, IPIV, WORK,
$ RESID )
*
* -- LAPACK test routine (version 3.1) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
INTEGER KL, KU, LDA, LDAFAC, M, N
REAL RESID
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
REAL A( LDA, * ), AFAC( LDAFAC, * ), WORK( * )
* ..
*
* Purpose
* =======
*
* SGBT01 reconstructs a band matrix A from its L*U factorization and
* computes the residual:
* norm(L*U - A) / ( N * norm(A) * EPS ),
* where EPS is the machine epsilon.
*
* The expression L*U - A is computed one column at a time, so A and
* AFAC are not modified.
*
* Arguments
* =========
*
* M (input) INTEGER
* The number of rows of the matrix A. M >= 0.
*
* N (input) INTEGER
* The number of columns of the matrix A. N >= 0.
*
* KL (input) INTEGER
* The number of subdiagonals within the band of A. KL >= 0.
*
* KU (input) INTEGER
* The number of superdiagonals within the band of A. KU >= 0.
*
* A (input/output) REAL array, dimension (LDA,N)
* The original matrix A in band storage, stored in rows 1 to
* KL+KU+1.
*
* LDA (input) INTEGER.
* The leading dimension of the array A. LDA >= max(1,KL+KU+1).
*
* AFAC (input) REAL array, dimension (LDAFAC,N)
* The factored form of the matrix A. AFAC contains the banded
* factors L and U from the L*U factorization, as computed by
* SGBTRF. U is stored as an upper triangular band matrix with
* KL+KU superdiagonals in rows 1 to KL+KU+1, and the
* multipliers used during the factorization are stored in rows
* KL+KU+2 to 2*KL+KU+1. See SGBTRF for further details.
*
* LDAFAC (input) INTEGER
* The leading dimension of the array AFAC.
* LDAFAC >= max(1,2*KL*KU+1).
*
* IPIV (input) INTEGER array, dimension (min(M,N))
* The pivot indices from SGBTRF.
*
* WORK (workspace) REAL array, dimension (2*KL+KU+1)
*
* RESID (output) REAL
* norm(L*U - A) / ( N * norm(A) * EPS )
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
* ..
* .. Local Scalars ..
INTEGER I, I1, I2, IL, IP, IW, J, JL, JU, JUA, KD, LENJ
REAL ANORM, EPS, T
* ..
* .. External Functions ..
REAL SASUM, SLAMCH
EXTERNAL SASUM, SLAMCH
* ..
* .. External Subroutines ..
EXTERNAL SAXPY, SCOPY
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN, REAL
* ..
* .. Executable Statements ..
*
* Quick exit if M = 0 or N = 0.
*
RESID = ZERO
IF( M.LE.0 .OR. N.LE.0 )
$ RETURN
*
* Determine EPS and the norm of A.
*
EPS = SLAMCH( 'Epsilon' )
KD = KU + 1
ANORM = ZERO
DO 10 J = 1, N
I1 = MAX( KD+1-J, 1 )
I2 = MIN( KD+M-J, KL+KD )
IF( I2.GE.I1 )
$ ANORM = MAX( ANORM, SASUM( I2-I1+1, A( I1, J ), 1 ) )
10 CONTINUE
*
* Compute one column at a time of L*U - A.
*
KD = KL + KU + 1
DO 40 J = 1, N
*
* Copy the J-th column of U to WORK.
*
JU = MIN( KL+KU, J-1 )
JL = MIN( KL, M-J )
LENJ = MIN( M, J ) - J + JU + 1
IF( LENJ.GT.0 ) THEN
CALL SCOPY( LENJ, AFAC( KD-JU, J ), 1, WORK, 1 )
DO 20 I = LENJ + 1, JU + JL + 1
WORK( I ) = ZERO
20 CONTINUE
*
* Multiply by the unit lower triangular matrix L. Note that L
* is stored as a product of transformations and permutations.
*
DO 30 I = MIN( M-1, J ), J - JU, -1
IL = MIN( KL, M-I )
IF( IL.GT.0 ) THEN
IW = I - J + JU + 1
T = WORK( IW )
CALL SAXPY( IL, T, AFAC( KD+1, I ), 1, WORK( IW+1 ),
$ 1 )
IP = IPIV( I )
IF( I.NE.IP ) THEN
IP = IP - J + JU + 1
WORK( IW ) = WORK( IP )
WORK( IP ) = T
END IF
END IF
30 CONTINUE
*
* Subtract the corresponding column of A.
*
JUA = MIN( JU, KU )
IF( JUA+JL+1.GT.0 )
$ CALL SAXPY( JUA+JL+1, -ONE, A( KU+1-JUA, J ), 1,
$ WORK( JU+1-JUA ), 1 )
*
* Compute the 1-norm of the column.
*
RESID = MAX( RESID, SASUM( JU+JL+1, WORK, 1 ) )
END IF
40 CONTINUE
*
* Compute norm( L*U - A ) / ( N * norm(A) * EPS )
*
IF( ANORM.LE.ZERO ) THEN
IF( RESID.NE.ZERO )
$ RESID = ONE / EPS
ELSE
RESID = ( ( RESID / REAL( N ) ) / ANORM ) / EPS
END IF
*
RETURN
*
* End of SGBT01
*
END
| bsd-3-clause |
mverleg/1957 | lib/lapack/ztrrfs.f | 29 | 14955 | *> \brief \b ZTRRFS
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download ZTRRFS + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ztrrfs.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ztrrfs.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ztrrfs.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE ZTRRFS( UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, X,
* LDX, FERR, BERR, WORK, RWORK, INFO )
*
* .. Scalar Arguments ..
* CHARACTER DIAG, TRANS, UPLO
* INTEGER INFO, LDA, LDB, LDX, N, NRHS
* ..
* .. Array Arguments ..
* DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
* COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * ),
* $ X( LDX, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ZTRRFS provides error bounds and backward error estimates for the
*> solution to a system of linear equations with a triangular
*> coefficient matrix.
*>
*> The solution matrix X must be computed by ZTRTRS or some other
*> means before entering this routine. ZTRRFS does not do iterative
*> refinement because doing so cannot improve the backward error.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] UPLO
*> \verbatim
*> UPLO is CHARACTER*1
*> = 'U': A is upper triangular;
*> = 'L': A is lower triangular.
*> \endverbatim
*>
*> \param[in] TRANS
*> \verbatim
*> TRANS is CHARACTER*1
*> Specifies the form of the system of equations:
*> = 'N': A * X = B (No transpose)
*> = 'T': A**T * X = B (Transpose)
*> = 'C': A**H * X = B (Conjugate transpose)
*> \endverbatim
*>
*> \param[in] DIAG
*> \verbatim
*> DIAG is CHARACTER*1
*> = 'N': A is non-unit triangular;
*> = 'U': A is unit triangular.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrix A. N >= 0.
*> \endverbatim
*>
*> \param[in] NRHS
*> \verbatim
*> NRHS is INTEGER
*> The number of right hand sides, i.e., the number of columns
*> of the matrices B and X. NRHS >= 0.
*> \endverbatim
*>
*> \param[in] A
*> \verbatim
*> A is COMPLEX*16 array, dimension (LDA,N)
*> The triangular matrix A. If UPLO = 'U', the leading N-by-N
*> upper triangular part of the array A contains the upper
*> triangular matrix, and the strictly lower triangular part of
*> A is not referenced. If UPLO = 'L', the leading N-by-N lower
*> triangular part of the array A contains the lower triangular
*> matrix, and the strictly upper triangular part of A is not
*> referenced. If DIAG = 'U', the diagonal elements of A are
*> also not referenced and are assumed to be 1.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[in] B
*> \verbatim
*> B is COMPLEX*16 array, dimension (LDB,NRHS)
*> The right hand side matrix B.
*> \endverbatim
*>
*> \param[in] LDB
*> \verbatim
*> LDB is INTEGER
*> The leading dimension of the array B. LDB >= max(1,N).
*> \endverbatim
*>
*> \param[in] X
*> \verbatim
*> X is COMPLEX*16 array, dimension (LDX,NRHS)
*> The solution matrix X.
*> \endverbatim
*>
*> \param[in] LDX
*> \verbatim
*> LDX is INTEGER
*> The leading dimension of the array X. LDX >= max(1,N).
*> \endverbatim
*>
*> \param[out] FERR
*> \verbatim
*> FERR is DOUBLE PRECISION array, dimension (NRHS)
*> The estimated forward error bound for each solution vector
*> X(j) (the j-th column of the solution matrix X).
*> If XTRUE is the true solution corresponding to X(j), FERR(j)
*> is an estimated upper bound for the magnitude of the largest
*> element in (X(j) - XTRUE) divided by the magnitude of the
*> largest element in X(j). The estimate is as reliable as
*> the estimate for RCOND, and is almost always a slight
*> overestimate of the true error.
*> \endverbatim
*>
*> \param[out] BERR
*> \verbatim
*> BERR is DOUBLE PRECISION array, dimension (NRHS)
*> The componentwise relative backward error of each solution
*> vector X(j) (i.e., the smallest relative change in
*> any element of A or B that makes X(j) an exact solution).
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is COMPLEX*16 array, dimension (2*N)
*> \endverbatim
*>
*> \param[out] RWORK
*> \verbatim
*> RWORK is DOUBLE PRECISION array, dimension (N)
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup complex16OTHERcomputational
*
* =====================================================================
SUBROUTINE ZTRRFS( UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, X,
$ LDX, FERR, BERR, WORK, RWORK, INFO )
*
* -- LAPACK computational routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
CHARACTER DIAG, TRANS, UPLO
INTEGER INFO, LDA, LDB, LDX, N, NRHS
* ..
* .. Array Arguments ..
DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * ),
$ X( LDX, * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO
PARAMETER ( ZERO = 0.0D+0 )
COMPLEX*16 ONE
PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) )
* ..
* .. Local Scalars ..
LOGICAL NOTRAN, NOUNIT, UPPER
CHARACTER TRANSN, TRANST
INTEGER I, J, K, KASE, NZ
DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
COMPLEX*16 ZDUM
* ..
* .. Local Arrays ..
INTEGER ISAVE( 3 )
* ..
* .. External Subroutines ..
EXTERNAL XERBLA, ZAXPY, ZCOPY, ZLACN2, ZTRMV, ZTRSV
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, DBLE, DIMAG, MAX
* ..
* .. External Functions ..
LOGICAL LSAME
DOUBLE PRECISION DLAMCH
EXTERNAL LSAME, DLAMCH
* ..
* .. Statement Functions ..
DOUBLE PRECISION CABS1
* ..
* .. Statement Function definitions ..
CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
UPPER = LSAME( UPLO, 'U' )
NOTRAN = LSAME( TRANS, 'N' )
NOUNIT = LSAME( DIAG, 'N' )
*
IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = -1
ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
$ LSAME( TRANS, 'C' ) ) THEN
INFO = -2
ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
INFO = -3
ELSE IF( N.LT.0 ) THEN
INFO = -4
ELSE IF( NRHS.LT.0 ) THEN
INFO = -5
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -7
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -9
ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
INFO = -11
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZTRRFS', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
DO 10 J = 1, NRHS
FERR( J ) = ZERO
BERR( J ) = ZERO
10 CONTINUE
RETURN
END IF
*
IF( NOTRAN ) THEN
TRANSN = 'N'
TRANST = 'C'
ELSE
TRANSN = 'C'
TRANST = 'N'
END IF
*
* NZ = maximum number of nonzero elements in each row of A, plus 1
*
NZ = N + 1
EPS = DLAMCH( 'Epsilon' )
SAFMIN = DLAMCH( 'Safe minimum' )
SAFE1 = NZ*SAFMIN
SAFE2 = SAFE1 / EPS
*
* Do for each right hand side
*
DO 250 J = 1, NRHS
*
* Compute residual R = B - op(A) * X,
* where op(A) = A, A**T, or A**H, depending on TRANS.
*
CALL ZCOPY( N, X( 1, J ), 1, WORK, 1 )
CALL ZTRMV( UPLO, TRANS, DIAG, N, A, LDA, WORK, 1 )
CALL ZAXPY( N, -ONE, B( 1, J ), 1, WORK, 1 )
*
* Compute componentwise relative backward error from formula
*
* max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
*
* where abs(Z) is the componentwise absolute value of the matrix
* or vector Z. If the i-th component of the denominator is less
* than SAFE2, then SAFE1 is added to the i-th components of the
* numerator and denominator before dividing.
*
DO 20 I = 1, N
RWORK( I ) = CABS1( B( I, J ) )
20 CONTINUE
*
IF( NOTRAN ) THEN
*
* Compute abs(A)*abs(X) + abs(B).
*
IF( UPPER ) THEN
IF( NOUNIT ) THEN
DO 40 K = 1, N
XK = CABS1( X( K, J ) )
DO 30 I = 1, K
RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
30 CONTINUE
40 CONTINUE
ELSE
DO 60 K = 1, N
XK = CABS1( X( K, J ) )
DO 50 I = 1, K - 1
RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
50 CONTINUE
RWORK( K ) = RWORK( K ) + XK
60 CONTINUE
END IF
ELSE
IF( NOUNIT ) THEN
DO 80 K = 1, N
XK = CABS1( X( K, J ) )
DO 70 I = K, N
RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
70 CONTINUE
80 CONTINUE
ELSE
DO 100 K = 1, N
XK = CABS1( X( K, J ) )
DO 90 I = K + 1, N
RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
90 CONTINUE
RWORK( K ) = RWORK( K ) + XK
100 CONTINUE
END IF
END IF
ELSE
*
* Compute abs(A**H)*abs(X) + abs(B).
*
IF( UPPER ) THEN
IF( NOUNIT ) THEN
DO 120 K = 1, N
S = ZERO
DO 110 I = 1, K
S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
110 CONTINUE
RWORK( K ) = RWORK( K ) + S
120 CONTINUE
ELSE
DO 140 K = 1, N
S = CABS1( X( K, J ) )
DO 130 I = 1, K - 1
S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
130 CONTINUE
RWORK( K ) = RWORK( K ) + S
140 CONTINUE
END IF
ELSE
IF( NOUNIT ) THEN
DO 160 K = 1, N
S = ZERO
DO 150 I = K, N
S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
150 CONTINUE
RWORK( K ) = RWORK( K ) + S
160 CONTINUE
ELSE
DO 180 K = 1, N
S = CABS1( X( K, J ) )
DO 170 I = K + 1, N
S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
170 CONTINUE
RWORK( K ) = RWORK( K ) + S
180 CONTINUE
END IF
END IF
END IF
S = ZERO
DO 190 I = 1, N
IF( RWORK( I ).GT.SAFE2 ) THEN
S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
ELSE
S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
$ ( RWORK( I )+SAFE1 ) )
END IF
190 CONTINUE
BERR( J ) = S
*
* Bound error from formula
*
* norm(X - XTRUE) / norm(X) .le. FERR =
* norm( abs(inv(op(A)))*
* ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
*
* where
* norm(Z) is the magnitude of the largest component of Z
* inv(op(A)) is the inverse of op(A)
* abs(Z) is the componentwise absolute value of the matrix or
* vector Z
* NZ is the maximum number of nonzeros in any row of A, plus 1
* EPS is machine epsilon
*
* The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
* is incremented by SAFE1 if the i-th component of
* abs(op(A))*abs(X) + abs(B) is less than SAFE2.
*
* Use ZLACN2 to estimate the infinity-norm of the matrix
* inv(op(A)) * diag(W),
* where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
*
DO 200 I = 1, N
IF( RWORK( I ).GT.SAFE2 ) THEN
RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
ELSE
RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
$ SAFE1
END IF
200 CONTINUE
*
KASE = 0
210 CONTINUE
CALL ZLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
IF( KASE.NE.0 ) THEN
IF( KASE.EQ.1 ) THEN
*
* Multiply by diag(W)*inv(op(A)**H).
*
CALL ZTRSV( UPLO, TRANST, DIAG, N, A, LDA, WORK, 1 )
DO 220 I = 1, N
WORK( I ) = RWORK( I )*WORK( I )
220 CONTINUE
ELSE
*
* Multiply by inv(op(A))*diag(W).
*
DO 230 I = 1, N
WORK( I ) = RWORK( I )*WORK( I )
230 CONTINUE
CALL ZTRSV( UPLO, TRANSN, DIAG, N, A, LDA, WORK, 1 )
END IF
GO TO 210
END IF
*
* Normalize error.
*
LSTRES = ZERO
DO 240 I = 1, N
LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
240 CONTINUE
IF( LSTRES.NE.ZERO )
$ FERR( J ) = FERR( J ) / LSTRES
*
250 CONTINUE
*
RETURN
*
* End of ZTRRFS
*
END
| bsd-3-clause |
maxhutch/magma | testing/lin/cppt05.f | 9 | 7148 | SUBROUTINE CPPT05( UPLO, N, NRHS, AP, B, LDB, X, LDX, XACT,
$ LDXACT, FERR, BERR, RESLTS )
*
* -- LAPACK test routine (version 3.1) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER LDB, LDX, LDXACT, N, NRHS
* ..
* .. Array Arguments ..
REAL BERR( * ), FERR( * ), RESLTS( * )
COMPLEX AP( * ), B( LDB, * ), X( LDX, * ),
$ XACT( LDXACT, * )
* ..
*
* Purpose
* =======
*
* CPPT05 tests the error bounds from iterative refinement for the
* computed solution to a system of equations A*X = B, where A is a
* Hermitian matrix in packed storage format.
*
* RESLTS(1) = test of the error bound
* = norm(X - XACT) / ( norm(X) * FERR )
*
* A large value is returned if this ratio is not less than one.
*
* RESLTS(2) = residual from the iterative refinement routine
* = the maximum of BERR / ( (n+1)*EPS + (*) ), where
* (*) = (n+1)*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i )
*
* Arguments
* =========
*
* UPLO (input) CHARACTER*1
* Specifies whether the upper or lower triangular part of the
* Hermitian matrix A is stored.
* = 'U': Upper triangular
* = 'L': Lower triangular
*
* N (input) INTEGER
* The number of rows of the matrices X, B, and XACT, and the
* order of the matrix A. N >= 0.
*
* NRHS (input) INTEGER
* The number of columns of the matrices X, B, and XACT.
* NRHS >= 0.
*
* AP (input) COMPLEX array, dimension (N*(N+1)/2)
* The upper or lower triangle of the Hermitian matrix A, packed
* columnwise in a linear array. The j-th column of A is stored
* in the array AP as follows:
* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
*
* B (input) COMPLEX array, dimension (LDB,NRHS)
* The right hand side vectors for the system of linear
* equations.
*
* LDB (input) INTEGER
* The leading dimension of the array B. LDB >= max(1,N).
*
* X (input) COMPLEX array, dimension (LDX,NRHS)
* The computed solution vectors. Each vector is stored as a
* column of the matrix X.
*
* LDX (input) INTEGER
* The leading dimension of the array X. LDX >= max(1,N).
*
* XACT (input) COMPLEX array, dimension (LDX,NRHS)
* The exact solution vectors. Each vector is stored as a
* column of the matrix XACT.
*
* LDXACT (input) INTEGER
* The leading dimension of the array XACT. LDXACT >= max(1,N).
*
* FERR (input) REAL array, dimension (NRHS)
* The estimated forward error bounds for each solution vector
* X. If XTRUE is the true solution, FERR bounds the magnitude
* of the largest entry in (X - XTRUE) divided by the magnitude
* of the largest entry in X.
*
* BERR (input) REAL array, dimension (NRHS)
* The componentwise relative backward error of each solution
* vector (i.e., the smallest relative change in any entry of A
* or B that makes X an exact solution).
*
* RESLTS (output) REAL array, dimension (2)
* The maximum over the NRHS solution vectors of the ratios:
* RESLTS(1) = norm(X - XACT) / ( norm(X) * FERR )
* RESLTS(2) = BERR / ( (n+1)*EPS + (*) )
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
* ..
* .. Local Scalars ..
LOGICAL UPPER
INTEGER I, IMAX, J, JC, K
REAL AXBI, DIFF, EPS, ERRBND, OVFL, TMP, UNFL, XNORM
COMPLEX ZDUM
* ..
* .. External Functions ..
LOGICAL LSAME
INTEGER ICAMAX
REAL SLAMCH
EXTERNAL LSAME, ICAMAX, SLAMCH
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, AIMAG, MAX, MIN, REAL
* ..
* .. Statement Functions ..
REAL CABS1
* ..
* .. Statement Function definitions ..
CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
* ..
* .. Executable Statements ..
*
* Quick exit if N = 0 or NRHS = 0.
*
IF( N.LE.0 .OR. NRHS.LE.0 ) THEN
RESLTS( 1 ) = ZERO
RESLTS( 2 ) = ZERO
RETURN
END IF
*
EPS = SLAMCH( 'Epsilon' )
UNFL = SLAMCH( 'Safe minimum' )
OVFL = ONE / UNFL
UPPER = LSAME( UPLO, 'U' )
*
* Test 1: Compute the maximum of
* norm(X - XACT) / ( norm(X) * FERR )
* over all the vectors X and XACT using the infinity-norm.
*
ERRBND = ZERO
DO 30 J = 1, NRHS
IMAX = ICAMAX( N, X( 1, J ), 1 )
XNORM = MAX( CABS1( X( IMAX, J ) ), UNFL )
DIFF = ZERO
DO 10 I = 1, N
DIFF = MAX( DIFF, CABS1( X( I, J )-XACT( I, J ) ) )
10 CONTINUE
*
IF( XNORM.GT.ONE ) THEN
GO TO 20
ELSE IF( DIFF.LE.OVFL*XNORM ) THEN
GO TO 20
ELSE
ERRBND = ONE / EPS
GO TO 30
END IF
*
20 CONTINUE
IF( DIFF / XNORM.LE.FERR( J ) ) THEN
ERRBND = MAX( ERRBND, ( DIFF / XNORM ) / FERR( J ) )
ELSE
ERRBND = ONE / EPS
END IF
30 CONTINUE
RESLTS( 1 ) = ERRBND
*
* Test 2: Compute the maximum of BERR / ( (n+1)*EPS + (*) ), where
* (*) = (n+1)*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i )
*
DO 90 K = 1, NRHS
DO 80 I = 1, N
TMP = CABS1( B( I, K ) )
IF( UPPER ) THEN
JC = ( ( I-1 )*I ) / 2
DO 40 J = 1, I - 1
TMP = TMP + CABS1( AP( JC+J ) )*CABS1( X( J, K ) )
40 CONTINUE
TMP = TMP + ABS( REAL( AP( JC+I ) ) )*CABS1( X( I, K ) )
JC = JC + I + I
DO 50 J = I + 1, N
TMP = TMP + CABS1( AP( JC ) )*CABS1( X( J, K ) )
JC = JC + J
50 CONTINUE
ELSE
JC = I
DO 60 J = 1, I - 1
TMP = TMP + CABS1( AP( JC ) )*CABS1( X( J, K ) )
JC = JC + N - J
60 CONTINUE
TMP = TMP + ABS( REAL( AP( JC ) ) )*CABS1( X( I, K ) )
DO 70 J = I + 1, N
TMP = TMP + CABS1( AP( JC+J-I ) )*CABS1( X( J, K ) )
70 CONTINUE
END IF
IF( I.EQ.1 ) THEN
AXBI = TMP
ELSE
AXBI = MIN( AXBI, TMP )
END IF
80 CONTINUE
TMP = BERR( K ) / ( ( N+1 )*EPS+( N+1 )*UNFL /
$ MAX( AXBI, ( N+1 )*UNFL ) )
IF( K.EQ.1 ) THEN
RESLTS( 2 ) = TMP
ELSE
RESLTS( 2 ) = MAX( RESLTS( 2 ), TMP )
END IF
90 CONTINUE
*
RETURN
*
* End of CPPT05
*
END
| bsd-3-clause |
mverleg/1957 | lib/lapack/sgejsv.f | 5 | 72353 | *> \brief \b SGEJSV
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download SGEJSV + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgejsv.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgejsv.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgejsv.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE SGEJSV( JOBA, JOBU, JOBV, JOBR, JOBT, JOBP,
* M, N, A, LDA, SVA, U, LDU, V, LDV,
* WORK, LWORK, IWORK, INFO )
*
* .. Scalar Arguments ..
* IMPLICIT NONE
* INTEGER INFO, LDA, LDU, LDV, LWORK, M, N
* ..
* .. Array Arguments ..
* REAL A( LDA, * ), SVA( N ), U( LDU, * ), V( LDV, * ),
* $ WORK( LWORK )
* INTEGER IWORK( * )
* CHARACTER*1 JOBA, JOBP, JOBR, JOBT, JOBU, JOBV
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> SGEJSV computes the singular value decomposition (SVD) of a real M-by-N
*> matrix [A], where M >= N. The SVD of [A] is written as
*>
*> [A] = [U] * [SIGMA] * [V]^t,
*>
*> where [SIGMA] is an N-by-N (M-by-N) matrix which is zero except for its N
*> diagonal elements, [U] is an M-by-N (or M-by-M) orthonormal matrix, and
*> [V] is an N-by-N orthogonal matrix. The diagonal elements of [SIGMA] are
*> the singular values of [A]. The columns of [U] and [V] are the left and
*> the right singular vectors of [A], respectively. The matrices [U] and [V]
*> are computed and stored in the arrays U and V, respectively. The diagonal
*> of [SIGMA] is computed and stored in the array SVA.
*> SGEJSV can sometimes compute tiny singular values and their singular vectors much
*> more accurately than other SVD routines, see below under Further Details.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] JOBA
*> \verbatim
*> JOBA is CHARACTER*1
*> Specifies the level of accuracy:
*> = 'C': This option works well (high relative accuracy) if A = B * D,
*> with well-conditioned B and arbitrary diagonal matrix D.
*> The accuracy cannot be spoiled by COLUMN scaling. The
*> accuracy of the computed output depends on the condition of
*> B, and the procedure aims at the best theoretical accuracy.
*> The relative error max_{i=1:N}|d sigma_i| / sigma_i is
*> bounded by f(M,N)*epsilon* cond(B), independent of D.
*> The input matrix is preprocessed with the QRF with column
*> pivoting. This initial preprocessing and preconditioning by
*> a rank revealing QR factorization is common for all values of
*> JOBA. Additional actions are specified as follows:
*> = 'E': Computation as with 'C' with an additional estimate of the
*> condition number of B. It provides a realistic error bound.
*> = 'F': If A = D1 * C * D2 with ill-conditioned diagonal scalings
*> D1, D2, and well-conditioned matrix C, this option gives
*> higher accuracy than the 'C' option. If the structure of the
*> input matrix is not known, and relative accuracy is
*> desirable, then this option is advisable. The input matrix A
*> is preprocessed with QR factorization with FULL (row and
*> column) pivoting.
*> = 'G' Computation as with 'F' with an additional estimate of the
*> condition number of B, where A=D*B. If A has heavily weighted
*> rows, then using this condition number gives too pessimistic
*> error bound.
*> = 'A': Small singular values are the noise and the matrix is treated
*> as numerically rank defficient. The error in the computed
*> singular values is bounded by f(m,n)*epsilon*||A||.
*> The computed SVD A = U * S * V^t restores A up to
*> f(m,n)*epsilon*||A||.
*> This gives the procedure the licence to discard (set to zero)
*> all singular values below N*epsilon*||A||.
*> = 'R': Similar as in 'A'. Rank revealing property of the initial
*> QR factorization is used do reveal (using triangular factor)
*> a gap sigma_{r+1} < epsilon * sigma_r in which case the
*> numerical RANK is declared to be r. The SVD is computed with
*> absolute error bounds, but more accurately than with 'A'.
*> \endverbatim
*>
*> \param[in] JOBU
*> \verbatim
*> JOBU is CHARACTER*1
*> Specifies whether to compute the columns of U:
*> = 'U': N columns of U are returned in the array U.
*> = 'F': full set of M left sing. vectors is returned in the array U.
*> = 'W': U may be used as workspace of length M*N. See the description
*> of U.
*> = 'N': U is not computed.
*> \endverbatim
*>
*> \param[in] JOBV
*> \verbatim
*> JOBV is CHARACTER*1
*> Specifies whether to compute the matrix V:
*> = 'V': N columns of V are returned in the array V; Jacobi rotations
*> are not explicitly accumulated.
*> = 'J': N columns of V are returned in the array V, but they are
*> computed as the product of Jacobi rotations. This option is
*> allowed only if JOBU .NE. 'N', i.e. in computing the full SVD.
*> = 'W': V may be used as workspace of length N*N. See the description
*> of V.
*> = 'N': V is not computed.
*> \endverbatim
*>
*> \param[in] JOBR
*> \verbatim
*> JOBR is CHARACTER*1
*> Specifies the RANGE for the singular values. Issues the licence to
*> set to zero small positive singular values if they are outside
*> specified range. If A .NE. 0 is scaled so that the largest singular
*> value of c*A is around SQRT(BIG), BIG=SLAMCH('O'), then JOBR issues
*> the licence to kill columns of A whose norm in c*A is less than
*> SQRT(SFMIN) (for JOBR.EQ.'R'), or less than SMALL=SFMIN/EPSLN,
*> where SFMIN=SLAMCH('S'), EPSLN=SLAMCH('E').
*> = 'N': Do not kill small columns of c*A. This option assumes that
*> BLAS and QR factorizations and triangular solvers are
*> implemented to work in that range. If the condition of A
*> is greater than BIG, use SGESVJ.
*> = 'R': RESTRICTED range for sigma(c*A) is [SQRT(SFMIN), SQRT(BIG)]
*> (roughly, as described above). This option is recommended.
*> ===========================
*> For computing the singular values in the FULL range [SFMIN,BIG]
*> use SGESVJ.
*> \endverbatim
*>
*> \param[in] JOBT
*> \verbatim
*> JOBT is CHARACTER*1
*> If the matrix is square then the procedure may determine to use
*> transposed A if A^t seems to be better with respect to convergence.
*> If the matrix is not square, JOBT is ignored. This is subject to
*> changes in the future.
*> The decision is based on two values of entropy over the adjoint
*> orbit of A^t * A. See the descriptions of WORK(6) and WORK(7).
*> = 'T': transpose if entropy test indicates possibly faster
*> convergence of Jacobi process if A^t is taken as input. If A is
*> replaced with A^t, then the row pivoting is included automatically.
*> = 'N': do not speculate.
*> This option can be used to compute only the singular values, or the
*> full SVD (U, SIGMA and V). For only one set of singular vectors
*> (U or V), the caller should provide both U and V, as one of the
*> matrices is used as workspace if the matrix A is transposed.
*> The implementer can easily remove this constraint and make the
*> code more complicated. See the descriptions of U and V.
*> \endverbatim
*>
*> \param[in] JOBP
*> \verbatim
*> JOBP is CHARACTER*1
*> Issues the licence to introduce structured perturbations to drown
*> denormalized numbers. This licence should be active if the
*> denormals are poorly implemented, causing slow computation,
*> especially in cases of fast convergence (!). For details see [1,2].
*> For the sake of simplicity, this perturbations are included only
*> when the full SVD or only the singular values are requested. The
*> implementer/user can easily add the perturbation for the cases of
*> computing one set of singular vectors.
*> = 'P': introduce perturbation
*> = 'N': do not perturb
*> \endverbatim
*>
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of rows of the input matrix A. M >= 0.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of columns of the input matrix A. M >= N >= 0.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is REAL array, dimension (LDA,N)
*> On entry, the M-by-N matrix A.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,M).
*> \endverbatim
*>
*> \param[out] SVA
*> \verbatim
*> SVA is REAL array, dimension (N)
*> On exit,
*> - For WORK(1)/WORK(2) = ONE: The singular values of A. During the
*> computation SVA contains Euclidean column norms of the
*> iterated matrices in the array A.
*> - For WORK(1) .NE. WORK(2): The singular values of A are
*> (WORK(1)/WORK(2)) * SVA(1:N). This factored form is used if
*> sigma_max(A) overflows or if small singular values have been
*> saved from underflow by scaling the input matrix A.
*> - If JOBR='R' then some of the singular values may be returned
*> as exact zeros obtained by "set to zero" because they are
*> below the numerical rank threshold or are denormalized numbers.
*> \endverbatim
*>
*> \param[out] U
*> \verbatim
*> U is REAL array, dimension ( LDU, N )
*> If JOBU = 'U', then U contains on exit the M-by-N matrix of
*> the left singular vectors.
*> If JOBU = 'F', then U contains on exit the M-by-M matrix of
*> the left singular vectors, including an ONB
*> of the orthogonal complement of the Range(A).
*> If JOBU = 'W' .AND. (JOBV.EQ.'V' .AND. JOBT.EQ.'T' .AND. M.EQ.N),
*> then U is used as workspace if the procedure
*> replaces A with A^t. In that case, [V] is computed
*> in U as left singular vectors of A^t and then
*> copied back to the V array. This 'W' option is just
*> a reminder to the caller that in this case U is
*> reserved as workspace of length N*N.
*> If JOBU = 'N' U is not referenced.
*> \endverbatim
*>
*> \param[in] LDU
*> \verbatim
*> LDU is INTEGER
*> The leading dimension of the array U, LDU >= 1.
*> IF JOBU = 'U' or 'F' or 'W', then LDU >= M.
*> \endverbatim
*>
*> \param[out] V
*> \verbatim
*> V is REAL array, dimension ( LDV, N )
*> If JOBV = 'V', 'J' then V contains on exit the N-by-N matrix of
*> the right singular vectors;
*> If JOBV = 'W', AND (JOBU.EQ.'U' AND JOBT.EQ.'T' AND M.EQ.N),
*> then V is used as workspace if the pprocedure
*> replaces A with A^t. In that case, [U] is computed
*> in V as right singular vectors of A^t and then
*> copied back to the U array. This 'W' option is just
*> a reminder to the caller that in this case V is
*> reserved as workspace of length N*N.
*> If JOBV = 'N' V is not referenced.
*> \endverbatim
*>
*> \param[in] LDV
*> \verbatim
*> LDV is INTEGER
*> The leading dimension of the array V, LDV >= 1.
*> If JOBV = 'V' or 'J' or 'W', then LDV >= N.
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is REAL array, dimension at least LWORK.
*> On exit,
*> WORK(1) = SCALE = WORK(2) / WORK(1) is the scaling factor such
*> that SCALE*SVA(1:N) are the computed singular values
*> of A. (See the description of SVA().)
*> WORK(2) = See the description of WORK(1).
*> WORK(3) = SCONDA is an estimate for the condition number of
*> column equilibrated A. (If JOBA .EQ. 'E' or 'G')
*> SCONDA is an estimate of SQRT(||(R^t * R)^(-1)||_1).
*> It is computed using SPOCON. It holds
*> N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA
*> where R is the triangular factor from the QRF of A.
*> However, if R is truncated and the numerical rank is
*> determined to be strictly smaller than N, SCONDA is
*> returned as -1, thus indicating that the smallest
*> singular values might be lost.
*>
*> If full SVD is needed, the following two condition numbers are
*> useful for the analysis of the algorithm. They are provied for
*> a developer/implementer who is familiar with the details of
*> the method.
*>
*> WORK(4) = an estimate of the scaled condition number of the
*> triangular factor in the first QR factorization.
*> WORK(5) = an estimate of the scaled condition number of the
*> triangular factor in the second QR factorization.
*> The following two parameters are computed if JOBT .EQ. 'T'.
*> They are provided for a developer/implementer who is familiar
*> with the details of the method.
*>
*> WORK(6) = the entropy of A^t*A :: this is the Shannon entropy
*> of diag(A^t*A) / Trace(A^t*A) taken as point in the
*> probability simplex.
*> WORK(7) = the entropy of A*A^t.
*> \endverbatim
*>
*> \param[in] LWORK
*> \verbatim
*> LWORK is INTEGER
*> Length of WORK to confirm proper allocation of work space.
*> LWORK depends on the job:
*>
*> If only SIGMA is needed ( JOBU.EQ.'N', JOBV.EQ.'N' ) and
*> -> .. no scaled condition estimate required (JOBE.EQ.'N'):
*> LWORK >= max(2*M+N,4*N+1,7). This is the minimal requirement.
*> ->> For optimal performance (blocked code) the optimal value
*> is LWORK >= max(2*M+N,3*N+(N+1)*NB,7). Here NB is the optimal
*> block size for DGEQP3 and DGEQRF.
*> In general, optimal LWORK is computed as
*> LWORK >= max(2*M+N,N+LWORK(DGEQP3),N+LWORK(DGEQRF), 7).
*> -> .. an estimate of the scaled condition number of A is
*> required (JOBA='E', 'G'). In this case, LWORK is the maximum
*> of the above and N*N+4*N, i.e. LWORK >= max(2*M+N,N*N+4*N,7).
*> ->> For optimal performance (blocked code) the optimal value
*> is LWORK >= max(2*M+N,3*N+(N+1)*NB, N*N+4*N, 7).
*> In general, the optimal length LWORK is computed as
*> LWORK >= max(2*M+N,N+LWORK(DGEQP3),N+LWORK(DGEQRF),
*> N+N*N+LWORK(DPOCON),7).
*>
*> If SIGMA and the right singular vectors are needed (JOBV.EQ.'V'),
*> -> the minimal requirement is LWORK >= max(2*M+N,4*N+1,7).
*> -> For optimal performance, LWORK >= max(2*M+N,3*N+(N+1)*NB,7),
*> where NB is the optimal block size for DGEQP3, DGEQRF, DGELQ,
*> DORMLQ. In general, the optimal length LWORK is computed as
*> LWORK >= max(2*M+N,N+LWORK(DGEQP3), N+LWORK(DPOCON),
*> N+LWORK(DGELQ), 2*N+LWORK(DGEQRF), N+LWORK(DORMLQ)).
*>
*> If SIGMA and the left singular vectors are needed
*> -> the minimal requirement is LWORK >= max(2*M+N,4*N+1,7).
*> -> For optimal performance:
*> if JOBU.EQ.'U' :: LWORK >= max(2*M+N,3*N+(N+1)*NB,7),
*> if JOBU.EQ.'F' :: LWORK >= max(2*M+N,3*N+(N+1)*NB,N+M*NB,7),
*> where NB is the optimal block size for DGEQP3, DGEQRF, DORMQR.
*> In general, the optimal length LWORK is computed as
*> LWORK >= max(2*M+N,N+LWORK(DGEQP3),N+LWORK(DPOCON),
*> 2*N+LWORK(DGEQRF), N+LWORK(DORMQR)).
*> Here LWORK(DORMQR) equals N*NB (for JOBU.EQ.'U') or
*> M*NB (for JOBU.EQ.'F').
*>
*> If the full SVD is needed: (JOBU.EQ.'U' or JOBU.EQ.'F') and
*> -> if JOBV.EQ.'V'
*> the minimal requirement is LWORK >= max(2*M+N,6*N+2*N*N).
*> -> if JOBV.EQ.'J' the minimal requirement is
*> LWORK >= max(2*M+N, 4*N+N*N,2*N+N*N+6).
*> -> For optimal performance, LWORK should be additionally
*> larger than N+M*NB, where NB is the optimal block size
*> for DORMQR.
*> \endverbatim
*>
*> \param[out] IWORK
*> \verbatim
*> IWORK is INTEGER array, dimension M+3*N.
*> On exit,
*> IWORK(1) = the numerical rank determined after the initial
*> QR factorization with pivoting. See the descriptions
*> of JOBA and JOBR.
*> IWORK(2) = the number of the computed nonzero singular values
*> IWORK(3) = if nonzero, a warning message:
*> If IWORK(3).EQ.1 then some of the column norms of A
*> were denormalized floats. The requested high accuracy
*> is not warranted by the data.
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> < 0 : if INFO = -i, then the i-th argument had an illegal value.
*> = 0 : successfull exit;
*> > 0 : SGEJSV did not converge in the maximal allowed number
*> of sweeps. The computed values may be inaccurate.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2015
*
*> \ingroup realGEsing
*
*> \par Further Details:
* =====================
*>
*> \verbatim
*>
*> SGEJSV implements a preconditioned Jacobi SVD algorithm. It uses SGEQP3,
*> SGEQRF, and SGELQF as preprocessors and preconditioners. Optionally, an
*> additional row pivoting can be used as a preprocessor, which in some
*> cases results in much higher accuracy. An example is matrix A with the
*> structure A = D1 * C * D2, where D1, D2 are arbitrarily ill-conditioned
*> diagonal matrices and C is well-conditioned matrix. In that case, complete
*> pivoting in the first QR factorizations provides accuracy dependent on the
*> condition number of C, and independent of D1, D2. Such higher accuracy is
*> not completely understood theoretically, but it works well in practice.
*> Further, if A can be written as A = B*D, with well-conditioned B and some
*> diagonal D, then the high accuracy is guaranteed, both theoretically and
*> in software, independent of D. For more details see [1], [2].
*> The computational range for the singular values can be the full range
*> ( UNDERFLOW,OVERFLOW ), provided that the machine arithmetic and the BLAS
*> & LAPACK routines called by SGEJSV are implemented to work in that range.
*> If that is not the case, then the restriction for safe computation with
*> the singular values in the range of normalized IEEE numbers is that the
*> spectral condition number kappa(A)=sigma_max(A)/sigma_min(A) does not
*> overflow. This code (SGEJSV) is best used in this restricted range,
*> meaning that singular values of magnitude below ||A||_2 / SLAMCH('O') are
*> returned as zeros. See JOBR for details on this.
*> Further, this implementation is somewhat slower than the one described
*> in [1,2] due to replacement of some non-LAPACK components, and because
*> the choice of some tuning parameters in the iterative part (SGESVJ) is
*> left to the implementer on a particular machine.
*> The rank revealing QR factorization (in this code: SGEQP3) should be
*> implemented as in [3]. We have a new version of SGEQP3 under development
*> that is more robust than the current one in LAPACK, with a cleaner cut in
*> rank defficient cases. It will be available in the SIGMA library [4].
*> If M is much larger than N, it is obvious that the inital QRF with
*> column pivoting can be preprocessed by the QRF without pivoting. That
*> well known trick is not used in SGEJSV because in some cases heavy row
*> weighting can be treated with complete pivoting. The overhead in cases
*> M much larger than N is then only due to pivoting, but the benefits in
*> terms of accuracy have prevailed. The implementer/user can incorporate
*> this extra QRF step easily. The implementer can also improve data movement
*> (matrix transpose, matrix copy, matrix transposed copy) - this
*> implementation of SGEJSV uses only the simplest, naive data movement.
*> \endverbatim
*
*> \par Contributors:
* ==================
*>
*> Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
*
*> \par References:
* ================
*>
*> \verbatim
*>
*> [1] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I.
*> SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342.
*> LAPACK Working note 169.
*> [2] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II.
*> SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362.
*> LAPACK Working note 170.
*> [3] Z. Drmac and Z. Bujanovic: On the failure of rank-revealing QR
*> factorization software - a case study.
*> ACM Trans. math. Softw. Vol. 35, No 2 (2008), pp. 1-28.
*> LAPACK Working note 176.
*> [4] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV,
*> QSVD, (H,K)-SVD computations.
*> Department of Mathematics, University of Zagreb, 2008.
*> \endverbatim
*
*> \par Bugs, examples and comments:
* =================================
*>
*> Please report all bugs and send interesting examples and/or comments to
*> drmac@math.hr. Thank you.
*>
* =====================================================================
SUBROUTINE SGEJSV( JOBA, JOBU, JOBV, JOBR, JOBT, JOBP,
$ M, N, A, LDA, SVA, U, LDU, V, LDV,
$ WORK, LWORK, IWORK, INFO )
*
* -- LAPACK computational routine (version 3.6.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2015
*
* .. Scalar Arguments ..
IMPLICIT NONE
INTEGER INFO, LDA, LDU, LDV, LWORK, M, N
* ..
* .. Array Arguments ..
REAL A( LDA, * ), SVA( N ), U( LDU, * ), V( LDV, * ),
$ WORK( LWORK )
INTEGER IWORK( * )
CHARACTER*1 JOBA, JOBP, JOBR, JOBT, JOBU, JOBV
* ..
*
* ===========================================================================
*
* .. Local Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
* ..
* .. Local Scalars ..
REAL AAPP, AAQQ, AATMAX, AATMIN, BIG, BIG1, COND_OK,
$ CONDR1, CONDR2, ENTRA, ENTRAT, EPSLN, MAXPRJ, SCALEM,
$ SCONDA, SFMIN, SMALL, TEMP1, USCAL1, USCAL2, XSC
INTEGER IERR, N1, NR, NUMRANK, p, q, WARNING
LOGICAL ALMORT, DEFR, ERREST, GOSCAL, JRACC, KILL, LSVEC,
$ L2ABER, L2KILL, L2PERT, L2RANK, L2TRAN,
$ NOSCAL, ROWPIV, RSVEC, TRANSP
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, ALOG, MAX, MIN, FLOAT, NINT, SIGN, SQRT
* ..
* .. External Functions ..
REAL SLAMCH, SNRM2
INTEGER ISAMAX
LOGICAL LSAME
EXTERNAL ISAMAX, LSAME, SLAMCH, SNRM2
* ..
* .. External Subroutines ..
EXTERNAL SCOPY, SGELQF, SGEQP3, SGEQRF, SLACPY, SLASCL,
$ SLASET, SLASSQ, SLASWP, SORGQR, SORMLQ,
$ SORMQR, SPOCON, SSCAL, SSWAP, STRSM, XERBLA
*
EXTERNAL SGESVJ
* ..
*
* Test the input arguments
*
LSVEC = LSAME( JOBU, 'U' ) .OR. LSAME( JOBU, 'F' )
JRACC = LSAME( JOBV, 'J' )
RSVEC = LSAME( JOBV, 'V' ) .OR. JRACC
ROWPIV = LSAME( JOBA, 'F' ) .OR. LSAME( JOBA, 'G' )
L2RANK = LSAME( JOBA, 'R' )
L2ABER = LSAME( JOBA, 'A' )
ERREST = LSAME( JOBA, 'E' ) .OR. LSAME( JOBA, 'G' )
L2TRAN = LSAME( JOBT, 'T' )
L2KILL = LSAME( JOBR, 'R' )
DEFR = LSAME( JOBR, 'N' )
L2PERT = LSAME( JOBP, 'P' )
*
IF ( .NOT.(ROWPIV .OR. L2RANK .OR. L2ABER .OR.
$ ERREST .OR. LSAME( JOBA, 'C' ) )) THEN
INFO = - 1
ELSE IF ( .NOT.( LSVEC .OR. LSAME( JOBU, 'N' ) .OR.
$ LSAME( JOBU, 'W' )) ) THEN
INFO = - 2
ELSE IF ( .NOT.( RSVEC .OR. LSAME( JOBV, 'N' ) .OR.
$ LSAME( JOBV, 'W' )) .OR. ( JRACC .AND. (.NOT.LSVEC) ) ) THEN
INFO = - 3
ELSE IF ( .NOT. ( L2KILL .OR. DEFR ) ) THEN
INFO = - 4
ELSE IF ( .NOT. ( L2TRAN .OR. LSAME( JOBT, 'N' ) ) ) THEN
INFO = - 5
ELSE IF ( .NOT. ( L2PERT .OR. LSAME( JOBP, 'N' ) ) ) THEN
INFO = - 6
ELSE IF ( M .LT. 0 ) THEN
INFO = - 7
ELSE IF ( ( N .LT. 0 ) .OR. ( N .GT. M ) ) THEN
INFO = - 8
ELSE IF ( LDA .LT. M ) THEN
INFO = - 10
ELSE IF ( LSVEC .AND. ( LDU .LT. M ) ) THEN
INFO = - 13
ELSE IF ( RSVEC .AND. ( LDV .LT. N ) ) THEN
INFO = - 14
ELSE IF ( (.NOT.(LSVEC .OR. RSVEC .OR. ERREST).AND.
$ (LWORK .LT. MAX(7,4*N+1,2*M+N))) .OR.
$ (.NOT.(LSVEC .OR. RSVEC) .AND. ERREST .AND.
$ (LWORK .LT. MAX(7,4*N+N*N,2*M+N))) .OR.
$ (LSVEC .AND. (.NOT.RSVEC) .AND. (LWORK .LT. MAX(7,2*M+N,4*N+1)))
$ .OR.
$ (RSVEC .AND. (.NOT.LSVEC) .AND. (LWORK .LT. MAX(7,2*M+N,4*N+1)))
$ .OR.
$ (LSVEC .AND. RSVEC .AND. (.NOT.JRACC) .AND.
$ (LWORK.LT.MAX(2*M+N,6*N+2*N*N)))
$ .OR. (LSVEC .AND. RSVEC .AND. JRACC .AND.
$ LWORK.LT.MAX(2*M+N,4*N+N*N,2*N+N*N+6)))
$ THEN
INFO = - 17
ELSE
* #:)
INFO = 0
END IF
*
IF ( INFO .NE. 0 ) THEN
* #:(
CALL XERBLA( 'SGEJSV', - INFO )
RETURN
END IF
*
* Quick return for void matrix (Y3K safe)
* #:)
IF ( ( M .EQ. 0 ) .OR. ( N .EQ. 0 ) ) RETURN
*
* Determine whether the matrix U should be M x N or M x M
*
IF ( LSVEC ) THEN
N1 = N
IF ( LSAME( JOBU, 'F' ) ) N1 = M
END IF
*
* Set numerical parameters
*
*! NOTE: Make sure SLAMCH() does not fail on the target architecture.
*
EPSLN = SLAMCH('Epsilon')
SFMIN = SLAMCH('SafeMinimum')
SMALL = SFMIN / EPSLN
BIG = SLAMCH('O')
* BIG = ONE / SFMIN
*
* Initialize SVA(1:N) = diag( ||A e_i||_2 )_1^N
*
*(!) If necessary, scale SVA() to protect the largest norm from
* overflow. It is possible that this scaling pushes the smallest
* column norm left from the underflow threshold (extreme case).
*
SCALEM = ONE / SQRT(FLOAT(M)*FLOAT(N))
NOSCAL = .TRUE.
GOSCAL = .TRUE.
DO 1874 p = 1, N
AAPP = ZERO
AAQQ = ONE
CALL SLASSQ( M, A(1,p), 1, AAPP, AAQQ )
IF ( AAPP .GT. BIG ) THEN
INFO = - 9
CALL XERBLA( 'SGEJSV', -INFO )
RETURN
END IF
AAQQ = SQRT(AAQQ)
IF ( ( AAPP .LT. (BIG / AAQQ) ) .AND. NOSCAL ) THEN
SVA(p) = AAPP * AAQQ
ELSE
NOSCAL = .FALSE.
SVA(p) = AAPP * ( AAQQ * SCALEM )
IF ( GOSCAL ) THEN
GOSCAL = .FALSE.
CALL SSCAL( p-1, SCALEM, SVA, 1 )
END IF
END IF
1874 CONTINUE
*
IF ( NOSCAL ) SCALEM = ONE
*
AAPP = ZERO
AAQQ = BIG
DO 4781 p = 1, N
AAPP = MAX( AAPP, SVA(p) )
IF ( SVA(p) .NE. ZERO ) AAQQ = MIN( AAQQ, SVA(p) )
4781 CONTINUE
*
* Quick return for zero M x N matrix
* #:)
IF ( AAPP .EQ. ZERO ) THEN
IF ( LSVEC ) CALL SLASET( 'G', M, N1, ZERO, ONE, U, LDU )
IF ( RSVEC ) CALL SLASET( 'G', N, N, ZERO, ONE, V, LDV )
WORK(1) = ONE
WORK(2) = ONE
IF ( ERREST ) WORK(3) = ONE
IF ( LSVEC .AND. RSVEC ) THEN
WORK(4) = ONE
WORK(5) = ONE
END IF
IF ( L2TRAN ) THEN
WORK(6) = ZERO
WORK(7) = ZERO
END IF
IWORK(1) = 0
IWORK(2) = 0
IWORK(3) = 0
RETURN
END IF
*
* Issue warning if denormalized column norms detected. Override the
* high relative accuracy request. Issue licence to kill columns
* (set them to zero) whose norm is less than sigma_max / BIG (roughly).
* #:(
WARNING = 0
IF ( AAQQ .LE. SFMIN ) THEN
L2RANK = .TRUE.
L2KILL = .TRUE.
WARNING = 1
END IF
*
* Quick return for one-column matrix
* #:)
IF ( N .EQ. 1 ) THEN
*
IF ( LSVEC ) THEN
CALL SLASCL( 'G',0,0,SVA(1),SCALEM, M,1,A(1,1),LDA,IERR )
CALL SLACPY( 'A', M, 1, A, LDA, U, LDU )
* computing all M left singular vectors of the M x 1 matrix
IF ( N1 .NE. N ) THEN
CALL SGEQRF( M, N, U,LDU, WORK, WORK(N+1),LWORK-N,IERR )
CALL SORGQR( M,N1,1, U,LDU,WORK,WORK(N+1),LWORK-N,IERR )
CALL SCOPY( M, A(1,1), 1, U(1,1), 1 )
END IF
END IF
IF ( RSVEC ) THEN
V(1,1) = ONE
END IF
IF ( SVA(1) .LT. (BIG*SCALEM) ) THEN
SVA(1) = SVA(1) / SCALEM
SCALEM = ONE
END IF
WORK(1) = ONE / SCALEM
WORK(2) = ONE
IF ( SVA(1) .NE. ZERO ) THEN
IWORK(1) = 1
IF ( ( SVA(1) / SCALEM) .GE. SFMIN ) THEN
IWORK(2) = 1
ELSE
IWORK(2) = 0
END IF
ELSE
IWORK(1) = 0
IWORK(2) = 0
END IF
IF ( ERREST ) WORK(3) = ONE
IF ( LSVEC .AND. RSVEC ) THEN
WORK(4) = ONE
WORK(5) = ONE
END IF
IF ( L2TRAN ) THEN
WORK(6) = ZERO
WORK(7) = ZERO
END IF
RETURN
*
END IF
*
TRANSP = .FALSE.
L2TRAN = L2TRAN .AND. ( M .EQ. N )
*
AATMAX = -ONE
AATMIN = BIG
IF ( ROWPIV .OR. L2TRAN ) THEN
*
* Compute the row norms, needed to determine row pivoting sequence
* (in the case of heavily row weighted A, row pivoting is strongly
* advised) and to collect information needed to compare the
* structures of A * A^t and A^t * A (in the case L2TRAN.EQ..TRUE.).
*
IF ( L2TRAN ) THEN
DO 1950 p = 1, M
XSC = ZERO
TEMP1 = ONE
CALL SLASSQ( N, A(p,1), LDA, XSC, TEMP1 )
* SLASSQ gets both the ell_2 and the ell_infinity norm
* in one pass through the vector
WORK(M+N+p) = XSC * SCALEM
WORK(N+p) = XSC * (SCALEM*SQRT(TEMP1))
AATMAX = MAX( AATMAX, WORK(N+p) )
IF (WORK(N+p) .NE. ZERO) AATMIN = MIN(AATMIN,WORK(N+p))
1950 CONTINUE
ELSE
DO 1904 p = 1, M
WORK(M+N+p) = SCALEM*ABS( A(p,ISAMAX(N,A(p,1),LDA)) )
AATMAX = MAX( AATMAX, WORK(M+N+p) )
AATMIN = MIN( AATMIN, WORK(M+N+p) )
1904 CONTINUE
END IF
*
END IF
*
* For square matrix A try to determine whether A^t would be better
* input for the preconditioned Jacobi SVD, with faster convergence.
* The decision is based on an O(N) function of the vector of column
* and row norms of A, based on the Shannon entropy. This should give
* the right choice in most cases when the difference actually matters.
* It may fail and pick the slower converging side.
*
ENTRA = ZERO
ENTRAT = ZERO
IF ( L2TRAN ) THEN
*
XSC = ZERO
TEMP1 = ONE
CALL SLASSQ( N, SVA, 1, XSC, TEMP1 )
TEMP1 = ONE / TEMP1
*
ENTRA = ZERO
DO 1113 p = 1, N
BIG1 = ( ( SVA(p) / XSC )**2 ) * TEMP1
IF ( BIG1 .NE. ZERO ) ENTRA = ENTRA + BIG1 * ALOG(BIG1)
1113 CONTINUE
ENTRA = - ENTRA / ALOG(FLOAT(N))
*
* Now, SVA().^2/Trace(A^t * A) is a point in the probability simplex.
* It is derived from the diagonal of A^t * A. Do the same with the
* diagonal of A * A^t, compute the entropy of the corresponding
* probability distribution. Note that A * A^t and A^t * A have the
* same trace.
*
ENTRAT = ZERO
DO 1114 p = N+1, N+M
BIG1 = ( ( WORK(p) / XSC )**2 ) * TEMP1
IF ( BIG1 .NE. ZERO ) ENTRAT = ENTRAT + BIG1 * ALOG(BIG1)
1114 CONTINUE
ENTRAT = - ENTRAT / ALOG(FLOAT(M))
*
* Analyze the entropies and decide A or A^t. Smaller entropy
* usually means better input for the algorithm.
*
TRANSP = ( ENTRAT .LT. ENTRA )
*
* If A^t is better than A, transpose A.
*
IF ( TRANSP ) THEN
* In an optimal implementation, this trivial transpose
* should be replaced with faster transpose.
DO 1115 p = 1, N - 1
DO 1116 q = p + 1, N
TEMP1 = A(q,p)
A(q,p) = A(p,q)
A(p,q) = TEMP1
1116 CONTINUE
1115 CONTINUE
DO 1117 p = 1, N
WORK(M+N+p) = SVA(p)
SVA(p) = WORK(N+p)
1117 CONTINUE
TEMP1 = AAPP
AAPP = AATMAX
AATMAX = TEMP1
TEMP1 = AAQQ
AAQQ = AATMIN
AATMIN = TEMP1
KILL = LSVEC
LSVEC = RSVEC
RSVEC = KILL
IF ( LSVEC ) N1 = N
*
ROWPIV = .TRUE.
END IF
*
END IF
* END IF L2TRAN
*
* Scale the matrix so that its maximal singular value remains less
* than SQRT(BIG) -- the matrix is scaled so that its maximal column
* has Euclidean norm equal to SQRT(BIG/N). The only reason to keep
* SQRT(BIG) instead of BIG is the fact that SGEJSV uses LAPACK and
* BLAS routines that, in some implementations, are not capable of
* working in the full interval [SFMIN,BIG] and that they may provoke
* overflows in the intermediate results. If the singular values spread
* from SFMIN to BIG, then SGESVJ will compute them. So, in that case,
* one should use SGESVJ instead of SGEJSV.
*
BIG1 = SQRT( BIG )
TEMP1 = SQRT( BIG / FLOAT(N) )
*
CALL SLASCL( 'G', 0, 0, AAPP, TEMP1, N, 1, SVA, N, IERR )
IF ( AAQQ .GT. (AAPP * SFMIN) ) THEN
AAQQ = ( AAQQ / AAPP ) * TEMP1
ELSE
AAQQ = ( AAQQ * TEMP1 ) / AAPP
END IF
TEMP1 = TEMP1 * SCALEM
CALL SLASCL( 'G', 0, 0, AAPP, TEMP1, M, N, A, LDA, IERR )
*
* To undo scaling at the end of this procedure, multiply the
* computed singular values with USCAL2 / USCAL1.
*
USCAL1 = TEMP1
USCAL2 = AAPP
*
IF ( L2KILL ) THEN
* L2KILL enforces computation of nonzero singular values in
* the restricted range of condition number of the initial A,
* sigma_max(A) / sigma_min(A) approx. SQRT(BIG)/SQRT(SFMIN).
XSC = SQRT( SFMIN )
ELSE
XSC = SMALL
*
* Now, if the condition number of A is too big,
* sigma_max(A) / sigma_min(A) .GT. SQRT(BIG/N) * EPSLN / SFMIN,
* as a precaution measure, the full SVD is computed using SGESVJ
* with accumulated Jacobi rotations. This provides numerically
* more robust computation, at the cost of slightly increased run
* time. Depending on the concrete implementation of BLAS and LAPACK
* (i.e. how they behave in presence of extreme ill-conditioning) the
* implementor may decide to remove this switch.
IF ( ( AAQQ.LT.SQRT(SFMIN) ) .AND. LSVEC .AND. RSVEC ) THEN
JRACC = .TRUE.
END IF
*
END IF
IF ( AAQQ .LT. XSC ) THEN
DO 700 p = 1, N
IF ( SVA(p) .LT. XSC ) THEN
CALL SLASET( 'A', M, 1, ZERO, ZERO, A(1,p), LDA )
SVA(p) = ZERO
END IF
700 CONTINUE
END IF
*
* Preconditioning using QR factorization with pivoting
*
IF ( ROWPIV ) THEN
* Optional row permutation (Bjoerck row pivoting):
* A result by Cox and Higham shows that the Bjoerck's
* row pivoting combined with standard column pivoting
* has similar effect as Powell-Reid complete pivoting.
* The ell-infinity norms of A are made nonincreasing.
DO 1952 p = 1, M - 1
q = ISAMAX( M-p+1, WORK(M+N+p), 1 ) + p - 1
IWORK(2*N+p) = q
IF ( p .NE. q ) THEN
TEMP1 = WORK(M+N+p)
WORK(M+N+p) = WORK(M+N+q)
WORK(M+N+q) = TEMP1
END IF
1952 CONTINUE
CALL SLASWP( N, A, LDA, 1, M-1, IWORK(2*N+1), 1 )
END IF
*
* End of the preparation phase (scaling, optional sorting and
* transposing, optional flushing of small columns).
*
* Preconditioning
*
* If the full SVD is needed, the right singular vectors are computed
* from a matrix equation, and for that we need theoretical analysis
* of the Businger-Golub pivoting. So we use SGEQP3 as the first RR QRF.
* In all other cases the first RR QRF can be chosen by other criteria
* (eg speed by replacing global with restricted window pivoting, such
* as in SGEQPX from TOMS # 782). Good results will be obtained using
* SGEQPX with properly (!) chosen numerical parameters.
* Any improvement of SGEQP3 improves overal performance of SGEJSV.
*
* A * P1 = Q1 * [ R1^t 0]^t:
DO 1963 p = 1, N
* .. all columns are free columns
IWORK(p) = 0
1963 CONTINUE
CALL SGEQP3( M,N,A,LDA, IWORK,WORK, WORK(N+1),LWORK-N, IERR )
*
* The upper triangular matrix R1 from the first QRF is inspected for
* rank deficiency and possibilities for deflation, or possible
* ill-conditioning. Depending on the user specified flag L2RANK,
* the procedure explores possibilities to reduce the numerical
* rank by inspecting the computed upper triangular factor. If
* L2RANK or L2ABER are up, then SGEJSV will compute the SVD of
* A + dA, where ||dA|| <= f(M,N)*EPSLN.
*
NR = 1
IF ( L2ABER ) THEN
* Standard absolute error bound suffices. All sigma_i with
* sigma_i < N*EPSLN*||A|| are flushed to zero. This is an
* agressive enforcement of lower numerical rank by introducing a
* backward error of the order of N*EPSLN*||A||.
TEMP1 = SQRT(FLOAT(N))*EPSLN
DO 3001 p = 2, N
IF ( ABS(A(p,p)) .GE. (TEMP1*ABS(A(1,1))) ) THEN
NR = NR + 1
ELSE
GO TO 3002
END IF
3001 CONTINUE
3002 CONTINUE
ELSE IF ( L2RANK ) THEN
* .. similarly as above, only slightly more gentle (less agressive).
* Sudden drop on the diagonal of R1 is used as the criterion for
* close-to-rank-defficient.
TEMP1 = SQRT(SFMIN)
DO 3401 p = 2, N
IF ( ( ABS(A(p,p)) .LT. (EPSLN*ABS(A(p-1,p-1))) ) .OR.
$ ( ABS(A(p,p)) .LT. SMALL ) .OR.
$ ( L2KILL .AND. (ABS(A(p,p)) .LT. TEMP1) ) ) GO TO 3402
NR = NR + 1
3401 CONTINUE
3402 CONTINUE
*
ELSE
* The goal is high relative accuracy. However, if the matrix
* has high scaled condition number the relative accuracy is in
* general not feasible. Later on, a condition number estimator
* will be deployed to estimate the scaled condition number.
* Here we just remove the underflowed part of the triangular
* factor. This prevents the situation in which the code is
* working hard to get the accuracy not warranted by the data.
TEMP1 = SQRT(SFMIN)
DO 3301 p = 2, N
IF ( ( ABS(A(p,p)) .LT. SMALL ) .OR.
$ ( L2KILL .AND. (ABS(A(p,p)) .LT. TEMP1) ) ) GO TO 3302
NR = NR + 1
3301 CONTINUE
3302 CONTINUE
*
END IF
*
ALMORT = .FALSE.
IF ( NR .EQ. N ) THEN
MAXPRJ = ONE
DO 3051 p = 2, N
TEMP1 = ABS(A(p,p)) / SVA(IWORK(p))
MAXPRJ = MIN( MAXPRJ, TEMP1 )
3051 CONTINUE
IF ( MAXPRJ**2 .GE. ONE - FLOAT(N)*EPSLN ) ALMORT = .TRUE.
END IF
*
*
SCONDA = - ONE
CONDR1 = - ONE
CONDR2 = - ONE
*
IF ( ERREST ) THEN
IF ( N .EQ. NR ) THEN
IF ( RSVEC ) THEN
* .. V is available as workspace
CALL SLACPY( 'U', N, N, A, LDA, V, LDV )
DO 3053 p = 1, N
TEMP1 = SVA(IWORK(p))
CALL SSCAL( p, ONE/TEMP1, V(1,p), 1 )
3053 CONTINUE
CALL SPOCON( 'U', N, V, LDV, ONE, TEMP1,
$ WORK(N+1), IWORK(2*N+M+1), IERR )
ELSE IF ( LSVEC ) THEN
* .. U is available as workspace
CALL SLACPY( 'U', N, N, A, LDA, U, LDU )
DO 3054 p = 1, N
TEMP1 = SVA(IWORK(p))
CALL SSCAL( p, ONE/TEMP1, U(1,p), 1 )
3054 CONTINUE
CALL SPOCON( 'U', N, U, LDU, ONE, TEMP1,
$ WORK(N+1), IWORK(2*N+M+1), IERR )
ELSE
CALL SLACPY( 'U', N, N, A, LDA, WORK(N+1), N )
DO 3052 p = 1, N
TEMP1 = SVA(IWORK(p))
CALL SSCAL( p, ONE/TEMP1, WORK(N+(p-1)*N+1), 1 )
3052 CONTINUE
* .. the columns of R are scaled to have unit Euclidean lengths.
CALL SPOCON( 'U', N, WORK(N+1), N, ONE, TEMP1,
$ WORK(N+N*N+1), IWORK(2*N+M+1), IERR )
END IF
SCONDA = ONE / SQRT(TEMP1)
* SCONDA is an estimate of SQRT(||(R^t * R)^(-1)||_1).
* N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA
ELSE
SCONDA = - ONE
END IF
END IF
*
L2PERT = L2PERT .AND. ( ABS( A(1,1)/A(NR,NR) ) .GT. SQRT(BIG1) )
* If there is no violent scaling, artificial perturbation is not needed.
*
* Phase 3:
*
IF ( .NOT. ( RSVEC .OR. LSVEC ) ) THEN
*
* Singular Values only
*
* .. transpose A(1:NR,1:N)
DO 1946 p = 1, MIN( N-1, NR )
CALL SCOPY( N-p, A(p,p+1), LDA, A(p+1,p), 1 )
1946 CONTINUE
*
* The following two DO-loops introduce small relative perturbation
* into the strict upper triangle of the lower triangular matrix.
* Small entries below the main diagonal are also changed.
* This modification is useful if the computing environment does not
* provide/allow FLUSH TO ZERO underflow, for it prevents many
* annoying denormalized numbers in case of strongly scaled matrices.
* The perturbation is structured so that it does not introduce any
* new perturbation of the singular values, and it does not destroy
* the job done by the preconditioner.
* The licence for this perturbation is in the variable L2PERT, which
* should be .FALSE. if FLUSH TO ZERO underflow is active.
*
IF ( .NOT. ALMORT ) THEN
*
IF ( L2PERT ) THEN
* XSC = SQRT(SMALL)
XSC = EPSLN / FLOAT(N)
DO 4947 q = 1, NR
TEMP1 = XSC*ABS(A(q,q))
DO 4949 p = 1, N
IF ( ( (p.GT.q) .AND. (ABS(A(p,q)).LE.TEMP1) )
$ .OR. ( p .LT. q ) )
$ A(p,q) = SIGN( TEMP1, A(p,q) )
4949 CONTINUE
4947 CONTINUE
ELSE
CALL SLASET( 'U', NR-1,NR-1, ZERO,ZERO, A(1,2),LDA )
END IF
*
* .. second preconditioning using the QR factorization
*
CALL SGEQRF( N,NR, A,LDA, WORK, WORK(N+1),LWORK-N, IERR )
*
* .. and transpose upper to lower triangular
DO 1948 p = 1, NR - 1
CALL SCOPY( NR-p, A(p,p+1), LDA, A(p+1,p), 1 )
1948 CONTINUE
*
END IF
*
* Row-cyclic Jacobi SVD algorithm with column pivoting
*
* .. again some perturbation (a "background noise") is added
* to drown denormals
IF ( L2PERT ) THEN
* XSC = SQRT(SMALL)
XSC = EPSLN / FLOAT(N)
DO 1947 q = 1, NR
TEMP1 = XSC*ABS(A(q,q))
DO 1949 p = 1, NR
IF ( ( (p.GT.q) .AND. (ABS(A(p,q)).LE.TEMP1) )
$ .OR. ( p .LT. q ) )
$ A(p,q) = SIGN( TEMP1, A(p,q) )
1949 CONTINUE
1947 CONTINUE
ELSE
CALL SLASET( 'U', NR-1, NR-1, ZERO, ZERO, A(1,2), LDA )
END IF
*
* .. and one-sided Jacobi rotations are started on a lower
* triangular matrix (plus perturbation which is ignored in
* the part which destroys triangular form (confusing?!))
*
CALL SGESVJ( 'L', 'NoU', 'NoV', NR, NR, A, LDA, SVA,
$ N, V, LDV, WORK, LWORK, INFO )
*
SCALEM = WORK(1)
NUMRANK = NINT(WORK(2))
*
*
ELSE IF ( RSVEC .AND. ( .NOT. LSVEC ) ) THEN
*
* -> Singular Values and Right Singular Vectors <-
*
IF ( ALMORT ) THEN
*
* .. in this case NR equals N
DO 1998 p = 1, NR
CALL SCOPY( N-p+1, A(p,p), LDA, V(p,p), 1 )
1998 CONTINUE
CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
*
CALL SGESVJ( 'L','U','N', N, NR, V,LDV, SVA, NR, A,LDA,
$ WORK, LWORK, INFO )
SCALEM = WORK(1)
NUMRANK = NINT(WORK(2))
ELSE
*
* .. two more QR factorizations ( one QRF is not enough, two require
* accumulated product of Jacobi rotations, three are perfect )
*
CALL SLASET( 'Lower', NR-1, NR-1, ZERO, ZERO, A(2,1), LDA )
CALL SGELQF( NR, N, A, LDA, WORK, WORK(N+1), LWORK-N, IERR)
CALL SLACPY( 'Lower', NR, NR, A, LDA, V, LDV )
CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
CALL SGEQRF( NR, NR, V, LDV, WORK(N+1), WORK(2*N+1),
$ LWORK-2*N, IERR )
DO 8998 p = 1, NR
CALL SCOPY( NR-p+1, V(p,p), LDV, V(p,p), 1 )
8998 CONTINUE
CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
*
CALL SGESVJ( 'Lower', 'U','N', NR, NR, V,LDV, SVA, NR, U,
$ LDU, WORK(N+1), LWORK-N, INFO )
SCALEM = WORK(N+1)
NUMRANK = NINT(WORK(N+2))
IF ( NR .LT. N ) THEN
CALL SLASET( 'A',N-NR, NR, ZERO,ZERO, V(NR+1,1), LDV )
CALL SLASET( 'A',NR, N-NR, ZERO,ZERO, V(1,NR+1), LDV )
CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE, V(NR+1,NR+1), LDV )
END IF
*
CALL SORMLQ( 'Left', 'Transpose', N, N, NR, A, LDA, WORK,
$ V, LDV, WORK(N+1), LWORK-N, IERR )
*
END IF
*
DO 8991 p = 1, N
CALL SCOPY( N, V(p,1), LDV, A(IWORK(p),1), LDA )
8991 CONTINUE
CALL SLACPY( 'All', N, N, A, LDA, V, LDV )
*
IF ( TRANSP ) THEN
CALL SLACPY( 'All', N, N, V, LDV, U, LDU )
END IF
*
ELSE IF ( LSVEC .AND. ( .NOT. RSVEC ) ) THEN
*
* .. Singular Values and Left Singular Vectors ..
*
* .. second preconditioning step to avoid need to accumulate
* Jacobi rotations in the Jacobi iterations.
DO 1965 p = 1, NR
CALL SCOPY( N-p+1, A(p,p), LDA, U(p,p), 1 )
1965 CONTINUE
CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, U(1,2), LDU )
*
CALL SGEQRF( N, NR, U, LDU, WORK(N+1), WORK(2*N+1),
$ LWORK-2*N, IERR )
*
DO 1967 p = 1, NR - 1
CALL SCOPY( NR-p, U(p,p+1), LDU, U(p+1,p), 1 )
1967 CONTINUE
CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, U(1,2), LDU )
*
CALL SGESVJ( 'Lower', 'U', 'N', NR,NR, U, LDU, SVA, NR, A,
$ LDA, WORK(N+1), LWORK-N, INFO )
SCALEM = WORK(N+1)
NUMRANK = NINT(WORK(N+2))
*
IF ( NR .LT. M ) THEN
CALL SLASET( 'A', M-NR, NR,ZERO, ZERO, U(NR+1,1), LDU )
IF ( NR .LT. N1 ) THEN
CALL SLASET( 'A',NR, N1-NR, ZERO, ZERO, U(1,NR+1), LDU )
CALL SLASET( 'A',M-NR,N1-NR,ZERO,ONE,U(NR+1,NR+1), LDU )
END IF
END IF
*
CALL SORMQR( 'Left', 'No Tr', M, N1, N, A, LDA, WORK, U,
$ LDU, WORK(N+1), LWORK-N, IERR )
*
IF ( ROWPIV )
$ CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
*
DO 1974 p = 1, N1
XSC = ONE / SNRM2( M, U(1,p), 1 )
CALL SSCAL( M, XSC, U(1,p), 1 )
1974 CONTINUE
*
IF ( TRANSP ) THEN
CALL SLACPY( 'All', N, N, U, LDU, V, LDV )
END IF
*
ELSE
*
* .. Full SVD ..
*
IF ( .NOT. JRACC ) THEN
*
IF ( .NOT. ALMORT ) THEN
*
* Second Preconditioning Step (QRF [with pivoting])
* Note that the composition of TRANSPOSE, QRF and TRANSPOSE is
* equivalent to an LQF CALL. Since in many libraries the QRF
* seems to be better optimized than the LQF, we do explicit
* transpose and use the QRF. This is subject to changes in an
* optimized implementation of SGEJSV.
*
DO 1968 p = 1, NR
CALL SCOPY( N-p+1, A(p,p), LDA, V(p,p), 1 )
1968 CONTINUE
*
* .. the following two loops perturb small entries to avoid
* denormals in the second QR factorization, where they are
* as good as zeros. This is done to avoid painfully slow
* computation with denormals. The relative size of the perturbation
* is a parameter that can be changed by the implementer.
* This perturbation device will be obsolete on machines with
* properly implemented arithmetic.
* To switch it off, set L2PERT=.FALSE. To remove it from the
* code, remove the action under L2PERT=.TRUE., leave the ELSE part.
* The following two loops should be blocked and fused with the
* transposed copy above.
*
IF ( L2PERT ) THEN
XSC = SQRT(SMALL)
DO 2969 q = 1, NR
TEMP1 = XSC*ABS( V(q,q) )
DO 2968 p = 1, N
IF ( ( p .GT. q ) .AND. ( ABS(V(p,q)) .LE. TEMP1 )
$ .OR. ( p .LT. q ) )
$ V(p,q) = SIGN( TEMP1, V(p,q) )
IF ( p .LT. q ) V(p,q) = - V(p,q)
2968 CONTINUE
2969 CONTINUE
ELSE
CALL SLASET( 'U', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
END IF
*
* Estimate the row scaled condition number of R1
* (If R1 is rectangular, N > NR, then the condition number
* of the leading NR x NR submatrix is estimated.)
*
CALL SLACPY( 'L', NR, NR, V, LDV, WORK(2*N+1), NR )
DO 3950 p = 1, NR
TEMP1 = SNRM2(NR-p+1,WORK(2*N+(p-1)*NR+p),1)
CALL SSCAL(NR-p+1,ONE/TEMP1,WORK(2*N+(p-1)*NR+p),1)
3950 CONTINUE
CALL SPOCON('Lower',NR,WORK(2*N+1),NR,ONE,TEMP1,
$ WORK(2*N+NR*NR+1),IWORK(M+2*N+1),IERR)
CONDR1 = ONE / SQRT(TEMP1)
* .. here need a second oppinion on the condition number
* .. then assume worst case scenario
* R1 is OK for inverse <=> CONDR1 .LT. FLOAT(N)
* more conservative <=> CONDR1 .LT. SQRT(FLOAT(N))
*
COND_OK = SQRT(FLOAT(NR))
*[TP] COND_OK is a tuning parameter.
IF ( CONDR1 .LT. COND_OK ) THEN
* .. the second QRF without pivoting. Note: in an optimized
* implementation, this QRF should be implemented as the QRF
* of a lower triangular matrix.
* R1^t = Q2 * R2
CALL SGEQRF( N, NR, V, LDV, WORK(N+1), WORK(2*N+1),
$ LWORK-2*N, IERR )
*
IF ( L2PERT ) THEN
XSC = SQRT(SMALL)/EPSLN
DO 3959 p = 2, NR
DO 3958 q = 1, p - 1
TEMP1 = XSC * MIN(ABS(V(p,p)),ABS(V(q,q)))
IF ( ABS(V(q,p)) .LE. TEMP1 )
$ V(q,p) = SIGN( TEMP1, V(q,p) )
3958 CONTINUE
3959 CONTINUE
END IF
*
IF ( NR .NE. N )
$ CALL SLACPY( 'A', N, NR, V, LDV, WORK(2*N+1), N )
* .. save ...
*
* .. this transposed copy should be better than naive
DO 1969 p = 1, NR - 1
CALL SCOPY( NR-p, V(p,p+1), LDV, V(p+1,p), 1 )
1969 CONTINUE
*
CONDR2 = CONDR1
*
ELSE
*
* .. ill-conditioned case: second QRF with pivoting
* Note that windowed pivoting would be equaly good
* numerically, and more run-time efficient. So, in
* an optimal implementation, the next call to SGEQP3
* should be replaced with eg. CALL SGEQPX (ACM TOMS #782)
* with properly (carefully) chosen parameters.
*
* R1^t * P2 = Q2 * R2
DO 3003 p = 1, NR
IWORK(N+p) = 0
3003 CONTINUE
CALL SGEQP3( N, NR, V, LDV, IWORK(N+1), WORK(N+1),
$ WORK(2*N+1), LWORK-2*N, IERR )
** CALL SGEQRF( N, NR, V, LDV, WORK(N+1), WORK(2*N+1),
** $ LWORK-2*N, IERR )
IF ( L2PERT ) THEN
XSC = SQRT(SMALL)
DO 3969 p = 2, NR
DO 3968 q = 1, p - 1
TEMP1 = XSC * MIN(ABS(V(p,p)),ABS(V(q,q)))
IF ( ABS(V(q,p)) .LE. TEMP1 )
$ V(q,p) = SIGN( TEMP1, V(q,p) )
3968 CONTINUE
3969 CONTINUE
END IF
*
CALL SLACPY( 'A', N, NR, V, LDV, WORK(2*N+1), N )
*
IF ( L2PERT ) THEN
XSC = SQRT(SMALL)
DO 8970 p = 2, NR
DO 8971 q = 1, p - 1
TEMP1 = XSC * MIN(ABS(V(p,p)),ABS(V(q,q)))
V(p,q) = - SIGN( TEMP1, V(q,p) )
8971 CONTINUE
8970 CONTINUE
ELSE
CALL SLASET( 'L',NR-1,NR-1,ZERO,ZERO,V(2,1),LDV )
END IF
* Now, compute R2 = L3 * Q3, the LQ factorization.
CALL SGELQF( NR, NR, V, LDV, WORK(2*N+N*NR+1),
$ WORK(2*N+N*NR+NR+1), LWORK-2*N-N*NR-NR, IERR )
* .. and estimate the condition number
CALL SLACPY( 'L',NR,NR,V,LDV,WORK(2*N+N*NR+NR+1),NR )
DO 4950 p = 1, NR
TEMP1 = SNRM2( p, WORK(2*N+N*NR+NR+p), NR )
CALL SSCAL( p, ONE/TEMP1, WORK(2*N+N*NR+NR+p), NR )
4950 CONTINUE
CALL SPOCON( 'L',NR,WORK(2*N+N*NR+NR+1),NR,ONE,TEMP1,
$ WORK(2*N+N*NR+NR+NR*NR+1),IWORK(M+2*N+1),IERR )
CONDR2 = ONE / SQRT(TEMP1)
*
IF ( CONDR2 .GE. COND_OK ) THEN
* .. save the Householder vectors used for Q3
* (this overwrittes the copy of R2, as it will not be
* needed in this branch, but it does not overwritte the
* Huseholder vectors of Q2.).
CALL SLACPY( 'U', NR, NR, V, LDV, WORK(2*N+1), N )
* .. and the rest of the information on Q3 is in
* WORK(2*N+N*NR+1:2*N+N*NR+N)
END IF
*
END IF
*
IF ( L2PERT ) THEN
XSC = SQRT(SMALL)
DO 4968 q = 2, NR
TEMP1 = XSC * V(q,q)
DO 4969 p = 1, q - 1
* V(p,q) = - SIGN( TEMP1, V(q,p) )
V(p,q) = - SIGN( TEMP1, V(p,q) )
4969 CONTINUE
4968 CONTINUE
ELSE
CALL SLASET( 'U', NR-1,NR-1, ZERO,ZERO, V(1,2), LDV )
END IF
*
* Second preconditioning finished; continue with Jacobi SVD
* The input matrix is lower trinagular.
*
* Recover the right singular vectors as solution of a well
* conditioned triangular matrix equation.
*
IF ( CONDR1 .LT. COND_OK ) THEN
*
CALL SGESVJ( 'L','U','N',NR,NR,V,LDV,SVA,NR,U,
$ LDU,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,INFO )
SCALEM = WORK(2*N+N*NR+NR+1)
NUMRANK = NINT(WORK(2*N+N*NR+NR+2))
DO 3970 p = 1, NR
CALL SCOPY( NR, V(1,p), 1, U(1,p), 1 )
CALL SSCAL( NR, SVA(p), V(1,p), 1 )
3970 CONTINUE
* .. pick the right matrix equation and solve it
*
IF ( NR .EQ. N ) THEN
* :)) .. best case, R1 is inverted. The solution of this matrix
* equation is Q2*V2 = the product of the Jacobi rotations
* used in SGESVJ, premultiplied with the orthogonal matrix
* from the second QR factorization.
CALL STRSM( 'L','U','N','N', NR,NR,ONE, A,LDA, V,LDV )
ELSE
* .. R1 is well conditioned, but non-square. Transpose(R2)
* is inverted to get the product of the Jacobi rotations
* used in SGESVJ. The Q-factor from the second QR
* factorization is then built in explicitly.
CALL STRSM('L','U','T','N',NR,NR,ONE,WORK(2*N+1),
$ N,V,LDV)
IF ( NR .LT. N ) THEN
CALL SLASET('A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV)
CALL SLASET('A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV)
CALL SLASET('A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV)
END IF
CALL SORMQR('L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
$ V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR)
END IF
*
ELSE IF ( CONDR2 .LT. COND_OK ) THEN
*
* :) .. the input matrix A is very likely a relative of
* the Kahan matrix :)
* The matrix R2 is inverted. The solution of the matrix equation
* is Q3^T*V3 = the product of the Jacobi rotations (appplied to
* the lower triangular L3 from the LQ factorization of
* R2=L3*Q3), pre-multiplied with the transposed Q3.
CALL SGESVJ( 'L', 'U', 'N', NR, NR, V, LDV, SVA, NR, U,
$ LDU, WORK(2*N+N*NR+NR+1), LWORK-2*N-N*NR-NR, INFO )
SCALEM = WORK(2*N+N*NR+NR+1)
NUMRANK = NINT(WORK(2*N+N*NR+NR+2))
DO 3870 p = 1, NR
CALL SCOPY( NR, V(1,p), 1, U(1,p), 1 )
CALL SSCAL( NR, SVA(p), U(1,p), 1 )
3870 CONTINUE
CALL STRSM('L','U','N','N',NR,NR,ONE,WORK(2*N+1),N,U,LDU)
* .. apply the permutation from the second QR factorization
DO 873 q = 1, NR
DO 872 p = 1, NR
WORK(2*N+N*NR+NR+IWORK(N+p)) = U(p,q)
872 CONTINUE
DO 874 p = 1, NR
U(p,q) = WORK(2*N+N*NR+NR+p)
874 CONTINUE
873 CONTINUE
IF ( NR .LT. N ) THEN
CALL SLASET( 'A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV )
CALL SLASET( 'A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV )
CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV )
END IF
CALL SORMQR( 'L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
$ V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR )
ELSE
* Last line of defense.
* #:( This is a rather pathological case: no scaled condition
* improvement after two pivoted QR factorizations. Other
* possibility is that the rank revealing QR factorization
* or the condition estimator has failed, or the COND_OK
* is set very close to ONE (which is unnecessary). Normally,
* this branch should never be executed, but in rare cases of
* failure of the RRQR or condition estimator, the last line of
* defense ensures that SGEJSV completes the task.
* Compute the full SVD of L3 using SGESVJ with explicit
* accumulation of Jacobi rotations.
CALL SGESVJ( 'L', 'U', 'V', NR, NR, V, LDV, SVA, NR, U,
$ LDU, WORK(2*N+N*NR+NR+1), LWORK-2*N-N*NR-NR, INFO )
SCALEM = WORK(2*N+N*NR+NR+1)
NUMRANK = NINT(WORK(2*N+N*NR+NR+2))
IF ( NR .LT. N ) THEN
CALL SLASET( 'A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV )
CALL SLASET( 'A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV )
CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV )
END IF
CALL SORMQR( 'L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
$ V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR )
*
CALL SORMLQ( 'L', 'T', NR, NR, NR, WORK(2*N+1), N,
$ WORK(2*N+N*NR+1), U, LDU, WORK(2*N+N*NR+NR+1),
$ LWORK-2*N-N*NR-NR, IERR )
DO 773 q = 1, NR
DO 772 p = 1, NR
WORK(2*N+N*NR+NR+IWORK(N+p)) = U(p,q)
772 CONTINUE
DO 774 p = 1, NR
U(p,q) = WORK(2*N+N*NR+NR+p)
774 CONTINUE
773 CONTINUE
*
END IF
*
* Permute the rows of V using the (column) permutation from the
* first QRF. Also, scale the columns to make them unit in
* Euclidean norm. This applies to all cases.
*
TEMP1 = SQRT(FLOAT(N)) * EPSLN
DO 1972 q = 1, N
DO 972 p = 1, N
WORK(2*N+N*NR+NR+IWORK(p)) = V(p,q)
972 CONTINUE
DO 973 p = 1, N
V(p,q) = WORK(2*N+N*NR+NR+p)
973 CONTINUE
XSC = ONE / SNRM2( N, V(1,q), 1 )
IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
$ CALL SSCAL( N, XSC, V(1,q), 1 )
1972 CONTINUE
* At this moment, V contains the right singular vectors of A.
* Next, assemble the left singular vector matrix U (M x N).
IF ( NR .LT. M ) THEN
CALL SLASET( 'A', M-NR, NR, ZERO, ZERO, U(NR+1,1), LDU )
IF ( NR .LT. N1 ) THEN
CALL SLASET('A',NR,N1-NR,ZERO,ZERO,U(1,NR+1),LDU)
CALL SLASET('A',M-NR,N1-NR,ZERO,ONE,U(NR+1,NR+1),LDU)
END IF
END IF
*
* The Q matrix from the first QRF is built into the left singular
* matrix U. This applies to all cases.
*
CALL SORMQR( 'Left', 'No_Tr', M, N1, N, A, LDA, WORK, U,
$ LDU, WORK(N+1), LWORK-N, IERR )
* The columns of U are normalized. The cost is O(M*N) flops.
TEMP1 = SQRT(FLOAT(M)) * EPSLN
DO 1973 p = 1, NR
XSC = ONE / SNRM2( M, U(1,p), 1 )
IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
$ CALL SSCAL( M, XSC, U(1,p), 1 )
1973 CONTINUE
*
* If the initial QRF is computed with row pivoting, the left
* singular vectors must be adjusted.
*
IF ( ROWPIV )
$ CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
*
ELSE
*
* .. the initial matrix A has almost orthogonal columns and
* the second QRF is not needed
*
CALL SLACPY( 'Upper', N, N, A, LDA, WORK(N+1), N )
IF ( L2PERT ) THEN
XSC = SQRT(SMALL)
DO 5970 p = 2, N
TEMP1 = XSC * WORK( N + (p-1)*N + p )
DO 5971 q = 1, p - 1
WORK(N+(q-1)*N+p)=-SIGN(TEMP1,WORK(N+(p-1)*N+q))
5971 CONTINUE
5970 CONTINUE
ELSE
CALL SLASET( 'Lower',N-1,N-1,ZERO,ZERO,WORK(N+2),N )
END IF
*
CALL SGESVJ( 'Upper', 'U', 'N', N, N, WORK(N+1), N, SVA,
$ N, U, LDU, WORK(N+N*N+1), LWORK-N-N*N, INFO )
*
SCALEM = WORK(N+N*N+1)
NUMRANK = NINT(WORK(N+N*N+2))
DO 6970 p = 1, N
CALL SCOPY( N, WORK(N+(p-1)*N+1), 1, U(1,p), 1 )
CALL SSCAL( N, SVA(p), WORK(N+(p-1)*N+1), 1 )
6970 CONTINUE
*
CALL STRSM( 'Left', 'Upper', 'NoTrans', 'No UD', N, N,
$ ONE, A, LDA, WORK(N+1), N )
DO 6972 p = 1, N
CALL SCOPY( N, WORK(N+p), N, V(IWORK(p),1), LDV )
6972 CONTINUE
TEMP1 = SQRT(FLOAT(N))*EPSLN
DO 6971 p = 1, N
XSC = ONE / SNRM2( N, V(1,p), 1 )
IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
$ CALL SSCAL( N, XSC, V(1,p), 1 )
6971 CONTINUE
*
* Assemble the left singular vector matrix U (M x N).
*
IF ( N .LT. M ) THEN
CALL SLASET( 'A', M-N, N, ZERO, ZERO, U(N+1,1), LDU )
IF ( N .LT. N1 ) THEN
CALL SLASET( 'A',N, N1-N, ZERO, ZERO, U(1,N+1),LDU )
CALL SLASET( 'A',M-N,N1-N, ZERO, ONE,U(N+1,N+1),LDU )
END IF
END IF
CALL SORMQR( 'Left', 'No Tr', M, N1, N, A, LDA, WORK, U,
$ LDU, WORK(N+1), LWORK-N, IERR )
TEMP1 = SQRT(FLOAT(M))*EPSLN
DO 6973 p = 1, N1
XSC = ONE / SNRM2( M, U(1,p), 1 )
IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
$ CALL SSCAL( M, XSC, U(1,p), 1 )
6973 CONTINUE
*
IF ( ROWPIV )
$ CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
*
END IF
*
* end of the >> almost orthogonal case << in the full SVD
*
ELSE
*
* This branch deploys a preconditioned Jacobi SVD with explicitly
* accumulated rotations. It is included as optional, mainly for
* experimental purposes. It does perfom well, and can also be used.
* In this implementation, this branch will be automatically activated
* if the condition number sigma_max(A) / sigma_min(A) is predicted
* to be greater than the overflow threshold. This is because the
* a posteriori computation of the singular vectors assumes robust
* implementation of BLAS and some LAPACK procedures, capable of working
* in presence of extreme values. Since that is not always the case, ...
*
DO 7968 p = 1, NR
CALL SCOPY( N-p+1, A(p,p), LDA, V(p,p), 1 )
7968 CONTINUE
*
IF ( L2PERT ) THEN
XSC = SQRT(SMALL/EPSLN)
DO 5969 q = 1, NR
TEMP1 = XSC*ABS( V(q,q) )
DO 5968 p = 1, N
IF ( ( p .GT. q ) .AND. ( ABS(V(p,q)) .LE. TEMP1 )
$ .OR. ( p .LT. q ) )
$ V(p,q) = SIGN( TEMP1, V(p,q) )
IF ( p .LT. q ) V(p,q) = - V(p,q)
5968 CONTINUE
5969 CONTINUE
ELSE
CALL SLASET( 'U', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
END IF
CALL SGEQRF( N, NR, V, LDV, WORK(N+1), WORK(2*N+1),
$ LWORK-2*N, IERR )
CALL SLACPY( 'L', N, NR, V, LDV, WORK(2*N+1), N )
*
DO 7969 p = 1, NR
CALL SCOPY( NR-p+1, V(p,p), LDV, U(p,p), 1 )
7969 CONTINUE
IF ( L2PERT ) THEN
XSC = SQRT(SMALL/EPSLN)
DO 9970 q = 2, NR
DO 9971 p = 1, q - 1
TEMP1 = XSC * MIN(ABS(U(p,p)),ABS(U(q,q)))
U(p,q) = - SIGN( TEMP1, U(q,p) )
9971 CONTINUE
9970 CONTINUE
ELSE
CALL SLASET('U', NR-1, NR-1, ZERO, ZERO, U(1,2), LDU )
END IF
CALL SGESVJ( 'L', 'U', 'V', NR, NR, U, LDU, SVA,
$ N, V, LDV, WORK(2*N+N*NR+1), LWORK-2*N-N*NR, INFO )
SCALEM = WORK(2*N+N*NR+1)
NUMRANK = NINT(WORK(2*N+N*NR+2))
IF ( NR .LT. N ) THEN
CALL SLASET( 'A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV )
CALL SLASET( 'A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV )
CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV )
END IF
CALL SORMQR( 'L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
$ V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR )
*
* Permute the rows of V using the (column) permutation from the
* first QRF. Also, scale the columns to make them unit in
* Euclidean norm. This applies to all cases.
*
TEMP1 = SQRT(FLOAT(N)) * EPSLN
DO 7972 q = 1, N
DO 8972 p = 1, N
WORK(2*N+N*NR+NR+IWORK(p)) = V(p,q)
8972 CONTINUE
DO 8973 p = 1, N
V(p,q) = WORK(2*N+N*NR+NR+p)
8973 CONTINUE
XSC = ONE / SNRM2( N, V(1,q), 1 )
IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
$ CALL SSCAL( N, XSC, V(1,q), 1 )
7972 CONTINUE
*
* At this moment, V contains the right singular vectors of A.
* Next, assemble the left singular vector matrix U (M x N).
*
IF ( NR .LT. M ) THEN
CALL SLASET( 'A', M-NR, NR, ZERO, ZERO, U(NR+1,1), LDU )
IF ( NR .LT. N1 ) THEN
CALL SLASET( 'A',NR, N1-NR, ZERO, ZERO, U(1,NR+1),LDU )
CALL SLASET( 'A',M-NR,N1-NR, ZERO, ONE,U(NR+1,NR+1),LDU )
END IF
END IF
*
CALL SORMQR( 'Left', 'No Tr', M, N1, N, A, LDA, WORK, U,
$ LDU, WORK(N+1), LWORK-N, IERR )
*
IF ( ROWPIV )
$ CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
*
*
END IF
IF ( TRANSP ) THEN
* .. swap U and V because the procedure worked on A^t
DO 6974 p = 1, N
CALL SSWAP( N, U(1,p), 1, V(1,p), 1 )
6974 CONTINUE
END IF
*
END IF
* end of the full SVD
*
* Undo scaling, if necessary (and possible)
*
IF ( USCAL2 .LE. (BIG/SVA(1))*USCAL1 ) THEN
CALL SLASCL( 'G', 0, 0, USCAL1, USCAL2, NR, 1, SVA, N, IERR )
USCAL1 = ONE
USCAL2 = ONE
END IF
*
IF ( NR .LT. N ) THEN
DO 3004 p = NR+1, N
SVA(p) = ZERO
3004 CONTINUE
END IF
*
WORK(1) = USCAL2 * SCALEM
WORK(2) = USCAL1
IF ( ERREST ) WORK(3) = SCONDA
IF ( LSVEC .AND. RSVEC ) THEN
WORK(4) = CONDR1
WORK(5) = CONDR2
END IF
IF ( L2TRAN ) THEN
WORK(6) = ENTRA
WORK(7) = ENTRAT
END IF
*
IWORK(1) = NR
IWORK(2) = NUMRANK
IWORK(3) = WARNING
*
RETURN
* ..
* .. END OF SGEJSV
* ..
END
*
| bsd-3-clause |
davidgiven/gcc-vc4 | gcc/testsuite/gfortran.dg/fmt_cache_2.f | 169 | 1037 | ! { dg-do run }
! PR42742 Handle very large format strings correctly
! Test derived from example developed by Manfred Schwarb.
character(12) bufarr(74)
character(74*13+30) fmtstr,fmtstr2
character(1) delim
integer i,j,dat(5),pindx, loopcounter
character(983) big_string ! any less and this test fails.
do i=1,74
write(bufarr(i),'(i12)') i
enddo
delim=" "
dat(1)=2009
dat(2)=10
dat(3)=31
dat(4)=3
dat(5)=0
fmtstr="(i2,i6,4(a1,i2.2)"
open(10, status="scratch")
do j=1,74
fmtstr=fmtstr(1:len_trim(fmtstr))//",a1,a12"
fmtstr2=fmtstr(1:len_trim(fmtstr))//")"
c write(0,*) "interation ",j,": ",len_trim(fmtstr2)
do i=1,10
write(10,fmtstr2)
& i,dat(1),"-",dat(2),"-",dat(3),
& delim,dat(4),":",dat(5),
& (delim,bufarr(pindx),pindx=1,j)
enddo
loopcounter = j
enddo
close(10)
if (loopcounter /= 74) call abort
end
| gpl-2.0 |
syftalent/dist-sys-exercises-1 | lec-6/mpi/mpich-3.1.4/test/mpi/f77/attr/typeattr2f.f | 3 | 3224 | C -*- Mode: Fortran; -*-
C
C (C) 2003 by Argonne National Laboratory.
C See COPYRIGHT in top-level directory.
C This is a modified version of typeattrf.f that uses two of the
C default functions
C
program main
implicit none
include 'mpif.h'
integer errs, ierr
include 'attraints.h'
integer type1, type2
integer keyval
logical flag
C
C The only difference between the MPI-2 and MPI-1 attribute caching
C routines in Fortran is that the take an address-sized integer
C instead of a simple integer. These still are not pointers,
C so the values are still just integers.
C
errs = 0
call mtest_init( ierr )
type1 = MPI_INTEGER
C
extrastate = 1001
call mpi_type_create_keyval( MPI_TYPE_DUP_FN,
& MPI_TYPE_NULL_DELETE_FN, keyval,
& extrastate, ierr )
flag = .true.
call mpi_type_get_attr( type1, keyval, valout, flag, ierr )
if (flag) then
errs = errs + 1
print *, ' get attr returned true when no attr set'
endif
valin = 2003
call mpi_type_set_attr( type1, keyval, valin, ierr )
flag = .false.
valout = -1
call mpi_type_get_attr( type1, keyval, valout, flag, ierr )
if (valout .ne. 2003) then
errs = errs + 1
print *, 'Unexpected value (should be 2003)', valout,
& ' from attr'
endif
valin = 2001
call mpi_type_set_attr( type1, keyval, valin, ierr )
flag = .false.
valout = -1
call mpi_type_get_attr( type1, keyval, valout, flag, ierr )
if (valout .ne. 2001) then
errs = errs + 1
print *, 'Unexpected value (should be 2001)', valout,
& ' from attr'
endif
C
C Test the copy function
valin = 5001
call mpi_type_set_attr( type1, keyval, valin, ierr )
call mpi_type_dup( type1, type2, ierr )
flag = .false.
call mpi_type_get_attr( type1, keyval, valout, flag, ierr )
if (valout .ne. 5001) then
errs = errs + 1
print *, 'Unexpected output value in type ', valout
endif
flag = .false.
call mpi_type_get_attr( type2, keyval, valout, flag, ierr )
if (valout .ne. 5001) then
errs = errs + 1
print *, 'Unexpected output value in type2 ', valout
endif
C Test the delete function
call mpi_type_free( type2, ierr )
C
C Test the attr delete function
call mpi_type_dup( type1, type2, ierr )
valin = 6001
extrastate = 1001
call mpi_type_set_attr( type2, keyval, valin, ierr )
call mpi_type_delete_attr( type2, keyval, ierr )
flag = .true.
call mpi_type_get_attr( type2, keyval, valout, flag, ierr )
if (flag) then
errs = errs + 1
print *, ' Delete_attr did not delete attribute'
endif
call mpi_type_free( type2, ierr )
C
ierr = -1
call mpi_type_free_keyval( keyval, ierr )
if (ierr .ne. MPI_SUCCESS) then
errs = errs + 1
call mtestprinterror( ierr )
endif
call mtest_finalize( errs )
call mpi_finalize( ierr )
end
| mit |
Vandemar/calypso | src/Fortran_libraries/UTILS_src/MESH/set_mesh_types.f90 | 3 | 4924 | !set_mesh_types.f90
! module set_mesh_types
!
! programmed by H. Matsui on Dec., 2008
!
!! subroutine set_mesh_data_types(femmesh)
!! subroutine set_mesh_data_type_to_IO(my_rank, femmesh)
!! type(mesh_data), intent(mesh_groups) :: femmesh
!!
!! subroutine set_geometry_types_data(mesh)
!! subroutine set_mesh_type_to_IO(my_rank, mesh)
!! subroutine set_mesh_data_to_IO(my_rank, nod_comm, node, ele)
!! type(mesh_geometry), intent(inout) :: mesh
!! type(communication_table), intent(inout) :: nod_comm
!! type(node_data), intent(inout) :: node
!! type(element_data), intent(inout) :: ele
!!
!! subroutine set_nnod_surf_edge_for_type(surf_mesh, edge_mesh, &
!! & mesh)
!! type(mesh_geometry), intent(in) :: mesh
!! type(surface_geometry), intent(inout) :: surf_mesh
!! type(edge_geometry), intent(inout) :: edge_mesh
!
module set_mesh_types
!
use m_precision
!
use t_mesh_data
!
implicit none
!
! ---------------------------------------------------------------------
!
contains
!
! ---------------------------------------------------------------------
!
subroutine set_mesh_data_types(femmesh)
!
use set_group_types_4_IO
!
type(mesh_data), intent(inout) :: femmesh
!
!
call set_geometry_types_data(femmesh%mesh)
call set_grp_data_type_from_IO(femmesh%group)
!
end subroutine set_mesh_data_types
!
! ---------------------------------------------------------------------
!
subroutine set_mesh_data_type_to_IO(my_rank, femmesh)
!
use set_group_types_4_IO
!
integer(kind = kint), intent(in) :: my_rank
type(mesh_data), intent(inout) :: femmesh
!
!
call set_mesh_type_to_IO(my_rank, femmesh%mesh)
call set_grp_data_type_to_IO(femmesh%group)
!
end subroutine set_mesh_data_type_to_IO
!
! ---------------------------------------------------------------------
! ---------------------------------------------------------------------
!
subroutine set_geometry_types_data(mesh)
!
type(mesh_geometry), intent(inout) :: mesh
!
!
call set_mesh_geometry_data(mesh%nod_comm, mesh%node, mesh%ele)
!
end subroutine set_geometry_types_data
!
! ---------------------------------------------------------------------
!
subroutine set_mesh_type_to_IO(my_rank, mesh)
!
use t_mesh_data
!
integer(kind = kint), intent(in) :: my_rank
type(mesh_geometry), intent(inout) :: mesh
!
!
call set_mesh_data_to_IO &
& (my_rank, mesh%nod_comm, mesh%node, mesh%ele)
!
end subroutine set_mesh_type_to_IO
!
! --------------------------------------------------------------------
! --------------------------------------------------------------------
!
subroutine set_mesh_geometry_data(nod_comm, node, ele)
!
use set_comm_table_4_IO
use set_node_data_4_IO
use set_element_data_4_IO
!
type(communication_table), intent(inout) :: nod_comm
type(node_data), intent(inout) :: node
type(element_data), intent(inout) :: ele
!
!
call copy_comm_tbl_type_from_IO(nod_comm)
!
call copy_node_geometry_from_IO(node)
call copy_ele_connect_from_IO(ele)
!
call allocate_sph_node_geometry(node)
!
end subroutine set_mesh_geometry_data
!
! ---------------------------------------------------------------------
!
subroutine set_mesh_data_to_IO(my_rank, nod_comm, node, ele)
!
use t_comm_table
use t_geometry_data
use set_comm_table_4_IO
use set_element_data_4_IO
use set_node_data_4_IO
!
integer(kind = kint), intent(in) :: my_rank
type(communication_table), intent(in) :: nod_comm
type(node_data), intent(in) :: node
type(element_data), intent(in) :: ele
!
!
call copy_comm_tbl_type_to_IO(my_rank, nod_comm)
call copy_node_geometry_to_IO(node)
call copy_ele_connect_to_IO(ele)
!
end subroutine set_mesh_data_to_IO
!
! ---------------------------------------------------------------------
! ---------------------------------------------------------------------
!
subroutine set_nnod_surf_edge_for_type(surf_mesh, edge_mesh, &
& mesh)
!
use t_mesh_data
use t_surface_data
use t_edge_data
use set_nnod_4_ele_by_type
!
!
type(mesh_geometry), intent(in) :: mesh
type(surface_geometry), intent(inout) :: surf_mesh
type(edge_geometry), intent(inout) :: edge_mesh
!
!
call set_3D_nnod_4_sfed_by_ele(mesh%ele%nnod_4_ele, &
& surf_mesh%surf%nnod_4_surf, edge_mesh%edge%nnod_4_edge)
!
end subroutine set_nnod_surf_edge_for_type
!
! ---------------------------------------------------------------------
!
end module set_mesh_types
| gpl-3.0 |
maxhutch/magma | testing/lin/stbt06.f | 9 | 4247 | SUBROUTINE STBT06( RCOND, RCONDC, UPLO, DIAG, N, KD, AB, LDAB,
$ WORK, RAT )
*
* -- LAPACK test routine (version 3.1) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
CHARACTER DIAG, UPLO
INTEGER KD, LDAB, N
REAL RAT, RCOND, RCONDC
* ..
* .. Array Arguments ..
REAL AB( LDAB, * ), WORK( * )
* ..
*
* Purpose
* =======
*
* STBT06 computes a test ratio comparing RCOND (the reciprocal
* condition number of a triangular matrix A) and RCONDC, the estimate
* computed by STBCON. Information about the triangular matrix A is
* used if one estimate is zero and the other is non-zero to decide if
* underflow in the estimate is justified.
*
* Arguments
* =========
*
* RCOND (input) REAL
* The estimate of the reciprocal condition number obtained by
* forming the explicit inverse of the matrix A and computing
* RCOND = 1/( norm(A) * norm(inv(A)) ).
*
* RCONDC (input) REAL
* The estimate of the reciprocal condition number computed by
* STBCON.
*
* UPLO (input) CHARACTER
* Specifies whether the matrix A is upper or lower triangular.
* = 'U': Upper triangular
* = 'L': Lower triangular
*
* DIAG (input) CHARACTER
* Specifies whether or not the matrix A is unit triangular.
* = 'N': Non-unit triangular
* = 'U': Unit triangular
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* KD (input) INTEGER
* The number of superdiagonals or subdiagonals of the
* triangular band matrix A. KD >= 0.
*
* AB (input) REAL array, dimension (LDAB,N)
* The upper or lower triangular band matrix A, stored in the
* first kd+1 rows of the array. The j-th column of A is stored
* in the j-th column of the array AB as follows:
* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd).
*
* LDAB (input) INTEGER
* The leading dimension of the array AB. LDAB >= KD+1.
*
* WORK (workspace) REAL array, dimension (N)
*
* RAT (output) REAL
* The test ratio. If both RCOND and RCONDC are nonzero,
* RAT = MAX( RCOND, RCONDC )/MIN( RCOND, RCONDC ) - 1.
* If RAT = 0, the two estimates are exactly the same.
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
* ..
* .. Local Scalars ..
REAL ANORM, BIGNUM, EPS, RMAX, RMIN, SMLNUM
* ..
* .. External Functions ..
REAL SLAMCH, SLANTB
EXTERNAL SLAMCH, SLANTB
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* ..
* .. External Subroutines ..
EXTERNAL SLABAD
* ..
* .. Executable Statements ..
*
EPS = SLAMCH( 'Epsilon' )
RMAX = MAX( RCOND, RCONDC )
RMIN = MIN( RCOND, RCONDC )
*
* Do the easy cases first.
*
IF( RMIN.LT.ZERO ) THEN
*
* Invalid value for RCOND or RCONDC, return 1/EPS.
*
RAT = ONE / EPS
*
ELSE IF( RMIN.GT.ZERO ) THEN
*
* Both estimates are positive, return RMAX/RMIN - 1.
*
RAT = RMAX / RMIN - ONE
*
ELSE IF( RMAX.EQ.ZERO ) THEN
*
* Both estimates zero.
*
RAT = ZERO
*
ELSE
*
* One estimate is zero, the other is non-zero. If the matrix is
* ill-conditioned, return the nonzero estimate multiplied by
* 1/EPS; if the matrix is badly scaled, return the nonzero
* estimate multiplied by BIGNUM/TMAX, where TMAX is the maximum
* element in absolute value in A.
*
SMLNUM = SLAMCH( 'Safe minimum' )
BIGNUM = ONE / SMLNUM
CALL SLABAD( SMLNUM, BIGNUM )
ANORM = SLANTB( 'M', UPLO, DIAG, N, KD, AB, LDAB, WORK )
*
RAT = RMAX*( MIN( BIGNUM / MAX( ONE, ANORM ), ONE / EPS ) )
END IF
*
RETURN
*
* End of STBT06
*
END
| bsd-3-clause |
mverleg/1957 | lib/lapack/spoequ.f | 29 | 5485 | *> \brief \b SPOEQU
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download SPOEQU + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/spoequ.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/spoequ.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/spoequ.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE SPOEQU( N, A, LDA, S, SCOND, AMAX, INFO )
*
* .. Scalar Arguments ..
* INTEGER INFO, LDA, N
* REAL AMAX, SCOND
* ..
* .. Array Arguments ..
* REAL A( LDA, * ), S( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> SPOEQU computes row and column scalings intended to equilibrate a
*> symmetric positive definite matrix A and reduce its condition number
*> (with respect to the two-norm). S contains the scale factors,
*> S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with
*> elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal. This
*> choice of S puts the condition number of B within a factor N of the
*> smallest possible condition number over all possible diagonal
*> scalings.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrix A. N >= 0.
*> \endverbatim
*>
*> \param[in] A
*> \verbatim
*> A is REAL array, dimension (LDA,N)
*> The N-by-N symmetric positive definite matrix whose scaling
*> factors are to be computed. Only the diagonal elements of A
*> are referenced.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[out] S
*> \verbatim
*> S is REAL array, dimension (N)
*> If INFO = 0, S contains the scale factors for A.
*> \endverbatim
*>
*> \param[out] SCOND
*> \verbatim
*> SCOND is REAL
*> If INFO = 0, S contains the ratio of the smallest S(i) to
*> the largest S(i). If SCOND >= 0.1 and AMAX is neither too
*> large nor too small, it is not worth scaling by S.
*> \endverbatim
*>
*> \param[out] AMAX
*> \verbatim
*> AMAX is REAL
*> Absolute value of largest matrix element. If AMAX is very
*> close to overflow or very close to underflow, the matrix
*> should be scaled.
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value
*> > 0: if INFO = i, the i-th diagonal element is nonpositive.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup realPOcomputational
*
* =====================================================================
SUBROUTINE SPOEQU( N, A, LDA, S, SCOND, AMAX, INFO )
*
* -- LAPACK computational routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
INTEGER INFO, LDA, N
REAL AMAX, SCOND
* ..
* .. Array Arguments ..
REAL A( LDA, * ), S( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
* ..
* .. Local Scalars ..
INTEGER I
REAL SMIN
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN, SQRT
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
IF( N.LT.0 ) THEN
INFO = -1
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -3
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'SPOEQU', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 ) THEN
SCOND = ONE
AMAX = ZERO
RETURN
END IF
*
* Find the minimum and maximum diagonal elements.
*
S( 1 ) = A( 1, 1 )
SMIN = S( 1 )
AMAX = S( 1 )
DO 10 I = 2, N
S( I ) = A( I, I )
SMIN = MIN( SMIN, S( I ) )
AMAX = MAX( AMAX, S( I ) )
10 CONTINUE
*
IF( SMIN.LE.ZERO ) THEN
*
* Find the first non-positive diagonal element and return.
*
DO 20 I = 1, N
IF( S( I ).LE.ZERO ) THEN
INFO = I
RETURN
END IF
20 CONTINUE
ELSE
*
* Set the scale factors to the reciprocals
* of the diagonal elements.
*
DO 30 I = 1, N
S( I ) = ONE / SQRT( S( I ) )
30 CONTINUE
*
* Compute SCOND = min(S(I)) / max(S(I))
*
SCOND = SQRT( SMIN ) / SQRT( AMAX )
END IF
RETURN
*
* End of SPOEQU
*
END
| bsd-3-clause |
syftalent/dist-sys-exercises-1 | lec-6/mpi/mpich-3.1.4/src/binding/fortran/use_mpi_f08/wrappers_f/bsend_init_f08ts.F90 | 1 | 1508 | ! -*- Mode: Fortran; -*-
!
! (C) 2014 by Argonne National Laboratory.
! See COPYRIGHT in top-level directory.
!
subroutine MPI_Bsend_init_f08ts(buf, count, datatype, dest, tag, comm, request, ierror)
use, intrinsic :: iso_c_binding, only : c_int
use :: mpi_f08, only : MPI_Datatype, MPI_Comm, MPI_Request
use :: mpi_c_interface, only : c_Datatype, c_Comm, c_Request
use :: mpi_c_interface, only : MPIR_Bsend_init_cdesc
implicit none
type(*), dimension(..) :: buf
integer, intent(in) :: count
integer, intent(in) :: dest
integer, intent(in) :: tag
type(MPI_Datatype), intent(in) :: datatype
type(MPI_Comm), intent(in) :: comm
type(MPI_Request), intent(out) :: request
integer, optional, intent(out) :: ierror
integer(c_int) :: count_c
integer(c_int) :: dest_c
integer(c_int) :: tag_c
integer(c_Datatype) :: datatype_c
integer(c_Comm) :: comm_c
integer(c_Request) :: request_c
integer(c_int) :: ierror_c
if (c_int == kind(0)) then
ierror_c = MPIR_Bsend_init_cdesc(buf, count, datatype%MPI_VAL, dest, tag, comm%MPI_VAL, request%MPI_VAL)
else
count_c = count
datatype_c = datatype%MPI_VAL
dest_c = dest
tag_c = tag
comm_c = comm%MPI_VAL
ierror_c = MPIR_Bsend_init_cdesc(buf, count_c, datatype_c, dest_c, tag_c, comm_c, request_c)
request%MPI_VAL = request_c
end if
if (present(ierror)) ierror = ierror_c
end subroutine MPI_Bsend_init_f08ts
| mit |
maxhutch/magma | testing/lin/zlattr.f | 9 | 21420 | SUBROUTINE ZLATTR( IMAT, UPLO, TRANS, DIAG, ISEED, N, A, LDA, B,
$ WORK, RWORK, INFO )
*
* -- LAPACK test routine (version 3.1) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
CHARACTER DIAG, TRANS, UPLO
INTEGER IMAT, INFO, LDA, N
* ..
* .. Array Arguments ..
INTEGER ISEED( 4 )
DOUBLE PRECISION RWORK( * )
COMPLEX*16 A( LDA, * ), B( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* ZLATTR generates a triangular test matrix in 2-dimensional storage.
* IMAT and UPLO uniquely specify the properties of the test matrix,
* which is returned in the array A.
*
* Arguments
* =========
*
* IMAT (input) INTEGER
* An integer key describing which matrix to generate for this
* path.
*
* UPLO (input) CHARACTER*1
* Specifies whether the matrix A will be upper or lower
* triangular.
* = 'U': Upper triangular
* = 'L': Lower triangular
*
* TRANS (input) CHARACTER*1
* Specifies whether the matrix or its transpose will be used.
* = 'N': No transpose
* = 'T': Transpose
* = 'C': Conjugate transpose
*
* DIAG (output) CHARACTER*1
* Specifies whether or not the matrix A is unit triangular.
* = 'N': Non-unit triangular
* = 'U': Unit triangular
*
* ISEED (input/output) INTEGER array, dimension (4)
* The seed vector for the random number generator (used in
* ZLATMS). Modified on exit.
*
* N (input) INTEGER
* The order of the matrix to be generated.
*
* A (output) COMPLEX*16 array, dimension (LDA,N)
* The triangular matrix A. If UPLO = 'U', the leading N x N
* upper triangular part of the array A contains the upper
* triangular matrix, and the strictly lower triangular part of
* A is not referenced. If UPLO = 'L', the leading N x N lower
* triangular part of the array A contains the lower triangular
* matrix and the strictly upper triangular part of A is not
* referenced.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,N).
*
* B (output) COMPLEX*16 array, dimension (N)
* The right hand side vector, if IMAT > 10.
*
* WORK (workspace) COMPLEX*16 array, dimension (2*N)
*
* RWORK (workspace) DOUBLE PRECISION array, dimension (N)
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, TWO, ZERO
PARAMETER ( ONE = 1.0D+0, TWO = 2.0D+0, ZERO = 0.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL UPPER
CHARACTER DIST, TYPE
CHARACTER*3 PATH
INTEGER I, IY, J, JCOUNT, KL, KU, MODE
DOUBLE PRECISION ANORM, BIGNUM, BNORM, BSCAL, C, CNDNUM, REXP,
$ SFAC, SMLNUM, TEXP, TLEFT, TSCAL, ULP, UNFL, X,
$ Y, Z
COMPLEX*16 PLUS1, PLUS2, RA, RB, S, STAR1
* ..
* .. External Functions ..
LOGICAL LSAME
INTEGER IZAMAX
DOUBLE PRECISION DLAMCH, DLARND
COMPLEX*16 ZLARND
EXTERNAL LSAME, IZAMAX, DLAMCH, DLARND, ZLARND
* ..
* .. External Subroutines ..
EXTERNAL DLABAD, DLARNV, ZCOPY, ZDSCAL, ZLARNV, ZLATB4,
$ ZLATMS, ZROT, ZROTG, ZSWAP
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, DBLE, DCMPLX, DCONJG, MAX, SQRT
* ..
* .. Executable Statements ..
*
PATH( 1: 1 ) = 'Zomplex precision'
PATH( 2: 3 ) = 'TR'
UNFL = DLAMCH( 'Safe minimum' )
ULP = DLAMCH( 'Epsilon' )*DLAMCH( 'Base' )
SMLNUM = UNFL
BIGNUM = ( ONE-ULP ) / SMLNUM
CALL DLABAD( SMLNUM, BIGNUM )
IF( ( IMAT.GE.7 .AND. IMAT.LE.10 ) .OR. IMAT.EQ.18 ) THEN
DIAG = 'U'
ELSE
DIAG = 'N'
END IF
INFO = 0
*
* Quick return if N.LE.0.
*
IF( N.LE.0 )
$ RETURN
*
* Call ZLATB4 to set parameters for CLATMS.
*
UPPER = LSAME( UPLO, 'U' )
IF( UPPER ) THEN
CALL ZLATB4( PATH, IMAT, N, N, TYPE, KL, KU, ANORM, MODE,
$ CNDNUM, DIST )
ELSE
CALL ZLATB4( PATH, -IMAT, N, N, TYPE, KL, KU, ANORM, MODE,
$ CNDNUM, DIST )
END IF
*
* IMAT <= 6: Non-unit triangular matrix
*
IF( IMAT.LE.6 ) THEN
CALL ZLATMS( N, N, DIST, ISEED, TYPE, RWORK, MODE, CNDNUM,
$ ANORM, KL, KU, 'No packing', A, LDA, WORK, INFO )
*
* IMAT > 6: Unit triangular matrix
* The diagonal is deliberately set to something other than 1.
*
* IMAT = 7: Matrix is the identity
*
ELSE IF( IMAT.EQ.7 ) THEN
IF( UPPER ) THEN
DO 20 J = 1, N
DO 10 I = 1, J - 1
A( I, J ) = ZERO
10 CONTINUE
A( J, J ) = J
20 CONTINUE
ELSE
DO 40 J = 1, N
A( J, J ) = J
DO 30 I = J + 1, N
A( I, J ) = ZERO
30 CONTINUE
40 CONTINUE
END IF
*
* IMAT > 7: Non-trivial unit triangular matrix
*
* Generate a unit triangular matrix T with condition CNDNUM by
* forming a triangular matrix with known singular values and
* filling in the zero entries with Givens rotations.
*
ELSE IF( IMAT.LE.10 ) THEN
IF( UPPER ) THEN
DO 60 J = 1, N
DO 50 I = 1, J - 1
A( I, J ) = ZERO
50 CONTINUE
A( J, J ) = J
60 CONTINUE
ELSE
DO 80 J = 1, N
A( J, J ) = J
DO 70 I = J + 1, N
A( I, J ) = ZERO
70 CONTINUE
80 CONTINUE
END IF
*
* Since the trace of a unit triangular matrix is 1, the product
* of its singular values must be 1. Let s = sqrt(CNDNUM),
* x = sqrt(s) - 1/sqrt(s), y = sqrt(2/(n-2))*x, and z = x**2.
* The following triangular matrix has singular values s, 1, 1,
* ..., 1, 1/s:
*
* 1 y y y ... y y z
* 1 0 0 ... 0 0 y
* 1 0 ... 0 0 y
* . ... . . .
* . . . .
* 1 0 y
* 1 y
* 1
*
* To fill in the zeros, we first multiply by a matrix with small
* condition number of the form
*
* 1 0 0 0 0 ...
* 1 + * 0 0 ...
* 1 + 0 0 0
* 1 + * 0 0
* 1 + 0 0
* ...
* 1 + 0
* 1 0
* 1
*
* Each element marked with a '*' is formed by taking the product
* of the adjacent elements marked with '+'. The '*'s can be
* chosen freely, and the '+'s are chosen so that the inverse of
* T will have elements of the same magnitude as T. If the *'s in
* both T and inv(T) have small magnitude, T is well conditioned.
* The two offdiagonals of T are stored in WORK.
*
* The product of these two matrices has the form
*
* 1 y y y y y . y y z
* 1 + * 0 0 . 0 0 y
* 1 + 0 0 . 0 0 y
* 1 + * . . . .
* 1 + . . . .
* . . . . .
* . . . .
* 1 + y
* 1 y
* 1
*
* Now we multiply by Givens rotations, using the fact that
*
* [ c s ] [ 1 w ] [ -c -s ] = [ 1 -w ]
* [ -s c ] [ 0 1 ] [ s -c ] [ 0 1 ]
* and
* [ -c -s ] [ 1 0 ] [ c s ] = [ 1 0 ]
* [ s -c ] [ w 1 ] [ -s c ] [ -w 1 ]
*
* where c = w / sqrt(w**2+4) and s = 2 / sqrt(w**2+4).
*
STAR1 = 0.25D0*ZLARND( 5, ISEED )
SFAC = 0.5D0
PLUS1 = SFAC*ZLARND( 5, ISEED )
DO 90 J = 1, N, 2
PLUS2 = STAR1 / PLUS1
WORK( J ) = PLUS1
WORK( N+J ) = STAR1
IF( J+1.LE.N ) THEN
WORK( J+1 ) = PLUS2
WORK( N+J+1 ) = ZERO
PLUS1 = STAR1 / PLUS2
REXP = DLARND( 2, ISEED )
IF( REXP.LT.ZERO ) THEN
STAR1 = -SFAC**( ONE-REXP )*ZLARND( 5, ISEED )
ELSE
STAR1 = SFAC**( ONE+REXP )*ZLARND( 5, ISEED )
END IF
END IF
90 CONTINUE
*
X = SQRT( CNDNUM ) - 1 / SQRT( CNDNUM )
IF( N.GT.2 ) THEN
Y = SQRT( 2.D0 / ( N-2 ) )*X
ELSE
Y = ZERO
END IF
Z = X*X
*
IF( UPPER ) THEN
IF( N.GT.3 ) THEN
CALL ZCOPY( N-3, WORK, 1, A( 2, 3 ), LDA+1 )
IF( N.GT.4 )
$ CALL ZCOPY( N-4, WORK( N+1 ), 1, A( 2, 4 ), LDA+1 )
END IF
DO 100 J = 2, N - 1
A( 1, J ) = Y
A( J, N ) = Y
100 CONTINUE
A( 1, N ) = Z
ELSE
IF( N.GT.3 ) THEN
CALL ZCOPY( N-3, WORK, 1, A( 3, 2 ), LDA+1 )
IF( N.GT.4 )
$ CALL ZCOPY( N-4, WORK( N+1 ), 1, A( 4, 2 ), LDA+1 )
END IF
DO 110 J = 2, N - 1
A( J, 1 ) = Y
A( N, J ) = Y
110 CONTINUE
A( N, 1 ) = Z
END IF
*
* Fill in the zeros using Givens rotations.
*
IF( UPPER ) THEN
DO 120 J = 1, N - 1
RA = A( J, J+1 )
RB = 2.0D0
CALL ZROTG( RA, RB, C, S )
*
* Multiply by [ c s; -conjg(s) c] on the left.
*
IF( N.GT.J+1 )
$ CALL ZROT( N-J-1, A( J, J+2 ), LDA, A( J+1, J+2 ),
$ LDA, C, S )
*
* Multiply by [-c -s; conjg(s) -c] on the right.
*
IF( J.GT.1 )
$ CALL ZROT( J-1, A( 1, J+1 ), 1, A( 1, J ), 1, -C, -S )
*
* Negate A(J,J+1).
*
A( J, J+1 ) = -A( J, J+1 )
120 CONTINUE
ELSE
DO 130 J = 1, N - 1
RA = A( J+1, J )
RB = 2.0D0
CALL ZROTG( RA, RB, C, S )
S = DCONJG( S )
*
* Multiply by [ c -s; conjg(s) c] on the right.
*
IF( N.GT.J+1 )
$ CALL ZROT( N-J-1, A( J+2, J+1 ), 1, A( J+2, J ), 1, C,
$ -S )
*
* Multiply by [-c s; -conjg(s) -c] on the left.
*
IF( J.GT.1 )
$ CALL ZROT( J-1, A( J, 1 ), LDA, A( J+1, 1 ), LDA, -C,
$ S )
*
* Negate A(J+1,J).
*
A( J+1, J ) = -A( J+1, J )
130 CONTINUE
END IF
*
* IMAT > 10: Pathological test cases. These triangular matrices
* are badly scaled or badly conditioned, so when used in solving a
* triangular system they may cause overflow in the solution vector.
*
ELSE IF( IMAT.EQ.11 ) THEN
*
* Type 11: Generate a triangular matrix with elements between
* -1 and 1. Give the diagonal norm 2 to make it well-conditioned.
* Make the right hand side large so that it requires scaling.
*
IF( UPPER ) THEN
DO 140 J = 1, N
CALL ZLARNV( 4, ISEED, J-1, A( 1, J ) )
A( J, J ) = ZLARND( 5, ISEED )*TWO
140 CONTINUE
ELSE
DO 150 J = 1, N
IF( J.LT.N )
$ CALL ZLARNV( 4, ISEED, N-J, A( J+1, J ) )
A( J, J ) = ZLARND( 5, ISEED )*TWO
150 CONTINUE
END IF
*
* Set the right hand side so that the largest value is BIGNUM.
*
CALL ZLARNV( 2, ISEED, N, B )
IY = IZAMAX( N, B, 1 )
BNORM = ABS( B( IY ) )
BSCAL = BIGNUM / MAX( ONE, BNORM )
CALL ZDSCAL( N, BSCAL, B, 1 )
*
ELSE IF( IMAT.EQ.12 ) THEN
*
* Type 12: Make the first diagonal element in the solve small to
* cause immediate overflow when dividing by T(j,j).
* In type 12, the offdiagonal elements are small (CNORM(j) < 1).
*
CALL ZLARNV( 2, ISEED, N, B )
TSCAL = ONE / MAX( ONE, DBLE( N-1 ) )
IF( UPPER ) THEN
DO 160 J = 1, N
CALL ZLARNV( 4, ISEED, J-1, A( 1, J ) )
CALL ZDSCAL( J-1, TSCAL, A( 1, J ), 1 )
A( J, J ) = ZLARND( 5, ISEED )
160 CONTINUE
A( N, N ) = SMLNUM*A( N, N )
ELSE
DO 170 J = 1, N
IF( J.LT.N ) THEN
CALL ZLARNV( 4, ISEED, N-J, A( J+1, J ) )
CALL ZDSCAL( N-J, TSCAL, A( J+1, J ), 1 )
END IF
A( J, J ) = ZLARND( 5, ISEED )
170 CONTINUE
A( 1, 1 ) = SMLNUM*A( 1, 1 )
END IF
*
ELSE IF( IMAT.EQ.13 ) THEN
*
* Type 13: Make the first diagonal element in the solve small to
* cause immediate overflow when dividing by T(j,j).
* In type 13, the offdiagonal elements are O(1) (CNORM(j) > 1).
*
CALL ZLARNV( 2, ISEED, N, B )
IF( UPPER ) THEN
DO 180 J = 1, N
CALL ZLARNV( 4, ISEED, J-1, A( 1, J ) )
A( J, J ) = ZLARND( 5, ISEED )
180 CONTINUE
A( N, N ) = SMLNUM*A( N, N )
ELSE
DO 190 J = 1, N
IF( J.LT.N )
$ CALL ZLARNV( 4, ISEED, N-J, A( J+1, J ) )
A( J, J ) = ZLARND( 5, ISEED )
190 CONTINUE
A( 1, 1 ) = SMLNUM*A( 1, 1 )
END IF
*
ELSE IF( IMAT.EQ.14 ) THEN
*
* Type 14: T is diagonal with small numbers on the diagonal to
* make the growth factor underflow, but a small right hand side
* chosen so that the solution does not overflow.
*
IF( UPPER ) THEN
JCOUNT = 1
DO 210 J = N, 1, -1
DO 200 I = 1, J - 1
A( I, J ) = ZERO
200 CONTINUE
IF( JCOUNT.LE.2 ) THEN
A( J, J ) = SMLNUM*ZLARND( 5, ISEED )
ELSE
A( J, J ) = ZLARND( 5, ISEED )
END IF
JCOUNT = JCOUNT + 1
IF( JCOUNT.GT.4 )
$ JCOUNT = 1
210 CONTINUE
ELSE
JCOUNT = 1
DO 230 J = 1, N
DO 220 I = J + 1, N
A( I, J ) = ZERO
220 CONTINUE
IF( JCOUNT.LE.2 ) THEN
A( J, J ) = SMLNUM*ZLARND( 5, ISEED )
ELSE
A( J, J ) = ZLARND( 5, ISEED )
END IF
JCOUNT = JCOUNT + 1
IF( JCOUNT.GT.4 )
$ JCOUNT = 1
230 CONTINUE
END IF
*
* Set the right hand side alternately zero and small.
*
IF( UPPER ) THEN
B( 1 ) = ZERO
DO 240 I = N, 2, -2
B( I ) = ZERO
B( I-1 ) = SMLNUM*ZLARND( 5, ISEED )
240 CONTINUE
ELSE
B( N ) = ZERO
DO 250 I = 1, N - 1, 2
B( I ) = ZERO
B( I+1 ) = SMLNUM*ZLARND( 5, ISEED )
250 CONTINUE
END IF
*
ELSE IF( IMAT.EQ.15 ) THEN
*
* Type 15: Make the diagonal elements small to cause gradual
* overflow when dividing by T(j,j). To control the amount of
* scaling needed, the matrix is bidiagonal.
*
TEXP = ONE / MAX( ONE, DBLE( N-1 ) )
TSCAL = SMLNUM**TEXP
CALL ZLARNV( 4, ISEED, N, B )
IF( UPPER ) THEN
DO 270 J = 1, N
DO 260 I = 1, J - 2
A( I, J ) = 0.D0
260 CONTINUE
IF( J.GT.1 )
$ A( J-1, J ) = DCMPLX( -ONE, -ONE )
A( J, J ) = TSCAL*ZLARND( 5, ISEED )
270 CONTINUE
B( N ) = DCMPLX( ONE, ONE )
ELSE
DO 290 J = 1, N
DO 280 I = J + 2, N
A( I, J ) = 0.D0
280 CONTINUE
IF( J.LT.N )
$ A( J+1, J ) = DCMPLX( -ONE, -ONE )
A( J, J ) = TSCAL*ZLARND( 5, ISEED )
290 CONTINUE
B( 1 ) = DCMPLX( ONE, ONE )
END IF
*
ELSE IF( IMAT.EQ.16 ) THEN
*
* Type 16: One zero diagonal element.
*
IY = N / 2 + 1
IF( UPPER ) THEN
DO 300 J = 1, N
CALL ZLARNV( 4, ISEED, J-1, A( 1, J ) )
IF( J.NE.IY ) THEN
A( J, J ) = ZLARND( 5, ISEED )*TWO
ELSE
A( J, J ) = ZERO
END IF
300 CONTINUE
ELSE
DO 310 J = 1, N
IF( J.LT.N )
$ CALL ZLARNV( 4, ISEED, N-J, A( J+1, J ) )
IF( J.NE.IY ) THEN
A( J, J ) = ZLARND( 5, ISEED )*TWO
ELSE
A( J, J ) = ZERO
END IF
310 CONTINUE
END IF
CALL ZLARNV( 2, ISEED, N, B )
CALL ZDSCAL( N, TWO, B, 1 )
*
ELSE IF( IMAT.EQ.17 ) THEN
*
* Type 17: Make the offdiagonal elements large to cause overflow
* when adding a column of T. In the non-transposed case, the
* matrix is constructed to cause overflow when adding a column in
* every other step.
*
TSCAL = UNFL / ULP
TSCAL = ( ONE-ULP ) / TSCAL
DO 330 J = 1, N
DO 320 I = 1, N
A( I, J ) = 0.D0
320 CONTINUE
330 CONTINUE
TEXP = ONE
IF( UPPER ) THEN
DO 340 J = N, 2, -2
A( 1, J ) = -TSCAL / DBLE( N+1 )
A( J, J ) = ONE
B( J ) = TEXP*( ONE-ULP )
A( 1, J-1 ) = -( TSCAL / DBLE( N+1 ) ) / DBLE( N+2 )
A( J-1, J-1 ) = ONE
B( J-1 ) = TEXP*DBLE( N*N+N-1 )
TEXP = TEXP*2.D0
340 CONTINUE
B( 1 ) = ( DBLE( N+1 ) / DBLE( N+2 ) )*TSCAL
ELSE
DO 350 J = 1, N - 1, 2
A( N, J ) = -TSCAL / DBLE( N+1 )
A( J, J ) = ONE
B( J ) = TEXP*( ONE-ULP )
A( N, J+1 ) = -( TSCAL / DBLE( N+1 ) ) / DBLE( N+2 )
A( J+1, J+1 ) = ONE
B( J+1 ) = TEXP*DBLE( N*N+N-1 )
TEXP = TEXP*2.D0
350 CONTINUE
B( N ) = ( DBLE( N+1 ) / DBLE( N+2 ) )*TSCAL
END IF
*
ELSE IF( IMAT.EQ.18 ) THEN
*
* Type 18: Generate a unit triangular matrix with elements
* between -1 and 1, and make the right hand side large so that it
* requires scaling.
*
IF( UPPER ) THEN
DO 360 J = 1, N
CALL ZLARNV( 4, ISEED, J-1, A( 1, J ) )
A( J, J ) = ZERO
360 CONTINUE
ELSE
DO 370 J = 1, N
IF( J.LT.N )
$ CALL ZLARNV( 4, ISEED, N-J, A( J+1, J ) )
A( J, J ) = ZERO
370 CONTINUE
END IF
*
* Set the right hand side so that the largest value is BIGNUM.
*
CALL ZLARNV( 2, ISEED, N, B )
IY = IZAMAX( N, B, 1 )
BNORM = ABS( B( IY ) )
BSCAL = BIGNUM / MAX( ONE, BNORM )
CALL ZDSCAL( N, BSCAL, B, 1 )
*
ELSE IF( IMAT.EQ.19 ) THEN
*
* Type 19: Generate a triangular matrix with elements between
* BIGNUM/(n-1) and BIGNUM so that at least one of the column
* norms will exceed BIGNUM.
* 1/3/91: ZLATRS no longer can handle this case
*
TLEFT = BIGNUM / MAX( ONE, DBLE( N-1 ) )
TSCAL = BIGNUM*( DBLE( N-1 ) / MAX( ONE, DBLE( N ) ) )
IF( UPPER ) THEN
DO 390 J = 1, N
CALL ZLARNV( 5, ISEED, J, A( 1, J ) )
CALL DLARNV( 1, ISEED, J, RWORK )
DO 380 I = 1, J
A( I, J ) = A( I, J )*( TLEFT+RWORK( I )*TSCAL )
380 CONTINUE
390 CONTINUE
ELSE
DO 410 J = 1, N
CALL ZLARNV( 5, ISEED, N-J+1, A( J, J ) )
CALL DLARNV( 1, ISEED, N-J+1, RWORK )
DO 400 I = J, N
A( I, J ) = A( I, J )*( TLEFT+RWORK( I-J+1 )*TSCAL )
400 CONTINUE
410 CONTINUE
END IF
CALL ZLARNV( 2, ISEED, N, B )
CALL ZDSCAL( N, TWO, B, 1 )
END IF
*
* Flip the matrix if the transpose will be used.
*
IF( .NOT.LSAME( TRANS, 'N' ) ) THEN
IF( UPPER ) THEN
DO 420 J = 1, N / 2
CALL ZSWAP( N-2*J+1, A( J, J ), LDA, A( J+1, N-J+1 ),
$ -1 )
420 CONTINUE
ELSE
DO 430 J = 1, N / 2
CALL ZSWAP( N-2*J+1, A( J, J ), 1, A( N-J+1, J+1 ),
$ -LDA )
430 CONTINUE
END IF
END IF
*
RETURN
*
* End of ZLATTR
*
END
| bsd-3-clause |
Vandemar/calypso | src/Fortran_libraries/MHD_src/IO/set_control_4_model.f90 | 3 | 10578 | !>@file set_control_4_model.f90
!!@brief module set_control_4_model
!!
!!@author H. Matsui and H. Okuda
!!@date Programmed by H. Okuda in 2000
!!@n Mmodified by H. Matsui in 2001
!!@n Mmodified by H. Matsui in Aug., 2007
!
!> @brief set models for MHD simulation from control data
!!
!!@verbatim
!! subroutine s_set_control_4_model
!! subroutine s_set_control_4_crank
!!@endverbatim
!
module set_control_4_model
!
use m_precision
use m_error_IDs
!
use m_machine_parameter
use m_control_parameter
use m_ctl_data_mhd_evo_scheme
use m_t_int_parameter
!
implicit none
!
! -----------------------------------------------------------------------
!
contains
!
! -----------------------------------------------------------------------
!
subroutine s_set_control_4_model
!
use calypso_mpi
use m_t_step_parameter
use m_phys_labels
use m_physical_property
use m_ctl_data_mhd_evolution
use m_ctl_data_temp_model
use m_ctl_data_node_monitor
use node_monitor_IO
!
integer (kind = kint) :: i
!
!
! set time_evolution scheme
!
if (i_scheme .eq. 0) then
e_message = 'Set time integration scheme'
call calypso_MPI_abort(ierr_evo, e_message)
else
if ( scheme_ctl .eq. 'explicit_Euler' ) then
iflag_scheme = id_explicit_euler
iflag_implicit_correct = 0
else if ( scheme_ctl .eq. '2nd_Adams_Bashforth' ) then
iflag_scheme = id_explicit_adams2
iflag_implicit_correct = 0
else if ( scheme_ctl .eq. 'Crank_Nicolson' ) then
iflag_scheme = id_Crank_nicolson
else if ( scheme_ctl .eq. 'Crank_Nicolson_consist' ) then
iflag_scheme = id_Crank_nicolson_cmass
end if
end if
!
if ( iflag_scheme .eq. id_Crank_nicolson &
& .or. iflag_scheme .eq. id_Crank_nicolson_cmass) then
if (i_diff_correct.eq.0) then
iflag_implicit_correct = 0
else
if ( diffuse_correct_ctl .eq. 'On' &
& .or. diffuse_correct_ctl .eq. 'on' &
& .or. diffuse_correct_ctl .eq. 'ON') then
iflag_implicit_correct = iflag_scheme
end if
end if
end if
!
! set control for time evolution
!
if (t_evo_field_ctl%icou .eq. 0) then
e_message = 'Set field for time integration'
call calypso_MPI_abort(ierr_evo, e_message)
else
num_field_to_evolve = t_evo_field_ctl%num
if (iflag_debug .ge. iflag_routine_msg) &
& write(*,*) 'num_field_to_evolve ',num_field_to_evolve
end if
!
if ( num_field_to_evolve .ne. 0 ) then
allocate( t_evo_name(num_field_to_evolve) )
!
do i = 1, num_field_to_evolve
t_evo_name(i) = t_evo_field_ctl%c_tbl(i)
end do
!
call dealloc_t_evo_name_ctl
!
if (iflag_debug .ge. iflag_routine_msg) then
write(*,*) 'num_field_to_evolve ',num_field_to_evolve
do i = 1, num_field_to_evolve
write(*,*) i, trim(t_evo_name(i))
end do
end if
!
do i = 1, num_field_to_evolve
if ( t_evo_name(i) .eq. fhd_velo ) then
iflag_t_evo_4_velo = iflag_scheme
else if ( t_evo_name(i) .eq. fhd_temp ) then
iflag_t_evo_4_temp = iflag_scheme
else if ( t_evo_name(i) .eq. fhd_light ) then
iflag_t_evo_4_composit = iflag_scheme
else if ( t_evo_name(i) .eq. fhd_magne ) then
iflag_t_evo_4_magne = iflag_scheme
else if ( t_evo_name(i) .eq. fhd_vecp ) then
iflag_t_evo_4_vect_p = iflag_scheme
end if
end do
!
end if
!
if (iflag_t_evo_4_velo .eq. id_no_evolution &
& .and. iflag_t_evo_4_temp .eq. id_no_evolution &
& .and. iflag_t_evo_4_composit .eq. id_no_evolution &
& .and. iflag_t_evo_4_magne .eq. id_no_evolution &
& .and. iflag_t_evo_4_vect_p .eq. id_no_evolution) then
e_message = 'Turn on field for time integration'
call calypso_MPI_abort(ierr_evo, e_message)
end if
!
if (iflag_debug .ge. iflag_routine_msg) then
write(*,*) 'iflag_t_evo_4_velo ', iflag_t_evo_4_velo
write(*,*) 'iflag_t_evo_4_temp ', iflag_t_evo_4_temp
write(*,*) 'iflag_t_evo_4_composit ', iflag_t_evo_4_composit
write(*,*) 'iflag_t_evo_4_magne ', iflag_t_evo_4_magne
write(*,*) 'iflag_t_evo_4_vect_p ', iflag_t_evo_4_vect_p
write(*,*) 'iflag_implicit_correct ', iflag_implicit_correct
end if
!
! set control for temperature
!
if (i_ref_temp .eq. 0) then
iflag_4_ref_temp = id_no_ref_temp
else
if (ref_temp_ctl .eq. 'spherical_shell') then
iflag_4_ref_temp = id_sphere_ref_temp
else if (ref_temp_ctl .eq. 'sph_constant_heat') then
iflag_4_ref_temp = id_linear_r_ref_temp
else if (ref_temp_ctl .eq. 'linear_x') then
iflag_4_ref_temp = id_x_ref_temp
else if (ref_temp_ctl .eq. 'linear_y') then
iflag_4_ref_temp = id_y_ref_temp
else if (ref_temp_ctl .eq. 'linear_z') then
iflag_4_ref_temp = id_z_ref_temp
end if
end if
!
if ( (i_low_temp_posi*i_low_temp_value) .eq. 0) then
if (iflag_4_ref_temp .eq. id_no_ref_temp) then
low_temp = 0.0d0
depth_low_t = 0.0d0
else
e_message &
& = 'Set lower temperature and its position'
call calypso_MPI_abort(ierr_fld, e_message)
end if
else
low_temp = low_temp_ctl
depth_low_t = depth_low_t_ctl
end if
!
if ( (i_high_temp_posi*i_high_temp_value) .eq. 0) then
if (iflag_4_ref_temp .eq. id_no_ref_temp) then
high_temp = 0.0d0
depth_high_t = 0.0d0
else
e_message &
& = 'Set lower temperature and its position'
call calypso_MPI_abort(ierr_fld, e_message)
end if
else
high_temp = high_temp_ctl
depth_high_t = depth_high_t_ctl
end if
!
if (iflag_debug .ge. iflag_routine_msg) then
write(*,*) 'iflag_4_ref_temp ',iflag_4_ref_temp
write(*,*) 'low_temp ',low_temp
write(*,*) 'high_temp ',high_temp
write(*,*) 'depth_low_t ',depth_low_t
write(*,*) 'depth_high_t ',depth_high_t
end if
!
!
!
iflag_t_strat = id_turn_OFF
if (i_strat_ctl .gt. id_turn_OFF) then
if(stratified_ctl .eq. 'on' .or. stratified_ctl .eq. 'On' &
& .or. stratified_ctl .eq. 'ON' .or. stratified_ctl .eq. '1') &
& iflag_t_strat = id_turn_ON
end if
!
if (iflag_t_strat .eq. id_turn_OFF) then
stratified_sigma = 0.0d0
stratified_width = 0.0d0
stratified_outer_r = 0.0d0
else
if ( (i_strat_sigma*i_strat_width*i_strat_outer) .eq. 0) then
e_message &
& = 'Set parameteres for stratification'
call calypso_MPI_abort(ierr_fld, e_message)
else
stratified_sigma = stratified_sigma_ctl
stratified_width = stratified_width_ctl
stratified_outer_r = stratified_outer_r_ctl
end if
end if
!
if (iflag_debug .ge. iflag_routine_msg) then
write(*,*) 'iflag_t_strat ', iflag_t_strat
write(*,*) 'stratified_sigma ', stratified_sigma
write(*,*) 'stratified_width ', stratified_width
write(*,*) 'stratified_outer_r ', stratified_outer_r
end if
!
if (group_4_monitor_ctl%icou .eq. 0) then
num_monitor = 0
else
num_monitor = group_4_monitor_ctl%num
end if
!
if (num_monitor .ne. 0) then
call allocate_monitor_group
!
do i = 1, num_monitor
monitor_grp(i) = group_4_monitor_ctl%c_tbl(i)
end do
call dealloc_monitor_grp_ctl
!
if (iflag_debug .ge. iflag_routine_msg) then
do i = 1, num_monitor
write(*,*) 'monitor_grp',i,monitor_grp(i)
end do
end if
end if
!
!
end subroutine s_set_control_4_model
!
! -----------------------------------------------------------------------
!
subroutine s_set_control_4_crank
!
!
if(iflag_t_evo_4_velo .ge. id_Crank_nicolson) then
if (i_coef_imp_v.eq.0) then
coef_imp_v = 0.5d0
else
coef_imp_v = coef_imp_v_ctl
end if
else
coef_imp_v = 0.0d0
end if
!
if(iflag_t_evo_4_temp .ge. id_Crank_nicolson) then
if (i_coef_imp_t.eq.0) then
coef_imp_t = 0.5d0
else
coef_imp_t = coef_imp_t_ctl
end if
else
coef_imp_t = 0.0d0
end if
!
if(iflag_t_evo_4_magne .ge. id_Crank_nicolson &
& .or. iflag_t_evo_4_vect_p .ge. id_Crank_nicolson) then
if (i_coef_imp_b.eq.0) then
coef_imp_b = 0.5d0
else
coef_imp_b = coef_imp_b_ctl
end if
else
coef_imp_b = 0.0d0
end if
!
if(iflag_t_evo_4_composit .ge. id_Crank_nicolson) then
if (i_coef_imp_c.eq.0) then
coef_imp_c = 0.5d0
else
coef_imp_c = coef_imp_c_ctl
end if
else
coef_imp_c = 0.0d0
end if
!
coef_exp_v = 1.0d0 - coef_imp_v
coef_exp_t = 1.0d0 - coef_imp_t
coef_exp_b = 1.0d0 - coef_imp_b
coef_exp_c = 1.0d0 - coef_imp_c
!
!
if (iflag_debug .ge. iflag_routine_msg) then
write(*,*) 'coef_imp_v ',coef_imp_v
write(*,*) 'coef_imp_t ',coef_imp_t
write(*,*) 'coef_imp_b ',coef_imp_b
write(*,*) 'coef_imp_c ',coef_imp_c
end if
!
end subroutine s_set_control_4_crank
!
! -----------------------------------------------------------------------
!
end module set_control_4_model
| gpl-3.0 |
maxhutch/magma | testing/lin/zsyt03.f | 9 | 4616 | SUBROUTINE ZSYT03( UPLO, N, A, LDA, AINV, LDAINV, WORK, LDWORK,
$ RWORK, RCOND, RESID )
*
* -- LAPACK test routine (version 3.1) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER LDA, LDAINV, LDWORK, N
DOUBLE PRECISION RCOND, RESID
* ..
* .. Array Arguments ..
DOUBLE PRECISION RWORK( * )
COMPLEX*16 A( LDA, * ), AINV( LDAINV, * ),
$ WORK( LDWORK, * )
* ..
*
* Purpose
* =======
*
* ZSYT03 computes the residual for a complex symmetric matrix times
* its inverse:
* norm( I - A*AINV ) / ( N * norm(A) * norm(AINV) * EPS )
* where EPS is the machine epsilon.
*
* Arguments
* ==========
*
* UPLO (input) CHARACTER*1
* Specifies whether the upper or lower triangular part of the
* complex symmetric matrix A is stored:
* = 'U': Upper triangular
* = 'L': Lower triangular
*
* N (input) INTEGER
* The number of rows and columns of the matrix A. N >= 0.
*
* A (input) COMPLEX*16 array, dimension (LDA,N)
* The original complex symmetric matrix A.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,N)
*
* AINV (input/output) COMPLEX*16 array, dimension (LDAINV,N)
* On entry, the inverse of the matrix A, stored as a symmetric
* matrix in the same format as A.
* In this version, AINV is expanded into a full matrix and
* multiplied by A, so the opposing triangle of AINV will be
* changed; i.e., if the upper triangular part of AINV is
* stored, the lower triangular part will be used as work space.
*
* LDAINV (input) INTEGER
* The leading dimension of the array AINV. LDAINV >= max(1,N).
*
* WORK (workspace) COMPLEX*16 array, dimension (LDWORK,N)
*
* LDWORK (input) INTEGER
* The leading dimension of the array WORK. LDWORK >= max(1,N).
*
* RWORK (workspace) DOUBLE PRECISION array, dimension (N)
*
* RCOND (output) DOUBLE PRECISION
* The reciprocal of the condition number of A, computed as
* RCOND = 1/ (norm(A) * norm(AINV)).
*
* RESID (output) DOUBLE PRECISION
* norm(I - A*AINV) / ( N * norm(A) * norm(AINV) * EPS )
*
* =====================================================================
*
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
COMPLEX*16 CZERO, CONE
PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),
$ CONE = ( 1.0D+0, 0.0D+0 ) )
* ..
* .. Local Scalars ..
INTEGER I, J
DOUBLE PRECISION AINVNM, ANORM, EPS
* ..
* .. External Functions ..
LOGICAL LSAME
DOUBLE PRECISION DLAMCH, ZLANGE, ZLANSY
EXTERNAL LSAME, DLAMCH, ZLANGE, ZLANSY
* ..
* .. External Subroutines ..
EXTERNAL ZSYMM
* ..
* .. Intrinsic Functions ..
INTRINSIC DBLE
* ..
* .. Executable Statements ..
*
* Quick exit if N = 0
*
IF( N.LE.0 ) THEN
RCOND = ONE
RESID = ZERO
RETURN
END IF
*
* Exit with RESID = 1/EPS if ANORM = 0 or AINVNM = 0.
*
EPS = DLAMCH( 'Epsilon' )
ANORM = ZLANSY( '1', UPLO, N, A, LDA, RWORK )
AINVNM = ZLANSY( '1', UPLO, N, AINV, LDAINV, RWORK )
IF( ANORM.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN
RCOND = ZERO
RESID = ONE / EPS
RETURN
END IF
RCOND = ( ONE / ANORM ) / AINVNM
*
* Expand AINV into a full matrix and call ZSYMM to multiply
* AINV on the left by A (store the result in WORK).
*
IF( LSAME( UPLO, 'U' ) ) THEN
DO 20 J = 1, N
DO 10 I = 1, J - 1
AINV( J, I ) = AINV( I, J )
10 CONTINUE
20 CONTINUE
ELSE
DO 40 J = 1, N
DO 30 I = J + 1, N
AINV( J, I ) = AINV( I, J )
30 CONTINUE
40 CONTINUE
END IF
CALL ZSYMM( 'Left', UPLO, N, N, -CONE, A, LDA, AINV, LDAINV,
$ CZERO, WORK, LDWORK )
*
* Add the identity matrix to WORK .
*
DO 50 I = 1, N
WORK( I, I ) = WORK( I, I ) + CONE
50 CONTINUE
*
* Compute norm(I - A*AINV) / (N * norm(A) * norm(AINV) * EPS)
*
RESID = ZLANGE( '1', N, N, WORK, LDWORK, RWORK )
*
RESID = ( ( RESID*RCOND ) / EPS ) / DBLE( N )
*
RETURN
*
* End of ZSYT03
*
END
| bsd-3-clause |
maxhutch/magma | testing/checkdiag/src/dlarfy.f | 13 | 2670 | SUBROUTINE DLARFY( UPLO, N, V, INCV, TAU, C, LDC, WORK )
*
* -- LAPACK auxiliary test routine (version 3.1) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INCV, LDC, N
DOUBLE PRECISION TAU
* ..
* .. Array Arguments ..
DOUBLE PRECISION C( LDC, * ), V( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* DLARFY applies an elementary reflector, or Householder matrix, H,
* to an n x n symmetric matrix C, from both the left and the right.
*
* H is represented in the form
*
* H = I - tau * v * v'
*
* where tau is a scalar and v is a vector.
*
* If tau is zero, then H is taken to be the unit matrix.
*
* Arguments
* =========
*
* UPLO (input) CHARACTER*1
* Specifies whether the upper or lower triangular part of the
* symmetric matrix C is stored.
* = 'U': Upper triangle
* = 'L': Lower triangle
*
* N (input) INTEGER
* The number of rows and columns of the matrix C. N >= 0.
*
* V (input) DOUBLE PRECISION array, dimension
* (1 + (N-1)*abs(INCV))
* The vector v as described above.
*
* INCV (input) INTEGER
* The increment between successive elements of v. INCV must
* not be zero.
*
* TAU (input) DOUBLE PRECISION
* The value tau as described above.
*
* C (input/output) DOUBLE PRECISION array, dimension (LDC, N)
* On entry, the matrix C.
* On exit, C is overwritten by H * C * H'.
*
* LDC (input) INTEGER
* The leading dimension of the array C. LDC >= max( 1, N ).
*
* WORK (workspace) DOUBLE PRECISION array, dimension (N)
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, ZERO, HALF
PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0, HALF = 0.5D+0 )
* ..
* .. Local Scalars ..
DOUBLE PRECISION ALPHA
* ..
* .. External Subroutines ..
EXTERNAL DAXPY, DSYMV, DSYR2
* ..
* .. External Functions ..
DOUBLE PRECISION DDOT
EXTERNAL DDOT
* ..
* .. Executable Statements ..
*
IF( TAU.EQ.ZERO )
$ RETURN
*
* Form w:= C * v
*
CALL DSYMV( UPLO, N, ONE, C, LDC, V, INCV, ZERO, WORK, 1 )
*
ALPHA = -HALF*TAU*DDOT( N, WORK, 1, V, INCV )
CALL DAXPY( N, ALPHA, V, INCV, WORK, 1 )
*
* C := C - v * w' - w * v'
*
CALL DSYR2( UPLO, N, -TAU, V, INCV, WORK, 1, C, LDC )
*
RETURN
*
* End of DLARFY
*
END
| bsd-3-clause |
mverleg/1957 | lib/lapack/dlaed7.f | 5 | 13290 | *> \brief \b DLAED7 used by sstedc. Computes the updated eigensystem of a diagonal matrix after modification by a rank-one symmetric matrix. Used when the original matrix is dense.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DLAED7 + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlaed7.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlaed7.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlaed7.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DLAED7( ICOMPQ, N, QSIZ, TLVLS, CURLVL, CURPBM, D, Q,
* LDQ, INDXQ, RHO, CUTPNT, QSTORE, QPTR, PRMPTR,
* PERM, GIVPTR, GIVCOL, GIVNUM, WORK, IWORK,
* INFO )
*
* .. Scalar Arguments ..
* INTEGER CURLVL, CURPBM, CUTPNT, ICOMPQ, INFO, LDQ, N,
* $ QSIZ, TLVLS
* DOUBLE PRECISION RHO
* ..
* .. Array Arguments ..
* INTEGER GIVCOL( 2, * ), GIVPTR( * ), INDXQ( * ),
* $ IWORK( * ), PERM( * ), PRMPTR( * ), QPTR( * )
* DOUBLE PRECISION D( * ), GIVNUM( 2, * ), Q( LDQ, * ),
* $ QSTORE( * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DLAED7 computes the updated eigensystem of a diagonal
*> matrix after modification by a rank-one symmetric matrix. This
*> routine is used only for the eigenproblem which requires all
*> eigenvalues and optionally eigenvectors of a dense symmetric matrix
*> that has been reduced to tridiagonal form. DLAED1 handles
*> the case in which all eigenvalues and eigenvectors of a symmetric
*> tridiagonal matrix are desired.
*>
*> T = Q(in) ( D(in) + RHO * Z*Z**T ) Q**T(in) = Q(out) * D(out) * Q**T(out)
*>
*> where Z = Q**Tu, u is a vector of length N with ones in the
*> CUTPNT and CUTPNT + 1 th elements and zeros elsewhere.
*>
*> The eigenvectors of the original matrix are stored in Q, and the
*> eigenvalues are in D. The algorithm consists of three stages:
*>
*> The first stage consists of deflating the size of the problem
*> when there are multiple eigenvalues or if there is a zero in
*> the Z vector. For each such occurence the dimension of the
*> secular equation problem is reduced by one. This stage is
*> performed by the routine DLAED8.
*>
*> The second stage consists of calculating the updated
*> eigenvalues. This is done by finding the roots of the secular
*> equation via the routine DLAED4 (as called by DLAED9).
*> This routine also calculates the eigenvectors of the current
*> problem.
*>
*> The final stage consists of computing the updated eigenvectors
*> directly using the updated eigenvalues. The eigenvectors for
*> the current problem are multiplied with the eigenvectors from
*> the overall problem.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] ICOMPQ
*> \verbatim
*> ICOMPQ is INTEGER
*> = 0: Compute eigenvalues only.
*> = 1: Compute eigenvectors of original dense symmetric matrix
*> also. On entry, Q contains the orthogonal matrix used
*> to reduce the original matrix to tridiagonal form.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The dimension of the symmetric tridiagonal matrix. N >= 0.
*> \endverbatim
*>
*> \param[in] QSIZ
*> \verbatim
*> QSIZ is INTEGER
*> The dimension of the orthogonal matrix used to reduce
*> the full matrix to tridiagonal form. QSIZ >= N if ICOMPQ = 1.
*> \endverbatim
*>
*> \param[in] TLVLS
*> \verbatim
*> TLVLS is INTEGER
*> The total number of merging levels in the overall divide and
*> conquer tree.
*> \endverbatim
*>
*> \param[in] CURLVL
*> \verbatim
*> CURLVL is INTEGER
*> The current level in the overall merge routine,
*> 0 <= CURLVL <= TLVLS.
*> \endverbatim
*>
*> \param[in] CURPBM
*> \verbatim
*> CURPBM is INTEGER
*> The current problem in the current level in the overall
*> merge routine (counting from upper left to lower right).
*> \endverbatim
*>
*> \param[in,out] D
*> \verbatim
*> D is DOUBLE PRECISION array, dimension (N)
*> On entry, the eigenvalues of the rank-1-perturbed matrix.
*> On exit, the eigenvalues of the repaired matrix.
*> \endverbatim
*>
*> \param[in,out] Q
*> \verbatim
*> Q is DOUBLE PRECISION array, dimension (LDQ, N)
*> On entry, the eigenvectors of the rank-1-perturbed matrix.
*> On exit, the eigenvectors of the repaired tridiagonal matrix.
*> \endverbatim
*>
*> \param[in] LDQ
*> \verbatim
*> LDQ is INTEGER
*> The leading dimension of the array Q. LDQ >= max(1,N).
*> \endverbatim
*>
*> \param[out] INDXQ
*> \verbatim
*> INDXQ is INTEGER array, dimension (N)
*> The permutation which will reintegrate the subproblem just
*> solved back into sorted order, i.e., D( INDXQ( I = 1, N ) )
*> will be in ascending order.
*> \endverbatim
*>
*> \param[in] RHO
*> \verbatim
*> RHO is DOUBLE PRECISION
*> The subdiagonal element used to create the rank-1
*> modification.
*> \endverbatim
*>
*> \param[in] CUTPNT
*> \verbatim
*> CUTPNT is INTEGER
*> Contains the location of the last eigenvalue in the leading
*> sub-matrix. min(1,N) <= CUTPNT <= N.
*> \endverbatim
*>
*> \param[in,out] QSTORE
*> \verbatim
*> QSTORE is DOUBLE PRECISION array, dimension (N**2+1)
*> Stores eigenvectors of submatrices encountered during
*> divide and conquer, packed together. QPTR points to
*> beginning of the submatrices.
*> \endverbatim
*>
*> \param[in,out] QPTR
*> \verbatim
*> QPTR is INTEGER array, dimension (N+2)
*> List of indices pointing to beginning of submatrices stored
*> in QSTORE. The submatrices are numbered starting at the
*> bottom left of the divide and conquer tree, from left to
*> right and bottom to top.
*> \endverbatim
*>
*> \param[in] PRMPTR
*> \verbatim
*> PRMPTR is INTEGER array, dimension (N lg N)
*> Contains a list of pointers which indicate where in PERM a
*> level's permutation is stored. PRMPTR(i+1) - PRMPTR(i)
*> indicates the size of the permutation and also the size of
*> the full, non-deflated problem.
*> \endverbatim
*>
*> \param[in] PERM
*> \verbatim
*> PERM is INTEGER array, dimension (N lg N)
*> Contains the permutations (from deflation and sorting) to be
*> applied to each eigenblock.
*> \endverbatim
*>
*> \param[in] GIVPTR
*> \verbatim
*> GIVPTR is INTEGER array, dimension (N lg N)
*> Contains a list of pointers which indicate where in GIVCOL a
*> level's Givens rotations are stored. GIVPTR(i+1) - GIVPTR(i)
*> indicates the number of Givens rotations.
*> \endverbatim
*>
*> \param[in] GIVCOL
*> \verbatim
*> GIVCOL is INTEGER array, dimension (2, N lg N)
*> Each pair of numbers indicates a pair of columns to take place
*> in a Givens rotation.
*> \endverbatim
*>
*> \param[in] GIVNUM
*> \verbatim
*> GIVNUM is DOUBLE PRECISION array, dimension (2, N lg N)
*> Each number indicates the S value to be used in the
*> corresponding Givens rotation.
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is DOUBLE PRECISION array, dimension (3*N+2*QSIZ*N)
*> \endverbatim
*>
*> \param[out] IWORK
*> \verbatim
*> IWORK is INTEGER array, dimension (4*N)
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit.
*> < 0: if INFO = -i, the i-th argument had an illegal value.
*> > 0: if INFO = 1, an eigenvalue did not converge
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2015
*
*> \ingroup auxOTHERcomputational
*
*> \par Contributors:
* ==================
*>
*> Jeff Rutter, Computer Science Division, University of California
*> at Berkeley, USA
*
* =====================================================================
SUBROUTINE DLAED7( ICOMPQ, N, QSIZ, TLVLS, CURLVL, CURPBM, D, Q,
$ LDQ, INDXQ, RHO, CUTPNT, QSTORE, QPTR, PRMPTR,
$ PERM, GIVPTR, GIVCOL, GIVNUM, WORK, IWORK,
$ INFO )
*
* -- LAPACK computational routine (version 3.6.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2015
*
* .. Scalar Arguments ..
INTEGER CURLVL, CURPBM, CUTPNT, ICOMPQ, INFO, LDQ, N,
$ QSIZ, TLVLS
DOUBLE PRECISION RHO
* ..
* .. Array Arguments ..
INTEGER GIVCOL( 2, * ), GIVPTR( * ), INDXQ( * ),
$ IWORK( * ), PERM( * ), PRMPTR( * ), QPTR( * )
DOUBLE PRECISION D( * ), GIVNUM( 2, * ), Q( LDQ, * ),
$ QSTORE( * ), WORK( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE, ZERO
PARAMETER ( ONE = 1.0D0, ZERO = 0.0D0 )
* ..
* .. Local Scalars ..
INTEGER COLTYP, CURR, I, IDLMDA, INDX, INDXC, INDXP,
$ IQ2, IS, IW, IZ, K, LDQ2, N1, N2, PTR
* ..
* .. External Subroutines ..
EXTERNAL DGEMM, DLAED8, DLAED9, DLAEDA, DLAMRG, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
*
IF( ICOMPQ.LT.0 .OR. ICOMPQ.GT.1 ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( ICOMPQ.EQ.1 .AND. QSIZ.LT.N ) THEN
INFO = -3
ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN
INFO = -9
ELSE IF( MIN( 1, N ).GT.CUTPNT .OR. N.LT.CUTPNT ) THEN
INFO = -12
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DLAED7', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
* The following values are for bookkeeping purposes only. They are
* integer pointers which indicate the portion of the workspace
* used by a particular array in DLAED8 and DLAED9.
*
IF( ICOMPQ.EQ.1 ) THEN
LDQ2 = QSIZ
ELSE
LDQ2 = N
END IF
*
IZ = 1
IDLMDA = IZ + N
IW = IDLMDA + N
IQ2 = IW + N
IS = IQ2 + N*LDQ2
*
INDX = 1
INDXC = INDX + N
COLTYP = INDXC + N
INDXP = COLTYP + N
*
* Form the z-vector which consists of the last row of Q_1 and the
* first row of Q_2.
*
PTR = 1 + 2**TLVLS
DO 10 I = 1, CURLVL - 1
PTR = PTR + 2**( TLVLS-I )
10 CONTINUE
CURR = PTR + CURPBM
CALL DLAEDA( N, TLVLS, CURLVL, CURPBM, PRMPTR, PERM, GIVPTR,
$ GIVCOL, GIVNUM, QSTORE, QPTR, WORK( IZ ),
$ WORK( IZ+N ), INFO )
*
* When solving the final problem, we no longer need the stored data,
* so we will overwrite the data from this level onto the previously
* used storage space.
*
IF( CURLVL.EQ.TLVLS ) THEN
QPTR( CURR ) = 1
PRMPTR( CURR ) = 1
GIVPTR( CURR ) = 1
END IF
*
* Sort and Deflate eigenvalues.
*
CALL DLAED8( ICOMPQ, K, N, QSIZ, D, Q, LDQ, INDXQ, RHO, CUTPNT,
$ WORK( IZ ), WORK( IDLMDA ), WORK( IQ2 ), LDQ2,
$ WORK( IW ), PERM( PRMPTR( CURR ) ), GIVPTR( CURR+1 ),
$ GIVCOL( 1, GIVPTR( CURR ) ),
$ GIVNUM( 1, GIVPTR( CURR ) ), IWORK( INDXP ),
$ IWORK( INDX ), INFO )
PRMPTR( CURR+1 ) = PRMPTR( CURR ) + N
GIVPTR( CURR+1 ) = GIVPTR( CURR+1 ) + GIVPTR( CURR )
*
* Solve Secular Equation.
*
IF( K.NE.0 ) THEN
CALL DLAED9( K, 1, K, N, D, WORK( IS ), K, RHO, WORK( IDLMDA ),
$ WORK( IW ), QSTORE( QPTR( CURR ) ), K, INFO )
IF( INFO.NE.0 )
$ GO TO 30
IF( ICOMPQ.EQ.1 ) THEN
CALL DGEMM( 'N', 'N', QSIZ, K, K, ONE, WORK( IQ2 ), LDQ2,
$ QSTORE( QPTR( CURR ) ), K, ZERO, Q, LDQ )
END IF
QPTR( CURR+1 ) = QPTR( CURR ) + K**2
*
* Prepare the INDXQ sorting permutation.
*
N1 = K
N2 = N - K
CALL DLAMRG( N1, N2, D, 1, -1, INDXQ )
ELSE
QPTR( CURR+1 ) = QPTR( CURR )
DO 20 I = 1, N
INDXQ( I ) = I
20 CONTINUE
END IF
*
30 CONTINUE
RETURN
*
* End of DLAED7
*
END
| bsd-3-clause |
davidgiven/gcc-vc4 | libgfortran/generated/_atan2_r4.F90 | 26 | 1484 | ! Copyright (C) 2002-2013 Free Software Foundation, Inc.
! Contributed by Paul Brook <paul@nowt.org>
!
!This file is part of the GNU Fortran 95 runtime library (libgfortran).
!
!GNU libgfortran is free software; you can redistribute it and/or
!modify it under the terms of the GNU General Public
!License as published by the Free Software Foundation; either
!version 3 of the License, or (at your option) any later version.
!GNU libgfortran is distributed in the hope that it will be useful,
!but WITHOUT ANY WARRANTY; without even the implied warranty of
!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!GNU General Public License for more details.
!
!Under Section 7 of GPL version 3, you are granted additional
!permissions described in the GCC Runtime Library Exception, version
!3.1, as published by the Free Software Foundation.
!
!You should have received a copy of the GNU General Public License and
!a copy of the GCC Runtime Library Exception along with this program;
!see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
!<http://www.gnu.org/licenses/>.
!
!This file is machine generated.
#include "config.h"
#include "kinds.inc"
#include "c99_protos.inc"
#if defined (HAVE_GFC_REAL_4)
#ifdef HAVE_ATAN2F
elemental function _gfortran_specific__atan2_r4 (p1, p2)
real (kind=4), intent (in) :: p1, p2
real (kind=4) :: _gfortran_specific__atan2_r4
_gfortran_specific__atan2_r4 = atan2 (p1, p2)
end function
#endif
#endif
| gpl-2.0 |
Vandemar/calypso | src/Fortran_libraries/SERIAL_src/SPH_SPECTR_src/copy_rj_phys_data_4_IO.f90 | 3 | 10066 | !> @file copy_rj_phys_data_4_IO.f90
!! module copy_rj_phys_data_4_IO
!!
!! @author H. Matsui
!! @date Programmed in Oct., 2007
!
!> @brief Copy between field data and IO data
!!
!!@verbatim
!! subroutine copy_rj_all_phys_name_to_IO(fld_IO)
!! subroutine copy_rj_all_phys_data_to_IO(fld_IO)
!! subroutine copy_rj_viz_phys_name_to_IO(fld_IO)
!! subroutine copy_rj_viz_phys_data_to_IO(fld_IO)
!!
!! subroutine copy_rj_phys_name_from_IO(fld_IO)
!! subroutine copy_rj_phys_data_from_IO(fld_IO)
!! subroutine set_rj_phys_data_from_IO(fld_IO)
!!
!! subroutine copy_each_sph_solenoid_to_IO(i_fld, j_IO, fld_IO)
!! subroutine copy_each_sph_vector_to_IO(i_fld, j_IO, fld_IO)
!! subroutine copy_each_sph_field_to_IO(i_fld, j_IO, fld_IO)
!!
!! subroutine copy_each_sph_solenoid_from_IO(i_fld, j_IO, fld_IO)
!! subroutine copy_each_sph_vector_from_IO(i_fld, j_IO, fld_IO)
!! subroutine copy_each_sph_field_from_IO(i_fld, j_IO, fld_IO)
!!@endverbatim
!
module copy_rj_phys_data_4_IO
!
use m_precision
!
use m_phys_constants
use m_sph_spectr_data
use m_spheric_parameter
use t_field_data_IO
!
implicit none
!
private :: copy_rj_phys_name_to_IO, copy_rj_phys_data_to_IO
!
! -------------------------------------------------------------------
!
contains
!
! -------------------------------------------------------------------
!
subroutine copy_rj_all_phys_name_to_IO(fld_IO)
!
type(field_IO), intent(inout) :: fld_IO
!
!
call copy_rj_phys_name_to_IO(num_phys_rj, fld_IO)
!
end subroutine copy_rj_all_phys_name_to_IO
!
! -------------------------------------------------------------------
!
subroutine copy_rj_viz_phys_name_to_IO(fld_IO)
!
type(field_IO), intent(inout) :: fld_IO
!
!
call copy_rj_phys_name_to_IO(num_phys_rj_vis, fld_IO)
!
end subroutine copy_rj_viz_phys_name_to_IO
!
! -------------------------------------------------------------------
! -------------------------------------------------------------------
!
subroutine copy_rj_all_phys_data_to_IO(fld_IO)
!
type(field_IO), intent(inout) :: fld_IO
!
!
call copy_rj_phys_data_to_IO(num_phys_rj, fld_IO)
!
end subroutine copy_rj_all_phys_data_to_IO
!
! -------------------------------------------------------------------
!
subroutine copy_rj_viz_phys_data_to_IO(fld_IO)
!
type(field_IO), intent(inout) :: fld_IO
!
!
call copy_rj_phys_data_to_IO(num_phys_rj_vis, fld_IO)
!
end subroutine copy_rj_viz_phys_data_to_IO
!
! -------------------------------------------------------------------
! -------------------------------------------------------------------
!
subroutine copy_rj_phys_name_to_IO(num_fld, fld_IO)
!
integer(kind = kint), intent(in) :: num_fld
type(field_IO), intent(inout) :: fld_IO
!
!
fld_IO%nnod_IO = nnod_rj
fld_IO%num_field_IO = num_fld
fld_IO%ntot_comp_IO = ntot_phys_rj
!
call alloc_phys_name_IO(fld_IO)
!
fld_IO%num_comp_IO(1:num_fld) = num_phys_comp_rj(1:num_fld)
fld_IO%istack_comp_IO(0:num_fld) = istack_phys_comp_rj(0:num_fld)
fld_IO%fld_name(1:num_fld) = phys_name_rj(1:num_fld)
!
end subroutine copy_rj_phys_name_to_IO
!
! -------------------------------------------------------------------
!
subroutine copy_rj_phys_data_to_IO(num_fld, fld_IO)
!
integer(kind = kint), intent(in) :: num_fld
type(field_IO), intent(inout) :: fld_IO
!
integer(kind = kint) :: i_fld
!
!
do i_fld = 1, num_fld
if (num_phys_comp_rj(i_fld) .eq. n_vector) then
call copy_each_sph_vector_to_IO(i_fld, i_fld, fld_IO)
else
call copy_each_sph_field_to_IO(i_fld, i_fld, fld_IO)
end if
end do
!
end subroutine copy_rj_phys_data_to_IO
!
! -------------------------------------------------------------------
! -------------------------------------------------------------------
!
subroutine copy_rj_phys_name_from_IO(fld_IO)
!
type(field_IO), intent(in) :: fld_IO
!
!
num_phys_rj = fld_IO%num_field_IO
ntot_phys_rj = fld_IO%ntot_comp_IO
!
call allocate_phys_rj_name
call allocate_phys_rj_data
!
num_phys_comp_rj(1:num_phys_rj) &
& = fld_IO%num_comp_IO(1:num_phys_rj)
istack_phys_comp_rj(0:num_phys_rj) &
& = fld_IO%istack_comp_IO(0:num_phys_rj)
phys_name_rj(1:num_phys_rj) = fld_IO%fld_name(1:num_phys_rj)
iflag_monitor_rj(1:num_phys_rj) = 1
!
end subroutine copy_rj_phys_name_from_IO
!
! -------------------------------------------------------------------
!
subroutine copy_rj_phys_data_from_IO(fld_IO)
!
type(field_IO), intent(in) :: fld_IO
integer(kind = kint) :: i_fld
!
!
do i_fld = 1, num_phys_rj
if (num_phys_comp_rj(i_fld) .eq. 3) then
call copy_each_sph_vector_from_IO(i_fld, i_fld, fld_IO)
else
call copy_each_sph_field_from_IO(i_fld, i_fld, fld_IO)
end if
end do
!
end subroutine copy_rj_phys_data_from_IO
!
! -------------------------------------------------------------------
!
subroutine set_rj_phys_data_from_IO(fld_IO)
!
type(field_IO), intent(in) :: fld_IO
integer(kind = kint) :: i_fld, j_IO
!
do i_fld = 1, num_phys_rj
do j_IO = 1, fld_IO%num_field_IO
if (phys_name_rj(i_fld) .eq. fld_IO%fld_name(j_IO)) then
if (fld_IO%num_comp_IO(j_IO) .eq. 3) then
call copy_each_sph_vector_from_IO(i_fld, j_IO, fld_IO)
else if (fld_IO%num_comp_IO(j_IO) .eq. 2) then
call copy_each_sph_solenoid_from_IO(i_fld, j_IO, fld_IO)
else
call copy_each_sph_field_from_IO(i_fld, j_IO, fld_IO)
end if
exit
end if
end do
end do
!
end subroutine set_rj_phys_data_from_IO
!
! -------------------------------------------------------------------
! -------------------------------------------------------------------
!
subroutine copy_each_sph_solenoid_to_IO(i_fld, j_IO, fld_IO)
!
integer(kind = kint), intent(in) :: i_fld, j_IO
type(field_IO), intent(inout) :: fld_IO
integer(kind = kint) :: ist, jst, inod
!
!
ist = istack_phys_comp_rj(i_fld-1)
jst = fld_IO%istack_comp_IO(j_IO-1)
!$omp parallel do
do inod = 1, nnod_rj
fld_IO%d_IO(inod,jst+1) = d_rj(inod,ist+1)
fld_IO%d_IO(inod,jst+2) = d_rj(inod,ist+3)
end do
!$omp end parallel do
!
end subroutine copy_each_sph_solenoid_to_IO
!
! -------------------------------------------------------------------
!
subroutine copy_each_sph_vector_to_IO(i_fld, j_IO, fld_IO)
!
integer(kind = kint), intent(in) :: i_fld, j_IO
type(field_IO), intent(inout) :: fld_IO
integer(kind = kint) :: ist, jst, inod
!
!
ist = istack_phys_comp_rj(i_fld-1)
jst = fld_IO%istack_comp_IO(j_IO-1)
!$omp parallel do
do inod = 1, nnod_rj
fld_IO%d_IO(inod,jst+1) = d_rj(inod,ist+1)
fld_IO%d_IO(inod,jst+2) = d_rj(inod,ist+3)
fld_IO%d_IO(inod,jst+3) = d_rj(inod,ist+2)
end do
!$omp end parallel do
!
end subroutine copy_each_sph_vector_to_IO
!
! -------------------------------------------------------------------
!
subroutine copy_each_sph_field_to_IO(i_fld, j_IO, fld_IO)
!
integer(kind = kint), intent(in) :: i_fld, j_IO
type(field_IO), intent(inout) :: fld_IO
integer(kind = kint) :: ist, jst, nd, inod
!
!
ist = istack_phys_comp_rj(i_fld-1)
jst = fld_IO%istack_comp_IO(j_IO-1 )
!$omp parallel
do nd = 1, num_phys_comp_rj(i_fld)
!$omp do
do inod = 1, nnod_rj
fld_IO%d_IO(inod,jst+nd) = d_rj(inod,ist+nd)
end do
!$omp end do nowait
end do
!$omp end parallel
!
end subroutine copy_each_sph_field_to_IO
!
! -------------------------------------------------------------------
! -------------------------------------------------------------------
!
subroutine copy_each_sph_solenoid_from_IO(i_fld, j_IO, fld_IO)
!
type(field_IO), intent(in) :: fld_IO
integer(kind = kint), intent(in) :: i_fld, j_IO
integer(kind = kint) :: ist, jst, inod
!
!
ist = istack_phys_comp_rj(i_fld-1)
jst = fld_IO%istack_comp_IO(j_IO-1)
!$omp parallel do
do inod = 1, nnod_rj
d_rj(inod,ist+1) = fld_IO%d_IO(inod,jst+1)
d_rj(inod,ist+3) = fld_IO%d_IO(inod,jst+2)
end do
!$omp end parallel do
!
end subroutine copy_each_sph_solenoid_from_IO
!
! -------------------------------------------------------------------
!
subroutine copy_each_sph_vector_from_IO(i_fld, j_IO, fld_IO)
!
type(field_IO), intent(in) :: fld_IO
integer(kind = kint), intent(in) :: i_fld, j_IO
integer(kind = kint) :: ist, jst, inod
!
!
ist = istack_phys_comp_rj(i_fld-1)
jst = fld_IO%istack_comp_IO(j_IO-1)
!$omp parallel do
do inod = 1, nnod_rj
d_rj(inod,ist+1) = fld_IO%d_IO(inod,jst+1)
d_rj(inod,ist+3) = fld_IO%d_IO(inod,jst+2)
d_rj(inod,ist+2) = fld_IO%d_IO(inod,jst+3)
end do
!$omp end parallel do
!
end subroutine copy_each_sph_vector_from_IO
!
! -------------------------------------------------------------------
!
subroutine copy_each_sph_field_from_IO(i_fld, j_IO, fld_IO)
!
type(field_IO), intent(in) :: fld_IO
integer(kind = kint), intent(in) :: i_fld, j_IO
integer(kind = kint) :: ist, jst, nd, inod
!
!
ist = istack_phys_comp_rj(i_fld-1)
jst = fld_IO%istack_comp_IO(j_IO-1 )
!$omp parallel
do nd = 1, num_phys_comp_rj(i_fld)
!$omp do
do inod = 1, nnod_rj
d_rj(inod,ist+nd) = fld_IO%d_IO(inod,jst+nd)
end do
!$omp end do nowait
end do
!$omp end parallel
!
end subroutine copy_each_sph_field_from_IO
!
! -------------------------------------------------------------------
!
end module copy_rj_phys_data_4_IO
| gpl-3.0 |
mverleg/1957 | lib/lapack/iladlc.f | 57 | 2999 | *> \brief \b ILADLC scans a matrix for its last non-zero column.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download ILADLC + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/iladlc.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/iladlc.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/iladlc.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* INTEGER FUNCTION ILADLC( M, N, A, LDA )
*
* .. Scalar Arguments ..
* INTEGER M, N, LDA
* ..
* .. Array Arguments ..
* DOUBLE PRECISION A( LDA, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ILADLC scans A for its last non-zero column.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of rows of the matrix A.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of columns of the matrix A.
*> \endverbatim
*>
*> \param[in] A
*> \verbatim
*> A is DOUBLE PRECISION array, dimension (LDA,N)
*> The m by n matrix A.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,M).
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date September 2012
*
*> \ingroup auxOTHERauxiliary
*
* =====================================================================
INTEGER FUNCTION ILADLC( M, N, A, LDA )
*
* -- LAPACK auxiliary routine (version 3.4.2) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* September 2012
*
* .. Scalar Arguments ..
INTEGER M, N, LDA
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO
PARAMETER ( ZERO = 0.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I
* ..
* .. Executable Statements ..
*
* Quick test for the common case where one corner is non-zero.
IF( N.EQ.0 ) THEN
ILADLC = N
ELSE IF( A(1, N).NE.ZERO .OR. A(M, N).NE.ZERO ) THEN
ILADLC = N
ELSE
* Now scan each column from the end, returning with the first non-zero.
DO ILADLC = N, 1, -1
DO I = 1, M
IF( A(I, ILADLC).NE.ZERO ) RETURN
END DO
END DO
END IF
RETURN
END
| bsd-3-clause |
maxhutch/magma | testing/lin/alahd.f | 8 | 32031 | SUBROUTINE ALAHD( IOUNIT, PATH )
*
* -- LAPACK test routine (version 3.3.0) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2010
*
* .. Scalar Arguments ..
CHARACTER*3 PATH
INTEGER IOUNIT
* ..
*
* Purpose
* =======
*
* ALAHD prints header information for the different test paths.
*
* Arguments
* =========
*
* IOUNIT (input) INTEGER
* The unit number to which the header information should be
* printed.
*
* PATH (input) CHARACTER*3
* The name of the path for which the header information is to
* be printed. Current paths are
* _GE: General matrices
* _GB: General band
* _GT: General Tridiagonal
* _PO: Symmetric or Hermitian positive definite
* _PS: Symmetric or Hermitian positive semi-definite
* _PP: Symmetric or Hermitian positive definite packed
* _PB: Symmetric or Hermitian positive definite band
* _PT: Symmetric or Hermitian positive definite tridiagonal
* _SY: Symmetric indefinite
* _SP: Symmetric indefinite packed
* _HE: (complex) Hermitian indefinite
* _HP: (complex) Hermitian indefinite packed
* _TR: Triangular
* _TP: Triangular packed
* _TB: Triangular band
* _QR: QR (general matrices)
* _LQ: LQ (general matrices)
* _QL: QL (general matrices)
* _RQ: RQ (general matrices)
* _QP: QR with column pivoting
* _TZ: Trapezoidal
* _LS: Least Squares driver routines
* _LU: LU variants
* _CH: Cholesky variants
* _QS: QR variants
* The first character must be one of S, D, C, or Z (C or Z only
* if complex).
*
* =====================================================================
*
* .. Local Scalars ..
LOGICAL CORZ, SORD
CHARACTER C1, C3
CHARACTER*2 P2
CHARACTER*4 EIGCNM
CHARACTER*32 SUBNAM
CHARACTER*9 SYM
* ..
* .. External Functions ..
LOGICAL LSAME, LSAMEN
EXTERNAL LSAME, LSAMEN
* ..
* .. Intrinsic Functions ..
INTRINSIC LEN_TRIM
* ..
* .. Executable Statements ..
*
IF( IOUNIT.LE.0 )
$ RETURN
C1 = PATH( 1: 1 )
C3 = PATH( 3: 3 )
P2 = PATH( 2: 3 )
SORD = LSAME( C1, 'S' ) .OR. LSAME( C1, 'D' )
CORZ = LSAME( C1, 'C' ) .OR. LSAME( C1, 'Z' )
IF( .NOT.( SORD .OR. CORZ ) )
$ RETURN
*
IF( LSAMEN( 2, P2, 'GE' ) ) THEN
*
* GE: General dense
*
WRITE( IOUNIT, FMT = 9999 )PATH
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9979 )
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9962 )1
WRITE( IOUNIT, FMT = 9961 )2
WRITE( IOUNIT, FMT = 9960 )3
WRITE( IOUNIT, FMT = 9959 )4
WRITE( IOUNIT, FMT = 9958 )5
WRITE( IOUNIT, FMT = 9957 )6
WRITE( IOUNIT, FMT = 9956 )7
WRITE( IOUNIT, FMT = 9955 )8
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'GB' ) ) THEN
*
* GB: General band
*
WRITE( IOUNIT, FMT = 9998 )PATH
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9978 )
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9962 )1
WRITE( IOUNIT, FMT = 9960 )2
WRITE( IOUNIT, FMT = 9959 )3
WRITE( IOUNIT, FMT = 9958 )4
WRITE( IOUNIT, FMT = 9957 )5
WRITE( IOUNIT, FMT = 9956 )6
WRITE( IOUNIT, FMT = 9955 )7
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'GT' ) ) THEN
*
* GT: General tridiagonal
*
WRITE( IOUNIT, FMT = 9997 )PATH
WRITE( IOUNIT, FMT = 9977 )
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9962 )1
WRITE( IOUNIT, FMT = 9960 )2
WRITE( IOUNIT, FMT = 9959 )3
WRITE( IOUNIT, FMT = 9958 )4
WRITE( IOUNIT, FMT = 9957 )5
WRITE( IOUNIT, FMT = 9956 )6
WRITE( IOUNIT, FMT = 9955 )7
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'PO' ) .OR. LSAMEN( 2, P2, 'PP' ) ) THEN
*
* PO: Positive definite full
* PP: Positive definite packed
*
IF( SORD ) THEN
SYM = 'Symmetric'
ELSE
SYM = 'Hermitian'
END IF
IF( LSAME( C3, 'O' ) ) THEN
WRITE( IOUNIT, FMT = 9996 )PATH, SYM
ELSE
WRITE( IOUNIT, FMT = 9995 )PATH, SYM
END IF
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9975 )PATH
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9954 )1
WRITE( IOUNIT, FMT = 9961 )2
WRITE( IOUNIT, FMT = 9960 )3
WRITE( IOUNIT, FMT = 9959 )4
WRITE( IOUNIT, FMT = 9958 )5
WRITE( IOUNIT, FMT = 9957 )6
WRITE( IOUNIT, FMT = 9956 )7
WRITE( IOUNIT, FMT = 9955 )8
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'PS' ) ) THEN
*
* PS: Positive semi-definite full
*
IF( SORD ) THEN
SYM = 'Symmetric'
ELSE
SYM = 'Hermitian'
END IF
IF( LSAME( C1, 'S' ) .OR. LSAME( C1, 'C' ) ) THEN
EIGCNM = '1E04'
ELSE
EIGCNM = '1D12'
END IF
WRITE( IOUNIT, FMT = 9995 )PATH, SYM
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 8973 )EIGCNM, EIGCNM, EIGCNM
WRITE( IOUNIT, FMT = '( '' Difference:'' )' )
WRITE( IOUNIT, FMT = 8972 )C1
WRITE( IOUNIT, FMT = '( '' Test ratio:'' )' )
WRITE( IOUNIT, FMT = 8950 )
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
ELSE IF( LSAMEN( 2, P2, 'PB' ) ) THEN
*
* PB: Positive definite band
*
IF( SORD ) THEN
WRITE( IOUNIT, FMT = 9994 )PATH, 'Symmetric'
ELSE
WRITE( IOUNIT, FMT = 9994 )PATH, 'Hermitian'
END IF
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9973 )PATH
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9954 )1
WRITE( IOUNIT, FMT = 9960 )2
WRITE( IOUNIT, FMT = 9959 )3
WRITE( IOUNIT, FMT = 9958 )4
WRITE( IOUNIT, FMT = 9957 )5
WRITE( IOUNIT, FMT = 9956 )6
WRITE( IOUNIT, FMT = 9955 )7
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'PT' ) ) THEN
*
* PT: Positive definite tridiagonal
*
IF( SORD ) THEN
WRITE( IOUNIT, FMT = 9993 )PATH, 'Symmetric'
ELSE
WRITE( IOUNIT, FMT = 9993 )PATH, 'Hermitian'
END IF
WRITE( IOUNIT, FMT = 9976 )
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9952 )1
WRITE( IOUNIT, FMT = 9960 )2
WRITE( IOUNIT, FMT = 9959 )3
WRITE( IOUNIT, FMT = 9958 )4
WRITE( IOUNIT, FMT = 9957 )5
WRITE( IOUNIT, FMT = 9956 )6
WRITE( IOUNIT, FMT = 9955 )7
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'SY' ) ) THEN
*
* SY: Symmetric indefinite full
*
IF( LSAME( C3, 'Y' ) ) THEN
WRITE( IOUNIT, FMT = 9992 )PATH, 'Symmetric'
ELSE
WRITE( IOUNIT, FMT = 9991 )PATH, 'Symmetric'
END IF
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
IF( SORD ) THEN
WRITE( IOUNIT, FMT = 9972 )
ELSE
WRITE( IOUNIT, FMT = 9971 )
END IF
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9953 )1
WRITE( IOUNIT, FMT = 9961 )2
WRITE( IOUNIT, FMT = 9960 )3
WRITE( IOUNIT, FMT = 9960 )4
WRITE( IOUNIT, FMT = 9959 )5
WRITE( IOUNIT, FMT = 9958 )6
WRITE( IOUNIT, FMT = 9956 )7
WRITE( IOUNIT, FMT = 9957 )8
WRITE( IOUNIT, FMT = 9955 )9
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'SP' ) ) THEN
*
* SP: Symmetric indefinite packed
*
IF( LSAME( C3, 'Y' ) ) THEN
WRITE( IOUNIT, FMT = 9992 )PATH, 'Symmetric'
ELSE
WRITE( IOUNIT, FMT = 9991 )PATH, 'Symmetric'
END IF
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
IF( SORD ) THEN
WRITE( IOUNIT, FMT = 9972 )
ELSE
WRITE( IOUNIT, FMT = 9971 )
END IF
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9953 )1
WRITE( IOUNIT, FMT = 9961 )2
WRITE( IOUNIT, FMT = 9960 )3
WRITE( IOUNIT, FMT = 9959 )4
WRITE( IOUNIT, FMT = 9958 )5
WRITE( IOUNIT, FMT = 9956 )6
WRITE( IOUNIT, FMT = 9957 )7
WRITE( IOUNIT, FMT = 9955 )8
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'HE' ) ) THEN
*
* HE: Hermitian indefinite full
*
IF( LSAME( C3, 'E' ) ) THEN
WRITE( IOUNIT, FMT = 9992 )PATH, 'Hermitian'
ELSE
WRITE( IOUNIT, FMT = 9991 )PATH, 'Hermitian'
END IF
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
IF( SORD ) THEN
WRITE( IOUNIT, FMT = 9972 )
ELSE
WRITE( IOUNIT, FMT = 9971 )
END IF
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9953 )1
WRITE( IOUNIT, FMT = 9961 )2
WRITE( IOUNIT, FMT = 9960 )3
WRITE( IOUNIT, FMT = 9960 )4
WRITE( IOUNIT, FMT = 9959 )5
WRITE( IOUNIT, FMT = 9958 )6
WRITE( IOUNIT, FMT = 9956 )7
WRITE( IOUNIT, FMT = 9957 )8
WRITE( IOUNIT, FMT = 9955 )9
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'HP' ) ) THEN
*
* HP: Hermitian indefinite packed
*
IF( LSAME( C3, 'E' ) ) THEN
WRITE( IOUNIT, FMT = 9992 )PATH, 'Hermitian'
ELSE
WRITE( IOUNIT, FMT = 9991 )PATH, 'Hermitian'
END IF
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9972 )
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9953 )1
WRITE( IOUNIT, FMT = 9961 )2
WRITE( IOUNIT, FMT = 9960 )3
WRITE( IOUNIT, FMT = 9959 )4
WRITE( IOUNIT, FMT = 9958 )5
WRITE( IOUNIT, FMT = 9956 )6
WRITE( IOUNIT, FMT = 9957 )7
WRITE( IOUNIT, FMT = 9955 )8
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'TR' ) .OR. LSAMEN( 2, P2, 'TP' ) ) THEN
*
* TR: Triangular full
* TP: Triangular packed
*
IF( LSAME( C3, 'R' ) ) THEN
WRITE( IOUNIT, FMT = 9990 )PATH
SUBNAM = PATH( 1: 1 ) // 'LATRS'
ELSE
WRITE( IOUNIT, FMT = 9989 )PATH
SUBNAM = PATH( 1: 1 ) // 'LATPS'
END IF
WRITE( IOUNIT, FMT = 9966 )PATH
WRITE( IOUNIT, FMT = 9965 )SUBNAM(1:LEN_TRIM( SUBNAM ))
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9961 )1
WRITE( IOUNIT, FMT = 9960 )2
WRITE( IOUNIT, FMT = 9959 )3
WRITE( IOUNIT, FMT = 9958 )4
WRITE( IOUNIT, FMT = 9957 )5
WRITE( IOUNIT, FMT = 9956 )6
WRITE( IOUNIT, FMT = 9955 )7
WRITE( IOUNIT, FMT = 9951 )SUBNAM(1:LEN_TRIM( SUBNAM )), 8
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'TB' ) ) THEN
*
* TB: Triangular band
*
WRITE( IOUNIT, FMT = 9988 )PATH
SUBNAM = PATH( 1: 1 ) // 'LATBS'
WRITE( IOUNIT, FMT = 9964 )PATH
WRITE( IOUNIT, FMT = 9963 )SUBNAM(1:LEN_TRIM( SUBNAM ))
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9960 )1
WRITE( IOUNIT, FMT = 9959 )2
WRITE( IOUNIT, FMT = 9958 )3
WRITE( IOUNIT, FMT = 9957 )4
WRITE( IOUNIT, FMT = 9956 )5
WRITE( IOUNIT, FMT = 9955 )6
WRITE( IOUNIT, FMT = 9951 )SUBNAM(1:LEN_TRIM( SUBNAM )), 7
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'QR' ) ) THEN
*
* QR decomposition of rectangular matrices
*
WRITE( IOUNIT, FMT = 9987 )PATH, 'QR'
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9970 )
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9950 )1
WRITE( IOUNIT, FMT = 6950 )8
WRITE( IOUNIT, FMT = 9946 )2
WRITE( IOUNIT, FMT = 9944 )3, 'M'
WRITE( IOUNIT, FMT = 9943 )4, 'M'
WRITE( IOUNIT, FMT = 9942 )5, 'M'
WRITE( IOUNIT, FMT = 9941 )6, 'M'
WRITE( IOUNIT, FMT = 9960 )7
WRITE( IOUNIT, FMT = 6660 )9
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'LQ' ) ) THEN
*
* LQ decomposition of rectangular matrices
*
WRITE( IOUNIT, FMT = 9987 )PATH, 'LQ'
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9970 )
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9949 )1
WRITE( IOUNIT, FMT = 9945 )2
WRITE( IOUNIT, FMT = 9944 )3, 'N'
WRITE( IOUNIT, FMT = 9943 )4, 'N'
WRITE( IOUNIT, FMT = 9942 )5, 'N'
WRITE( IOUNIT, FMT = 9941 )6, 'N'
WRITE( IOUNIT, FMT = 9960 )7
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'QL' ) ) THEN
*
* QL decomposition of rectangular matrices
*
WRITE( IOUNIT, FMT = 9987 )PATH, 'QL'
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9970 )
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9948 )1
WRITE( IOUNIT, FMT = 9946 )2
WRITE( IOUNIT, FMT = 9944 )3, 'M'
WRITE( IOUNIT, FMT = 9943 )4, 'M'
WRITE( IOUNIT, FMT = 9942 )5, 'M'
WRITE( IOUNIT, FMT = 9941 )6, 'M'
WRITE( IOUNIT, FMT = 9960 )7
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'RQ' ) ) THEN
*
* RQ decomposition of rectangular matrices
*
WRITE( IOUNIT, FMT = 9987 )PATH, 'RQ'
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9970 )
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9947 )1
WRITE( IOUNIT, FMT = 9945 )2
WRITE( IOUNIT, FMT = 9944 )3, 'N'
WRITE( IOUNIT, FMT = 9943 )4, 'N'
WRITE( IOUNIT, FMT = 9942 )5, 'N'
WRITE( IOUNIT, FMT = 9941 )6, 'N'
WRITE( IOUNIT, FMT = 9960 )7
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'QP' ) ) THEN
*
* QR decomposition with column pivoting
*
WRITE( IOUNIT, FMT = 9986 )PATH
WRITE( IOUNIT, FMT = 9969 )
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9940 )1
WRITE( IOUNIT, FMT = 9939 )2
WRITE( IOUNIT, FMT = 9938 )3
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'TZ' ) ) THEN
*
* TZ: Trapezoidal
*
WRITE( IOUNIT, FMT = 9985 )PATH
WRITE( IOUNIT, FMT = 9968 )
WRITE( IOUNIT, FMT = 9929 )C1, C1
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
WRITE( IOUNIT, FMT = 9940 )1
WRITE( IOUNIT, FMT = 9937 )2
WRITE( IOUNIT, FMT = 9938 )3
WRITE( IOUNIT, FMT = 9940 )4
WRITE( IOUNIT, FMT = 9937 )5
WRITE( IOUNIT, FMT = 9938 )6
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'LS' ) ) THEN
*
* LS: Least Squares driver routines for
* LS, LSD, LSS, LSX and LSY.
*
WRITE( IOUNIT, FMT = 9984 )PATH
WRITE( IOUNIT, FMT = 9967 )
WRITE( IOUNIT, FMT = 9921 )C1, C1, C1, C1, C1
WRITE( IOUNIT, FMT = 9935 )1
WRITE( IOUNIT, FMT = 9931 )2
WRITE( IOUNIT, FMT = 9933 )3
WRITE( IOUNIT, FMT = 9935 )4
WRITE( IOUNIT, FMT = 9934 )5
WRITE( IOUNIT, FMT = 9932 )6
WRITE( IOUNIT, FMT = 9920 )
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'LU' ) ) THEN
*
* LU factorization variants
*
WRITE( IOUNIT, FMT = 9983 )PATH
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9979 )
WRITE( IOUNIT, FMT = '( '' Test ratio:'' )' )
WRITE( IOUNIT, FMT = 9962 )1
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'CH' ) ) THEN
*
* Cholesky factorization variants
*
WRITE( IOUNIT, FMT = 9982 )PATH
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9974 )
WRITE( IOUNIT, FMT = '( '' Test ratio:'' )' )
WRITE( IOUNIT, FMT = 9954 )1
WRITE( IOUNIT, FMT = '( '' Messages:'' )' )
*
ELSE IF( LSAMEN( 2, P2, 'QS' ) ) THEN
*
* QR factorization variants
*
WRITE( IOUNIT, FMT = 9981 )PATH
WRITE( IOUNIT, FMT = '( '' Matrix types:'' )' )
WRITE( IOUNIT, FMT = 9970 )
WRITE( IOUNIT, FMT = '( '' Test ratios:'' )' )
*
ELSE
*
* Print error message if no header is available.
*
WRITE( IOUNIT, FMT = 9980 )PATH
END IF
*
* First line of header
*
9999 FORMAT( / 1X, A3, ': General dense matrices' )
9998 FORMAT( / 1X, A3, ': General band matrices' )
9997 FORMAT( / 1X, A3, ': General tridiagonal' )
9996 FORMAT( / 1X, A3, ': ', A9, ' positive definite matrices' )
9995 FORMAT( / 1X, A3, ': ', A9, ' positive definite packed matrices'
$ )
9994 FORMAT( / 1X, A3, ': ', A9, ' positive definite band matrices' )
9993 FORMAT( / 1X, A3, ': ', A9, ' positive definite tridiagonal' )
9992 FORMAT( / 1X, A3, ': ', A9, ' indefinite matrices' )
9991 FORMAT( / 1X, A3, ': ', A9, ' indefinite packed matrices' )
9990 FORMAT( / 1X, A3, ': Triangular matrices' )
9989 FORMAT( / 1X, A3, ': Triangular packed matrices' )
9988 FORMAT( / 1X, A3, ': Triangular band matrices' )
9987 FORMAT( / 1X, A3, ': ', A2, ' factorization of general matrices'
$ )
9986 FORMAT( / 1X, A3, ': QR factorization with column pivoting' )
9985 FORMAT( / 1X, A3, ': RQ factorization of trapezoidal matrix' )
9984 FORMAT( / 1X, A3, ': Least squares driver routines' )
9983 FORMAT( / 1X, A3, ': LU factorization variants' )
9982 FORMAT( / 1X, A3, ': Cholesky factorization variants' )
9981 FORMAT( / 1X, A3, ': QR factorization variants' )
9980 FORMAT( / 1X, A3, ': No header available' )
*
* GE matrix types
*
9979 FORMAT( 4X, '1. Diagonal', 24X, '7. Last n/2 columns zero', / 4X,
$ '2. Upper triangular', 16X,
$ '8. Random, CNDNUM = sqrt(0.1/EPS)', / 4X,
$ '3. Lower triangular', 16X, '9. Random, CNDNUM = 0.1/EPS',
$ / 4X, '4. Random, CNDNUM = 2', 13X,
$ '10. Scaled near underflow', / 4X, '5. First column zero',
$ 14X, '11. Scaled near overflow', / 4X,
$ '6. Last column zero' )
*
* GB matrix types
*
9978 FORMAT( 4X, '1. Random, CNDNUM = 2', 14X,
$ '5. Random, CNDNUM = sqrt(0.1/EPS)', / 4X,
$ '2. First column zero', 15X, '6. Random, CNDNUM = .01/EPS',
$ / 4X, '3. Last column zero', 16X,
$ '7. Scaled near underflow', / 4X,
$ '4. Last n/2 columns zero', 11X, '8. Scaled near overflow' )
*
* GT matrix types
*
9977 FORMAT( ' Matrix types (1-6 have specified condition numbers):',
$ / 4X, '1. Diagonal', 24X, '7. Random, unspecified CNDNUM',
$ / 4X, '2. Random, CNDNUM = 2', 14X, '8. First column zero',
$ / 4X, '3. Random, CNDNUM = sqrt(0.1/EPS)', 2X,
$ '9. Last column zero', / 4X, '4. Random, CNDNUM = 0.1/EPS',
$ 7X, '10. Last n/2 columns zero', / 4X,
$ '5. Scaled near underflow', 10X,
$ '11. Scaled near underflow', / 4X,
$ '6. Scaled near overflow', 11X, '12. Scaled near overflow' )
*
* PT matrix types
*
9976 FORMAT( ' Matrix types (1-6 have specified condition numbers):',
$ / 4X, '1. Diagonal', 24X, '7. Random, unspecified CNDNUM',
$ / 4X, '2. Random, CNDNUM = 2', 14X,
$ '8. First row and column zero', / 4X,
$ '3. Random, CNDNUM = sqrt(0.1/EPS)', 2X,
$ '9. Last row and column zero', / 4X,
$ '4. Random, CNDNUM = 0.1/EPS', 7X,
$ '10. Middle row and column zero', / 4X,
$ '5. Scaled near underflow', 10X,
$ '11. Scaled near underflow', / 4X,
$ '6. Scaled near overflow', 11X, '12. Scaled near overflow' )
*
* PO, PP matrix types
*
9975 FORMAT( 4X, '1. Diagonal', 24X,
$ '6. Random, CNDNUM = sqrt(0.1/EPS)', / 4X,
$ '2. Random, CNDNUM = 2', 14X, '7. Random, CNDNUM = 0.1/EPS',
$ / 3X, '*3. First row and column zero', 7X,
$ '8. Scaled near underflow', / 3X,
$ '*4. Last row and column zero', 8X,
$ '9. Scaled near overflow', / 3X,
$ '*5. Middle row and column zero', / 3X,
$ '(* - tests error exits from ', A3,
$ 'TRF, no test ratios are computed)' )
*
* CH matrix types
*
9974 FORMAT( 4X, '1. Diagonal', 24X,
$ '6. Random, CNDNUM = sqrt(0.1/EPS)', / 4X,
$ '2. Random, CNDNUM = 2', 14X, '7. Random, CNDNUM = 0.1/EPS',
$ / 3X, '*3. First row and column zero', 7X,
$ '8. Scaled near underflow', / 3X,
$ '*4. Last row and column zero', 8X,
$ '9. Scaled near overflow', / 3X,
$ '*5. Middle row and column zero', / 3X,
$ '(* - tests error exits, no test ratios are computed)' )
*
* PS matrix types
*
8973 FORMAT( 4X, '1. Diagonal', / 4X, '2. Random, CNDNUM = 2', 14X,
$ / 3X, '*3. Nonzero eigenvalues of: D(1:RANK-1)=1 and ',
$ 'D(RANK) = 1.0/', A4, / 3X,
$ '*4. Nonzero eigenvalues of: D(1)=1 and ',
$ ' D(2:RANK) = 1.0/', A4, / 3X,
$ '*5. Nonzero eigenvalues of: D(I) = ', A4,
$ '**(-(I-1)/(RANK-1)) ', ' I=1:RANK', / 4X,
$ '6. Random, CNDNUM = sqrt(0.1/EPS)', / 4X,
$ '7. Random, CNDNUM = 0.1/EPS', / 4X,
$ '8. Scaled near underflow', / 4X, '9. Scaled near overflow',
$ / 3X, '(* - Semi-definite tests )' )
8972 FORMAT( 3X, 'RANK minus computed rank, returned by ', A, 'PSTRF' )
*
* PB matrix types
*
9973 FORMAT( 4X, '1. Random, CNDNUM = 2', 14X,
$ '5. Random, CNDNUM = sqrt(0.1/EPS)', / 3X,
$ '*2. First row and column zero', 7X,
$ '6. Random, CNDNUM = 0.1/EPS', / 3X,
$ '*3. Last row and column zero', 8X,
$ '7. Scaled near underflow', / 3X,
$ '*4. Middle row and column zero', 6X,
$ '8. Scaled near overflow', / 3X,
$ '(* - tests error exits from ', A3,
$ 'TRF, no test ratios are computed)' )
*
* SSY, SSP, CHE, CHP matrix types
*
9972 FORMAT( 4X, '1. Diagonal', 24X,
$ '6. Last n/2 rows and columns zero', / 4X,
$ '2. Random, CNDNUM = 2', 14X,
$ '7. Random, CNDNUM = sqrt(0.1/EPS)', / 4X,
$ '3. First row and column zero', 7X,
$ '8. Random, CNDNUM = 0.1/EPS', / 4X,
$ '4. Last row and column zero', 8X,
$ '9. Scaled near underflow', / 4X,
$ '5. Middle row and column zero', 5X,
$ '10. Scaled near overflow' )
*
* CSY, CSP matrix types
*
9971 FORMAT( 4X, '1. Diagonal', 24X,
$ '7. Random, CNDNUM = sqrt(0.1/EPS)', / 4X,
$ '2. Random, CNDNUM = 2', 14X, '8. Random, CNDNUM = 0.1/EPS',
$ / 4X, '3. First row and column zero', 7X,
$ '9. Scaled near underflow', / 4X,
$ '4. Last row and column zero', 7X,
$ '10. Scaled near overflow', / 4X,
$ '5. Middle row and column zero', 5X,
$ '11. Block diagonal matrix', / 4X,
$ '6. Last n/2 rows and columns zero' )
*
* QR matrix types
*
9970 FORMAT( 4X, '1. Diagonal', 24X,
$ '5. Random, CNDNUM = sqrt(0.1/EPS)', / 4X,
$ '2. Upper triangular', 16X, '6. Random, CNDNUM = 0.1/EPS',
$ / 4X, '3. Lower triangular', 16X,
$ '7. Scaled near underflow', / 4X, '4. Random, CNDNUM = 2',
$ 14X, '8. Scaled near overflow' )
*
* QP matrix types
*
9969 FORMAT( ' Matrix types (2-6 have condition 1/EPS):', / 4X,
$ '1. Zero matrix', 21X, '4. First n/2 columns fixed', / 4X,
$ '2. One small eigenvalue', 12X, '5. Last n/2 columns fixed',
$ / 4X, '3. Geometric distribution', 10X,
$ '6. Every second column fixed' )
*
* TZ matrix types
*
9968 FORMAT( ' Matrix types (2-3 have condition 1/EPS):', / 4X,
$ '1. Zero matrix', / 4X, '2. One small eigenvalue', / 4X,
$ '3. Geometric distribution' )
*
* LS matrix types
*
9967 FORMAT( ' Matrix types (1-3: full rank, 4-6: rank deficient):',
$ / 4X, '1 and 4. Normal scaling', / 4X,
$ '2 and 5. Scaled near overflow', / 4X,
$ '3 and 6. Scaled near underflow' )
*
* TR, TP matrix types
*
9966 FORMAT( ' Matrix types for ', A3, ' routines:', / 4X,
$ '1. Diagonal', 24X, '6. Scaled near overflow', / 4X,
$ '2. Random, CNDNUM = 2', 14X, '7. Identity', / 4X,
$ '3. Random, CNDNUM = sqrt(0.1/EPS) ',
$ '8. Unit triangular, CNDNUM = 2', / 4X,
$ '4. Random, CNDNUM = 0.1/EPS', 8X,
$ '9. Unit, CNDNUM = sqrt(0.1/EPS)', / 4X,
$ '5. Scaled near underflow', 10X,
$ '10. Unit, CNDNUM = 0.1/EPS' )
9965 FORMAT( ' Special types for testing ', A, ':', / 3X,
$ '11. Matrix elements are O(1), large right hand side', / 3X,
$ '12. First diagonal causes overflow,',
$ ' offdiagonal column norms < 1', / 3X,
$ '13. First diagonal causes overflow,',
$ ' offdiagonal column norms > 1', / 3X,
$ '14. Growth factor underflows, solution does not overflow',
$ / 3X, '15. Small diagonal causes gradual overflow', / 3X,
$ '16. One zero diagonal element', / 3X,
$ '17. Large offdiagonals cause overflow when adding a column'
$ , / 3X, '18. Unit triangular with large right hand side' )
*
* TB matrix types
*
9964 FORMAT( ' Matrix types for ', A3, ' routines:', / 4X,
$ '1. Random, CNDNUM = 2', 14X, '6. Identity', / 4X,
$ '2. Random, CNDNUM = sqrt(0.1/EPS) ',
$ '7. Unit triangular, CNDNUM = 2', / 4X,
$ '3. Random, CNDNUM = 0.1/EPS', 8X,
$ '8. Unit, CNDNUM = sqrt(0.1/EPS)', / 4X,
$ '4. Scaled near underflow', 11X,
$ '9. Unit, CNDNUM = 0.1/EPS', / 4X,
$ '5. Scaled near overflow' )
9963 FORMAT( ' Special types for testing ', A, ':', / 3X,
$ '10. Matrix elements are O(1), large right hand side', / 3X,
$ '11. First diagonal causes overflow,',
$ ' offdiagonal column norms < 1', / 3X,
$ '12. First diagonal causes overflow,',
$ ' offdiagonal column norms > 1', / 3X,
$ '13. Growth factor underflows, solution does not overflow',
$ / 3X, '14. Small diagonal causes gradual overflow', / 3X,
$ '15. One zero diagonal element', / 3X,
$ '16. Large offdiagonals cause overflow when adding a column'
$ , / 3X, '17. Unit triangular with large right hand side' )
*
* Test ratios
*
9962 FORMAT( 3X, I2, ': norm( L * U - A ) / ( N * norm(A) * EPS )' )
9961 FORMAT( 3X, I2, ': norm( I - A*AINV ) / ',
$ '( N * norm(A) * norm(AINV) * EPS )' )
9960 FORMAT( 3X, I2, ': norm( B - A * X ) / ',
$ '( norm(A) * norm(X) * EPS )' )
6660 FORMAT( 3X, I2, ': diagonal is not non-negative')
9959 FORMAT( 3X, I2, ': norm( X - XACT ) / ',
$ '( norm(XACT) * CNDNUM * EPS )' )
9958 FORMAT( 3X, I2, ': norm( X - XACT ) / ',
$ '( norm(XACT) * CNDNUM * EPS ), refined' )
9957 FORMAT( 3X, I2, ': norm( X - XACT ) / ',
$ '( norm(XACT) * (error bound) )' )
9956 FORMAT( 3X, I2, ': (backward error) / EPS' )
9955 FORMAT( 3X, I2, ': RCOND * CNDNUM - 1.0' )
9954 FORMAT( 3X, I2, ': norm( U'' * U - A ) / ( N * norm(A) * EPS )',
$ ', or', / 7X, 'norm( L * L'' - A ) / ( N * norm(A) * EPS )'
$ )
8950 FORMAT( 3X,
$ 'norm( P * U'' * U * P'' - A ) / ( N * norm(A) * EPS )',
$ ', or', / 3X,
$ 'norm( P * L * L'' * P'' - A ) / ( N * norm(A) * EPS )' )
9953 FORMAT( 3X, I2, ': norm( U*D*U'' - A ) / ( N * norm(A) * EPS )',
$ ', or', / 7X, 'norm( L*D*L'' - A ) / ( N * norm(A) * EPS )'
$ )
9952 FORMAT( 3X, I2, ': norm( U''*D*U - A ) / ( N * norm(A) * EPS )',
$ ', or', / 7X, 'norm( L*D*L'' - A ) / ( N * norm(A) * EPS )'
$ )
9951 FORMAT( ' Test ratio for ', A, ':', / 3X, I2,
$ ': norm( s*b - A*x ) / ( norm(A) * norm(x) * EPS )' )
9950 FORMAT( 3X, I2, ': norm( R - Q'' * A ) / ( M * norm(A) * EPS )' )
6950 FORMAT( 3X, I2, ': norm( R - Q'' * A ) / ( M * norm(A) * EPS )
$ [RFPG]' )
9949 FORMAT( 3X, I2, ': norm( L - A * Q'' ) / ( N * norm(A) * EPS )' )
9948 FORMAT( 3X, I2, ': norm( L - Q'' * A ) / ( M * norm(A) * EPS )' )
9947 FORMAT( 3X, I2, ': norm( R - A * Q'' ) / ( N * norm(A) * EPS )' )
9946 FORMAT( 3X, I2, ': norm( I - Q''*Q ) / ( M * EPS )' )
9945 FORMAT( 3X, I2, ': norm( I - Q*Q'' ) / ( N * EPS )' )
9944 FORMAT( 3X, I2, ': norm( Q*C - Q*C ) / ', '( ', A1,
$ ' * norm(C) * EPS )' )
9943 FORMAT( 3X, I2, ': norm( C*Q - C*Q ) / ', '( ', A1,
$ ' * norm(C) * EPS )' )
9942 FORMAT( 3X, I2, ': norm( Q''*C - Q''*C )/ ', '( ', A1,
$ ' * norm(C) * EPS )' )
9941 FORMAT( 3X, I2, ': norm( C*Q'' - C*Q'' )/ ', '( ', A1,
$ ' * norm(C) * EPS )' )
9940 FORMAT( 3X, I2, ': norm(svd(A) - svd(R)) / ',
$ '( M * norm(svd(R)) * EPS )' )
9939 FORMAT( 3X, I2, ': norm( A*P - Q*R ) / ( M * norm(A) * EPS )'
$ )
9938 FORMAT( 3X, I2, ': norm( I - Q''*Q ) / ( M * EPS )' )
9937 FORMAT( 3X, I2, ': norm( A - R*Q ) / ( M * norm(A) * EPS )'
$ )
9936 FORMAT( ' Test ratios (1-2: ', A1, 'GELS, 3-6: ', A1,
$ 'GELSS, 7-10: ', A1, 'GELSX):' )
9935 FORMAT( 3X, I2, ': norm( B - A * X ) / ',
$ '( max(M,N) * norm(A) * norm(X) * EPS )' )
9934 FORMAT( 3X, I2, ': norm( (A*X-B)'' *A ) / ',
$ '( max(M,N,NRHS) * norm(A) * norm(B) * EPS )' )
9933 FORMAT( 3X, I2, ': norm(svd(A)-svd(R)) / ',
$ '( min(M,N) * norm(svd(R)) * EPS )' )
9932 FORMAT( 3X, I2, ': Check if X is in the row space of A or A''' )
9931 FORMAT( 3X, I2, ': norm( (A*X-B)'' *A ) / ',
$ '( max(M,N,NRHS) * norm(A) * norm(B) * EPS )', / 7X,
$ 'if TRANS=''N'' and M.GE.N or TRANS=''T'' and M.LT.N, ',
$ 'otherwise', / 7X,
$ 'check if X is in the row space of A or A'' ',
$ '(overdetermined case)' )
9930 FORMAT( 3X, ' 7-10: same as 3-6' )
9929 FORMAT( ' Test ratios (1-3: ', A1, 'TZRQF, 4-6: ', A1,
$ 'TZRZF):' )
9920 FORMAT( 3X, ' 7-10: same as 3-6', 3X, ' 11-14: same as 3-6',
$ 3X, ' 15-18: same as 3-6' )
9921 FORMAT( ' Test ratios:', / ' (1-2: ', A1, 'GELS, 3-6: ', A1,
$ 'GELSX, 7-10: ', A1, 'GELSY, 11-14: ', A1, 'GELSS, 15-18: ',
$ A1, 'GELSD)' )
*
RETURN
*
* End of ALAHD
*
END
| bsd-3-clause |
mverleg/1957 | lib/lapack/ctgexc.f | 25 | 8930 | *> \brief \b CTGEXC
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download CTGEXC + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ctgexc.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ctgexc.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ctgexc.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE CTGEXC( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z,
* LDZ, IFST, ILST, INFO )
*
* .. Scalar Arguments ..
* LOGICAL WANTQ, WANTZ
* INTEGER IFST, ILST, INFO, LDA, LDB, LDQ, LDZ, N
* ..
* .. Array Arguments ..
* COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
* $ Z( LDZ, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> CTGEXC reorders the generalized Schur decomposition of a complex
*> matrix pair (A,B), using an unitary equivalence transformation
*> (A, B) := Q * (A, B) * Z**H, so that the diagonal block of (A, B) with
*> row index IFST is moved to row ILST.
*>
*> (A, B) must be in generalized Schur canonical form, that is, A and
*> B are both upper triangular.
*>
*> Optionally, the matrices Q and Z of generalized Schur vectors are
*> updated.
*>
*> Q(in) * A(in) * Z(in)**H = Q(out) * A(out) * Z(out)**H
*> Q(in) * B(in) * Z(in)**H = Q(out) * B(out) * Z(out)**H
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] WANTQ
*> \verbatim
*> WANTQ is LOGICAL
*> .TRUE. : update the left transformation matrix Q;
*> .FALSE.: do not update Q.
*> \endverbatim
*>
*> \param[in] WANTZ
*> \verbatim
*> WANTZ is LOGICAL
*> .TRUE. : update the right transformation matrix Z;
*> .FALSE.: do not update Z.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrices A and B. N >= 0.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is COMPLEX array, dimension (LDA,N)
*> On entry, the upper triangular matrix A in the pair (A, B).
*> On exit, the updated matrix A.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[in,out] B
*> \verbatim
*> B is COMPLEX array, dimension (LDB,N)
*> On entry, the upper triangular matrix B in the pair (A, B).
*> On exit, the updated matrix B.
*> \endverbatim
*>
*> \param[in] LDB
*> \verbatim
*> LDB is INTEGER
*> The leading dimension of the array B. LDB >= max(1,N).
*> \endverbatim
*>
*> \param[in,out] Q
*> \verbatim
*> Q is COMPLEX array, dimension (LDZ,N)
*> On entry, if WANTQ = .TRUE., the unitary matrix Q.
*> On exit, the updated matrix Q.
*> If WANTQ = .FALSE., Q is not referenced.
*> \endverbatim
*>
*> \param[in] LDQ
*> \verbatim
*> LDQ is INTEGER
*> The leading dimension of the array Q. LDQ >= 1;
*> If WANTQ = .TRUE., LDQ >= N.
*> \endverbatim
*>
*> \param[in,out] Z
*> \verbatim
*> Z is COMPLEX array, dimension (LDZ,N)
*> On entry, if WANTZ = .TRUE., the unitary matrix Z.
*> On exit, the updated matrix Z.
*> If WANTZ = .FALSE., Z is not referenced.
*> \endverbatim
*>
*> \param[in] LDZ
*> \verbatim
*> LDZ is INTEGER
*> The leading dimension of the array Z. LDZ >= 1;
*> If WANTZ = .TRUE., LDZ >= N.
*> \endverbatim
*>
*> \param[in] IFST
*> \verbatim
*> IFST is INTEGER
*> \endverbatim
*>
*> \param[in,out] ILST
*> \verbatim
*> ILST is INTEGER
*> Specify the reordering of the diagonal blocks of (A, B).
*> The block with row index IFST is moved to row ILST, by a
*> sequence of swapping between adjacent blocks.
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> =0: Successful exit.
*> <0: if INFO = -i, the i-th argument had an illegal value.
*> =1: The transformed matrix pair (A, B) would be too far
*> from generalized Schur form; the problem is ill-
*> conditioned. (A, B) may have been partially reordered,
*> and ILST points to the first row of the current
*> position of the block being moved.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup complexGEcomputational
*
*> \par Contributors:
* ==================
*>
*> Bo Kagstrom and Peter Poromaa, Department of Computing Science,
*> Umea University, S-901 87 Umea, Sweden.
*
*> \par References:
* ================
*>
*> [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the
*> Generalized Real Schur Form of a Regular Matrix Pair (A, B), in
*> M.S. Moonen et al (eds), Linear Algebra for Large Scale and
*> Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218.
*> \n
*> [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified
*> Eigenvalues of a Regular Matrix Pair (A, B) and Condition
*> Estimation: Theory, Algorithms and Software, Report
*> UMINF - 94.04, Department of Computing Science, Umea University,
*> S-901 87 Umea, Sweden, 1994. Also as LAPACK Working Note 87.
*> To appear in Numerical Algorithms, 1996.
*> \n
*> [3] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software
*> for Solving the Generalized Sylvester Equation and Estimating the
*> Separation between Regular Matrix Pairs, Report UMINF - 93.23,
*> Department of Computing Science, Umea University, S-901 87 Umea,
*> Sweden, December 1993, Revised April 1994, Also as LAPACK working
*> Note 75. To appear in ACM Trans. on Math. Software, Vol 22, No 1,
*> 1996.
*>
* =====================================================================
SUBROUTINE CTGEXC( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z,
$ LDZ, IFST, ILST, INFO )
*
* -- LAPACK computational routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
LOGICAL WANTQ, WANTZ
INTEGER IFST, ILST, INFO, LDA, LDB, LDQ, LDZ, N
* ..
* .. Array Arguments ..
COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
$ Z( LDZ, * )
* ..
*
* =====================================================================
*
* .. Local Scalars ..
INTEGER HERE
* ..
* .. External Subroutines ..
EXTERNAL CTGEX2, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
* Decode and test input arguments.
INFO = 0
IF( N.LT.0 ) THEN
INFO = -3
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -5
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -7
ELSE IF( LDQ.LT.1 .OR. WANTQ .AND. ( LDQ.LT.MAX( 1, N ) ) ) THEN
INFO = -9
ELSE IF( LDZ.LT.1 .OR. WANTZ .AND. ( LDZ.LT.MAX( 1, N ) ) ) THEN
INFO = -11
ELSE IF( IFST.LT.1 .OR. IFST.GT.N ) THEN
INFO = -12
ELSE IF( ILST.LT.1 .OR. ILST.GT.N ) THEN
INFO = -13
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CTGEXC', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.LE.1 )
$ RETURN
IF( IFST.EQ.ILST )
$ RETURN
*
IF( IFST.LT.ILST ) THEN
*
HERE = IFST
*
10 CONTINUE
*
* Swap with next one below
*
CALL CTGEX2( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z, LDZ,
$ HERE, INFO )
IF( INFO.NE.0 ) THEN
ILST = HERE
RETURN
END IF
HERE = HERE + 1
IF( HERE.LT.ILST )
$ GO TO 10
HERE = HERE - 1
ELSE
HERE = IFST - 1
*
20 CONTINUE
*
* Swap with next one above
*
CALL CTGEX2( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z, LDZ,
$ HERE, INFO )
IF( INFO.NE.0 ) THEN
ILST = HERE
RETURN
END IF
HERE = HERE - 1
IF( HERE.GE.ILST )
$ GO TO 20
HERE = HERE + 1
END IF
ILST = HERE
RETURN
*
* End of CTGEXC
*
END
| bsd-3-clause |
davidgiven/gcc-vc4 | gcc/testsuite/gfortran.dg/shiftalr_2.F90 | 162 | 1511 | ! Test the SHIFTA, SHIFTL and SHIFTR intrinsics.
!
! { dg-do run }
! { dg-options "-ffree-line-length-none" }
! { dg-require-effective-target fortran_integer_16 }
implicit none
#define CHECK(I,SHIFT,RESA,RESL,RESR) \
if (shifta(I,SHIFT) /= RESA) call abort ; \
if (shiftr(I,SHIFT) /= RESR) call abort ; \
if (shiftl(I,SHIFT) /= RESL) call abort ; \
if (run_shifta(I,SHIFT) /= RESA) call abort ; \
if (run_shiftr(I,SHIFT) /= RESR) call abort ; \
if (run_shiftl(I,SHIFT) /= RESL) call abort ; \
if (ishft(I,SHIFT) /= RESL) call abort ; \
if (ishft(I,-SHIFT) /= RESR) call abort ; \
if (run_ishft(I,SHIFT) /= RESL) call abort ; \
if (run_ishft(I,-SHIFT) /= RESR) call abort
CHECK(0_16,0,0_16,0_16,0_16)
CHECK(11_16,0,11_16,11_16,11_16)
CHECK(-11_16,0,-11_16,-11_16,-11_16)
CHECK(0_16,1,0_16,0_16,0_16)
CHECK(11_16,1,5_16,22_16,5_16)
CHECK(11_16,2,2_16,44_16,2_16)
CHECK(-11_16,1,-6_16,-22_16,huge(0_16)-5_16)
contains
function run_shifta (i, shift) result(res)
integer(kind=16) :: i, res
integer :: shift
res = shifta(i,shift)
end function
function run_shiftl (i, shift) result(res)
integer(kind=16) :: i, res
integer :: shift
res = shiftl(i,shift)
end function
function run_shiftr (i, shift) result(res)
integer(kind=16) :: i, res
integer :: shift
res = shiftr(i,shift)
end function
function run_ishft (i, shift) result(res)
integer(kind=16) :: i, res
integer :: shift
res = ishft(i,shift)
end function
end
| gpl-2.0 |
Vandemar/calypso | src/Fortran_libraries/SERIAL_src/FFT_wrapper/t_FFTPACK5_wrapper.f90 | 3 | 9075 | !>@file t_FFTPACK5_wrapper.f90
!!@brief module t_FFTPACK5_wrapper
!!
!!@author H. Matsui
!!@date Programmed on Apr., 2013
!
!>@brief Fourier transform using FFTPACK5
!!
!!@verbatim
!! ------------------------------------------------------------------
!!
!! subroutine init_WK_FFTPACK_t(Nsmp, Nstacksmp, Nfft, WK)
!! subroutine finalize_WK_FFTPACK_t(WK)
!! subroutine verify_wk_FFTPACK_t(Nsmp, Nstacksmp, Nfft, WK)
!! ------------------------------------------------------------------
!! wrapper subroutine for initierize FFT
!! ------------------------------------------------------------------
!!
!! subroutine CALYPSO_RFFTMF_t(Nsmp, Nstacksmp, M, Nfft, X, WK)
!! ------------------------------------------------------------------
!!
!! wrapper subroutine for forward Fourier transform by FFTPACK5
!!
!! a_{k} = \frac{2}{Nfft} \sum_{j=0}^{Nfft-1} x_{j}
!! * \cos (\frac{2\pi j k}{Nfft})
!! b_{k} = \frac{2}{Nfft} \sum_{j=0}^{Nfft-1} x_{j}
!! * \cos (\frac{2\pi j k}{Nfft})
!!
!! a_{0} = \frac{1}{Nfft} \sum_{j=0}^{Nfft-1} x_{j}
!! K = Nfft/2....
!! a_{k} = \frac{1}{Nfft} \sum_{j=0}^{Nfft-1} x_{j}
!! * \cos (\frac{2\pi j k}{Nfft})
!!
!! ------------------------------------------------------------------
!!
!! subroutine CALYPSO_RFFTMB_t(Nsmp, Nstacksmp, M, Nfft, X, WK)
!! ------------------------------------------------------------------
!!
!! wrapper subroutine for backward Fourier transform by FFTPACK5
!!
!! x_{k} = a_{0} + (-1)^{j} a_{Nfft/2} + sum_{k=1}^{Nfft/2-1}
!! (a_{k} \cos(2\pijk/Nfft) + b_{k} \sin(2\pijk/Nfft))
!!
!! ------------------------------------------------------------------
!!
!! i = 1: a_{0}
!! i = 2: a_{Nfft/2}
!! i = 3: a_{1}
!! i = 4: b_{1}
!! ...
!! i = 2*k+1: a_{k}
!! i = 2*k+2: b_{k}
!! ...
!! i = Nfft-1: a_{Nfft/2-1}
!! i = Nfft: b_{Nfft/2-1}
!!
!! ------------------------------------------------------------------
!!@endverbatim
!!
!!@n @param Nsmp Number of SMP processors
!!@n @param Nstacksmp(0:Nsmp) End number for each SMP process
!!@n @param M Number of components for Fourier transforms
!!@n @param Nfft Data length for eadh FFT
!!@n @param X(M, Nfft) Data for Fourier transform
!!@n @param WK Work structure for FFTPACK5
!
module t_FFTPACK5_wrapper
!
use m_precision
use m_constants
!
implicit none
!
!> structure for working data for FFTPACK5
type working_FFTPACK
!> Maximum nuber of components for each SMP process
integer(kind = kint) :: Mmax_smp
!> Data for multiple Fourier transform
real(kind = 8), pointer :: X_FFTPACK5(:,:)
!
!> Work area for FFTPACK
integer(kind = kint) :: lsave_FFTPACK
!> Work constatnts for FFTPACK
real(kind = 8), pointer :: WSAVE_FFTPACK(:)
!> Work area for FFTPACK
real(kind = 8), pointer :: WORK_FFTPACK(:,:)
!> flag for length of Fourier transform
integer(kind = kint) :: iflag_fft_len = -1
!> flag for number of components for Fourier transform
integer(kind = kint) :: iflag_fft_comp = -1
end type working_FFTPACK
!
private :: alloc_work_4_FFTPACK_t, alloc_const_4_FFTPACK_t
private :: dealloc_work_4_FFTPACK_t, dealloc_const_FFTPACK_t
!
! ------------------------------------------------------------------
!
contains
!
! ------------------------------------------------------------------
!
subroutine init_WK_FFTPACK_t(Nsmp, Nstacksmp, Nfft, WK)
!
use FFTPACK5_wrapper
!
integer(kind = kint), intent(in) :: Nfft
integer(kind = kint), intent(in) :: Nsmp, Nstacksmp(0:Nsmp)
!
type(working_FFTPACK), intent(inout) :: WK
!
integer(kind = kint) :: ip
!
!
WK%Mmax_smp = Nstacksmp(1)
do ip = 1, Nsmp
WK%Mmax_smp &
& = max(WK%Mmax_smp, (Nstacksmp(ip) - Nstacksmp(ip-1)) )
end do
!
call alloc_const_4_FFTPACK_t(Nfft, WK)
call init_CALYPSO_FFTPACK(Nfft, &
& WK%lsave_FFTPACK, WK%WSAVE_FFTPACK)
!
call alloc_work_4_FFTPACK_t(Nsmp, Nfft, WK)
!
end subroutine init_WK_FFTPACK_t
!
! ------------------------------------------------------------------
!
subroutine finalize_WK_FFTPACK_t(WK)
!
type(working_FFTPACK), intent(inout) :: WK
!
!
call dealloc_const_FFTPACK_t(WK)
call dealloc_work_4_FFTPACK_t(WK)
!
end subroutine finalize_WK_FFTPACK_t
!
! ------------------------------------------------------------------
!
subroutine verify_wk_FFTPACK_t(Nsmp, Nstacksmp, Nfft, WK)
!
use FFTPACK5_wrapper
!
integer(kind = kint), intent(in) :: Nfft
integer(kind = kint), intent(in) :: Nsmp, Nstacksmp(0:Nsmp)
!
type(working_FFTPACK), intent(inout) :: WK
!
integer(kind = kint) :: ip
!
!
WK%Mmax_smp = Nstacksmp(1)
do ip = 1, Nsmp
WK%Mmax_smp &
& = max(WK%Mmax_smp, (Nstacksmp(ip) - Nstacksmp(ip-1)) )
end do
!
if(WK%iflag_fft_len .ne. Nfft) then
!
if(WK%iflag_fft_len .lt. 0) then
call alloc_const_4_FFTPACK_t(Nfft, WK)
else if( Nfft .gt. WK%iflag_fft_comp ) then
call dealloc_const_FFTPACK_t(WK)
call alloc_const_4_FFTPACK_t(Nfft, WK)
end if
!
call init_CALYPSO_FFTPACK(Nfft, &
& WK%lsave_FFTPACK, WK%WSAVE_FFTPACK)
end if
!
if(WK%iflag_fft_comp .lt. 0) then
call alloc_work_4_FFTPACK_t(Nsmp, Nfft, WK)
else if( (WK%Mmax_smp*Nfft) .gt. WK%iflag_fft_comp ) then
call dealloc_work_4_FFTPACK_t(WK)
call alloc_work_4_FFTPACK_t(Nsmp, Nfft, WK)
end if
!
end subroutine verify_wk_FFTPACK_t
!
! ------------------------------------------------------------------
! ------------------------------------------------------------------
!
subroutine CALYPSO_RFFTMF_t(Nsmp, Nstacksmp, M, Nfft, X, WK)
!
use FFTPACK5_wrapper
!
integer(kind = kint), intent(in) :: Nsmp, Nstacksmp(0:Nsmp)
integer(kind = kint), intent(in) :: M, Nfft
!
real(kind = kreal), intent(inout) :: X(M, Nfft)
type(working_FFTPACK), intent(inout) :: WK
!
!
call CALYPSO_RFFTMF_SMP(Nsmp, Nstacksmp, M, Nfft, X, &
& WK%X_FFTPACK5, WK%Mmax_smp, WK%lsave_FFTPACK, &
& WK%WSAVE_FFTPACK, WK%WORK_FFTPACK)
!
end subroutine CALYPSO_RFFTMF_t
!
! ------------------------------------------------------------------
!
subroutine CALYPSO_RFFTMB_t(Nsmp, Nstacksmp, M, Nfft, X, WK)
!
use FFTPACK5_wrapper
!
integer(kind = kint), intent(in) :: Nsmp, Nstacksmp(0:Nsmp)
integer(kind = kint), intent(in) :: M, Nfft
!
real(kind = kreal), intent(inout) :: X(M,Nfft)
type(working_FFTPACK), intent(inout) :: WK
!
!
call CALYPSO_RFFTMB_SMP(Nsmp, Nstacksmp, M, Nfft, X, &
& WK%X_FFTPACK5, WK%Mmax_smp, WK%lsave_FFTPACK, &
& WK%WSAVE_FFTPACK, WK%WORK_FFTPACK)
!
end subroutine CALYPSO_RFFTMB_t
!
! ------------------------------------------------------------------
! ------------------------------------------------------------------
!
subroutine alloc_work_4_FFTPACK_t(Nsmp, Nfft, WK)
!
integer(kind = kint), intent(in) :: Nsmp, Nfft
type(working_FFTPACK), intent(inout) :: WK
!
!
WK%iflag_fft_comp = WK%Mmax_smp*Nfft
allocate( WK%X_FFTPACK5(WK%iflag_fft_comp,Nsmp) )
allocate( WK%WORK_FFTPACK(WK%iflag_fft_comp,Nsmp) )
WK%WORK_FFTPACK = 0.0d0
!
end subroutine alloc_work_4_FFTPACK_t
!
! ------------------------------------------------------------------
!
subroutine alloc_const_4_FFTPACK_t(nfft, WK)
!
integer(kind = kint), intent(in) :: nfft
type(working_FFTPACK), intent(inout) :: WK
!
!
WK%iflag_fft_len = nfft
WK%lsave_FFTPACK = Nfft &
& + int ( log ( real(Nfft) ) / log(two) ) + ifour
allocate(WK%WSAVE_FFTPACK(WK%lsave_FFTPACK) )
WK%WSAVE_FFTPACK = 0.0d0
!
end subroutine alloc_const_4_FFTPACK_t
!
! ------------------------------------------------------------------
! ------------------------------------------------------------------
!
subroutine dealloc_work_4_FFTPACK_t(WK)
!
type(working_FFTPACK), intent(inout) :: WK
!
!
deallocate(WK%X_FFTPACK5, WK%WORK_FFTPACK)
WK%iflag_fft_comp = 0
!
end subroutine dealloc_work_4_FFTPACK_t
!
! ------------------------------------------------------------------
!
subroutine dealloc_const_FFTPACK_t(WK)
!
type(working_FFTPACK), intent(inout) :: WK
!
!
deallocate( WK%WSAVE_FFTPACK )
WK%iflag_fft_len = 0
!
end subroutine dealloc_const_FFTPACK_t
!
! ------------------------------------------------------------------
!
end module t_FFTPACK5_wrapper
| gpl-3.0 |
mverleg/1957 | lib/lapack/slas2.f | 24 | 5060 | *> \brief \b SLAS2 computes singular values of a 2-by-2 triangular matrix.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download SLAS2 + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slas2.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slas2.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slas2.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE SLAS2( F, G, H, SSMIN, SSMAX )
*
* .. Scalar Arguments ..
* REAL F, G, H, SSMAX, SSMIN
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> SLAS2 computes the singular values of the 2-by-2 matrix
*> [ F G ]
*> [ 0 H ].
*> On return, SSMIN is the smaller singular value and SSMAX is the
*> larger singular value.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] F
*> \verbatim
*> F is REAL
*> The (1,1) element of the 2-by-2 matrix.
*> \endverbatim
*>
*> \param[in] G
*> \verbatim
*> G is REAL
*> The (1,2) element of the 2-by-2 matrix.
*> \endverbatim
*>
*> \param[in] H
*> \verbatim
*> H is REAL
*> The (2,2) element of the 2-by-2 matrix.
*> \endverbatim
*>
*> \param[out] SSMIN
*> \verbatim
*> SSMIN is REAL
*> The smaller singular value.
*> \endverbatim
*>
*> \param[out] SSMAX
*> \verbatim
*> SSMAX is REAL
*> The larger singular value.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date September 2012
*
*> \ingroup auxOTHERauxiliary
*
*> \par Further Details:
* =====================
*>
*> \verbatim
*>
*> Barring over/underflow, all output quantities are correct to within
*> a few units in the last place (ulps), even in the absence of a guard
*> digit in addition/subtraction.
*>
*> In IEEE arithmetic, the code works correctly if one matrix element is
*> infinite.
*>
*> Overflow will not occur unless the largest singular value itself
*> overflows, or is within a few ulps of overflow. (On machines with
*> partial overflow, like the Cray, overflow may occur if the largest
*> singular value is within a factor of 2 of overflow.)
*>
*> Underflow is harmless if underflow is gradual. Otherwise, results
*> may correspond to a matrix modified by perturbations of size near
*> the underflow threshold.
*> \endverbatim
*>
* =====================================================================
SUBROUTINE SLAS2( F, G, H, SSMIN, SSMAX )
*
* -- LAPACK auxiliary routine (version 3.4.2) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* September 2012
*
* .. Scalar Arguments ..
REAL F, G, H, SSMAX, SSMIN
* ..
*
* ====================================================================
*
* .. Parameters ..
REAL ZERO
PARAMETER ( ZERO = 0.0E0 )
REAL ONE
PARAMETER ( ONE = 1.0E0 )
REAL TWO
PARAMETER ( TWO = 2.0E0 )
* ..
* .. Local Scalars ..
REAL AS, AT, AU, C, FA, FHMN, FHMX, GA, HA
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, MAX, MIN, SQRT
* ..
* .. Executable Statements ..
*
FA = ABS( F )
GA = ABS( G )
HA = ABS( H )
FHMN = MIN( FA, HA )
FHMX = MAX( FA, HA )
IF( FHMN.EQ.ZERO ) THEN
SSMIN = ZERO
IF( FHMX.EQ.ZERO ) THEN
SSMAX = GA
ELSE
SSMAX = MAX( FHMX, GA )*SQRT( ONE+
$ ( MIN( FHMX, GA ) / MAX( FHMX, GA ) )**2 )
END IF
ELSE
IF( GA.LT.FHMX ) THEN
AS = ONE + FHMN / FHMX
AT = ( FHMX-FHMN ) / FHMX
AU = ( GA / FHMX )**2
C = TWO / ( SQRT( AS*AS+AU )+SQRT( AT*AT+AU ) )
SSMIN = FHMN*C
SSMAX = FHMX / C
ELSE
AU = FHMX / GA
IF( AU.EQ.ZERO ) THEN
*
* Avoid possible harmful underflow if exponent range
* asymmetric (true SSMIN may not underflow even if
* AU underflows)
*
SSMIN = ( FHMN*FHMX ) / GA
SSMAX = GA
ELSE
AS = ONE + FHMN / FHMX
AT = ( FHMX-FHMN ) / FHMX
C = ONE / ( SQRT( ONE+( AS*AU )**2 )+
$ SQRT( ONE+( AT*AU )**2 ) )
SSMIN = ( FHMN*C )*AU
SSMIN = SSMIN + SSMIN
SSMAX = GA / ( C+C )
END IF
END IF
END IF
RETURN
*
* End of SLAS2
*
END
| bsd-3-clause |
mverleg/1957 | lib/lapack/zgesvxx.f | 28 | 29944 | *> \brief <b> ZGESVXX computes the solution to system of linear equations A * X = B for GE matrices</b>
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download ZGESVXX + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgesvxx.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgesvxx.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgesvxx.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE ZGESVXX( FACT, TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV,
* EQUED, R, C, B, LDB, X, LDX, RCOND, RPVGRW,
* BERR, N_ERR_BNDS, ERR_BNDS_NORM,
* ERR_BNDS_COMP, NPARAMS, PARAMS, WORK, RWORK,
* INFO )
*
* .. Scalar Arguments ..
* CHARACTER EQUED, FACT, TRANS
* INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS, NPARAMS,
* $ N_ERR_BNDS
* DOUBLE PRECISION RCOND, RPVGRW
* ..
* .. Array Arguments ..
* INTEGER IPIV( * )
* COMPLEX*16 A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
* $ X( LDX , * ),WORK( * )
* DOUBLE PRECISION R( * ), C( * ), PARAMS( * ), BERR( * ),
* $ ERR_BNDS_NORM( NRHS, * ),
* $ ERR_BNDS_COMP( NRHS, * ), RWORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> ZGESVXX uses the LU factorization to compute the solution to a
*> complex*16 system of linear equations A * X = B, where A is an
*> N-by-N matrix and X and B are N-by-NRHS matrices.
*>
*> If requested, both normwise and maximum componentwise error bounds
*> are returned. ZGESVXX will return a solution with a tiny
*> guaranteed error (O(eps) where eps is the working machine
*> precision) unless the matrix is very ill-conditioned, in which
*> case a warning is returned. Relevant condition numbers also are
*> calculated and returned.
*>
*> ZGESVXX accepts user-provided factorizations and equilibration
*> factors; see the definitions of the FACT and EQUED options.
*> Solving with refinement and using a factorization from a previous
*> ZGESVXX call will also produce a solution with either O(eps)
*> errors or warnings, but we cannot make that claim for general
*> user-provided factorizations and equilibration factors if they
*> differ from what ZGESVXX would itself produce.
*> \endverbatim
*
*> \par Description:
* =================
*>
*> \verbatim
*>
*> The following steps are performed:
*>
*> 1. If FACT = 'E', double precision scaling factors are computed to equilibrate
*> the system:
*>
*> TRANS = 'N': diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B
*> TRANS = 'T': (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B
*> TRANS = 'C': (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B
*>
*> Whether or not the system will be equilibrated depends on the
*> scaling of the matrix A, but if equilibration is used, A is
*> overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if TRANS='N')
*> or diag(C)*B (if TRANS = 'T' or 'C').
*>
*> 2. If FACT = 'N' or 'E', the LU decomposition is used to factor
*> the matrix A (after equilibration if FACT = 'E') as
*>
*> A = P * L * U,
*>
*> where P is a permutation matrix, L is a unit lower triangular
*> matrix, and U is upper triangular.
*>
*> 3. If some U(i,i)=0, so that U is exactly singular, then the
*> routine returns with INFO = i. Otherwise, the factored form of A
*> is used to estimate the condition number of the matrix A (see
*> argument RCOND). If the reciprocal of the condition number is less
*> than machine precision, the routine still goes on to solve for X
*> and compute error bounds as described below.
*>
*> 4. The system of equations is solved for X using the factored form
*> of A.
*>
*> 5. By default (unless PARAMS(LA_LINRX_ITREF_I) is set to zero),
*> the routine will use iterative refinement to try to get a small
*> error and error bounds. Refinement calculates the residual to at
*> least twice the working precision.
*>
*> 6. If equilibration was used, the matrix X is premultiplied by
*> diag(C) (if TRANS = 'N') or diag(R) (if TRANS = 'T' or 'C') so
*> that it solves the original system before equilibration.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \verbatim
*> Some optional parameters are bundled in the PARAMS array. These
*> settings determine how refinement is performed, but often the
*> defaults are acceptable. If the defaults are acceptable, users
*> can pass NPARAMS = 0 which prevents the source code from accessing
*> the PARAMS argument.
*> \endverbatim
*>
*> \param[in] FACT
*> \verbatim
*> FACT is CHARACTER*1
*> Specifies whether or not the factored form of the matrix A is
*> supplied on entry, and if not, whether the matrix A should be
*> equilibrated before it is factored.
*> = 'F': On entry, AF and IPIV contain the factored form of A.
*> If EQUED is not 'N', the matrix A has been
*> equilibrated with scaling factors given by R and C.
*> A, AF, and IPIV are not modified.
*> = 'N': The matrix A will be copied to AF and factored.
*> = 'E': The matrix A will be equilibrated if necessary, then
*> copied to AF and factored.
*> \endverbatim
*>
*> \param[in] TRANS
*> \verbatim
*> TRANS is CHARACTER*1
*> Specifies the form of the system of equations:
*> = 'N': A * X = B (No transpose)
*> = 'T': A**T * X = B (Transpose)
*> = 'C': A**H * X = B (Conjugate Transpose)
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of linear equations, i.e., the order of the
*> matrix A. N >= 0.
*> \endverbatim
*>
*> \param[in] NRHS
*> \verbatim
*> NRHS is INTEGER
*> The number of right hand sides, i.e., the number of columns
*> of the matrices B and X. NRHS >= 0.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is COMPLEX*16 array, dimension (LDA,N)
*> On entry, the N-by-N matrix A. If FACT = 'F' and EQUED is
*> not 'N', then A must have been equilibrated by the scaling
*> factors in R and/or C. A is not modified if FACT = 'F' or
*> 'N', or if FACT = 'E' and EQUED = 'N' on exit.
*>
*> On exit, if EQUED .ne. 'N', A is scaled as follows:
*> EQUED = 'R': A := diag(R) * A
*> EQUED = 'C': A := A * diag(C)
*> EQUED = 'B': A := diag(R) * A * diag(C).
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[in,out] AF
*> \verbatim
*> AF is COMPLEX*16 array, dimension (LDAF,N)
*> If FACT = 'F', then AF is an input argument and on entry
*> contains the factors L and U from the factorization
*> A = P*L*U as computed by ZGETRF. If EQUED .ne. 'N', then
*> AF is the factored form of the equilibrated matrix A.
*>
*> If FACT = 'N', then AF is an output argument and on exit
*> returns the factors L and U from the factorization A = P*L*U
*> of the original matrix A.
*>
*> If FACT = 'E', then AF is an output argument and on exit
*> returns the factors L and U from the factorization A = P*L*U
*> of the equilibrated matrix A (see the description of A for
*> the form of the equilibrated matrix).
*> \endverbatim
*>
*> \param[in] LDAF
*> \verbatim
*> LDAF is INTEGER
*> The leading dimension of the array AF. LDAF >= max(1,N).
*> \endverbatim
*>
*> \param[in,out] IPIV
*> \verbatim
*> IPIV is INTEGER array, dimension (N)
*> If FACT = 'F', then IPIV is an input argument and on entry
*> contains the pivot indices from the factorization A = P*L*U
*> as computed by ZGETRF; row i of the matrix was interchanged
*> with row IPIV(i).
*>
*> If FACT = 'N', then IPIV is an output argument and on exit
*> contains the pivot indices from the factorization A = P*L*U
*> of the original matrix A.
*>
*> If FACT = 'E', then IPIV is an output argument and on exit
*> contains the pivot indices from the factorization A = P*L*U
*> of the equilibrated matrix A.
*> \endverbatim
*>
*> \param[in,out] EQUED
*> \verbatim
*> EQUED is CHARACTER*1
*> Specifies the form of equilibration that was done.
*> = 'N': No equilibration (always true if FACT = 'N').
*> = 'R': Row equilibration, i.e., A has been premultiplied by
*> diag(R).
*> = 'C': Column equilibration, i.e., A has been postmultiplied
*> by diag(C).
*> = 'B': Both row and column equilibration, i.e., A has been
*> replaced by diag(R) * A * diag(C).
*> EQUED is an input argument if FACT = 'F'; otherwise, it is an
*> output argument.
*> \endverbatim
*>
*> \param[in,out] R
*> \verbatim
*> R is DOUBLE PRECISION array, dimension (N)
*> The row scale factors for A. If EQUED = 'R' or 'B', A is
*> multiplied on the left by diag(R); if EQUED = 'N' or 'C', R
*> is not accessed. R is an input argument if FACT = 'F';
*> otherwise, R is an output argument. If FACT = 'F' and
*> EQUED = 'R' or 'B', each element of R must be positive.
*> If R is output, each element of R is a power of the radix.
*> If R is input, each element of R should be a power of the radix
*> to ensure a reliable solution and error estimates. Scaling by
*> powers of the radix does not cause rounding errors unless the
*> result underflows or overflows. Rounding errors during scaling
*> lead to refining with a matrix that is not equivalent to the
*> input matrix, producing error estimates that may not be
*> reliable.
*> \endverbatim
*>
*> \param[in,out] C
*> \verbatim
*> C is DOUBLE PRECISION array, dimension (N)
*> The column scale factors for A. If EQUED = 'C' or 'B', A is
*> multiplied on the right by diag(C); if EQUED = 'N' or 'R', C
*> is not accessed. C is an input argument if FACT = 'F';
*> otherwise, C is an output argument. If FACT = 'F' and
*> EQUED = 'C' or 'B', each element of C must be positive.
*> If C is output, each element of C is a power of the radix.
*> If C is input, each element of C should be a power of the radix
*> to ensure a reliable solution and error estimates. Scaling by
*> powers of the radix does not cause rounding errors unless the
*> result underflows or overflows. Rounding errors during scaling
*> lead to refining with a matrix that is not equivalent to the
*> input matrix, producing error estimates that may not be
*> reliable.
*> \endverbatim
*>
*> \param[in,out] B
*> \verbatim
*> B is COMPLEX*16 array, dimension (LDB,NRHS)
*> On entry, the N-by-NRHS right hand side matrix B.
*> On exit,
*> if EQUED = 'N', B is not modified;
*> if TRANS = 'N' and EQUED = 'R' or 'B', B is overwritten by
*> diag(R)*B;
*> if TRANS = 'T' or 'C' and EQUED = 'C' or 'B', B is
*> overwritten by diag(C)*B.
*> \endverbatim
*>
*> \param[in] LDB
*> \verbatim
*> LDB is INTEGER
*> The leading dimension of the array B. LDB >= max(1,N).
*> \endverbatim
*>
*> \param[out] X
*> \verbatim
*> X is COMPLEX*16 array, dimension (LDX,NRHS)
*> If INFO = 0, the N-by-NRHS solution matrix X to the original
*> system of equations. Note that A and B are modified on exit
*> if EQUED .ne. 'N', and the solution to the equilibrated system is
*> inv(diag(C))*X if TRANS = 'N' and EQUED = 'C' or 'B', or
*> inv(diag(R))*X if TRANS = 'T' or 'C' and EQUED = 'R' or 'B'.
*> \endverbatim
*>
*> \param[in] LDX
*> \verbatim
*> LDX is INTEGER
*> The leading dimension of the array X. LDX >= max(1,N).
*> \endverbatim
*>
*> \param[out] RCOND
*> \verbatim
*> RCOND is DOUBLE PRECISION
*> Reciprocal scaled condition number. This is an estimate of the
*> reciprocal Skeel condition number of the matrix A after
*> equilibration (if done). If this is less than the machine
*> precision (in particular, if it is zero), the matrix is singular
*> to working precision. Note that the error may still be small even
*> if this number is very small and the matrix appears ill-
*> conditioned.
*> \endverbatim
*>
*> \param[out] RPVGRW
*> \verbatim
*> RPVGRW is DOUBLE PRECISION
*> Reciprocal pivot growth. On exit, this contains the reciprocal
*> pivot growth factor norm(A)/norm(U). The "max absolute element"
*> norm is used. If this is much less than 1, then the stability of
*> the LU factorization of the (equilibrated) matrix A could be poor.
*> This also means that the solution X, estimated condition numbers,
*> and error bounds could be unreliable. If factorization fails with
*> 0<INFO<=N, then this contains the reciprocal pivot growth factor
*> for the leading INFO columns of A. In ZGESVX, this quantity is
*> returned in WORK(1).
*> \endverbatim
*>
*> \param[out] BERR
*> \verbatim
*> BERR is DOUBLE PRECISION array, dimension (NRHS)
*> Componentwise relative backward error. This is the
*> componentwise relative backward error of each solution vector X(j)
*> (i.e., the smallest relative change in any element of A or B that
*> makes X(j) an exact solution).
*> \endverbatim
*>
*> \param[in] N_ERR_BNDS
*> \verbatim
*> N_ERR_BNDS is INTEGER
*> Number of error bounds to return for each right hand side
*> and each type (normwise or componentwise). See ERR_BNDS_NORM and
*> ERR_BNDS_COMP below.
*> \endverbatim
*>
*> \param[out] ERR_BNDS_NORM
*> \verbatim
*> ERR_BNDS_NORM is DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS)
*> For each right-hand side, this array contains information about
*> various error bounds and condition numbers corresponding to the
*> normwise relative error, which is defined as follows:
*>
*> Normwise relative error in the ith solution vector:
*> max_j (abs(XTRUE(j,i) - X(j,i)))
*> ------------------------------
*> max_j abs(X(j,i))
*>
*> The array is indexed by the type of error information as described
*> below. There currently are up to three pieces of information
*> returned.
*>
*> The first index in ERR_BNDS_NORM(i,:) corresponds to the ith
*> right-hand side.
*>
*> The second index in ERR_BNDS_NORM(:,err) contains the following
*> three fields:
*> err = 1 "Trust/don't trust" boolean. Trust the answer if the
*> reciprocal condition number is less than the threshold
*> sqrt(n) * dlamch('Epsilon').
*>
*> err = 2 "Guaranteed" error bound: The estimated forward error,
*> almost certainly within a factor of 10 of the true error
*> so long as the next entry is greater than the threshold
*> sqrt(n) * dlamch('Epsilon'). This error bound should only
*> be trusted if the previous boolean is true.
*>
*> err = 3 Reciprocal condition number: Estimated normwise
*> reciprocal condition number. Compared with the threshold
*> sqrt(n) * dlamch('Epsilon') to determine if the error
*> estimate is "guaranteed". These reciprocal condition
*> numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
*> appropriately scaled matrix Z.
*> Let Z = S*A, where S scales each row by a power of the
*> radix so all absolute row sums of Z are approximately 1.
*>
*> See Lapack Working Note 165 for further details and extra
*> cautions.
*> \endverbatim
*>
*> \param[out] ERR_BNDS_COMP
*> \verbatim
*> ERR_BNDS_COMP is DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS)
*> For each right-hand side, this array contains information about
*> various error bounds and condition numbers corresponding to the
*> componentwise relative error, which is defined as follows:
*>
*> Componentwise relative error in the ith solution vector:
*> abs(XTRUE(j,i) - X(j,i))
*> max_j ----------------------
*> abs(X(j,i))
*>
*> The array is indexed by the right-hand side i (on which the
*> componentwise relative error depends), and the type of error
*> information as described below. There currently are up to three
*> pieces of information returned for each right-hand side. If
*> componentwise accuracy is not requested (PARAMS(3) = 0.0), then
*> ERR_BNDS_COMP is not accessed. If N_ERR_BNDS .LT. 3, then at most
*> the first (:,N_ERR_BNDS) entries are returned.
*>
*> The first index in ERR_BNDS_COMP(i,:) corresponds to the ith
*> right-hand side.
*>
*> The second index in ERR_BNDS_COMP(:,err) contains the following
*> three fields:
*> err = 1 "Trust/don't trust" boolean. Trust the answer if the
*> reciprocal condition number is less than the threshold
*> sqrt(n) * dlamch('Epsilon').
*>
*> err = 2 "Guaranteed" error bound: The estimated forward error,
*> almost certainly within a factor of 10 of the true error
*> so long as the next entry is greater than the threshold
*> sqrt(n) * dlamch('Epsilon'). This error bound should only
*> be trusted if the previous boolean is true.
*>
*> err = 3 Reciprocal condition number: Estimated componentwise
*> reciprocal condition number. Compared with the threshold
*> sqrt(n) * dlamch('Epsilon') to determine if the error
*> estimate is "guaranteed". These reciprocal condition
*> numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
*> appropriately scaled matrix Z.
*> Let Z = S*(A*diag(x)), where x is the solution for the
*> current right-hand side and S scales each row of
*> A*diag(x) by a power of the radix so all absolute row
*> sums of Z are approximately 1.
*>
*> See Lapack Working Note 165 for further details and extra
*> cautions.
*> \endverbatim
*>
*> \param[in] NPARAMS
*> \verbatim
*> NPARAMS is INTEGER
*> Specifies the number of parameters set in PARAMS. If .LE. 0, the
*> PARAMS array is never referenced and default values are used.
*> \endverbatim
*>
*> \param[in,out] PARAMS
*> \verbatim
*> PARAMS is DOUBLE PRECISION array, dimension NPARAMS
*> Specifies algorithm parameters. If an entry is .LT. 0.0, then
*> that entry will be filled with default value used for that
*> parameter. Only positions up to NPARAMS are accessed; defaults
*> are used for higher-numbered parameters.
*>
*> PARAMS(LA_LINRX_ITREF_I = 1) : Whether to perform iterative
*> refinement or not.
*> Default: 1.0D+0
*> = 0.0 : No refinement is performed, and no error bounds are
*> computed.
*> = 1.0 : Use the extra-precise refinement algorithm.
*> (other values are reserved for future use)
*>
*> PARAMS(LA_LINRX_ITHRESH_I = 2) : Maximum number of residual
*> computations allowed for refinement.
*> Default: 10
*> Aggressive: Set to 100 to permit convergence using approximate
*> factorizations or factorizations other than LU. If
*> the factorization uses a technique other than
*> Gaussian elimination, the guarantees in
*> err_bnds_norm and err_bnds_comp may no longer be
*> trustworthy.
*>
*> PARAMS(LA_LINRX_CWISE_I = 3) : Flag determining if the code
*> will attempt to find a solution with small componentwise
*> relative error in the double-precision algorithm. Positive
*> is true, 0.0 is false.
*> Default: 1.0 (attempt componentwise convergence)
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is COMPLEX*16 array, dimension (2*N)
*> \endverbatim
*>
*> \param[out] RWORK
*> \verbatim
*> RWORK is DOUBLE PRECISION array, dimension (2*N)
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: Successful exit. The solution to every right-hand side is
*> guaranteed.
*> < 0: If INFO = -i, the i-th argument had an illegal value
*> > 0 and <= N: U(INFO,INFO) is exactly zero. The factorization
*> has been completed, but the factor U is exactly singular, so
*> the solution and error bounds could not be computed. RCOND = 0
*> is returned.
*> = N+J: The solution corresponding to the Jth right-hand side is
*> not guaranteed. The solutions corresponding to other right-
*> hand sides K with K > J may not be guaranteed as well, but
*> only the first such right-hand side is reported. If a small
*> componentwise error is not requested (PARAMS(3) = 0.0) then
*> the Jth right-hand side is the first with a normwise error
*> bound that is not guaranteed (the smallest J such
*> that ERR_BNDS_NORM(J,1) = 0.0). By default (PARAMS(3) = 1.0)
*> the Jth right-hand side is the first with either a normwise or
*> componentwise error bound that is not guaranteed (the smallest
*> J such that either ERR_BNDS_NORM(J,1) = 0.0 or
*> ERR_BNDS_COMP(J,1) = 0.0). See the definition of
*> ERR_BNDS_NORM(:,1) and ERR_BNDS_COMP(:,1). To get information
*> about all of the right-hand sides check ERR_BNDS_NORM or
*> ERR_BNDS_COMP.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date April 2012
*
*> \ingroup complex16GEsolve
*
* =====================================================================
SUBROUTINE ZGESVXX( FACT, TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV,
$ EQUED, R, C, B, LDB, X, LDX, RCOND, RPVGRW,
$ BERR, N_ERR_BNDS, ERR_BNDS_NORM,
$ ERR_BNDS_COMP, NPARAMS, PARAMS, WORK, RWORK,
$ INFO )
*
* -- LAPACK driver routine (version 3.4.1) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* April 2012
*
* .. Scalar Arguments ..
CHARACTER EQUED, FACT, TRANS
INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS, NPARAMS,
$ N_ERR_BNDS
DOUBLE PRECISION RCOND, RPVGRW
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
COMPLEX*16 A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
$ X( LDX , * ),WORK( * )
DOUBLE PRECISION R( * ), C( * ), PARAMS( * ), BERR( * ),
$ ERR_BNDS_NORM( NRHS, * ),
$ ERR_BNDS_COMP( NRHS, * ), RWORK( * )
* ..
*
* ==================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
INTEGER FINAL_NRM_ERR_I, FINAL_CMP_ERR_I, BERR_I
INTEGER RCOND_I, NRM_RCOND_I, NRM_ERR_I, CMP_RCOND_I
INTEGER CMP_ERR_I, PIV_GROWTH_I
PARAMETER ( FINAL_NRM_ERR_I = 1, FINAL_CMP_ERR_I = 2,
$ BERR_I = 3 )
PARAMETER ( RCOND_I = 4, NRM_RCOND_I = 5, NRM_ERR_I = 6 )
PARAMETER ( CMP_RCOND_I = 7, CMP_ERR_I = 8,
$ PIV_GROWTH_I = 9 )
* ..
* .. Local Scalars ..
LOGICAL COLEQU, EQUIL, NOFACT, NOTRAN, ROWEQU
INTEGER INFEQU, J
DOUBLE PRECISION AMAX, BIGNUM, COLCND, RCMAX, RCMIN,
$ ROWCND, SMLNUM
* ..
* .. External Functions ..
EXTERNAL LSAME, DLAMCH, ZLA_GERPVGRW
LOGICAL LSAME
DOUBLE PRECISION DLAMCH, ZLA_GERPVGRW
* ..
* .. External Subroutines ..
EXTERNAL ZGEEQUB, ZGETRF, ZGETRS, ZLACPY, ZLAQGE,
$ XERBLA, ZLASCL2, ZGERFSX
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* ..
* .. Executable Statements ..
*
INFO = 0
NOFACT = LSAME( FACT, 'N' )
EQUIL = LSAME( FACT, 'E' )
NOTRAN = LSAME( TRANS, 'N' )
SMLNUM = DLAMCH( 'Safe minimum' )
BIGNUM = ONE / SMLNUM
IF( NOFACT .OR. EQUIL ) THEN
EQUED = 'N'
ROWEQU = .FALSE.
COLEQU = .FALSE.
ELSE
ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' )
COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' )
END IF
*
* Default is failure. If an input parameter is wrong or
* factorization fails, make everything look horrible. Only the
* pivot growth is set here, the rest is initialized in ZGERFSX.
*
RPVGRW = ZERO
*
* Test the input parameters. PARAMS is not tested until ZGERFSX.
*
IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT.
$ LSAME( FACT, 'F' ) ) THEN
INFO = -1
ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
$ LSAME( TRANS, 'C' ) ) THEN
INFO = -2
ELSE IF( N.LT.0 ) THEN
INFO = -3
ELSE IF( NRHS.LT.0 ) THEN
INFO = -4
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -6
ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
INFO = -8
ELSE IF( LSAME( FACT, 'F' ) .AND. .NOT.
$ ( ROWEQU .OR. COLEQU .OR. LSAME( EQUED, 'N' ) ) ) THEN
INFO = -10
ELSE
IF( ROWEQU ) THEN
RCMIN = BIGNUM
RCMAX = ZERO
DO 10 J = 1, N
RCMIN = MIN( RCMIN, R( J ) )
RCMAX = MAX( RCMAX, R( J ) )
10 CONTINUE
IF( RCMIN.LE.ZERO ) THEN
INFO = -11
ELSE IF( N.GT.0 ) THEN
ROWCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM )
ELSE
ROWCND = ONE
END IF
END IF
IF( COLEQU .AND. INFO.EQ.0 ) THEN
RCMIN = BIGNUM
RCMAX = ZERO
DO 20 J = 1, N
RCMIN = MIN( RCMIN, C( J ) )
RCMAX = MAX( RCMAX, C( J ) )
20 CONTINUE
IF( RCMIN.LE.ZERO ) THEN
INFO = -12
ELSE IF( N.GT.0 ) THEN
COLCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM )
ELSE
COLCND = ONE
END IF
END IF
IF( INFO.EQ.0 ) THEN
IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -14
ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
INFO = -16
END IF
END IF
END IF
*
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZGESVXX', -INFO )
RETURN
END IF
*
IF( EQUIL ) THEN
*
* Compute row and column scalings to equilibrate the matrix A.
*
CALL ZGEEQUB( N, N, A, LDA, R, C, ROWCND, COLCND, AMAX,
$ INFEQU )
IF( INFEQU.EQ.0 ) THEN
*
* Equilibrate the matrix.
*
CALL ZLAQGE( N, N, A, LDA, R, C, ROWCND, COLCND, AMAX,
$ EQUED )
ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' )
COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' )
END IF
*
* If the scaling factors are not applied, set them to 1.0.
*
IF ( .NOT.ROWEQU ) THEN
DO J = 1, N
R( J ) = 1.0D+0
END DO
END IF
IF ( .NOT.COLEQU ) THEN
DO J = 1, N
C( J ) = 1.0D+0
END DO
END IF
END IF
*
* Scale the right-hand side.
*
IF( NOTRAN ) THEN
IF( ROWEQU ) CALL ZLASCL2( N, NRHS, R, B, LDB )
ELSE
IF( COLEQU ) CALL ZLASCL2( N, NRHS, C, B, LDB )
END IF
*
IF( NOFACT .OR. EQUIL ) THEN
*
* Compute the LU factorization of A.
*
CALL ZLACPY( 'Full', N, N, A, LDA, AF, LDAF )
CALL ZGETRF( N, N, AF, LDAF, IPIV, INFO )
*
* Return if INFO is non-zero.
*
IF( INFO.GT.0 ) THEN
*
* Pivot in column INFO is exactly 0
* Compute the reciprocal pivot growth factor of the
* leading rank-deficient INFO columns of A.
*
RPVGRW = ZLA_GERPVGRW( N, INFO, A, LDA, AF, LDAF )
RETURN
END IF
END IF
*
* Compute the reciprocal pivot growth factor RPVGRW.
*
RPVGRW = ZLA_GERPVGRW( N, N, A, LDA, AF, LDAF )
*
* Compute the solution matrix X.
*
CALL ZLACPY( 'Full', N, NRHS, B, LDB, X, LDX )
CALL ZGETRS( TRANS, N, NRHS, AF, LDAF, IPIV, X, LDX, INFO )
*
* Use iterative refinement to improve the computed solution and
* compute error bounds and backward error estimates for it.
*
CALL ZGERFSX( TRANS, EQUED, N, NRHS, A, LDA, AF, LDAF,
$ IPIV, R, C, B, LDB, X, LDX, RCOND, BERR,
$ N_ERR_BNDS, ERR_BNDS_NORM, ERR_BNDS_COMP, NPARAMS, PARAMS,
$ WORK, RWORK, INFO )
*
* Scale solutions.
*
IF ( COLEQU .AND. NOTRAN ) THEN
CALL ZLASCL2 ( N, NRHS, C, X, LDX )
ELSE IF ( ROWEQU .AND. .NOT.NOTRAN ) THEN
CALL ZLASCL2 ( N, NRHS, R, X, LDX )
END IF
*
RETURN
*
* End of ZGESVXX
*
END
| bsd-3-clause |
davidgiven/gcc-vc4 | gcc/testsuite/gfortran.dg/associated_target_2.f90 | 193 | 1069 | ! { dg-do run }
!
! PR fortran/35721
!
! ASSOCIATED(ptr, trgt) should return true if
! the same storage units (in the same order)
! gfortran was returning false if the strips
! were different but only one (the same!) element
! was present.
!
! Contributed by Dick Hendrickson
!
program try_mg0028
implicit none
real tda2r(2,3)
call mg0028(tda2r, 1, 2, 3)
CONTAINS
SUBROUTINE MG0028(TDA2R,nf1,nf2,nf3)
integer :: nf1,nf2,nf3
real, target :: TDA2R(NF2,NF3)
real, pointer :: TLA2L(:,:),TLA2L1(:,:)
logical LL(4)
TLA2L => TDA2R(NF2:NF1:-NF2,NF3:NF1:-NF2)
TLA2L1 => TLA2L
LL(1) = ASSOCIATED(TLA2L)
LL(2) = ASSOCIATED(TLA2L,TLA2L1)
LL(3) = ASSOCIATED(TLA2L,TDA2R)
LL(4) = ASSOCIATED(TLA2L1,TDA2R(2:2,3:1:-2)) !should be true
if (any(LL .neqv. (/ .true., .true., .false., .true./))) then
print *, LL
print *, shape(TLA2L1)
print *, shape(TDA2R(2:2,3:1:-2))
stop
endif
END SUBROUTINE
END PROGRAM
| gpl-2.0 |
syftalent/dist-sys-exercises-1 | lec-6/mpi/mpich-3.1.4/src/binding/fortran/use_mpi_f08/wrappers_f/win_set_attr_f08ts.F90 | 1 | 1140 | ! -*- Mode: Fortran; -*-
!
! (C) 2014 by Argonne National Laboratory.
! See COPYRIGHT in top-level directory.
!
subroutine MPI_Win_set_attr_f08(win, win_keyval, attribute_val, ierror)
use, intrinsic :: iso_c_binding, only : c_int
use :: mpi_f08, only : MPI_Win
use :: mpi_f08, only : MPI_ADDRESS_KIND
use :: mpi_c_interface, only : c_Win
use :: mpi_c_interface, only : MPIR_ATTR_AINT
use :: mpi_c_interface, only : MPIR_Win_set_attr_c
implicit none
type(MPI_Win), intent(in) :: win
integer, intent(in) :: win_keyval
integer(MPI_ADDRESS_KIND), intent(in) :: attribute_val
integer, optional, intent(out) :: ierror
integer(c_Win) :: win_c
integer(c_int) :: win_keyval_c
integer(c_int) :: ierror_c
if (c_int == kind(0)) then
ierror_c = MPIR_Win_set_attr_c(win%MPI_VAL, win_keyval, attribute_val, MPIR_ATTR_AINT)
else
win_c = win%MPI_VAL
win_keyval_c = win_keyval
ierror_c = MPIR_Win_set_attr_c(win_c, win_keyval_c, attribute_val, MPIR_ATTR_AINT)
end if
if (present(ierror)) ierror = ierror_c
end subroutine MPI_Win_set_attr_f08
| mit |
syftalent/dist-sys-exercises-1 | lec-6/mpi/mpich-3.1.4/src/binding/fortran/use_mpi_f08/wrappers_f/comm_connect_f08ts.F90 | 1 | 1446 | ! -*- Mode: Fortran; -*-
!
! (C) 2014 by Argonne National Laboratory.
! See COPYRIGHT in top-level directory.
!
subroutine MPI_Comm_connect_f08(port_name, info, root, comm, newcomm, ierror)
use, intrinsic :: iso_c_binding, only : c_int, c_char
use :: mpi_f08, only : MPI_Info, MPI_Comm
use :: mpi_c_interface, only : c_Info, c_Comm
use :: mpi_c_interface, only : MPIR_Comm_connect_c
use :: mpi_c_interface, only : MPIR_Fortran_string_f2c
implicit none
character(len=*), intent(in) :: port_name
type(MPI_Info), intent(in) :: info
integer, intent(in) :: root
type(MPI_Comm), intent(in) :: comm
type(MPI_Comm), intent(out) :: newcomm
integer, optional, intent(out) :: ierror
character(kind=c_char) :: port_name_c(len_trim(port_name)+1)
integer(c_Info) :: info_c
integer(c_int) :: root_c
integer(c_Comm) :: comm_c
integer(c_Comm) :: newcomm_c
integer(c_int) :: ierror_c
call MPIR_Fortran_string_f2c(port_name, port_name_c)
if (c_int == kind(0)) then
ierror_c = MPIR_Comm_connect_c(port_name_c, info%MPI_VAL, root, comm%MPI_VAL, newcomm%MPI_VAL)
else
info_c = info%MPI_VAL
root_c = root
comm_c = comm%MPI_VAL
ierror_c = MPIR_Comm_connect_c(port_name_c, info_c, root_c, comm_c, newcomm_c)
newcomm%MPI_VAL = newcomm_c
end if
if (present(ierror)) ierror = ierror_c
end subroutine MPI_Comm_connect_f08
| mit |
mverleg/1957 | lib/lapack/dsygvd.f | 5 | 12188 | *> \brief \b DSYGVD
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DSYGVD + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsygvd.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsygvd.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsygvd.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DSYGVD( ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK,
* LWORK, IWORK, LIWORK, INFO )
*
* .. Scalar Arguments ..
* CHARACTER JOBZ, UPLO
* INTEGER INFO, ITYPE, LDA, LDB, LIWORK, LWORK, N
* ..
* .. Array Arguments ..
* INTEGER IWORK( * )
* DOUBLE PRECISION A( LDA, * ), B( LDB, * ), W( * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DSYGVD computes all the eigenvalues, and optionally, the eigenvectors
*> of a real generalized symmetric-definite eigenproblem, of the form
*> A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A and
*> B are assumed to be symmetric and B is also positive definite.
*> If eigenvectors are desired, it uses a divide and conquer algorithm.
*>
*> The divide and conquer algorithm makes very mild assumptions about
*> floating point arithmetic. It will work on machines with a guard
*> digit in add/subtract, or on those binary machines without guard
*> digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
*> Cray-2. It could conceivably fail on hexadecimal or decimal machines
*> without guard digits, but we know of none.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] ITYPE
*> \verbatim
*> ITYPE is INTEGER
*> Specifies the problem type to be solved:
*> = 1: A*x = (lambda)*B*x
*> = 2: A*B*x = (lambda)*x
*> = 3: B*A*x = (lambda)*x
*> \endverbatim
*>
*> \param[in] JOBZ
*> \verbatim
*> JOBZ is CHARACTER*1
*> = 'N': Compute eigenvalues only;
*> = 'V': Compute eigenvalues and eigenvectors.
*> \endverbatim
*>
*> \param[in] UPLO
*> \verbatim
*> UPLO is CHARACTER*1
*> = 'U': Upper triangles of A and B are stored;
*> = 'L': Lower triangles of A and B are stored.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrices A and B. N >= 0.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is DOUBLE PRECISION array, dimension (LDA, N)
*> On entry, the symmetric matrix A. If UPLO = 'U', the
*> leading N-by-N upper triangular part of A contains the
*> upper triangular part of the matrix A. If UPLO = 'L',
*> the leading N-by-N lower triangular part of A contains
*> the lower triangular part of the matrix A.
*>
*> On exit, if JOBZ = 'V', then if INFO = 0, A contains the
*> matrix Z of eigenvectors. The eigenvectors are normalized
*> as follows:
*> if ITYPE = 1 or 2, Z**T*B*Z = I;
*> if ITYPE = 3, Z**T*inv(B)*Z = I.
*> If JOBZ = 'N', then on exit the upper triangle (if UPLO='U')
*> or the lower triangle (if UPLO='L') of A, including the
*> diagonal, is destroyed.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[in,out] B
*> \verbatim
*> B is DOUBLE PRECISION array, dimension (LDB, N)
*> On entry, the symmetric matrix B. If UPLO = 'U', the
*> leading N-by-N upper triangular part of B contains the
*> upper triangular part of the matrix B. If UPLO = 'L',
*> the leading N-by-N lower triangular part of B contains
*> the lower triangular part of the matrix B.
*>
*> On exit, if INFO <= N, the part of B containing the matrix is
*> overwritten by the triangular factor U or L from the Cholesky
*> factorization B = U**T*U or B = L*L**T.
*> \endverbatim
*>
*> \param[in] LDB
*> \verbatim
*> LDB is INTEGER
*> The leading dimension of the array B. LDB >= max(1,N).
*> \endverbatim
*>
*> \param[out] W
*> \verbatim
*> W is DOUBLE PRECISION array, dimension (N)
*> If INFO = 0, the eigenvalues in ascending order.
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
*> \endverbatim
*>
*> \param[in] LWORK
*> \verbatim
*> LWORK is INTEGER
*> The dimension of the array WORK.
*> If N <= 1, LWORK >= 1.
*> If JOBZ = 'N' and N > 1, LWORK >= 2*N+1.
*> If JOBZ = 'V' and N > 1, LWORK >= 1 + 6*N + 2*N**2.
*>
*> If LWORK = -1, then a workspace query is assumed; the routine
*> only calculates the optimal sizes of the WORK and IWORK
*> arrays, returns these values as the first entries of the WORK
*> and IWORK arrays, and no error message related to LWORK or
*> LIWORK is issued by XERBLA.
*> \endverbatim
*>
*> \param[out] IWORK
*> \verbatim
*> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
*> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
*> \endverbatim
*>
*> \param[in] LIWORK
*> \verbatim
*> LIWORK is INTEGER
*> The dimension of the array IWORK.
*> If N <= 1, LIWORK >= 1.
*> If JOBZ = 'N' and N > 1, LIWORK >= 1.
*> If JOBZ = 'V' and N > 1, LIWORK >= 3 + 5*N.
*>
*> If LIWORK = -1, then a workspace query is assumed; the
*> routine only calculates the optimal sizes of the WORK and
*> IWORK arrays, returns these values as the first entries of
*> the WORK and IWORK arrays, and no error message related to
*> LWORK or LIWORK is issued by XERBLA.
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value
*> > 0: DPOTRF or DSYEVD returned an error code:
*> <= N: if INFO = i and JOBZ = 'N', then the algorithm
*> failed to converge; i off-diagonal elements of an
*> intermediate tridiagonal form did not converge to
*> zero;
*> if INFO = i and JOBZ = 'V', then the algorithm
*> failed to compute an eigenvalue while working on
*> the submatrix lying in rows and columns INFO/(N+1)
*> through mod(INFO,N+1);
*> > N: if INFO = N + i, for 1 <= i <= N, then the leading
*> minor of order i of B is not positive definite.
*> The factorization of B could not be completed and
*> no eigenvalues or eigenvectors were computed.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2015
*
*> \ingroup doubleSYeigen
*
*> \par Further Details:
* =====================
*>
*> \verbatim
*>
*> Modified so that no backsubstitution is performed if DSYEVD fails to
*> converge (NEIG in old code could be greater than N causing out of
*> bounds reference to A - reported by Ralf Meyer). Also corrected the
*> description of INFO and the test on ITYPE. Sven, 16 Feb 05.
*> \endverbatim
*
*> \par Contributors:
* ==================
*>
*> Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA
*>
* =====================================================================
SUBROUTINE DSYGVD( ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK,
$ LWORK, IWORK, LIWORK, INFO )
*
* -- LAPACK driver routine (version 3.6.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2015
*
* .. Scalar Arguments ..
CHARACTER JOBZ, UPLO
INTEGER INFO, ITYPE, LDA, LDB, LIWORK, LWORK, N
* ..
* .. Array Arguments ..
INTEGER IWORK( * )
DOUBLE PRECISION A( LDA, * ), B( LDB, * ), W( * ), WORK( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ONE
PARAMETER ( ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
LOGICAL LQUERY, UPPER, WANTZ
CHARACTER TRANS
INTEGER LIOPT, LIWMIN, LOPT, LWMIN
* ..
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL DPOTRF, DSYEVD, DSYGST, DTRMM, DTRSM, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC DBLE, MAX
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
WANTZ = LSAME( JOBZ, 'V' )
UPPER = LSAME( UPLO, 'U' )
LQUERY = ( LWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
*
INFO = 0
IF( N.LE.1 ) THEN
LIWMIN = 1
LWMIN = 1
ELSE IF( WANTZ ) THEN
LIWMIN = 3 + 5*N
LWMIN = 1 + 6*N + 2*N**2
ELSE
LIWMIN = 1
LWMIN = 2*N + 1
END IF
LOPT = LWMIN
LIOPT = LIWMIN
IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN
INFO = -1
ELSE IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
INFO = -2
ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN
INFO = -3
ELSE IF( N.LT.0 ) THEN
INFO = -4
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -6
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -8
END IF
*
IF( INFO.EQ.0 ) THEN
WORK( 1 ) = LOPT
IWORK( 1 ) = LIOPT
*
IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
INFO = -11
ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
INFO = -13
END IF
END IF
*
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DSYGVD', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
* Form a Cholesky factorization of B.
*
CALL DPOTRF( UPLO, N, B, LDB, INFO )
IF( INFO.NE.0 ) THEN
INFO = N + INFO
RETURN
END IF
*
* Transform problem to standard eigenvalue problem and solve.
*
CALL DSYGST( ITYPE, UPLO, N, A, LDA, B, LDB, INFO )
CALL DSYEVD( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK, IWORK, LIWORK,
$ INFO )
LOPT = MAX( DBLE( LOPT ), DBLE( WORK( 1 ) ) )
LIOPT = MAX( DBLE( LIOPT ), DBLE( IWORK( 1 ) ) )
*
IF( WANTZ .AND. INFO.EQ.0 ) THEN
*
* Backtransform eigenvectors to the original problem.
*
IF( ITYPE.EQ.1 .OR. ITYPE.EQ.2 ) THEN
*
* For A*x=(lambda)*B*x and A*B*x=(lambda)*x;
* backtransform eigenvectors: x = inv(L)**T*y or inv(U)*y
*
IF( UPPER ) THEN
TRANS = 'N'
ELSE
TRANS = 'T'
END IF
*
CALL DTRSM( 'Left', UPLO, TRANS, 'Non-unit', N, N, ONE,
$ B, LDB, A, LDA )
*
ELSE IF( ITYPE.EQ.3 ) THEN
*
* For B*A*x=(lambda)*x;
* backtransform eigenvectors: x = L*y or U**T*y
*
IF( UPPER ) THEN
TRANS = 'T'
ELSE
TRANS = 'N'
END IF
*
CALL DTRMM( 'Left', UPLO, TRANS, 'Non-unit', N, N, ONE,
$ B, LDB, A, LDA )
END IF
END IF
*
WORK( 1 ) = LOPT
IWORK( 1 ) = LIOPT
*
RETURN
*
* End of DSYGVD
*
END
| bsd-3-clause |
mverleg/1957 | lib/lapack/dpotri.f | 29 | 4180 | *> \brief \b DPOTRI
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DPOTRI + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dpotri.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dpotri.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dpotri.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DPOTRI( UPLO, N, A, LDA, INFO )
*
* .. Scalar Arguments ..
* CHARACTER UPLO
* INTEGER INFO, LDA, N
* ..
* .. Array Arguments ..
* DOUBLE PRECISION A( LDA, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DPOTRI computes the inverse of a real symmetric positive definite
*> matrix A using the Cholesky factorization A = U**T*U or A = L*L**T
*> computed by DPOTRF.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] UPLO
*> \verbatim
*> UPLO is CHARACTER*1
*> = 'U': Upper triangle of A is stored;
*> = 'L': Lower triangle of A is stored.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrix A. N >= 0.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is DOUBLE PRECISION array, dimension (LDA,N)
*> On entry, the triangular factor U or L from the Cholesky
*> factorization A = U**T*U or A = L*L**T, as computed by
*> DPOTRF.
*> On exit, the upper or lower triangle of the (symmetric)
*> inverse of A, overwriting the input factor U or L.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value
*> > 0: if INFO = i, the (i,i) element of the factor U or L is
*> zero, and the inverse could not be computed.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup doublePOcomputational
*
* =====================================================================
SUBROUTINE DPOTRI( UPLO, N, A, LDA, INFO )
*
* -- LAPACK computational routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, LDA, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * )
* ..
*
* =====================================================================
*
* .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
* ..
* .. External Subroutines ..
EXTERNAL DLAUUM, DTRTRI, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -4
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DPOTRI', -INFO )
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
* Invert the triangular Cholesky factor U or L.
*
CALL DTRTRI( UPLO, 'Non-unit', N, A, LDA, INFO )
IF( INFO.GT.0 )
$ RETURN
*
* Form inv(U) * inv(U)**T or inv(L)**T * inv(L).
*
CALL DLAUUM( UPLO, N, A, LDA, INFO )
*
RETURN
*
* End of DPOTRI
*
END
| bsd-3-clause |
mverleg/1957 | lib/lapack/slantp.f | 24 | 10849 | *> \brief \b SLANTP returns the value of the 1-norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a triangular matrix supplied in packed form.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download SLANTP + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slantp.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slantp.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slantp.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* REAL FUNCTION SLANTP( NORM, UPLO, DIAG, N, AP, WORK )
*
* .. Scalar Arguments ..
* CHARACTER DIAG, NORM, UPLO
* INTEGER N
* ..
* .. Array Arguments ..
* REAL AP( * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> SLANTP returns the value of the one norm, or the Frobenius norm, or
*> the infinity norm, or the element of largest absolute value of a
*> triangular matrix A, supplied in packed form.
*> \endverbatim
*>
*> \return SLANTP
*> \verbatim
*>
*> SLANTP = ( max(abs(A(i,j))), NORM = 'M' or 'm'
*> (
*> ( norm1(A), NORM = '1', 'O' or 'o'
*> (
*> ( normI(A), NORM = 'I' or 'i'
*> (
*> ( normF(A), NORM = 'F', 'f', 'E' or 'e'
*>
*> where norm1 denotes the one norm of a matrix (maximum column sum),
*> normI denotes the infinity norm of a matrix (maximum row sum) and
*> normF denotes the Frobenius norm of a matrix (square root of sum of
*> squares). Note that max(abs(A(i,j))) is not a consistent matrix norm.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] NORM
*> \verbatim
*> NORM is CHARACTER*1
*> Specifies the value to be returned in SLANTP as described
*> above.
*> \endverbatim
*>
*> \param[in] UPLO
*> \verbatim
*> UPLO is CHARACTER*1
*> Specifies whether the matrix A is upper or lower triangular.
*> = 'U': Upper triangular
*> = 'L': Lower triangular
*> \endverbatim
*>
*> \param[in] DIAG
*> \verbatim
*> DIAG is CHARACTER*1
*> Specifies whether or not the matrix A is unit triangular.
*> = 'N': Non-unit triangular
*> = 'U': Unit triangular
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrix A. N >= 0. When N = 0, SLANTP is
*> set to zero.
*> \endverbatim
*>
*> \param[in] AP
*> \verbatim
*> AP is REAL array, dimension (N*(N+1)/2)
*> The upper or lower triangular matrix A, packed columnwise in
*> a linear array. The j-th column of A is stored in the array
*> AP as follows:
*> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
*> if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
*> Note that when DIAG = 'U', the elements of the array AP
*> corresponding to the diagonal elements of the matrix A are
*> not referenced, but are assumed to be one.
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is REAL array, dimension (MAX(1,LWORK)),
*> where LWORK >= N when NORM = 'I'; otherwise, WORK is not
*> referenced.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date September 2012
*
*> \ingroup realOTHERauxiliary
*
* =====================================================================
REAL FUNCTION SLANTP( NORM, UPLO, DIAG, N, AP, WORK )
*
* -- LAPACK auxiliary routine (version 3.4.2) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* September 2012
*
* .. Scalar Arguments ..
CHARACTER DIAG, NORM, UPLO
INTEGER N
* ..
* .. Array Arguments ..
REAL AP( * ), WORK( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
REAL ONE, ZERO
PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
* ..
* .. Local Scalars ..
LOGICAL UDIAG
INTEGER I, J, K
REAL SCALE, SUM, VALUE
* ..
* .. External Subroutines ..
EXTERNAL SLASSQ
* ..
* .. External Functions ..
LOGICAL LSAME, SISNAN
EXTERNAL LSAME, SISNAN
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, SQRT
* ..
* .. Executable Statements ..
*
IF( N.EQ.0 ) THEN
VALUE = ZERO
ELSE IF( LSAME( NORM, 'M' ) ) THEN
*
* Find max(abs(A(i,j))).
*
K = 1
IF( LSAME( DIAG, 'U' ) ) THEN
VALUE = ONE
IF( LSAME( UPLO, 'U' ) ) THEN
DO 20 J = 1, N
DO 10 I = K, K + J - 2
SUM = ABS( AP( I ) )
IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
10 CONTINUE
K = K + J
20 CONTINUE
ELSE
DO 40 J = 1, N
DO 30 I = K + 1, K + N - J
SUM = ABS( AP( I ) )
IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
30 CONTINUE
K = K + N - J + 1
40 CONTINUE
END IF
ELSE
VALUE = ZERO
IF( LSAME( UPLO, 'U' ) ) THEN
DO 60 J = 1, N
DO 50 I = K, K + J - 1
SUM = ABS( AP( I ) )
IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
50 CONTINUE
K = K + J
60 CONTINUE
ELSE
DO 80 J = 1, N
DO 70 I = K, K + N - J
SUM = ABS( AP( I ) )
IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
70 CONTINUE
K = K + N - J + 1
80 CONTINUE
END IF
END IF
ELSE IF( ( LSAME( NORM, 'O' ) ) .OR. ( NORM.EQ.'1' ) ) THEN
*
* Find norm1(A).
*
VALUE = ZERO
K = 1
UDIAG = LSAME( DIAG, 'U' )
IF( LSAME( UPLO, 'U' ) ) THEN
DO 110 J = 1, N
IF( UDIAG ) THEN
SUM = ONE
DO 90 I = K, K + J - 2
SUM = SUM + ABS( AP( I ) )
90 CONTINUE
ELSE
SUM = ZERO
DO 100 I = K, K + J - 1
SUM = SUM + ABS( AP( I ) )
100 CONTINUE
END IF
K = K + J
IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
110 CONTINUE
ELSE
DO 140 J = 1, N
IF( UDIAG ) THEN
SUM = ONE
DO 120 I = K + 1, K + N - J
SUM = SUM + ABS( AP( I ) )
120 CONTINUE
ELSE
SUM = ZERO
DO 130 I = K, K + N - J
SUM = SUM + ABS( AP( I ) )
130 CONTINUE
END IF
K = K + N - J + 1
IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
140 CONTINUE
END IF
ELSE IF( LSAME( NORM, 'I' ) ) THEN
*
* Find normI(A).
*
K = 1
IF( LSAME( UPLO, 'U' ) ) THEN
IF( LSAME( DIAG, 'U' ) ) THEN
DO 150 I = 1, N
WORK( I ) = ONE
150 CONTINUE
DO 170 J = 1, N
DO 160 I = 1, J - 1
WORK( I ) = WORK( I ) + ABS( AP( K ) )
K = K + 1
160 CONTINUE
K = K + 1
170 CONTINUE
ELSE
DO 180 I = 1, N
WORK( I ) = ZERO
180 CONTINUE
DO 200 J = 1, N
DO 190 I = 1, J
WORK( I ) = WORK( I ) + ABS( AP( K ) )
K = K + 1
190 CONTINUE
200 CONTINUE
END IF
ELSE
IF( LSAME( DIAG, 'U' ) ) THEN
DO 210 I = 1, N
WORK( I ) = ONE
210 CONTINUE
DO 230 J = 1, N
K = K + 1
DO 220 I = J + 1, N
WORK( I ) = WORK( I ) + ABS( AP( K ) )
K = K + 1
220 CONTINUE
230 CONTINUE
ELSE
DO 240 I = 1, N
WORK( I ) = ZERO
240 CONTINUE
DO 260 J = 1, N
DO 250 I = J, N
WORK( I ) = WORK( I ) + ABS( AP( K ) )
K = K + 1
250 CONTINUE
260 CONTINUE
END IF
END IF
VALUE = ZERO
DO 270 I = 1, N
SUM = WORK( I )
IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
270 CONTINUE
ELSE IF( ( LSAME( NORM, 'F' ) ) .OR. ( LSAME( NORM, 'E' ) ) ) THEN
*
* Find normF(A).
*
IF( LSAME( UPLO, 'U' ) ) THEN
IF( LSAME( DIAG, 'U' ) ) THEN
SCALE = ONE
SUM = N
K = 2
DO 280 J = 2, N
CALL SLASSQ( J-1, AP( K ), 1, SCALE, SUM )
K = K + J
280 CONTINUE
ELSE
SCALE = ZERO
SUM = ONE
K = 1
DO 290 J = 1, N
CALL SLASSQ( J, AP( K ), 1, SCALE, SUM )
K = K + J
290 CONTINUE
END IF
ELSE
IF( LSAME( DIAG, 'U' ) ) THEN
SCALE = ONE
SUM = N
K = 2
DO 300 J = 1, N - 1
CALL SLASSQ( N-J, AP( K ), 1, SCALE, SUM )
K = K + N - J + 1
300 CONTINUE
ELSE
SCALE = ZERO
SUM = ONE
K = 1
DO 310 J = 1, N
CALL SLASSQ( N-J+1, AP( K ), 1, SCALE, SUM )
K = K + N - J + 1
310 CONTINUE
END IF
END IF
VALUE = SCALE*SQRT( SUM )
END IF
*
SLANTP = VALUE
RETURN
*
* End of SLANTP
*
END
| bsd-3-clause |
mverleg/1957 | lib/lapack/ssytrf_rook.f | 5 | 12082 | *> \brief \b SSYTRF_ROOK
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download SSYTRF_ROOK + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytrf_rook.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytrf_rook.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytrf_rook.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE SSYTRF_ROOK( UPLO, N, A, LDA, IPIV, WORK, LWORK, INFO )
*
* .. Scalar Arguments ..
* CHARACTER UPLO
* INTEGER INFO, LDA, LWORK, N
* ..
* .. Array Arguments ..
* INTEGER IPIV( * )
* REAL A( LDA, * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> SSYTRF_ROOK computes the factorization of a real symmetric matrix A
*> using the bounded Bunch-Kaufman ("rook") diagonal pivoting method.
*> The form of the factorization is
*>
*> A = U*D*U**T or A = L*D*L**T
*>
*> where U (or L) is a product of permutation and unit upper (lower)
*> triangular matrices, and D is symmetric and block diagonal with
*> 1-by-1 and 2-by-2 diagonal blocks.
*>
*> This is the blocked version of the algorithm, calling Level 3 BLAS.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] UPLO
*> \verbatim
*> UPLO is CHARACTER*1
*> = 'U': Upper triangle of A is stored;
*> = 'L': Lower triangle of A is stored.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrix A. N >= 0.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is REAL array, dimension (LDA,N)
*> On entry, the symmetric matrix A. If UPLO = 'U', the leading
*> N-by-N upper triangular part of A contains the upper
*> triangular part of the matrix A, and the strictly lower
*> triangular part of A is not referenced. If UPLO = 'L', the
*> leading N-by-N lower triangular part of A contains the lower
*> triangular part of the matrix A, and the strictly upper
*> triangular part of A is not referenced.
*>
*> On exit, the block diagonal matrix D and the multipliers used
*> to obtain the factor U or L (see below for further details).
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[out] IPIV
*> \verbatim
*> IPIV is INTEGER array, dimension (N)
*> Details of the interchanges and the block structure of D.
*>
*> If UPLO = 'U':
*> If IPIV(k) > 0, then rows and columns k and IPIV(k)
*> were interchanged and D(k,k) is a 1-by-1 diagonal block.
*>
*> If IPIV(k) < 0 and IPIV(k-1) < 0, then rows and
*> columns k and -IPIV(k) were interchanged and rows and
*> columns k-1 and -IPIV(k-1) were inerchaged,
*> D(k-1:k,k-1:k) is a 2-by-2 diagonal block.
*>
*> If UPLO = 'L':
*> If IPIV(k) > 0, then rows and columns k and IPIV(k)
*> were interchanged and D(k,k) is a 1-by-1 diagonal block.
*>
*> If IPIV(k) < 0 and IPIV(k+1) < 0, then rows and
*> columns k and -IPIV(k) were interchanged and rows and
*> columns k+1 and -IPIV(k+1) were inerchaged,
*> D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is REAL array, dimension (MAX(1,LWORK)).
*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
*> \endverbatim
*>
*> \param[in] LWORK
*> \verbatim
*> LWORK is INTEGER
*> The length of WORK. LWORK >=1. For best performance
*> LWORK >= N*NB, where NB is the block size returned by ILAENV.
*>
*> If LWORK = -1, then a workspace query is assumed; the routine
*> only calculates the optimal size of the WORK array, returns
*> this value as the first entry of the WORK array, and no error
*> message related to LWORK is issued by XERBLA.
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value
*> > 0: if INFO = i, D(i,i) is exactly zero. The factorization
*> has been completed, but the block diagonal matrix D is
*> exactly singular, and division by zero will occur if it
*> is used to solve a system of equations.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2015
*
*> \ingroup realSYcomputational
*
*> \par Further Details:
* =====================
*>
*> \verbatim
*>
*> If UPLO = 'U', then A = U*D*U**T, where
*> U = P(n)*U(n)* ... *P(k)U(k)* ...,
*> i.e., U is a product of terms P(k)*U(k), where k decreases from n to
*> 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
*> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
*> defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
*> that if the diagonal block D(k) is of order s (s = 1 or 2), then
*>
*> ( I v 0 ) k-s
*> U(k) = ( 0 I 0 ) s
*> ( 0 0 I ) n-k
*> k-s s n-k
*>
*> If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
*> If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
*> and A(k,k), and v overwrites A(1:k-2,k-1:k).
*>
*> If UPLO = 'L', then A = L*D*L**T, where
*> L = P(1)*L(1)* ... *P(k)*L(k)* ...,
*> i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
*> n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
*> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
*> defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
*> that if the diagonal block D(k) is of order s (s = 1 or 2), then
*>
*> ( I 0 0 ) k-1
*> L(k) = ( 0 I 0 ) s
*> ( 0 v I ) n-k-s+1
*> k-1 s n-k-s+1
*>
*> If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
*> If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
*> and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
*> \endverbatim
*
*> \par Contributors:
* ==================
*>
*> \verbatim
*>
*> November 2015, Igor Kozachenko,
*> Computer Science Division,
*> University of California, Berkeley
*>
*> September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas,
*> School of Mathematics,
*> University of Manchester
*>
*> \endverbatim
*
* =====================================================================
SUBROUTINE SSYTRF_ROOK( UPLO, N, A, LDA, IPIV, WORK, LWORK, INFO )
*
* -- LAPACK computational routine (version 3.6.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2015
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, LDA, LWORK, N
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
REAL A( LDA, * ), WORK( * )
* ..
*
* =====================================================================
*
* .. Local Scalars ..
LOGICAL LQUERY, UPPER
INTEGER IINFO, IWS, J, K, KB, LDWORK, LWKOPT, NB, NBMIN
* ..
* .. External Functions ..
LOGICAL LSAME
INTEGER ILAENV
EXTERNAL LSAME, ILAENV
* ..
* .. External Subroutines ..
EXTERNAL SLASYF_ROOK, SSYTF2_ROOK, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
UPPER = LSAME( UPLO, 'U' )
LQUERY = ( LWORK.EQ.-1 )
IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -4
ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN
INFO = -7
END IF
*
IF( INFO.EQ.0 ) THEN
*
* Determine the block size
*
NB = ILAENV( 1, 'SSYTRF_ROOK', UPLO, N, -1, -1, -1 )
LWKOPT = N*NB
WORK( 1 ) = LWKOPT
END IF
*
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'SSYTRF_ROOK', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
NBMIN = 2
LDWORK = N
IF( NB.GT.1 .AND. NB.LT.N ) THEN
IWS = LDWORK*NB
IF( LWORK.LT.IWS ) THEN
NB = MAX( LWORK / LDWORK, 1 )
NBMIN = MAX( 2, ILAENV( 2, 'SSYTRF_ROOK',
$ UPLO, N, -1, -1, -1 ) )
END IF
ELSE
IWS = 1
END IF
IF( NB.LT.NBMIN )
$ NB = N
*
IF( UPPER ) THEN
*
* Factorize A as U*D*U**T using the upper triangle of A
*
* K is the main loop index, decreasing from N to 1 in steps of
* KB, where KB is the number of columns factorized by SLASYF_ROOK;
* KB is either NB or NB-1, or K for the last block
*
K = N
10 CONTINUE
*
* If K < 1, exit from loop
*
IF( K.LT.1 )
$ GO TO 40
*
IF( K.GT.NB ) THEN
*
* Factorize columns k-kb+1:k of A and use blocked code to
* update columns 1:k-kb
*
CALL SLASYF_ROOK( UPLO, K, NB, KB, A, LDA,
$ IPIV, WORK, LDWORK, IINFO )
ELSE
*
* Use unblocked code to factorize columns 1:k of A
*
CALL SSYTF2_ROOK( UPLO, K, A, LDA, IPIV, IINFO )
KB = K
END IF
*
* Set INFO on the first occurrence of a zero pivot
*
IF( INFO.EQ.0 .AND. IINFO.GT.0 )
$ INFO = IINFO
*
* No need to adjust IPIV
*
* Decrease K and return to the start of the main loop
*
K = K - KB
GO TO 10
*
ELSE
*
* Factorize A as L*D*L**T using the lower triangle of A
*
* K is the main loop index, increasing from 1 to N in steps of
* KB, where KB is the number of columns factorized by SLASYF_ROOK;
* KB is either NB or NB-1, or N-K+1 for the last block
*
K = 1
20 CONTINUE
*
* If K > N, exit from loop
*
IF( K.GT.N )
$ GO TO 40
*
IF( K.LE.N-NB ) THEN
*
* Factorize columns k:k+kb-1 of A and use blocked code to
* update columns k+kb:n
*
CALL SLASYF_ROOK( UPLO, N-K+1, NB, KB, A( K, K ), LDA,
$ IPIV( K ), WORK, LDWORK, IINFO )
ELSE
*
* Use unblocked code to factorize columns k:n of A
*
CALL SSYTF2_ROOK( UPLO, N-K+1, A( K, K ), LDA, IPIV( K ),
$ IINFO )
KB = N - K + 1
END IF
*
* Set INFO on the first occurrence of a zero pivot
*
IF( INFO.EQ.0 .AND. IINFO.GT.0 )
$ INFO = IINFO + K - 1
*
* Adjust IPIV
*
DO 30 J = K, K + KB - 1
IF( IPIV( J ).GT.0 ) THEN
IPIV( J ) = IPIV( J ) + K - 1
ELSE
IPIV( J ) = IPIV( J ) - K + 1
END IF
30 CONTINUE
*
* Increase K and return to the start of the main loop
*
K = K + KB
GO TO 20
*
END IF
*
40 CONTINUE
WORK( 1 ) = LWKOPT
RETURN
*
* End of SSYTRF_ROOK
*
END
| bsd-3-clause |
jimhester/r-source | src/library/stats/src/stl.f | 46 | 15661 | c
c from netlib/a/stl: no authorship nor copyright claim in the source;
c presumably by the authors of
c
c R.B. Cleveland, W.S.Cleveland, J.E. McRae, and I. Terpenning,
c STL: A Seasonal-Trend Decomposition Procedure Based on Loess,
c Statistics Research Report, AT&T Bell Laboratories.
c
c Converted to double precision by B.D. Ripley 1999.
c Indented, goto labels renamed, many goto's replaced by `if then {else}'
c (using Emacs), many more comments; by M.Maechler 2001-02.
c
subroutine stl(y,n,np,ns,nt,nl, isdeg,itdeg,ildeg,
& nsjump,ntjump,nljump, ni,no, rw,season,trend,work)
c implicit none
c Arg
integer n, np, ns,nt,nl, isdeg,itdeg,ildeg, nsjump,ntjump,nljump,
& ni, no
c n : length(y)
c ns, nt, nl : spans for `s', `t' and `l' smoother
c isdeg, itdeg, ildeg : local degree for `s', `t' and `l' smoother
c nsjump,ntjump,nljump: ........ for `s', `t' and `l' smoother
c ni, no : number of inner and outer (robust) iterations
double precision y(n), rw(n), season(n), trend(n),
& work(n+2*np,5)
c Var
integer i,k, newns, newnt, newnl, newnp
logical userw
userw = .false.
do 1 i = 1,n
trend(i) = 0.d0
1 continue
c the three spans must be at least three and odd:
newns = max0(3,ns)
newnt = max0(3,nt)
newnl = max0(3,nl)
if(mod(newns,2) .eq. 0) newns = newns + 1
if(mod(newnt,2) .eq. 0) newnt = newnt + 1
if(mod(newnl,2) .eq. 0) newnl = newnl + 1
c periodicity at least 2:
newnp = max0(2,np)
k = 0
c --- outer loop -- robustnes iterations
100 continue
call stlstp(y,n, newnp,newns,newnt,newnl, isdeg,itdeg,ildeg,
& nsjump,ntjump,nljump, ni,userw,rw,season, trend, work)
k = k+1
if(k .gt. no) goto 10
do 3 i = 1,n
work(i,1) = trend(i)+season(i)
3 continue
call stlrwt(y,n,work(1,1),rw)
userw = .true.
goto 100
c --- end Loop
10 continue
c robustness weights when there were no robustness iterations:
if(no .le. 0) then
do 15 i = 1,n
rw(i) = 1.d0
15 continue
endif
return
end
subroutine stless(y,n,len,ideg,njump,userw,rw,ys,res)
c implicit none
c Arg
integer n, len, ideg, njump
double precision y(n), rw(n), ys(n), res(n)
c Var
integer newnj, nleft, nright, nsh, k, i, j
double precision delta
logical ok, userw
if(n .lt. 2) then
ys(1) = y(1)
return
endif
newnj = min0(njump, n-1)
if(len .ge. n) then
nleft = 1
nright = n
do 20 i = 1,n,newnj
call stlest(y,n,len,ideg,dble(i),ys(i),nleft,nright,res,
& userw,rw,ok)
if(.not. ok) ys(i) = y(i)
20 continue
else
if(newnj .eq. 1) then
nsh = (len+1)/2
nleft = 1
nright = len
do 30 i = 1,n
if(i .gt. nsh .and. nright .ne. n) then
nleft = nleft+1
nright = nright+1
endif
call stlest(y,n,len,ideg,dble(i),ys(i),nleft,nright,res,
& userw,rw,ok)
if(.not. ok) ys(i) = y(i)
30 continue
else
nsh = (len+1)/2
do 40 i = 1,n,newnj
if(i .lt. nsh) then
nleft = 1
nright = len
else if(i .ge. n-nsh+1) then
nleft = n-len+1
nright = n
else
nleft = i-nsh+1
nright = len+i-nsh
endif
call stlest(y,n,len,ideg,dble(i),ys(i),nleft,nright,res,
& userw,rw,ok)
if(.not. ok) ys(i) = y(i)
40 continue
endif
endif
if(newnj .ne. 1) then
do 45 i = 1,n-newnj,newnj
delta = (ys(i+newnj)-ys(i))/dble(newnj)
do 47 j = i+1,i+newnj-1
ys(j) = ys(i)+delta*dble(j-i)
47 continue
45 continue
k = ((n-1)/newnj)*newnj+1
if(k .ne. n) then
call stlest(y,n,len,ideg,dble(n),ys(n),nleft,nright,res,
& userw,rw,ok)
if(.not. ok) ys(n) = y(n)
if(k .ne. n-1) then
delta = (ys(n)-ys(k))/dble(n-k)
do 55 j = k+1,n-1
ys(j) = ys(k)+delta*dble(j-k)
55 continue
endif
endif
endif
return
end
subroutine stlest(y,n,len,ideg,xs,ys,nleft,nright,w,
& userw,rw,ok)
c implicit none
c Arg
integer n, len, ideg, nleft, nright
double precision y(n), w(n), rw(n), xs, ys
logical userw,ok
c Var
double precision range, h, h1, h9, a, b, c, r
integer j
range = dble(n)-dble(1)
h = max(xs - dble(nleft), dble(nright) - xs)
if(len .gt. n) h = h + dble((len-n)/2)
h9 = 0.999d0*h
h1 = 0.001d0*h
a = 0.d0
do 60 j = nleft,nright
r = abs(dble(j)-xs)
if(r .le. h9) then
if(r .le. h1) then
w(j) = 1.d0
else
w(j) = (1.d0 - (r/h)**3)**3
endif
if(userw) w(j) = rw(j)*w(j)
a = a+w(j)
else
w(j) = 0.d0
endif
60 continue
if(a .le. 0.d0) then
ok = .false.
else
ok = .true.
do 69 j = nleft,nright
w(j) = w(j)/a
69 continue
if((h .gt. 0.d0) .and. (ideg .gt. 0)) then
a = 0.d0
do 73 j = nleft,nright
a = a+w(j)*dble(j)
73 continue
b = xs-a
c = 0.d0
do 75 j = nleft,nright
c = c+w(j)*(dble(j)-a)**2
75 continue
if(sqrt(c) .gt. 0.001d0*range) then
b = b/c
do 79 j = nleft,nright
w(j) = w(j)*(b*(dble(j)-a)+1.0d0)
79 continue
endif
endif
ys = 0.d0
do 81 j = nleft,nright
ys = ys+w(j)*y(j)
81 continue
endif
return
end
subroutine stlfts(x,n,np,trend,work)
integer n, np
double precision x(n), trend(n), work(n)
call stlma(x, n, np, trend)
call stlma(trend,n-np+1, np, work)
call stlma(work, n-2*np+2,3, trend)
return
end
subroutine stlma(x, n, len, ave)
c Moving Average (aka "running mean")
c ave(i) := mean(x{j}, j = max(1,i-k),..., min(n, i+k))
c for i = 1,2,..,n
c implicit none
c Arg
integer n, len
double precision x(n), ave(n)
c Var
double precision flen, v
integer i, j, k, m, newn
newn = n-len+1
flen = dble(len)
v = 0.d0
do 3 i = 1,len
v = v+x(i)
3 continue
ave(1) = v/flen
if(newn .gt. 1) then
k = len
m = 0
do 7 j = 2, newn
k = k+1
m = m+1
v = v-x(m)+x(k)
ave(j) = v/flen
7 continue
endif
return
end
subroutine stlstp(y,n,np,ns,nt,nl,isdeg,itdeg,ildeg,nsjump,
& ntjump,nljump,ni,userw,rw,season,trend,work)
c implicit none
c Arg
integer n,np,ns,nt,nl,isdeg,itdeg,ildeg,nsjump,ntjump,nljump,ni
logical userw
double precision y(n),rw(n),season(n),trend(n),work(n+2*np,5)
c Var
integer i,j
do 80 j = 1,ni
do 1 i = 1,n
work(i,1) = y(i)-trend(i)
1 continue
call stlss(work(1,1),n,np,ns,isdeg,nsjump,userw,rw,work(1,2),
& work(1,3),work(1,4),work(1,5),season)
call stlfts(work(1,2),n+2*np,np,work(1,3),work(1,1))
call stless(work(1,3),n,nl,ildeg,nljump,.false.,work(1,4),
& work(1,1),work(1,5))
do 3 i = 1,n
season(i) = work(np+i,2)-work(i,1)
3 continue
do 5 i = 1,n
work(i,1) = y(i)-season(i)
5 continue
call stless(work(1,1),n,nt,itdeg,ntjump,userw,rw,trend,
& work(1,3))
80 continue
return
end
subroutine stlrwt(y,n,fit,rw)
c Robustness Weights
c rw_i := B( |y_i - fit_i| / (6 M) ), i = 1,2,...,n
c where B(u) = (1 - u^2)^2 * 1[|u| < 1] {Tukey's biweight}
c and M := median{ |y_i - fit_i| }
c implicit none
c Arg
integer n
double precision y(n), fit(n), rw(n)
c Var
integer mid(2), i
double precision cmad, c9, c1, r
do 7 i = 1,n
rw(i) = abs(y(i)-fit(i))
7 continue
mid(1) = n/2+1
mid(2) = n-mid(1)+1
call psort(rw,n,mid,2)
cmad = 3.0d0*(rw(mid(1))+rw(mid(2)))
c = 6 * MAD
c9 = 0.999d0*cmad
c1 = 0.001d0*cmad
do 10 i = 1,n
r = abs(y(i)-fit(i))
if(r .le. c1) then
rw(i) = 1.d0
else if(r .le. c9) then
rw(i) = (1.d0 - (r/cmad)**2)**2
else
rw(i) = 0.d0
endif
10 continue
return
end
subroutine stlss(y,n,np,ns,isdeg,nsjump,userw,rw,season,
& work1,work2,work3,work4)
c
c called by stlstp() at the beginning of each (inner) iteration
c
c implicit none
c Arg
integer n, np, ns, isdeg, nsjump
double precision y(n), rw(n), season(n+2*np),
& work1(n), work2(n), work3(n), work4(n)
logical userw
c Var
integer nright, nleft, i, j, k, m
logical ok
double precision xs
if(np .lt. 1) return
do 200 j = 1, np
k = (n-j)/np+1
do 10 i = 1,k
work1(i) = y((i-1)*np+j)
10 continue
if(userw) then
do 12 i = 1,k
work3(i) = rw((i-1)*np+j)
12 continue
endif
call stless(work1,k,ns,isdeg,nsjump,userw,work3,work2(2),work4)
xs = 0
nright = min0(ns,k)
call stlest(work1,k,ns,isdeg,xs,work2(1),1,nright,work4,
& userw,work3,ok)
if(.not. ok) work2(1) = work2(2)
xs = k+1
nleft = max0(1,k-ns+1)
call stlest(work1,k,ns,isdeg,xs,work2(k+2),nleft,k,work4,
& userw,work3,ok)
if(.not. ok) work2(k+2) = work2(k+1)
do 18 m = 1,k+2
season((m-1)*np+j) = work2(m)
18 continue
200 continue
return
end
c STL E_Z_ : "Easy" user interface -- not called from R
subroutine stlez(y, n, np, ns, isdeg, itdeg, robust, no, rw,
& season, trend, work)
c implicit none
c Arg
integer n, np, ns, isdeg, itdeg, no
logical robust
double precision y(n), rw(n), season(n), trend(n), work(n+2*np,7)
c Var
integer i, j, ildeg, nt, nl, ni, nsjump, ntjump, nljump,
& newns, newnp
double precision maxs, mins, maxt, mint, maxds, maxdt, difs, dift
ildeg = itdeg
newns = max0(3,ns)
if(mod(newns,2) .eq. 0) newns = newns+1
newnp = max0(2,np)
nt = int((1.5d0*newnp)/(1.d0 - 1.5d0/newns) + 0.5d0)
nt = max0(3,nt)
if(mod(nt,2) .eq. 0) nt = nt+1
nl = newnp
if(mod(nl,2) .eq. 0) nl = nl+1
if(robust) then
ni = 1
else
ni = 2
endif
nsjump = max0(1,int(float(newns)/10 + 0.9))
ntjump = max0(1,int(float(nt)/10 + 0.9))
nljump = max0(1,int(float(nl)/10 + 0.9))
do 2 i = 1,n
trend(i) = 0.d0
2 continue
call stlstp(y,n,newnp,newns,nt,nl,isdeg,itdeg,ildeg,nsjump,
& ntjump,nljump,ni,.false.,rw,season,trend,work)
no = 0
if(robust) then
j=1
C Loop --- 15 robustness iterations
100 if(j .le. 15) then
do 35 i = 1,n
work(i,6) = season(i)
work(i,7) = trend(i)
work(i,1) = trend(i)+season(i)
35 continue
call stlrwt(y,n,work(1,1),rw)
call stlstp(y, n, newnp, newns, nt,nl, isdeg,itdeg,ildeg,
& nsjump,ntjump,nljump, ni, .true.,
& rw, season, trend, work)
no = no+1
maxs = work(1,6)
mins = work(1,6)
maxt = work(1,7)
mint = work(1,7)
maxds = abs(work(1,6) - season(1))
maxdt = abs(work(1,7) - trend(1))
do 137 i = 2,n
if(maxs .lt. work(i,6)) maxs = work(i,6)
if(maxt .lt. work(i,7)) maxt = work(i,7)
if(mins .gt. work(i,6)) mins = work(i,6)
if(mint .gt. work(i,7)) mint = work(i,7)
difs = abs(work(i,6) - season(i))
dift = abs(work(i,7) - trend(i))
if(maxds .lt. difs) maxds = difs
if(maxdt .lt. dift) maxdt = dift
137 continue
if((maxds/(maxs-mins) .lt. 0.01d0) .and.
& (maxdt/(maxt-mint) .lt. 0.01d0)) goto 300
continue
j=j+1
goto 100
endif
C end Loop
300 continue
else
c .not. robust
do 150 i = 1,n
rw(i) = 1.0d0
150 continue
endif
return
end
subroutine psort(a,n,ind,ni)
c
c Partial Sorting ; used for Median (MAD) computation only
c
c implicit none
c Arg
integer n,ni
double precision a(n)
integer ind(ni)
c Var
integer indu(16),indl(16),iu(16),il(16),p,jl,ju,i,j,m,k,ij,l
double precision t,tt
if(n .lt. 0 .or. ni .lt. 0) return
if(n .lt. 2 .or. ni .eq. 0) return
jl = 1
ju = ni
indl(1) = 1
indu(1) = ni
i = 1
j = n
m = 1
c Outer Loop
161 continue
if(i .lt. j) go to 10
c _Loop_
166 continue
m = m-1
if(m .eq. 0) return
i = il(m)
j = iu(m)
jl = indl(m)
ju = indu(m)
if(.not.(jl .le. ju)) goto 166
c while (j - i > 10)
173 if(.not.(j-i .gt. 10)) goto 174
10 k = i
ij = (i+j)/2
t = a(ij)
if(a(i) .gt. t) then
a(ij) = a(i)
a(i) = t
t = a(ij)
endif
l = j
if(a(j) .lt. t) then
a(ij) = a(j)
a(j) = t
t = a(ij)
if(a(i) .gt. t) then
a(ij) = a(i)
a(i) = t
t = a(ij)
endif
endif
181 continue
l = l-1
if(a(l) .le. t)then
tt = a(l)
186 continue
k = k+1
if(.not.(a(k) .ge. t)) goto 186
if(k .gt. l) goto 183
a(l) = a(k)
a(k) = tt
endif
goto 181
183 continue
indl(m) = jl
indu(m) = ju
p = m
m = m+1
if(l-i .le. j-k) then
il(p) = k
iu(p) = j
j = l
193 continue
if(jl .gt. ju) goto 166
if(ind(ju) .gt. j) then
ju = ju-1
goto 193
endif
indl(p) = ju+1
else
il(p) = i
iu(p) = l
i = k
200 continue
if(jl .gt. ju) goto 166
if(ind(jl) .lt. i) then
jl = jl+1
goto 200
endif
indu(p) = jl-1
endif
goto 173
c end while
174 continue
if(i .ne. 1) then
i = i-1
209 continue
i = i+1
if(i .eq. j) goto 166
t = a(i+1)
if(a(i) .gt. t) then
k = i
c repeat
216 continue
a(k+1) = a(k)
k = k-1
if(.not.(t .ge. a(k))) goto 216
c until t >= a(k)
a(k+1) = t
endif
goto 209
endif
goto 161
c End Outer Loop
end
| gpl-2.0 |
mverleg/1957 | lib/lapack/cpoequb.f | 29 | 5819 | *> \brief \b CPOEQUB
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download CPOEQUB + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cpoequb.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cpoequb.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cpoequb.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE CPOEQUB( N, A, LDA, S, SCOND, AMAX, INFO )
*
* .. Scalar Arguments ..
* INTEGER INFO, LDA, N
* REAL AMAX, SCOND
* ..
* .. Array Arguments ..
* COMPLEX A( LDA, * )
* REAL S( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> CPOEQUB computes row and column scalings intended to equilibrate a
*> symmetric positive definite matrix A and reduce its condition number
*> (with respect to the two-norm). S contains the scale factors,
*> S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with
*> elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal. This
*> choice of S puts the condition number of B within a factor N of the
*> smallest possible condition number over all possible diagonal
*> scalings.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrix A. N >= 0.
*> \endverbatim
*>
*> \param[in] A
*> \verbatim
*> A is COMPLEX array, dimension (LDA,N)
*> The N-by-N symmetric positive definite matrix whose scaling
*> factors are to be computed. Only the diagonal elements of A
*> are referenced.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[out] S
*> \verbatim
*> S is REAL array, dimension (N)
*> If INFO = 0, S contains the scale factors for A.
*> \endverbatim
*>
*> \param[out] SCOND
*> \verbatim
*> SCOND is REAL
*> If INFO = 0, S contains the ratio of the smallest S(i) to
*> the largest S(i). If SCOND >= 0.1 and AMAX is neither too
*> large nor too small, it is not worth scaling by S.
*> \endverbatim
*>
*> \param[out] AMAX
*> \verbatim
*> AMAX is REAL
*> Absolute value of largest matrix element. If AMAX is very
*> close to overflow or very close to underflow, the matrix
*> should be scaled.
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value
*> > 0: if INFO = i, the i-th diagonal element is nonpositive.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup complexPOcomputational
*
* =====================================================================
SUBROUTINE CPOEQUB( N, A, LDA, S, SCOND, AMAX, INFO )
*
* -- LAPACK computational routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
INTEGER INFO, LDA, N
REAL AMAX, SCOND
* ..
* .. Array Arguments ..
COMPLEX A( LDA, * )
REAL S( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
* ..
* .. Local Scalars ..
INTEGER I
REAL SMIN, BASE, TMP
* ..
* .. External Functions ..
REAL SLAMCH
EXTERNAL SLAMCH
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN, SQRT, LOG, INT
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
* Positive definite only performs 1 pass of equilibration.
*
INFO = 0
IF( N.LT.0 ) THEN
INFO = -1
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -3
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CPOEQUB', -INFO )
RETURN
END IF
*
* Quick return if possible.
*
IF( N.EQ.0 ) THEN
SCOND = ONE
AMAX = ZERO
RETURN
END IF
BASE = SLAMCH( 'B' )
TMP = -0.5 / LOG ( BASE )
*
* Find the minimum and maximum diagonal elements.
*
S( 1 ) = A( 1, 1 )
SMIN = S( 1 )
AMAX = S( 1 )
DO 10 I = 2, N
S( I ) = A( I, I )
SMIN = MIN( SMIN, S( I ) )
AMAX = MAX( AMAX, S( I ) )
10 CONTINUE
*
IF( SMIN.LE.ZERO ) THEN
*
* Find the first non-positive diagonal element and return.
*
DO 20 I = 1, N
IF( S( I ).LE.ZERO ) THEN
INFO = I
RETURN
END IF
20 CONTINUE
ELSE
*
* Set the scale factors to the reciprocals
* of the diagonal elements.
*
DO 30 I = 1, N
S( I ) = BASE ** INT( TMP * LOG( S( I ) ) )
30 CONTINUE
*
* Compute SCOND = min(S(I)) / max(S(I)).
*
SCOND = SQRT( SMIN ) / SQRT( AMAX )
END IF
*
RETURN
*
* End of CPOEQUB
*
END
| bsd-3-clause |
mverleg/1957 | lib/lapack/sggglm.f | 5 | 10292 | *> \brief \b SGGGLM
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download SGGGLM + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sggglm.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sggglm.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sggglm.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE SGGGLM( N, M, P, A, LDA, B, LDB, D, X, Y, WORK, LWORK,
* INFO )
*
* .. Scalar Arguments ..
* INTEGER INFO, LDA, LDB, LWORK, M, N, P
* ..
* .. Array Arguments ..
* REAL A( LDA, * ), B( LDB, * ), D( * ), WORK( * ),
* $ X( * ), Y( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> SGGGLM solves a general Gauss-Markov linear model (GLM) problem:
*>
*> minimize || y ||_2 subject to d = A*x + B*y
*> x
*>
*> where A is an N-by-M matrix, B is an N-by-P matrix, and d is a
*> given N-vector. It is assumed that M <= N <= M+P, and
*>
*> rank(A) = M and rank( A B ) = N.
*>
*> Under these assumptions, the constrained equation is always
*> consistent, and there is a unique solution x and a minimal 2-norm
*> solution y, which is obtained using a generalized QR factorization
*> of the matrices (A, B) given by
*>
*> A = Q*(R), B = Q*T*Z.
*> (0)
*>
*> In particular, if matrix B is square nonsingular, then the problem
*> GLM is equivalent to the following weighted linear least squares
*> problem
*>
*> minimize || inv(B)*(d-A*x) ||_2
*> x
*>
*> where inv(B) denotes the inverse of B.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The number of rows of the matrices A and B. N >= 0.
*> \endverbatim
*>
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The number of columns of the matrix A. 0 <= M <= N.
*> \endverbatim
*>
*> \param[in] P
*> \verbatim
*> P is INTEGER
*> The number of columns of the matrix B. P >= N-M.
*> \endverbatim
*>
*> \param[in,out] A
*> \verbatim
*> A is REAL array, dimension (LDA,M)
*> On entry, the N-by-M matrix A.
*> On exit, the upper triangular part of the array A contains
*> the M-by-M upper triangular matrix R.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,N).
*> \endverbatim
*>
*> \param[in,out] B
*> \verbatim
*> B is REAL array, dimension (LDB,P)
*> On entry, the N-by-P matrix B.
*> On exit, if N <= P, the upper triangle of the subarray
*> B(1:N,P-N+1:P) contains the N-by-N upper triangular matrix T;
*> if N > P, the elements on and above the (N-P)th subdiagonal
*> contain the N-by-P upper trapezoidal matrix T.
*> \endverbatim
*>
*> \param[in] LDB
*> \verbatim
*> LDB is INTEGER
*> The leading dimension of the array B. LDB >= max(1,N).
*> \endverbatim
*>
*> \param[in,out] D
*> \verbatim
*> D is REAL array, dimension (N)
*> On entry, D is the left hand side of the GLM equation.
*> On exit, D is destroyed.
*> \endverbatim
*>
*> \param[out] X
*> \verbatim
*> X is REAL array, dimension (M)
*> \endverbatim
*>
*> \param[out] Y
*> \verbatim
*> Y is REAL array, dimension (P)
*>
*> On exit, X and Y are the solutions of the GLM problem.
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is REAL array, dimension (MAX(1,LWORK))
*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
*> \endverbatim
*>
*> \param[in] LWORK
*> \verbatim
*> LWORK is INTEGER
*> The dimension of the array WORK. LWORK >= max(1,N+M+P).
*> For optimum performance, LWORK >= M+min(N,P)+max(N,P)*NB,
*> where NB is an upper bound for the optimal blocksizes for
*> SGEQRF, SGERQF, SORMQR and SORMRQ.
*>
*> If LWORK = -1, then a workspace query is assumed; the routine
*> only calculates the optimal size of the WORK array, returns
*> this value as the first entry of the WORK array, and no error
*> message related to LWORK is issued by XERBLA.
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit.
*> < 0: if INFO = -i, the i-th argument had an illegal value.
*> = 1: the upper triangular factor R associated with A in the
*> generalized QR factorization of the pair (A, B) is
*> singular, so that rank(A) < M; the least squares
*> solution could not be computed.
*> = 2: the bottom (N-M) by (N-M) part of the upper trapezoidal
*> factor T associated with B in the generalized QR
*> factorization of the pair (A, B) is singular, so that
*> rank( A B ) < N; the least squares solution could not
*> be computed.
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2015
*
*> \ingroup realOTHEReigen
*
* =====================================================================
SUBROUTINE SGGGLM( N, M, P, A, LDA, B, LDB, D, X, Y, WORK, LWORK,
$ INFO )
*
* -- LAPACK driver routine (version 3.6.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2015
*
* .. Scalar Arguments ..
INTEGER INFO, LDA, LDB, LWORK, M, N, P
* ..
* .. Array Arguments ..
REAL A( LDA, * ), B( LDB, * ), D( * ), WORK( * ),
$ X( * ), Y( * )
* ..
*
* ===================================================================
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
* ..
* .. Local Scalars ..
LOGICAL LQUERY
INTEGER I, LOPT, LWKMIN, LWKOPT, NB, NB1, NB2, NB3,
$ NB4, NP
* ..
* .. External Subroutines ..
EXTERNAL SCOPY, SGEMV, SGGQRF, SORMQR, SORMRQ, STRTRS,
$ XERBLA
* ..
* .. External Functions ..
INTEGER ILAENV
EXTERNAL ILAENV
* ..
* .. Intrinsic Functions ..
INTRINSIC INT, MAX, MIN
* ..
* .. Executable Statements ..
*
* Test the input parameters
*
INFO = 0
NP = MIN( N, P )
LQUERY = ( LWORK.EQ.-1 )
IF( N.LT.0 ) THEN
INFO = -1
ELSE IF( M.LT.0 .OR. M.GT.N ) THEN
INFO = -2
ELSE IF( P.LT.0 .OR. P.LT.N-M ) THEN
INFO = -3
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
INFO = -5
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -7
END IF
*
* Calculate workspace
*
IF( INFO.EQ.0) THEN
IF( N.EQ.0 ) THEN
LWKMIN = 1
LWKOPT = 1
ELSE
NB1 = ILAENV( 1, 'SGEQRF', ' ', N, M, -1, -1 )
NB2 = ILAENV( 1, 'SGERQF', ' ', N, M, -1, -1 )
NB3 = ILAENV( 1, 'SORMQR', ' ', N, M, P, -1 )
NB4 = ILAENV( 1, 'SORMRQ', ' ', N, M, P, -1 )
NB = MAX( NB1, NB2, NB3, NB4 )
LWKMIN = M + N + P
LWKOPT = M + NP + MAX( N, P )*NB
END IF
WORK( 1 ) = LWKOPT
*
IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN
INFO = -12
END IF
END IF
*
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'SGGGLM', -INFO )
RETURN
ELSE IF( LQUERY ) THEN
RETURN
END IF
*
* Quick return if possible
*
IF( N.EQ.0 )
$ RETURN
*
* Compute the GQR factorization of matrices A and B:
*
* Q**T*A = ( R11 ) M, Q**T*B*Z**T = ( T11 T12 ) M
* ( 0 ) N-M ( 0 T22 ) N-M
* M M+P-N N-M
*
* where R11 and T22 are upper triangular, and Q and Z are
* orthogonal.
*
CALL SGGQRF( N, M, P, A, LDA, WORK, B, LDB, WORK( M+1 ),
$ WORK( M+NP+1 ), LWORK-M-NP, INFO )
LOPT = WORK( M+NP+1 )
*
* Update left-hand-side vector d = Q**T*d = ( d1 ) M
* ( d2 ) N-M
*
CALL SORMQR( 'Left', 'Transpose', N, 1, M, A, LDA, WORK, D,
$ MAX( 1, N ), WORK( M+NP+1 ), LWORK-M-NP, INFO )
LOPT = MAX( LOPT, INT( WORK( M+NP+1 ) ) )
*
* Solve T22*y2 = d2 for y2
*
IF( N.GT.M ) THEN
CALL STRTRS( 'Upper', 'No transpose', 'Non unit', N-M, 1,
$ B( M+1, M+P-N+1 ), LDB, D( M+1 ), N-M, INFO )
*
IF( INFO.GT.0 ) THEN
INFO = 1
RETURN
END IF
*
CALL SCOPY( N-M, D( M+1 ), 1, Y( M+P-N+1 ), 1 )
END IF
*
* Set y1 = 0
*
DO 10 I = 1, M + P - N
Y( I ) = ZERO
10 CONTINUE
*
* Update d1 = d1 - T12*y2
*
CALL SGEMV( 'No transpose', M, N-M, -ONE, B( 1, M+P-N+1 ), LDB,
$ Y( M+P-N+1 ), 1, ONE, D, 1 )
*
* Solve triangular system: R11*x = d1
*
IF( M.GT.0 ) THEN
CALL STRTRS( 'Upper', 'No Transpose', 'Non unit', M, 1, A, LDA,
$ D, M, INFO )
*
IF( INFO.GT.0 ) THEN
INFO = 2
RETURN
END IF
*
* Copy D to X
*
CALL SCOPY( M, D, 1, X, 1 )
END IF
*
* Backward transformation y = Z**T *y
*
CALL SORMRQ( 'Left', 'Transpose', P, 1, NP,
$ B( MAX( 1, N-P+1 ), 1 ), LDB, WORK( M+1 ), Y,
$ MAX( 1, P ), WORK( M+NP+1 ), LWORK-M-NP, INFO )
WORK( 1 ) = M + NP + MAX( LOPT, INT( WORK( M+NP+1 ) ) )
*
RETURN
*
* End of SGGGLM
*
END
| bsd-3-clause |
Vandemar/calypso | src/Fortran_libraries/MHD_src/field_data/m_cal_max_indices.f90 | 3 | 5476 | !>@file m_cal_max_indices.f90
!!@brief module m_cal_max_indices
!!
!!@author H. Matsui
!!@date Programmed by H.Matsui and H.Okuda in July 2000
!!@n Modified by H. Matsui on Aug., 2007
!
!>@brief Find node positions of maximum values
!!
!!@verbatim
!! subroutine allocate_phys_range(ncomp_viz)
!! subroutine deallocate_phys_range
!! subroutine cal_max_indices
!!@endverbatim
!
module m_cal_max_indices
!
use m_precision
!
implicit none
!
!> Number of components for range data
integer(kind=kint) :: ncomp_minmax
!
!> Global node address for minimum value
integer(kind=kint_gl), allocatable :: node_min(:)
!> Global node address for maximum value
integer(kind=kint_gl), allocatable :: node_max(:)
!> Minimum value of field
real(kind=kreal), allocatable :: phys_min(:)
!> Maximum value of field
real(kind=kreal), allocatable :: phys_max(:)
!
!> local node address for minimum value in subdomain
integer(kind=kint), allocatable :: inod_min_lc(:)
!> local node address for minimum value in subdomain
integer(kind=kint), allocatable :: inod_max_lc(:)
!> Global node address for minimum value in subdomain
integer(kind=kint_gl), allocatable :: node_min_local(:)
!> Global node address for minimum value in subdomain
integer(kind=kint_gl), allocatable :: node_max_local(:)
!> Minimum value of field in subdomain
real(kind=kreal), allocatable :: phys_min_local(:)
!> Maximum value of field in subdomain
real(kind=kreal), allocatable :: phys_max_local(:)
!
private :: inod_min_lc, inod_max_lc
private :: node_min_local, node_max_local
private :: phys_min_local, phys_max_local
!
! ----------------------------------------------------------------------
!
contains
!
! ----------------------------------------------------------------------
!
subroutine allocate_phys_range(ncomp_viz)
!
integer(kind = kint), intent(in) :: ncomp_viz
!
!
ncomp_minmax = ncomp_viz
allocate(node_min(ncomp_minmax))
allocate(node_max(ncomp_minmax))
allocate(phys_min(ncomp_minmax))
allocate(phys_max(ncomp_minmax))
!
allocate(inod_min_lc(ncomp_minmax))
allocate(inod_max_lc(ncomp_minmax))
allocate(node_min_local(ncomp_minmax))
allocate(node_max_local(ncomp_minmax))
allocate(phys_min_local(ncomp_minmax))
allocate(phys_max_local(ncomp_minmax))
!
node_min = 0
node_max = 0
phys_min = 0.0d0
phys_max = 0.0d0
!
node_min_local = 0
node_max_local = 0
phys_min_local = 1.0d15
phys_max_local =-1.0d15
!
end subroutine allocate_phys_range
!
! ----------------------------------------------------------------------
!
subroutine deallocate_phys_range
!
deallocate (node_min, node_min_local)
deallocate (node_max, node_max_local)
deallocate (phys_min, phys_min_local)
deallocate (phys_max, phys_max_local)
deallocate (inod_min_lc, inod_max_lc)
!
end subroutine deallocate_phys_range
!
! ----------------------------------------------------------------------
! ---------------------------------------------------------------------
!
subroutine cal_max_indices
!
use calypso_mpi
use m_geometry_data
use m_node_phys_data
!
integer (kind = kint) :: nd, inod
!
!$omp parallel do private(nd,inod)
do nd = 1, ncomp_minmax
!
inod_max_lc(nd) = 1
do inod = 1, node1%numnod
if (nod_fld1%d_fld(inod,nd) &
& .gt. nod_fld1%d_fld(inod_max_lc(nd),nd)) then
inod_max_lc(nd) = inod
end if
end do
!
inod_min_lc(nd) = 1
do inod = 1, node1%numnod
if (nod_fld1%d_fld(inod,nd) &
& .lt. nod_fld1%d_fld(inod_min_lc(nd),nd)) then
inod_min_lc(nd) = inod
end if
end do
!
phys_max_local(nd) = nod_fld1%d_fld(inod_max_lc(nd),nd)
phys_min_local(nd) = nod_fld1%d_fld(inod_min_lc(nd),nd)
end do
!$omp end parallel do
!
call MPI_allREDUCE (phys_max_local(1), phys_max(1), &
& ncomp_minmax, CALYPSO_REAL, MPI_MAX, CALYPSO_COMM, ierr_MPI)
!
call MPI_allREDUCE (phys_min_local(1), phys_min(1), &
& ncomp_minmax, CALYPSO_REAL, MPI_MIN, CALYPSO_COMM, ierr_MPI)
!
node_max_local = 0
node_min_local = 0
!
!$omp parallel do private(nd,inod)
do nd = 1, ncomp_minmax
if ( phys_max(nd) .eq. phys_max_local(nd) ) then
inod = inod_max_lc(nd)
node_max_local(nd) = node1%inod_global(inod)
end if
if ( phys_min(nd) .eq. phys_min_local(nd) ) then
inod = inod_min_lc(nd)
node_min_local(nd) = node1%inod_global(inod)
end if
end do
!$omp end parallel do
!
call MPI_allREDUCE (node_max_local(1), node_max(1), &
& ncomp_minmax, CALYPSO_GLOBAL_INT, MPI_SUM, &
& CALYPSO_COMM, ierr_MPI)
!
call MPI_allREDUCE (node_min_local(1), node_min(1), &
& ncomp_minmax, CALYPSO_GLOBAL_INT, MPI_SUM, &
& CALYPSO_COMM, ierr_MPI)
!
end subroutine cal_max_indices
!
! ---------------------------------------------------------------------
!
end module m_cal_max_indices
| gpl-3.0 |
maxhutch/magma | testing/lin/zdrvrf1.f | 9 | 6736 | SUBROUTINE ZDRVRF1( NOUT, NN, NVAL, THRESH, A, LDA, ARF, WORK )
*
IMPLICIT NONE
*
* -- LAPACK test routine (version 3.2.0) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2008
*
* .. Scalar Arguments ..
INTEGER LDA, NN, NOUT
DOUBLE PRECISION THRESH
* ..
* .. Array Arguments ..
INTEGER NVAL( NN )
DOUBLE PRECISION WORK( * )
COMPLEX*16 A( LDA, * ), ARF( * )
* ..
*
* Purpose
* =======
*
* ZDRVRF1 tests the LAPACK RFP routines:
* ZLANHF.F
*
* Arguments
* =========
*
* NOUT (input) INTEGER
* The unit number for output.
*
* NN (input) INTEGER
* The number of values of N contained in the vector NVAL.
*
* NVAL (input) INTEGER array, dimension (NN)
* The values of the matrix dimension N.
*
* THRESH (input) DOUBLE PRECISION
* The threshold value for the test ratios. A result is
* included in the output file if RESULT >= THRESH. To have
* every test ratio printed, use THRESH = 0.
*
* A (workspace) COMPLEX*16 array, dimension (LDA,NMAX)
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,NMAX).
*
* ARF (workspace) COMPLEX*16 array, dimension ((NMAX*(NMAX+1))/2).
*
* WORK (workspace) DOUBLE PRECISION array, dimension ( NMAX )
*
* =====================================================================
* ..
* .. Parameters ..
DOUBLE PRECISION ONE
PARAMETER ( ONE = 1.0D+0 )
INTEGER NTESTS
PARAMETER ( NTESTS = 1 )
* ..
* .. Local Scalars ..
CHARACTER UPLO, CFORM, NORM
INTEGER I, IFORM, IIN, IIT, INFO, INORM, IUPLO, J, N,
+ NERRS, NFAIL, NRUN
DOUBLE PRECISION EPS, LARGE, NORMA, NORMARF, SMALL
* ..
* .. Local Arrays ..
CHARACTER UPLOS( 2 ), FORMS( 2 ), NORMS( 4 )
INTEGER ISEED( 4 ), ISEEDY( 4 )
DOUBLE PRECISION RESULT( NTESTS )
* ..
* .. External Functions ..
COMPLEX*16 ZLARND
DOUBLE PRECISION DLAMCH, ZLANHE, ZLANHF
EXTERNAL DLAMCH, ZLARND, ZLANHE, ZLANHF
* ..
* .. External Subroutines ..
EXTERNAL ZTRTTF
* ..
* .. Scalars in Common ..
CHARACTER*32 SRNAMT
* ..
* .. Common blocks ..
COMMON / SRNAMC / SRNAMT
* ..
* .. Data statements ..
DATA ISEEDY / 1988, 1989, 1990, 1991 /
DATA UPLOS / 'U', 'L' /
DATA FORMS / 'N', 'C' /
DATA NORMS / 'M', '1', 'I', 'F' /
* ..
* .. Executable Statements ..
*
* Initialize constants and the random number seed.
*
NRUN = 0
NFAIL = 0
NERRS = 0
INFO = 0
DO 10 I = 1, 4
ISEED( I ) = ISEEDY( I )
10 CONTINUE
*
EPS = DLAMCH( 'Precision' )
SMALL = DLAMCH( 'Safe minimum' )
LARGE = ONE / SMALL
SMALL = SMALL * LDA * LDA
LARGE = LARGE / LDA / LDA
*
DO 130 IIN = 1, NN
*
N = NVAL( IIN )
*
DO 120 IIT = 1, 3
*
* IIT = 1 : random matrix
* IIT = 2 : random matrix scaled near underflow
* IIT = 3 : random matrix scaled near overflow
*
DO J = 1, N
DO I = 1, N
A( I, J) = ZLARND( 4, ISEED )
END DO
END DO
*
IF ( IIT.EQ.2 ) THEN
DO J = 1, N
DO I = 1, N
A( I, J) = A( I, J ) * LARGE
END DO
END DO
END IF
*
IF ( IIT.EQ.3 ) THEN
DO J = 1, N
DO I = 1, N
A( I, J) = A( I, J) * SMALL
END DO
END DO
END IF
*
* Do first for UPLO = 'U', then for UPLO = 'L'
*
DO 110 IUPLO = 1, 2
*
UPLO = UPLOS( IUPLO )
*
* Do first for CFORM = 'N', then for CFORM = 'C'
*
DO 100 IFORM = 1, 2
*
CFORM = FORMS( IFORM )
*
SRNAMT = 'ZTRTTF'
CALL ZTRTTF( CFORM, UPLO, N, A, LDA, ARF, INFO )
*
* Check error code from ZTRTTF
*
IF( INFO.NE.0 ) THEN
IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) THEN
WRITE( NOUT, * )
WRITE( NOUT, FMT = 9999 )
END IF
WRITE( NOUT, FMT = 9998 ) SRNAMT, UPLO, CFORM, N
NERRS = NERRS + 1
GO TO 100
END IF
*
DO 90 INORM = 1, 4
*
* Check all four norms: 'M', '1', 'I', 'F'
*
NORM = NORMS( INORM )
NORMARF = ZLANHF( NORM, CFORM, UPLO, N, ARF, WORK )
NORMA = ZLANHE( NORM, UPLO, N, A, LDA, WORK )
*
RESULT(1) = ( NORMA - NORMARF ) / NORMA / EPS
NRUN = NRUN + 1
*
IF( RESULT(1).GE.THRESH ) THEN
IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) THEN
WRITE( NOUT, * )
WRITE( NOUT, FMT = 9999 )
END IF
WRITE( NOUT, FMT = 9997 ) 'ZLANHF',
+ N, IIT, UPLO, CFORM, NORM, RESULT(1)
NFAIL = NFAIL + 1
END IF
90 CONTINUE
100 CONTINUE
110 CONTINUE
120 CONTINUE
130 CONTINUE
*
* Print a summary of the results.
*
IF ( NFAIL.EQ.0 ) THEN
WRITE( NOUT, FMT = 9996 ) 'ZLANHF', NRUN
ELSE
WRITE( NOUT, FMT = 9995 ) 'ZLANHF', NFAIL, NRUN
END IF
IF ( NERRS.NE.0 ) THEN
WRITE( NOUT, FMT = 9994 ) NERRS, 'ZLANHF'
END IF
*
9999 FORMAT( 1X, ' *** Error(s) or Failure(s) while testing ZLANHF
+ ***')
9998 FORMAT( 1X, ' Error in ',A6,' with UPLO=''',A1,''', FORM=''',
+ A1,''', N=',I5)
9997 FORMAT( 1X, ' Failure in ',A6,' N=',I5,' TYPE=',I5,' UPLO=''',
+ A1, ''', FORM =''',A1,''', NORM=''',A1,''', test=',G12.5)
9996 FORMAT( 1X, 'All tests for ',A6,' auxiliary routine passed the ',
+ 'threshold (',I5,' tests run)')
9995 FORMAT( 1X, A6, ' auxiliary routine:',I5,' out of ',I5,
+ ' tests failed to pass the threshold')
9994 FORMAT( 26X, I5,' error message recorded (',A6,')')
*
RETURN
*
* End of ZDRVRF1
*
END
| bsd-3-clause |
doslab/gcc-designated-initializer-support-cpp | libgomp/testsuite/libgomp.fortran/lib1.f90 | 90 | 2237 | ! { dg-do run }
use omp_lib
double precision :: d, e
logical :: l
integer (kind = omp_lock_kind) :: lck
integer (kind = omp_nest_lock_kind) :: nlck
d = omp_get_wtime ()
call omp_init_lock (lck)
call omp_set_lock (lck)
if (omp_test_lock (lck)) call abort
call omp_unset_lock (lck)
if (.not. omp_test_lock (lck)) call abort
if (omp_test_lock (lck)) call abort
call omp_unset_lock (lck)
call omp_destroy_lock (lck)
call omp_init_nest_lock (nlck)
if (omp_test_nest_lock (nlck) .ne. 1) call abort
call omp_set_nest_lock (nlck)
if (omp_test_nest_lock (nlck) .ne. 3) call abort
call omp_unset_nest_lock (nlck)
call omp_unset_nest_lock (nlck)
if (omp_test_nest_lock (nlck) .ne. 2) call abort
call omp_unset_nest_lock (nlck)
call omp_unset_nest_lock (nlck)
call omp_destroy_nest_lock (nlck)
call omp_set_dynamic (.true.)
if (.not. omp_get_dynamic ()) call abort
call omp_set_dynamic (.false.)
if (omp_get_dynamic ()) call abort
call omp_set_nested (.true.)
if (.not. omp_get_nested ()) call abort
call omp_set_nested (.false.)
if (omp_get_nested ()) call abort
call omp_set_num_threads (5)
if (omp_get_num_threads () .ne. 1) call abort
if (omp_get_max_threads () .ne. 5) call abort
if (omp_get_thread_num () .ne. 0) call abort
call omp_set_num_threads (3)
if (omp_get_num_threads () .ne. 1) call abort
if (omp_get_max_threads () .ne. 3) call abort
if (omp_get_thread_num () .ne. 0) call abort
l = .false.
!$omp parallel reduction (.or.:l)
l = omp_get_num_threads () .ne. 3
l = l .or. (omp_get_thread_num () .lt. 0)
l = l .or. (omp_get_thread_num () .ge. 3)
!$omp master
l = l .or. (omp_get_thread_num () .ne. 0)
!$omp end master
!$omp end parallel
if (l) call abort
if (omp_get_num_procs () .le. 0) call abort
if (omp_in_parallel ()) call abort
!$omp parallel reduction (.or.:l)
l = .not. omp_in_parallel ()
!$omp end parallel
!$omp parallel reduction (.or.:l) if (.true.)
l = .not. omp_in_parallel ()
!$omp end parallel
e = omp_get_wtime ()
if (d .gt. e) call abort
d = omp_get_wtick ()
! Negative precision is definitely wrong,
! bigger than 1s clock resolution is also strange
if (d .le. 0 .or. d .gt. 1.) call abort
end
| gpl-2.0 |
doslab/gcc-designated-initializer-support-cpp | gcc/testsuite/gfortran.fortran-torture/execute/der_type.f90 | 191 | 1101 | ! Program to test derived types
program der_type
implicit none
type t1
integer, dimension (4, 5) :: a
integer :: s
end type
type my_type
character(20) :: c
type (t1), dimension (4, 3) :: ca
type (t1) :: r
end type
type init_type
integer :: i = 13
integer :: j = 14
end type
type (my_type) :: var
type (init_type) :: def_init
type (init_type) :: is_init = init_type (10, 11)
integer i;
if ((def_init%i .ne. 13) .or. (def_init%j .ne. 14)) call abort
if ((is_init%i .ne. 10) .or. (is_init%j .ne. 11)) call abort
! Passing a component as a parameter tests getting the addr of a component
call test_call(def_init%i)
var%c = "Hello World"
if (var%c .ne. "Hello World") call abort
var%r%a(:, :) = 0
var%ca(:, :)%s = 0
var%r%a(1, 1) = 42
var%r%a(4, 5) = 43
var%ca(:, :)%s = var%r%a(:, 1:5:2)
if (var%ca(1, 1)%s .ne. 42) call abort
if (var%ca(4, 3)%s .ne. 43) call abort
contains
subroutine test_call (p)
integer p
if (p .ne. 13) call abort
end subroutine
end program
| gpl-2.0 |
qsnake/abinit | src/42_geometry/symaxes.F90 | 1 | 12753 | !{\src2tex{textfont=tt}}
!!****f* ABINIT/symaxes
!! NAME
!! symaxes
!!
!! FUNCTION
!! Determines the type of symmetry operation, for
!! the proper symmetries 2,2_1,3,3_1,3_2,4,4_1,4_2,4_3,6,6_1,...6_5
!!
!! COPYRIGHT
!! Copyright (C) 2000-2012 ABINIT group (RC, XG)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!! For the initials of contributors, see ~abinit/doc/developers/contributors.txt .
!!
!! INPUTS
!! center=type of bravais lattice centering
!! center=0 no centering
!! center=-1 body-centered
!! center=-3 face-centered
!! center=1 A-face centered
!! center=2 B-face centered
!! center=3 C-face centered
!! iholohedry=type of holohedry
!! iholohedry=1 triclinic 1bar
!! iholohedry=2 monoclinic 2/m
!! iholohedry=3 orthorhombic mmm
!! iholohedry=4 tetragonal 4/mmm
!! iholohedry=5 trigonal 3bar m (rhombohedral Bravais latt)
!! iholohedry=6 hexagonal 6/mmm
!! iholohedry=7 cubic m3bar m
!! isym=number of the symmetry operation that is currently analyzed
!! isymrelconv=symrel matrix for the particular operation, in conv. axes
!! ordersym=order of the symmetry operation
!! tnons_order=order of the screw translation
!! trialt(3)=screw translation associated with the symmetry operation
!! in conventional axes (all components in the range ]-1/2,1/2] )
!!
!! OUTPUT
!! label=a user friendly label for the rotation
!! type_axis=type of the symmetry operation
!!
!! NOTES
!! It is assumed that the symmetry operations will be entered in the
!! symrel tnonsconv arrays, for the CONVENTIONAL cell.
!! For proper symmetries (rotations), the
!! associated translation is determined.
!!
!! There is a subtlety with translations associated with rotations :
!! all the rotations with axis
!! parallel to the one analysed do not all have the
!! same translation characteristics. This is clearly seen
!! in the extended Hermann-Mauguin symbols, see the international
!! table for crystallography, chapter 4.
!! In the treatment that we adopt, one will distinguish
!! the cases of primitive Bravais lattices, and centered
!! bravais lattices. In the latter case, in the present routine,
!! at the exception of the trigonal axis for the
!! cubic system, we explicitely generate the correct ratio of different
!! translations, so that their type can be explicitely assigned,
!! without confusion. By contrast, for primitive lattices,
!! the "tnons" that has been transmitted to the present routine
!! might be one of the few possible translations vectors,
!! nearly at random. We deal with this case by the explicit
!! examination of the system classes, and the identification
!! of such a possibility. In particular:
!! (1) for the trigonal axis in the rhombohedral Bravais lattice,
!! or in the cubic system, there is an equal number of 3, 3_1,
!! and 3_2 axes parallel to each other, in a cell that
!! is primitive (as well as conventional). In this particular case,
!! in the present
!! routine, all 3, 3_1 and 3_2 axes are assigned to be 3 axes,
!! independently of the centering.
!! (2) for the 4- or 6- axes, no confusion is possible :
!! in the primitive cell, there is only one possible translation,
!! while in the centered cells, the correct ratio of translation
!! vectors will be generated
!! (3) for the binary axes, there is no problem when the cell
!! is centered, but there are problems
!! (3a) for the tP Bravais lattice, for an axis in a tertiary direction,
!! (see the description of the lattice symmetry directions
!! table 2.4.1 of the international tables for crystallography),
!! where the family of axes is made equally of 2 and 2_1 axis.
!! In this case, we attribute the binary axis to the specific class
!! of "tertiary 2-axis". We keep track of the 2 or 2_1
!! characteristics of all other binary axes
!! (3b) for the tI Bravais lattice, in all the directions,
!! there is an equal number of 2 and 2_1 axes. We distinguish
!! the primary and secondary family from the tertiary family.
!! (3c) for the hP Bravais lattice, each binary axis can present
!! no translation or be a screw axis (in the same direction).
!! For primary axes, one need the "2" and "2_1" classification,
!! while for secondary and tertiary axes, the associated
!! translation vector will have not importance.
!! However, one will need to distinguish secondary from
!! tertiary, and these from primary axes.
!! So, this is the most complicated case, for binary axes,
!! with the following sets of binary axes : "2", "2_1",
!! "secondary 2" and "tertiary 2".
!! (3d) for the hR Bravais lattice, each binary axis can present
!! no translation or be a screw axis (in the same direction).
!! There is no distinction between tertiary axes and other, so that
!! we simply assign a binary axis to "2-axis"
!! (3e) for the cP lattice, the binary axes along tertiary directions
!! can also have different translation vectors, while for the primary
!! direction, there is no such ambiguity. So, we will attribute
!! tertiary 2 axis to the "tertiary 2-axis" set (there are always 6),
!! and attribute 2 and 2_1 primary axes to the corresponding sets.
!!
!! PARENTS
!! symcharac
!!
!! CHILDREN
!! wrtout
!!
!! SOURCE
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "abi_common.h"
subroutine symaxes(center,iholohedry,&
&isym,isymrelconv,label,ordersym,tnons_order,trialt,type_axis)
use m_profiling
use defs_basis
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'symaxes'
use interfaces_14_hidewrite
!End of the abilint section
implicit none
!Arguments ------------------------------------
!scalars
integer,intent(in) :: center,iholohedry,isym,ordersym,tnons_order
integer,intent(out) :: type_axis
character(len = 128), intent(out) :: label
!arrays
integer,intent(in) :: isymrelconv(3,3)
real(dp),intent(in) :: trialt(3)
!Local variables-------------------------------
!scalars
character(len=500) :: message
integer :: direction,directiontype
real(dp),parameter :: nzero=1.0d-6
!**************************************************************************
!DEBUG
!write(std_out,*)' symaxes : enter, isym=',isym
!write(std_out,*)' symaxes : iholohedry, ',iholohedry
!write(std_out,*)' symaxes : center, ',center
!stop
!ENDDEBUG
select case(ordersym)
case(2) ! point symmetry 2
! Must characterize directiontype for cP, tP, tI, and hP Bravais lattices
directiontype=1
if( iholohedry==4 .or. iholohedry==7) then ! tP or cP Bravais lattices
if(abs(isymrelconv(1,1))+ &
& abs(isymrelconv(2,2))+ &
& abs(isymrelconv(3,3)) ==1) directiontype=3
else if(iholohedry==6)then ! hP Bravais lattice
if(sum(isymrelconv(:,:))/=-1 )directiontype=2
if(sum(isymrelconv(:,:))==0 .or. sum(isymrelconv(:,:))==-3 )&
& directiontype=3
! directiontype=1 corresponds to a primary axis
! directiontype=2 corresponds to a tertiary axis
! directiontype=3 corresponds to a secondary axis
end if
! DEBUG
! write(std_out,*)' directiontype=',directiontype
! write(std_out,'(a,3i6)' )' isymrelconv(1:3)=',isymrelconv(:,1)
! write(std_out,'(a,3i6)' )' isymrelconv(4:6)=',isymrelconv(:,2)
! write(std_out,'(a,3i6)' )' isymrelconv(7:9)=',isymrelconv(:,3)
! write(std_out,'(a,i)' )' tnons_order=',tnons_order
! ENDDEBUG
! Now, classify the 2 axes
if(directiontype==2)then
type_axis=4 ! secondary 2 (only in the hP Bravais latt case)
write(label,'(a)') 'a secondary 2-axis '
else if(directiontype==3 .and. iholohedry==4)then
type_axis=21 ! tertiary 2
write(label,'(a)') 'a tertiary 2-axis '
else if(directiontype==3 .and. &
& center==0 .and. (iholohedry==6.or.iholohedry==7) )then
type_axis=21 ! tertiary 2
write(label,'(a)') 'a tertiary 2-axis '
else if(tnons_order==1 .or. (iholohedry==4 .and. center==-1) .or. &
& iholohedry==5)then
type_axis=9 ! 2
write(label,'(a)') 'a 2-axis '
else
type_axis=20 ! 2_1
write(label,'(a)') 'a 2_1-axis '
end if
case(3) ! point symmetry 3
if(tnons_order==1)then
type_axis=10 ! 3
write(label,'(a)') 'a 3-axis '
else if(iholohedry==5 .or. iholohedry==7)then
! This is a special situation : in the same family of parallel 3-axis,
! one will have an equal number of 3, 3_1 and 3_2 axes, so that
! it is non-sense to try to classify one of them.
type_axis=10 ! 3, 3_1 or 3_2, undistinguishable
write(label,'(a)') 'a 3, 3_1 or 3_2 axis '
else
! DEBUG
! write(std_out,*)'isymrelconv=',isymrelconv(:,:)
! write(std_out,*)'trialt=',trialt(:)
! ENDDEBUG
! Must recognize 3_1 or 3_2
if(isymrelconv(1,1)==0)then ! 3+
if(abs(trialt(3)-third)<nzero)type_axis=22 ! 3_1
if(abs(trialt(3)+third)<nzero)type_axis=23 ! 3_2
else if(isymrelconv(1,1)==-1)then ! 3-
if(abs(trialt(3)-third)<nzero)type_axis=23 ! 3_2
if(abs(trialt(3)+third)<nzero)type_axis=22 ! 3_1
end if
write(label,'(a)') 'a 3_1 or 3_2-axis '
end if
case(4) ! point symmetry 4
if(tnons_order==1)then
type_axis=12 ! 4
write(label,'(a)') 'a 4-axis '
else if(tnons_order==2)then
type_axis=25 ! 4_2
write(label,'(a)') 'a 4_2-axis '
else if(center/=0)then
type_axis=24 ! 4_1 or 4_3
write(label,'(a)') 'a 4_1 or 4_3-axis '
else
! DEBUG
! write(std_out,*)'isymrelconv=',isymrelconv(:,:)
! write(std_out,*)'trialt=',trialt(:)
! ENDDEBUG
! Must recognize 4_1 or 4_3, along the three primary directions
do direction=1,3
if(isymrelconv(direction,direction)==1)then !
if( (direction==1 .and. isymrelconv(2,3)==-1) .or. &
& (direction==2 .and. isymrelconv(3,1)==-1) .or. &
& (direction==3 .and. isymrelconv(1,2)==-1) )then ! 4+
if(abs(trialt(direction)-quarter)<nzero)type_axis=24 ! 4_1
if(abs(trialt(direction)+quarter)<nzero)type_axis=26 ! 4_3
else if( (direction==1 .and. isymrelconv(2,3)==1) .or. &
& (direction==2 .and. isymrelconv(3,1)==1) .or. &
& (direction==3 .and. isymrelconv(1,2)==1) )then ! 4-
if(abs(trialt(direction)-quarter)<nzero)type_axis=26 ! 4_3
if(abs(trialt(direction)+quarter)<nzero)type_axis=24 ! 4_1
end if
end if
end do
write(label,'(a)') 'a 4_1 or 4_3-axis '
end if
case(6) ! point symmetry 6
if(tnons_order==1)then
type_axis=14 ! 6
write(label,'(a)') 'a 6-axis '
else if(tnons_order==2)then
type_axis=29 ! 6_3
write(label,'(a)') 'a 6_3-axis '
else if(tnons_order==3)then
! DEBUG
! write(std_out,*)'isymrelconv=',isymrelconv(:,:)
! write(std_out,*)'trialt=',trialt(:)
! ENDDEBUG
! Must recognize 6_2 or 6_4
if(isymrelconv(1,1)==1)then ! 6+
if(abs(trialt(3)-third)<nzero)type_axis=28 ! 6_2
if(abs(trialt(3)+third)<nzero)type_axis=30 ! 6_4
else if(isymrelconv(1,1)==0)then ! 6-
if(abs(trialt(3)-third)<nzero)type_axis=30 ! 6_4
if(abs(trialt(3)+third)<nzero)type_axis=28 ! 6_2
end if
write(label,'(a)') 'a 6_2 or 6_4-axis '
else
! DEBUG
! write(std_out,*)'isymrelconv=',isymrelconv(:,:)
! write(std_out,*)'trialt=',trialt(:)
! ENDDEBUG
! Must recognize 6_1 or 6_5
if(isymrelconv(1,1)==1)then ! 6+
if(abs(trialt(3)-sixth)<nzero)type_axis=27 ! 6_1
if(abs(trialt(3)+sixth)<nzero)type_axis=31 ! 6_5
else if(isymrelconv(1,1)==0)then ! 6-
if(abs(trialt(3)-sixth)<nzero)type_axis=31 ! 6_5
if(abs(trialt(3)+sixth)<nzero)type_axis=27 ! 6_1
end if
write(label,'(a)') 'a 6_1 or 6_5-axis '
end if
end select
write(message,'(a,i3,a,a)') &
& ' symaxes : the symmetry operation no. ',isym,' is ', trim(label)
call wrtout(std_out,message,'COLL')
!DEBUG
!write(std_out,*)' symaxes : exit'
!stop
!ENDDEBUG
end subroutine symaxes
!!***
| gpl-3.0 |
haudren/scipy | scipy/sparse/linalg/eigen/arpack/ARPACK/SRC/dstats.f | 170 | 1166 | c
c\SCCS Information: @(#)
c FILE: stats.F SID: 2.1 DATE OF SID: 4/19/96 RELEASE: 2
c %---------------------------------------------%
c | Initialize statistic and timing information |
c | for symmetric Arnoldi code. |
c %---------------------------------------------%
subroutine dstats
c %--------------------------------%
c | See stat.doc for documentation |
c %--------------------------------%
include 'stat.h'
c %-----------------------%
c | Executable Statements |
c %-----------------------%
nopx = 0
nbx = 0
nrorth = 0
nitref = 0
nrstrt = 0
tsaupd = 0.0D+0
tsaup2 = 0.0D+0
tsaitr = 0.0D+0
tseigt = 0.0D+0
tsgets = 0.0D+0
tsapps = 0.0D+0
tsconv = 0.0D+0
titref = 0.0D+0
tgetv0 = 0.0D+0
trvec = 0.0D+0
c %----------------------------------------------------%
c | User time including reverse communication overhead |
c %----------------------------------------------------%
tmvopx = 0.0D+0
tmvbx = 0.0D+0
return
c
c End of dstats
c
end
| bsd-3-clause |
qsnake/abinit | src/65_psp/smoothvlocal.F90 | 1 | 16461 | !{\src2tex{textfont=tt}}
!!****f* ABINIT/smoothvlocal
!! NAME
!! smoothvlocal
!!
!! FUNCTION
!! Constructs the local pseudopotential used by SIESTA. Different from
!! the individual v_l components, it must be as smooth as possible in
!! order to be well represented on a 3D real space grid in SIESTA.
!!
!! COPYRIGHT
!! Copyright (C) 2005-2012 ABINIT group (JJ)
!!
!! INPUTS
!! (to be completed)
!!
!! OUTPUT
!! (to be completed)
!!
!! PARENTS
!! psp9in
!!
!! CHILDREN
!!
!! SOURCE
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "abi_common.h"
subroutine smoothvlocal( lmax, npts, scale, step, vlocal, vps, zval)
use m_profiling
use defs_basis
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'smoothvlocal'
use interfaces_65_psp, except_this_one => smoothvlocal
!End of the abilint section
implicit none
!Arguments --------------------------------
integer, intent(in) :: npts, lmax
real(dp), intent(in) :: zval, scale, step, vps(npts,0:lmax)
real(dp), intent(out) :: vlocal(npts)
!Local variables --------------------------
real(dp) :: rpb, ea, rgauss, rgauss2
real(dp), allocatable :: rofi(:), drdi(:), s(:), chlocal(:)
integer :: ir, nrgauss, nchloc
! *************************************************************************
!Allocate radial functions -----
ABI_ALLOCATE( rofi,(npts))
ABI_ALLOCATE( drdi,(npts))
ABI_ALLOCATE( s,(npts))
ABI_ALLOCATE( chlocal,(npts))
rpb = scale
ea = exp(step)
do ir = 1, npts
rofi(ir) = scale * ( exp( step*(ir-1) ) - 1 )
drdi(ir) = step * rpb
s(ir) = sqrt( step*rpb )
rpb = rpb * ea
! write(std_out,'(i5,3f20.12)')ir, rofi(ir), drdi(ir), s(ir)
end do
call radii_ps( vps, rofi, zval, npts, lmax, nrgauss, rgauss, rgauss2)
!Calculate local pseudopotential
if ( rgauss2 .gt. 1.30d0 * rgauss ) then
! In this case the atom core is so big that we do not have an asymptotic
! of 2*Zval/r until Rgauss2 > Rc . To retain the same asymptotic
! behaviour as in the pseudopotentials we modified the definition
! of the local potential
!
call vlocal2( zval, npts, step, rofi, drdi, s, vps(:,0), &
& nrgauss, vlocal, nchloc, chlocal )
else
!
! In this case the pseudopotential reach to an asymptotic
! behaviour 2*Zval/r for a radius approximately equal to Rc.
!
call vlocal1( zval, npts, step, rofi, drdi, s, rgauss, vlocal, &
& nchloc, chlocal )
end if
ABI_DEALLOCATE( rofi)
ABI_DEALLOCATE( drdi)
ABI_DEALLOCATE( s)
ABI_DEALLOCATE( chlocal)
end subroutine smoothvlocal
!!***
!!****f* ABINIT/vlocal2
!! NAME
!! vlocal2
!!
!! FUNCTION
!! This routine generates the local pseudopotential appropriate
!! for species with a large core.
!!
!! NOTES
!! Written by D. Sanchez-Portal, Aug. 1998
!!
!! INPUTS
!!
!! OUTPUT
!!
!! PARENTS
!! smoothvlocal
!!
!! CHILDREN
!!
!! SOURCE
subroutine vlocal2( zval, nrval, a, rofi, drdi, s, vps, nrgauss, &
& vlocal,nchloc,chlocal )
use m_profiling
use defs_basis
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'vlocal2'
!End of the abilint section
implicit none
!Arguments -------------------------------
real(dp), intent(in) :: zval, a
integer, intent(in) :: nrval
integer, intent(inout) :: nrgauss
real(dp), intent(in) :: rofi(:), drdi(:), s(:), vps(:)
real(dp), intent(out) :: vlocal(:), chlocal(:)
integer, intent(out) :: nchloc
!Local variables -------------------------
real(dp) :: vlc, r, dev, dev2, dev3, var1, var2, var3, v1, v2, v3, v4, &
& dm11, dm12, dm13, dm21, dm22, dm23, dm31, dm32, dm33, &
& g0, g1, g2, g3, g4, d2g, d2u, cons, a2b4, qtot
integer :: ndevfit, ir
real(dp), parameter :: eps=1.0d-5
! *********************************************************************
!Continuity up to second derivative***
ndevfit=2
!Continuity up to third derivative****
!ndevfit=3
nrgauss = nrgauss + 3 !! For good measure...
do ir = 1, nrval
vlocal(ir) = vps(ir) * rofi(ir)
end do
ir = nrgauss
dev = ( vlocal(ir+1) - vlocal(ir-1) ) * 0.5d0
dev2 = ( vlocal(ir+1) + vlocal(ir-1) - 2.0d0 * vlocal(ir) )
dev3 = ( vlocal(ir+2) - 2.0d0 * vlocal(ir+1) &
& + 2.0d0 * vlocal(ir-1) - vlocal(ir-2) ) * 0.5d0
dev3 = ( dev3 - 3.0d0 * a * dev2 + 2.0d0 * (a**2) * dev ) / ( drdi(ir)**3 )
dev2 = ( dev2 - a * dev ) / ( drdi(ir)**2 )
dev = dev / drdi(ir)
!Local potential is Vloc(r)=v3*exp(v1*r^2+v2*r^3)
!inside Rgauss and equals the
!all-electron atomic potential outside Rgauss
!We impose the continuity up to second derivative
if( ndevfit .eq. 2 ) then
vlc = vlocal(nrgauss)
r = rofi(nrgauss)
var1 = dev / vlc - 1.0d0 / r
var2 = dev2 / vlc - 2.0d0 * var1 / r - ( var1**2 )
dm11 = 2.0d0 * r
dm12 = 3.0d0 * r * r
dm21 = 2.0d0
dm22 = 6.0d0 * r
v1 = ( dm22 * var1 - dm12 * var2 ) /( 6.0d0 * r * r )
v2 = ( dm11 * var2 - dm21 * var1 ) /( 6.0d0 * r * r )
v3 = vlc / ( r * exp( ( v1 + v2*r ) * r * r ) )
! elseif(ndevfit.eq.3) then
else
! We can also construct a local potential
! Vloc(r)=v4*exp(v1*r^2+v2*r^3+v3*r^4),
! this new coefficient allows us to impose the continuity
! of the potential up to the third derivative.
vlc = vlocal( nrgauss )
r = rofi( nrgauss )
var1 = dev / vlc - 1.d0 / r
var2 = dev2 / vlc - 2.0d0 * var1 / r - ( var1**2 )
var3 = dev3 / vlc - 3.0d0 * var1 * var2 - ( var1**3 ) &
& - 3.0d0 *( var1**2 + var2 ) / r
dm11 = 2.0d0 * r
dm12 = 3.0d0 * r * r
dm13 = 4.0d0 * r * r * r
dm21 = 2.0d0
dm22 = 6.0d0 * r
dm23 = 12.0d0 * r * r
dm31 = 0.0d0
dm32 = 6.0d0
dm33 = 24.0d0 * r
v1 = ( ( var1 * dm22 * dm33 + var2 * dm13 * dm32 + var3 * dm12 * dm23 ) &
& -(var3*dm22*dm13+var1*dm32*dm23+var2*dm12*dm33))/(48.0_dp*r*r*r)
v2 = ( ( var2 * dm11 * dm33 + var3 * dm21 * dm13 + var1 * dm23 * dm31 ) &
& -(var2*dm31*dm13+var3*dm23*dm11+var1*dm21*dm33))/(48.0_dp*r*r*r)
v3 = ( ( var3 * dm11 * dm22 + var2 * dm12 * dm31 + var1 * dm32 * dm21 ) &
& -(var1*dm22*dm31+var3*dm21*dm12+var2*dm11*dm32))/(48.0_dp*r*r*r)
v4 = vlc / ( r * exp( ( v1 + v2 * r + v3 * r * r ) * r * r ) )
end if
do ir = 1, nrval
r = rofi(ir)
if( ir .le. nrgauss ) then
! ** If second derivative fit***
if( ndevfit .eq. 2 ) then
vlocal(ir) = v3 * exp( ( v1 + v2*r ) * r * r )
! ** If third derivative fit****
else if(ndevfit.eq.3) then
vlocal(ir) = v4 * exp ( ( v1 + v2 * r + v3 * r * r ) * r * r )
! ****
end if
else
vlocal(ir) = vps(ir)
end if
end do
!Once we have the local potential we define the 'local-pseudopotential
!charge' which help us to calculate the electrostatic interation
!between the ions
!
!Poisson's eq.:
!
!1/r* d2(rV)/dr2 = -8*pi*rho
!
a2b4 = 0.25d0 * a * a
qtot = 0.d0
do ir = 1, nrval-1
g2 = vlocal(ir) * rofi(ir)
!
! To determine the chlocal cutoff, use the reduced_vlocal cutoff
!
if( abs ( g2 + 2.0d0 * zval ) .lt. eps ) exit !exit loop
if( ir .gt. nrgauss ) then
if( ( ir .gt. 2 ) .and. ( ir .lt. (nrval-1) ) ) then
g0 = vlocal(ir-2) * rofi(ir-2) / s(ir-2)
g1 = vlocal(ir-1) * rofi(ir-1) / s(ir-1)
g2 = vlocal(ir) * rofi(ir) / s(ir)
g3 = vlocal(ir+1) * rofi(ir+1) / s(ir+1)
g4 = vlocal(ir+2) * rofi(ir+2) / s(ir+2)
d2g = ( 16.d0 * ( g1 + g3 ) - ( g0 + g4 ) -30.d0 * g2 ) / 12.d0
else
g1 = vlocal(ir-1) * rofi(ir-1) / s(ir-1)
g2 = vlocal(ir) * rofi(ir) / s(ir)
g3 = vlocal(ir+1) * rofi(ir+1) / s(ir+1)
d2g = g1 + g3 - 2.0d0 * g2
end if
d2u = d2g - a2b4 * g2
r = rofi(ir)
cons = 8.0d0 * pi * r * drdi(ir) * s(ir)
chlocal(ir) = (-d2u) / cons
qtot = qtot + 0.5d0 * d2u * r / s(ir)
else
! If second derivative fit
if( ndevfit .eq. 2 ) then
r = rofi(ir)
g0 = v3 * exp( ( v1 + v2 * r ) * r **2 )
g1 = ( 2.d0 * v1 + 3.0d0 * v2 * r )
g2 = 2.d0 * v1 + 6.0d0 * v2 * r
g3 = ( g2 + g1 * g1 * r * r + 2.0d0 * g1 ) * g0
cons = 8.0d0 * pi
chlocal(ir) = (-g3) / cons
qtot = qtot + 0.5d0 * g3 * r * r * drdi(ir)
! **** If third derivative fit
else if ( ndevfit .eq. 3 ) then
r = rofi(ir)
g0 = v4 * exp( ( v1 + v2 * r + v3 * r * r ) * r * r )
g1 = ( 2.0d0 * v1 + 3.0d0 * v2 * r + 4.0d0 * v3 * r * r )
g2 = ( 2.0d0 * v1 + 6.0d0 * v2 * r + 12.0d0 * v3 * r * r )
g3 = ( g2 + g1 * g1 * r * r + 2.0d0 * g1 ) * g0
cons = 8.0d0 * pi
chlocal(ir) = -g3 / cons
qtot = qtot + 0.5d0 * g3 * r * r * drdi(ir)
end if
end if
end do
!
!This sets the cutoff point for chlocal in a rather
!arbitrary way, as that in which Vlocal "equals" 2Z/r
!
nchloc = ir
do ir = 1, nchloc-1
chlocal(ir) = zval * chlocal(ir) / qtot
end do
do ir = nchloc, nrval
chlocal(ir) = 0.0_dp
end do
end subroutine vlocal2
!!***
!!****f* ABINIT/vlocal1
!! NAME
!! vlocal1
!!
!! FUNCTION
!! This routine generates a smooth local pseudopotential.
!!
!! NOTES
!! Written by D. Sanchez-Portal, Aug. 1998
!!
!! INPUTS
!!
!! OUTPUT
!!
!! PARENTS
!! smoothvlocal
!!
!! CHILDREN
!!
!! SOURCE
subroutine vlocal1( zval, nrval, a, rofi, drdi, s, rgauss, vlocal, &
& nchloc, chlocal)
use m_profiling
use defs_basis
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'vlocal1'
use interfaces_65_psp, except_this_one => vlocal1
!End of the abilint section
implicit none
real(dp), intent(in) :: zval, a
integer, intent(in) :: nrval
real(dp), intent(in) :: rofi(:), drdi(:), s(:)
real(dp), intent(out) :: vlocal(:)
real(dp), intent(out) :: chlocal(:)
integer, intent(out) :: nchloc
real(dp), intent(inout) :: rgauss !!???
! *Internal variables*
real(dp) :: van, factor, alp, cutoff1, cutoff2, &
& qtot, eps, chc, r, Rchloc, rhor1, rhor
integer :: ir
character loctype*3
parameter(eps = 1.0d-4)
! *************************************************************************
!** Usual local potential
!(generated with an optimum Vandebilt function)**
loctype = 'new'
!*** The very first local potential used by SIESTA was
!the electrostatic potential generated by a gaussian
!distribution ===> loctype='old'
!loctype='old'
!***
!Local-potential size parameter 'rgauss'
!We choose as a smooth pseudopotential the one generated
!by a 'Vanderbilt-function' charge distribution. We have to select
!the size of this distribution somehow.
!'Vanderbilt-functions' are of the form :
!p(r)=N*exp(-(sinh(van*r)/sinh(van))**2)
!when van---> 0 we will obtain a 'gaussian'
!when van---> Inf. we will obtain a step function
!Some test has revealed that the best election to achieve
!a good convergence in real and reciprocal space is b in the
!range 0.5-1.0 .
!*
!So, the 'gaussian' charge distribution
!must go to zero at a distance 'rgauss'.
if( loctype .eq. 'new' ) then
! We take a 'Vanderbilt-function' as local potential
! van=1.0_dp all the parameter have optimized for this value
van = 1.0d0
cutoff1 = 3.63d0
cutoff2 = 5.48d0
! ** 99% of charge inside Rgauss**
! factor=1.627_dp
! ** 99.9% of charge inside Rgauss
factor = 1.815d0
! * Scaling factor for local-pseudopot. charge**
alp = factor / rgauss
! write(std_out,'(/,a,f10.3,a)') &
! & 'VLOCAL1: 99.0% of the norm of Vloc inside ', &
! & (alp*cutoff1)**2,' Ry'
! write(std_out,'(a,f10.3,a)') &
! & 'VLOCAL1: 99.9% of the norm of Vloc inside ', &
! & (alp*cutoff2)**2,' Ry'
else
! This is just a gaussian !!!!!!!!!!!!!!!!!
van = 0.00001d0
rgauss = 0.80d0
factor = 2.0d0
! * Scaling factor for local-pseudopot. charge**
alp = factor / rgauss
end if
qtot = 0.0d0
rhor1 = vander( van, alp * rofi(1) ) ! This is 1...
do ir = 1, nrval
r = rofi(ir)
rhor = vander( van, alp * r)
chlocal(ir) = (-4.0d0) * pi * rhor * r * r
qtot = qtot + rhor * drdi(ir) * r * r
end do
qtot = 4.0d0 * pi * qtot
nchloc = 0
do ir = nrval, 1, -1
chc = zval * chlocal(ir) / qtot
chlocal(ir) = chc
if( ( abs(chc) .gt. eps ) .and. ( nchloc .eq. 0 ) ) then
nchloc = ir + 1
end if
end do
Rchloc = rofi(nchloc)
!
!Note that the above cutoff is for 4*pi*r*r*rho_local(r)...
!
call vhrtre( chlocal, vlocal, rofi, drdi, s, nrval, a )
do ir = 2, nrval
r = rofi(ir)
chlocal(ir) = chlocal(ir) / ( 4.0d0 * pi * r * r )
!
! Poor man's cutoff!! Largely irrelevant?
!
if ( r .gt. 1.1d0 * Rchloc ) then
vlocal(ir) = (-2.0d0) * zval / rofi(ir)
end if
end do
chlocal(1) = -rhor1 * zval / qtot
end subroutine vlocal1
!!***
!!****f* ABINIT/vhrtre
!! NAME
!! vhrtre
!!
!! FUNCTION
!! Finds the Hartree potential created by a radial electron density,
!! using Numerov's method to integrate the radial Poisson equation:
!! d2(r*V)/dr2 = -4*pi*rho*r = -(4*pi*r2*rho)/r
!!
!! NOTES
!! Imported from SIESTA package
!!
!! INPUTS
!!
!! OUTPUT
!!
!! PARENTS
!! smoothvlocal
!!
!! CHILDREN
!!
!! SOURCE
subroutine vhrtre(R2RHO,V,R,DRDI,SRDRDI,NR,A)
use m_profiling
!***********************************************************************
!Finds the Hartree potential created by a radial electron density,
!using Numerov's method to integrate the radial Poisson equation:
!d2(r*V)/dr2 = -4*pi*rho*r = -(4*pi*r2*rho)/r
!Input:
!real*8 R2RHO(NR) : 4*pi*r**2*rho, with rho the electron density
!real*8 R(NR) : Logarithmic radial mesh R(i)=B*(exp(A*(i-1)-1)
!real*8 DRDI(NR) : dr/di at the mesh points
!real*8 SRDRDI(NR): sqrt(dr/di) at the mesh points
!integer NR : Number of radial mesh points, including r(1)=0
!real*8 A : The parameter A in r(i)=B*(exp(A*(i-1)-1)
!Output:
!real*8 V(NR) : Electrostatic potential created by rho, in Ryd
!The constants of integration are fixed so that
!V=finite at the origin and V(NR)=Q/R(NR),
!where Q is the integral of rho up to R(NR)
!Algorithm: see routine NUMOUT
!***********************************************************************
use defs_basis
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'vhrtre'
!End of the abilint section
implicit none
INTEGER :: NR
REAL(dp) :: R2RHO(NR),V(NR),R(NR),DRDI(NR),SRDRDI(NR),A
INTEGER :: IR
REAL(dp) :: A2BY4, BETA, DV, DY, DZ, Q, QBYY, QPARTC, QT, &
& T, V0, Y, YBYQ
!Find some constants
A2BY4 = A * A / 4.D0
YBYQ = 1.D0 - A * A / 48.D0
QBYY = 1.D0 / YBYQ
!Use Simpson's rule to find the total charge QT, and the
!potential at the origin V0:
!QT = Int(4*pi*r**2*rho*dr) = Int((4*pi*r**2*rho)*(dr/di)*di)
!V0 = Int(4*pi*r*rho*dr) = Int((4*pi*r**2*rho)/r*(dr/di)*di)
V0 = 0.D0
QT = 0.D0
do IR = 2, NR-1, 2
DZ = DRDI(IR) * R2RHO(IR)
QT = QT + DZ
V0 = V0 + DZ / R(IR)
end do
V0 = V0 + V0
QT = QT + QT
do IR = 3, NR-2, 2
DZ = DRDI(IR) * R2RHO(IR)
QT = QT + DZ
V0 = V0 + DZ / R(IR)
end do
DZ =DRDI(NR) * R2RHO(NR)
QT =( QT + QT + DZ ) / 3.D0
V0 =( V0 + V0 + DZ / R(NR) ) / 3.D0
!Fix V(1) and V(2) to start Numerov integration. To find a
!particular solution of the inhomog. eqn, V(2) is fixed by
!setting rV(2)=0. Notice that V=finite => rV=0 at r=0
V(1)=2.D0*V0 ! Factor 2 because we use Rydbergs
T = SRDRDI(2) / R(2)
BETA = DRDI(2) * T * R2RHO(2)
DY = 0.D0
Y = 0.D0
Q = ( Y - BETA / 12.D0 ) * QBYY
V(2) = 2.D0 * T * Q
!Integrate Poisson's equation outwards, using Numerov's method
do IR = 3,NR
DY = DY + A2BY4 * Q - BETA
Y = Y + DY
T = SRDRDI(IR) / R(IR)
BETA = T * DRDI(IR) * R2RHO(IR)
Q = ( Y - BETA / 12.D0 ) * QBYY
V(IR) = 2.D0 * T * Q
end do
!Add a solution (finite at r=0) of the homogeneous equation
!d2(r*V)/dr2=0 => rV=const*r => V=const, to ensure that
!V(NR)=Q/R(NR). Notice that V(1) is set independently
QPARTC = R(NR) * V(NR) / 2.D0
DZ = QT - QPARTC
DV = 2.D0 * DZ / R(NR)
do IR = 2, NR
V(IR) = V(IR) + DV
end do
end subroutine vhrtre
!!***
| gpl-3.0 |
SamKChang/abinit-7.10.5_multipole | src/01_macroavnew_ext/numeric.F90 | 2 | 7338 | #if defined HAVE_CONFIG_H
#include "config.h"
#endif
SUBROUTINE FOUR1(DATA,NN,ISIGN)
!**********************************************************************
! Discrete Fourier transform.
!**********************************************************************
! Input:
! real*8 DATA(2*NN) : Function to be Fourier transformed
! integer NN : Number of points. Must be a power of 2
! integer ISIGN : ISIG=+1/-1 => Direct/inverse transform
! Output:
! real*8 DATA(2*NN) : Fourier transformed function
!**********************************************************************
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'FOUR1'
!End of the abilint section
IMPLICIT NONE
INTEGER :: NN, ISIGN
real(kind=kind(0.0d0)) :: DATA(2*NN)
INTEGER :: I, ISTEP, J, M, MMAX, N
real(kind=kind(0.0d0)) :: TEMPI, TEMPR, THETA, WI, WPI, WPR, WR, WTEMP
DOUBLE PRECISION, PARAMETER :: TWOPI=6.28318530717959D0,&
& HALF=0.5D0, ONE=1.D0, TWO=2.D0, ZERO=0.D0
N=2*NN
J=1
DO I=1,N,2
IF(J>I)THEN
TEMPR=DATA(J)
TEMPI=DATA(J+1)
DATA(J)=DATA(I)
DATA(J+1)=DATA(I+1)
DATA(I)=TEMPR
DATA(I+1)=TEMPI
ENDIF
M=N/2
DO ! until following condition is met
IF ((M<2).OR.(J<=M)) EXIT
J=J-M
M=M/2
END DO
J=J+M
END DO ! I
MMAX=2
DO ! until following condition is met
IF (N<=MMAX) EXIT
ISTEP=2*MMAX
THETA=TWOPI/(ISIGN*MMAX)
WPR=(-TWO)*SIN(HALF*THETA)**2
WPI=SIN(THETA)
WR=ONE
WI=ZERO
DO M=1,MMAX,2
DO I=M,N,ISTEP
J=I+MMAX
TEMPR=WR*DATA(J)-WI*DATA(J+1)
TEMPI=WR*DATA(J+1)+WI*DATA(J)
DATA(J)=DATA(I)-TEMPR
DATA(J+1)=DATA(I+1)-TEMPI
DATA(I)=DATA(I)+TEMPR
DATA(I+1)=DATA(I+1)+TEMPI
END DO ! I
WTEMP=WR
WR=WR*WPR-WI*WPI+WR
WI=WI*WPR+WTEMP*WPI+WI
END DO ! M
MMAX=ISTEP
END DO ! until (N<=MMAX)
END SUBROUTINE FOUR1
SUBROUTINE POLINT(XA,YA,N,X,Y,DY)
!*****************************************************************
! Polinomic interpolation.
! D. Sanchez-Portal, Oct. 1996
!*****************************************************************
! Input:
! real*8 XA(N) : x values of the function y(x) to interpolate
! real*8 YA(N) : y values of the function y(x) to interpolate
! integer N : Number of data points
! real*8 X : x value at which the interpolation is desired
! Output:
! real*8 Y : interpolated value of y(x) at X
! real*8 DY : accuracy estimate
!*****************************************************************
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'POLINT'
!End of the abilint section
IMPLICIT NONE
INTEGER :: N
real(kind=kind(0.0d0)) :: XA(N),YA(N), X, Y, DY
INTEGER :: I, M, NS
real(kind=kind(0.0d0)) :: C(N), D(N), DEN, DIF, DIFT, HO, HP, W
DOUBLE PRECISION, PARAMETER :: ZERO=0.D0
NS=1
DIF=ABS(X-XA(1))
DO I=1,N
DIFT=ABS(X-XA(I))
IF (DIFT<DIF) THEN
NS=I
DIF=DIFT
ENDIF
C(I)=YA(I)
D(I)=YA(I)
END DO ! I
Y=YA(NS)
NS=NS-1
DO M=1,N-1
DO I=1,N-M
HO=XA(I)-X
HP=XA(I+M)-X
W=C(I+1)-D(I)
DEN=HO-HP
IF (DEN==ZERO) STOP 'polint: ERROR. Two XAs are equal'
DEN=W/DEN
D(I)=HP*DEN
C(I)=HO*DEN
END DO ! I
IF (2*NS<N-M) THEN
DY=C(NS+1)
ELSE
DY=D(NS)
NS=NS-1
ENDIF
Y=Y+DY
END DO ! M
END SUBROUTINE POLINT
SUBROUTINE MACROAV_SPLINE(DX,Y,N,YP1,YPN,Y2)
!***********************************************************
! Cubic Spline Interpolation.
! D. Sanchez-Portal, Oct. 1996.
! Input:
! real*8 DX : x interval between data points
! real*8 Y(N) : value of y(x) at data points
! integer N : number of data points
! real*8 YP1 : value of dy/dx at X1 (first point)
! real*8 YPN : value of dy/dx at XN (last point)
! Output:
! real*8 Y2(N): array to be used by routine MACROAV_SPLINT
! Behavior:
! - If YP1 or YPN are larger than 1E30, the natural spline
! condition (d2y/dx2=0) at the corresponding edge point.
!************************************************************
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'MACROAV_SPLINE'
!End of the abilint section
IMPLICIT NONE
INTEGER :: N
real(kind=kind(0.0d0)) :: DX, Y(N), YP1, YPN, Y2(N)
INTEGER :: I, K
real(kind=kind(0.0d0)) :: QN, P, SIG, U(N), UN
DOUBLE PRECISION, PARAMETER :: YPMAX=0.99D30, &
& HALF=0.5D0, ONE=1.D0, THREE=3.D0, TWO=2.D0, ZERO=0.D0
IF (YP1>YPMAX) THEN
Y2(1)=ZERO
U(1)=ZERO
ELSE
Y2(1)=-HALF
U(1)=(THREE/DX)*((Y(2)-Y(1))/DX-YP1)
ENDIF
DO I=2,N-1
SIG=HALF
P=SIG*Y2(I-1)+TWO
Y2(I)=(SIG-ONE)/P
U(I)=(THREE*( Y(I+1)+Y(I-1)-TWO*Y(I) )/(DX*DX)&
& -SIG*U(I-1))/P
END DO ! I
IF (YPN>YPMAX) THEN
QN=ZERO
UN=ZERO
ELSE
QN=HALF
UN=(THREE/DX)*(YPN-(Y(N)-Y(N-1))/DX)
ENDIF
Y2(N)=(UN-QN*U(N-1))/(QN*Y2(N-1)+ONE)
DO K=N-1,1,-1
Y2(K)=Y2(K)*Y2(K+1)+U(K)
END DO ! K
END SUBROUTINE MACROAV_SPLINE
SUBROUTINE MACROAV_SPLINT(DX,YA,Y2A,N,X,Y,DYDX)
!***************************************************************
! Cubic Spline Interpolation.
! D. Sanchez-Portal, Oct. 1996.
! Input:
! real*8 DX : x interval between data points
! real*8 YA(N) : value of y(x) at data points
! real*8 Y2A(N): array returned by routine MACROAV_SPLINE
! integer N : number of data points
! real*8 X : point at which interpolation is desired
! real*8 Y : interpolated value of y(x) at point X
! real*8 DYDX : interpolated value of dy/dx at point X
!***************************************************************
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'MACROAV_SPLINT'
!End of the abilint section
IMPLICIT NONE
INTEGER :: N
real(kind=kind(0.0d0)) :: DX, YA(N), Y2A(N), X, Y, DYDX
INTEGER :: NHI, NLO
real(kind=kind(0.0d0)) :: A, B
DOUBLE PRECISION, PARAMETER ::&
& ONE=1.D0, THREE=3.D0, SIX=6.D0, ZERO=0.D0
IF (DX==ZERO) STOP 'splint: ERROR: DX=0'
NLO=INT(X/DX)+1
NHI=NLO+1
A=NHI-X/DX-1
B=ONE-A
Y=A*YA(NLO)+B*YA(NHI)+&
& ((A**3-A)*Y2A(NLO)+(B**3-B)*Y2A(NHI))*(DX**2)/SIX
DYDX=(YA(NHI)-YA(NLO))/DX+&
& (-((THREE*(A**2)-ONE)*Y2A(NLO))+&
& (THREE*(B**2)-ONE)*Y2A(NHI))*DX/SIX
END SUBROUTINE MACROAV_SPLINT
| gpl-3.0 |
qsnake/abinit | src/42_nlstrain/contistr03.F90 | 1 | 177558 | !{\src2tex{textfont=tt}}
!!****f* ABINIT/contistr03
!! NAME
!! contistr03
!!
!! FUNCTION
!! Carries out specialized metric tensor operations needed for contraction
!! of the 2nd strain derivative of the l=0,1,2,3 nonlocal Kleinman-Bylander
!! pseudopotential operation. Derivatives are wrt a pair of cartesian
!! strain components.
!! Full advantage is taken of the full permutational symmetry of these
!! tensors.
!!
!! COPYRIGHT
!! Copyright (C) 1998-2012 ABINIT group (DRH)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!! For the initials of contributors, see ~abinit/doc/developers/contributors.txt.
!!
!! INPUTS
!! istr=1,...6 specifies cartesian strain component 11,22,33,32,31,21
!! rank=angular momentum
!! gm(3,3)=metric tensor (array is symmetric but stored as 3x3)
!! gprimd(3,3)=reciprocal space dimensional primitive translations
!! aa(2,*)=unique elements of complex right-hand tensor
!! bb(2,*)=unique elements of complex left-hand tensor
!!
!! OUTPUT
!! eisnl(3)=contraction for nonlocal internal strain derivative energy
!!
!! NOTES
!! All tensors are stored in a compressed storage mode defined below;
!! input and output conform to this scheme.
!! When tensor elements occur repeatedly due to symmetry, the
!! WEIGHT IS INCLUDED in the output tensor element to simplify later
!! contractions with other tensors of the same rank and form, i.e. the
!! next contraction is then simply a dot product over the unique elements.
!!
!! PARENTS
!! nonlop_pl
!!
!! CHILDREN
!!
!! SOURCE
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "abi_common.h"
subroutine contistr03(istr,rank,gm,gprimd,eisnl,aa,bb)
use m_profiling
use defs_basis
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'contistr03'
!End of the abilint section
implicit none
!Arguments ------------------------------------
!scalars
integer,intent(in) :: istr,rank
!arrays
real(dp),intent(in) :: aa(2,((rank+1)*(rank+2))/2),bb(2,((rank+4)*(rank+5))/2)
real(dp),intent(in) :: gm(3,3),gprimd(3,3)
real(dp),intent(out) :: eisnl(3)
!Local variables-------------------------------
!scalars
integer :: ii,jj,ka,kb
!arrays
integer,save :: idx(12)=(/1,1,2,2,3,3,3,2,3,1,2,1/)
real(dp) :: dgm(3,3),tmp(2,3)
real(dp),allocatable :: cm(:,:,:)
! *************************************************************************
ABI_ALLOCATE(cm,(3,((rank+1)*(rank+2))/2,((rank+4)*(rank+5))/2))
ka=idx(2*istr-1);kb=idx(2*istr)
do ii = 1,3
dgm(:,ii)=-(gprimd(ka,:)*gprimd(kb,ii)+gprimd(kb,:)*gprimd(ka,ii))
end do
cm(:,:,:)=0.d0
!
!The code below was written by a Mathematica program and formatted by
!a combination of editing scripts. It is not intended to be read
!by human beings, and certainly not to be modified by one. Conceivably
!it could be shortened somewhat by identifying common subexpressions.
!
if(rank==0)then
cm(1,1,1)=dgm(1,1)
cm(1,1,2)=dgm(2,2)
cm(1,1,3)=dgm(3,3)
cm(1,1,4)=2*dgm(2,3)
cm(1,1,5)=2*dgm(1,3)
cm(1,1,6)=2*dgm(1,2)
cm(2,1,2)=2*dgm(1,2)
cm(2,1,4)=2*dgm(1,3)
cm(2,1,6)=dgm(1,1)
cm(2,1,7)=dgm(2,2)
cm(2,1,8)=dgm(3,3)
cm(2,1,9)=2*dgm(2,3)
cm(3,1,3)=2*dgm(1,3)
cm(3,1,4)=2*dgm(1,2)
cm(3,1,5)=dgm(1,1)
cm(3,1,8)=2*dgm(2,3)
cm(3,1,9)=dgm(2,2)
cm(3,1,10)=dgm(3,3)
elseif(rank==1)then
cm(1,1,1)=gm(1,1)*dgm(1,1)
cm(1,2,1)=gm(1,2)*dgm(1,1)
cm(1,3,1)=gm(1,3)*dgm(1,1)
cm(1,1,2)=2*gm(1,2)*dgm(1,2)+gm(1,1)*dgm(2,2)
cm(1,2,2)=2*gm(2,2)*dgm(1,2)+gm(1,2)*dgm(2,2)
cm(1,3,2)=2*gm(2,3)*dgm(1,2)+gm(1,3)*dgm(2,2)
cm(1,1,3)=2*gm(1,3)*dgm(1,3)+gm(1,1)*dgm(3,3)
cm(1,2,3)=2*gm(2,3)*dgm(1,3)+gm(1,2)*dgm(3,3)
cm(1,3,3)=2*gm(3,3)*dgm(1,3)+gm(1,3)*dgm(3,3)
cm(1,1,4)=2*(gm(1,3)*dgm(1,2)+gm(1,2)*dgm(1,3)+gm(1,1)*dgm(2,3))
cm(1,2,4)=2*(gm(2,3)*dgm(1,2)+gm(2,2)*dg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:)=0.d0
do jj=1,((rank+4)*(rank+5))/2
tmp(:,:)=0.d0
do ii=1,((rank+1)*(rank+2))/2
tmp(:,1)=tmp(:,1)+aa(:,ii)*cm(1,ii,jj)
tmp(:,2)=tmp(:,2)+aa(:,ii)*cm(2,ii,jj)
tmp(:,3)=tmp(:,3)+aa(:,ii)*cm(3,ii,jj)
end do
eisnl(:)=eisnl(:)+tmp(1,:)*bb(1,jj)+tmp(2,:)*bb(2,jj)
end do
!factor of 2 multiplied in to drop call to conjugate contraction
!eisnl(:)=0.5d0*eisnl(:)
ABI_DEALLOCATE(cm)
end subroutine contistr03
!!***
| gpl-3.0 |
qsnake/abinit | src/68_dmft/m_hu.F90 | 1 | 8749 | !{\src2tex{textfont=tt}}
!!****m* ABINIT/m_hu
!! NAME
!! m_hu
!!
!! FUNCTION
!!
!! COPYRIGHT
!! Copyright (C) 2006-2012 ABINIT group (BAmadon)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!!
!! INPUTS
!!
!! OUTPUT
!!
!! PARENTS
!!
!! CHILDREN
!!
!! SOURCE
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "abi_common.h"
MODULE m_hu
use m_profiling
use defs_basis
use defs_datatypes
implicit none
private
public :: init_hu
public :: destroy_hu
! public :: qmc_hu
public :: nullify_hu
public :: print_hu
!!***
!!****t* m_hu/hu_type
!! NAME
!! hu_type
!!
!! FUNCTION
!! This structured datatype contains interaction matrices for the correlated subspace
!!
!! SOURCE
type, public :: hu_type ! for each typat
integer :: lpawu
real(dp) :: upawu ! => upaw
real(dp) :: jpawu ! => jpaw
real(dp), pointer :: vee(:,:,:,:) ! => vee
real(dp), pointer :: uqmc(:)
real(dp), pointer :: udens(:,:)
end type hu_type
!----------------------------------------------------------------------
CONTAINS !========================================================================================
!!***
!!****f* m_hu/init_hu
!! NAME
!! init_hu
!!
!! FUNCTION
!! Allocate variables used in type hu_type.
!!
!! INPUTS
!!
!! OUTPUTS
!! hu = structure of data for dmft of type hu_type
!!
!! PARENTS
!! dmft_solve
!!
!! CHILDREN
!! wrtout
!!
!! SOURCE
subroutine init_hu(cryst_struc,pawtab,hu)
use defs_basis
use defs_datatypes
use defs_abitypes
use m_crystal, only : crystal_structure
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'init_hu'
use interfaces_14_hidewrite
!End of the abilint section
implicit none
!Arguments ------------------------------------
!type
type(crystal_structure),intent(in) :: cryst_struc
type(pawtab_type), target, intent(in) :: pawtab(cryst_struc%ntypat)
type(hu_type), intent(inout) :: hu(cryst_struc%ntypat)
!Local variables ------------------------------------
integer :: itypat,i,ij,ij1,ij2,j,lpawu,ms,ms1,m,m1,ndim
integer, allocatable :: xij(:,:)
real(dp) :: xtemp
character(len=500) :: message
!************************************************************************
write(message,'(2a)') ch10," == Compute Interactions for DMFT"
call wrtout(std_out,message,'COLL')
xtemp=zero
call nullify_hu(hu,cryst_struc%ntypat)
! ====================================
! Compute hu(iatom)%uqmc from vee
! ====================================
do itypat=1,cryst_struc%ntypat
lpawu=pawtab(itypat)%lpawu
hu(itypat)%lpawu=lpawu
if(lpawu.ne.-1) then
hu(itypat)%upawu=pawtab(itypat)%upawu
hu(itypat)%jpawu=pawtab(itypat)%jpawu
ndim=2*lpawu+1
write(message,'(2a,i4)') ch10,' -------> For Correlated Species', itypat
call wrtout(std_out, message,'COLL')
! allocate(hu(itypat)%vee(ndim,ndim,ndim,ndim))
ABI_ALLOCATE(hu(itypat)%uqmc,(ndim*(2*ndim-1)))
ABI_ALLOCATE(hu(itypat)%udens,(2*ndim,2*ndim))
ABI_ALLOCATE(xij,(2*ndim,2*ndim))
hu(itypat)%vee => pawtab(itypat)%vee
hu(itypat)%udens=zero
ij=0
do ms=1,2*ndim-1
xij(ms,ms)=0
do ms1=ms+1,2*ndim
ij=ij+1
xij(ms,ms1)=ij
xij(ms1,ms)=ij
if(ms<=ndim.and.ms1>ndim) then
m1 = ms1 - ndim
m = ms
hu(itypat)%uqmc(ij)=hu(itypat)%vee(m,m1,m,m1)
hu(itypat)%udens(ms,ms1)= hu(itypat)%vee(m,m1,m,m1)
hu(itypat)%udens(ms1,ms)= hu(itypat)%udens(ms,ms1)
else if(ms<=ndim.and.ms1<=ndim) then
m1 = ms1
m = ms
hu(itypat)%uqmc(ij)=hu(itypat)%vee(m,m1,m,m1)-hu(itypat)%vee(m,m1,m1,m)
hu(itypat)%udens(ms,ms1)= hu(itypat)%uqmc(ij)
hu(itypat)%udens(ms1,ms)= hu(itypat)%udens(ms,ms1)
else
m1 = ms1 - ndim
m = ms - ndim
hu(itypat)%uqmc(ij)=hu(itypat)%vee(m,m1,m,m1)-hu(itypat)%vee(m,m1,m1,m)
hu(itypat)%udens(ms,ms1)= hu(itypat)%uqmc(ij)
hu(itypat)%udens(ms1,ms)= hu(itypat)%udens(ms,ms1)
endif
enddo
enddo
xij(2*ndim,2*ndim)=0
write(message,'(a,5x,a)') ch10,"-------- Interactions in the density matrix representation "
call wrtout(std_out, message,'COLL')
write(message,'(6x,14(2x,i5))') (m,m=1,2*ndim)
call wrtout(std_out, message,'COLL')
! xtemp1b=0.d0
! ====================================
! Print hu(iatom)%uqmc
! ====================================
ij1=-10
ij2=-10
ij=0
do i=1,2*ndim
do j=i+1,2*ndim
ij=ij+1
if(j==i+1) ij1=ij
if(j==2*ndim) ij2=ij
enddo
! write(std_out,*) itypat
! do m=1,i
! write(std_out,*) i,m
! write(std_out,*) xij(i,m)
! write(std_out,*) ij1,ij2
! enddo
if(i==1) write(message,'(i3,14f7.3)') &
& i,xtemp, (hu(itypat)%uqmc(m),m=ij1,ij2)
if(i/=2*ndim.and.i/=1) write(message,'(i3,14f7.3)') i, &
& (hu(itypat)%uqmc(xij(i,m)), m=1,i-1),xtemp, (hu(itypat)%uqmc(m),m=ij1,ij2)
if(i==2*ndim) write(message,'(i3,14f7.3)') i, &
& (hu(itypat)%uqmc(xij(i,m)), m=1,i-1),xtemp
call wrtout(std_out, message,'COLL')
enddo
write(message,'(5x,a)') "--------------------------------------------------------"
call wrtout(std_out, message,'COLL')
ABI_DEALLOCATE(xij)
else
hu(itypat)%upawu=zero
hu(itypat)%jpawu=zero
! allocate(hu(itypat)%vee(0,0,0,0))
endif
enddo ! itypat
end subroutine init_hu
!!***
!!****f* m_hu/nullify_hu
!! NAME
!! nullify_hu
!!
!! FUNCTION
!! nullify hu
!!
!! INPUTS
!!
!! OUTPUT
!!
!! PARENTS
!! m_hu
!!
!! CHILDREN
!! wrtout
!!
!! SOURCE
subroutine nullify_hu(hu,ntypat)
use defs_basis
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'nullify_hu'
!End of the abilint section
implicit none
!Arguments ------------------------------------
!scalars
integer, intent(in) :: ntypat
type(hu_type),intent(inout) :: hu(ntypat)
!Local variables-------------------------------
integer :: itypat
!*********************************************************************
do itypat=1,ntypat
nullify(hu(itypat)%vee)
nullify(hu(itypat)%uqmc)
nullify(hu(itypat)%udens)
enddo
end subroutine nullify_hu
!!***
!!****f* m_hu/destroy_hu
!! NAME
!! destroy_mh
!!
!! FUNCTION
!! deallocate hu
!!
!! INPUTS
!! hu
!!
!! OUTPUT
!!
!! PARENTS
!!
!!
!! CHILDREN
!! wrtout
!!
!! SOURCE
subroutine destroy_hu(hu,ntypat)
use defs_basis
use m_crystal, only : crystal_structure
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'destroy_hu'
!End of the abilint section
implicit none
!Arguments ------------------------------------
!scalars
integer, intent(in) :: ntypat
type(hu_type),intent(inout) :: hu(ntypat)
!Local variables-------------------------------
integer :: itypat
! *********************************************************************
do itypat=1,ntypat
! if ( associated(hu(itypat)%vee) ) deallocate(hu(itypat)%vee)
if ( associated(hu(itypat)%uqmc) ) then
ABI_DEALLOCATE(hu(itypat)%uqmc)
end if
if ( associated(hu(itypat)%udens) ) then
ABI_DEALLOCATE(hu(itypat)%udens)
end if
enddo
end subroutine destroy_hu
!!***
!!****f* m_hu/print_hu
!! NAME
!! print_hu
!!
!! FUNCTION
!!
!! INPUTS
!!
!! OUTPUT
!!
!! PARENTS
!!
!! CHILDREN
!! wrtout
!!
!! SOURCE
subroutine print_hu(hu,ntypat,prtopt)
use defs_basis
use m_crystal, only : crystal_structure
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'print_hu'
use interfaces_14_hidewrite
!End of the abilint section
implicit none
!Arguments ------------------------------------
!type
integer, intent(in):: ntypat
type(hu_type),intent(in) :: hu(ntypat)
integer :: prtopt
!Local variables-------------------------------
integer :: itypat,lpawu
character(len=500) :: message
! *********************************************************************
if(prtopt>0) then
endif
do itypat = 1 , ntypat
lpawu=hu(itypat)%lpawu
if(lpawu/=-1) then
write(message,'(2a,i4)') ch10,' -------> For Correlated species'
call wrtout(std_out, message,'COLL')
endif ! lpawu/=1
enddo ! ntypat
end subroutine print_hu
END MODULE m_hu
!!***
| gpl-3.0 |
jeremiahyan/lammps | lib/linalg/dlalsd.f | 19 | 16947 | *> \brief \b DLALSD uses the singular value decomposition of A to solve the least squares problem.
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download DLALSD + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlalsd.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlalsd.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlalsd.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE DLALSD( UPLO, SMLSIZ, N, NRHS, D, E, B, LDB, RCOND,
* RANK, WORK, IWORK, INFO )
*
* .. Scalar Arguments ..
* CHARACTER UPLO
* INTEGER INFO, LDB, N, NRHS, RANK, SMLSIZ
* DOUBLE PRECISION RCOND
* ..
* .. Array Arguments ..
* INTEGER IWORK( * )
* DOUBLE PRECISION B( LDB, * ), D( * ), E( * ), WORK( * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> DLALSD uses the singular value decomposition of A to solve the least
*> squares problem of finding X to minimize the Euclidean norm of each
*> column of A*X-B, where A is N-by-N upper bidiagonal, and X and B
*> are N-by-NRHS. The solution X overwrites B.
*>
*> The singular values of A smaller than RCOND times the largest
*> singular value are treated as zero in solving the least squares
*> problem; in this case a minimum norm solution is returned.
*> The actual singular values are returned in D in ascending order.
*>
*> This code makes very mild assumptions about floating point
*> arithmetic. It will work on machines with a guard digit in
*> add/subtract, or on those binary machines without guard digits
*> which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2.
*> It could conceivably fail on hexadecimal or decimal machines
*> without guard digits, but we know of none.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] UPLO
*> \verbatim
*> UPLO is CHARACTER*1
*> = 'U': D and E define an upper bidiagonal matrix.
*> = 'L': D and E define a lower bidiagonal matrix.
*> \endverbatim
*>
*> \param[in] SMLSIZ
*> \verbatim
*> SMLSIZ is INTEGER
*> The maximum size of the subproblems at the bottom of the
*> computation tree.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The dimension of the bidiagonal matrix. N >= 0.
*> \endverbatim
*>
*> \param[in] NRHS
*> \verbatim
*> NRHS is INTEGER
*> The number of columns of B. NRHS must be at least 1.
*> \endverbatim
*>
*> \param[in,out] D
*> \verbatim
*> D is DOUBLE PRECISION array, dimension (N)
*> On entry D contains the main diagonal of the bidiagonal
*> matrix. On exit, if INFO = 0, D contains its singular values.
*> \endverbatim
*>
*> \param[in,out] E
*> \verbatim
*> E is DOUBLE PRECISION array, dimension (N-1)
*> Contains the super-diagonal entries of the bidiagonal matrix.
*> On exit, E has been destroyed.
*> \endverbatim
*>
*> \param[in,out] B
*> \verbatim
*> B is DOUBLE PRECISION array, dimension (LDB,NRHS)
*> On input, B contains the right hand sides of the least
*> squares problem. On output, B contains the solution X.
*> \endverbatim
*>
*> \param[in] LDB
*> \verbatim
*> LDB is INTEGER
*> The leading dimension of B in the calling subprogram.
*> LDB must be at least max(1,N).
*> \endverbatim
*>
*> \param[in] RCOND
*> \verbatim
*> RCOND is DOUBLE PRECISION
*> The singular values of A less than or equal to RCOND times
*> the largest singular value are treated as zero in solving
*> the least squares problem. If RCOND is negative,
*> machine precision is used instead.
*> For example, if diag(S)*X=B were the least squares problem,
*> where diag(S) is a diagonal matrix of singular values, the
*> solution would be X(i) = B(i) / S(i) if S(i) is greater than
*> RCOND*max(S), and X(i) = 0 if S(i) is less than or equal to
*> RCOND*max(S).
*> \endverbatim
*>
*> \param[out] RANK
*> \verbatim
*> RANK is INTEGER
*> The number of singular values of A greater than RCOND times
*> the largest singular value.
*> \endverbatim
*>
*> \param[out] WORK
*> \verbatim
*> WORK is DOUBLE PRECISION array, dimension at least
*> (9*N + 2*N*SMLSIZ + 8*N*NLVL + N*NRHS + (SMLSIZ+1)**2),
*> where NLVL = max(0, INT(log_2 (N/(SMLSIZ+1))) + 1).
*> \endverbatim
*>
*> \param[out] IWORK
*> \verbatim
*> IWORK is INTEGER array, dimension at least
*> (3*N*NLVL + 11*N)
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit.
*> < 0: if INFO = -i, the i-th argument had an illegal value.
*> > 0: The algorithm failed to compute a singular value while
*> working on the submatrix lying in rows and columns
*> INFO/(N+1) through MOD(INFO,N+1).
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date December 2016
*
*> \ingroup doubleOTHERcomputational
*
*> \par Contributors:
* ==================
*>
*> Ming Gu and Ren-Cang Li, Computer Science Division, University of
*> California at Berkeley, USA \n
*> Osni Marques, LBNL/NERSC, USA \n
*
* =====================================================================
SUBROUTINE DLALSD( UPLO, SMLSIZ, N, NRHS, D, E, B, LDB, RCOND,
$ RANK, WORK, IWORK, INFO )
*
* -- LAPACK computational routine (version 3.7.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* December 2016
*
* .. Scalar Arguments ..
CHARACTER UPLO
INTEGER INFO, LDB, N, NRHS, RANK, SMLSIZ
DOUBLE PRECISION RCOND
* ..
* .. Array Arguments ..
INTEGER IWORK( * )
DOUBLE PRECISION B( LDB, * ), D( * ), E( * ), WORK( * )
* ..
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE, TWO
PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0 )
* ..
* .. Local Scalars ..
INTEGER BX, BXST, C, DIFL, DIFR, GIVCOL, GIVNUM,
$ GIVPTR, I, ICMPQ1, ICMPQ2, IWK, J, K, NLVL,
$ NM1, NSIZE, NSUB, NWORK, PERM, POLES, S, SIZEI,
$ SMLSZP, SQRE, ST, ST1, U, VT, Z
DOUBLE PRECISION CS, EPS, ORGNRM, R, RCND, SN, TOL
* ..
* .. External Functions ..
INTEGER IDAMAX
DOUBLE PRECISION DLAMCH, DLANST
EXTERNAL IDAMAX, DLAMCH, DLANST
* ..
* .. External Subroutines ..
EXTERNAL DCOPY, DGEMM, DLACPY, DLALSA, DLARTG, DLASCL,
$ DLASDA, DLASDQ, DLASET, DLASRT, DROT, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, DBLE, INT, LOG, SIGN
* ..
* .. Executable Statements ..
*
* Test the input parameters.
*
INFO = 0
*
IF( N.LT.0 ) THEN
INFO = -3
ELSE IF( NRHS.LT.1 ) THEN
INFO = -4
ELSE IF( ( LDB.LT.1 ) .OR. ( LDB.LT.N ) ) THEN
INFO = -8
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'DLALSD', -INFO )
RETURN
END IF
*
EPS = DLAMCH( 'Epsilon' )
*
* Set up the tolerance.
*
IF( ( RCOND.LE.ZERO ) .OR. ( RCOND.GE.ONE ) ) THEN
RCND = EPS
ELSE
RCND = RCOND
END IF
*
RANK = 0
*
* Quick return if possible.
*
IF( N.EQ.0 ) THEN
RETURN
ELSE IF( N.EQ.1 ) THEN
IF( D( 1 ).EQ.ZERO ) THEN
CALL DLASET( 'A', 1, NRHS, ZERO, ZERO, B, LDB )
ELSE
RANK = 1
CALL DLASCL( 'G', 0, 0, D( 1 ), ONE, 1, NRHS, B, LDB, INFO )
D( 1 ) = ABS( D( 1 ) )
END IF
RETURN
END IF
*
* Rotate the matrix if it is lower bidiagonal.
*
IF( UPLO.EQ.'L' ) THEN
DO 10 I = 1, N - 1
CALL DLARTG( D( I ), E( I ), CS, SN, R )
D( I ) = R
E( I ) = SN*D( I+1 )
D( I+1 ) = CS*D( I+1 )
IF( NRHS.EQ.1 ) THEN
CALL DROT( 1, B( I, 1 ), 1, B( I+1, 1 ), 1, CS, SN )
ELSE
WORK( I*2-1 ) = CS
WORK( I*2 ) = SN
END IF
10 CONTINUE
IF( NRHS.GT.1 ) THEN
DO 30 I = 1, NRHS
DO 20 J = 1, N - 1
CS = WORK( J*2-1 )
SN = WORK( J*2 )
CALL DROT( 1, B( J, I ), 1, B( J+1, I ), 1, CS, SN )
20 CONTINUE
30 CONTINUE
END IF
END IF
*
* Scale.
*
NM1 = N - 1
ORGNRM = DLANST( 'M', N, D, E )
IF( ORGNRM.EQ.ZERO ) THEN
CALL DLASET( 'A', N, NRHS, ZERO, ZERO, B, LDB )
RETURN
END IF
*
CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, N, 1, D, N, INFO )
CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, NM1, 1, E, NM1, INFO )
*
* If N is smaller than the minimum divide size SMLSIZ, then solve
* the problem with another solver.
*
IF( N.LE.SMLSIZ ) THEN
NWORK = 1 + N*N
CALL DLASET( 'A', N, N, ZERO, ONE, WORK, N )
CALL DLASDQ( 'U', 0, N, N, 0, NRHS, D, E, WORK, N, WORK, N, B,
$ LDB, WORK( NWORK ), INFO )
IF( INFO.NE.0 ) THEN
RETURN
END IF
TOL = RCND*ABS( D( IDAMAX( N, D, 1 ) ) )
DO 40 I = 1, N
IF( D( I ).LE.TOL ) THEN
CALL DLASET( 'A', 1, NRHS, ZERO, ZERO, B( I, 1 ), LDB )
ELSE
CALL DLASCL( 'G', 0, 0, D( I ), ONE, 1, NRHS, B( I, 1 ),
$ LDB, INFO )
RANK = RANK + 1
END IF
40 CONTINUE
CALL DGEMM( 'T', 'N', N, NRHS, N, ONE, WORK, N, B, LDB, ZERO,
$ WORK( NWORK ), N )
CALL DLACPY( 'A', N, NRHS, WORK( NWORK ), N, B, LDB )
*
* Unscale.
*
CALL DLASCL( 'G', 0, 0, ONE, ORGNRM, N, 1, D, N, INFO )
CALL DLASRT( 'D', N, D, INFO )
CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, N, NRHS, B, LDB, INFO )
*
RETURN
END IF
*
* Book-keeping and setting up some constants.
*
NLVL = INT( LOG( DBLE( N ) / DBLE( SMLSIZ+1 ) ) / LOG( TWO ) ) + 1
*
SMLSZP = SMLSIZ + 1
*
U = 1
VT = 1 + SMLSIZ*N
DIFL = VT + SMLSZP*N
DIFR = DIFL + NLVL*N
Z = DIFR + NLVL*N*2
C = Z + NLVL*N
S = C + N
POLES = S + N
GIVNUM = POLES + 2*NLVL*N
BX = GIVNUM + 2*NLVL*N
NWORK = BX + N*NRHS
*
SIZEI = 1 + N
K = SIZEI + N
GIVPTR = K + N
PERM = GIVPTR + N
GIVCOL = PERM + NLVL*N
IWK = GIVCOL + NLVL*N*2
*
ST = 1
SQRE = 0
ICMPQ1 = 1
ICMPQ2 = 0
NSUB = 0
*
DO 50 I = 1, N
IF( ABS( D( I ) ).LT.EPS ) THEN
D( I ) = SIGN( EPS, D( I ) )
END IF
50 CONTINUE
*
DO 60 I = 1, NM1
IF( ( ABS( E( I ) ).LT.EPS ) .OR. ( I.EQ.NM1 ) ) THEN
NSUB = NSUB + 1
IWORK( NSUB ) = ST
*
* Subproblem found. First determine its size and then
* apply divide and conquer on it.
*
IF( I.LT.NM1 ) THEN
*
* A subproblem with E(I) small for I < NM1.
*
NSIZE = I - ST + 1
IWORK( SIZEI+NSUB-1 ) = NSIZE
ELSE IF( ABS( E( I ) ).GE.EPS ) THEN
*
* A subproblem with E(NM1) not too small but I = NM1.
*
NSIZE = N - ST + 1
IWORK( SIZEI+NSUB-1 ) = NSIZE
ELSE
*
* A subproblem with E(NM1) small. This implies an
* 1-by-1 subproblem at D(N), which is not solved
* explicitly.
*
NSIZE = I - ST + 1
IWORK( SIZEI+NSUB-1 ) = NSIZE
NSUB = NSUB + 1
IWORK( NSUB ) = N
IWORK( SIZEI+NSUB-1 ) = 1
CALL DCOPY( NRHS, B( N, 1 ), LDB, WORK( BX+NM1 ), N )
END IF
ST1 = ST - 1
IF( NSIZE.EQ.1 ) THEN
*
* This is a 1-by-1 subproblem and is not solved
* explicitly.
*
CALL DCOPY( NRHS, B( ST, 1 ), LDB, WORK( BX+ST1 ), N )
ELSE IF( NSIZE.LE.SMLSIZ ) THEN
*
* This is a small subproblem and is solved by DLASDQ.
*
CALL DLASET( 'A', NSIZE, NSIZE, ZERO, ONE,
$ WORK( VT+ST1 ), N )
CALL DLASDQ( 'U', 0, NSIZE, NSIZE, 0, NRHS, D( ST ),
$ E( ST ), WORK( VT+ST1 ), N, WORK( NWORK ),
$ N, B( ST, 1 ), LDB, WORK( NWORK ), INFO )
IF( INFO.NE.0 ) THEN
RETURN
END IF
CALL DLACPY( 'A', NSIZE, NRHS, B( ST, 1 ), LDB,
$ WORK( BX+ST1 ), N )
ELSE
*
* A large problem. Solve it using divide and conquer.
*
CALL DLASDA( ICMPQ1, SMLSIZ, NSIZE, SQRE, D( ST ),
$ E( ST ), WORK( U+ST1 ), N, WORK( VT+ST1 ),
$ IWORK( K+ST1 ), WORK( DIFL+ST1 ),
$ WORK( DIFR+ST1 ), WORK( Z+ST1 ),
$ WORK( POLES+ST1 ), IWORK( GIVPTR+ST1 ),
$ IWORK( GIVCOL+ST1 ), N, IWORK( PERM+ST1 ),
$ WORK( GIVNUM+ST1 ), WORK( C+ST1 ),
$ WORK( S+ST1 ), WORK( NWORK ), IWORK( IWK ),
$ INFO )
IF( INFO.NE.0 ) THEN
RETURN
END IF
BXST = BX + ST1
CALL DLALSA( ICMPQ2, SMLSIZ, NSIZE, NRHS, B( ST, 1 ),
$ LDB, WORK( BXST ), N, WORK( U+ST1 ), N,
$ WORK( VT+ST1 ), IWORK( K+ST1 ),
$ WORK( DIFL+ST1 ), WORK( DIFR+ST1 ),
$ WORK( Z+ST1 ), WORK( POLES+ST1 ),
$ IWORK( GIVPTR+ST1 ), IWORK( GIVCOL+ST1 ), N,
$ IWORK( PERM+ST1 ), WORK( GIVNUM+ST1 ),
$ WORK( C+ST1 ), WORK( S+ST1 ), WORK( NWORK ),
$ IWORK( IWK ), INFO )
IF( INFO.NE.0 ) THEN
RETURN
END IF
END IF
ST = I + 1
END IF
60 CONTINUE
*
* Apply the singular values and treat the tiny ones as zero.
*
TOL = RCND*ABS( D( IDAMAX( N, D, 1 ) ) )
*
DO 70 I = 1, N
*
* Some of the elements in D can be negative because 1-by-1
* subproblems were not solved explicitly.
*
IF( ABS( D( I ) ).LE.TOL ) THEN
CALL DLASET( 'A', 1, NRHS, ZERO, ZERO, WORK( BX+I-1 ), N )
ELSE
RANK = RANK + 1
CALL DLASCL( 'G', 0, 0, D( I ), ONE, 1, NRHS,
$ WORK( BX+I-1 ), N, INFO )
END IF
D( I ) = ABS( D( I ) )
70 CONTINUE
*
* Now apply back the right singular vectors.
*
ICMPQ2 = 1
DO 80 I = 1, NSUB
ST = IWORK( I )
ST1 = ST - 1
NSIZE = IWORK( SIZEI+I-1 )
BXST = BX + ST1
IF( NSIZE.EQ.1 ) THEN
CALL DCOPY( NRHS, WORK( BXST ), N, B( ST, 1 ), LDB )
ELSE IF( NSIZE.LE.SMLSIZ ) THEN
CALL DGEMM( 'T', 'N', NSIZE, NRHS, NSIZE, ONE,
$ WORK( VT+ST1 ), N, WORK( BXST ), N, ZERO,
$ B( ST, 1 ), LDB )
ELSE
CALL DLALSA( ICMPQ2, SMLSIZ, NSIZE, NRHS, WORK( BXST ), N,
$ B( ST, 1 ), LDB, WORK( U+ST1 ), N,
$ WORK( VT+ST1 ), IWORK( K+ST1 ),
$ WORK( DIFL+ST1 ), WORK( DIFR+ST1 ),
$ WORK( Z+ST1 ), WORK( POLES+ST1 ),
$ IWORK( GIVPTR+ST1 ), IWORK( GIVCOL+ST1 ), N,
$ IWORK( PERM+ST1 ), WORK( GIVNUM+ST1 ),
$ WORK( C+ST1 ), WORK( S+ST1 ), WORK( NWORK ),
$ IWORK( IWK ), INFO )
IF( INFO.NE.0 ) THEN
RETURN
END IF
END IF
80 CONTINUE
*
* Unscale and sort the singular values.
*
CALL DLASCL( 'G', 0, 0, ONE, ORGNRM, N, 1, D, N, INFO )
CALL DLASRT( 'D', N, D, INFO )
CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, N, NRHS, B, LDB, INFO )
*
RETURN
*
* End of DLALSD
*
END
| gpl-2.0 |
jamestwebber/scipy | scipy/special/cdflib/cumf.f | 151 | 2394 | SUBROUTINE cumf(f,dfn,dfd,cum,ccum)
C**********************************************************************
C
C SUBROUTINE CUMF(F,DFN,DFD,CUM,CCUM)
C CUMulative F distribution
C
C
C Function
C
C
C Computes the integral from 0 to F of the f-density with DFN
C and DFD degrees of freedom.
C
C
C Arguments
C
C
C F --> Upper limit of integration of the f-density.
C F is DOUBLE PRECISION
C
C DFN --> Degrees of freedom of the numerator sum of squares.
C DFN is DOUBLE PRECISI
C
C DFD --> Degrees of freedom of the denominator sum of squares.
C DFD is DOUBLE PRECISI
C
C CUM <-- Cumulative f distribution.
C CUM is DOUBLE PRECISI
C
C CCUM <-- Compliment of Cumulative f distribution.
C CCUM is DOUBLE PRECIS
C
C
C Method
C
C
C Formula 26.5.28 of Abramowitz and Stegun is used to reduce
C the cumulative F to a cumulative beta distribution.
C
C
C Note
C
C
C If F is less than or equal to 0, 0 is returned.
C
C**********************************************************************
C .. Scalar Arguments ..
DOUBLE PRECISION dfd,dfn,f,cum,ccum
C ..
C .. Local Scalars ..
DOUBLE PRECISION dsum,prod,xx,yy
INTEGER ierr
C ..
C .. Parameters ..
DOUBLE PRECISION half
PARAMETER (half=0.5D0)
DOUBLE PRECISION done
PARAMETER (done=1.0D0)
C ..
C .. External Subroutines ..
EXTERNAL bratio
C ..
C .. Executable Statements ..
IF (.NOT. (f.LE.0.0D0)) GO TO 10
cum = 0.0D0
ccum = 1.0D0
RETURN
10 prod = dfn*f
C
C XX is such that the incomplete beta with parameters
C DFD/2 and DFN/2 evaluated at XX is 1 - CUM or CCUM
C
C YY is 1 - XX
C
C Calculate the smaller of XX and YY accurately
C
dsum = dfd + prod
xx = dfd/dsum
IF (xx.GT.half) THEN
yy = prod/dsum
xx = done - yy
ELSE
yy = done - xx
END IF
CALL bratio(dfd*half,dfn*half,xx,yy,ccum,cum,ierr)
RETURN
END
| bsd-3-clause |
sungsujo/nacl-llvm-branches.llvm-gcc-trunk | gcc/testsuite/gfortran.dg/hollerith_legacy.f90 | 14 | 1310 | ! { dg-do compile }
! { dg-options "-std=legacy" }
! PR15966, PR18781 & PR16531
implicit none
complex(kind=8) x(2)
complex a(2,2)
character*4 z
character z1(4)
character*4 z2(2,2)
character*80 line
integer i
logical l
real r
character*8 c
data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
data a /8H(i3),abc, 0, 4H(i4), 8H (i9)/
data z/4h(i5)/
data z1/1h(,1hi,1h6,1h)/
data z2/4h(i7),'xxxx','xxxx','xxxx'/
z2 (1,2) = 4h(i8)
i = 4hHell
l = 4Ho wo
r = 4Hrld!
write (line, '(3A4)') i, l, r
if (line .ne. 'Hello world!') call abort
i = 2Hab
r = 2Hab
l = 2Hab
c = 2Hab
write (line, '(3A4, 8A)') i, l, r, c
if (line .ne. 'ab ab ab ab ') call abort
write(line, '(4A8, "!")' ) x
if (line .ne. 'abcdefghijklmnopqrstuvwxyz012345!') call abort
write (line, a) 3
if (line .ne. ' 3') call abort
write (line, a (1,2)) 4
if (line .ne. ' 4') call abort
write (line, z) 5
if (line .ne. ' 5') call abort
write (line, z1) 6
if (line .ne. ' 6') call abort
write (line, z2) 7
if (line .ne. ' 7') call abort
write (line, z2 (1,2)) 8
if (line .ne. ' 8') call abort
write (line, '(16A)') z2
if (line .ne. '(i7)xxxx(i8)xxxx') call abort
call test (8h hello)
end
subroutine test (h)
integer(kind=8) h
character*80 line
write (line, '(8a)') h
if (line .ne. ' hello') call abort
end subroutine
| gpl-2.0 |
jamestwebber/scipy | scipy/integrate/odepack/xerrwv.f | 155 | 5250 | subroutine xerrwv (msg, nmes, nerr, level, ni, i1, i2, nr, r1, r2)
integer msg, nmes, nerr, level, ni, i1, i2, nr,
1 i, lun, lunit, mesflg, ncpw, nch, nwds
double precision r1, r2
dimension msg(nmes)
c-----------------------------------------------------------------------
c subroutines xerrwv, xsetf, and xsetun, as given here, constitute
c a simplified version of the slatec error handling package.
c written by a. c. hindmarsh at llnl. version of march 30, 1987.
c this version is in double precision.
c
c all arguments are input arguments.
c
c msg = the message (hollerith literal or integer array).
c nmes = the length of msg (number of characters).
c nerr = the error number (not used).
c level = the error level..
c 0 or 1 means recoverable (control returns to caller).
c 2 means fatal (run is aborted--see note below).
c ni = number of integers (0, 1, or 2) to be printed with message.
c i1,i2 = integers to be printed, depending on ni.
c nr = number of reals (0, 1, or 2) to be printed with message.
c r1,r2 = reals to be printed, depending on nr.
c
c note.. this routine is machine-dependent and specialized for use
c in limited context, in the following ways..
c 1. the number of hollerith characters stored per word, denoted
c by ncpw below, is a data-loaded constant.
c 2. the value of nmes is assumed to be at most 60.
c (multi-line messages are generated by repeated calls.)
c 3. if level = 2, control passes to the statement stop
c to abort the run. this statement may be machine-dependent.
c 4. r1 and r2 are assumed to be in double precision and are printed
c in d21.13 format.
c 5. the common block /eh0001/ below is data-loaded (a machine-
c dependent feature) with default values.
c this block is needed for proper retention of parameters used by
c this routine which the user can reset by calling xsetf or xsetun.
c the variables in this block are as follows..
c mesflg = print control flag..
c 1 means print all messages (the default).
c 0 means no printing.
c lunit = logical unit number for messages.
c the default is 6 (machine-dependent).
c-----------------------------------------------------------------------
c the following are instructions for installing this routine
c in different machine environments.
c
c to change the default output unit, change the data statement
c in the block data subprogram below.
c
c for a different number of characters per word, change the
c data statement setting ncpw below, and format 10. alternatives for
c various computers are shown in comment cards.
c
c for a different run-abort command, change the statement following
c statement 100 at the end.
c-----------------------------------------------------------------------
common /eh0001/ mesflg, lunit
c-----------------------------------------------------------------------
c the following data-loaded value of ncpw is valid for the cdc-6600
c and cdc-7600 computers.
c data ncpw/10/
c the following is valid for the cray-1 computer.
c data ncpw/8/
c the following is valid for the burroughs 6700 and 7800 computers.
c data ncpw/6/
c the following is valid for the pdp-10 computer.
c data ncpw/5/
c the following is valid for the vax computer with 4 bytes per integer,
c and for the ibm-360, ibm-370, ibm-303x, and ibm-43xx computers.
data ncpw/4/
c the following is valid for the pdp-11, or vax with 2-byte integers.
c data ncpw/2/
c-----------------------------------------------------------------------
if (mesflg .eq. 0) go to 100
c get logical unit number. ---------------------------------------------
lun = lunit
c get number of words in message. --------------------------------------
nch = min0(nmes,60)
nwds = nch/ncpw
if (nch .ne. nwds*ncpw) nwds = nwds + 1
c write the message. ---------------------------------------------------
write (lun, 10) (msg(i),i=1,nwds)
c-----------------------------------------------------------------------
c the following format statement is to have the form
c 10 format(1x,mmann)
c where nn = ncpw and mm is the smallest integer .ge. 60/ncpw.
c the following is valid for ncpw = 10.
c 10 format(1x,6a10)
c the following is valid for ncpw = 8.
c 10 format(1x,8a8)
c the following is valid for ncpw = 6.
c 10 format(1x,10a6)
c the following is valid for ncpw = 5.
c 10 format(1x,12a5)
c the following is valid for ncpw = 4.
10 format(1x,15a4)
c the following is valid for ncpw = 2.
c 10 format(1x,30a2)
c-----------------------------------------------------------------------
if (ni .eq. 1) write (lun, 20) i1
20 format(6x,'in above message, i1 =',i10)
if (ni .eq. 2) write (lun, 30) i1,i2
30 format(6x,'in above message, i1 =',i10,3x,'i2 =',i10)
if (nr .eq. 1) write (lun, 40) r1
40 format(6x,'in above message, r1 =',d21.13)
if (nr .eq. 2) write (lun, 50) r1,r2
50 format(6x,'in above, r1 =',d21.13,3x,'r2 =',d21.13)
c abort the run if level = 2. ------------------------------------------
100 if (level .ne. 2) return
stop
c----------------------- end of subroutine xerrwv ----------------------
end
| bsd-3-clause |
doslab/gcc-designated-initializer-support-cpp | libgfortran/generated/_cosh_r16.F90 | 22 | 1483 | ! Copyright 2002, 2007, 2009 Free Software Foundation, Inc.
! Contributed by Paul Brook <paul@nowt.org>
!
!This file is part of the GNU Fortran 95 runtime library (libgfortran).
!
!GNU libgfortran is free software; you can redistribute it and/or
!modify it under the terms of the GNU General Public
!License as published by the Free Software Foundation; either
!version 3 of the License, or (at your option) any later version.
!
!GNU libgfortran is distributed in the hope that it will be useful,
!but WITHOUT ANY WARRANTY; without even the implied warranty of
!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!GNU General Public License for more details.
!
!Under Section 7 of GPL version 3, you are granted additional
!permissions described in the GCC Runtime Library Exception, version
!3.1, as published by the Free Software Foundation.
!
!You should have received a copy of the GNU General Public License and
!a copy of the GCC Runtime Library Exception along with this program;
!see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
!<http://www.gnu.org/licenses/>.
!
!This file is machine generated.
#include "config.h"
#include "kinds.inc"
#include "c99_protos.inc"
#if defined (HAVE_GFC_REAL_16)
#ifdef HAVE_COSHL
elemental function _gfortran_specific__cosh_r16 (parm)
real (kind=16), intent (in) :: parm
real (kind=16) :: _gfortran_specific__cosh_r16
_gfortran_specific__cosh_r16 = cosh (parm)
end function
#endif
#endif
| gpl-2.0 |
qsnake/abinit | src/72_response/kpgstr.F90 | 1 | 4270 | !{\src2tex{textfont=tt}}
!!****f* ABINIT/kpgstr
!! NAME
!! kpgstr
!!
!! FUNCTION
!! Compute elements of the derivative
!! the kinetic energy operator in reciprocal
!! space at given k point wrt a single cartesian strain
!! component
!!
!! COPYRIGHT
!! Copyright (C) 1999-2012 ABINIT group (DRH, XG)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!!
!! INPUTS
!! ecut=cut-off energy for plane wave basis sphere (Ha)
!! ecutsm=smearing energy for plane wave kinetic energy (Ha)
!! effmass=effective mass for electrons (1. in common case)
!! gmet(3,3) = reciprocal lattice metric tensor (Bohr**-2)
!! gprimd(3,3)=reciprocal space dimensional primitive translations
!! istr=1,...6 specifies cartesian strain component 11,22,33,32,31,21
!! kg(3,npw) = integer coordinates of planewaves in basis sphere.
!! kpt(3) = reduced coordinates of k point
!! npw = number of plane waves at kpt.
!!
!! OUTPUT
!! dkinpw(npw)=d/deps(istr) ( (1/2)*(2 pi)**2 * (k+G)**2 )
!!
!!
!! NOTES
!! Src_6response/kpg3.f
!!
!!
!! PARENTS
!! nstwf4,rhofermi3,vtorho3
!!
!! CHILDREN
!! leave_new,wrtout
!!
!! SOURCE
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "abi_common.h"
subroutine kpgstr(dkinpw,ecut,ecutsm,effmass,gmet,gprimd,istr,kg,kpt,npw)
use m_profiling
use defs_basis
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'kpgstr'
use interfaces_14_hidewrite
use interfaces_16_hideleave
!End of the abilint section
implicit none
!Arguments -------------------------------
!scalars
integer,intent(in) :: istr,npw
real(dp),intent(in) :: ecut,ecutsm,effmass
!arrays
integer,intent(in) :: kg(3,npw)
real(dp),intent(in) :: gmet(3,3),gprimd(3,3),kpt(3)
real(dp),intent(out) :: dkinpw(npw)
!Local variables -------------------------
!scalars
integer :: ig,ii,ka,kb
real(dp) :: dfsm,dkinetic,dkpg2,ecutsm_inv,fsm,gpk1,gpk2,gpk3,htpisq
! real(dp) :: d2fsm ! used in commented section below
real(dp) :: kpg2,xx
character(len=500) :: message
!arrays
integer,save :: idx(12)=(/1,1,2,2,3,3,3,2,3,1,2,1/)
real(dp) :: dgmetds(3,3)
! *********************************************************************
!htpisq is (1/2) (2 Pi) **2:
htpisq=0.5_dp*(two_pi)**2
ecutsm_inv=0.0_dp
if(ecutsm>1.0d-20)ecutsm_inv=1/ecutsm
!Compute derivative of metric tensor wrt strain component istr
if(istr<1 .or. istr>6)then
write(message, '(a,a,a,a,i10,a,a,a)' )ch10,&
& ' vlocalstr: BUG -',ch10,&
& ' Input istr=',istr,' not allowed.',ch10,&
& ' Possible values are 1,2,3,4,5,6 only.'
call wrtout(std_out,message,'PERS')
call leave_new('PERS')
end if
ka=idx(2*istr-1);kb=idx(2*istr)
do ii = 1,3
dgmetds(:,ii)=-(gprimd(ka,:)*gprimd(kb,ii)+gprimd(kb,:)*gprimd(ka,ii))
end do
!For historical reasons:
dgmetds(:,:)=0.5_dp*dgmetds(:,:)
do ig=1,npw
gpk1=dble(kg(1,ig))+kpt(1)
gpk2=dble(kg(2,ig))+kpt(2)
gpk3=dble(kg(3,ig))+kpt(3)
kpg2=htpisq*&
& ( gmet(1,1)*gpk1**2+ &
& gmet(2,2)*gpk2**2+ &
& gmet(3,3)*gpk3**2 &
& +2.0_dp*(gpk1*gmet(1,2)*gpk2+ &
& gpk1*gmet(1,3)*gpk3+ &
& gpk2*gmet(2,3)*gpk3 ) )
dkpg2=htpisq*2.0_dp*&
& (gpk1*(dgmetds(1,1)*gpk1+dgmetds(1,2)*gpk2+dgmetds(1,3)*gpk3)+ &
& gpk2*(dgmetds(2,1)*gpk1+dgmetds(2,2)*gpk2+dgmetds(2,3)*gpk3)+ &
& gpk3*(dgmetds(3,1)*gpk1+dgmetds(3,2)*gpk2+dgmetds(3,3)*gpk3) )
dkinetic=dkpg2
if(kpg2>ecut-ecutsm)then
if(kpg2>ecut-tol12)then
! The wavefunction has been filtered : no derivative
dkinetic=0.0_dp
else
xx=(ecut-kpg2)*ecutsm_inv
! This kinetic cutoff smoothing function and its xx derivatives
! were produced with Mathematica and the fortran code has been
! numerically checked against Mathematica.
fsm=1.0_dp/(xx**2*(3+xx*(1+xx*(-6+3*xx))))
dfsm=-3.0_dp*(-1+xx)**2*xx*(2+5*xx)*fsm**2
! d2fsm=6.0_dp*xx**2*(9+xx*(8+xx*(-52+xx*(-3+xx*(137+xx*&
! & (-144+45*xx))))))*fsm**3
dkinetic=dkpg2*(fsm-ecutsm_inv*kpg2*dfsm)
end if
end if
dkinpw(ig)=dkinetic/effmass
end do
end subroutine kpgstr
!!***
| gpl-3.0 |
qsnake/abinit | src/63_bader/plint.F90 | 1 | 2782 | !{\src2tex{textfont=tt}}
!!****f* ABINIT/plint
!! NAME
!! plint
!!
!! FUNCTION
!! This simple routine gives the profile of the density
!! integrated in xy plane belong the z-axes (it works only
!! for orthogonal coordinates at present - it is better to use cut3d)
!! integration in plane - with equilateral triangles (not really
!! finished and not tested!)
!!
!! COPYRIGHT
!! Copyright (C) 2002-2012 ABINIT group (PCasek,FF,XG)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!! For the initials of contributors, see ~abinit/doc/developers/contributors.txt .
!!
!! INPUTS
!! (this routine works on the data in the aimprom module)
!!
!! OUTPUT
!! (this routine works on the data in the aimprom module)
!!
!! WARNING
!! This file does not follow the ABINIT coding rules (yet)
!!
!! PARENTS
!! drvaim
!!
!! CHILDREN
!! vgh_rho
!!
!! SOURCE
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "abi_common.h"
subroutine plint()
use m_profiling
use defs_basis
use defs_aimprom
!This section has been created automatically by the script Abilint (TD).
!Do not modify the following lines by hand.
#undef ABI_FUNC
#define ABI_FUNC 'plint'
use interfaces_63_bader, except_this_one => plint
!End of the abilint section
implicit none
!Arguments ------------------------------------
!Local variables ------------------------------
!scalars
integer,parameter :: nd=150,ng=300
integer :: cod,iat,ii,ipos,jj,kk,nn
real(dp) :: dd,ee,ff,gg,hh,igr,rho,ss
logical :: prep
!arrays
real(dp) :: grho(3),hrho(3,3),vv(3),xl(nd+1),xs(nd)
real(dp),allocatable :: uu(:)
! *********************************************************************
ff=rprimd(1,1)/nd
ss=2._dp/sqrt(3._dp)*rprimd(2,2)/rprimd(1,1)*nd
nn=int(ss)
gg=sqrt(3._dp)/2.*ff
hh=rprimd(2,2)-nn/nd*sqrt(3._dp)/2.*rprimd(1,1)
ee=hh/sqrt(3._dp)
hh=hh/2.
ss=sqrt(3._dp)*ff*ff/4.
dd=ee*ff/2.
do ii=1,nd
xl(ii)=ii*ff
xs(ii)=ff/2.+ii*ff
end do
xl(nd+1)=rprimd(1,1)
ABI_ALLOCATE(uu,(nn+3))
uu(1)=0._dp
uu(nn+3)=rprimd(2,2)
do ii=2,nn+2
uu(ii)=hh+(ii-1)*gg
end do
igr=0._dp
prep=.true.
do kk=1,ng
igr=0._dp
vv(3)=(kk-1)*rprimd(3,3)/ng
do ii=1,nn+3
vv(2)=uu(ii)
do jj=1,nd
if (prep) then
vv(1)=xl(jj)
prep=.false.
else
vv(1)=xs(jj)
prep=.true.
end if
call vgh_rho(vv,rho,grho,hrho,dd,iat,ipos,cod)
if ((ii==1).or.(ii==nn+3)) then
igr=igr+dd*rho
elseif ((ii==2).or.(ii==nn+2)) then
igr=igr+(dd+ss)*rho
else
igr=igr+ss*2*rho
end if
end do
end do
write(untp,'(2E16.8)') vv(3), igr
end do
ABI_DEALLOCATE(uu)
end subroutine plint
!!***
| gpl-3.0 |
jamestwebber/scipy | scipy/integrate/quadpack/dqaws.f | 143 | 8961 | subroutine dqaws(f,a,b,alfa,beta,integr,epsabs,epsrel,result,
* abserr,neval,ier,limit,lenw,last,iwork,work)
c***begin prologue dqaws
c***date written 800101 (yymmdd)
c***revision date 830518 (yymmdd)
c***category no. h2a2a1
c***keywords automatic integrator, special-purpose,
c algebraico-logarithmic end-point singularities,
c clenshaw-curtis, globally adaptive
c***author piessens,robert,appl. math. & progr. div. -k.u.leuven
c de doncker,elise,appl. math. & progr. div. - k.u.leuven
c***purpose the routine calculates an approximation result to a given
c definite integral i = integral of f*w over (a,b),
c (where w shows a singular behaviour at the end points
c see parameter integr).
c hopefully satisfying following claim for accuracy
c abs(i-result).le.max(epsabs,epsrel*abs(i)).
c***description
c
c integration of functions having algebraico-logarithmic
c end point singularities
c standard fortran subroutine
c double precision version
c
c parameters
c on entry
c f - double precision
c function subprogram defining the integrand
c function f(x). the actual name for f needs to be
c declared e x t e r n a l in the driver program.
c
c a - double precision
c lower limit of integration
c
c b - double precision
c upper limit of integration, b.gt.a
c if b.le.a, the routine will end with ier = 6.
c
c alfa - double precision
c parameter in the integrand function, alfa.gt.(-1)
c if alfa.le.(-1), the routine will end with
c ier = 6.
c
c beta - double precision
c parameter in the integrand function, beta.gt.(-1)
c if beta.le.(-1), the routine will end with
c ier = 6.
c
c integr - integer
c indicates which weight function is to be used
c = 1 (x-a)**alfa*(b-x)**beta
c = 2 (x-a)**alfa*(b-x)**beta*log(x-a)
c = 3 (x-a)**alfa*(b-x)**beta*log(b-x)
c = 4 (x-a)**alfa*(b-x)**beta*log(x-a)*log(b-x)
c if integr.lt.1 or integr.gt.4, the routine
c will end with ier = 6.
c
c epsabs - double precision
c absolute accuracy requested
c epsrel - double precision
c relative accuracy requested
c if epsabs.le.0
c and epsrel.lt.max(50*rel.mach.acc.,0.5d-28),
c the routine will end with ier = 6.
c
c on return
c result - double precision
c approximation to the integral
c
c abserr - double precision
c estimate of the modulus of the absolute error,
c which should equal or exceed abs(i-result)
c
c neval - integer
c number of integrand evaluations
c
c ier - integer
c ier = 0 normal and reliable termination of the
c routine. it is assumed that the requested
c accuracy has been achieved.
c ier.gt.0 abnormal termination of the routine
c the estimates for the integral and error
c are less reliable. it is assumed that the
c requested accuracy has not been achieved.
c error messages
c ier = 1 maximum number of subdivisions allowed
c has been achieved. one can allow more
c subdivisions by increasing the value of
c limit (and taking the according dimension
c adjustments into account). however, if
c this yields no improvement it is advised
c to analyze the integrand, in order to
c determine the integration difficulties
c which prevent the requested tolerance from
c being achieved. in case of a jump
c discontinuity or a local singularity
c of algebraico-logarithmic type at one or
c more interior points of the integration
c range, one should proceed by splitting up
c the interval at these points and calling
c the integrator on the subranges.
c = 2 the occurrence of roundoff error is
c detected, which prevents the requested
c tolerance from being achieved.
c = 3 extremely bad integrand behaviour occurs
c at some points of the integration
c interval.
c = 6 the input is invalid, because
c b.le.a or alfa.le.(-1) or beta.le.(-1) or
c or integr.lt.1 or integr.gt.4 or
c (epsabs.le.0 and
c epsrel.lt.max(50*rel.mach.acc.,0.5d-28))
c or limit.lt.2 or lenw.lt.limit*4.
c result, abserr, neval, last are set to
c zero. except when lenw or limit is invalid
c iwork(1), work(limit*2+1) and
c work(limit*3+1) are set to zero, work(1)
c is set to a and work(limit+1) to b.
c
c dimensioning parameters
c limit - integer
c dimensioning parameter for iwork
c limit determines the maximum number of
c subintervals in the partition of the given
c integration interval (a,b), limit.ge.2.
c if limit.lt.2, the routine will end with ier = 6.
c
c lenw - integer
c dimensioning parameter for work
c lenw must be at least limit*4.
c if lenw.lt.limit*4, the routine will end
c with ier = 6.
c
c last - integer
c on return, last equals the number of
c subintervals produced in the subdivision process,
c which determines the significant number of
c elements actually in the work arrays.
c
c work arrays
c iwork - integer
c vector of dimension limit, the first k
c elements of which contain pointers
c to the error estimates over the subintervals,
c such that work(limit*3+iwork(1)), ...,
c work(limit*3+iwork(k)) form a decreasing
c sequence with k = last if last.le.(limit/2+2),
c and k = limit+1-last otherwise
c
c work - double precision
c vector of dimension lenw
c on return
c work(1), ..., work(last) contain the left
c end points of the subintervals in the
c partition of (a,b),
c work(limit+1), ..., work(limit+last) contain
c the right end points,
c work(limit*2+1), ..., work(limit*2+last)
c contain the integral approximations over
c the subintervals,
c work(limit*3+1), ..., work(limit*3+last)
c contain the error estimates.
c
c***references (none)
c***routines called dqawse,xerror
c***end prologue dqaws
c
double precision a,abserr,alfa,b,beta,epsabs,epsrel,f,result,work
integer ier,integr,iwork,last,lenw,limit,lvl,l1,l2,l3,neval
c
dimension iwork(limit),work(lenw)
c
external f
c
c check validity of limit and lenw.
c
c***first executable statement dqaws
ier = 6
neval = 0
last = 0
result = 0.0d+00
abserr = 0.0d+00
if(limit.lt.2.or.lenw.lt.limit*4) go to 10
c
c prepare call for dqawse.
c
l1 = limit+1
l2 = limit+l1
l3 = limit+l2
c
call dqawse(f,a,b,alfa,beta,integr,epsabs,epsrel,limit,result,
* abserr,neval,ier,work(1),work(l1),work(l2),work(l3),iwork,last)
c
c call error handler if necessary.
c
lvl = 0
10 if(ier.eq.6) lvl = 1
if(ier.ne.0) call xerror('abnormal return from dqaws',26,ier,lvl)
return
end
| bsd-3-clause |
doslab/gcc-designated-initializer-support-cpp | gcc/testsuite/gfortran.dg/ichar_1.f90 | 22 | 2074 | ! { dg-do compile }
! PR20879
! Check that we reject expressions longer than one character for the
! ICHAR and IACHAR intrinsics.
! Assumed length variables are special because the frontend doesn't have
! an expression for their length
subroutine test (c)
character(len=*) :: c
integer i
i = ichar(c)
i = ichar(c(2:))
i = ichar(c(:1))
end subroutine
program ichar_1
type derivedtype
character(len=4) :: addr
end type derivedtype
type derivedtype1
character(len=1) :: addr
end type derivedtype1
integer i
integer, parameter :: j = 2
character(len=8) :: c = 'abcd'
character(len=1) :: g1(2)
character(len=1) :: g2(2,2)
character*1, parameter :: s1 = 'e'
character*2, parameter :: s2 = 'ef'
type(derivedtype) :: dt
type(derivedtype1) :: dt1
if (ichar(c(3:3)) /= 97) call abort
if (ichar(c(:1)) /= 97) call abort
if (ichar(c(j:j)) /= 98) call abort
if (ichar(s1) /= 101) call abort
if (ichar('f') /= 102) call abort
g1(1) = 'a'
if (ichar(g1(1)) /= 97) call abort
if (ichar(g1(1)(:)) /= 97) call abort
g2(1,1) = 'a'
if (ichar(g2(1,1)) /= 97) call abort
i = ichar(c) ! { dg-error "must be of length one" "" }
i = ichar(c(:)) ! { dg-error "must be of length one" "" }
i = ichar(s2) ! { dg-error "must be of length one" "" }
i = ichar(c(1:2)) ! { dg-error "must be of length one" "" }
i = ichar(c(1:)) ! { dg-error "must be of length one" "" }
i = ichar('abc') ! { dg-error "must be of length one" "" }
! ichar and iachar use the same checking routines. DO a couple of tests to
! make sure it's not totally broken.
if (ichar(c(3:3)) /= 97) call abort
i = ichar(c) ! { dg-error "must be of length one" "" }
i = ichar(dt%addr(1:1))
i = ichar(dt%addr) ! { dg-error "must be of length one" "" }
i = ichar(dt%addr(1:2)) ! { dg-error "must be of length one" "" }
i = ichar(dt%addr(1:)) ! { dg-error "must be of length one" "" }
i = ichar(dt1%addr(1:1))
i = ichar(dt1%addr)
call test(g1(1))
end program ichar_1
| gpl-2.0 |
qsnake/abinit | src/12_hide_mpi/interfaces_12_hide_mpi.F90 | 1 | 43390 | !!****m* ABINIT/interfaces_12_hide_mpi
!! NAME
!! interfaces_12_hide_mpi
!!
!! FUNCTION
!! This module contains the interfaces of the routines
!! in the directory src/12_hide_mpi
!!
!! COPYRIGHT
!! Copyright (C) 2010-2011 ABINIT group
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!!
!! NOTES
!! THIS FILE IS GENERATED AUTOMATICALLY BY abilint.
!! To do that: config/scripts/abilint . .
!!
!!
!! SOURCE
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
module interfaces_12_hide_mpi
implicit none
interface
subroutine xallgather_mpi_int(xval,recvcounts,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
integer,intent(inout) :: xval
integer,intent(inout) :: recvcounts(:)
end subroutine xallgather_mpi_int
end interface
interface
subroutine xallgather_mpi_char(charval,recvcounts,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
character(20),intent(inout) :: charval
character(20),intent(inout) :: recvcounts(:)
end subroutine xallgather_mpi_char
end interface
interface
subroutine xallgather_mpi_int1d(xval,nelem,recvcounts,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: nelem
integer ,intent(in) :: spaceComm
integer,intent(inout) :: recvcounts(:)
integer,intent(in) :: xval(:)
end subroutine xallgather_mpi_int1d
end interface
interface
subroutine xallgather_mpi_dp1d(xval,nelem,recvcounts,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: nelem
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: recvcounts(:)
real(dp),intent(in) :: xval(:)
end subroutine xallgather_mpi_dp1d
end interface
interface
subroutine xallgather_mpi_dp2d(xval,nelem,recvcounts,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: nelem
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: recvcounts(:,:)
real(dp),intent(in) :: xval(:,:)
end subroutine xallgather_mpi_dp2d
end interface
interface
subroutine xallgather_mpi_dp3d(xval,nelem,recvcounts,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: nelem
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: recvcounts(:,:,:)
real(dp),intent(in) :: xval(:,:,:)
end subroutine xallgather_mpi_dp3d
end interface
interface
subroutine xallgather_mpi_dp4d(xval,nelem,recvcounts,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: nelem
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: recvcounts(:,:,:,:)
real(dp),intent(in) :: xval(:,:,:,:)
end subroutine xallgather_mpi_dp4d
end interface
interface
subroutine xallgatherv_mpi_int2d(xval,nelem,recvbuf,recvcounts,displs,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(inout) :: recvbuf(:,:)
integer,intent(in) :: recvcounts(:)
integer,intent(in) :: xval(:,:)
end subroutine xallgatherv_mpi_int2d
end interface
interface
subroutine xallgatherv_mpi_int(xval,nelem,recvbuf,recvcounts,displs,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(inout) :: recvbuf(:)
integer,intent(in) :: recvcounts(:)
integer,intent(in) :: xval(:)
end subroutine xallgatherv_mpi_int
end interface
interface
subroutine xallgatherv_mpi_dp(xval,nelem,recvbuf,recvcounts,displs,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: recvcounts(:)
real(dp),intent(inout) :: recvbuf(:)
real(dp),intent(in) :: xval(:)
end subroutine xallgatherv_mpi_dp
end interface
interface
subroutine xallgatherv_mpi_dp2d(xval,nelem,recvbuf,recvcounts,displs,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: recvcounts(:)
real(dp),intent(inout) :: recvbuf(:,:)
real(dp),intent(in) :: xval(:,:)
end subroutine xallgatherv_mpi_dp2d
end interface
interface
subroutine xallgatherv_mpi_dp3d(xval,nelem,recvbuf,recvcounts,displs,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: recvcounts(:)
real(dp),intent(inout) :: recvbuf(:,:,:)
real(dp),intent(in) :: xval(:,:,:)
end subroutine xallgatherv_mpi_dp3d
end interface
interface
subroutine xallgatherv_mpi_dp4d(xval,nelem,recvbuf,recvcounts,displs,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: recvcounts(:)
real(dp),intent(inout) :: recvbuf(:,:,:,:)
real(dp),intent(in) :: xval(:,:,:,:)
end subroutine xallgatherv_mpi_dp4d
end interface
interface
subroutine xalltoall_mpi_dp2d(xval, sendsize, recvbuf, recvsize, spaceComm, ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: recvsize
integer ,intent(in) :: sendsize
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: recvbuf(:,:)
real(dp),intent(in) :: xval(:,:)
end subroutine xalltoall_mpi_dp2d
end interface
interface
subroutine xalltoallv_mpi_dp2d(xval,sendcnts,sdispls,recvbuf,recvcnts,rdispls,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
integer ,intent(in) :: rdispls(:)
integer ,intent(in) :: recvcnts(:)
integer ,intent(in) :: sdispls(:)
integer ,intent(in) :: sendcnts(:)
real(dp),intent(inout) :: recvbuf(:,:)
real(dp),intent(in) :: xval(:,:)
end subroutine xalltoallv_mpi_dp2d
end interface
interface
subroutine xalltoallv_mpi_int2d(xval,sendcnts,sdispls,recvbuf,recvcnts,rdispls,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
integer ,intent(in) :: rdispls(:)
integer,intent(inout) :: recvbuf(:,:)
integer ,intent(in) :: recvcnts(:)
integer ,intent(in) :: sdispls(:)
integer ,intent(in) :: sendcnts(:)
integer,intent(in) :: xval(:,:)
end subroutine xalltoallv_mpi_int2d
end interface
interface
subroutine xalltoallv_mpi_dp1d(xval,sendcnts,sdispls,recvbuf,recvcnts,rdispls,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: rdispls
integer ,intent(in) :: spaceComm
integer ,intent(in) :: recvcnts(:)
integer ,intent(in) :: sdispls(:)
integer ,intent(in) :: sendcnts(:)
real(dp),intent(inout) :: recvbuf(:)
real(dp),intent(in) :: xval(:)
end subroutine xalltoallv_mpi_dp1d
end interface
interface
subroutine xalltoallv_mpi_dp1d2(xval,sendcnts,sdispls,recvbuf,recvcnts,rdispls,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
integer ,intent(in) :: rdispls(:)
integer ,intent(in) :: recvcnts(:)
integer ,intent(in) :: sdispls(:)
integer ,intent(in) :: sendcnts(:)
real(dp),intent(inout) :: recvbuf(:)
real(dp),intent(in) :: xval(:)
end subroutine xalltoallv_mpi_dp1d2
end interface
interface
subroutine xcast_mpi_intv(xval,master,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: master
integer,intent(in) :: spaceComm
integer,intent(inout) :: xval
end subroutine xcast_mpi_intv
end interface
interface
subroutine xcast_mpi_int1d(xval,master,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: master
integer,intent(in) :: spaceComm
integer,intent(inout) :: xval(:)
end subroutine xcast_mpi_int1d
end interface
interface
subroutine xcast_mpi_int2d(xval,master,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: master
integer,intent(in) :: spaceComm
integer,intent(inout) :: xval(:,:)
end subroutine xcast_mpi_int2d
end interface
interface
subroutine xcast_mpi_int3d(xval,master,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: master
integer,intent(in) :: spaceComm
integer,intent(inout) :: xval(:,:,:)
end subroutine xcast_mpi_int3d
end interface
interface
subroutine xcast_mpi_dpv(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval
end subroutine xcast_mpi_dpv
end interface
interface
subroutine xcast_mpi_dp1d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:)
end subroutine xcast_mpi_dp1d
end interface
interface
subroutine xcast_mpi_dp2d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:)
end subroutine xcast_mpi_dp2d
end interface
interface
subroutine xcast_mpi_dp3d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:)
end subroutine xcast_mpi_dp3d
end interface
interface
subroutine xcast_mpi_dp4d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:,:)
end subroutine xcast_mpi_dp4d
end interface
interface
subroutine xcast_mpi_spv(xval,master,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: master
integer,intent(in) :: spaceComm
real,intent(inout) :: xval
end subroutine xcast_mpi_spv
end interface
interface
subroutine xcast_mpi_sp1d(xval,master,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real,intent(inout) :: xval(:)
end subroutine xcast_mpi_sp1d
end interface
interface
subroutine xcast_mpi_sp2d(xval,master,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real,intent(inout) :: xval(:,:)
end subroutine xcast_mpi_sp2d
end interface
interface
subroutine xcast_mpi_sp3d(xval,master,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real,intent(inout) :: xval(:,:,:)
end subroutine xcast_mpi_sp3d
end interface
interface
subroutine xcast_mpi_sp4d(xval,master,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real,intent(inout) :: xval(:,:,:,:)
end subroutine xcast_mpi_sp4d
end interface
interface
subroutine xcast_mpi_cplxv(xval,master,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex,intent(inout) :: xval
end subroutine xcast_mpi_cplxv
end interface
interface
subroutine xcast_mpi_cplx1d(xval,master,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex,intent(inout) :: xval(:)
end subroutine xcast_mpi_cplx1d
end interface
interface
subroutine xcast_mpi_cplx2d(xval,master,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex,intent(inout) :: xval(:,:)
end subroutine xcast_mpi_cplx2d
end interface
interface
subroutine xcast_mpi_cplx3d(xval,master,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex,intent(inout) :: xval(:,:,:)
end subroutine xcast_mpi_cplx3d
end interface
interface
subroutine xcast_mpi_cplx4d(xval,master,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex,intent(inout) :: xval(:,:,:,:)
end subroutine xcast_mpi_cplx4d
end interface
interface
subroutine xcast_mpi_dcv(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval
end subroutine xcast_mpi_dcv
end interface
interface
subroutine xcast_mpi_dc1d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval(:)
end subroutine xcast_mpi_dc1d
end interface
interface
subroutine xcast_mpi_dc2d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval(:,:)
end subroutine xcast_mpi_dc2d
end interface
interface
subroutine xcast_mpi_dc3d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval(:,:,:)
end subroutine xcast_mpi_dc3d
end interface
interface
subroutine xcast_mpi_dc4d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: master
integer,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval(:,:,:,:)
end subroutine xcast_mpi_dc4d
end interface
interface
subroutine xcast_mpi_ch0d(xval,master,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: master
integer,intent(in) :: spaceComm
character(len=*),intent(inout) :: xval
end subroutine xcast_mpi_ch0d
end interface
interface
subroutine xcast_mpi_ch1d(xval,master,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: master
integer,intent(in) :: spaceComm
character(len=*),intent(inout) :: xval(:)
end subroutine xcast_mpi_ch1d
end interface
interface
subroutine xexch_mpi_intn(vsend,n1,sender,vrecv,recever,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: n1
integer,intent(in) :: recever
integer,intent(in) :: sender
integer,intent(in) :: spaceComm
integer,intent(inout) :: vrecv(:)
integer,intent(in) :: vsend(:)
end subroutine xexch_mpi_intn
end interface
interface
subroutine xexch_mpi_int2d(vsend,nt,sender,vrecv,recever,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nt
integer,intent(in) :: recever
integer,intent(in) :: sender
integer,intent(in) :: spaceComm
integer,intent(inout) :: vrecv(:,:)
integer,intent(in) :: vsend(:,:)
end subroutine xexch_mpi_int2d
end interface
interface
subroutine xexch_mpi_dpn(vsend,n1,sender,vrecv,recever,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: n1
integer,intent(in) :: recever
integer,intent(in) :: sender
integer,intent(in) :: spaceComm
real(dp),intent(inout) :: vrecv(:)
real(dp),intent(in) :: vsend(:)
end subroutine xexch_mpi_dpn
end interface
interface
subroutine xexch_mpi_dp2d(vsend,nt,sender,vrecv,recever,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nt
integer,intent(in) :: recever
integer,intent(in) :: sender
integer,intent(in) :: spaceComm
real(dp),intent(inout) :: vrecv(:,:)
real(dp),intent(in) :: vsend(:,:)
end subroutine xexch_mpi_dp2d
end interface
interface
subroutine xexch_mpi_dp3d(vsend,nt,sender,vrecv,recever,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nt
integer,intent(in) :: recever
integer,intent(in) :: sender
integer,intent(in) :: spaceComm
real(dp),intent(inout) :: vrecv(:,:,:)
real(dp),intent(in) :: vsend(:,:,:)
end subroutine xexch_mpi_dp3d
end interface
interface
subroutine xexch_mpi_dp4d_tag(vsend,mtag,sender,vrecv,recever,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: mtag
integer,intent(in) :: recever
integer,intent(in) :: sender
integer,intent(in) :: spaceComm
real(dp),intent(inout) :: vrecv(:,:,:,:)
real(dp),intent(in) :: vsend(:,:,:,:)
end subroutine xexch_mpi_dp4d_tag
end interface
interface
subroutine xexch_mpi_dp5d_tag(vsend,mtag,sender,vrecv,recever,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: mtag
integer,intent(in) :: recever
integer,intent(in) :: sender
integer,intent(in) :: spaceComm
real(dp),intent(inout) :: vrecv(:,:,:,:,:)
real(dp),intent(in) :: vsend(:,:,:,:,:)
end subroutine xexch_mpi_dp5d_tag
end interface
interface
subroutine xexch_mpi_spc_1d(vsend,n1,sender,vrecv,recever,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: n1
integer,intent(in) :: recever
integer,intent(in) :: sender
integer,intent(in) :: spaceComm
complex(spc),intent(inout) :: vrecv(:)
complex(spc),intent(in) :: vsend(:)
end subroutine xexch_mpi_spc_1d
end interface
interface
subroutine xexch_mpi_dpc_1d(vsend,n1,sender,vrecv,recever,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: n1
integer,intent(in) :: recever
integer,intent(in) :: sender
integer,intent(in) :: spaceComm
complex(dpc),intent(inout) :: vrecv(:)
complex(dpc),intent(in) :: vsend(:)
end subroutine xexch_mpi_dpc_1d
end interface
interface
subroutine xexch_mpi_dpc_2d(vsend,nt,sender,vrecv,recever,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nt
integer,intent(in) :: recever
integer,intent(in) :: sender
integer,intent(in) :: spaceComm
complex(dpc),intent(inout) :: vrecv(:,:)
complex(dpc),intent(in) :: vsend(:,:)
end subroutine xexch_mpi_dpc_2d
end interface
interface
subroutine xgather_mpi_int(xval,sendcount,recvbuf,recvcount,root,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer :: recvcount
integer,intent(in) :: root
integer :: sendcount
integer,intent(in) :: spaceComm
integer,intent(inout) :: recvbuf(:)
integer,intent(in) :: xval(:)
end subroutine xgather_mpi_int
end interface
interface
subroutine xgather_mpi_int2d(xval,sendcount,recvbuf,recvcount,root,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer :: recvcount
integer,intent(in) :: root
integer :: sendcount
integer,intent(in) :: spaceComm
integer,intent(inout) :: recvbuf(:,:)
integer,intent(in) :: xval(:,:)
end subroutine xgather_mpi_int2d
end interface
interface
subroutine xgather_mpi_dp(xval,sendcount,recvbuf,recvcount,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer :: recvcount
integer,intent(in) :: root
integer :: sendcount
integer,intent(in) :: spaceComm
real(dp),intent(inout) :: recvbuf(:)
real(dp),intent(in) :: xval(:)
end subroutine xgather_mpi_dp
end interface
interface
subroutine xgather_mpi_dp2d(xval,sendcount,recvbuf,recvcount,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer :: recvcount
integer,intent(in) :: root
integer :: sendcount
integer,intent(in) :: spaceComm
real(dp),intent(inout) :: recvbuf(:,:)
real(dp),intent(in) :: xval(:,:)
end subroutine xgather_mpi_dp2d
end interface
interface
subroutine xgather_mpi_dp3d(xval,sendcount,recvbuf,recvcount,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer :: recvcount
integer,intent(in) :: root
integer :: sendcount
integer,intent(in) :: spaceComm
real(dp),intent(inout) :: recvbuf(:,:,:)
real(dp),intent(in) :: xval(:,:,:)
end subroutine xgather_mpi_dp3d
end interface
interface
subroutine xgather_mpi_dp4d(xval,sendcount,recvbuf,recvcount,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer :: recvcount
integer,intent(in) :: root
integer :: sendcount
integer,intent(in) :: spaceComm
real(dp),intent(inout) :: recvbuf(:,:,:,:)
real(dp),intent(in) :: xval(:,:,:,:)
end subroutine xgather_mpi_dp4d
end interface
interface
subroutine xgatherv_mpi_int(xval,nelem,recvbuf,recvcounts,displs,root,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(inout) :: recvbuf(:)
integer,intent(in) :: recvcounts(:)
integer,intent(in) :: xval(:)
end subroutine xgatherv_mpi_int
end interface
interface
subroutine xgatherv_mpi_int2d(xval,nelem,recvbuf,recvcounts,displs,root,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(inout) :: recvbuf(:,:)
integer,intent(in) :: recvcounts(:)
integer,intent(in) :: xval(:,:)
end subroutine xgatherv_mpi_int2d
end interface
interface
subroutine xgatherv_mpi_dp(xval,nelem,recvbuf,recvcounts,displs,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: recvcounts(:)
real(dp),intent(inout) :: recvbuf(:)
real(dp),intent(in) :: xval(:)
end subroutine xgatherv_mpi_dp
end interface
interface
subroutine xgatherv_mpi_dp2d(xval,nelem,recvbuf,recvcounts,displs,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: recvcounts(:)
real(dp),intent(inout) :: recvbuf(:,:)
real(dp),intent(in) :: xval(:,:)
end subroutine xgatherv_mpi_dp2d
end interface
interface
subroutine xgatherv_mpi_dp3d(xval,nelem,recvbuf,recvcounts,displs,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: recvcounts(:)
real(dp),intent(inout) :: recvbuf(:,:,:)
real(dp),intent(in) :: xval(:,:,:)
end subroutine xgatherv_mpi_dp3d
end interface
interface
subroutine xgatherv_mpi_dp4d(xval,nelem,recvbuf,recvcounts,displs,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: nelem
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: recvcounts(:)
real(dp),intent(inout) :: recvbuf(:,:,:,:)
real(dp),intent(in) :: xval(:,:,:,:)
end subroutine xgatherv_mpi_dp4d
end interface
interface
subroutine xmax_mpi_intv(xval,xmax,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
integer ,intent(inout) :: xmax
integer ,intent(inout) :: xval
end subroutine xmax_mpi_intv
end interface
interface
subroutine xmax_mpi_dpv(xval,xmax,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xmax
real(dp),intent(inout) :: xval
end subroutine xmax_mpi_dpv
end interface
interface
subroutine xmin_mpi_intv(xval,xmin,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
integer ,intent(inout) :: xmin
integer ,intent(inout) :: xval
end subroutine xmin_mpi_intv
end interface
interface
subroutine xmin_mpi_dpv(xval,xmin,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xmin
real(dp),intent(inout) :: xval
end subroutine xmin_mpi_dpv
end interface
interface
subroutine xrecv_mpi_intv(xval,source,tag,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: source
integer,intent(in) :: spaceComm
integer,intent(in) :: tag
integer,intent(inout) :: xval
end subroutine xrecv_mpi_intv
end interface
interface
subroutine xrecv_mpi_dp2d(xval,source,tag,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: source
integer ,intent(in) :: spaceComm
integer ,intent(in) :: tag
real(dp),intent(inout) :: xval(:,:)
end subroutine xrecv_mpi_dp2d
end interface
interface
subroutine xrecv_mpi_dp3d(xval,source,tag,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: source
integer ,intent(in) :: spaceComm
integer ,intent(in) :: tag
real(dp),intent(inout) :: xval(:,:,:)
end subroutine xrecv_mpi_dp3d
end interface
interface
subroutine xscatterv_mpi_int(xval,sendcounts,displs,recvbuf,recvcount,root,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: recvcount
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(inout) :: recvbuf(:)
integer,intent(in) :: sendcounts(:)
integer,intent(in) :: xval(:)
end subroutine xscatterv_mpi_int
end interface
interface
subroutine xscatterv_mpi_int2d(xval,sendcounts,displs,recvbuf,recvcount,root,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: recvcount
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(inout) :: recvbuf(:,:)
integer,intent(in) :: sendcounts(:)
integer,intent(in) :: xval(:,:)
end subroutine xscatterv_mpi_int2d
end interface
interface
subroutine xscatterv_mpi_dp(xval,sendcounts,displs,recvbuf,recvcount,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: recvcount
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: sendcounts(:)
real(dp),intent(inout) :: recvbuf(:)
real(dp),intent(in) :: xval(:)
end subroutine xscatterv_mpi_dp
end interface
interface
subroutine xscatterv_mpi_dp2d(xval,sendcounts,displs,recvbuf,recvcount,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: recvcount
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: sendcounts(:)
real(dp),intent(inout) :: recvbuf(:,:)
real(dp),intent(in) :: xval(:,:)
end subroutine xscatterv_mpi_dp2d
end interface
interface
subroutine xscatterv_mpi_dp3d(xval,sendcounts,displs,recvbuf,recvcount,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: recvcount
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: sendcounts(:)
real(dp),intent(inout) :: recvbuf(:,:,:)
real(dp),intent(in) :: xval(:,:,:)
end subroutine xscatterv_mpi_dp3d
end interface
interface
subroutine xscatterv_mpi_dp4d(xval,sendcounts,displs,recvbuf,recvcount,root,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: recvcount
integer,intent(in) :: root
integer,intent(in) :: spaceComm
integer,intent(in) :: displs(:)
integer,intent(in) :: sendcounts(:)
real(dp),intent(inout) :: recvbuf(:,:,:,:)
real(dp),intent(in) :: xval(:,:,:,:)
end subroutine xscatterv_mpi_dp4d
end interface
interface
subroutine xsend_mpi_intv(xval,dest,tag,spaceComm,ier)
implicit none
integer,intent(in) :: dest
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
integer,intent(in) :: tag
integer,intent(inout) :: xval
end subroutine xsend_mpi_intv
end interface
interface
subroutine xsend_mpi_dp2d(xval,dest,tag,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(in) :: dest
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
integer ,intent(in) :: tag
real(dp),intent(inout) :: xval(:,:)
end subroutine xsend_mpi_dp2d
end interface
interface
subroutine xsend_mpi_dp3d(xval,dest,tag,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(in) :: dest
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
integer ,intent(in) :: tag
real(dp),intent(inout) :: xval(:,:,:)
end subroutine xsend_mpi_dp3d
end interface
interface
subroutine xsum_master_int(xval,master,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
integer,intent(inout) :: xval
end subroutine xsum_master_int
end interface
interface
subroutine xsum_master_dp1d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:)
end subroutine xsum_master_dp1d
end interface
interface
subroutine xsum_master_dp2d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:)
end subroutine xsum_master_dp2d
end interface
interface
subroutine xsum_master_dp3d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:)
end subroutine xsum_master_dp3d
end interface
interface
subroutine xsum_master_dp4d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:,:)
end subroutine xsum_master_dp4d
end interface
interface
subroutine xsum_master_dp5d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:,:,:)
end subroutine xsum_master_dp5d
end interface
interface
subroutine xsum_master_dp6d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:,:,:,:)
end subroutine xsum_master_dp6d
end interface
interface
subroutine xsum_master_dp7d(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:,:,:,:,:)
end subroutine xsum_master_dp7d
end interface
interface
subroutine xsum_master_int4d(xval,master,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
integer ,intent(inout) :: xval(:,:,:,:)
end subroutine xsum_master_int4d
end interface
interface
subroutine xsum_master_c1cplx(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex(spc),intent(inout) :: xval(:)
end subroutine xsum_master_c1cplx
end interface
interface
subroutine xsum_master_c2cplx(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex(spc),intent(inout) :: xval(:,:)
end subroutine xsum_master_c2cplx
end interface
interface
subroutine xsum_master_c3cplx(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex(spc),intent(inout) :: xval(:,:,:)
end subroutine xsum_master_c3cplx
end interface
interface
subroutine xsum_master_c4cplx(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex(spc),intent(inout) :: xval(:,:,:,:)
end subroutine xsum_master_c4cplx
end interface
interface
subroutine xsum_master_c5cplx(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: master
integer,intent(in) :: spaceComm
complex(spc) ,intent(inout) :: xval(:,:,:,:,:)
end subroutine xsum_master_c5cplx
end interface
interface
subroutine xsum_master_c1dpc(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: master
integer,intent(in) :: spaceComm
complex(dpc) ,intent(inout) :: xval(:)
end subroutine xsum_master_c1dpc
end interface
interface
subroutine xsum_master_c2dpc(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex(dpc) ,intent(inout) :: xval(:,:)
end subroutine xsum_master_c2dpc
end interface
interface
subroutine xsum_master_c3dpc(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex(dpc) ,intent(inout) :: xval(:,:,:)
end subroutine xsum_master_c3dpc
end interface
interface
subroutine xsum_master_c4dpc(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: master
integer ,intent(in) :: spaceComm
complex(dpc) ,intent(inout) :: xval(:,:,:,:)
end subroutine xsum_master_c4dpc
end interface
interface
subroutine xsum_master_c5dpc(xval,master,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: master
integer,intent(in) :: spaceComm
complex(dpc) ,intent(inout) :: xval(:,:,:,:,:)
end subroutine xsum_master_c5dpc
end interface
interface
subroutine xsum_mpi_int(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
integer,intent(inout) :: xval(:)
end subroutine xsum_mpi_int
end interface
interface
subroutine xsum_mpi_intv(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
integer,intent(inout) :: xval
end subroutine xsum_mpi_intv
end interface
interface
subroutine xsum_mpi_intv2(xval,xsum,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
integer,intent(inout) :: xsum
integer,intent(inout) :: xval
end subroutine xsum_mpi_intv2
end interface
interface
subroutine xsum_mpi_intn(xval,n1,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: n1
integer,intent(in) :: spaceComm
integer,intent(inout) :: xval(:)
end subroutine xsum_mpi_intn
end interface
interface
subroutine xsum_mpi_int2t(xval,xsum,n1,spaceComm,ier)
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: n1
integer ,intent(in) :: spaceComm
integer ,intent(inout) :: xsum(:)
integer ,intent(inout) :: xval(:)
end subroutine xsum_mpi_int2t
end interface
interface
subroutine xsum_mpi_int2d(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
integer,intent(inout) :: xval(:,:)
end subroutine xsum_mpi_int2d
end interface
interface
subroutine xsum_mpi_int3d(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
integer,intent(inout) :: xval(:,:,:)
end subroutine xsum_mpi_int3d
end interface
interface
subroutine xsum_mpi_int4d(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
integer,intent(inout) :: xval(:,:,:,:)
end subroutine xsum_mpi_int4d
end interface
interface
subroutine xsum_mpi_dp(xval,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:)
end subroutine xsum_mpi_dp
end interface
interface
subroutine xsum_mpi_dpvt(xval,xsum,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
real(dp),intent(out) :: xsum
real(dp),intent(in) :: xval
end subroutine xsum_mpi_dpvt
end interface
interface
subroutine xsum_mpi_dpv(xval,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval
end subroutine xsum_mpi_dpv
end interface
interface
subroutine xsum_mpi_dpn(xval,n1,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: n1
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:)
end subroutine xsum_mpi_dpn
end interface
interface
subroutine xsum_mpi_dp2d(xval,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:)
end subroutine xsum_mpi_dp2d
end interface
interface
subroutine xsum_mpi_dp3d(xval,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:)
end subroutine xsum_mpi_dp3d
end interface
interface
subroutine xsum_mpi_dp4d(xval,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:,:)
end subroutine xsum_mpi_dp4d
end interface
interface
subroutine xsum_mpi_dp5d(xval,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:,:,:)
end subroutine xsum_mpi_dp5d
end interface
interface
subroutine xsum_mpi_dp6d(xval,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:,:,:,:)
end subroutine xsum_mpi_dp6d
end interface
interface
subroutine xsum_mpi_dp7d(xval,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xval(:,:,:,:,:,:,:)
end subroutine xsum_mpi_dp7d
end interface
interface
subroutine xsum_mpi_dp2t(xval,xsum,n1,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: n1
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xsum(:)
real(dp),intent(inout) :: xval(:)
end subroutine xsum_mpi_dp2t
end interface
interface
subroutine xsum_mpi_dp3d2t(xval,xsum,n1,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: n1
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xsum(:,:,:)
real(dp),intent(inout) :: xval(:,:,:)
end subroutine xsum_mpi_dp3d2t
end interface
interface
subroutine xsum_mpi_dp4d2t(xval,xsum,n1,spaceComm,ier)
use defs_basis
implicit none
integer ,intent(out) :: ier
integer ,intent(in) :: n1
integer ,intent(in) :: spaceComm
real(dp),intent(inout) :: xsum(:,:,:,:)
real(dp),intent(inout) :: xval(:,:,:,:)
end subroutine xsum_mpi_dp4d2t
end interface
interface
subroutine xsum_mpi_c0dc(xval,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval
end subroutine xsum_mpi_c0dc
end interface
interface
subroutine xsum_mpi_c1dc(xval,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval(:)
end subroutine xsum_mpi_c1dc
end interface
interface
subroutine xsum_mpi_c2dc(xval,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval(:,:)
end subroutine xsum_mpi_c2dc
end interface
interface
subroutine xsum_mpi_c3dc(xval,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval(:,:,:)
end subroutine xsum_mpi_c3dc
end interface
interface
subroutine xsum_mpi_c4dc(xval,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval(:,:,:,:)
end subroutine xsum_mpi_c4dc
end interface
interface
subroutine xsum_mpi_c5dc(xval,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval(:,:,:,:,:)
end subroutine xsum_mpi_c5dc
end interface
interface
subroutine xsum_mpi_c6dc(xval,spaceComm,ier)
use defs_basis
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex(dpc),intent(inout) :: xval(:,:,:,:,:,:)
end subroutine xsum_mpi_c6dc
end interface
interface
subroutine xsum_mpi_c1cplx(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex,intent(inout) :: xval(:)
end subroutine xsum_mpi_c1cplx
end interface
interface
subroutine xsum_mpi_c2cplx(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex,intent(inout) :: xval(:,:)
end subroutine xsum_mpi_c2cplx
end interface
interface
subroutine xsum_mpi_c3cplx(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex,intent(inout) :: xval(:,:,:)
end subroutine xsum_mpi_c3cplx
end interface
interface
subroutine xsum_mpi_c4cplx(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex,intent(inout) :: xval(:,:,:,:)
end subroutine xsum_mpi_c4cplx
end interface
interface
subroutine xsum_mpi_c5cplx(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex,intent(inout) :: xval(:,:,:,:,:)
end subroutine xsum_mpi_c5cplx
end interface
interface
subroutine xsum_mpi_c6cplx(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
complex,intent(inout) :: xval(:,:,:,:,:,:)
end subroutine xsum_mpi_c6cplx
end interface
interface
subroutine xsum_mpi_log1d(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
logical,intent(inout) :: xval(:)
end subroutine xsum_mpi_log1d
end interface
interface
subroutine xsum_mpi_log2d(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
logical,intent(inout) :: xval(:,:)
end subroutine xsum_mpi_log2d
end interface
interface
subroutine xsum_mpi_log3d(xval,spaceComm,ier)
implicit none
integer,intent(out) :: ier
integer,intent(in) :: spaceComm
logical,intent(inout) :: xval(:,:,:)
end subroutine xsum_mpi_log3d
end interface
end module interfaces_12_hide_mpi
!!***
| gpl-3.0 |
jjones-cavium/gcc | gcc/testsuite/gfortran.dg/widechar_select_1.f90 | 174 | 1479 | ! { dg-do run }
! { dg-options "-fbackslash" }
call testme(test("foo"), test4(4_"foo"), 1)
call testme(test(""), test4(4_""), 1)
call testme(test("gee"), test4(4_"gee"), 4)
call testme(test("bar"), test4(4_"bar"), 1)
call testme(test("magi"), test4(4_"magi"), 4)
call testme(test("magic"), test4(4_"magic"), 2)
call testme(test("magic "), test4(4_"magic "), 2)
call testme(test("magica"), test4(4_"magica"), 4)
call testme(test("freeze"), test4(4_"freeze"), 3)
call testme(test("freeze "), test4(4_"freeze "), 3)
call testme(test("frugal"), test4(4_"frugal"), 3)
call testme(test("frugal "), test4(4_"frugal "), 3)
call testme(test("frugal \x01"), test4(4_"frugal \x01"), 3)
call testme(test("frugal \xFF"), test4(4_"frugal \xFF"), 4)
contains
integer function test(s)
character(len=*) :: s
select case (s)
case ("":"foo")
test = 1
case ("magic")
test = 2
case ("freeze":"frugal")
test = 3
case default
test = 4
end select
end function test
integer function test4(s)
character(kind=4,len=*) :: s
select case (s)
case (4_"":4_"foo")
test4 = 1
case (4_"magic")
test4 = 2
case (4_"freeze":4_"frugal")
test4 = 3
case default
test4 = 4
end select
end function test4
subroutine testme(x,y,z)
integer :: x, y, z
if (x /= y) call abort
if (x /= z) call abort
end subroutine testme
end
| gpl-2.0 |
haudren/scipy | scipy/optimize/minpack/r1updt.f | 125 | 5702 | subroutine r1updt(m,n,s,ls,u,v,w,sing)
integer m,n,ls
logical sing
double precision s(ls),u(m),v(n),w(m)
c **********
c
c subroutine r1updt
c
c given an m by n lower trapezoidal matrix s, an m-vector u,
c and an n-vector v, the problem is to determine an
c orthogonal matrix q such that
c
c t
c (s + u*v )*q
c
c is again lower trapezoidal.
c
c this subroutine determines q as the product of 2*(n - 1)
c transformations
c
c gv(n-1)*...*gv(1)*gw(1)*...*gw(n-1)
c
c where gv(i), gw(i) are givens rotations in the (i,n) plane
c which eliminate elements in the i-th and n-th planes,
c respectively. q itself is not accumulated, rather the
c information to recover the gv, gw rotations is returned.
c
c the subroutine statement is
c
c subroutine r1updt(m,n,s,ls,u,v,w,sing)
c
c where
c
c m is a positive integer input variable set to the number
c of rows of s.
c
c n is a positive integer input variable set to the number
c of columns of s. n must not exceed m.
c
c s is an array of length ls. on input s must contain the lower
c trapezoidal matrix s stored by columns. on output s contains
c the lower trapezoidal matrix produced as described above.
c
c ls is a positive integer input variable not less than
c (n*(2*m-n+1))/2.
c
c u is an input array of length m which must contain the
c vector u.
c
c v is an array of length n. on input v must contain the vector
c v. on output v(i) contains the information necessary to
c recover the givens rotation gv(i) described above.
c
c w is an output array of length m. w(i) contains information
c necessary to recover the givens rotation gw(i) described
c above.
c
c sing is a logical output variable. sing is set true if any
c of the diagonal elements of the output s are zero. otherwise
c sing is set false.
c
c subprograms called
c
c minpack-supplied ... dpmpar
c
c fortran-supplied ... dabs,dsqrt
c
c argonne national laboratory. minpack project. march 1980.
c burton s. garbow, kenneth e. hillstrom, jorge j. more,
c john l. nazareth
c
c **********
integer i,j,jj,l,nmj,nm1
double precision cos,cotan,giant,one,p5,p25,sin,tan,tau,temp,
* zero
double precision dpmpar
data one,p5,p25,zero /1.0d0,5.0d-1,2.5d-1,0.0d0/
c
c giant is the largest magnitude.
c
giant = dpmpar(3)
c
c initialize the diagonal element pointer.
c
jj = (n*(2*m - n + 1))/2 - (m - n)
c
c move the nontrivial part of the last column of s into w.
c
l = jj
do 10 i = n, m
w(i) = s(l)
l = l + 1
10 continue
c
c rotate the vector v into a multiple of the n-th unit vector
c in such a way that a spike is introduced into w.
c
nm1 = n - 1
if (nm1 .lt. 1) go to 70
do 60 nmj = 1, nm1
j = n - nmj
jj = jj - (m - j + 1)
w(j) = zero
if (v(j) .eq. zero) go to 50
c
c determine a givens rotation which eliminates the
c j-th element of v.
c
if (dabs(v(n)) .ge. dabs(v(j))) go to 20
cotan = v(n)/v(j)
sin = p5/dsqrt(p25+p25*cotan**2)
cos = sin*cotan
tau = one
if (dabs(cos)*giant .gt. one) tau = one/cos
go to 30
20 continue
tan = v(j)/v(n)
cos = p5/dsqrt(p25+p25*tan**2)
sin = cos*tan
tau = sin
30 continue
c
c apply the transformation to v and store the information
c necessary to recover the givens rotation.
c
v(n) = sin*v(j) + cos*v(n)
v(j) = tau
c
c apply the transformation to s and extend the spike in w.
c
l = jj
do 40 i = j, m
temp = cos*s(l) - sin*w(i)
w(i) = sin*s(l) + cos*w(i)
s(l) = temp
l = l + 1
40 continue
50 continue
60 continue
70 continue
c
c add the spike from the rank 1 update to w.
c
do 80 i = 1, m
w(i) = w(i) + v(n)*u(i)
80 continue
c
c eliminate the spike.
c
sing = .false.
if (nm1 .lt. 1) go to 140
do 130 j = 1, nm1
if (w(j) .eq. zero) go to 120
c
c determine a givens rotation which eliminates the
c j-th element of the spike.
c
if (dabs(s(jj)) .ge. dabs(w(j))) go to 90
cotan = s(jj)/w(j)
sin = p5/dsqrt(p25+p25*cotan**2)
cos = sin*cotan
tau = one
if (dabs(cos)*giant .gt. one) tau = one/cos
go to 100
90 continue
tan = w(j)/s(jj)
cos = p5/dsqrt(p25+p25*tan**2)
sin = cos*tan
tau = sin
100 continue
c
c apply the transformation to s and reduce the spike in w.
c
l = jj
do 110 i = j, m
temp = cos*s(l) + sin*w(i)
w(i) = -sin*s(l) + cos*w(i)
s(l) = temp
l = l + 1
110 continue
c
c store the information necessary to recover the
c givens rotation.
c
w(j) = tau
120 continue
c
c test for zero diagonal elements in the output s.
c
if (s(jj) .eq. zero) sing = .true.
jj = jj + (m - j + 1)
130 continue
140 continue
c
c move w back into the last column of the output s.
c
l = jj
do 150 i = n, m
s(l) = w(i)
l = l + 1
150 continue
if (s(jj) .eq. zero) sing = .true.
return
c
c last card of subroutine r1updt.
c
end
| bsd-3-clause |
slitvinov/maxima | share/lapack/lapack/fortran/dgebd2.f | 15 | 7994 | SUBROUTINE DGEBD2( M, N, A, LDA, D, E, TAUQ, TAUP, WORK, INFO )
*
* -- LAPACK routine (version 3.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* February 29, 1992
*
* .. Scalar Arguments ..
INTEGER INFO, LDA, M, N
* ..
* .. Array Arguments ..
DOUBLE PRECISION A( LDA, * ), D( * ), E( * ), TAUP( * ),
$ TAUQ( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* DGEBD2 reduces a real general m by n matrix A to upper or lower
* bidiagonal form B by an orthogonal transformation: Q' * A * P = B.
*
* If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal.
*
* Arguments
* =========
*
* M (input) INTEGER
* The number of rows in the matrix A. M >= 0.
*
* N (input) INTEGER
* The number of columns in the matrix A. N >= 0.
*
* A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
* On entry, the m by n general matrix to be reduced.
* On exit,
* if m >= n, the diagonal and the first superdiagonal are
* overwritten with the upper bidiagonal matrix B; the
* elements below the diagonal, with the array TAUQ, represent
* the orthogonal matrix Q as a product of elementary
* reflectors, and the elements above the first superdiagonal,
* with the array TAUP, represent the orthogonal matrix P as
* a product of elementary reflectors;
* if m < n, the diagonal and the first subdiagonal are
* overwritten with the lower bidiagonal matrix B; the
* elements below the first subdiagonal, with the array TAUQ,
* represent the orthogonal matrix Q as a product of
* elementary reflectors, and the elements above the diagonal,
* with the array TAUP, represent the orthogonal matrix P as
* a product of elementary reflectors.
* See Further Details.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,M).
*
* D (output) DOUBLE PRECISION array, dimension (min(M,N))
* The diagonal elements of the bidiagonal matrix B:
* D(i) = A(i,i).
*
* E (output) DOUBLE PRECISION array, dimension (min(M,N)-1)
* The off-diagonal elements of the bidiagonal matrix B:
* if m >= n, E(i) = A(i,i+1) for i = 1,2,...,n-1;
* if m < n, E(i) = A(i+1,i) for i = 1,2,...,m-1.
*
* TAUQ (output) DOUBLE PRECISION array dimension (min(M,N))
* The scalar factors of the elementary reflectors which
* represent the orthogonal matrix Q. See Further Details.
*
* TAUP (output) DOUBLE PRECISION array, dimension (min(M,N))
* The scalar factors of the elementary reflectors which
* represent the orthogonal matrix P. See Further Details.
*
* WORK (workspace) DOUBLE PRECISION array, dimension (max(M,N))
*
* INFO (output) INTEGER
* = 0: successful exit.
* < 0: if INFO = -i, the i-th argument had an illegal value.
*
* Further Details
* ===============
*
* The matrices Q and P are represented as products of elementary
* reflectors:
*
* If m >= n,
*
* Q = H(1) H(2) . . . H(n) and P = G(1) G(2) . . . G(n-1)
*
* Each H(i) and G(i) has the form:
*
* H(i) = I - tauq * v * v' and G(i) = I - taup * u * u'
*
* where tauq and taup are real scalars, and v and u are real vectors;
* v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in A(i+1:m,i);
* u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in A(i,i+2:n);
* tauq is stored in TAUQ(i) and taup in TAUP(i).
*
* If m < n,
*
* Q = H(1) H(2) . . . H(m-1) and P = G(1) G(2) . . . G(m)
*
* Each H(i) and G(i) has the form:
*
* H(i) = I - tauq * v * v' and G(i) = I - taup * u * u'
*
* where tauq and taup are real scalars, and v and u are real vectors;
* v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in A(i+2:m,i);
* u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n);
* tauq is stored in TAUQ(i) and taup in TAUP(i).
*
* The contents of A on exit are illustrated by the following examples:
*
* m = 6 and n = 5 (m > n): m = 5 and n = 6 (m < n):
*
* ( d e u1 u1 u1 ) ( d u1 u1 u1 u1 u1 )
* ( v1 d e u2 u2 ) ( e d u2 u2 u2 u2 )
* ( v1 v2 d e u3 ) ( v1 e d u3 u3 u3 )
* ( v1 v2 v3 d e ) ( v1 v2 e d u4 u4 )
* ( v1 v2 v3 v4 d ) ( v1 v2 v3 e d u5 )
* ( v1 v2 v3 v4 v5 )
*
* where d and e denote diagonal and off-diagonal elements of B, vi
* denotes an element of the vector defining H(i), and ui an element of
* the vector defining G(i).
*
* =====================================================================
*
* .. Parameters ..
DOUBLE PRECISION ZERO, ONE
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
* ..
* .. Local Scalars ..
INTEGER I
* ..
* .. External Subroutines ..
EXTERNAL DLARF, DLARFG, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC MAX, MIN
* ..
* .. Executable Statements ..
*
* Test the input parameters
*
INFO = 0
IF( M.LT.0 ) THEN
INFO = -1
ELSE IF( N.LT.0 ) THEN
INFO = -2
ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
INFO = -4
END IF
IF( INFO.LT.0 ) THEN
CALL XERBLA( 'DGEBD2', -INFO )
RETURN
END IF
*
IF( M.GE.N ) THEN
*
* Reduce to upper bidiagonal form
*
DO 10 I = 1, N
*
* Generate elementary reflector H(i) to annihilate A(i+1:m,i)
*
CALL DLARFG( M-I+1, A( I, I ), A( MIN( I+1, M ), I ), 1,
$ TAUQ( I ) )
D( I ) = A( I, I )
A( I, I ) = ONE
*
* Apply H(i) to A(i:m,i+1:n) from the left
*
CALL DLARF( 'Left', M-I+1, N-I, A( I, I ), 1, TAUQ( I ),
$ A( I, I+1 ), LDA, WORK )
A( I, I ) = D( I )
*
IF( I.LT.N ) THEN
*
* Generate elementary reflector G(i) to annihilate
* A(i,i+2:n)
*
CALL DLARFG( N-I, A( I, I+1 ), A( I, MIN( I+2, N ) ),
$ LDA, TAUP( I ) )
E( I ) = A( I, I+1 )
A( I, I+1 ) = ONE
*
* Apply G(i) to A(i+1:m,i+1:n) from the right
*
CALL DLARF( 'Right', M-I, N-I, A( I, I+1 ), LDA,
$ TAUP( I ), A( I+1, I+1 ), LDA, WORK )
A( I, I+1 ) = E( I )
ELSE
TAUP( I ) = ZERO
END IF
10 CONTINUE
ELSE
*
* Reduce to lower bidiagonal form
*
DO 20 I = 1, M
*
* Generate elementary reflector G(i) to annihilate A(i,i+1:n)
*
CALL DLARFG( N-I+1, A( I, I ), A( I, MIN( I+1, N ) ), LDA,
$ TAUP( I ) )
D( I ) = A( I, I )
A( I, I ) = ONE
*
* Apply G(i) to A(i+1:m,i:n) from the right
*
CALL DLARF( 'Right', M-I, N-I+1, A( I, I ), LDA, TAUP( I ),
$ A( MIN( I+1, M ), I ), LDA, WORK )
A( I, I ) = D( I )
*
IF( I.LT.M ) THEN
*
* Generate elementary reflector H(i) to annihilate
* A(i+2:m,i)
*
CALL DLARFG( M-I, A( I+1, I ), A( MIN( I+2, M ), I ), 1,
$ TAUQ( I ) )
E( I ) = A( I+1, I )
A( I+1, I ) = ONE
*
* Apply H(i) to A(i+1:m,i+1:n) from the left
*
CALL DLARF( 'Left', M-I, N-I, A( I+1, I ), 1, TAUQ( I ),
$ A( I+1, I+1 ), LDA, WORK )
A( I+1, I ) = E( I )
ELSE
TAUQ( I ) = ZERO
END IF
20 CONTINUE
END IF
RETURN
*
* End of DGEBD2
*
END
| gpl-2.0 |
sungsujo/nacl-llvm-branches.llvm-gcc-trunk | gcc/testsuite/gfortran.dg/char_length_5.f90 | 52 | 2036 | ! { dg-do run }
! Tests the fix for PR31867, in which the interface evaluation
! of the character length of 'join' (ie. the length available in
! the caller) was wrong.
!
! Contributed by <beliavsky@aol.com>
!
module util_mod
implicit none
contains
function join (words, sep) result(str)
character (len=*), intent(in) :: words(:),sep
character (len = (size (words) - 1) * len_trim (sep) + &
sum (len_trim (words))) :: str
integer :: i,nw
nw = size (words)
str = ""
if (nw < 1) then
return
else
str = words(1)
end if
do i=2,nw
str = trim (str) // trim (sep) // words(i)
end do
end function join
end module util_mod
!
program xjoin
use util_mod, only: join
implicit none
integer yy
character (len=5) :: words(5:8) = (/"two ","three","four ","five "/), sep = "^#^"
character (len=5) :: words2(4) = (/"bat ","ball ","goal ","stump"/), sep2 = "&"
if (join (words, sep) .ne. "two^#^three^#^four^#^five") call abort ()
if (len (join (words, sep)) .ne. 25) call abort ()
if (join (words(5:6), sep) .ne. "two^#^three") call abort ()
if (len (join (words(5:6), sep)) .ne. 11) call abort ()
if (join (words(7:8), sep) .ne. "four^#^five") call abort ()
if (len (join (words(7:8), sep)) .ne. 11) call abort ()
if (join (words(5:7:2), sep) .ne. "two^#^four") call abort ()
if (len (join (words(5:7:2), sep)) .ne. 10) call abort ()
if (join (words(6:8:2), sep) .ne. "three^#^five") call abort ()
if (len (join (words(6:8:2), sep)) .ne. 12) call abort ()
if (join (words2, sep2) .ne. "bat&ball&goal&stump") call abort ()
if (len (join (words2, sep2)) .ne. 19) call abort ()
if (join (words2(1:2), sep2) .ne. "bat&ball") call abort ()
if (len (join (words2(1:2), sep2)) .ne. 8) call abort ()
if (join (words2(2:4:2), sep2) .ne. "ball&stump") call abort ()
if (len (join (words2(2:4:2), sep2)) .ne. 10) call abort ()
end program xjoin
! { dg-final { cleanup-modules "util_mod" } }
| gpl-2.0 |
jjones-cavium/gcc | gcc/testsuite/gfortran.dg/char_length_5.f90 | 52 | 2036 | ! { dg-do run }
! Tests the fix for PR31867, in which the interface evaluation
! of the character length of 'join' (ie. the length available in
! the caller) was wrong.
!
! Contributed by <beliavsky@aol.com>
!
module util_mod
implicit none
contains
function join (words, sep) result(str)
character (len=*), intent(in) :: words(:),sep
character (len = (size (words) - 1) * len_trim (sep) + &
sum (len_trim (words))) :: str
integer :: i,nw
nw = size (words)
str = ""
if (nw < 1) then
return
else
str = words(1)
end if
do i=2,nw
str = trim (str) // trim (sep) // words(i)
end do
end function join
end module util_mod
!
program xjoin
use util_mod, only: join
implicit none
integer yy
character (len=5) :: words(5:8) = (/"two ","three","four ","five "/), sep = "^#^"
character (len=5) :: words2(4) = (/"bat ","ball ","goal ","stump"/), sep2 = "&"
if (join (words, sep) .ne. "two^#^three^#^four^#^five") call abort ()
if (len (join (words, sep)) .ne. 25) call abort ()
if (join (words(5:6), sep) .ne. "two^#^three") call abort ()
if (len (join (words(5:6), sep)) .ne. 11) call abort ()
if (join (words(7:8), sep) .ne. "four^#^five") call abort ()
if (len (join (words(7:8), sep)) .ne. 11) call abort ()
if (join (words(5:7:2), sep) .ne. "two^#^four") call abort ()
if (len (join (words(5:7:2), sep)) .ne. 10) call abort ()
if (join (words(6:8:2), sep) .ne. "three^#^five") call abort ()
if (len (join (words(6:8:2), sep)) .ne. 12) call abort ()
if (join (words2, sep2) .ne. "bat&ball&goal&stump") call abort ()
if (len (join (words2, sep2)) .ne. 19) call abort ()
if (join (words2(1:2), sep2) .ne. "bat&ball") call abort ()
if (len (join (words2(1:2), sep2)) .ne. 8) call abort ()
if (join (words2(2:4:2), sep2) .ne. "ball&stump") call abort ()
if (len (join (words2(2:4:2), sep2)) .ne. 10) call abort ()
end program xjoin
! { dg-final { cleanup-modules "util_mod" } }
| gpl-2.0 |
SCECcode/BBP | bbp/src/ucsb/GreenBank/source.f | 1 | 1498 | c***************************************************************
c F-K: @(#) source.f 1.0 4/29/2000
c
c Copyright (c) 2000 by L. Zhu
c See README file for copying and redistribution conditions.
c
c Setup the displacement-stress vector jump across the source
c The coefficients can be all derived from the potential jump in
c Haskell (1964), or directly from Takiuchi and Saito (1972)
c
c Input:
c src --- source type, 0=ex; 1=sf; 2=dc
c k --- wavenumber
c xi --- mu/(lambda+2*mu) at the source
c mu --- shear module
c Output:
c s(3,6) --- source coef. for n=0, 1, 2
c
c called by: kernel() in kernel.f
c
c modified history:
c May 12, 2000 Lupei Zhu initial coding
c July 17, 2000 Lupei Zhu change xi, mu to be complex
c***************************************************************
subroutine source(src, k, xi, mu, s)
integer i, j, src
real k
complex s(3,6), xi, mu
do i = 1, 3
do j = 1, 6
s(i,j) = 0.
enddo
enddo
if (src .EQ. 2) then ! DOUBLE_COUPLE
s(1,2) = 2.*xi/mu
s(1,4) = 4.*xi-3.
s(2,1) = 1./mu
s(2,5) =-s(2,1)
s(3,4) = 1.
s(3,6) =-1.
else if (src .EQ. 0) then ! EXPLOSION
s(1,2) = xi/mu
s(1,4) = 2.*xi
else if (src .EQ. 1) then ! SINGLE_FORCE
s(1,3) = -1./k
s(2,4) = -s(1,3)
s(2,6) = s(1,3)
else ! unknow source type
write(0,*)'unknown source type'
stop
endif
return
end
| apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.