I need to initialize an static array in a Fortran subroutine
double precision A(56136,8)
like so:
A(1,1)=0.999950528145
A(1,2)=0.99982470274
A(1,3)=0.999987006187
.
.
.
A(56136,7)=0.933468163013
A(56136,8)=0.0668926686049
The latter is generated by another program.
Compilation with ifort 13.0 ifort file.f -O0
takes very long (around 30 minutes).
Q1: What is the reason for this and how can I avoid it?
I have no handle on the main program, the subroutine is linked to third party files. The subroutine is called very often, so file access is not desirable.
Q2: Can I put the initialization outside the subroutine, without having a main program, avoiding the initialization every time the subroutine is called?
Edit
It is constant. Initializing it in the declaration statement would look like this?
double precision A(56136:8)=reshape(/*
& #, #, #, #, #, #, #, #,
& #, #, #, #, #, #, #, #,
:
& */,(56136,8))
This does not work because there are too many newlines.
I did a test with 10000 integers and it compiles in seconds when using a
DATA
statement. My array holds 50000 integers but wanted to see if I can assign them in blocks of 10000.Edit 1
Here is how do use a
DATA
statement with aCOMMON
block to set the values inside a subroutine. Note that use of common blocks is nearly deprecated.Edit 2
Another solution that uses a function to copy the saved array into a secondary working copy.