For Programmers: Free Programming Magazines  


Home > Archive > Fortran > October 2006 > Data files format









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Data files format
Julian Bessenroth

2006-09-29, 8:01 am


Hi folks,

is there an easy/simple way to read in data files thar a in a human
readable format. actually I'm using a data struct in my program. This
struct holds all the variables that are required to set up the model
(in this case).

I'd like to fill this struct from a text file e.g. loking like this:
(file1.dat)


long_identifier=1
short_ident=4.0d0
vary_long_identifier=0.05d0

index=1
array_indx=5

index=2
array_indx=6

All this should lead to this:

struct B

B.long_indentifier=1
B.short_ident=4.0d0
B.vary_long_identifier=0.05d0

B.array_indx(1)=5
B.array_indx(2)=6

Does anyone has an idea how I could do this the best way?

Thanks in advance

Julian

Julian Bessenroth

2006-09-29, 8:01 am


Ah, some additional information:

I have to use Fortran 77
I use unix with Sun Solaris (should not make any difference)

TIA

Julian

David Flower

2006-09-29, 8:01 am


Julian Bessenroth wrote:
> Hi folks,
>
> is there an easy/simple way to read in data files thar a in a human
> readable format. actually I'm using a data struct in my program. This
> struct holds all the variables that are required to set up the model
> (in this case).
>
> I'd like to fill this struct from a text file e.g. loking like this:
> (file1.dat)
>
>
> long_identifier=1
> short_ident=4.0d0
> vary_long_identifier=0.05d0
>
> index=1
> array_indx=5
>
> index=2
> array_indx=6
>
> All this should lead to this:
>
> struct B
>
> B.long_indentifier=1
> B.short_ident=4.0d0
> B.vary_long_identifier=0.05d0
>
> B.array_indx(1)=5
> B.array_indx(2)=6
>
> Does anyone has an idea how I could do this the best way?
>
> Thanks in advance
>
> Julian


NAMELIST is not standard F77, but is a frequently encountered
extension; if it is available on your compiler, have a look at it

Dave Flower

beliavsky@aol.com

2006-09-29, 8:01 am


Julian Bessenroth wrote:
> Ah, some additional information:
>
> I have to use Fortran 77
> I use unix with Sun Solaris (should not make any difference)


With code you have shown such as

struct B

B.long_indentifier=1
B.short_ident=4.0d0
B.vary_long_identifier=0.05d0

you are not using Fortran 77 anyway. F77 did not have "struct" or
variable names longer than 6 letters. Maybe you are relying on
non-standard features of a Sun F77 compiler.

There exists a Sun Fortran 95 compiler and free compilers such as
gfortran g95. It is better to use features of the modern version of a
language (in this case a derived type instead of a struct) rather than
non-standard extensions of a compiler that may no longer be supported.

beliavsky@aol.com

2006-09-29, 8:01 am


beliav...@aol.com wrote:

<snip>

> There exists a Sun Fortran 95 compiler and free compilers such as
> gfortran g95.


I left out an "and" between gfortran and g95 -- they started out as the
same project but are now distinct compilers. There is enough confusion
on this subject without my adding to it :).

Julian Bessenroth

2006-09-29, 8:01 am

hi,

beliavsky@aol.com wrote:[color=darkred]
> beliav...@aol.com wrote:
>
> <snip>
>

thanks, but I'm do not have the choicewhat to use. We/I've got a
fortran 90/95 compiler awailable, but I do not have the permissions to
use it.

=> F77, It's Hobson's choice.

regards

Julian

Julian Bessenroth

2006-09-29, 7:01 pm


David Flower wrote:

> NAMELIST is not standard F77, but is a frequently encountered
> extension; if it is available on your compiler, have a look at it


Hi David,

that namelist stuff is quite interesting. Haven't work with it yet. Do
you have [know / know where to find] an example for that. I found some
information in the manual (Sun F77), but its not that rich as I'd like
it to be.

TIA

regards

Julian

Herman D. Knoble

2006-09-29, 7:01 pm

Julian: Namelist Examples (F90):

Skip

http://www.codecomments.com/archive...5-3-438971.html
http://www.engr.umd.edu/~nsw/ench25...n1.htm#NAMELIST
http://ftp.cac.psu.edu/pub/ger/fort...ameListDemo.f90


On 29 Sep 2006 07:11:57 -0700, "Julian Bessenroth" <jbusenet@gmx.de> wrote:

-|
-|David Flower wrote:
-|
-|> NAMELIST is not standard F77, but is a frequently encountered
-|> extension; if it is available on your compiler, have a look at it
-|
-|Hi David,
-|
-|that namelist stuff is quite interesting. Haven't work with it yet. Do
-|you have [know / know where to find] an example for that. I found some
-|information in the manual (Sun F77), but its not that rich as I'd like
-|it to be.
-|
-|TIA
-|
-|regards
-|
-|Julian

Richard Maine

2006-09-29, 7:01 pm

Julian Bessenroth <jbusenet@gmx.de> wrote:

> David Flower wrote:
>
>
> that namelist stuff is quite interesting. Haven't work with it yet. Do
> you have [know / know where to find] an example for that. I found some
> information in the manual (Sun F77), but its not that rich as I'd like
> it to be.


As Herman observed, namelist is standard f90 (and also a common
extension in f77 compilers). Thus you can find some documentation in any
f90 text. However....

As others have noted, you are not using f77. You are using nonstandard
features of a specific compiler. It might well matter here. In
particular, f90 documentation is not going to tell you how namelist
works with so-called VAX structures (which is what I assume you are
using from the looks of it). In f77, you are looking at the intersection
of two nonstandard features. Both are fairly common as f77 extensions,
but I'd be hesitant to trust anything other than the Sun documentation
for details of how they work together in the Sun f77 compiler.

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

2006-09-29, 7:01 pm


Richard Maine wrote:
> Julian Bessenroth <jbusenet@gmx.de> wrote:
>
>
> As Herman observed, namelist is standard f90 (and also a common
> extension in f77 compilers). Thus you can find some documentation in any
> f90 text. However....
>
> As others have noted, you are not using f77. You are using nonstandard
> features of a specific compiler. It might well matter here. In
> particular, f90 documentation is not going to tell you how namelist
> works with so-called VAX structures (which is what I assume you are
> using from the looks of it). In f77, you are looking at the intersection
> of two nonstandard features. Both are fairly common as f77 extensions,
> but I'd be hesitant to trust anything other than the Sun documentation
> for details of how they work together in the Sun f77 compiler.
>
> --
> Richard Maine | Good judgement comes from experience;
> email: last name at domain . net | experience comes from bad judgement.
> domain: summertriangle | -- Mark Twain


Sounds like a case of 'If all else fails, read the manual'

Dave Flower

Rich Townsend

2006-09-29, 7:01 pm

Julian Bessenroth wrote:
> hi,
>
> beliavsky@aol.com wrote:
>
> thanks, but I'm do not have the choicewhat to use. We/I've got a
> fortran 90/95 compiler awailable, but I do not have the permissions to
> use it.
>
> => F77, It's Hobson's choice.
>


Well, then, your code will never work, since F77 doesn't support the a.b syntax
you seem to want to use. Unless there is vendor extension that supports this syntax.

cheers,

Rich
meek@skyway.usask.ca

2006-09-29, 7:01 pm

In a previous article, Rich Townsend <rhdt@barVOIDtol.udel.edu> wrote:
>Julian Bessenroth wrote:
>
>Well, then, your code will never work, since F77 doesn't support the a.b syntax
>you seem to want to use. Unless there is vendor extension that supports this syntax.
>
>cheers,
>
>Rich

OPENWATCOM supports this (extension to Fortran77)
Chris
Julian Bessenroth

2006-09-29, 7:01 pm


Rich Townsend schrieb:

> Well, then, your code will never work, since F77 doesn't support the a.b syntax
> you seem to want to use. Unless there is vendor extension that supports this syntax.


The Sun F77 does support those struct. I'm allready using them. Have a
look at sun.com . I found the a f77 manual with structs in.

have a look at:

http://vnox.de/zip/2
http://vnox.de/zip/3

regards

Julian

Julian Bessenroth

2006-09-29, 7:01 pm


Richard Maine schrieb:

> As Herman observed, namelist is standard f90 (and also a common
> extension in f77 compilers). Thus you can find some documentation in any
> f90 text. However....


I read that f90 and f77 namelist (if supported) are hardle in the same
notation.

> As others have noted, you are not using f77. You are using nonstandard
> features of a specific compiler. It might well matter here. In
> particular, f90 documentation is not going to tell you how namelist
> works with so-called VAX structures (which is what I assume you are
> using from the looks of it). In f77, you are looking at the intersection
> of two nonstandard features. Both are fairly common as f77 extensions,
> but I'd be hesitant to trust anything other than the Sun documentation
> for details of how they work together in the Sun f77 compiler.


Have alook at the links I've posted before. Sun does support structures
as well as namelist. The examples in the Manual could be a bit more
detailed

Thanks to all for your helb. I've found an example that does exacty
what I want (even though iI think the char variables are not set
correct).

http://vnox.de/zip/4

cheers

julian

Richard Maine

2006-09-29, 7:01 pm

Julian Bessenroth <jbusenet@gmx.de> wrote:

> I read that f90 and f77 namelist (if supported) are hardle in the same
> notation.


That is probably so in some compilers (possibly including the specific
one you are using), but it is *NOT* true in general. I know this from
extensive first-hand experience. Because namelist was not standardized
in f77, there were multiple forms of it. They looked generally similar,
but had variation in detail. In fact, the standard f90 form was not
particularly common among at least earlier f77 compilers. Converting
namelist syntax was one of the things one sometimes had to do when
moving from one system to another; I've been there and done that.

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

2006-10-04, 8:02 am


Richard Maine schrieb:

> That is probably so in some compilers (possibly including the specific
> one you are using), but it is *NOT* true in general. I know this from
> extensive first-hand experience. Because namelist was not standardized
> in f77, there were multiple forms of it. They looked generally similar,
> but had variation in detail. In fact, the standard f90 form was not
> particularly common among at least earlier f77 compilers. Converting
> namelist syntax was one of the things one sometimes had to do when
> moving from one system to another; I've been there and done that.


Oh you're right. I found out that not even the Sun related (actual)
documentation on using namelists are true. It said array can't be used,
but they can.

regards

Julian

glen herrmannsfeldt

2006-10-04, 7:01 pm

Julian Bessenroth <jbusenet@gmx.de> wrote:
(snip on NAMELIST)

> Oh you're right. I found out that not even the Sun related (actual)
> documentation on using namelists are true. It said array can't be used,
> but they can.


I would be pretty surprised if any didn't support arrays.

Usually there are two forms, either assign to individual array
elements:

X(1)=3

or to a sequence of elements:

X=3,4,5,6

-- glen
Ron Shepard

2006-10-05, 4:02 am

In article <eg0r4r$jj5$1@naig.caltech.edu>,
glen herrmannsfeldt <gah@seniti.ugcs.caltech.edu> wrote:

> Julian Bessenroth <jbusenet@gmx.de> wrote:
> (snip on NAMELIST)
>
>
> I would be pretty surprised if any didn't support arrays.
>
> Usually there are two forms, either assign to individual array
> elements:
>
> X(1)=3
>
> or to a sequence of elements:
>
> X=3,4,5,6


This is one of the differences between (de facto) f77 namelist and
standard f90 namelist. If you wanted to specify a subblock in f77,
you would do something like

X(2)=4,5,6

while with f90 you have to use

X(2:4)=4,5,6

Somewhat surprisingly, the various input forms

X(1:4)=(/3,4,5,6/)
X(:)=(/3,4,5,6/)
X(:)=3,4,5,6

do not work.

Another common problem with f77 namelist was character variables. I
used to avoid character variables because there were enough
compilers that has problems of one kind or another that it wasn't
worth the trouble making it work in a portable way.

Also, of course, is the way to specify the end of the block. With
f77 namelist, you needed the characters "&end" to begin in column 2
(in upper, lower, or mixed case, and the & could be replaced with a
$). With f90 namelist, a "/" is used and it can be in any column in
the record. When f90 was still new, I used to put "/&end" beginning
in column 1, and that worked for both kinds of input. These days,
IMO, the standard f90 convention is portable enough to use by itself.

$.02 -Ron Shepard
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com