writing mat file from fortran
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2014-7-24
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.
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fortran with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!