Gfortran spacing

  • Follow


Hello,

I am used to the lahey fortran compiler..... recently I have switched
to the gfortran compiler.... now when I write out data the default
puts several spaces between variables in the outputted text file....
for example if I do: write (11,*) Data(:)
the text file will have several spaces between the Data variables in
the file 11.... In lahey the default was set to 2 I think... how do i
change this to 2 in gfortran?

Regards,

John Hickey
0
Reply JohnHickey 2/3/2011 1:26:41 AM

On Feb 2, 8:26=A0pm, JohnHickey <hickeyj...@gmail.com> wrote:
> Hello,
>
> I am used to the lahey fortran compiler..... recently I have switched
> to the gfortran compiler.... now when I write out data the default
> puts several spaces between variables in the outputted text file....
> for example if I do: write (11,*) Data(:)
> the text file will have several spaces between the Data variables in
> the file 11.... In lahey the default was set to 2 I think... how do i
> change this to 2 in gfortran?
>
> Regards,
>
> John Hickey

You change it by using an explicit format, for example

write (11,"(1000(f0.4,1x)") Data(:)

assuming Data(:) is real.

The free g95 compiler uses fewer spaces in list-directed output. You
could try it.

0
Reply Beliavsky 2/3/2011 2:02:39 AM


JohnHickey <hickeyjohn@gmail.com> wrote:

> I am used to the lahey fortran compiler..... recently I have switched
> to the gfortran compiler.... now when I write out data the default
> puts several spaces between variables in the outputted text file....
> for example if I do: write (11,*) Data(:)
> the text file will have several spaces between the Data variables in
> the file 11.... In lahey the default was set to 2 I think... how do i
> change this to 2 in gfortran?

Variants of this count as a frequently asked question here. The specific
question varies, but the general theme is asking how to control
list-directed output formatting.

The answer is invariably to not use list-directed formatting when you
care about the details. Use an explicit format instead.

The whole point of list-directed formatting is to make things simple by
not bothering to specify detaults, but to let the compiler put out the
data in whatever way it wants. (Well, not quite whatever way; there are
some specifications in the standard, but the compiler is still left a
lot of liberty).

If you want to specify the formatting details, that's what explicit
formats are for. Yes, that is often more awkward than list-directed.

No, there do not tend to be ways for you to control the details of
list-directed formatting. I have commented several times that the
user-defined output feature of f2003 could trivially be enhanced to
allow this, but there doesn't seem to be much general interest in such
an enhancement. Heck, there doesn't seem to be much rush to implement
even the feature as it is in the f2003 standard. It is one of the last
f2003 features in terms of implementation progress.

P.S. Well, in theory there are ways to control such things in gfortran.
It being open source, you could change it yourself, but I'm going to go
out on a limb and guess that's not what you had in mind. (I'm feeling
pretty steady on that limb. :-)

-- 
Richard Maine                    | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle           |  -- Mark Twain
0
Reply nospam 2/3/2011 2:27:46 AM

On Feb 2, 9:27=A0pm, nos...@see.signature (Richard Maine) wrote:

> No, there do not tend to be ways for you to control the details of
> list-directed formatting.

True, but in g95 one can set the G95_LIST_SEPARATOR variable, which is
the

"string Separator to use when writing list output. May contain any
number of spaces and at most one comma. Default is a single space."

http://g95.org/docs.shtml
0
Reply beliavsky (2207) 2/3/2011 1:39:54 PM

On 02/03/2011 02:39 PM, Beliavsky wrote:
> On Feb 2, 9:27 pm, nos...@see.signature (Richard Maine) wrote:
>> No, there do not tend to be ways for you to control the details of
>> list-directed formatting.
>
> True, but in g95 one can set the G95_LIST_SEPARATOR variable, which is
> the "string Separator to use when writing list output. May contain any
> number of spaces and at most one comma. Default is a single space."


Which also does not really toggle between the two design choices:

One group of compilers adds many spaces such that when writing multiple 
lines, a nice grid is created and numbers belonging to each other are 
underneath each other.

The other group adds just a single space and avoids filling the space 
with useless spaces; typically that a good choice if one wants to print 
only a single line.

There is an additional design choice: Whether a line break should happen 
automatically such that no line is longer than a certain number of 
characters or whether one simply writes in one line as long there is 
still data left in the IO transfer statement.

I think there are good reasons for those 4 combinations. Usually, I 
would like to have a different result at different places in my program 
- without tweaking the edit descriptor.

At least "g0" is a convenient edit descriptors which usually gives the 
desired result without requiring the user to think too much. :-)

Tobias

PS: There are more choices in list-directed I/O, e.g. how many digits 
should be printed, but I think the two mentioned above are the most visible.
0
Reply burnus (564) 2/3/2011 2:31:51 PM

On 02/03/2011 06:31 AM, Tobias Burnus wrote:
> On 02/03/2011 02:39 PM, Beliavsky wrote:
>> On Feb 2, 9:27 pm, nos...@see.signature (Richard Maine) wrote:
>>> No, there do not tend to be ways for you to control the details of
>>> list-directed formatting.
>>
> 
> At least "g0" is a convenient edit descriptors which usually gives the
> desired result without requiring the user to think too much. :-)
> 
> Tobias
> 
> PS: There are more choices in list-directed I/O, e.g. how many digits
> should be printed, but I think the two mentioned above are the most
> visible.

I though only the i, f, b, o, and z edit descriptors could have zero width?


0
Reply baf (63) 2/3/2011 4:52:38 PM

On 2/3/11 10:52 AM, baf wrote:
> On 02/03/2011 06:31 AM, Tobias Burnus wrote:
>> On 02/03/2011 02:39 PM, Beliavsky wrote:
>>> On Feb 2, 9:27 pm, nos...@see.signature (Richard Maine) wrote:
>>>> No, there do not tend to be ways for you to control the details of
>>>> list-directed formatting.
>>>
>>
>> At least "g0" is a convenient edit descriptors which usually gives the
>> desired result without requiring the user to think too much. :-)
>>
>> Tobias
>>
>> PS: There are more choices in list-directed I/O, e.g. how many digits
>> should be printed, but I think the two mentioned above are the most
>> visible.
>
> I though only the i, f, b, o, and z edit descriptors could have zero width?
>
>
True for Fortran 2003, Fortran 2008 also allows zero width for G.

Dick Hendrickson
0
Reply dick.hendrickson (1286) 2/3/2011 5:19:29 PM

On 02/03/2011 05:52 PM, baf wrote:
> I though only the i, f, b, o, and z edit descriptors could have zero width?

It was added with Fortran 2008. I tend to forget that it was a 2008 and 
not a 2003 addition as gfortran supports it since GCC 4.4 (i.e. since 
more than 2 years). [1]

Thus, if one restricts oneself to gfortran and Cray [2], one can already 
use g0. Otherwise, it might be better to restrict oneself to the other 
edit descriptors.

Tobias,
who is looking forward to see compilers with full - well-tested - 
Fortran 2003 (and possibly also Fortran 2008) support.

[1] http://fortranwiki.org/fortran/show/Fortran+2008+status
0
Reply burnus (564) 2/3/2011 5:25:18 PM

"JohnHickey" <hickeyjohn@gmail.com> wrote in message 
news:a934a4ba-b51b-45ce-abce-b43a12dfd654@n11g2000vbm.googlegroups.com...
| Hello,
|
| I am used to the lahey fortran compiler..... recently I have switched
| to the gfortran compiler.... now when I write out data the default
| puts several spaces between variables in the outputted text file....
| for example if I do: write (11,*) Data(:)
| the text file will have several spaces between the Data variables in
| the file 11.... In lahey the default was set to 2 I think... how do i
| change this to 2 in gfortran?

With * as the format, the compiler can use any layout that it likes.

If you want specific layout, best to use an explicit format.
That way you can control the position of spaces and how many of them. 


0
Reply robin 2/7/2011 12:35:43 AM

8 Replies
192 Views

(page loaded in 2.015 seconds)

Similiar Articles:













7/26/2012 6:18:00 AM


Reply: