Skip to contents

This function creates a data frame suitable for defining forcing functions in a rodeo model. It specifies the names of the forcing functions, the corresponding column names in the input data file, and other metadata.

Usage

generate_forcings(datafile, columns)

Arguments

datafile

The name of the data file that contains the forcing data.

columns

A character vector specifying the names of the columns in the datafile that correspond to the forcing functions. These names will also be used as the function names.

Value

A data frame with columns name, column, file, mode, and default, structured for rodeo::forcingFunctions.

Examples

# Assuming `rodeo::forcingFunctions` is available and correctly setup
# Example: Create a dummy data file
cat("stagnation\tVE\n",
    "1\t10\n",
    "2\t20\n",
    file = "input_data.tsv")

# Generate forcing function specifications
forcings_spec <- generate_forcings(
  datafile = "input_data.tsv",
  columns = c("stagnation", "VE")
)
print(forcings_spec)
#> [1] "! GENERATED CODE -- YOU PROBABLY DO NOT WANT TO EDIT THIS\n\ninclude '/home/runner/work/_temp/Library/rodeo/fortran/forcingsGenericMethods.f95'\nmodule forcings\nuse forcings_generic\nimplicit none\nprivate TSeries, readTS, interpol\ncontains\n\n  function stagnation (time) result (res)\n  double precision, intent(in):: time\n  character(len=256), parameter:: file='input_data.tsv'\n  character(len=256), parameter:: col='stagnation'\n  integer, parameter:: lweight= -1\n  logical, save:: firstCall= .TRUE.\n  integer, save:: latest= 1\n  type(TSeries), save:: x\n  double precision, parameter:: NA= huge(0d0)\n  character(len=512):: errmsg\n  double precision:: res\n  include '/home/runner/work/_temp/Library/rodeo/fortran/forcingsInclude.f95'\nend function\n  function VE (time) result (res)\n  double precision, intent(in):: time\n  character(len=256), parameter:: file='input_data.tsv'\n  character(len=256), parameter:: col='VE'\n  integer, parameter:: lweight= -1\n  logical, save:: firstCall= .TRUE.\n  integer, save:: latest= 1\n  type(TSeries), save:: x\n  double precision, parameter:: NA= huge(0d0)\n  character(len=512):: errmsg\n  double precision:: res\n  include '/home/runner/work/_temp/Library/rodeo/fortran/forcingsInclude.f95'\nend function\nend module"
# Note: The actual `forcingFunctions` call within the function
# will generate Fortran/C code based on this data frame.
# For this example, we just show the data frame output.

# Clean up dummy file
unlink("input_data.tsv")