Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fortran: error #6562: A data initialization-expr is not valid for this object

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.

like image 338
Millemila Avatar asked Aug 22 '14 09:08

Millemila


People also ask

What is Fortran runtime error?

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.

How do you find errors in Fortran?

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.

What is floating point error in Fortran?

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.

How do you stop a code in Fortran?

If you wish execution of your program to cease, you can insert a stop statement.


1 Answers

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.

like image 169
High Performance Mark Avatar answered Oct 21 '22 08:10

High Performance Mark