Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Fortran Programming Language

namelist read


I cannot figure out the error in the simple namelist read. Any
comments would be welcome

c     Program to check namelist
      INTEGER    i1, i2, i4, iarray(3)
      LOGICAL    l1, l2, l4
      REAL       r4, r8
      COMPLEX    z8, z16
      CHARACTER*9  c1, c10
      open(unit=8,file='ex1.namelist')
      open(unit=9,file='output')
      NAMELIST /example/ i1, i2, i4, l1, l2, l4, r4, r8,
     $                   z8, z16, c1, c10, iarray

      i1  =  11
      i2  =  12
      i4  =  14
      l1  = .TRUE.
      l2  = .TRUE.
      l4  = .TRUE.
      r4  =  24.0
      r8  =  28.0e0
      c1  = 'A'
      c10 = '0123456789'
      iarray(1) = 41
      iarray(2) = 42
      iarray(3) = 43
      read(*,example,end=99)
      print *, i1,i2,c1
      WRITE (9, nml=example)
99    stop
      end

and the file which goes with it
more ex1.namelist
&example
   i1=66
   i2=77
   c1 ='abcdef'
&end

pips wrote:
> I cannot figure out the error in the simple namelist read. Any
> comments would be welcome

what error?  what bad thing happens?
I believe you need a slash (/) at the end of the values, not an
&END.

Dick Hendrickson

You opened unit 8 for FILE='ex.namelist', but now you're
trying to READ from "standard input".  In addition, the
second parameter to READ defaults to a format statement,
not the name of a namelist.  Try this instead:

         read(8,NML=example,end=99)

>       print *, i1,i2,c1
>       WRITE (9, nml=example)
> 99    stop
>       end

> and the file which goes with it
> more ex1.namelist
> &example
>    i1=66
>    i2=77
>    c1 ='abcdef'
> &end

As Dick Hendrickson noted, you need to end the namelist
with a slash, "/", not "&end".

    -Ken
--
Ken & Ann Fairfield
What:  Ken dot And dot Ann
Where: Gmail dot Com

Ken Fairfield <K@Napili.Fairfield.Home> wrote:
> In addition, the
> second parameter to READ defaults to a format statement,
> not the name of a namelist.

It can be either a format specifier (any of the 3 forms - not just a
statement number) or a namelist group name. The NML= is optional, just
like the FMT=. That's not a problem. Your other comments seem on the
mark, though.

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain

On Jun 5, 8:20 pm, nos@see.signature (Richard Maine) wrote:

> Ken Fairfield <K@Napili.Fairfield.Home> wrote:
> > In addition, the
> > second parameter to READ defaults to a format statement,
> > not the name of a namelist.

> It can be either a format specifier (any of the 3 forms - not just a
> statement number) or a namelist group name. The NML= is optional, just
> like the FMT=. That's not a problem. Your other comments seem on the
> mark, though.

> --
> Richard Maine                    | Good judgement comes from experience;
> email: last name at domain . net | experience comes from bad judgement.
> domain: summertriangle           |  -- Mark Twain

Thanks all, it works in MS Fortran and not in Unix!!
Get this error msg "ex1.f", line 9: Error: declaration among
executables
On Jun 6, 9:03 am, pips <k_par@yahoo.com> wrote:
...

> Thanks all, it works in MS Fortran and not in Unix!!
> Get this error msg "ex1.f", line 9: Error: declaration among
> executables

Move the OPEN statements after the NAMELIST...

--

"pips" <k_par@yahoo.com> wrote in message

news:1181138601.863503.13380@q66g2000hsg.googlegroups.com...

> Thanks all, it works in MS Fortran and not in Unix!!
> Get this error msg "ex1.f", line 9: Error: declaration among
> executables

Which is correct: the NAMELIST statement (declaration) should precede the
open statements (executables).

Regards,

Mike Metcalf

On Tue, 5 Jun 2007, pips wrote:
> I cannot figure out the error in the simple namelist read. Any
> comments would be welcome

>       CHARACTER*9  c1, c10

[ ... snip ... ]

>       c10 = '0123456789'

you declared "c10" with space for nine characters, then assigned it ten.

Chip

--
Charles M. "Chip" Coldwell
"Turn on, log in, tune out"

That's OK, maybe not what was intended, but OK and well defined.
The standard says that if there is a length mismatch between
the left and right hand sides characters are truncated from the
right or blank padded on the right.

In a sort of way, it's somewhat like
      single_thing = 12345.678901234567890D0
and
      double_thing = 1.2

Dick Hendrickson

There's a whole host of problems with NAMELIST.  In the good old days,
it was a non-standard extension to Fortran.  Different vendors did it in
different ways.  In particular, the NAMELIST statement is sort of like
a DATA statement (without the values in the /.../ part) and, since DATA
can be intermixed with executable statements some vendors allowed
NAMELIST to be also intermixed.  Other vendors thought NAMELIST was
more like a declarative and didn't allow it to be intermixed.  There
were also a ton of ways to end the namelist input.  &END was one, so
was $END and ....

MS Fortran is a pretty old Fortran and it's a mistake to assume that
what it accepts is portable.  You'd be better off to get a newer
Fortran 95 compiler (there are a couple of good free ones) and use
those.  Also, you should get in the habit of compiling with full
enforcement of standard checking turned on.  Many compilers don't
always warn you if you are using one of their extensions.

Dick Hendrickson

On Jun 6, 11:38 am, Dick Hendrickson <dick.hendrick@att.net> wrote:

I switched over Compaq 6.6 andit works fine but not on unix!
On 2007-06-06 14:10:29 -0300, pips <k_par@yahoo.com> said:

DOS (or Windows) has a different file format than Unix. DOS uses
<CR><LF> for a line end but Unix uses <LF>. There are many trivial
conversion utilities that do the job. Often a text editor will have
options to do the job. To add to the confusion MacOs uses <CR> when
it thinks it is a Mac and <LF> when it thinks it is Unix.

A diagnostic of "not on Unix" is unlikely to be literally true so
will not generate any help.

You will be repeatedly told that the fact that you have an error that you
do not understand shows that there is something that you do not understand.
Repeating what you understand and what you think the error is of no help
either you or those who you are asking for advice.

Only when you show everything (and that means especially the things you
think do not matter) will make things clearer to others and they may then
be able to find the point of your confusion. By definition it will be
something that you did not realize was important!

This message gets repeated at least once a day because it violated much more
often than once a day.

pips <k_par@yahoo.com> wrote:
> Thanks all, it works in MS Fortran and not in Unix!!
> Get this error msg "ex1.f", line 9: Error: declaration among
> executables

Asothers have noted, the NAMELIST statement needs to be before the OPEN.
WIth the OPEN first, you have nonstandard code.It is common for
nonstandard code to act differently with different compilers.

However, the main reason I'm posting this is to correct the comment
about it not working "in Unix." This has absolutely zero to do with the
operating system. It depends on the compiler. There have probably been
hundreds, arguably even thousands if you want to count in such a way as
to stretch the point, of different compilers on Unix systems. Those
compilers do not share the same feature set.

Saying that something worked "in Unix" is about as meaningful as saying
that it works on a laptop computer, but not a desktop one; it just is
not the relevant distinction.

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain

On Jun 6, 10:03 am, pips <k_par@yahoo.com> wrote:

In article <5cm85uF30r7s@mid.individual.net>,
Ken Fairfield  <K@Napili.Fairfield.Home> wrote:
>pips wrote:
>> I cannot figure out the error in the simple namelist read. Any
>> comments would be welcome

>> c     Program to check namelist
...
>>       open(unit=8,file='ex1.namelist')
>>       open(unit=9,file='output')
>>       NAMELIST /example/ i1, i2, i4, l1, l2, l4, r4, r8,
>>      $                   z8, z16, c1, c10, iarray

...

The NAMELIST statement is a specification statement so it must come
before those OPEN statements not after them. However, that's not a
Constraint, so a program with that error may or may not compile, and
if it does, anything may happen at run time.

With both that correction and Ken's to the 'ex1.namelist' file the
program ran with three different unix compilers and gave the expected
output. But our old version of a fourth compiler said at run time
'Arithmetic exception: Floating invalid operand - aborting', and core-
dumped, when trying to write the namelist. That error went away if z8
and z16 were given values before the write statement. I suspect all 4
compilers are standard-conforming here, because the last sentence of
the f95 standard 9.4.4.4 says "On output, every entity whose value is
to be transferred shall be defined", but that's not a Constraint. :-(

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.har@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045

It's not a "constraint", it's part of the formal syntax rules, so
compilers are required to diagnose the error.  But, they are also
allowed to have extensions (or errors in their diagnosis :( ) and can
accept non-standard things.   Unfortunately, reporting use of an
extension doesn't have to be the compiler default, but it does have
to have the capability.

If you have an afternoon to kill and want to see that the syntax
requires NAMELIST before the executables, the easiest place to start
is with rule R1223 in chapter 2 (not 12) and you'll eventually find that
NAMELIST is part of the specification part.  If you're really
looking for fun try to trace through how DATA, FORMAT, and ENTRY
can be intermixed amongst both specification and execution parts.

Dick Hendrickson

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc