Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!batcomputer!cornell!rochester!uhura.cc.rochester.edu!rbr4 From: rbr4@uhura.cc.rochester.edu (Roland Roberts) Newsgroups: comp.lang.fortran Subject: Re: Implied do loop in write (SUMMARY) Message-ID: <13617@ur-cc.UUCP> Date: 24 Apr 91 01:55:03 GMT References: <1991Apr23.201123.3908@unixg.ubc.ca> Organization: University of Rochester, Rochester NY Lines: 35 In article moshkovi@sanandreas.ecn.purdue.edu (Gennady Moshkovich) writes: [elided] >Just look at the code, and you will see where the problem is. >You can't print with this code more then _10_ elements in a row. >I can repeat again !!!. I don't know beforehand how many >elements I have, I can have 3, or I can have 300, but the >output MUST look nice. Depending on what you mean by ``nice,'' there are easier ways that using a subroutine call. The technique I have often used (both on IBM VS Fortran and DEC Fortran) is to take advantage of the format statement having an implied loop, i.e., the last grouping is repeated until there is no data. For example: do 1 i = 1,n write(6,100) (matrix(i,j),j=1,m) 1 continue 100 format(1x,10i8,:/,(11x,10i8,:/)) This results in 10 values per row, with all but the first being indented by one value to ease in spotting its beginning. Obviously, the subroutine method gives greater flexibility in what you get, but this is the simplest. On both VS Fortran and DEC Fortran, the `:' says ignore additional format specifiers if there is no additional data. I don't know how widespread this is. roland -- Roland Roberts, University of Rochester BITNET: roberts@uornsrl Nuclear Structure Research Lab INTERNET: rbr4@uhura.cc.rochester.edu 271 East River Road UUCP: rochester!ur-cc!rbr4 Rochester, NY 14267 AT&T: (716) 275-8962