For Programmers: Free Programming Magazines  


Home > Archive > Fortran > August 2005 > Fortran write(print) problem









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 Fortran write(print) problem
Wang Jun

2005-08-27, 3:56 am

When I was processing some data files, there needed many ctl
file(something like .ini),
and they should start every line without any "space".
But when I write some code like:

write(5,*)'DSET ^', filenamep
write(5,*)"OPTIONS little_endian"
write(5,*)"UNDEF -999.0"
write(5,*)"TITLE Rainfall of Tibetean"

in the written file, every line start with a "space":
"
DSET ^ gra3.dat
OPTIONS little_endian
UNDEF -999.0
"
not:
"
DSET ^ gra3.dat
OPTIONS little_endian
UNDEF -999.0
"

that coursed many problems, so how can I get the output lines
start with none "space"??

Thank you very much

Brooks Moses

2005-08-27, 3:56 am

Wang Jun wrote:
> When I was processing some data files, there needed many ctl
> file(something like .ini),
> and they should start every line without any "space".
> But when I write some code like:
>
> write(5,*)'DSET ^', filenamep
> write(5,*)"OPTIONS little_endian"
> write(5,*)"UNDEF -999.0"
> write(5,*)"TITLE Rainfall of Tibetean"
>
> in the written file, every line start with a "space":


Yes. You've specified "*" formatting, which means (essentially) that
you don't care about the details of how it looks so long as you can read
it. Some compilers print out *-formatted lines with spaces in front of
them; some don't.

If you do care about the details (such as whether or not the line starts
with a space), you need to specify the format in more detail, like so:

write(5,'(2A)')'DSET ^', filenamep
write(5,'(A)')"OPTIONS little_endian"
write(5,'(A)')"UNDEF -999.0"
write(5,'(A)')"TITLE Rainfall of Tibetean"

- Brooks


--
The "bmoses-nospam" address is valid; no unmunging needed.
Gib Bogle

2005-08-27, 6:58 pm

Wang Jun wrote:

> When I was processing some data files, there needed many ctl
> file(something like .ini),
> and they should start every line without any "space".
> But when I write some code like:
>
> write(5,*)'DSET ^', filenamep
> write(5,*)"OPTIONS little_endian"
> write(5,*)"UNDEF -999.0"
> write(5,*)"TITLE Rainfall of Tibetean"


That should be "Tibetan", or "Tibet" ;-)
Richard E Maine

2005-08-27, 9:58 pm

In article <43101BF9.6040506@cits1.stanford.edu>,
Brooks Moses <bmoses-nospam@cits1.stanford.edu> wrote:

> Yes. You've specified "*" formatting, which means (essentially) that
> you don't care about the details of how it looks so long as you can read
> it. Some compilers print out *-formatted lines with spaces in front of
> them; some don't.


Those that don't were violating the standard. To my knowledge, most or
all of them have been fixed (possibly with compiler switches to ask for
the nonstandard behavior).

Although I agree (and have regularly said) that the general rule is that
* formatting is for when you don't care about the details, this
particular case is not even a matter where the compiler might or might
not do what you want. In this case, the standard actually *REQUIRES*
the compiler to do what you don't want (even if some compilers have been
known to violate the standard). The reasons for that are historical.

Brooks gave the recommended solution, which I won't repeat.

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
Brooks Moses

2005-08-28, 3:56 am

Richard E Maine wrote:
> Although I agree (and have regularly said) that the general rule is that
> * formatting is for when you don't care about the details, this
> particular case is not even a matter where the compiler might or might
> not do what you want. In this case, the standard actually *REQUIRES*
> the compiler to do what you don't want (even if some compilers have been
> known to violate the standard). The reasons for that are historical.


If you don't mind the telling, I'd like to hear the historical reasons.
I find myself curious as to how this came about whenever I run across it.

- Brooks


--
The "bmoses-nospam" address is valid; no unmunging needed.
Wang Jun

2005-08-28, 3:56 am


Thank you all very much!

maybe the format standard is quite different
to C, aha.

Thomas Koenig

2005-08-28, 7:57 am

Brooks Moses <bmoses-nospam@cits1.stanford.edu> wrote:
>Richard E Maine wrote:
[color=darkred]
>If you don't mind the telling, I'd like to hear the historical reasons.


The first character in a printed line was interpreted as a (hardware)
carriage control character. ' ' meant a new line, '1' a new page,
'+' overprinting, and possibly a few others that I've forgotten.

The 'asa' utility on Unix systems is usually used to convert this to
something more Unixish.
Ron Shepard

2005-08-28, 6:57 pm

In article <des045$5m5$1@meiner.onlinehome.de>,
Thomas Koenig <Thomas.Koenig@online.de> wrote:

> Brooks Moses <bmoses-nospam@cits1.stanford.edu> wrote:
>
>
> The first character in a printed line was interpreted as a (hardware)
> carriage control character. ' ' meant a new line, '1' a new page,
> '+' overprinting, and possibly a few others that I've forgotten.
>
> The 'asa' utility on Unix systems is usually used to convert this to
> something more Unixish.


The other one that I remember was "0" for double spacing.

The American Standards Association (ASA) was formed in 1928 and
published standards for, among other things, electrical wiring
standards, photographic standards, and standards for bolts and
fasteners. As computing and information technology became more
popular over the following decades, it also published standards
related to that. One of those was the printer control convention
mentioned above. In 1968, ASA was renamed the American National
Standards Institute (ANSI), and it approved the 7-bit American
Standard Code for Information Interchange (ASCII) character set in
1968. There were many other computer character sets at that time,
including 8-bit EBCDIC and the 6-bit character sets used by Univac
and CDC. Early adopters of the ASCII character set included DEC,
which stored five 7-bit ASCII characters in each 36-bit word. Other
computer systems stored each 7-bit character in an 8-bit byte, which
also introduced compatibility problems over what exactly that extra
bit was supposed to do; some systems used it for parity checking,
others always set the extra bit either on or off, others used the
extra bit to extend the character set to 256 characters, and some
systems tried to do several of these in different contexts on the
same computer.

Fortran was originally designed to be consistent with the standard
ASA conventions for printed files and to be independent of the
underlying character set representation. That meant that list
directed formatting was required to begin each line with a space
(just in case it were to be printed on an ASA printer). This is
also why many fortran programs routinely insert spaces at the
beginning of even lines printed with explicit formats (e.g. formats
begin with 1x, or 1H , or ' ', or otherwise ensure that there will
be a blank space at the beginning). Unix and C were developed after
1969, so they broke with standards compliance and used the idea of
embedded control characters using the ASCII character set. Over
time, that convention (with some ambiguity about exactly how lines
are terminated, CR, CR+LF, or LF) replaced the ASA format first as
the de facto standard, and later as the actual standard (e.g. for
FTP file transfers and other contexts).

Mostly for compatibility reasons, i.e. historical reasons, modern
fortran standards have continued to require the space at the
beginning of each line in list directed output.

$.02 -Ron Shepard
glen herrmannsfeldt

2005-08-28, 6:57 pm

Ron Shepard wrote:

(snip with history of ASA, ANSI, and such)

> Fortran was originally designed to be consistent with the standard
> ASA conventions for printed files and to be independent of the
> underlying character set representation. That meant that list
> directed formatting was required to begin each line with a space
> (just in case it were to be printed on an ASA printer). This is
> also why many fortran programs routinely insert spaces at the
> beginning of even lines printed with explicit formats (e.g. formats
> begin with 1x, or 1H , or ' ', or otherwise ensure that there will
> be a blank space at the beginning). Unix and C were developed after
> 1969, so they broke with standards compliance and used the idea of
> embedded control characters using the ASCII character set. Over
> time, that convention (with some ambiguity about exactly how lines
> are terminated, CR, CR+LF, or LF) replaced the ASA format first as
> the de facto standard, and later as the actual standard (e.g. for
> FTP file transfers and other contexts).


That, and the transition from line at a time printers, such as
chain, train, and drum printers, to character at a time printers
or printers connected up through a serial line. (The DECwriter
and daisy wheel printers were popular hard copy output devices
for some years.)

To an IBM 1403 printer, CR and LF are just like any other
character that can be printed in a given column, though usually
they don't print anything. (I have done it before, as character
constants in Fortran programs.)

> Mostly for compatibility reasons, i.e. historical reasons, modern
> fortran standards have continued to require the space at the
> beginning of each line in list directed output.


-- glen

Sponsored Links







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

Copyright 2008 codecomments.com