Search code examples
fortranmexderived-types

Is there a way to get all components of a derived type?


I'm trying to write a subroutine in a MEX file to convert Fortran derived types to MATLAB structs. I'd like to automate the process because I have a derived type with multiple components that are themselves derived types, so manually converting every component would take a very long time.

I found one other question related to this that suggests it's not possible to access these components as strings: Is there a way to call the field of a derived type using a string?

Barring that, I was thinking there might be a way to get the number of components and access each one by a numeric index, but I haven't found anything indicating that this is possible. None of the derived types I'm dealing with have procedure components, just variables.

Can I access these variables in a generic way, like myObj%(1)?


Solution

  • The answer is the same as in the linked question. No, no such indexing is possible.