Fortran 95 Reading in Multi-Dimensional Arrays

  • Fortran
  • Thread starter Sam032789
  • Start date
  • #1
11
0

Main Question or Discussion Point

Hi. I have a file like this:

Code:
1990     01       01       0000     27       16      
1990     01       01       0100     25       15      
1990     01       01       0200     24       16      
1990     01       01       0300     24       16      
1990     01       01       0400     22       15      
1990     01       01       0500     21       13      
1990     01       01       0600     20       13      
1990     01       01       0700     17       12      
1990     01       01       0800     16       12      
1990     01       01       0900     13       9       
1990     01       01       1000     12       8       
1990     01       01       1100     12       8       
1990     01       01       1200     12       8       
1990     01       01       1300     11       7       
1990     01       01       1400     9        5       
1990     01       01       1500     14       9       
1990     01       01       1600     21       16      
1990     01       01       1700     27       17      
1990     01       01       1800     30       17      
1990     01       01       1900     34       17      
1990     01       01       2000     37       17      
1990     01       01       2100     39       18      
1990     01       01       2200     38       18      
1990     01       01       2300     37       18      
1990     01       02       0000     34       19      
1990     01       02       0100     32       19      
1990     01       02       0200     33       20      
1990     01       02       0300     32       19      
1990     01       02       0400     32       19      
1990     01       02       0500     30       18      
1990     01       02       0600     25       18      
1990     01       02       0700     26       18      
1990     01       02       0800     30       20      
1990     01       02       0900     29       20      
1990     01       02       1000     30       21      
1990     01       02       1100     31       22      
1990     01       02       1200     27       20      
1990     01       02       1300     25       19      
1990     01       02       1400     27       21      
1990     01       02       1500     32       22      
1990     01       02       1600     38       24      
1990     01       02       1700     42       25      
1990     01       02       1800     45       26      
1990     01       02       1900     49       27      
1990     01       02       2000     50       28      
1990     01       02       2100     51       28      
1990     01       02       2200     51       28      
1990     01       02       2300     48       28  
2011     06       01       0054     79       45      
2011     06       01       0154     76       47      
2011     06       01       0254     65       53      
2011     06       01       0354     66       53      
2011     06       01       0454     57       52      
2011     06       01       0554     59       54      
2011     06       01       0600     59       54      
2011     06       01       0654     58       52      
2011     06       01       0754     56       52      
2011     06       01       0854     52       50      
2011     06       01       0954     52       51      
2011     06       01       1054     52       50      
2011     06       01       1154     57       51      
2011     06       01       1200     57       51      
2011     06       01       1254     62       53      
2011     06       01       1354     64       53      
2011     06       01       1454     70       54      
2011     06       01       1554     72       54      
2011     06       01       1654     74       55      
2011     06       01       1754     78       53      
2011     06       01       1800     78       53      
2011     06       01       1854     82       57      
2011     06       01       1954     85       59      
2011     06       01       2054     84       65      
2011     06       01       2154     82       64      
2011     06       01       2254     80       66     
2011     06       01       2354     76       61
Where the columns are year, month, day, hour, temperature, and dew point, respectively. I need to read each column in as an array so I can find the high, low, and average temperature and dewpoint of each day, and the times at which they occur. Please help me.
 

Answers and Replies

  • #2
11
0
Nevermind, I figured it out:

Code:
PROGRAM FileArray
implicit none

integer :: i, j, lines
integer, dimension(6,75) :: a

!a(1,*) = year
!a(2,*) = month
!a(3,*) = day
!a(4,*) = hour
!a(5,*) = temp
!a(6,*) = dew point

100 FORMAT(I4, 5X, I2, 7X, I2, 7X, I4, 5X, I2, 7X, I2)

open(55,file='testfile.txt',status='OLD')

read(55,100) ((a(i,j),i=1,6),j=1,75)

write(*,100) a

close(55)

END PROGRAM FileArray
 
  • #3
121
0
Note that the following also works. (Fortran can work out its own implied do loops.)

read(55,*) a
 
  • #4
33,723
5,419
Code:
1990     01       01       0000     27       16      
1990     01       01       0100     25       15      
1990     01       01       0200     24       16      
1990     01       01       0300     24       16      
1990     01       01       0400     22       15      
1990     01       01       0500     21       13      
1990     01       01       0600     20       13      
1990     01       01       0700     17       12      
1990     01       01       0800     16       12      
1990     01       01       0900     13       9       
1990     01       01       1000     12       8       
1990     01       01       1100     12       8       
1990     01       01       1200     12       8       
1990     01       01       1300     11       7       
1990     01       01       1400     9        5       
1990     01       01       1500     14       9       
1990     01       01       1600     21       16      
1990     01       01       1700     27       17      
1990     01       01       1800     30       17      
1990     01       01       1900     34       17      
1990     01       01       2000     37       17      
1990     01       01       2100     39       18      
1990     01       01       2200     38       18      
1990     01       01       2300     37       18      
1990     01       02       0000     34       19      
1990     01       02       0100     32       19      
1990     01       02       0200     33       20      
1990     01       02       0300     32       19      
1990     01       02       0400     32       19      
1990     01       02       0500     30       18      
1990     01       02       0600     25       18      
1990     01       02       0700     26       18      
1990     01       02       0800     30       20      
1990     01       02       0900     29       20      
1990     01       02       1000     30       21      
1990     01       02       1100     31       22      
1990     01       02       1200     27       20      
1990     01       02       1300     25       19      
1990     01       02       1400     27       21      
1990     01       02       1500     32       22      
1990     01       02       1600     38       24      
1990     01       02       1700     42       25      
1990     01       02       1800     45       26      
1990     01       02       1900     49       27      
1990     01       02       2000     50       28      
1990     01       02       2100     51       28      
1990     01       02       2200     51       28      
1990     01       02       2300     48       28  
2011     06       01       0054     79       45      
2011     06       01       0154     76       47      
2011     06       01       0254     65       53      
2011     06       01       0354     66       53      
2011     06       01       0454     57       52      
2011     06       01       0554     59       54      
2011     06       01       0600     59       54      
2011     06       01       0654     58       52      
2011     06       01       0754     56       52      
2011     06       01       0854     52       50      
2011     06       01       0954     52       51      
2011     06       01       1054     52       50      
2011     06       01       1154     57       51      
2011     06       01       1200     57       51      
2011     06       01       1254     62       53      
2011     06       01       1354     64       53      
2011     06       01       1454     70       54      
2011     06       01       1554     72       54      
2011     06       01       1654     74       55      
2011     06       01       1754     78       53      
2011     06       01       1800     78       53      
2011     06       01       1854     82       57      
2011     06       01       1954     85       59      
2011     06       01       2054     84       65      
2011     06       01       2154     82       64      
2011     06       01       2254     80       66     
2011     06       01       2354     76       61
Where the columns are year, month, day, hour, temperature, and dew point, respectively. I need to read each column in as an array so I can find the high, low, and average temperature and dewpoint of each day, and the times at which they occur.
From the code you supplied, you apparently want to read each row in the file. In an array, the rows go across, and the columns go up and down.
 
  • #5
11
0
I thought I had it, but apparently I cannot figure out how to obtain the high and low temperature values for each day. Anyone have any suggestions?
 

Related Threads on Fortran 95 Reading in Multi-Dimensional Arrays

Replies
6
Views
4K
  • Last Post
Replies
2
Views
6K
Replies
2
Views
2K
Replies
1
Views
3K
Replies
2
Views
2K
  • Last Post
Replies
2
Views
708
Replies
4
Views
10K
Replies
7
Views
4K
Top