Fortran Fortran 95 Reading in Multi-Dimensional Arrays

AI Thread Summary
The discussion revolves around reading a formatted data file containing weather information, specifically year, month, day, hour, temperature, and dew point. The initial request was to process this data into arrays to calculate daily high, low, and average temperatures and dew points, along with the times they occur. The user initially struggled with the implementation but eventually shared a Fortran program that successfully reads the data into a two-dimensional array. The program uses formatted reading to populate the array and demonstrates how to handle the data. There was also a mention of using implied do loops in Fortran for efficient data reading. However, the user expressed difficulty in extracting daily high and low temperature values, prompting a request for further assistance on that specific aspect.
Sam032789
Messages
11
Reaction score
0
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.
 
Technology news on Phys.org
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
 
Note that the following also works. (Fortran can work out its own implied do loops.)

read(55,*) a
 
Sam032789 said:
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.
 
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?
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top