Re: Newbie question

beliavsky_at_aol.com
Date: 02/26/05


Date: 26 Feb 2005 14:44:16 -0800


OIx wrote:
> Hi! I have a fortran program, that creates mesh for two-dim. area. I
> have to load nodes into Ansys, therefore i have to write node
> coordinates into specifically formatted file. The bad thing is i do
not
> know how to do it, so please help!
>
> I have the following piece of code:
>
> OPEN(UNIT, FILE='Grid', FORM = 'FORMATTED', STATUS= 'REPLACE',
> IOSTAT=error)
> WRITE(UNIT, FMT='(F8.5)') ((X(i,j), Y(i,j), j=1, N2_G), i=1, N1_G)
> CLOSE(UNIT)
>
> I writes coordinates line by line:
> x11
> y11
> x12
> y12
> etc.
>
> Instead of this, i'd like it to write as
> NODE_NUMBER X Y Z
> i.e.
> (i*N2_G +j) Xij Yij 0
>
> I'm absolutely new to fortran, and it's doesnot look like C or smth.
at
> all :))

Why should Fortran look like C? We got there first :).

You need to change the FMT='(F8.5)' part of the write statement. For
example, FMT='(1x,i6,1000F8.5)' will print an integer followed by up to
1000 reals on one line.

I think one of the tutorials at
http://www.dmoz.org/Computers/Programming/Languages/Fortran/Tutorials/Fortran_77/
, perhaps the book by Clive Page, discusses the syntax of format
strings. They are not that different from formats of the C printf
statement, although C does not have the handy repeat edit descriptor,
does have the handy newline character, and by default does not start
the output of each printf on a new line.



Relevant Pages

  • Re: Fortran is eating my brain
    ... Last few years of my life i have learned many languages (otherthan ... Nowadays i use perl python tcl etc for creating traslating and parsers ... first one writes the output file using fortran units wither in UNFMTD ... Once upon a time formatted data was only available if you used a FORMAT but then a variety of ways for having the system use some format, of its convenience, arrived. ...
    (comp.lang.fortran)
  • Re: speed up calculation suggestions
    ... Fortran matter. ... same internal formats - the ones that the CPU supports. ... the large majority of machines today use the same format. ...
    (comp.lang.fortran)
  • Re: Variable length/precision formats?
    ... I'm returning to Fortran after many years of C, ... is passed to the printfrather than being hardcoded into the format. ... request more features, the standard changes, and more ... vendor representatives were discussing "DEC VFE's". ...
    (comp.lang.fortran)
  • Re: Read Fortran .exe results
    ... You need to specify the file format of the fortran program. ... vary from compiler to compiler and from system to system, ... Actually very often I have binary format output. ...
    (comp.soft-sys.matlab)
  • Re: Read Fortran .exe results
    ... You need to specify the file format of the fortran program. ... vary from compiler to compiler and from system to system, ... Actually very often I have binary format output. ...
    (comp.soft-sys.matlab)