Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #88429
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: best way to convert a Fortran implied do loop to C++ |
| Date | 2023-01-07 22:41 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <871qo6hsrf.fsf@bsb.me.uk> (permalink) |
| References | <tpau9h$3e4fi$1@dont-email.me> <87k01yijwp.fsf@bsb.me.uk> <6NguL.537322$GNG9.514912@fx18.iad> <87eds6hv8c.fsf@bsb.me.uk> |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Richard Damon <Richard@Damon-Family.org> writes:
>
>> On 1/7/23 7:55 AM, Ben Bacarisse wrote:
>>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>>>
>>>> So what is the best way to convert a Fortran implied do loop to C++ ?
>>>>
>>>> WRITE (2,2) (N (I), I = 1, 80)
>>>> 2 FORMAT(' ',80A1)
>>> Presumably the bounds are not always literals, and you probably also
>>> want to general solution the works for multiple implied loops, some of
>>> which might be nested? So not much!
>>> My first question would be how you translate WRITE/FORMAT combinations
>>> with no loops as that's going to form the basis of a solution.
>>> (I presume you know Fortran well enough to know that this is not the
>>> same as putting a loop round the
>>
>> Althogh in C++ you COULD put the loop around the write equivalent
>> since C++ doesn't automatically take the first character as carriage
>> control and add the new line to the end (if you use the right
>> functions).
>
> I would expect that with a clean translation the carriage control
> handling (if wanted) would just come out in the wash. Even in modern
> Fortran (where the "carriage control" malarkey is obsolete) you can't
> just turn an implied loop into an explicit one. Presumably the
> translating software already has some mechanism to iterate through the
> format and that's what has to be driven by the implied loop.
>
> If, as I suppose is possible, the first character is still to be treated
> specially, that should just work out correctly as the code iterates
> through the format.
To add a bit more detail, I image that formats will be turned into
run-time objects containing a 'compiled' version of the format
mini-language. A statement like
WRITE(*, 2) A, X
2 FORMAT(I2, F5.2)
would turn into
format_2.start();
format_2.write(UNIT_STAR, A);
format_2.write(UNIT_STAR, X);
format_2.end();
where the write method is a templated method that advances an internal
pointer in the format "list" (it may, in fact, be a cyclic graph). And
WRITE(*,2) (N(I), X(I), I = 1, 6)
would turn into
format_2.start();
for (int i = 1; i <= 6; i++) {
format_2.write(STAR, N[i]);
format_2.write(STAR, X[i]);
}
format_2.end();
The member function 'end' should be idempotent, because the write
function will also call it when the last format specification is used.
I'm sure this is turn out to be way more complicated that it looks to me
right now, but this feel like the gist of what's needed.
--
Ben.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
best way to convert a Fortran implied do loop to C++ Lynn McGuire <lynnmcguire5@gmail.com> - 2023-01-06 23:00 -0600
Re: best way to convert a Fortran implied do loop to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-01-07 12:55 +0000
Re: best way to convert a Fortran implied do loop to C++ Richard Damon <Richard@Damon-Family.org> - 2023-01-07 11:07 -0500
Re: best way to convert a Fortran implied do loop to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-01-07 21:48 +0000
Re: best way to convert a Fortran implied do loop to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-01-07 22:41 +0000
Re: best way to convert a Fortran implied do loop to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-01-07 22:46 +0000
Re: best way to convert a Fortran implied do loop to C++ Lynn McGuire <lynnmcguire5@gmail.com> - 2023-01-07 21:29 -0600
Re: best way to convert a Fortran implied do loop to C++ Lynn McGuire <lynnmcguire5@gmail.com> - 2023-01-11 14:16 -0600
csiph-web