Reputation: 35
I have to work with a file that can change number of line due to the previous operation(from python script), and that number of line will used to declare the other variable, like this.
integer NumberOfLine !This is not work,Of course.
real(8) F(FixedDimension,NumberOfLine)
integer, parameter :: NewDimension = ANumber*NumberOfLine
How can I declare the NumberOfLine properly. Thanks. I can pass number of line from python, So basicly I know that number after python operation complete
Upvotes: 0
Views: 89
Reputation: 8140
If you declare a parameter, its value must be fixed at compile time. So your integer, parameter :: newDimension = ANumber * NumberOfLine
cannot work if the compiler doesn't know the value of NumberOfLine
.
What you can do is use allocatable arrays:
program test_alloc
implicit none
integer, parameter :: dp = selected_real_kind(p=15)
real(kind=dp), dimension(:,:), allocatable :: F
integer :: i
integer, parameter :: FixedDimension = 10
print *, "Enter i"
read(*, *) i
allocate (a(FixedDimension, i))
a = i
print *, a
end program test_alloc
Upvotes: 2