source: altifloat/nemed/demo_matlab.txt @ 199

Last change on this file since 199 was 127, checked in by kodalazian, 10 years ago

add nemed buoys

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