F90 arrays in namelists w/o abc(2,3)=44.4 notation

  • Thread starter Thread starter solarblast
  • Start date Start date
  • Tags Tags
    Arrays Notation
Click For Summary

Discussion Overview

The discussion revolves around the behavior of Fortran 90 arrays when written to a namelist, specifically addressing issues related to the output format and the handling of array dimensions. Participants explore the implications of array declarations, data input methods, and the resulting output in namelist files.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a program that outputs a 100x2 array in a namelist format, noting that the output consists of a single name followed by a long list of numbers, which seems incorrect compared to expectations of individual element notation.
  • Another participant suggests that to have separate names for each element, one should write each element individually, indicating that the Fortran standard allows for a single namelist name for the entire array, which may simplify file size and processing.
  • A participant inquires about how to specify the number of rows used in the array to avoid including unused elements in the output.
  • Another participant mentions the need to specify a format in the write command to control how many columns are written, implying that defaults may not suit all cases.
  • A participant shares their experience with a declared array showing unexpected random numbers in the output when only a portion of the array is populated, raising concerns about the handling of uninitialized elements.
  • A later reply indicates that changing the array size to match the number of populated rows resolved the issue of extraneous numbers in the output.

Areas of Agreement / Disagreement

Participants express differing views on the output format of arrays in namelists, with some suggesting that the Fortran standard's handling is appropriate while others find it problematic. The discussion includes unresolved questions about how to manage array dimensions and output formatting effectively.

Contextual Notes

Participants mention limitations related to the handling of array dimensions and the implications of using default formatting in output commands, which may lead to confusion or unexpected results.

solarblast
Messages
146
Reaction score
2
I wrote a program that writes arrays in a namelist under MinGW in Win7. The array is 100x2. It is written in two columns, alf(*,1) and then alf(*,2), where * means 100 row elements. It puts out the name of the array followed by a lot of numbers without any alf(1,1), alf(2,1), ..., alf(1,100), alf(1,2),alf(2,2), ..., alf(100,2) notation. Further, the namelist in the output file shows alf = followed by 200 numbers separated by commas. That seems wrong to me. Another fellow I'm working with that uses f90 in Linux claims one should get alf(1,1) = 33.2, alf(2,1) = 84.5, etc., and not just numbers. Perhaps he has a different version of f90.

I wrote a small program dealing with this declaration:
real, dimension(1:5, 1:2) :: astro_data (I didn't use the 1:5 notation in the above pgm)

and filled the elements with numbers. I write the array, then read it back. The result looks the same, and I see no indication of astro_data(int,int)=number.

What's going on here?
 
Technology news on Phys.org
If you want a separate name for each element of the array, do a separate write for each element.

The Fortran standard says you can have one namelist name for the whole array, That reduces the size of the data file and speeds up reading and writing it (because the program doesn't have to parse 100 separate names), but a single name might make it harder for humans to read or edit the data file. In any particular case, the "best" option is a tradeoff.
 
How do I specify 40 rows are used, so that I don't drag around the other 60?

I finally got a hold of F 90 Hbk by Adams, Martin, et al. On p434 it shows, pg 442, a namelist output example with three array names (DEPTH(1) = 1.2, ...) followed with another 3 element array (Pressure(1)=3. 3.0, ...). Strange.
 
If you want to specify how many columns to write, you need to specify a format in your write command...otherwise, it would go on default...don't remember how many they are if you matrix is too wide
 
Well, this is a bit bizarre. My declared array is alf(100,2). I read data into the first data of column in alf(100,1). Then later I read it into alf(100,2). Really only 40 rows of data in each. When I write the namelist, it shows 200 elements. The first 40 elements are the data from the second column, and the other 160 are random numbers.

Here's some the code (ne is 100):
real :: ALFMET(ne,2) ! Alpha measured, radians
real :: DLTMET(ne,2) ! Delta measured, radians
...
namelist /MeteorIn_Meteor_nml/ alfmet, dltmet, pxm, &
pym, w, cmetd, cmetno
...
case("A08") ! Ra, Dec, etc. on plate for station A
do k=1,ncards
i=1
Read(unit=astro_in, fmt=508, err=8881, iostat=iostat) &
alfmet(k,i), dltmet(k,i), &
pxm(k,i), pym(k,i), w(k,i), cmetd
end do
...
case("B08") ! Ra, Dec, etc. on plate on plate for station A
do k=1,ncards
i=2
Read(unit=astro_in, fmt=508, err=8881, iostat=iostat) &
alfmet(k,i), dltmet(k,i), &
pxm(k,i), pym(k,i), w(k,i), cmetd
end do

(ncards is 40, and yes, I put i= inside a loop. It belongs outside. )
...
Write(*,*) "Output namelists"
Open(unit=astro_out, file="MeteorNamelist.dat", status = "REPLACE")

Write(unit=astro_out, nml=MeteorIn_Meteor_nml)
 
All is well. What I did above is correct. It was made clearer by changing NE to 40. It eliminated all the junk numbers that followed from 41 to 100.
 
Last edited: