Code Comments
Programming Forum and web based access to our favorite programming groups.Hi all, I would like to know how can I write in Fortran77 to the std. out without putting a new line character at the end of the writting. Furthermore I would like to know how to write a new line character. What I want to do is to print a m x n matrix using a double loop, so I will only put new lines after the last item in each row. Thanks for your help. I am a newbie and my teacher didn't talk this in class.
Post Follow-up to this messagebeatdown wrote: > I would like to know how can I write in Fortran77 to the std. out > without putting a new line character at the end of the writting. > Furthermore I would like to know how to write a new line character. That is hard. > What I want to do is to print a m x n matrix using a double loop, so I > will only put new lines after the last item in each row. That is easy. Write each row with one WRITE statement and the appropriate format inside a DO loop. DO 1 I=1,M 1 WRITE(6,2) (A(J,I),J=1,N) 2 FORMAT(1X,100G20.10) (I am not sure between your m and n which is rows and which columns. It is preferred in Fortran to very the leftmost subscript fastest in nested loops.) In Fortran 77 each WRITE always starts a new line. The FORMAT above will print up to 100 numbers on a line, up to 2000 characters long. It is legal to write less than the FORMAT statement describes. -- glen
Post Follow-up to this message"beatdown" <ruben.santacruz@gmail.com> wrote: >Hi all, >I would like to know how can I write in Fortran77 to the std. out >without putting a new line character at the end of the writting. Check your users' manual for an extension that will allow this. It is most likely to be a format descriptor like "$" or "\" >Furthermore I would like to know how to write a new line character. write(*,*) >What I want to do is to print a m x n matrix using a double loop, so I >will only put new lines after the last item in each row. Look up "implied do list" in your manual for a better way than using a double loop. >Thanks for your help. I am a newbie and my teacher didn't talk this in >class. -- Mike Prager, NOAA, Beaufort, NC Address spam-trapped; remove color to reply. * Opinions expressed are personal and not represented otherwise. * Any use of tradenames does not constitute a NOAA endorsement.
Post Follow-up to this messageIn article <UeqdneEdDY8rnBzfRVn-tQ@comcast.com>, glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote: >beatdown wrote: > > > >That is hard. ADVANCE='NO' has been part of Fortran for about 15 years. Why stay with f77? There are two free f95 compilers available. A valid f77 program is (with very minor exceptions) a valid f95 program. John Harper, School of Mathematics, Statistics and Computer Science, Victoria University, PO Box 600, Wellington, New Zealand e-mail john.harper@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045
Post Follow-up to this messagebeatdown wrote: > > What I want to do is to print a m x n matrix using a double loop, so I > will only put new lines after the last item in each row. Try, write(*,fmt(n)) ((a(i,j), j=1,n), i=1,m) where "fmt" is a tiny char fcn which you should try and write - from then on, parts or all of your matrix print can be manipulated by simply twiddling with m & n.
Post Follow-up to this messageThanks you all. I have solved the problem using something similar to glen's solution. I use fortran77 because my teacher wants me to do this. I will ask him why not moving to f95. Bye.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.