Home > Archive > Fortran > May 2005 > simple question about writting
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
simple question about writting
|
|
| beatdown 2005-05-10, 8:58 pm |
| 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.
| |
| glen herrmannsfeldt 2005-05-10, 8:58 pm |
| beatdown 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
| |
| Michael Prager 2005-05-10, 8:58 pm |
| "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.
| |
| John Harper 2005-05-10, 8:58 pm |
| In 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
| |
|
| beatdown 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.
| |
| beatdown 2005-05-11, 8:57 am |
| Thanks 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.
|
|
|
|
|