Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Jun 9, 2012 #1
    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?
     
  2. jcsd
  3. Jun 9, 2012 #2

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    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.
     
  4. Jun 9, 2012 #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.
     
  5. Jun 10, 2012 #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
     
  6. Jun 10, 2012 #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)
     
  7. Jun 10, 2012 #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: Jun 10, 2012
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: F90 arrays in namelists w/o abc(2,3)=44.4 notation
  1. O notation (Replies: 1)

Loading...