Guest User

Fortran routine only works for statically allocated matrixII

a guest
Jul 16th, 2014
312
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), stat = f)
  39.     if (f /= 0) then
  40.         stop 'allocation error'
  41.     end if
  42.     allocate(dPP(dN, dN))
  43.     if (f /= 0) then
  44.         stop 'allocation error'
  45.     end if
  46.     allocate(dwsp(dlwsp))
  47.     if (f /= 0) then
  48.         stop 'allocation error'
  49.     end if
  50.     allocate(dipiv(dN))
  51.     if (f /= 0) then
  52.         stop 'allocation error'
  53.     end if
  54.    
  55.     write (*, *) sizeof(fN), sizeof(dN)
  56.     write (*, *) sizeof(fH), sizeof(dH)
  57.     write (*, *) sizeof(fwsp), sizeof(dwsp)
  58.     write (*, *) sizeof(flwsp), sizeof(dlwsp)
  59.     write (*, *) sizeof(fipiv), sizeof(dipiv)
  60.     write (*, *) '+++'
  61.     write (*, *) size(fH), size(dH)
  62.     write (*, *) 'dH allocated:', allocated(dH)
  63.    
  64.     ! fixed: Hermitian matrix H & 'unitary' propagator P
  65.     fH = 0
  66.     do i = 1, fN
  67.         fH(i, i) = 1
  68.     end do
  69.     call ZHPADM(pade_deg, fN, dt, fH, fN, fwsp, flwsp, fipiv, iexph, ns, f)
  70.     fP = reshape(fwsp(iexph:iexph+fN**2-1), [fN, fN])
  71.    
  72.     ! dynamic: Hermitian matrix H & 'unitary' propagator P
  73.     dH = 0
  74.     do i = 1, dN
  75.         dH(i, i) = 1
  76.     end do
  77.     call ZHPADM(pade_deg, dN, dt, dH, dN, dwsp, dlwsp, dipiv, iexph, ns, f)
  78.     !call ZHPADM(pade_deg, dN, dt, fH, dN, fwsp, dlwsp, dipiv, iexph, ns, f)
  79.     dPP = reshape(dwsp(iexph:iexph+dN**2-1), [dN, dN])
  80.    
  81.     write (*, *) 'end of program'
  82.    
  83. end program propagate
Advertisement
Add Comment
Please, Sign In to add comment