28 mwpointer plhs(*), prhs(*)
35 mwpointer mxcreatestring
36 mwpointer mxgetstring, getstring_stat
43 mwpointer mxcreatedoublematrix
44 mwpointer mxgetm, mxgetn
47 character(len=100) :: filename
48 character(len=7) :: file_status
51 mwpointer mxrows, mxcols
57 real*8,
allocatable :: mtx(:,:)
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.')
84 if(mxischar(prhs(1)) .ne. 1)
then 85 call mexerrmsgidandtxt (
'MATLAB:import_real_full:NonString',
86 +
'Input filename must be a string.')
90 mxrows = mxgetm(prhs(1))
91 mxcols = mxgetn(prhs(1))
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.')
102 + mxgetstring(prhs(1), filename, int(len(filename), 8))
105 write(line,*)
'Input file name: ',filename, new_line(
'A')
106 tmp = mexprintf(line)
113 inquire(file=trim(filename),exist=fileexist)
114 if(.not.fileexist)
then 115 call mexerrmsgidandtxt (
'MATLAB:import_real_full:FileNotFound',
116 +
'input file ', trim(filename),
'not found.')
120 OPEN(unit=6, file=trim(filename),status=
'OLD' 121 + ,form=
'UNFORMATTED')
123 READ(6,end=999,err=1000) rows
124 READ(6,end=999,err=1000) cols
127 write(line,*)
'rows: ',rows,
' cols: ', cols, new_line(
'A')
128 tmp = mexprintf(line)
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.')
139 READ(6,end=999,err=1000) mtx(:,j)
148 mxrows = int( rows, 8)
149 mxcols = int( cols, 8)
150 plhs(1) = mxcreatedoublematrix(mxrows, mxcols,
152 mxmtx = mxgetpr(plhs(1))
153 call mxcopyreal8toptr(mtx, mxmtx,mxrows*mxcols)
158 999
call mexerrmsgidandtxt (
'MATLAB:import_real_full:FileEnd',
159 +
'File end reached while reading the file')
161 1000
call mexerrmsgidandtxt (
'MATLAB:import_real_full:FileError',
162 +
'Error occured while reading the file')
subroutine mexfunction(nlhs, plhs, nrhs, prhs)