writing mat file from fortran
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
First of all this is not a mex file. I have complicated type variables in fortran with hundreds of fields that i would like to write to a mat file. The only way i know to do this is to first create a matlab structure using mxCreateStructArray, then individually populate each field of this structure with each field of the fortran type variable. So the way i do it now involves a lot of repetitive coding.
Is there a better more generic way to do this? Ideally it would be nice to write a fortran type variable directly to the mat file using a function that makes the necessary conversions, but i'm guessing this isn't possible.
Or is it possible to loop through a fortran type variable of unknown number and types of fields?
Here is an example of the variable i'd like to write:
TYPE exampletype
CHARACTER*300 c1
REAL*8 r1,r2,r3
INTEGER i1,i2,i3
REAL*8, ALLOCATABLE :: ra1(:)
REAL*8, ALLOCATABLE, DIMENSION(:,:) :: ra2,ra3
REAL*8, DIMENSION(17) :: r4
LOGICAL L1
LOGICAL L2
TYPE(othertype) t1
ENDTYPE exampletype
thanks.
1 Kommentar
dpb
am 24 Jul. 2014
There isn't a general-purpose routine that will scan the content of a UDT automagically, no. It'll require writing the specific members of a UDT as you've outlined.
It might be as straightforward if you're using (and the compiler implements it) a defined output procedure (F2008 Section 9.6.4.8.3) and essentially serialize the output as unformatted stream which could be written/read from Matlab as well rather than working to build the .mat file.
Antworten (1)
Siehe auch
Kategorien
Mehr zu Fortran with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!