First functional mtclim import
This commit is contained in:
parent
1512832ce3
commit
9aab86d79d
@ -8,6 +8,7 @@ export(copyMusoExampleTo)
|
||||
export(corrigMuso)
|
||||
export(getyearlycum)
|
||||
export(getyearlymax)
|
||||
export(mtclim)
|
||||
export(musoDate)
|
||||
export(musoMapping)
|
||||
export(musoMappingFind)
|
||||
|
||||
@ -1,6 +1,18 @@
|
||||
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
|
||||
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
|
||||
|
||||
#' mtclim
|
||||
#'
|
||||
#' This is the core mtclim function
|
||||
#' @importFrom Rcpp evalCpp
|
||||
#' @useDynLib RBBGCMuso
|
||||
#' @param iniFile is the name of the inifile
|
||||
#' @keywords internal
|
||||
#' @export
|
||||
mtclim <- function(iniFile) {
|
||||
invisible(.Call('_RBBGCMuso_mtclim', PACKAGE = 'RBBGCMuso', iniFile))
|
||||
}
|
||||
|
||||
getWritePositions <- function(a) {
|
||||
.Call('_RBBGCMuso_getWritePositions', PACKAGE = 'RBBGCMuso', a)
|
||||
}
|
||||
|
||||
@ -7,10 +7,10 @@
|
||||
copyMusoExampleTo(example = NULL, destination = NULL)
|
||||
}
|
||||
\arguments{
|
||||
\item{example}{The name of the example file, if it is NULL tcl/tk menu will pop up to select.}
|
||||
\item{example}{This is the name of the example file. If it is not set then a simple graphical user interface (tcl/tk menu) will open to select the target dataset (which is typically an experimental site). In the list hhs means the Hegyhatsal eddy covariance site in Hungary.}
|
||||
|
||||
\item{destination}{The destination where the example files will be copied.}
|
||||
}
|
||||
\description{
|
||||
With this function you can copy RBBGCMuso example library whereever you want
|
||||
This function enables the user to download a complete, working file set to quickly start using Biome-BGCMuSo through RBBGCMuso (or in standalone mode). The user has to specify the target directory for the files. The file set contains the model executable (muso.exe in Windows), the INI files that drive the model, and other files like meteorology input, ecophysiological constants file (EPC), and other ancillary files (CO2 concentration, parameter range definition file called parameters.csv). Note that we strongly recommend to read the User's Guide of Biome-BGCMuSo to clarify the meaning of the input files. The input files (s.ini, n.ini, maize.epc, meteorology files) are simple text files, so the user can read (and modify) them with his/her favourite text editor (like Editpad Lite, vim, emacs). Note that some files use UNIX/Linux style text which means that the text will not be readable using the Windows Notepad.
|
||||
}
|
||||
|
||||
15
RBBGCMuso/man/mtclim.Rd
Normal file
15
RBBGCMuso/man/mtclim.Rd
Normal file
@ -0,0 +1,15 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/RcppExports.R
|
||||
\name{mtclim}
|
||||
\alias{mtclim}
|
||||
\title{mtclim}
|
||||
\usage{
|
||||
mtclim(iniFile)
|
||||
}
|
||||
\arguments{
|
||||
\item{iniFile}{is the name of the inifile}
|
||||
}
|
||||
\description{
|
||||
This is the core mtclim function
|
||||
}
|
||||
\keyword{internal}
|
||||
@ -14,51 +14,51 @@ fertInput=NULL, irrInput=NULL,
|
||||
nitInput=NULL, iniInput=NULL, epcInput=NULL)
|
||||
}
|
||||
\arguments{
|
||||
\item{executable}{This parameter stores the location (directory) of the modell-executable file. In normal usage, you don't have to set this parameter, because a RBBGCMuso package contains allways the latest modell executable. In spite of this, if you would like to use this package for modell development or just want to use different models (for example for comparison), you will find it useful}
|
||||
\item{executable}{This parameter stores the location (directory) of the model-executable file. In normal usage, you don't have to set this parameter, because the RBBGCMuso package always contains the latest model executable. In spite of this, if you would like to use this package for model development or just want to use different model version (for example for comparison), you will find this option useful}
|
||||
|
||||
\item{parallel}{Set this variable to TRUE if you would like to implement parallel execution of the model}
|
||||
|
||||
\item{calibrationPar}{You may want to change some parameters in your epc file, before you run the modell. You have to select the appropirate modell parameters. You can refence to these with the number of the line in the epc file where the variables are. It indexes from one. You should use a vector for this, like: c(1,5,8)}
|
||||
\item{calibrationPar}{You might want to change some parameters in your EPC file before running the model. setupMuso offers possibility for this without editing the EPC file. In this situation you have to select the appropirate model parameters first. You can refer to these parameters with the number of the line in the EPC file. Indexing of lines start from one. You should use a vector for this referencing like c(1,5,8)}
|
||||
|
||||
\item{outputLoc}{Where should the modell puts its outputs. You should give a location for it via this variable, for example: outputLoc="/place/of/the/outputs/"}
|
||||
\item{outputLoc}{With this parameter the user can specify the directory for the model output. The syntax is simple, for example: outputLoc="/place/of/the/outputs/" or outputLoc="C:/my_model_directory/". Note that this output directory is specified by the user within the INI file, which means that the outputLoc parameter overrides the INI settings if specified.}
|
||||
|
||||
\item{modelOutputs}{This parameter is the list of the codes of outpu}
|
||||
\item{modelOutputs}{This parameter contains the list of the codes that defines the required model output variables. Check the Biome-BGCMuS website for the complete list of possible output variables at http://agromo.agrar.mta.hu/bbgc/download.html}
|
||||
|
||||
\item{inputLoc}{Usually it is the root directory, where you put the iniFiles for the modell}
|
||||
\item{inputLoc}{Usually this is the root (or base) directory where the user stores the INI files for the model. If the working directory is set by the user, this parameter can be skipped.}
|
||||
|
||||
\item{metInput}{Via metInput parameter, you can tell the modell where are the meteorological files. As default it reads this from the iniFiles.}
|
||||
\item{metInput}{Via the metInput parameter the user can specify the location of the input meteorological files. By default the package reads this information from the INI files.}
|
||||
|
||||
\item{CO2Input}{Via CO2 parameter, you can tell the modell where are the CO2 data files. As default it reads this from the iniFiles.}
|
||||
\item{CO2Input}{Via the CO2Input parameter the user can specify the location of the CO2 data file. By default the package reads this information from the INI files.}
|
||||
|
||||
\item{plantInput}{Via planting parameter, you can tell the modell where are the data files, which contains the planting informations. As default it reads this from the iniFiles.}
|
||||
\item{plantInput}{Via the plantInput parameter, the user can specify the location of the the file that contains the planting information. By default the package reads this information from the INI files.}
|
||||
|
||||
\item{thinInput}{Via thining parameter, you can tell the modell where are the data files, which contains the thining informations. As default it reads this from the iniFiles.}
|
||||
\item{thinInput}{Via the thinInput parameter,the user can specify the location of the file that contains the thinning information. By default the package reads this information from the INI files.}
|
||||
|
||||
\item{mowInput}{Via mowing parameter, you can tell the modell where are the data files, which contains the mowing informations. As default it reads this from the iniFiles.}
|
||||
\item{mowInput}{Via the mowInput parameter, the user can specify the location of the file that contains the mowing (i.e. grass cutting) information. By default the package reads this information from the INI files.}
|
||||
|
||||
\item{grazInput}{Via grazing parameter, you can tell the modell where are the data files, which contains the grazing informations. As default it reads this from the iniFiles.}
|
||||
\item{grazInput}{Via the grazInput parameter, the user can specify the location of the file that contains the grazing information. By default the package reads this information from the INI files.}
|
||||
|
||||
\item{harvInput}{Via harvesting parameter, you can tell the modell where are the data files, which contains the harvesting informations. As default it reads this from the iniFiles.}
|
||||
\item{harvInput}{Via the harvInput parameter, the user can specify the location of the file that contains the harvesting information. By default the package reads this information from the INI files.}
|
||||
|
||||
\item{plougInput}{Via ploughing parameter, you can tell the modell where are the data files, which contains the ploughing informations. As default it reads this from the iniFiles.}
|
||||
\item{plougInput}{Via the plougInput parameter, the user can specify the location of the file that contains the ploughing information. By default the package reads this information from the INI files.}
|
||||
|
||||
\item{fertInput}{Via fertilizing parameter, you can tell the modell where are the fertilizing data files, which contains the fertilizing informations. As default it reads this from the iniFiles.}
|
||||
\item{fertInput}{Via the fertInput parameter, ythe user can specify the location of the file that contains the fertilizing information. By default the package reads this information from the INI files.}
|
||||
|
||||
\item{irrInput}{Via irrigation parameter, you can tell the modell where are the data files, which contains the irrigation informations. As default it reads this from the iniFiles.}
|
||||
\item{irrInput}{Via the irrInput parameter, the user can specify the location of the file that contains the irrigation information. By default the package reads this information from the INI files.}
|
||||
|
||||
\item{nitInput}{Via this parameter, you can tell the modell where are the NO2 data files. As default it reads this from the iniFiles.}
|
||||
\item{nitInput}{Via the nitInput parameter, the user can specify the location of the file that contains the nitrogen deposition data. By default the package reads this information from the INI files.}
|
||||
|
||||
\item{iniInput}{Via this parameter, you can tell the modell where are the ini files. As default it reads this from the iniFiles.}
|
||||
\item{iniInput}{Via the iniInput parameter, the user can specify the location of the INI files. By default the package reads the INI files from the working directory.}
|
||||
|
||||
\item{epcInput}{Via this parameter, you can tell the modell where are the epc data files. As default it reads this from the iniFiles.}
|
||||
\item{epcInput}{Via the epcInput parameter, the user can specify the location of the EPC data file. By default the package reads this information from the INI files.}
|
||||
}
|
||||
\value{
|
||||
The output is a the modell setting list wich contains the following elements:
|
||||
The output is a the model settings list wich contains the following elements:
|
||||
executable, calibrationPar, outputLoc, outputName, inputLoc, iniInput, metInput, epcInput,thinInput,CO2Input, mowInput, grazInput, harvInput, plougInput, fertInput,rrInput, nitInput, inputFiles, numData, startyear, numYears, outputVars
|
||||
}
|
||||
\description{
|
||||
This funcion is fundamental for the Biome-BGCMuSo model related functions like runMuso, spinupMuso, normalMuso, rungetMuso, as it sets the model's environment. The function reads the INI files from a given directory, analyzes them with error checking, and creates a data structure in R that contains the complete information content for the simulation.
|
||||
The setupMuso is fundamental for the Biome-BGCMuSo model related other functions like runMuso, spinupMuso, normalMuso, rungetMuso, as it sets the model's environment. The function reads the INI files from a given directory, analyzes them with error checking, and creates a data structure in R that contains the complete information content for the simulation.
|
||||
}
|
||||
\author{
|
||||
Roland Hollos
|
||||
Roland HOLLOS
|
||||
}
|
||||
|
||||
@ -5,6 +5,16 @@
|
||||
|
||||
using namespace Rcpp;
|
||||
|
||||
// mtclim
|
||||
void mtclim(std::string iniFile);
|
||||
RcppExport SEXP _RBBGCMuso_mtclim(SEXP iniFileSEXP) {
|
||||
BEGIN_RCPP
|
||||
Rcpp::RNGScope rcpp_rngScope_gen;
|
||||
Rcpp::traits::input_parameter< std::string >::type iniFile(iniFileSEXP);
|
||||
mtclim(iniFile);
|
||||
return R_NilValue;
|
||||
END_RCPP
|
||||
}
|
||||
// getWritePositions
|
||||
IntegerVector getWritePositions(double a);
|
||||
RcppExport SEXP _RBBGCMuso_getWritePositions(SEXP aSEXP) {
|
||||
@ -64,6 +74,7 @@ END_RCPP
|
||||
}
|
||||
|
||||
static const R_CallMethodDef CallEntries[] = {
|
||||
{"_RBBGCMuso_mtclim", (DL_FUNC) &_RBBGCMuso_mtclim, 1},
|
||||
{"_RBBGCMuso_getWritePositions", (DL_FUNC) &_RBBGCMuso_getWritePositions, 1},
|
||||
{"_RBBGCMuso_changeMusoC", (DL_FUNC) &_RBBGCMuso_changeMusoC, 3},
|
||||
{"_RBBGCMuso_randTypeOne", (DL_FUNC) &_RBBGCMuso_randTypeOne, 1},
|
||||
|
||||
156
RBBGCMuso/src/ini.h
Normal file
156
RBBGCMuso/src/ini.h
Normal file
@ -0,0 +1,156 @@
|
||||
/*
|
||||
ini.h
|
||||
Peter Thornton, NTSG
|
||||
8/6/93
|
||||
|
||||
Header file for functions that read *.ini files and either
|
||||
store values in variables or open files for input or output
|
||||
General *.ini file format:
|
||||
value/string (whitespace) comment, not required (\n)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* structure definition for filename handling */
|
||||
typedef struct {
|
||||
char name[128];
|
||||
FILE *ptr;
|
||||
} file;
|
||||
|
||||
/* function prototypes */
|
||||
int file_open (file *target, char mode);
|
||||
int scan_value (file ini, void *var, char mode);
|
||||
int scan_open (file ini,file *target,char mode);
|
||||
|
||||
|
||||
/* file_open is the generic file opening routine using the file structure
|
||||
defined above */
|
||||
int file_open (file *target, char mode)
|
||||
/* Possible values for mode
|
||||
'r' for read binary
|
||||
'i' for read ascii
|
||||
'w' for write binary
|
||||
'o' for write ascii
|
||||
*/
|
||||
{
|
||||
int ok=1;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case 'r':
|
||||
if ((target->ptr = fopen(target->name,"rb")) == NULL)
|
||||
{
|
||||
printf("Can't open %s for binary read ... Exiting\n",target->name);
|
||||
ok=0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
if ((target->ptr = fopen(target->name,"r")) == NULL)
|
||||
{
|
||||
printf("Can't open %s for ascii read ... Exiting\n",target->name);
|
||||
ok=0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
if ((target->ptr = fopen(target->name,"wb")) == NULL)
|
||||
{
|
||||
printf("Can't open %s for binary write ... Exiting\n",target->name);
|
||||
ok=0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
if ((target->ptr = fopen(target->name,"w")) == NULL)
|
||||
{
|
||||
printf("Can't open %s for ascii write ... Exiting\n",target->name);
|
||||
ok=0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Invalid mode specification for file_open ... Exiting\n");
|
||||
ok=0;
|
||||
}
|
||||
return(!ok);
|
||||
}
|
||||
|
||||
|
||||
/* scan_value is the generic ascii input function for use with text
|
||||
initialization files. Reads the first whitespace delimited word on a line,
|
||||
and discards the remainder of the line. Returns a value depending on the
|
||||
specified scan type */
|
||||
int scan_value (file ini, void *var, char type)
|
||||
/* Possible values for type
|
||||
'i' for integer
|
||||
'd' for double
|
||||
's' for string
|
||||
*/
|
||||
|
||||
{
|
||||
int ok_scan;
|
||||
int ok=1;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 'i':
|
||||
ok_scan = fscanf(ini.ptr, "%d%*[^\n]",(int*)var);
|
||||
if (ok_scan == 0 || ok_scan == EOF)
|
||||
{
|
||||
printf("Error reading int value from %s ... exiting\n",ini.name);
|
||||
ok=0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
ok_scan = fscanf(ini.ptr, "%lf%*[^\n]",(double*)var);
|
||||
if (ok_scan == 0 || ok_scan == EOF)
|
||||
{
|
||||
printf("Error reading double value from %s... exiting\n",ini.name);
|
||||
ok=0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
ok_scan = fscanf(ini.ptr, "%s%*[^\n]",(char*)var);
|
||||
if (ok_scan == 0 || ok_scan == EOF)
|
||||
{
|
||||
printf("Error reading string value from %s... exiting\n",ini.name);
|
||||
ok=0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Invalid type specifier for scan_value ... Exiting\n");
|
||||
ok=0;
|
||||
}
|
||||
return(!ok);
|
||||
}
|
||||
|
||||
/* combines scan_value with file_open for reading a filename from an
|
||||
initialization file and then opening it with a specified access mode */
|
||||
int scan_open (file ini,file *target,char mode)
|
||||
/* Possible values for mode
|
||||
'r' for read binary
|
||||
'i' for read ascii
|
||||
'w' for write binary
|
||||
'o' for write ascii
|
||||
*/
|
||||
{
|
||||
int ok=1;
|
||||
|
||||
if (scan_value(ini,target->name,'s'))
|
||||
{
|
||||
printf("Error reading filename from %s... Exiting\n",ini.name);
|
||||
ok=0;
|
||||
}
|
||||
if (ok)
|
||||
{
|
||||
if (file_open(target,mode))
|
||||
{
|
||||
ok=0;
|
||||
}
|
||||
}
|
||||
return(!ok);
|
||||
}
|
||||
28
RBBGCMuso/src/mtc.cpp
Normal file
28
RBBGCMuso/src/mtc.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <Rcpp.h>
|
||||
#include <numeric>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <ctime>
|
||||
|
||||
|
||||
using namespace Rcpp;
|
||||
using namespace std;
|
||||
extern "C" {
|
||||
void mtc(char*);
|
||||
};
|
||||
|
||||
//' mtclim
|
||||
//'
|
||||
//' This is the core mtclim function
|
||||
//' @importFrom Rcpp evalCpp
|
||||
//' @useDynLib RBBGCMuso
|
||||
//' @param iniFile is the name of the inifile
|
||||
//' @keywords internal
|
||||
//' @export
|
||||
// [[Rcpp::export]]
|
||||
void mtclim(std::string iniFile){
|
||||
char *y = new char[iniFile.length() + 1]; // Allocate memory for char array input
|
||||
std::strcpy(y, iniFile.c_str()); // Copy c++ string to that input.
|
||||
mtc(y);
|
||||
}
|
||||
2223
RBBGCMuso/src/mtclim43.c
Normal file
2223
RBBGCMuso/src/mtclim43.c
Normal file
File diff suppressed because it is too large
Load Diff
29
RBBGCMuso/src/mtclim43_constants.h
Normal file
29
RBBGCMuso/src/mtclim43_constants.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
mtclim43_constants.h
|
||||
physical constants for MTCLIM 4.3
|
||||
|
||||
Peter Thornton
|
||||
NTSG, School of Forestry
|
||||
University of Montana
|
||||
1/20/2000
|
||||
|
||||
(dim) stands for dimensionless values
|
||||
*/
|
||||
|
||||
#define SECPERRAD 13750.9871 /* seconds per radian of hour angle */
|
||||
#define RADPERDAY 0.017214 /* radians of Earth orbit per julian day */
|
||||
#define RADPERDEG 0.01745329 /* radians per degree */
|
||||
#define MINDECL -0.4092797 /* minimum declination (radians) */
|
||||
#define DAYSOFF 11.25 /* julian day offset of winter solstice */
|
||||
#define SRADDT 600.0 /* timestep for radiation routine (seconds) */
|
||||
|
||||
#define MA 28.9644e-3 /* (kg mol-1) molecular weight of air */
|
||||
#define MW 18.0148e-3 /* (kg mol-1) molecular weight of water */
|
||||
#define R 8.3143 /* (m3 Pa mol-1 K-1) gas law constant */
|
||||
#define G_STD 9.80665 /* (m s-2) standard gravitational accel. */
|
||||
#define P_STD 101325.0 /* (Pa) standard pressure at 0.0 m elevation */
|
||||
#define T_STD 288.15 /* (K) standard temp at 0.0 m elevation */
|
||||
#define CP 1010.0 /* (J kg-1 K-1) specific heat of air */
|
||||
#define LR_STD 0.0065 /* (-K m-1) standard temperature lapse rate */
|
||||
#define EPS 0.62196351 /* (MW/MA) unitless ratio of molec weights */
|
||||
#define PI 3.14159265 /* pi */
|
||||
35
RBBGCMuso/src/mtclim43_parameters.h
Normal file
35
RBBGCMuso/src/mtclim43_parameters.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
mtclim43_parameters.h
|
||||
model parameters for MTCLIM 4.3
|
||||
|
||||
Some model parameters are set in the *.ini file. Others are set here.
|
||||
|
||||
Peter Thornton
|
||||
NTSG, School of Forestry
|
||||
University of Montana
|
||||
1/20/2000
|
||||
|
||||
(dim) stands for dimensionless values
|
||||
*/
|
||||
|
||||
/* parameters for the Tair algorithm */
|
||||
#define TDAYCOEF 0.45 /* (dim) daylight air temperature coefficient (dim) */
|
||||
|
||||
/* parameters for the snowpack algorithm */
|
||||
#define SNOW_TCRIT -6.0 /* (deg C) critical temperature for snowmelt */
|
||||
#define SNOW_TRATE 0.042 /* (cm/degC/day) snowmelt rate */
|
||||
|
||||
/* parameters for the radiation algorithm */
|
||||
#define TBASE 0.870 /* (dim) max inst. trans., 0m, nadir, dry atm */
|
||||
#define ABASE -6.1e-5 /* (1/Pa) vapor pressure effect on transmittance */
|
||||
#define C 1.5 /* (dim) radiation parameter */
|
||||
#define B0 0.013 /* (dim) radiation parameter */
|
||||
#define B1 0.201 /* (dim) radiation parameter */
|
||||
#define B2 0.185 /* (dim) radiation parameter */
|
||||
#define RAIN_SCALAR 0.75 /* (dim) correction to trans. for rain day */
|
||||
#define DIF_ALB 0.6 /* (dim) diffuse albedo for horizon correction */
|
||||
#define SC_INT 1.32 /* (MJ/m2/day) snow correction intercept */
|
||||
#define SC_SLOPE 0.096 /* (MJ/m2/day/cm) snow correction slope */
|
||||
|
||||
/* output file extension */
|
||||
#define POSTFIX ".mtc43" /* extension added to output filename prefix */
|
||||
Loading…
Reference in New Issue
Block a user