djo7613@blake.acs.washington.edu (Dick O'Connor) (01/24/90)
Somewhere in my youth (or childhood!) I recall working on a (CDC?) FORTRAN compiler that allowed you to pass an integer variable in a READ or WRITE statement to the FORMAT statement to enable a variable number of repetitions of a particular descriptor. I think the equals sign was used on the FORMAT end, so that ICOUNT=4 WRITE (41,900) ICOUNT, (IARRAY(I),I=1,ICOUNT) 900 FORMAT (=(I5)) would act as if the FORMAT statement read 900 FORMAT (4(I5)) Now in this case, it's trivial, because FORMAT will do what you want anyway, without any special repetition count. In The Real World, I have a case where the FORMAT statement is complicated, writes different alpha descriptions on each line, followed by the rep count and ICOUNT many real numbers, where ICOUNT is actually an array of integer variables, not all the same. That equals sign (if I recall the character used correctly) would come in handy, but my current environment doesn't support it. I can clever my way around the problem with a bit more code, but it got me wondering...is this construct I recall a legal bit of FORTRAN in any current implementations? Is this all just a bad dream? :) "Moby" Dick O'Connor ** DISCLAIMER: It would Washington Department of Fisheries ** surprise me if the Olympia, Washington 98504 ** rest of the Department Internet Mail: djo7613@blake.u.washington.edu ** agreed with any of this!
maine@elxsi.dfrf.nasa.gov (Richard Maine) (01/25/90)
On 24 Jan 90 15:52:44 GMT, djo7613@blake.acs.washington.edu (Dick O'Connor) said: Dick> Somewhere in my youth (or childhood!) I recall working on a (CDC?) Dick> FORTRAN compiler that allowed you to pass an integer variable in a Dick> READ or WRITE statement to the FORMAT statement to enable a variable Dick> number of repetitions of a particular descriptor. I think the equals Dick> sign was used on the FORMAT end, so that Dick> ICOUNT=4 Dick> WRITE (41,900) ICOUNT, (IARRAY(I),I=1,ICOUNT) Dick> 900 FORMAT (=(I5)) Dick> would act as if the FORMAT statement read Dick> 900 FORMAT (4(I5)) Dick> Now in this case, it's trivial, because FORMAT will do what you want Dick> anyway, without any special repetition count. In The Real World, I have Dick> a case where the FORMAT statement is complicated, writes different Dick> alpha descriptions on each line, followed by the rep count and ICOUNT Dick> many real numbers, where ICOUNT is actually an array of integer variables, Dick> not all the same. That equals sign (if I recall the character used Dick> correctly) would come in handy, but my current environment doesn't Dick> support it. Dick> I can clever my way around the problem with a bit more code, but it got Dick> me wondering...is this construct I recall a legal bit of FORTRAN in any Dick> current implementations? Is this all just a bad dream? :) There are several implementations that allow things like that, but its all non-standard. Its not really too hard to do a perfectly standard replacement using a character variable for the format, with an internal write to define the character variable. For your example, we would have something like character fmt*8 write (fmt,1000) icount 1000 format('(',i2,'(i5))') write (41,fmt) (iarray(i),i=1,icount) Perhaps not quite as slick as the method you remember, but its not too bad and it does extend readily to cases as complicated as you want. In fact its quite a bit more flexible that the method you remember. ..and, of course, its standard (other than my lower case in the above example), which has a lot to say for it. -- Richard Maine maine@elxsi.dfrf.nasa.gov [130.134.64.6]
khb@chiba.kbierman@sun.com (Keith Bierman - SPD Advanced Languages) (01/25/90)
In article <5435@blake.acs.washington.edu> djo7613@blake.acs.washington.edu (Dick O'Connor) writes:
....
ICOUNT=4
WRITE (41,900) ICOUNT, (IARRAY(I),I=1,ICOUNT)
900 FORMAT (=(I5))
would act as if the FORMAT statement read
900 FORMAT (4(I5))
Consider the following
program bork
do i = 1, 10
write(*,'(<i>x,"*")')
enddo
end
Produces
*
*
*
*
*
*
*
*
*
*
Sun f77v1.3. This is along the same lines as the DEC/VMS "spelling" it
is certainly non-standard code. Here is a standard complying version:
character*12 myform
character*3 temp
do 100 i = 1, 10
write(temp,'(i2)') i
myform = '(' // temp // 'x,' // '''*''' // ')'
write(*,myform)
100 continue
end
Clever use of quotation rules can be employed so this can be done with
just two write statements (one internal, one external).
Bottom line:
Buy a VMS machine or a Sun (or anything else with this feature ...
typically spelt <n>) or write the code to be portable, and create your
format "statements" as character strings on the fly.
--
Keith H. Bierman |*My thoughts are my own. !! kbierman@sun.com
It's Not My Fault | MTS --Only my work belongs to Sun*
I Voted for Bill & | Advanced Languages/Floating Point Group
Opus | "When the going gets Weird .. the Weird turn PRO"
"There is NO defense against the attack of the KILLER MICROS!"
Eugene Brooks
chidsey@smoke.BRL.MIL (Irving Chidsey) (01/25/90)
In article <5435@blake.acs.washington.edu> djo7613@blake.acs.washington.edu (Dick O'Connor) writes:
<
<Somewhere in my youth (or childhood!) I recall working on a (CDC?)
<FORTRAN compiler that allowed you to pass an integer variable in a
<READ or WRITE statement to the FORMAT statement to enable a variable
<number of repetitions of a particular descriptor. I think the equals
<sign was used on the FORMAT end, so that
< ICOUNT=4
< WRITE (41,900) ICOUNT, (IARRAY(I),I=1,ICOUNT)
<900 FORMAT (=(I5))
<
<would act as if the FORMAT statement read
<900 FORMAT (4(I5))
<
<Now in this case, it's trivial, because FORMAT will do what you want
<anyway, without any special repetition count. In The Real World, I have
<a case where the FORMAT statement is complicated, writes different
<alpha descriptions on each line, followed by the rep count and ICOUNT
<many real numbers, where ICOUNT is actually an array of integer variables,
<not all the same. That equals sign (if I recall the character used
<correctly) would come in handy, but my current environment doesn't
<support it.
<
<I can clever my way around the problem with a bit more code, but it got
<me wondering...is this construct I recall a legal bit of FORTRAN in any
<current implementations? Is this all just a bad dream? :)
<
<"Moby" Dick O'Connor ** DISCLAIMER: It would
I have an old CDC Fortran Extended Version 4 manual, revision H,
1982, that lists = sign specification and also V specification as CDC extensions
for doing neat things with outputs. I even used the = a few times. I would
hate to have to explain it without much thought, but it did exist.
Irv
--
I do not have signature authority. I am not authorized to sign anything.
I am not authorized to commit the BRL, the DOA, the DOD, or the US Government
to anything, not even by implication.
Irving L. Chidsey <chidsey@brl.mil>