Re: assumed-size array arguments vs generic interfaces
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
Re: assumed-size array arguments vs generic interfaces         


Author: glen herrmannsfeldt
Date: Jul 12, 2006 00:34

Richard E Maine wrote:

(snip)
> Note that it has nothing in particular to do with assumed size. The same
> thing happens with explicit shape dummy arguments. It is just that when
> code is doing such rank-mismatch tricks, it often uses assumed size
> dummy arguments, so people tend to make that mistaken connection. The
> isssue doesn't come up the same way for assumed shape, because there
> rank matching is required even for specific procedures, so it doesn't
> show up as a difference between specifics and generics.

Can you have the same specific entry more than once, declared
with different ranks, something like:

INTERFACE SWITCH
SUBROUTINE SWITCHX (X)
INTEGER, INTENT (INOUT) :: X(*)
END SUBROUTINE SWITCHX

SUBROUTINE SWITCHX (X)
INTEGER, INTENT (INOUT) :: X(1,*)
END SUBROUTINE SWITCHX
Show full article (1.13Kb)
16 Comments
Re: writing output listing onto screen (or not) and onto file         


Author: Tim Prince
Date: Jul 17, 2006 05:37

Bernard Bru wrote:
> Is it possible to simplify my code by putting only one
> WRITE statement when I want to write output results onto screen
> (or not) and onto a file :
>
Are you asking about facilities provided by most systems for redirecting
output sent to '*' (or, on many systems, unit 6 without an OPEN)?
For example, the tee program, or redirection using '>' on the command line?
3 Comments
Re: writing output listing onto screen (or not) and onto file         


Author: bru
Date: Jul 17, 2006 05:57

Tim Prince wrote:
> Bernard Bru wrote:
>
>> Is it possible to simplify my code by putting only one
>> WRITE statement when I want to write output results onto screen
>> (or not) and onto a file :
>>
> Are you asking about facilities provided by most systems for redirecting
> output sent to '*' (or, on many systems, unit 6 without an OPEN)?
> For example, the tee program, or redirection using '>' on the command line?

Sorry, perhaps I'm not so clear:

Some time I want to have at the same time output on screen (Unit 6 or *)
and onto a file (OPEN(8,FILE= 'sosout')
An an other time I want only output on file (here unit 8) (for me it is
easier to visualize the output using vim editor) So I put in this case
OPEN(6,FILE= 'NO') because I dont need it

It seems to me heavy to put in the code 2 WRITE's for each output!!!

WRITE(6,....................
WRITE(8, the same as above
Show full article (0.91Kb)
no comments
Re: writing output listing onto screen (or not) and onto file         


Author: jwm
Date: Jul 17, 2006 07:09

bru wrote:
> Some time I want to have at the same time output on screen (Unit 6 or *)
> and onto a file (OPEN(8,FILE= 'sosout')
> An an other time I want only output on file (here unit 8) (for me it is
> easier to visualize the output using vim editor) So I put in this case
> OPEN(6,FILE= 'NO') because I dont need it

What about this:

integer, parameter :: USR_UNIT(2) = [6, 8]
integer i
logical StdOutput, FileOutput
real a, b, c

a = 1.; b = 2.; c = 3.

write(*, '("Std output? [T/F]: ")', ADVANCE = 'NO')
read(*, *) StdOutput

write(*, '("File? [T/F]: ")', ADVANCE = 'NO')
read(*, *) FileOutput

if (FileOutput) Open(unit = USR_UNIT(2), file = 'userfile.txt')
Show full article (0.88Kb)
4 Comments
Re: writing output listing onto screen (or not) and onto file         


Author: bru
Date: Jul 17, 2006 08:15

jwm wrote:
> bru wrote:
>
>>Some time I want to have at the same time output on screen (Unit 6 or *)
>>and onto a file (OPEN(8,FILE= 'sosout')
>
>
>>An an other time I want only output on file (here unit 8) (for me it is
>>easier to visualize the output using vim editor) So I put in this case
>>OPEN(6,FILE= 'NO') because I dont need it
>
>
> What about this:
>
> integer, parameter :: USR_UNIT(2) = [6, 8]
> integer i
> logical StdOutput, FileOutput
> real a, b, c
>
> a = 1.; b = 2.; c = 3. ...
Show full article (1.97Kb)
2 Comments
Re: writing output listing onto screen (or not) and onto file         


Author: jwm
Date: Jul 17, 2006 08:24

bru wrote:
>
> I tried to compile your code: it works with g95, ifort and pgf90 but not
> with f90 of Sun; error messages are:
>
>
> integer, parameter :: USR_UNIT(2) = [6, 8]
> ^
> "io.f90", Line = 2, Column = 40: ERROR: Unexpected syntax: "operand" was
> expected but found "[".
> ^
> "io.f90", Line = 2, Column = 44: ERROR: Unexpected syntax: "object-name"
> was expected but found "8".

Yes, It's a f2003 feature, sorry about that. Try using:

integer, parameter :: USR_UNIT(2) = (/ 6, 8 /)
no comments
Re: writing output listing onto screen (or not) and onto file         


Author: bru
Date: Jul 17, 2006 08:26

Tim Prince wrote:
> Bernard Bru wrote:
>
>> Is it possible to simplify my code by putting only one
>> WRITE statement when I want to write output results onto screen
>> (or not) and onto a file :
>>
> Are you asking about facilities provided by most systems for redirecting
> output sent to '*' (or, on many systems, unit 6 without an OPEN)?
> For example, the tee program, or redirection using '>' on the command line?

Your solution is good for me in the case I want to have results only on
a file.

In the other case I want to have results at the same time on the screen
and on a file!!

Thanks for your ansver

Bernard Bru
1 Comment
Re: writing output listing onto screen (or not) and onto file         


Date: Jul 17, 2006 08:36

On Mon, 17 Jul 2006 08:15:09 -0700, bru wrote
(in article ):
> Some time I want to have at the same time output on screen (Unit 6 or *)
> and onto a file (OPEN(8,FILE= 'sosout')
...
>> integer, parameter :: USR_UNIT(2) = [6, 8]
> ^
> "io.f90", Line = 2, Column = 40: ERROR: Unexpected syntax: "operand" was
> expected but found "[".

That's just because of the use of the [] for array constructors. That
is an f2003 feature adopted as an extension by some f95 compilers, but
you can't portably count on it in f95. But that is peripheral to the
question.
> Your solution seems to me to heavy because I have hundred of writes in
> my code!!

Yes. I'd agree that this is a bit much for most applications. It
requires too much structuring of the code around this particular I/O
requirement.
Show full article (2.03Kb)
no comments
Re: writing output listing onto screen (or not) and onto file         


Author: bru
Date: Jul 17, 2006 08:45

jwm wrote:
> bru wrote:
>
>>Some time I want to have at the same time output on screen (Unit 6 or *)
>>and onto a file (OPEN(8,FILE= 'sosout')
>
>
>>An an other time I want only output on file (here unit 8) (for me it is
>>easier to visualize the output using vim editor) So I put in this case
>>OPEN(6,FILE= 'NO') because I dont need it
>
>
> What about this:
>
> integer, parameter :: USR_UNIT(2) = [6, 8]
> integer i
> logical StdOutput, FileOutput
> real a, b, c
>
> a = 1.; b = 2.; c = 3. ...
Show full article (1.45Kb)
no comments
Re: writing output listing onto screen (or not) and onto file         


Author: Ken Fairfield
Date: Jul 17, 2006 13:57

On 7/17/2006 8:15 AM, bru wrote:
[...snip example of selecting output units...]
> Your solution seems to me to heavy because I have hundred of writes in
> my code!!

In priniciple, you could generalize jwm's example to any number of
units/files, but isolate the multiple WRITE's to a subroutine you've
written, e.g., MY_WRITE, and then replace all the WRITE's with
MY_WRITE's in your code. Unfortunately in practice, that may be
quite difficult because of needing to pass a variable number of
arguments to MY_WRITE. Only if the number of different combinations
of format, argument number and argument types is fairly small would
this be feasible (presumably be using a generic feature to overload
the finite number of different versions...).

-Ken
--
I don't speak for Intel, Intel doesn't speak for me...
Show full article (0.92Kb)
no comments
1 2