From: Bil Kleb on
e p chandler wrote:
> One Fortran feature that I do not use but that might help you is a
> NAMELIST.

I second this recommendation. With very minor tweaks to your
configuration file, it could become a namelist. Then you can get
on with your work and let Fortran worry about parsing etc.

Regards,
--
Bil Kleb
http://fun3d.larc.nasa.gov
From: Bart Vandewoestyne on
On 2009-09-15, e p chandler <epc8(a)juno.com> wrote:
>
> Greetings. It's hard to believe that during all of the time you were
> an active member of this newsgroup, you never had need for "INTERNAL
> READ" or "INTERNAL WRITE" [smile]. It's one of the FAQs.

:-) I did use internal writes, but actually I didn'nt know there
was such as thing as an internal read. This is what I like about
this newsgroup and Fortran 95 programming: even after 5 years,
you still learn new things! :-)

> One Fortran feature that I do not use but that might help you is a
> NAMELIST. Using it would involve changing the format of your config
> file. Essentially it sets up a group of named variables. Then you can
> specify name/value pairs in its particular format and Fortran takes
> care of the multi-way branch logic.

Hmm... i don't think I will use the namelist option, for three
reasons:

1) On
http://www.pcc.qub.ac.uk/tec/courses/f77tof90/stu-notes/f90studentMIF_7.html
is written:

"The NAMELIST statement has been available as a suppliers
extension to Fortran since the early days (it was available as an
IBM extension to FORTRAN II in the early 60's!). It has now been
included in the Fortran 90 language. However, NAMELIST is a
poorly designed feature and should be avoided whenever possible."

2) I'm not sure, but i think using NAMELIST would make it harder
for me to allow comments starting with # in my config file...

3) I prefer to have the freedom of organizing my config file as
*I* (and also my not-so-Fortran-educated) users want it to be.
If I use NAMELIST, i am forcing me and my users to stick with the
namelists syntax.

But thanks for the suggestion!

Bart

--
"Share what you know. Learn what you don't."
From: Ron Shepard on
In article
<0dba33c0-a5fb-4a4c-87e6-5562f50ea9b5(a)m20g2000vbp.googlegroups.com>,
e p chandler <epc8(a)juno.com> wrote:

> Greetings. It's hard to believe that during all of the time you were
> an active member of this newsgroup, you never had need for "INTERNAL
> READ" or "INTERNAL WRITE" [smile]. It's one of the FAQs.

The internal I/O itself has been around since f77 with explicit
formats, but the fmt=* list directed I/O version is new to f90.
Now, f90 itself is 19 years old (or older if you count the f8x
drafts), and that's pretty old in computer years, but for some
reason it still would not surprise me that someone who knows about
internal reads might not realize that fmt=* is now allowed.

I also recommend looking at NAMELIST for this purpose. Basically,
all you need to change in the input file is to put equals signs
between the variable names and the values, insert a line at the
beginning naming the block, and add a slash at the end denoting the
end of the block. This would mean that you would need some control
over the input format. Another possibility is to read the current
input file and write it out in namelist format, and then use fortran
NAMELIST I/O to read that file. That could be done in a fairly
generic way that would allow variables to be added or removed. BTW,
that is the reason for using namelist, it makes it very easy to add,
change, or remove variables, something that is a little more tedious
when you do all the parsing yourself. It also works with all
variable types, arrays, and derived types, something else that
becomes tedious when rolling your own.

$.02 -Ron Shepard
From: Richard Maine on
Bart Vandewoestyne <MyFirstName.MyLastName(a)telenet.be> wrote:

> I would like to read a configuration file that could look like
> this:
>
> nb_apples 3
> my_weight 68.5
> elephant_weight 4.6e3
> smoking_allowed true
> name TestName
....

You appear to have already found an answer on how to do this using
internal read, which is the approach I use for this kind of thing. My
only comment is...

> read(unit=1, fmt=*, iostat=ios) variable_name, variable_value
>
> where variable_name is a character array

No it isn't. If it were, then this would not work. Your variable name is
a scalar character string - not an array. There are such things as
character arrays, but this isn't one. Character strings and arrays have
some similarities, but they are not the same thing. If you don't keep
the concepts separate, you will later be back here asking for help with
them - all but guaranteed.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: nmm1 on
In article <WxOrm.143751$LX3.72405(a)newsfe17.ams2>,
Bart Vandewoestyne <MyFirstName.MyLastName(a)telenet.be> wrote:
>
>Hmm... i don't think I will use the namelist option, for three
>reasons:
>
>1) On
>http://www.pcc.qub.ac.uk/tec/courses/f77tof90/stu-notes/f90studentMIF_7.html
>is written:
>
>"The NAMELIST statement has been available as a suppliers
>extension to Fortran since the early days (it was available as an
>IBM extension to FORTRAN II in the early 60's!). It has now been
>included in the Fortran 90 language. However, NAMELIST is a
>poorly designed feature and should be avoided whenever possible."

Snurfl! That's pretty close to what I say in slide 21 of:

http://www-uxsup.csx.cam.ac.uk/courses/OldFortran/full.pdf


Regards,
Nick Maclaren.