Eötvös Quantum Utilities  v4.9.146
Providing the Horsepowers in the Quantum Realm
import_real_full.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 mxgetjc
34  mwpointer mxgetir
35  mwpointer mxcreatestring
36  mwpointer mxgetstring, getstring_stat
37  integer mxIsChar
38 
39 C Arguments for copying data between fortran and MATLAB
40  integer*4 complexflag
41 
42  mwpointer mxgetpr
43  mwpointer mxcreatedoublematrix
44  mwpointer mxgetm, mxgetn
45 
46  logical fileExist
47  character(len=100) :: filename
48  character(len=7) :: file_status
49 
50 C Array information:
51  mwpointer mxrows, mxcols !size of the input string containing the filename
52  integer*4 strlen ! the length of the input string
53 
54 C Arguments for computational routine:
55 C fortran representation of the input matrix (CSR format)
56  integer*4 rows, cols
57  real*8, allocatable :: mtx(:,:)
58  mwpointer mxmtx
59 
60 C Parameters for pardiso
61  integer i,j
62 
63 #ifdef DEBUG
64 C Debug parameters
65  integer*4 mexPrintf
66  integer*4 tmp
67  character*800 line
68 #endif
69 
70 
71 C-----------------------------------------------------------------------
72 C Check for proper number of arguments.
73  if(nrhs .ne. 1) then
74  call mexerrmsgidandtxt ('MATLAB:import_real_full:nInput',
75  + 'One input required.')
76  elseif(nlhs .gt. 1) then
77  call mexerrmsgidandtxt ('MATLAB:import_real_full:nOutput',
78  + 'Too many output arguments.')
79  endif
80 
81 C Validate inputs
82 
83 C The input filename must be a string.
84  if(mxischar(prhs(1)) .ne. 1) then
85  call mexerrmsgidandtxt ('MATLAB:import_real_full:NonString',
86  + 'Input filename must be a string.')
87  endif
88 
89 C Get the size of the input string.
90  mxrows = mxgetm(prhs(1))
91  mxcols = mxgetn(prhs(1))
92 
93 C Get the length of the input string and validate.
94  strlen = int(mxrows*mxcols, 4)
95  if (strlen .gt. len(filename)) then
96  call mexerrmsgidandtxt ('MATLAB:import_real_full:NonDouble',
97  + 'input filename is greater than max str size.')
98  endif
99 
100 C Get the input filename.
101  getstring_stat =
102  + mxgetstring(prhs(1), filename, int(len(filename), 8))
103 
104 #ifdef DEBUG
105  write(line,*) 'Input file name: ',filename, new_line('A')
106  tmp = mexprintf(line)
107 #endif
108 
109 
110 
111 C Read in the matrix from the binary
112 C Testing the existance of the input file containing the sparse matrix A
113  inquire(file=trim(filename),exist=fileexist)!check if it exist
114  if(.not.fileexist)then
115  call mexerrmsgidandtxt ('MATLAB:import_real_full:FileNotFound',
116  + 'input file ', trim(filename), 'not found.')
117  endif
118 
119 C Opening the file to read in data
120  OPEN(unit=6, file=trim(filename),status='OLD'
121  + ,form='UNFORMATTED')
122 
123  READ(6,end=999,err=1000) rows
124  READ(6,end=999,err=1000) cols
125 
126 #ifdef DEBUG
127  write(line,*) 'rows: ',rows, ' cols: ', cols, new_line('A')
128  tmp = mexprintf(line)
129 #endif
130 
131  allocate(mtx(rows,cols))
132  if ( .not.(allocated(mtx) )) then
133  call mexerrmsgidandtxt (
134  + 'MATLAB:import_real_full:BadAllocation',
135  + 'Memory space failed to allocate for the matrix.')
136  end if
137 
138  do j = 1, cols
139  READ(6,end=999,err=1000) mtx(:,j)
140  end do
141 
142 
143 C Closing the input file
144  CLOSE(unit=6)
145 
146 
147  complexflag = 0;
148  mxrows = int( rows, 8)
149  mxcols = int( cols, 8)
150  plhs(1) = mxcreatedoublematrix(mxrows, mxcols,
151  + complexflag)
152  mxmtx = mxgetpr(plhs(1))
153  call mxcopyreal8toptr(mtx, mxmtx,mxrows*mxcols)
154 
155  deallocate(mtx)
156  return
157 
158  999 call mexerrmsgidandtxt ('MATLAB:import_real_full:FileEnd',
159  + 'File end reached while reading the file')
160 
161  1000 call mexerrmsgidandtxt ('MATLAB:import_real_full:FileError',
162  + 'Error occured while reading the file')
163 
164 
165 
166  return
167 
168 
169  end
170 
171 
subroutine mexfunction(nlhs, plhs, nrhs, prhs)