Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!ames!skipper!elxsi!maine From: maine@elxsi.dfrf.nasa.gov (Richard Maine) Newsgroups: comp.lang.fortran Subject: Re: Variable repetition count in FORMAT Message-ID: Date: 24 Jan 90 19:17:09 GMT References: <5435@blake.acs.washington.edu> Sender: news@skipper.dfrf.nasa.gov Distribution: na Organization: NASA Dryden, Edwards, Cal. Lines: 48 In-reply-to: djo7613@blake.acs.washington.edu's message of 24 Jan 90 15:52:44 GMT 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]