Eötvös Quantum Utilities  v4.9.146
Providing the Horsepowers in the Quantum Realm
dggev.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/d9/d52/dggev_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 alphar_ptr
44  mwpointer alphai_ptr
45  mwpointer beta_ptr
46  mwpointer lvecs_ptr
47  mwpointer rvecs_ptr
48 
49 C Array information:
50  mwsize hrows, hcols, brows, bcols, cols
51  mwsize sizeh, sizeb
52 
53 C Arguments for computational routine:
54  real*8, allocatable :: h_eff(:,:), b_eff(:,:)
55  real*8, allocatable :: alphar(:), alphai(:)
56  real*8, allocatable :: beta(:)
57  real*8, allocatable :: l_eigvec(:,:)
58  real*8, allocatable :: r_eigvec(:,:)
59 
60  real*8 work1(1)
61  real*8, allocatable :: work(:)
62 
63  mwsignedindex lwork, info
64 
65 
66 C-----------------------------------------------------------------------
67 C Check for proper number of arguments.
68  if(nrhs .ne. 2) then
69  call mexerrmsgidandtxt ('MATLAB:timestwo:nInput',
70  + 'Two inputs required.')
71  elseif(nlhs .gt. 5) then
72  call mexerrmsgidandtxt ('MATLAB:timestwo:nOutput',
73  + 'Too many output arguments.')
74  endif
75 
76 C Validate inputs
77 
78 C Check that the input is a number.
79  if ((mxisnumeric(prhs(1)) .eq. 0) .or.
80  + (mxisnumeric(prhs(2)) .ne. 1)) then
81  call mexerrmsgidandtxt ('MATLAB:timestwo:NonNumeric',
82  + 'Input must be a number.')
83  endif
84 
85 C Check if inputs are complex.
86  if ((mxiscomplex(prhs(1)) .ne. 0) .or.
87  + (mxiscomplex(prhs(2)) .ne. 0)) then
88  call mexerrmsgidandtxt ('MATLAB:convec:NonComplex',
89  + 'Inputs must be real.')
90  endif
91 
92 C Get the size of the input array. (MATLAB)
93  hrows = mxgetm(prhs(1))
94  hcols = mxgetn(prhs(1))
95  brows = mxgetm(prhs(2))
96  bcols = mxgetn(prhs(2))
97  sizeh = hrows*hcols
98  sizeb = brows*bcols
99 
100 
101  if ((hrows .ne. brows) .or.
102  + (hcols .ne. bcols)) then
103  call mexerrmsgidandtxt ('MATLAB:zggev:WrongSize',
104  + 'The dimensions of the matrices must equal.')
105  endif
106 
107 
108 C Allocating memory for the matrices
109  allocate(h_eff(hrows,hcols))
110  allocate(b_eff(brows,bcols))
111  allocate(alphar(brows))
112  allocate(alphai(brows))
113  allocate(beta(brows))
114  allocate(l_eigvec(brows,bcols))
115  allocate(r_eigvec(brows,bcols))
116 C
117 C Check the allocated arrays
118  if (.not. ( allocated(h_eff) .and.
119  + allocated(h_eff) .and.
120  + allocated(b_eff) .and.
121  + allocated(alphar) .and.
122  + allocated(alphai) .and.
123  + allocated(beta) .and.
124  + allocated(l_eigvec) .and.
125  + allocated(r_eigvec) )) then
126  call mexerrmsgidandtxt ('MATLAB:zggev:BadAllocation',
127  + 'The allocation of variables was unsuccesfull.')
128  endif
129 C
130 C Copy input data to the Fortran arrays
131  call mxcopyptrtoreal8(mxgetpr(prhs(1)),
132  + h_eff,sizeh)
133 
134  call mxcopyptrtoreal8(mxgetpr(prhs(2)),
135  + b_eff,sizeb)
136 
137  lwork = -1
138 C Query for the workspace
139  call dggev( 'V', 'V', hcols, h_eff, hrows,
140  + b_eff, brows,
141  + alphar, alphai, beta, l_eigvec, hrows, r_eigvec, hrows,
142  + work1, lwork, info )
143 C
144 C Test the resulted INFO flag
145  call checkinfo( info )
146 C
147  lwork = work1(1)
148  allocate( work(lwork))
149  if (.not. ( allocated(work) )) then
150  call mexerrmsgidandtxt ('MATLAB:zggev:BadAllocation',
151  + 'The allocation of variable Work was unsuccesfull.')
152  endif
153 C
154 C Call the computational subroutine.
155  call dggev( 'V', 'V', hcols, h_eff, hrows,
156  + b_eff, hrows,
157  + alphar, alphai, beta, l_eigvec, hrows, r_eigvec, hrows,
158  + work, lwork, info )
159 C
160 C Test the resulted INFO flag
161  call checkinfo( info )
162 
163 C Create matrices for the return arguments.
164  cols = 1
165  plhs(1) = mxcreatedoublematrix(hrows,cols,0) ! ALPHAR
166  plhs(2) = mxcreatedoublematrix(hrows,cols,0) ! ALPHAI
167  plhs(3) = mxcreatedoublematrix(hrows,cols,0) ! BETA
168  plhs(4) = mxcreatedoublematrix(hrows,hcols,1) ! l_eigvec
169  plhs(5) = mxcreatedoublematrix(hrows,hcols,1) ! r_eigvec
170 
171 C Load the data into to MATLAB outputs.
172  alphar_ptr = mxgetpr(plhs(1))
173  call mxcopyreal8toptr(alphar,alphar_ptr, hrows)
174 C
175  alphai_ptr = mxgetpr(plhs(2))
176  call mxcopyreal8toptr(alphai,alphai_ptr, hrows)
177 C
178  beta_ptr = mxgetpr(plhs(3))
179  call mxcopyreal8toptr(beta,beta_ptr, hrows)
180 C
181  lvecs_ptr = mxgetpr(plhs(4))
182  call mxcopyreal8toptr(l_eigvec, lvecs_ptr,sizeb)
183 C
184  rvecs_ptr = mxgetpr(plhs(5))
185  call mxcopyreal8toptr(r_eigvec, rvecs_ptr,sizeb)
186 
187 
188 
189 C Free the allocated matrices
190  deallocate(h_eff)
191  deallocate(b_eff)
192  deallocate(alphar)
193  deallocate(alphai)
194  deallocate(beta)
195  deallocate(l_eigvec)
196  deallocate(r_eigvec)
197  deallocate(work)
198 
199 
200  return
201  end
202 
203 
204 
205 C=========================================================
206 C Test the output INFO flag of the LAPACK function
207  subroutine checkinfo( INFO )
209  mwsignedindex info
210  character(len=100) :: msg
211 
212  if (info<0) then
213  msg = 'Illegal argumemnt in the LAPACK function'
214  call mexerrmsgidandtxt ('MATLAB:zggev:IllegalLAPACKArgument',
215  + msg)
216  elseif (info>0) then
217  msg = 'Calculations failed in the LAPACK function'
218  call mexerrmsgidandtxt ('MATLAB:zggev:FailedLAPACK',
219  + msg)
220  endif
221 
222  return
223  end subroutine
224 
225 
subroutine checkinfo(INFO)
Definition: dggev.F:208
subroutine mexfunction(nlhs, plhs, nrhs, prhs)