file copy routine
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
file copy routine         


Author: John
Date: May 16, 2008 18:34

Hi,

I've written a small file copy routine for text files. The problem I
have is that sometimes the final of the line is copied twice and
sometimes only once. I can't quite figure out why the final line is
being copied inconsistently. Usually, it is copied twice however, which
is preferable to having the final line not copied. Can anyone spot the
problem, or is it just one of those problems I have to live with?

Any other comments on improving my subroutine are welcome also.

Thanks,
John

module copy_file
implicit none

contains

!=======================================================================
subroutine copy(oname,nname,max_line_length)
implicit none

character (len=*), intent(in) :: oname
character (len=*), intent(in) :: nname
integer, intent(in) :: max_line_length
Show full article (2.97Kb)
38 Comments
Re: file copy routine         


Author: nospam
Date: May 16, 2008 19:22

John yahoo.com> wrote:
> I've written a small file copy routine for text files. The problem I
> have is that sometimes the final of the line is copied twice and
> sometimes only once. I can't quite figure out why the final line is
> being copied inconsistently. Usually, it is copied twice however, which
> is preferable to having the final line not copied. Can anyone spot the
> problem, or is it just one of those problems I have to live with?
>
> Any other comments on improving my subroutine are welcome also.

I personally find usage of err=, end=, and eor= hard to follow because
of the way they jump around. Not just your code in particular, but those
features in general. I tend to prefer using iostat= and testing the
value. That's just my personal style preference, though.
> do while (rstat .eq. 0 .and. wstat .eq. 0)
Show full article (3.10Kb)
no comments
Re: file copy routine         


Author: Tim Prince
Date: May 16, 2008 23:21

Richard Maine wrote:
> I personally find usage of err=, end=, and eor= hard to follow because
> of the way they jump around. Not just your code in particular, but those
> features in general. I tend to prefer using iostat= and testing the
> value. That's just my personal style preference, though.

Some of us spent some effort putting automatic conversion of err= ,end=
into iostat= with IF..ELSE blocks in our Fortran reformatters, back in the
days when f77 was relatively new.
I am humbled a bit by finding that my web search skills aren't adequate to
turn up examples of this recommendation, though I did turn up plenty of
evidence in favor.
I have to wonder if people use iostat= and err= together (not only in
gfortran testsuite) in order to break automatic reformatting scripts.
no comments
Re: file copy routine         


Author: John
Date: May 17, 2008 00:20

Richard Maine wrote:
> John yahoo.com> wrote:
>
>> I've written a small file copy routine for text files. The problem I
>> have is that sometimes the final of the line is copied twice and
>> sometimes only once. I can't quite figure out why the final line is
>> being copied inconsistently. Usually, it is copied twice however, which
>> is preferable to having the final line not copied. Can anyone spot the
>> problem, or is it just one of those problems I have to live with?
>>
>> Any other comments on improving my subroutine are welcome also.
>
> I personally find usage of err=, end=, and eor= hard to follow because
> of the way they jump around. Not just your code in particular, but those
> features in general. I tend to prefer using iostat= and testing the
> value. That's just my personal style preference, though.
>
>> do while (rstat .eq. 0 .and. wstat .eq. 0)
>
> I also tend to find that particular style of DO while confusing. I know ...
Show full article (6.38Kb)
no comments
Re: file copy routine         


Author: nospam
Date: May 17, 2008 07:13

John yahoo.com> wrote:
> Richard Maine wrote:
>> I personally find usage of err=, end=, and eor= hard to follow because
>> of the way they jump around. Not just your code in particular, but those
>> features in general. I tend to prefer using iostat= and testing the
>> value. That's just my personal style preference, though.
>
> I will rewrite this and see which one I like better. I guess I was
> using the jumps so I would not have to look up the iostat codes. Are
> the iostat portable. I seem to recall that the sign was the main
> indicator and not necessarily the number (which differ from compiler to
> compiler). In that case, it doesn't like there would be enough
> information to tell between err, end, eor.

That's a good point. You can distinguish between err and the others by
the sign. But you can't easily and portably distinguish between end and
eor. (You can do it either easily or portably, but not both). I rarely
need to do that, but in contexts where you would need to, I'll grant the
point. F2003 provides an easy portable way to distinguish, but f90/f95
don't.
Show full article (1.31Kb)
no comments
Re: file copy routine         


Author: James Giles
Date: May 17, 2008 10:46

John wrote:
> Richard Maine wrote:
...
>> I personally find usage of err=, end=, and eor= hard to follow
>> because of the way they jump around. Not just your code in
>> particular, but those features in general. I tend to prefer using
>> iostat= and testing the value. That's just my personal style
>> preference, though.
>
> I will rewrite this and see which one I like better. I guess I was
> using the jumps so I would not have to look up the iostat codes. Are
> the iostat portable. I seem to recall that the sign was the main
> indicator and not necessarily the number (which differ from compiler
> to compiler). In that case, it doesn't like there would be enough
> information to tell between err, end, eor.
Show full article (4.99Kb)
no comments
Re: file copy routine         


Author: nospam
Date: May 17, 2008 11:57

James Giles worldnet.att.net> wrote:
>> Richard Maine wrote:
>>>> do while (rstat .eq. 0 .and. wstat .eq. 0)
>>>
>>> I also tend to find that particular style of DO while confusing....
> I actually don't even understand Maine's point here. I know that some
> people are more comfortable with expressing the reason to leave in
> a positive sense and would prefer an UNTIL clause.

No. My point is nothing to do with that. It is more that the loop
condition is one place, but the variables that control it are defined
elsewhere. It is that separation that makes it hard to read for me. An
UNTIL would be just as bad because it still isn't particularly near to
where the relevant variables get defined.
Show full article (4.60Kb)
no comments
Re: file copy routine         


Author: James Giles
Date: May 17, 2008 12:16

Richard Maine wrote:
> James Giles worldnet.att.net> wrote:
...
>> The problem with EXIT is twofold. First: all the control statements
>> that are part of a given control construct are best kept at the same
>> nexting level as the construct they are part of.
>
> That's exactly what I disagree with. I like the fact that with EXIT
> the loop control can be exactly where the relevant data becomes
> available. I don't want it separated and put with the statements at
> the beginning or end of the loop. When I decide that it is time to
> exit the loop, I can simply say so right there. Without EXIT, I end
> up instead setting some variable, which is tested elsewhere. I just
> find
>
> if (some_condition) EXIT do_loop
>
> to be incredibly easier to read and follow than, say
>
> if (some_condition) need_to_exit = .true. ...
Show full article (1.97Kb)
no comments
Re: file copy routine         


Author: James Giles
Date: May 17, 2008 12:24

Richard Maine wrote:
> James Giles worldnet.att.net> wrote:
>
>>> Richard Maine wrote:
>
>>>>> do while (rstat .eq. 0 .and. wstat .eq. 0)
>>>>
>>>> I also tend to find that particular style of DO while confusing....
>
>> I actually don't even understand Maine's point here. I know that
>> some people are more comfortable with expressing the reason to leave
>> in
>> a positive sense and would prefer an UNTIL clause.
>
> No. My point is nothing to do with that. It is more that the loop
> condition is one place, but the variables that control it are defined
> elsewhere. [...]
Show full article (1.44Kb)
no comments
Re: file copy routine         


Author: glen herrmannsfeldt
Date: May 17, 2008 12:53

Richard Maine wrote:
(snip)
> No. My point is nothing to do with that. It is more that the loop
> condition is one place, but the variables that control it are defined
> elsewhere. It is that separation that makes it hard to read for me. An
> UNTIL would be just as bad because it still isn't particularly near to
> where the relevant variables get defined.

I believe there is at least one language with a WHILE loop testing
at the beginning, and an UNTIL loop testing at the end. It might
be that in some cases a test at the end would reduce the separation.

-- glen
no comments
1 2 3 4