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
AI Thread Summary
The discussion revolves around the handling of F90 arrays in namelists, specifically the output format when writing arrays in a program under MinGW on Windows 7. The author notes that their output displays a single namelist entry for the entire array, resulting in a long list of numbers without individual element references, which contrasts with expectations based on a colleague's experience using F90 in Linux. The Fortran standard allows for this compact representation, which can streamline file size and processing, but may complicate readability. The author seeks clarification on how to limit the output to only the used rows of the array, as they encountered random numbers in their output due to unused elements. Adjusting the declaration to reflect the actual number of used rows resolved the issue, eliminating extraneous data.
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:
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top