Pass derived type as array

后端 未结 2 540
有刺的猬
有刺的猬 2021-01-22 18:03

In Fortran, one can operate on arrays, but how can one treat the indices of a derived type as part of an array too? Code would explain what I want to do best:

ty         


        
2条回答
  •  抹茶落季
    2021-01-22 18:10

    You want the compiler to regard mat(:)%c as a 2 x 4 matrix? It doesn't work that way. mat and c are different objects and their ranks don't merge into a single array. mat is a user-defined type and c is a real matrix. Just because you are only using the c-component of mat doesn't mean the compiler will promote c to a higher dimensional real array, based on the dimension of mat.

    You could create a new array via X = [ mat(1)%c, mat(2)%c ]. You could use reshape to control the shape.

提交回复
热议问题