Fortran 95 Reading in Multi-Dimensional Arrays

Click For Summary

Discussion Overview

The discussion revolves around reading multi-dimensional arrays from a text file in Fortran 95. Participants explore methods to extract data from a formatted file containing weather-related information, specifically focusing on temperature and dew point readings over time.

Discussion Character

  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant presents a structured file format containing year, month, day, hour, temperature, and dew point, and seeks assistance in reading this data into arrays for further analysis.
  • Another participant shares a Fortran program that successfully reads the data into a two-dimensional array, demonstrating the use of formatted input to parse the file.
  • A third participant notes that Fortran can handle implied do loops, suggesting an alternative method to read the data without explicit formatting.

Areas of Agreement / Disagreement

There is no explicit consensus on the best method to read the data, as multiple approaches are discussed, and participants present different techniques without resolving which is superior.

Contextual Notes

The discussion does not clarify the limitations of the proposed methods, such as potential issues with data size or format variations that may affect the reading process.

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?
 

Similar threads

  • · Replies 58 ·
2
Replies
58
Views
5K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
Replies
0
Views
2K
Replies
31
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 20 ·
Replies
20
Views
6K