1

My IDE is Code::Blocks 17.12 with MinGW compiler 6.3.0

I am new in coding with Fortran so I need a help about specific things and tricks in proces of learning so, this is my simple program:

PROGRAM DO_LOOP_ALLOCATION

IMPLICIT NONE

INTEGER              :: I, ALLOC_ERR
INTEGER,   PARAMETER :: N_NN_DM = 5
INTEGER,   PARAMETER :: AN_NN_DM( N_NN_DM ) = [ 3, 3, 3, 3, 3 ]
INTEGER, ALLOCATABLE :: ARRAY_DM( :, : )

DO I = 1, N_NN_DM

   IF ( .NOT. ALLOCATED( ARRAY_DM( I, AN_NN_DM( I ) ) ) ) THEN

         ALLOCATE( ARRAY_DM( I,  AN_NN_DM( I ) ), STAT = ALLOC_ERR )


   END IF

   IF ( ALLOC_ERR .NE. 0 ) STOP ( "ERROR - MEMEORY ALLOCATION ISSUE !!!" )

END DO

END PROGRAM DO_LOOP_ALLOCATION

In the compiling process I got this error message:

Error: 'array' argument of 'allocated' intrinsic  must be ALLOCATABLE

What is wrong with this simple code?

  • You should use `allocated(array_dm)` to see whether `array_dm` is allocated. Is that what you wish to do, or are you trying to find something else out about the array with the statement as you have it? That is, are you wanting "allocated and of this shape?" etc? – francescalus Feb 12 '19 at 18:51
  • @francescalus This is what I want to do: `ARRAY_DM(1,3)….ARRAY_DM(5,3)` Second dimension of `ARRAY_DIM` must be corresponding element of `AN_NN_DM` for every single `I`. –  Feb 12 '19 at 19:24
  • Do you want the shape of the array to change through each iteration, or do you want each "row or column" of the array to have different lengths? – francescalus Feb 12 '19 at 19:28
  • 1
    @francescalus First dimension of `ARRAY_DM` must be `N_NN_DM` end second dimension must be correspondin element from `AN_NN_DM`. –  Feb 12 '19 at 19:31
  • @francescalus That is a very good solution! –  Feb 12 '19 at 19:43

0 Answers0