Description Usage Arguments Details Author(s) Examples
View source: R/fortran.datamodule.R
Convert R list to a Fortran /data/
module block
1 | fortran_data_module(dat, types, modname, fname = paste0(modname, ".f90"))
|
dat |
Named list object for creating module. List names will be used to initialize FORTRAN variabiles. |
types |
Character vector of FORTAN types (e.g. real*8, integer) |
modname |
Name of the module. We suggest the format 'MOD_yourmodname'. |
fname |
Output file name. Defaults to 'yourmodname.f90' |
For models with large constants (e.g. absorption features in the PROSPECT model), it may be preferable to store these in FORTRAN90 modules. However, manually creating and formatting these files is tedious. This script allows you to automatically generate module files from R lists. It automatically interprets the object lengths as array dimensions (only vectors are supported right now – higher dimension arrays may be in the future) and splits long data into rows of 10. Currently, only numeric data are supported (i.e. no characters).
Alexey Shiklomanov
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | w <- 3.2
x <- 1:5
y <- 6:15
z <- seq(exp(1), pi, length.out=42)
l <- list(x=x, y=y, z=z) ## NOTE that names must be explicitly declared
l.types <- c('real','integer', 'real*4', 'real*8')
fortran_data_module(l, l.types, 'testmod')
x <- runif(10)
y <- rnorm(10)
z <- rgamma(10, 3)
d <- data.frame(x,y,z) ## NOTE that data.frames are just named lists
d.types <- rep('real*8', ncol(d))
fortran_data_module(d, d.types, 'random')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.