1 | #include "fintrf.h" |
---|
2 | C |
---|
3 | #if 0 |
---|
4 | C |
---|
5 | C matdemo2.F |
---|
6 | C .F file needs to be preprocessed to generate .for equivalent |
---|
7 | C |
---|
8 | #endif |
---|
9 | C |
---|
10 | C matdemo2.f |
---|
11 | C |
---|
12 | C This is a simple program that illustrates how to call the MATLAB |
---|
13 | C MAT-file functions from a FORTRAN program. This demonstration |
---|
14 | C focuses on reading MAT-files. It reads in the MAT-file created |
---|
15 | C by matdemo1.f, and describe its contents. |
---|
16 | C |
---|
17 | C Copyright 1984-2004 The MathWorks, Inc. |
---|
18 | C===================================================================== |
---|
19 | C $Revision: 1.11.4.3 $ |
---|
20 | C |
---|
21 | program matdemo2 |
---|
22 | C----------------------------------------------------------------------- |
---|
23 | C (pointer) Replace integer by integer*8 on 64-bit platforms |
---|
24 | C |
---|
25 | mwpointer matOpen, matGetDir, matGetNextVariable |
---|
26 | mwpointer matGetVariableInfo, matGetNextVariableInfo |
---|
27 | mwpointer mp, dir, adir(100), pa |
---|
28 | C---------------------------------------------------------------------- |
---|
29 | C |
---|
30 | C Other variable declarations here |
---|
31 | C |
---|
32 | integer mxGetM, mxGetN, matClose |
---|
33 | integer ndir, i, stat |
---|
34 | character*32 names(100), name |
---|
35 | |
---|
36 | C |
---|
37 | C------------------------------------------------------------- |
---|
38 | C Open file and read directory |
---|
39 | C------------------------------------------------------------- |
---|
40 | C |
---|
41 | mp = matOpen('matdemo.mat', 'r') |
---|
42 | if (mp .eq. 0) then |
---|
43 | write(6,*) 'Can''t open ''matdemo.mat''.' |
---|
44 | stop |
---|
45 | end if |
---|
46 | C |
---|
47 | C Read directory |
---|
48 | C |
---|
49 | dir = matgetdir(mp, ndir) |
---|
50 | if (dir .eq. 0) then |
---|
51 | write(6,*) 'Can''t read directory.' |
---|
52 | stop |
---|
53 | endif |
---|
54 | C |
---|
55 | C Copy pointer into an array of pointers |
---|
56 | C |
---|
57 | call mxCopyPtrToPtrArray(dir, adir, ndir) |
---|
58 | C |
---|
59 | C Copy pointer to character string |
---|
60 | C |
---|
61 | do 20 i=1,ndir |
---|
62 | call mxCopyPtrToCharacter(adir(i), names(i), 32) |
---|
63 | 20 continue |
---|
64 | C |
---|
65 | write(6,*) 'Directory of Mat-file:' |
---|
66 | do 30 i=1,ndir |
---|
67 | write(6,*) names(i) |
---|
68 | 30 continue |
---|
69 | C |
---|
70 | stat = matClose(mp) |
---|
71 | if (stat .ne. 0) then |
---|
72 | write(6,*) 'Error closing ''matdemo.mat''.' |
---|
73 | stop |
---|
74 | end if |
---|
75 | C |
---|
76 | C------------------------------------------------------------- |
---|
77 | C Reopen file and read full arrays |
---|
78 | C------------------------------------------------------------- |
---|
79 | C |
---|
80 | mp = matOpen('matdemo.mat', 'r') |
---|
81 | if (mp .eq. 0) then |
---|
82 | write(6,*) 'Can''t open ''matdemo.mat''.' |
---|
83 | stop |
---|
84 | end if |
---|
85 | C |
---|
86 | C Get Information on first array in mat file |
---|
87 | C |
---|
88 | write(6,*) 'Getting Header info from first array.' |
---|
89 | pa = matGetVariableInfo(mp, names(1)) |
---|
90 | write(6,*) 'Retrieved ', names(1) |
---|
91 | write(6,*) ' With size ', mxGetM(pa), '-by-', mxGetN(pa) |
---|
92 | call mxDestroyArray(pa) |
---|
93 | |
---|
94 | write(6,*) 'Getting Header info from next array.' |
---|
95 | pa = matGetNextVariableInfo(mp, name) |
---|
96 | write(6,*) 'Retrieved ', name |
---|
97 | write(6,*) ' With size ', mxGetM(pa), '-by-', mxGetN(pa) |
---|
98 | call mxDestroyArray(pa) |
---|
99 | C |
---|
100 | C Read directory |
---|
101 | C |
---|
102 | write(6,*) 'Getting rest of array contents:' |
---|
103 | pa = matGetNextVariable(mp, name) |
---|
104 | do while (pa .ne. 0) |
---|
105 | C |
---|
106 | C Copy name to character string |
---|
107 | C |
---|
108 | i=mxGetM(pa) |
---|
109 | write(*, *) i |
---|
110 | write(6,*) 'Retrieved ', name |
---|
111 | write(6,*) ' With size ', mxGetM(pa), '-by-', mxGetN(pa) |
---|
112 | call mxDestroyArray(pa) |
---|
113 | pa = matGetNextVariable(mp, name) |
---|
114 | end do |
---|
115 | C |
---|
116 | stat = matClose(mp) |
---|
117 | if (stat .ne. 0) then |
---|
118 | write(6,*) 'Error closing ''matdemo.mat''.' |
---|
119 | stop |
---|
120 | end if |
---|
121 | stop |
---|
122 | C |
---|
123 | end |
---|
124 | |
---|
125 | |
---|
126 | |
---|