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
tectronics/force-distribution-analysis.gromacs-4-5-3
src/gmxlib/nonbonded/nb_kernel_power6/pwr6kernel331.F
3
26907
C C This source code is part of C C G R O M A C S C C Copyright (c) 1991-2000, University of Groningen, The Netherlands. C Copyright (c) 2001-2009, The GROMACS Development Team C C Gromacs is a library for molecular simulation and trajectory analysis, C written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for C a full list of developers and information, check out http://www.gromacs.org C C This program is free software; you can redistribute it and/or modify it under C the terms of the GNU Lesser General Public License as published by the Free C Software Foundation; either version 2 of the License, or (at your option) any C later version. C As a special exception, you may use this file as part of a free software C library without restriction. Specifically, if other files instantiate C templates or use macros or inline functions from this file, or you compile C this file and link it with other files to produce an executable, this C file does not by itself cause the resulting executable to be covered by C the GNU Lesser General Public License. C C In plain-speak: do not worry about classes/macros/templates either - only C changes to the library have to be LGPL, not an application linking with it. C C To help fund GROMACS development, we humbly ask that you cite C the papers people have written on it - you can find them on the website! C #ifdef HAVE_CONFIG_H # include<config.h> #endif #ifdef GMX_DOUBLE # define gmxreal real*8 #else # define gmxreal real*4 #endif C C Gromacs nonbonded kernel pwr6kernel331 C Coulomb interaction: Tabulated C VdW interaction: Tabulated C water optimization: SPC/TIP3P - other atoms C Calculate forces: yes C subroutine pwr6kernel331( & nri, & iinr, & jindex, & jjnr, & shift, & shiftvec, & fshift, & gid, & pos, & faction, & charge, & facel, & krf, & crf, & Vc, & type, & ntype, & vdwparam, & Vvdw, & tabscale, & VFtab, & invsqrta, & dvda, & gbtabscale, & GBtab, & nthreads, & count, & mtx, & outeriter, & inneriter, & work) implicit none integer*4 nri,iinr(*),jindex(*),jjnr(*),shift(*) gmxreal shiftvec(*),fshift(*),pos(*),faction(*) integer*4 gid(*),type(*),ntype gmxreal charge(*),facel,krf,crf,Vc(*),vdwparam(*) gmxreal Vvdw(*),tabscale,VFtab(*) gmxreal invsqrta(*),dvda(*),gbtabscale,GBtab(*) integer*4 nthreads,count,mtx,outeriter,inneriter gmxreal work(*) integer*4 n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid integer*4 nn0,nn1,nouter,ninner gmxreal shX,shY,shZ gmxreal fscal,tx,ty,tz gmxreal jq gmxreal qq,vcoul,vctot integer*4 nti integer*4 tj gmxreal Vvdw6,Vvdwtot gmxreal Vvdw12 gmxreal r,rt,eps,eps2 integer*4 n0,nnn gmxreal Y,F,Geps,Heps2,Fp,VV gmxreal FF gmxreal fijC gmxreal fijD,fijR gmxreal ix1,iy1,iz1,fix1,fiy1,fiz1 gmxreal ix2,iy2,iz2,fix2,fiy2,fiz2 gmxreal ix3,iy3,iz3,fix3,fiy3,fiz3 gmxreal jx1,jy1,jz1,fjx1,fjy1,fjz1 gmxreal dx11,dy11,dz11,rsq11,rinv11 gmxreal dx21,dy21,dz21,rsq21,rinv21 gmxreal dx31,dy31,dz31,rsq31,rinv31 gmxreal qO,qH gmxreal c6,c12 C Initialize water data ii = iinr(1)+1 qO = facel*charge(ii) qH = facel*charge(ii+1) nti = 2*ntype*type(ii) C Reset outer and inner iteration counters nouter = 0 ninner = 0 C Loop over thread workunits 10 call pwr6kernelsync(mtx,count,nri,nthreads,nn0,nn1) if(nn1.gt.nri) nn1=nri C Start outer loop over neighborlists do n=nn0+1,nn1 C Load shift vector for this list is3 = 3*shift(n)+1 shX = shiftvec(is3) shY = shiftvec(is3+1) shZ = shiftvec(is3+2) C Load limits for loop over neighbors nj0 = jindex(n)+1 nj1 = jindex(n+1) C Get outer coordinate index ii = iinr(n)+1 ii3 = 3*ii-2 C Load i atom data, add shift vector ix1 = shX + pos(ii3+0) iy1 = shY + pos(ii3+1) iz1 = shZ + pos(ii3+2) ix2 = shX + pos(ii3+3) iy2 = shY + pos(ii3+4) iz2 = shZ + pos(ii3+5) ix3 = shX + pos(ii3+6) iy3 = shY + pos(ii3+7) iz3 = shZ + pos(ii3+8) C Zero the potential energy for this list vctot = 0 Vvdwtot = 0 C Clear i atom forces fix1 = 0 fiy1 = 0 fiz1 = 0 fix2 = 0 fiy2 = 0 fiz2 = 0 fix3 = 0 fiy3 = 0 fiz3 = 0 do k=nj0,nj1 C Get j neighbor index, and coordinate index jnr = jjnr(k)+1 j3 = 3*jnr-2 C load j atom coordinates jx1 = pos(j3+0) jy1 = pos(j3+1) jz1 = pos(j3+2) C Calculate distance dx11 = ix1 - jx1 dy11 = iy1 - jy1 dz11 = iz1 - jz1 rsq11 = dx11*dx11+dy11*dy11+dz11*dz11 dx21 = ix2 - jx1 dy21 = iy2 - jy1 dz21 = iz2 - jz1 rsq21 = dx21*dx21+dy21*dy21+dz21*dz21 dx31 = ix3 - jx1 dy31 = iy3 - jy1 dz31 = iz3 - jz1 rsq31 = dx31*dx31+dy31*dy31+dz31*dz31 C Calculate 1/r and 1/r2 C PowerPC intrinsics 1/sqrt lookup table #ifndef GMX_BLUEGENE rinv11 = frsqrtes(rsq11) #else rinv11 = frsqrte(dble(rsq11)) #endif rinv11 = (0.5*rinv11*(3.0-((rsq11*rinv11) & *rinv11))) #ifdef GMX_DOUBLE rinv11 = (0.5*rinv11*(3.0-((rsq11*rinv11) & *rinv11))) #endif C PowerPC intrinsics 1/sqrt lookup table #ifndef GMX_BLUEGENE rinv21 = frsqrtes(rsq21) #else rinv21 = frsqrte(dble(rsq21)) #endif rinv21 = (0.5*rinv21*(3.0-((rsq21*rinv21) & *rinv21))) #ifdef GMX_DOUBLE rinv21 = (0.5*rinv21*(3.0-((rsq21*rinv21) & *rinv21))) #endif C PowerPC intrinsics 1/sqrt lookup table #ifndef GMX_BLUEGENE rinv31 = frsqrtes(rsq31) #else rinv31 = frsqrte(dble(rsq31)) #endif rinv31 = (0.5*rinv31*(3.0-((rsq31*rinv31) & *rinv31))) #ifdef GMX_DOUBLE rinv31 = (0.5*rinv31*(3.0-((rsq31*rinv31) & *rinv31))) #endif C Load parameters for j atom jq = charge(jnr+0) qq = qO*jq tj = nti+2*type(jnr)+1 c6 = vdwparam(tj) c12 = vdwparam(tj+1) C Calculate table index r = rsq11*rinv11 C Calculate table index rt = r*tabscale n0 = rt eps = rt-n0 eps2 = eps*eps nnn = 12*n0+1 C Tabulated coulomb interaction Y = VFtab(nnn) F = VFtab(nnn+1) Geps = eps*VFtab(nnn+2) Heps2 = eps2*VFtab(nnn+3) Fp = F+Geps+Heps2 VV = Y+eps*Fp FF = Fp+Geps+2.0*Heps2 vcoul = qq*VV fijC = qq*FF vctot = vctot + vcoul C Tabulated VdW interaction - dispersion nnn = nnn+4 Y = VFtab(nnn) F = VFtab(nnn+1) Geps = eps*VFtab(nnn+2) Heps2 = eps2*VFtab(nnn+3) Fp = F+Geps+Heps2 VV = Y+eps*Fp FF = Fp+Geps+2.0*Heps2 Vvdw6 = c6*VV fijD = c6*FF C Tabulated VdW interaction - repulsion nnn = nnn+4 Y = VFtab(nnn) F = VFtab(nnn+1) Geps = eps*VFtab(nnn+2) Heps2 = eps2*VFtab(nnn+3) Fp = F+Geps+Heps2 VV = Y+eps*Fp FF = Fp+Geps+2.0*Heps2 Vvdw12 = c12*VV fijR = c12*FF Vvdwtot = Vvdwtot+ Vvdw6 + Vvdw12 fscal = -((fijC+fijD+fijR)*tabscale)*rinv11 C Calculate temporary vectorial force tx = fscal*dx11 ty = fscal*dy11 tz = fscal*dz11 C Increment i atom force fix1 = fix1 + tx fiy1 = fiy1 + ty fiz1 = fiz1 + tz C Decrement j atom force fjx1 = faction(j3+0) - tx fjy1 = faction(j3+1) - ty fjz1 = faction(j3+2) - tz C Load parameters for j atom qq = qH*jq C Calculate table index r = rsq21*rinv21 C Calculate table index rt = r*tabscale n0 = rt eps = rt-n0 eps2 = eps*eps nnn = 12*n0+1 C Tabulated coulomb interaction Y = VFtab(nnn) F = VFtab(nnn+1) Geps = eps*VFtab(nnn+2) Heps2 = eps2*VFtab(nnn+3) Fp = F+Geps+Heps2 VV = Y+eps*Fp FF = Fp+Geps+2.0*Heps2 vcoul = qq*VV fijC = qq*FF vctot = vctot + vcoul fscal = -((fijC)*tabscale)*rinv21 C Calculate temporary vectorial force tx = fscal*dx21 ty = fscal*dy21 tz = fscal*dz21 C Increment i atom force fix2 = fix2 + tx fiy2 = fiy2 + ty fiz2 = fiz2 + tz C Decrement j atom force fjx1 = fjx1 - tx fjy1 = fjy1 - ty fjz1 = fjz1 - tz C Load parameters for j atom C Calculate table index r = rsq31*rinv31 C Calculate table index rt = r*tabscale n0 = rt eps = rt-n0 eps2 = eps*eps nnn = 12*n0+1 C Tabulated coulomb interaction Y = VFtab(nnn) F = VFtab(nnn+1) Geps = eps*VFtab(nnn+2) Heps2 = eps2*VFtab(nnn+3) Fp = F+Geps+Heps2 VV = Y+eps*Fp FF = Fp+Geps+2.0*Heps2 vcoul = qq*VV fijC = qq*FF vctot = vctot + vcoul fscal = -((fijC)*tabscale)*rinv31 C Calculate temporary vectorial force tx = fscal*dx31 ty = fscal*dy31 tz = fscal*dz31 C Increment i atom force fix3 = fix3 + tx fiy3 = fiy3 + ty fiz3 = fiz3 + tz C Decrement j atom force faction(j3+0) = fjx1 - tx faction(j3+1) = fjy1 - ty faction(j3+2) = fjz1 - tz C Inner loop uses 154 flops/iteration end do C Add i forces to mem and shifted force list faction(ii3+0) = faction(ii3+0) + fix1 faction(ii3+1) = faction(ii3+1) + fiy1 faction(ii3+2) = faction(ii3+2) + fiz1 faction(ii3+3) = faction(ii3+3) + fix2 faction(ii3+4) = faction(ii3+4) + fiy2 faction(ii3+5) = faction(ii3+5) + fiz2 faction(ii3+6) = faction(ii3+6) + fix3 faction(ii3+7) = faction(ii3+7) + fiy3 faction(ii3+8) = faction(ii3+8) + fiz3 fshift(is3) = fshift(is3)+fix1+fix2+fix3 fshift(is3+1) = fshift(is3+1)+fiy1+fiy2+fiy3 fshift(is3+2) = fshift(is3+2)+fiz1+fiz2+fiz3 C Add potential energies to the group for this list ggid = gid(n)+1 Vc(ggid) = Vc(ggid) + vctot Vvdw(ggid) = Vvdw(ggid) + Vvdwtot C Increment number of inner iterations ninner = ninner + nj1 - nj0 C Outer loop uses 29 flops/iteration end do C Increment number of outer iterations nouter = nouter + nn1 - nn0 if(nn1.lt.nri) goto 10 C Write outer/inner iteration count to pointers outeriter = nouter inneriter = ninner return end C C Gromacs nonbonded kernel pwr6kernel331nf C Coulomb interaction: Tabulated C VdW interaction: Tabulated C water optimization: SPC/TIP3P - other atoms C Calculate forces: no C subroutine pwr6kernel331nf( & nri, & iinr, & jindex, & jjnr, & shift, & shiftvec, & fshift, & gid, & pos, & faction, & charge, & facel, & krf, & crf, & Vc, & type, & ntype, & vdwparam, & Vvdw, & tabscale, & VFtab, & invsqrta, & dvda, & gbtabscale, & GBtab, & nthreads, & count, & mtx, & outeriter, & inneriter, & work) implicit none integer*4 nri,iinr(*),jindex(*),jjnr(*),shift(*) gmxreal shiftvec(*),fshift(*),pos(*),faction(*) integer*4 gid(*),type(*),ntype gmxreal charge(*),facel,krf,crf,Vc(*),vdwparam(*) gmxreal Vvdw(*),tabscale,VFtab(*) gmxreal invsqrta(*),dvda(*),gbtabscale,GBtab(*) integer*4 nthreads,count,mtx,outeriter,inneriter gmxreal work(*) integer*4 n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid integer*4 nn0,nn1,nouter,ninner gmxreal shX,shY,shZ gmxreal jq gmxreal qq,vcoul,vctot integer*4 nti integer*4 tj gmxreal Vvdw6,Vvdwtot gmxreal Vvdw12 gmxreal r,rt,eps,eps2 integer*4 n0,nnn gmxreal Y,F,Geps,Heps2,Fp,VV gmxreal ix1,iy1,iz1 gmxreal ix2,iy2,iz2 gmxreal ix3,iy3,iz3 gmxreal jx1,jy1,jz1 gmxreal dx11,dy11,dz11,rsq11,rinv11 gmxreal dx21,dy21,dz21,rsq21,rinv21 gmxreal dx31,dy31,dz31,rsq31,rinv31 gmxreal qO,qH gmxreal c6,c12 C Initialize water data ii = iinr(1)+1 qO = facel*charge(ii) qH = facel*charge(ii+1) nti = 2*ntype*type(ii) C Reset outer and inner iteration counters nouter = 0 ninner = 0 C Loop over thread workunits 10 call pwr6kernelsync(mtx,count,nri,nthreads,nn0,nn1) if(nn1.gt.nri) nn1=nri C Start outer loop over neighborlists do n=nn0+1,nn1 C Load shift vector for this list is3 = 3*shift(n)+1 shX = shiftvec(is3) shY = shiftvec(is3+1) shZ = shiftvec(is3+2) C Load limits for loop over neighbors nj0 = jindex(n)+1 nj1 = jindex(n+1) C Get outer coordinate index ii = iinr(n)+1 ii3 = 3*ii-2 C Load i atom data, add shift vector ix1 = shX + pos(ii3+0) iy1 = shY + pos(ii3+1) iz1 = shZ + pos(ii3+2) ix2 = shX + pos(ii3+3) iy2 = shY + pos(ii3+4) iz2 = shZ + pos(ii3+5) ix3 = shX + pos(ii3+6) iy3 = shY + pos(ii3+7) iz3 = shZ + pos(ii3+8) C Zero the potential energy for this list vctot = 0 Vvdwtot = 0 C Clear i atom forces do k=nj0,nj1 C Get j neighbor index, and coordinate index jnr = jjnr(k)+1 j3 = 3*jnr-2 C load j atom coordinates jx1 = pos(j3+0) jy1 = pos(j3+1) jz1 = pos(j3+2) C Calculate distance dx11 = ix1 - jx1 dy11 = iy1 - jy1 dz11 = iz1 - jz1 rsq11 = dx11*dx11+dy11*dy11+dz11*dz11 dx21 = ix2 - jx1 dy21 = iy2 - jy1 dz21 = iz2 - jz1 rsq21 = dx21*dx21+dy21*dy21+dz21*dz21 dx31 = ix3 - jx1 dy31 = iy3 - jy1 dz31 = iz3 - jz1 rsq31 = dx31*dx31+dy31*dy31+dz31*dz31 C Calculate 1/r and 1/r2 C PowerPC intrinsics 1/sqrt lookup table #ifndef GMX_BLUEGENE rinv11 = frsqrtes(rsq11) #else rinv11 = frsqrte(dble(rsq11)) #endif rinv11 = (0.5*rinv11*(3.0-((rsq11*rinv11) & *rinv11))) #ifdef GMX_DOUBLE rinv11 = (0.5*rinv11*(3.0-((rsq11*rinv11) & *rinv11))) #endif C PowerPC intrinsics 1/sqrt lookup table #ifndef GMX_BLUEGENE rinv21 = frsqrtes(rsq21) #else rinv21 = frsqrte(dble(rsq21)) #endif rinv21 = (0.5*rinv21*(3.0-((rsq21*rinv21) & *rinv21))) #ifdef GMX_DOUBLE rinv21 = (0.5*rinv21*(3.0-((rsq21*rinv21) & *rinv21))) #endif C PowerPC intrinsics 1/sqrt lookup table #ifndef GMX_BLUEGENE rinv31 = frsqrtes(rsq31) #else rinv31 = frsqrte(dble(rsq31)) #endif rinv31 = (0.5*rinv31*(3.0-((rsq31*rinv31) & *rinv31))) #ifdef GMX_DOUBLE rinv31 = (0.5*rinv31*(3.0-((rsq31*rinv31) & *rinv31))) #endif C Load parameters for j atom jq = charge(jnr+0) qq = qO*jq tj = nti+2*type(jnr)+1 c6 = vdwparam(tj) c12 = vdwparam(tj+1) C Calculate table index r = rsq11*rinv11 C Calculate table index rt = r*tabscale n0 = rt eps = rt-n0 eps2 = eps*eps nnn = 12*n0+1 C Tabulated coulomb interaction Y = VFtab(nnn) F = VFtab(nnn+1) Geps = eps*VFtab(nnn+2) Heps2 = eps2*VFtab(nnn+3) Fp = F+Geps+Heps2 VV = Y+eps*Fp vcoul = qq*VV vctot = vctot + vcoul C Tabulated VdW interaction - dispersion nnn = nnn+4 Y = VFtab(nnn) F = VFtab(nnn+1) Geps = eps*VFtab(nnn+2) Heps2 = eps2*VFtab(nnn+3) Fp = F+Geps+Heps2 VV = Y+eps*Fp Vvdw6 = c6*VV C Tabulated VdW interaction - repulsion nnn = nnn+4 Y = VFtab(nnn) F = VFtab(nnn+1) Geps = eps*VFtab(nnn+2) Heps2 = eps2*VFtab(nnn+3) Fp = F+Geps+Heps2 VV = Y+eps*Fp Vvdw12 = c12*VV Vvdwtot = Vvdwtot+ Vvdw6 + Vvdw12 C Load parameters for j atom qq = qH*jq C Calculate table index r = rsq21*rinv21 C Calculate table index rt = r*tabscale n0 = rt eps = rt-n0 eps2 = eps*eps nnn = 12*n0+1 C Tabulated coulomb interaction Y = VFtab(nnn) F = VFtab(nnn+1) Geps = eps*VFtab(nnn+2) Heps2 = eps2*VFtab(nnn+3) Fp = F+Geps+Heps2 VV = Y+eps*Fp vcoul = qq*VV vctot = vctot + vcoul C Load parameters for j atom C Calculate table index r = rsq31*rinv31 C Calculate table index rt = r*tabscale n0 = rt eps = rt-n0 eps2 = eps*eps nnn = 12*n0+1 C Tabulated coulomb interaction Y = VFtab(nnn) F = VFtab(nnn+1) Geps = eps*VFtab(nnn+2) Heps2 = eps2*VFtab(nnn+3) Fp = F+Geps+Heps2 VV = Y+eps*Fp vcoul = qq*VV vctot = vctot + vcoul C Inner loop uses 96 flops/iteration end do C Add i forces to mem and shifted force list C Add potential energies to the group for this list ggid = gid(n)+1 Vc(ggid) = Vc(ggid) + vctot Vvdw(ggid) = Vvdw(ggid) + Vvdwtot C Increment number of inner iterations ninner = ninner + nj1 - nj0 C Outer loop uses 11 flops/iteration end do C Increment number of outer iterations nouter = nouter + nn1 - nn0 if(nn1.lt.nri) goto 10 C Write outer/inner iteration count to pointers outeriter = nouter inneriter = ninner return end
gpl-2.0
ars599/mom5
src/land_lad2/lake/lake.F90
10
45363
! ============================================================================ ! lake model module ! ============================================================================ module lake_mod #ifdef INTERNAL_FILE_NML use mpp_mod, only: input_nml_file #else use fms_mod, only: open_namelist_file #endif use fms_mod, only : error_mesg, file_exist, read_data, check_nml_error, & stdlog, write_version_number, close_file, mpp_pe, mpp_root_pe, FATAL, NOTE use time_manager_mod, only: time_type, increment_time, time_type_to_real use diag_manager_mod, only: diag_axis_init, register_diag_field, & register_static_field, send_data use constants_mod, only: tfreeze, hlv, hlf, dens_h2o, PI, grav, vonkarm, & rdgas use land_constants_mod, only : & NBANDS use land_io_mod, only : read_field use lake_tile_mod, only : & lake_tile_type, lake_pars_type, lake_prog_type, read_lake_data_namelist, & lake_data_radiation, lake_data_diffusion, & lake_data_thermodynamics, & max_lev, cpw,clw,csw, lake_width_inside_lake, large_lake_sill_width, & lake_specific_width, n_outlet, outlet_face, outlet_i, outlet_j, outlet_width use land_tile_mod, only : land_tile_type, land_tile_enum_type, & first_elmt, tail_elmt, next_elmt, current_tile, operator(/=) use land_tile_diag_mod, only : register_tiled_static_field, & register_tiled_diag_field, send_tile_data, diag_buff_type, & send_tile_data_r0d_fptr, add_tiled_static_field_alias use land_data_mod, only : land_state_type, lnd use land_tile_io_mod, only : print_netcdf_error, create_tile_out_file, & read_tile_data_r1d_fptr, write_tile_data_r1d_fptr, sync_nc_files, & get_input_restart_name use nf_utils_mod, only : nfu_inq_var, nfu_def_dim, nfu_put_att use land_debug_mod, only: is_watch_point use land_utils_mod, only : put_to_tiles_r0d_fptr implicit none private ! ==== public interfaces ===================================================== public :: read_lake_namelist public :: lake_init public :: lake_end public :: save_lake_restart public :: lake_get_sfc_temp public :: lake_radiation public :: lake_diffusion public :: lake_step_1 public :: lake_step_2 public :: large_dyn_small_stat ! =====end of public interfaces ============================================== ! ==== module constants ====================================================== character(len=*), parameter, private :: & module_name = 'lake',& version = '$Id: lake.F90,v 20.0 2013/12/13 23:29:37 fms Exp $',& tagname = '$Name: tikal $' ! ==== module variables ====================================================== !---- namelist --------------------------------------------------------------- real :: init_temp = 288. ! cold-start lake T real :: init_w = 1000. ! cold-start w(l)/dz(l) real :: init_groundwater = 0. ! cold-start gw storage logical :: use_rh_feedback = .true. logical :: make_all_lakes_wide = .false. logical :: large_dyn_small_stat = .true. logical :: relayer_in_step_one = .false. logical :: float_ice_to_top = .false. logical :: wind_penetrates_ice = .false. real :: min_rat = 0.4 logical :: do_stratify = .true. character(len=16):: albedo_to_use = '' ! or 'brdf-params' real :: K_z_large = 1. real :: K_z_background = 0. real :: K_z_min = 0. real :: K_z_factor = 1. real :: c_drag = 1.2e-3 real :: lake_depth_max = 1.e10 real :: lake_depth_min = 1.99 real :: max_plain_slope = -1.e10 namelist /lake_nml/ init_temp, init_w, & init_groundwater, use_rh_feedback, cpw, clw, csw, & make_all_lakes_wide, large_dyn_small_stat, & relayer_in_step_one, float_ice_to_top, & min_rat, do_stratify, albedo_to_use, K_z_large, & K_z_background, K_z_min, K_z_factor, & lake_depth_max, lake_depth_min, max_plain_slope !---- end of namelist -------------------------------------------------------- real :: K_z_molec = 1.4e-7 real :: tc_molec = 0.59052 ! dens_h2o*clw*K_z_molec real :: tc_molec_ice = 2.5 logical :: module_is_initialized =.FALSE. logical :: use_brdf type(time_type) :: time real :: delta_time integer :: num_l ! # of water layers real, allocatable:: zfull (:) ! diag axis, dimensionless layer number real, allocatable:: zhalf (:) real :: max_rat ! ---- diagnostic field IDs integer :: id_lwc, id_swc, id_temp, id_ie, id_sn, id_bf, id_hie, id_hsn, id_hbf integer :: id_evap, id_dz, id_wl, id_ws, id_K_z, id_silld, id_sillw, id_backw integer :: id_back1 ! ==== end of module variables =============================================== ! ==== NetCDF declarations =================================================== include 'netcdf.inc' #define __NF_ASRT__(x) call print_netcdf_error((x),module_name,__LINE__) contains ! ============================================================================ subroutine read_lake_namelist() ! ---- local vars integer :: unit ! unit for namelist i/o integer :: io ! i/o status for the namelist integer :: ierr ! error code, returned by i/o routines integer :: l call read_lake_data_namelist(num_l) call write_version_number(version, tagname) #ifdef INTERNAL_FILE_NML read (input_nml_file, nml=lake_nml, iostat=io) ierr = check_nml_error(io, 'lake_nml') #else if (file_exist('input.nml')) then unit = open_namelist_file() ierr = 1; do while (ierr /= 0) read (unit, nml=lake_nml, iostat=io, end=10) ierr = check_nml_error (io, 'lake_nml') enddo 10 continue call close_file (unit) endif #endif if (mpp_pe() == mpp_root_pe()) then unit=stdlog() write(unit, nml=lake_nml) endif ! ---- set up vertical discretization allocate (zhalf(num_l+1), zfull(num_l)) zhalf(1) = 0 do l = 1, num_l; zhalf(l+1) = zhalf(l) + 1. zfull(l) = 0.5*(zhalf(l+1) + zhalf(l)) enddo max_rat = 1. / min_rat if (trim(albedo_to_use)=='brdf-params') then use_brdf = .true. else if (trim(albedo_to_use)=='') then use_brdf = .false. else call error_mesg('lake_init',& 'option albedo_to_use="'// trim(albedo_to_use)//& '" is invalid, use "brdf-params", or nothing ("")',& FATAL) endif end subroutine read_lake_namelist ! ============================================================================ ! initialize lake model subroutine lake_init ( id_lon, id_lat ) integer, intent(in) :: id_lon ! ID of land longitude (X) axis integer, intent(in) :: id_lat ! ID of land latitude (Y) axis ! ---- local vars integer :: unit ! unit for various i/o type(land_tile_enum_type) :: te,ce ! last and current tile list elements type(land_tile_type), pointer :: tile ! pointer to current tile character(len=256) :: restart_file_name logical :: restart_exists real, allocatable :: buffer(:,:),bufferc(:,:),buffert(:,:) integer i module_is_initialized = .TRUE. time = lnd%time delta_time = time_type_to_real(lnd%dt_fast) allocate(buffer (lnd%is:lnd%ie,lnd%js:lnd%je)) allocate(bufferc(lnd%is:lnd%ie,lnd%js:lnd%je)) allocate(buffert(lnd%is:lnd%ie,lnd%js:lnd%je)) IF (LARGE_DYN_SMALL_STAT) THEN call read_data('INPUT/river_data.nc', 'connected_to_next', bufferc(:,:), lnd%domain) call put_to_tiles_r0d_fptr(bufferc, lnd%tile_map, lake_connected_to_next_ptr) call read_data('INPUT/river_data.nc', 'whole_lake_area', buffer(:,:), lnd%domain) call put_to_tiles_r0d_fptr(buffer, lnd%tile_map, lake_whole_area_ptr) call read_data('INPUT/river_data.nc', 'lake_depth_sill', buffer(:,:), lnd%domain) buffer = min(buffer, lake_depth_max) buffer = max(buffer, lake_depth_min) call put_to_tiles_r0d_fptr(buffer, lnd%tile_map, lake_depth_sill_ptr) ! lake_tau is just used here as a flag for 'large lakes' ! sill width of -1 is a flag saying not to allow transient storage call read_data('INPUT/river_data.nc', 'lake_tau', buffert(:,:), lnd%domain) buffer = -1. !where (bufferc.gt.0.5) buffer = lake_width_inside_lake where (bufferc.lt.0.5 .and. buffert.gt.1.) buffer = large_lake_sill_width if (lake_specific_width) then do i = 1, n_outlet if(lnd%face.eq.outlet_face(i).and.lnd%is.le.outlet_i(i).and.lnd%ie.ge.outlet_i(i) & .and.lnd%js.le.outlet_j(i).and.lnd%je.ge.outlet_j(i)) & buffer(outlet_i(i),outlet_j(i)) = outlet_width(i) enddo endif call put_to_tiles_r0d_fptr(buffer, lnd%tile_map, lake_width_sill_ptr) buffer = 1.e8 if (max_plain_slope.gt.0.) & call read_data('INPUT/river_data.nc', 'max_slope_to_next', buffer(:,:), lnd%domain) call read_data('INPUT/river_data.nc', 'travel', buffert(:,:), lnd%domain) bufferc = 0. where (buffer.lt.max_plain_slope .and. buffert.gt.1.5) bufferc = 1. call put_to_tiles_r0d_fptr(bufferc, lnd%tile_map, lake_backwater_ptr) bufferc = 0 where (buffer.lt.max_plain_slope .and. buffert.lt.1.5) bufferc = 1. call put_to_tiles_r0d_fptr(bufferc, lnd%tile_map, lake_backwater_1_ptr) ELSE call read_data('INPUT/river_data.nc', 'whole_lake_area', bufferc(:,:), lnd%domain) call read_data('INPUT/river_data.nc', 'lake_depth_sill', buffer(:,:), lnd%domain) where (bufferc.eq.0.) buffer = 0. where (bufferc.gt.0..and.bufferc.lt.2.e10) buffer = max(2., 2.5e-4*sqrt(bufferc)) call put_to_tiles_r0d_fptr(buffer, lnd%tile_map, lake_depth_sill_ptr) call put_to_tiles_r0d_fptr(bufferc, lnd%tile_map, lake_whole_area_ptr) buffer = 4. * buffer where (bufferc.gt.2.e10) buffer = min(buffer, 60.) call read_data('INPUT/river_data.nc', 'connected_to_next', bufferc(:,:), lnd%domain) call put_to_tiles_r0d_fptr(bufferc, lnd%tile_map, lake_connected_to_next_ptr) where (bufferc.gt.0.5) buffer=lake_width_inside_lake if (make_all_lakes_wide) buffer = lake_width_inside_lake call put_to_tiles_r0d_fptr(buffer, lnd%tile_map, lake_width_sill_ptr) ENDIF deallocate (buffer, bufferc, buffert) ! -------- initialize lake state -------- te = tail_elmt (lnd%tile_map) ce = first_elmt(lnd%tile_map) do while(ce /= te) tile=>current_tile(ce) ! get pointer to current tile ce=next_elmt(ce) ! advance position to the next tile if (.not.associated(tile%lake)) cycle tile%lake%prog%dz = tile%lake%pars%depth_sill/num_l if (init_temp.ge.tfreeze) then tile%lake%prog%wl = init_w*tile%lake%prog%dz tile%lake%prog%ws = 0 else tile%lake%prog%wl = 0 tile%lake%prog%ws = init_w*tile%lake%prog%dz endif tile%lake%prog%T = init_temp tile%lake%prog%groundwater = init_groundwater tile%lake%prog%groundwater_T = init_temp enddo call get_input_restart_name('INPUT/lake.res.nc',restart_exists,restart_file_name) if (restart_exists) then call error_mesg('lake_init',& 'reading NetCDF restart "'//trim(restart_file_name)//'"',& NOTE) __NF_ASRT__(nf_open(restart_file_name,NF_NOWRITE,unit)) if(nfu_inq_var(unit, 'dz')==NF_NOERR) & call read_tile_data_r1d_fptr(unit, 'dz', lake_dz_ptr ) call read_tile_data_r1d_fptr(unit, 'temp' , lake_temp_ptr ) call read_tile_data_r1d_fptr(unit, 'wl' , lake_wl_ptr ) call read_tile_data_r1d_fptr(unit, 'ws' , lake_ws_ptr ) call read_tile_data_r1d_fptr(unit, 'groundwater' , lake_gw_ptr ) call read_tile_data_r1d_fptr(unit, 'groundwater_T', lake_gwT_ptr) __NF_ASRT__(nf_close(unit)) else call error_mesg('lake_init',& 'cold-starting lake',& NOTE) endif call lake_diag_init ( id_lon, id_lat ) ! ---- static diagnostic section call send_tile_data_r0d_fptr(id_sillw, lnd%tile_map, lake_width_sill_ptr) call send_tile_data_r0d_fptr(id_silld, lnd%tile_map, lake_depth_sill_ptr) call send_tile_data_r0d_fptr(id_backw, lnd%tile_map, lake_backwater_ptr) call send_tile_data_r0d_fptr(id_back1, lnd%tile_map, lake_backwater_1_ptr) end subroutine lake_init ! ============================================================================ subroutine lake_end () deallocate (zfull, zhalf) module_is_initialized =.FALSE. end subroutine lake_end ! ============================================================================ subroutine save_lake_restart (tile_dim_length, timestamp) integer, intent(in) :: tile_dim_length ! length of tile dim. in the output file character(*), intent(in) :: timestamp ! timestamp to add to the file name ! ---- local vars ---------------------------------------------------------- integer :: unit ! restart file i/o unit call error_mesg('lake_end','writing NetCDF restart',NOTE) call create_tile_out_file(unit,'RESTART/'//trim(timestamp)//'lake.res.nc', & lnd%coord_glon, lnd%coord_glat, lake_tile_exists, tile_dim_length) ! in addition, define vertical coordinate if (mpp_pe()==lnd%io_pelist(1)) then __NF_ASRT__(nfu_def_dim(unit,'zfull',zfull(1:num_l),'full level','m')) __NF_ASRT__(nfu_put_att(unit,'zfull','positive','down')) endif call sync_nc_files(unit) ! write out fields call write_tile_data_r1d_fptr(unit,'dz' ,lake_dz_ptr, 'zfull','layer thickness','m') call write_tile_data_r1d_fptr(unit,'temp' ,lake_temp_ptr,'zfull','lake temperature','degrees_K') call write_tile_data_r1d_fptr(unit,'wl' ,lake_wl_ptr ,'zfull','liquid water content','kg/m2') call write_tile_data_r1d_fptr(unit,'ws' ,lake_ws_ptr ,'zfull','solid water content','kg/m2') call write_tile_data_r1d_fptr(unit,'groundwater' ,lake_gw_ptr ,'zfull') call write_tile_data_r1d_fptr(unit,'groundwater_T',lake_gwT_ptr ,'zfull') ! close file __NF_ASRT__(nf_close(unit)) end subroutine save_lake_restart ! ============================================================================ subroutine lake_get_sfc_temp(lake, lake_T) type(lake_tile_type), intent(in) :: lake real, intent(out) :: lake_T lake_T = lake%prog(1)%T end subroutine lake_get_sfc_temp ! ============================================================================ ! compute lake-only radiation properties subroutine lake_radiation ( lake, cosz, & lake_refl_dir, lake_refl_dif, lake_refl_lw, lake_emis ) type(lake_tile_type), intent(in) :: lake real, intent(in) :: cosz real, intent(out) :: lake_refl_dir(NBANDS), lake_refl_dif(NBANDS), lake_refl_lw, lake_emis call lake_data_radiation ( lake, cosz, use_brdf, lake_refl_dir, lake_refl_dif, lake_emis ) lake_refl_lw = 1 - lake_emis end subroutine lake_radiation ! ============================================================================ ! compute lake-only roughness parameters subroutine lake_diffusion ( lake, lake_z0s, lake_z0m ) type(lake_tile_type), intent(in) :: lake real, intent(out) :: lake_z0s, lake_z0m call lake_data_diffusion ( lake, lake_z0s, lake_z0m ) end subroutine lake_diffusion ! ============================================================================ ! update lake properties explicitly for time step. ! integrate lake-heat conduction equation upward from bottom of lake ! to surface, delivering linearization of surface ground heat flux. subroutine lake_step_1 ( u_star_a, p_surf, latitude, lake, & lake_T, & lake_rh, lake_liq, lake_ice, lake_subl, lake_tf, lake_G0, & lake_DGDT ) real, intent(in) :: u_star_a, p_surf, latitude type(lake_tile_type), intent(inout) :: lake real, intent(out) :: & lake_T, & lake_rh, lake_liq, lake_ice, lake_subl, & lake_tf, & ! freezing temperature of lake, degK lake_G0, & lake_DGDT ! ---- local vars real :: bbb, denom, dt_e, tc_dz_eff real :: z_cum, z_mid, dz_mid, rho_t_mid, k_neutral real, dimension(num_l):: aaa, ccc, thermal_cond, heat_capacity, dz_alt, & z_alt, rho_t integer :: l real :: k_star, N_sq, Ri, u_star, z_liq, z_ice, rho_a real :: lake_depth, lshc1, lshc2 ! ---------------------------------------------------------------------------- ! in preparation for implicit energy balance, determine various measures ! of water availability, so that vapor fluxes will not exceed mass limits ! ---------------------------------------------------------------------------- if(is_watch_point()) then write(*,*) 'lake_step_1 checkpoint 1' write(*,*) 'mask ', .true. write(*,*) 'T ', lake_T write(*,*) 'rh ', lake_rh write(*,*) 'liq ', lake_liq write(*,*) 'ice ', lake_ice write(*,*) 'subl ', lake_subl write(*,*) 'G0 ', lake_G0 write(*,*) 'DGDT ', lake_DGDT do l = 1, num_l write(*,'(a,i2.2,100(2x,a,g23.16))') ' level=', l,& ' dz=', lake%prog(l)%dz,& ' T =', lake%prog(l)%T,& ' wl=', lake%prog(l)%wl,& ' ws=', lake%prog(l)%ws, & 'K_z=', lake%prog(l)%K_z enddo endif if (relayer_in_step_one) call lake_relayer ( lake ) lake%prog%K_z = 0. lake_T = lake%prog(1)%T if (use_rh_feedback) then lake_depth = (sum(lake%prog(:)%wl)+sum(lake%prog(:)%ws)) / DENS_H2O else lake_depth = lake%pars%depth_sill endif call lake_data_thermodynamics ( lake%pars, lake_depth, lake_rh, & lake%heat_capacity_dry, thermal_cond ) ! Ignore air humidity in converting atmospheric friction velocity to lake value rho_a = p_surf/(rdgas*lake_T) ! No momentum transfer through ice cover if (lake%prog(1)%ws.le.0. .or. wind_penetrates_ice) then u_star = u_star_a*sqrt(rho_a/dens_h2o) k_star = 2.79e-5*sqrt(sin(abs(latitude)))*u_star**(-1.84) k_star = k_star*(c_drag/1.2e-3)**1.84 else u_star = 0. k_star = 1. endif ! k_star from B. Henderson-Sellers (1985, Appl. Math. Mod., 9) ! k_star = 2.79e-5*sqrt(sin(abs(latitude)))*u_star**(-1.84) z_cum = 0. do l = 1, num_l heat_capacity(l) = lake%heat_capacity_dry(l) * lake%prog(l)%dz & + clw*lake%prog(l)%wl + csw*lake%prog(l)%ws dz_alt(l) = (lake%prog(l)%wl + lake%prog(l)%ws)/dens_h2o z_alt(l) = z_cum + 0.5*dz_alt(l) z_cum = z_cum + dz_alt(l) ! rho_t from hostetler and bartlein (1990), citing Heggen (1983) ! is a call available in fms? rho_t(l) = 1. - 1.9549e-5*abs(lake%prog(l)%T-277.)**1.68 enddo lake_liq = max(lake%prog(1)%wl, 0.) lake_ice = max(lake%prog(1)%ws, 0.) if (lake_ice > 0) then lake_subl = 1 else lake_subl = 0 endif if(num_l > 1) then if (do_stratify) then do l = 1, num_l-1 if (lake%prog(l)%ws.le.0..and.lake%prog(l+1)%ws.le.0.) then dz_mid = z_alt(l+1)-z_alt(l) z_mid = 0.5 * (z_alt(l)+z_alt(l+1)) rho_t_mid = 0.5*(rho_t(l)+rho_t(l+1)) if (k_star*z_mid .lt. 10.) then k_neutral = vonkarm * u_star * z_mid * exp (-k_star * z_mid) else k_neutral = 0. endif N_sq = (grav / rho_t_mid) * (rho_t(l+1)-rho_t(l)) /dz_mid if (N_sq .gt. 0. .and. k_neutral.ne.0.) then ! stability function from B. Henderson-Sellers (1985) Ri = 0.05*(-1. + sqrt(1.+40.*N_sq*(vonkarm*z_mid/u_star)**2 & *exp(2.*k_star*z_mid))) lake%prog(l)%K_z = k_neutral / (1. + 37.*Ri*Ri) + K_z_molec else if (k_neutral.eq.0.) then lake%prog(l)%K_z = K_z_molec else ! arbitrary constant for unstable mixing lake%prog(l)%K_z = K_z_large endif if (lake%pars%depth_sill.gt.2.01) & lake%prog(l)%K_z = K_z_factor & * max(lake%prog(l)%K_z + K_z_background, K_z_min) aaa(l+1) = - lake%prog(l)%K_z * delta_time / (dz_alt(l+1)*dz_mid) ccc(l) = - lake%prog(l)%K_z * delta_time / (dz_alt(l )*dz_mid) else z_liq = 0.5*(lake%prog(l)%wl+lake%prog(l+1)%wl)/dens_h2o z_ice = 0.5*(lake%prog(l)%ws+lake%prog(l+1)%ws)/dens_h2o tc_dz_eff = 1. / (z_liq/tc_molec + z_ice/tc_molec_ice) aaa(l+1) = - tc_dz_eff * delta_time / heat_capacity(l+1) ccc(l) = - tc_dz_eff * delta_time / heat_capacity(l) endif enddo else do l = 1, num_l-1 tc_dz_eff = 2 / ( dz_alt(l+1)/thermal_cond(l+1) & + dz_alt(l)/thermal_cond(l) ) aaa(l+1) = - tc_dz_eff * delta_time / heat_capacity(l+1) ccc(l) = - tc_dz_eff * delta_time / heat_capacity(l) enddo endif bbb = 1.0 - aaa(num_l) denom = bbb dt_e = aaa(num_l)*(lake%prog(num_l)%T - lake%prog(num_l-1)%T) & + lake%geothermal_heat_flux * delta_time / heat_capacity(num_l) lake%e(num_l-1) = -aaa(num_l)/denom lake%f(num_l-1) = dt_e/denom do l = num_l-1, 2, -1 bbb = 1.0 - aaa(l) - ccc(l) denom = bbb + ccc(l)*lake%e(l) dt_e = - ( ccc(l)*(lake%prog(l+1)%T - lake%prog(l)%T ) & -aaa(l)*(lake%prog(l)%T - lake%prog(l-1)%T) ) lake%e(l-1) = -aaa(l)/denom lake%f(l-1) = (dt_e - ccc(l)*lake%f(l))/denom end do denom = delta_time/(heat_capacity(1) ) lake_G0 = ccc(1)*(lake%prog(2)%T- lake%prog(1)%T & + lake%f(1)) / denom lake_DGDT = (1 - ccc(1)*(1-lake%e(1))) / denom else ! one-level case denom = delta_time/heat_capacity(1) lake_G0 = 0. lake_DGDT = 1. / denom end if ! set the freezing temperature of the lake lake_tf = tfreeze if(is_watch_point()) then write(*,*) 'lake_step_1 checkpoint 2' write(*,*) 'mask ', .true. write(*,*) 'T ', lake_T write(*,*) 'rh ', lake_rh write(*,*) 'liq ', lake_liq write(*,*) 'ice ', lake_ice write(*,*) 'subl ', lake_subl write(*,*) 'G0 ', lake_G0 write(*,*) 'DGDT ', lake_DGDT do l = 1, num_l write(*,'(a,i2.2,100(2x,a,g23.16))') ' level=', l,& ' dz=', lake%prog(l)%dz,& ' T =', lake%prog(l)%T,& ' wl=', lake%prog(l)%wl,& ' ws=', lake%prog(l)%ws, & 'K_z=', lake%prog(l)%K_z enddo endif end subroutine lake_step_1 ! ============================================================================ ! apply boundary flows to lake water and move lake water vertically. subroutine lake_step_2 ( lake, diag, lake_subl, snow_lprec, snow_hlprec, & subs_DT, subs_M_imp, subs_evap, & use_tfreeze_in_grnd_latent, & lake_levap, lake_fevap, lake_melt, & lake_Ttop, lake_Ctop ) type(lake_tile_type), intent(inout) :: lake type(diag_buff_type), intent(inout) :: diag real, intent(in) :: & lake_subl ! real, intent(in) :: & snow_lprec, & snow_hlprec, & subs_DT, &! subs_M_imp, &! rate of phase change of non-evaporated lake water subs_evap logical, intent(in) :: use_tfreeze_in_grnd_latent real, intent(out) :: & lake_levap, lake_fevap, lake_melt, & lake_Ttop, lake_Ctop ! ---- local vars real, dimension(num_l) :: del_t, eee, fff, & psi, DThDP, hyd_cond, DKDP, K, DKDPm, DKDPp, grad, & dW_l, u_minus, u_plus, DPsi, lake_w_fc real, dimension(num_l+1) :: flow real, dimension(num_l ) :: div real :: ice_to_move, h_upper, h_lower, h_to_move_up, & lprec_eff, hlprec_eff, hcap, dheat, & melt_per_deg, melt, lshc1, lshc2 real, dimension(num_l-1) :: del_z real :: jj integer :: l jj = 1. if(is_watch_point()) then write(*,*) ' ***** lake_step_2 checkpoint 1 ***** ' write(*,*) 'mask ', .true. write(*,*) 'subs_evap ', subs_evap write(*,*) 'snow_lprec ', snow_lprec write(*,*) 'subs_M_imp ', subs_M_imp write(*,*) 'theta_s ', lake%pars%w_sat do l = 1, num_l write(*,'(a,i2.2,100(2x,a,g23.16))') ' level=', l,& ' dz=', lake%prog(l)%dz,& ' T =', lake%prog(l)%T,& ' Th=', (lake%prog(l)%ws & +lake%prog(l)%wl)/(dens_h2o*lake%prog(l)%dz),& ' wl=', lake%prog(l)%wl,& ' ws=', lake%prog(l)%ws,& ' gw=', lake%prog(l)%groundwater enddo endif ! ---- record fluxes --------- lake_levap = subs_evap*(1-lake_subl) lake_fevap = subs_evap* lake_subl lake_melt = subs_M_imp / delta_time ! ---- load surface temp change and perform back substitution -------------- del_t(1) = subs_DT lake%prog(1)%T = lake%prog(1)%T + del_t(1) if ( num_l > 1) then do l = 1, num_l-1 del_t(l+1) = lake%e(l) * del_t(l) + lake%f(l) lake%prog(l+1)%T = lake%prog(l+1)%T + del_t(l+1) end do end if if(is_watch_point()) then write(*,*) ' ***** lake_step_2 checkpoint 2 ***** ' do l = 1, num_l write(*,*) 'level=', l, 'T', lake%prog(l)%T enddo endif ! ---- extract evap from lake and do implicit melt -------------------- lake%prog(1)%wl = lake%prog(1)%wl - lake_levap*delta_time lake%prog(1)%ws = lake%prog(1)%ws - lake_fevap*delta_time hcap = lake%heat_capacity_dry(1)*lake%prog(1)%dz & + clw*lake%prog(1)%wl + csw*lake%prog(1)%ws ! T adjustment for nonlinear terms (del_T)*(del_W) dheat = delta_time*(clw*lake_levap+csw*lake_fevap)*del_T(1) ! take out extra heat not claimed in advance for evaporation if (use_tfreeze_in_grnd_latent) dheat = dheat & - delta_time*((cpw-clw)*lake_levap+(cpw-csw)*lake_fevap) & *(lake%prog(1)%T-del_T(1)-tfreeze) lake%prog(1)%T = lake%prog(1)%T + dheat/hcap lake%prog(1)%wl = lake%prog(1)%wl + subs_M_imp lake%prog(1)%ws = lake%prog(1)%ws - subs_M_imp lake%prog(1)%T = tfreeze + (hcap*(lake%prog(1)%T-tfreeze) ) & / ( hcap + (clw-csw)*subs_M_imp ) if(is_watch_point()) then write(*,*) ' ***** lake_step_2 checkpoint 2.1 ***** ' do l = 1, num_l write(*,*) 'level=', l, 'T', lake%prog(l)%T enddo endif ! ---- remainder of mass fluxes and associated sensible heat fluxes -------- ! note that only liquid inputs are received by lake from snow pack. any ! snow fall just creates a snow pack on top of lake, even if lake is not ! frozen. but snow pack on top of unfrozen lake will interact thermally, ! so that either lake freezes or snow melts and falls in. flow=1 flow(1) = snow_lprec *delta_time do l = 1, num_l flow(l+1) = 0 dW_l(l) = flow(l) - flow(l+1) lake%prog(l)%wl = lake%prog(l)%wl + dW_l(l) enddo if(is_watch_point()) then write(*,*) ' ***** lake_step_2 checkpoint 3.3 ***** ' do l = 1, num_l write(*,'(a,i2.2,100(2x,a,g23.16))') ' level=', l,& ' wl=', lake%prog(l)%wl,& 'flow=', flow(l) enddo endif hcap = lake%heat_capacity_dry(1)*lake%prog(1)%dz & + clw*(lake%prog(1)%wl-dW_l(1)) + csw*lake%prog(1)%ws lake%prog(1)%T = tfreeze + (hcap*(lake%prog(1)%T-tfreeze) + & snow_hlprec*delta_time) & / ( hcap + clw*dW_l(1) ) if(is_watch_point()) then write(*,*) ' ***** lake_step_2 checkpoint 3.4 ***** ' write(*,*) ' tfreeze', tfreeze write(*,*) ' snow_hlprec', snow_hlprec endif do l = 1, num_l ! ---- compute explicit melt/freeze -------------------------------------- hcap = lake%heat_capacity_dry(l)*lake%prog(l)%dz & + clw*lake%prog(l)%wl + csw*lake%prog(l)%ws melt_per_deg = hcap/hlf if (lake%prog(l)%ws>0 .and. lake%prog(l)%T>tfreeze) then melt = min(lake%prog(l)%ws, (lake%prog(l)%T-tfreeze)*melt_per_deg) else if (lake%prog(l)%wl>0 .and. lake%prog(l)%T<tfreeze) then melt = -min(lake%prog(l)%wl, (tfreeze-lake%prog(l)%T)*melt_per_deg) else melt = 0 endif lake%prog(l)%wl = lake%prog(l)%wl + melt lake%prog(l)%ws = lake%prog(l)%ws - melt lake%prog(l)%T = tfreeze & + (hcap*(lake%prog(l)%T-tfreeze) - hlf*melt) & / ( hcap + (clw-csw)*melt ) lake_melt = lake_melt + melt / delta_time enddo if(is_watch_point()) then write(*,*) ' ***** lake_step_2 checkpoint 5 ***** ' do l = 1, num_l write(*,'(a,i2.2,100(2x,a,g23.16))') ' level=', l,& ' dz=', lake%prog(l)%dz,& ' T =', lake%prog(l)%T,& ' Th=', (lake%prog(l)%ws +lake%prog(l)%wl)/(dens_h2o*lake%prog(l)%dz),& ' wl=', lake%prog(l)%wl,& ' ws=', lake%prog(l)%ws,& ' gw=', lake%prog(l)%groundwater enddo endif if (.not.relayer_in_step_one) call lake_relayer ( lake ) if(is_watch_point()) then write(*,*) ' ***** lake_step_2 checkpoint 6 ***** ' do l = 1, num_l write(*,'(a,i2.2,100(2x,a,g23.16))') ' level=', l,& ' dz=', lake%prog(l)%dz,& ' T =', lake%prog(l)%T,& ' Th=', (lake%prog(l)%ws +lake%prog(l)%wl)/(dens_h2o*lake%prog(l)%dz),& ' wl=', lake%prog(l)%wl,& ' ws=', lake%prog(l)%ws,& ' gw=', lake%prog(l)%groundwater enddo endif if (float_ice_to_top) then do l = num_l, 2, -1 if (lake%prog(l)%ws .gt. 0. .and. lake%prog(l-1)%wl .gt. 0.) then ice_to_move = min(lake%prog(l)%ws, lake%prog(l-1)%wl) h_upper = (clw*lake%prog(l-1)%wl+csw*lake%prog(l-1)%ws)*lake%prog(l-1)%T h_lower = (clw*lake%prog(l )%wl+csw*lake%prog(l )%ws)*lake%prog(l )%T lake%prog(l-1)%wl = lake%prog(l-1)%wl - ice_to_move lake%prog(l-1)%ws = lake%prog(l-1)%ws + ice_to_move lake%prog(l )%wl = lake%prog(l )%wl + ice_to_move lake%prog(l )%ws = lake%prog(l )%ws - ice_to_move h_to_move_up = ice_to_move*(csw*lake%prog(l)%T-clw*lake%prog(l-1)%T) h_upper = h_upper + h_to_move_up h_lower = h_lower - h_to_move_up lake%prog(l-1)%T = h_upper / (clw*lake%prog(l-1)%wl+csw*lake%prog(l-1)%ws) lake%prog(l )%T = h_lower / (clw*lake%prog(l )%wl+csw*lake%prog(l )%ws) endif enddo endif if(is_watch_point()) then write(*,*) ' ***** lake_step_2 checkpoint 7 ***** ' do l = 1, num_l write(*,'(a,i2.2,100(2x,a,g23.16))') ' level=', l,& ' dz=', lake%prog(l)%dz,& ' T =', lake%prog(l)%T,& ' Th=', (lake%prog(l)%ws +lake%prog(l)%wl)/(dens_h2o*lake%prog(l)%dz),& ' wl=', lake%prog(l)%wl,& ' ws=', lake%prog(l)%ws,& ' gw=', lake%prog(l)%groundwater enddo endif lake_Ttop = lake%prog(1)%T lake_Ctop = lake%heat_capacity_dry(1)*lake%prog(1)%dz & + clw*lake%prog(1)%wl + csw*lake%prog(1)%ws ! ---------------------------------------------------------------------------- ! given solution for surface energy balance, write diagnostic output. ! ! ---- increment time time = increment_time(time, int(delta_time), 0) ! ---- diagnostic section call send_tile_data (id_dz, lake%prog%dz, diag ) call send_tile_data (id_temp, lake%prog%T, diag ) call send_tile_data (id_wl, lake%prog(1:num_l)%wl, diag ) call send_tile_data (id_ws, lake%prog(1:num_l)%ws, diag ) call send_tile_data (id_lwc, lake%prog(1:num_l)%wl/lake%prog(1:num_l)%dz, diag ) call send_tile_data (id_swc, lake%prog(1:num_l)%ws/lake%prog(1:num_l)%dz, diag ) call send_tile_data (id_K_z, lake%prog(1:num_l)%K_z, diag ) call send_tile_data (id_evap, lake_levap+lake_fevap, diag ) end subroutine lake_step_2 ! ============================================================================ ! subroutine lake_relayer ( lake ) type(lake_tile_type), intent(inout) :: lake ! ---- local vars integer :: l, l_lowest_thin_layer, l_highest_thick_layer real :: new_dz, new_ws, new_wl, new_h, new_T, liq_frac ! now check whether we need to re-layer the lake. if ( (lake%prog(1)%wl+lake%prog(1)%ws) & /(lake%prog(2)%wl+lake%prog(2)%ws) .gt. max_rat) then ! top layer has grown too thick. join two lower layers, and split ! top layer into two layers. in special case, just join and ! re-split top two layers. l_lowest_thin_layer = num_l do l = 2, num_l-1 if (lake%prog(l)%dz.lt.0.99*lake%prog(num_l)%dz) l_lowest_thin_layer = l enddo if (l_lowest_thin_layer.gt.2) then new_dz = lake%prog(l_lowest_thin_layer)%dz & + lake%prog(l_lowest_thin_layer-1)%dz new_wl = lake%prog(l_lowest_thin_layer)%wl & + lake%prog(l_lowest_thin_layer-1)%wl new_ws = lake%prog(l_lowest_thin_layer)%ws & + lake%prog(l_lowest_thin_layer-1)%ws new_h = ( clw*lake%prog(l_lowest_thin_layer)%wl & + csw*lake%prog(l_lowest_thin_layer)%ws) & * lake%prog(l_lowest_thin_layer)%T & + ( clw*lake%prog(l_lowest_thin_layer-1)%wl & + csw*lake%prog(l_lowest_thin_layer-1)%ws) & * lake%prog(l_lowest_thin_layer-1)%T new_T = new_h / (clw*new_wl+csw*new_ws) lake%prog(l_lowest_thin_layer)%dz = new_dz lake%prog(l_lowest_thin_layer)%wl = new_wl lake%prog(l_lowest_thin_layer)%ws = new_ws lake%prog(l_lowest_thin_layer)%T = new_T do l = l_lowest_thin_layer-1, 3, -1 lake%prog(l)%dz = lake%prog(l-1)%dz lake%prog(l)%wl = lake%prog(l-1)%wl lake%prog(l)%ws = lake%prog(l-1)%ws lake%prog(l)%T = lake%prog(l-1)%T enddo liq_frac = lake%prog(1)%wl / (lake%prog(1)%wl+lake%prog(1)%ws) lake%prog(2)%wl = liq_frac *DENS_H2O*lake%prog(2)%dz lake%prog(2)%ws = (1.-liq_frac)*DENS_H2O*lake%prog(2)%dz lake%prog(2)%T = lake%prog(1)%T lake%prog(1)%dz = lake%prog(2)%dz lake%prog(1)%wl = lake%prog(1)%wl - lake%prog(2)%wl lake%prog(1)%ws = lake%prog(1)%ws - lake%prog(2)%ws else new_wl = lake%prog(1)%wl + lake%prog(2)%wl new_ws = lake%prog(1)%ws + lake%prog(2)%ws new_h = ( clw*lake%prog(1)%wl + csw*lake%prog(1)%ws) & * lake%prog(1)%T & + ( clw*lake%prog(2)%wl + csw*lake%prog(2)%ws) & * lake%prog(2)%T new_T = new_h / (clw*new_wl+csw*new_ws) liq_frac = new_wl / (new_wl+new_ws) lake%prog(2)%dz = lake%prog(3)%dz lake%prog(2)%wl = liq_frac *DENS_H2O*lake%prog(2)%dz lake%prog(2)%ws = (1.-liq_frac)*DENS_H2O*lake%prog(2)%dz lake%prog(2)%T = new_T lake%prog(1)%dz = lake%prog(2)%dz lake%prog(1)%wl = new_wl - lake%prog(2)%wl lake%prog(1)%ws = new_ws - lake%prog(2)%ws lake%prog(1)%T = new_T endif else if( (lake%prog(1)%wl+lake%prog(1)%ws) & /(lake%prog(2)%wl+lake%prog(2)%ws) .lt. min_rat) then ! top layer has grown too thin. join with next layer down, and split ! a lower layer to maintain number of layers. in special case, just ! join and re-split top two layers. l_highest_thick_layer = 2 do l = num_l, 3, -1 if (lake%prog(l)%dz.gt.1.01*lake%prog(2)%dz) l_highest_thick_layer = l enddo new_wl = lake%prog(1)%wl + lake%prog(2)%wl new_ws = lake%prog(1)%ws + lake%prog(2)%ws new_h = ( clw*lake%prog(1)%wl + csw*lake%prog(1)%ws) & * lake%prog(1)%T & + ( clw*lake%prog(2)%wl + csw*lake%prog(2)%ws) & * lake%prog(2)%T new_T = new_h / (clw*new_wl+csw*new_ws) if (l_highest_thick_layer.gt.2) then lake%prog(1)%dz = lake%prog(2)%dz lake%prog(1)%wl = new_wl lake%prog(1)%ws = new_ws lake%prog(1)%T = new_T do l = 2, l_highest_thick_layer-2 lake%prog(l)%dz = lake%prog(l+1)%dz lake%prog(l)%wl = lake%prog(l+1)%wl lake%prog(l)%ws = lake%prog(l+1)%ws lake%prog(l)%T = lake%prog(l+1)%T enddo new_dz = lake%prog(l_highest_thick_layer)%dz / 2. new_wl = lake%prog(l_highest_thick_layer)%wl / 2. new_ws = lake%prog(l_highest_thick_layer)%ws / 2. new_T = lake%prog(l_highest_thick_layer)%T lake%prog(l_highest_thick_layer-1)%dz = new_dz lake%prog(l_highest_thick_layer-1)%wl = new_wl lake%prog(l_highest_thick_layer-1)%ws = new_ws lake%prog(l_highest_thick_layer-1)%T = new_T lake%prog(l_highest_thick_layer)%dz = new_dz lake%prog(l_highest_thick_layer)%wl = new_wl lake%prog(l_highest_thick_layer)%ws = new_ws lake%prog(l_highest_thick_layer)%T = new_T else liq_frac = new_wl / (new_wl+new_ws) lake%prog(2)%dz = lake%prog(3)%dz / 2. lake%prog(2)%wl = liq_frac *DENS_H2O*lake%prog(2)%dz lake%prog(2)%ws = (1.-liq_frac)*DENS_H2O*lake%prog(2)%dz lake%prog(2)%T = new_T lake%prog(1)%dz = lake%prog(2)%dz lake%prog(1)%wl = new_wl - lake%prog(2)%wl lake%prog(1)%ws = new_ws - lake%prog(2)%ws lake%prog(1)%T = new_T endif endif end subroutine lake_relayer ! ============================================================================ subroutine lake_diag_init ( id_lon, id_lat ) integer, intent(in) :: id_lon ! ID of land longitude (X) axis integer, intent(in) :: id_lat ! ID of land longitude (X) axis ! ---- local vars integer :: axes(3) integer :: id_zhalf, id_zfull ! define vertical axis id_zhalf = diag_axis_init ( & 'zhalf_lake', zhalf(1:num_l+1), 'meters', 'z', 'half level', -1, set_name='lake' ) id_zfull = diag_axis_init ( & 'zfull_lake', zfull(1:num_l), 'meters', 'z', 'full level', -1, set_name='lake', & edges=id_zhalf ) ! define array of axis indices axes = (/ id_lon, id_lat, id_zfull /) ! define static diagnostic fields id_sillw = register_tiled_static_field ( module_name, 'lake_width', & axes(1:2), 'lake width at outflow', 'm', missing_value=-100.0 ) id_silld = register_tiled_static_field ( module_name, 'lake_depth', & axes(1:2), 'lake depth below sill', 'm', missing_value=-100.0 ) id_backw = register_tiled_static_field ( module_name, 'backwater', & axes(1:2), 'backwater flag', '-', missing_value=-100.0 ) id_back1 = register_tiled_static_field ( module_name, 'backwater_1', & axes(1:2), 'backwater1 flag', '-', missing_value=-100.0 ) ! define dynamic diagnostic fields id_dz = register_tiled_diag_field ( module_name, 'lake_dz', axes, & Time, 'nominal layer thickness', 'm', missing_value=-100.0 ) id_wl = register_tiled_diag_field ( module_name, 'lake_wl', axes, & Time, 'liquid water mass', 'kg/m2', missing_value=-100.0 ) id_ws = register_tiled_diag_field ( module_name, 'lake_ws', axes, & Time, 'solid water mass', 'kg/m2', missing_value=-100.0 ) id_lwc = register_tiled_diag_field ( module_name, 'lake_liq', axes, & Time, 'bulk density of liquid water', 'kg/m3', missing_value=-100.0 ) id_swc = register_tiled_diag_field ( module_name, 'lake_ice', axes, & Time, 'bulk density of solid water', 'kg/m3', missing_value=-100.0 ) id_temp = register_tiled_diag_field ( module_name, 'lake_T', axes, & Time, 'temperature', 'degK', missing_value=-100.0 ) id_K_z = register_tiled_diag_field ( module_name, 'lake_K_z', axes, & Time, 'vertical diffusivity', 'm2/s', missing_value=-100.0 ) id_evap = register_tiled_diag_field ( module_name, 'lake_evap', axes(1:2), & Time, 'lake evap', 'kg/(m2 s)', missing_value=-100.0 ) call add_tiled_static_field_alias (id_silld, module_name, 'sill_depth', & axes(1:2), 'obsolete, pls use lake_depth (static)','m', & missing_value=-100.0 ) call add_tiled_static_field_alias (id_sillw, module_name, 'sill_width', & axes(1:2), 'obsolete, pls use lake_width (static)','m', & missing_value=-100.0 ) end subroutine lake_diag_init ! ============================================================================ ! tile existence detector: returns a logical value indicating wether component ! model tile exists or not logical function lake_tile_exists(tile) type(land_tile_type), pointer :: tile lake_tile_exists = associated(tile%lake) end function lake_tile_exists ! ============================================================================ ! accessor functions: given a pointer to a land tile, they return pointer ! to the desired member of the land tile, of NULL if this member does not ! exist. subroutine lake_dz_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr(:) integer :: n ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) then n = size(tile%lake%prog) ptr(1:n) => tile%lake%prog(1:n)%dz endif endif end subroutine lake_dz_ptr subroutine lake_temp_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr(:) integer :: n ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) then n = size(tile%lake%prog) ptr(1:n) => tile%lake%prog(1:n)%T endif endif end subroutine lake_temp_ptr subroutine lake_wl_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr(:) integer :: n ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) then n = size(tile%lake%prog) ptr(1:n) => tile%lake%prog(1:n)%wl endif endif end subroutine lake_wl_ptr subroutine lake_ws_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr(:) integer :: n ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) then n = size(tile%lake%prog) ptr(1:n) => tile%lake%prog(1:n)%ws endif endif end subroutine lake_ws_ptr subroutine lake_gw_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr(:) integer :: n ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) then n = size(tile%lake%prog) ptr(1:n) => tile%lake%prog(1:n)%groundwater endif endif end subroutine lake_gw_ptr subroutine lake_gwT_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr(:) integer :: n ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) then n = size(tile%lake%prog) ptr(1:n) => tile%lake%prog(1:n)%groundwater_T endif endif end subroutine lake_gwT_ptr subroutine lake_connected_to_next_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) ptr=>tile%lake%pars%connected_to_next endif end subroutine lake_connected_to_next_ptr subroutine lake_depth_sill_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) ptr=>tile%lake%pars%depth_sill endif end subroutine lake_depth_sill_ptr subroutine lake_whole_area_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) ptr=>tile%lake%pars%whole_area endif end subroutine lake_whole_area_ptr subroutine lake_width_sill_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) ptr=>tile%lake%pars%width_sill endif end subroutine lake_width_sill_ptr subroutine lake_backwater_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) ptr=>tile%lake%pars%backwater endif end subroutine lake_backwater_ptr subroutine lake_backwater_1_ptr(tile, ptr) type(land_tile_type), pointer :: tile real , pointer :: ptr ptr=>NULL() if(associated(tile)) then if(associated(tile%lake)) ptr=>tile%lake%pars%backwater_1 endif end subroutine lake_backwater_1_ptr end module lake_mod
gpl-2.0
bgin/MissileSimulation
External/SLICOT/TB04BW.f
2
8893
SUBROUTINE TB04BW( ORDER, P, M, MD, IGN, LDIGN, IGD, LDIGD, GN, $ GD, D, LDD, INFO ) C C SLICOT RELEASE 5.5. C C Copyright (c) 2002-2012 NICONET e.V. C C PURPOSE C C To compute the sum of an P-by-M rational matrix G and a real C P-by-M matrix D. C C ARGUMENTS C C Mode Parameters C C ORDER CHARACTER*1 C Specifies the order in which the polynomial coefficients C of the rational matrix are stored, as follows: C = 'I': Increasing order of powers of the indeterminate; C = 'D': Decreasing order of powers of the indeterminate. C C Input/Output Parameters C C P (input) INTEGER C The number of the system outputs. P >= 0. C C M (input) INTEGER C The number of the system inputs. M >= 0. C C MD (input) INTEGER C The maximum degree of the polynomials in G, plus 1, i.e., C MD = MAX(IGN(I,J),IGD(I,J)) + 1. C I,J C C IGN (input/output) INTEGER array, dimension (LDIGN,M) C On entry, the leading P-by-M part of this array must C contain the degrees of the numerator polynomials in G: C the (i,j) element of IGN must contain the degree of the C numerator polynomial of the polynomial ratio G(i,j). C On exit, the leading P-by-M part of this array contains C the degrees of the numerator polynomials in G + D. C C LDIGN INTEGER C The leading dimension of array IGN. LDIGN >= max(1,P). C C IGD (input) INTEGER array, dimension (LDIGD,M) C The leading P-by-M part of this array must contain the C degrees of the denominator polynomials in G (and G + D): C the (i,j) element of IGD contains the degree of the C denominator polynomial of the polynomial ratio G(i,j). C C LDIGD INTEGER C The leading dimension of array IGD. LDIGD >= max(1,P). C C GN (input/output) DOUBLE PRECISION array, dimension (P*M*MD) C On entry, this array must contain the coefficients of the C numerator polynomials, Num(i,j), of the rational matrix G. C The polynomials are stored in a column-wise order, i.e., C Num(1,1), Num(2,1), ..., Num(P,1), Num(1,2), Num(2,2), C ..., Num(P,2), ..., Num(1,M), Num(2,M), ..., Num(P,M); C MD memory locations are reserved for each polynomial, C hence, the (i,j) polynomial is stored starting from the C location ((j-1)*P+i-1)*MD+1. The coefficients appear in C increasing or decreasing order of the powers of the C indeterminate, according to ORDER. C On exit, this array contains the coefficients of the C numerator polynomials of the rational matrix G + D, C stored similarly. C C GD (input) DOUBLE PRECISION array, dimension (P*M*MD) C This array must contain the coefficients of the C denominator polynomials, Den(i,j), of the rational C matrix G. The polynomials are stored as for the C numerator polynomials. C C D (input) DOUBLE PRECISION array, dimension (LDD,M) C The leading P-by-M part of this array must contain the C matrix D. C C LDD INTEGER C The leading dimension of array D. LDD >= max(1,P). C C Error Indicator C C INFO INTEGER C = 0: successful exit; C < 0: if INFO = -i, the i-th argument had an illegal C value. C C METHOD C C The (i,j) entry of the real matrix D is added to the (i,j) entry C of the matrix G, g(i,j), which is a ratio of two polynomials, C for i = 1 : P, and for j = 1 : M. If g(i,j) = 0, it is assumed C that its denominator is 1. C C NUMERICAL ASPECTS C C The algorithm is numerically stable. C C FURTHER COMMENTS C C Often, the rational matrix G is found from a state-space C representation (A,B,C), and D corresponds to the direct C feedthrough matrix of the system. The sum G + D gives the C transfer function matrix of the system (A,B,C,D). C For maximum efficiency of index calculations, GN and GD are C implemented as one-dimensional arrays. C C CONTRIBUTORS C C V. Sima, Research Institute for Informatics, Bucharest, May 2002. C Based on the BIMASC Library routine TMCADD by A. Varga. C C REVISIONS C C V. Sima, Research Institute for Informatics, Bucharest, Feb. 2004. C C KEYWORDS C C State-space representation, transfer function. C C ****************************************************************** C C .. Parameters .. DOUBLE PRECISION ZERO PARAMETER ( ZERO = 0.0D0 ) C .. Scalar Arguments .. CHARACTER ORDER INTEGER INFO, LDD, LDIGD, LDIGN, M, MD, P C .. Array Arguments .. DOUBLE PRECISION D(LDD,*), GD(*), GN(*) INTEGER IGD(LDIGD,*), IGN(LDIGN,*) C .. Local Scalars .. LOGICAL ASCEND INTEGER I, II, J, K, KK, KM, ND, NN DOUBLE PRECISION DIJ C .. External Functions .. LOGICAL LSAME EXTERNAL LSAME C .. External Subroutines .. EXTERNAL DAXPY, XERBLA C .. Intrinsic Functions .. INTRINSIC MAX, MIN C .. C .. Executable Statements .. C C Test the input scalar parameters. C INFO = 0 ASCEND = LSAME( ORDER, 'I' ) IF( .NOT.ASCEND .AND. .NOT.LSAME( ORDER, 'D' ) ) THEN INFO = -1 ELSE IF( P.LT.0 ) THEN INFO = -2 ELSE IF( M.LT.0 ) THEN INFO = -3 ELSE IF( MD.LT.1 ) THEN INFO = -4 ELSE IF( LDIGN.LT.MAX( 1, P ) ) THEN INFO = -6 ELSE IF( LDIGD.LT.MAX( 1, P ) ) THEN INFO = -8 ELSE IF( LDD.LT.MAX( 1, P ) ) THEN INFO = -12 END IF C IF ( INFO.NE.0 ) THEN C C Error return. C CALL XERBLA( 'TB04BW', -INFO ) RETURN END IF C C Quick return if possible. C IF( MIN( P, M ).EQ.0 ) $ RETURN C K = 1 C IF ( ASCEND ) THEN C C Polynomial coefficients are stored in increasing order. C DO 30 J = 1, M C DO 20 I = 1, P DIJ = D(I,J) IF ( DIJ.NE.ZERO ) THEN NN = IGN(I,J) ND = IGD(I,J) IF ( NN.EQ.0 .AND. ND.EQ.0 ) THEN IF ( GN(K).EQ.ZERO ) THEN GN(K) = DIJ ELSE GN(K) = GN(K) + DIJ*GD(K) ENDIF ELSE KM = MIN( NN, ND ) + 1 CALL DAXPY( KM, DIJ, GD(K), 1, GN(K), 1 ) IF ( NN.LT.ND ) THEN C DO 10 II = K + KM, K + ND GN(II) = DIJ*GD(II) 10 CONTINUE C IGN(I,J) = ND ENDIF ENDIF ENDIF K = K + MD 20 CONTINUE C 30 CONTINUE C ELSE C C Polynomial coefficients are stored in decreasing order. C DO 60 J = 1, M C DO 50 I = 1, P DIJ = D(I,J) IF ( DIJ.NE.ZERO ) THEN NN = IGN(I,J) ND = IGD(I,J) IF ( NN.EQ.0 .AND. ND.EQ.0 ) THEN IF ( GN(K).EQ.ZERO ) THEN GN(K) = DIJ ELSE GN(K) = GN(K) + DIJ*GD(K) ENDIF ELSE KM = MIN( NN, ND ) + 1 IF ( NN.LT.ND ) THEN KK = K + ND - NN C DO 35 II = K + NN, K, -1 GN(II+ND-NN) = GN(II) 35 CONTINUE C DO 40 II = K, KK - 1 GN(II) = DIJ*GD(II) 40 CONTINUE C IGN(I,J) = ND CALL DAXPY( KM, DIJ, GD(KK), 1, GN(KK), 1 ) ELSE KK = K + NN - ND CALL DAXPY( KM, DIJ, GD(K), 1, GN(KK), 1 ) ENDIF ENDIF ENDIF K = K + MD 50 CONTINUE C 60 CONTINUE C ENDIF C RETURN C *** Last line of TB04BW *** END
mit
eiselekd/gcc
gcc/testsuite/gfortran.dg/transpose_optimization_1.f90
46
3321
! { 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" } }
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/fmt_t_2.f90
180
1092
! { dg-options "" } ! { dg-do run } ! pr24699, handle end-of-record on READ with T format ! test contributed by Jerry DeLisle <jvdelisle@gcc.gnu.org> character*132 :: foost1, foost2, foost3 open (11, status="scratch", action="readwrite") write(11, '(a)') "ab cdefghijkl mnop qrst" write(11, '(a)') "123456789 123456789 123456789" write(11, '(a)') " Now is the time for all good." rewind(11) read (11, '(a040,t1,040a)', end = 999) foost1 , foost2 if (foost1.ne.foost2) call abort() read (11, '(a032,t2,a032t3,a032)', end = 999) foost1 , foost2, foost3 if (foost1(1:32).ne."123456789 123456789 123456789 ") call abort() if (foost2(1:32).ne."23456789 123456789 123456789 ") call abort() if (foost3(1:32).ne."3456789 123456789 123456789 ") call abort() read (11, '(a017,t1,a0017)', end = 999) foost1 , foost2 if (foost1.ne.foost2) call abort() if (foost2(1:17).ne." Now is the time ") call abort() goto 1000 999 call abort() 1000 continue close(11) end
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/masklr_2.F90
162
1106
! Test the MASKL and MASKR intrinsics. ! ! { dg-do run } ! { dg-options "-ffree-line-length-none" } ! { dg-require-effective-target fortran_integer_16 } #define CHECK(I,KIND,FUNCL,FUNCR,RESL,RESR) \ if (maskl(I,KIND) /= RESL) call abort ; \ if (FUNCL(I) /= RESL) call abort ; \ if (maskr(I,KIND) /= RESR) call abort ; \ if (FUNCR(I) /= RESR) call abort CHECK(0,16,run_maskl16,run_maskr16,0_16,0_16) CHECK(1,16,run_maskl16,run_maskr16,-huge(0_16)-1_16,1_16) CHECK(2,16,run_maskl16,run_maskr16,(-huge(0_16)-1_16)/2_16,3_16) CHECK(3,16,run_maskl16,run_maskr16,(-huge(0_16)-1_16)/4_16,7_16) CHECK(int(bit_size(0_16))-2,16,run_maskl16,run_maskr16,-4_16,huge(0_16)/2_16) CHECK(int(bit_size(0_16))-1,16,run_maskl16,run_maskr16,-2_16,huge(0_16)) CHECK(int(bit_size(0_16)),16,run_maskl16,run_maskr16,-1_16,-1_16) contains pure integer(kind=16) function run_maskl16(i) result(res) integer, intent(in) :: i res = maskl(i,kind=16) end function pure integer(kind=16) function run_maskr16(i) result(res) integer, intent(in) :: i res = maskr(i,kind=16) end function end
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/fmt_error_9.f
166
1082
! { dg-do run } ! { dg-options "-std=gnu" } ! PR38439 I/O PD edit descriptor inconsistency ! Test case prepared by Jerry DeLisle <jvdelisle@gcc.gnu.org> character(len=25) :: str character(len=132) :: msg, line str = '(1pd24.15e6)' line = "initial string" x = 555.25 write (line,str,iostat=istat, iomsg=msg) 1.0d0, 1.234 if (istat.ne.5006 .or. msg(1:15).ne."Period required") call abort if (line.ne."initial string") call abort str = '(1pf0.15)' write (line,str,iostat=istat, iomsg=msg) 1.0d0 if (istat.ne.0) call abort read (*,str,iostat=istat, iomsg=msg) x if (istat.ne.5006 .or. msg(1:15).ne."Positive width ") call abort if (x.ne.555.25) call abort write (line,'(1pd24.15e11.3)') 1.0d0, 1.234 if (line.ne." 1.000000000000000D+00 1.234E+00") call abort str = '(1p2d24.15)' msg = " 1.000000000000000D+00 1.233999967575073D+00That's it!" write (line,'(1p2d24.15a)') 1.0d0, 1.234, "That's it!" if (line.ne.msg) print *, msg end
gpl-2.0
pablodebiase/bromoc-e_suite
imc-macro/src/xerbla.f
11
1283
SUBROUTINE XERBLA( SRNAME, INFO ) * * -- LAPACK auxiliary routine (preliminary version) -- * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. * November 2006 * * .. Scalar Arguments .. CHARACTER*(*) SRNAME INTEGER INFO * .. * * Purpose * ======= * * XERBLA is an error handler for the LAPACK routines. * It is called by an LAPACK routine if an input parameter has an * invalid value. A message is printed and execution stops. * * Installers may consider modifying the STOP statement in order to * call system-specific exception-handling facilities. * * Arguments * ========= * * SRNAME (input) CHARACTER*(*) * The name of the routine which called XERBLA. * * INFO (input) INTEGER * The position of the invalid parameter in the parameter list * of the calling routine. * * ===================================================================== * * .. Intrinsic Functions .. INTRINSIC LEN_TRIM * .. * .. Executable Statements .. * WRITE( *, FMT = 9999 )SRNAME( 1:LEN_TRIM( SRNAME ) ), INFO * STOP * 9999 FORMAT( ' ** On entry to ', A, ' parameter number ', I2, ' had ', $ 'an illegal value' ) * * End of XERBLA * END
gpl-3.0
redstar3894/android-gcc-4.6
libgfortran/generated/_asinh_r4.F90
22
1482
! 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_4) #ifdef HAVE_ASINHF elemental function _gfortran_specific__asinh_r4 (parm) real (kind=4), intent (in) :: parm real (kind=4) :: _gfortran_specific__asinh_r4 _gfortran_specific__asinh_r4 = asinh (parm) end function #endif #endif
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/auto_char_dummy_array_1.f90
52
1246
! { dg-do run } ! This tests the fix for pr15809 in which automatic character length, ! dummy, pointer arrays were broken. ! ! contributed by Paul Thomas <pault@gcc.gnu.org> ! module global character(12), dimension(2), target :: t end module global program oh_no_not_pr15908_again character(12), dimension(:), pointer :: ptr call a (ptr, 12) if (.not.associated (ptr) ) call abort () if (any (ptr.ne."abc")) call abort () ptr => null () ! ptr points to 't' here. allocate (ptr(3)) ptr = "xyz" call a (ptr, 12) if (.not.associated (ptr)) call abort () if (any (ptr.ne."lmn")) call abort () call a (ptr, 0) if (associated (ptr)) call abort () contains subroutine a (p, l) use global character(l), dimension(:), pointer :: p character(l), dimension(3) :: s s = "lmn" if (l.ne.12) then deallocate (p) ! ptr was allocated in main. p => null () return end if if (.not.associated (p)) then t = "abc" p => t else if (size (p,1).ne.3) call abort () if (any (p.ne."xyz")) call abort () p = s end if end subroutine a end program oh_no_not_pr15908_again ! { dg-final { cleanup-modules "global" } }
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/volatile3.f90
181
1123
! { dg-do compile } ! { dg-shouldfail "Invalid use of VOLATILE" } ! Test whether volatile statements and attributes are ! properly error checked. ! PR fortran/29601 program volatile_test implicit none real, external, volatile :: foo ! { dg-error "VOLATILE attribute conflicts with EXTERNAL attribute" } real, intrinsic, volatile :: sin ! { dg-error "VOLATILE attribute conflicts with INTRINSIC attribute" } real, parameter, volatile :: r = 5.5 ! { dg-error "PARAMETER attribute conflicts with VOLATILE attribute" } real :: l,m real,volatile :: n real, volatile,volatile :: r = 3. ! { dg-error "Duplicate VOLATILE attribute" } volatile :: l,n ! { dg-warning "Duplicate VOLATILE attribute" } volatile ! { dg-error "Syntax error in VOLATILE statement" } volatile :: volatile_test ! { dg-error "PROGRAM attribute conflicts with VOLATILE attribute" } l = 4.0 m = 3.0 contains subroutine foo(a) ! { dg-error "has no IMPLICIT type" } ! due to error below integer, intent(in), volatile :: a ! { dg-error "VOLATILE attribute conflicts with INTENT\\(IN\\)" } end subroutine end program volatile_test
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/backspace_1.f
174
1699
! This file is all about BACKSPACE ! { dg-do run { target fd_truncate } } integer i, n, nr real x(10), y(10) ! PR libfortran/20068 open (20, status='scratch') write (20,*) 1 write (20,*) 2 write (20,*) 3 rewind (20) read (20,*) i if (i .ne. 1) call abort write (*,*) ' ' backspace (20) read (20,*) i if (i .ne. 1) call abort close (20) ! PR libfortran/20125 open (20, status='scratch') write (20,*) 7 backspace (20) read (20,*) i if (i .ne. 7) call abort close (20) open (20, status='scratch', form='unformatted') write (20) 8 backspace (20) read (20) i if (i .ne. 8) call abort close (20) ! PR libfortran/20471 do n = 1, 10 x(n) = sqrt(real(n)) end do open (3, form='unformatted', status='scratch') write (3) (x(n),n=1,10) backspace (3) rewind (3) read (3) (y(n),n=1,10) do n = 1, 10 if (abs(x(n)-y(n)) > 0.00001) call abort end do close (3) ! PR libfortran/20156 open (3, form='unformatted', status='scratch') do i = 1, 5 x(1) = i write (3) n, (x(n),n=1,10) end do nr = 0 rewind (3) 20 continue read (3,end=30,err=90) n, (x(n),n=1,10) nr = nr + 1 goto 20 30 continue if (nr .ne. 5) call abort do i = 1, nr+1 backspace (3) end do do i = 1, nr read(3,end=70,err=90) n, (x(n),n=1,10) if (abs(x(1) - i) .gt. 0.001) call abort end do close (3) stop 70 continue call abort 90 continue call abort end
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/actual_array_result_1.f90
136
1492
! { dg-do run } ! PR fortan/31692 ! Passing array valued results to procedures ! ! Test case contributed by rakuen_himawari@yahoo.co.jp module one integer :: flag = 0 contains function foo1 (n) integer :: n integer :: foo1(n) if (flag == 0) then call bar1 (n, foo1) else call bar2 (n, foo1) end if end function function foo2 (n) implicit none integer :: n integer,ALLOCATABLE :: foo2(:) allocate (foo2(n)) if (flag == 0) then call bar1 (n, foo2) else call bar2 (n, foo2) end if end function function foo3 (n) implicit none integer :: n integer,ALLOCATABLE :: foo3(:) allocate (foo3(n)) foo3 = 0 call bar2(n, foo3(2:(n-1))) ! Check that sections are OK end function subroutine bar1 (n, array) ! Checks assumed size formal arg. integer :: n integer :: array(*) integer :: i do i = 1, n array(i) = i enddo end subroutine subroutine bar2(n, array) ! Checks assumed shape formal arg. integer :: n integer :: array(:) integer :: i do i = 1, size (array, 1) array(i) = i enddo end subroutine end module program main use one integer :: n n = 3 if(any (foo1(n) /= [ 1,2,3 ])) call abort() if(any (foo2(n) /= [ 1,2,3 ])) call abort() flag = 1 if(any (foo1(n) /= [ 1,2,3 ])) call abort() if(any (foo2(n) /= [ 1,2,3 ])) call abort() n = 5 if(any (foo3(n) /= [ 0,1,2,3,0 ])) call abort() end program
gpl-2.0
eiselekd/gcc
libgfortran/generated/_sin_r8.F90
9
1467
! Copyright (C) 2002-2017 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_8) #ifdef HAVE_SIN elemental function _gfortran_specific__sin_r8 (parm) real (kind=8), intent (in) :: parm real (kind=8) :: _gfortran_specific__sin_r8 _gfortran_specific__sin_r8 = sin (parm) end function #endif #endif
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/nan_1.f90
30
4338
! Test if MIN and MAX intrinsics behave correctly when passed NaNs ! as arguments ! ! { dg-do run } ! { dg-add-options ieee } ! { dg-skip-if "NaN not supported" { spu-*-* } { "*" } { "" } } ! module aux2 interface isnan module procedure isnan_r module procedure isnan_d end interface isnan interface isinf module procedure isinf_r module procedure isinf_d end interface isinf contains pure function isnan_r(x) result (isnan) logical :: isnan real, intent(in) :: x isnan = (.not.(x == x)) end function isnan_r pure function isnan_d(x) result (isnan) logical :: isnan double precision, intent(in) :: x isnan = (.not.(x == x)) end function isnan_d pure function isinf_r(x) result (isinf) logical :: isinf real, intent(in) :: x isinf = (x > huge(x)) .or. (x < -huge(x)) end function isinf_r pure function isinf_d(x) result (isinf) logical :: isinf double precision, intent(in) :: x isinf = (x > huge(x)) .or. (x < -huge(x)) end function isinf_d end module aux2 program test use aux2 implicit none real :: nan, large, inf ! Create a NaN and check it nan = 0 nan = nan / nan if (nan == nan .or. nan > nan .or. nan < nan .or. nan >= nan & .or. nan <= nan) call abort if (isnan (2.d0) .or. (.not. isnan(nan)) .or. & (.not. isnan(real(nan,kind=kind(2.d0))))) call abort ! Create an INF and check it large = huge(large) inf = 2 * large if (isinf(nan) .or. isinf(large) .or. .not. isinf(inf)) call abort if (isinf(-nan) .or. isinf(-large) .or. .not. isinf(-inf)) call abort ! Check that MIN and MAX behave correctly if (max(2.0, nan) /= 2.0) call abort if (min(2.0, nan) /= 2.0) call abort if (max(nan, 2.0) /= 2.0) call abort if (min(nan, 2.0) /= 2.0) call abort if (max(2.d0, nan) /= 2.d0) call abort ! { dg-warning "Extension: Different type kinds" } if (min(2.d0, nan) /= 2.d0) call abort ! { dg-warning "Extension: Different type kinds" } if (max(nan, 2.d0) /= 2.d0) call abort ! { dg-warning "Extension: Different type kinds" } if (min(nan, 2.d0) /= 2.d0) call abort ! { dg-warning "Extension: Different type kinds" } if (.not. isnan(min(nan,nan))) call abort if (.not. isnan(max(nan,nan))) call abort ! Same thing, with more arguments if (max(3.0, 2.0, nan) /= 3.0) call abort if (min(3.0, 2.0, nan) /= 2.0) call abort if (max(3.0, nan, 2.0) /= 3.0) call abort if (min(3.0, nan, 2.0) /= 2.0) call abort if (max(nan, 3.0, 2.0) /= 3.0) call abort if (min(nan, 3.0, 2.0) /= 2.0) call abort if (max(3.d0, 2.d0, nan) /= 3.d0) call abort ! { dg-warning "Extension: Different type kinds" } if (min(3.d0, 2.d0, nan) /= 2.d0) call abort ! { dg-warning "Extension: Different type kinds" } if (max(3.d0, nan, 2.d0) /= 3.d0) call abort ! { dg-warning "Extension: Different type kinds" } if (min(3.d0, nan, 2.d0) /= 2.d0) call abort ! { dg-warning "Extension: Different type kinds" } if (max(nan, 3.d0, 2.d0) /= 3.d0) call abort ! { dg-warning "Extension: Different type kinds" } if (min(nan, 3.d0, 2.d0) /= 2.d0) call abort ! { dg-warning "Extension: Different type kinds" } if (.not. isnan(min(nan,nan,nan))) call abort if (.not. isnan(max(nan,nan,nan))) call abort if (.not. isnan(min(nan,nan,nan,nan))) call abort if (.not. isnan(max(nan,nan,nan,nan))) call abort if (.not. isnan(min(nan,nan,nan,nan,nan))) call abort if (.not. isnan(max(nan,nan,nan,nan,nan))) call abort ! Large values, INF and NaNs if (.not. isinf(max(large, inf))) call abort if (isinf(min(large, inf))) call abort if (.not. isinf(max(nan, large, inf))) call abort if (isinf(min(nan, large, inf))) call abort if (.not. isinf(max(large, nan, inf))) call abort if (isinf(min(large, nan, inf))) call abort if (.not. isinf(max(large, inf, nan))) call abort if (isinf(min(large, inf, nan))) call abort if (.not. isinf(min(-large, -inf))) call abort if (isinf(max(-large, -inf))) call abort if (.not. isinf(min(nan, -large, -inf))) call abort if (isinf(max(nan, -large, -inf))) call abort if (.not. isinf(min(-large, nan, -inf))) call abort if (isinf(max(-large, nan, -inf))) call abort if (.not. isinf(min(-large, -inf, nan))) call abort if (isinf(max(-large, -inf, nan))) call abort end program test ! { dg-final { cleanup-modules "aux2" } }
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/unformatted_subrecord_1.f90
174
1579
! { dg-do run { target fd_truncate } } ! { dg-options "-fmax-subrecord-length=16" } ! Test Intel record markers with 16-byte subrecord sizes. ! PR 32770: Use explicit kinds for all integers and constants, ! to avoid problems with -fdefault-integer-8 and -fdefault-real-8 program main implicit none integer(kind=4), dimension(20) :: n integer(kind=4), dimension(30) :: m integer(kind=4) :: i real(kind=4) :: r integer(kind=4) :: k ! Maximum subrecord length is 16 here, or the test will fail. open (10, file="f10.dat", & form="unformatted", access="sequential") n = (/ (i**2, i=1, 20) /) write (10) n close (10) ! Read back the file, including record markers. open (10, file="f10.dat", form="unformatted", access="stream") read (10) m if (any(m .ne. (/ -16, 1, 4, 9, 16, 16, -16, 25, 36, 49, 64, & -16, -16, 81, 100, 121, 144, -16, -16, 169, 196, 225, & 256, -16, 16, 289, 324, 361, 400, -16 /))) call abort close (10) open (10, file="f10.dat", form="unformatted", & access="sequential") m = 42 read (10) m(1:5) if (any(m(1:5) .ne. (/ 1, 4, 9, 16, 25 /))) call abort if (any(m(6:30) .ne. 42)) call abort backspace 10 n = 0 read (10) n(1:5) if (any(n(1:5) .ne. (/ 1, 4, 9, 16, 25 /))) call abort if (any(n(6:20) .ne. 0)) call abort ! Append to the end of the file write (10) 3.14_4 ! Test multiple backspace statements backspace 10 backspace 10 read (10) k if (k .ne. 1) call abort read (10) r if (abs(r-3.14_4) .gt. 1e-7) call abort close (10, status="delete") end program main
gpl-2.0
trankmichael/scipy
scipy/sparse/linalg/eigen/arpack/ARPACK/UTIL/dmout.f
173
5551
*----------------------------------------------------------------------- * Routine: DMOUT * * Purpose: Real matrix output routine. * * Usage: CALL DMOUT (LOUT, M, N, A, LDA, IDIGIT, IFMT) * * Arguments * M - Number of rows of A. (Input) * N - Number of columns of A. (Input) * A - Real M by N matrix to be printed. (Input) * LDA - Leading dimension of A exactly as specified in the * dimension statement of the calling program. (Input) * IFMT - Format to be used in printing matrix A. (Input) * IDIGIT - Print up to IABS(IDIGIT) decimal digits per number. (In) * If IDIGIT .LT. 0, printing is done with 72 columns. * If IDIGIT .GT. 0, printing is done with 132 columns. * *----------------------------------------------------------------------- * SUBROUTINE DMOUT( LOUT, M, N, A, LDA, IDIGIT, IFMT ) * ... * ... SPECIFICATIONS FOR ARGUMENTS * ... * ... SPECIFICATIONS FOR LOCAL VARIABLES * .. Scalar Arguments .. CHARACTER*( * ) IFMT INTEGER IDIGIT, LDA, LOUT, M, N * .. * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ) * .. * .. Local Scalars .. CHARACTER*80 LINE INTEGER I, J, K1, K2, LLL, NDIGIT * .. * .. Local Arrays .. CHARACTER ICOL( 3 ) * .. * .. Intrinsic Functions .. INTRINSIC LEN, MIN, MIN0 * .. * .. Data statements .. DATA ICOL( 1 ), ICOL( 2 ), ICOL( 3 ) / 'C', 'o', $ 'l' / * .. * .. Executable Statements .. * ... * ... FIRST EXECUTABLE STATEMENT * LLL = MIN( LEN( IFMT ), 80 ) DO 10 I = 1, LLL LINE( I: I ) = '-' 10 CONTINUE * DO 20 I = LLL + 1, 80 LINE( I: I ) = ' ' 20 CONTINUE * WRITE( LOUT, FMT = 9999 )IFMT, LINE( 1: LLL ) 9999 FORMAT( / 1X, A, / 1X, A ) * IF( M.LE.0 .OR. N.LE.0 .OR. LDA.LE.0 ) $ RETURN NDIGIT = IDIGIT IF( IDIGIT.EQ.0 ) $ NDIGIT = 4 * *======================================================================= * CODE FOR OUTPUT USING 72 COLUMNS FORMAT *======================================================================= * IF( IDIGIT.LT.0 ) THEN NDIGIT = -IDIGIT IF( NDIGIT.LE.4 ) THEN DO 40 K1 = 1, N, 5 K2 = MIN0( N, K1+4 ) WRITE( LOUT, FMT = 9998 )( ICOL, I, I = K1, K2 ) DO 30 I = 1, M WRITE( LOUT, FMT = 9994 )I, ( A( I, J ), J = K1, K2 ) 30 CONTINUE 40 CONTINUE * ELSE IF( NDIGIT.LE.6 ) THEN DO 60 K1 = 1, N, 4 K2 = MIN0( N, K1+3 ) WRITE( LOUT, FMT = 9997 )( ICOL, I, I = K1, K2 ) DO 50 I = 1, M WRITE( LOUT, FMT = 9993 )I, ( A( I, J ), J = K1, K2 ) 50 CONTINUE 60 CONTINUE * ELSE IF( NDIGIT.LE.10 ) THEN DO 80 K1 = 1, N, 3 K2 = MIN0( N, K1+2 ) WRITE( LOUT, FMT = 9996 )( ICOL, I, I = K1, K2 ) DO 70 I = 1, M WRITE( LOUT, FMT = 9992 )I, ( A( I, J ), J = K1, K2 ) 70 CONTINUE 80 CONTINUE * ELSE DO 100 K1 = 1, N, 2 K2 = MIN0( N, K1+1 ) WRITE( LOUT, FMT = 9995 )( ICOL, I, I = K1, K2 ) DO 90 I = 1, M WRITE( LOUT, FMT = 9991 )I, ( A( I, J ), J = K1, K2 ) 90 CONTINUE 100 CONTINUE END IF * *======================================================================= * CODE FOR OUTPUT USING 132 COLUMNS FORMAT *======================================================================= * ELSE IF( NDIGIT.LE.4 ) THEN DO 120 K1 = 1, N, 10 K2 = MIN0( N, K1+9 ) WRITE( LOUT, FMT = 9998 )( ICOL, I, I = K1, K2 ) DO 110 I = 1, M WRITE( LOUT, FMT = 9994 )I, ( A( I, J ), J = K1, K2 ) 110 CONTINUE 120 CONTINUE * ELSE IF( NDIGIT.LE.6 ) THEN DO 140 K1 = 1, N, 8 K2 = MIN0( N, K1+7 ) WRITE( LOUT, FMT = 9997 )( ICOL, I, I = K1, K2 ) DO 130 I = 1, M WRITE( LOUT, FMT = 9993 )I, ( A( I, J ), J = K1, K2 ) 130 CONTINUE 140 CONTINUE * ELSE IF( NDIGIT.LE.10 ) THEN DO 160 K1 = 1, N, 6 K2 = MIN0( N, K1+5 ) WRITE( LOUT, FMT = 9996 )( ICOL, I, I = K1, K2 ) DO 150 I = 1, M WRITE( LOUT, FMT = 9992 )I, ( A( I, J ), J = K1, K2 ) 150 CONTINUE 160 CONTINUE * ELSE DO 180 K1 = 1, N, 5 K2 = MIN0( N, K1+4 ) WRITE( LOUT, FMT = 9995 )( ICOL, I, I = K1, K2 ) DO 170 I = 1, M WRITE( LOUT, FMT = 9991 )I, ( A( I, J ), J = K1, K2 ) 170 CONTINUE 180 CONTINUE END IF END IF WRITE( LOUT, FMT = 9990 ) * 9998 FORMAT( 10X, 10( 4X, 3A1, I4, 1X ) ) 9997 FORMAT( 10X, 8( 5X, 3A1, I4, 2X ) ) 9996 FORMAT( 10X, 6( 7X, 3A1, I4, 4X ) ) 9995 FORMAT( 10X, 5( 9X, 3A1, I4, 6X ) ) 9994 FORMAT( 1X, ' Row', I4, ':', 1X, 1P, 10D12.3 ) 9993 FORMAT( 1X, ' Row', I4, ':', 1X, 1P, 8D14.5 ) 9992 FORMAT( 1X, ' Row', I4, ':', 1X, 1P, 6D18.9 ) 9991 FORMAT( 1X, ' Row', I4, ':', 1X, 1P, 5D22.13 ) 9990 FORMAT( 1X, ' ' ) * RETURN END
bsd-3-clause
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/pr46519-1.f
151
1032
! { dg-do compile { target i?86-*-* x86_64-*-* } } ! { dg-options "-O3 -mavx -mvzeroupper -mtune=generic -dp" } PROGRAM MG3XDEMO INTEGER LM, NM, NV, NR, NIT PARAMETER( LM=7 ) C PARAMETER( NIT=40 ) PARAMETER( NM=2+2**LM, NV=NM**3 ) PARAMETER( NR = (8*(NM**3+NM**2+5*NM-23+7*LM))/7 ) C C C If commented line is used than there is no penalty C COMMON /X/ U, V, R, A, C, IR, MM COMMON /X/ A, C, IR, MM REAL*8 A(0:3),C(0:3) INTEGER IT, N INTEGER LMI, MTIME, NTIMES C READ *,LMI READ *,NIT READ *,NTIMES READ *,U0 READ 9004, A READ 9004, C 9004 FORMAT (4D8.0) DO I = 0, 3 A(I) = A(I)/3.0D0 C(I) = C(I)/64.0D0 ENDDO C N = 2 + 2**LMI WRITE(6,7)N-2,N-2,N-2,NIT 6 FORMAT( I4, 2E19.12) 7 FORMAT(/,' KERNEL B: SOLVING A POISSON PROBLEM ON A ',I6,' BY ', > I6,' BY ',I6,' GRID,',/,' USING ',I6,' MULTIGRID ITERATIONS.',/) C STOP END ! { dg-final { scan-assembler-times "avx_vzeroupper" 1 } }
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/array_initializer_1.f90
171
1563
! { dg-do run } ! Check the fix for PR16206, in which array sections would not work ! in array initializers. Use of implied do loop variables for indices ! and substrings, with and without implied do loops, were fixed at the ! same time. ! ! Contributed by Paul Thomas <pault@gcc.gnu.org> ! based on testcase from Harald Anlauf <anlauf@gmx.de> ! real, parameter :: x(4,4) = reshape((/(i, i = 1, 16)/), (/4,4/)) real, parameter :: y(4) = (/ x(1:2, 2), x(3:4, 4)/) real, parameter :: z(2) = x(2:3, 3) + 1 real, parameter :: r(6) = (/(x(i:i +1, i), i = 1,3)/) real, parameter :: s(12) = (/((x(i, i:j-1:-1), i = 3,4), j = 2,3)/) real, parameter :: t(8) = (/(z, real (i)**3, y(i), i = 2, 3)/) integer, parameter :: ii = 4 character(4), parameter :: chr(4) = (/"abcd", "efgh", "ijkl", "mnop"/) character(4), parameter :: chrs = chr(ii)(2:3)//chr(2)(ii-3:ii-2) character(4), parameter :: chrt(2) = (/chr(2:2)(2:3), chr(ii-1)(3:ii)/) character(2), parameter :: chrx(2) = (/(chr(i)(i:i+1), i=2,3)/) if (any (y .ne. (/5., 6., 15., 16./))) call abort () if (any (z .ne. (/11., 12./))) call abort () if (any (r .ne. (/1., 2., 6., 7., 11., 12./))) call abort () if (any (s .ne. (/11., 7., 3., 16., 12., 8., 4., & 11., 7., 16., 12., 8. /))) call abort () if (any (t .ne. (/11., 12., 8., 6., 11., 12., 27., 15. /))) call abort () if (chrs .ne. "noef") call abort () if (any (chrt .ne. (/"fg", "kl"/))) call abort () if (any (chrx .ne. (/"fg", "kl"/))) call abort () end
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/subref_array_pointer_1.f90
174
1647
! { dg-do run } ! Test the fix for PRs29396, 29606, 30625 and 30871, in which pointers ! to arrays with subreferences did not work. ! call pr29396 call pr29606 call pr30625 call pr30871 contains subroutine pr29396 ! Contributed by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> CHARACTER(LEN=2), DIMENSION(:), POINTER :: a CHARACTER(LEN=4), DIMENSION(3), TARGET :: b b=(/"bbbb","bbbb","bbbb"/) a=>b(:)(2:3) a="aa" IF (ANY(b.NE.(/"baab","baab","baab"/))) CALL ABORT() END subroutine subroutine pr29606 ! Contributed by Daniel Franke <franke.daniel@gmail.com> TYPE foo INTEGER :: value END TYPE TYPE foo_array TYPE(foo), DIMENSION(:), POINTER :: array END TYPE TYPE(foo_array) :: array_holder INTEGER, DIMENSION(:), POINTER :: array_ptr ALLOCATE( array_holder%array(3) ) array_holder%array = (/ foo(1), foo(2), foo(3) /) array_ptr => array_holder%array%value if (any (array_ptr .ne. (/1,2,3/))) call abort () END subroutine subroutine pr30625 ! Contributed by Paul Thomas <pault@gcc.gnu.org> type :: a real :: r = 3.14159 integer :: i = 42 end type a type(a), target :: dt(2) integer, pointer :: ip(:) ip => dt%i if (any (ip .ne. 42)) call abort () end subroutine subroutine pr30871 ! Contributed by Joost VandeVondele <jv244@cam.ac.uk> TYPE data CHARACTER(LEN=3) :: A END TYPE TYPE(data), DIMENSION(10), TARGET :: Z CHARACTER(LEN=1), DIMENSION(:), POINTER :: ptr Z(:)%A="123" ptr=>Z(:)%A(2:2) if (any (ptr .ne. "2")) call abort () END subroutine end
gpl-2.0
Lrakulka/visp
3rdparty/lapackblas/lapack/dlasv2.f
22
8489
*> \brief \b DLASV2 computes the singular value decomposition of a 2-by-2 triangular matrix. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DLASV2 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasv2.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasv2.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasv2.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DLASV2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL ) * * .. Scalar Arguments .. * DOUBLE PRECISION CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DLASV2 computes the singular value decomposition of a 2-by-2 *> triangular matrix *> [ F G ] *> [ 0 H ]. *> On return, abs(SSMAX) is the larger singular value, abs(SSMIN) is the *> smaller singular value, and (CSL,SNL) and (CSR,SNR) are the left and *> right singular vectors for abs(SSMAX), giving the decomposition *> *> [ CSL SNL ] [ F G ] [ CSR -SNR ] = [ SSMAX 0 ] *> [-SNL CSL ] [ 0 H ] [ SNR CSR ] [ 0 SSMIN ]. *> \endverbatim * * Arguments: * ========== * *> \param[in] F *> \verbatim *> F is DOUBLE PRECISION *> The (1,1) element of the 2-by-2 matrix. *> \endverbatim *> *> \param[in] G *> \verbatim *> G is DOUBLE PRECISION *> The (1,2) element of the 2-by-2 matrix. *> \endverbatim *> *> \param[in] H *> \verbatim *> H is DOUBLE PRECISION *> The (2,2) element of the 2-by-2 matrix. *> \endverbatim *> *> \param[out] SSMIN *> \verbatim *> SSMIN is DOUBLE PRECISION *> abs(SSMIN) is the smaller singular value. *> \endverbatim *> *> \param[out] SSMAX *> \verbatim *> SSMAX is DOUBLE PRECISION *> abs(SSMAX) is the larger singular value. *> \endverbatim *> *> \param[out] SNL *> \verbatim *> SNL is DOUBLE PRECISION *> \endverbatim *> *> \param[out] CSL *> \verbatim *> CSL is DOUBLE PRECISION *> The vector (CSL, SNL) is a unit left singular vector for the *> singular value abs(SSMAX). *> \endverbatim *> *> \param[out] SNR *> \verbatim *> SNR is DOUBLE PRECISION *> \endverbatim *> *> \param[out] CSR *> \verbatim *> CSR is DOUBLE PRECISION *> The vector (CSR, SNR) is a unit right singular vector for the *> singular value abs(SSMAX). *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date December 2016 * *> \ingroup OTHERauxiliary * *> \par Further Details: * ===================== *> *> \verbatim *> *> Any input parameter may be aliased with any output parameter. *> *> Barring over/underflow and assuming a guard digit in subtraction, all *> output quantities are correct to within a few units in the last *> place (ulps). *> *> 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 DLASV2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL ) * * -- LAPACK auxiliary 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 .. DOUBLE PRECISION CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO PARAMETER ( ZERO = 0.0D0 ) DOUBLE PRECISION HALF PARAMETER ( HALF = 0.5D0 ) DOUBLE PRECISION ONE PARAMETER ( ONE = 1.0D0 ) DOUBLE PRECISION TWO PARAMETER ( TWO = 2.0D0 ) DOUBLE PRECISION FOUR PARAMETER ( FOUR = 4.0D0 ) * .. * .. Local Scalars .. LOGICAL GASMAL, SWAP INTEGER PMAX DOUBLE PRECISION A, CLT, CRT, D, FA, FT, GA, GT, HA, HT, L, M, $ MM, R, S, SLT, SRT, T, TEMP, TSIGN, TT * .. * .. Intrinsic Functions .. INTRINSIC ABS, SIGN, SQRT * .. * .. External Functions .. DOUBLE PRECISION DLAMCH EXTERNAL DLAMCH * .. * .. Executable Statements .. * FT = F FA = ABS( FT ) HT = H HA = ABS( H ) * * PMAX points to the maximum absolute element of matrix * PMAX = 1 if F largest in absolute values * PMAX = 2 if G largest in absolute values * PMAX = 3 if H largest in absolute values * PMAX = 1 SWAP = ( HA.GT.FA ) IF( SWAP ) THEN PMAX = 3 TEMP = FT FT = HT HT = TEMP TEMP = FA FA = HA HA = TEMP * * Now FA .ge. HA * END IF GT = G GA = ABS( GT ) IF( GA.EQ.ZERO ) THEN * * Diagonal matrix * SSMIN = HA SSMAX = FA CLT = ONE CRT = ONE SLT = ZERO SRT = ZERO ELSE GASMAL = .TRUE. IF( GA.GT.FA ) THEN PMAX = 2 IF( ( FA / GA ).LT.DLAMCH( 'EPS' ) ) THEN * * Case of very large GA * GASMAL = .FALSE. SSMAX = GA IF( HA.GT.ONE ) THEN SSMIN = FA / ( GA / HA ) ELSE SSMIN = ( FA / GA )*HA END IF CLT = ONE SLT = HT / GT SRT = ONE CRT = FT / GT END IF END IF IF( GASMAL ) THEN * * Normal case * D = FA - HA IF( D.EQ.FA ) THEN * * Copes with infinite F or H * L = ONE ELSE L = D / FA END IF * * Note that 0 .le. L .le. 1 * M = GT / FT * * Note that abs(M) .le. 1/macheps * T = TWO - L * * Note that T .ge. 1 * MM = M*M TT = T*T S = SQRT( TT+MM ) * * Note that 1 .le. S .le. 1 + 1/macheps * IF( L.EQ.ZERO ) THEN R = ABS( M ) ELSE R = SQRT( L*L+MM ) END IF * * Note that 0 .le. R .le. 1 + 1/macheps * A = HALF*( S+R ) * * Note that 1 .le. A .le. 1 + abs(M) * SSMIN = HA / A SSMAX = FA*A IF( MM.EQ.ZERO ) THEN * * Note that M is very tiny * IF( L.EQ.ZERO ) THEN T = SIGN( TWO, FT )*SIGN( ONE, GT ) ELSE T = GT / SIGN( D, FT ) + M / T END IF ELSE T = ( M / ( S+T )+M / ( R+L ) )*( ONE+A ) END IF L = SQRT( T*T+FOUR ) CRT = TWO / L SRT = T / L CLT = ( CRT+SRT*M ) / A SLT = ( HT / FT )*SRT / A END IF END IF IF( SWAP ) THEN CSL = SRT SNL = CRT CSR = SLT SNR = CLT ELSE CSL = CLT SNL = SLT CSR = CRT SNR = SRT END IF * * Correct signs of SSMAX and SSMIN * IF( PMAX.EQ.1 ) $ TSIGN = SIGN( ONE, CSR )*SIGN( ONE, CSL )*SIGN( ONE, F ) IF( PMAX.EQ.2 ) $ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, CSL )*SIGN( ONE, G ) IF( PMAX.EQ.3 ) $ TSIGN = SIGN( ONE, SNR )*SIGN( ONE, SNL )*SIGN( ONE, H ) SSMAX = SIGN( SSMAX, TSIGN ) SSMIN = SIGN( SSMIN, TSIGN*SIGN( ONE, F )*SIGN( ONE, H ) ) RETURN * * End of DLASV2 * END
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/intrinsic_spread_1.f90
174
6514
! { dg-do run } program foo implicit none integer(kind=1), dimension (10) :: i_1 integer(kind=1), dimension (2, 3) :: a_1 integer(kind=1), dimension (2, 2, 3) :: b_1 integer(kind=2), dimension (10) :: i_2 integer(kind=2), dimension (2, 3) :: a_2 integer(kind=2), dimension (2, 2, 3) :: b_2 integer(kind=4), dimension (10) :: i_4 integer(kind=4), dimension (2, 3) :: a_4 integer(kind=4), dimension (2, 2, 3) :: b_4 integer(kind=8), dimension (10) :: i_8 integer(kind=8), dimension (2, 3) :: a_8 integer(kind=8), dimension (2, 2, 3) :: b_8 real(kind=4), dimension (10) :: r_4 real(kind=4), dimension (2, 3) :: ar_4 real(kind=4), dimension (2, 2, 3) :: br_4 real(kind=8), dimension (10) :: r_8 real(kind=8), dimension (2, 3) :: ar_8 real(kind=8), dimension (2, 2, 3) :: br_8 complex(kind=4), dimension (10) :: c_4 complex(kind=4), dimension (2, 3) :: ac_4 complex(kind=4), dimension (2, 2, 3) :: bc_4 complex(kind=8), dimension (10) :: c_8 complex(kind=8), dimension (2, 3) :: ac_8 complex(kind=8), dimension (2, 2, 3) :: bc_8 type i4_t integer(kind=4) :: v end type i4_t type(i4_t), dimension (10) :: it_4 type(i4_t), dimension (2, 3) :: at_4 type(i4_t), dimension (2, 2, 3) :: bt_4 type(i4_t) :: iv_4 character (len=200) line1, line2, line3 a_1 = reshape ((/1_1, 2_1, 3_1, 4_1, 5_1, 6_1/), (/2, 3/)) b_1 = spread (a_1, 1, 2) if (any (b_1 .ne. reshape ((/1_1, 1_1, 2_1, 2_1, 3_1, 3_1, 4_1, 4_1, 5_1, 5_1, 6_1, 6_1/), & (/2, 2, 3/)))) & call abort line1 = ' ' write(line1, 9000) b_1 line2 = ' ' write(line2, 9000) spread (a_1, 1, 2) if (line1 /= line2) call abort line3 = ' ' write(line3, 9000) spread (a_1, 1, 2) + 0_1 if (line1 /= line3) call abort i_1 = spread(1_1,1,10) if (any(i_1 /= 1_1)) call abort a_2 = reshape ((/1_2, 2_2, 3_2, 4_2, 5_2, 6_2/), (/2, 3/)) b_2 = spread (a_2, 1, 2) if (any (b_2 .ne. reshape ((/1_2, 1_2, 2_2, 2_2, 3_2, 3_2, 4_2, 4_2, 5_2, 5_2, 6_2, 6_2/), & (/2, 2, 3/)))) & call abort line1 = ' ' write(line1, 9000) b_2 line2 = ' ' write(line2, 9000) spread (a_2, 1, 2) if (line1 /= line2) call abort line3 = ' ' write(line3, 9000) spread (a_2, 1, 2) + 0_2 if (line1 /= line3) call abort i_2 = spread(1_2,1,10) if (any(i_2 /= 1_2)) call abort a_4 = reshape ((/1_4, 2_4, 3_4, 4_4, 5_4, 6_4/), (/2, 3/)) b_4 = spread (a_4, 1, 2) if (any (b_4 .ne. reshape ((/1_4, 1_4, 2_4, 2_4, 3_4, 3_4, 4_4, 4_4, 5_4, 5_4, 6_4, 6_4/), & (/2, 2, 3/)))) & call abort line1 = ' ' write(line1, 9000) b_4 line2 = ' ' write(line2, 9000) spread (a_4, 1, 2) if (line1 /= line2) call abort line3 = ' ' write(line3, 9000) spread (a_4, 1, 2) + 0_4 if (line1 /= line3) call abort i_4 = spread(1_4,1,10) if (any(i_4 /= 1_4)) call abort a_8 = reshape ((/1_8, 2_8, 3_8, 4_8, 5_8, 6_8/), (/2, 3/)) b_8 = spread (a_8, 1, 2) if (any (b_8 .ne. reshape ((/1_8, 1_8, 2_8, 2_8, 3_8, 3_8, 4_8, 4_8, 5_8, 5_8, 6_8, 6_8/), & (/2, 2, 3/)))) & call abort line1 = ' ' write(line1, 9000) b_8 line2 = ' ' write(line2, 9000) spread (a_8, 1, 2) if (line1 /= line2) call abort line3 = ' ' write(line3, 9000) spread (a_8, 1, 2) + 0_8 if (line1 /= line3) call abort i_8 = spread(1_8,1,10) if (any(i_8 /= 1_8)) call abort ar_4 = reshape ((/1._4, 2._4, 3._4, 4._4, 5._4, 6._4/), (/2, 3/)) br_4 = spread (ar_4, 1, 2) if (any (br_4 .ne. reshape ((/1._4, 1._4, 2._4, 2._4, 3._4, 3._4, & & 4._4, 4._4, 5._4, 5._4, 6._4, 6._4/), (/2, 2, 3/)))) call abort line1 = ' ' write(line1, 9010) br_4 line2 = ' ' write(line2, 9010) spread (ar_4, 1, 2) if (line1 /= line2) call abort line3 = ' ' write(line3, 9010) spread (ar_4, 1, 2) + 0._4 if (line1 /= line3) call abort r_4 = spread(1._4,1,10) if (any(r_4 /= 1._4)) call abort ar_8 = reshape ((/1._8, 2._8, 3._8, 4._8, 5._8, 6._8/), (/2, 3/)) br_8 = spread (ar_8, 1, 2) if (any (br_8 .ne. reshape ((/1._8, 1._8, 2._8, 2._8, 3._8, 3._8, & & 4._8, 4._8, 5._8, 5._8, 6._8, 6._8/), (/2, 2, 3/)))) call abort line1 = ' ' write(line1, 9010) br_8 line2 = ' ' write(line2, 9010) spread (ar_8, 1, 2) if (line1 /= line2) call abort line3 = ' ' write(line3, 9010) spread (ar_8, 1, 2) + 0._8 if (line1 /= line3) call abort r_8 = spread(1._8,1,10) if (any(r_8 /= 1._8)) call abort ac_4 = reshape ((/(1._4,-1._4), (2._4,-2._4), (3._4, -3._4), (4._4, -4._4), & & (5._4,-5._4), (6._4,-6._4)/), (/2, 3/)) bc_4 = spread (ac_4, 1, 2) if (any (real(bc_4) .ne. reshape ((/1._4, 1._4, 2._4, 2._4, 3._4, 3._4, & & 4._4, 4._4, 5._4, 5._4, 6._4, 6._4/), (/2, 2, 3/)))) call abort if (any (-aimag(bc_4) .ne. reshape ((/1._4, 1._4, 2._4, 2._4, 3._4, 3._4, & & 4._4, 4._4, 5._4, 5._4, 6._4, 6._4/), (/2, 2, 3/)))) call abort line1 = ' ' write(line1, 9020) bc_4 line2 = ' ' write(line2, 9020) spread (ac_4, 1, 2) if (line1 /= line2) call abort line3 = ' ' write(line3, 9020) spread (ac_4, 1, 2) + 0._4 if (line1 /= line3) call abort c_4 = spread((1._4,-1._4),1,10) if (any(c_4 /= (1._4,-1._4))) call abort ac_8 = reshape ((/(1._8,-1._8), (2._8,-2._8), (3._8, -3._8), (4._8, -4._8), & & (5._8,-5._8), (6._8,-6._8)/), (/2, 3/)) bc_8 = spread (ac_8, 1, 2) if (any (real(bc_8) .ne. reshape ((/1._8, 1._8, 2._8, 2._8, 3._8, 3._8, & & 4._8, 4._8, 5._8, 5._8, 6._8, 6._8/), (/2, 2, 3/)))) call abort if (any (-aimag(bc_8) .ne. reshape ((/1._8, 1._8, 2._8, 2._8, 3._8, 3._8, & & 4._8, 4._8, 5._8, 5._8, 6._8, 6._8/), (/2, 2, 3/)))) call abort line1 = ' ' write(line1, 9020) bc_8 line2 = ' ' write(line2, 9020) spread (ac_8, 1, 2) if (line1 /= line2) call abort line3 = ' ' write(line3, 9020) spread (ac_8, 1, 2) + 0._8 if (line1 /= line3) call abort c_8 = spread((1._8,-1._8),1,10) if (any(c_8 /= (1._8,-1._8))) call abort at_4%v = reshape ((/1_4, 2_4, 3_4, 4_4, 5_4, 6_4/), (/2, 3/)) bt_4 = spread (at_4, 1, 2) if (any (bt_4%v .ne. reshape ((/1_4, 1_4, 2_4, 2_4, 3_4, 3_4, 4_4, & & 4_4, 5_4, 5_4, 6_4, 6_4/), (/2, 2, 3/)))) & call abort iv_4%v = 123_4 it_4 = spread(iv_4,1,10) if (any(it_4%v /= 123_4)) call abort 9000 format(12I3) 9010 format(12F7.3) 9020 format(25F7.3) end program
gpl-2.0
eiselekd/gcc
libgomp/testsuite/libgomp.fortran/omp_parse4.f90
202
1904
! { dg-do run } !$ use omp_lib call test_workshare contains subroutine test_workshare integer :: i, j, k, l, m double precision, dimension (64) :: d, e integer, dimension (10) :: f, g integer, dimension (16, 16) :: a, b, c integer, dimension (16) :: n d(:) = 1 e = 7 f = 10 l = 256 m = 512 g(1:3) = -1 g(4:6) = 0 g(7:8) = 5 g(9:10) = 10 forall (i = 1:16, j = 1:16) a (i, j) = i * 16 + j forall (j = 1:16) n (j) = j !$omp parallel num_threads (4) private (j, k) !$omp barrier !$omp workshare i = 6 e(:) = d(:) where (g .lt. 0) f = 100 elsewhere (g .eq. 0) f = 200 + f elsewhere where (g .gt. 6) f = f + sum (g) f = 300 + f end where where (f .gt. 210) g = 0 !$omp end workshare nowait !$omp workshare forall (j = 1:16, k = 1:16) b (k, j) = a (j, k) forall (k = 1:16) c (k, 1:16) = a (1:16, k) forall (j = 2:16, n (17 - j) / 4 * 4 .ne. n (17 - j)) n (j) = n (j - 1) * n (j) end forall !$omp endworkshare !$omp workshare !$omp atomic i = i + 8 + 6 !$omp critical !$omp critical (critical_foox) l = 128 !$omp end critical (critical_foox) !$omp endcritical !$omp parallel num_threads (2) !$ if (omp_get_thread_num () .eq. 0) m = omp_get_num_threads () !$omp atomic l = 1 + l !$omp end parallel !$omp end workshare !$omp end parallel if (any (f .ne. (/100, 100, 100, 210, 210, 210, 310, 310, 337, 337/))) & & call abort if (any (g .ne. (/-1, -1, -1, 0, 0, 0, 0, 0, 0, 0/))) call abort if (i .ne. 20) call abort !$ if (l .ne. 128 + m) call abort if (any (d .ne. 1 .or. e .ne. 1)) call abort if (any (b .ne. transpose (a))) call abort if (any (c .ne. b)) call abort if (any (n .ne. (/1, 2, 6, 12, 5, 30, 42, 56, 9, 90, & & 110, 132, 13, 182, 210, 240/))) call abort end subroutine test_workshare end
gpl-2.0
pablodebiase/bromoc-e_suite
tools/src/wordmod.f90
3
4820
! WORDMOD Word Handler Library/Module ! Copyright (C) 2014 Pablo M. De Biase (pablodebiase@gmail.com) ! ! This program 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. ! ! This program 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. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. module wordmod implicit none contains ! convert integer to character function num2str(n,mx) implicit none integer n,num,i,a,mx character num2str*(mx),numero*10 numero='0123456789' num=n do i=mx,1,-1 a=int(num/(10**(i-1))) num2str(mx-i+1:mx-i+1)=numero(a+1:a+1) num=num-a*10**(i-1) enddo end function ! convert to lowercase function lcase(inchar) implicit none integer i integer*1 s character ( len = * ) inchar character ( len = len_trim(inchar) ) lcase lcase=trim(inchar) do i=1,len(lcase) s=iachar(lcase(i:i)) if (s.ge.65.and.s.le.90) lcase(i:i)=achar(s+32) enddo end function ! convert to uppercase function ucase(inchar) implicit none integer i integer*1 s character ( len = * ) inchar character ( len = len_trim(inchar) ) ucase ucase=trim(inchar) do i=1,len(ucase) s=iachar(ucase(i:i)) if (s.ge.97.and.s.le.122) ucase(i:i)=achar(s-32) enddo end function ! convert character to integer function chr2int(str) implicit none integer chr2int,kode character str*(*) read(str,*,iostat=kode) chr2int if (kode.ne.0) stop 'Not an integer' end function ! convert character to real8 function chr2real(str) implicit none integer kode real*8 chr2real character str*(*) read(str,*,iostat=kode) chr2real if (kode.ne.0) stop 'Not a real' end function ! get parameter pn from line function getparm(str,num,llim,ulim,pn) implicit none integer num,pn integer llim(*),ulim(*) character getparm*(ulim(pn)-llim(pn)+1),str*(*) if (pn.gt.num.or.pn.lt.1.or.num.lt.1) then getparm='' else getparm=str(llim(pn):ulim(pn)) endif end function function isint(str) implicit none character str*(*) integer*4 test,kode logical*1 isint read(str,*,iostat=kode) test if (kode.eq.0) then isint=.true. else isint=.false. endif end function function isreal(str) implicit none character str*(*) integer*4 kode real*8 test logical*1 isreal read(str,*,iostat=kode) test if (kode.eq.0) then isreal=.true. else isreal=.false. endif end function function isword(str) implicit none integer*4 i,s character str*(*) logical*1 isword isword=.true. if (len_trim(str).eq.0) isword=.false. do i=1,len_trim(str) s=iachar(str(i:i)) if (.not.((s.ge.65.and.s.le.90).or.(s.ge.97.and.s.le.122))) then isword=.false. return endif enddo end function function iswordnum(str) implicit none integer*4 i,s character str*(*) logical*1 iswordnum iswordnum=.true. if (len_trim(str).eq.0) iswordnum=.false. do i=1,len_trim(str) s=iachar(str(i:i)) if (.not.((s.ge.65.and.s.le.90).or.(s.ge.97.and.s.le.122).or.(s.ge.48.and.s.le.57))) then iswordnum=.false. return endif enddo end function function isalfa(str) implicit none integer*4 i,s character str*(*) logical*1 isalfa isalfa=.true. if (len_trim(str).eq.0) isalfa=.false. do i=1,len_trim(str) s=iachar(str(i:i)) if (s.le.32.or.s.ge.127) then isalfa=.false. return endif enddo end function ! identify words from line subroutine findparm(str,num,llim,ulim) implicit none integer i,length,num integer ulim(*),llim(*) character str*(*) logical chng length=len_trim(str) chng=.false. num=0 do i=1,length if (iachar(str(i:i)).le.32.or.iachar(str(i:i)).ge.127) then if (chng) ulim(num)=i-1 chng=.false. else if (.not.chng) then num=num+1 llim(num)=i ulim(num)=0 endif chng=.true. endif enddo if (ulim(num).eq.0) ulim(num)=length end subroutine subroutine countparm(str,num) implicit none integer i,length,num character str*(*) logical chng length=len_trim(str) chng=.false. num=0 do i=1,length if (iachar(str(i:i)).le.32.or.iachar(str(i:i)).ge.127) then chng=.false. else if (.not.chng) num=num+1 chng=.true. endif enddo end subroutine end module
gpl-3.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/coarray_lib_alloc_4.f90
9
1927
! { dg-do run } ! { dg-options "-fcoarray=lib -lcaf_single -fdump-tree-original" } ! { dg-additional-options "-latomic" { target libatomic_available } } ! ! Allocate/deallocate with libcaf. ! program test_caf_alloc type t integer, allocatable :: i real, allocatable :: r(:) end type t type(t), allocatable :: xx[:] allocate (xx[*]) if (allocated(xx%i)) call abort() if (allocated(xx[1]%i)) call abort() if (allocated(xx[1]%r)) call abort() allocate(xx%i) if (.not. allocated(xx[1]%i)) call abort() if (allocated(xx[1]%r)) call abort() allocate(xx%r(5)) if (.not. allocated(xx[1]%i)) call abort() if (.not. allocated(xx[1]%r)) call abort() deallocate(xx%i) if (allocated(xx[1]%i)) call abort() if (.not. allocated(xx[1]%r)) call abort() deallocate(xx%r) if (allocated(xx[1]%i)) call abort() if (allocated(xx[1]%r)) call abort() deallocate(xx) end ! { dg-final { scan-tree-dump-times "_gfortran_caf_is_present \\(xx\\.token, 2 - \\(integer\\(kind=4\\)\\) xx\\.dim\\\[0\\\]\\.lbound, &caf_ref\\.\[0-9\]+\\)|_gfortran_caf_is_present \\(xx\\.token, 2 - xx\\.dim\\\[0\\\]\\.lbound, &caf_ref\\.\[0-9\]+\\)" 10 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_register \\(\[0-9\]+, 1, &xx\\.token, \\(void \\*\\) &xx, 0B, 0B, 0\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_register \\(\[0-9\]+, 7" 2 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_register \\(\[0-9\]+, 8" 2 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_deregister \\(&xx\\.token, 0, 0B, 0B, 0\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_deregister \\(&\\(\\(struct t \\* restrict\\) xx\\.data\\)->r\\.token, 1, 0B, 0B, 0\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_deregister \\(&\\(\\(struct t \\* restrict\\) xx\\.data\\)->_caf_i, 1, 0B, 0B, 0\\)" 1 "original" } }
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/substr_5.f90
174
1277
! { dg-do run } ! character(*), parameter :: chrs = '-+.0123456789eEdD' character(*), parameter :: expr = '-+.0123456789eEdD' integer :: i if (index(chrs(:), expr) /= 1) call abort if (index(chrs(14:), expr) /= 0) call abort if (index(chrs(:12), expr) /= 0) call abort if (index(chrs, expr(:)) /= 1) call abort if (index(chrs, expr(1:)) /= 1) call abort if (index(chrs, expr(:1)) /= 1) call abort if (foo(expr) /= 1) call abort if (foo(expr) /= 1) call abort if (foo(expr) /= 1) call abort if (foo(expr(:)) /= 1) call abort if (foo(expr(1:)) /= 1) call abort if (foo(expr(:1)) /= 1) call abort call bar(expr) contains subroutine bar(expr) character(*), intent(in) :: expr character(*), parameter :: chrs = '-+.0123456789eEdD' integer :: foo if (index(chrs(:), expr) /= 1) call abort if (index(chrs(14:), expr) /= 0) call abort if (index(chrs(:12), expr) /= 0) call abort if (index(chrs, expr(:)) /= 1) call abort if (index(chrs, expr(1:)) /= 1) call abort if (index(chrs, expr(:1)) /= 1) call abort end subroutine bar integer function foo(expr) character(*), intent(in) :: expr character(*), parameter :: chrs = '-+.0123456789eEdD' foo = index(chrs, expr) end function foo end
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/substr_5.f90
174
1277
! { dg-do run } ! character(*), parameter :: chrs = '-+.0123456789eEdD' character(*), parameter :: expr = '-+.0123456789eEdD' integer :: i if (index(chrs(:), expr) /= 1) call abort if (index(chrs(14:), expr) /= 0) call abort if (index(chrs(:12), expr) /= 0) call abort if (index(chrs, expr(:)) /= 1) call abort if (index(chrs, expr(1:)) /= 1) call abort if (index(chrs, expr(:1)) /= 1) call abort if (foo(expr) /= 1) call abort if (foo(expr) /= 1) call abort if (foo(expr) /= 1) call abort if (foo(expr(:)) /= 1) call abort if (foo(expr(1:)) /= 1) call abort if (foo(expr(:1)) /= 1) call abort call bar(expr) contains subroutine bar(expr) character(*), intent(in) :: expr character(*), parameter :: chrs = '-+.0123456789eEdD' integer :: foo if (index(chrs(:), expr) /= 1) call abort if (index(chrs(14:), expr) /= 0) call abort if (index(chrs(:12), expr) /= 0) call abort if (index(chrs, expr(:)) /= 1) call abort if (index(chrs, expr(1:)) /= 1) call abort if (index(chrs, expr(:1)) /= 1) call abort end subroutine bar integer function foo(expr) character(*), intent(in) :: expr character(*), parameter :: chrs = '-+.0123456789eEdD' foo = index(chrs, expr) end function foo end
gpl-2.0
eiselekd/gcc
libgfortran/generated/_atan2_r10.F90
9
1490
! Copyright (C) 2002-2017 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_10) #ifdef HAVE_ATAN2L elemental function _gfortran_specific__atan2_r10 (p1, p2) real (kind=10), intent (in) :: p1, p2 real (kind=10) :: _gfortran_specific__atan2_r10 _gfortran_specific__atan2_r10 = atan2 (p1, p2) end function #endif #endif
gpl-2.0
dagss/healpix
src/f90/mod/indmed.f90
3
7331
!----------------------------------------------------------------------------- ! ! Copyright (C) 1997-2013 Krzysztof M. Gorski, Eric Hivon, ! Benjamin D. Wandelt, Anthony J. Banday, ! Matthias Bartelmann, Hans K. Eriksen, ! Frode K. Hansen, Martin Reinecke ! ! ! This file is part of HEALPix. ! ! HEALPix 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 2 of the License, or ! (at your option) any later version. ! ! HEALPix 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. ! ! You should have received a copy of the GNU General Public License ! along with HEALPix; if not, write to the Free Software ! Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ! ! For more information about HEALPix see http://healpix.sourceforge.net ! !----------------------------------------------------------------------------- ! ! module m_indmed of Orderpack 2.0, by Michel Olagnon http://www.fortran-2000.com/rank/ ! ! edited 2012-07-16: ! - use includes to avoid repetition of same lines of code ! for R,D, I (and forthcoming) implementations ! - remove SAVE attribute of IDONT, and remove IDONT from module header ! Module m_indmed Integer, Parameter :: kdp = selected_real_kind(12,200) Integer, Parameter :: ksp = selected_real_kind(5, 30) Integer, Parameter :: i4b = selected_int_kind(9) public :: indmed private :: kdp, ksp, i4b private :: R_indmed, I_indmed, D_indmed private :: r_med, i_med, d_med !! Integer, Allocatable, Dimension(:), Private, Save :: IDONT interface indmed module procedure d_indmed, r_indmed, i_indmed end interface contains ! ************************************************************* Subroutine D_indmed (XDONT, INDM) ! Returns index of median value of XDONT. ! __________________________________________________________ Real (kind=kdp), Dimension (:), Intent (In) :: XDONT Integer (kind=i4b), Intent (Out):: INDM integer, allocatable, dimension(:) :: idont Integer :: tmpout, IDON ! can be 4 or 8 bytes depending on default ! __________________________________________________________ ! Allocate (IDONT (SIZE(XDONT))) Do IDON = 1, SIZE(XDONT) IDONT (IDON) = IDON End Do ! Call d_med (XDONT, IDONT, tmpout) indm = tmpout ! Deallocate (IDONT) End Subroutine D_indmed Recursive Subroutine d_med (XDATT, IDATT, ires_med) ! Finds the index of the median of XDONT using the recursive procedure ! described in Knuth, The Art of Computer Programming, ! vol. 3, 5.3.3 - This procedure is linear in time, and ! does not require to be able to interpolate in the ! set as the one used in INDNTH. It also has better worst ! case behavior than INDNTH, but is about 30% slower in ! average for random uniformly distributed values. ! __________________________________________________________ Real (kind=kdp), Dimension (:), Intent (In) :: XDATT Integer, Dimension (:), Intent (In) :: IDATT Integer, Intent (Out):: ires_med ! __________________________________________________________ ! Real (kind=kdp), Parameter :: XHUGE = HUGE (XDATT) Real (kind=kdp) :: XWRK, XWRK1, XMED7, XMAX, XMIN ! Integer, Dimension (7*(((Size (IDATT)+6)/7+6)/7)) :: ISTRT, IENDT, IMEDT Integer, Dimension (7*((Size(IDATT)+6)/7)) :: IWRKT Integer :: NTRI, NMED, NORD, NEQU, NLEQ, IMED, IDON, IDON1 Integer :: IDEB, ITMP, IDCR, ICRS, ICRS1, ICRS2, IMAX, IMIN Integer :: IWRK, IWRK1, IMED1, IMED7, NDAT ! NDAT = Size (IDATT) include 'indmed_part1.f90' Call d_med (XDATT, IMEDT(1:IDON1), IMED7) include 'indmed_part2.f90' ! END Subroutine d_med ! ************************************************************* Subroutine R_indmed (XDONT, INDM) ! Returns index of median value of XDONT. ! __________________________________________________________ Real (kind=ksp), Dimension (:), Intent (In) :: XDONT Integer (kind=i4b), Intent (Out):: INDM integer, allocatable, dimension(:) :: idont Integer :: tmpout, IDON ! can be 4 or 8 bytes depending on default ! __________________________________________________________ ! Allocate (IDONT (SIZE(XDONT))) Do IDON = 1, SIZE(XDONT) IDONT (IDON) = IDON End Do ! Call r_med (XDONT, IDONT, tmpout) indm = tmpout ! Deallocate (IDONT) End Subroutine R_indmed Recursive Subroutine r_med (XDATT, IDATT, ires_med) ! __________________________________________________________ Real, Dimension (:), Intent (In) :: XDATT Integer, Dimension (:), Intent (In) :: IDATT Integer, Intent (Out) :: ires_med ! __________________________________________________________ ! Real, Parameter :: XHUGE = HUGE (XDATT) Real :: XWRK, XWRK1, XMED7, XMAX, XMIN ! Integer, Dimension (7*(((Size (IDATT)+6)/7+6)/7)) :: ISTRT, IENDT, IMEDT Integer, Dimension (7*((Size(IDATT)+6)/7)) :: IWRKT Integer :: NTRI, NMED, NORD, NEQU, NLEQ, IMED, IDON, IDON1 Integer :: IDEB, ITMP, IDCR, ICRS, ICRS1, ICRS2, IMAX, IMIN Integer :: IWRK, IWRK1, IMED1, IMED7, NDAT ! NDAT = Size (IDATT) include 'indmed_part1.f90' Call r_med (XDATT, IMEDT(1:IDON1), IMED7) include 'indmed_part2.f90' ! END Subroutine r_med ! ************************************************************* Subroutine I_indmed (XDONT, INDM) ! Returns index of median value of XDONT. ! __________________________________________________________ Integer, Dimension (:), Intent (In) :: XDONT Integer, Intent (Out) :: INDM integer, allocatable, dimension(:) :: idont Integer :: tmpout, IDON ! __________________________________________________________ ! Allocate (IDONT (SIZE(XDONT))) Do IDON = 1, SIZE(XDONT) IDONT (IDON) = IDON End Do ! Call i_med (XDONT, IDONT, tmpout) INDM = tmpout ! Deallocate (IDONT) End Subroutine I_indmed Recursive Subroutine i_med (XDATT, IDATT, ires_med) ! __________________________________________________________ Integer, Dimension (:), Intent (In) :: XDATT Integer, Dimension (:), Intent (In) :: IDATT Integer, Intent (Out) :: ires_med ! __________________________________________________________ ! Integer, Parameter :: XHUGE = HUGE (XDATT) Integer :: XWRK, XWRK1, XMED7, XMAX, XMIN ! Integer, Dimension (7*(((Size (IDATT)+6)/7+6)/7)) :: ISTRT, IENDT, IMEDT Integer, Dimension (7*((Size(IDATT)+6)/7)) :: IWRKT Integer :: NTRI, NMED, NORD, NEQU, NLEQ, IMED, IDON, IDON1 Integer :: IDEB, ITMP, IDCR, ICRS, ICRS1, ICRS2, IMAX, IMIN Integer :: IWRK, IWRK1, IMED1, IMED7, NDAT ! NDAT = Size (IDATT) include 'indmed_part1.f90' Call i_med (XDATT, IMEDT(1:IDON1), IMED7) include 'indmed_part2.f90' END Subroutine i_med end module m_indmed
gpl-2.0
msleigh/snes
src/io_utils.f90
1
1404
MODULE io_utils_mod PRIVATE PUBLIC :: get_free_lun CONTAINS !> \author msleigh !! !! PURPOSE: Gets free logical unit number (LUN) !! !! STRUCTURE !! 1. Initialise variables !! 2. Find free LUN SUBROUTINE get_free_lun( & & logical_unit_number, & & errstat) USE getkinds_mod IMPLICIT NONE CHARACTER(LEN=12), PARAMETER :: unitname = 'GET_FREE_LUN' INTEGER(KIND=ik), INTENT(OUT) :: logical_unit_number !< INTEGER(KIND=ik), INTENT(OUT) :: errstat !< LOGICAL :: lun_in_use !---------------------------------------------------------------------------- ! 1. Initialise variables !---------------------------------------------------------------------------- errstat = 0_ik logical_unit_number = 0_ik lun_in_use = .TRUE. !---------------------------------------------------------------------------- ! 2. Find free LUN !---------------------------------------------------------------------------- DO WHILE (lun_in_use .AND. logical_unit_number < 100_ik) logical_unit_number = logical_unit_number + 1_ik INQUIRE( & & UNIT=logical_unit_number, & & OPENED=lun_in_use) ENDDO IF (lun_in_use .AND. logical_unit_number == 100_ik) THEN WRITE(*,*) unitname, ': ERROR - no free logical unit numbers available' errstat = -1_ik RETURN ENDIF RETURN END SUBROUTINE get_free_lun END MODULE io_utils_mod
mit
Lrakulka/visp
3rdparty/lapackblas/lapack/dlasd3.f
3
14988
*> \brief \b DLASD3 finds all square roots of the roots of the secular equation, as defined by the values in D and Z, and then updates the singular vectors by matrix multiplication. Used by sbdsdc. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DLASD3 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasd3.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasd3.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasd3.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DLASD3( NL, NR, SQRE, K, D, Q, LDQ, DSIGMA, U, LDU, U2, * LDU2, VT, LDVT, VT2, LDVT2, IDXC, CTOT, Z, * INFO ) * * .. Scalar Arguments .. * INTEGER INFO, K, LDQ, LDU, LDU2, LDVT, LDVT2, NL, NR, * $ SQRE * .. * .. Array Arguments .. * INTEGER CTOT( * ), IDXC( * ) * DOUBLE PRECISION D( * ), DSIGMA( * ), Q( LDQ, * ), U( LDU, * ), * $ U2( LDU2, * ), VT( LDVT, * ), VT2( LDVT2, * ), * $ Z( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DLASD3 finds all the square roots of the roots of the secular *> equation, as defined by the values in D and Z. It makes the *> appropriate calls to DLASD4 and then updates the singular *> vectors by matrix multiplication. *> *> 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. *> *> DLASD3 is called from DLASD1. *> \endverbatim * * Arguments: * ========== * *> \param[in] NL *> \verbatim *> NL is INTEGER *> The row dimension of the upper block. NL >= 1. *> \endverbatim *> *> \param[in] NR *> \verbatim *> NR is INTEGER *> The row dimension of the lower block. NR >= 1. *> \endverbatim *> *> \param[in] SQRE *> \verbatim *> SQRE is INTEGER *> = 0: the lower block is an NR-by-NR square matrix. *> = 1: the lower block is an NR-by-(NR+1) rectangular matrix. *> *> The bidiagonal matrix has N = NL + NR + 1 rows and *> M = N + SQRE >= N columns. *> \endverbatim *> *> \param[in] K *> \verbatim *> K is INTEGER *> The size of the secular equation, 1 =< K = < N. *> \endverbatim *> *> \param[out] D *> \verbatim *> D is DOUBLE PRECISION array, dimension(K) *> On exit the square roots of the roots of the secular equation, *> in ascending order. *> \endverbatim *> *> \param[out] Q *> \verbatim *> Q is DOUBLE PRECISION array, *> dimension at least (LDQ,K). *> \endverbatim *> *> \param[in] LDQ *> \verbatim *> LDQ is INTEGER *> The leading dimension of the array Q. LDQ >= K. *> \endverbatim *> *> \param[in] DSIGMA *> \verbatim *> DSIGMA is DOUBLE PRECISION array, dimension(K) *> The first K elements of this array contain the old roots *> of the deflated updating problem. These are the poles *> of the secular equation. *> \endverbatim *> *> \param[out] U *> \verbatim *> U is DOUBLE PRECISION array, dimension (LDU, N) *> The last N - K columns of this matrix contain the deflated *> left singular vectors. *> \endverbatim *> *> \param[in] LDU *> \verbatim *> LDU is INTEGER *> The leading dimension of the array U. LDU >= N. *> \endverbatim *> *> \param[in,out] U2 *> \verbatim *> U2 is DOUBLE PRECISION array, dimension (LDU2, N) *> The first K columns of this matrix contain the non-deflated *> left singular vectors for the split problem. *> \endverbatim *> *> \param[in] LDU2 *> \verbatim *> LDU2 is INTEGER *> The leading dimension of the array U2. LDU2 >= N. *> \endverbatim *> *> \param[out] VT *> \verbatim *> VT is DOUBLE PRECISION array, dimension (LDVT, M) *> The last M - K columns of VT**T contain the deflated *> right singular vectors. *> \endverbatim *> *> \param[in] LDVT *> \verbatim *> LDVT is INTEGER *> The leading dimension of the array VT. LDVT >= N. *> \endverbatim *> *> \param[in,out] VT2 *> \verbatim *> VT2 is DOUBLE PRECISION array, dimension (LDVT2, N) *> The first K columns of VT2**T contain the non-deflated *> right singular vectors for the split problem. *> \endverbatim *> *> \param[in] LDVT2 *> \verbatim *> LDVT2 is INTEGER *> The leading dimension of the array VT2. LDVT2 >= N. *> \endverbatim *> *> \param[in] IDXC *> \verbatim *> IDXC is INTEGER array, dimension ( N ) *> The permutation used to arrange the columns of U (and rows of *> VT) into three groups: the first group contains non-zero *> entries only at and above (or before) NL +1; the second *> contains non-zero entries only at and below (or after) NL+2; *> and the third is dense. The first column of U and the row of *> VT are treated separately, however. *> *> The rows of the singular vectors found by DLASD4 *> must be likewise permuted before the matrix multiplies can *> take place. *> \endverbatim *> *> \param[in] CTOT *> \verbatim *> CTOT is INTEGER array, dimension ( 4 ) *> A count of the total number of the various types of columns *> in U (or rows in VT), as described in IDXC. The fourth column *> type is any column which has been deflated. *> \endverbatim *> *> \param[in] Z *> \verbatim *> Z is DOUBLE PRECISION array, dimension (K) *> The first K elements of this array contain the components *> of the deflation-adjusted updating row vector. *> \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, a singular value did not converge *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date December 2016 * *> \ingroup OTHERauxiliary * *> \par Contributors: * ================== *> *> Ming Gu and Huan Ren, Computer Science Division, University of *> California at Berkeley, USA *> * ===================================================================== SUBROUTINE DLASD3( NL, NR, SQRE, K, D, Q, LDQ, DSIGMA, U, LDU, U2, $ LDU2, VT, LDVT, VT2, LDVT2, IDXC, CTOT, Z, $ INFO ) * * -- LAPACK auxiliary 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 .. INTEGER INFO, K, LDQ, LDU, LDU2, LDVT, LDVT2, NL, NR, $ SQRE * .. * .. Array Arguments .. INTEGER CTOT( * ), IDXC( * ) DOUBLE PRECISION D( * ), DSIGMA( * ), Q( LDQ, * ), U( LDU, * ), $ U2( LDU2, * ), VT( LDVT, * ), VT2( LDVT2, * ), $ Z( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, ZERO, NEGONE PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0, $ NEGONE = -1.0D+0 ) * .. * .. Local Scalars .. INTEGER CTEMP, I, J, JC, KTEMP, M, N, NLP1, NLP2, NRP1 DOUBLE PRECISION RHO, TEMP * .. * .. External Functions .. DOUBLE PRECISION DLAMC3, DNRM2 EXTERNAL DLAMC3, DNRM2 * .. * .. External Subroutines .. EXTERNAL DCOPY, DGEMM, DLACPY, DLASCL, DLASD4, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC ABS, SIGN, SQRT * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 * IF( NL.LT.1 ) THEN INFO = -1 ELSE IF( NR.LT.1 ) THEN INFO = -2 ELSE IF( ( SQRE.NE.1 ) .AND. ( SQRE.NE.0 ) ) THEN INFO = -3 END IF * N = NL + NR + 1 M = N + SQRE NLP1 = NL + 1 NLP2 = NL + 2 * IF( ( K.LT.1 ) .OR. ( K.GT.N ) ) THEN INFO = -4 ELSE IF( LDQ.LT.K ) THEN INFO = -7 ELSE IF( LDU.LT.N ) THEN INFO = -10 ELSE IF( LDU2.LT.N ) THEN INFO = -12 ELSE IF( LDVT.LT.M ) THEN INFO = -14 ELSE IF( LDVT2.LT.M ) THEN INFO = -16 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DLASD3', -INFO ) RETURN END IF * * Quick return if possible * IF( K.EQ.1 ) THEN D( 1 ) = ABS( Z( 1 ) ) CALL DCOPY( M, VT2( 1, 1 ), LDVT2, VT( 1, 1 ), LDVT ) IF( Z( 1 ).GT.ZERO ) THEN CALL DCOPY( N, U2( 1, 1 ), 1, U( 1, 1 ), 1 ) ELSE DO 10 I = 1, N U( I, 1 ) = -U2( I, 1 ) 10 CONTINUE END IF RETURN END IF * * Modify values DSIGMA(i) to make sure all DSIGMA(i)-DSIGMA(j) can * be computed with high relative accuracy (barring over/underflow). * This is a problem on machines without a guard digit in * add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2). * The following code replaces DSIGMA(I) by 2*DSIGMA(I)-DSIGMA(I), * which on any of these machines zeros out the bottommost * bit of DSIGMA(I) if it is 1; this makes the subsequent * subtractions DSIGMA(I)-DSIGMA(J) unproblematic when cancellation * occurs. On binary machines with a guard digit (almost all * machines) it does not change DSIGMA(I) at all. On hexadecimal * and decimal machines with a guard digit, it slightly * changes the bottommost bits of DSIGMA(I). It does not account * for hexadecimal or decimal machines without guard digits * (we know of none). We use a subroutine call to compute * 2*DSIGMA(I) to prevent optimizing compilers from eliminating * this code. * DO 20 I = 1, K DSIGMA( I ) = DLAMC3( DSIGMA( I ), DSIGMA( I ) ) - DSIGMA( I ) 20 CONTINUE * * Keep a copy of Z. * CALL DCOPY( K, Z, 1, Q, 1 ) * * Normalize Z. * RHO = DNRM2( K, Z, 1 ) CALL DLASCL( 'G', 0, 0, RHO, ONE, K, 1, Z, K, INFO ) RHO = RHO*RHO * * Find the new singular values. * DO 30 J = 1, K CALL DLASD4( K, J, DSIGMA, Z, U( 1, J ), RHO, D( J ), $ VT( 1, J ), INFO ) * * If the zero finder fails, report the convergence failure. * IF( INFO.NE.0 ) THEN RETURN END IF 30 CONTINUE * * Compute updated Z. * DO 60 I = 1, K Z( I ) = U( I, K )*VT( I, K ) DO 40 J = 1, I - 1 Z( I ) = Z( I )*( U( I, J )*VT( I, J ) / $ ( DSIGMA( I )-DSIGMA( J ) ) / $ ( DSIGMA( I )+DSIGMA( J ) ) ) 40 CONTINUE DO 50 J = I, K - 1 Z( I ) = Z( I )*( U( I, J )*VT( I, J ) / $ ( DSIGMA( I )-DSIGMA( J+1 ) ) / $ ( DSIGMA( I )+DSIGMA( J+1 ) ) ) 50 CONTINUE Z( I ) = SIGN( SQRT( ABS( Z( I ) ) ), Q( I, 1 ) ) 60 CONTINUE * * Compute left singular vectors of the modified diagonal matrix, * and store related information for the right singular vectors. * DO 90 I = 1, K VT( 1, I ) = Z( 1 ) / U( 1, I ) / VT( 1, I ) U( 1, I ) = NEGONE DO 70 J = 2, K VT( J, I ) = Z( J ) / U( J, I ) / VT( J, I ) U( J, I ) = DSIGMA( J )*VT( J, I ) 70 CONTINUE TEMP = DNRM2( K, U( 1, I ), 1 ) Q( 1, I ) = U( 1, I ) / TEMP DO 80 J = 2, K JC = IDXC( J ) Q( J, I ) = U( JC, I ) / TEMP 80 CONTINUE 90 CONTINUE * * Update the left singular vector matrix. * IF( K.EQ.2 ) THEN CALL DGEMM( 'N', 'N', N, K, K, ONE, U2, LDU2, Q, LDQ, ZERO, U, $ LDU ) GO TO 100 END IF IF( CTOT( 1 ).GT.0 ) THEN CALL DGEMM( 'N', 'N', NL, K, CTOT( 1 ), ONE, U2( 1, 2 ), LDU2, $ Q( 2, 1 ), LDQ, ZERO, U( 1, 1 ), LDU ) IF( CTOT( 3 ).GT.0 ) THEN KTEMP = 2 + CTOT( 1 ) + CTOT( 2 ) CALL DGEMM( 'N', 'N', NL, K, CTOT( 3 ), ONE, U2( 1, KTEMP ), $ LDU2, Q( KTEMP, 1 ), LDQ, ONE, U( 1, 1 ), LDU ) END IF ELSE IF( CTOT( 3 ).GT.0 ) THEN KTEMP = 2 + CTOT( 1 ) + CTOT( 2 ) CALL DGEMM( 'N', 'N', NL, K, CTOT( 3 ), ONE, U2( 1, KTEMP ), $ LDU2, Q( KTEMP, 1 ), LDQ, ZERO, U( 1, 1 ), LDU ) ELSE CALL DLACPY( 'F', NL, K, U2, LDU2, U, LDU ) END IF CALL DCOPY( K, Q( 1, 1 ), LDQ, U( NLP1, 1 ), LDU ) KTEMP = 2 + CTOT( 1 ) CTEMP = CTOT( 2 ) + CTOT( 3 ) CALL DGEMM( 'N', 'N', NR, K, CTEMP, ONE, U2( NLP2, KTEMP ), LDU2, $ Q( KTEMP, 1 ), LDQ, ZERO, U( NLP2, 1 ), LDU ) * * Generate the right singular vectors. * 100 CONTINUE DO 120 I = 1, K TEMP = DNRM2( K, VT( 1, I ), 1 ) Q( I, 1 ) = VT( 1, I ) / TEMP DO 110 J = 2, K JC = IDXC( J ) Q( I, J ) = VT( JC, I ) / TEMP 110 CONTINUE 120 CONTINUE * * Update the right singular vector matrix. * IF( K.EQ.2 ) THEN CALL DGEMM( 'N', 'N', K, M, K, ONE, Q, LDQ, VT2, LDVT2, ZERO, $ VT, LDVT ) RETURN END IF KTEMP = 1 + CTOT( 1 ) CALL DGEMM( 'N', 'N', K, NLP1, KTEMP, ONE, Q( 1, 1 ), LDQ, $ VT2( 1, 1 ), LDVT2, ZERO, VT( 1, 1 ), LDVT ) KTEMP = 2 + CTOT( 1 ) + CTOT( 2 ) IF( KTEMP.LE.LDVT2 ) $ CALL DGEMM( 'N', 'N', K, NLP1, CTOT( 3 ), ONE, Q( 1, KTEMP ), $ LDQ, VT2( KTEMP, 1 ), LDVT2, ONE, VT( 1, 1 ), $ LDVT ) * KTEMP = CTOT( 1 ) + 1 NRP1 = NR + SQRE IF( KTEMP.GT.1 ) THEN DO 130 I = 1, K Q( I, KTEMP ) = Q( I, 1 ) 130 CONTINUE DO 140 I = NLP2, M VT2( KTEMP, I ) = VT2( 1, I ) 140 CONTINUE END IF CTEMP = 1 + CTOT( 2 ) + CTOT( 3 ) CALL DGEMM( 'N', 'N', K, NRP1, CTEMP, ONE, Q( 1, KTEMP ), LDQ, $ VT2( KTEMP, NLP2 ), LDVT2, ZERO, VT( 1, NLP2 ), LDVT ) * RETURN * * End of DLASD3 * END
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/intrinsic_argument_conformance_2.f90
166
1763
! { dg-do compile } ! Some CSHIFT, EOSHIFT and UNPACK conformance tests ! program main implicit none real, dimension(1) :: a1, b1, c1 real, dimension(1,1) :: a2, b2, c2 real, dimension(1,0) :: a, b, c real :: tempn(1), tempv(5) real,allocatable :: foo(:) allocate(foo(0)) tempn = 2.0 a1 = 0 a2 = 0 c1 = 0 a2 = 0 b1 = cshift (a1,1) b1 = cshift (a1,(/1/)) ! { dg-error "must be a scalar" } b1 = eoshift (a1,1) b2 = eoshift (a1,c1(1)) ! { dg-error "must be INTEGER" } b1 = eoshift (a1,(/1/)) ! { dg-error "must be a scalar" } b1 = eoshift (a1,1,boundary=c1) ! { dg-error "must be a scalar" } b1 = eoshift (a1,(/1/), boundary=c2) ! { dg-error "must be a scalar" } b2 = cshift (a2,1) b2 = cshift (a2,(/1/)) b2 = cshift (a2,reshape([1],[1,1])) ! { dg-error "have rank 1 or be a scalar" } b2 = eoshift (a2,1) b2 = eoshift (a2,c1) ! { dg-error "must be INTEGER" } b2 = eoshift (a2,(/1/)) b2 = eoshift (a2,reshape([1],[1,1]), boundary=c1) ! { dg-error "have rank 1 or be a scalar" } b2 = eoshift (a2,1,boundary=c2(:,:)) ! { dg-error "have rank 1 or be a scalar" } b2 = eoshift (a2,(/1/), boundary=c2(:,:)) ! { dg-error "have rank 1 or be a scalar" } b = eoshift (a,(/1/), boundary=c(1,:)) ! { dg-error "invalid shape in dimension" } if (any(eoshift(foo,dim=1,shift=1,boundary=(/42.0,-7.0/))/= 0)) call abort() ! { dg-error "must be a scalar" } if (any(eoshift(tempn(2:1),dim=1,shift=1,boundary=(/42.0,-7.0/))/= 0)) call abort() ! { dg-error "must be a scalar" } if (any(unpack(tempv,tempv(1:0)/=0,tempv) /= -47)) call abort() ! { dg-error "must have identical shape" } if (any(unpack(tempv(5:4),tempv(1:0)/=0,tempv) /= -47)) call abort() ! { dg-error "must have identical shape" } end program main
gpl-2.0
gomezstevena/x-wind
src/mbaMesh.f
1
2801
C ===================================================================== Program Main C ===================================================================== implicit none c Maximum number of nodes, elements and boundary edges Integer nvmax, nbmax, ntmax Parameter(nvmax= 20000, nbmax= 10000, ntmax= 2 * nvmax) c Available memory Integer MaxWr, MaxWi Parameter(MaxWr = 2 000 000, MaxWi = 3 000 000) C ===================================================================== C group (M) Integer nv, nvfix, labelv(nvmax), fixedV(nvmax) Real*8 vrt(2, nvmax) Integer nb, nbfix, bnd(2, nbmax), labelB(nbmax), fixedB(nbmax) Integer nc, labelC(nbmax) Real*8 Crv(2, nbmax) EXTERNAL ANI_CrvFunction Integer nt, ntfix, tri(3, ntmax), labelT(ntmax), fixedT(ntmax) C group (CONTROL) Integer control(6) Real*8 Metric(3, nvmax), Quality C group (W) Real*8 rW(MaxWr) Integer iW(MaxWi) C LOCAL VARIABLES Integer i, j, nEStar, iERR Real*8 x, y C ===================================================================== c ... load the initial mesh. The extension must be .ani c nEStar is desired number of triangles Read (*,*) nEStar, nv, nt, nb Do i = 1, nv Read(*,*) (vrt(j,i),j=1,2) labelv(i) = 0 End do Do i = 1, nt Read(*,*) (tri(j,i),j=1,3) labelT(i) = 1 End do Do i = 1, nb Read(*,*) (bnd(j,i),j=1,2) labelB(i) = i End do Do i = 1, nv Read(*,*) (Metric(j,i),j=1,3) End do nvfix = 0 nbfix = 0 ntfix = 0 nc = 0 c ... generate adaptive mesh control(1) = nEStar / 10 ! MaxSkipE control(2) = 15000 ! MaxQItr control(3) = 1 ! status control(4) = 1 ! flagAuto control(5) = 1 ! iPrint: minimal level of output information control(6) = 0 ! iErrMesgt: only critical termination allowed Quality = 0.8D0 ! request shape-regular triangles in metric Call mbaNodal( & nv, nvfix, nvmax, vrt, labelv, fixedV, & nb, nbfix, nbmax, bnd, labelB, fixedB, & nc, Crv, labelC, ANI_CrvFunction, & nt, ntfix, ntmax, tri, labelT, fixedT, & nEStar, Quality, control, Metric, & MaxWr, MaxWi, rW, iW, iERR) write (*,*) "Error ", iERR write (*,*) "=== Output Data Starts Here 09887654321 ===\n" Write (*,*) nv, nt, nb Do i = 1, nv Write(*,*) (vrt(j,i),j=1,2) End do Do i = 1, nt Write(*,*) (tri(j,i),j=1,3) End do Do i = 1, nb Write(*,*) (bnd(j,i),j=1,2) End do Stop End
gpl-3.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/c_f_pointer_tests_6.f90
116
1333
! { dg-do compile } ! ! PR fortran/38894 ! ! subroutine test2 use iso_c_binding type(c_funptr) :: fun type(c_ptr) :: fptr procedure(), pointer :: bar integer, pointer :: bari call c_f_procpointer(fptr,bar) ! { dg-error "Argument CPTR at .1. to C_F_PROCPOINTER shall have the type TYPE.C_FUNPTR." } call c_f_pointer(fun,bari) ! { dg-error "Argument CPTR at .1. to C_F_POINTER shall have the type TYPE.C_PTR." } fun = fptr ! { dg-error "Can't convert TYPE.c_ptr. to TYPE.c_funptr." } end subroutine test() use iso_c_binding, c_ptr2 => c_ptr type(c_ptr2) :: fun procedure(), pointer :: bar integer, pointer :: foo call c_f_procpointer(fun,bar) ! { dg-error "Argument CPTR at .1. to C_F_PROCPOINTER shall have the type TYPE.C_FUNPTR." } call c_f_pointer(fun,foo) ! OK end module rename use, intrinsic :: iso_c_binding, only: my_c_ptr_0 => c_ptr end module rename program p use, intrinsic :: iso_c_binding, my_c_ptr => c_ptr type(my_c_ptr) :: my_ptr print *,c_associated(my_ptr) contains subroutine sub() use rename ! (***) type(my_c_ptr_0) :: my_ptr2 type(c_funptr) :: myfun print *,c_associated(my_ptr,my_ptr2) print *,c_associated(my_ptr,myfun) ! { dg-error "Argument C_PTR_2 at .1. to C_ASSOCIATED shall have the same type as C_PTR_1: TYPE.c_ptr. instead of TYPE.c_funptr." } end subroutine end
gpl-2.0
trankmichael/scipy
scipy/linalg/src/id_dist/src/iddp_rid.f
133
10029
c this file contains the following user-callable routines: c c c routine iddp_rid computes the ID, to a specified precision, c of a matrix specified by a routine for applying its transpose c to arbitrary vectors. This routine is randomized. c c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c c c c subroutine iddp_rid(lproj,eps,m,n,matvect,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 real*8 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 matvect -- routine which applies the transpose 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 matvect(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 transpose c of the matrix is to be applied, c n is the length of y, c y is the product of the transposed matrix and x, c and p1, p2, p3, and p4 are user-specified parameters c p1 -- parameter to be passed to routine matvect c p2 -- parameter to be passed to routine matvect c p3 -- parameter to be passed to routine matvect c p4 -- parameter to be passed to routine matvect 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) real*8 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) real*8 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,p1,p2,p3,p4,proj(*) external matvect 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 idd_findrank(lra,eps,m,n,matvect,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 Transpose ra. c call idd_rtransposer(n,kranki,proj(ira),proj(ira+kranki*n)) c c c Move the tranposed matrix 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 transposed matrix. c call iddp_id(eps,kranki,n,proj,krank,list,proj(1+kranki*n)) c c return end c c c c subroutine idd_findrank(lra,eps,m,n,matvect,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 matvect applies the transpose of a c to an arbitrary vector. This routine applies the transpose 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 real*8 elements) of array ra c eps -- precision defining the numerical rank c m -- first dimension of a c n -- second dimension of a c matvect -- routine which applies the transpose 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 matvect(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 transpose c of the matrix is to be applied, c n is the length of y, c y is the product of the transposed matrix and x, c and p1, p2, p3, and p4 are user-specified parameters c p1 -- parameter to be passed to routine matvect c p2 -- parameter to be passed to routine matvect c p3 -- parameter to be passed to routine matvect c p4 -- parameter to be passed to routine matvect c c output: c krank -- estimate of the numerical rank of a c ra -- product of the transpose 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 real*8 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 real*8 elements long c c _N.B._: ra must be at least 2*n*krank real*8 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,p1,p2,p3,p4,ra(n,*),w(m+2*n+1) external matvect 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 idd_findrank0(lra,eps,m,n,matvect,p1,p2,p3,p4, 1 krank,ra,ier,w(ix),w(iy),w(iscal)) c c return end c c c c subroutine idd_findrank0(lra,eps,m,n,matvect,p1,p2,p3,p4, 1 krank,ra,ier,x,y,scal) c c routine idd_findrank serves as a memory wrapper c for the present routine. (Please see routine idd_findrank c for further documentation.) c implicit none integer m,n,krank,ifrescal,k,lra,ier real*8 x(m),ra(n,2,*),p1,p2,p3,p4,scal(n+1),y(n),eps,residual, 1 enorm external matvect 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 transpose of a to a random vector. c call id_srand(m,x) call matvect(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)**2 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 idd_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 idd_house(n-krank,y(krank+1), 1 residual,ra(1,2,krank+1),scal(krank+1)) residual = abs(residual) c c krank = krank+1 c c if(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 idd_crunch(n,krank,ra) c c return end c c c c subroutine idd_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 real*8 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 idd_rtransposer(m,n,a,at) c c transposes a to obtain at. c c input: c m -- first dimension of a, and second dimension of at c n -- second dimension of a, and first dimension of at c a -- matrix to be transposed c c output: c at -- transpose of a c implicit none integer m,n,j,k real*8 a(m,n),at(n,m) c c do k = 1,n do j = 1,m c at(k,j) = a(j,k) c enddo ! j enddo ! k c c return end
bsd-3-clause
eiselekd/gcc
gcc/testsuite/gfortran.dg/coarray_lib_alloc_3.f90
28
1240
! { dg-do compile } ! { dg-options "-fcoarray=lib -fdump-tree-original" } ! ! Allocate/deallocate with libcaf. ! ! As coarray_lib_alloc_2.f90 but for a subroutine instead of the PROGRAM ! subroutine test type t end type t class(t), allocatable :: xx[:], yy(:)[:] integer :: stat character(len=200) :: errmsg allocate(xx[*], stat=stat, errmsg=errmsg) allocate(yy(2)[*], stat=stat, errmsg=errmsg) deallocate(xx,yy,stat=stat, errmsg=errmsg) end ! { dg-final { scan-tree-dump-times "_gfortran_caf_register \\(1, 1, &xx._data.token, \\(void \\*\\) &xx._data, &stat.., &errmsg, 200\\);" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_register \\(1, 1, &yy._data.token, \\(void \\*\\) &yy._data, &stat.., &errmsg, 200\\);" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_deregister .&xx._data.token, 0, &stat.., &errmsg, 200.;" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_deregister .&yy._data.token, 0, &stat.., &errmsg, 200.;" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_deregister .&yy._data.token, 0, 0B, 0B, 0.;" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_deregister .&xx._data.token, 0, 0B, 0B, 0.;" 1 "original" } }
gpl-2.0
eiselekd/gcc
libgfortran/generated/_sqrt_c8.F90
9
1482
! Copyright (C) 2002-2017 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_COMPLEX_8) #ifdef HAVE_CSQRT elemental function _gfortran_specific__sqrt_c8 (parm) complex (kind=8), intent (in) :: parm complex (kind=8) :: _gfortran_specific__sqrt_c8 _gfortran_specific__sqrt_c8 = sqrt (parm) end function #endif #endif
gpl-2.0
seismology-RUB/ASKI
f90/primitiveTypeEncoding.f90
1
1400
!---------------------------------------------------------------------------- ! Copyright 2016 Wolfgang Friederich (Ruhr-Universitaet Bochum, Germany) ! ! This file is part of ASKI version 1.2. ! ! ASKI version 1.2 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 2 of the License, or (at your option) ! any later version. ! ! ASKI version 1.2 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. ! ! You should have received a copy of the GNU General Public License ! along with ASKI version 1.2. !---------------------------------------------------------------------- ! conventions for identifying pritive data types !---------------------------------------------------------------------- module primitiveTypeEncoding implicit none integer, parameter :: T_INTEGER = 1 integer, parameter :: T_REAL = 2 integer, parameter :: T_DOUBLE = 3 integer, parameter :: T_COMPLEX = 4 integer, parameter :: T_DOUBLE_COMPLEX = 5 integer, parameter :: T_CHAR = 6 integer, parameter :: T_FLEXIBLE = 7 integer, parameter :: T_LOGICAL = 8 end module
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/ieee/ieee_8.f90
7
3794
! { dg-do run { xfail aarch64*-*-gnu arm*-*-gnueabi arm*-*-gnueabihf } } ! XFAIL because of PR libfortran/78449. module foo use :: ieee_exceptions use :: ieee_arithmetic end module foo module bar use foo use :: ieee_arithmetic, yyy => ieee_support_rounding use :: ieee_arithmetic, zzz => ieee_selected_real_kind end module program test use :: bar use :: ieee_arithmetic, xxx => ieee_support_rounding implicit none ! IEEE functions allowed in constant expressions integer, parameter :: n1 = ieee_selected_real_kind(0, 0) logical, parameter :: l1 = ieee_support_halting(ieee_overflow) logical, parameter :: l2 = ieee_support_flag(ieee_overflow) logical, parameter :: l3 = ieee_support_flag(ieee_overflow, 0.) logical, parameter :: l4 = ieee_support_rounding(ieee_to_zero) logical, parameter :: l5 = ieee_support_rounding(ieee_to_zero, 0.d0) logical, parameter :: l6 = xxx(ieee_to_zero, 0.d0) logical, parameter :: l7 = yyy(ieee_to_zero, 0.d0) integer, parameter :: n2 = zzz(0, 0) call gee(8, ieee_to_zero, ieee_overflow) end ! IEEE functions allowed in specification expressions subroutine gee(n, rounding, flag) use :: bar implicit none integer :: n type(ieee_round_type) :: rounding type(ieee_flag_type) :: flag character(len=ieee_selected_real_kind(n)) :: s1 character(len=ieee_selected_real_kind(n,2*n)) :: s2 character(len=ieee_selected_real_kind(n,2*n,2)) :: s3 character(len=merge(4,2,ieee_support_rounding(rounding))) :: s4 character(len=merge(4,2,ieee_support_rounding(rounding, 0.d0))) :: s5 character(len=merge(4,2,ieee_support_flag(flag))) :: s6 character(len=merge(4,2,ieee_support_flag(flag, 0.))) :: s7 character(len=merge(4,2,ieee_support_halting(flag))) :: s8 character(len=merge(4,2,ieee_support_datatype())) :: s9 character(len=merge(4,2,ieee_support_datatype(0.))) :: s10 character(len=merge(4,2,ieee_support_denormal())) :: s11 character(len=merge(4,2,ieee_support_denormal(0.))) :: s12 character(len=merge(4,2,ieee_support_divide())) :: s13 character(len=merge(4,2,ieee_support_divide(0.))) :: s14 character(len=merge(4,2,ieee_support_inf())) :: s15 character(len=merge(4,2,ieee_support_inf(0.))) :: s16 character(len=merge(4,2,ieee_support_io())) :: s17 character(len=merge(4,2,ieee_support_io(0.))) :: s18 character(len=merge(4,2,ieee_support_nan())) :: s19 character(len=merge(4,2,ieee_support_nan(0.))) :: s20 character(len=merge(4,2,ieee_support_sqrt())) :: s21 character(len=merge(4,2,ieee_support_sqrt(0.))) :: s22 character(len=merge(4,2,ieee_support_standard())) :: s23 character(len=merge(4,2,ieee_support_standard(0.))) :: s24 character(len=merge(4,2,ieee_support_underflow_control())) :: s25 character(len=merge(4,2,ieee_support_underflow_control(0.))) :: s26 ! Now, check that runtime values match compile-time constants ! (for those that are allowed) integer, parameter :: x1 = ieee_selected_real_kind(8) integer, parameter :: x2 = ieee_selected_real_kind(8,2*8) integer, parameter :: x3 = ieee_selected_real_kind(8,2*8,2) integer, parameter :: x4 = merge(4,2,ieee_support_rounding(rounding)) integer, parameter :: x5 = merge(4,2,ieee_support_rounding(rounding, 0.d0)) integer, parameter :: x6 = merge(4,2,ieee_support_flag(ieee_overflow)) integer, parameter :: x7 = merge(4,2,ieee_support_flag(ieee_overflow, 0.)) integer, parameter :: x8 = merge(4,2,ieee_support_halting(ieee_overflow)) if (len(s1) /= x1) call abort if (len(s2) /= x2) call abort if (len(s3) /= x3) call abort if (len(s4) /= x4) call abort if (len(s5) /= x5) call abort if (len(s6) /= x6) call abort if (len(s7) /= x7) call abort if (len(s8) /= x8) call abort end subroutine ! { dg-final { cleanup-modules "foo bar" } }
gpl-2.0
redstar3894/android-gcc-4.6
libgfortran/generated/_dim_r10.F90
22
1462
! 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_10) elemental function _gfortran_specific__dim_r10 (p1, p2) real (kind=10), intent (in) :: p1, p2 real (kind=10) :: _gfortran_specific__dim_r10 _gfortran_specific__dim_r10 = dim (p1, p2) end function #endif
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/vect/fast-math-real8-pr40801.f90
26
1047
! { dg-do compile } MODULE YOMPHY0 REAL :: ECMNP REAL :: SCO REAL :: USDMLT END MODULE YOMPHY0 SUBROUTINE ACCONV ( KIDIA,KFDIA,KLON,KTDIA,KLEV,& &CDLOCK) USE YOMPHY0 , ONLY : ECMNP ,SCO ,USDMLT REAL :: PAPHIF(KLON,KLEV),PCVGQ(KLON,KLEV)& &,PFPLCL(KLON,0:KLEV),PFPLCN(KLON,0:KLEV),PSTRCU(KLON,0:KLEV)& &,PSTRCV(KLON,0:KLEV) INTEGER :: KNLAB(KLON,KLEV),KNND(KLON) REAL :: ZCP(KLON,KLEV),ZLHE(KLON,KLEV),ZDSE(KLON,KLEV)& &,ZPOII(KLON),ZALF(KLON),ZLN(KLON),ZUN(KLON),ZVN(KLON)& &,ZPOIL(KLON) DO JLEV=KLEV-1,KTDIA,-1 DO JIT=1,NBITER ZLN(JLON)=MAX(0.,ZLN(JLON)& &-(ZQW(JLON,JLEV)-ZQN(JLON)& &*(PQ(JLON,JLEV+1)-ZQN(JLON))))*KNLAB(JLON,JLEV) ENDDO ENDDO IF (ITOP < KLEV+1) THEN DO JLON=KIDIA,KFDIA ZZVAL=PFPLCL(JLON,KLEV)+PFPLCN(JLON,KLEV)-SCO KNND(JLON)=KNND(JLON)*MAX(0.,-SIGN(1.,0.-ZZVAL)) ENDDO DO JLEV=ITOP,KLEV DO JLON=KIDIA,KFDIA ENDDO ENDDO ENDIF END SUBROUTINE ACCONV ! { dg-final { cleanup-tree-dump "vect" } } ! { dg-final { cleanup-modules "yomphy0" } }
gpl-2.0
redstar3894/android-gcc-4.6
libgfortran/generated/_log_r10.F90
22
1478
! 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_10) #ifdef HAVE_LOGL elemental function _gfortran_specific__log_r10 (parm) real (kind=10), intent (in) :: parm real (kind=10) :: _gfortran_specific__log_r10 _gfortran_specific__log_r10 = log (parm) end function #endif #endif
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/write_rewind_2.f
166
1183
! { dg-do run } ! PR 26499 Test write with rewind sequences to make sure buffering and ! end-of-file conditions are handled correctly. Derived from test case by Dale ! Ranta. Submitted by Jerry DeLisle <jvdelisle@gcc.gnu.org>. program test dimension idata(1011) idata = -42 open(unit=11,form='unformatted') idata(1) = -705 idata( 1011) = -706 write(11)idata idata(1) = -706 idata( 1011) = -707 write(11)idata idata(1) = -707 idata( 1011) = -708 write(11)idata read(11,end= 1000 )idata call abort() 1000 continue rewind 11 read(11,end= 1001 )idata if(idata(1).ne. -705.or.idata( 1011).ne. -706)call abort() 1001 continue close(11,status='keep') open(unit=11,form='unformatted') rewind 11 read(11)idata if(idata(1).ne.-705)then call abort() endif read(11)idata if(idata(1).ne.-706)then call abort() endif read(11)idata if(idata(1).ne.-707)then call abort() endif close(11,status='delete') stop end
gpl-2.0
pseudospectators/UP2D
src/navier_stokes/add_pressure.f90
2
1449
!------------------------------------------------------------------------------- ! add pressure gradient to right hand side of navier-stokes ! INPUT: ! nlk pre-computed source terms (penalization, non-linear) FOURIER space ! OUTPUT: ! nlk now divergence-free right hand side !------------------------------------------------------------------------------- subroutine add_pressure (nlk) use vars implicit none real(kind=pr),dimension(0:nx-1,0:ny-1,1:2), intent (inout) :: nlk real(kind=pr),dimension(:,:),allocatable :: work1, work2, work3 integer :: iy ! allocate work memory allocate ( work1(0:nx-1,0:ny-1), work2(0:nx-1,0:ny-1), work3(0:nx-1,0:ny-1) ) !--------------------------------------------------------------------------- ! classic pressure projects all source terms !--------------------------------------------------------------------------- ! divergence of non-linear terms call cofdx ( nlk(:,:,1), work1 ) call cofdy ( nlk(:,:,2), work2 ) ! solve poisson eqn to get the pressure (in work3) call poisson ( work1+work2, work3) ! compute gradient of pressure call cofdx (work3, work1) call cofdy (work3, work2) ! add gradient to RHS !$omp parallel do private(iy) do iy=0,ny-1 nlk(:,iy,1) = nlk(:,iy,1) + work1(:,iy) nlk(:,iy,2) = nlk(:,iy,2) + work2(:,iy) enddo !$omp end parallel do ! release work memory deallocate(work1, work2, work3) end subroutine add_pressure
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/move_alloc_8.f90
151
2675
! { dg-do compile } ! ! PR fortran/50684 ! ! Module "bug" contributed by Martin Steghöfer. ! MODULE BUG TYPE MY_TYPE INTEGER, ALLOCATABLE :: VALUE END TYPE CONTAINS SUBROUTINE POINTER_INTENT_IN_BUG_WORKING(POINTER_INTENT_IN_VARIABLE) TYPE(MY_TYPE), POINTER, INTENT(IN) :: POINTER_INTENT_IN_VARIABLE TYPE(MY_TYPE), POINTER :: POINTER_VARIABLE_LOCAL INTEGER, ALLOCATABLE :: LOCAL_VALUE POINTER_VARIABLE_LOCAL=>POINTER_INTENT_IN_VARIABLE CALL MOVE_ALLOC(POINTER_VARIABLE_LOCAL%VALUE, LOCAL_VALUE) RETURN END SUBROUTINE POINTER_INTENT_IN_BUG_WORKING SUBROUTINE POINTER_INTENT_IN_BUG_FAILING(POINTER_INTENT_IN_VARIABLE) TYPE(MY_TYPE), POINTER, INTENT(IN) :: POINTER_INTENT_IN_VARIABLE INTEGER, ALLOCATABLE :: LOCAL_VALUE CALL MOVE_ALLOC(POINTER_INTENT_IN_VARIABLE%VALUE, LOCAL_VALUE) RETURN END SUBROUTINE POINTER_INTENT_IN_BUG_FAILING end module bug subroutine test1() TYPE MY_TYPE INTEGER, ALLOCATABLE :: VALUE END TYPE CONTAINS SUBROUTINE sub (dt) type(MY_TYPE), intent(in) :: dt INTEGER, ALLOCATABLE :: lv call move_alloc(dt%VALUE, lv) ! { dg-error "cannot be INTENT.IN." } END SUBROUTINE end subroutine test1 subroutine test2 (x, px) implicit none type t integer, allocatable :: a end type t type t2 type(t), pointer :: ptr integer, allocatable :: a end type t2 type(t2), intent(in) :: x type(t2), pointer, intent(in) :: px integer, allocatable :: a type(t2), pointer :: ta call move_alloc (px, ta) ! { dg-error "cannot be INTENT.IN." } call move_alloc (x%a, a) ! { dg-error "cannot be INTENT.IN." } call move_alloc (x%ptr%a, a) ! OK (3) call move_alloc (px%a, a) ! OK (4) call move_alloc (px%ptr%a, a) ! OK (5) end subroutine test2 subroutine test3 (x, px) implicit none type t integer, allocatable :: a end type t type t2 class(t), pointer :: ptr integer, allocatable :: a end type t2 type(t2), intent(in) :: x class(t2), pointer, intent(in) :: px integer, allocatable :: a class(t2), pointer :: ta call move_alloc (px, ta) ! { dg-error "cannot be INTENT.IN." } call move_alloc (x%a, a) ! { dg-error "cannot be INTENT.IN." } call move_alloc (x%ptr%a, a) ! OK (6) call move_alloc (px%a, a) ! OK (7) call move_alloc (px%ptr%a, a) ! OK (8) end subroutine test3 subroutine test4() TYPE MY_TYPE INTEGER, ALLOCATABLE :: VALUE END TYPE CONTAINS SUBROUTINE sub (dt) CLASS(MY_TYPE), intent(in) :: dt INTEGER, ALLOCATABLE :: lv call move_alloc(dt%VALUE, lv) ! { dg-error "cannot be INTENT.IN." } END SUBROUTINE end subroutine test4
gpl-2.0
kbrannan/PyHSPF
src/hspf13/hrints.f
2
67724
C C C SUBROUTINE HRITSI I (MSGFL) C C + + + PURPOSE + + + C read in general timseries data from message file C C + + + DUMMY ARGUMENTS + + + INTEGER MSGFL C C + + + ARGUMENT DEFINITIONS + + + C MSGFL - message file unit number C C + + + COMMON BLOCKS- INTERP3 + + + INCLUDE 'crin3.inc' INCLUDE 'crin3c.inc' C C + + + LOCAL VARIABLES + + + INTEGER N,J,CASE,STKIND,SCLU,SGRP,INITFG,CONT,CLEN CHARACTER*1 INBUF1(80) C C + + + EQUIVALENCES + + + EQUIVALENCE (INBUF1,INBUFF) CHARACTER*80 INBUFF C C + + + EXTERNALS + + + EXTERNAL WMSGTT C C + + + INPUT FORMATS + + + 1010 FORMAT (8(A4,6X)) 1040 FORMAT (A6,4X,2I10) 1050 FORMAT (11I5) C C + + + END SPECIFICATIONS + + + C SCLU = 215 C C external sources/targets keyword library SGRP = 12 INITFG= 1 CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) READ (INBUFF,1010) EXTKWL C C access mode keyword library SGRP = 13 INITFG= 1 CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) READ (INBUFF,1010) AMDKWL C C unit system keyword library SGRP = 14 INITFG= 1 CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) READ (INBUFF,1010) SYSKWL C C gap code keyword library SGRP = 15 INITFG= 1 CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) READ (INBUFF,1010) GAPKWL C C format class keyword library SGRP = 16 INITFG= 1 N = 0 10 CONTINUE CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) INITFG= 0 N = N+ 1 READ (INBUFF,1040) FMTKWL(N),(FMTINF(J,N),J=1,2) IF (CONT .EQ. 1) GO TO 10 C C transformation keyword library SGRP = 17 INITFG= 1 CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) READ (INBUFF,1010) TRNKWL C C transformation code table SGRP = 18 INITFG= 1 20 CONTINUE CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) INITFG= 0 READ(INBUFF,1050) CASE,STKIND,(TRNTAB(J,STKIND,CASE),J=1,9) IF (CONT .EQ. 1) GO TO 20 C RETURN END C C C SUBROUTINE GPFINT I (RECLT,FILE, O GPKEY) C C + + + PURPOSE + + + C Initialize the instruction files for tsget/tsput by C placing the appropriate error offsets plus other data C in the initial record of each instruction file. C note: several scalars and EOFFST share storage with INSTR. C C + + + DUMMY ARGUMENTS + + + INTEGER RECLT,FILE(15),GPKEY C C + + + ARGUMENT DEFINITIONS + + + C RECLT - record length of the time series store C FILE - array of file unit numbers C GPKEY - key in tsget file C C + + + LOCAL VARIABLES + + + INTEGER INSTR(3),K,MSGFL,I3,SCLU,SGRP,INITFG,CONT,CLEN CHARACTER*1 INBUF1(80) C C + + + EQIVALENCES + + + EQUIVALENCE (INSTR(1),TESTFG),(INSTR(2),RECL), # (INSTR(3),UNDEF) INTEGER TESTFG,RECL REAL UNDEF EQUIVALENCE (INBUF1,INBUFF) CHARACTER*80 INBUFF C C + + + EXTERNALS + + + EXTERNAL WMSGTT,PUTTSI C C + + + INPUT FORMATS + + + 1000 FORMAT (20X,I10) C C + + + END SPECIFICATIONS + + + C I3 = 3 MSGFL = FILE(15) SCLU = 215 C define record length and undefined value. RECL = RECLT UNDEF = -1.E30 C DO 100 K= 1,2 C read info for tsget and tsput errors (temp) SGRP = K+ 30 INITFG= 1 CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) READ(INBUFF,1000) TESTFG C CALL PUTTSI (I3,K,INSTR) C 100 CONTINUE C C set key for tsgetf/tsputf GPKEY= 2 C RETURN END C C C SUBROUTINE HRIMSI I (MSGFL,AREA,STTYP,MAXCNX, O SGPNAM,SMMNAM,SMMSUB, O TRANSF,NUMCON,MFCT, O TGPNAM,TMMNAM,TMMSUB) C C + + + PURPOSE + + + C read in mass link default data from information file C C + + + DUMMY ARGUMENTS + + + INTEGER MSGFL,STTYP,MAXCNX, # SMMSUB(2,MAXCNX), # NUMCON,TMMSUB(2,MAXCNX) REAL AREA,MFCT(MAXCNX) CHARACTER*6 SGPNAM(MAXCNX),SMMNAM(MAXCNX), # TGPNAM(MAXCNX),TMMNAM(MAXCNX) CHARACTER*4 TRANSF(MAXCNX) C C + + + ARGUMENT DEFINITIONS + + + C MSGFL - information file C AREA - ??? C STTYP - source to target type, 1-per to rch, 2-imp to rch C SGPNAM - ??? C SMNNAM - ??? C SMNSUB - ??? C TRANSF - ??? C NUMCON - ??? C MFACT - ??? C TGPNAM - ??? C TMNNAM - ??? C TMNSUB - ??? C C + + + LOCAL VARIABLES + + + INTEGER I,SCLU,SGRP,CONT,INITFG,CLEN REAL CONV CHARACTER*1 INBUF1(80) C C + + + EQUIVALENCES + + + EQUIVALENCE (INBUF1,INBUFF) CHARACTER*80 INBUFF C C + + + EXTERNALS + + + EXTERNAL WMSGTT C C + + + INPUT FORMATS + + + 1000 FORMAT (A6,2X,A6,2I2,4X,F10.0,4X,A6,2X,A6,2I2,26X,I4) C C + + + END SPECIFICATIONS + + + C SCLU= 215 SGRP= STTYP+ 40 C INITFG= 1 NUMCON= 0 10 CONTINUE CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) INITFG= 0 NUMCON= NUMCON+ 1 READ (INBUFF,1000) SGPNAM(NUMCON),SMMNAM(NUMCON), $ (SMMSUB(I,NUMCON),I=1,2),CONV, $ TGPNAM(NUMCON),TMMNAM(NUMCON), $ (TMMSUB(I,NUMCON),I=1,2) C MFCT(NUMCON) = AREA * CONV TRANSF(NUMCON)= ' ' IF (CONT.EQ.1 .AND. NUMCON.LT.MAXCNX) GO TO 10 C RETURN END C C C SUBROUTINE FINSTR I (SKY,EKY,GETF,VOPAD, I WIDTH,START,ENDR,STIME,FMIN,DELT, M INKEY) C C + + + PURPOSE + + + C Finish the tsget/tsput instruction C C + + + HISTORY + + + C 12/6/2004 - jlk&pbd - changed I200 to I220 for new C TSGET/TSPUT file length, updated to use enhanced C primitive instruction C C + + + DUMMY ARGUMENTS + + + INTEGER SKY,EKY,GETF,VOPAD,WIDTH,START(5), $ ENDR(5),STIME,FMIN,DELT,INKEY C C + + + ARGUMENT DEFINITIONS + + + C SKY - ??? C EKY - ??? C GETF - get(1)/put(0) flag C VOPAD - ??? C WIDTH - inpad width C START - ??? C ENDR - ??? C STIME - ??? C FMIN - ??? C DELT - simulation time interval in minutes C INKEY - ??? C C + + + COMMON BLOCKS- INTERP4 + + + INCLUDE 'crin4.inc' INCLUDE 'cpthnm.inc' C C + + + LOCAL VARIABLES + + + INTEGER FIFLG,I,J,KEY,NTS,TREC,VECA(35),VECB(35),I2,SCLU, # SGRP,CONT,INITFG,CLEN,I35,I220,I0,BLNK, # VECT(35),TKEY,IMATCH REAL INITPV(8) CHARACTER*1 INBUF1(80) CHARACTER*80 UCIBF CHARACTER*4 CBLNK C C + + + EQUIVALENCES + + + EQUIVALENCE (VECA(4),ROW),(VECA(9),AT),(VECA(10),BT), $ (VECA(15),FRC),(VECA(25),AORIGT) INTEGER ROW,FRC REAL AT,BT,AORIGT EQUIVALENCE (INBUF1,INBUFF) CHARACTER*80 INBUFF C C + + + INTRINSICS + + + INTRINSIC ABS C C + + + EXTERNALS + + + EXTERNAL OMSG,RBUFF,GINIT,PINIT,TIMHTW,TIMBAK,TINOUT,WMSGTT, # OMSTI,GETTSI,PUTTSI,GETUCI C C + + + DATA INITIALIZATIONS + + + DATA INITPV/-999.,-999.,0.0,0.0,-1.0E30,1.0E30,-999.,0.0/ DATA CBLNK/' '/ C C + + + INPUT FORMATS + + + 1000 FORMAT(4X,19A4) 1010 FORMAT(19A4) 1020 FORMAT(A4) C C + + + OUTPUT FORMATS + + + 2000 FORMAT(' BEGIN FINISHING TSGET/TSPUT INSTRUCTION') 2020 FORMAT(' END FINISHING TSGET/TSPUT INSTRUCTION') C C + + + END SPECIFICATIONS + + + C SCLU = 215 I0 = 0 I2 = 2 I35 = 35 I220 = 220 C READ(CBLNK,'(A4)') BLNK C IF (OUTLEV .GT. 5) THEN C finishing message WRITE(MESSU,2000) END IF C IF (SKY .NE. 0) THEN C something to finish CALL GETTSI (I35,SKY, O VECA) NTS = 0 LTRNFG = 0 KEY = SKY C dountil key > eky 10 CONTINUE C process the component NTS = NTS+ 1 VOPADR(NTS) = VOPAD+ (ROW-1)*(WIDTH+1) OFFSET(NTS) = VECA(5) STKIND(NTS) = VECA(6) STTRAN(NTS) = VECA(7) INMODE(NTS) = VECA(8) A(NTS) = AT B(NTS) = BT C if (at .ne. 1.0 .or. bt .ne. 0.0) then IF ((ABS(AT-1.0)) .GT. 1.0E-5 .OR. (ABS(BT)) .GT. 0.0) THEN LTRNFG = 1 END IF C KEY = KEY + 1 FIFLG = 0 IF (KEY .GT. EKY) THEN C done with this operation - therefore finish instruction FIFLG = 1 ELSE C get next primitive instruction CALL GETTSI (I35,KEY, O VECB) IF (NTS .EQ. 20) THEN C instruction is filled - set finish flag FIFLG= 1 ELSE IF (VECA(1) .NE. 4 .OR. VECB(1) .NE. 4. $ OR.VECA(2) .NE. VECB(2)) THEN C new group of components encountered - set flag FIFLG=1 END IF END IF END IF C IF (FIFLG .EQ. 1) THEN C finish the instruction, process information from veca C some values not needed by tsget but supplied anyway VOLCOD = VECA(1) FILE = VECA(2) DELTAT = VECA(3) AMODE = VECA(13) C C check subsequent primitive instructions for this same source/target pair TKEY = KEY C loop thru timser instrctions for this operation 15 CONTINUE C assume a match exists IMATCH = 1 C get a temp copy of later instruction CALL GETTSI (I35,TKEY, O VECT) TKEY = TKEY + 1 C check for matching source DO 17 I = 16,24 IF (VECA(I).NE.VECT(I)) THEN IMATCH = 0 END IF 17 CONTINUE C check for matching target DO 18 I = 26,34 IF (VECA(I).NE.VECT(I)) THEN IMATCH = 0 END IF 18 CONTINUE C IF (IMATCH.EQ.1) THEN C found another occurance of this source/target pair C force exit TKEY = EKY + 1 END IF IF (TKEY .LE. EKY) GOTO 15 C IF (IMATCH.EQ.0) THEN C variables in veca below needed for ability to modify mfactr during execution SVOLX(1) = VECA(16) SVOLX(2) = VECA(17) SNUMX = VECA(18) SGRPNX(1) = VECA(19) SGRPNX(2) = VECA(20) SMEMN(1) = VECA(21) SMEMN(2) = VECA(22) SMEMSB(1) = VECA(23) SMEMSB(2) = VECA(24) ARATIO = AT/AORIGT TVOLX(1) = VECA(26) TVOLX(2) = VECA(27) TNUMX = VECA(28) TGRPNX(1) = VECA(29) TGRPNX(2) = VECA(30) TMEMN(1) = VECA(31) TMEMN(2) = VECA(32) TMEMSB(1) = VECA(33) TMEMSB(2) = VECA(34) ELSE C not the last occurance of this source/target pair, C instruction modify not allowed SVOLX(1) = BLNK SVOLX(2) = BLNK SNUMX = 0 SGRPNX(1) = BLNK SGRPNX(2) = BLNK SMEMN(1) = BLNK SMEMN(2) = BLNK SMEMSB(1) = 0 SMEMSB(2) = 0 ARATIO = 0 TVOLX(1) = BLNK TVOLX(2) = BLNK TNUMX = 0 TGRPNX(1) = BLNK TGRPNX(2) = BLNK TMEMN(1) = BLNK TMEMN(2) = BLNK TMEMSB(1) = 0 TMEMSB(2) = 0 END IF C NCOMPS = NTS ENDF = 0 C IF (VOLCOD .EQ. 1) THEN C sequential file - read format from proper source FMTCLS = VECA(11) IF (VECA(12) .NE. 0) THEN C get format from ucifl TREC= -VECA(12) CALL GETUCI (I0, M TREC, O UCIBF) READ (UCIBF,1000) (PVAR(J),J=1,19) READ (CBLNK,1020) PVAR(20) ELSE C get format from message file using fmtcls SGRP = FMTCLS+ 20 INITFG= 1 CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) READ (INBUFF,1010) (PVAR(J),J=1,19) READ (CBLNK,1020) PVAR(20) END IF IF (VECA(14) .EQ. 0) THEN GAPVAL = 0.0 ELSE GAPVAL = -1.E30 END IF C C initialize card sequence information CRDSEQ(1) = BEGYR- 1 CRDSEQ(2) = 12 CRDSEQ(3) = 31 CRDNO = 1 OLDOFF = -1440 C ELSE IF (VOLCOD .EQ. 2) THEN C expad - not yet implemented C program bug - report error SGRP = 123 CALL OMSG (MESSU,MSGFL,SCLU,SGRP, M ECOUNT) C ELSE IF (VOLCOD .EQ. 3) THEN C inpad C convert row number in file to virtual origin of inpad row FILE = VOPAD+ (FILE-1)*(WIDTH+1) ELSE IF (VOLCOD .EQ. 4) THEN C tss C input the dataset label CALL RBUFF (FRC,RECLT,TSSFL, O TBUFF) TRCNO = FRC VOBUFF = 0 BMTFLG = 0 BADR = 1 C set up values dependent on label info only DELTAT = DSDELT FREC = DSFREC LREC = DSLREC COMPR = DSCMPR TOTCOM = 0 DO 20 I=1,NMEMS TOTCOM = TOTCOM + MSUB(I) 20 CONTINUE C set up values already known UCNT = 0 ZCNT = 0 IF (GETF .EQ. 1) THEN C processing tsget instructions CALL GINIT (START) ELSE C processing tsput instructions CALL PINIT (START,ENDR,STIME,FMIN,DELT) DO 30 I= 1, TOTCOM PVAR(I)= 0.0 30 CONTINUE END IF ELSE IF (VOLCOD .LT. 0) THEN C wdms C set gap value for get IF (GETF .EQ. 1) THEN IF (VECA(14) .EQ. 0) THEN GAPVAL= 0.0 ELSE GAPVAL= -1.E30 END IF ELSE C set aggregation flag for put AGGRFG= VECA(14) END IF C C set data quality code QLFG= VECA(11) C C initialize nrem and pvar for put NREM= 0 PVAR(1)= INITPV(STTRAN(1)) C C set time at start of run, convert to wdms time, DO 40 I= 1, 5 INPDAT(I)= START(I) 40 CONTINUE INPDAT(6)= 0 C CALL TIMHTW (MESSU,MSGFL, M INPDAT) C IF (GETF .EQ. 1) THEN DO 50 I= 1, DELT CALL TIMBAK (I2, M INPDAT) 50 CONTINUE END IF ELSE IF (VOLCOD .EQ. 6) THEN C dss C set gap value for get IF (GETF .EQ. 1) THEN IF (VECA(14) .EQ. 0) THEN GAPVAL= 0.0 ELSE GAPVAL= -1.E30 END IF END IF C C get info from pathname block I= 0 C dountil found (i= -1) 60 CONTINUE I= I+ 1 IF (I .GT. NPATH) THEN C error - program bug - missing dss record id number C should be checked and stopped in DSSDS CALL OMSTI (VECA(2)) SGRP= 124 CALL OMSG (MESSU,MSGFL,SCLU,SGRP, M ECOUNT) ELSE C check for dss record id number IF (DSSDSN(I) .EQ. VECA(2)) THEN FILE= DSSFL(I) READ (CTYPE(I),1010) (CTYPI(J),J= 1, 2) READ (CPATH(I),1010) (PVAR(J),J= 1, 16) DO 70 J= 17, 20 READ(CBLNK,1020) PVAR(J) 70 CONTINUE I= -1 END IF END IF IF (I .GT. 0) GO TO 60 C IF (GETF .NE. 1) THEN C set nrem and aggrfg to indicate pvar(20) is empty C initialize accumulator for aggregation on put NREM= 0 AGGRFG= 0 PVAR(20)= INITPV(STTRAN(1)) END IF C C set time at start of run DO 80 I= 1, 5 INPDAT(I)= START(I) 80 CONTINUE INPDAT(6)= 0 C END IF C INKEY= INKEY +1 CALL PUTTSI (I220,INKEY,INSTR) IF (OUTLEV .GT. 5) THEN CALL TINOUT (INKEY,GETF) END IF C set up for next instruction NTS = 0 LTRNFG = 0 END IF DO 100 I= 1, 35 VECA(I)= VECB(I) 100 CONTINUE IF (KEY .LE. EKY) GO TO 10 END IF C IF (OUTLEV .GT. 5) THEN WRITE(MESSU,2020) END IF C RETURN END C C C SUBROUTINE NETBLK I (OPST,OPND,KEYST,KEYND, M WKEY) C C + + + PURPOSE + + + C Expand and check any entries for a given exgrp, in the network C block. chain entries by source and target opn sequence C order. C C + + + DUMMY ARGUMENTS + + + INTEGER KEYND,KEYST,OPND,OPST,WKEY C C + + + ARGUMENT DEFINITIONS + + + C OPST - ??? C OPND - ??? C KEYST - starting record number C KEYND - ending record number C WKEY - ??? C C + + + COMMON BLOCKS- INTERP3, OSV + + + INCLUDE 'crin3.inc' INCLUDE 'crin3c.inc' INCLUDE 'cmosv.inc' INCLUDE 'cmpad.inc' C C + + + LOCAL VARIABLES + + + INTEGER EUNITS,MESSU,MSGFL,SCLU,BGRP,GRP,I6, $ RWFG,SGRP,SMEMSB(2),START,SXGRP,TGRP, $ TOPFST,TOPLST,TMEMSB(2),TXGRP, $ TSBKCD,ITSR,GTCOD,DUMTVN REAL MFACTR CHARACTER*6 SMEMN,TMEMN CHARACTER*4 TRAN,SSYST,SGAPST,DUMTSY,DUMTGP,DUMAMD C C + + + FUNCTIONS + + + INTEGER OPNNO C C + + + EXTERNALS + + + EXTERNAL GTTMRC,OPNNO,OPNTS,TOPTNO,PAIRS,OMSG,OMSTI,OMSTC C C + + + OUTPUT FORMATS + + + 2000 FORMAT (/,' PROCESSING ANY ENTRIES IN NETWORK BLOCK') 2010 FORMAT (/,' THE FOLLOWING TARGET OPN-ID SPECIFICATION ', $ 'IMPLIES NO OPERATION WHICH IS IN THE') 2020 FORMAT (' SAME EXGRP AS THE SOURCE OPN - ENTRY IGNORED ', $ A6,2I4) 2060 FORMAT (/,' FINISHED PROCESSING ANY ENTRIES IN NETWORK BLOCK') C C + + + END SPECIFICATIONS + + + C MESSU = FILE(1) MSGFL = FILE(15) C SCLU = 215 C I6 = 6 C IF (OUTLEV .GT. 4) THEN C processing message WRITE (MESSU,2000) END IF C TSBKCD= 2 ITSR= KEYST BGRP= 52 C 10 CONTINUE C get a network entry (first network entry if first time through) CALL GTTMRC I (TSBKCD,KEYND,MESSU,MSGFL,SCLU,BGRP, M ITSR,ECOUNT, O SVOLC,SVOLNO,SGRPN,SMEMN,SMEMSB,SSYST,SGAPST, O MFACTR,TRAN,TVOLC,DUMTVN,TOPFST,TOPLST,TGRPN, O TMEMN,TMEMSB,DUMTSY,DUMTGP,DUMAMD,GTCOD) C IF (GTCOD .EQ. 2) THEN C network entry, process, check the source opn-id SNUM= OPNNO(SVOLC,SVOLNO,SVOLNO,MAXOPN,OPNTAB,OPST,OPND) C IF (SNUM .GT. 0) THEN C something in this exgrp matches the spec SXGRP = OPNTAB(5,SNUM) SGRP = OPNTAB(6,SNUM) SDELT = GRPTAB(3,SGRP) C dummy values SAMDCD= 0 SGAPCD= 0 SFRC = 0 C check and expand the supplied group and member-ids EUNITS= 0 C reading timseries RWFG = 2 CALL OPNTS I (SNUM,MAXOPN,OPNTAB,MSGFL,MESSU,SGRPN, I RWFG,SMEMN,SMEMSB,MAXOSV,MAXTTB, M ECOUNT,EUNITS, O OSV,SNTS,STABL,STABLR) C C check the supplied target opn-ids C check that the opn-type numbers are valid CALL TOPTNO I (MESSU,MSGFL, M TOPFST,TOPLST,ECOUNT) C C look for 1st operation which fits supplied target opn-id spec TNUM= OPNNO(TVOLC,TOPFST,TOPLST,MAXOPN,OPNTAB,OPST,OPND) C IF (TNUM .EQ. 0) THEN C nothing in this exgroup matches spec IF (OUTLEV .GE. 3) THEN C skip info message WRITE (MESSU,2010) WRITE (MESSU,2020) TVOLC, TOPFST, TOPLST END IF ELSE C process each target C whiledo tnum not=0 IF (TNUM .NE. 0) THEN 40 CONTINUE TVOLNO= OPNTAB(3,TNUM) TGRP = OPNTAB(6,TNUM) TDELT = GRPTAB(3,TGRP) C dummy values TAMDCD= 0 TGAPCD= 0 TFRC = 0 C writing timeseries RWFG = 1 C check and expand supplied group and member ids CALL OPNTS I (TNUM,MAXOPN,OPNTAB,MSGFL,MESSU, I TGRPN,RWFG,TMEMN,TMEMSB,MAXOSV, I MAXTTB, M ECOUNT,EUNITS, O OSV,TNTS,TTABL,TTABLR) C C check that source/target relationship is valid TXGRP= OPNTAB(6,TNUM) IF (SNUM .GE. TNUM .OR. SXGRP .NE. TXGRP) THEN C error - source/target operations are incompatible; C will be ignored CALL OMSTC (I6,SVOLC1) CALL OMSTI (SVOLNO) CALL OMSTC (I6,TVOLC1) CALL OMSTI (TVOLNO) GRP = 119 CALL OMSG (MESSU,MSGFL,SCLU,GRP, M ECOUNT) ELSE C match individual time series now situated in C source and target tables. write matched entries C to workfl CALL PAIRS I (TRAN,-999.0, M MFACTR,WKEY) END IF C C find next target operation for this entry START= TNUM+ 1 TNUM = OPNNO(TVOLC,TOPFST,TOPLST,MAXOPN,OPNTAB, 1 START,OPND) IF (TNUM .NE. 0) GO TO 40 END IF END IF END IF END IF IF (GTCOD .EQ. 2) GO TO 10 C IF (OUTLEV .GT. 4) THEN C done processing message WRITE (MESSU,2060) END IF C RETURN END C C C SUBROUTINE OPNTS I (OPNO,MAXOPN,OPNTAB,MSGFL,MESSU,GRPN, I RWFG,MEMN,MEMSB,MAXOSV,MXTTB, M ECOUNT,EUNITS, O OSV,NTS,TABL,TABLR) C C + + + PURPOSE + + + C Process a reference to time series pertaining to operation opno, C which were specified in, or implied by, a user's instruction C C + + + DUMMY ARGUMENTS + + + INTEGER ECOUNT,EUNITS,MAXOPN,MAXOSV,MXTTB, $ MSGFL,MEMSB(2), $ MESSU,NTS,OPNO,OPNTAB(20,MAXOPN),OSV(MAXOSV), $ RWFG,TABL(10,MXTTB) REAL TABLR(10,MXTTB) CHARACTER*6 GRPN,MEMN C C + + + ARGUMENT DEFINITIONS + + + C OPNO - ??? C MAXOPN - ??? C OPNTAB - ??? C MSGFL - fortran unit number of message file C MESSU - ftn unit no. to be used for printout of messages C GRPN - ??? C RWFG - read/write flag, 1-write, 2-read C MEMN - ??? C MEMSB - ??? C MAXOSV - ??? C MXTTB - ??? C ECOUNT - count(s) of specific errors C EUNITS - ??? C OSV - operation status vector for current operation C NTS - ??? C TABL - ??? C TABLR - ??? C C + + + PARAMETERS + + + INCLUDE 'pmxttb.inc' C C + + + SAVE VARIABLES + + + INTEGER GCUR,MCUR,MMAX,GMAX,GGRP(MAXTTB),SCLU CHARACTER*6 GKYWDS(MAXTTB),MKYWDS(MAXTTB) SAVE GCUR,MCUR,MMAX,GMAX,GGRP,SCLU, $ GKYWDS,MKYWDS C C + + + EQUIVALENCES + + + INTEGER MAXTT6 PARAMETER (MAXTT6=MAXTTB*6) EQUIVALENCE (GKYWDS,GKYWD1),(MKYWDS,MKYWD1) CHARACTER*1 GKYWD1(MAXTT6),MKYWD1(MAXTT6) C C + + + LOCAL VARIABLES + + + INTEGER GRPNO,I6,J, $ N,OMCODE,OPTNO, $ OSVKND,OSVKST,UUNITS, $ CLU,SGRP,CONT,INITFG,CLEN CHARACTER*80 INBUFF CHARACTER*6 CHSTR,OPTYP C C + + + EQUIVALENCES + + + EQUIVALENCE (INBUFF,INBUF1),(CHSTR,CHSTR1) CHARACTER*1 INBUF1(80),CHSTR1(6) C C + + + FUNCTIONS + + + INTEGER CHKSTR C C + + + EXTERNALS + + + EXTERNAL CHKSTR,OMSG,OMSTI,OMSTC,GETOSV,MEMTS,WMSGTT C C + + + INITIALIZATIONS + + + DATA GCUR/0/ C C + + + INPUT FORMATS + + + 1000 FORMAT (A6,I4) C C + + + OUTPUT FORMATS + + + 2070 FORMAT (A4,A2) C C + + + END SPECIFICATIONS + + + C I6= 6 C C initialize number of time series in result table NTS= 0 C WRITE(OPTYP,2070) (OPNTAB(J,OPNO),J=1,2) OPTNO = OPNTAB(3,OPNO) OMCODE= OPNTAB(4,OPNO) C C read in the osv OSVKST= OPNTAB(7,OPNO) OSVKND= OPNTAB(8,OPNO) CALL GETOSV (OSVKST,OSVKND,MAXOSV, O OSV) C C get internal unit system IF (OMCODE .GE. 4) THEN C utility operation UUNITS= OSV(29) ELSE IF (OMCODE .EQ. 3) THEN C rchres operation UUNITS= OSV(43) ELSE C perlnd or implnd operation UUNITS= OSV(44) END IF C C determine the external unit system appropriate to this reference IF (EUNITS .EQ. 0) THEN C use internal units of this opn as external units if the C opn is a utility opn; use ounits if the opn is a process opn IF (OMCODE .GE. 4) THEN C utility operation EUNITS= UUNITS ELSE IF (OMCODE .EQ. 3) THEN C rchres operation EUNITS= OSV(45) ELSE C perlnd or implnd operation EUNITS= OSV(46) END IF ELSE C valid value was supplied in argument list END IF C IF (OMCODE .NE. GCUR) THEN C need new group keys, get ready to read msgfl SCLU = 140+ OMCODE SGRP = 1 INITFG= 1 GMAX = 0 20 CONTINUE CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) INITFG= 0 GMAX = GMAX+ 1 READ (INBUFF,1000) GKYWDS(GMAX),GGRP(GMAX) IF (CONT.EQ.1 .AND. GMAX.LT.50) GO TO 20 GCUR= OMCODE MCUR= 0 END IF C C check the group name supplied by the user CHSTR= GRPN GRPNO= CHKSTR(I6,GMAX,CHSTR1,GKYWD1) C IF (GRPNO .EQ. 0) THEN C error - group name is invalid CHSTR= GRPN CALL OMSTC (I6,CHSTR1) CHSTR= OPTYP CALL OMSTC (I6,CHSTR1) CALL OMSTI (OPTNO) CLU = 215 SGRP = 111 CALL OMSG (MESSU,MSGFL,CLU,SGRP, M ECOUNT) ELSE C group valid, check the member name/subscript reference IF (MCUR .NE. GRPNO) THEN C need to know whats valid and how many there are SGRP = GRPNO+ 1 INITFG= 1 MMAX = 0 30 CONTINUE CLEN = 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) INITFG= 0 MMAX = MMAX+ 1 READ (INBUFF,1000) MKYWDS(MMAX) IF (CONT.EQ.1 .AND. MMAX.LT.50) GO TO 30 MCUR= GRPNO END IF C IF (MEMN .EQ.' ') THEN C all members are implied DO 70 N= 1,MMAX SGRP= N+ GGRP(GRPNO) CALL MEMTS (MESSU,MSGFL,SCLU,SGRP,MEMSB,OPTYP,OPTNO,GRPN, I EUNITS,UUNITS,MAXOSV,OSV,RWFG,MXTTB, M NTS,ECOUNT, O TABL,TABLR) 70 CONTINUE ELSE C only one member is involved, check the name CHSTR= MEMN N = CHKSTR(I6,MMAX,CHSTR1,MKYWD1) C IF (N .EQ. 0) THEN C error - invalid member name CHSTR= OPTYP CALL OMSTC (I6,CHSTR1) CALL OMSTI (OPTNO) CHSTR= GRPN CALL OMSTC (I6,CHSTR1) CHSTR= MEMN CALL OMSTC (I6,CHSTR1) CLU = 215 SGRP = 112 CALL OMSG (MESSU,MSGFL,CLU,SGRP, M ECOUNT) ELSE C ok - process this member SGRP= N+ GGRP(GRPNO) CALL MEMTS (MESSU,MSGFL,SCLU,SGRP,MEMSB,OPTYP,OPTNO,GRPN, I EUNITS,UUNITS,MAXOSV,OSV,RWFG,MXTTB, M NTS,ECOUNT, O TABL,TABLR) END IF END IF END IF C RETURN END C C C SUBROUTINE MEMTS I (MESSU,MSGFL,SCLU,SGRP,MEMSB,OPTYP,OPTNO,GRPN, I EUNITS,UUNITS,MAXOSV,OSV,RWFG,MAXTTB, M NTS,ECOUNT, O TABL,TABLR) C C + + + PURPOSE + + + C Process a single member (n) C C + + + DUMMY ARGUMENTS + + + INTEGER ECOUNT,EUNITS,MAXTTB,MAXOSV, $ MSGFL,SCLU,MEMSB(2),MESSU,SGRP,NTS,OPTNO, $ OSV(MAXOSV),RWFG,TABL(10,MAXTTB),UUNITS REAL TABLR(10,MAXTTB) CHARACTER*6 GRPN,OPTYP C C + + + ARGUMENT DEFINITIONS + + + C MESSU - ftn unit no. to be used for printout of messages C MSGFL - fortran unit number of message file C SCLU - current cluster in message file C SGRP - current group in message file C MEMSB - ??? C OPTYP - operation type C OPTNO - ??? C GRPN - ??? C EUNITS - ??? C UUNITS - system of units 1-english, 2-metric C OSV - ??? C RWFG - read write flag, 1-write, 2-read C NTS - ??? C ECOUNT - count(s) of specific errors C TABL - ??? C TABLR - ??? C C + + + LOCAL VARIABLES + + + INTEGER ERRFG,J,MAXSB1,MAXSB2,MDIM1,MIO,MKIND,MSECT, # OSVBAS,OSVOFF,PROCFG,SPTRN,SUB1,SUB1HI,SUB1LO,SUB2, # SUB2HI,SUB2LO,K1,OFONFG,PROARR(3,2,2),L,K,CONT, # INITFG,CLEN,CLU,GRP,I6 REAL ADD,LTVAL(2,2,2),MULT CHARACTER*1 INBUF1(80) CHARACTER*6 CHSTR,MEMN C C + + + EQUIVALENCES + + + EQUIVALENCE (INBUF1,INBUFF) CHARACTER*80 INBUFF EQUIVALENCE (CHSTR,CHSTR1) CHARACTER*1 CHSTR1(6) C C + + + FUNCTIONS + + + INTEGER IVALUE C C + + + EXTERNALS + + + EXTERNAL OMSG,OMSTI,OMSTC,IVALUE,WMSGTT C C + + + DATA INITIALIZATIONS + + + DATA PROARR/0,1,0,3,0,1,0,0,0,1,1,2/ C C + + + INPUT FORMATS + + + 1000 FORMAT (A6,I3,3X,2I6,4I2,I5,I6,13X,2(F4.0,F8.0)) 1005 FORMAT (56X,2(F4.0,F8.0)) 1010 FORMAT (A4,A2) C C + + + END SPECIFICATIONS + + + C I6= 6 C C get info about this member from message file INITFG= 1 CLEN= 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) READ (INBUFF,1000) MEMN,MDIM1,MAXSB1,MAXSB2,MKIND,SPTRN,MSECT, # MIO,OSVBAS,OSVOFF,((LTVAL(K,L,1),K=1,2),L=1,2) INITFG= 0 CLEN= 80 CALL WMSGTT (MSGFL,SCLU,SGRP,INITFG, M CLEN, O INBUF1,CONT) READ (INBUFF,1005) ((LTVAL(K,L,2),K=1,2),L=1,2) C C section off(1) or on(2) C IF (MSECT .GT. 0) THEN C timseries associated with module section, C section may not be active - check active sections vector OFONFG= OSV(MSECT)+ 1 ELSE C section always on OFONFG= 2 END IF C K1= MIO+ 1 PROCFG= PROARR(K1,OFONFG,RWFG) C IF (PROCFG .EQ. 0) THEN C dont process, not active ELSE IF (PROCFG .EQ. 1) THEN C check subscripts to make sure this member is used ERRFG= 0 C some data which have come from message file may be pointers to C osv locations containing the actual information - process these C max values for subscripts MAXSB1= IVALUE (MAXSB1,MAXOSV,OSV) MAXSB2= IVALUE (MAXSB2,MAXOSV,OSV) C IF ( (MAXSB1 .LE. 0) .OR. (MAXSB2 .LE. 0) ) THEN C dont process, maximum subscript is zero - treat like procfg=0 ELSE C process the member, assume no problem with subscripts C IF ( (MEMSB(2) .LT. 0) .OR. (MEMSB(2) .GT. MAXSB2) ) THEN C error - subscript out of range ERRFG= 1 CHSTR= OPTYP CALL OMSTC (I6,CHSTR1) CALL OMSTI (OPTNO) CHSTR= GRPN CALL OMSTC (I6,CHSTR1) CHSTR= MEMN CALL OMSTC (I6,CHSTR1) CALL OMSTI (MEMSB(2)) CLU= 215 GRP= 115 CALL OMSG (MESSU,MSGFL,CLU,GRP, M ECOUNT) MEMSB(2)= 1 END IF C IF (MEMSB(2) .EQ. 0) THEN C whole possible range SUB2LO= 1 SUB2HI= MAXSB2 ELSE C just specified value SUB2LO= MEMSB(2) SUB2HI= MEMSB(2) END IF C C look at first subscript IF ( (MEMSB(1) .LT. 0) .OR. (MEMSB(1) .GT. MAXSB1) ) THEN C error - subscript out of range ERRFG= 1 CHSTR= OPTYP CALL OMSTC (I6,CHSTR1) CALL OMSTI (OPTNO) CHSTR= GRPN CALL OMSTC (I6,CHSTR1) CHSTR= MEMN CALL OMSTC (I6,CHSTR1) CALL OMSTI (MEMSB(1)) CLU= 215 GRP= 115 CALL OMSG (MESSU,MSGFL,CLU,GRP, M ECOUNT) MEMSB(1)= 1 ELSE IF (MEMSB(1) .EQ. 0) THEN C whole possible range SUB1LO= 1 SUB1HI= MAXSB1 ELSE C just specified value SUB1LO= MEMSB(1) SUB1HI= MEMSB(1) END IF C IF (ERRFG .EQ. 0) THEN C unit system conversion constants IF ( (EUNITS .EQ. 1) .OR. (EUNITS .EQ. 2) ) THEN ADD= LTVAL(1,EUNITS,UUNITS) MULT= LTVAL(2,EUNITS,UUNITS) ELSE ADD= 0. MULT= 1. END IF C built output table DO 130 SUB2= SUB2LO,SUB2HI DO 120 SUB1= SUB1LO,SUB1HI C enter this time series in the results table NTS= NTS+ 1 C member name READ (MEMN,1010) (TABL(J,NTS),J=1,2) C subscripts TABL(3,NTS)= SUB1 TABL(4,NTS)= SUB2 C C osv offset TABL(5,NTS)= OSVBAS+ OSVOFF+ (SUB2- 1)*MDIM1+ SUB1- 1 TABL(6,NTS)= MKIND TABL(7,NTS)= SPTRN TABLR(8,NTS)= ADD TABLR(9,NTS)= MULT 120 CONTINUE 130 CONTINUE END IF END IF ELSE IF (PROCFG .EQ. 2) THEN C trying to output an input only timeseries ERRFG= 1 CHSTR= OPTYP CALL OMSTC (I6,CHSTR1) CALL OMSTI (OPTNO) CHSTR= GRPN CALL OMSTC (I6,CHSTR1) CHSTR= MEMN CALL OMSTC (I6,CHSTR1) CLU= 215 GRP= 96 CALL OMSG (MESSU,MSGFL,CLU,GRP, M ECOUNT) ELSE IF (PROCFG .EQ. 3) THEN C trying to input an output only timeseries ERRFG= 1 CHSTR= OPTYP CALL OMSTC (I6,CHSTR1) CALL OMSTI (OPTNO) CHSTR= GRPN CALL OMSTC (I6,CHSTR1) CHSTR= MEMN CALL OMSTC (I6,CHSTR1) CLU= 215 GRP= 97 CALL OMSG (MESSU,MSGFL,CLU,GRP, M ECOUNT) END IF C RETURN END C C C INTEGER FUNCTION IVALUE I (IVAL,MAXOSV,OSV) C C + + + PURPOSE + + + C Look at a supplied integer value. if it's positive, return the C value, if negative return the value in the osv with a virtual C origin equal to its absolute value. C C + + + DUMMY ARGUMENTS + + + INTEGER IVAL,MAXOSV,OSV(MAXOSV) C C + + + ARGUMENT DEFINITIONS + + + C IVAL - value supplied C MAXOSV - maximum size of osv C OSV - operation status vector C C + + + LOCAL VARIABLES + + + INTEGER ADDR C C + + + INTRINSICS + + + INTRINSIC IABS C C + + + END SPECIFICATIONS + + + C IF (IVAL .GE. 0) THEN C positive, return the value IVALUE= IVAL ELSE C negative, return value from osv at position value ADDR = IABS(IVAL) IVALUE= OSV(ADDR) END IF C RETURN END C C C SUBROUTINE PAIRS I (TRAN,AREA, M MFACTR,WKEY) C C + + + PURPOSE + + + C Check pairs of entries in source and target tables and write C paired entries to workfl C C + + + DUMMY ARGUMENTS + + + INTEGER WKEY REAL AREA,MFACTR CHARACTER*4 TRAN C C + + + ARGUMENT DEFINITIONS + + + C TRAN - ??? C AREA - area term for pair, -999 for ignore C MFACTR - ??? C WKEY - ??? C C + + + COMMON BLOCKS- INTERP3 + + + INCLUDE 'crin3.inc' INCLUDE 'crin3c.inc' C C + + + LOCAL VARIABLES + + + INTEGER CASE,DIFF,IDUM1(8),IDUM2(10),ERRFG,I0,I8,J, $ MESSU,N,NUMBR,SKIND,SPTRN,STKIND,STTRAN,MSGFL, $ TKIND,RWFG,LEN,REC(50),MXKY,I6,I4,SCLU,SGRP REAL A,B,SADD,SMULT,TADD,TMULT CHARACTER*6 CHSTR C C + + + EQUIVALENCES + + + EQUIVALENCE (CHSTR,CHSTR1) CHARACTER*1 CHSTR1(6) EQUIVALENCE (REC(1),RREC(1)) REAL RREC(50) C C + + + INTRINSICS + + + INTRINSIC MOD,ABS C C + + + FUNCTIONS + + + INTEGER CHKSTR C C + + + EXTERNALS + + + EXTERNAL CHKSTR,WORKIO,OMSG,ZIPI,OMSTC,OMSTI C C + + + INPUT FORMATS + + + 1000 FORMAT (A4,A2) C C + + + OUTPUT FORMATS + + + 2070 FORMAT (A4,A2) C C + + + END SPECIFICATIONS + + + C I0 = 0 I4 = 4 I6 = 6 I8 = 8 SCLU= 215 C CALL ZIPI(I8,I0,IDUM1) J= 10 CALL ZIPI(J,I0,IDUM2) C MESSU = FILE(1) MSGFL = FILE(15) C DIFF = SNTS- TNTS IF (DIFF .GT. 0) THEN NUMBR= TNTS ELSE NUMBR= SNTS END IF C IF (SNTS.EQ.0 .OR. TNTS.EQ.0) THEN NUMBR= 0 END IF C IF (NUMBR .GT. 0) THEN C there are 1 or more pairs to process ERRFG= 0 C C check time step relationship for aggregation to wdm dataset; C set wdm target time step to inpad time step of source if C aggregation not being performed IF (TVOLC(1:3) .EQ. EXTKWL(3)(1:3)) THEN C target is wdm dataset IF (TDELT .GT. SDELT .AND. $ (TGAPCD .EQ. 1 .OR. TGAPCD .EQ. 3)) THEN C wdm dataset timestep > opn timestep and aggregation is on IF (MOD(TDELT,SDELT) .NE. 0) THEN C error - wdm time step not even multiple of opn timestep SGRP = 150 CALL OMSG (MESSU,MSGFL,SCLU,SGRP, M ECOUNT) END IF IF (TGAPCD .EQ. 3) THEN TGAPCD= 1 END IF ELSE C aggregation not being performed IF (TGAPCD .EQ. 2 .OR. TGAPCD .EQ. 3) THEN C vbtime is 1, check time step IF (SDELT .NE. TDELT) THEN C error, time step of dataset and run dont match SGRP = 150 CALL OMSG (MESSU,MSGFL,SCLU,SGRP, M ECOUNT) END IF END IF TGAPCD= 0 TDELT = SDELT END IF END IF C C now check for compatibility of time intervals IF (SDELT .EQ. TDELT) THEN CASE= 1 ELSE IF ( MOD(SDELT,TDELT) .NE. 0) THEN IF ( MOD(TDELT,SDELT) .NE. 0) THEN C error - source and target time intervals not C compatible CALL OMSTC (I6,SVOLC1) CALL OMSTI (SVOLNO) CALL OMSTC (I6,TVOLC1) CALL OMSTI (TVOLNO) SGRP = 116 CALL OMSG (MESSU,MSGFL,SCLU,SGRP, M ECOUNT) ERRFG= 1 END IF END IF C IF (SDELT .GT. TDELT) THEN CASE= 2 ELSE CASE= 3 END IF END IF C IF (ERRFG .EQ. 0) THEN C process the entries DO 100 N= 1,NUMBR C check the next source/target pair SKIND= STABL(6,N) TKIND= TTABL(6,N) C IF (SKIND .EQ. 1) THEN C source timeseries is point IF (TKIND .EQ. 1 .OR. TKIND .EQ. 3) THEN C point to point (since target is point or undefined) STKIND= 1 ELSE C point to mean STKIND= 3 END IF ELSE IF (SKIND .EQ. 2) THEN C source timeseries is mean IF (TKIND .EQ. 1) THEN C mean to point - error ERRFG = 1 STKIND= 0 CALL OMSTC (I6,SVOLC1) CALL OMSTI (SVOLNO) CHSTR= SGRPN CALL OMSTC (I6,CHSTR1) WRITE (CHSTR,2070) (STABL(J,N),J=1,2) CALL OMSTC (I6,CHSTR1) CALL OMSTI (STABL(3,N)) CALL OMSTI (STABL(4,N)) CALL OMSTC (I6,TVOLC1) CALL OMSTI (TVOLNO) CHSTR= TGRPN CALL OMSTC (I6,CHSTR1) WRITE (CHSTR,2070) (TTABL(J,N),J=1,2) CALL OMSTC (I6,CHSTR1) CALL OMSTI (TTABL(3,N)) CALL OMSTI (TTABL(4,N)) SGRP = 117 CALL OMSG (MESSU,MSGFL,SCLU,SGRP, M ECOUNT) C ELSE C mean to mean (target is either mean or undefined) STKIND= 2 END IF ELSE IF (SKIND .EQ. 3) THEN C skind is undefined so base stkind on tkind C this is for sequential input IF (TKIND .EQ. 1) THEN STKIND= 1 ELSE IF (TKIND .EQ. 2) THEN STKIND= 2 END IF END IF C IF (ERRFG .NE. 1) THEN C ok - continue IF (TRAN .EQ. ' ') THEN C use default source/target transformation functional SPTRN= TTABL(7,N) IF (SPTRN .GT. 0 .AND. SDELT .EQ. 1440) THEN C a special disaggregation functional is to be used STTRAN= SPTRN ELSE C default functional to be used STTRAN= TRNTAB(9,STKIND,CASE) C change default intp or last to aver if wdm or dss C source, or dss target IF ( (SVOLC(1:3) .EQ. EXTKWL(3)(1:3)) .OR. # (SVOLC(1:4) .EQ. EXTKWL(4)) .OR. # (TVOLC(1:4) .EQ. EXTKWL(4)) ) THEN IF (STTRAN .EQ. 7 .OR. STTRAN .EQ. 8) THEN STTRAN= 3 END IF END IF END IF ELSE C check supplied transformation functional CHSTR(1:4)= TRAN STTRAN = CHKSTR(I4,I8,CHSTR1,TRNKW1) IF (STTRAN .EQ. 0) THEN C invalid functional keyword ERRFG= 1 ELSE C valid keyword so far, but must check wdm source C and other sources separately ERRFG = 0 C sources other than wdm - regular functionals are used; C this is ok since disagg to a wdm target is not allowed, C and intp is not implemented for wdm put; C sdelt <= tdelt for wdm put IF (TRNTAB(STTRAN,STKIND,CASE) .EQ. 0) THEN C transformation not allowed ERRFG =1 END IF C check wdm and dss source, and dss target separately IF ( (SVOLC(1:3) .EQ. EXTKWL(3)(1:3)) .OR. # (SVOLC(1:4) .EQ. EXTKWL(4)) .OR. # (TVOLC(1:4) .EQ. EXTKWL(4)) ) THEN IF ( (STTRAN .EQ. 7) .OR. (STTRAN .EQ. 8) ) THEN C intp/last not valid ERRFG= 1 ELSE IF ((STTRAN .EQ. 1) .OR. (STTRAN .EQ. 3)) THEN C same/aver is valid ERRFG= 0 END IF END IF END IF C IF (ERRFG .EQ. 1) THEN C error - invalid source/target transformation C functional CALL OMSTC (I6,SVOLC1) CALL OMSTI (SVOLNO) CHSTR= SGRPN CALL OMSTC (I6,CHSTR1) WRITE (CHSTR,2070) (STABL(J,N),J=1,2) CALL OMSTC (I6,CHSTR1) CALL OMSTI (STABL(3,N)) CALL OMSTI (STABL(4,N)) CHSTR(1:4)= TRAN CALL OMSTC (I4,CHSTR1) CALL OMSTI (STKIND) CALL OMSTI (CASE) CALL OMSTC (I6,TVOLC1) CALL OMSTI (TVOLNO) CHSTR= TGRPN CALL OMSTC (I6,CHSTR1) WRITE (CHSTR,2070) (TTABL(J,N),J=1,2) CALL OMSTC (I6,CHSTR1) CALL OMSTI (TTABL(3,N)) CALL OMSTI (TTABL(4,N)) SGRP = 118 CALL OMSG (MESSU,MSGFL,SCLU,SGRP, M ECOUNT) END IF END IF C IF (ERRFG .EQ. 0) THEN C derive composite pair of constants for linear transform SMULT= STABLR(9,N) SADD = STABLR(8,N) TMULT= TTABLR(9,N) TADD = TTABLR(8,N) cC cC mfactr is user-supplied factor, check for default value c IF ((ABS(MFACTR)) .LE. 0.0) THEN c MFACTR= 1.0 c END IF C A= (TMULT/SMULT)*MFACTR IF (ABS(A-1.0) .LT. .001) THEN A= 1.0 END IF C B= (TADD- MFACTR* SADD)*TMULT IF (ABS(B-0.0) .LT. .0001) THEN B= 0.0 END IF C C put this pair in workfl WKEY = WKEY+ 1 C make up rec READ(SVOLC,1000) (REC(J),J=1,2) REC(3)= SNUM REC(4)= SDELT READ(SGRPN,1000) (REC(J),J=5,6) DO 70 J= 1,5 REC(J+6) = STABL(J,N) REC(J+32)= TTABL(J,N) 70 CONTINUE REC(12)= SAMDCD REC(13)= SGAPCD REC(14)= SFRC DO 80 J= 1,8 REC(J+14)=IDUM1(J) 80 CONTINUE C addition for enhanced timser output REC(19) = SDELT REC(20) = STTRAN IF (ABS(AREA+999.0).GT.1.0E-5) THEN C area term specified, primary for update during run RREC(21)= AREA RREC(22)= MFACTR/AREA ELSE RREC(21)= MFACTR RREC(22)= 1.0 END IF C end addition REC(23) = STKIND REC(24) = STTRAN RREC(25)= A RREC(26)= B READ(TVOLC,1000) (REC(J),J=27,28) REC(29) = TNUM REC(30) = TDELT READ(TGRPN,1000) (REC(J),J=31,32) REC(38) = TAMDCD REC(39) = TGAPCD REC(40) = TFRC DO 90 J= 1,10 REC(J+40)= IDUM2(1) 90 CONTINUE C RWFG= 1 LEN = 50 MXKY= 0 CALL WORKIO (RWFG,LEN,WKEY, M REC,MXKY) END IF END IF 100 CONTINUE END IF END IF C RETURN END C C C SUBROUTINE SCHBLK I (OPST,OPND,KEYST,KEYND,MAXMLK, I MSLINX,NMLTBS, M WKEY) C C + + + PURPOSE + + + C Expand and check any entries for a given exgrp, in the schematics C block. C C + + + HISTORY + + + C 12/7/2004 jlk&pbd added area C C + + + DUMMY ARGUMENTS + + + INTEGER KEYND,KEYST,OPND,OPST,WKEY,MAXMLK,MSLINX(MAXMLK,3), # NMLTBS C C + + + ARGUMENT DEFINITIONS + + + C OPST - ??? C OPND - ??? C KEYST - starting record number C KEYND - ending record number C MAXMLK - maximum number of mass-link tables C MSLINX - ??? C NMLTBS - ??? C WKEY - ??? C C + + + PARAMETERS + + + INTEGER MAXCNX PARAMETER (MAXCNX=150) C C + + + COMMON BLOCKS- INTERP3, OSV + + + INCLUDE 'crin3.inc' INCLUDE 'crin3c.inc' INCLUDE 'cmosv.inc' INCLUDE 'cmpad.inc' C C + + + LOCAL VARIABLES + + + INTEGER EUNITS,MSGFL,MESSU,BGRP,RWFG,SGRP,SMEMSB(2), $ SXGRP,TGRP,TMEMSB(2),TXGRP,I,MSLKTB, $ SMMSUB(2,MAXCNX), # TMMSUB(2,MAXCNX),NUMCON,CNNXN, # DUMSMS(2),DTMSUB(2), # TSBKCD,ITSR,GTCOD,DUMTPL,SCLU,GRP,I6 REAL MFACTR,MFCT(MAXCNX),AREA CHARACTER*6 SMEMN,TMEMN,SGPNAM(MAXCNX),SMMNAM(MAXCNX), # TGPNAM(MAXCNX),TMMNAM(MAXCNX), # DUMSGN,DUMTGN,DUMSMB,DUMTMB CHARACTER*4 TRAN,TRANSF(MAXCNX),DUMTSY,DUMTGP,DUMAMD, # DUMSSY,DUMTRN,DUMSGP C C + + + FUNCTIONS + + + INTEGER OPNNO C C + + + EXTERNALS + + + EXTERNAL OPNNO,PSCHEM,OPNTS,TOPTNO,OMSG,OMSTI,OMSTC EXTERNAL PAIRS,GTTMRC C C + + + OUTPUT FORMATS + + + 2000 FORMAT (/,' PROCESSING ANY ENTRIES IN SCHEMATICS BLOCK') 2010 FORMAT (/,' THE FOLLOWING TARGET OPN-ID SPECIFICATION ', $ 'IS NOT IN THE') 2020 FORMAT (' SAME INGRP AS THE SOURCE OPN - ENTRY IGNORED ', $ A6,I4) 2060 FORMAT (/,' FINISHED PROCESSING ANY ENTRIES IN SCHEMATICS BLOCK') C C + + + END SPECIFICATIONS + + + C SCLU = 215 MESSU = FILE(1) MSGFL = FILE(15) I6 = 6 C IF (OUTLEV .GT. 4) THEN C processing message WRITE (MESSU,2000) END IF C TSBKCD= 4 ITSR= KEYST BGRP= 54 C 10 CONTINUE C get a schematic entry (first schematic entry if first time through) CALL GTTMRC I (TSBKCD,KEYND,MESSU,MSGFL,SCLU,BGRP, M ITSR,ECOUNT, O SVOLC,SVOLNO,DUMSGN,DUMSMB,DUMSMS,DUMSSY,DUMSGP, O AREA,DUMTRN,TVOLC,TVOLNO,MSLKTB,DUMTPL,DUMTGN, O DUMTMB,DTMSUB,DUMTSY,DUMTGP,DUMAMD,GTCOD) C IF (GTCOD .EQ. 4) THEN C schematic entry, expand it CALL PSCHEM I (MSGFL,MESSU,MAXOPN,OPNTAB,OPST,OPND,SVOLC,SVOLNO, I TVOLC,TVOLNO,AREA,MAXMLK,MSLINX,NMLTBS,MSLKTB, I MAXCNX, M ECOUNT, O SGPNAM,SMMNAM,SMMSUB,MFCT,TRANSF, O TGPNAM,TMMNAM,TMMSUB,NUMCON) IF (NUMCON .GT. 0) THEN C process each connection implied by the schematic entry DO 50 CNNXN = 1, NUMCON C assign necessary variables for subroutines opnts and pairs MFACTR= MFCT(CNNXN) TRAN = TRANSF(CNNXN) SGRPN = SGPNAM(CNNXN) SMEMN = SMMNAM(CNNXN) TGRPN = TGPNAM(CNNXN) TMEMN = TMMNAM(CNNXN) DO 20 I= 1,2 SMEMSB(I)= SMMSUB(I,CNNXN) IF (TMMSUB(I,CNNXN) .GE. 1) THEN C mass-link specified subscript overrides schematic default TMEMSB(I)= TMMSUB(I,CNNXN) ELSE C use default TMEMSB(I)= DTMSUB(I) END IF 20 CONTINUE C C check the source opn-id SNUM= OPNNO(SVOLC,SVOLNO,SVOLNO,MAXOPN,OPNTAB,OPST,OPND) C IF (SNUM .GT. 0) THEN C entry in this exgrp matches the source spec SXGRP = OPNTAB(5,SNUM) SGRP = OPNTAB(6,SNUM) SDELT = GRPTAB(3,SGRP) C dummy values SAMDCD= 0 SGAPCD= 0 SFRC = 0 C check the supplied group and member-ids EUNITS= 0 C reading timseries RWFG = 2 CALL OPNTS (SNUM,MAXOPN,OPNTAB,MSGFL,MESSU, I SGRPN,RWFG,SMEMN,SMEMSB,MAXOSV,MAXTTB, M ECOUNT,EUNITS, O OSV,SNTS,STABL,STABLR) C C check the supplied target opn-id C check that the opn-type number is valid CALL TOPTNO (MESSU,MSGFL, M TVOLNO,TVOLNO,ECOUNT) C C check the target opn-id TNUM= OPNNO(TVOLC,TVOLNO,TVOLNO,MAXOPN,OPNTAB,OPST,OPND) C IF (TNUM .EQ. 0) THEN C nothing in this exin group matches target IF (OUTLEV .GT. 4) THEN WRITE (MESSU,2010) WRITE (MESSU,2020) TVOLC, TVOLNO END IF ELSE C process the target TGRP = OPNTAB(6,TNUM) TDELT = GRPTAB(3,TGRP) C dummy values TAMDCD= 0 TGAPCD= 0 TFRC = 0 C writing timseries RWFG = 1 C check and expand supplied group and member ids CALL OPNTS (TNUM,MAXOPN,OPNTAB,MSGFL,MESSU, I TGRPN,RWFG,TMEMN,TMEMSB,MAXOSV, I MAXTTB, M ECOUNT,EUNITS, O OSV,TNTS,TTABL,TTABLR) C C check that source/target relationship is valid TXGRP= OPNTAB(6,TNUM) IF (SNUM .GE. TNUM .OR. SXGRP .NE. TXGRP) THEN C error - source/target operations are incompatible; C will be ignored CALL OMSTC (I6,SVOLC1) CALL OMSTI (SVOLNO) CALL OMSTC (I6,TVOLC1) CALL OMSTI (TVOLNO) GRP = 119 CALL OMSG (MESSU,MSGFL,SCLU,GRP, M ECOUNT) ELSE C match individual time series now situated in C source and target tables. write matched entries C to workfl CALL PAIRS (TRAN,AREA, M MFACTR,WKEY) END IF END IF END IF 50 CONTINUE END IF END IF C IF (GTCOD .EQ. 4) GO TO 10 C IF (OUTLEV .GT. 4) THEN C end processing message WRITE (MESSU,2060) END IF C RETURN END C C C SUBROUTINE SRCBLK I (OPST,OPND,KEYST,KEYND,SDATIM,EDATIM, I SFTKST,SFTKND,IHMFG, M WKEY,WKSTES,WKNDES) C C + + + PURPOSE + + + C expand and check entries in ext sources block, for a given range C of operations, and chain by target opn sequence order C C + + + DUMMY ARGUMENTS + + + INTEGER EDATIM(5),OPND,OPST,SDATIM(5),SFTKND,SFTKST,WKEY, # WKNDES,WKSTES,KEYST,KEYND,IHMFG C C + + + HISTORY + + + C 05/06/2004 BRB added IHMFG to allow no data range checking for WDM datasets C 12/7/2004 jlk&pbd added dummy area C C + + + ARGUMENT DEFINITIONS + + + C OPST - ??? C OPND - ??? C KEYST - starting record number C KEYND - ending record number C SDATIM - ??? C EDATIM - ??? C SFTKST - ??? C SFTKND - ??? C IHMFG - IHM flag (normal-0,IHM control-1) C WKEY - ??? C WKSTES - ??? C WKNDES - ??? C C + + + COMMON BLOCKS- INTERP3, OSV + + + INCLUDE 'crin3.inc' INCLUDE 'crin3c.inc' INCLUDE 'cmosv.inc' INCLUDE 'cmpad.inc' C C + + + LOCAL VARIABLES + + + INTEGER MESSU,SMEMSB(2),TMEMSB(2),SCLU,BGRP, $ START,TGRP,TOPFST,TOPLST, $ MSGFL,WKND,WKST,I1,I2,I3,I4,RWFG, $ TSBKCD,ITSR,GTCOD,DUMTVN REAL MFACTR CHARACTER*6 SMEMN,TMEMN CHARACTER*4 TRAN,SSYST,AMDST,SGAPST,DUMTSY,DUMAMD,DUMTGP C C + + + FUNCTIONS + + + INTEGER OPNNO C C + + + EXTERNALS + + + EXTERNAL GTTMRC,TOPTNO,EXTTS,OPNTS,PAIRS,CHAIN,WKDMP1,OPNNO C C + + + OUTPUT FORMATS + + + 2000 FORMAT (/,' PROCESSING ANY ENTRIES IN EXT SOURCES BLOCK') 2010 FORMAT (/,' FINISHED PROCESSING ANY ENTRIES IN EXT SOURCES BLOCK') C C + + + END SPECIFICATIONS + + + C MESSU= FILE(1) MSGFL= FILE(15) C SCLU= 215 C C wkst is key at which first record will be written to workfl, C if any are written WKST= WKEY+ 1 C IF (OUTLEV .GT. 4) THEN C processing message WRITE (MESSU,2000) END IF C TSBKCD= 1 ITSR= KEYST BGRP= 50 C 10 CONTINUE C get an ext sources entry (first entry if first time through) CALL GTTMRC I (TSBKCD,KEYND,MESSU,MSGFL,SCLU,BGRP, M ITSR,ECOUNT, O SVOLC,SVOLNO,SGRPN,SMEMN,SMEMSB,SSYST,SGAPST, O MFACTR,TRAN,TVOLC,DUMTVN,TOPFST,TOPLST,TGRPN, O TMEMN,TMEMSB,DUMTSY,DUMTGP,DUMAMD,GTCOD) IF (GTCOD .EQ. 1) THEN C ext sources entry, process C C check whether target reference is valid and if it covers C any time series in this exgroup CALL TOPTNO I (MESSU,MSGFL, M TOPFST,TOPLST,ECOUNT) TNUM= OPNNO(TVOLC,TOPFST,TOPLST,MAXOPN,OPNTAB,OPST,OPND) C IF (TNUM .GT. 0) THEN C at least one operation in this exgroup is included in this C entry - check entry in detail and expand it if necessary C C source reference C for ext sources, access mode is not meaningful AMDST= ' ' I1 = 0 CALL EXTTS I (SMEMN,SMEMSB,SSYST,AMDST,SGAPST,SDATIM, I EDATIM,SVOLC,SVOLNO,SFTKST,SFTKND,I1,MAXTTB, I IHMFG, O SNUM,SDELT,SUNITS,SGRPN,SNTS,SAMDCD,SFRC, O SGAPCD,STABL,STABLR) C C whiledo tnum not= 0 30 CONTINUE IF (TNUM .NE. 0) THEN TVOLNO= OPNTAB(3,TNUM) TGRP = OPNTAB(6,TNUM) TDELT = GRPTAB(3,TGRP) C dummy values TAMDCD= 0 TGAPCD= 0 TFRC = 0 C writing timeseries RWFG = 1 C check target reference CALL OPNTS I (TNUM,MAXOPN,OPNTAB,MSGFL,MESSU, I TGRPN,RWFG,TMEMN,TMEMSB,MAXOSV,MAXTTB, M ECOUNT,SUNITS, O OSV,TNTS,TTABL,TTABLR) C C match source and target entries, C write matched pairs to workfl CALL PAIRS I (TRAN,-999.0, M MFACTR,WKEY) C C find the next target opn for this entry START= TNUM+ 1 TNUM = OPNNO(TVOLC,TOPFST,TOPLST,MAXOPN,OPNTAB,START, I OPND) END IF IF (TNUM .NE. 0) GO TO 30 END IF END IF C loop back if more entries IF (GTCOD .EQ. 1) GO TO 10 C IF (WKEY .GE. WKST) THEN C something was written to workfl WKND= WKEY C C sort, using pointers, in target opn seq order and keep workfl C keys in opntab I1= 29 I2= 41 I3= 9 I4= 10 CALL CHAIN I (OPST,OPND,WKST,WKND,I1,I2,I3,I4,MAXOPN, O OPNTAB,WKSTES,WKNDES) C IF (OUTLEV .GT. 5) THEN C dump records written to workfl CALL WKDMP1 (WKST,WKND,MESSU) END IF END IF C IF (OUTLEV .GT. 4) THEN C done processing message WRITE (MESSU,2010) END IF C RETURN END C C C SUBROUTINE TARBLK I (OPST,OPND,KEYST,KEYND,SDATIM,EDATIM,TFTKST, I TFTKND,IHMFG, M WKEY) C C + + + PURPOSE + + + C Expand and check any entries in the ext targets block for this C exgrp. chain entries by source opn sequence order. C C + + + HISTORY + + + C 05/06/2004 BRB added IHMFG to allow no data range checking for WDM datasets C 12/7/2004 jlk&pbd added dummy area C C + + + DUMMY ARGUMENTS + + + INTEGER EDATIM(5),KEYND,KEYST,OPND,OPST,SDATIM(5), $ TFTKND,TFTKST,WKEY,IHMFG C C + + + ARGUMENT DEFINITIONS + + + C OPST - ??? C OPND - ??? C KEYST - starting record number C KEYND - ending record number C SDATIM - starting date/time C EDATIM - ending date/time C TFTKST - ??? C TFTKND - ??? C IHMFG - IHM flag (normal-0,IHM control-1) C WKEY - ??? C C + + + COMMON BLOCKS- INTERP3, OSV + + + INCLUDE 'crin3.inc' INCLUDE 'crin3c.inc' INCLUDE 'cmosv.inc' INCLUDE 'cmpad.inc' C C + + + LOCAL VARIABLES + + + INTEGER IDUM1,IDUM2,MESSU,MSGFL,SGRP,SCLU,BGRP, $ SMEMSB(2),TMEMSB(2), $ WKND,WKST,I1,I2,I3,I4,TSBKCD, $ ITSR,GTCOD,RWFG,TOPFST,TOPLST REAL MFACTR CHARACTER*6 SMEMN,TMEMN CHARACTER*4 TRAN,TSYST,SSYST,TGAPST,AMDST,SGAPST C C + + + FUNCTIONS + + + INTEGER OPNNO C C + + + EXTERNALS + + + EXTERNAL GTTMRC,OPNNO,EXTTS,OPNTS,PAIRS,CHAIN,WKDMP1 C C + + + OUTPUT FORMATS + + + 2000 FORMAT (/,' PROCESSING ANY ENTRIES IN EXT TARGETS BLOCK') 2010 FORMAT (/,' FINISHED PROCESSING ANY ENTRIES IN EXT TARGETS BLOCK') C C + + + END SPECIFICATIONS + + + C I1 = 1 SCLU= 215 C MESSU= FILE(1) MSGFL= FILE(15) C C wkst is key at which first record will be written to C workfl, if any are written WKST= WKEY+ 1 C IF (OUTLEV .GT. 4) THEN C processing message WRITE (MESSU,2000) END IF C TSBKCD= 3 ITSR= KEYST BGRP= 56 C 10 CONTINUE C get an ext targets entry (first entry if first time through) CALL GTTMRC I (TSBKCD,KEYND,MESSU,MSGFL,SCLU,BGRP, M ITSR,ECOUNT, O SVOLC,SVOLNO,SGRPN,SMEMN,SMEMSB,SSYST,SGAPST, O MFACTR,TRAN,TVOLC,TVOLNO,TOPFST,TOPLST,TGRPN, O TMEMN,TMEMSB,TSYST,TGAPST,AMDST,GTCOD) C IF (GTCOD .EQ. 3) THEN C ext targets entry, process C C check the source opn-id SNUM= OPNNO(SVOLC,SVOLNO,SVOLNO,MAXOPN,OPNTAB,OPST,OPND) C IF (SNUM .GT. 0) THEN C check and expand the supplied target reference CALL EXTTS I (TMEMN,TMEMSB,TSYST,AMDST,TGAPST,SDATIM, I EDATIM,TVOLC,TVOLNO,TFTKST,TFTKND,I1,MAXTTB, I IHMFG, O TNUM,TDELT,TUNITS,TGRPN,TNTS,TAMDCD,TFRC, O TGAPCD,TTABL,TTABLR) C C check and expand the supplied source reference SGRP = OPNTAB(6,SNUM) SDELT = GRPTAB(3,SGRP) C dummy values SAMDCD= 0 SGAPCD= 0 SFRC = 0 C reading timeseries RWFG = 2 CALL OPNTS I (SNUM,MAXOPN,OPNTAB,MSGFL,MESSU,SGRPN, I RWFG,SMEMN,SMEMSB,MAXOSV,MAXTTB, M ECOUNT,TUNITS, O OSV,SNTS,STABL,STABLR) C C match any individual time series references situated C in the source and target tables. write matched C references to workfl. CALL PAIRS I (TRAN,-999.0, M MFACTR,WKEY) END IF END IF IF (GTCOD .EQ. 3) GO TO 10 C IF (WKEY .GE. WKST) THEN C something was written to workfl WKND= WKEY C C chain in source opn sequence order, and keep keys in opntab I1= 3 I2= 15 I3= 15 I4= 16 CALL CHAIN I (OPST,OPND,WKST,WKND,I1,I2,I3,I4,MAXOPN, O OPNTAB,IDUM1,IDUM2) C IF (OUTLEV .GT. 5) THEN C dump records written to workfl CALL WKDMP1 (WKST,WKND,MESSU) END IF END IF C IF (OUTLEV .GT. 4) THEN C done processing message WRITE (MESSU,2010) END IF C RETURN END
bsd-3-clause
eiselekd/gcc
gcc/testsuite/gfortran.fortran-torture/execute/entry_2.f90
190
1166
! Test alternate entry points for functions when the result types ! of all entry points match character*(*) function f1 (str, i, j) character str*(*), e1*(*), e2*(*) integer i, j f1 = str (i:j) return entry e1 (str, i, j) i = i + 1 entry e2 (str, i, j) j = j - 1 e2 = str (i:j) end function character*5 function f3 () character e3*(*), e4*(*) integer i f3 = 'ABCDE' return entry e3 (i) entry e4 (i) if (i .gt. 0) then e3 = 'abcde' else e4 = 'UVWXY' endif end function program entrytest character f1*16, e1*16, e2*16, str*16, ret*16 character f3*5, e3*5, e4*5 integer i, j str = 'ABCDEFGHIJ' i = 2 j = 6 ret = f1 (str, i, j) if ((i .ne. 2) .or. (j .ne. 6)) call abort () if (ret .ne. 'BCDEF') call abort () ret = e1 (str, i, j) if ((i .ne. 3) .or. (j .ne. 5)) call abort () if (ret .ne. 'CDE') call abort () ret = e2 (str, i, j) if ((i .ne. 3) .or. (j .ne. 4)) call abort () if (ret .ne. 'CD') call abort () if (f3 () .ne. 'ABCDE') call abort () if (e3 (1) .ne. 'abcde') call abort () if (e4 (1) .ne. 'abcde') call abort () if (e3 (0) .ne. 'UVWXY') call abort () if (e4 (0) .ne. 'UVWXY') call abort () end program
gpl-2.0
redstar3894/android-gcc-4.6
libgfortran/generated/_anint_r16.F90
22
1488
! 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_ROUNDL elemental function _gfortran_specific__anint_r16 (parm) real (kind=16), intent (in) :: parm real (kind=16) :: _gfortran_specific__anint_r16 _gfortran_specific__anint_r16 = anint (parm) end function #endif #endif
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/alloc_comp_transformational_1.f90
166
2244
! { dg-do run } ! Tests the fix for PR41478, in which double frees would occur because ! transformational intrinsics did not copy the allocatable components ! so that they were (sometimes) freed twice on exit. In addition, ! The original allocatable components of a1 were not freed, so that ! memory leakage occurred. ! ! Contributed by Juergen Reuter <reuter@physik.uni-freiburg.de> ! type :: container_t integer, dimension(:), allocatable :: entry integer index end type container_t call foo call bar contains ! ! This is the reported problem. ! subroutine foo type(container_t), dimension(4) :: a1, a2, a3 integer :: i do i = 1, 4 allocate (a1(i)%entry (2), a2(i)%entry (2), a3(i)%entry (2)) a1(i)%entry = [1,2] a2(i)%entry = [3,4] a3(i)%entry = [4,5] a1(i)%index = i a2(i)%index = i a3(i)%index = i end do a1(1:2) = pack (a2, [.true., .false., .true., .false.]) do i = 1, 4 if (.not.allocated (a1(i)%entry)) call abort if (i .gt. 2) then if (any (a1(i)%entry .ne. [1,2])) call abort else if (any (a1(i)%entry .ne. [3,4])) call abort end if end do ! ! Now check unpack ! a1 = unpack (a1, [.true., .true., .false., .false.], a3) if (any (a1%index .ne. [1,3,3,4])) call abort do i = 1, 4 if (.not.allocated (a1(i)%entry)) call abort if (i .gt. 2) then if (any (a1(i)%entry .ne. [4,5])) call abort else if (any (a1(i)%entry .ne. [3,4])) call abort end if end do end subroutine ! ! Other all transformational intrinsics display it. Having done ! PACK and UNPACK, just use TRANSPOSE as a demonstrator. ! subroutine bar type(container_t), dimension(2,2) :: a1, a2 integer :: i, j do i = 1, 2 do j = 1, 2 allocate (a1(i, j)%entry (2), a2(i, j)%entry (2)) a1(i, j)%entry = [i,j] a2(i, j)%entry = [i,j] a1(i,j)%index = j + (i - 1)*2 a2(i,j)%index = j + (i - 1)*2 end do end do a1 = transpose (a2) do i = 1, 2 do j = 1, 2 if (a1(i,j)%index .ne. i + (j - 1)*2) call abort if (any (a1(i,j)%entry .ne. [j,i])) call abort end do end do end subroutine end
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/move_alloc_6.f90
146
1565
! { dg-do run } ! ! Test move_alloc for polymorphic scalars ! ! module myalloc implicit none type :: base_type integer :: i =2 end type base_type type, extends(base_type) :: extended_type integer :: j = 77 end type extended_type contains subroutine myallocate (a) class(base_type), allocatable, intent(inout) :: a class(base_type), allocatable :: tmp allocate (extended_type :: tmp) select type(tmp) type is(base_type) call abort () type is(extended_type) if (tmp%i /= 2 .or. tmp%j /= 77) call abort() tmp%i = 5 tmp%j = 88 end select select type(a) type is(base_type) if (a%i /= -44) call abort() a%i = -99 class default call abort () end select call move_alloc (from=tmp, to=a) select type(a) type is(extended_type) if (a%i /= 5) call abort() if (a%j /= 88) call abort() a%i = 123 a%j = 9498 class default call abort () end select if (allocated (tmp)) call abort() end subroutine myallocate end module myalloc program main use myalloc implicit none class(base_type), allocatable :: a allocate (a) select type(a) type is(base_type) if (a%i /= 2) call abort() a%i = -44 class default call abort () end select call myallocate (a) select type(a) type is(extended_type) if (a%i /= 123) call abort() if (a%j /= 9498) call abort() class default call abort () end select end program main
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/bound_7.f90
174
7185
! { dg-do run } ! { dg-options "-std=gnu" } ! PR fortran/29391 ! This file is here to check that LBOUND and UBOUND return correct values ! ! Contributed by Francois-Xavier Coudert (coudert@clipper.ens.fr) implicit none integer, allocatable :: i(:,:), j(:), u(:,:,:,:) allocate (i(-1:1,-1:1)) i = 0 allocate (j(-1:2)) j = 0 allocate (u(7,4,2,9)) call foo(u,4) call jackal(-1,-8) call jackal(-1,8) if (any(lbound(i(-1:1,-1:1)) /= 1)) call abort if (lbound(i(-1:1,-1:1), 1) /= 1) call abort if (lbound(i(-1:1,-1:1), 2) /= 1) call abort if (any(ubound(i(-1:1,-1:1)) /= 3)) call abort if (ubound(i(-1:1,-1:1), 1) /= 3) call abort if (ubound(i(-1:1,-1:1), 2) /= 3) call abort if (any(lbound(i(:,:)) /= 1)) call abort if (lbound(i(:,:), 1) /= 1) call abort if (lbound(i(:,:), 2) /= 1) call abort if (any(ubound(i(:,:)) /= 3)) call abort if (ubound(i(:,:), 1) /= 3) call abort if (ubound(i(:,:), 2) /= 3) call abort if (any(lbound(i(0:,-1:)) /= 1)) call abort if (lbound(i(0:,-1:), 1) /= 1) call abort if (lbound(i(0:,-1:), 2) /= 1) call abort if (any(ubound(i(0:,-1:)) /= [2,3])) call abort if (ubound(i(0:,-1:), 1) /= 2) call abort if (ubound(i(0:,-1:), 2) /= 3) call abort if (any(lbound(i(:0,:0)) /= 1)) call abort if (lbound(i(:0,:0), 1) /= 1) call abort if (lbound(i(:0,:0), 2) /= 1) call abort if (any(ubound(i(:0,:0)) /= 2)) call abort if (ubound(i(:0,:0), 1) /= 2) call abort if (ubound(i(:0,:0), 2) /= 2) call abort if (any(lbound(transpose(i)) /= 1)) call abort if (lbound(transpose(i), 1) /= 1) call abort if (lbound(transpose(i), 2) /= 1) call abort if (any(ubound(transpose(i)) /= 3)) call abort if (ubound(transpose(i), 1) /= 3) call abort if (ubound(transpose(i), 2) /= 3) call abort if (any(lbound(reshape(i,[2,2])) /= 1)) call abort if (lbound(reshape(i,[2,2]), 1) /= 1) call abort if (lbound(reshape(i,[2,2]), 2) /= 1) call abort if (any(ubound(reshape(i,[2,2])) /= 2)) call abort if (ubound(reshape(i,[2,2]), 1) /= 2) call abort if (ubound(reshape(i,[2,2]), 2) /= 2) call abort if (any(lbound(cshift(i,-1)) /= 1)) call abort if (lbound(cshift(i,-1), 1) /= 1) call abort if (lbound(cshift(i,-1), 2) /= 1) call abort if (any(ubound(cshift(i,-1)) /= 3)) call abort if (ubound(cshift(i,-1), 1) /= 3) call abort if (ubound(cshift(i,-1), 2) /= 3) call abort if (any(lbound(eoshift(i,-1)) /= 1)) call abort if (lbound(eoshift(i,-1), 1) /= 1) call abort if (lbound(eoshift(i,-1), 2) /= 1) call abort if (any(ubound(eoshift(i,-1)) /= 3)) call abort if (ubound(eoshift(i,-1), 1) /= 3) call abort if (ubound(eoshift(i,-1), 2) /= 3) call abort if (any(lbound(spread(i,1,2)) /= 1)) call abort if (lbound(spread(i,1,2), 1) /= 1) call abort if (lbound(spread(i,1,2), 2) /= 1) call abort if (any(ubound(spread(i,1,2)) /= [2,3,3])) call abort if (ubound(spread(i,1,2), 1) /= 2) call abort if (ubound(spread(i,1,2), 2) /= 3) call abort if (ubound(spread(i,1,2), 3) /= 3) call abort if (any(lbound(maxloc(i)) /= 1)) call abort if (lbound(maxloc(i), 1) /= 1) call abort if (any(ubound(maxloc(i)) /= 2)) call abort if (ubound(maxloc(i), 1) /= 2) call abort if (any(lbound(minloc(i)) /= 1)) call abort if (lbound(minloc(i), 1) /= 1) call abort if (any(ubound(minloc(i)) /= 2)) call abort if (ubound(minloc(i), 1) /= 2) call abort if (any(lbound(maxval(i,2)) /= 1)) call abort if (lbound(maxval(i,2), 1) /= 1) call abort if (any(ubound(maxval(i,2)) /= 3)) call abort if (ubound(maxval(i,2), 1) /= 3) call abort if (any(lbound(minval(i,2)) /= 1)) call abort if (lbound(minval(i,2), 1) /= 1) call abort if (any(ubound(minval(i,2)) /= 3)) call abort if (ubound(minval(i,2), 1) /= 3) call abort if (any(lbound(any(i==1,2)) /= 1)) call abort if (lbound(any(i==1,2), 1) /= 1) call abort if (any(ubound(any(i==1,2)) /= 3)) call abort if (ubound(any(i==1,2), 1) /= 3) call abort if (any(lbound(count(i==1,2)) /= 1)) call abort if (lbound(count(i==1,2), 1) /= 1) call abort if (any(ubound(count(i==1,2)) /= 3)) call abort if (ubound(count(i==1,2), 1) /= 3) call abort if (any(lbound(merge(i,i,.true.)) /= 1)) call abort if (lbound(merge(i,i,.true.), 1) /= 1) call abort if (lbound(merge(i,i,.true.), 2) /= 1) call abort if (any(ubound(merge(i,i,.true.)) /= 3)) call abort if (ubound(merge(i,i,.true.), 1) /= 3) call abort if (ubound(merge(i,i,.true.), 2) /= 3) call abort if (any(lbound(lbound(i)) /= 1)) call abort if (lbound(lbound(i), 1) /= 1) call abort if (any(ubound(lbound(i)) /= 2)) call abort if (ubound(lbound(i), 1) /= 2) call abort if (any(lbound(ubound(i)) /= 1)) call abort if (lbound(ubound(i), 1) /= 1) call abort if (any(ubound(ubound(i)) /= 2)) call abort if (ubound(ubound(i), 1) /= 2) call abort if (any(lbound(shape(i)) /= 1)) call abort if (lbound(shape(i), 1) /= 1) call abort if (any(ubound(shape(i)) /= 2)) call abort if (ubound(shape(i), 1) /= 2) call abort if (any(lbound(product(i,2)) /= 1)) call abort if (any(ubound(product(i,2)) /= 3)) call abort if (any(lbound(sum(i,2)) /= 1)) call abort if (any(ubound(sum(i,2)) /= 3)) call abort if (any(lbound(matmul(i,i)) /= 1)) call abort if (any(ubound(matmul(i,i)) /= 3)) call abort if (any(lbound(pack(i,.true.)) /= 1)) call abort if (any(ubound(pack(i,.true.)) /= 9)) call abort if (any(lbound(unpack(j,[.true.],[2])) /= 1)) call abort if (any(ubound(unpack(j,[.true.],[2])) /= 1)) call abort call sub1(i,3) call sub1(reshape([7,9,4,6,7,9],[3,2]),3) call sub2 contains subroutine sub1(a,n) integer :: n, a(2:n+1,4:*) if (any([lbound(a,1), lbound(a,2)] /= [2, 4])) call abort if (any(lbound(a) /= [2, 4])) call abort end subroutine sub1 subroutine sub2 integer :: x(3:2, 1:2) if (size(x) /= 0) call abort if (lbound (x, 1) /= 1 .or. lbound(x, 2) /= 1) call abort if (any (lbound (x) /= [1, 1])) call abort if (ubound (x, 1) /= 0 .or. ubound(x, 2) /= 2) call abort if (any (ubound (x) /= [0, 2])) call abort end subroutine sub2 subroutine sub3 integer :: x(4:5, 1:2) if (size(x) /= 0) call abort if (lbound (x, 1) /= 4 .or. lbound(x, 2) /= 1) call abort if (any (lbound (x) /= [4, 1])) call abort if (ubound (x, 1) /= 4 .or. ubound(x, 2) /= 2) call abort if (any (ubound (x) /= [4, 2])) call abort end subroutine sub3 subroutine foo (x,n) integer :: x(7,n,2,*), n if (ubound(x,1) /= 7 .or. ubound(x,2) /= 4 .or. ubound(x,3) /= 2) call abort end subroutine foo subroutine jackal (b, c) integer :: b, c integer :: soda(b:c, 3:4) if (b > c) then if (size(soda) /= 0) call abort if (lbound (soda, 1) /= 1 .or. ubound (soda, 1) /= 0) call abort else if (size(soda) /= 2*(c-b+1)) call abort if (lbound (soda, 1) /= b .or. ubound (soda, 1) /= c) call abort end if if (lbound (soda, 2) /= 3 .or. ubound (soda, 2) /= 4) call abort if (any (lbound (soda) /= [lbound(soda,1), lbound(soda,2)])) call abort if (any (ubound (soda) /= [ubound(soda,1), ubound(soda,2)])) call abort end subroutine jackal end
gpl-2.0
trankmichael/scipy
scipy/special/cdflib/fpser.f
151
1154
DOUBLE PRECISION FUNCTION fpser(a,b,x,eps) C----------------------------------------------------------------------- C C EVALUATION OF I (A,B) C X C C FOR B .LT. MIN(EPS,EPS*A) AND X .LE. 0.5. C C----------------------------------------------------------------------- C C SET FPSER = X**A C C .. Scalar Arguments .. DOUBLE PRECISION a,b,eps,x C .. C .. Local Scalars .. DOUBLE PRECISION an,c,s,t,tol C .. C .. External Functions .. DOUBLE PRECISION exparg EXTERNAL exparg C .. C .. Intrinsic Functions .. INTRINSIC abs,dlog,exp C .. C .. Executable Statements .. fpser = 1.0D0 IF (a.LE.1.D-3*eps) GO TO 10 fpser = 0.0D0 t = a*dlog(x) IF (t.LT.exparg(1)) RETURN fpser = exp(t) C C NOTE THAT 1/B(A,B) = B C 10 fpser = (b/a)*fpser tol = eps/a an = a + 1.0D0 t = x s = t/an 20 an = an + 1.0D0 t = x*t c = t/an s = s + c IF (abs(c).GT.tol) GO TO 20 C fpser = fpser* (1.0D0+a*s) RETURN END
bsd-3-clause
eiselekd/gcc
gcc/testsuite/gfortran.dg/gomp/udr1.f90
119
1508
! { dg-do compile } subroutine f1 !$omp declare reduction (.le.:integer:omp_out = omp_out + omp_in) ! { dg-error "Invalid operator for" } end subroutine f1 subroutine f2 !$omp declare reduction (bar:real(kind=4):omp_out = omp_out + omp_in) real(kind=4) :: r integer :: i r = 0.0 !$omp parallel do reduction (bar:r) do i = 1, 10 r = r + i end do !$omp parallel do reduction (foo:r) ! { dg-error "foo not found" } do i = 1, 10 r = r + i end do !$omp parallel do reduction (.gt.:r) ! { dg-error "cannot be used as a defined operator" } do i = 1, 10 r = r + i end do end subroutine f2 subroutine f3 !$omp declare reduction (foo:blah:omp_out=omp_out + omp_in) ! { dg-error "Unclassifiable OpenMP directive" } end subroutine f3 subroutine f4 !$omp declare reduction (foo:integer:a => null()) ! { dg-error "Invalid character in name" } !$omp declare reduction (foo:integer:omp_out = omp_in + omp_out) & !$omp & initializer(a => null()) ! { dg-error "Invalid character in name" } end subroutine f4 subroutine f5 integer :: a, b !$omp declare reduction (foo:integer:a = b + 1) ! { dg-error "Variable other than OMP_OUT or OMP_IN used in combiner" } !$omp declare reduction (bar:integer:omp_out = omp_out * omp_in) & !$omp & initializer(b = a + 1) ! { dg-error "Variable other than OMP_PRIV or OMP_ORIG used in INITIALIZER clause" } end subroutine f5 subroutine f6 !$omp declare reduction (foo:integer:omp_out=omp_out+omp_in) & !$omp & initializer(omp_orig=omp_priv) end subroutine f6
gpl-2.0
trankmichael/scipy
scipy/sparse/linalg/eigen/arpack/ARPACK/SRC/znaupd.f
142
27770
c\BeginDoc c c\Name: znaupd c c\Description: c Reverse communication interface for the Implicitly Restarted Arnoldi c iteration. This is intended to be used to find a few eigenpairs of a c complex linear operator OP with respect to a semi-inner product defined c by a hermitian positive semi-definite real matrix B. B may be the identity c matrix. NOTE: if both OP and B are real, then dsaupd or dnaupd should c be used. c c c The computed approximate eigenvalues are called Ritz values and c the corresponding approximate eigenvectors are called Ritz vectors. c c znaupd is usually called iteratively to solve one of the c following problems: c c Mode 1: A*x = lambda*x. c ===> OP = A and B = I. c c Mode 2: A*x = lambda*M*x, M hermitian positive definite c ===> OP = inv[M]*A and B = M. c ===> (If M can be factored see remark 3 below) c c Mode 3: A*x = lambda*M*x, M hermitian semi-definite c ===> OP = inv[A - sigma*M]*M and B = M. c ===> shift-and-invert mode c If OP*x = amu*x, then lambda = sigma + 1/amu. c c c NOTE: The action of w <- inv[A - sigma*M]*v or w <- inv[M]*v c should be accomplished either by a direct method c using a sparse matrix factorization and solving c c [A - sigma*M]*w = v or M*w = v, c c or through an iterative method for solving these c systems. If an iterative method is used, the c convergence test must be more stringent than c the accuracy requirements for the eigenvalue c approximations. c c\Usage: c call znaupd c ( IDO, BMAT, N, WHICH, NEV, TOL, RESID, NCV, V, LDV, IPARAM, c IPNTR, WORKD, WORKL, LWORKL, RWORK, INFO ) c c\Arguments c IDO Integer. (INPUT/OUTPUT) c Reverse communication flag. IDO must be zero on the first c call to znaupd . IDO will be set internally to c indicate the type of operation to be performed. Control is c then given back to the calling routine which has the c responsibility to carry out the requested operation and call c znaupd with the result. The operand is given in c WORKD(IPNTR(1)), the result must be put in WORKD(IPNTR(2)). c ------------------------------------------------------------- c IDO = 0: first call to the reverse communication interface c IDO = -1: compute Y = OP * X where c IPNTR(1) is the pointer into WORKD for X, c IPNTR(2) is the pointer into WORKD for Y. c This is for the initialization phase to force the c starting vector into the range of OP. c IDO = 1: compute Y = OP * X where c IPNTR(1) is the pointer into WORKD for X, c IPNTR(2) is the pointer into WORKD for Y. c In mode 3, the vector B * X is already c available in WORKD(ipntr(3)). It does not c need to be recomputed in forming OP * X. c IDO = 2: compute Y = M * X where c IPNTR(1) is the pointer into WORKD for X, c IPNTR(2) is the pointer into WORKD for Y. c IDO = 3: compute and return the shifts in the first c NP locations of WORKL. c IDO = 99: done c ------------------------------------------------------------- c After the initialization phase, when the routine is used in c the "shift-and-invert" mode, the vector M * X is already c available and does not need to be recomputed in forming OP*X. c c BMAT Character*1. (INPUT) c BMAT specifies the type of the matrix B that defines the c semi-inner product for the operator OP. c BMAT = 'I' -> standard eigenvalue problem A*x = lambda*x c BMAT = 'G' -> generalized eigenvalue problem A*x = lambda*M*x c c N Integer. (INPUT) c Dimension of the eigenproblem. c c WHICH Character*2. (INPUT) c 'LM' -> want the NEV eigenvalues of largest magnitude. c 'SM' -> want the NEV eigenvalues of smallest magnitude. c 'LR' -> want the NEV eigenvalues of largest real part. c 'SR' -> want the NEV eigenvalues of smallest real part. c 'LI' -> want the NEV eigenvalues of largest imaginary part. c 'SI' -> want the NEV eigenvalues of smallest imaginary part. c c NEV Integer. (INPUT) c Number of eigenvalues of OP to be computed. 0 < NEV < N-1. c c TOL Double precision scalar. (INPUT) c Stopping criteria: the relative accuracy of the Ritz value c is considered acceptable if BOUNDS(I) .LE. TOL*ABS(RITZ(I)) c where ABS(RITZ(I)) is the magnitude when RITZ(I) is complex. c DEFAULT = dlamch ('EPS') (machine precision as computed c by the LAPACK auxiliary subroutine dlamch ). c c RESID Complex*16 array of length N. (INPUT/OUTPUT) c On INPUT: c If INFO .EQ. 0, a random initial residual vector is used. c If INFO .NE. 0, RESID contains the initial residual vector, c possibly from a previous run. c On OUTPUT: c RESID contains the final residual vector. c c NCV Integer. (INPUT) c Number of columns of the matrix V. NCV must satisfy the two c inequalities 1 <= NCV-NEV and NCV <= N. c This will indicate how many Arnoldi vectors are generated c at each iteration. After the startup phase in which NEV c Arnoldi vectors are generated, the algorithm generates c approximately NCV-NEV Arnoldi vectors at each subsequent update c iteration. Most of the cost in generating each Arnoldi vector is c in the matrix-vector operation OP*x. (See remark 4 below.) c c V Complex*16 array N by NCV. (OUTPUT) c Contains the final set of Arnoldi basis vectors. c c LDV Integer. (INPUT) c Leading dimension of V exactly as declared in the calling program. c c IPARAM Integer array of length 11. (INPUT/OUTPUT) c IPARAM(1) = ISHIFT: method for selecting the implicit shifts. c The shifts selected at each iteration are used to filter out c the components of the unwanted eigenvector. c ------------------------------------------------------------- c ISHIFT = 0: the shifts are to be provided by the user via c reverse communication. The NCV eigenvalues of c the Hessenberg matrix H are returned in the part c of WORKL array corresponding to RITZ. c ISHIFT = 1: exact shifts with respect to the current c Hessenberg matrix H. This is equivalent to c restarting the iteration from the beginning c after updating the starting vector with a linear c combination of Ritz vectors associated with the c "wanted" eigenvalues. c ISHIFT = 2: other choice of internal shift to be defined. c ------------------------------------------------------------- c c IPARAM(2) = No longer referenced c c IPARAM(3) = MXITER c On INPUT: maximum number of Arnoldi update iterations allowed. c On OUTPUT: actual number of Arnoldi update iterations taken. c c IPARAM(4) = NB: blocksize to be used in the recurrence. c The code currently works only for NB = 1. c c IPARAM(5) = NCONV: number of "converged" Ritz values. c This represents the number of Ritz values that satisfy c the convergence criterion. c c IPARAM(6) = IUPD c No longer referenced. Implicit restarting is ALWAYS used. c c IPARAM(7) = MODE c On INPUT determines what type of eigenproblem is being solved. c Must be 1,2,3; See under \Description of znaupd for the c four modes available. c c IPARAM(8) = NP c When ido = 3 and the user provides shifts through reverse c communication (IPARAM(1)=0), _naupd returns NP, the number c of shifts the user is to provide. 0 < NP < NCV-NEV. c c IPARAM(9) = NUMOP, IPARAM(10) = NUMOPB, IPARAM(11) = NUMREO, c OUTPUT: NUMOP = total number of OP*x operations, c NUMOPB = total number of B*x operations if BMAT='G', c NUMREO = total number of steps of re-orthogonalization. c c IPNTR Integer array of length 14. (OUTPUT) c Pointer to mark the starting locations in the WORKD and WORKL c arrays for matrices/vectors used by the Arnoldi iteration. c ------------------------------------------------------------- c IPNTR(1): pointer to the current operand vector X in WORKD. c IPNTR(2): pointer to the current result vector Y in WORKD. c IPNTR(3): pointer to the vector B * X in WORKD when used in c the shift-and-invert mode. c IPNTR(4): pointer to the next available location in WORKL c that is untouched by the program. c IPNTR(5): pointer to the NCV by NCV upper Hessenberg c matrix H in WORKL. c IPNTR(6): pointer to the ritz value array RITZ c IPNTR(7): pointer to the (projected) ritz vector array Q c IPNTR(8): pointer to the error BOUNDS array in WORKL. c IPNTR(14): pointer to the NP shifts in WORKL. See Remark 5 below. c c Note: IPNTR(9:13) is only referenced by zneupd . See Remark 2 below. c c IPNTR(9): pointer to the NCV RITZ values of the c original system. c IPNTR(10): Not Used c IPNTR(11): pointer to the NCV corresponding error bounds. c IPNTR(12): pointer to the NCV by NCV upper triangular c Schur matrix for H. c IPNTR(13): pointer to the NCV by NCV matrix of eigenvectors c of the upper Hessenberg matrix H. Only referenced by c zneupd if RVEC = .TRUE. See Remark 2 below. c c ------------------------------------------------------------- c c WORKD Complex*16 work array of length 3*N. (REVERSE COMMUNICATION) c Distributed array to be used in the basic Arnoldi iteration c for reverse communication. The user should not use WORKD c as temporary workspace during the iteration !!!!!!!!!! c See Data Distribution Note below. c c WORKL Complex*16 work array of length LWORKL. (OUTPUT/WORKSPACE) c Private (replicated) array on each PE or array allocated on c the front end. See Data Distribution Note below. c c LWORKL Integer. (INPUT) c LWORKL must be at least 3*NCV**2 + 5*NCV. c c RWORK Double precision work array of length NCV (WORKSPACE) c Private (replicated) array on each PE or array allocated on c the front end. c c c INFO Integer. (INPUT/OUTPUT) c If INFO .EQ. 0, a randomly initial residual vector is used. c If INFO .NE. 0, RESID contains the initial residual vector, c possibly from a previous run. c Error flag on output. c = 0: Normal exit. c = 1: Maximum number of iterations taken. c All possible eigenvalues of OP has been found. IPARAM(5) c returns the number of wanted converged Ritz values. c = 2: No longer an informational error. Deprecated starting c with release 2 of ARPACK. c = 3: No shifts could be applied during a cycle of the c Implicitly restarted Arnoldi iteration. One possibility c is to increase the size of NCV relative to NEV. c See remark 4 below. c = -1: N must be positive. c = -2: NEV must be positive. c = -3: NCV-NEV >= 2 and less than or equal to N. c = -4: The maximum number of Arnoldi update iteration c must be greater than zero. c = -5: WHICH must be one of 'LM', 'SM', 'LR', 'SR', 'LI', 'SI' c = -6: BMAT must be one of 'I' or 'G'. c = -7: Length of private work array is not sufficient. c = -8: Error return from LAPACK eigenvalue calculation; c = -9: Starting vector is zero. c = -10: IPARAM(7) must be 1,2,3. c = -11: IPARAM(7) = 1 and BMAT = 'G' are incompatible. c = -12: IPARAM(1) must be equal to 0 or 1. c = -9999: Could not build an Arnoldi factorization. c User input error highly likely. Please c check actual array dimensions and layout. c IPARAM(5) returns the size of the current Arnoldi c factorization. c c\Remarks c 1. The computed Ritz values are approximate eigenvalues of OP. The c selection of WHICH should be made with this in mind when using c Mode = 3. When operating in Mode = 3 setting WHICH = 'LM' will c compute the NEV eigenvalues of the original problem that are c closest to the shift SIGMA . After convergence, approximate eigenvalues c of the original problem may be obtained with the ARPACK subroutine zneupd . c c 2. If a basis for the invariant subspace corresponding to the converged Ritz c values is needed, the user must call zneupd immediately following c completion of znaupd . This is new starting with release 2 of ARPACK. c c 3. If M can be factored into a Cholesky factorization M = LL` c then Mode = 2 should not be selected. Instead one should use c Mode = 1 with OP = inv(L)*A*inv(L`). Appropriate triangular c linear systems should be solved with L and L` rather c than computing inverses. After convergence, an approximate c eigenvector z of the original problem is recovered by solving c L`z = x where x is a Ritz vector of OP. c c 4. At present there is no a-priori analysis to guide the selection c of NCV relative to NEV. The only formal requirement is that NCV > NEV + 1. c However, it is recommended that NCV .ge. 2*NEV. If many problems of c the same type are to be solved, one should experiment with increasing c NCV while keeping NEV fixed for a given test problem. This will c usually decrease the required number of OP*x operations but it c also increases the work and storage required to maintain the orthogonal c basis vectors. The optimal "cross-over" with respect to CPU time c is problem dependent and must be determined empirically. c See Chapter 8 of Reference 2 for further information. c c 5. When IPARAM(1) = 0, and IDO = 3, the user needs to provide the c NP = IPARAM(8) complex shifts in locations c WORKL(IPNTR(14)), WORKL(IPNTR(14)+1), ... , WORKL(IPNTR(14)+NP). c Eigenvalues of the current upper Hessenberg matrix are located in c WORKL(IPNTR(6)) through WORKL(IPNTR(6)+NCV-1). They are ordered c according to the order defined by WHICH. The associated Ritz estimates c are located in WORKL(IPNTR(8)), WORKL(IPNTR(8)+1), ... , c WORKL(IPNTR(8)+NCV-1). c c----------------------------------------------------------------------- c c\Data Distribution Note: c c Fortran-D syntax: c ================ c Complex*16 resid(n), v(ldv,ncv), workd(3*n), workl(lworkl) c decompose d1(n), d2(n,ncv) c align resid(i) with d1(i) c align v(i,j) with d2(i,j) c align workd(i) with d1(i) range (1:n) c align workd(i) with d1(i-n) range (n+1:2*n) c align workd(i) with d1(i-2*n) range (2*n+1:3*n) c distribute d1(block), d2(block,:) c replicated workl(lworkl) c c Cray MPP syntax: c =============== c Complex*16 resid(n), v(ldv,ncv), workd(n,3), workl(lworkl) c shared resid(block), v(block,:), workd(block,:) c replicated workl(lworkl) c c CM2/CM5 syntax: c ============== c c----------------------------------------------------------------------- c c include 'ex-nonsym.doc' c c----------------------------------------------------------------------- c c\BeginLib c c\Local variables: c xxxxxx Complex*16 c c\References: c 1. D.C. Sorensen, "Implicit Application of Polynomial Filters in c a k-Step Arnoldi Method", SIAM J. Matr. Anal. Apps., 13 (1992), c pp 357-385. c 2. R.B. Lehoucq, "Analysis and Implementation of an Implicitly c Restarted Arnoldi Iteration", Rice University Technical Report c TR95-13, Department of Computational and Applied Mathematics. c 3. B.N. Parlett & Y. Saad, "_Complex_ Shift and Invert Strategies for c _Real_ Matrices", Linear Algebra and its Applications, vol 88/89, c pp 575-595, (1987). c c\Routines called: c znaup2 ARPACK routine that implements the Implicitly Restarted c Arnoldi Iteration. c zstatn ARPACK routine that initializes the timing variables. c ivout ARPACK utility routine that prints integers. c zvout ARPACK utility routine that prints vectors. c arscnd ARPACK utility routine for timing. c dlamch LAPACK routine that determines machine constants. c c\Author c Danny Sorensen Phuong Vu c Richard Lehoucq CRPC / Rice University c Dept. of Computational & Houston, Texas c Applied Mathematics c Rice University c Houston, Texas c c\SCCS Information: @(#) c FILE: naupd.F SID: 2.8 DATE OF SID: 04/10/01 RELEASE: 2 c c\Remarks c c\EndLib c c----------------------------------------------------------------------- c subroutine znaupd & ( ido, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, & ipntr, workd, workl, lworkl, rwork, info ) c c %----------------------------------------------------% c | Include files for debugging and timing information | c %----------------------------------------------------% c include 'debug.h' include 'stat.h' c c %------------------% c | Scalar Arguments | c %------------------% c character bmat*1, which*2 integer ido, info, ldv, lworkl, n, ncv, nev Double precision & tol c c %-----------------% c | Array Arguments | c %-----------------% c integer iparam(11), ipntr(14) Complex*16 & resid(n), v(ldv,ncv), workd(3*n), workl(lworkl) Double precision & rwork(ncv) c c %------------% c | Parameters | c %------------% c Complex*16 & one, zero parameter (one = (1.0D+0, 0.0D+0) , zero = (0.0D+0, 0.0D+0) ) c c %---------------% c | Local Scalars | c %---------------% c integer bounds, ierr, ih, iq, ishift, iupd, iw, & ldh, ldq, levec, mode, msglvl, mxiter, nb, & nev0, next, np, ritz, j save bounds, ih, iq, ishift, iupd, iw, & ldh, ldq, levec, mode, msglvl, mxiter, nb, & nev0, next, np, ritz c c %----------------------% c | External Subroutines | c %----------------------% c external znaup2 , zvout , ivout, arscnd, zstatn c c %--------------------% c | External Functions | c %--------------------% c Double precision & dlamch external dlamch c c %-----------------------% c | Executable Statements | c %-----------------------% c if (ido .eq. 0) then c c %-------------------------------% c | Initialize timing statistics | c | & message level for debugging | c %-------------------------------% c call zstatn call arscnd (t0) msglvl = mcaupd c c %----------------% c | Error checking | c %----------------% c ierr = 0 ishift = iparam(1) c levec = iparam(2) mxiter = iparam(3) c nb = iparam(4) nb = 1 c c %--------------------------------------------% c | Revision 2 performs only implicit restart. | c %--------------------------------------------% c iupd = 1 mode = iparam(7) c if (n .le. 0) then ierr = -1 else if (nev .le. 0) then ierr = -2 else if (ncv .le. nev .or. ncv .gt. n) then ierr = -3 else if (mxiter .le. 0) then ierr = -4 else if (which .ne. 'LM' .and. & which .ne. 'SM' .and. & which .ne. 'LR' .and. & which .ne. 'SR' .and. & which .ne. 'LI' .and. & which .ne. 'SI') then ierr = -5 else if (bmat .ne. 'I' .and. bmat .ne. 'G') then ierr = -6 else if (lworkl .lt. 3*ncv**2 + 5*ncv) then ierr = -7 else if (mode .lt. 1 .or. mode .gt. 3) then ierr = -10 else if (mode .eq. 1 .and. bmat .eq. 'G') then ierr = -11 end if c c %------------% c | Error Exit | c %------------% c if (ierr .ne. 0) then info = ierr ido = 99 go to 9000 end if c c %------------------------% c | Set default parameters | c %------------------------% c if (nb .le. 0) nb = 1 if (tol .le. 0.0D+0 ) tol = dlamch ('EpsMach') if (ishift .ne. 0 .and. & ishift .ne. 1 .and. & ishift .ne. 2) ishift = 1 c c %----------------------------------------------% c | NP is the number of additional steps to | c | extend the length NEV Lanczos factorization. | c | NEV0 is the local variable designating the | c | size of the invariant subspace desired. | c %----------------------------------------------% c np = ncv - nev nev0 = nev c c %-----------------------------% c | Zero out internal workspace | c %-----------------------------% c do 10 j = 1, 3*ncv**2 + 5*ncv workl(j) = zero 10 continue c c %-------------------------------------------------------------% c | Pointer into WORKL for address of H, RITZ, BOUNDS, Q | c | etc... and the remaining workspace. | c | Also update pointer to be used on output. | c | Memory is laid out as follows: | c | workl(1:ncv*ncv) := generated Hessenberg matrix | c | workl(ncv*ncv+1:ncv*ncv+ncv) := the ritz values | c | workl(ncv*ncv+ncv+1:ncv*ncv+2*ncv) := error bounds | c | workl(ncv*ncv+2*ncv+1:2*ncv*ncv+2*ncv) := rotation matrix Q | c | workl(2*ncv*ncv+2*ncv+1:3*ncv*ncv+5*ncv) := workspace | c | The final workspace is needed by subroutine zneigh called | c | by znaup2 . Subroutine zneigh calls LAPACK routines for | c | calculating eigenvalues and the last row of the eigenvector | c | matrix. | c %-------------------------------------------------------------% c ldh = ncv ldq = ncv ih = 1 ritz = ih + ldh*ncv bounds = ritz + ncv iq = bounds + ncv iw = iq + ldq*ncv next = iw + ncv**2 + 3*ncv c ipntr(4) = next ipntr(5) = ih ipntr(6) = ritz ipntr(7) = iq ipntr(8) = bounds ipntr(14) = iw end if c c %-------------------------------------------------------% c | Carry out the Implicitly restarted Arnoldi Iteration. | c %-------------------------------------------------------% c call znaup2 & ( ido, bmat, n, which, nev0, np, tol, resid, mode, iupd, & ishift, mxiter, v, ldv, workl(ih), ldh, workl(ritz), & workl(bounds), workl(iq), ldq, workl(iw), & ipntr, workd, rwork, info ) c c %--------------------------------------------------% c | ido .ne. 99 implies use of reverse communication | c | to compute operations involving OP. | c %--------------------------------------------------% c if (ido .eq. 3) iparam(8) = np if (ido .ne. 99) go to 9000 c iparam(3) = mxiter iparam(5) = np iparam(9) = nopx iparam(10) = nbx iparam(11) = nrorth c c %------------------------------------% c | Exit if there was an informational | c | error within znaup2 . | c %------------------------------------% c if (info .lt. 0) go to 9000 if (info .eq. 2) info = 3 c if (msglvl .gt. 0) then call ivout (logfil, 1, mxiter, ndigit, & '_naupd: Number of update iterations taken') call ivout (logfil, 1, np, ndigit, & '_naupd: Number of wanted "converged" Ritz values') call zvout (logfil, np, workl(ritz), ndigit, & '_naupd: The final Ritz values') call zvout (logfil, np, workl(bounds), ndigit, & '_naupd: Associated Ritz estimates') end if c call arscnd (t1) tcaupd = t1 - t0 c if (msglvl .gt. 0) then c c %--------------------------------------------------------% c | Version Number & Version Date are defined in version.h | c %--------------------------------------------------------% c write (6,1000) write (6,1100) mxiter, nopx, nbx, nrorth, nitref, nrstrt, & tmvopx, tmvbx, tcaupd, tcaup2, tcaitr, titref, & tgetv0, tceigh, tcgets, tcapps, tcconv, trvec 1000 format (//, & 5x, '=============================================',/ & 5x, '= Complex implicit Arnoldi update code =',/ & 5x, '= Version Number: ', ' 2.3' , 21x, ' =',/ & 5x, '= Version Date: ', ' 07/31/96' , 16x, ' =',/ & 5x, '=============================================',/ & 5x, '= Summary of timing statistics =',/ & 5x, '=============================================',//) 1100 format ( & 5x, 'Total number update iterations = ', i5,/ & 5x, 'Total number of OP*x operations = ', i5,/ & 5x, 'Total number of B*x operations = ', i5,/ & 5x, 'Total number of reorthogonalization steps = ', i5,/ & 5x, 'Total number of iterative refinement steps = ', i5,/ & 5x, 'Total number of restart steps = ', i5,/ & 5x, 'Total time in user OP*x operation = ', f12.6,/ & 5x, 'Total time in user B*x operation = ', f12.6,/ & 5x, 'Total time in Arnoldi update routine = ', f12.6,/ & 5x, 'Total time in naup2 routine = ', f12.6,/ & 5x, 'Total time in basic Arnoldi iteration loop = ', f12.6,/ & 5x, 'Total time in reorthogonalization phase = ', f12.6,/ & 5x, 'Total time in (re)start vector generation = ', f12.6,/ & 5x, 'Total time in Hessenberg eig. subproblem = ', f12.6,/ & 5x, 'Total time in getting the shifts = ', f12.6,/ & 5x, 'Total time in applying the shifts = ', f12.6,/ & 5x, 'Total time in convergence testing = ', f12.6,/ & 5x, 'Total time in computing final Ritz vectors = ', f12.6/) end if c 9000 continue c return c c %---------------% c | End of znaupd | c %---------------% c end
bsd-3-clause
pablodebiase/bromoc-e_suite
bromoc-e/src/grandmod.f90
1
3666
! BROMOC-E ! Electrodiffusion, Gran Canonical Monte Carlo, Brownian,Dynamics ! and Coarse Grain Model DNA Simulation Program. ! Copyright (C) 2014 Pablo M. De Biase (pablodebiase@gmail.com) ! ! This program 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. ! ! This program 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. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. ! Fortran common block for Grand Canonical Monte Carlo ! estaticf static field energy ! erfpar reaction field energy ! evdwgd repulsive energy ! Dimension of arrays module grandmod implicit none integer dtype, datom, mxcnt parameter (datom = 2000, dtype = 20) ! if datom bigger than 23000 start giving segm fault in ifort, solution -heap-arrays 0 integer dbuff parameter (dbuff = 2*dtype) !integer dindx !parameter (dindx = dtype*(dtype+1)/2) real,external :: rndm,rndm1 real ikbt,ikbtdna real temp,kbt,kBTdt,dnatemp,kbtdna real*8 runtime integer nbuffer integer,allocatable :: warn(:) integer ibfftyp(dbuff),nat(dtype),ncnt(dtype) integer nremove(dtype),ninsert(dtype),ntotat(dtype) real ampl1(dtype),p1(2,dtype) real ampl2(dtype),p2(2,dtype),rcylinder(dtype),deltaz,ampl3(dtype),p3(dtype) real volume(dbuff),avnum(dbuff),mu(dbuff),density(dbuff),kb(dbuff) real LZmin(dbuff),LZmax(dbuff),Rmin(dbuff),Rmax(dbuff) character*4 atnam(dtype), atnam2(dtype) logical*1 Qbufferbias(dtype) integer,allocatable :: nforward(:,:),nbackward(:,:) real,allocatable :: zcont(:) integer nprint,nanal,cntpts,svcntfq integer igr, nframe real dt,mcmax,bdmax real dids(5,datom),fact2a(dtype),fact1a(dtype),fact2pd,beta,diff0,ibeta,diffcutoff real erfpar,estaticf,evdwgd,riffac real ener,eelec,evdw,ememb,esrpmf,eefpot,enonbond,eintern real emembi,erfpari,estaticfi,evdwgdi,enonbondi,einterni real rsphe,rsphe2,lx,ly,lz,lx2p,ly2p,lz2p,lx2m,ly2m,lz2m,cx,cy,cz,iecx,iecy real, allocatable :: epp4(:),sgp2(:) real, allocatable :: c0(:),c1(:),c2(:),c3(:),c4(:) real cdie,rth,srpx,srpk,srpy,tvol real afact,kappa,ikappa !integer typat(datom) logical*1 Qsphere, Qecyl, Qbox logical*1 Qenergy, Qforces, Qbond, Qnonbond, Qmemb, Qgr, Qrho, Qrdna, Qprob logical*1 Qdiffuse, Qsrpmf, Qionpair, Qforceanapot, Qresintfor logical*1 Qenerprofile, Qprofile, Qsec, Qpres, Qpore, Qwarn, Qcountion, Qproxdiff logical*1,allocatable :: Qlj(:),Qsrpmfi(:),Qefpot(:) ! membrane parameters real voltage, thick2, zmemb, plength2, pcenter real czmax, czmin real tmemb, epsm, zmemb1,zmemb2, ceps real cecd contains function outbox(xi,yi,zi) implicit none real xi,yi,zi logical*1 outbox if (Qsphere) then if (((xi-cx)**2+(yi-cy)**2+(zi-cz)**2).gt.Rsphe2) then outbox=.true. else outbox=.false. endif elseif (Qecyl) then if ((((xi-cx)*iecx)**2+((yi-cy)*iecy)**2).gt.1.0.or.zi.lt.lz2m.or.zi.gt.lz2p) then outbox=.true. else outbox=.false. endif else if (xi.lt.lx2m.or.xi.gt.lx2p.or.yi.lt.ly2m.or.yi.gt.ly2p.or.zi.lt.lz2m.or.zi.gt.lz2p) then outbox=.true. else outbox=.false. endif endif end function end module
gpl-3.0
eiselekd/gcc
libgfortran/generated/_sqrt_c4.F90
9
1483
! Copyright (C) 2002-2017 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_COMPLEX_4) #ifdef HAVE_CSQRTF elemental function _gfortran_specific__sqrt_c4 (parm) complex (kind=4), intent (in) :: parm complex (kind=4) :: _gfortran_specific__sqrt_c4 _gfortran_specific__sqrt_c4 = sqrt (parm) end function #endif #endif
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/allocatable_scalar_13.f90
48
2175
! { dg-do run } ! { dg-options "-fdump-tree-original" } ! ! Test the fix for PR66079. The original problem was with the first ! allocate statement. The rest of this testcase fixes problems found ! whilst working on it! ! ! Reported by Damian Rouson <damian@sourceryinstitute.org> ! type subdata integer, allocatable :: b endtype ! block call newRealVec ! end block contains subroutine newRealVec type(subdata), allocatable :: d, e, f character(:), allocatable :: g, h, i character(8), allocatable :: j allocate(d,source=subdata(1)) ! memory was lost, now OK allocate(e,source=d) ! OK allocate(f,source=create (99)) ! memory was lost, now OK if (d%b .ne. 1) call abort if (e%b .ne. 1) call abort if (f%b .ne. 99) call abort allocate (g, source = greeting1("good day")) if (g .ne. "good day") call abort allocate (h, source = greeting2("hello")) if (h .ne. "hello") call abort allocate (i, source = greeting3("hiya!")) if (i .ne. "hiya!") call abort call greeting4 (j, "Goodbye ") ! Test that dummy arguments are OK if (j .ne. "Goodbye ") call abort end subroutine function create (arg) result(res) integer :: arg type(subdata), allocatable :: res, res1 allocate(res, res1, source = subdata(arg)) end function function greeting1 (arg) result(res) ! memory was lost, now OK character(*) :: arg Character(:), allocatable :: res allocate(res, source = arg) end function function greeting2 (arg) result(res) character(5) :: arg Character(:), allocatable :: res allocate(res, source = arg) end function function greeting3 (arg) result(res) character(5) :: arg Character(5), allocatable :: res, res1 allocate(res, res1, source = arg) ! Caused an ICE if (res1 .ne. res) call abort end function subroutine greeting4 (res, arg) character(8), intent(in) :: arg Character(8), allocatable, intent(out) :: res allocate(res, source = arg) ! Caused an ICE end subroutine end ! { dg-final { scan-tree-dump-times "builtin_malloc" 20 "original" } } ! { dg-final { scan-tree-dump-times "builtin_free" 21 "original" } }
gpl-2.0
Lrakulka/visp
3rdparty/lapackblas/lapack/dpotrf2.f
22
6318
*> \brief \b DPOTRF2 * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * RECURSIVE SUBROUTINE DPOTRF2( UPLO, N, A, LDA, INFO ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INFO, LDA, N * .. * .. Array Arguments .. * REAL A( LDA, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DPOTRF2 computes the Cholesky factorization of a real symmetric *> positive definite matrix A using the recursive algorithm. *> *> The factorization has the form *> A = U**T * U, if UPLO = 'U', or *> A = L * L**T, if UPLO = 'L', *> where U is an upper triangular matrix and L is lower triangular. *> *> This is the recursive version of the algorithm. It divides *> the matrix into four submatrices: *> *> [ A11 | A12 ] where A11 is n1 by n1 and A22 is n2 by n2 *> A = [ -----|----- ] with n1 = n/2 *> [ A21 | A22 ] n2 = n-n1 *> *> The subroutine calls itself to factor A11. Update and scale A21 *> or A12, update A22 then calls itself to factor A22. *> *> \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 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, if INFO = 0, the factor U or L from the Cholesky *> factorization A = U**T*U or A = L*L**T. *> \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 leading minor of order i is not *> positive definite, and the factorization could not be *> completed. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date December 2016 * *> \ingroup doublePOcomputational * * ===================================================================== RECURSIVE SUBROUTINE DPOTRF2( UPLO, N, A, LDA, 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, LDA, N * .. * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, ZERO PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) * .. * .. Local Scalars .. LOGICAL UPPER INTEGER N1, N2, IINFO * .. * .. External Functions .. LOGICAL LSAME, DISNAN EXTERNAL LSAME, DISNAN * .. * .. External Subroutines .. EXTERNAL DSYRK, DTRSM, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, SQRT * .. * .. 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( LDA.LT.MAX( 1, N ) ) THEN INFO = -4 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DPOTRF2', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN * * N=1 case * IF( N.EQ.1 ) THEN * * Test for non-positive-definiteness * IF( A( 1, 1 ).LE.ZERO.OR.DISNAN( A( 1, 1 ) ) ) THEN INFO = 1 RETURN END IF * * Factor * A( 1, 1 ) = SQRT( A( 1, 1 ) ) * * Use recursive code * ELSE N1 = N/2 N2 = N-N1 * * Factor A11 * CALL DPOTRF2( UPLO, N1, A( 1, 1 ), LDA, IINFO ) IF ( IINFO.NE.0 ) THEN INFO = IINFO RETURN END IF * * Compute the Cholesky factorization A = U**T*U * IF( UPPER ) THEN * * Update and scale A12 * CALL DTRSM( 'L', 'U', 'T', 'N', N1, N2, ONE, $ A( 1, 1 ), LDA, A( 1, N1+1 ), LDA ) * * Update and factor A22 * CALL DSYRK( UPLO, 'T', N2, N1, -ONE, A( 1, N1+1 ), LDA, $ ONE, A( N1+1, N1+1 ), LDA ) CALL DPOTRF2( UPLO, N2, A( N1+1, N1+1 ), LDA, IINFO ) IF ( IINFO.NE.0 ) THEN INFO = IINFO + N1 RETURN END IF * * Compute the Cholesky factorization A = L*L**T * ELSE * * Update and scale A21 * CALL DTRSM( 'R', 'L', 'T', 'N', N2, N1, ONE, $ A( 1, 1 ), LDA, A( N1+1, 1 ), LDA ) * * Update and factor A22 * CALL DSYRK( UPLO, 'N', N2, N1, -ONE, A( N1+1, 1 ), LDA, $ ONE, A( N1+1, N1+1 ), LDA ) CALL DPOTRF2( UPLO, N2, A( N1+1, N1+1 ), LDA, IINFO ) IF ( IINFO.NE.0 ) THEN INFO = IINFO + N1 RETURN END IF END IF END IF RETURN * * End of DPOTRF2 * END
gpl-2.0
seismology-RUB/ASKI
f90/eventStationVtkFile.f90
1
45433
!---------------------------------------------------------------------------- ! Copyright 2016 Florian Schumacher (Ruhr-Universitaet Bochum, Germany) ! ! This file is part of ASKI version 1.2. ! ! ASKI version 1.2 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 2 of the License, or ! (at your option) any later version. ! ! ASKI version 1.2 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. ! ! You should have received a copy of the GNU General Public License ! along with ASKI version 1.2. If not, see <http://www.gnu.org/licenses/>. !---------------------------------------------------------------------------- !> \brief module to write data on event,station coordinates or pahts to vkt output !! !! \details A vtk POLYDATA dataset consisting of event or station coordinate points !! as VERTICES along with any scalar POINT DATA living on the event or station coordinate !! points is written to binary or ascii vtk files. Alternatively, any data living on paths, !! defined as vtk LINES, can be written to vtk files. !! Complex data is handled as 2 component scalar float data. As an option, multiple !! files containing data w.r.t. some index (frequency, time) may be written having the same !! file base name followed by an index, in order to be considered by Paraview as a sequence of data. !! !! \author Florian Schumacher !! \date March 2013 ! module eventStationVtkFile ! use seismicEventList use seismicEvent use seismicNetwork use seismicStation use inversionGrid use fileUnitHandler use errorMessage ! implicit none ! ! by allowing calls to only certain routines, it is tried to assure that e.g. ! a file is open when writing to it, etc. (this way, certain security checks ! may be omitted, as unintended calls to auxilliary routines are forbidden) private public :: event_station_vtk_file,init,writeData,writeEvents,writeStations,writePaths,dealloc ! interface init module procedure initiateEventsVtkFile module procedure initiateStationsVtkFile module procedure initiatePathsVtkFile end interface init interface writeData module procedure writeRealDataEventStationVtkFile !module procedure writeRealVectorDataEventStationVtkFile ! for multidimensional data (suitable on paths e.g. for focussing coefficients per path, for all components), can be (1?),2,3 dimensional module procedure writeComplexDataEventStationVtkFile end interface writeData interface writeEvents; module procedure writeEventsVtkFile; end interface interface writeStations; module procedure writeStationsVtkFile; end interface interface writePaths; module procedure writePathsVtkFile; end interface interface dealloc; module procedure deallocateEventStationVtkFile; end interface ! !> \brief general file, geometry and cell information of vtk file type event_station_vtk_file private integer :: type_of_file = 0 !< 1 = events vtk file, 2 = stations vtk file, 3 = paths vtk file character (len=300) :: filename = '' !< (base) file name of vtk file (WITHOUT '.vtk') logical :: is_ascii !< indicating ascii (true) or binary (false) format of vtk file character (len=100) :: title = '' !< second line of vtk file integer :: nstat = 0 !< number of stations integer :: nev = 0 !< number of events integer :: npath = 0 !< number of paths integer :: npoint = 0 !< number of points (size of second dimension of array points) real, dimension(:,:), pointer :: points => null() !< POINTS geometry for POLYDATA VERTICES, coordinates of stations or events according to type_of_file integer, dimension(:,:), pointer :: lines => null() !< LINES geometry for POLYDATA LINES, array of point indices defining the paths end type event_station_vtk_file ! contains !------------------------------------------------------------------------ !> \brief initiate naming and geometry structure of events vtk file !! \details Define base filename, format (ascii /binary) and header title of vtk file !! and get set the respective point coordinates !! \param this event station vtk file !! \param events seismic event list !! \param invgrid inversion grid !! \param filename vtk base name (without '.vtk'). Will optionally be concatenated with a filename extension !! \param vtk_format 'ASCII' or 'BINARY' indicating the vtk file format !! \param vtk_title optional second line of vtk file (by default 'data on event coordinates') !! \param errmsg error message !! \return error message ! subroutine initiateEventsVtkFile(this,events,invgrid,filename,vtk_format,errmsg,vtk_title) ! incoming type (event_station_vtk_file) :: this type (seismic_event_list) :: events type (inversion_grid) :: invgrid character(len=*) :: filename,vtk_format character(len=*), optional :: vtk_title ! outgoing type (error_message) :: errmsg ! local character(len=21) :: myname = 'initiateEventsVtkFile' character (len=400) :: errstr type (seismic_event) :: event integer :: ipoint real, dimension(:), allocatable :: c1,c2,c3 ! call addTrace(errmsg,myname) if(trim(this%filename) /= '') call deallocateEventStationVtkFile(this) ! this%type_of_file = 1 this%nev = .nev.events if(this%nev .le. 0) then write(errstr,*) "there are ",this%nev," events in incoming event list. there must be a positive number of events" call add(errmsg,2,trim(errstr),myname) return end if if(trim(vtk_format) /= 'ASCII' .and. trim(vtk_format) /= 'BINARY') then errstr = "incoming vtk_format string '"//trim(vtk_format)//"' not valid, must be either 'ASCII' or 'BINARY'" call add(errmsg,2,trim(errstr),myname) return endif this%is_ascii = (trim(vtk_format) == 'ASCII') if(trim(filename) == '') then call add(errmsg,2,'incoming filename is empty string',myname) return else this%filename = trim(filename) endif if(present(vtk_title)) then this%title = trim(vtk_title) else this%title = 'data on event coordinates' endif ! allocate(c1(this%nev),c2(this%nev),c3(this%nev)) ipoint = 0 do while (nextEventSeismicEventList(events,event)) ipoint = ipoint + 1 c1(ipoint) = .slat.event c2(ipoint) = .slon.event c3(ipoint) = .sdepth.event end do ! while (nextEvent) ! call transformToVtkInversionGrid(invgrid,c1,c2,c3,'event',errmsg) if(.level.errmsg==2) goto 1 ! this%npoint = this%nev allocate(this%points(3,this%npoint)) this%points(1,:) = c1 this%points(2,:) = c2 this%points(3,:) = c3 ! 1 if(allocated(c1)) deallocate(c1) if(allocated(c2)) deallocate(c2) if(allocated(c3)) deallocate(c3) end subroutine initiateEventsVtkFile !------------------------------------------------------------------------ !> \brief initiate naming and geometry structure of stations vtk file !! \details Define base filename, format (ascii /binary) and header title of vtk file !! and get set the respective point coordinates !! \param this event station vtk file !! \param stations seismic network !! \param invgrid inversion grid !! \param filename vtk base name (without '.vtk'). Will optionally be concatenated with a filename extension !! \param vtk_format 'ASCII' or 'BINARY' indicating the vtk file format !! \param vtk_title optional second line of vtk file (by default 'data on event coordinates') !! \param errmsg error message !! \return error message ! subroutine initiateStationsVtkFile(this,stations,invgrid,filename,vtk_format,errmsg,vtk_title) ! incoming type (event_station_vtk_file) :: this type (seismic_network) :: stations type (inversion_grid) :: invgrid character(len=*) :: filename,vtk_format character(len=*), optional :: vtk_title ! outgoing type (error_message) :: errmsg ! local character(len=21) :: myname = 'initiateEventsVtkFile' character (len=400) :: errstr type (seismic_station) :: station integer :: ipoint real, dimension(:), allocatable :: c1,c2,c3 ! call addTrace(errmsg,myname) if(trim(this%filename) /= '') call deallocateEventStationVtkFile(this) ! this%type_of_file = 2 this%nstat = .nstat.stations if(this%nstat .le. 0) then write(errstr,*) "there are ",this%nstat," stations in incoming network. there must be a positive number of stations" call add(errmsg,2,trim(errstr),myname) return end if if(trim(vtk_format) /= 'ASCII' .and. trim(vtk_format) /= 'BINARY') then errstr = "incoming vtk_format string '"//trim(vtk_format)//"' not valid, must be either 'ASCII' or 'BINARY'" call add(errmsg,2,trim(errstr),myname) return endif this%is_ascii = (trim(vtk_format) == 'ASCII') if(trim(filename) == '') then call add(errmsg,2,'incoming filename is empty string',myname) return else this%filename = trim(filename) endif if(present(vtk_title)) then this%title = trim(vtk_title) else this%title = 'data on station coordinates' endif ! allocate(c1(this%nstat),c2(this%nstat),c3(this%nstat)) ipoint = 0 do while (nextStationSeismicNetwork(stations,station)) ipoint = ipoint + 1 c1(ipoint) = .lat.station c2(ipoint) = .lon.station c3(ipoint) = .alt.station end do ! while (nextStation) ! call transformToVtkInversionGrid(invgrid,c1,c2,c3,'station',errmsg) if(.level.errmsg==2) goto 1 ! this%npoint = this%nstat allocate(this%points(3,this%npoint)) this%points(1,:) = c1 this%points(2,:) = c2 this%points(3,:) = c3 ! 1 if(allocated(c1)) deallocate(c1) if(allocated(c2)) deallocate(c2) if(allocated(c3)) deallocate(c3) end subroutine initiateStationsVtkFile !------------------------------------------------------------------------ !> \brief initiate naming and geometry structure of paths vtk file !! \details Define base filename, format (ascii /binary) and header title of vtk file !! and get set the respective point coordinates !! \param this event station vtk file !! \param events seismic event list !! \param stations seismic network !! \param paths array of dimension(2,npath) which contains event IDs (first entry) and station names (second entry) !! \param invgrid inversion grid !! \param filename vtk base name (without '.vtk'). Will optionally be concatenated with a filename extension !! \param vtk_format 'ASCII' or 'BINARY' indicating the vtk file format !! \param vtk_title optional second line of vtk file (by default 'data on event coordinates') !! \param errmsg error message !! \return error message ! subroutine initiatePathsVtkFile(this,events,stations,paths,invgrid,filename,vtk_format,errmsg,vtk_title) ! incoming type (event_station_vtk_file) :: this type (seismic_event_list) :: events type (seismic_network) :: stations character(len=*), dimension(:,:) :: paths type (inversion_grid) :: invgrid character(len=*) :: filename,vtk_format character(len=*), optional :: vtk_title ! outgoing type (error_message) :: errmsg ! local character(len=20) :: myname = 'initiatePathsVtkFile' character (len=400) :: errstr type (error_message) :: errmsg2 type (seismic_event) :: event type (seismic_station) :: station integer :: ipoint,ipath,nev,iev,nstat,istat real, dimension(:), allocatable :: ev_c1,ev_c2,ev_c3,stat_c1,stat_c2,stat_c3 integer, dimension(:), allocatable :: ipoint_of_station,ipoint_of_event real, dimension(:,:), pointer :: points_tmp ! nullify(points_tmp) call addTrace(errmsg,myname) if(trim(this%filename) /= '') call deallocateEventStationVtkFile(this) ! this%type_of_file = 3 this%npath = size(paths,2) if(this%npath .le. 0 .or. size(paths,1)/=2) then write(errstr,*) "there are ",this%npath," paths in incoming path array (must be positive), and ",size(paths,1),& " names per path (must be 2: 'eventID','station name' pair)" call add(errmsg,2,trim(errstr),myname) return end if if(trim(vtk_format) /= 'ASCII' .and. trim(vtk_format) /= 'BINARY') then errstr = "incoming vtk_format string '"//trim(vtk_format)//"' not valid, must be either 'ASCII' or 'BINARY'" call add(errmsg,2,trim(errstr),myname) return endif this%is_ascii = (trim(vtk_format) == 'ASCII') if(trim(filename) == '') then call add(errmsg,2,'incoming filename is empty string',myname) return else this%filename = trim(filename) endif if(present(vtk_title)) then this%title = trim(vtk_title) else this%title = 'data on paths' endif ! nev = .nev.events if(nev .le. 0) then write(errstr,*) "there are ",nev," events in incoming event list. there must be a positive number of events" call add(errmsg,2,trim(errstr),myname) return end if nstat = .nstat.stations if(nstat .le. 0) then write(errstr,*) "there are ",nstat," stations in incoming network. there must be a positive number of stations" call add(errmsg,2,trim(errstr),myname) return end if ! ! FIRST TRANSFORM ALL STATION AND EVENT COORDINATE TO VTK FRAME BY INVERSION GRID MODULE ! allocate(stat_c1(nstat),stat_c2(nstat),stat_c3(nstat)) ipoint = 0 do while (nextStationSeismicNetwork(stations,station)) ipoint = ipoint + 1 stat_c1(ipoint) = .lat.station stat_c2(ipoint) = .lon.station stat_c3(ipoint) = .alt.station end do ! while (nextStation) ! call transformToVtkInversionGrid(invgrid,stat_c1,stat_c2,stat_c3,'station',errmsg) if(.level.errmsg==2) goto 1 ! allocate(ev_c1(nev),ev_c2(nev),ev_c3(nev)) ipoint = 0 do while (nextEventSeismicEventList(events,event)) ipoint = ipoint + 1 ev_c1(ipoint) = .slat.event ev_c2(ipoint) = .slon.event ev_c3(ipoint) = .sdepth.event end do ! while (nextEvent) ! call transformToVtkInversionGrid(invgrid,ev_c1,ev_c2,ev_c3,'event',errmsg) if(.level.errmsg==2) goto 1 ! ! SECONDLY, SELECT THOSE STATIONS AND EVENTS THAT ARE CONTAINED IN THE PATHS AT ALL ! AND STORE THEIR COORDINATES IN ARRAY THIS%POINTS. REMEMBER THEIR POINT INDICES ! IN ORDER TO CORRECTLY CONNECT THE LINES GEOMETRY BELOW ! allocate(points_tmp(3,nstat+nev)) ipoint = 0 ! ! first iterate through the events allocate(ipoint_of_event(nev)); ipoint_of_event = -1 iev = 0 do while (nextEventSeismicEventList(events,event)) iev = iev + 1 if(any(paths(1,:)==.evid.event)) then ipoint = ipoint + 1 ! add the event coordinates to the (temporary) point array points_tmp(:,ipoint) = (/ ev_c1(iev),ev_c2(iev),ev_c3(iev) /) ! connect this point to the event index in the event list ipoint_of_event(iev) = ipoint end if end do ! then iterate through the stations, keep the value of ipoint!! (simply continue) allocate(ipoint_of_station(nstat)); ipoint_of_station = -1 istat = 0 do while (nextStationSeismicNetwork(stations,station)) istat = istat + 1 if(any(paths(2,:)==.staname.station)) then ipoint = ipoint + 1 ! add the station coordinates to the (temporary) point array points_tmp(:,ipoint) = (/ stat_c1(istat),stat_c2(istat),stat_c3(istat) /) ! connect this point to the event index in the event list ipoint_of_station(istat) = ipoint end if end do ! finally define the actual points array this%points if(ipoint == nstat+nev) then this%npoint = nstat+nev this%points => points_tmp nullify(points_tmp) else this%npoint = ipoint allocate(this%points(3,this%npoint)) this%points = points_tmp(:,1:ipoint) deallocate(points_tmp) end if ! ! THIRDLY, DEFINE THE LINES GEOMETRY: FOR EACH GIVEN PATH CONNECT THE TWO POINTS CORRESPONDING TO ! THE RESPECTIVE STATION AND EVENT ! allocate(this%lines(3,this%npath)) this%lines(1,:) = 2 ! always have 2 point indices following defining a line do ipath = 1,this%npath ! first search for the event index of this event in the incoming event list errmsg2 = searchEventidSeismicEventList(events,paths(1,ipath),iev=iev) if(.level.errmsg2 == 2) then write(errstr,*) "event ID '"//trim(paths(1,ipath))//"' of ",ipath,"'th path was not found in event list "//& "(the corresponding station name of this path is '"//trim(paths(2,ipath))//"'" call add(errmsg,2,trim(errstr),myname) call deallocateEventStationVtkFile(this) goto 1 end if call dealloc(errmsg2) ! ! define geometry connectivity array LINE for this path, event coordinates are first point this%lines(2,ipath) = ipoint_of_event(iev)-1 ! ! then search for the station index of this station in the incoming station list errmsg2 = searchStationNameSeismicNetwork(stations,paths(2,ipath),istat=istat) if(.level.errmsg2 == 2) then write(errstr,*) "station name '"//trim(paths(2,ipath))//"' of ",ipath,"'th path was not found in station list"//& "(the corresponding event ID of this path is '"//trim(paths(1,ipath))//"'" call add(errmsg,2,trim(errstr),myname) call deallocateEventStationVtkFile(this) goto 1 end if call dealloc(errmsg2) ! ! define geometry connectivity array LINE for this path, station coordinates are second point this%lines(3,ipath) = ipoint_of_station(istat)-1 end do ! ipath ! 1 if(allocated(ev_c1)) deallocate(ev_c1) if(allocated(ev_c2)) deallocate(ev_c2) if(allocated(ev_c3)) deallocate(ev_c3) if(allocated(stat_c1)) deallocate(stat_c1) if(allocated(stat_c2)) deallocate(stat_c2) if(allocated(stat_c3)) deallocate(stat_c3) if(allocated(ipoint_of_station)) deallocate(ipoint_of_station) if(allocated(ipoint_of_event)) deallocate(ipoint_of_event) end subroutine initiatePathsVtkFile !------------------------------------------------------------------------ !> \brief open vtk file to write !! \param this event station vtk file !! \param lu file unit !! \param file_index optional index of file (will be appended to filename base) !! \param overwrite_in optional logical to indicate behaviour in case file exists, by default, no overwrite !! \param errmsg error message !! \return error message ! subroutine openEventStationVtkFile(this,lu,filename_extension,errmsg,overwrite_in) ! incoming type (event_station_vtk_file) :: this integer :: lu character (len=*) :: filename_extension logical, optional :: overwrite_in ! outgoing type (error_message) :: errmsg ! local character(len=23) :: myname = 'openEventStationVtkFile' character (len=400) :: vtk_file integer :: ios logical :: overwrite,file_exists character (len=7) :: open_status ! call addTrace(errmsg,myname) ! if(present(overwrite_in)) then overwrite = overwrite_in else ! by default, do not overwrite overwrite = .False. endif ! ! create filename from basename and (possibly empty) filename extension plus '.vtk' extension vtk_file = trim(this%filename)//trim(filename_extension)//'.vtk' ! ! check if file exists, set open_status as required inquire(file=trim(vtk_file),exist=file_exists) if(file_exists) then if(overwrite) then ! give warning and replace existing file call add(errmsg,1,"file '"//trim(vtk_file)//"' exists and will be overwritten",myname) open_status = 'REPLACE' else ! overwrite ! raise error call add(errmsg,2,"file '"//trim(vtk_file)//"' exists. Please rename or indicate 'overwrite'",myname) return endif ! overwrite else ! file_exists open_status = 'NEW' endif ! file_exists ! ! open file. According to value of open_status, an existing file is overwritten if(this%is_ascii) then open(unit=lu,file=trim(vtk_file),form='FORMATTED',status=trim(open_status),action='WRITE',iostat=ios) if(ios/=0) call add(errmsg,2,"could not open ascii file '"//trim(vtk_file)//"'to write",myname) else ! this%is_ascii open(unit=lu,file=trim(vtk_file),form='UNFORMATTED',access='STREAM',status=trim(open_status),action='WRITE',& convert='BIG_ENDIAN',iostat=ios) if(ios/=0) call add(errmsg,2,"could not open binary file '"//trim(vtk_file)//"'to write",myname) endif ! this%is_ascii end subroutine openEventStationVtkFile !------------------------------------------------------------------------ !> \brief write vtk header and points structure to open vtk file !! \param this event station vtk file !! \param lu file unit of file (MUST BE OPENED ALREADY!) !! \param errmsg error message !! \return error message ! subroutine writeHeaderPointsEventStationVtkFile(this,lu,errmsg) type (event_station_vtk_file) :: this integer :: lu type(error_message) :: errmsg ! local integer :: ios character(len=38) :: myname = 'writeHeaderGeometryEventStationVtkFile' character (len=500) :: string character (len=1), parameter :: eol_char = char(10) logical :: err ! call addTrace(errmsg,myname) ! ! remember with err if there was an error somewhere err = .false. if(this%is_ascii) then ! vkt Header write(unit=lu,fmt='(a)',iostat=ios) '# vtk DataFile Version 3.1' ; err = err.or.(ios/=0) write(unit=lu,fmt='(a)',iostat=ios) trim(this%title) ; err = err.or.(ios/=0) write(unit=lu,fmt='(a)',iostat=ios) 'ASCII' ; err = err.or.(ios/=0) write(unit=lu,fmt='(a)',iostat=ios) 'DATASET POLYDATA' ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing vtk Header',myname) return endif ! POINTS write(unit=lu,fmt='(a,i12,a)',iostat=ios) 'POINTS ',this%npoint,' float' ; err = err.or.(ios/=0) write(unit=lu,fmt='(3e14.6e2)',iostat=ios) this%points ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing POINTS',myname) return endif else ! this%is_ascii ! vtk Header write(unit=lu,iostat=ios) '# vtk DataFile Version 3.1'//eol_char ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) trim(this%title)//eol_char ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) 'BINARY'//eol_char ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) 'DATASET POLYDATA'//eol_char ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing vtk Header',myname) return endif ! POINTS write(string,'(a,i12,a)',iostat=ios) 'POINTS ',this%npoint,' float' write(unit=lu,iostat=ios) trim(string)//eol_char ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) this%points ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) eol_char ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing POINTS',myname) return endif endif ! this%is_ascii end subroutine writeHeaderPointsEventStationVtkFile !------------------------------------------------------------------------ !> \brief write POLYDATA VERTICES structure (one vertex for each defined point) to open vtk file !! \param this event station vtk file !! \param lu file unit of file (MUST BE OPENED ALREADY!) !! \param errmsg error message !! \return error message ! subroutine writeVerticesEventStationVtkFile(this,lu,errmsg) type (event_station_vtk_file) :: this integer :: lu type(error_message) :: errmsg ! local integer :: ios,i character(len=32) :: myname = 'writeVerticesEventStationVtkFile' character (len=500) :: string character (len=1), parameter :: eol_char = char(10) logical :: err ! call addTrace(errmsg,myname) ! ! remember with err if there was an error somewhere err = .false. if(this%is_ascii) then ! VERTICES write(unit=lu,fmt='(a,2i12)',iostat=ios)'VERTICES ',this%npoint,2*this%npoint ; err = err.or.(ios/=0) write(unit=lu,fmt='(i12)',iostat=ios) (/ ((/1,i-1/),i=1,this%npoint) /) ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing VERTICES',myname) return endif else ! this%is_ascii ! VERTICES write(string,'(a,2i12)',iostat=ios)'VERTICES ',this%npoint,2*this%npoint write(unit=lu,iostat=ios) trim(string)//eol_char ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) (/ ((/1,i-1/),i=1,this%npoint) /) ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) eol_char ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing VERTICES',myname) return endif endif ! this%is_ascii end subroutine writeVerticesEventStationVtkFile !------------------------------------------------------------------------ !> \brief write POLYDATA LINES structure (basically content of this%path array) to open vtk file !! \param this event station vtk file !! \param lu file unit of file (MUST BE OPENED ALREADY!) !! \param errmsg error message !! \return error message ! subroutine writeLinesEventStationVtkFile(this,lu,errmsg) type (event_station_vtk_file) :: this integer :: lu type(error_message) :: errmsg ! local integer :: ios character(len=29) :: myname = 'writeLinesEventStationVtkFile' character (len=500) :: string character (len=1), parameter :: eol_char = char(10) logical :: err ! call addTrace(errmsg,myname) ! ! remember with err if there was an error somewhere err = .false. if(this%is_ascii) then ! LINES write(unit=lu,fmt='(a,2i12)',iostat=ios)'LINES ',this%npath,size(this%lines) ; err = err.or.(ios/=0) write(unit=lu,fmt='(3i12)',iostat=ios) this%lines ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing LINES',myname) return endif else ! this%is_ascii ! LINES write(string,'(a,2i12)',iostat=ios)'LINES ',this%npath,size(this%lines) write(unit=lu,iostat=ios) trim(string)//eol_char ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) this%lines ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) eol_char ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing LINES',myname) return endif endif ! this%is_ascii end subroutine writeLinesEventStationVtkFile !------------------------------------------------------------------------ !> \brief open file, write header and geometry and one component float scalar valued point (cell) data to vtk file !! \details The number of incoming real data values must match the number of points (i.e. this%nev,this%nstat, !! respectively) or number of cells (lines, i.e. this%npath), dependent on this%type_of_file, !! because here scalar POINT_DATA (CELL_DATA) (i.e. one scalar value per point (cell)) !! is added to the vtk file. !! First a file is opened calling openEventStationVtkFile and header and point and vertex (lines) !! geometry information is written to that file calling writeHeaderPointsEventStationVtkFile, !! writeVerticesEventStationVtkFile,writeLinesEventStationVtkFile. !! Then the incoming data values are added to the vtk file as scalar valued float point data. !! \param this event station vtk file !! \param lu file unit !! \param data data values to be added to vtk file !! \param data_name optional name of the data (by default 'data') !! \param file_index optional index of file (will be appended to filename base) !! \param overwrite_in optional logical to indicate behaviour in case file exists. By default, no overwrite !! \param errmsg error message !! \return error message ! subroutine writeRealDataEventStationVtkFile(this,lu,data,errmsg,data_name,file_index,overwrite) ! incoming type (event_station_vtk_file) :: this integer :: lu real, dimension(:) :: data character (len=*), optional :: data_name integer, optional :: file_index logical, optional :: overwrite ! outgoing type (error_message) :: errmsg ! local character (len=400) :: errstr character(len=32) :: myname = 'writeRealDataEventStationVtkFile' character (len=500) :: string character (len=100) :: filename_extension character (len=10) :: dataset_attribute ! either "POINT_DATA", or "CELL_DATA" character (len=1), parameter :: eol_char = char(10) integer :: ios,ndata logical :: err ! call addTrace(errmsg,myname) ! ! check if object is initiated already if(this%filename== '') then call add(errmsg,2,'it appears that this event_station_vtk_file object is not initiated yet',myname) return endif ! ! check if number of incoming data is correct, depending on type of file select case(this%type_of_file) case(1) ndata = this%nev write(errstr,*) 'number of data ( =',size(data),') does not match number of events ( =',this%nev,')' case(2) ndata = this%nstat write(errstr,*) 'number of data ( =',size(data),') does not match number of stations ( =',this%nstat,')' case(3) ndata = this%npath write(errstr,*) 'number of data ( =',size(data),') does not match number of paths ( =',this%npath,')' end select if(size(data) /= ndata) then call add(errmsg,2,trim(errstr),myname) return endif ! if(present(file_index)) then write(filename_extension,"('_',i6.6)") file_index else filename_extension = '' endif ! open vtk file to write call openEventStationVtkFile(this,lu,trim(filename_extension),errmsg,overwrite) if(.level.errmsg == 2) then close(lu) return endif ! ! write header and points information to file call writeHeaderPointsEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif ! ! write vertices or lines to file, depending on type of file select case(this%type_of_file) case(1,2) dataset_attribute = 'POINT_DATA' call writeVerticesEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif case(3) dataset_attribute = 'CELL_DATA' call writeLinesEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif end select ! ! write data to file err = .false. if(this%is_ascii) then write(unit=lu,fmt='(a,i12)',iostat=ios) trim(dataset_attribute)//' ',ndata ; err = err.or.(ios/=0) if(present(data_name)) then string = 'SCALARS '//trim(data_name)//' float 1' else string = 'SCALARS data float 1' endif write(unit=lu,fmt='(a)',iostat=ios) trim(string) ; err = err.or.(ios/=0) write(unit=lu,fmt='(a)',iostat=ios) 'LOOKUP_TABLE default' ; err = err.or.(ios/=0) write(unit=lu,fmt='(e14.6e2)', iostat=ios) data ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing POINT_DATA',myname) close(lu) return endif else write(string,fmt='(a,i12)',iostat=ios) trim(dataset_attribute)//' ',ndata write(unit=lu,iostat=ios) trim(string)//eol_char ; err = err.or.(ios/=0) if(present(data_name)) then string = 'SCALARS '//trim(data_name)//' float 1' else string = 'SCALARS data float 1' endif write(unit=lu,iostat=ios) trim(string)//eol_char ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) 'LOOKUP_TABLE default'//eol_char ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) data ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) eol_char ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing POINT_DATA',myname) close(lu) return endif endif ! ! close file close(lu) end subroutine writeRealDataEventStationVtkFile !------------------------------------------------------------------------ !> \brief open file, write header and geometry and two component scalar valued float data to vtk file !! \details The number of incoming complex data values must match the number of points (i.e. this%nev,this%nstat, !! respectively) or number of cells (lines, i.e. this%npath), dependent on this%type_of_file, !! because here scalar POINT_DATA (CELL_DATA) (i.e. one scalar value per point (cell)) !! is added to the vtk file. !! First a file is opened calling openEventStationVtkFile and header and point and vertex (lines) !! geometry information is written to that file calling writeHeaderPointsEventStationVtkFile, !! writeVerticesEventStationVtkFile,writeLinesEventStationVtkFile. !! Then the incoming data values are added to the vtk file as two component scalar valued float data. !! \param this event station vtk file !! \param lu file unit !! \param data data values to be added to vtk file !! \param data_name optional name of the data (by default 'data') !! \param file_index optional index of file (will be appended to filename base) !! \param overwrite_in optional logical to indicate behaviour in case file exists. By default, no overwrite !! \param errmsg error message !! \return error message ! subroutine writeComplexDataEventStationVtkFile(this,lu,data,errmsg,data_name,file_index,overwrite) ! incoming type (event_station_vtk_file) :: this integer :: lu complex, dimension(:) :: data character (len=*), optional :: data_name integer, optional :: file_index logical, optional :: overwrite ! outgoing type (error_message) :: errmsg ! local character (len=400) :: errstr character(len=35) :: myname = 'writeComplexDataEventStationVtkFile' character (len=500) :: string character (len=100) :: filename_extension character (len=10) :: dataset_attribute ! either "POINT_DATA", or "CELL_DATA" character (len=1), parameter :: eol_char = char(10) integer :: ios,ndata logical :: err ! call addTrace(errmsg,myname) ! ! check if object is initiated already if(this%filename== '') then call add(errmsg,2,'it appears that this event_station_vtk_file object is not initiated yet',myname) return endif ! ! check if number of incoming data is correct, depending on type of file select case(this%type_of_file) case(1) ndata = this%nev write(errstr,*) 'number of data ( =',size(data),') does not match number of events ( =',this%nev,')' case(2) ndata = this%nstat write(errstr,*) 'number of data ( =',size(data),') does not match number of stations ( =',this%nstat,')' case(3) ndata = this%npath write(errstr,*) 'number of data ( =',size(data),') does not match number of paths ( =',this%npath,')' end select if(size(data) /= ndata) then call add(errmsg,2,trim(errstr),myname) return endif ! if(present(file_index)) then write(filename_extension,"('_',i6.6)") file_index else filename_extension = '' endif ! open vtk file to write call openEventStationVtkFile(this,lu,trim(filename_extension),errmsg,overwrite) if(.level.errmsg == 2) then close(lu) return endif ! ! write header and points information to file call writeHeaderPointsEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif ! ! write vertices or lines to file, depending on type of file select case(this%type_of_file) case(1,2) dataset_attribute = 'POINT_DATA' call writeVerticesEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif case(3) dataset_attribute = 'CELL_DATA' call writeLinesEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif end select ! ! write data to file err = .false. if(this%is_ascii) then write(unit=lu,fmt='(a,i12)',iostat=ios) trim(dataset_attribute)//' ',ndata ; err = err.or.(ios/=0) if(present(data_name)) then string = 'SCALARS '//trim(data_name)//' float 2' else string = 'SCALARS data float 2' endif write(unit=lu,fmt='(a)',iostat=ios) trim(string) ; err = err.or.(ios/=0) write(unit=lu,fmt='(a)',iostat=ios) 'LOOKUP_TABLE default' ; err = err.or.(ios/=0) write(unit=lu,fmt='(2e14.6e2)', iostat=ios) data ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing POINT_DATA',myname) close(lu) return endif else write(string,fmt='(a,i12)',iostat=ios) trim(dataset_attribute)//' ',ndata write(unit=lu,iostat=ios) trim(string)//eol_char ; err = err.or.(ios/=0) if(present(data_name)) then string = 'SCALARS '//trim(data_name)//' float 1' else string = 'SCALARS data float 1' endif write(unit=lu,iostat=ios) trim(string)//eol_char ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) 'LOOKUP_TABLE default'//eol_char ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) data ; err = err.or.(ios/=0) write(unit=lu,iostat=ios) eol_char ; err = err.or.(ios/=0) if(err) then ! if any of the above ios were /= 0 call add(errmsg,2,'there was an error writing POINT_DATA',myname) close(lu) return endif endif ! ! close file close(lu) end subroutine writeComplexDataEventStationVtkFile !------------------------------------------------------------------------ !> \brief open file, write only header and geometry without data to vtk file !! \param this event station vtk file !! \param lu file unit !! \param overwrite_in optional logical to indicate behaviour in case file exists. By default, no overwrite !! \param errmsg error message !! \return error message ! subroutine writeEventsVtkFile(this,lu,errmsg,overwrite) ! incoming type (event_station_vtk_file) :: this integer :: lu logical, optional :: overwrite ! outgoing type (error_message) :: errmsg ! local character(len=17) :: myname = 'writeEventVtkFile' character (len=1), parameter :: eol_char = char(10) ! call addTrace(errmsg,myname) ! ! check if object is initiated already if(this%filename== '') then call add(errmsg,2,'it appears that this event_station_vtk_file object is not initiated yet',myname) return endif if(this%type_of_file /= 1) then call add(errmsg,2,'it appears that this event_station_vtk_file object was not initiated with event information',myname) return end if ! ! open vtk file to write call openEventStationVtkFile(this,lu,'_events',errmsg,overwrite) if(.level.errmsg == 2) then close(lu) return endif ! ! write header and points information to file call writeHeaderPointsEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif ! ! write vertices to file call writeVerticesEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif ! ! close file close(lu) end subroutine writeEventsVtkFile !------------------------------------------------------------------------ !> \brief open file, write only header and geometry without data to vtk file !! \param this event station vtk file !! \param lu file unit !! \param overwrite_in optional logical to indicate behaviour in case file exists. By default, no overwrite !! \param errmsg error message !! \return error message ! subroutine writeStationsVtkFile(this,lu,errmsg,overwrite) ! incoming type (event_station_vtk_file) :: this integer :: lu logical, optional :: overwrite ! outgoing type (error_message) :: errmsg ! local character(len=20) :: myname = 'writeStationsVtkFile' character (len=1), parameter :: eol_char = char(10) ! call addTrace(errmsg,myname) ! ! check if object is initiated already if(this%filename== '') then call add(errmsg,2,'it appears that this event_station_vtk_file object is not initiated yet',myname) return endif if(this%type_of_file /= 2) then call add(errmsg,2,'it appears that this event_station_vtk_file object was not initiated with station information',myname) return end if ! ! open vtk file to write call openEventStationVtkFile(this,lu,'_stations',errmsg,overwrite) if(.level.errmsg == 2) then close(lu) return endif ! ! write header and points information to file call writeHeaderPointsEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif ! ! write vertices to file call writeVerticesEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif ! ! close file close(lu) end subroutine writeStationsVtkFile !------------------------------------------------------------------------ !> \brief open file, write only header and geometry without data to vtk file !! \param this event station vtk file !! \param lu file unit !! \param overwrite_in optional logical to indicate behaviour in case file exists. By default, no overwrite !! \param errmsg error message !! \return error message ! subroutine writePathsVtkFile(this,lu,errmsg,overwrite) ! incoming type (event_station_vtk_file) :: this integer :: lu logical, optional :: overwrite ! outgoing type (error_message) :: errmsg ! local character(len=17) :: myname = 'writePathsVtkFile' character (len=1), parameter :: eol_char = char(10) ! call addTrace(errmsg,myname) ! ! check if object is initiated already if(this%filename== '') then call add(errmsg,2,'it appears that this event_station_vtk_file object is not initiated yet',myname) return endif if(this%type_of_file /= 3) then call add(errmsg,2,'it appears that this event_station_vtk_file object was not initiated with path information',myname) return end if ! ! open vtk file to write call openEventStationVtkFile(this,lu,'_paths',errmsg,overwrite) if(.level.errmsg == 2) then close(lu) return endif ! ! write header and points information to file call writeHeaderPointsEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif ! ! write LINES to file call writeLinesEventStationVtkFile(this,lu,errmsg) if(.level.errmsg == 2) then close(lu) return endif ! ! close file close(lu) end subroutine writePathsVtkFile !------------------------------------------------------------------------ !> \brief deallocate object !! \param this event_station_vtk_file object ! subroutine deallocateEventStationVtkFile(this) type (event_station_vtk_file) :: this this%type_of_file = 0 this%filename = '' this%title = '' this%nev = 0 this%nstat = 0 this%npath = 0 this%npoint = 0 if(associated(this%points)) deallocate(this%points) if(associated(this%lines)) deallocate(this%lines) end subroutine deallocateEventStationVtkFile ! end module eventStationVtkFile
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/c_by_val_5.f90
107
1516
! { dg-do run } ! Overwrite -pedantic setting: ! { dg-options "-Wall" } ! ! Tests the fix for PR31668, in which %VAL was rejected for ! module and internal procedures. ! subroutine bmp_write(nx) implicit none integer, value :: nx if(nx /= 10) call abort() nx = 11 if(nx /= 11) call abort() end subroutine bmp_write module x implicit none ! The following interface does in principle ! not match the procedure (missing VALUE attribute) ! However, this occures in real-world code calling ! C routines where an interface is better than ! "external" only. interface subroutine bmp_write(nx) integer, value :: nx end subroutine bmp_write end interface contains SUBROUTINE Grid2BMP(NX) INTEGER, INTENT(IN) :: NX if(nx /= 10) call abort() call bmp_write(%val(nx)) if(nx /= 10) call abort() END SUBROUTINE Grid2BMP END module x ! The following test is possible and ! accepted by other compilers, but ! does not make much sense. ! Either one uses VALUE then %VAL is ! not needed or the function will give ! wrong results. ! !subroutine test() ! implicit none ! integer :: n ! n = 5 ! if(n /= 5) call abort() ! call test2(%VAL(n)) ! if(n /= 5) call abort() ! contains ! subroutine test2(a) ! integer, value :: a ! if(a /= 5) call abort() ! a = 2 ! if(a /= 2) call abort() ! end subroutine test2 !end subroutine test program main use x implicit none ! external test call Grid2BMP(10) ! call test() end program main
gpl-2.0
pablodebiase/bromoc-e_suite
bromoc-e/src/angdih.f90
1
1566
! BROMOC-E ! Electrodiffusion, Gran Canonical Monte Carlo, Brownian,Dynamics ! and Coarse Grain Model DNA Simulation Program. ! Copyright (C) 2014 Pablo M. De Biase (pablodebiase@gmail.com) ! ! This program 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. ! ! This program 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. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. real function angdih(vecR) implicit none !Input real vecR(3,3) !Local variables real vecN(3,2), R2, sinphi, cosphi integer i vecN(1,1) = vecR(2,1)*vecR(3,2) - vecR(3,1)*vecR(2,2) vecN(2,1) = vecR(3,1)*vecR(1,2) - vecR(1,1)*vecR(3,2) vecN(3,1) = vecR(1,1)*vecR(2,2) - vecR(2,1)*vecR(1,2) vecN(1,2) = vecR(2,2)*vecR(3,3) - vecR(3,2)*vecR(2,3) vecN(2,2) = vecR(3,2)*vecR(1,3) - vecR(1,2)*vecR(3,3) vecN(3,2) = vecR(1,2)*vecR(2,3) - vecR(2,2)*vecR(1,3) R2 = sqrt(vecR(1,2)**2+vecR(2,2)**2+vecR(3,2)**2) sinphi = 0.0 cosphi = 0.0 do i = 1, 3 sinphi = sinphi + vecR(i,1)*vecN(i,2) cosphi = cosphi + vecN(i,1)*vecN(i,2) enddo sinphi = R2*sinphi angdih = atan2(sinphi,cosphi) return end function
gpl-3.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/use_iso_c_binding.f90
155
1509
! { dg-do compile } ! this is to simply test that the various ways the use statement can ! appear are handled by the compiler, since i did a special treatment ! of the intrinsic iso_c_binding module. note: if the user doesn't ! provide the 'intrinsic' keyword, the compiler will check for a user ! provided module by the name of iso_c_binding before using the ! intrinsic one. --Rickett, 09.26.06 module use_stmt_0 ! this is an error because c_ptr_2 does not exist use, intrinsic :: iso_c_binding, only: c_ptr_2 ! { dg-error "Symbol 'c_ptr_2' referenced at \\(1\\) not found" } end module use_stmt_0 module use_stmt_1 ! this is an error because c_ptr_2 does not exist use iso_c_binding, only: c_ptr_2 ! { dg-error "Symbol 'c_ptr_2' referenced at \\(1\\) not found" } end module use_stmt_1 module use_stmt_2 ! works fine use, intrinsic :: iso_c_binding, only: c_ptr end module use_stmt_2 module use_stmt_3 ! works fine use iso_c_binding, only: c_ptr end module use_stmt_3 module use_stmt_4 ! works fine use, intrinsic :: iso_c_binding end module use_stmt_4 module use_stmt_5 ! works fine use iso_c_binding end module use_stmt_5 module use_stmt_6 ! hmm, is this an error? if so, it's not being caught... ! --Rickett, 09.13.06 use, intrinsic :: iso_c_binding, only: c_int, c_int end module use_stmt_6 module use_stmt_7 ! hmm, is this an error? if so, it's not being caught... ! --Rickett, 09.13.06 use iso_c_binding, only: c_int, c_int end module use_stmt_7
gpl-2.0
trankmichael/scipy
scipy/interpolate/fitpack/pardeu.f
91
5124
subroutine pardeu(tx,nx,ty,ny,c,kx,ky,nux,nuy,x,y,z,m, * wrk,lwrk,iwrk,kwrk,ier) c subroutine pardeu evaluates on a set of points (x(i),y(i)),i=1,...,m c the partial derivative ( order nux,nuy) of a bivariate spline c s(x,y) of degrees kx and ky, given in the b-spline representation. c c calling sequence: c call parder(tx,nx,ty,ny,c,kx,ky,nux,nuy,x,mx,y,my,z,wrk,lwrk, c * iwrk,kwrk,ier) c c input parameters: c tx : real array, length nx, which contains the position of the c knots in the x-direction. c nx : integer, giving the total number of knots in the x-direction c ty : real array, length ny, which contains the position of the c knots in the y-direction. c ny : integer, giving the total number of knots in the y-direction c c : real array, length (nx-kx-1)*(ny-ky-1), which contains the c b-spline coefficients. c kx,ky : integer values, giving the degrees of the spline. c nux : integer values, specifying the order of the partial c nuy derivative. 0<=nux<kx, 0<=nuy<ky. c kx,ky : integer values, giving the degrees of the spline. c x : real array of dimension (mx). c y : real array of dimension (my). c m : on entry m must specify the number points. m >= 1. c wrk : real array of dimension lwrk. used as workspace. c lwrk : integer, specifying the dimension of wrk. c lwrk >= mx*(kx+1-nux)+my*(ky+1-nuy)+(nx-kx-1)*(ny-ky-1) c iwrk : integer array of dimension kwrk. used as workspace. c kwrk : integer, specifying the dimension of iwrk. kwrk >= mx+my. c c output parameters: c z : real array of dimension (m). c on succesful exit z(i) contains the value of the c specified partial derivative of s(x,y) at the point c (x(i),y(i)),i=1,...,m. c ier : integer error flag c ier=0 : normal return c ier=10: invalid input data (see restrictions) c c restrictions: c lwrk>=m*(kx+1-nux)+m*(ky+1-nuy)+(nx-kx-1)*(ny-ky-1), c c other subroutines required: c fpbisp,fpbspl c c references : c de boor c : on calculating with b-splines, j. approximation theory c 6 (1972) 50-62. c dierckx p. : curve and surface fitting with splines, monographs on c numerical analysis, oxford university press, 1993. c c author : c p.dierckx c dept. computer science, k.u.leuven c celestijnenlaan 200a, b-3001 heverlee, belgium. c e-mail : Paul.Dierckx@cs.kuleuven.ac.be c c latest update : march 1989 c c ..scalar arguments.. integer nx,ny,kx,ky,m,lwrk,kwrk,ier,nux,nuy c ..array arguments.. integer iwrk(kwrk) real*8 tx(nx),ty(ny),c((nx-kx-1)*(ny-ky-1)),x(m),y(m),z(m), * wrk(lwrk) c ..local scalars.. integer i,iwx,iwy,j,kkx,kky,kx1,ky1,lx,ly,lwest,l1,l2,mm,m0,m1, * nc,nkx1,nky1,nxx,nyy real*8 ak,fac c .. c before starting computations a data check is made. if the input data c are invalid control is immediately repassed to the calling program. ier = 10 kx1 = kx+1 ky1 = ky+1 nkx1 = nx-kx1 nky1 = ny-ky1 nc = nkx1*nky1 if(nux.lt.0 .or. nux.ge.kx) go to 400 if(nuy.lt.0 .or. nuy.ge.ky) go to 400 lwest = nc +(kx1-nux)*m+(ky1-nuy)*m if(lwrk.lt.lwest) go to 400 if(kwrk.lt.(m+m)) go to 400 if (m.lt.1) go to 400 ier = 0 nxx = nkx1 nyy = nky1 kkx = kx kky = ky c the partial derivative of order (nux,nuy) of a bivariate spline of c degrees kx,ky is a bivariate spline of degrees kx-nux,ky-nuy. c we calculate the b-spline coefficients of this spline do 70 i=1,nc wrk(i) = c(i) 70 continue if(nux.eq.0) go to 200 lx = 1 do 100 j=1,nux ak = kkx nxx = nxx-1 l1 = lx m0 = 1 do 90 i=1,nxx l1 = l1+1 l2 = l1+kkx fac = tx(l2)-tx(l1) if(fac.le.0.) go to 90 do 80 mm=1,nyy m1 = m0+nyy wrk(m0) = (wrk(m1)-wrk(m0))*ak/fac m0 = m0+1 80 continue 90 continue lx = lx+1 kkx = kkx-1 100 continue 200 if(nuy.eq.0) go to 300 ly = 1 do 230 j=1,nuy ak = kky nyy = nyy-1 l1 = ly do 220 i=1,nyy l1 = l1+1 l2 = l1+kky fac = ty(l2)-ty(l1) if(fac.le.0.) go to 220 m0 = i do 210 mm=1,nxx m1 = m0+1 wrk(m0) = (wrk(m1)-wrk(m0))*ak/fac m0 = m0+nky1 210 continue 220 continue ly = ly+1 kky = kky-1 230 continue m0 = nyy m1 = nky1 do 250 mm=2,nxx do 240 i=1,nyy m0 = m0+1 m1 = m1+1 wrk(m0) = wrk(m1) 240 continue m1 = m1+nuy 250 continue c we partition the working space and evaluate the partial derivative 300 iwx = 1+nxx*nyy iwy = iwx+m*(kx1-nux) do 390 i=1,m call fpbisp(tx(nux+1),nx-2*nux,ty(nuy+1),ny-2*nuy,wrk,kkx,kky, * x(i),1,y(i),1,z(i),wrk(iwx),wrk(iwy),iwrk(1),iwrk(2)) 390 continue 400 return end
bsd-3-clause
eiselekd/gcc
gcc/testsuite/gfortran.dg/missing_optional_dummy_1.f90
188
1681
! { dg-do run } ! Test the fix for PR26891, in which an optional argument, whose actual ! is a missing dummy argument would cause a segfault. ! ! Contributed by Paul Thomas <pault@gcc.gnu.org> ! logical :: back =.false. ! This was the case that would fail - PR case was an intrinsic call. if (scan ("A quick brown fox jumps over the lazy dog", "lazy", back) & .ne. myscan ("A quick brown fox jumps over the lazy dog", "lazy")) & call abort () ! Check that the patch works with non-intrinsic functions. if (myscan ("A quick brown fox jumps over the lazy dog", "fox", back) & .ne. thyscan ("A quick brown fox jumps over the lazy dog", "fox")) & call abort () ! Check that missing, optional character actual arguments are OK. if (scan ("A quick brown fox jumps over the lazy dog", "over", back) & .ne. thyscan ("A quick brown fox jumps over the lazy dog")) & call abort () contains integer function myscan (str, substr, back) character(*), intent(in) :: str, substr logical, optional, intent(in) :: back myscan = scan (str, substr, back) end function myscan integer function thyscan (str, substr, back) character(*), intent(in) :: str character(*), optional, intent(in) :: substr logical, optional, intent(in) :: back thyscan = isscan (str, substr, back) end function thyscan integer function isscan (str, substr, back) character(*), intent(in) :: str character(*), optional :: substr logical, optional, intent(in) :: back if (.not.present(substr)) then isscan = myscan (str, "over", back) else isscan = myscan (str, substr, back) end if end function isscan end
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/namelist_70.f90
162
13948
! { dg-do run } ! ! PR fortran/47339 ! PR fortran/43062 ! ! Run-time test for Fortran 2003 NAMELISTS ! Version for non-strings ! program nml_test implicit none character(len=1000) :: str character(len=5), allocatable :: a(:) character(len=5), allocatable :: b character(len=5), pointer :: ap(:) character(len=5), pointer :: bp character(len=5) :: c character(len=5) :: d(3) type t character(len=5) :: c1 character(len=5) :: c2(3) end type t type(t) :: e,f(2) type(t),allocatable :: g,h(:) type(t),pointer :: i,j(:) namelist /nml/ a, b, c, d, ap, bp,e,f,g,h,i,j a = ["aa01", "aa02"] allocate(b,ap(2),bp) ap = ['98', '99'] b = '7' bp = '101' c = '8' d = ['-1', '-2', '-3'] e%c1 = '-701' e%c2 = ['-702','-703','-704'] f(1)%c1 = '33001' f(2)%c1 = '33002' f(1)%c2 = ['44001','44002','44003'] f(2)%c2 = ['44011','44012','44013'] allocate(g,h(2),i,j(2)) g%c1 = '-601' g%c2 = ['-602','6703','-604'] h(1)%c1 = '35001' h(2)%c1 = '35002' h(1)%c2 = ['45001','45002','45003'] h(2)%c2 = ['45011','45012','45013'] i%c1 = '-501' i%c2 = ['-502','-503','-504'] j(1)%c1 = '36001' j(2)%c1 = '36002' j(1)%c2 = ['46001','46002','46003'] j(2)%c2 = ['46011','46012','46013'] ! SAVE NAMELIST str = repeat('X', len(str)) write(str,nml=nml) ! RESET NAMELIST a = repeat('X', len(a)) ap = repeat('X', len(ap)) b = repeat('X', len(b)) bp = repeat('X', len(bp)) c = repeat('X', len(c)) d = repeat('X', len(d)) e%c1 = repeat('X', len(e%c1)) e%c2 = repeat('X', len(e%c2)) f(1)%c1 = repeat('X', len(f(1)%c1)) f(2)%c1 = repeat('X', len(f(2)%c1)) f(1)%c2 = repeat('X', len(f(1)%c2)) f(2)%c2 = repeat('X', len(f(2)%c2)) g%c1 = repeat('X', len(g%c1)) g%c2 = repeat('X', len(g%c1)) h(1)%c1 = repeat('X', len(h(1)%c1)) h(2)%c1 = repeat('X', len(h(1)%c1)) h(1)%c2 = repeat('X', len(h(1)%c1)) h(2)%c2 = repeat('X', len(h(1)%c1)) i%c1 = repeat('X', len(i%c1)) i%c2 = repeat('X', len(i%c1)) j(1)%c1 = repeat('X', len(j(1)%c1)) j(2)%c1 = repeat('X', len(j(2)%c1)) j(1)%c2 = repeat('X', len(j(1)%c2)) j(2)%c2 = repeat('X', len(j(2)%c2)) ! Read back read(str,nml=nml) ! Check result if (any (a /= ['aa01','aa02'])) call abort() if (any (ap /= ['98', '99'])) call abort() if (b /= '7') call abort() if (bp /= '101') call abort() if (c /= '8') call abort() if (any (d /= ['-1', '-2', '-3'])) call abort() if (e%c1 /= '-701') call abort() if (any (e%c2 /= ['-702','-703','-704'])) call abort() if (f(1)%c1 /= '33001') call abort() if (f(2)%c1 /= '33002') call abort() if (any (f(1)%c2 /= ['44001','44002','44003'])) call abort() if (any (f(2)%c2 /= ['44011','44012','44013'])) call abort() if (g%c1 /= '-601') call abort() if (any(g%c2 /= ['-602','6703','-604'])) call abort() if (h(1)%c1 /= '35001') call abort() if (h(2)%c1 /= '35002') call abort() if (any (h(1)%c2 /= ['45001','45002','45003'])) call abort() if (any (h(2)%c2 /= ['45011','45012','45013'])) call abort() if (i%c1 /= '-501') call abort() if (any (i%c2 /= ['-502','-503','-504'])) call abort() if (j(1)%c1 /= '36001') call abort() if (j(2)%c1 /= '36002') call abort() if (any (j(1)%c2 /= ['46001','46002','46003'])) call abort() if (any (j(2)%c2 /= ['46011','46012','46013'])) call abort() ! Check argument passing (dummy processing) call test2(a,b,c,d,ap,bp,e,f,g,h,i,j,2) call test3(a,b,c,d,ap,bp,e,f,g,h,i,j,2,len(a)) call test4(a,b,c,d,ap,bp,e,f,g,h,i,j,2) contains subroutine test2(x1,x2,x3,x4,x1p,x2p,x6,x7,x8,x9,x10,x11,n) character(len=5), allocatable :: x1(:) character(len=5), allocatable :: x2 character(len=5), pointer :: x1p(:) character(len=5), pointer :: x2p character(len=5) :: x3 character(len=5) :: x4(3) integer :: n character(len=5) :: x5(n) type(t) :: x6,x7(2) type(t),allocatable :: x8,x9(:) type(t),pointer :: x10,x11(:) type(t) :: x12(n) namelist /nml2/ x1, x2, x3, x4,x5,x1p,x2p,x6,x7,x8,x9,x10,x11,x12 x5 = [ 'x5-42', 'x5-53' ] x12(1)%c1 = '37001' x12(2)%c1 = '37002' x12(1)%c2 = ['47001','47002','47003'] x12(2)%c2 = ['47011','47012','47013'] ! SAVE NAMELIST str = repeat('X', len(str)) write(str,nml=nml2) ! RESET NAMELIST x1 = repeat('X', len(x1)) x1p = repeat('X', len(x1p)) x2 = repeat('X', len(x2)) x2p = repeat('X', len(x2p)) x3 = repeat('X', len(x3)) x4 = repeat('X', len(x4)) x6%c1 = repeat('X', len(x6%c1)) x6%c2 = repeat('X', len(x6%c2)) x7(1)%c1 = repeat('X', len(x7(1)%c1)) x7(2)%c1 = repeat('X', len(x7(2)%c1)) x7(1)%c2 = repeat('X', len(x7(1)%c2)) x7(2)%c2 = repeat('X', len(x7(2)%c2)) x8%c1 = repeat('X', len(x8%c1)) x8%c2 = repeat('X', len(x8%c1)) x9(1)%c1 = repeat('X', len(x9(1)%c1)) x9(2)%c1 = repeat('X', len(x9(1)%c1)) x9(1)%c2 = repeat('X', len(x9(1)%c1)) x9(2)%c2 = repeat('X', len(x9(1)%c1)) x10%c1 = repeat('X', len(x10%c1)) x10%c2 = repeat('X', len(x10%c1)) x11(1)%c1 = repeat('X', len(x11(1)%c1)) x11(2)%c1 = repeat('X', len(x11(2)%c1)) x11(1)%c2 = repeat('X', len(x11(1)%c2)) x11(2)%c2 = repeat('X', len(x11(2)%c2)) x5 = repeat('X', len(x5)) x12(1)%c1 = repeat('X', len(x12(2)%c2)) x12(2)%c1 = repeat('X', len(x12(2)%c2)) x12(1)%c2 = repeat('X', len(x12(2)%c2)) x12(2)%c2 = repeat('X', len(x12(2)%c2)) ! Read back read(str,nml=nml2) ! Check result if (any (x1 /= ['aa01','aa02'])) call abort() if (any (x1p /= ['98', '99'])) call abort() if (x2 /= '7') call abort() if (x2p /= '101') call abort() if (x3 /= '8') call abort() if (any (x4 /= ['-1', '-2', '-3'])) call abort() if (x6%c1 /= '-701') call abort() if (any (x6%c2 /= ['-702','-703','-704'])) call abort() if (x7(1)%c1 /= '33001') call abort() if (x7(2)%c1 /= '33002') call abort() if (any (x7(1)%c2 /= ['44001','44002','44003'])) call abort() if (any (x7(2)%c2 /= ['44011','44012','44013'])) call abort() if (x8%c1 /= '-601') call abort() if (any(x8%c2 /= ['-602','6703','-604'])) call abort() if (x9(1)%c1 /= '35001') call abort() if (x9(2)%c1 /= '35002') call abort() if (any (x9(1)%c2 /= ['45001','45002','45003'])) call abort() if (any (x9(2)%c2 /= ['45011','45012','45013'])) call abort() if (x10%c1 /= '-501') call abort() if (any (x10%c2 /= ['-502','-503','-504'])) call abort() if (x11(1)%c1 /= '36001') call abort() if (x11(2)%c1 /= '36002') call abort() if (any (x11(1)%c2 /= ['46001','46002','46003'])) call abort() if (any (x11(2)%c2 /= ['46011','46012','46013'])) call abort() if (any (x5 /= [ 'x5-42', 'x5-53' ])) call abort() if (x12(1)%c1 /= '37001') call abort() if (x12(2)%c1 /= '37002') call abort() if (any (x12(1)%c2 /= ['47001','47002','47003'])) call abort() if (any (x12(2)%c2 /= ['47011','47012','47013'])) call abort() end subroutine test2 subroutine test3(x1,x2,x3,x4,x1p,x2p,x6,x7,x8,x9,x10,x11,n,ll) integer :: n, ll character(len=ll), allocatable :: x1(:) character(len=ll), allocatable :: x2 character(len=ll), pointer :: x1p(:) character(len=ll), pointer :: x2p character(len=ll) :: x3 character(len=ll) :: x4(3) character(len=ll) :: x5(n) type(t) :: x6,x7(2) type(t),allocatable :: x8,x9(:) type(t),pointer :: x10,x11(:) type(t) :: x12(n) namelist /nml2/ x1, x2, x3, x4,x5,x1p,x2p,x6,x7,x8,x9,x10,x11,x12 x5 = [ 'x5-42', 'x5-53' ] x12(1)%c1 = '37001' x12(2)%c1 = '37002' x12(1)%c2 = ['47001','47002','47003'] x12(2)%c2 = ['47011','47012','47013'] ! SAVE NAMELIST str = repeat('X', len(str)) write(str,nml=nml2) ! RESET NAMELIST x1 = repeat('X', len(x1)) x1p = repeat('X', len(x1p)) x2 = repeat('X', len(x2)) x2p = repeat('X', len(x2p)) x3 = repeat('X', len(x3)) x4 = repeat('X', len(x4)) x6%c1 = repeat('X', len(x6%c1)) x6%c2 = repeat('X', len(x6%c2)) x7(1)%c1 = repeat('X', len(x7(1)%c1)) x7(2)%c1 = repeat('X', len(x7(2)%c1)) x7(1)%c2 = repeat('X', len(x7(1)%c2)) x7(2)%c2 = repeat('X', len(x7(2)%c2)) x8%c1 = repeat('X', len(x8%c1)) x8%c2 = repeat('X', len(x8%c1)) x9(1)%c1 = repeat('X', len(x9(1)%c1)) x9(2)%c1 = repeat('X', len(x9(1)%c1)) x9(1)%c2 = repeat('X', len(x9(1)%c1)) x9(2)%c2 = repeat('X', len(x9(1)%c1)) x10%c1 = repeat('X', len(x10%c1)) x10%c2 = repeat('X', len(x10%c1)) x11(1)%c1 = repeat('X', len(x11(1)%c1)) x11(2)%c1 = repeat('X', len(x11(2)%c1)) x11(1)%c2 = repeat('X', len(x11(1)%c2)) x11(2)%c2 = repeat('X', len(x11(2)%c2)) x5 = repeat('X', len(x5)) x12(1)%c1 = repeat('X', len(x12(2)%c2)) x12(2)%c1 = repeat('X', len(x12(2)%c2)) x12(1)%c2 = repeat('X', len(x12(2)%c2)) x12(2)%c2 = repeat('X', len(x12(2)%c2)) ! Read back read(str,nml=nml2) ! Check result if (any (x1 /= ['aa01','aa02'])) call abort() if (any (x1p /= ['98', '99'])) call abort() if (x2 /= '7') call abort() if (x2p /= '101') call abort() if (x3 /= '8') call abort() if (any (x4 /= ['-1', '-2', '-3'])) call abort() if (x6%c1 /= '-701') call abort() if (any (x6%c2 /= ['-702','-703','-704'])) call abort() if (x7(1)%c1 /= '33001') call abort() if (x7(2)%c1 /= '33002') call abort() if (any (x7(1)%c2 /= ['44001','44002','44003'])) call abort() if (any (x7(2)%c2 /= ['44011','44012','44013'])) call abort() if (x8%c1 /= '-601') call abort() if (any(x8%c2 /= ['-602','6703','-604'])) call abort() if (x9(1)%c1 /= '35001') call abort() if (x9(2)%c1 /= '35002') call abort() if (any (x9(1)%c2 /= ['45001','45002','45003'])) call abort() if (any (x9(2)%c2 /= ['45011','45012','45013'])) call abort() if (x10%c1 /= '-501') call abort() if (any (x10%c2 /= ['-502','-503','-504'])) call abort() if (x11(1)%c1 /= '36001') call abort() if (x11(2)%c1 /= '36002') call abort() if (any (x11(1)%c2 /= ['46001','46002','46003'])) call abort() if (any (x11(2)%c2 /= ['46011','46012','46013'])) call abort() if (any (x5 /= [ 'x5-42', 'x5-53' ])) call abort() if (x12(1)%c1 /= '37001') call abort() if (x12(2)%c1 /= '37002') call abort() if (any (x12(1)%c2 /= ['47001','47002','47003'])) call abort() if (any (x12(2)%c2 /= ['47011','47012','47013'])) call abort() end subroutine test3 subroutine test4(x1,x2,x3,x4,x1p,x2p,x6,x7,x8,x9,x10,x11,n) character(len=*), allocatable :: x1(:) character(len=*), allocatable :: x2 character(len=*), pointer :: x1p(:) character(len=*), pointer :: x2p character(len=*) :: x3 character(len=*) :: x4(3) integer :: n character(len=5) :: x5(n) type(t) :: x6,x7(2) type(t),allocatable :: x8,x9(:) type(t),pointer :: x10,x11(:) type(t) :: x12(n) namelist /nml2/ x1, x2, x3, x4,x5,x1p,x2p,x6,x7,x8,x9,x10,x11,x12 x5 = [ 'x5-42', 'x5-53' ] x12(1)%c1 = '37001' x12(2)%c1 = '37002' x12(1)%c2 = ['47001','47002','47003'] x12(2)%c2 = ['47011','47012','47013'] ! SAVE NAMELIST str = repeat('X', len(str)) write(str,nml=nml2) ! RESET NAMELIST x1 = repeat('X', len(x1)) x1p = repeat('X', len(x1p)) x2 = repeat('X', len(x2)) x2p = repeat('X', len(x2p)) x3 = repeat('X', len(x3)) x4 = repeat('X', len(x4)) x6%c1 = repeat('X', len(x6%c1)) x6%c2 = repeat('X', len(x6%c2)) x7(1)%c1 = repeat('X', len(x7(1)%c1)) x7(2)%c1 = repeat('X', len(x7(2)%c1)) x7(1)%c2 = repeat('X', len(x7(1)%c2)) x7(2)%c2 = repeat('X', len(x7(2)%c2)) x8%c1 = repeat('X', len(x8%c1)) x8%c2 = repeat('X', len(x8%c1)) x9(1)%c1 = repeat('X', len(x9(1)%c1)) x9(2)%c1 = repeat('X', len(x9(1)%c1)) x9(1)%c2 = repeat('X', len(x9(1)%c1)) x9(2)%c2 = repeat('X', len(x9(1)%c1)) x10%c1 = repeat('X', len(x10%c1)) x10%c2 = repeat('X', len(x10%c1)) x11(1)%c1 = repeat('X', len(x11(1)%c1)) x11(2)%c1 = repeat('X', len(x11(2)%c1)) x11(1)%c2 = repeat('X', len(x11(1)%c2)) x11(2)%c2 = repeat('X', len(x11(2)%c2)) x5 = repeat('X', len(x5)) x12(1)%c1 = repeat('X', len(x12(2)%c2)) x12(2)%c1 = repeat('X', len(x12(2)%c2)) x12(1)%c2 = repeat('X', len(x12(2)%c2)) x12(2)%c2 = repeat('X', len(x12(2)%c2)) ! Read back read(str,nml=nml2) ! Check result if (any (x1 /= ['aa01','aa02'])) call abort() if (any (x1p /= ['98', '99'])) call abort() if (x2 /= '7') call abort() if (x2p /= '101') call abort() if (x3 /= '8') call abort() if (any (x4 /= ['-1', '-2', '-3'])) call abort() if (x6%c1 /= '-701') call abort() if (any (x6%c2 /= ['-702','-703','-704'])) call abort() if (x7(1)%c1 /= '33001') call abort() if (x7(2)%c1 /= '33002') call abort() if (any (x7(1)%c2 /= ['44001','44002','44003'])) call abort() if (any (x7(2)%c2 /= ['44011','44012','44013'])) call abort() if (x8%c1 /= '-601') call abort() if (any(x8%c2 /= ['-602','6703','-604'])) call abort() if (x9(1)%c1 /= '35001') call abort() if (x9(2)%c1 /= '35002') call abort() if (any (x9(1)%c2 /= ['45001','45002','45003'])) call abort() if (any (x9(2)%c2 /= ['45011','45012','45013'])) call abort() if (x10%c1 /= '-501') call abort() if (any (x10%c2 /= ['-502','-503','-504'])) call abort() if (x11(1)%c1 /= '36001') call abort() if (x11(2)%c1 /= '36002') call abort() if (any (x11(1)%c2 /= ['46001','46002','46003'])) call abort() if (any (x11(2)%c2 /= ['46011','46012','46013'])) call abort() if (any (x5 /= [ 'x5-42', 'x5-53' ])) call abort() if (x12(1)%c1 /= '37001') call abort() if (x12(2)%c1 /= '37002') call abort() if (any (x12(1)%c2 /= ['47001','47002','47003'])) call abort() if (any (x12(2)%c2 /= ['47011','47012','47013'])) call abort() end subroutine test4 end program nml_test
gpl-2.0
Lrakulka/visp
3rdparty/lapackblas/blas/dgemv.f
4
8770
*> \brief \b DGEMV * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * 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(*) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DGEMV performs one of the matrix-vector operations *> *> y := alpha*A*x + beta*y, or y := alpha*A**T*x + beta*y, *> *> where alpha and beta are scalars, x and y are vectors and A is an *> m by n matrix. *> \endverbatim * * Arguments: * ========== * *> \param[in] TRANS *> \verbatim *> TRANS is 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**T*x + beta*y. *> *> TRANS = 'C' or 'c' y := alpha*A**T*x + beta*y. *> \endverbatim *> *> \param[in] M *> \verbatim *> M is INTEGER *> On entry, M specifies the number of rows of the matrix A. *> M must be at least zero. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> On entry, N specifies the number of columns of the matrix A. *> N must be at least zero. *> \endverbatim *> *> \param[in] ALPHA *> \verbatim *> ALPHA is DOUBLE PRECISION. *> On entry, ALPHA specifies the scalar alpha. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is 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. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is 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 ). *> \endverbatim *> *> \param[in] X *> \verbatim *> X is 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. *> \endverbatim *> *> \param[in] INCX *> \verbatim *> INCX is INTEGER *> On entry, INCX specifies the increment for the elements of *> X. INCX must not be zero. *> \endverbatim *> *> \param[in] BETA *> \verbatim *> BETA is DOUBLE PRECISION. *> On entry, BETA specifies the scalar beta. When BETA is *> supplied as zero then Y need not be set on input. *> \endverbatim *> *> \param[in,out] Y *> \verbatim *> Y is 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. *> \endverbatim *> *> \param[in] INCY *> \verbatim *> INCY is INTEGER *> On entry, INCY specifies the increment for the elements of *> Y. INCY must not be zero. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date December 2016 * *> \ingroup double_blas_level2 * *> \par Further Details: * ===================== *> *> \verbatim *> *> Level 2 Blas routine. *> The vector and matrix arguments are not referenced when N = 0, or M = 0 *> *> -- 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. *> \endverbatim *> * ===================================================================== SUBROUTINE DGEMV(TRANS,M,N,ALPHA,A,LDA,X,INCX,BETA,Y,INCY) * * -- Reference BLAS level2 routine (version 3.7.0) -- * -- Reference BLAS is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * December 2016 * * .. Scalar Arguments .. DOUBLE PRECISION ALPHA,BETA INTEGER INCX,INCY,LDA,M,N CHARACTER TRANS * .. * .. Array Arguments .. DOUBLE PRECISION A(LDA,*),X(*),Y(*) * .. * * ===================================================================== * * .. 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 TEMP = ALPHA*X(JX) DO 50 I = 1,M Y(I) = Y(I) + TEMP*A(I,J) 50 CONTINUE JX = JX + INCX 60 CONTINUE ELSE DO 80 J = 1,N TEMP = ALPHA*X(JX) IY = KY DO 70 I = 1,M Y(IY) = Y(IY) + TEMP*A(I,J) IY = IY + INCY 70 CONTINUE JX = JX + INCX 80 CONTINUE END IF ELSE * * Form y := alpha*A**T*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
trankmichael/scipy
scipy/interpolate/fitpack/fpknot.f
124
2079
subroutine fpknot(x,m,t,n,fpint,nrdata,nrint,nest,istart) implicit none c subroutine fpknot locates an additional knot for a spline of degree c k and adjusts the corresponding parameters,i.e. c t : the position of the knots. c n : the number of knots. c nrint : the number of knotintervals. c fpint : the sum of squares of residual right hand sides c for each knot interval. c nrdata: the number of data points inside each knot interval. c istart indicates that the smallest data point at which the new knot c may be added is x(istart+1) c .. c ..scalar arguments.. integer m,n,nrint,nest,istart c ..array arguments.. real*8 x(m),t(nest),fpint(nest) integer nrdata(nest) c ..local scalars.. real*8 an,am,fpmax integer ihalf,j,jbegin,jj,jk,jpoint,k,maxbeg,maxpt, * next,nrx,number c .. k = (n-nrint-1)/2 c search for knot interval t(number+k) <= x <= t(number+k+1) where c fpint(number) is maximal on the condition that nrdata(number) c not equals zero. fpmax = 0. jbegin = istart do 20 j=1,nrint jpoint = nrdata(j) if(fpmax.ge.fpint(j) .or. jpoint.eq.0) go to 10 fpmax = fpint(j) number = j maxpt = jpoint maxbeg = jbegin 10 jbegin = jbegin+jpoint+1 20 continue c let coincide the new knot t(number+k+1) with a data point x(nrx) c inside the old knot interval t(number+k) <= x <= t(number+k+1). ihalf = maxpt/2+1 nrx = maxbeg+ihalf next = number+1 if(next.gt.nrint) go to 40 c adjust the different parameters. do 30 j=next,nrint jj = next+nrint-j fpint(jj+1) = fpint(jj) nrdata(jj+1) = nrdata(jj) jk = jj+k t(jk+1) = t(jk) 30 continue 40 nrdata(number) = ihalf-1 nrdata(next) = maxpt-ihalf am = maxpt an = nrdata(number) fpint(number) = fpmax*an/am an = nrdata(next) fpint(next) = fpmax*an/am jk = next+k t(jk) = x(nrx) n = n+1 nrint = nrint+1 return end
bsd-3-clause
jasonlarkin/p3dfft
build/fft_spec.F90
3
1906
! This file is part of P3DFFT library ! ! P3DFFT ! ! Software Framework for Scalable Fourier Transforms in Three Dimensions ! ! Copyright (C) 2006-2014 Dmitry Pekurovsky ! Copyright (C) 2006-2014 University of California ! Copyright (C) 2010-2011 Jens Henrik Goebbert ! ! This program 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. ! ! This program 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. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. ! ! !---------------------------------------------------------------------------- module fft_spec integer, parameter, public :: r8 = KIND(1.0d0) integer, parameter, public :: i8 = SELECTED_INT_KIND(18) #ifdef FFTW include "fftw3.f" integer(i8) plan1_frc,plan1_bcr,plan1_fc,plan1_bc integer(i8) plan_ctrans_same, plan_strans_same, & plan_ctrans_dif, plan_strans_dif integer(i8) plan2_bc_same,plan2_fc_same,plan2_bc_dif,plan2_fc_dif ! integer(i8) plan1,plan2,plan3 integer fftw_flag,NULL #ifdef ESTIMATE parameter(fftw_flag = FFTW_ESTIMATE,NULL=0) #elif defined PATIENT parameter(fftw_flag = FFTW_PATIENT,NULL=0) #else parameter(fftw_flag = FFTW_MEASURE,NULL=0) #endif #endif #ifdef ESSL integer :: cnaux,rnaux1,rnaux2 real(r8),save,allocatable :: caux1(:),caux2(:),raux1(:),raux2(:) real(r8),save :: raux3(1) #endif end module
gpl-3.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/spread_scalar_source.f90
188
1376
! { dg-do run } ! { dg-options "-O0" } character*1 :: i, j(10) character*8 :: buffer integer(kind=1) :: ii, jj(10) type :: mytype real(kind=8) :: x integer(kind=1) :: i character*15 :: ch end type mytype type(mytype) :: iii, jjj(10) i = "w" ii = 42 iii = mytype (41.9999_8, 77, "test_of_spread_") ! Test constant sources. j = spread ("z", 1 , 10) if (any (j /= "z")) call abort () jj = spread (19, 1 , 10) if (any (jj /= 19)) call abort () ! Test variable sources. j = spread (i, 1 , 10) if (any (j /= "w")) call abort () jj = spread (ii, 1 , 10) if (any (jj /= 42)) call abort () jjj = spread (iii, 1 , 10) if (any (jjj%x /= 41.9999_8)) call abort () if (any (jjj%i /= 77)) call abort () if (any (jjj%ch /= "test_of_spread_")) call abort () ! Check that spread != 1 is OK. jj(2:10:2) = spread (1, 1, 5) if (any (jj(1:9:2) /= 42) .or. any (jj(2:10:2) /= 1)) call abort () ! Finally, check that temporaries and trans-io.c work correctly. write (buffer, '(4a1)') spread (i, 1 , 4) if (trim(buffer) /= "wwww") call abort () write (buffer, '(4a1)') spread ("r", 1 , 4) if (trim(buffer) /= "rrrr") call abort () write (buffer, '(4i2)') spread (ii, 1 , 4) if (trim(buffer) /= "42424242") call abort () write (buffer, '(4i2)') spread (31, 1 , 4) if (trim(buffer) /= "31313131") call abort () end
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/argument_checking_14.f90
193
2725
! { dg-do compile } ! { dg-options "-std=f95" } ! ! PR fortran/34796 ! ! This checks for Fortran 2003 extensions. ! ! Argument checks: ! - elements of deferred-shape arrays (= non-dummies) are allowed ! as the memory is contiguous ! - while assumed-shape arrays (= dummy arguments) and pointers are ! not (strides can make them non-contiguous) ! and ! - if the memory is non-contigous, character arguments have as ! storage size only the size of the element itself, check for ! too short actual arguments. ! subroutine test2(assumed_sh_dummy, pointer_dummy) implicit none interface subroutine rlv2(y) character :: y(3) end subroutine rlv2 end interface character(3) :: assumed_sh_dummy(:,:,:) character(3), pointer :: pointer_dummy(:,:,:) character(3), allocatable :: deferred(:,:,:) character(3), pointer :: ptr(:,:,:) call rlv2(deferred(1,1,1)) ! Valid since contiguous call rlv2(ptr(1,1,1)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } call rlv2(assumed_sh_dummy(1,1,1)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } call rlv2(pointer_dummy(1,1,1)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } ! The following is kind of ok: The memory access it valid ! We warn nonetheless as the result is not what is intented ! and also formally wrong. ! Using (1:string_length) would be ok. call rlv2(deferred(1,1,1)(1:3)) ! OK call rlv2(ptr(1,1,1)(1:1)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } call rlv2(assumed_sh_dummy(1,1,1)(1:2)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } call rlv2(pointer_dummy(1,1,1)(1:3)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } end subroutine test3(assumed_sh_dummy, pointer_dummy) implicit none interface subroutine rlv3(y) character :: y(2) end subroutine rlv3 end interface character(2) :: assumed_sh_dummy(:,:,:) character(2), pointer :: pointer_dummy(:,:,:) character(2), allocatable :: deferred(:,:,:) character(2), pointer :: ptr(:,:,:) call rlv3(deferred(1,1,1)) ! Valid since contiguous call rlv3(ptr(1,1,1)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } call rlv3(assumed_sh_dummy(1,1,1)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } call rlv3(pointer_dummy(1,1,1)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } call rlv3(deferred(1,1,1)(1:2)) ! Valid since contiguous call rlv3(ptr(1,1,1)(1:2)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } call rlv3(assumed_sh_dummy(1,1,1)(1:2)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } call rlv3(pointer_dummy(1,1,1)(1:2)) ! { dg-error "Fortran 2003: Scalar CHARACTER actual" } end
gpl-2.0
pablodebiase/bromoc-e_suite
pb-pnp/src/pnpanal.f
3
46095
! PB-PNP - Poisson-Boltzmann and Poisson-Nernst-Planck Equations Solver ! Copyright (C) 2014 Pablo M. De Biase (pablodebiase@gmail.com) ! ! This program 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. ! ! This program 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. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. SUBROUTINE PROFILE(Ntype,Iontype,Temp,Nclx,Ncly,Nclz,dcel, $ tranx,trany,tranz,xbcen,ybcen,zbcen, $ rsphe,xsphe,ysphe,zsphe, $ PHI,Cion,Zion,Diffusion,Qrho,Qflux,Qcurrent) c------------------------------------------------------------------------ c Calculate density or flux profiles along Z-axis for each ion c implicit none include 'mainio.fcm' include 'consta.fcm' integer*4 Ntype,NCLX,NCLY,NCLZ real*8 Temp,dcel,Zion(*),Diffusion(*) real*8 tranx,trany,tranz,xbcen,ybcen,zbcen real*8 rsphe,xsphe,ysphe,zsphe real*4 PHI(*),Cion(*) CHARACTER*4 Iontype(*) LOGICAL Qrho,Qflux,Qcurrent c local real*4 Zprofile(8) real*8 volume(8),area(8),NUMION(8),Isum(8),Isum2(8) real*8 Ic,Ic2,Icsum,Icsum2 real*8 dcel2,dcel3,zz,factor,factor2 real*8 phi0,phi6,avephi,c0,c6 real*8 zmaxsphe,zminsphe,rsphe2,xx,yy,r2 integer*4 ncyz,nc3,i,kg,ig,jg,iii,ip0,ipi,ipd c if(Ntype.GT.8) then stop 'Increase dimension of Zprofile ... in PROFILE' endif c ncyz=ncly*nclz nc3=nclx*ncly*nclz dcel2=dcel*dcel dcel3=dcel2*dcel factor = celec / ( kboltz * Temp / kcalmol) zmaxsphe= rsphe+zsphe zminsphe=-rsphe+zsphe rsphe2 = rsphe*rsphe c write(outu,'(6x,a)') write(outu,'(6x,a)') $ 'Ion accessible cross-sectional area along Z : [A^2]' write(outu,'(9x,a,7x,8(4x,a4,4x))') 'Z',(Iontype(i),i=1,ntype) do i=1,ntype NUMION(i)=0.0d0 volume(i)=0.0d0 enddo do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen if(rsphe.gt.0.0d0) then if(zz.gt.zmaxsphe.or.zz.lt.zminsphe) goto 1001 endif do i=1,Ntype Zprofile(i)=0.0d0 area(i)=0.0d0 enddo do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz if(rsphe.gt.0.0d0) then yy=(jg-1)*dcel-trany+ybcen r2=xx*xx+yy*yy+zz*zz if(r2.le.rsphe2) then do i=1,ntype ipi=ip0+nc3*(i-1) if(Cion(ipi).ne.0.0d0) then area(i)=area(i)+1.0d0 Zprofile(i)=Zprofile(i)+Cion(ipi) endif enddo endif else do i=1,ntype ipi=ip0+nc3*(i-1) if(Cion(ipi).ne.0.0d0) then area(i)=area(i)+1.0d0 Zprofile(i)=Zprofile(i)+Cion(ipi) endif enddo endif enddo enddo do i=1,ntype volume(i)=volume(i)+area(i)*dcel3 NUMION(i)=NUMION(i)+Zprofile(i)*dcel3 enddo write(outu,'(3x,f10.3,2x,8f12.3)') zz,(area(i)*dcel2,i=1,ntype) 1001 enddo write(outu,'(6x,a)') write(outu,'(40x,8(4x,a4,4x))') (Iontype(i),i=1,ntype) write(outu,'(6x,a,8f12.3)') $ 'Ion accessible volume [Angs**3] :',(volume(i),i=1,ntype) write(outu,'(6x,a,8f12.3)') $ 'Total number of ions :',(NUMION(i),i=1,ntype) c IF(Qrho) THEN write(outu,'(6x,a)') write(outu,'(6x,2a)') 'Integrated number of ions along Z : ', $ '[unit charge]' write(outu,'(6x,a)') write(outu,'(9x,a,8x,8(a4,8x))') 'Z',(Iontype(i),i=1,ntype) do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen if(rsphe.gt.0.0d0) then if(zz.gt.zmaxsphe.or.zz.lt.zminsphe) goto 1002 endif do i=1,Ntype Zprofile(i)=0.0d0 enddo do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz if(rsphe.gt.0.0d0) then yy=(jg-1)*dcel-trany+ybcen r2=xx*xx+yy*yy+zz*zz if(r2.le.rsphe2) then do i=1,ntype ipi=ip0+nc3*(i-1) if(Cion(ipi).ne.0.0d0) then Zprofile(i)=Zprofile(i)+Cion(ipi) endif enddo endif else do i=1,ntype ipi=ip0+nc3*(i-1) if(Cion(ipi).ne.0.0d0) then Zprofile(i)=Zprofile(i)+Cion(ipi) endif enddo endif enddo enddo write(outu,'(3x,f10.3,2x,8(e11.4,2x))') $ zz,(Zprofile(i)*dcel3,i=1,ntype) 1002 enddo write(outu,'(6x,a)') write(outu,'(6x,2a)') $ 'Density Profile based on ion-accessible area along Z : ', $ '[unit charge]/[A^3]' write(outu,'(6x,a)') write(outu,'(9x,a,8x,8(a4,8x))') 'Z',(Iontype(i),i=1,ntype) do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen if(rsphe.gt.0.0d0) then if(zz.gt.zmaxsphe.or.zz.lt.zminsphe) goto 1003 endif do i=1,Ntype area(i)=0.0d0 Zprofile(i)=0.0d0 enddo do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz if(rsphe.gt.0.0d0) then yy=(jg-1)*dcel-trany+ybcen r2=xx*xx+yy*yy+zz*zz if(r2.le.rsphe2) then do i=1,ntype ipi=ip0+nc3*(i-1) if(Cion(ipi).ne.0.0d0) then area(i)=area(i)+1.0d0 Zprofile(i)=Zprofile(i)+Cion(ipi) endif enddo endif else do i=1,ntype ipi=ip0+nc3*(i-1) if(Cion(ipi).ne.0.0d0) then area(i)=area(i)+1.0d0 Zprofile(i)=Zprofile(i)+Cion(ipi) endif enddo endif enddo enddo write(outu,'(3x,f10.3,2x,8(e11.4,2x))') $ zz,(Zprofile(i)/(area(i)+rsmall),i=1,ntype) 1003 enddo write(outu,'(6x,a)') write(outu,'(6x,2a)') $ 'Density Profile based on system area along Z : ', $ '[unit charge]/[A^3]' write(outu,'(6x,a)') write(outu,'(9x,a,8x,8(a4,8x))') 'Z',(Iontype(i),i=1,ntype) do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen do i=1,Ntype area(i)=0.0d0 Zprofile(i)=0.0d0 if(rsphe.eq.0.0d0) area(i)=nclx*ncly enddo if(rsphe.gt.0.0d0) then if(zz.gt.zmaxsphe.or.zz.lt.zminsphe) goto 1004 endif do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz if(rsphe.gt.0.0d0) then yy=(jg-1)*dcel-trany+ybcen r2=xx*xx+yy*yy+zz*zz if(r2.le.rsphe2) then do i=1,ntype ipi=ip0+nc3*(i-1) if(Cion(ipi).ne.0.0d0) then area(i)=area(i)+1.0d0 Zprofile(i)=Zprofile(i)+Cion(ipi) endif enddo endif else do i=1,ntype ipi=ip0+nc3*(i-1) if(Cion(ipi).ne.0.0d0) then Zprofile(i)=Zprofile(i)+Cion(ipi) endif enddo endif enddo enddo write(outu,'(3x,f10.3,2x,8(e11.4,2x))') $ zz,(Zprofile(i)/(area(i)+rsmall),i=1,ntype) 1004 enddo ENDIF ! Qrho c IF(Qflux) THEN write(outu,'(6x,a)') write(outu,'(6x,2a)') 'Flux (Jz) Profile along Z : ', $ '[unit charge]/[ps][Angs^2]' write(outu,'(6x,a)') write(outu,'(9x,a,8x,8(a4,8x))') 'Z',(Iontype(i),i=1,ntype) do kg=1,nclz-1 ! exclude upper boundary points zz=(kg-1)*dcel-tranz+zbcen do i=1,Ntype area(i)=0.0d0 Zprofile(i)=0.0d0 enddo do ig=1,nclx iii=(ig-1)*ncyz+kg do jg=1,ncly ip0=iii+(jg-1)*nclz do i=1,ntype ipi=ip0+(i-1)*nc3 if(Cion(ipi).ne.0.0d0.and.Cion(ipi+1).ne.0.0d0) then area(i)=area(i)+1.0d0 phi0=phi(ip0) *factor phi6=phi(ip0+1)*factor avephi=(phi0+phi6)*0.5d0 c0=Cion(ipi) *exp(phi0*zion(i)) !conc. -> effective conc. c6=Cion(ipi+1)*exp(phi6*zion(i)) !conc. -> effective conc. ipd=kg+(i-1)*nclz Zprofile(i)=Zprofile(i)- $ Diffusion(ipd)*exp(-avephi*zion(i))*(c6-c0)/dcel endif enddo enddo enddo write(outu,'(3x,f10.3,2x,8(e11.4,2x))') $ zz+dcel*0.5d0,(Zprofile(i)/(area(i)+rsmall),i=1,ntype) enddo ENDIF ! Qflux c IF(Qcurrent) THEN write(outu,'(6x,a)') write(outu,'(6x,2a)') 'Current Profile along Z : ','[pA]' write(outu,'(6x,a)') write(outu,'(9x,a,8x,8(a4,8x))') 'Z',(Iontype(i),i=1,ntype) factor2=coulomb/psec/pico*dcel2 Icsum2=0.0d0 do i=1,ntype Isum(i)=0.0d0 Isum2(i)=0.0d0 enddo do kg=1,nclz-1 ! exclude upper boundary points zz=(kg-1)*dcel-tranz+zbcen do i=1,Ntype Zprofile(i)=0.0d0 enddo do ig=1,nclx iii=(ig-1)*ncyz+kg do jg=1,ncly ip0=iii+(jg-1)*nclz do i=1,ntype ipi=ip0+(i-1)*nc3 if(Cion(ipi).ne.0.0d0.and.Cion(ipi+1).ne.0.0d0) then phi0=phi(ip0) *factor phi6=phi(ip0+1)*factor avephi=(phi0+phi6)*0.5d0 c0=Cion(ipi) *exp(phi0*zion(i)) !conc. -> effective conc. c6=Cion(ipi+1)*exp(phi6*zion(i)) !conc. -> effective conc. ipd=kg+(i-1)*nclz Zprofile(i)=Zprofile(i)- $ Diffusion(ipd)*exp(-avephi*zion(i))*(c6-c0)/dcel endif enddo enddo enddo write(outu,'(3x,f10.3,2x,8(e11.4,2x))') $ zz+dcel*0.5d0,(Zprofile(i)*Zion(i)*factor2,i=1,ntype) Icsum=0.0d0 do i=1,Ntype Ic=Zprofile(i)*Zion(i)*factor2 Isum(i)=Isum(i)+Ic Isum2(i)=Isum2(i)+Ic*Ic Icsum=Icsum+Ic enddo Icsum2=Icsum2+Icsum*Icsum enddo write(outu,'(6x,a)') write(outu,'(6x,2a)') 'Current Statistics : ' Icsum=0.0d0 do i=1,ntype Ic=Isum(i)/(nclz-1) Ic2=Isum2(i)/(nclz-1) write(outu,'(6x,a4,a,f10.4,a,f10.4,a)') $ iontype(i),' : ',Ic,' +/-',sqrt(Ic2-Ic*Ic),' [pA]' Icsum=Icsum+Isum(i) enddo Icsum=Icsum/(nclz-1) Icsum2=Icsum2/(nclz-1) write(outu,'(6x,a,f10.4,a,f10.4,a)') $ 'TOTAL : ',Icsum,' +/-',sqrt(Icsum2-Icsum*Icsum),' [pA]' ENDIF ! Qcurrent c return end SUBROUTINE COUNTERION1(NCLX,NCLY,NCLZ,DCEL,PHI,MCDEN, $ VMEMB,TMEMB,ZMEMB,TRANZ,ZBCEN,CONC,TEMP, $ Qnonlinear,Qpartlinear) c----------------------------------------------------------------------- c This subroutine computes the number of counter ions c implicit none include 'mainio.fcm' include 'consta.fcm' integer*4 NCLX,NCLY,NCLZ real*8 dcel,tranz,zbcen,conc,temp real*8 vmemb,tmemb,zmemb real*4 phi(*),mcden(*) logical*1 Qnonlinear,Qpartlinear c local real*8 factor1 real*8 bulk_num,volume,nion_num,pion_num,bulk_rho real*8 nion_numzp,pion_numzp,nion_numzn,pion_numzn real*8 nion_nummb,pion_nummb,nfactor,pfactor,area real*8 dcel2,dcel3,zz,zc,zmemb2,phif integer*4 ip0,nc3,ncyz,ig,jg,kg,iii c ncyz=ncly*nclz nc3=nclx*ncly*nclz dcel2=dcel*dcel dcel3=dcel2*dcel zmemb2=tranz-zbcen+0.5d0*tmemb+zmemb+rsmall c conversion factoer from 1/(kcal/(mol*e)) to 1/(e/A) factor1 = celec / ( kboltz * Temp / kcalmol) c calculate ion accessible volume volume=0.0D0 do ip0=1,nc3 if(mcden(ip0).ne.0.0d0) volume=volume+dcel3 enddo c bulk density and number of counter ions bulk_rho=conc*(avogadro/liter)*(angstrom**3) ! [unit charge]/A^3 bulk_num=bulk_rho*volume c deviation from bulk number of count ions pion_num=0.0D0 nion_num=0.0D0 pion_numzp=0.0D0 nion_numzp=0.0D0 pion_numzn=0.0D0 nion_numzn=0.0D0 pion_nummb=0.0D0 nion_nummb=0.0D0 do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen do ig=1,nclx iii=(ig-1)*ncyz+kg do 101 jg=1,ncly ip0=iii+(jg-1)*nclz if(mcden(ip0).ne.0.0d0) then phif=phi(ip0)*factor1 if(vmemb.ne.0.0d0)then zc=(kg-1)*dcel if(zc.gt.zmemb2) phif=phif-vmemb*factor1 endif if(Qnonlinear) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*exp(+phif) elseif(Qpartlinear) then if(phif.gt.0.0d0) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*exp(+phif) endif else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) endif pion_num=pion_num+pfactor nion_num=nion_num+nfactor if(zz.ge.0.0d0) then pion_numzp=pion_numzp+pfactor nion_numzp=nion_numzp+nfactor else pion_numzn=pion_numzn+pfactor nion_numzn=nion_numzn+nfactor endif endif 101 enddo enddo enddo c write(outu,'(6x,a)') write(outu,'(6x,a,f13.5,a)') $ 'Ion accessible volume :',volume, $ ' [Angs**3]' write(outu,'(6x,a,f13.5,a)') $ 'Bulk density :',bulk_rho, $ ' [unit charge]/[Angs**3]' write(outu,'(6x,a,f13.5,a)') $ 'Bulk number of counter ions :',bulk_num, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of positive ions :',pion_num, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of positive ions (Z > 0) :',pion_numzp, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of positive ions (Z < 0) :',pion_numzn, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of negative ions :',nion_num, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of negative ions (Z > 0) :',nion_numzp, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of negative ions (Z < 0) :',nion_numzn, $ ' [unit charge]' c Counter Ion Distributions write(outu,'(6x,a)') write(outu,'(6x,2a)') 'Integrated number of ions along Z : ', $ '[unit charge]' write(outu,'(6x,a)') write(outu,'(11x,a,7x,a,7x,a,7x,a)') $ 'Z','AREA','+ ION','- ION' do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen pion_num=0.0D0 nion_num=0.0D0 area=0.0d0 do ig=1,nclx iii=(ig-1)*ncyz+kg do jg=1,ncly ip0=iii+(jg-1)*nclz if(mcden(ip0).ne.0.0d0) then area=area+1.0d0 phif=phi(ip0)*factor1 if(vmemb.ne.0.0d0)then zc=(kg-1)*dcel if(zc.gt.zmemb2) phif=phif-vmemb*factor1 endif if(Qnonlinear) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*exp(+phif) elseif(Qpartlinear) then if(phif.gt.0.0d0) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*exp(+phif) endif else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) endif pion_num=pion_num+pfactor nion_num=nion_num+nfactor endif enddo enddo write(outu,'(6x,2f10.3,2x,2(e11.4,2x))') $ zz,area*dcel2,pion_num,nion_num enddo write(outu,'(6x,a)') write(outu,'(6x,2a)') $ 'Density Profile based on ion-accessible area along Z : ', $ '[unit charge]/[A^3]' write(outu,'(6x,a)') write(outu,'(11x,a,7x,a,7x,a,7x,a)') $ 'Z','AREA','+ ION','- ION' do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen pion_num=0.0D0 nion_num=0.0D0 area=0.0d0 do ig=1,nclx iii=(ig-1)*ncyz+kg do jg=1,ncly ip0=iii+(jg-1)*nclz if(mcden(ip0).ne.0.0d0) then area=area+1.0d0 phif=phi(ip0)*factor1 if(vmemb.ne.0.0d0)then zc=(kg-1)*dcel if(zc.gt.zmemb2) phif=phif-vmemb*factor1 endif if(Qnonlinear) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*exp(+phif) elseif(Qpartlinear) then if(phif.gt.0.0d0) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*exp(+phif) endif else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) endif pion_num=pion_num+pfactor nion_num=nion_num+nfactor endif enddo enddo write(outu,'(6x,2f10.3,2x,2(e11.4,2x))') $ zz,area*dcel2, $ pion_num/(area*dcel3+rsmall),nion_num/(area*dcel3+rsmall) enddo write(outu,'(6x,a)') write(outu,'(6x,2a)') $ 'Density Profile based on system area along Z : ', $ '[unit charge]/[A^3]' write(outu,'(6x,a)') write(outu,'(11x,a,7x,a,7x,a,7x,a)') $ 'Z','AREA','+ ION','- ION' area=nclx*ncly do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen pion_num=0.0D0 nion_num=0.0D0 do ig=1,nclx iii=(ig-1)*ncyz+kg zz=(kg-1)*dcel-tranz+zbcen do jg=1,ncly ip0=iii+(jg-1)*nclz if(mcden(ip0).ne.0.0d0) then phif=phi(ip0)*factor1 if(vmemb.ne.0.0d0)then zc=(kg-1)*dcel if(zc.gt.zmemb2) phif=phif-vmemb*factor1 endif if(Qnonlinear) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*exp(+phif) elseif(Qpartlinear) then if(phif.gt.0.0d0) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*exp(+phif) endif else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) endif pion_num=pion_num+pfactor nion_num=nion_num+nfactor endif enddo enddo write(outu,'(6x,2f10.3,2x,2(e11.4,2x))') $ zz,area*dcel2, $ pion_num/(area*dcel3+rsmall),nion_num/(area*dcel3+rsmall) enddo c RETURN END SUBROUTINE COUNTERION2(NCLX,NCLY,NCLZ,DCEL,PHI,MCDEN, $ VMEMB,TMEMB,ZMEMB,CONC,TEMP, $ TRANX,TRANY,TRANZ,XBCEN,YBCEN,ZBCEN, $ rsphe,xsphe,ysphe,zsphe,rdist, $ Qnonlinear,Qpartlinear) c----------------------------------------------------------------------- c This subroutine computes the number of counter ions c implicit none include 'mainio.fcm' include 'consta.fcm' integer*4 NCLX,NCLY,NCLZ real*8 dcel,conc,temp,tranx,trany,tranz,xbcen,ybcen,zbcen real*8 rsphe,xsphe,ysphe,zsphe,rdist real*8 vmemb,tmemb,zmemb real*4 phi(*),mcden(*) logical*1 Qnonlinear,Qpartlinear c local real*8 factor1 real*8 bulk_num,volume,nion_num,pion_num,bulk_rho real*8 nion_numzp,pion_numzp,nion_numzn,pion_numzn real*8 nion_nummb,pion_nummb,nfactor,pfactor,area real*8 dcel2,dcel3,zz,zc,zmemb2,phif integer*4 ip0,nc3,ncyz,ig,jg,kg,iii real*8 zmaxsphe,zminsphe,rsphe2,xx,yy,r2,rdist2 c ncyz=ncly*nclz nc3=nclx*ncly*nclz dcel2=dcel*dcel dcel3=dcel2*dcel zmemb2=tranz-zbcen+0.5d0*tmemb+zmemb+rsmall zmaxsphe= rsphe+zsphe zminsphe=-rsphe+zsphe rsphe2 = rsphe*rsphe rdist2 = rdist*rdist c conversion factoer from 1/(kcal/(mol*e)) to 1/(e/A) factor1 = celec / ( kboltz * Temp / kcalmol) c calculate ion accessible volume volume=0.0D0 do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen if((zz.gt.zmaxsphe.or.zz.lt.zminsphe).and.rdist.eq.0.0d0) $ goto 1001 do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz yy=(jg-1)*dcel-trany+ybcen if(mcden(ip0).ne.0.0d0) then if(rsphe.gt.0.0d0) then r2=xx*xx+yy*yy+zz*zz if(r2.le.rsphe2) volume=volume+dcel3 goto 101 endif if(rdist.gt.0.0d0) then r2=xx*xx+yy*yy if(r2.le.rdist2) volume=volume+dcel3 goto 101 endif endif 101 enddo enddo 1001 enddo c bulk density and number of counter ions bulk_rho=conc*(avogadro/liter)*(angstrom**3) ! [unit charge]/A^3 bulk_num=bulk_rho*volume c deviation from bulk number of count ions pion_num=0.0D0 nion_num=0.0D0 pion_numzp=0.0D0 nion_numzp=0.0D0 pion_numzn=0.0D0 nion_numzn=0.0D0 pion_nummb=0.0D0 nion_nummb=0.0D0 do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen if((zz.gt.zmaxsphe.or.zz.lt.zminsphe).and.rdist.eq.0.0d0) $ goto 1002 do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz yy=(jg-1)*dcel-trany+ybcen if(mcden(ip0).ne.0.0d0) then if(rsphe.gt.0.0d0) then r2=xx*xx+yy*yy+zz*zz if(r2.gt.rsphe2) goto 102 endif if(rdist.gt.0.0d0) then r2=xx*xx+yy*yy if(r2.gt.rdist2) goto 102 endif phif=phi(ip0)*factor1 if(vmemb.ne.0.0d0)then zc=(kg-1)*dcel if(zc.gt.zmemb2) phif=phif-vmemb*factor1 endif if(Qnonlinear) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*exp(+phif) elseif(Qpartlinear) then if(phif.gt.0.0d0) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*exp(+phif) endif else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) endif pion_num=pion_num+pfactor nion_num=nion_num+nfactor if(zz.ge.0.0d0) then pion_numzp=pion_numzp+pfactor nion_numzp=nion_numzp+nfactor else pion_numzn=pion_numzn+pfactor nion_numzn=nion_numzn+nfactor endif endif 102 enddo enddo 1002 enddo c write(outu,'(6x,a)') write(outu,'(6x,a,f13.5,a)') $ 'Ion accessible volume :',volume, $ ' [Angs**3]' write(outu,'(6x,a,f13.5,a)') $ 'Bulk density :',bulk_rho, $ ' [unit charge]/[Angs**3]' write(outu,'(6x,a,f13.5,a)') $ 'Bulk number of counter ions :',bulk_num, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of positive ions :',pion_num, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of positive ions (Z > 0) :',pion_numzp, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of positive ions (Z < 0) :',pion_numzn, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of negative ions :',nion_num, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of negative ions (Z > 0) :',nion_numzp, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of negative ions (Z < 0) :',nion_numzn, $ ' [unit charge]' c Counter Ion Distributions write(outu,'(6x,a)') write(outu,'(6x,2a)') 'Integrated number of ions along Z : ', $ '[unit charge]' write(outu,'(6x,a)') write(outu,'(11x,a,7x,a,7x,a,7x,a)') $ 'Z','AREA','+ ION','- ION' do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen if((zz.gt.zmaxsphe.or.zz.lt.zminsphe).and.rdist.eq.0.0d0) $ goto 1003 pion_num=0.0D0 nion_num=0.0D0 area=0.0d0 do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz yy=(jg-1)*dcel-trany+ybcen if(mcden(ip0).ne.0.0d0) then if(rsphe.gt.0.0d0) then r2=xx*xx+yy*yy+zz*zz if(r2.gt.rsphe2) goto 103 endif if(rdist.gt.0.0d0) then r2=xx*xx+yy*yy if(r2.gt.rdist2) goto 103 endif area=area+1.0d0 phif=phi(ip0)*factor1 if(vmemb.ne.0.0d0)then zc=(kg-1)*dcel if(zc.gt.zmemb2) phif=phif-vmemb*factor1 endif if(Qnonlinear) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*exp(+phif) elseif(Qpartlinear) then if(phif.gt.0.0d0) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*exp(+phif) endif else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) endif pion_num=pion_num+pfactor nion_num=nion_num+nfactor endif 103 enddo enddo write(outu,'(6x,2f10.3,2x,2(e11.4,2x))') $ zz,area*dcel2,pion_num,nion_num 1003 enddo write(outu,'(6x,a)') write(outu,'(6x,2a)') $ 'Density Profile based on ion-accessible area along Z : ', $ '[unit charge]/[A^3]' write(outu,'(6x,a)') write(outu,'(11x,a,7x,a,7x,a,7x,a)') $ 'Z','AREA','+ ION','- ION' do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen if((zz.gt.zmaxsphe.or.zz.lt.zminsphe).and.rdist.eq.0.0d0) $ goto 1004 pion_num=0.0D0 nion_num=0.0D0 area=0.0d0 do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz yy=(jg-1)*dcel-trany+ybcen if(mcden(ip0).ne.0.0d0) then if(rsphe.gt.0.0d0) then r2=xx*xx+yy*yy+zz*zz if(r2.gt.rsphe2) goto 104 endif if(rdist.gt.0.0d0) then r2=xx*xx+yy*yy if(r2.gt.rdist2) goto 104 endif area=area+1.0d0 phif=phi(ip0)*factor1 if(vmemb.ne.0.0d0)then zc=(kg-1)*dcel if(zc.gt.zmemb2) phif=phif-vmemb*factor1 endif if(Qnonlinear) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*exp(+phif) elseif(Qpartlinear) then if(phif.gt.0.0d0) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*exp(+phif) endif else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) endif pion_num=pion_num+pfactor nion_num=nion_num+nfactor endif 104 enddo enddo write(outu,'(6x,2f10.3,2x,2(e11.4,2x))') $ zz,area*dcel2, $ pion_num/(area*dcel3+rsmall),nion_num/(area*dcel3+rsmall) 1004 enddo write(outu,'(6x,a)') write(outu,'(6x,2a)') $ 'Density Profile based on system area along Z : ', $ '[unit charge]/[A^3]' write(outu,'(6x,a)') write(outu,'(11x,a,7x,a,7x,a,7x,a)') $ 'Z','AREA','+ ION','- ION' do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen if((zz.gt.zmaxsphe.or.zz.lt.zminsphe).and.rdist.eq.0.0d0) $ goto 1005 area=0.0d0 pion_num=0.0D0 nion_num=0.0D0 do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz yy=(jg-1)*dcel-trany+ybcen if(mcden(ip0).ne.0.0d0) then if(rsphe.gt.0.0d0) then r2=xx*xx+yy*yy+zz*zz if(r2.gt.rsphe2) goto 105 endif if(rdist.gt.0.0d0) then r2=xx*xx+yy*yy if(r2.gt.rdist2) goto 105 endif area=area+1.0d0 phif=phi(ip0)*factor1 if(vmemb.ne.0.0d0)then zc=(kg-1)*dcel if(zc.gt.zmemb2) phif=phif-vmemb*factor1 endif if(Qnonlinear) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*exp(+phif) elseif(Qpartlinear) then if(phif.gt.0.0d0) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*exp(+phif) endif else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) endif pion_num=pion_num+pfactor nion_num=nion_num+nfactor endif 105 enddo enddo write(outu,'(6x,2f10.3,2x,2(e11.4,2x))') $ zz,area*dcel2, $ pion_num/(area*dcel3+rsmall),nion_num/(area*dcel3+rsmall) 1005 enddo c RETURN END SUBROUTINE PORIN(NCLX,NCLY,NCLZ,DCEL,PHI,MCDEN, $ VMEMB,TMEMB,ZMEMB,CONC,TEMP, $ TRANX,TRANY,TRANZ,XBCEN,YBCEN,ZBCEN, $ Qnonlinear,Qpartlinear) c----------------------------------------------------------------------- c This subroutine computes the number of counter ions c implicit none include 'mainio.fcm' include 'consta.fcm' integer*4 NCLX,NCLY,NCLZ real*8 dcel,conc,temp,tranx,trany,tranz,xbcen,ybcen,zbcen real*8 vmemb,tmemb,zmemb real*4 phi(*),mcden(*) logical*1 Qnonlinear,Qpartlinear c local real*8 factor1 real*8 bulk_num,volume,nion_num,pion_num,bulk_rho real*8 nion_numzp,pion_numzp,nion_numzn,pion_numzn real*8 nion_nummb,pion_nummb,nfactor,pfactor,area real*8 dcel2,dcel3,zz,zc,zmemb2,phif integer*4 ip0,nc3,ncyz,ig,jg,kg,iii real*8 xx,yy real*8 area1,area2,area3 real*8 minarea1,minarea2,minarea3 real*8 minzz1,minzz2,minzz3 real*8 xave1,yave1,rave1,cost1,sint1 real*8 xave2,yave2,rave2,cost2,sint2 real*8 xave3,yave3,rave3,cost3,sint3 real*8 r2,xnew,ynew,ellip1,ellip2,ellip3 c ncyz=ncly*nclz nc3=nclx*ncly*nclz dcel2=dcel*dcel dcel3=dcel2*dcel zmemb2=tranz-zbcen+0.5d0*tmemb+zmemb+rsmall c c pore1 xave1 = 21.600829d0 yave1 = -7.021551d0 rave1 = sqrt(xave1*xave1+yave1*yave1) cost1 = xave1/rave1 sint1 = yave1/rave1 rave1 = rave1 - 3.0d0 xave1 = rave1*cost1 yave1 = rave1*sint1 c pore2 xave2 =-16.881256d0 yave2 =-15.196091d0 rave2 = sqrt(xave2*xave2+yave2*yave2) cost2 = xave2/rave2 sint2 = yave2/rave2 rave2 = rave2 - 3.0d0 xave2 = rave2*cost2 yave2 = rave2*sint2 c pore3 xave3 = -4.719573d0 yave3 = 22.217642d0 rave3 = sqrt(xave3*xave3+yave3*yave3) cost3 = xave3/rave3 sint3 = yave3/rave3 rave3 = rave3 - 3.0d0 xave3 = rave3*cost3 yave3 = rave3*sint3 c conversion factoer from 1/(kcal/(mol*e)) to 1/(e/A) factor1 = celec / ( kboltz * Temp / kcalmol) c calculate ion accessible volume volume=0.0D0 minarea1=10000.0d0 minarea2=10000.0d0 minarea3=10000.0d0 do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen if(zz.gt.16.0d0.or.zz.lt.-16.0d0) goto 1001 area1=0.0D0 area2=0.0D0 area3=0.0D0 do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz yy=(jg-1)*dcel-trany+ybcen if(mcden(ip0).ne.0.0d0) then c pore1 xnew = (xx-xave1)*cost1+(yy-yave1)*sint1 ynew = (yy-yave1)*cost1-(xx-xave1)*sint1 ellip1= xnew*xnew/225d0 + ynew*ynew/324d0 c pore2 xnew = (xx-xave2)*cost2+(yy-yave2)*sint2 ynew = (yy-yave2)*cost2-(xx-xave2)*sint2 ellip2= xnew*xnew/225d0 + ynew*ynew/324d0 c pore3 xnew = (xx-xave3)*cost3+(yy-yave3)*sint3 ynew = (yy-yave3)*cost3-(xx-xave3)*sint3 ellip3= xnew*xnew/225d0 + ynew*ynew/324d0 c common pore r2=xx*xx+yy*yy if(ellip1.le.1.0d0) area1=area1+1.0d0 if(ellip2.le.1.0d0) area2=area2+1.0d0 if(ellip3.le.1.0d0) area3=area3+1.0d0 if(ellip1.gt.1.0d0.and. $ ellip2.gt.1.0d0.and. $ ellip3.gt.1.0d0.and.r2.gt.20.0d0) then mcden(ip0)=0.0d0 else volume=volume+dcel3 endif endif enddo enddo if(area1.lt.minarea1) then minarea1=area1 minzz1=zz endif if(area2.lt.minarea2) then minarea2=area2 minzz2=zz endif if(area3.lt.minarea3) then minarea3=area3 minzz3=zz endif write(71,'(6x,4f10.3)') $ zz,area1*dcel2,area2*dcel2,area3*dcel2 1001 enddo write(72,'(6x,6f10.3)') minzz1,minarea1*dcel2, $ minzz2,minarea2*dcel2,minzz3,minarea3*dcel2 c bulk density and number of counter ions bulk_rho=conc*(avogadro/liter)*(angstrom**3) ! [unit charge]/A^3 bulk_num=bulk_rho*volume c deviation from bulk number of count ions pion_num=0.0D0 nion_num=0.0D0 pion_numzp=0.0D0 nion_numzp=0.0D0 pion_numzn=0.0D0 nion_numzn=0.0D0 pion_nummb=0.0D0 nion_nummb=0.0D0 do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen if(zz.gt.16.0d0.or.zz.lt.-16.0d0) goto 1002 do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz yy=(jg-1)*dcel-trany+ybcen if(mcden(ip0).ne.0.0d0) then c pore1 xnew = (xx-xave1)*cost1+(yy-yave1)*sint1 ynew = (yy-yave1)*cost1-(xx-xave1)*sint1 ellip1= xnew*xnew/225d0 + ynew*ynew/324d0 c pore2 xnew = (xx-xave2)*cost2+(yy-yave2)*sint2 ynew = (yy-yave2)*cost2-(xx-xave2)*sint2 ellip2= xnew*xnew/225d0 + ynew*ynew/324d0 c pore3 xnew = (xx-xave3)*cost3+(yy-yave3)*sint3 ynew = (yy-yave3)*cost3-(xx-xave3)*sint3 ellip3= xnew*xnew/225d0 + ynew*ynew/324d0 c common pore r2=xx*xx+yy*yy if(ellip1.gt.1.0d0.and. $ ellip2.gt.1.0d0.and. $ ellip3.gt.1.0d0.and.r2.gt.20.0d0) goto 102 phif=phi(ip0)*factor1 if(vmemb.ne.0.0d0)then zc=(kg-1)*dcel if(zc.gt.zmemb2) phif=phif-vmemb*factor1 endif if(Qnonlinear) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*exp(+phif) elseif(Qpartlinear) then if(phif.gt.0.0d0) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*exp(+phif) endif else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) endif pion_num=pion_num+pfactor nion_num=nion_num+nfactor if(zz.ge.0.0d0) then pion_numzp=pion_numzp+pfactor nion_numzp=nion_numzp+nfactor else pion_numzn=pion_numzn+pfactor nion_numzn=nion_numzn+nfactor endif endif 102 enddo enddo 1002 enddo c write(outu,'(6x,a)') write(outu,'(6x,a,f13.5,a)') $ 'Ion accessible volume :',volume, $ ' [Angs**3]' write(outu,'(6x,a,f13.5,a)') $ 'Bulk density :',bulk_rho, $ ' [unit charge]/[Angs**3]' write(outu,'(6x,a,f13.5,a)') $ 'Bulk number of counter ions :',bulk_num, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of positive ions :',pion_num, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of positive ions (Z > 0) :',pion_numzp, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of positive ions (Z < 0) :',pion_numzn, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of negative ions :',nion_num, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of negative ions (Z > 0) :',nion_numzp, $ ' [unit charge]' write(outu,'(6x,a,f13.5,a)') $ 'Number of negative ions (Z < 0) :',nion_numzn, $ ' [unit charge]' c Counter Ion Distributions write(outu,'(6x,a)') write(outu,'(6x,2a)') 'Integrated number of ions along Z : ', $ '[unit charge]' write(outu,'(6x,a)') write(outu,'(11x,a,7x,a,7x,a,7x,a)') $ 'Z','AREA','+ ION','- ION' do kg=1,nclz zz=(kg-1)*dcel-tranz+zbcen if(zz.gt.16.0d0.or.zz.lt.-16.0d0) goto 1003 pion_num=0.0D0 nion_num=0.0D0 area=0.0d0 do ig=1,nclx iii=(ig-1)*ncyz+kg xx=(ig-1)*dcel-tranx+xbcen do jg=1,ncly ip0=iii+(jg-1)*nclz yy=(jg-1)*dcel-trany+ybcen r2=xx*xx+yy*yy+zz*zz if(mcden(ip0).ne.0.0d0) then c pore1 xnew = (xx-xave1)*cost1+(yy-yave1)*sint1 ynew = (yy-yave1)*cost1-(xx-xave1)*sint1 ellip1= xnew*xnew/225d0 + ynew*ynew/324d0 c pore2 xnew = (xx-xave2)*cost2+(yy-yave2)*sint2 ynew = (yy-yave2)*cost2-(xx-xave2)*sint2 ellip2= xnew*xnew/225d0 + ynew*ynew/324d0 c pore3 xnew = (xx-xave3)*cost3+(yy-yave3)*sint3 ynew = (yy-yave3)*cost3-(xx-xave3)*sint3 ellip3= xnew*xnew/225d0 + ynew*ynew/324d0 c common pore r2=xx*xx+yy*yy if(ellip1.gt.1.0d0.and. $ ellip2.gt.1.0d0.and. $ ellip3.gt.1.0d0.and.r2.gt.20.0d0) goto 103 area=area+1.0d0 phif=phi(ip0)*factor1 if(vmemb.ne.0.0d0)then zc=(kg-1)*dcel if(zc.gt.zmemb2) phif=phif-vmemb*factor1 endif if(Qnonlinear) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*exp(+phif) elseif(Qpartlinear) then if(phif.gt.0.0d0) then pfactor=bulk_rho*dcel3*exp(-phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*exp(+phif) endif else pfactor=bulk_rho*dcel3*(1.0d0 - phif) nfactor=bulk_rho*dcel3*(1.0d0 + phif) endif pion_num=pion_num+pfactor nion_num=nion_num+nfactor endif 103 enddo enddo write(outu,'(6x,2f10.3,2x,4(e11.4,2x))') $ zz,area*dcel2,pion_num,nion_num,pion_num/3.0d0,nion_num/3.0d0 1003 enddo c RETURN END
gpl-3.0
trankmichael/scipy
scipy/linalg/src/id_dist/src/idz_qrpiv.f
128
26268
c this file contains the following user-callable routines: c c c routine idzp_qrpiv computes the pivoted QR decomposition c of a matrix via Householder transformations, c stopping at a specified precision of the decomposition. c c routine idzr_qrpiv computes the pivoted QR decomposition c of a matrix via Householder transformations, c stopping at a specified rank of the decomposition. c c routine idz_qmatvec applies to a single vector c the Q matrix (or its adjoint) in the QR decomposition c of a matrix, as described by the output of idzp_qrpiv or c idzr_qrpiv. If you're concerned about efficiency and want c to apply Q (or its adjoint) to multiple vectors, c use idz_qmatmat instead. c c routine idz_qmatmat applies c to multiple vectors collected together c as a matrix the Q matrix (or its adjoint) c in the QR decomposition of a matrix, as described c by the output of idzp_qrpiv. If you don't want to provide c a work array and want to apply Q (or its adjoint) c to a single vector, use idz_qmatvec instead. c c routine idz_qinqr reconstructs the Q matrix c in a QR decomposition from the data generated by idzp_qrpiv c or idzr_qrpiv. c c routine idz_permmult multiplies together a bunch c of permutations. c c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c c c c subroutine idz_permmult(m,ind,n,indprod) c c multiplies together the series of permutations in ind. c c input: c m -- length of ind c ind(k) -- number of the slot with which to swap c the k^th slot c n -- length of indprod and indprodinv c c output: c indprod -- product of the permutations in ind, c with the permutation swapping 1 and ind(1) c taken leftmost in the product, c that swapping 2 and ind(2) taken next leftmost, c ..., that swapping krank and ind(krank) c taken rightmost; indprod(k) is the number c of the slot with which to swap the k^th slot c in the product permutation c implicit none integer m,n,ind(m),indprod(n),k,iswap c c do k = 1,n indprod(k) = k enddo ! k c do k = m,1,-1 c c Swap indprod(k) and indprod(ind(k)). c iswap = indprod(k) indprod(k) = indprod(ind(k)) indprod(ind(k)) = iswap c enddo ! k c c return end c c c c subroutine idz_qinqr(m,n,a,krank,q) c c constructs the matrix q from idzp_qrpiv or idzr_qrpiv c (see the routine idzp_qrpiv or idzr_qrpiv c for more information). c c input: c m -- first dimension of a; also, right now, q is m x m c n -- second dimension of a c a -- matrix output by idzp_qrpiv or idzr_qrpiv c (and denoted the same there) c krank -- numerical rank output by idzp_qrpiv or idzr_qrpiv c (and denoted the same there) c c output: c q -- unitary matrix implicitly specified by the data in a c from idzp_qrpiv or idzr_qrpiv c c Note: c Right now, this routine simply multiplies c one after another the krank Householder matrices c in the full QR decomposition of a, c in order to obtain the complete m x m Q factor in the QR. c This routine should instead use the following c (more elaborate but more efficient) scheme c to construct a q dimensioned q(krank,m); this scheme c was introduced by Robert Schreiber and Charles Van Loan c in "A Storage-Efficient _WY_ Representation c for Products of Householder Transformations," c _SIAM Journal on Scientific and Statistical Computing_, c Vol. 10, No. 1, pp. 53-57, January, 1989: c c Theorem 1. Suppose that Q = _1_ + YTY^* is c an m x m unitary matrix, c where Y is an m x k matrix c and T is a k x k upper triangular matrix. c Suppose also that P = _1_ - 2 v v^* is c a Householder matrix and Q_+ = QP, c where v is an m x 1 real vector, c normalized so that v^* v = 1. c Then, Q_+ = _1_ + Y_+ T_+ Y_+^*, c where Y_+ = (Y v) is the m x (k+1) matrix c formed by adjoining v to the right of Y, c ( T z ) c and T_+ = ( ) is c ( 0 -2 ) c the (k+1) x (k+1) upper triangular matrix c formed by adjoining z to the right of T c and the vector (0 ... 0 -2) with k zeroes below (T z), c where z = -2 T Y^* v. c c Now, suppose that A is a (rank-deficient) matrix c whose complete QR decomposition has c the blockwise partioned form c ( Q_11 Q_12 ) ( R_11 R_12 ) ( Q_11 ) c A = ( ) ( ) = ( ) (R_11 R_12). c ( Q_21 Q_22 ) ( 0 0 ) ( Q_21 ) c Then, the only blocks of the orthogonal factor c in the above QR decomposition of A that matter are c ( Q_11 ) c Q_11 and Q_21, _i.e._, only the block of columns ( ) c ( Q_21 ) c interests us. c Suppose in addition that Q_11 is a k x k matrix, c Q_21 is an (m-k) x k matrix, and that c ( Q_11 Q_12 ) c ( ) = _1_ + YTY^*, as in Theorem 1 above. c ( Q_21 Q_22 ) c Then, Q_11 = _1_ + Y_1 T Y_1^* c and Q_21 = Y_2 T Y_1^*, c where Y_1 is the k x k matrix and Y_2 is the (m-k) x k matrix c ( Y_1 ) c so that Y = ( ). c ( Y_2 ) c c So, you can calculate T and Y via the above recursions, c and then use these to compute the desired Q_11 and Q_21. c c implicit none integer m,n,krank,j,k,mm,ifrescal real*8 scal complex*16 a(m,n),q(m,m) c c c Zero all of the entries of q. c do k = 1,m do j = 1,m q(j,k) = 0 enddo ! j enddo ! k c c c Place 1's along the diagonal of q. c do k = 1,m q(k,k) = 1 enddo ! k c c c Apply the krank Householder transformations stored in a. c do k = krank,1,-1 do j = k,m mm = m-k+1 ifrescal = 1 if(k .lt. m) call idz_houseapp(mm,a(k+1,k),q(k,j), 1 ifrescal,scal,q(k,j)) enddo ! j enddo ! k c c return end c c c c subroutine idz_qmatvec(ifadjoint,m,n,a,krank,v) c c applies to a single vector the Q matrix (or its adjoint) c which the routine idzp_qrpiv or idzr_qrpiv has stored c in a triangle of the matrix it produces (stored, incidentally, c as data for applying a bunch of Householder reflections). c Use the routine idz_qmatmat to apply the Q matrix c (or its adjoint) c to a bunch of vectors collected together as a matrix, c if you're concerned about efficiency. c c input: c ifadjoint -- set to 0 for applying Q; c set to 1 for applying the adjoint of Q c m -- first dimension of a and length of v c n -- second dimension of a c a -- data describing the qr decomposition of a matrix, c as produced by idzp_qrpiv or idzr_qrpiv c krank -- numerical rank c v -- vector to which Q (or its adjoint) is to be applied c c output: c v -- vector to which Q (or its adjoint) has been applied c implicit none save integer m,n,krank,k,ifrescal,mm,ifadjoint real*8 scal complex*16 a(m,n),v(m) c c ifrescal = 1 c c if(ifadjoint .eq. 0) then c do k = krank,1,-1 mm = m-k+1 if(k .lt. m) call idz_houseapp(mm,a(k+1,k),v(k), 1 ifrescal,scal,v(k)) enddo ! k c endif c c if(ifadjoint .eq. 1) then c do k = 1,krank mm = m-k+1 if(k .lt. m) call idz_houseapp(mm,a(k+1,k),v(k), 1 ifrescal,scal,v(k)) enddo ! k c endif c c return end c c c c subroutine idz_qmatmat(ifadjoint,m,n,a,krank,l,b,work) c c applies to a bunch of vectors collected together as a matrix c the Q matrix (or its adjoint) which the routine idzp_qrpiv c or idzr_qrpiv has stored in a triangle of the matrix c it produces (stored, incidentally, as data c for applying a bunch of Householder reflections). c Use the routine idz_qmatvec to apply the Q matrix c (or its adjoint) c to a single vector, if you'd rather not provide a work array. c c input: c ifadjoint -- set to 0 for applying Q; c set to 1 for applying the adjoint of Q c m -- first dimension of both a and b c n -- second dimension of a c a -- data describing the qr decomposition of a matrix, c as produced by idzp_qrpiv or idzr_qrpiv c krank -- numerical rank c l -- second dimension of b c b -- matrix to which Q (or its adjoint) is to be applied c c output: c b -- matrix to which Q (or its adjoint) has been applied c c work: c work -- must be at least krank real*8 elements long c implicit none save integer l,m,n,krank,j,k,ifrescal,mm,ifadjoint real*8 work(krank) complex*16 a(m,n),b(m,l) c c if(ifadjoint .eq. 0) then c c c Handle the first iteration, j = 1, c calculating all scals (ifrescal = 1). c ifrescal = 1 c j = 1 c do k = krank,1,-1 if(k .lt. m) then mm = m-k+1 call idz_houseapp(mm,a(k+1,k),b(k,j),ifrescal, 1 work(k),b(k,j)) endif enddo ! k c c if(l .gt. 1) then c c Handle the other iterations, j > 1, c using the scals just computed (ifrescal = 0). c ifrescal = 0 c do j = 2,l c do k = krank,1,-1 if(k .lt. m) then mm = m-k+1 call idz_houseapp(mm,a(k+1,k),b(k,j),ifrescal, 1 work(k),b(k,j)) endif enddo ! k c enddo ! j c endif ! j .gt. 1 c c endif ! ifadjoint .eq. 0 c c if(ifadjoint .eq. 1) then c c c Handle the first iteration, j = 1, c calculating all scals (ifrescal = 1). c ifrescal = 1 c j = 1 c do k = 1,krank if(k .lt. m) then mm = m-k+1 call idz_houseapp(mm,a(k+1,k),b(k,j),ifrescal, 1 work(k),b(k,j)) endif enddo ! k c c if(l .gt. 1) then c c Handle the other iterations, j > 1, c using the scals just computed (ifrescal = 0). c ifrescal = 0 c do j = 2,l c do k = 1,krank if(k .lt. m) then mm = m-k+1 call idz_houseapp(mm,a(k+1,k),b(k,j),ifrescal, 1 work(k),b(k,j)) endif enddo ! k c enddo ! j c endif ! j .gt. 1 c c endif ! ifadjoint .eq. 1 c c return end c c c c subroutine idzp_qrpiv(eps,m,n,a,krank,ind,ss) c c computes the pivoted QR decomposition c of the matrix input into a, using Householder transformations, c _i.e._, transforms the matrix a from its input value in c to the matrix out with entry c c m c out(j,indprod(k)) = Sigma q(l,j) * in(l,k), c l=1 c c for all j = 1, ..., krank, and k = 1, ..., n, c c where in = the a from before the routine runs, c out = the a from after the routine runs, c out(j,k) = 0 when j > k (so that out is triangular), c q(1:m,1), ..., q(1:m,krank) are orthonormal, c indprod is the product of the permutations given by ind, c (as computable via the routine permmult, c with the permutation swapping 1 and ind(1) taken leftmost c in the product, that swapping 2 and ind(2) taken next leftmost, c ..., that swapping krank and ind(krank) taken rightmost), c and with the matrix out satisfying c c krank c in(j,k) = Sigma q(j,l) * out(l,indprod(k)) + epsilon(j,k), c l=1 c c for all j = 1, ..., m, and k = 1, ..., n, c c for some matrix epsilon such that c the root-sum-square of the entries of epsilon c <= the root-sum-square of the entries of in * eps. c Well, technically, this routine outputs the Householder vectors c (or, rather, their second through last entries) c in the part of a that is supposed to get zeroed, that is, c in a(j,k) with m >= j > k >= 1. c c input: c eps -- relative precision of the resulting QR decomposition c m -- first dimension of a and q c n -- second dimension of a c a -- matrix whose QR decomposition gets computed c c output: c a -- triangular (R) factor in the QR decompositon c of the matrix input into the same storage locations, c with the Householder vectors stored in the part of a c that would otherwise consist entirely of zeroes, that is, c in a(j,k) with m >= j > k >= 1 c krank -- numerical rank c ind(k) -- index of the k^th pivot vector; c the following code segment will correctly rearrange c the product b of q and the upper triangle of out c so that b matches the input matrix in c to relative precision eps: c c copy the non-rearranged product of q and out into b c set k to krank c [start of loop] c swap b(1:m,k) and b(1:m,ind(k)) c decrement k by 1 c if k > 0, then go to [start of loop] c c work: c ss -- must be at least n real*8 words long c c _N.B._: This routine outputs the Householder vectors c (or, rather, their second through last entries) c in the part of a that is supposed to get zeroed, that is, c in a(j,k) with m >= j > k >= 1. c c reference: c Golub and Van Loan, "Matrix Computations," 3rd edition, c Johns Hopkins University Press, 1996, Chapter 5. c implicit none integer n,m,ind(n),krank,k,j,kpiv,mm,nupdate,ifrescal real*8 ss(n),eps,ssmax,scal,ssmaxin,rswap,feps complex*16 a(m,n),cswap c c feps = .1d-16 c c c Compute the sum of squares of the entries in each column of a, c the maximum of all such sums, and find the first pivot c (column with the greatest such sum). c ssmax = 0 kpiv = 1 c do k = 1,n c ss(k) = 0 do j = 1,m ss(k) = ss(k)+a(j,k)*conjg(a(j,k)) enddo ! j c if(ss(k) .gt. ssmax) then ssmax = ss(k) kpiv = k endif c enddo ! k c ssmaxin = ssmax c nupdate = 0 c c c While ssmax > eps**2*ssmaxin, krank < m, and krank < n, c do the following block of code, c which ends at the statement labeled 2000. c krank = 0 1000 continue c if(ssmax .le. eps**2*ssmaxin 1 .or. krank .ge. m .or. krank .ge. n) goto 2000 krank = krank+1 c c mm = m-krank+1 c c c Perform the pivoting. c ind(krank) = kpiv c c Swap a(1:m,krank) and a(1:m,kpiv). c do j = 1,m cswap = a(j,krank) a(j,krank) = a(j,kpiv) a(j,kpiv) = cswap enddo ! j c c Swap ss(krank) and ss(kpiv). c rswap = ss(krank) ss(krank) = ss(kpiv) ss(kpiv) = rswap c c if(krank .lt. m) then c c c Compute the data for the Householder transformation c which will zero a(krank+1,krank), ..., a(m,krank) c when applied to a, replacing a(krank,krank) c with the first entry of the result of the application c of the Householder matrix to a(krank:m,krank), c and storing entries 2 to mm of the Householder vector c in a(krank+1,krank), ..., a(m,krank) c (which otherwise would get zeroed upon application c of the Householder transformation). c call idz_house(mm,a(krank,krank),a(krank,krank), 1 a(krank+1,krank),scal) ifrescal = 0 c c c Apply the Householder transformation c to the lower right submatrix of a c with upper leftmost entry at position (krank,krank+1). c if(krank .lt. n) then do k = krank+1,n call idz_houseapp(mm,a(krank+1,krank),a(krank,k), 1 ifrescal,scal,a(krank,k)) enddo ! k endif c c c Update the sums-of-squares array ss. c do k = krank,n ss(k) = ss(k)-a(krank,k)*conjg(a(krank,k)) enddo ! k c c c Find the pivot (column with the greatest sum of squares c of its entries). c ssmax = 0 kpiv = krank+1 c if(krank .lt. n) then c do k = krank+1,n c if(ss(k) .gt. ssmax) then ssmax = ss(k) kpiv = k endif c enddo ! k c endif ! krank .lt. n c c c Recompute the sums-of-squares and the pivot c when ssmax first falls below c sqrt((1000*feps)^2) * ssmaxin c and when ssmax first falls below c ((1000*feps)^2) * ssmaxin. c if( 1 (ssmax .lt. sqrt((1000*feps)**2) * ssmaxin 2 .and. nupdate .eq. 0) .or. 3 (ssmax .lt. ((1000*feps)**2) * ssmaxin 4 .and. nupdate .eq. 1) 5 ) then c nupdate = nupdate+1 c ssmax = 0 kpiv = krank+1 c if(krank .lt. n) then c do k = krank+1,n c ss(k) = 0 do j = krank+1,m ss(k) = ss(k)+a(j,k)*conjg(a(j,k)) enddo ! j c if(ss(k) .gt. ssmax) then ssmax = ss(k) kpiv = k endif c enddo ! k c endif ! krank .lt. n c endif c c endif ! krank .lt. m c c goto 1000 2000 continue c c return end c c c c subroutine idzr_qrpiv(m,n,a,krank,ind,ss) c c computes the pivoted QR decomposition c of the matrix input into a, using Householder transformations, c _i.e._, transforms the matrix a from its input value in c to the matrix out with entry c c m c out(j,indprod(k)) = Sigma q(l,j) * in(l,k), c l=1 c c for all j = 1, ..., krank, and k = 1, ..., n, c c where in = the a from before the routine runs, c out = the a from after the routine runs, c out(j,k) = 0 when j > k (so that out is triangular), c q(1:m,1), ..., q(1:m,krank) are orthonormal, c indprod is the product of the permutations given by ind, c (as computable via the routine permmult, c with the permutation swapping 1 and ind(1) taken leftmost c in the product, that swapping 2 and ind(2) taken next leftmost, c ..., that swapping krank and ind(krank) taken rightmost), c and with the matrix out satisfying c c min(m,n,krank) c in(j,k) = Sigma q(j,l) * out(l,indprod(k)) c l=1 c c + epsilon(j,k), c c for all j = 1, ..., m, and k = 1, ..., n, c c for some matrix epsilon whose norm is (hopefully) minimized c by the pivoting procedure. c Well, technically, this routine outputs the Householder vectors c (or, rather, their second through last entries) c in the part of a that is supposed to get zeroed, that is, c in a(j,k) with m >= j > k >= 1. c c input: c m -- first dimension of a and q c n -- second dimension of a c a -- matrix whose QR decomposition gets computed c krank -- desired rank of the output matrix c (please note that if krank > m or krank > n, c then the rank of the output matrix will be c less than krank) c c output: c a -- triangular (R) factor in the QR decompositon c of the matrix input into the same storage locations, c with the Householder vectors stored in the part of a c that would otherwise consist entirely of zeroes, that is, c in a(j,k) with m >= j > k >= 1 c ind(k) -- index of the k^th pivot vector; c the following code segment will correctly rearrange c the product b of q and the upper triangle of out c so that b matches the input matrix in c to relative precision eps: c c copy the non-rearranged product of q and out into b c set k to krank c [start of loop] c swap b(1:m,k) and b(1:m,ind(k)) c decrement k by 1 c if k > 0, then go to [start of loop] c c work: c ss -- must be at least n real*8 words long c c _N.B._: This routine outputs the Householder vectors c (or, rather, their second through last entries) c in the part of a that is supposed to get zeroed, that is, c in a(j,k) with m >= j > k >= 1. c c reference: c Golub and Van Loan, "Matrix Computations," 3rd edition, c Johns Hopkins University Press, 1996, Chapter 5. c implicit none integer n,m,ind(n),krank,k,j,kpiv,mm,nupdate,ifrescal, 1 loops,loop real*8 ss(n),ssmax,scal,ssmaxin,rswap,feps complex*16 a(m,n),cswap c c feps = .1d-16 c c c Compute the sum of squares of the entries in each column of a, c the maximum of all such sums, and find the first pivot c (column with the greatest such sum). c ssmax = 0 kpiv = 1 c do k = 1,n c ss(k) = 0 do j = 1,m ss(k) = ss(k)+a(j,k)*conjg(a(j,k)) enddo ! j c if(ss(k) .gt. ssmax) then ssmax = ss(k) kpiv = k endif c enddo ! k c ssmaxin = ssmax c nupdate = 0 c c c Set loops = min(krank,m,n). c loops = krank if(m .lt. loops) loops = m if(n .lt. loops) loops = n c do loop = 1,loops c c mm = m-loop+1 c c c Perform the pivoting. c ind(loop) = kpiv c c Swap a(1:m,loop) and a(1:m,kpiv). c do j = 1,m cswap = a(j,loop) a(j,loop) = a(j,kpiv) a(j,kpiv) = cswap enddo ! j c c Swap ss(loop) and ss(kpiv). c rswap = ss(loop) ss(loop) = ss(kpiv) ss(kpiv) = rswap c c if(loop .lt. m) then c c c Compute the data for the Householder transformation c which will zero a(loop+1,loop), ..., a(m,loop) c when applied to a, replacing a(loop,loop) c with the first entry of the result of the application c of the Householder matrix to a(loop:m,loop), c and storing entries 2 to mm of the Householder vector c in a(loop+1,loop), ..., a(m,loop) c (which otherwise would get zeroed upon application c of the Householder transformation). c call idz_house(mm,a(loop,loop),a(loop,loop), 1 a(loop+1,loop),scal) ifrescal = 0 c c c Apply the Householder transformation c to the lower right submatrix of a c with upper leftmost entry at position (loop,loop+1). c if(loop .lt. n) then do k = loop+1,n call idz_houseapp(mm,a(loop+1,loop),a(loop,k), 1 ifrescal,scal,a(loop,k)) enddo ! k endif c c c Update the sums-of-squares array ss. c do k = loop,n ss(k) = ss(k)-a(loop,k)*conjg(a(loop,k)) enddo ! k c c c Find the pivot (column with the greatest sum of squares c of its entries). c ssmax = 0 kpiv = loop+1 c if(loop .lt. n) then c do k = loop+1,n c if(ss(k) .gt. ssmax) then ssmax = ss(k) kpiv = k endif c enddo ! k c endif ! loop .lt. n c c c Recompute the sums-of-squares and the pivot c when ssmax first falls below c sqrt((1000*feps)^2) * ssmaxin c and when ssmax first falls below c ((1000*feps)^2) * ssmaxin. c if( 1 (ssmax .lt. sqrt((1000*feps)**2) * ssmaxin 2 .and. nupdate .eq. 0) .or. 3 (ssmax .lt. ((1000*feps)**2) * ssmaxin 4 .and. nupdate .eq. 1) 5 ) then c nupdate = nupdate+1 c ssmax = 0 kpiv = loop+1 c if(loop .lt. n) then c do k = loop+1,n c ss(k) = 0 do j = loop+1,m ss(k) = ss(k)+a(j,k)*conjg(a(j,k)) enddo ! j c if(ss(k) .gt. ssmax) then ssmax = ss(k) kpiv = k endif c enddo ! k c endif ! loop .lt. n c endif c c endif ! loop .lt. m c c enddo ! loop c c return end
bsd-3-clause
eiselekd/gcc
libgfortran/generated/_conjg_c4.F90
9
1460
! Copyright (C) 2002-2017 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_COMPLEX_4) elemental function _gfortran_specific__conjg_4 (parm) complex (kind=4), intent (in) :: parm complex (kind=4) :: _gfortran_specific__conjg_4 _gfortran_specific__conjg_4 = conjg (parm) end function #endif
gpl-2.0
trankmichael/scipy
scipy/interpolate/fitpack/fpgrre.f
115
10174
subroutine fpgrre(ifsx,ifsy,ifbx,ifby,x,mx,y,my,z,mz,kx,ky,tx,nx, * ty,ny,p,c,nc,fp,fpx,fpy,mm,mynx,kx1,kx2,ky1,ky2,spx,spy,right,q, * ax,ay,bx,by,nrx,nry) c .. c ..scalar arguments.. real*8 p,fp integer ifsx,ifsy,ifbx,ifby,mx,my,mz,kx,ky,nx,ny,nc,mm,mynx, * kx1,kx2,ky1,ky2 c ..array arguments.. real*8 x(mx),y(my),z(mz),tx(nx),ty(ny),c(nc),spx(mx,kx1),spy(my,ky *1) * ,right(mm),q(mynx),ax(nx,kx2),bx(nx,kx2),ay(ny,ky2),by(ny,ky2), * fpx(nx),fpy(ny) integer nrx(mx),nry(my) c ..local scalars.. real*8 arg,cos,fac,pinv,piv,sin,term,one,half integer i,ibandx,ibandy,ic,iq,irot,it,iz,i1,i2,i3,j,k,k1,k2,l, * l1,l2,ncof,nk1x,nk1y,nrold,nroldx,nroldy,number,numx,numx1, * numy,numy1,n1 c ..local arrays.. real*8 h(7) c ..subroutine references.. c fpback,fpbspl,fpgivs,fpdisc,fprota c .. c the b-spline coefficients of the smoothing spline are calculated as c the least-squares solution of the over-determined linear system of c equations (ay) c (ax)' = q where c c | (spx) | | (spy) | c (ax) = | ---------- | (ay) = | ---------- | c | (1/p) (bx) | | (1/p) (by) | c c | z ' 0 | c q = | ------ | c | 0 ' 0 | c c with c : the (ny-ky-1) x (nx-kx-1) matrix which contains the c b-spline coefficients. c z : the my x mx matrix which contains the function values. c spx,spy: the mx x (nx-kx-1) and my x (ny-ky-1) observation c matrices according to the least-squares problems in c the x- and y-direction. c bx,by : the (nx-2*kx-1) x (nx-kx-1) and (ny-2*ky-1) x (ny-ky-1) c matrices which contain the discontinuity jumps of the c derivatives of the b-splines in the x- and y-direction. one = 1 half = 0.5 nk1x = nx-kx1 nk1y = ny-ky1 if(p.gt.0.) pinv = one/p c it depends on the value of the flags ifsx,ifsy,ifbx and ifby and on c the value of p whether the matrices (spx),(spy),(bx) and (by) still c must be determined. if(ifsx.ne.0) go to 50 c calculate the non-zero elements of the matrix (spx) which is the c observation matrix according to the least-squares spline approximat- c ion problem in the x-direction. l = kx1 l1 = kx2 number = 0 do 40 it=1,mx arg = x(it) 10 if(arg.lt.tx(l1) .or. l.eq.nk1x) go to 20 l = l1 l1 = l+1 number = number+1 go to 10 20 call fpbspl(tx,nx,kx,arg,l,h) do 30 i=1,kx1 spx(it,i) = h(i) 30 continue nrx(it) = number 40 continue ifsx = 1 50 if(ifsy.ne.0) go to 100 c calculate the non-zero elements of the matrix (spy) which is the c observation matrix according to the least-squares spline approximat- c ion problem in the y-direction. l = ky1 l1 = ky2 number = 0 do 90 it=1,my arg = y(it) 60 if(arg.lt.ty(l1) .or. l.eq.nk1y) go to 70 l = l1 l1 = l+1 number = number+1 go to 60 70 call fpbspl(ty,ny,ky,arg,l,h) do 80 i=1,ky1 spy(it,i) = h(i) 80 continue nry(it) = number 90 continue ifsy = 1 100 if(p.le.0.) go to 120 c calculate the non-zero elements of the matrix (bx). if(ifbx.ne.0 .or. nx.eq.2*kx1) go to 110 call fpdisc(tx,nx,kx2,bx,nx) ifbx = 1 c calculate the non-zero elements of the matrix (by). 110 if(ifby.ne.0 .or. ny.eq.2*ky1) go to 120 call fpdisc(ty,ny,ky2,by,ny) ifby = 1 c reduce the matrix (ax) to upper triangular form (rx) using givens c rotations. apply the same transformations to the rows of matrix q c to obtain the my x (nx-kx-1) matrix g. c store matrix (rx) into (ax) and g into q. 120 l = my*nk1x c initialization. do 130 i=1,l q(i) = 0. 130 continue do 140 i=1,nk1x do 140 j=1,kx2 ax(i,j) = 0. 140 continue l = 0 nrold = 0 c ibandx denotes the bandwidth of the matrices (ax) and (rx). ibandx = kx1 do 270 it=1,mx number = nrx(it) 150 if(nrold.eq.number) go to 180 if(p.le.0.) go to 260 ibandx = kx2 c fetch a new row of matrix (bx). n1 = nrold+1 do 160 j=1,kx2 h(j) = bx(n1,j)*pinv 160 continue c find the appropriate column of q. do 170 j=1,my right(j) = 0. 170 continue irot = nrold go to 210 c fetch a new row of matrix (spx). 180 h(ibandx) = 0. do 190 j=1,kx1 h(j) = spx(it,j) 190 continue c find the appropriate column of q. do 200 j=1,my l = l+1 right(j) = z(l) 200 continue irot = number c rotate the new row of matrix (ax) into triangle. 210 do 240 i=1,ibandx irot = irot+1 piv = h(i) if(piv.eq.0.) go to 240 c calculate the parameters of the givens transformation. call fpgivs(piv,ax(irot,1),cos,sin) c apply that transformation to the rows of matrix q. iq = (irot-1)*my do 220 j=1,my iq = iq+1 call fprota(cos,sin,right(j),q(iq)) 220 continue c apply that transformation to the columns of (ax). if(i.eq.ibandx) go to 250 i2 = 1 i3 = i+1 do 230 j=i3,ibandx i2 = i2+1 call fprota(cos,sin,h(j),ax(irot,i2)) 230 continue 240 continue 250 if(nrold.eq.number) go to 270 260 nrold = nrold+1 go to 150 270 continue c reduce the matrix (ay) to upper triangular form (ry) using givens c rotations. apply the same transformations to the columns of matrix g c to obtain the (ny-ky-1) x (nx-kx-1) matrix h. c store matrix (ry) into (ay) and h into c. ncof = nk1x*nk1y c initialization. do 280 i=1,ncof c(i) = 0. 280 continue do 290 i=1,nk1y do 290 j=1,ky2 ay(i,j) = 0. 290 continue nrold = 0 c ibandy denotes the bandwidth of the matrices (ay) and (ry). ibandy = ky1 do 420 it=1,my number = nry(it) 300 if(nrold.eq.number) go to 330 if(p.le.0.) go to 410 ibandy = ky2 c fetch a new row of matrix (by). n1 = nrold+1 do 310 j=1,ky2 h(j) = by(n1,j)*pinv 310 continue c find the appropiate row of g. do 320 j=1,nk1x right(j) = 0. 320 continue irot = nrold go to 360 c fetch a new row of matrix (spy) 330 h(ibandy) = 0. do 340 j=1,ky1 h(j) = spy(it,j) 340 continue c find the appropiate row of g. l = it do 350 j=1,nk1x right(j) = q(l) l = l+my 350 continue irot = number c rotate the new row of matrix (ay) into triangle. 360 do 390 i=1,ibandy irot = irot+1 piv = h(i) if(piv.eq.0.) go to 390 c calculate the parameters of the givens transformation. call fpgivs(piv,ay(irot,1),cos,sin) c apply that transformation to the colums of matrix g. ic = irot do 370 j=1,nk1x call fprota(cos,sin,right(j),c(ic)) ic = ic+nk1y 370 continue c apply that transformation to the columns of matrix (ay). if(i.eq.ibandy) go to 400 i2 = 1 i3 = i+1 do 380 j=i3,ibandy i2 = i2+1 call fprota(cos,sin,h(j),ay(irot,i2)) 380 continue 390 continue 400 if(nrold.eq.number) go to 420 410 nrold = nrold+1 go to 300 420 continue c backward substitution to obtain the b-spline coefficients as the c solution of the linear system (ry) c (rx)' = h. c first step: solve the system (ry) (c1) = h. k = 1 do 450 i=1,nk1x call fpback(ay,c(k),nk1y,ibandy,c(k),ny) k = k+nk1y 450 continue c second step: solve the system c (rx)' = (c1). k = 0 do 480 j=1,nk1y k = k+1 l = k do 460 i=1,nk1x right(i) = c(l) l = l+nk1y 460 continue call fpback(ax,right,nk1x,ibandx,right,nx) l = k do 470 i=1,nk1x c(l) = right(i) l = l+nk1y 470 continue 480 continue c calculate the quantities c res(i,j) = (z(i,j) - s(x(i),y(j)))**2 , i=1,2,..,mx;j=1,2,..,my c fp = sumi=1,mx(sumj=1,my(res(i,j))) c fpx(r) = sum''i(sumj=1,my(res(i,j))) , r=1,2,...,nx-2*kx-1 c tx(r+kx) <= x(i) <= tx(r+kx+1) c fpy(r) = sumi=1,mx(sum''j(res(i,j))) , r=1,2,...,ny-2*ky-1 c ty(r+ky) <= y(j) <= ty(r+ky+1) fp = 0. do 490 i=1,nx fpx(i) = 0. 490 continue do 500 i=1,ny fpy(i) = 0. 500 continue nk1y = ny-ky1 iz = 0 nroldx = 0 c main loop for the different grid points. do 550 i1=1,mx numx = nrx(i1) numx1 = numx+1 nroldy = 0 do 540 i2=1,my numy = nry(i2) numy1 = numy+1 iz = iz+1 c evaluate s(x,y) at the current grid point by making the sum of the c cross products of the non-zero b-splines at (x,y), multiplied with c the appropiate b-spline coefficients. term = 0. k1 = numx*nk1y+numy do 520 l1=1,kx1 k2 = k1 fac = spx(i1,l1) do 510 l2=1,ky1 k2 = k2+1 term = term+fac*spy(i2,l2)*c(k2) 510 continue k1 = k1+nk1y 520 continue c calculate the squared residual at the current grid point. term = (z(iz)-term)**2 c adjust the different parameters. fp = fp+term fpx(numx1) = fpx(numx1)+term fpy(numy1) = fpy(numy1)+term fac = term*half if(numy.eq.nroldy) go to 530 fpy(numy1) = fpy(numy1)-fac fpy(numy) = fpy(numy)+fac 530 nroldy = numy if(numx.eq.nroldx) go to 540 fpx(numx1) = fpx(numx1)-fac fpx(numx) = fpx(numx)+fac 540 continue nroldx = numx 550 continue return end
bsd-3-clause
eiselekd/gcc
gcc/testsuite/gfortran.dg/class_optional_1.f90
136
4791
! { dg-do run } ! { dg-options "-fcoarray=single" } ! ! PR fortran/50981 ! PR fortran/54618 ! implicit none type t integer, allocatable :: i end type t type, extends (t):: t2 integer, allocatable :: j end type t2 class(t), allocatable :: xa, xa2(:), xac[:], xa2c(:)[:] class(t), pointer :: xp, xp2(:) xp => null() xp2 => null() call suba(alloc=.false., prsnt=.false.) call suba(xa, alloc=.false., prsnt=.true.) if (.not. allocated (xa)) call abort () if (.not. allocated (xa%i)) call abort () if (xa%i /= 5) call abort () xa%i = -3 call suba(xa, alloc=.true., prsnt=.true.) if (allocated (xa)) call abort () call suba2(alloc=.false., prsnt=.false.) call suba2(xa2, alloc=.false., prsnt=.true.) if (.not. allocated (xa2)) call abort () if (size (xa2) /= 1) call abort () if (.not. allocated (xa2(1)%i)) call abort () if (xa2(1)%i /= 5) call abort () xa2(1)%i = -3 call suba2(xa2, alloc=.true., prsnt=.true.) if (allocated (xa2)) call abort () call subp(alloc=.false., prsnt=.false.) call subp(xp, alloc=.false., prsnt=.true.) if (.not. associated (xp)) call abort () if (.not. allocated (xp%i)) call abort () if (xp%i /= 5) call abort () xp%i = -3 call subp(xp, alloc=.true., prsnt=.true.) if (associated (xp)) call abort () call subp2(alloc=.false., prsnt=.false.) call subp2(xp2, alloc=.false., prsnt=.true.) if (.not. associated (xp2)) call abort () if (size (xp2) /= 1) call abort () if (.not. allocated (xp2(1)%i)) call abort () if (xp2(1)%i /= 5) call abort () xp2(1)%i = -3 call subp2(xp2, alloc=.true., prsnt=.true.) if (associated (xp2)) call abort () call subac(alloc=.false., prsnt=.false.) call subac(xac, alloc=.false., prsnt=.true.) if (.not. allocated (xac)) call abort () if (.not. allocated (xac%i)) call abort () if (xac%i /= 5) call abort () xac%i = -3 call subac(xac, alloc=.true., prsnt=.true.) if (allocated (xac)) call abort () call suba2c(alloc=.false., prsnt=.false.) call suba2c(xa2c, alloc=.false., prsnt=.true.) if (.not. allocated (xa2c)) call abort () if (size (xa2c) /= 1) call abort () if (.not. allocated (xa2c(1)%i)) call abort () if (xa2c(1)%i /= 5) call abort () xa2c(1)%i = -3 call suba2c(xa2c, alloc=.true., prsnt=.true.) if (allocated (xa2c)) call abort () contains subroutine suba2c(x, prsnt, alloc) class(t), optional, allocatable :: x(:)[:] logical prsnt, alloc if (present (x) .neqv. prsnt) call abort () if (prsnt) then if (alloc .neqv. allocated(x)) call abort () if (.not. allocated (x)) then allocate (x(1)[*]) x(1)%i = 5 else if (x(1)%i /= -3) call abort() deallocate (x) end if end if end subroutine suba2c subroutine subac(x, prsnt, alloc) class(t), optional, allocatable :: x[:] logical prsnt, alloc if (present (x) .neqv. prsnt) call abort () if (present (x)) then if (alloc .neqv. allocated(x)) call abort () if (.not. allocated (x)) then allocate (x[*]) x%i = 5 else if (x%i /= -3) call abort() deallocate (x) end if end if end subroutine subac subroutine suba2(x, prsnt, alloc) class(t), optional, allocatable :: x(:) logical prsnt, alloc if (present (x) .neqv. prsnt) call abort () if (prsnt) then if (alloc .neqv. allocated(x)) call abort () if (.not. allocated (x)) then allocate (x(1)) x(1)%i = 5 else if (x(1)%i /= -3) call abort() deallocate (x) end if end if end subroutine suba2 subroutine suba(x, prsnt, alloc) class(t), optional, allocatable :: x logical prsnt, alloc if (present (x) .neqv. prsnt) call abort () if (present (x)) then if (alloc .neqv. allocated(x)) call abort () if (.not. allocated (x)) then allocate (x) x%i = 5 else if (x%i /= -3) call abort() deallocate (x) end if end if end subroutine suba subroutine subp2(x, prsnt, alloc) class(t), optional, pointer :: x(:) logical prsnt, alloc if (present (x) .neqv. prsnt) call abort () if (present (x)) then if (alloc .neqv. associated(x)) call abort () if (.not. associated (x)) then allocate (x(1)) x(1)%i = 5 else if (x(1)%i /= -3) call abort() deallocate (x) end if end if end subroutine subp2 subroutine subp(x, prsnt, alloc) class(t), optional, pointer :: x logical prsnt, alloc if (present (x) .neqv. prsnt) call abort () if (present (x)) then if (alloc .neqv. associated(x)) call abort () if (.not. associated (x)) then allocate (x) x%i = 5 else if (x%i /= -3) call abort() deallocate (x) end if end if end subroutine subp end
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/PR49268.f90
159
1113
! { dg-do run } ! { dg-options "-fcray-pointer" } ! Test the fix for a runtime error ! Contributed by Mike Kumbera <kumbera1@llnl.gov> program bob implicit none integer*8 ipfoo integer n,m,i,j real*8 foo common /ipdata/ ipfoo common /ipsize/ n,m POINTER ( ipfoo, foo(3,7) ) n=3 m=7 ipfoo=malloc(8*n*m) do i=1,n do j=1,m foo(i,j)=1.d0 end do end do call use_foo() end program bob subroutine use_foo() implicit none integer n,m,i,j integer*8 ipfoo common /ipdata/ ipfoo common /ipsize/ n,m real*8 foo,boo !fails if * is the last dimension POINTER ( ipfoo, foo(n,*) ) !works if the last dimension is specified !POINTER ( ipfoo, foo(n,m) ) boo=0.d0 do i=1,n do j=1,m boo=foo(i,j)+1.0 if (abs (boo - 2.0) .gt. 1e-6) call abort end do end do end subroutine use_foo
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/goacc/loop-tree-1.f90
36
1316
! { dg-additional-options "-fdump-tree-original -fdump-tree-gimple -std=f2008" } ! test for tree-dump-original and spaces-commas program test implicit none integer :: i, j, k, m, sum REAL :: a(64), b(64), c(64) !$acc kernels !$acc loop collapse(2) DO i = 1,10 DO j = 1,10 ENDDO ENDDO !$acc loop independent gang (3) DO i = 1,10 !$acc loop worker(3) DO j = 1,10 !$acc loop vector(5) DO k = 1,10 ENDDO ENDDO ENDDO !$acc end kernels sum = 0 !$acc parallel !$acc loop private(m) reduction(+:sum) DO i = 1,10 sum = sum + 1 ENDDO !$acc end parallel end program test ! { dg-final { scan-tree-dump-times "pragma acc loop" 5 "original" } } ! { dg-final { scan-tree-dump-times "collapse\\(2\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "independent" 1 "original" } } ! { dg-final { scan-tree-dump-times "gang\\(num: 3\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "worker\\(3\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "vector\\(5\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "private\\(m\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "reduction\\(\\+:sum\\)" 1 "original" } } ! { dg-final { scan-tree-dump-times "map\\(tofrom:sum \\\[len: \[0-9\]+\\\]\\)" 1 "gimple" } }
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/protected_6.f90
26
1567
! { dg-do compile } ! { dg-shouldfail "Invalid Fortran 2003 code" } ! { dg-options "-std=f2003 -fall-intrinsics" } ! PR fortran/23994 ! ! Test PROTECTED attribute. Within the module everything is allowed. ! Outside (use-associated): For pointers, their association status ! may not be changed. For nonpointers, their value may not be changed. ! ! Test of a invalid code module protmod implicit none integer, Protected :: a integer, protected, target :: at integer, protected, pointer :: ap end module protmod program main use protmod implicit none a = 43 ! { dg-error "variable definition context" } ap => null() ! { dg-error "pointer association context" } nullify(ap) ! { dg-error "pointer association context" } ap => at ! { dg-error "pointer association context" } ap = 3 ! OK allocate(ap) ! { dg-error "pointer association context" } ap = 73 ! OK call increment(a,at) ! { dg-error "variable definition context" } call pointer_assignments(ap) ! { dg-error "pointer association context" } contains subroutine increment(a1,a3) integer, intent(inout) :: a1, a3 a1 = a1 + 1 a3 = a3 + 1 end subroutine increment subroutine pointer_assignments(p) integer, pointer,intent (inout) :: p p => null() end subroutine pointer_assignments end program main module prot2 implicit none contains subroutine bar real, protected :: b ! { dg-error "only allowed in specification part of a module" } end subroutine bar end module prot2 ! { dg-final { cleanup-modules "protmod" } }
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/actual_array_substr_2.f90
188
1570
! { dg-do run } ! Tests the fix for pr28174, in which the fix for pr28118 was ! corrupting the character lengths of arrays that shared a ! character length structure. In addition, in developing the ! fix, it was noted that intent(out/inout) arguments were not ! getting written back to the calling scope. ! ! Based on the testscase by Harald Anlauf <anlauf@gmx.de> ! program pr28174 implicit none character(len=12) :: teststring(2) = (/ "abc def ghij", & "klm nop qrst" /) character(len=12) :: a(2), b(2), c(2), d(2) integer :: m = 7, n a = teststring b = a c = a d = a n = m - 4 ! Make sure that variable substring references work. call foo (a(:)(m:m+5), c(:)(n:m+2), d(:)(5:9)) if (any (a .ne. teststring)) call abort () if (any (b .ne. teststring)) call abort () if (any (c .ne. (/"ab456789#hij", & "kl7654321rst"/))) call abort () if (any (d .ne. (/"abc 23456hij", & "klm 98765rst"/))) call abort () contains subroutine foo (w, x, y) character(len=*), intent(in) :: w(:) character(len=*), intent(inOUT) :: x(:) character(len=*), intent(OUT) :: y(:) character(len=12) :: foostring(2) = (/"0123456789#$" , & "$#9876543210"/) ! This next is not required by the standard but tests the ! functioning of the gfortran implementation. ! if (all (x(:)(3:7) .eq. y)) call abort () x = foostring (:)(5 : 4 + len (x)) y = foostring (:)(3 : 2 + len (y)) end subroutine foo end program pr28174
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/do_1.f90
10
1484
! { dg-do run } ! { dg-options "-Wall" } ! Program to check corner cases for DO statements. program do_1 implicit none integer i, j ! limit=HUGE(i), step > 1 j = 0 do i = HUGE(i) - 10, HUGE(i), 2 j = j + 1 end do if (j .ne. 6) call abort j = 0 do i = HUGE(i) - 9, HUGE(i), 2 j = j + 1 end do if (j .ne. 5) call abort ! Same again, but unknown loop step if (test1(10, 1) .ne. 11) call abort if (test1(10, 2) .ne. 6) call abort if (test1(9, 2) .ne. 5) call abort ! Zero iterations j = 0 do i = 1, 0, 1 ! { dg-warning "executed zero times" } j = j + 1 end do if (j .ne. 0) call abort j = 0 do i = 1, 0, 2 ! { dg-warning "executed zero times" } j = j + 1 end do if (j .ne. 0) call abort j = 0 do i = 1, 2, -1 ! { dg-warning "executed zero times" } j = j + 1 end do if (j .ne. 0) call abort call test2 (0, 1) call test2 (0, 2) call test2 (2, -1) call test2 (2, -2) ! Bound near smallest value j = 0; do i = -HUGE(i), -HUGE(i), 10 j = j + 1 end do if (j .ne. 1) call abort contains ! Returns the number of iterations performed. function test1(r, step) implicit none integer test1, r, step integer k, n k = 0 do n = HUGE(n) - r, HUGE(n), step k = k + 1 end do test1 = k end function subroutine test2 (lim, step) implicit none integer lim, step integer k, n k = 0 do n = 1, lim, step k = k + 1 end do if (k .ne. 0) call abort end subroutine end program
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/char_result_3.f90
188
1934
! Related to PR 15326. Try calling string functions whose lengths involve ! some sort of array calculation. ! { dg-do run } pure elemental function double (x) integer, intent (in) :: x integer :: double double = x * 2 end function double program main implicit none interface pure elemental function double (x) integer, intent (in) :: x integer :: double end function double end interface integer, dimension (100:104), target :: a integer, dimension (:), pointer :: ap integer :: i, lower a = (/ (i + 5, i = 0, 4) /) ap => a lower = 11 call test (f1 (a), 35) call test (f1 (ap), 35) call test (f1 ((/ 5, 10, 50 /)), 65) call test (f1 (a (101:103)), 21) call test (f2 (a), 115) call test (f2 (ap), 115) call test (f2 ((/ 5, 10, 50 /)), 119) call test (f2 (a (101:103)), 116) call test (f3 (a), 60) call test (f3 (ap), 60) call test (f3 ((/ 5, 10, 50 /)), 120) call test (f3 (a (101:103)), 30) call test (f4 (a, 13, 1), 21) call test (f4 (ap, 13, 2), 14) call test (f4 ((/ 5, 10, 50 /), 12, 1), 60) call test (f4 (a (101:103), 12, 1), 15) contains function f1 (array) integer, dimension (10:) :: array character (len = sum (array)) :: f1 f1 = '' end function f1 function f2 (array) integer, dimension (10:) :: array character (len = array (11) + a (104) + 100) :: f2 f2 = '' end function f2 function f3 (array) integer, dimension (:) :: array character (len = sum (double (array (2:)))) :: f3 f3 = '' end function f3 function f4 (array, upper, stride) integer, dimension (10:) :: array integer :: upper, stride character (len = sum (array (lower:upper:stride))) :: f4 f4 = '' end function f4 subroutine test (string, length) character (len = *) :: string integer, intent (in) :: length if (len (string) .ne. length) call abort end subroutine test end program main
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/assumed_type_1.f90
155
1256
! { dg-do compile } ! ! PR fortran/48820 ! ! Test TYPE(*) ! ! Based on a contributed test case by Walter Spector ! module mpi_interface implicit none interface mpi_send subroutine MPI_Send (buf, count, datatype, dest, tag, comm, ierr) type(*), intent(in) :: buf(:) integer, intent(in) :: count integer, intent(in) :: datatype integer, intent(in) :: dest integer, intent(in) :: tag integer, intent(in) :: comm integer, intent(out):: ierr end subroutine end interface interface mpi_send2 subroutine MPI_Send2 (buf, count, datatype, dest, tag, comm, ierr) type(*), intent(in) :: buf(*) integer, intent(in) :: count integer, intent(in) :: datatype integer, intent(in) :: dest integer, intent(in) :: tag integer, intent(in) :: comm integer, intent(out):: ierr end subroutine end interface end module use mpi_interface real :: a(3) integer :: b(3) call foo(a) call foo(b) call foo(a(1:2)) call foo(b(1:2)) call MPI_Send(a, 1, 1,1,1,j,i) call MPI_Send(b, 1, 1,1,1,j,i) call MPI_Send2(a, 1, 1,1,1,j,i) call MPI_Send2(b, 1, 1,1,1,j,i) contains subroutine foo(x) type(*):: x(*) call MPI_Send2(x, 1, 1,1,1,j,i) end end
gpl-2.0
pablodebiase/bromoc-e_suite
bromoc-e/src/ioxmod.f90
1
1088
! BROMOC-E ! Electrodiffusion, Gran Canonical Monte Carlo, Brownian,Dynamics ! and Coarse Grain Model DNA Simulation Program. ! Copyright (C) 2014 Pablo M. De Biase (pablodebiase@gmail.com) ! ! This program 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. ! ! This program 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. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. module ioxmod ! !.....iox - common block for i/o primitives. ! implicit none integer maxopen parameter (maxopen = 100) ! !.....allocation flag array ! logical*1 alloc (1:maxopen) end module
gpl-3.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/gomp/udr2.f90
119
2306
! { dg-do compile } subroutine f6 !$omp declare reduction (foo:real:omp_out (omp_in)) ! { dg-error "Unclassifiable OpenMP directive" } !$omp declare reduction (bar:real:omp_out = omp_in * omp_out) & ! { dg-error "Unclassifiable OpenMP directive" } !$omp & initializer (omp_priv (omp_orig)) end subroutine f6 subroutine f7 integer :: a !$omp declare reduction (foo:integer:a (omp_out, omp_in)) ! { dg-error "Unclassifiable OpenMP directive" } !$omp declare reduction (bar:real:omp_out = omp_out.or.omp_in) ! { dg-error "Operands of logical operator" } !$omp declare reduction (baz:real:omp_out = omp_out + omp_in) !$omp & initializer (a (omp_priv, omp_orig)) ! { dg-error "Unclassifiable OpenMP directive" } real :: r r = 0.0 !$omp parallel reduction (bar:r) !$omp end parallel end subroutine f7 subroutine f8 interface subroutine f8a (x) integer :: x end subroutine f8a end interface !$omp declare reduction (baz:integer:omp_out = omp_out + omp_in) & !$omp & initializer (f8a (omp_orig)) ! { dg-error "One of actual subroutine arguments in INITIALIZER clause" } !$omp declare reduction (foo:integer:f8a) ! { dg-error "is not a variable" } !$omp declare reduction (bar:integer:omp_out = omp_out - omp_in) & !$omp & initializer (f8a) ! { dg-error "is not a variable" } end subroutine f8 subroutine f9 type dt ! { dg-error "which is not consistent with the CALL" } integer :: x = 0 integer :: y = 0 end type dt integer :: i !$omp declare reduction (foo:integer:dt (omp_out, omp_in)) ! { dg-error "which is not consistent with the CALL" } !$omp declare reduction (bar:integer:omp_out = omp_out + omp_in) & !$omp & initializer (dt (omp_priv, omp_orig)) ! { dg-error "which is not consistent with the CALL" } i = 0 !$omp parallel reduction (foo : i) !$omp end parallel !$omp parallel reduction (bar : i) !$omp end parallel end subroutine f9 subroutine f10 integer :: a, b !$omp declare reduction(foo:character(len=64) & !$omp & :omp_out(a:b) = omp_in(a:b)) ! { dg-error "Variable other than OMP_OUT or OMP_IN used in combiner" } !$omp declare reduction(bar:character(len=16) & !$omp & :omp_out = trim(omp_out) // omp_in) & !$omp & initializer (omp_priv(a:b) = ' ') ! { dg-error "Variable other than OMP_PRIV or OMP_ORIG used in INITIALIZER clause" } end subroutine f10
gpl-2.0
dagss/healpix
src/f90/ngsims_full_sky/sky_ng_sim.F90
4
24999
!----------------------------------------------------------------------------- ! ! Copyright (C) 1997-2013 Krzysztof M. Gorski, Eric Hivon, ! Benjamin D. Wandelt, Anthony J. Banday, ! Matthias Bartelmann, Hans K. Eriksen, ! Frode K. Hansen, Martin Reinecke ! ! ! This file is part of HEALPix. ! ! HEALPix 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 2 of the License, or ! (at your option) any later version. ! ! HEALPix 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. ! ! You should have received a copy of the GNU General Public License ! along with HEALPix; if not, write to the Free Software ! Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ! ! For more information about HEALPix see http://healpix.sourceforge.net ! !----------------------------------------------------------------------------- !****************************************************** ! Sarah Smith (sjm84@mrao.cam.ac.uk) ! and Graca Rocha (graca@mrao.cam.ac.uk) ! June 2004 ! Module sub_ngpdf_sho based on code by Michael ! Hobson and Graca Rocha ! Module sub_ngpdf_powergauss based on code by ! Anthony Challinor ! Please include an appropriate acknowledgement ! in any publications based on work that has ! made use of this package - 'NGsims' !****************************************************** Program sky_ng_sim ! Makes a full-sky non-Gaussian simulation using ! values drawn from pdf made from eigenstates of ! a simple harmonic oscillator or powers of a Gaussian ! Uses Healpix pixelisation and subroutines ! Some of the program is based on the Healpix synfast program USE healpix_types USE alm_tools, ONLY : map2alm_iterative, alm2map, alm2map_der, pow2alm_units USE fitstools, ONLY : read_asctab, write_bintab, dump_alms USE pix_tools, ONLY : nside2npix USE head_fits, ONLY : add_card, merge_headers, get_card, write_minimal_header, del_card ! USE utilities, ONLY : die_alloc use misc_utils, only : wall_clock_time, assert_alloc, brag_openmp, fatal_error USE extension, ONLY : getArgument, nArguments USE paramfile_io, ONLY : paramfile_handle, parse_int, parse_init, & & parse_string, parse_lgt, parse_double, parse_check_unused, & & concatnl, scan_directories, parse_summarize, parse_finish, & & get_healpix_data_dir, get_healpix_test_dir,get_healpix_pixel_window_file USE sub_ngpdf_sho USE sub_ngpdf_powergauss USE sky_sub Implicit none INTEGER(I4B) :: nsmax ! The value of N_{side} in the pixelisation scheme INTEGER(I4B) :: nlmax, lmax ! The maximum l-value used INTEGER(I4B) :: nmmax ! The maximum m-value used (set equal to nlmax) COMPLEX(SPC), DIMENSION(:,:,:), ALLOCATABLE :: alm_T !The a_{lm} values REAL(SP), DIMENSION(:, :), ALLOCATABLE :: map_T !The pixel values in real space REAL(SP), DIMENSION(:,:), ALLOCATABLE :: cl_T !The Cl values REAL(KIND=DP), DIMENSION(:,:), ALLOCATABLE :: w8ring_T REAL(SP), DIMENSION(:,:), ALLOCATABLE :: tmp_2d ! INTEGER(I4B), DIMENSION(8,2) :: values_time ! REAL(SP) :: clock_time real(SP) :: time0, time1, clock_time, ptime0, ptime1, ptime INTEGER(I4B) :: status INTEGER(I4B) npixtot !The total number of pixels CHARACTER(LEN=filenamelen) :: parafile = '' CHARACTER(LEN=filenamelen) :: infile character(len=FILENAMELEN) :: outfile_alms CHARACTER(LEN=filenamelen) :: outfile CHARACTER(LEN=filenamelen) :: windowfile CHARACTER(LEN=filenamelen) :: windowname CHARACTER(LEN=filenamelen) :: def_dir, def_file CHARACTER(LEN=filenamelen) :: usr_dir, usr_file CHARACTER(LEN=filenamelen) :: final_file CHARACTER(LEN=filenamelen) :: healpixtestdir Character(LEN=filenamelen) :: beam_file character(len=filenamelen) :: description character(len=100) :: chline LOGICAL(LGT) :: ok, fitscl, polarisation = .FALSE. logical(LGT) :: do_map, output_alms CHARACTER(LEN=80), DIMENSION(1:180) :: header, header_PS !, header_file CHARACTER(LEN=*), PARAMETER :: code = "sky_ng_sim" character(len=*), parameter :: VERSION = HEALPIX_VERSION character(len=80), dimension(1:1) :: units_power, units_map CHARACTER(LEN=20) :: string_quad ! CHARACTER(LEN=80) :: temptype, com_tt ! REAL(SP) :: quadrupole ! INTEGER(I4B) :: count_tt INTEGER(I4B) nlheader Integer :: i,m, n_pols, n_maps, simul_type, deriv Real(DP) :: sigma0, factor Real(DP),dimension(1:3) :: nu !Added to match with f90 version of shodev_driver !nu(i) is the ith moment of the distribution. !The size of nu is fixed to 3 to prevent problems with passing unallocated arrays Real(DP) :: power, rms_alm, mean Integer :: count, iter_order Integer(I4B) :: pdf_choice !Used to chose type of pdf required logical :: plot ! External shodev_driver Real(SP) :: Tmin, Tmax, convert Integer, parameter :: npts = 1000 Real(SP) :: xline(npts), yline(npts), xstep, xval type(paramfile_handle) :: handle Real(DP) :: fwhm_arcmin Real(SP) :: fwhm_deg Character(len=30) :: xlabel !----------------------------------------------------------------------- ! get input parameters and create arrays !----------------------------------------------------------------------- call wall_clock_time(time0) call cpu_time(ptime0) ! --- read parameters interactively if no command-line arguments ! --- are given, otherwise interpret first command-line argument ! --- as parameter file name and read parameters from it: if (nArguments() == 0) then parafile='' else if (nArguments() /= 1) then print *, " Usage: "//code//" [parameter file name]" call fatal_error() end if call getArgument(1,parafile) end if handle = parse_init(parafile) PRINT *, " " PRINT *," "//code//" "//version Write(*, '(a)') "*** Simulation of a non-Gaussian full-sky temperature map ***" ! --- choose temp. only or temp. + deriv. --- description = concatnl( & & " Do you want to simulate", & & " 1) Temperature only", & !& " 2) Temperature + polarisation", & & " 3) Temperature + 1st derivatives", & & " 4) Temperature + 1st & 2nd derivatives") simul_type = parse_int(handle, 'simul_type', default=1, valid=(/1,3,4/), descr=description) deriv = 0 ! no derivatives if (simul_type == 3) deriv = 1 if (simul_type == 4) deriv = 2 n_pols = 1 n_maps = max(1, 3*deriv) ! --- gets the effective resolution of the sky map --- 3 continue description = concatnl( & & "", & & " Enter the resolution parameter (Nside) for the simulated skymap: ",& & " (Npix = 12*Nside**2, where Nside HAS to be a power of 2, eg: 32, 512, ...)" ) nsmax = parse_int(handle, 'nsmax', default=32, descr=description) if (nside2npix(nsmax) < 0) then print *, " Error: nsmax is not a power of two." if (handle%interactive) goto 3 call fatal_error(code) endif ! --- gets the L range for the simulation --- WRITE(chline,"(a,i5,a)") "We recommend: (0 <= l <= l_max <= ",3*nsmax-1,")" description = concatnl(& & "", & & " Enter the maximum l range (l_max) for the simulation. ", & & chline ) nlmax = parse_int(handle, 'nlmax', default=2*nsmax, descr=description) ! --- get filename for input power spectrum --- chline = '' healpixtestdir = get_healpix_test_dir() if (trim(healpixtestdir)/='') chline = trim(healpixtestdir)//'/cl.fits' description = concatnl( "", & & " Enter input Power Spectrum filename", & & " Can be either in FITS format or in the .dat format produced by CAMB.") infile = parse_string(handle, 'infile', default=chline, descr=description, filestatus='old') ! Find out whether input cl file is a fits file fitscl = (index(infile, '.fits') /= 0) ! --- gets the output sky map filename --- description = concatnl(& & "", & & " Enter Output map file name (eg, test.fits) :", & & " (or !test.fits to overwrite an existing file)" ) outfile = parse_string(handle, "outfile", & default="!test.fits", descr=description, filestatus="new") do_map = (trim(outfile) /= '') ! --- gets the output alm-filename --- description = concatnl(& & "", & & " Enter file name in which to write a_lm used to synthesize the map : ", & & " (eg alm.fits or !alms.fits to overwrite an existing file): ", & & " (If '', the alms are not written to a file) ") outfile_alms = parse_string(handle, 'outfile_alms', & & default="''", descr=description, filestatus='new') output_alms = (trim(outfile_alms) /= '') ! --- gets the fwhm of beam --- description = concatnl(& & "", & & " Enter FWMH of beam in arcminutes (0 for no beam):") fwhm_arcmin = parse_double(handle, "fwhm_arcmin", & default=0d0, descr=description, vmin = 0d0) description = concatnl(& & "", & & " Enter an external file name containing ", & & " a symmetric beam Legendre transform (eg: mybeam.fits)", & & " NB: if set to an existing file, it will override the FWHM chosen above", & & " if set to '', the gaussian FWHM will be used.") beam_file = parse_string(handle, 'beam_file', default="''", & & descr=description, filestatus='old') if (beam_file /= '') then fwhm_arcmin = 0. print*,'fwhm_arcmin is now : 0.' print*,'The beam file '//trim(beam_file)//' will be used instead.' endif ! including pixel window function, EH-2008-03-05 ! --- check for pixel-window-files --- windowname = get_healpix_pixel_window_file(nsmax) def_file = trim(windowname) def_dir = get_healpix_data_dir() 22 continue final_file = '' ok = .false. ! if interactive, try default name in default directories first if (handle%interactive) ok = scan_directories(def_dir, def_file, final_file) if (.not. ok) then ! not found, ask the user description = concatnl("",& & " Could not find window file", & & " Enter the directory where this file can be found:") usr_dir = parse_string(handle,'winfiledir',default='',descr=description) if (trim(usr_dir) == '') usr_dir = trim(def_dir) description = concatnl("",& & " Enter the name of the window file:") usr_file = parse_string(handle,'windowfile',default=def_file,descr=description) ! look for new name in user provided or default directories ok = scan_directories(usr_dir, usr_file, final_file) ! if still fails, crash or ask again if interactive if (.not. ok) then print*,' File not found' if (handle%interactive) goto 22 call fatal_error(code) endif endif windowfile = final_file PRINT *," " !----------------------------------------------------------------------- nmmax = nlmax npixtot = nside2npix(nsmax) !----------------------------------------------------------------------- ! allocates space for arrays !----------------------------------------------------------------------- ! ALLOCATE(units_alm(1:1),units_map(1:1+2*polar),stat = status) ! call assert_alloc(status, code,"units_alm & units_map") ALLOCATE(alm_T(1:1,0:nlmax, 0:nmmax),stat = status) call assert_alloc(status, code,"alm_T") ALLOCATE(map_T(0:npixtot-1, 1:n_maps),stat = status) call assert_alloc(status, code,"map_T") ALLOCATE(w8ring_T(1:2*nsmax,1:1),stat = status) call assert_alloc(status, code,"w8ring_T") ! For now, not using ring weights for quadrature correction w8ring_T = 1.d0 ! single analysis iter_order = 0 ALLOCATE(cl_T(0:nlmax,1:1),stat = status) call assert_alloc(status, code,"cl_T") !------------------------------------------------------------------------ ! Read in the input power spectrum !----------------------------------------------------------------------- cl_T = 0.0 !New lines added 8th June 2004 lmax = nlmax call read_powerspec(infile, nsmax, lmax, cl_T, header_PS, fwhm_arcmin, units_power, beam_file = beam_file, winfile = windowfile) call pow2alm_units(units_power, units_map) call del_card(header_PS, (/ "TUNIT#","TTYPE#"/)) ! remove TUNIT* and TTYPE* from header to avoid confusion later on !------------------------------------------------------------------------ ! Draw pixel values in real space from non-Gaussian distribution !------------------------------------------------------------------------ Write (*,*) "Creating non-Gaussian map with flat power spectrum" ! --- Chose the type of pdf to use --- description = concatnl(& & "", & & " Select non-Gaussian pdf to use: Simple harmonic oscillator (1)", & & "or powers of a Gaussian (2)" ) pdf_choice = parse_int(handle, 'pdf_choice', default=1, vmin = 1, vmax = 2, descr=description) !Write (*,*) "Use SHO pdf (0) or powers of a Gaussian pdf (1) ?" !Read (*,*) m If (pdf_choice .eq. 1) Then call shodev_driver(handle, npixtot, sigma0, map_T(:,1), nu) Else ! call powergauss_driver(npixtot, npixtot, sigma0, map_T, nu) call powergauss_driver(handle, npixtot, sigma0, map_T(:,1), nu) End If print*,'NG map MIN and MAX:',minval(map_T(:,1)),maxval(map_T(:,1)) !Normalise the map If (nu(1) .ge. 0) Then !nu (1) is set to -1 if highest non-zero alpha > 3 ! ie if we can't calculate moments analytically map_T = map_T / sqrt(nu(2)) !Compute the rms value of the pixels power = 0 Do i = 0, npixtot-1 power = power + map_T(i,1)**2 End Do power = Sqrt(power/npixtot) Write (*,*) "rms value of the pixels is ", power Else Write (*,*) "Can't calculate theoretical value of nu(2) to normalise" Write (*,*) "Normalising using rms pixel value instead" Write (*,*) "note - this method may change the statistical properties of the map" !Compute the mean value of the pixels mean = SUM(map_T(:,1)*1.d0)/npixtot Write (*,*) 'Mean pixel value is ',mean,' - adjusting to zero' map_T(:,1) = map_T(:,1) - mean !Compute the rms value of the pixels power = 0 Do i = 0, npixtot-1 power = power + map_T(i,1)**2 End Do power = Sqrt(power/npixtot) Write (*,*) "rms value of the pixels is ", power ," - setting to 1.0" map_T(:,1) = map_T(:,1) / power !Check power = 0 Do i = 0, npixtot-1 power = power + map_T(i,1)**2 End Do power = Sqrt(power/npixtot) Write (*,*) "Now rms value of the pixels is ", power End If !------------------------------------------------------------------------ ! Now compute the a_{lm} values from this distribution !------------------------------------------------------------------------ Write (*,*) "Computing the values of the a_{lm}" ! call map2alm(nsmax, nlmax, nmmax, map_T, alm_T, -1000.d0, w8ring_T) ! call map2alm(nsmax, nlmax, nmmax, map_T, alm_T, (/ 0.d0, 0.d0 /), w8ring_T) call map2alm_iterative(nsmax, nlmax, nmmax, iter_order, map_T(:,1:1), alm_T, w8ring=w8ring_T) !Compute the rms value of the a_{lm} power = 0.0 count = 0 Do i = 1, nlmax power = power + abs(alm_T(1,i,0))**2. count = count + 1 Do m = 1, i power = power + 2.0*abs(alm_T(1,i,m))**2. count = count + 2 End Do End Do rms_alm = sqrt(power/count) Write (*,*) "rms value of the a_{lm} is ",rms_alm factor = sqrt(FOURPI/npixtot) Write (*,*) "Expected rms value is ", factor !------------------------------------------------------------------------ ! Multiply the a_{lm} by the correct power spectrum !------------------------------------------------------------------------ Do i = 1, nlmax !Write (*,*) 'cl(',i,') is ', cl_T(i,1) alm_T(1,i,0:i) = alm_T(1,i,0:i)*sqrt(cl_T(i,1))/factor End Do !------------------------------------------------------------------------ ! Now transform back to a real space map !------------------------------------------------------------------------ select case (deriv) case(0) ! temperature only call alm2map( nsmax,nlmax,nmmax,alm_T,map_T(:,1)) case(1) call alm2map_der(nsmax,nlmax,nmmax,alm_T,map_T(:,1),map_T(:,2:3)) case(2) call alm2map_der(nsmax,nlmax,nmmax,alm_T,map_T(:,1),map_T(:,2:3),map_T(:,4:6)) case default print*,'Not valid case' print*,'Derivatives: ', deriv call fatal_error(code) end select !------------------------------------------------------------------------ ! Plot histogram of pixel distribution (if required) !------------------------------------------------------------------------ #ifdef PGPLOT description = concatnl( "", & & " Plot histogram of pixel values? (True or False)") plot = parse_lgt(handle, 'plot', default=.false., descr=description) ! Write (*,*) 'Plot histrogram of pixel values (0) or not (1)?' ! Read (*,*) m If (plot) Then Tmin = 0.0 Tmax = 0.0 do i=1,npixtot if (map_T(i,1) .lt. Tmin) Tmin=map_T(i,1) if (map_T(i,1) .gt. Tmax) Tmax=map_T(i,1) end do call pgbegin(0,'?',1,1) if (.not. fitscl) then ! If reading in from .dat file Cls are already converted to uK convert = 1.0 xlabel = 'Temperature / \gmK' else if (ABS(cl_T(2,1) - 1.0) .lt. 0.05) then ! If values in fits file are normalised to Cl(2) = 1.0 ! convert to uK for plot, assuming COBE normalisation ! of Qrms = 18uK convert = sqrt(4.0*PI/5.0)*18.0 xlabel = 'Temperature / \gmK' else ! Otherwise, units unknown convert = 1.0 xlabel = 'Pixel value' end if Tmin = Tmin * convert Tmax = Tmax * convert call pghist(npixtot,map_T*convert,Tmin,Tmax,200,0) !Pixel values scaled to convert to uK if input fits file of cl values !which are normalised to C_2 = 1.0 call pglab(xlabel,'Number of pixels','') !Calculate 2*mean square value of T (ie 2 sigma^2) power = 0 Do i = 1, npixtot power = power + map_T(i,1)**2 End Do power = 2 * power*(convert**2) / npixtot xstep=(Tmax-Tmin)/real(npts-1) do i=1,npts xval=Tmin+real(i)*xstep xline(i)=xval yline(i)=exp(-xval**2/power)/sqrt(PI*power) yline(i)=yline(i)*real(npixtot)*(Tmax-Tmin)/200. end do call pgsci(13) call pgline(npts, xline, yline) call pgend End If #endif call parse_check_unused(handle, code=code) call parse_summarize(handle, code=code) call parse_finish(handle) call brag_openmp() !----------------------------------------------------------------------- ! write the alm to FITS file !----------------------------------------------------------------------- if (output_alms) then PRINT *," "//code//"> outputting alms " do i = 1, n_pols header = "" ! put inherited information immediatly, so that keyword values can be updated later on ! by current code values call add_card(header,"COMMENT","****************************************************************") call merge_headers(header_PS, header) ! insert header_PS in header at this point call add_card(header,"COMMENT","****************************************************************") ! start putting information relative to this code and run call write_minimal_header(header, 'alm', append=.true., & creator = CODE, version = VERSION, & nlmax = nlmax, nmmax = nmmax, & !randseed = ioriginseed, & units = units_map(i), polar = polarisation) if (i == 1) then call add_card(header,"EXTNAME","'SIMULATED a_lms (TEMPERATURE)'", update = .true.) elseif (i == 2) then call add_card(header,"EXTNAME","'SIMULATED a_lms (GRAD / ELECTRIC component)'", update = .true.) elseif (i == 3) then call add_card(header,"EXTNAME","'SIMULATED a_lms (CURL / MAGNETIC component)'", update = .true.) endif !if (input_cl) then call add_card(header,"HISTORY","File with input C(l):") call add_card(header,"HISTORY",trim(infile)) call add_card(header,"HISTORY","These alms are multiplied by pixel and beam window functions") call add_card(header,"NSIDE" ,nsmax, "Resolution parameter for HEALPIX") if (trim(beam_file) == '') then call add_card(header,"FWHM" ,fwhm_deg ," [deg] FWHM of gaussian symmetric beam") else call add_card(header,"BEAM_LEG",trim(beam_file), & & "File containing Legendre transform of symmetric beam") endif call add_card(header,"PDF_TYPE",pdf_choice,"1: Harmon. Oscill. ;2: Power of Gauss.") !endif call add_card(header,"HISTORY") nlheader = SIZE(header) call dump_alms (outfile_alms,alm_T(i,0:nlmax,0:nmmax),nlmax,header,nlheader,i-1_i4b) enddo endif !----------------------------------------------------------------------- ! write the map to FITS file !----------------------------------------------------------------------- nlheader = SIZE(header) header = "" PRINT *," "//code//"> Writing sky map to FITS file " ! put inherited information immediatly, so that keyword values can be updated later on ! by current code values call add_card(header,"COMMENT","****************************************************************") call merge_headers(header_PS, header) ! insert header_PS in header at this point call add_card(header,"COMMENT","****************************************************************") ! start putting information relative to this code and run call write_minimal_header(header, 'map', append=.true., & nside = nsmax, ordering = 'RING', & !, coordsys = coordsys, & fwhm_degree = fwhm_arcmin / 60.d0, & beam_leg = trim(beam_file), & polar = polarisation, & deriv = deriv, & creator = CODE, version = VERSION, & nlmax = lmax, & !randseed = ioriginseed, & units = units_map(1) ) !Note using lmax rather than nlmax - lmax will be smaller than nlmax if not enough values ! in input power spectrum file call add_card(header,"PDF_TYPE",pdf_choice,"1: Harmon. Oscill. ;2: Power of Gauss.") call add_card(header,"EXTNAME","'SIMULATED MAP'", update=.true.) call add_card(header,"COMMENT","*************************************") ! allocate(tmp_2d(0:npixtot-1,1:1)) ! tmp_2d(:,1) = map_T ! call write_bintab(tmp_2d, npixtot, 1, header, nlheader, outfile) ! deallocate(tmp_2d) call write_bintab(map_T, npixtot, n_maps, header, nlheader, outfile) !!$ endif !----------------------------------------------------------------------- ! deallocate memory for arrays !----------------------------------------------------------------------- DEALLOCATE( map_T ) DEALLOCATE( alm_T ) ! DEALLOCATE( units_alm, units_map ) !----------------------------------------------------------------------- ! output and report card !----------------------------------------------------------------------- call wall_clock_time(time1) call cpu_time(ptime1) clock_time = time1 - time0 ptime = ptime1 - ptime0 WRITE(*,9000) " " WRITE(*,9000) " Report Card for "//code//" simulation run" WRITE(*,9000) "----------------------------------------" WRITE(*,9000) " " WRITE(*,9000) " Input power spectrum : "//TRIM(infile) WRITE(*,9010) " Multipole range : 0 < l <= ", nlmax WRITE(*,9010) " Number of pixels : ", npixtot ! WRITE(*,9020) " Pixel size in arcmin : ", pix_size_arcmin ! WRITE(*,9010) " Initial random # seed: ", ioriginseed if (trim(beam_file) == '') then write(*,9020) " Gauss. FWHM in arcmin: ", fwhm_arcmin else write(*,9000) " Beam file: "//trim(beam_file) endif WRITE(*,9000) " Output map : "//TRIM(outfile) write(*,9030) " Clock and CPU time [s] : ", clock_time, ptime !----------------------------------------------------------------------- ! end of routine !----------------------------------------------------------------------- WRITE(*,9000) " " WRITE(*,9000) " "//code//"> normal completion" 9000 format(a) 9010 format(a,i16) 9020 format(a,g20.5) 9030 format(a,f11.2,f11.2) Stop End Program sky_ng_sim
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/integer_exponentiation_4.f90
172
1485
! { dg-do compile } ! { dg-options "" } program test implicit none !!!!!! INTEGER BASE !!!!!! print *, 0**0 print *, 0**1 print *, 0**(-1) ! { dg-error "Division by zero" } print *, 0**(huge(0)) print *, 0**(-huge(0)-1) ! { dg-error "Division by zero" } print *, 0**(2_8**32) print *, 0**(-(2_8**32)) ! { dg-error "Division by zero" } print *, 1**huge(0) print *, 1**(-huge(0)-1) print *, 1**huge(0_8) print *, 1**(-huge(0_8)-1_8) print *, (-1)**huge(0) print *, (-1)**(-huge(0)-1) print *, (-1)**huge(0_8) print *, (-1)**(-huge(0_8)-1_8) print *, 2**huge(0) ! { dg-error "Arithmetic overflow" } print *, 2**huge(0_8) ! { dg-error "Arithmetic overflow" } print *, (-2)**huge(0) ! { dg-error "Arithmetic overflow" } print *, (-2)**huge(0_8) ! { dg-error "Arithmetic overflow" } print *, 2**(-huge(0)-1) print *, 2**(-huge(0_8)-1_8) print *, (-2)**(-huge(0)-1) print *, (-2)**(-huge(0_8)-1_8) !!!!!! REAL BASE !!!!!! print *, 0.0**(-1) ! { dg-error "Arithmetic overflow" } print *, 0.0**(-huge(0)-1) ! { dg-error "Arithmetic overflow" } print *, 2.0**huge(0) ! { dg-error "Arithmetic overflow" } print *, nearest(1.0,-1.0)**(-huge(0)) ! { dg-error "Arithmetic overflow" } !!!!!! COMPLEX BASE !!!!!! print *, (2.0,-4.3)**huge(0) ! { dg-error "Arithmetic overflow" } print *, (2.0,-4.3)**huge(0_8) ! { dg-error "Arithmetic overflow" } print *, (2.0,-4.3)**(-huge(0)) print *, (2.0,-4.3)**(-huge(0_8)) end program test
gpl-2.0
eiselekd/gcc
gcc/testsuite/gfortran.dg/graphite/pr68335.f90
46
2800
! { dg-options "-O2 -floop-nest-optimize" } MODULE whittaker INTEGER, PARAMETER :: dp=8 INTEGER, PARAMETER :: maxfac = 30 REAL(KIND=dp), PARAMETER, DIMENSION (-1:2*maxfac+1) :: dfac = (/& 0.10000000000000000000E+01_dp, 0.10000000000000000000E+01_dp, 0.10000000000000000000E+01_dp,& 0.20000000000000000000E+01_dp, 0.30000000000000000000E+01_dp, 0.80000000000000000000E+01_dp,& 0.15000000000000000000E+02_dp, 0.48000000000000000000E+02_dp, 0.10500000000000000000E+03_dp,& 0.38400000000000000000E+03_dp, 0.94500000000000000000E+03_dp, 0.38400000000000000000E+04_dp,& 0.10395000000000000000E+05_dp, 0.46080000000000000000E+05_dp, 0.13513500000000000000E+06_dp,& 0.64512000000000000000E+06_dp, 0.20270250000000000000E+07_dp, 0.10321920000000000000E+08_dp,& 0.34459425000000000000E+08_dp, 0.18579456000000000000E+09_dp, 0.65472907500000000000E+09_dp,& 0.37158912000000000000E+10_dp, 0.13749310575000000000E+11_dp, 0.81749606400000000000E+11_dp,& 0.31623414322500000000E+12_dp, 0.19619905536000000000E+13_dp, 0.79058535806250000000E+13_dp,& 0.51011754393600000000E+14_dp, 0.21345804667687500000E+15_dp, 0.14283291230208000000E+16_dp,& 0.61902833536293750000E+16_dp, 0.42849873690624000000E+17_dp, 0.19189878396251062500E+18_dp,& 0.13711959580999680000E+19_dp, 0.63326598707628506250E+19_dp, 0.46620662575398912000E+20_dp,& 0.22164309547669977187E+21_dp, 0.16783438527143608320E+22_dp, 0.82007945326378915594E+22_dp,& 0.63777066403145711616E+23_dp, 0.31983098677287777082E+24_dp, 0.25510826561258284646E+25_dp,& 0.13113070457687988603E+26_dp, 0.10714547155728479551E+27_dp, 0.56386202968058350995E+27_dp,& 0.47144007485205310027E+28_dp, 0.25373791335626257948E+29_dp, 0.21686243443194442612E+30_dp,& 0.11925681927744341235E+31_dp, 0.10409396852733332454E+32_dp, 0.58435841445947272053E+32_dp,& 0.52046984263666662269E+33_dp, 0.29802279137433108747E+34_dp, 0.27064431817106664380E+35_dp,& 0.15795207942839547636E+36_dp, 0.14614793181237598765E+37_dp, 0.86873643685617511998E+37_dp,& 0.81842841814930553085E+38_dp, 0.49517976900801981839E+39_dp, 0.47468848252659720789E+40_dp,& 0.29215606371473169285E+41_dp, 0.28481308951595832474E+42_dp, 0.17821519886598633264E+43_dp/) CONTAINS SUBROUTINE whittaker_c0 ( wc, r, expa, erfa, alpha, l, n ) INTEGER, INTENT(IN) :: n, l REAL(KIND=dp), INTENT(IN) :: alpha REAL(KIND=dp), DIMENSION(n) :: erfa, expa, r, wc INTEGER :: i, k REAL(dp) :: t1,x SELECT CASE (l) CASE DEFAULT DO i = 1, n DO k = 0, l/2 wc(i) = wc(i) + expa(i)*x**(2*k+1)*t1**(2*k+3)*& dfac(l+1)/dfac(2*k+1)*2**(k+1) END DO END DO END SELECT END SUBROUTINE whittaker_c0 END MODULE whittaker
gpl-2.0
redstar3894/android-gcc-4.6
gcc/testsuite/gfortran.dg/large_real_kind_2.F90
172
2852
! { dg-do run } ! { dg-require-effective-target fortran_large_real } ! { dg-xfail-if "" { "*-*-freebsd*" } { "*" } { "" } } ! Testing library calls on large real kinds (larger than kind=8) implicit none integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1) real(8),parameter :: eps = 1e-8 real(kind=k) :: x, x1 real(8) :: y, y1 complex(kind=k) :: z, z1 complex(8) :: w, w1 #define TEST_FUNCTION(func,val) \ x = val ;\ y = x ;\ x = func (x) ;\ y = func (y) ;\ if (abs((y - x) / y) > eps) call abort #define CTEST_FUNCTION(func,valc) \ z = valc ;\ w = z ;\ z = func (z) ;\ w = func (w) ;\ if (abs((z - w) / w) > eps) call abort TEST_FUNCTION(cos,17.456) TEST_FUNCTION(sin,17.456) TEST_FUNCTION(tan,1.456) TEST_FUNCTION(cosh,-2.45) TEST_FUNCTION(sinh,7.1) TEST_FUNCTION(tanh,12.7) TEST_FUNCTION(acos,0.78) TEST_FUNCTION(asin,-0.24) TEST_FUNCTION(atan,-17.123) TEST_FUNCTION(acosh,0.2) TEST_FUNCTION(asinh,0.3) TEST_FUNCTION(atanh,0.4) TEST_FUNCTION(exp,1.74) TEST_FUNCTION(log,0.00178914) TEST_FUNCTION(log10,123789.123) TEST_FUNCTION(sqrt,789.1356) CTEST_FUNCTION(cos,(17.456,-1.123)) CTEST_FUNCTION(sin,(17.456,-7.6)) CTEST_FUNCTION(exp,(1.74,-1.01)) CTEST_FUNCTION(log,(0.00178914,-1.207)) CTEST_FUNCTION(sqrt,(789.1356,2.4)) #define TEST_POWER(val1,val2) \ x = val1 ; \ y = x ; \ x1 = val2 ; \ y1 = x1; \ if (abs((x**x1 - y**y1)/(y**y1)) > eps) call abort #define CTEST_POWER(val1,val2) \ z = val1 ; \ w = z ; \ z1 = val2 ; \ w1 = z1; \ if (abs((z**z1 - w**w1)/(w**w1)) > eps) call abort CTEST_POWER (1.0,1.0) CTEST_POWER (1.0,5.4) CTEST_POWER (1.0,-5.4) CTEST_POWER (1.0,0.0) CTEST_POWER (-1.0,1.0) CTEST_POWER (-1.0,5.4) CTEST_POWER (-1.0,-5.4) CTEST_POWER (-1.0,0.0) CTEST_POWER (0.0,1.0) CTEST_POWER (0.0,5.4) CTEST_POWER (0.0,-5.4) CTEST_POWER (0.0,0.0) CTEST_POWER (7.6,1.0) CTEST_POWER (7.6,5.4) CTEST_POWER (7.6,-5.4) CTEST_POWER (7.6,0.0) CTEST_POWER (-7.6,1.0) CTEST_POWER (-7.6,5.4) CTEST_POWER (-7.6,-5.4) CTEST_POWER (-7.6,0.0) CTEST_POWER ((10.78,123.213),(14.123,13279.5)) CTEST_POWER ((-10.78,123.213),(14.123,13279.5)) CTEST_POWER ((10.78,-123.213),(14.123,13279.5)) CTEST_POWER ((10.78,123.213),(-14.123,13279.5)) CTEST_POWER ((10.78,123.213),(14.123,-13279.5)) CTEST_POWER ((-10.78,-123.213),(14.123,13279.5)) CTEST_POWER ((-10.78,123.213),(-14.123,13279.5)) CTEST_POWER ((-10.78,123.213),(14.123,-13279.5)) CTEST_POWER ((10.78,-123.213),(-14.123,13279.5)) CTEST_POWER ((10.78,-123.213),(14.123,-13279.5)) CTEST_POWER ((10.78,123.213),(-14.123,-13279.5)) CTEST_POWER ((-10.78,-123.213),(-14.123,13279.5)) CTEST_POWER ((-10.78,-123.213),(14.123,-13279.5)) CTEST_POWER ((-10.78,123.213),(-14.123,-13279.5)) CTEST_POWER ((10.78,-123.213),(-14.123,-13279.5)) CTEST_POWER ((-10.78,-123.213),(-14.123,-13279.5)) end
gpl-2.0
eiselekd/gcc
libgomp/testsuite/libgomp.fortran/examples-4/simd-5.f90
47
1551
! { dg-do run } ! { dg-additional-options "-msse2" { target sse2_runtime } } ! { dg-additional-options "-mavx" { target avx_runtime } } module SIMD5_mod contains subroutine work( a, b, c, n ) implicit none integer :: i,j,n double precision :: a(n,n), b(n,n), c(n,n), tmp !$omp do simd collapse(2) private(tmp) do j = 1,n do i = 1,n tmp = a(i,j) + b(i,j) c(i,j) = tmp end do end do end subroutine work subroutine work_ref( a, b, c, n ) implicit none integer :: i,j,n double precision :: a(n,n), b(n,n), c(n,n), tmp do j = 1,n do i = 1,n tmp = a(i,j) + b(i,j) c(i,j) = tmp end do end do end subroutine work_ref subroutine init (a, b, n) integer :: i,j,n,s double precision :: a(n,n), b(n,n) s = -1 do j = 1,n do i = 1,n a(i,j) = i*j*s b(i,j) = i+j s = -s end do end do end subroutine subroutine check (a, b, n) integer :: i, j, n double precision, parameter :: EPS = 0.0000000000000001 double precision :: diff, a(n,n), b(n,n) do j = 1, n do i = 1, n diff = a(i,j) - b(i,j) if (diff > EPS .or. -diff > EPS) call abort end do end do end subroutine end module program SIMD5 use SIMD5_mod double precision, dimension(32, 32) :: a, b, c, c_ref call init(a, b, 32) call work(a, b, c, 32) call work_ref(a, b, c_ref, 32) call check(c, c_ref, 32) end program
gpl-2.0
laagesen/moose
modules/tensor_mechanics/test/include/materials/abaqus/utility/ROTSIGInterface.f
62
3234
**************************************************************************************** ** UTILITY SUBROUTINE FOR INTERFACE: ROTSIG ** ** CALULATE ROTATED STRESS/STRAIN TENSOR ** **************************************************************************************** ** ROTATED STRESS CALCULATIONS BASED OFF OF "ON THE ROTATED STRESS TENSOR AND THE ** ** MATERIAL VERSION OF THE DOYLE-ERICKSEN FORMULA" BY J. SIMO AND J. MARSDEN ** **************************************************************************************** SUBROUTINE ROTSIG (S, DROT, SPRIME, LSTR, NDI, NSHR) DOUBLE PRECISION S(NDI+NSHR), R(3,3), RINV(3,3), SPRIME(NDI+NSHR), 1 DROT(3,3) INTEGER LSTR, NDI, NSHR C C======================================================================+ C----------- C INPUT : C----------- C DROT : ROTATION INCREMENT MATRIX C S : STRESS OR STRAIN TENSOR TO BE ROTATED C LSTR : FLAG DETERMINING STRESS OR STRAIN CALCULATION C NDI : NUMBER OF DIRECT STRESS/STRAIN COMPONENTS C----------- C OUTPUT : C----------- C SPRIME : ROTATED STRESS/STRAIN TENSOR C----------------------------------------------------------------------+ C======================================================================= C STRESS = ROTATIONMATRIX * ROTATEDSTRESS C ROTATEDSTRESS = ROTATIONMATRIX^-1 * STRESS C RXX = DROT(1,1) RXY = DROT(2,1) RXZ = DROT(3,1) RYX = DROT(1,2) RYY = DROT(2,2) RYZ = DROT(3,2) RZX = DROT(1,3) RZY = DROT(2,3) RZZ = DROT(3,3) C C Calculate Determinant of the rotation matrix C DETR = (RXX*RYY*RZZ)+(RXY*RYZ*RZX)+(RXZ*RYX*RZY)- + (RZX*RYY*RXZ)-(RZY*RYZ*RXX)-(RZZ*RYX*RXY) C C Inverse of determinant C IF (DETR.NE. 0.0) THEN DETINV = 1. / DETR C C Calculate inverse rotation matrix components C RINV(1,1) = +(RYY*RZZ-RZY*RYZ) * DETINV RINV(2,1) = -(RXY*RZZ-RZY*RXZ) * DETINV RINV(3,1) = +(RXY*RYZ-RYY*RXZ) * DETINV RINV(1,2) = -(RYX*RZZ-RZX*RYZ) * DETINV RINV(2,2) = +(RXX*RZZ-RZX*RXZ) * DETINV RINV(3,2) = -(RXX*RYZ-RYX*RXZ) * DETINV RINV(1,3) = +(RYX*RZY-RZX*RYY) * DETINV RINV(2,3) = -(RXX*RZY-RZX*RXY) * DETINV RINV(3,3) = +(RXX*RYY-RYX*RXY) * DETINV C C Calculate rotated stress/strain tensor based on LSTR value C LSTR = 1 for stresses C LSTR = 2 for strains - Equations must be added C IF ((LSTR.EQ.1).OR.(LSTR.EQ.2)) THEN SPRIME(1) = RINV(1,1)*S(1)+RINV(2,1)*S(4)+RINV(3,1)*S(6) SPRIME(2) = RINV(1,2)*S(4)+RINV(2,2)*S(2)+RINV(3,2)*S(5) SPRIME(3) = RINV(1,3)*S(6)+RINV(2,3)*S(5)+RINV(3,3)*S(3) SPRIME(4) = RINV(1,1)*S(4)+RINV(2,1)*S(2)+RINV(3,1)*S(5) SPRIME(5) = RINV(1,2)*S(6)+RINV(2,2)*S(5)+RINV(3,2)*S(3) SPRIME(6) = RINV(1,1)*S(6)+RINV(2,1)*S(5)+RINV(3,1)*S(3) ELSE DO K = 1, NDI+NSHR SPRIME(K) = S(K) END DO END IF ELSE DO K = 1, NDI+NSHR SPRIME(K) = S(K) END DO END IF RETURN END
lgpl-2.1
katyhuff/moose
modules/solid_mechanics/include/materials/abaqus/utility/ROTSIGInterface.f
62
3234
**************************************************************************************** ** UTILITY SUBROUTINE FOR INTERFACE: ROTSIG ** ** CALULATE ROTATED STRESS/STRAIN TENSOR ** **************************************************************************************** ** ROTATED STRESS CALCULATIONS BASED OFF OF "ON THE ROTATED STRESS TENSOR AND THE ** ** MATERIAL VERSION OF THE DOYLE-ERICKSEN FORMULA" BY J. SIMO AND J. MARSDEN ** **************************************************************************************** SUBROUTINE ROTSIG (S, DROT, SPRIME, LSTR, NDI, NSHR) DOUBLE PRECISION S(NDI+NSHR), R(3,3), RINV(3,3), SPRIME(NDI+NSHR), 1 DROT(3,3) INTEGER LSTR, NDI, NSHR C C======================================================================+ C----------- C INPUT : C----------- C DROT : ROTATION INCREMENT MATRIX C S : STRESS OR STRAIN TENSOR TO BE ROTATED C LSTR : FLAG DETERMINING STRESS OR STRAIN CALCULATION C NDI : NUMBER OF DIRECT STRESS/STRAIN COMPONENTS C----------- C OUTPUT : C----------- C SPRIME : ROTATED STRESS/STRAIN TENSOR C----------------------------------------------------------------------+ C======================================================================= C STRESS = ROTATIONMATRIX * ROTATEDSTRESS C ROTATEDSTRESS = ROTATIONMATRIX^-1 * STRESS C RXX = DROT(1,1) RXY = DROT(2,1) RXZ = DROT(3,1) RYX = DROT(1,2) RYY = DROT(2,2) RYZ = DROT(3,2) RZX = DROT(1,3) RZY = DROT(2,3) RZZ = DROT(3,3) C C Calculate Determinant of the rotation matrix C DETR = (RXX*RYY*RZZ)+(RXY*RYZ*RZX)+(RXZ*RYX*RZY)- + (RZX*RYY*RXZ)-(RZY*RYZ*RXX)-(RZZ*RYX*RXY) C C Inverse of determinant C IF (DETR.NE. 0.0) THEN DETINV = 1. / DETR C C Calculate inverse rotation matrix components C RINV(1,1) = +(RYY*RZZ-RZY*RYZ) * DETINV RINV(2,1) = -(RXY*RZZ-RZY*RXZ) * DETINV RINV(3,1) = +(RXY*RYZ-RYY*RXZ) * DETINV RINV(1,2) = -(RYX*RZZ-RZX*RYZ) * DETINV RINV(2,2) = +(RXX*RZZ-RZX*RXZ) * DETINV RINV(3,2) = -(RXX*RYZ-RYX*RXZ) * DETINV RINV(1,3) = +(RYX*RZY-RZX*RYY) * DETINV RINV(2,3) = -(RXX*RZY-RZX*RXY) * DETINV RINV(3,3) = +(RXX*RYY-RYX*RXY) * DETINV C C Calculate rotated stress/strain tensor based on LSTR value C LSTR = 1 for stresses C LSTR = 2 for strains - Equations must be added C IF ((LSTR.EQ.1).OR.(LSTR.EQ.2)) THEN SPRIME(1) = RINV(1,1)*S(1)+RINV(2,1)*S(4)+RINV(3,1)*S(6) SPRIME(2) = RINV(1,2)*S(4)+RINV(2,2)*S(2)+RINV(3,2)*S(5) SPRIME(3) = RINV(1,3)*S(6)+RINV(2,3)*S(5)+RINV(3,3)*S(3) SPRIME(4) = RINV(1,1)*S(4)+RINV(2,1)*S(2)+RINV(3,1)*S(5) SPRIME(5) = RINV(1,2)*S(6)+RINV(2,2)*S(5)+RINV(3,2)*S(3) SPRIME(6) = RINV(1,1)*S(6)+RINV(2,1)*S(5)+RINV(3,1)*S(3) ELSE DO K = 1, NDI+NSHR SPRIME(K) = S(K) END DO END IF ELSE DO K = 1, NDI+NSHR SPRIME(K) = S(K) END DO END IF RETURN END
lgpl-2.1
nguy/AWOT
awot/src/libs/libtmg/gridbox_1d.f
2
1746
SUBROUTINE GRIDBOX_1D(XMIN,DELX,NX,X, $IX_FACE,X_FACE) C Thomas Matejka NOAA/NSSL 28 April 1998 C======================================================================= C This subroutine finds consecutive points in a one-dimensional grid C that enclose a specified coordinate. When the specified coordinate C lies beyond the edge of the grid, the consecutive grid points are C those at the closer edge of the grid. When the grid consists of only C one point, the consecutive grid points are both this point. C Input: C XMIN (real) specifies the minimum grid coordinate. C DELX (real) specifies the grid point spacing. C NX (integer) specifies the number of grid points. C X (real) specifies the coordinate for which to find the enclosing C grid points. C Output: C IX_FACE(1) and IX_FACE(2) (integer) return the smaller and larger C consecutive grid point numbers that enclose X. C X_FACE(1) and X_FACE(2) (real) return the smaller and larger C consecutive grid coordinates that enclose X. C======================================================================= IMPLICIT NONE INTEGER::NX,I INTEGER,DIMENSION(2)::IX_FACE REAL::X,XMIN,DELX,XMAX REAL,DIMENSION(2)::X_FACE IF(NX.GT.1)THEN XMAX=XMIN+DELX*FLOAT(NX-1) IF(X.LE.XMIN)THEN IX_FACE(1)=1 IX_FACE(2)=2 ELSEIF(X.GE.XMAX)THEN IX_FACE(1)=NX-1 IX_FACE(2)=NX ELSE IX_FACE(1)=IFIX((X-XMIN)/DELX)+1 IX_FACE(2)=IX_FACE(1)+1 ENDIF ELSE IX_FACE(1)=1 IX_FACE(2)=1 ENDIF DO I=1,2 X_FACE(I)=XMIN+FLOAT(IX_FACE(I)-1)*DELX ENDDO END SUBROUTINE GRIDBOX_1D
gpl-2.0
tkelman/OpenBLAS
lapack-netlib/SRC/slargv.f
24
4368
*> \brief \b SLARGV generates a vector of plane rotations with real cosines and real sines. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download SLARGV + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slargv.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slargv.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slargv.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE SLARGV( N, X, INCX, Y, INCY, C, INCC ) * * .. Scalar Arguments .. * INTEGER INCC, INCX, INCY, N * .. * .. Array Arguments .. * REAL C( * ), X( * ), Y( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SLARGV generates a vector of real plane rotations, determined by *> elements of the real vectors x and y. For i = 1,2,...,n *> *> ( c(i) s(i) ) ( x(i) ) = ( a(i) ) *> ( -s(i) c(i) ) ( y(i) ) = ( 0 ) *> \endverbatim * * Arguments: * ========== * *> \param[in] N *> \verbatim *> N is INTEGER *> The number of plane rotations to be generated. *> \endverbatim *> *> \param[in,out] X *> \verbatim *> X is REAL array, *> dimension (1+(N-1)*INCX) *> On entry, the vector x. *> On exit, x(i) is overwritten by a(i), for i = 1,...,n. *> \endverbatim *> *> \param[in] INCX *> \verbatim *> INCX is INTEGER *> The increment between elements of X. INCX > 0. *> \endverbatim *> *> \param[in,out] Y *> \verbatim *> Y is REAL array, *> dimension (1+(N-1)*INCY) *> On entry, the vector y. *> On exit, the sines of the plane rotations. *> \endverbatim *> *> \param[in] INCY *> \verbatim *> INCY is INTEGER *> The increment between elements of Y. INCY > 0. *> \endverbatim *> *> \param[out] C *> \verbatim *> C is REAL array, dimension (1+(N-1)*INCC) *> The cosines of the plane rotations. *> \endverbatim *> *> \param[in] INCC *> \verbatim *> INCC is INTEGER *> The increment between elements of C. INCC > 0. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup realOTHERauxiliary * * ===================================================================== SUBROUTINE SLARGV( N, X, INCX, Y, INCY, C, INCC ) * * -- 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 INCC, INCX, INCY, N * .. * .. Array Arguments .. REAL C( * ), X( * ), Y( * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) * .. * .. Local Scalars .. INTEGER I, IC, IX, IY REAL F, G, T, TT * .. * .. Intrinsic Functions .. INTRINSIC ABS, SQRT * .. * .. Executable Statements .. * IX = 1 IY = 1 IC = 1 DO 10 I = 1, N F = X( IX ) G = Y( IY ) IF( G.EQ.ZERO ) THEN C( IC ) = ONE ELSE IF( F.EQ.ZERO ) THEN C( IC ) = ZERO Y( IY ) = ONE X( IX ) = G ELSE IF( ABS( F ).GT.ABS( G ) ) THEN T = G / F TT = SQRT( ONE+T*T ) C( IC ) = ONE / TT Y( IY ) = T*C( IC ) X( IX ) = F*TT ELSE T = F / G TT = SQRT( ONE+T*T ) Y( IY ) = ONE / TT C( IC ) = T*Y( IY ) X( IX ) = G*TT END IF IC = IC + INCC IY = IY + INCY IX = IX + INCX 10 CONTINUE RETURN * * End of SLARGV * END
bsd-3-clause
xavierandrade/fortrancl
testsuite/utils.f90
3
3378
module utils use cl implicit none private public :: & error_exit, & initialize, & build_kernel contains subroutine error_exit(msg, ierr) character(len=*), intent(in) :: msg integer, optional, intent(in) :: ierr write(*,'(a)') msg if(present(ierr)) write(*,'(a,i6)') 'Error code = ', ierr stop 1 end subroutine error_exit ! ----------------------------------------------- subroutine initialize(device, context, command_queue) type(cl_device_id), intent(out) :: device type(cl_context), intent(out) :: context type(cl_command_queue), intent(out) :: command_queue integer :: num, ierr character(len = 100) :: info type(cl_platform_id) :: platform ! get the platform ID call clGetPlatformIDs(platform, num, ierr) if(ierr /= CL_SUCCESS) call error_exit('Cannot get CL platform.') ! get the device ID call clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, device, num, ierr) if(ierr /= CL_SUCCESS) call error_exit('Cannot get CL device.') ! get the device name and print it call clGetDeviceInfo(device, CL_DEVICE_NAME, info, ierr) print*, "CL device: ", info ! create the context and the command queue context = clCreateContext(platform, device, ierr) command_queue = clCreateCommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE, ierr) end subroutine initialize ! ----------------------------------------------- subroutine build_kernel(filename, kernelname, context, device, kernel) character(len=*), intent(in) :: filename character(len=*), intent(in) :: kernelname type(cl_context), intent(inout) :: context type(cl_device_id), intent(in) :: device type(cl_kernel), intent(out) :: kernel integer, parameter :: iunit = 10 integer, parameter :: source_length = 1000 character(len = source_length) :: source integer :: irec, ierr type(cl_program) :: prog ! read the source file open(unit = iunit, file = trim(filename), access='direct', status = 'old', action = 'read', iostat = ierr, recl = 1) if (ierr /= 0) then call error_exit('Cannot open file '//trim(filename)) end if source = '' irec = 1 do read(unit = iunit, rec = irec, iostat = ierr) source(irec:irec) if (ierr /= 0) exit if(irec == source_length) call error_exit('Error: CL source file is too big') irec = irec + 1 end do close(unit = iunit) ! create the program prog = clCreateProgramWithSource(context, source, ierr) if(ierr /= CL_SUCCESS) call error_exit('Error: cannot create program from source.') ! build call clBuildProgram(prog, '-cl-mad-enable', ierr) ! get the compilation log call clGetProgramBuildInfo(prog, device, CL_PROGRAM_BUILD_LOG, source, irec) if(len(trim(source)) > 0) print*, trim(source) if(ierr /= CL_SUCCESS) call error_exit('Error: program build failed.') ! finally get the kernel and release the program kernel = clCreateKernel(prog, trim(kernelname), ierr) call clReleaseProgram(prog, ierr) end subroutine build_kernel end module utils
lgpl-3.0
blue236/gcc
gcc/testsuite/gfortran.dg/typebound_override_5.f90
109
1118
! { dg-do compile } ! ! PR 54190: TYPE(*)/assumed-rank: Type/rank check too relaxed for dummy procedure ! PR 57217: [4.7/4.8/4.9 Regression][OOP] Accepts invalid TBP overriding - lacking arguments check ! ! Contributed by Tobias Burnus <burnus@gcc.gnu.org> module base_mod implicit none type base_type integer :: kind contains procedure, pass(map) :: clone => base_clone end type contains subroutine base_clone(map,mapout,info) class(base_type), intent(inout) :: map class(base_type), intent(inout) :: mapout integer :: info end subroutine end module module r_mod use base_mod implicit none type, extends(base_type) :: r_type real :: dat contains procedure, pass(map) :: clone => r_clone ! { dg-error "Type mismatch in argument" } end type contains subroutine r_clone(map,mapout,info) class(r_type), intent(inout) :: map !gcc$ attributes no_arg_check :: mapout integer, intent(inout) :: mapout integer :: info end subroutine end module ! { dg-final { cleanup-modules "base_mod r_mod" } }
gpl-2.0
migueldvb/piernik
src/gravity/hydrostatic.F90
2
19672
! ! PIERNIK Code Copyright (C) 2006 Michal Hanasz ! ! This file is part of PIERNIK code. ! ! PIERNIK 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. ! ! PIERNIK 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. ! ! You should have received a copy of the GNU General Public License ! along with PIERNIK. If not, see <http://www.gnu.org/licenses/>. ! ! Initial implementation of PIERNIK code was based on TVD split MHD code by ! Ue-Li Pen ! see: Pen, Arras & Wong (2003) for algorithm and ! http://www.cita.utoronto.ca/~pen/MHD ! for original source code "mhd.f90" ! ! For full list of developers see $PIERNIK_HOME/license/pdt.txt ! #include "piernik.h" !> !! \brief Module containing a subroutine that arranges %hydrostatic equilibrium in the vertical (z) direction !! \details There are two routines to call to set hydrostatic equilibrium: !! @n hydrostatic_zeq_coldens that fixes column density, !! @n hydrostatic_zeq_densmid that fixes density value in the midplane. !! @n Additionally there is also outh_bnd routine to keep hydrostatic equilibrium on the boundaries. !< module hydrostatic ! pulled by GRAV use grid_cont, only: grid_container implicit none private #ifdef GRAV public :: set_default_hsparams, hydrostatic_zeq_coldens, hydrostatic_zeq_densmid, cleanup_hydrostatic, outh_bnd, init_hydrostatic public :: dprof, gprofs, nstot, zs, dzs, hsmin, hsbn, hsl, sdlim, hscg #endif /* GRAV */ real, allocatable, dimension(:), save :: zs !< array of z-positions of subgrid cells centers real, allocatable, dimension(:), save :: gprofs !< array of gravitational acceleration in a column of subgrid real, allocatable, dimension(:), save :: dprof !< Array used for storing density during calculation of hydrostatic equilibrium real, save :: dzs !< length of the subgrid cell in z-direction integer(kind=4), save :: nstot !< total number of subgrid cells in a column through all z-blocks real, save :: dmid !< density value in a midplane (fixed for hydrostatic_zeq_densmid, overwritten by hydrostatic_zeq_coldens) real, save :: hsmin !< lower position limit integer(kind=4), dimension(2), save :: hsbn !< first and last cell indices in proceeded block real, allocatable, dimension(:), save :: hsl !< lower borders of cells of proceeded block real, dimension(2), save :: sdlim !< edges for sd sum type(grid_container), pointer, save :: hscg interface subroutine hzeqscheme(ksub, up, factor) implicit none integer, intent(in) :: ksub real, intent(in) :: up real, intent(out) :: factor end subroutine hzeqscheme end interface procedure(hzeqscheme), pointer :: hzeq_scheme => NULL() contains #ifdef GRAV !> !! \brief Routine that establishes hydrostatic equilibrium for fixed column density !! \details Routine calls the routine of the case of fixed plane density value and use the correction for column density. !! To properly use this routine it is important to make sure that get_gprofs pointer has been associated. See details of start_hydrostatic routine. !! \param iia x index of z-column !! \param jja y index of z-column !! \param coldens column density value for given x and y coordinates !! \param csim2 sqare of sound velocity !< subroutine hydrostatic_zeq_coldens(iia, jja, coldens, csim2) implicit none integer, intent(in) :: iia, jja real, intent(in) :: coldens, csim2 real :: sdprof, sd sdprof = 1.0 call hydrostatic_zeq_densmid(iia, jja, sdprof, csim2, sd) dprof(:) = dprof(:) * coldens / sd end subroutine hydrostatic_zeq_coldens !> !! \brief Routine that establishes hydrostatic equilibrium for fixed plane density value !! \details To properly use this routine it is important to make sure that get_gprofs pointer has been associated. See details of start_hydrostatic routine. !! \param iia x-coordinate of z-column !! \param jja y-coordinate of z-column !! \param d0 plane density value for given x and y coordinates !! \param csim2 sqare of sound velocity !! \param sd optional variable to give a sum of dprofs array from hydrostatic_main routine !< subroutine hydrostatic_zeq_densmid(iia, jja, d0, csim2, sd) use constants, only: small use dataio_pub, only: die implicit none integer, intent(in) :: iia, jja real, intent(in) :: d0, csim2 real, optional, intent(inout) :: sd if (d0 <= small) call die("[hydrostatic:hydrostatic_zeq_densmid] d0 must be /= 0") dmid = d0 call start_hydrostatic(iia, jja, csim2, sd) call finish_hydrostatic end subroutine hydrostatic_zeq_densmid !> !! \brief Routine to set up sizes of arrays used in hydrostatic module. Settings depend on cg structure. !! \details Routine has to be called before the firs usage of hydrostatic_zeq_coldens/densmid if there is no other equivalent user settings. !< subroutine set_default_hsparams(cg) use constants, only: zdim, LO, HI, I_ONE, LEFT, RIGHT use diagnostics, only: my_deallocate !, my_allocate use domain, only: dom use gravity, only: nsub use grid_cont, only: grid_container implicit none type(grid_container), pointer, intent(in) :: cg hscg => cg nstot = nsub * dom%n_t(zdim) dzs = (dom%edge(zdim, HI)-dom%edge(zdim, LO))/real(nstot-2*dom%nb*nsub) hsmin = dom%edge(zdim, LO)-dom%nb*cg%dl(zdim) hsbn = cg%lhn(zdim,:) sdlim = dom%edge(zdim,:) if (allocated(dprof)) call my_deallocate(dprof) ! call my_allocate(dprof, [cg%n_(zdim)], "dprof") allocate(dprof(hsbn(LO):hsbn(HI))) if (allocated(hsl)) call my_deallocate(hsl) ! call my_allocate(hsl, [hsbn+I_ONE], "hsl") allocate(hsl(hsbn(LO):hsbn(HI)+I_ONE)) hsl(hsbn(LO):hsbn(HI)) = cg%coord(LEFT, zdim)%r(hsbn(LO):hsbn(HI)) hsl(hsbn(HI)+I_ONE) = cg%coord(RIGHT, zdim)%r(hsbn(HI)) end subroutine set_default_hsparams !> !! \brief Initialize hydrostatic module !< subroutine init_hydrostatic use fluidboundaries_funcs, only: user_fluidbnd implicit none ! BEWARE: This is a sweet little hack that allows to drop hydrostatic ! dependency from fluidboundaries module. It's bad due to several reasons, ! which I'll gracefully omit in this comment. It should be fixed asap... user_fluidbnd => outh_bnd end subroutine init_hydrostatic !> !! \brief Routine to clean up after the last usage of hydrostatic routines !< subroutine cleanup_hydrostatic use diagnostics, only: my_deallocate implicit none if (allocated(dprof)) call my_deallocate(dprof) if (allocated(hsl)) call my_deallocate(hsl) if (associated(hscg)) nullify(hscg) end subroutine cleanup_hydrostatic !> !! \brief Routine that arranges %hydrostatic equilibrium in the vertical (z) direction !< subroutine hydrostatic_main(sd) use constants, only: LO, HI use dataio_pub, only: die use gravity, only: nsub #ifdef HYDROSTATIC_V2 use constants, only: big_float #endif /* !HYDROSTATIC_V2 */ implicit none real, optional, intent(out) :: sd real, allocatable, dimension(:) :: dprofs integer :: ksub, ksmid, k real :: factor allocate(dprofs(nstot)) ksmid = 0 #ifdef HYDROSTATIC_V2 dprofs(1) = gprofs(1) do k = 2, nstot dprofs(k) = dprofs(k-1) + gprofs(k) enddo ksmid = maxloc(dprofs,1) ! generally the midplane is where gravity is 0, practically we want the least gravity potential value dprofs = big_float ! ksmid = minloc(abs(gprofs),1) ! generally the midplane is where gravity is 0, practically we want the least gravity absolute value (yet it may provide wrong results because of resolution) hzeq_scheme => hzeq_scheme_v2 #else /* !HYDROSTATIC_V2 */ ksmid = maxloc(zs,1,mask=(zs < 0.0)) ! the midplane is in between ksmid and ksmid+1 hzeq_scheme => hzeq_scheme_v1 #endif /* !HYDROSTATIC_V2 */ if (ksmid == 0) call die("[hydrostatic:hydrostatic_main] ksmid not set") if (ksmid < nstot) then dprofs(ksmid+1) = dmid do ksub=ksmid+1, nstot-1 call hzeq_scheme(ksub, 1.0, factor) dprofs(ksub+1) = factor * dprofs(ksub) enddo endif if (ksmid > 1) then dprofs(ksmid) = dmid do ksub=ksmid, 2, -1 call hzeq_scheme(ksub, -1.0, factor) dprofs(ksub-1) = factor * dprofs(ksub) enddo endif dprof(:) = 0.0 do k=hsbn(LO), hsbn(HI) do ksub=1, nstot if (zs(ksub) > hsl(k) .and. zs(ksub) < hsl(k+1)) then dprof(k) = dprof(k) + dprofs(ksub)/real(nsub) endif enddo enddo if (present(sd)) then sd = 0.0 do ksub=1, nstot if (zs(ksub) > sdlim(LO) .and. zs(ksub) < sdlim(HI)) sd = sd + dprofs(ksub)*dzs enddo endif if (allocated(dprofs)) deallocate(dprofs) end subroutine hydrostatic_main subroutine hzeq_scheme_v1(ksub, up, factor) implicit none integer, intent(in) :: ksub real, intent(in) :: up real, intent(out) :: factor factor = (2.0 + up*gprofs(ksub))/(2.0 - up*gprofs(ksub)) end subroutine hzeq_scheme_v1 subroutine hzeq_scheme_v2(ksub, up, factor) implicit none integer, intent(in) :: ksub real, intent(in) :: up real, intent(out) :: factor factor = gprofs(ksub)+gprofs(ksub+nint(up)) factor = (4.0 + up*factor)/(4.0 - up*factor) end subroutine hzeq_scheme_v2 subroutine get_gprofs_accel(iia, jja) use constants, only: xdim, ydim, zdim use gravity, only: tune_zeq, grav_accel implicit none integer, intent(in) :: iia, jja integer :: ia, ja ia = min(hscg%n_(xdim), int(max(1, iia), kind=4)) ja = min(hscg%n_(ydim), int(max(1, jja), kind=4)) call grav_accel(zdim, ia, ja, zs, nstot, gprofs) gprofs(:) = tune_zeq*gprofs(:) end subroutine get_gprofs_accel !> !! \brief Routine that has to offer a z-sweep of external gravity potential with extended z-grid !! \warning in case of moving 'use axes_M, only: axes'' behind use gravity there could be gcc(4.5) internal compiler error: in fold_convert_loc, at fold-const.c:2792 (solved in >=gcc-4.6) !< subroutine get_gprofs_extgp(iia, jja) use axes_M, only: axes use constants, only: half, I_ONE, ndims, zdim, LO, HI use gravity, only: tune_zeq, grav_type implicit none integer, intent(in) :: iia, jja integer(kind=4), dimension(ndims,LO:HI) :: lhn integer(kind=4) :: nstot1 real, dimension(:,:,:), pointer :: gpots type(axes) :: ax nstot1 = nstot + I_ONE allocate(gpots(1,1,nstot1)) lhn = I_ONE ; lhn(zdim,HI) = nstot1 call ax%allocate_axes(lhn) ax%x = hscg%x(iia) ax%y = hscg%y(jja) ax%z(1:nstot) = zs - half*dzs ax%z(nstot1) = ax%z(nstot) + dzs call grav_type(gpots, ax, lhn) call ax%deallocate_axes gprofs(1:nstot) = (gpots(1,1,1:nstot) - gpots(1,1,2:nstot1))/dzs gprofs(:) = tune_zeq*gprofs(:) if (associated(gpots)) deallocate(gpots) end subroutine get_gprofs_extgp !> !! \brief Routine that prepares data for constructing hydrostatic equilibrium by hydrostatic_main routine !! \details It is important to have get_gprofs pointer associated to a proper routine that gives back the column of nsub*nzt elements of gravitational acceleration in z direction. In the most common cases the gprofs_target parameter from GRAVITY namelist may be used. When it is set to 'accel' or 'extgp' the pointer is associated to get_gprofs_accel or get_gprofs_extgp routines, respectively. !! \note After calling this routine gprofs is multiplied by dzs/csim2 which are assumed to be constant. This is done for optimizing the hydrostatic_main routine. !! \param iia x-coordinate of z-column !! \param jja y-coordinate of z-column !! \param csim2 sqare of sound velocity !! \param sd optional variable to give a sum of dprofs array from hydrostatic_main routine !< subroutine start_hydrostatic(iia, jja, csim2, sd) use constants, only: half use dataio_pub, only: die use gravity, only: get_gprofs, gprofs_target implicit none integer, intent(in) :: iia, jja real, intent(in) :: csim2 real, optional, intent(inout) :: sd integer :: ksub if (.not.associated(get_gprofs)) then select case (gprofs_target) case ('accel') get_gprofs => get_gprofs_accel case ('extgp') get_gprofs => get_gprofs_extgp case default call die("[hydrostatic:start_hydrostatic] get_gprofs'' target has not been specified") end select endif allocate(zs(nstot), gprofs(nstot)) do ksub=1, nstot zs(ksub) = hsmin + (real(ksub)-half)*dzs enddo call get_gprofs(iia, jja) gprofs(:) = gprofs(:) / csim2 *dzs call hydrostatic_main(sd) end subroutine start_hydrostatic subroutine finish_hydrostatic implicit none if (allocated(zs)) deallocate(zs) if (allocated(gprofs)) deallocate(gprofs) end subroutine finish_hydrostatic !> !! \todo this procedure is incompatible with cg%cs_iso2 !< subroutine outh_bnd(dir, side, cg, wn, qn, emfdir) use constants, only: xdim, ydim, zdim, half, LO, HI, INT4, LEFT, RIGHT, I_ONE use dataio_pub, only: die use domain, only: dom use fluidindex, only: flind, iarr_all_dn, iarr_all_mx, iarr_all_my, iarr_all_mz use func, only: ekin use global, only: smalld use gravity, only: nsub, get_gprofs, tune_zeq_bnd use grid_cont, only: grid_container #ifndef ISO use fluidindex, only: iarr_all_en use global, only: smallei #endif /* !ISO */ #ifdef COSM_RAYS use fluidindex, only: iarr_all_crs use initcosmicrays, only: smallecr #endif /* COSM_RAYS */ implicit none integer(kind=4), intent(in) :: dir, side type(grid_container), pointer, intent(inout) :: cg integer(kind=4), optional, intent(in) :: wn, qn, emfdir integer(kind=4) :: ib, ssign, kb, kk integer :: ksub, i, j, lksub integer :: ifl real, dimension(:,:), allocatable :: dprofs real, dimension(flind%fluids) :: factor, db, dbr, csi2b #ifndef ISO real, dimension(flind%fluids) :: eib #endif /* !ISO */ if (dir /= zdim) return if (.not.present(wn)) call die("[hydrostatic:outh_bnd] unable to discern OUTH from OUTHD") if (.not.associated(get_gprofs)) call die("[hydrostatic:outh_bnd] get_gprofs not associated") hscg => cg nstot = int(3*nsub/2+1,kind=4) allocate(zs(nstot), gprofs(nstot), dprofs(flind%fluids,nstot)) ssign = 2_INT4*side - 3_INT4 dzs = (cg%z(cg%ijkse(zdim,side)+ssign)-cg%z(cg%ijkse(zdim,side)))/real(nsub) do j = cg%lhn(ydim,LO), cg%lhn(ydim,HI) do i = cg%lhn(xdim,LO), cg%lhn(xdim,HI) dbr = 1.0 do ib = 0_INT4, dom%nb kb = cg%ijkse(zdim,side)+ssign*(ib-1_INT4) kk = kb + ssign zs(:) = cg%z(kb) + dzs*(real([(ksub,ksub=1,nstot)])+real(nsub-3)*half) db(:) = max(cg%u(iarr_all_dn,i,j,kb), smalld) #ifdef ISO ! csi2b = maxval(flind%all_fluids(:)%fl%cs2) !> \deprecated BEWARE should be fluid dependent csi2b = 0.0 do ifl = lbound(flind%all_fluids, dim=1), ubound(flind%all_fluids, dim=1) csi2b(:) = max(csi2b(:), flind%all_fluids(ifl)%fl%cs2) enddo #else /* !ISO */ eib(:) = cg%u(iarr_all_en,i,j,kb) - ekin(cg%u(iarr_all_mx,i,j,kb),cg%u(iarr_all_my,i,j,kb),cg%u(iarr_all_mz,i,j,kb),db(:)) eib(:) = max(eib(:), smallei) do ifl = lbound(flind%all_fluids, dim=1), ubound(flind%all_fluids, dim=1) csi2b(ifl) = (flind%all_fluids(ifl)%fl%gam_1)*eib(ifl)/db(ifl) enddo #endif /* !ISO */ call get_gprofs(i,j) gprofs(:) = tune_zeq_bnd * gprofs(:) dprofs(:,1) = dbr(:) do ksub = 1, nstot-1 factor = (2.0 + dzs*gprofs(ksub)/csi2b(:)) / (2.0 - dzs*gprofs(ksub)/csi2b(:)) !> \todo use hzeq_scheme here dprofs(:,ksub+1) = factor * dprofs(:,ksub) enddo db(:) = 0.0 lksub = 0 do ksub = 1, nstot if (zs(ksub) > cg%coord(LEFT, zdim)%r(kk) .and. zs(ksub) < cg%coord(RIGHT, zdim)%r(kk)) then db(:) = db(:) + dprofs(:,ksub)/real(nsub) lksub = ksub endif enddo if (ib == 0_INT4) dprofs(:,lksub) = dprofs(:,lksub) * cg%u(iarr_all_dn,i,j,kk) / db(:) dbr(:) = dprofs(:,lksub) db(:) = max(db(:), smalld) #ifndef ISO do ifl = lbound(flind%all_fluids, dim=1), ubound(flind%all_fluids, dim=1) eib(ifl) = csi2b(ifl)*db(ifl) / (flind%all_fluids(ifl)%fl%gam_1) enddo eib(:) = max(eib(:), smallei) #endif /* !ISO */ if (ib /= 0_INT4) then cg%u(iarr_all_dn,i,j,kk) = db(:) cg%u(iarr_all_mx,i,j,kk) = cg%u(iarr_all_mx,i,j,kb) cg%u(iarr_all_my,i,j,kk) = cg%u(iarr_all_my,i,j,kb) cg%u(iarr_all_mz,i,j,kk) = cg%u(iarr_all_mz,i,j,kb) if (wn == I_ONE) then if (side == HI) then cg%u(iarr_all_mz,i,j,kk) = max(cg%u(iarr_all_mz,i,j,kk),0.0) else cg%u(iarr_all_mz,i,j,kk) = min(cg%u(iarr_all_mz,i,j,kk),0.0) endif endif #ifndef ISO cg%u(iarr_all_en,i,j,kk) = eib(:) + ekin(cg%u(iarr_all_mx,i,j,kk),cg%u(iarr_all_my,i,j,kk),cg%u(iarr_all_mz,i,j,kk),db(:)) #endif /* !ISO */ #ifdef COSM_RAYS cg%u(iarr_all_crs,i,j,kk) = smallecr #endif /* COSM_RAYS */ endif enddo enddo enddo deallocate(zs,gprofs) if (.false.) then ! suppress compiler warnings on unused arguments if (present(qn)) i = qn if (present(emfdir)) i = emfdir endif end subroutine outh_bnd #endif /* GRAV */ end module hydrostatic
gpl-3.0
blue236/gcc
gcc/testsuite/gfortran.dg/auto_char_dummy_array_1.f90
79
1217
! { dg-do run } ! This tests the fix for pr15809 in which automatic character length, ! dummy, pointer arrays were broken. ! ! contributed by Paul Thomas <pault@gcc.gnu.org> ! module global character(12), dimension(2), target :: t end module global program oh_no_not_pr15908_again character(12), dimension(:), pointer :: ptr nullify(ptr) call a (ptr, 12) if (.not.associated (ptr) ) call abort () if (any (ptr.ne."abc")) call abort () ptr => null () ! ptr points to 't' here. allocate (ptr(3)) ptr = "xyz" call a (ptr, 12) if (.not.associated (ptr)) call abort () if (any (ptr.ne."lmn")) call abort () call a (ptr, 0) if (associated (ptr)) call abort () contains subroutine a (p, l) use global character(l), dimension(:), pointer :: p character(l), dimension(3) :: s s = "lmn" if (l.ne.12) then deallocate (p) ! ptr was allocated in main. p => null () return end if if (.not.associated (p)) then t = "abc" p => t else if (size (p,1).ne.3) call abort () if (any (p.ne."xyz")) call abort () p = s end if end subroutine a end program oh_no_not_pr15908_again
gpl-2.0
william-dawson/NTPoly
Source/Fortran/ExponentialSolversModule.F90
1
23371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> A Module For Computing Matrix Exponentials and Logarithms. MODULE ExponentialSolversModule USE ChebyshevSolversModule, ONLY : ChebyshevPolynomial_t, Compute, & & ConstructPolynomial, DestructPolynomial, FactorizedCompute, & & SetCoefficient USE DataTypesModule, ONLY : NTREAL USE EigenBoundsModule, ONLY : GershgorinBounds, PowerBounds USE LinearSolversModule, ONLY : CGSolver USE LoadBalancerModule, ONLY : PermuteMatrix, UndoPermuteMatrix USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, WriteHeader, & & WriteElement USE PSMatrixAlgebraModule, ONLY : MatrixMultiply, MatrixNorm, ScaleMatrix, & & IncrementMatrix USE PMatrixMemoryPoolModule, ONLY : MatrixMemoryPool_p, & & DestructMatrixMemoryPool USE PSMatrixModule, ONLY : Matrix_ps, ConstructEmptyMatrix, CopyMatrix, & & DestructMatrix, FillMatrixIdentity, PrintMatrixInformation USE RootSolversModule, ONLY : ComputeRoot USE SolverParametersModule, ONLY : SolverParameters_t, PrintParameters, & & DestructSolverParameters USE SquareRootSolversModule, ONLY : SquareRoot IMPLICIT NONE PRIVATE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! Solvers PUBLIC :: ComputeExponential PUBLIC :: ComputeExponentialPade PUBLIC :: ComputeExponentialTaylor PUBLIC :: ComputeLogarithm PUBLIC :: ComputeLogarithmTaylor CONTAINS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Compute the exponential of a matrix. SUBROUTINE ComputeExponential(InputMat, OutputMat, solver_parameters_in) !> The input matrix TYPE(Matrix_ps), INTENT(IN) :: InputMat !> OutputMat = exp(InputMat) TYPE(Matrix_ps), INTENT(INOUT) :: OutputMat !> Parameters for the solver TYPE(SolverParameters_t), INTENT(IN), OPTIONAL :: solver_parameters_in !! Handling Solver Parameters TYPE(SolverParameters_t) :: solver_parameters TYPE(SolverParameters_t) :: sub_solver_parameters TYPE(SolverParameters_t) :: psub_solver_parameters !! Local Matrices TYPE(Matrix_ps) :: ScaledMat TYPE(Matrix_ps) :: TempMat TYPE(MatrixMemoryPool_p) :: pool !! For Chebyshev Expansion TYPE(ChebyshevPolynomial_t) :: polynomial !! Local Variables REAL(NTREAL) :: spectral_radius REAL(NTREAL) :: sigma_val INTEGER :: sigma_counter INTEGER :: counter !! Handle The Optional Parameters !! Optional Parameters IF (PRESENT(solver_parameters_in)) THEN solver_parameters = solver_parameters_in ELSE solver_parameters = SolverParameters_t() END IF sub_solver_parameters = solver_parameters psub_solver_parameters = solver_parameters psub_solver_parameters%max_iterations = 10 IF (solver_parameters%be_verbose) THEN CALL WriteHeader("Exponential Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="Chebyshev") CALL PrintParameters(solver_parameters) END IF CALL ConstructEmptyMatrix(OutputMat, InputMat) !! Scale the matrix CALL PowerBounds(InputMat,spectral_radius,psub_solver_parameters) sigma_val = 1.0 sigma_counter = 1 DO WHILE (spectral_radius/sigma_val .GT. 1.0) sigma_val = sigma_val * 2 sigma_counter = sigma_counter + 1 END DO CALL CopyMatrix(InputMat, ScaledMat) CALL ScaleMatrix(ScaledMat,1.0/sigma_val) sub_solver_parameters%threshold = sub_solver_parameters%threshold/sigma_val IF (solver_parameters%be_verbose) THEN CALL WriteElement(key="Sigma", VALUE=sigma_val) END IF !! Expand Chebyshev Series CALL ConstructPolynomial(polynomial,16) CALL SetCoefficient(polynomial,1,1.266065877752007e+00_NTREAL) CALL SetCoefficient(polynomial,2,1.130318207984970e+00_NTREAL) CALL SetCoefficient(polynomial,3,2.714953395340771e-01_NTREAL) CALL SetCoefficient(polynomial,4,4.433684984866504e-02_NTREAL) CALL SetCoefficient(polynomial,5,5.474240442092110e-03_NTREAL) CALL SetCoefficient(polynomial,6,5.429263119148932e-04_NTREAL) CALL SetCoefficient(polynomial,7,4.497732295351912e-05_NTREAL) CALL SetCoefficient(polynomial,8,3.198436462630565e-06_NTREAL) CALL SetCoefficient(polynomial,9,1.992124801999838e-07_NTREAL) CALL SetCoefficient(polynomial,10,1.103677287249654e-08_NTREAL) CALL SetCoefficient(polynomial,11,5.505891628277851e-10_NTREAL) CALL SetCoefficient(polynomial,12,2.498021534339559e-11_NTREAL) CALL SetCoefficient(polynomial,13,1.038827668772902e-12_NTREAL) CALL SetCoefficient(polynomial,14,4.032447357431817e-14_NTREAL) CALL SetCoefficient(polynomial,15,2.127980007794583e-15_NTREAL) CALL SetCoefficient(polynomial,16,-1.629151584468762e-16_NTREAL) CALL Compute(ScaledMat,OutputMat,polynomial,sub_solver_parameters) !CALL FactorizedChebyshevCompute(ScaledMat,OutputMat,polynomial, & ! & sub_solver_parameters) !! Undo the scaling by squaring at the end. !! Load Balancing Step IF (solver_parameters%do_load_balancing) THEN CALL PermuteMatrix(OutputMat, OutputMat, & & solver_parameters%BalancePermutation, memorypool_in=pool) END IF DO counter=1,sigma_counter-1 CALL MatrixMultiply(OutputMat,OutputMat,TempMat, & & threshold_in=solver_parameters%threshold, memory_pool_in=pool) CALL CopyMatrix(TempMat,OutputMat) END DO IF (solver_parameters%be_verbose) THEN CALL PrintMatrixInformation(OutputMat) END IF IF (solver_parameters%do_load_balancing) THEN CALL UndoPermuteMatrix(OutputMat, OutputMat, & & solver_parameters%BalancePermutation, memorypool_in=pool) END IF !! Cleanup IF (solver_parameters%be_verbose) THEN CALL ExitSubLog END IF CALL DestructPolynomial(polynomial) CALL DestructMatrix(ScaledMat) CALL DestructMatrix(TempMat) CALL DestructSolverParameters(solver_parameters) END SUBROUTINE ComputeExponential !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Compute the exponential of a matrix using a pade approximation. !> Be warned, the pade method can result in a lot of intermediate fill. SUBROUTINE ComputeExponentialPade(InputMat, OutputMat, solver_parameters_in) !> The input matrix TYPE(Matrix_ps), INTENT(IN) :: InputMat !> OutputMat = exp(InputMat) TYPE(Matrix_ps), INTENT(INOUT) :: OutputMat !> Parameters for the solver TYPE(SolverParameters_t), INTENT(IN), OPTIONAL :: solver_parameters_in !! Handling Solver Parameters TYPE(SolverParameters_t) :: solver_parameters TYPE(SolverParameters_t) :: sub_solver_parameters !! Local Matrices TYPE(Matrix_ps) :: ScaledMat TYPE(Matrix_ps) :: IdentityMat TYPE(Matrix_ps) :: TempMat TYPE(Matrix_ps) :: B1, B2, B3 TYPE(Matrix_ps) :: P1, P2 TYPE(Matrix_ps) :: LeftMat, RightMat TYPE(MatrixMemoryPool_p) :: pool !! Local Variables REAL(NTREAL) :: spectral_radius REAL(NTREAL) :: sigma_val INTEGER :: sigma_counter INTEGER :: counter !! Handle The Optional Parameters !! Optional Parameters IF (PRESENT(solver_parameters_in)) THEN solver_parameters = solver_parameters_in ELSE solver_parameters = SolverParameters_t() END IF IF (solver_parameters%be_verbose) THEN CALL WriteHeader("Exponential Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="Pade") CALL PrintParameters(solver_parameters) END IF !! Setup CALL ConstructEmptyMatrix(IdentityMat, InputMat) CALL FillMatrixIdentity(IdentityMat) !! Scale the matrix spectral_radius = MatrixNorm(InputMat) sigma_val = 1.0 sigma_counter = 1 DO WHILE (spectral_radius/sigma_val .GT. 1.0) sigma_val = sigma_val * 2 sigma_counter = sigma_counter + 1 END DO CALL CopyMatrix(InputMat, ScaledMat) CALL ScaleMatrix(ScaledMat,1.0/sigma_val) IF (solver_parameters%be_verbose) THEN CALL WriteElement(key="Sigma", VALUE=sigma_val) CALL WriteElement(key="Scaling_Steps", VALUE=sigma_counter) END IF !! Sub Solver Parameters sub_solver_parameters = solver_parameters sub_solver_parameters%threshold = sub_solver_parameters%threshold/sigma_val !! Power Matrices CALL MatrixMultiply(ScaledMat, ScaledMat, B1, & & threshold_in=sub_solver_parameters%threshold, memory_pool_in=pool) CALL MatrixMultiply(B1, B1, B2, & & threshold_in=sub_solver_parameters%threshold, memory_pool_in=pool) CALL MatrixMultiply(B2, B2, B3, & & threshold_in=sub_solver_parameters%threshold, memory_pool_in=pool) !! Polynomials - 1 CALL CopyMatrix(IdentityMat, P1) CALL ScaleMatrix(P1,17297280.0_NTREAL) CALL IncrementMatrix(B1, P1, alpha_in=1995840.0_NTREAL) CALL IncrementMatrix(B2, P1, alpha_in=25200.0_NTREAL) CALL IncrementMatrix(B3, P1, alpha_in=56.0_NTREAL) !! Polynomials - 2 CALL CopyMatrix(IdentityMat, TempMat) CALL ScaleMatrix(TempMat,8648640.0_NTREAL) CALL IncrementMatrix(B1, TempMat, alpha_in=277200.0_NTREAL) CALL IncrementMatrix(B2, TempMat, alpha_in=1512.0_NTREAL) CALL IncrementMatrix(B3, TempMat) CALL MatrixMultiply(ScaledMat, TempMat, P2, & & threshold_in=sub_solver_parameters%threshold, memory_pool_in=pool) !! Left and Right CALL CopyMatrix(P1, LeftMat) CALL IncrementMatrix(P2, LeftMat, -1.0_NTREAL) CALL CopyMatrix(P1, RightMat) CALL IncrementMatrix(P2, RightMat, 1.0_NTREAL) CALL CGSolver(LeftMat, OutputMat, RightMat, sub_solver_parameters) !! Undo the scaling by squaring at the end. DO counter=1,sigma_counter-1 CALL MatrixMultiply(OutputMat,OutputMat,TempMat, & & threshold_in=solver_parameters%threshold, memory_pool_in=pool) CALL CopyMatrix(TempMat,OutputMat) END DO IF (solver_parameters%be_verbose) THEN CALL PrintMatrixInformation(OutputMat) END IF !! Cleanup IF (solver_parameters%be_verbose) THEN CALL ExitSubLog END IF CALL DestructMatrix(ScaledMat) CALL DestructMatrix(TempMat) CALL DestructMatrix(B1) CALL DestructMatrix(B2) CALL DestructMatrix(B3) CALL DestructMatrix(P1) CALL DestructMatrix(P2) CALL DestructMatrix(LeftMat) CALL DestructMatrix(RightMat) CALL DestructMatrixMemoryPool(pool) CALL DestructSolverParameters(solver_parameters) END SUBROUTINE ComputeExponentialPade !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Compute the exponential of a matrix using a taylor series expansion. !> This is only really useful if you have a very small spectrum, because !> quite a bit of scaling is required. SUBROUTINE ComputeExponentialTaylor(InputMat, OutputMat, solver_parameters_in) !> The input matrix TYPE(Matrix_ps), INTENT(IN) :: InputMat !> OutputMat = exp(InputMat) TYPE(Matrix_ps), INTENT(INOUT) :: OutputMat !> Parameters for the solver TYPE(SolverParameters_t), INTENT(IN), OPTIONAL :: solver_parameters_in !! Handling Solver Parameters TYPE(SolverParameters_t) :: solver_parameters TYPE(SolverParameters_t) :: psub_solver_parameters !! Local Matrices TYPE(Matrix_ps) :: ScaledMat TYPE(Matrix_ps) :: Ak TYPE(Matrix_ps) :: TempMat TYPE(MatrixMemoryPool_p) :: pool !! Local Variables REAL(NTREAL) :: spectral_radius REAL(NTREAL) :: sigma_val REAL(NTREAL) :: taylor_denom INTEGER :: sigma_counter INTEGER :: counter !! Handle The Optional Parameters !! Optional Parameters IF (PRESENT(solver_parameters_in)) THEN solver_parameters = solver_parameters_in ELSE solver_parameters = SolverParameters_t() END IF psub_solver_parameters = solver_parameters psub_solver_parameters%max_iterations = 10 IF (solver_parameters%be_verbose) THEN CALL WriteHeader("Exponential Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="Taylor") CALL PrintParameters(solver_parameters) END IF !! Compute The Scaling Factor CALL PowerBounds(InputMat,spectral_radius,psub_solver_parameters) !! Figure out how much to scale the matrix. sigma_val = 1.0 sigma_counter = 1 DO WHILE (spectral_radius/sigma_val .GT. 3.0e-8) sigma_val = sigma_val * 2 sigma_counter = sigma_counter + 1 END DO CALL CopyMatrix(InputMat, ScaledMat) CALL ScaleMatrix(ScaledMat,1.0/sigma_val) CALL ConstructEmptyMatrix(OutputMat, InputMat) CALL FillMatrixIdentity(OutputMat) !! Load Balancing Step IF (solver_parameters%do_load_balancing) THEN CALL PermuteMatrix(ScaledMat, ScaledMat, & & solver_parameters%BalancePermutation, memorypool_in=pool) CALL PermuteMatrix(OutputMat, OutputMat, & & solver_parameters%BalancePermutation, memorypool_in=pool) END IF !! Expand Taylor Series taylor_denom = 1.0 CALL CopyMatrix(OutputMat, Ak) DO counter=1,10 taylor_denom = taylor_denom * counter CALL MatrixMultiply(Ak,ScaledMat,TempMat, & & threshold_in=solver_parameters%threshold, memory_pool_in=pool) CALL CopyMatrix(TempMat,Ak) CALL IncrementMatrix(Ak,OutputMat) END DO DO counter=1,sigma_counter-1 CALL MatrixMultiply(OutputMat,OutputMat,TempMat, & & threshold_in=solver_parameters%threshold, memory_pool_in=pool) CALL CopyMatrix(TempMat,OutputMat) END DO IF (solver_parameters%do_load_balancing) THEN CALL UndoPermuteMatrix(OutputMat, OutputMat, & & solver_parameters%BalancePermutation, memorypool_in=pool) END IF !! Cleanup IF (solver_parameters%be_verbose) THEN CALL ExitSubLog END IF CALL DestructMatrix(ScaledMat) CALL DestructMatrix(Ak) CALL DestructMatrix(TempMat) CALL DestructMatrixMemoryPool(pool) CALL DestructSolverParameters(solver_parameters) END SUBROUTINE ComputeExponentialTaylor !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Compute the logarithm of a matrix. SUBROUTINE ComputeLogarithm(InputMat, OutputMat, solver_parameters_in) !> The input matrix TYPE(Matrix_ps), INTENT(IN) :: InputMat !> OutputMat = exp(InputMat) TYPE(Matrix_ps), INTENT(INOUT) :: OutputMat !> Parameters for the solver TYPE(SolverParameters_t), INTENT(IN), OPTIONAL :: solver_parameters_in !! Handling Solver Parameters TYPE(SolverParameters_t) :: solver_parameters !! Local Matrices TYPE(Matrix_ps) :: ScaledMat TYPE(Matrix_ps) :: TempMat TYPE(Matrix_ps) :: IdentityMat !! For Chebyshev Expansion TYPE(ChebyshevPolynomial_t) :: polynomial !! Local Variables TYPE(SolverParameters_t) :: i_sub_solver_parameters TYPE(SolverParameters_t) :: p_sub_solver_parameters TYPE(SolverParameters_t) :: f_sub_solver_parameters REAL(NTREAL) :: spectral_radius INTEGER :: sigma_val INTEGER :: sigma_counter !! Handle The Optional Parameters !! Optional Parameters IF (PRESENT(solver_parameters_in)) THEN solver_parameters = solver_parameters_in ELSE solver_parameters = SolverParameters_t() END IF i_sub_solver_parameters = solver_parameters p_sub_solver_parameters = solver_parameters p_sub_solver_parameters%max_iterations=16 f_sub_solver_parameters = solver_parameters IF (solver_parameters%be_verbose) THEN CALL WriteHeader("Logarithm Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="Chebyshev") CALL PrintParameters(solver_parameters) END IF !! Setup CALL ConstructEmptyMatrix(IdentityMat, InputMat) CALL FillMatrixIdentity(IdentityMat) !! Copy to a temporary matrix for scaling. CALL CopyMatrix(InputMat,ScaledMat) !! Compute The Scaling Factor sigma_val = 1 sigma_counter = 1 CALL PowerBounds(InputMat,spectral_radius,p_sub_solver_parameters) DO WHILE (spectral_radius .GT. SQRT(2.0)) spectral_radius = SQRT(spectral_radius) sigma_val = sigma_val * 2 sigma_counter = sigma_counter + 1 END DO IF (solver_parameters%be_verbose) THEN CALL WriteElement(key="Sigma", VALUE=sigma_val) END IF f_sub_solver_parameters%threshold = & & f_sub_solver_parameters%threshold/REAL(2**(sigma_counter-1),NTREAL) CALL ComputeRoot(InputMat, ScaledMat, sigma_val, i_sub_solver_parameters) !! Shift Scaled Matrix CALL IncrementMatrix(IdentityMat,ScaledMat, & & alpha_in=REAL(-1.0,NTREAL)) !! Expand Chebyshev Series CALL ConstructPolynomial(polynomial,32) CALL SetCoefficient(polynomial,1,-0.485101351704_NTREAL) CALL SetCoefficient(polynomial,2,1.58828112379_NTREAL) CALL SetCoefficient(polynomial,3,-0.600947731795_NTREAL) CALL SetCoefficient(polynomial,4,0.287304748177_NTREAL) CALL SetCoefficient(polynomial,5,-0.145496447103_NTREAL) CALL SetCoefficient(polynomial,6,0.0734013668818_NTREAL) CALL SetCoefficient(polynomial,7,-0.0356277942958_NTREAL) CALL SetCoefficient(polynomial,8,0.0161605505166_NTREAL) CALL SetCoefficient(polynomial,9,-0.0066133591188_NTREAL) CALL SetCoefficient(polynomial,10,0.00229833505456_NTREAL) CALL SetCoefficient(polynomial,11,-0.000577804103964_NTREAL) CALL SetCoefficient(polynomial,12,2.2849332964e-05_NTREAL) CALL SetCoefficient(polynomial,13,8.37426826403e-05_NTREAL) CALL SetCoefficient(polynomial,14,-6.10822859027e-05_NTREAL) CALL SetCoefficient(polynomial,15,2.58132364523e-05_NTREAL) CALL SetCoefficient(polynomial,16,-5.87577322647e-06_NTREAL) CALL SetCoefficient(polynomial,17,-8.56711062722e-07_NTREAL) CALL SetCoefficient(polynomial,18,1.52066488969e-06_NTREAL) CALL SetCoefficient(polynomial,19,-7.12760496253e-07_NTREAL) CALL SetCoefficient(polynomial,20,1.23102245249e-07_NTREAL) CALL SetCoefficient(polynomial,21,6.03168259043e-08_NTREAL) CALL SetCoefficient(polynomial,22,-5.1865499826e-08_NTREAL) CALL SetCoefficient(polynomial,23,1.43185107512e-08_NTREAL) CALL SetCoefficient(polynomial,24,2.58449717089e-09_NTREAL) CALL SetCoefficient(polynomial,25,-3.73189861771e-09_NTREAL) CALL SetCoefficient(polynomial,26,1.18469334815e-09_NTREAL) CALL SetCoefficient(polynomial,27,1.51569931066e-10_NTREAL) CALL SetCoefficient(polynomial,28,-2.89595999673e-10_NTREAL) CALL SetCoefficient(polynomial,29,1.26720668874e-10_NTREAL) CALL SetCoefficient(polynomial,30,-3.00079067694e-11_NTREAL) CALL SetCoefficient(polynomial,31,3.91175568865e-12_NTREAL) CALL SetCoefficient(polynomial,32,-2.21155654398e-13_NTREAL) CALL FactorizedCompute(ScaledMat, OutputMat, polynomial, & & f_sub_solver_parameters) !! Scale Back CALL ScaleMatrix(OutputMat, & & REAL(2**(sigma_counter-1),NTREAL)) !! Cleanup IF (solver_parameters%be_verbose) THEN CALL ExitSubLog END IF CALL DestructPolynomial(polynomial) CALL DestructMatrix(ScaledMat) CALL DestructMatrix(IdentityMat) CALL DestructMatrix(TempMat) CALL DestructSolverParameters(solver_parameters) END SUBROUTINE ComputeLogarithm !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Compute the logarithm of a matrix using a taylor series expansion. SUBROUTINE ComputeLogarithmTaylor(InputMat, OutputMat, solver_parameters_in) !> The input matrix TYPE(Matrix_ps), INTENT(IN) :: InputMat !> OutputMat = exp(InputMat) TYPE(Matrix_ps), INTENT(INOUT) :: OutputMat !> Parameters for the solver TYPE(SolverParameters_t), INTENT(IN), OPTIONAL :: solver_parameters_in !! Handling Solver Parameters TYPE(SolverParameters_t) :: solver_parameters !! Local Matrices TYPE(Matrix_ps) :: ScaledMat TYPE(Matrix_ps) :: TempMat TYPE(Matrix_ps) :: Ak TYPE(Matrix_ps) :: IdentityMat TYPE(MatrixMemoryPool_p) :: pool !! Local Variables TYPE(SolverParameters_t) :: sub_solver_parameters REAL(NTREAL) :: e_min, e_max, spectral_radius REAL(NTREAL) :: sigma_val REAL(NTREAL) :: taylor_denom INTEGER :: sigma_counter INTEGER :: counter !! Handle The Optional Parameters !! Optional Parameters IF (PRESENT(solver_parameters_in)) THEN solver_parameters = solver_parameters_in ELSE solver_parameters = SolverParameters_t() END IF sub_solver_parameters = solver_parameters IF (solver_parameters%be_verbose) THEN CALL WriteHeader("Logarithm Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="Taylor") CALL PrintParameters(solver_parameters) END IF !! Compute The Scaling Factor CALL GershgorinBounds(InputMat, e_min, e_max) spectral_radius = MAX(ABS(e_min), ABS(e_max)) !! Figure out how much to scale the matrix. sigma_val = 1.0 sigma_counter = 1 CALL CopyMatrix(InputMat,ScaledMat) !do while (spectral_radius/sigma_val .gt. 1.1e-5) DO WHILE (spectral_radius/sigma_val .GT. 1.1e-7) CALL SquareRoot(ScaledMat,TempMat,sub_solver_parameters) CALL CopyMatrix(TempMat,ScaledMat) CALL GershgorinBounds(ScaledMat, e_min, e_max) spectral_radius = MAX(ABS(e_min), ABS(e_max)) sigma_val = sigma_val * 2 sigma_counter = sigma_counter + 1 END DO CALL ConstructEmptyMatrix(IdentityMat, InputMat) CALL FillMatrixIdentity(IdentityMat) !! Setup Matrices CALL IncrementMatrix(IdentityMat,ScaledMat, & & alpha_in=REAL(-1.0,NTREAL)) CALL CopyMatrix(IdentityMat,Ak) !! Load Balancing Step IF (solver_parameters%do_load_balancing) THEN CALL PermuteMatrix(ScaledMat, ScaledMat, & & solver_parameters%BalancePermutation, memorypool_in=pool) CALL PermuteMatrix(Ak, Ak, & & solver_parameters%BalancePermutation, memorypool_in=pool) END IF !! Expand taylor series. CALL CopyMatrix(ScaledMat,OutputMat) DO counter=2,10 IF (MOD(counter,2) .EQ. 0) THEN taylor_denom = -1 * counter ELSE taylor_denom = counter END IF CALL MatrixMultiply(Ak,ScaledMat,TempMat, & & threshold_in=solver_parameters%threshold, memory_pool_in=pool) CALL CopyMatrix(TempMat,Ak) CALL IncrementMatrix(Ak, OutputMat, & & alpha_in=1.0/taylor_denom) END DO !! Undo scaling. CALL ScaleMatrix(OutputMat,REAL(2**sigma_counter,NTREAL)) !! Undo load balancing. IF (solver_parameters%do_load_balancing) THEN CALL UndoPermuteMatrix(OutputMat, OutputMat, & & solver_parameters%BalancePermutation, memorypool_in=pool) END IF !! Cleanup IF (solver_parameters%be_verbose) THEN CALL ExitSubLog END IF CALL DestructMatrix(ScaledMat) CALL DestructMatrix(TempMat) CALL DestructMatrix(IdentityMat) CALL DestructMatrix(Ak) CALL DestructMatrixMemoryPool(pool) CALL DestructSolverParameters(solver_parameters) END SUBROUTINE ComputeLogarithmTaylor !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! END MODULE ExponentialSolversModule
mit
tkelman/OpenBLAS
lapack-netlib/SRC/sgegv.f
94
25204
*> \brief <b> SGEEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices</b> * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download SGEGV + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgegv.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgegv.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgegv.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE SGEGV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR, ALPHAI, * BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER JOBVL, JOBVR * INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N * .. * .. Array Arguments .. * REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), * $ B( LDB, * ), BETA( * ), VL( LDVL, * ), * $ VR( LDVR, * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> This routine is deprecated and has been replaced by routine SGGEV. *> *> SGEGV computes the eigenvalues and, optionally, the left and/or right *> eigenvectors of a real matrix pair (A,B). *> Given two square matrices A and B, *> the generalized nonsymmetric eigenvalue problem (GNEP) is to find the *> eigenvalues lambda and corresponding (non-zero) eigenvectors x such *> that *> *> A*x = lambda*B*x. *> *> An alternate form is to find the eigenvalues mu and corresponding *> eigenvectors y such that *> *> mu*A*y = B*y. *> *> These two forms are equivalent with mu = 1/lambda and x = y if *> neither lambda nor mu is zero. In order to deal with the case that *> lambda or mu is zero or small, two values alpha and beta are returned *> for each eigenvalue, such that lambda = alpha/beta and *> mu = beta/alpha. *> *> The vectors x and y in the above equations are right eigenvectors of *> the matrix pair (A,B). Vectors u and v satisfying *> *> u**H*A = lambda*u**H*B or mu*v**H*A = v**H*B *> *> are left eigenvectors of (A,B). *> *> Note: this routine performs "full balancing" on A and B *> \endverbatim * * Arguments: * ========== * *> \param[in] JOBVL *> \verbatim *> JOBVL is CHARACTER*1 *> = 'N': do not compute the left generalized eigenvectors; *> = 'V': compute the left generalized eigenvectors (returned *> in VL). *> \endverbatim *> *> \param[in] JOBVR *> \verbatim *> JOBVR is CHARACTER*1 *> = 'N': do not compute the right generalized eigenvectors; *> = 'V': compute the right generalized eigenvectors (returned *> in VR). *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrices A, B, VL, and VR. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is REAL array, dimension (LDA, N) *> On entry, the matrix A. *> If JOBVL = 'V' or JOBVR = 'V', then on exit A *> contains the real Schur form of A from the generalized Schur *> factorization of the pair (A,B) after balancing. *> If no eigenvectors were computed, then only the diagonal *> blocks from the Schur form will be correct. See SGGHRD and *> SHGEQZ for details. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of A. LDA >= max(1,N). *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is REAL array, dimension (LDB, N) *> On entry, the matrix B. *> If JOBVL = 'V' or JOBVR = 'V', then on exit B contains the *> upper triangular matrix obtained from B in the generalized *> Schur factorization of the pair (A,B) after balancing. *> If no eigenvectors were computed, then only those elements of *> B corresponding to the diagonal blocks from the Schur form of *> A will be correct. See SGGHRD and SHGEQZ for details. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of B. LDB >= max(1,N). *> \endverbatim *> *> \param[out] ALPHAR *> \verbatim *> ALPHAR is REAL array, dimension (N) *> The real parts of each scalar alpha defining an eigenvalue of *> GNEP. *> \endverbatim *> *> \param[out] ALPHAI *> \verbatim *> ALPHAI is REAL array, dimension (N) *> The imaginary parts of each scalar alpha defining an *> eigenvalue of GNEP. If ALPHAI(j) is zero, then the j-th *> eigenvalue is real; if positive, then the j-th and *> (j+1)-st eigenvalues are a complex conjugate pair, with *> ALPHAI(j+1) = -ALPHAI(j). *> \endverbatim *> *> \param[out] BETA *> \verbatim *> BETA is REAL array, dimension (N) *> The scalars beta that define the eigenvalues of GNEP. *> *> Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and *> beta = BETA(j) represent the j-th eigenvalue of the matrix *> pair (A,B), in one of the forms lambda = alpha/beta or *> mu = beta/alpha. Since either lambda or mu may overflow, *> they should not, in general, be computed. *> \endverbatim *> *> \param[out] VL *> \verbatim *> VL is REAL array, dimension (LDVL,N) *> If JOBVL = 'V', the left eigenvectors u(j) are stored *> in the columns of VL, in the same order as their eigenvalues. *> If the j-th eigenvalue is real, then u(j) = VL(:,j). *> If the j-th and (j+1)-st eigenvalues form a complex conjugate *> pair, then *> u(j) = VL(:,j) + i*VL(:,j+1) *> and *> u(j+1) = VL(:,j) - i*VL(:,j+1). *> *> Each eigenvector is scaled so that its largest component has *> abs(real part) + abs(imag. part) = 1, except for eigenvectors *> corresponding to an eigenvalue with alpha = beta = 0, which *> are set to zero. *> Not referenced if JOBVL = 'N'. *> \endverbatim *> *> \param[in] LDVL *> \verbatim *> LDVL is INTEGER *> The leading dimension of the matrix VL. LDVL >= 1, and *> if JOBVL = 'V', LDVL >= N. *> \endverbatim *> *> \param[out] VR *> \verbatim *> VR is REAL array, dimension (LDVR,N) *> If JOBVR = 'V', the right eigenvectors x(j) are stored *> in the columns of VR, in the same order as their eigenvalues. *> If the j-th eigenvalue is real, then x(j) = VR(:,j). *> If the j-th and (j+1)-st eigenvalues form a complex conjugate *> pair, then *> x(j) = VR(:,j) + i*VR(:,j+1) *> and *> x(j+1) = VR(:,j) - i*VR(:,j+1). *> *> Each eigenvector is scaled so that its largest component has *> abs(real part) + abs(imag. part) = 1, except for eigenvalues *> corresponding to an eigenvalue with alpha = beta = 0, which *> are set to zero. *> Not referenced if JOBVR = 'N'. *> \endverbatim *> *> \param[in] LDVR *> \verbatim *> LDVR is INTEGER *> The leading dimension of the matrix VR. LDVR >= 1, and *> if JOBVR = 'V', LDVR >= N. *> \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,8*N). *> For good performance, LWORK must generally be larger. *> To compute the optimal value of LWORK, call ILAENV to get *> blocksizes (for SGEQRF, SORMQR, and SORGQR.) Then compute: *> NB -- MAX of the blocksizes for SGEQRF, SORMQR, and SORGQR; *> The optimal LWORK is: *> 2*N + MAX( 6*N, N*(NB+1) ). *> *> 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,...,N: *> The QZ iteration failed. No eigenvectors have been *> calculated, but ALPHAR(j), ALPHAI(j), and BETA(j) *> should be correct for j=INFO+1,...,N. *> > N: errors that usually indicate LAPACK problems: *> =N+1: error return from SGGBAL *> =N+2: error return from SGEQRF *> =N+3: error return from SORMQR *> =N+4: error return from SORGQR *> =N+5: error return from SGGHRD *> =N+6: error return from SHGEQZ (other than failed *> iteration) *> =N+7: error return from STGEVC *> =N+8: error return from SGGBAK (computing VL) *> =N+9: error return from SGGBAK (computing VR) *> =N+10: error return from SLASCL (various calls) *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup realGEeigen * *> \par Further Details: * ===================== *> *> \verbatim *> *> Balancing *> --------- *> *> This driver calls SGGBAL to both permute and scale rows and columns *> of A and B. The permutations PL and PR are chosen so that PL*A*PR *> and PL*B*R will be upper triangular except for the diagonal blocks *> A(i:j,i:j) and B(i:j,i:j), with i and j as close together as *> possible. The diagonal scaling matrices DL and DR are chosen so *> that the pair DL*PL*A*PR*DR, DL*PL*B*PR*DR have elements close to *> one (except for the elements that start out zero.) *> *> After the eigenvalues and eigenvectors of the balanced matrices *> have been computed, SGGBAK transforms the eigenvectors back to what *> they would have been (in perfect arithmetic) if they had not been *> balanced. *> *> Contents of A and B on Exit *> -------- -- - --- - -- ---- *> *> If any eigenvectors are computed (either JOBVL='V' or JOBVR='V' or *> both), then on exit the arrays A and B will contain the real Schur *> form[*] of the "balanced" versions of A and B. If no eigenvectors *> are computed, then only the diagonal blocks will be correct. *> *> [*] See SHGEQZ, SGEGS, or read the book "Matrix Computations", *> by Golub & van Loan, pub. by Johns Hopkins U. Press. *> \endverbatim *> * ===================================================================== SUBROUTINE SGEGV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR, ALPHAI, $ BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO ) * * -- LAPACK driver 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 JOBVL, JOBVR INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N * .. * .. Array Arguments .. REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), $ B( LDB, * ), BETA( * ), VL( LDVL, * ), $ VR( LDVR, * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 ) * .. * .. Local Scalars .. LOGICAL ILIMIT, ILV, ILVL, ILVR, LQUERY CHARACTER CHTEMP INTEGER ICOLS, IHI, IINFO, IJOBVL, IJOBVR, ILEFT, ILO, $ IN, IRIGHT, IROWS, ITAU, IWORK, JC, JR, LOPT, $ LWKMIN, LWKOPT, NB, NB1, NB2, NB3 REAL ABSAI, ABSAR, ABSB, ANRM, ANRM1, ANRM2, BNRM, $ BNRM1, BNRM2, EPS, ONEPLS, SAFMAX, SAFMIN, $ SALFAI, SALFAR, SBETA, SCALE, TEMP * .. * .. Local Arrays .. LOGICAL LDUMMA( 1 ) * .. * .. External Subroutines .. EXTERNAL SGEQRF, SGGBAK, SGGBAL, SGGHRD, SHGEQZ, SLACPY, $ SLASCL, SLASET, SORGQR, SORMQR, STGEVC, XERBLA * .. * .. External Functions .. LOGICAL LSAME INTEGER ILAENV REAL SLAMCH, SLANGE EXTERNAL ILAENV, LSAME, SLAMCH, SLANGE * .. * .. Intrinsic Functions .. INTRINSIC ABS, INT, MAX * .. * .. Executable Statements .. * * Decode the input arguments * IF( LSAME( JOBVL, 'N' ) ) THEN IJOBVL = 1 ILVL = .FALSE. ELSE IF( LSAME( JOBVL, 'V' ) ) THEN IJOBVL = 2 ILVL = .TRUE. ELSE IJOBVL = -1 ILVL = .FALSE. END IF * IF( LSAME( JOBVR, 'N' ) ) THEN IJOBVR = 1 ILVR = .FALSE. ELSE IF( LSAME( JOBVR, 'V' ) ) THEN IJOBVR = 2 ILVR = .TRUE. ELSE IJOBVR = -1 ILVR = .FALSE. END IF ILV = ILVL .OR. ILVR * * Test the input arguments * LWKMIN = MAX( 8*N, 1 ) LWKOPT = LWKMIN WORK( 1 ) = LWKOPT LQUERY = ( LWORK.EQ.-1 ) INFO = 0 IF( IJOBVL.LE.0 ) THEN INFO = -1 ELSE IF( IJOBVR.LE.0 ) THEN INFO = -2 ELSE 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( LDVL.LT.1 .OR. ( ILVL .AND. LDVL.LT.N ) ) THEN INFO = -12 ELSE IF( LDVR.LT.1 .OR. ( ILVR .AND. LDVR.LT.N ) ) THEN INFO = -14 ELSE IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN INFO = -16 END IF * IF( INFO.EQ.0 ) THEN NB1 = ILAENV( 1, 'SGEQRF', ' ', N, N, -1, -1 ) NB2 = ILAENV( 1, 'SORMQR', ' ', N, N, N, -1 ) NB3 = ILAENV( 1, 'SORGQR', ' ', N, N, N, -1 ) NB = MAX( NB1, NB2, NB3 ) LOPT = 2*N + MAX( 6*N, N*(NB+1) ) WORK( 1 ) = LOPT END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'SGEGV ', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN * * Get machine constants * EPS = SLAMCH( 'E' )*SLAMCH( 'B' ) SAFMIN = SLAMCH( 'S' ) SAFMIN = SAFMIN + SAFMIN SAFMAX = ONE / SAFMIN ONEPLS = ONE + ( 4*EPS ) * * Scale A * ANRM = SLANGE( 'M', N, N, A, LDA, WORK ) ANRM1 = ANRM ANRM2 = ONE IF( ANRM.LT.ONE ) THEN IF( SAFMAX*ANRM.LT.ONE ) THEN ANRM1 = SAFMIN ANRM2 = SAFMAX*ANRM END IF END IF * IF( ANRM.GT.ZERO ) THEN CALL SLASCL( 'G', -1, -1, ANRM, ONE, N, N, A, LDA, IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 10 RETURN END IF END IF * * Scale B * BNRM = SLANGE( 'M', N, N, B, LDB, WORK ) BNRM1 = BNRM BNRM2 = ONE IF( BNRM.LT.ONE ) THEN IF( SAFMAX*BNRM.LT.ONE ) THEN BNRM1 = SAFMIN BNRM2 = SAFMAX*BNRM END IF END IF * IF( BNRM.GT.ZERO ) THEN CALL SLASCL( 'G', -1, -1, BNRM, ONE, N, N, B, LDB, IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 10 RETURN END IF END IF * * Permute the matrix to make it more nearly triangular * Workspace layout: (8*N words -- "work" requires 6*N words) * left_permutation, right_permutation, work... * ILEFT = 1 IRIGHT = N + 1 IWORK = IRIGHT + N CALL SGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, WORK( ILEFT ), $ WORK( IRIGHT ), WORK( IWORK ), IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 1 GO TO 120 END IF * * Reduce B to triangular form, and initialize VL and/or VR * Workspace layout: ("work..." must have at least N words) * left_permutation, right_permutation, tau, work... * IROWS = IHI + 1 - ILO IF( ILV ) THEN ICOLS = N + 1 - ILO ELSE ICOLS = IROWS END IF ITAU = IWORK IWORK = ITAU + IROWS CALL SGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ), $ WORK( IWORK ), LWORK+1-IWORK, IINFO ) IF( IINFO.GE.0 ) $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 ) IF( IINFO.NE.0 ) THEN INFO = N + 2 GO TO 120 END IF * CALL SORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB, $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWORK ), $ LWORK+1-IWORK, IINFO ) IF( IINFO.GE.0 ) $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 ) IF( IINFO.NE.0 ) THEN INFO = N + 3 GO TO 120 END IF * IF( ILVL ) THEN CALL SLASET( 'Full', N, N, ZERO, ONE, VL, LDVL ) CALL SLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB, $ VL( ILO+1, ILO ), LDVL ) CALL SORGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL, $ WORK( ITAU ), WORK( IWORK ), LWORK+1-IWORK, $ IINFO ) IF( IINFO.GE.0 ) $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 ) IF( IINFO.NE.0 ) THEN INFO = N + 4 GO TO 120 END IF END IF * IF( ILVR ) $ CALL SLASET( 'Full', N, N, ZERO, ONE, VR, LDVR ) * * Reduce to generalized Hessenberg form * IF( ILV ) THEN * * Eigenvectors requested -- work on whole matrix. * CALL SGGHRD( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL, $ LDVL, VR, LDVR, IINFO ) ELSE CALL SGGHRD( 'N', 'N', IROWS, 1, IROWS, A( ILO, ILO ), LDA, $ B( ILO, ILO ), LDB, VL, LDVL, VR, LDVR, IINFO ) END IF IF( IINFO.NE.0 ) THEN INFO = N + 5 GO TO 120 END IF * * Perform QZ algorithm * Workspace layout: ("work..." must have at least 1 word) * left_permutation, right_permutation, work... * IWORK = ITAU IF( ILV ) THEN CHTEMP = 'S' ELSE CHTEMP = 'E' END IF CALL SHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, $ WORK( IWORK ), LWORK+1-IWORK, IINFO ) IF( IINFO.GE.0 ) $ LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 ) IF( IINFO.NE.0 ) THEN IF( IINFO.GT.0 .AND. IINFO.LE.N ) THEN INFO = IINFO ELSE IF( IINFO.GT.N .AND. IINFO.LE.2*N ) THEN INFO = IINFO - N ELSE INFO = N + 6 END IF GO TO 120 END IF * IF( ILV ) THEN * * Compute Eigenvectors (STGEVC requires 6*N words of workspace) * IF( ILVL ) THEN IF( ILVR ) THEN CHTEMP = 'B' ELSE CHTEMP = 'L' END IF ELSE CHTEMP = 'R' END IF * CALL STGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL, LDVL, $ VR, LDVR, N, IN, WORK( IWORK ), IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 7 GO TO 120 END IF * * Undo balancing on VL and VR, rescale * IF( ILVL ) THEN CALL SGGBAK( 'P', 'L', N, ILO, IHI, WORK( ILEFT ), $ WORK( IRIGHT ), N, VL, LDVL, IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 8 GO TO 120 END IF DO 50 JC = 1, N IF( ALPHAI( JC ).LT.ZERO ) $ GO TO 50 TEMP = ZERO IF( ALPHAI( JC ).EQ.ZERO ) THEN DO 10 JR = 1, N TEMP = MAX( TEMP, ABS( VL( JR, JC ) ) ) 10 CONTINUE ELSE DO 20 JR = 1, N TEMP = MAX( TEMP, ABS( VL( JR, JC ) )+ $ ABS( VL( JR, JC+1 ) ) ) 20 CONTINUE END IF IF( TEMP.LT.SAFMIN ) $ GO TO 50 TEMP = ONE / TEMP IF( ALPHAI( JC ).EQ.ZERO ) THEN DO 30 JR = 1, N VL( JR, JC ) = VL( JR, JC )*TEMP 30 CONTINUE ELSE DO 40 JR = 1, N VL( JR, JC ) = VL( JR, JC )*TEMP VL( JR, JC+1 ) = VL( JR, JC+1 )*TEMP 40 CONTINUE END IF 50 CONTINUE END IF IF( ILVR ) THEN CALL SGGBAK( 'P', 'R', N, ILO, IHI, WORK( ILEFT ), $ WORK( IRIGHT ), N, VR, LDVR, IINFO ) IF( IINFO.NE.0 ) THEN INFO = N + 9 GO TO 120 END IF DO 100 JC = 1, N IF( ALPHAI( JC ).LT.ZERO ) $ GO TO 100 TEMP = ZERO IF( ALPHAI( JC ).EQ.ZERO ) THEN DO 60 JR = 1, N TEMP = MAX( TEMP, ABS( VR( JR, JC ) ) ) 60 CONTINUE ELSE DO 70 JR = 1, N TEMP = MAX( TEMP, ABS( VR( JR, JC ) )+ $ ABS( VR( JR, JC+1 ) ) ) 70 CONTINUE END IF IF( TEMP.LT.SAFMIN ) $ GO TO 100 TEMP = ONE / TEMP IF( ALPHAI( JC ).EQ.ZERO ) THEN DO 80 JR = 1, N VR( JR, JC ) = VR( JR, JC )*TEMP 80 CONTINUE ELSE DO 90 JR = 1, N VR( JR, JC ) = VR( JR, JC )*TEMP VR( JR, JC+1 ) = VR( JR, JC+1 )*TEMP 90 CONTINUE END IF 100 CONTINUE END IF * * End of eigenvector calculation * END IF * * Undo scaling in alpha, beta * * Note: this does not give the alpha and beta for the unscaled * problem. * * Un-scaling is limited to avoid underflow in alpha and beta * if they are significant. * DO 110 JC = 1, N ABSAR = ABS( ALPHAR( JC ) ) ABSAI = ABS( ALPHAI( JC ) ) ABSB = ABS( BETA( JC ) ) SALFAR = ANRM*ALPHAR( JC ) SALFAI = ANRM*ALPHAI( JC ) SBETA = BNRM*BETA( JC ) ILIMIT = .FALSE. SCALE = ONE * * Check for significant underflow in ALPHAI * IF( ABS( SALFAI ).LT.SAFMIN .AND. ABSAI.GE. $ MAX( SAFMIN, EPS*ABSAR, EPS*ABSB ) ) THEN ILIMIT = .TRUE. SCALE = ( ONEPLS*SAFMIN / ANRM1 ) / $ MAX( ONEPLS*SAFMIN, ANRM2*ABSAI ) * ELSE IF( SALFAI.EQ.ZERO ) THEN * * If insignificant underflow in ALPHAI, then make the * conjugate eigenvalue real. * IF( ALPHAI( JC ).LT.ZERO .AND. JC.GT.1 ) THEN ALPHAI( JC-1 ) = ZERO ELSE IF( ALPHAI( JC ).GT.ZERO .AND. JC.LT.N ) THEN ALPHAI( JC+1 ) = ZERO END IF END IF * * Check for significant underflow in ALPHAR * IF( ABS( SALFAR ).LT.SAFMIN .AND. ABSAR.GE. $ MAX( SAFMIN, EPS*ABSAI, EPS*ABSB ) ) THEN ILIMIT = .TRUE. SCALE = MAX( SCALE, ( ONEPLS*SAFMIN / ANRM1 ) / $ MAX( ONEPLS*SAFMIN, ANRM2*ABSAR ) ) END IF * * Check for significant underflow in BETA * IF( ABS( SBETA ).LT.SAFMIN .AND. ABSB.GE. $ MAX( SAFMIN, EPS*ABSAR, EPS*ABSAI ) ) THEN ILIMIT = .TRUE. SCALE = MAX( SCALE, ( ONEPLS*SAFMIN / BNRM1 ) / $ MAX( ONEPLS*SAFMIN, BNRM2*ABSB ) ) END IF * * Check for possible overflow when limiting scaling * IF( ILIMIT ) THEN TEMP = ( SCALE*SAFMIN )*MAX( ABS( SALFAR ), ABS( SALFAI ), $ ABS( SBETA ) ) IF( TEMP.GT.ONE ) $ SCALE = SCALE / TEMP IF( SCALE.LT.ONE ) $ ILIMIT = .FALSE. END IF * * Recompute un-scaled ALPHAR, ALPHAI, BETA if necessary. * IF( ILIMIT ) THEN SALFAR = ( SCALE*ALPHAR( JC ) )*ANRM SALFAI = ( SCALE*ALPHAI( JC ) )*ANRM SBETA = ( SCALE*BETA( JC ) )*BNRM END IF ALPHAR( JC ) = SALFAR ALPHAI( JC ) = SALFAI BETA( JC ) = SBETA 110 CONTINUE * 120 CONTINUE WORK( 1 ) = LWKOPT * RETURN * * End of SGEGV * END
bsd-3-clause
tkelman/OpenBLAS
lapack-netlib/SRC/clahef_rook.f
27
39771
* \brief \b CLAHEF_ROOK computes a partial factorization of a complex Hermitian indefinite matrix using the bounded Bunch-Kaufman ("rook") diagonal pivoting method (blocked algorithm, calling Level 3 BLAS). * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CLAHEF_ROOK + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clahef_rook.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clahef_rook.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clahef_rook.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CLAHEF_ROOK( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INFO, KB, LDA, LDW, N, NB * .. * .. Array Arguments .. * INTEGER IPIV( * ) * COMPLEX A( LDA, * ), W( LDW, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CLAHEF_ROOK computes a partial factorization of a complex Hermitian *> matrix A using the bounded Bunch-Kaufman ("rook") diagonal pivoting *> method. The partial factorization has the form: *> *> A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or: *> ( 0 U22 ) ( 0 D ) ( U12**H U22**H ) *> *> A = ( L11 0 ) ( D 0 ) ( L11**H L21**H ) if UPLO = 'L' *> ( L21 I ) ( 0 A22 ) ( 0 I ) *> *> where the order of D is at most NB. The actual order is returned in *> the argument KB, and is either NB or NB-1, or N if N <= NB. *> Note that U**H denotes the conjugate transpose of U. *> *> CLAHEF_ROOK is an auxiliary routine called by CHETRF_ROOK. It uses *> blocked code (calling Level 3 BLAS) to update the submatrix *> A11 (if UPLO = 'U') or A22 (if UPLO = 'L'). *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> Specifies whether the upper or lower triangular part of the *> Hermitian matrix A is stored: *> = 'U': Upper triangular *> = 'L': Lower triangular *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] NB *> \verbatim *> NB is INTEGER *> The maximum number of columns of the matrix A that should be *> factored. NB should be at least 2 to allow for 2-by-2 pivot *> blocks. *> \endverbatim *> *> \param[out] KB *> \verbatim *> KB is INTEGER *> The number of columns of A that were actually factored. *> KB is either NB-1 or NB, or N if N <= NB. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX array, dimension (LDA,N) *> On entry, the Hermitian 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, A contains details of the partial factorization. *> \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': *> Only the last KB elements of IPIV are set. *> *> 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': *> Only the first KB elements of IPIV are set. *> *> 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] W *> \verbatim *> W is COMPLEX array, dimension (LDW,NB) *> \endverbatim *> *> \param[in] LDW *> \verbatim *> LDW is INTEGER *> The leading dimension of the array W. LDW >= max(1,N). *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> > 0: if INFO = k, D(k,k) is exactly zero. The factorization *> has been completed, but the block diagonal matrix D is *> exactly singular. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2013 * *> \ingroup complexHEcomputational * *> \par Contributors: * ================== *> *> \verbatim *> *> November 2013, 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 CLAHEF_ROOK( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, $ INFO ) * * -- LAPACK computational routine (version 3.5.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2013 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, KB, LDA, LDW, N, NB * .. * .. Array Arguments .. INTEGER IPIV( * ) COMPLEX A( LDA, * ), W( LDW, * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) COMPLEX CONE PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) ) REAL EIGHT, SEVTEN PARAMETER ( EIGHT = 8.0E+0, SEVTEN = 17.0E+0 ) * .. * .. Local Scalars .. LOGICAL DONE INTEGER IMAX, ITEMP, II, J, JB, JJ, JMAX, JP1, JP2, K, $ KK, KKW, KP, KSTEP, KW, P REAL ABSAKK, ALPHA, COLMAX, STEMP, R1, ROWMAX, T, $ SFMIN COMPLEX D11, D21, D22, Z * .. * .. External Functions .. LOGICAL LSAME INTEGER ICAMAX REAL SLAMCH EXTERNAL LSAME, ICAMAX, SLAMCH * .. * .. External Subroutines .. EXTERNAL CCOPY, CSSCAL, CGEMM, CGEMV, CLACGV, CSWAP * .. * .. Intrinsic Functions .. INTRINSIC ABS, CONJG, AIMAG, MAX, MIN, REAL, SQRT * .. * .. Statement Functions .. REAL CABS1 * .. * .. Statement Function definitions .. CABS1( Z ) = ABS( REAL( Z ) ) + ABS( AIMAG( Z ) ) * .. * .. Executable Statements .. * INFO = 0 * * Initialize ALPHA for use in choosing pivot block size. * ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT * * Compute machine safe minimum * SFMIN = SLAMCH( 'S' ) * IF( LSAME( UPLO, 'U' ) ) THEN * * Factorize the trailing columns of A using the upper triangle * of A and working backwards, and compute the matrix W = U12*D * for use in updating A11 (note that conjg(W) is actually stored) * * K is the main loop index, decreasing from N in steps of 1 or 2 * K = N 10 CONTINUE * * KW is the column of W which corresponds to column K of A * KW = NB + K - N * * Exit from loop * IF( ( K.LE.N-NB+1 .AND. NB.LT.N ) .OR. K.LT.1 ) $ GO TO 30 * KSTEP = 1 P = K * * Copy column K of A to column KW of W and update it * IF( K.GT.1 ) $ CALL CCOPY( K-1, A( 1, K ), 1, W( 1, KW ), 1 ) W( K, KW ) = REAL( A( K, K ) ) IF( K.LT.N ) THEN CALL CGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ), LDA, $ W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 ) W( K, KW ) = REAL( W( K, KW ) ) END IF * * Determine rows and columns to be interchanged and whether * a 1-by-1 or 2-by-2 pivot block will be used * ABSAKK = ABS( REAL( W( K, KW ) ) ) * * IMAX is the row-index of the largest off-diagonal element in * column K, and COLMAX is its absolute value. * Determine both COLMAX and IMAX. * IF( K.GT.1 ) THEN IMAX = ICAMAX( K-1, W( 1, KW ), 1 ) COLMAX = CABS1( W( IMAX, KW ) ) ELSE COLMAX = ZERO END IF * IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN * * Column K is zero or underflow: set INFO and continue * IF( INFO.EQ.0 ) $ INFO = K KP = K A( K, K ) = REAL( W( K, KW ) ) IF( K.GT.1 ) $ CALL CCOPY( K-1, W( 1, KW ), 1, A( 1, K ), 1 ) ELSE * * ============================================================ * * BEGIN pivot search * * Case(1) * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX * (used to handle NaN and Inf) IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN * * no interchange, use 1-by-1 pivot block * KP = K * ELSE * * Lop until pivot found * DONE = .FALSE. * 12 CONTINUE * * BEGIN pivot search loop body * * * Copy column IMAX to column KW-1 of W and update it * IF( IMAX.GT.1 ) $ CALL CCOPY( IMAX-1, A( 1, IMAX ), 1, W( 1, KW-1 ), $ 1 ) W( IMAX, KW-1 ) = REAL( A( IMAX, IMAX ) ) * CALL CCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA, $ W( IMAX+1, KW-1 ), 1 ) CALL CLACGV( K-IMAX, W( IMAX+1, KW-1 ), 1 ) * IF( K.LT.N ) THEN CALL CGEMV( 'No transpose', K, N-K, -CONE, $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW, $ CONE, W( 1, KW-1 ), 1 ) W( IMAX, KW-1 ) = REAL( W( IMAX, KW-1 ) ) END IF * * JMAX is the column-index of the largest off-diagonal * element in row IMAX, and ROWMAX is its absolute value. * Determine both ROWMAX and JMAX. * IF( IMAX.NE.K ) THEN JMAX = IMAX + ICAMAX( K-IMAX, W( IMAX+1, KW-1 ), $ 1 ) ROWMAX = CABS1( W( JMAX, KW-1 ) ) ELSE ROWMAX = ZERO END IF * IF( IMAX.GT.1 ) THEN ITEMP = ICAMAX( IMAX-1, W( 1, KW-1 ), 1 ) STEMP = CABS1( W( ITEMP, KW-1 ) ) IF( STEMP.GT.ROWMAX ) THEN ROWMAX = STEMP JMAX = ITEMP END IF END IF * * Case(2) * Equivalent to testing for * ABS( REAL( W( IMAX,KW-1 ) ) ).GE.ALPHA*ROWMAX * (used to handle NaN and Inf) * IF( .NOT.( ABS( REAL( W( IMAX,KW-1 ) ) ) $ .LT.ALPHA*ROWMAX ) ) THEN * * interchange rows and columns K and IMAX, * use 1-by-1 pivot block * KP = IMAX * * copy column KW-1 of W to column KW of W * CALL CCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 ) * DONE = .TRUE. * * Case(3) * Equivalent to testing for ROWMAX.EQ.COLMAX, * (used to handle NaN and Inf) * ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) ) $ THEN * * interchange rows and columns K-1 and IMAX, * use 2-by-2 pivot block * KP = IMAX KSTEP = 2 DONE = .TRUE. * * Case(4) ELSE * * Pivot not found: set params and repeat * P = IMAX COLMAX = ROWMAX IMAX = JMAX * * Copy updated JMAXth (next IMAXth) column to Kth of W * CALL CCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 ) * END IF * * * END pivot search loop body * IF( .NOT.DONE ) GOTO 12 * END IF * * END pivot search * * ============================================================ * * KK is the column of A where pivoting step stopped * KK = K - KSTEP + 1 * * KKW is the column of W which corresponds to column KK of A * KKW = NB + KK - N * * Interchange rows and columns P and K. * Updated column P is already stored in column KW of W. * IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN * * Copy non-updated column K to column P of submatrix A * at step K. No need to copy element into columns * K and K-1 of A for 2-by-2 pivot, since these columns * will be later overwritten. * A( P, P ) = REAL( A( K, K ) ) CALL CCOPY( K-1-P, A( P+1, K ), 1, A( P, P+1 ), $ LDA ) CALL CLACGV( K-1-P, A( P, P+1 ), LDA ) IF( P.GT.1 ) $ CALL CCOPY( P-1, A( 1, K ), 1, A( 1, P ), 1 ) * * Interchange rows K and P in the last K+1 to N columns of A * (columns K and K-1 of A for 2-by-2 pivot will be * later overwritten). Interchange rows K and P * in last KKW to NB columns of W. * IF( K.LT.N ) $ CALL CSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ), $ LDA ) CALL CSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ), $ LDW ) END IF * * Interchange rows and columns KP and KK. * Updated column KP is already stored in column KKW of W. * IF( KP.NE.KK ) THEN * * Copy non-updated column KK to column KP of submatrix A * at step K. No need to copy element into column K * (or K and K-1 for 2-by-2 pivot) of A, since these columns * will be later overwritten. * A( KP, KP ) = REAL( A( KK, KK ) ) CALL CCOPY( KK-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ), $ LDA ) CALL CLACGV( KK-1-KP, A( KP, KP+1 ), LDA ) IF( KP.GT.1 ) $ CALL CCOPY( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 ) * * Interchange rows KK and KP in last K+1 to N columns of A * (columns K (or K and K-1 for 2-by-2 pivot) of A will be * later overwritten). Interchange rows KK and KP * in last KKW to NB columns of W. * IF( K.LT.N ) $ CALL CSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ), $ LDA ) CALL CSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ), $ LDW ) END IF * IF( KSTEP.EQ.1 ) THEN * * 1-by-1 pivot block D(k): column kw of W now holds * * W(kw) = U(k)*D(k), * * where U(k) is the k-th column of U * * (1) Store subdiag. elements of column U(k) * and 1-by-1 block D(k) in column k of A. * (NOTE: Diagonal element U(k,k) is a UNIT element * and not stored) * A(k,k) := D(k,k) = W(k,kw) * A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k) * * (NOTE: No need to use for Hermitian matrix * A( K, K ) = REAL( W( K, K) ) to separately copy diagonal * element D(k,k) from W (potentially saves only one load)) CALL CCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 ) IF( K.GT.1 ) THEN * * (NOTE: No need to check if A(k,k) is NOT ZERO, * since that was ensured earlier in pivot search: * case A(k,k) = 0 falls into 2x2 pivot case(3)) * * Handle division by a small number * T = REAL( A( K, K ) ) IF( ABS( T ).GE.SFMIN ) THEN R1 = ONE / T CALL CSSCAL( K-1, R1, A( 1, K ), 1 ) ELSE DO 14 II = 1, K-1 A( II, K ) = A( II, K ) / T 14 CONTINUE END IF * * (2) Conjugate column W(kw) * CALL CLACGV( K-1, W( 1, KW ), 1 ) END IF * ELSE * * 2-by-2 pivot block D(k): columns kw and kw-1 of W now hold * * ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k) * * where U(k) and U(k-1) are the k-th and (k-1)-th columns * of U * * (1) Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2 * block D(k-1:k,k-1:k) in columns k-1 and k of A. * (NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT * block and not stored) * A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw) * A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) = * = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) ) * IF( K.GT.2 ) THEN * * Factor out the columns of the inverse of 2-by-2 pivot * block D, so that each column contains 1, to reduce the * number of FLOPS when we multiply panel * ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1). * * D**(-1) = ( d11 cj(d21) )**(-1) = * ( d21 d22 ) * * = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) = * ( (-d21) ( d11 ) ) * * = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) * * * * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) = * ( ( -1 ) ( d11/conj(d21) ) ) * * = 1/(|d21|**2) * 1/(D22*D11-1) * * * * ( d21*( D11 ) conj(d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * Handle division by a small number. (NOTE: order of * operations is important) * * = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) ) * ( (( -1 ) ) (( D22 ) ) ), * * where D11 = d22/d21, * D22 = d11/conj(d21), * D21 = d21, * T = 1/(D22*D11-1). * * (NOTE: No need to check for division by ZERO, * since that was ensured earlier in pivot search: * (a) d21 != 0 in 2x2 pivot case(4), * since |d21| should be larger than |d11| and |d22|; * (b) (D22*D11 - 1) != 0, since from (a), * both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.) * D21 = W( K-1, KW ) D11 = W( K, KW ) / CONJG( D21 ) D22 = W( K-1, KW-1 ) / D21 T = ONE / ( REAL( D11*D22 )-ONE ) * * Update elements in columns A(k-1) and A(k) as * dot products of rows of ( W(kw-1) W(kw) ) and columns * of D**(-1) * DO 20 J = 1, K - 2 A( J, K-1 ) = T*( ( D11*W( J, KW-1 )-W( J, KW ) ) / $ D21 ) A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) / $ CONJG( D21 ) ) 20 CONTINUE END IF * * Copy D(k) to A * A( K-1, K-1 ) = W( K-1, KW-1 ) A( K-1, K ) = W( K-1, KW ) A( K, K ) = W( K, KW ) * * (2) Conjugate columns W(kw) and W(kw-1) * CALL CLACGV( K-1, W( 1, KW ), 1 ) CALL CLACGV( K-2, W( 1, KW-1 ), 1 ) * END IF * END IF * * Store details of the interchanges in IPIV * IF( KSTEP.EQ.1 ) THEN IPIV( K ) = KP ELSE IPIV( K ) = -P IPIV( K-1 ) = -KP END IF * * Decrease K and return to the start of the main loop * K = K - KSTEP GO TO 10 * 30 CONTINUE * * Update the upper triangle of A11 (= A(1:k,1:k)) as * * A11 := A11 - U12*D*U12**H = A11 - U12*W**H * * computing blocks of NB columns at a time (note that conjg(W) is * actually stored) * DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB JB = MIN( NB, K-J+1 ) * * Update the upper triangle of the diagonal block * DO 40 JJ = J, J + JB - 1 A( JJ, JJ ) = REAL( A( JJ, JJ ) ) CALL CGEMV( 'No transpose', JJ-J+1, N-K, -CONE, $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE, $ A( J, JJ ), 1 ) A( JJ, JJ ) = REAL( A( JJ, JJ ) ) 40 CONTINUE * * Update the rectangular superdiagonal block * IF( J.GE.2 ) $ CALL CGEMM( 'No transpose', 'Transpose', J-1, JB, N-K, $ -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW, $ CONE, A( 1, J ), LDA ) 50 CONTINUE * * Put U12 in standard form by partially undoing the interchanges * in of rows in columns k+1:n looping backwards from k+1 to n * J = K + 1 60 CONTINUE * * Undo the interchanges (if any) of rows J and JP2 * (or J and JP2, and J+1 and JP1) at each step J * KSTEP = 1 JP1 = 1 * (Here, J is a diagonal index) JJ = J JP2 = IPIV( J ) IF( JP2.LT.0 ) THEN JP2 = -JP2 * (Here, J is a diagonal index) J = J + 1 JP1 = -IPIV( J ) KSTEP = 2 END IF * (NOTE: Here, J is used to determine row length. Length N-J+1 * of the rows to swap back doesn't include diagonal element) J = J + 1 IF( JP2.NE.JJ .AND. J.LE.N ) $ CALL CSWAP( N-J+1, A( JP2, J ), LDA, A( JJ, J ), LDA ) JJ = JJ + 1 IF( KSTEP.EQ.2 .AND. JP1.NE.JJ .AND. J.LE.N ) $ CALL CSWAP( N-J+1, A( JP1, J ), LDA, A( JJ, J ), LDA ) IF( J.LT.N ) $ GO TO 60 * * Set KB to the number of columns factorized * KB = N - K * ELSE * * Factorize the leading columns of A using the lower triangle * of A and working forwards, and compute the matrix W = L21*D * for use in updating A22 (note that conjg(W) is actually stored) * * K is the main loop index, increasing from 1 in steps of 1 or 2 * K = 1 70 CONTINUE * * Exit from loop * IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N ) $ GO TO 90 * KSTEP = 1 P = K * * Copy column K of A to column K of W and update column K of W * W( K, K ) = REAL( A( K, K ) ) IF( K.LT.N ) $ CALL CCOPY( N-K, A( K+1, K ), 1, W( K+1, K ), 1 ) IF( K.GT.1 ) THEN CALL CGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ), $ LDA, W( K, 1 ), LDW, CONE, W( K, K ), 1 ) W( K, K ) = REAL( W( K, K ) ) END IF * * Determine rows and columns to be interchanged and whether * a 1-by-1 or 2-by-2 pivot block will be used * ABSAKK = ABS( REAL( W( K, K ) ) ) * * IMAX is the row-index of the largest off-diagonal element in * column K, and COLMAX is its absolute value. * Determine both COLMAX and IMAX. * IF( K.LT.N ) THEN IMAX = K + ICAMAX( N-K, W( K+1, K ), 1 ) COLMAX = CABS1( W( IMAX, K ) ) ELSE COLMAX = ZERO END IF * IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN * * Column K is zero or underflow: set INFO and continue * IF( INFO.EQ.0 ) $ INFO = K KP = K A( K, K ) = REAL( W( K, K ) ) IF( K.LT.N ) $ CALL CCOPY( N-K, W( K+1, K ), 1, A( K+1, K ), 1 ) ELSE * * ============================================================ * * BEGIN pivot search * * Case(1) * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX * (used to handle NaN and Inf) * IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN * * no interchange, use 1-by-1 pivot block * KP = K * ELSE * DONE = .FALSE. * * Loop until pivot found * 72 CONTINUE * * BEGIN pivot search loop body * * * Copy column IMAX to column k+1 of W and update it * CALL CCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1) CALL CLACGV( IMAX-K, W( K, K+1 ), 1 ) W( IMAX, K+1 ) = REAL( A( IMAX, IMAX ) ) * IF( IMAX.LT.N ) $ CALL CCOPY( N-IMAX, A( IMAX+1, IMAX ), 1, $ W( IMAX+1, K+1 ), 1 ) * IF( K.GT.1 ) THEN CALL CGEMV( 'No transpose', N-K+1, K-1, -CONE, $ A( K, 1 ), LDA, W( IMAX, 1 ), LDW, $ CONE, W( K, K+1 ), 1 ) W( IMAX, K+1 ) = REAL( W( IMAX, K+1 ) ) END IF * * JMAX is the column-index of the largest off-diagonal * element in row IMAX, and ROWMAX is its absolute value. * Determine both ROWMAX and JMAX. * IF( IMAX.NE.K ) THEN JMAX = K - 1 + ICAMAX( IMAX-K, W( K, K+1 ), 1 ) ROWMAX = CABS1( W( JMAX, K+1 ) ) ELSE ROWMAX = ZERO END IF * IF( IMAX.LT.N ) THEN ITEMP = IMAX + ICAMAX( N-IMAX, W( IMAX+1, K+1 ), 1) STEMP = CABS1( W( ITEMP, K+1 ) ) IF( STEMP.GT.ROWMAX ) THEN ROWMAX = STEMP JMAX = ITEMP END IF END IF * * Case(2) * Equivalent to testing for * ABS( REAL( W( IMAX,K+1 ) ) ).GE.ALPHA*ROWMAX * (used to handle NaN and Inf) * IF( .NOT.( ABS( REAL( W( IMAX,K+1 ) ) ) $ .LT.ALPHA*ROWMAX ) ) THEN * * interchange rows and columns K and IMAX, * use 1-by-1 pivot block * KP = IMAX * * copy column K+1 of W to column K of W * CALL CCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 ) * DONE = .TRUE. * * Case(3) * Equivalent to testing for ROWMAX.EQ.COLMAX, * (used to handle NaN and Inf) * ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) ) $ THEN * * interchange rows and columns K+1 and IMAX, * use 2-by-2 pivot block * KP = IMAX KSTEP = 2 DONE = .TRUE. * * Case(4) ELSE * * Pivot not found: set params and repeat * P = IMAX COLMAX = ROWMAX IMAX = JMAX * * Copy updated JMAXth (next IMAXth) column to Kth of W * CALL CCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 ) * END IF * * * End pivot search loop body * IF( .NOT.DONE ) GOTO 72 * END IF * * END pivot search * * ============================================================ * * KK is the column of A where pivoting step stopped * KK = K + KSTEP - 1 * * Interchange rows and columns P and K (only for 2-by-2 pivot). * Updated column P is already stored in column K of W. * IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN * * Copy non-updated column KK-1 to column P of submatrix A * at step K. No need to copy element into columns * K and K+1 of A for 2-by-2 pivot, since these columns * will be later overwritten. * A( P, P ) = REAL( A( K, K ) ) CALL CCOPY( P-K-1, A( K+1, K ), 1, A( P, K+1 ), LDA ) CALL CLACGV( P-K-1, A( P, K+1 ), LDA ) IF( P.LT.N ) $ CALL CCOPY( N-P, A( P+1, K ), 1, A( P+1, P ), 1 ) * * Interchange rows K and P in first K-1 columns of A * (columns K and K+1 of A for 2-by-2 pivot will be * later overwritten). Interchange rows K and P * in first KK columns of W. * IF( K.GT.1 ) $ CALL CSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA ) CALL CSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW ) END IF * * Interchange rows and columns KP and KK. * Updated column KP is already stored in column KK of W. * IF( KP.NE.KK ) THEN * * Copy non-updated column KK to column KP of submatrix A * at step K. No need to copy element into column K * (or K and K+1 for 2-by-2 pivot) of A, since these columns * will be later overwritten. * A( KP, KP ) = REAL( A( KK, KK ) ) CALL CCOPY( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ), $ LDA ) CALL CLACGV( KP-KK-1, A( KP, KK+1 ), LDA ) IF( KP.LT.N ) $ CALL CCOPY( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 ) * * Interchange rows KK and KP in first K-1 columns of A * (column K (or K and K+1 for 2-by-2 pivot) of A will be * later overwritten). Interchange rows KK and KP * in first KK columns of W. * IF( K.GT.1 ) $ CALL CSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) CALL CSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW ) END IF * IF( KSTEP.EQ.1 ) THEN * * 1-by-1 pivot block D(k): column k of W now holds * * W(k) = L(k)*D(k), * * where L(k) is the k-th column of L * * (1) Store subdiag. elements of column L(k) * and 1-by-1 block D(k) in column k of A. * (NOTE: Diagonal element L(k,k) is a UNIT element * and not stored) * A(k,k) := D(k,k) = W(k,k) * A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k) * * (NOTE: No need to use for Hermitian matrix * A( K, K ) = REAL( W( K, K) ) to separately copy diagonal * element D(k,k) from W (potentially saves only one load)) CALL CCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 ) IF( K.LT.N ) THEN * * (NOTE: No need to check if A(k,k) is NOT ZERO, * since that was ensured earlier in pivot search: * case A(k,k) = 0 falls into 2x2 pivot case(3)) * * Handle division by a small number * T = REAL( A( K, K ) ) IF( ABS( T ).GE.SFMIN ) THEN R1 = ONE / T CALL CSSCAL( N-K, R1, A( K+1, K ), 1 ) ELSE DO 74 II = K + 1, N A( II, K ) = A( II, K ) / T 74 CONTINUE END IF * * (2) Conjugate column W(k) * CALL CLACGV( N-K, W( K+1, K ), 1 ) END IF * ELSE * * 2-by-2 pivot block D(k): columns k and k+1 of W now hold * * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) * * where L(k) and L(k+1) are the k-th and (k+1)-th columns * of L * * (1) Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2 * block D(k:k+1,k:k+1) in columns k and k+1 of A. * NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT * block and not stored. * A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1) * A(k+2:N,k:k+1) := L(k+2:N,k:k+1) = * = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) ) * IF( K.LT.N-1 ) THEN * * Factor out the columns of the inverse of 2-by-2 pivot * block D, so that each column contains 1, to reduce the * number of FLOPS when we multiply panel * ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1). * * D**(-1) = ( d11 cj(d21) )**(-1) = * ( d21 d22 ) * * = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) = * ( (-d21) ( d11 ) ) * * = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) * * * * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) = * ( ( -1 ) ( d11/conj(d21) ) ) * * = 1/(|d21|**2) * 1/(D22*D11-1) * * * * ( d21*( D11 ) conj(d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * Handle division by a small number. (NOTE: order of * operations is important) * * = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) ) * ( (( -1 ) ) (( D22 ) ) ), * * where D11 = d22/d21, * D22 = d11/conj(d21), * D21 = d21, * T = 1/(D22*D11-1). * * (NOTE: No need to check for division by ZERO, * since that was ensured earlier in pivot search: * (a) d21 != 0 in 2x2 pivot case(4), * since |d21| should be larger than |d11| and |d22|; * (b) (D22*D11 - 1) != 0, since from (a), * both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.) * D21 = W( K+1, K ) D11 = W( K+1, K+1 ) / D21 D22 = W( K, K ) / CONJG( D21 ) T = ONE / ( REAL( D11*D22 )-ONE ) * * Update elements in columns A(k) and A(k+1) as * dot products of rows of ( W(k) W(k+1) ) and columns * of D**(-1) * DO 80 J = K + 2, N A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) / $ CONJG( D21 ) ) A( J, K+1 ) = T*( ( D22*W( J, K+1 )-W( J, K ) ) / $ D21 ) 80 CONTINUE END IF * * Copy D(k) to A * A( K, K ) = W( K, K ) A( K+1, K ) = W( K+1, K ) A( K+1, K+1 ) = W( K+1, K+1 ) * * (2) Conjugate columns W(k) and W(k+1) * CALL CLACGV( N-K, W( K+1, K ), 1 ) CALL CLACGV( N-K-1, W( K+2, K+1 ), 1 ) * END IF * END IF * * Store details of the interchanges in IPIV * IF( KSTEP.EQ.1 ) THEN IPIV( K ) = KP ELSE IPIV( K ) = -P IPIV( K+1 ) = -KP END IF * * Increase K and return to the start of the main loop * K = K + KSTEP GO TO 70 * 90 CONTINUE * * Update the lower triangle of A22 (= A(k:n,k:n)) as * * A22 := A22 - L21*D*L21**H = A22 - L21*W**H * * computing blocks of NB columns at a time (note that conjg(W) is * actually stored) * DO 110 J = K, N, NB JB = MIN( NB, N-J+1 ) * * Update the lower triangle of the diagonal block * DO 100 JJ = J, J + JB - 1 A( JJ, JJ ) = REAL( A( JJ, JJ ) ) CALL CGEMV( 'No transpose', J+JB-JJ, K-1, -CONE, $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE, $ A( JJ, JJ ), 1 ) A( JJ, JJ ) = REAL( A( JJ, JJ ) ) 100 CONTINUE * * Update the rectangular subdiagonal block * IF( J+JB.LE.N ) $ CALL CGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB, $ K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ), $ LDW, CONE, A( J+JB, J ), LDA ) 110 CONTINUE * * Put L21 in standard form by partially undoing the interchanges * of rows in columns 1:k-1 looping backwards from k-1 to 1 * J = K - 1 120 CONTINUE * * Undo the interchanges (if any) of rows J and JP2 * (or J and JP2, and J-1 and JP1) at each step J * KSTEP = 1 JP1 = 1 * (Here, J is a diagonal index) JJ = J JP2 = IPIV( J ) IF( JP2.LT.0 ) THEN JP2 = -JP2 * (Here, J is a diagonal index) J = J - 1 JP1 = -IPIV( J ) KSTEP = 2 END IF * (NOTE: Here, J is used to determine row length. Length J * of the rows to swap back doesn't include diagonal element) J = J - 1 IF( JP2.NE.JJ .AND. J.GE.1 ) $ CALL CSWAP( J, A( JP2, 1 ), LDA, A( JJ, 1 ), LDA ) JJ = JJ -1 IF( KSTEP.EQ.2 .AND. JP1.NE.JJ .AND. J.GE.1 ) $ CALL CSWAP( J, A( JP1, 1 ), LDA, A( JJ, 1 ), LDA ) IF( J.GT.1 ) $ GO TO 120 * * Set KB to the number of columns factorized * KB = K - 1 * END IF RETURN * * End of CLAHEF_ROOK * END
bsd-3-clause