writing mat file from fortran

3 visualizaciones (últimos 30 días)
rob
rob el 24 de Jul. de 2014
Editada: James Tursa el 7 de En. de 2017
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 comentario
dpb
dpb el 24 de Jul. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Joshua Hundley
Joshua Hundley el 7 de En. de 2017

Categorías

Más información sobre Fortran with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by