Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29281 Discussions

Efficient use of NAMELIST and arrays...

OP1
New Contributor III
735 Views
Is it possible to use a NAMELIST construct to read an array efficiently? For instance, assuming that A is an integer array of dimension 2x5, can we use something that would be similar (in principle) to the following pseudo code?

&MY_NAMELIST
A(:,2) = /1,2/
A(1,1:5:2) = /3,4,5/
/

The idea is to input efficiently sections of the array, or maybe even specify non-unity strides. Obviously the example above will not work - but maybe there is a way to achieve this?

Thanks!

Olivier

0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
735 Views
Oliver,

You might want to construct a state machine and reader to read-in your sparse arrays (or sparse updates to previously loaded data).

This will provide for extended capabilities over NAMELIST (you add the extended capabilities).

The state machine works off a data file to be read sequentially. The mechanics of the state machine is to work somewhat like a binary loader. The data contains an identifier for next entity (or end of file). In your case the entity would be an array identifier (A), the next input data might be an offset (index), then count of data, then data for insert. You might configure the state table such that you can have multiple read-in formats

array id, offset, n, { n elements }
array id, stride fill, stride, offset, n, {n elements at stride seperation }
array id, wipe, offset, n
...


A technique that I found useful was for the read-in code to expect numeric values (easy to code hard to read) but then use the Fortran Preprocessor to preprocess the "human readable text" file for input into numeric format for program reading.

Use the #define ARRAYnameHere nnnn

And other mnemonic names for the numeric values/codes.

The preprocessor additionaly supports

#include aFileNameHere.xx

And then you can then construct your master data tables out of pre-build components.


Jim Dempsey
0 Kudos
John4
Valued Contributor I
735 Views

Maybe I don't understand the question... Or maybe the previous answer is way too much for a simple question, but:

In Fortran, slash ( / ) is used to skip or end input. Try changing the data file to something like:

&MY_NAMELIST
A(:,2) = 1,2
A(1,1:5:2) = 3,4,5

/

The following example works just fine with it:

!--------------------------------------------------------------------------------------------------
program nml_test

implicit none

integer :: a(2,5), ios, i, j
namelist /my_namelist/ a

continue
a = 0
open (unit = 100, file = 'nml.dat', status = 'old', action = 'read', iostat = ios)
print '("open ios = ", i0)', ios

read (100, my_namelist, iostat = ios)
print '("read ios = ", i0)', ios

close (100, iostat = ios)

print '("A(", i0, ",", i0, ") = ", i0)', ((i, j, a(i, j), i = 1, 2), j = 1, 5)

end program nml_test
!--------------------------------------------------------------------------------------------------

0 Kudos
OP1
New Contributor III
735 Views
AAArgh! Thanks John!! That was so simple... I can't believe I let this syntax error pass by without catching it. My namelist group was a lot more complicated that this, and I was wondering why my arrays were not initialized properly when all the previous scalarvariables were.

Thanks again!
Olivier
0 Kudos
Reply