[comp.lang.fortran] Implied write loop question

moshkovi@sanandreas.ecn.purdue.edu (Gennady Moshkovich) (04/23/91)

Hi,

I am looking for the way to print out matrix type table with
n rows and m columns.  I don't know before what n and m are.
What is the way to print it ?

Thanks.  Gene

--
Gennady Moshkovich          
Purdue University
Department of Civil Engineering
moshkovi@ecn.purdue.edu

v087mxgb@ubvmsa.cc.buffalo.edu (Shawn E Thompson) (04/23/91)

In article <moshkovi.672369609@sanandreas.ecn.purdue.edu>, moshkovi@sanandreas.ecn.purdue.edu (Gennady Moshkovich) writes...
>Hi,
hi....
> 
>I am looking for the way to print out matrix type table with
>n rows and m columns.  I don't know before what n and m are.
>What is the way to print it ?
> 
>Thanks.  Gene
sure......



ummm....now if I can remember this without references....



WRITE(*,###) ( ( X(I,J), j=1,n), I=1,m)


where, of course * is your unit number to write to
and ### is your format statement label (or lack thereof)


the extra spaces are for clarity only........



st

mac@cis.ksu.edu (Myron A. Calhoun) (04/23/91)

>In article... moshkovi@sanandreas.ecn.purdue.edu (Gennady Moshkovich) writes...
>I am looking for the way to print out matrix type table with
>n rows and m columns.  I don't know before what n and m are.
>What is the way to print it ?

If you want it to LOOK nice, do it this way:

      DO 100 row = 1, n
         WRITE (DevNum, 99) (Table(Column), Column = 1, m)
   99          FORMAT (20I6)
  100 CONTINUE

where DevNum and FORMAT need definitions appropriate to your situation.
The above example assumed that your table was full of integers and
that there were never more than 20 of them in any one row.
--Myron.
--
# Myron A. Calhoun, Ph.D. E.E.; Associate Professor   (913) 539-4448 home
#  INTERNET:  mac@cis.ksu.edu (129.130.10.2)                532-6350 work
#      UUCP:  ...rutgers!ksuvax1!harry!mac                  532-7353 fax
# AT&T Mail:  attmail!ksuvax1!mac                   W0PBV @ K0VAY.KS.USA.NA

greg@monu6.cc.monash.edu.au (Greg Coldicutt) (04/24/91)

In article <72495@eerie.acsu.Buffalo.EDU> v087mxgb@ubvmsa.cc.buffalo.edu writes:
>In article <moshkovi.672369609@sanandreas.ecn.purdue.edu>, moshkovi@sanandreas.ecn.purdue.edu (Gennady Moshkovich) writes...
>> 
>>I am looking for the way to print out matrix type table with
>>n rows and m columns.  I don't know before what n and m are.
>>What is the way to print it ?
>> 
>ummm....now if I can remember this without references....
>WRITE(*,###) ( ( X(I,J), j=1,n), I=1,m)
>where, of course * is your unit number to write to
>and ### is your format statement label (or lack thereof)
>

That will not give the correct shape (correct number of columns per line).
You need a DO loop for the rows, and an implied do for columns, plus a
flexible format which allows for a range of potential column numbers, eg

      do 200 i=1,m
         write(*,100) (x(i,j), j=1,n)
100      format(1x,8f10.4/(11x,7f10.4))
200   continue

(assuming Fortran printer control is required, with 80 column screen width.)