Problem with printing matrix

2 views
Skip to first unread message

Schokoholic

unread,
Nov 30, 2009, 5:31:16 PM11/30/09
to Fortran
hi everyone,

i'am pretty new to fortran90, but i'm using it for my thesis.

i have a question about printing matrix on a txt file.

this is what i do:

OPEN(UNIT=1, FILE='mat_data.txt', STATUS='REPLACE', ACTION='WRITE',
IOSTAT=ierror)

write(1,*) ((mat_data(j_data,i_data),i_data=1,n+1), j_data=1,10)

but i still can't get the row on the same line, what happen is that
after the third term, it prints on a new line. WHY?

what i'am doing wrong?

i'm trying to find out the problem reading different guides, and
searching on the internet, but i still can't find what i'm looking
for.

thank you all,

Terence

unread,
Dec 16, 2009, 4:42:38 PM12/16/09
to Fortran
First, I'm not happy with the use of unit=1.
For historic reasons you should avoid using units 1 through 3 and
possibly 1 through 5.
Unit 0 is the keyboard also referred to a asterisk,
Unit 1 is usually the error listing unit
Unit 2 is usually the printing unit (and so on, for punch units from
the "good old days")

For input from the keyboard , or output to the screen, you should use
"*" or "0"
You don't have to actually use the unit=number parameter as long as
the first parameter is a unit number (and the second optionally a
format statement number, otherwise use FMT=format number).


So I would have replaced your
OPEN(UNIT=1, FILE='mat_data.txt', STATUS='REPLACE', ACTION='WRITE',
IOSTAT=ierror)

with
OPEN(2, FILE='mat_data.txt',
STATUS='NEW',ACCESS='SEQUENTIAL',FORM='FORMATTED')


Before you write out your matrix, check that you have the variable
"n" set to some valid integer value within the bounds of your matrix.

CaptainKirk1966

unread,
Dec 26, 2009, 12:11:42 PM12/26/09
to Fortran

On Dec 16, 4:42 pm, Terence <tbwri...@cantv.net> wrote:
> First, I'm not happy with the use of unit=1.
> For historic reasons you should avoid using units 1 through 3 and
> possibly 1 through 5.
> Unit 0 is the keyboard also referred to a asterisk,

Bad advice. Unit 0 is in most cases the standard error device
(stderr). If you write to it, the output may show up on your screen,
Reading from it will usually cause an error.

> Unit 1 is usually the error listing unit
> Unit 2 is usually the printing unit (and so on, for punch units from
> the "good old days")
>
> For input from the keyboard , or output to  the screen, you should use
> "*" or "0"

Bad advice. Input from and output to the same unit is never a good
idea. Input from the standard error device (unit=0) fails with most
compilers.

unit=5 is the standard input, usually associated with the user's
keyboard same as unit=* for input
unit=6 is the standard output, usually associated with the user's
screen same as unit=* for output

Terence

unread,
Dec 27, 2009, 2:45:07 AM12/27/09
to Fortran

Disagree. Unit zero is almost always equivalent to "*" which is
standard for keyboard in and screen out.
If you DON'T want to write to screen than use unit 2 for a print file
(which was almost always, [again], a printer; or any other number over
6), properly named of course.

The use of 5 and 6 as you describe is mainly IBM derived. There are
others. But keeping clear of 0 through 6 is a good idea for persons
new to the history of Fortran.
I always used unit zero since 1960, but have more recently switched to
"*" for keyboard/screen and started to modify old code.

CaptainKirk1966

unread,
Dec 27, 2009, 8:45:12 AM12/27/09
to Fortran

On Dec 27, 2:45 am, Terence <tbwri...@cantv.net> wrote:

> Disagree. Unit zero is almost always equivalent to "*" which is
> standard for keyboard in and screen out.

Try reading from unit zero with something other than an old version of
MS Fortran


Reply all
Reply to author
Forward
0 new messages