1

Is there a way in Fortran to store a static array like this or something similar

Real*8,Save,Dimension( 1 : 3 ) :: z = ( / 1 , 0 , 0 /)
                                       1
Error: Syntax error in expression at (1)

The problem is if I define the array like that, I get

Real*8,Save,Dimension( 1 : 3 ) :: z = ( / 1 , 0 , 0 /)
                                       1
Error: Syntax error in expression at (1)

I would like to store this array in a subroutine which is called several times during the program execution, but I do not want to initialise this array over and over again for every subroutine call. How can I declare this array?

3
  • 1
    Does the value of the array ever change? Can you just use a named constant? Commented Nov 23, 2017 at 8:32
  • Yes you are right it is working indeed. The error which I had is quite surprising to me. I am not allowed to have a space between the "/" and ")" or "(" and "/". If I remove this everything is working fine. And for sure also by defining a constant this would work in my case. Thank You Commented Nov 23, 2017 at 8:55
  • I am not sure what is the question. What is "not working"? Do you have any error messages or wrong results which you can show? More code will be necessary if yes. Commented Nov 23, 2017 at 8:58

1 Answer 1

1

The problem is solved already. The problem is if I define the array like, I get

Real*8,Save,dimension( 1 : 3 ) :: z = ( / 0d0 , 0d0 , 1d0 / )
                                       1
 Error: Syntax error in expression at (1)

So with spaces between the brackets and the slash. But if I do ( so I just remove the spaces ( at "( /" and "/ )" ) like this

Real*8,Save,dimension( 1 : 3 ) :: z = (/ 0d0 , 0d0 , 1d0 /)

it works fine.

Sign up to request clarification or add additional context in comments.

3 Comments

you can also use [ ] instead of (/ /).
Interesting! This seems to be easier. Thank you!
Yes, it is a handy feature from Fortran 2003.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.