FORTRAN 90 2d arrays

  • #1
48
0
program pr2
implicit none
integer:: i,j
real, dimension(21,80) :: istat
open(7,file='sens.dat',status='old',action='read')
read(7,*)((istat(i,j),i=1,21),j=1,80)
write(*,*)istat
end

Where is the problem?Input file has 1680 values.But I get this:

1.3598419E-08 4.9547498E-19 -2.3852840E-09 1.1903219E-04 4.6582014E-07
-8.6184544E-18 -9.3819693E-08 1.3887561E-02 -8.2534843E-06 -1.7656002E-16
-3.4295390E-08 8.9485317E-02 -1.4944331E-03 -4.6679033E-15 5.9263188E-05
0.4140495 -5.5463272E-03 3.7684741E-15 1.6822672E-04 -0.2041877

I want to get 21 times 80 table.
 

Answers and Replies

  • #2
I have made some changes but no use of it.
program pr2

implicit none
integer:: i,j
real, dimension(21,80) :: istat
open(7,file='sens.dat',status='old',action='read')
do i=1,21
read(7,*)(istat(i,j),j=1,80)
write(*,*)istat
end do
end
 
  • #3
I would do the writes just like you did the reads, in implied do loops. That might make the difference.
Code:
read(7,*) (istat(i,j), i=1,21, j=1,80)
write(*,*) (istat (istat(i,j), i=1,21, j=1,80)

As an alternative, here's a variant of your second technique.
Code:
do i=1,21
  read(7,*) (istat(i,j), j=1,80)
  write(*,*) (istat(i,j), j=1,80)
end do
 
  • #4
No,I have tried but still I get output in 5 columns.My professor told me the same as you but he is working on windows and I am on Linux.
 
  • #5
Windows vs. Linux wouldn't make any difference, I don't believe. Are the values you're getting the right ones?

If you want to control the format of the output, you need to use a formatted WRITE statement. Your textbook should have some examples of how to do this. If not, here is a link showing how it can be done - http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html.
 
  • #6
Thanks.But I still have problems with reading files,even with format.
program pr

c creat 2d array appres and phase
implicit none
integer::a,b
real,dimension(20,4)::model,data
do a=1,20
open(20,file='apandph.dat',status='unknown')
read(20,175)(model(a,b),b=1,4)
175 format(f10.6,2x,f11.8,2x,f10.6,2x,f11.8)
end do
end
3.645672 -0.47391191 3.634044 -0.53884584
3.645537 -0.47391942 3.643924 -0.53889292
3.632416 -0.47286296 3.723857 -0.58097768
9.571163 -0.33350858 6.509775 -0.65866327
127.110130 -0.97106200 205.496704 -0.77715313
107.565323 -0.98180515 191.546555 -0.99031007
54.473228 -0.72339439 53.588963 -1.01995885
35.943069 -0.46582329 8.643129 -0.84699863
85.260635 -0.80550200 590.542480 -0.60874861
79.657425 -0.80408365 80.931747 -0.69449586
56.826580 -0.70932525 9.529596 -0.87045997
53.008141 -0.81282926 10.899014 -1.45818961
11.361421 -0.39589506 3.772177 -1.23566055
72.485718 -1.03836429 204.431763 -1.09789932
100.328796 -1.20606327 154.542145 -1.13996935
32.644672 -1.13054383 37.369968 -1.19683146
43.448734 -1.23686874 55.834637 -1.16218436
108.154144 -0.69512361 103.532623 -0.66260660
108.352539 -0.64010102 110.725822 -0.63119751
108.218521 -0.63990360 110.622787 -0.63112277
 
  • #7
What problem are you having? How did you get the output you showed? There is no write statement.
 

Suggested for: FORTRAN 90 2d arrays

Replies
4
Views
688
Replies
4
Views
823
Replies
2
Views
501
2
Replies
60
Views
601
Replies
1
Views
704
Replies
12
Views
1K
Replies
9
Views
405
Replies
12
Views
635
Replies
3
Views
25
Back
Top