skip an item to WRITE using a FORMAT

  • Follow


Is it possible to skip the WRITE'ing of an item in an output list by
modifying the FORMAT? For example, to print elements [1,2,4] of array
ivec(1:4) I can just write

write (*,"(100i6)") ivec((/1,2,4/))

but I would like to do it as

write (*,fmt_skip) ivec

where fmt_skip tells the compiler to skip printing ivec(3). I want to
be able to change the output of a program by changing the format
string, which can be read from a text file, rather than changing the
source code. It would be nice if something like

write (*,"(2i6,-,100i6)") ivec

worked, where the '-' indicates that one item is to be skipped.

The real goal to print arrays of times (stored as a derived type with
integer components hour, minute, second), easily switching between
printing or not printing seconds. I would like to get output of

12:10:00 12:20:00 12:30:00

OR

12:10    12:20    12:30

with the decision made at run time. I know it is possible using IF
statements.

0
Reply beliavsky (2207) 12/8/2004 4:45:49 PM

In article <1102524349.769695.131020@c13g2000cwb.googlegroups.com>,
beliavsky@aol.com writes: 

> Is it possible to skip the WRITE'ing of an item in an output list by
> modifying the FORMAT? For example, to print elements [1,2,4] of array
> ivec(1:4) I can just write
> 
> write (*,"(100i6)") ivec((/1,2,4/))
> 
> but I would like to do it as
> 
> write (*,fmt_skip) ivec
> 
> where fmt_skip tells the compiler to skip printing ivec(3). I want to
> be able to change the output of a program by changing the format
> string, which can be read from a text file, rather than changing the
> source code. It would be nice if something like

The FORMAT can be a character variable, which of course you can read 
from a text file.  Or am I missing something?

0
Reply helbig (4874) 12/8/2004 6:45:48 PM


helbig@astro.multiCLOTHESvax.de (Phillip Helbig---remove CLOTHES to reply)
wrote:
>In article <1102524349.769695.131020@c13g2000cwb.googlegroups.com>,
>beliavsky@aol.com writes: 
>
>> Is it possible to skip the WRITE'ing of an item in an output list by
>> modifying the FORMAT? For example, to print elements [1,2,4] of array
>> ivec(1:4) I can just write
>> 
>> write (*,"(100i6)") ivec((/1,2,4/))
>> 
>> but I would like to do it as
>> 
>> write (*,fmt_skip) ivec
>> 
>> where fmt_skip tells the compiler to skip printing ivec(3). I want to
>> be able to change the output of a program by changing the format
>> string, which can be read from a text file, rather than changing the
>> source code. It would be nice if something like
>
>The FORMAT can be a character variable, which of course you can read 
>from a text file.  Or am I missing something?
>

I was asking what FORMAT to use to skip element 3. I have since devised an
inelegant solution that overwrites the 2nd element with the 3rd (note the
repeated use of t6):

write (*,"(t2,i4,t6,i4,t6,i4,t10,i4)") ivec

I still wonder if there is a better way -- my code would look like a bug
to the reader.



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
0
Reply beliavsky (2207) 12/8/2004 7:01:16 PM


beliavsky@aol.com wrote:
> helbig@astro.multiCLOTHESvax.de (Phillip Helbig---remove CLOTHES to reply)
> wrote:
> 
>>In article <1102524349.769695.131020@c13g2000cwb.googlegroups.com>,
>>beliavsky@aol.com writes: 
>>
>>
>>>Is it possible to skip the WRITE'ing of an item in an output list by
>>>modifying the FORMAT? For example, to print elements [1,2,4] of array
>>>ivec(1:4) I can just write
>>>
>>>write (*,"(100i6)") ivec((/1,2,4/))
>>>
>>>but I would like to do it as
>>>
>>>write (*,fmt_skip) ivec
>>>
>>>where fmt_skip tells the compiler to skip printing ivec(3). I want to
>>>be able to change the output of a program by changing the format
>>>string, which can be read from a text file, rather than changing the
>>>source code. It would be nice if something like

Have you tried writing the whole list to a character
variable and then using a vector substript to only actually
output the parts you want?  You'd need to EQUIVALENCE
an array and a string to use the VVS.  Or maybe write
the list to an array of character(len=3 or so) elements and
only print selected elements.

>>
>>The FORMAT can be a character variable, which of course you can read 
> 
>>from a text file.  Or am I missing something?
> 
> 
> I was asking what FORMAT to use to skip element 3. I have since devised an
> inelegant solution that overwrites the 2nd element with the 3rd (note the

???Are sure that's inelegant?  It was going to be my first
suggestion, so the odds are that it's quite elegant! ;)

> repeated use of t6):
> 
> write (*,"(t2,i4,t6,i4,t6,i4,t10,i4)") ivec
> 
> I still wonder if there is a better way -- my code would look like a bug
> to the reader.
> 
Ah yes, but most Fortran codes have bugs, so they will
be surprised when this isn't ;(

Dick Hendrickson
> 
> 
> ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
> ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

0
Reply dick.hendrickson (1286) 12/8/2004 8:33:03 PM

3 Replies
45 Views

(page loaded in 0.466 seconds)

Similiar Articles:













7/18/2012 10:23:41 AM


Reply: