Fortran 90, how to use array defined in derived type in a subroutine

user3023645

I defined a derived type as follows:

  TYPE CLST_MEAN
     REAL(8), ALLOCATABLE :: OMX(:,:), OMZ(:,:)
     REAL(8), ALLOCATABLE :: U(:,:), W(:,:)
     REAL(8), ALLOCATABLE :: YO(:,:), ZO(:,:)
     REAL(8), ALLOCATABLE :: XU(:,:), ZU(:,:)
     INTEGER :: NUM
  END TYPE Clst_Mean

In the main code, I defined an array and input it in a subroutine as

   TYPE(CLST_MEAN), ALLOCATABLE :: MEAN(:)
   ALLOCATE(MEAN(NCL))
   DO I = 1, NCL
      ALLOCATE(MEAN(I)%OMX(NY,NZ))
      ALLOCATE(MEAN(I)%OMZ(NY,NZ))
      ALLOCATE(MEAN(I)%YO(NY,NZ))
      ALLOCATE(MEAN(I)%ZO(NY,NZ))
      ALLOCATE(MEAN(I)%U(NX,NZ))
      ALLOCATE(MEAN(I)%W(NX,NZ))
      ALLOCATE(MEAN(I)%XU(NX,NZ))
      ALLOCATE(MEAN(I)%ZU(NX,NZ))
   END DO
   CALL K_MEAN(MEAN,SMP)

In the subroutine,

SUBROUTINE K_MEAN(CL_MEAN,SMP)
  USE DATATYPE, ONLY : CLST_MEAN, SAMPLE
  IMPLICIT NONE
  TYPE(CLST_MEAN), DIMENSION(:), INTENT(OUT) :: CL_MEAN
  ....
  write(*,*) size(cl_mean), SIZE(CL_MEAN(1)%OMX)

The output for size(cl_mean) is correct. But the output of size(cl_mean(1)%omx) is 1. That means that the compiler considers cl_mean(1)%omx is a variable not an array.

How can I access the array? Thank you.

dwwork

I think using intent(out) causes the allocatable array in the derived datatype to be deallocated. Using intent(inout) fixed the problem for me using gfortran 4.7.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to declare a complex type array in fortran 90

From Dev

fortran subroutine: array of arbitrary type

From Dev

How to use fortran module subroutine in c

From Dev

How to use fortran module subroutine in c

From Dev

MPI send derived data type with pointer in Fortran 90

From Dev

MPI send derived data type with pointer in Fortran 90

From Dev

Fortran: Allocatable array of derived type containing an array of derived type

From Dev

FORTRAN - allocatable array in subroutine

From Dev

fortran: how to pass a null pointer to a subroutine, in which it will be defined and returned

From Dev

using real(A[,kind=]) in passing a single precision array as a double precision to a subroutine in Fortran 90/2003

From Dev

How to have generic subroutine to work in fortran with assumed size array

From Dev

updating values of an array in a subroutine in fortran

From Dev

Fortran derived type assignment

From Dev

Fortran derived type assignment

From Dev

Fortran derived data type two dimensional array storage

From Dev

Clean way to separate functions/subroutine declaration from definition in Fortran 90

From Dev

Clean way to separate functions/subroutine declaration from definition in Fortran 90

From Dev

Real data type fortran 90

From Dev

Loading derived types with a subroutine within a module in modern Fortran

From Dev

How to add new element to dynamical array in Fortran 90

From Dev

How to add new element to dynamical array in Fortran 90

From Dev

Decrease size of array in Fortran 90

From Dev

Using a giant workspace array for a Fortran subroutine

From Dev

Use Fortran subroutine in R? Undefined symbol

From Dev

Use a subroutine to exit a `do while` loop in Fortran

From Dev

Fortran Allocatable Array Member of a User-Defined Type

From Dev

How to flush stdout in Fortran 90?

From Dev

How to flush stdout in Fortran 90?

From Dev

How to get Fortran to warn me if I pass an allocated array to a subroutine with mismatching dimensions?

Related Related

  1. 1

    How to declare a complex type array in fortran 90

  2. 2

    fortran subroutine: array of arbitrary type

  3. 3

    How to use fortran module subroutine in c

  4. 4

    How to use fortran module subroutine in c

  5. 5

    MPI send derived data type with pointer in Fortran 90

  6. 6

    MPI send derived data type with pointer in Fortran 90

  7. 7

    Fortran: Allocatable array of derived type containing an array of derived type

  8. 8

    FORTRAN - allocatable array in subroutine

  9. 9

    fortran: how to pass a null pointer to a subroutine, in which it will be defined and returned

  10. 10

    using real(A[,kind=]) in passing a single precision array as a double precision to a subroutine in Fortran 90/2003

  11. 11

    How to have generic subroutine to work in fortran with assumed size array

  12. 12

    updating values of an array in a subroutine in fortran

  13. 13

    Fortran derived type assignment

  14. 14

    Fortran derived type assignment

  15. 15

    Fortran derived data type two dimensional array storage

  16. 16

    Clean way to separate functions/subroutine declaration from definition in Fortran 90

  17. 17

    Clean way to separate functions/subroutine declaration from definition in Fortran 90

  18. 18

    Real data type fortran 90

  19. 19

    Loading derived types with a subroutine within a module in modern Fortran

  20. 20

    How to add new element to dynamical array in Fortran 90

  21. 21

    How to add new element to dynamical array in Fortran 90

  22. 22

    Decrease size of array in Fortran 90

  23. 23

    Using a giant workspace array for a Fortran subroutine

  24. 24

    Use Fortran subroutine in R? Undefined symbol

  25. 25

    Use a subroutine to exit a `do while` loop in Fortran

  26. 26

    Fortran Allocatable Array Member of a User-Defined Type

  27. 27

    How to flush stdout in Fortran 90?

  28. 28

    How to flush stdout in Fortran 90?

  29. 29

    How to get Fortran to warn me if I pass an allocated array to a subroutine with mismatching dimensions?

HotTag

Archive