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

In summary, the program 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
  • #1
solarblast
152
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
  • #2
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.
 
  • #3
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.
 
  • #4
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
 
  • #5
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)
 
  • #6
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:

1. What is the purpose of using F90 arrays in namelists without the "abc(2,3)=44.4" notation?

F90 arrays in namelists without the "abc(2,3)=44.4" notation allow for more efficient and concise coding, as it eliminates the need for specifying each individual element of the array. It also helps to reduce errors and makes the code easier to read and maintain.

2. How do you declare F90 arrays in namelists without the "abc(2,3)=44.4" notation?

To declare F90 arrays in namelists without the "abc(2,3)=44.4" notation, you can use the "abc(:,:)" notation instead. This indicates that all elements of the array will be included in the namelist without having to specify each individual element.

3. Can you use the "abc(:,:)" notation with non-rectangular arrays?

Yes, the "abc(:,:)" notation can be used with non-rectangular arrays as well. This allows for more flexibility in the size and shape of the array, making it easier to work with complex data sets.

4. Are there any limitations to using F90 arrays in namelists without the "abc(2,3)=44.4" notation?

One limitation of using F90 arrays in namelists without the "abc(2,3)=44.4" notation is that it cannot be used with arrays that have string or character elements. It is best suited for numerical data.

5. How does using F90 arrays in namelists without the "abc(2,3)=44.4" notation affect the performance of the code?

Using F90 arrays in namelists without the "abc(2,3)=44.4" notation can improve the performance of the code, as it eliminates the need for multiple lines of code to specify each individual element of the array. This can also lead to faster execution times and more efficient memory usage.

Back
Top