PDA

View Full Version : Re: [LF] Formated Namelists!


Lahey Support
08-15-2003, 01:33 AM
> Farschad Torabi wrote:
>
> Dear Users,
> I have a problem in writing formated namelists.
> The problem begins when i want to
> compare the variables that are read
> by a namelist at the first and last line
> of the program! All i want to do is reading
> and writing a namelist with a good format.
> For example suppose that i have a namelist
> like the one bellow:
>
> NAMELIST /TEST/ A , B
>
> and the input file is something like this:
>
> &TEST
> A=10
> B=10
> &END
> then when i run the following code:
>
> READ(10,TEST)
> WRITE(11,TEST)
>
> the output file is not like the one that i wrote
> in input file. The result may be something like this:
>
> &TEST A=10.000000,B=15.000000 /
>
> Is there any soulution for this problem??

No real solution, unless you go to formatted input/output.
Namelist are, by their very nature, a flexible entry
mode, where any properly defined variable can be
assigned a suitable value, in any order. In fact, you
may even clobber a value by setting it several times in
the same namelist block, and only the last entry will
be retained. As such, the ordering, the completeness (i.e.
not all variables need be present in a namelist block,
which means the value remains as it was before the
read itself), the layout (leading blanks, coma, or number
of variables set on each line) and the representation
of the REAL variables (as Fn.m) are unspecified, and not
retained internally.

The system thus has no way to determine how you want
your data in the output, and can only give you something that
will work if you were to read it using the same read.
In this case, the system decided to give you all the
significant digits, on a single line, in the order
that the variables are specified in your namelist definition,
and using the "/" character that is equivalent to "&END"
or "$END". This, I presume, is the only way the computer
will be able to produce namelist on output.

Now, for your specific problem, you may want to compare the
way your namelist output data, through a namelist WRITE,
at the beginning and at the end of your program. You may
not have something identical to YOUR input file, but at least
the WRITE will produce something consistent between themselves.
Note that, when outputting a namelist, ALL the variables defined
in the namelist will be output, whether they were updated or not.

If this is not acceptable, the only approach left is the
"if you can't beat them, join them" attitude, where YOU
enter your namelist in the same way the program writes them.

Good luck.

>
> Thank you in advance,
> Farschad Torabi

--
C.B.Vincent Goudreault, Ing. tél: (514) 855-5001 poste 53442
BTS, Dept 747 fax: (514) 855-2497
Bombardier Aéronautique
1800 Marcel-Laurin, St-Laurent, Québec H4R 1K2 CANADA
----------------------------------------------------------
To unsubscribe, send to [address removed] the following
as the first and only line of the message body:
unsubscribe fortran
----------------------------------------------------------