Guest User

Fortran routine only works for statically allocated matrix

a guest
Jul 16th, 2014
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. program propagate
  3.    
  4.     integer, parameter :: dp=kind(0.d0)
  5.    
  6.     ! general
  7.     real(dp), parameter :: dt = 1
  8.     integer, parameter :: pade_deg = 6
  9.     integer :: iexph, ns, f = 0
  10.     character(len=12) :: Narg
  11.    
  12.     ! fixed size
  13.     integer, parameter :: fN = 100
  14.     integer, parameter :: flwsp = 4*fN**2+pade_deg+1
  15.     real(dp), dimension(fN, fN) :: fH
  16.     complex(dp), dimension(fN, fN) :: fP
  17.     complex(dp), dimension(flwsp) :: fwsp
  18.     integer, dimension(fN) :: fipiv
  19.    
  20.     ! dynamic size
  21.     integer :: dN
  22.     integer :: dlwsp
  23.     real(dp), allocatable, dimension(:, :) :: dH
  24.     complex(dp), allocatable, dimension(:, :) :: dPP
  25.     complex(dp), allocatable, dimension(:) :: dwsp
  26.     integer, allocatable, dimension(:) :: dipiv
  27.    
  28.     ! command args
  29.     if (command_argument_count() < 1) then
  30.         stop 'provide integer command arg for grid size N'
  31.     else
  32.         call get_command_argument(1, Narg)
  33.         read (Narg, '(i12)') dN
  34.     end if
  35.     dlwsp = 4*dN**2+pade_deg+1
  36.    
  37.     ! allocation
  38.     allocate(dH(dN, dN))
  39.     allocate(dPP(dN, dN))
  40.     allocate(dwsp(dlwsp))
  41.     allocate(dipiv(dN))
  42.    
  43.     write (*, *) sizeof(fN), sizeof(dN)
  44.     write (*, *) sizeof(fH), sizeof(dH)
  45.     write (*, *) sizeof(fwsp), sizeof(dwsp)
  46.     write (*, *) sizeof(flwsp), sizeof(dlwsp)
  47.     write (*, *) sizeof(fipiv), sizeof(dipiv)
  48.     write (*, *) '+++'
  49.     write (*, *) size(fH), size(dH)
  50.     write (*, *) 'dH allocated:', allocated(dH)
  51.    
  52.     ! fixed: Hermitian matrix H & 'unitary' propagator P
  53.     fH = 0
  54.     do i = 1, fN
  55.         fH(i, i) = 1
  56.     end do
  57.     call ZHPADM(pade_deg, fN, dt, fH, fN, fwsp, flwsp, fipiv, iexph, ns, f)
  58.     fP = reshape(fwsp(iexph:iexph+fN**2-1), [fN, fN])
  59.    
  60.     ! dynamic: Hermitian matrix H & 'unitary' propagator P
  61.     dH = 0
  62.     do i = 1, dN
  63.         dH(i, i) = 1
  64.     end do
  65.     !call ZHPADM(pade_deg, dN, dt, fH, dN, dwsp, dlwsp, dipiv, iexph, ns, f)
  66.     call ZHPADM(pade_deg, fN, dt, dH, fN, fwsp, flwsp, fipiv, iexph, ns, f)
  67.     dPP = reshape(dwsp(iexph:iexph+dN**2-1), [dN, dN])
  68.    
  69.     write (*, *) 'end of program'
  70.    
  71. end program propagate
Advertisement
Add Comment
Please, Sign In to add comment