Skip to content
Prev 85940 / 398506 Next

Reading in FORTRAN data using R

Tyler,

One relatively easy way to get structured model data into R is to use 
output routines I have written with my colleagues.  They are called 
For2R and are available at

http://shrimp.ccfhrb.noaa.gov/~mprager/Rinter.html

To go that route, you would replace (or supplement) your Fortran write 
statements with a series of calls to our output routines. When you read 
the data from the resulting file, you won't need to specify variable 
names, lengths, or anything else, as they will all be stored in the 
output file.  A single R statement will read everything into an R "list" 
object. 

The alternative would be using the the R scan() function to read your 
variables into R.  In that case, you would need to specify the length of 
each and give it a name, similar to how you read your data into another 
Fortran program.

By the way, watch out for the term "unformatted" in a Fortran context.  
"Unformatted" in Fortran is a specific term that means something close 
to what "binary" data I/O means to a C programmer.  Your I/O is 
"list-directed," but perhaps you know that already.

Regards,
...Mike Prager




on 2/7/2006 3:30 PM Tyler Hayes said the following: