I am trying to initialize a local logical array in a Fortran subroutine to false, but I get the error:
error #6562: A data initialization-expr is not valid for this object.
Here is my declaration:
integer , intent(in) :: nLOW
integer , intent(in) :: nUP
logical , dimension(nLOW:nUP) :: leastSQUARE = .false.
I get the same error if I use:
integer :: I
integer , intent(in) :: nLOW
integer , intent(in) :: nUP
logical , dimension(nLOW:nUP) :: leastSQUARE = (/ (.false., I = nLOW:nUP) /)
If I write:
integer , intent(in) :: nLOW
integer , intent(in) :: nUP
logical , dimension(1:100) :: leastSQUARE = .false.
the subroutine compiles with zero errors. Any idea why this happens? I clearly need leastSQUARE
with dimensions nLOW:nUP
, so the latter is not a workaround.
The likely cause of this error is that the processor attempted to parse the contents of the external input file that you provided to the ParaMonte routines. However, while doing do, it reached the end of file before completing the input file reading.
Most errors in Fortran routines can be identified by the information provided in Fortran runtime messages, which begin with the prefix "FOR". The Fortran compiler cannot identify all possible errors.
Floating-Point Exceptions and Fortran In general, a message results if any one of the invalid, division-by-zero, or overflow exceptions have occurred. Inexact exceptions do not generate messages because they occur so frequently in real programs.
If you wish execution of your program to cease, you can insert a stop statement.
I believe that the error-generating construction is forbidden by the language standard, specifically (in the Fortran 2008 version) by C506 on R503. That constraint states
An initialization shall not appear if object-name is a dummy argument, a function result, an object in a named common block unless the type declaration is in a block data program unit, an object in blank common, an allocatable variable, or an automatic object.
leastSQUARE
is just such an automatic object, one whose bounds are only known at run-time. You'll have to initialise it separately from its declaration.
To be clear (thanks to @IanH), you will have to execute an assignment statement to give your automatic object an initial value. My use of the verb initialise in the previous paragraph was not Fortran standard standard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With