Removing C/C++ dependencies
This commit is contained in:
parent
89e5f6933a
commit
33abd4dff3
@ -31,8 +31,6 @@ Imports:
|
|||||||
openxlsx,
|
openxlsx,
|
||||||
ncdf4,
|
ncdf4,
|
||||||
tcltk
|
tcltk
|
||||||
LinkingTo: Rcpp
|
|
||||||
SystemRequirements: C++11
|
|
||||||
Maintainer: Roland Hollo's <hollorol@gmail.com>
|
Maintainer: Roland Hollo's <hollorol@gmail.com>
|
||||||
RoxygenNote: 7.1.0
|
RoxygenNote: 7.1.0
|
||||||
Suggests: knitr,
|
Suggests: knitr,
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
export(calibMuso)
|
export(calibMuso)
|
||||||
export(calibrateMuso)
|
export(calibrateMuso)
|
||||||
export(changeMusoC)
|
|
||||||
export(changemulline)
|
export(changemulline)
|
||||||
export(checkMeteoBGC)
|
export(checkMeteoBGC)
|
||||||
export(cleanupMuso)
|
export(cleanupMuso)
|
||||||
@ -15,7 +14,6 @@ export(getConstMatrix)
|
|||||||
export(getDailyOutputList)
|
export(getDailyOutputList)
|
||||||
export(getyearlycum)
|
export(getyearlycum)
|
||||||
export(getyearlymax)
|
export(getyearlymax)
|
||||||
export(mtclim)
|
|
||||||
export(musoDate)
|
export(musoDate)
|
||||||
export(musoGlue)
|
export(musoGlue)
|
||||||
export(musoMapping)
|
export(musoMapping)
|
||||||
@ -23,7 +21,6 @@ export(musoMappingFind)
|
|||||||
export(musoMonte)
|
export(musoMonte)
|
||||||
export(musoQuickEffect)
|
export(musoQuickEffect)
|
||||||
export(musoRand)
|
export(musoRand)
|
||||||
export(musoRandomizer)
|
|
||||||
export(musoSensi)
|
export(musoSensi)
|
||||||
export(normalMuso)
|
export(normalMuso)
|
||||||
export(optiMuso)
|
export(optiMuso)
|
||||||
@ -41,7 +38,6 @@ export(supportedMuso)
|
|||||||
export(updateMusoMapping)
|
export(updateMusoMapping)
|
||||||
import(ggplot2)
|
import(ggplot2)
|
||||||
import(utils)
|
import(utils)
|
||||||
importFrom(Rcpp,evalCpp)
|
|
||||||
importFrom(data.table,':=')
|
importFrom(data.table,':=')
|
||||||
importFrom(data.table,data.table)
|
importFrom(data.table,data.table)
|
||||||
importFrom(data.table,fread)
|
importFrom(data.table,fread)
|
||||||
@ -91,4 +87,3 @@ importFrom(tcltk,tk_choose.files)
|
|||||||
importFrom(tibble,rownames_to_column)
|
importFrom(tibble,rownames_to_column)
|
||||||
importFrom(tidyr,gather)
|
importFrom(tidyr,gather)
|
||||||
importFrom(tidyr,separate)
|
importFrom(tidyr,separate)
|
||||||
useDynLib(RBBGCMuso)
|
|
||||||
|
|||||||
@ -1,52 +0,0 @@
|
|||||||
# 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
#' changeMusoC
|
|
||||||
#'
|
|
||||||
#' This function is fastly randomize values based on min and max values
|
|
||||||
#' @importFrom Rcpp evalCpp
|
|
||||||
#' @useDynLib RBBGCMuso
|
|
||||||
#' @param inFile is the big matrix
|
|
||||||
#' @param outFile is the small matrix
|
|
||||||
#' @export
|
|
||||||
changeMusoC <- function(inFile, outFile, inMat) {
|
|
||||||
invisible(.Call('_RBBGCMuso_changeMusoC', PACKAGE = 'RBBGCMuso', inFile, outFile, inMat))
|
|
||||||
}
|
|
||||||
|
|
||||||
randTypeOne <- function(m) {
|
|
||||||
.Call('_RBBGCMuso_randTypeOne', PACKAGE = 'RBBGCMuso', m)
|
|
||||||
}
|
|
||||||
|
|
||||||
randTypeTwo <- function(m) {
|
|
||||||
.Call('_RBBGCMuso_randTypeTwo', PACKAGE = 'RBBGCMuso', m)
|
|
||||||
}
|
|
||||||
|
|
||||||
#' musoRandomizer
|
|
||||||
#'
|
|
||||||
#' This function is fastly randomize values based on min and max values,
|
|
||||||
#' and row indexes.
|
|
||||||
#' @importFrom Rcpp evalCpp
|
|
||||||
#' @useDynLib RBBGCMuso
|
|
||||||
#' @param A is the big matrix
|
|
||||||
#' @param B is the small matrix
|
|
||||||
#' @export
|
|
||||||
musoRandomizer <- function(A, B) {
|
|
||||||
.Call('_RBBGCMuso_musoRandomizer', PACKAGE = 'RBBGCMuso', A, B)
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -125,9 +125,12 @@ calibrateMuso <- function(measuredData, parameters = NULL, startDate = NULL,
|
|||||||
},
|
},
|
||||||
"agromo"={
|
"agromo"={
|
||||||
liks <- results[,sprintf("%s_likelihood",names(likelihood))]
|
liks <- results[,sprintf("%s_likelihood",names(likelihood))]
|
||||||
epcIndexes <- value(fut[[1]], stdout = FALSE, signal=FALSE)
|
epcIndexes <- future::value(fut[[1]], stdout = FALSE, signal=FALSE)
|
||||||
epcVals <- results[which.max(liks),1:length(epcIndexes)]
|
epcVals <- results[which.max(liks),1:length(epcIndexes)]
|
||||||
changemulline(filePaths= settings$epcInput[2], epcIndexes, epcVals, src = settings$epcInput[2], outFiles = "maxLikelihood_epc.epc")
|
epcPlace <- file.path(dirname(settings$inputFiles),settings$epc)[2]
|
||||||
|
changemulline(filePaths= epcPlace, epcIndexes,
|
||||||
|
epcVals, src = settings$epcInput[2],
|
||||||
|
outFiles = "maxLikelihood_epc.epc")
|
||||||
names(epcVals) <- epcIndexes
|
names(epcVals) <- epcIndexes
|
||||||
xdate <- as.Date(measuredData$date)
|
xdate <- as.Date(measuredData$date)
|
||||||
meanM <- measuredData[,sprintf("mean.%s", names(likelihood))]
|
meanM <- measuredData[,sprintf("mean.%s", names(likelihood))]
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
% Generated by roxygen2: do not edit by hand
|
|
||||||
% Please edit documentation in R/RcppExports.R
|
|
||||||
\name{changeMusoC}
|
|
||||||
\alias{changeMusoC}
|
|
||||||
\title{changeMusoC}
|
|
||||||
\usage{
|
|
||||||
changeMusoC(inFile, outFile, inMat)
|
|
||||||
}
|
|
||||||
\arguments{
|
|
||||||
\item{inFile}{is the big matrix}
|
|
||||||
|
|
||||||
\item{outFile}{is the small matrix}
|
|
||||||
}
|
|
||||||
\description{
|
|
||||||
This function is fastly randomize values based on min and max values
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
% 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}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
% Generated by roxygen2: do not edit by hand
|
|
||||||
% Please edit documentation in R/RcppExports.R
|
|
||||||
\name{musoRandomizer}
|
|
||||||
\alias{musoRandomizer}
|
|
||||||
\title{musoRandomizer}
|
|
||||||
\usage{
|
|
||||||
musoRandomizer(A, B)
|
|
||||||
}
|
|
||||||
\arguments{
|
|
||||||
\item{A}{is the big matrix}
|
|
||||||
|
|
||||||
\item{B}{is the small matrix}
|
|
||||||
}
|
|
||||||
\description{
|
|
||||||
This function is fastly randomize values based on min and max values,
|
|
||||||
and row indexes.
|
|
||||||
}
|
|
||||||
@ -1,89 +0,0 @@
|
|||||||
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
|
|
||||||
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
|
|
||||||
|
|
||||||
#include <Rcpp.h>
|
|
||||||
|
|
||||||
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) {
|
|
||||||
BEGIN_RCPP
|
|
||||||
Rcpp::RObject rcpp_result_gen;
|
|
||||||
Rcpp::RNGScope rcpp_rngScope_gen;
|
|
||||||
Rcpp::traits::input_parameter< double >::type a(aSEXP);
|
|
||||||
rcpp_result_gen = Rcpp::wrap(getWritePositions(a));
|
|
||||||
return rcpp_result_gen;
|
|
||||||
END_RCPP
|
|
||||||
}
|
|
||||||
// changeMusoC
|
|
||||||
void changeMusoC(std::string inFile, std::string outFile, NumericMatrix inMat);
|
|
||||||
RcppExport SEXP _RBBGCMuso_changeMusoC(SEXP inFileSEXP, SEXP outFileSEXP, SEXP inMatSEXP) {
|
|
||||||
BEGIN_RCPP
|
|
||||||
Rcpp::RNGScope rcpp_rngScope_gen;
|
|
||||||
Rcpp::traits::input_parameter< std::string >::type inFile(inFileSEXP);
|
|
||||||
Rcpp::traits::input_parameter< std::string >::type outFile(outFileSEXP);
|
|
||||||
Rcpp::traits::input_parameter< NumericMatrix >::type inMat(inMatSEXP);
|
|
||||||
changeMusoC(inFile, outFile, inMat);
|
|
||||||
return R_NilValue;
|
|
||||||
END_RCPP
|
|
||||||
}
|
|
||||||
// randTypeOne
|
|
||||||
NumericMatrix randTypeOne(NumericMatrix m);
|
|
||||||
RcppExport SEXP _RBBGCMuso_randTypeOne(SEXP mSEXP) {
|
|
||||||
BEGIN_RCPP
|
|
||||||
Rcpp::RObject rcpp_result_gen;
|
|
||||||
Rcpp::RNGScope rcpp_rngScope_gen;
|
|
||||||
Rcpp::traits::input_parameter< NumericMatrix >::type m(mSEXP);
|
|
||||||
rcpp_result_gen = Rcpp::wrap(randTypeOne(m));
|
|
||||||
return rcpp_result_gen;
|
|
||||||
END_RCPP
|
|
||||||
}
|
|
||||||
// randTypeTwo
|
|
||||||
NumericMatrix randTypeTwo(NumericMatrix m);
|
|
||||||
RcppExport SEXP _RBBGCMuso_randTypeTwo(SEXP mSEXP) {
|
|
||||||
BEGIN_RCPP
|
|
||||||
Rcpp::RObject rcpp_result_gen;
|
|
||||||
Rcpp::RNGScope rcpp_rngScope_gen;
|
|
||||||
Rcpp::traits::input_parameter< NumericMatrix >::type m(mSEXP);
|
|
||||||
rcpp_result_gen = Rcpp::wrap(randTypeTwo(m));
|
|
||||||
return rcpp_result_gen;
|
|
||||||
END_RCPP
|
|
||||||
}
|
|
||||||
// musoRandomizer
|
|
||||||
NumericMatrix musoRandomizer(NumericMatrix A, NumericMatrix B);
|
|
||||||
RcppExport SEXP _RBBGCMuso_musoRandomizer(SEXP ASEXP, SEXP BSEXP) {
|
|
||||||
BEGIN_RCPP
|
|
||||||
Rcpp::RObject rcpp_result_gen;
|
|
||||||
Rcpp::RNGScope rcpp_rngScope_gen;
|
|
||||||
Rcpp::traits::input_parameter< NumericMatrix >::type A(ASEXP);
|
|
||||||
Rcpp::traits::input_parameter< NumericMatrix >::type B(BSEXP);
|
|
||||||
rcpp_result_gen = Rcpp::wrap(musoRandomizer(A, B));
|
|
||||||
return rcpp_result_gen;
|
|
||||||
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},
|
|
||||||
{"_RBBGCMuso_randTypeTwo", (DL_FUNC) &_RBBGCMuso_randTypeTwo, 1},
|
|
||||||
{"_RBBGCMuso_musoRandomizer", (DL_FUNC) &_RBBGCMuso_musoRandomizer, 2},
|
|
||||||
{NULL, NULL, 0}
|
|
||||||
};
|
|
||||||
|
|
||||||
RcppExport void R_init_RBBGCMuso(DllInfo *dll) {
|
|
||||||
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
|
|
||||||
R_useDynamicSymbols(dll, FALSE);
|
|
||||||
}
|
|
||||||
@ -1,156 +0,0 @@
|
|||||||
/*
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
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 */
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
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 */
|
|
||||||
@ -1,138 +0,0 @@
|
|||||||
#include <Rcpp.h>
|
|
||||||
#include <numeric>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <string>
|
|
||||||
#include <new>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <numeric>
|
|
||||||
#include <ctime>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace Rcpp;
|
|
||||||
using namespace std;
|
|
||||||
// [[Rcpp::plugins(cpp11)]]
|
|
||||||
|
|
||||||
// [[Rcpp::export]]
|
|
||||||
IntegerVector getWritePositions(double a){
|
|
||||||
//getWritePositions returns abstract rownumbers to rownumbers and other indexek
|
|
||||||
// getWritePositions(173.62) = c(173,7,3) // it supports up to 10 subvalues
|
|
||||||
IntegerVector outVec(3); // outVec is vector of rowIndex, colNumber, choosen Index
|
|
||||||
a = a * 100;
|
|
||||||
a = round(a); //without this line 155.92 ~= 155.9199999999, (int) 155.9199999999*100 = 15591
|
|
||||||
outVec[0] = (int)a / 100;
|
|
||||||
outVec[1] = ((int)a /10) % 10 + 1;
|
|
||||||
outVec[2] = (int)a % 10;
|
|
||||||
|
|
||||||
|
|
||||||
return outVec;
|
|
||||||
}
|
|
||||||
|
|
||||||
IntegerMatrix getPositions(NumericVector v){
|
|
||||||
|
|
||||||
int numVari = v.size();
|
|
||||||
IntegerMatrix indexek(numVari,3);
|
|
||||||
IntegerVector positions(3);
|
|
||||||
for(int i = 0; i < numVari; ++i){
|
|
||||||
positions = getWritePositions(v[i]);
|
|
||||||
indexek(i,_) = positions;
|
|
||||||
}
|
|
||||||
return indexek;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void goNextLine(std::ifstream& fin){
|
|
||||||
char c='a';
|
|
||||||
while((c!='\n')&&(fin.get(c))){}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define NEXT goNextLine(fin)
|
|
||||||
int fileChanger(std::string inFile, std::string outFile, IntegerVector linum, NumericVector num, IntegerVector colnum, IntegerVector colindex){
|
|
||||||
std::ifstream fin(inFile);
|
|
||||||
if (!fin.is_open()) {
|
|
||||||
stop("Cannot open " + inFile + " for read");
|
|
||||||
}
|
|
||||||
std::ofstream fot(outFile);
|
|
||||||
|
|
||||||
if (!fot.is_open()) {
|
|
||||||
stop("Cannot open " + outFile + " for read");
|
|
||||||
}
|
|
||||||
string tempString;
|
|
||||||
|
|
||||||
int counter = 1;
|
|
||||||
int counterV = 0;
|
|
||||||
while (!fin.eof()) {
|
|
||||||
|
|
||||||
|
|
||||||
if(counter == linum[counterV]){
|
|
||||||
if(colnum[counterV]==1){
|
|
||||||
fot << num[counterV] << "\n";
|
|
||||||
NEXT;
|
|
||||||
} else {
|
|
||||||
double * elements;
|
|
||||||
elements = new double [colnum[counterV]];
|
|
||||||
if(linum[counterV]!=linum[counterV+1]){
|
|
||||||
for(int i=0;i<colnum[counterV];++i){
|
|
||||||
|
|
||||||
fin >> elements[i];
|
|
||||||
|
|
||||||
if(i==colindex[counterV]){
|
|
||||||
elements[i]=num[counterV];
|
|
||||||
}
|
|
||||||
// std::cout << colnum[counterV] << " " << colindex[counterV] << " " << elements[i] << " "<< i <<"\n";
|
|
||||||
// std::cout << colindex[counterV] << getWritePositions(155.92) <<"\n";
|
|
||||||
// std::cout << "======================== \n";
|
|
||||||
fot << elements[i] << '\t';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int k=0;
|
|
||||||
for(int i=0;i<colnum[counterV];++i){
|
|
||||||
|
|
||||||
fin >> elements[i];
|
|
||||||
if(i==colindex[counterV + k]){
|
|
||||||
elements[i]=num[counterV + k];
|
|
||||||
if(linum[counterV +k]==linum[counterV + k + 1]){
|
|
||||||
++k;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fot << elements[i] << '\t';
|
|
||||||
|
|
||||||
}
|
|
||||||
counterV = counterV + k;
|
|
||||||
}
|
|
||||||
|
|
||||||
fot << "\n";
|
|
||||||
delete [] elements;
|
|
||||||
NEXT;
|
|
||||||
}
|
|
||||||
++counterV;
|
|
||||||
} else {
|
|
||||||
getline(fin,tempString);
|
|
||||||
fot << tempString << "\n";
|
|
||||||
}
|
|
||||||
++counter;
|
|
||||||
if(counter > 1000){
|
|
||||||
stop("You modified a line which has not as many columns as you specified.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fin.close();
|
|
||||||
fot.close();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//' changeMusoC
|
|
||||||
//'
|
|
||||||
//' This function is fastly randomize values based on min and max values
|
|
||||||
//' @importFrom Rcpp evalCpp
|
|
||||||
//' @useDynLib RBBGCMuso
|
|
||||||
//' @param inFile is the big matrix
|
|
||||||
//' @param outFile is the small matrix
|
|
||||||
//' @export
|
|
||||||
// [[Rcpp::export]]
|
|
||||||
void changeMusoC(std::string inFile, std::string outFile, NumericMatrix inMat){
|
|
||||||
int numChanges = inMat.nrow();
|
|
||||||
IntegerMatrix indexes(numChanges,3);
|
|
||||||
indexes = getPositions(inMat(_,0));
|
|
||||||
fileChanger(inFile,outFile,indexes(_,0),inMat(_,1),indexes(_,1),indexes(_,2));
|
|
||||||
}
|
|
||||||
@ -1,245 +0,0 @@
|
|||||||
#include <Rcpp.h>
|
|
||||||
#include <numeric>
|
|
||||||
#include <iostream>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <numeric>
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace Rcpp;
|
|
||||||
using namespace std;
|
|
||||||
// [[Rcpp::plugins(cpp11)]]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NumericMatrix randTypeZero(NumericMatrix m){
|
|
||||||
/*
|
|
||||||
A typical matrix like m:
|
|
||||||
|
|
||||||
| INDEX | DEPENDENCE | MIN | MAX |
|
|
||||||
|-------+------------+------+------|
|
|
||||||
| 21 | 0 | 0 | 364 |
|
|
||||||
| 57 | 0 | bkla | asdf |
|
|
||||||
|
|
||||||
This randomization type is the easiest,
|
|
||||||
the function produces a matrix which first
|
|
||||||
column contains the indexes, and the second contains
|
|
||||||
random numbers, which was drawn from uniform distribution
|
|
||||||
with the corresponding min and max parameters, specified
|
|
||||||
by the matrix m.
|
|
||||||
|
|
||||||
*/
|
|
||||||
int n=m.nrow()-1;
|
|
||||||
NumericMatrix M(n+1,2);
|
|
||||||
M(_,0)=m(_,0);
|
|
||||||
for(int i=0;i<=n;++i){
|
|
||||||
double min=m(i,2);
|
|
||||||
double max=m(i,3);
|
|
||||||
M(i,1)=runif(1,min,max)[0];
|
|
||||||
}
|
|
||||||
return M;
|
|
||||||
}
|
|
||||||
|
|
||||||
// [[Rcpp::export]]
|
|
||||||
NumericMatrix randTypeOne(NumericMatrix m){
|
|
||||||
/*
|
|
||||||
The stucture of matrix m here is the same
|
|
||||||
as in randTypeZero.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
NumericVector dependence=m(_,2);
|
|
||||||
int n=m.nrow()-1;
|
|
||||||
NumericMatrix M(n+1,2);
|
|
||||||
M(_,0)=m(_,0);
|
|
||||||
M(0,1)=runif(1,m(0,2),m(0,3))[0];
|
|
||||||
for(int i=1;i<=n;++i){
|
|
||||||
int dep=m(i,1)-1;
|
|
||||||
double min=max(M(dep,1),m(i,2));
|
|
||||||
double max=m(i,3);
|
|
||||||
M(i,1)=runif(1,min,max)[0];
|
|
||||||
}
|
|
||||||
return M;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IntegerVector orderDec(NumericVector v){
|
|
||||||
//This function is order a vector decreasingly
|
|
||||||
Function f("order");
|
|
||||||
return f(v,_["decreasing"]=1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NumericMatrix randTypeTwo(NumericMatrix m){
|
|
||||||
// int n=m.nrow()-1;
|
|
||||||
// int N=n-1;
|
|
||||||
// NumericMatrix mv=m(Range(0,(n-1)),_);
|
|
||||||
// NumericVector dependence=m(_,2);
|
|
||||||
// NumericMatrix M(n+1,2);
|
|
||||||
// M(_,0)=m(_,0);
|
|
||||||
// IntegerVector indexes=orderDec(mv(_,2));
|
|
||||||
// NumericVector sorban=mv(_,2);
|
|
||||||
// sorban.sort(true);
|
|
||||||
// NumericVector sor=cumsum(sorban);
|
|
||||||
// sor.sort(true);
|
|
||||||
// for(int i=0;i<=N;++i){
|
|
||||||
// if(i!=N){
|
|
||||||
// mv((indexes[i]-1),3)-= sor[i+1];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// double rollingNumber=0;
|
|
||||||
|
|
||||||
// for(int i=0;i<=N;++i){
|
|
||||||
// double minimum=mv((indexes[i]-1),2);
|
|
||||||
// double maximum=mv((indexes[i]-1),3)-rollingNumber;
|
|
||||||
// M(i,1)=runif(1,minimum,maximum)[0];
|
|
||||||
// rollingNumber+=M(i,1);
|
|
||||||
// // cout << "minimum:\t" << minimum << endl;
|
|
||||||
// // cout << "maximum:\t" << maximum << endl;
|
|
||||||
// // cout << "indexes:\t" << indexes[i] << endl;
|
|
||||||
// // cout << "rollingNumber:\t" << rollingNumber << endl;
|
|
||||||
// // cout << "choosen:\t" << M(i,1) <<endl;
|
|
||||||
// // cout << "sor:\t" << sor <<endl;
|
|
||||||
// // cout << "\n\n\n" << mv;
|
|
||||||
// }
|
|
||||||
// M(n,1)=1-rollingNumber;
|
|
||||||
// return M;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
//[[Rcpp::export]]
|
|
||||||
NumericMatrix randTypeTwo(NumericMatrix m){
|
|
||||||
int n = m.nrow()-1; //Just for optimalization (indexing from 0)
|
|
||||||
int N = n-1; //Just for optimalization (indexing from 0)
|
|
||||||
NumericMatrix mv = m(Range(0,(n-1)),_); // We take off the first n-1 element. What about the last element?????????
|
|
||||||
NumericVector dependence = m(_,2); // Th dependence vector represent the matrix and other information for function based on the elements.
|
|
||||||
NumericMatrix M(n+1,2); // M is the randomizated matrix. It will have n+1 rows (identical to m).
|
|
||||||
M(_,0) = m(_,0); //Insert the indexes
|
|
||||||
IntegerVector indexes = orderDec(mv(_,2)); // Why not use the dependence variable?
|
|
||||||
NumericVector sorban = mv(_,2); // Original ordering of the dependence variable?
|
|
||||||
sorban.sort(true); // With the previous line, it sorts the dependence variable.
|
|
||||||
NumericVector sor=cumsum(sorban); // ?????
|
|
||||||
sor.sort(true); // ??????
|
|
||||||
for(int i=0;i<=N;++i){
|
|
||||||
if(i!=N){
|
|
||||||
mv((indexes[i]-1),3)-= sor[i+1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double rollingNumber=0;
|
|
||||||
|
|
||||||
for(int i=0;i<=N;++i){
|
|
||||||
double minimum=mv((indexes[i]-1),2);
|
|
||||||
double maximum=mv((indexes[i]-1),3)-rollingNumber;
|
|
||||||
M(i,1)=runif(1,minimum,maximum)[0];
|
|
||||||
rollingNumber+=M(i,1);
|
|
||||||
// cout << "minimum:\t" << minimum << endl;
|
|
||||||
// cout << "maximum:\t" << maximum << endl;
|
|
||||||
// cout << "indexes:\t" << indexes[i] << endl;
|
|
||||||
// cout << "rollingNumber:\t" << rollingNumber << endl;
|
|
||||||
// cout << "choosen:\t" << M(i,1) <<endl;
|
|
||||||
// cout << "sor:\t" << sor <<endl;
|
|
||||||
// cout << "\n\n\n" << mv;
|
|
||||||
}
|
|
||||||
M(n,1)=1-rollingNumber;
|
|
||||||
return M;
|
|
||||||
}
|
|
||||||
|
|
||||||
NumericMatrix randTypeThree(NumericMatrix m){
|
|
||||||
int n=m.nrow()-1;
|
|
||||||
int N=n-1;
|
|
||||||
NumericMatrix mv=m(Range(0,(n-1)),_);
|
|
||||||
NumericVector dependence=m(_,2);
|
|
||||||
NumericMatrix M(n+1,2);
|
|
||||||
M(_,0)=m(_,0);
|
|
||||||
IntegerVector indexes=orderDec(mv(_,2));
|
|
||||||
NumericVector sorban=mv(_,2);
|
|
||||||
sorban.sort(true);
|
|
||||||
NumericVector sor=cumsum(sorban);
|
|
||||||
sor.sort(true);
|
|
||||||
for(int i=0;i<=N;++i){
|
|
||||||
if(i!=N){
|
|
||||||
mv((indexes[i]-1),3)-= sor[i+1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double rollingNumber=0;
|
|
||||||
|
|
||||||
for(int i=0;i<=N;++i){
|
|
||||||
double minimum=mv((indexes[i]-1),2);
|
|
||||||
double maximum=mv((indexes[i]-1),3)-rollingNumber;
|
|
||||||
M(i,1)=runif(1,minimum,maximum)[0];
|
|
||||||
rollingNumber+=M(i,1);
|
|
||||||
// cout << "minimum:\t" << minimum << endl;
|
|
||||||
// cout << "maximum:\t" << maximum << endl;
|
|
||||||
// cout << "indexes:\t" << indexes[i] << endl;
|
|
||||||
// cout << "rollingNumber:\t" << rollingNumber << endl;
|
|
||||||
// cout << "choosen:\t" << M(i,1) <<endl;
|
|
||||||
// cout << "sor:\t" << sor <<endl;
|
|
||||||
// cout << "\n\n\n" << mv;
|
|
||||||
}
|
|
||||||
M(n,1)=1-rollingNumber;
|
|
||||||
return M;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NumericMatrix copyMatSpec(NumericMatrix A, NumericMatrix B, int u, int v){
|
|
||||||
int k=0;
|
|
||||||
for(int i=u;i<=v;++i){
|
|
||||||
A(i,_)=B(k,_);
|
|
||||||
k+=1;
|
|
||||||
}
|
|
||||||
return A;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//' musoRandomizer
|
|
||||||
//'
|
|
||||||
//' This function is fastly randomize values based on min and max values,
|
|
||||||
//' and row indexes.
|
|
||||||
//' @importFrom Rcpp evalCpp
|
|
||||||
//' @useDynLib RBBGCMuso
|
|
||||||
//' @param A is the big matrix
|
|
||||||
//' @param B is the small matrix
|
|
||||||
//' @export
|
|
||||||
// [[Rcpp::export]]
|
|
||||||
NumericMatrix musoRandomizer(NumericMatrix A, NumericMatrix B){
|
|
||||||
NumericMatrix M(A.nrow(),2);
|
|
||||||
int nGroup = B.nrow()-1;
|
|
||||||
int k=0;
|
|
||||||
for(int i=0;i<=nGroup;++i)
|
|
||||||
{
|
|
||||||
int b=B(i,0)-1;
|
|
||||||
int till=b+k;
|
|
||||||
int t=B(i,1);
|
|
||||||
// cout << b << "\t" << t <<endl;
|
|
||||||
switch(t){
|
|
||||||
case 0:
|
|
||||||
M=copyMatSpec(M,randTypeZero(A(Range(k,till),_)),k,till);
|
|
||||||
// cout << M << endl;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
M=copyMatSpec(M,randTypeOne(A(Range(k,till),_)),k,till);
|
|
||||||
// cout << M << endl;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
M=copyMatSpec(M,randTypeTwo(A(Range(k,till),_)),k,till);
|
|
||||||
// cout << M << endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
k=till+1;
|
|
||||||
// cout << k << endl;
|
|
||||||
}
|
|
||||||
return M;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string concatenate(std::string A, std::string B){
|
|
||||||
std::string C = A + B;
|
|
||||||
return C;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user