0

I wish to define a parameter that will not change in my module from a input variable.

Example

module foo
    contains
    subroutine function1(external_var)
       integer, parameter x = external_var(1)
       write(*,*) x
    end subroutine function1
end module foo

However, this gives an error.

PGF90-S-0087-Non-constant expression where constant expression required
Laurence_jj
  • 646
  • 1
  • 10
  • 23
  • 1
    A "parameter" (named constant) must be known "at compile time". However, from your code fragment there's no obvious reason why you would need `x` to be a named constant. Can you explain more about what you want to do with the set-once-by-input variable? If so, we can give you alternative approaches to consider, – francescalus Sep 24 '19 at 15:59
  • Note also that just because the actual argument associated with `external_var` may be a constant doesn't mean that [`external_var` itself is](https://stackoverflow.com/q/32553490/3157076). – francescalus Sep 24 '19 at 16:01
  • the array external_var is read from a file and fixed, I want to assign it to a parameter that will not change. I was having some trouble in my code, where arrays were being wiped and wanted to prevent them from being altered. – Laurence_jj Sep 24 '19 at 16:02
  • 3
    Protected might go some of the way to what the OP wants - https://stackoverflow.com/questions/15020460/protected-global-variables-in-fortran – Ian Bush Sep 24 '19 at 16:32

0 Answers0