writing mat file from fortran
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
dpb
le 24 Juil 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.
Réponses (1)
Voir également
Catégories
En savoir plus sur Fortran with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!