Eötvös Quantum Utilities  v4.9.146
Providing the Horsepowers in the Quantum Realm
zggev.F
Go to the documentation of this file.
1 #include "fintrf.h"
2 C======================================================================
3 C Gateway routine to call the zggev.f function from LAPACK package.
4 C (See: http://www.netlib.org/lapack/explore-html/d3/d47/zggev_8f.html for details)
5 C Copyright (C) 2009-2015 Peter Rakyta, Ph.D.
6 C
7 C This program is free software: you can redistribute it and/or modify
8 C it under the terms of the GNU General Public License as published by
9 C the Free Software Foundation, either version 3 of the License, or
10 C (at your option) any later version.
11 C
12 C This program is distributed in the hope that it will be useful,
13 C but WITHOUT ANY WARRANTY; without even the implied warranty of
14 C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 C GNU General Public License for more details.
16 C
17 C You should have received a copy of the GNU General Public License
18 C along with this program. If not, see http://www.gnu.org/licenses/.
19 C
20 C======================================================================
21 C Gateway routine
22  subroutine mexfunction(nlhs, plhs, nrhs, prhs)
23 
24 C Declarations
25  implicit none
26 
27 C mexFunction arguments:
28  mwpointer plhs(*), prhs(*)
29  integer nlhs, nrhs
30 
31 
32 C Function declarations:
33  mwpointer mxgetpr
34  mwpointer mxgetpi
35  mwpointer mxcreatedoublematrix
36  mwpointer mxgetm, mxgetn
37  integer*4 mxIsNumeric
38  integer*4 mxIsComplex
39 
40 
41 
42 C Pointers to input/output mxArrays:
43  mwpointer alpha_ptr_real, alpha_ptr_imag
44  mwpointer beta_ptr_real, beta_ptr_imag
45  mwpointer lvecs_ptr_real, lvecs_ptr_imag
46  mwpointer rvecs_ptr_real, rvecs_ptr_imag
47 
48 C Array information:
49  mwsize hrows, hcols, brows, bcols, cols
50  mwsize sizeh, sizeb
51 
52 C Arguments for computational routine:
53  complex*16, allocatable :: H_eff(:,:), B_eff(:,:)
54  complex*16, allocatable :: ALPHA(:), BETA(:)
55  complex*16, allocatable :: l_eigvec(:,:)
56  complex*16, allocatable :: r_eigvec(:,:)
57 
58  complex*16 Work1(1)
59  complex*16, allocatable :: Work(:)
60  DOUBLE PRECISION, allocatable :: RWork(:)
61 
62  mwsignedindex lwork, info
63 
64 
65 C-----------------------------------------------------------------------
66 C Check for proper number of arguments.
67  if(nrhs .ne. 2) then
68  call mexerrmsgidandtxt ('MATLAB:timestwo:nInput',
69  + 'Two inputs required.')
70  elseif(nlhs .gt. 4) then
71  call mexerrmsgidandtxt ('MATLAB:timestwo:nOutput',
72  + 'Too many output arguments.')
73  endif
74 
75 C Validate inputs
76 
77 C Check that the input is a number.
78  if ((mxisnumeric(prhs(1)) .eq. 0) .or.
79  + (mxisnumeric(prhs(2)) .ne. 1)) then
80  call mexerrmsgidandtxt ('MATLAB:timestwo:NonNumeric',
81  + 'Input must be a number.')
82  endif
83 
84 C Check if inputs are complex.
85  if ((mxiscomplex(prhs(1)) .ne. 1) .or.
86  + (mxiscomplex(prhs(2)) .ne. 1)) then
87  call mexerrmsgidandtxt ('MATLAB:convec:NonComplex',
88  + 'Inputs must be complex.')
89  endif
90 
91 C Get the size of the input array. (MATLAB)
92  hrows = mxgetm(prhs(1))
93  hcols = mxgetn(prhs(1))
94  brows = mxgetm(prhs(2))
95  bcols = mxgetn(prhs(2))
96  sizeh = hrows*hcols
97  sizeb = brows*bcols
98 
99 
100  if ((hrows .ne. brows) .or.
101  + (hcols .ne. bcols)) then
102  call mexerrmsgidandtxt ('MATLAB:zggev:WrongSize',
103  + 'The dimensions of the matrices must equal.')
104  endif
105 
106 
107 C Allocating memory for the matrices
108  allocate(h_eff(hrows,hcols))
109  allocate(b_eff(brows,bcols))
110  allocate(alpha(brows))
111  allocate(beta(brows))
112  allocate(l_eigvec(brows,bcols))
113  allocate(r_eigvec(brows,bcols))
114  allocate(rwork(8*hrows))
115 C
116 C Check the allocated arrays
117  if (.not. ( allocated(h_eff) .and.
118  + allocated(h_eff) .and.
119  + allocated(b_eff) .and.
120  + allocated(alpha) .and.
121  + allocated(beta) .and.
122  + allocated(l_eigvec) .and.
123  + allocated(r_eigvec) .and.
124  + allocated(rwork) )) then
125  call mexerrmsgidandtxt ('MATLAB:zggev:BadAllocation',
126  + 'The allocation of variables was unsuccesfull.')
127  endif
128 C
129 C Copy input data to the Fortran arrays
130  call mxcopyptrtocomplex16(mxgetpr(prhs(1)),
131  + mxgetpi(prhs(1)),h_eff,sizeh)
132 
133  call mxcopyptrtocomplex16(mxgetpr(prhs(2)),
134  + mxgetpi(prhs(2)),b_eff,sizeb)
135 
136  lwork = -1
137 C Query for the workspace
138  call zggev( 'V', 'V', hcols, h_eff, hrows,
139  + b_eff, brows,
140  + alpha, beta, l_eigvec, hrows, r_eigvec, hrows,
141  + work1, lwork, rwork, info )
142 C
143 C Test the resulted INFO flag
144  call checkinfo( info )
145 C
146  lwork = work1(1)
147  allocate( work(lwork))
148  if (.not. ( allocated(work) )) then
149  call mexerrmsgidandtxt ('MATLAB:zggev:BadAllocation',
150  + 'The allocation of variable Work was unsuccesfull.')
151  endif
152 C
153 C Call the computational subroutine.
154  call zggev( 'V', 'V', hcols, h_eff, hrows,
155  + b_eff, hrows,
156  + alpha, beta, l_eigvec, hrows, r_eigvec, hrows,
157  + work, lwork, rwork, info )
158 C
159 C Test the resulted INFO flag
160  call checkinfo( info )
161 
162 C Create matrices for the return arguments.
163  cols = 1
164  plhs(1) = mxcreatedoublematrix(hrows,cols,1) ! ALPHA
165  plhs(2) = mxcreatedoublematrix(hrows,cols,1) ! BETA
166  plhs(3) = mxcreatedoublematrix(hrows,hcols,1) ! l_eigvec
167  plhs(4) = mxcreatedoublematrix(hrows,hcols,1) ! r_eigvec
168 
169 C Load the data into to MATLAB outputs.
170  alpha_ptr_real = mxgetpr(plhs(1))
171  alpha_ptr_imag = mxgetpi(plhs(1))
172  call mxcopycomplex16toptr(alpha,alpha_ptr_real,alpha_ptr_imag,
173  + hrows)
174 C
175  beta_ptr_real = mxgetpr(plhs(2))
176  beta_ptr_imag = mxgetpi(plhs(2))
177  call mxcopycomplex16toptr(beta,beta_ptr_real,beta_ptr_imag,
178  + hrows)
179 C
180  lvecs_ptr_real = mxgetpr(plhs(3))
181  lvecs_ptr_imag = mxgetpi(plhs(3))
182  call mxcopycomplex16toptr(l_eigvec,lvecs_ptr_real,
183  + lvecs_ptr_imag,sizeb)
184 C
185  rvecs_ptr_real = mxgetpr(plhs(4))
186  rvecs_ptr_imag = mxgetpi(plhs(4))
187  call mxcopycomplex16toptr(r_eigvec,rvecs_ptr_real,
188  + rvecs_ptr_imag,sizeb)
189 
190 
191 
192 C Free the allocated matrices
193  deallocate(h_eff)
194  deallocate(b_eff)
195  deallocate(alpha)
196  deallocate(beta)
197  deallocate(l_eigvec)
198  deallocate(r_eigvec)
199  deallocate(work)
200  deallocate(rwork)
201 
202 
203  return
204  end
205 
206 
207 
208 C=========================================================
209 C Test the output INFO flag of the LAPACK function
210  subroutine checkinfo( INFO )
212  mwsignedindex info
213  character(len=100) :: msg
214 
215  if (info<0) then
216  msg = 'Illegal argumemnt in the LAPACK function'
217  call mexerrmsgidandtxt ('MATLAB:zggev:IllegalLAPACKArgument',
218  + msg)
219  elseif (info>0) then
220  msg = 'Calculations failed in the LAPACK function'
221  call mexerrmsgidandtxt ('MATLAB:zggev:FailedLAPACK',
222  + msg)
223  endif
224 
225  return
226  end subroutine
227 
228 
subroutine checkinfo(INFO)
Definition: dggev.F:208
subroutine mexfunction(nlhs, plhs, nrhs, prhs)