ASSIGN VECTOR INSIDE MODULE

Hello eveybody,

I would like to know how can i assign vector values inside a module.

For Example:

MODULE IBANDS
!
INTEGER, PUBLIC, DIMENSION (40) :: IBAND
!
DATA IBAND / &
& 2, 1, 2, 2, 1, 2, 1, 3, 2, 2, 3, 2, 2, 4, 2, 4, 2, 3, 3, 2, &
& 4, 3, 4, 3, 7, 5, 6, 7, 6, 5, 7, 6, 7, 8, 6, 6, 8, 8, 8, 8 /
!
END MODULE IBANDS

Thank you very much for your attention.



All the best

The short answer is that with data blocks initializing arrays in a module,
you need to link in the module object with the program.


pgfortran -c ibands_mod.f90 !to create ibands.mod
pgfortran -o test test.f90 ! will look for ibands.mod ‘use ibands’
! but will fail to link completely.

pgfortran -o test test.f90 ibands_mod.o
or
pgfortran -o test ibands_mod.f90 test.f90

should work.
% more test.f90
program use_ibands
use ibands
print *,“The array assignment should be”
print *,“INTEGER, PUBLIC, DIMENSION (40) :: IBAND "
print *,“DATA IBAND "
print *,” 2,1,2,2,1,2,1,3,2,2,3,2,2,4,2,4,2,3,3,2,”
print *," 4,3,4,3,7,5,6,7,6,5,7,6,7,8,6,6,8,8,8,8"
print *," "
print *," "
print *," "
print *," "
print *,“IBAND[40]=”,iband
end program use_ibands

% more ibands_mod.f90
MODULE IBANDS
!
INTEGER, PUBLIC, DIMENSION (40) :: IBAND
!
DATA IBAND / &
& 2, 1, 2, 2, 1, 2, 1, 3, 2, 2, 3, 2, 2, 4, 2, 4, 2, 3, 3, 2, &
& 4, 3, 4, 3, 7, 5, 6, 7, 6, 5, 7, 6, 7, 8, 6, 6, 8, 8, 8, 8 /
!
END MODULE IBANDS