if(difftime(tail(DatesR,1),tail(DatesR,2),units="secs")[[1]]%in%TimeStep==FALSE){stop(paste("the time step of the model inputs must be ",TimeStep," seconds \n",sep=""));return(NULL);}
if(difftime(tail(DatesR,1),tail(DatesR,2),units="secs")[[1]]%in%TimeStep==FALSE){stop(paste("the time step of the model inputs must be ",TimeStep," seconds \n",sep=""));return(NULL);}
LLL<-length(DatesR);
LLL<-length(DatesR);
}
}
if("GR"%in%ObjectClass){
if("GR"%in%ObjectClass){
if(is.null(Precip)){stop("Precip is missing \n");return(NULL);}
if(is.null(Precip)){stop("Precip is missing \n");return(NULL);}
if(is.null(PotEvap)){stop("PotEvap is missing \n");return(NULL);}
if(is.null(PotEvap)){stop("PotEvap is missing \n");return(NULL);}
if(!is.vector(Precip)|!is.vector(PotEvap)){stop("Precip and PotEvap must be vectors of numeric values \n");return(NULL);}
if(!is.vector(Precip)|!is.vector(PotEvap)){stop("Precip and PotEvap must be vectors of numeric values \n");return(NULL);}
if(!is.numeric(Precip)|!is.numeric(PotEvap)){stop("Precip and PotEvap must be vectors of numeric values \n");return(NULL);}
if(!is.numeric(Precip)|!is.numeric(PotEvap)){stop("Precip and PotEvap must be vectors of numeric values \n");return(NULL);}
if(length(Precip)!=LLL|length(PotEvap)!=LLL){stop("Precip, PotEvap and DatesR must have the same length \n");return(NULL);}
if(length(Precip)!=LLL|length(PotEvap)!=LLL){stop("Precip, PotEvap and DatesR must have the same length \n");return(NULL);}
}
}
if("CemaNeige"%in%ObjectClass){
if("CemaNeige"%in%ObjectClass){
if(is.null(Precip)){stop("Precip is missing \n");return(NULL);}
if(is.null(Precip)){stop("Precip is missing \n");return(NULL);}
if(is.null(TempMean)){stop("TempMean is missing \n");return(NULL);}
if(is.null(TempMean)){stop("TempMean is missing \n");return(NULL);}
if(!is.vector(Precip)|!is.vector(TempMean)){stop("Precip and TempMean must be vectors of numeric values \n");return(NULL);}
if(!is.vector(Precip)|!is.vector(TempMean)){stop("Precip and TempMean must be vectors of numeric values \n");return(NULL);}
if(!is.numeric(Precip)|!is.numeric(TempMean)){stop("Precip and TempMean must be vectors of numeric values \n");return(NULL);}
if(!is.numeric(Precip)|!is.numeric(TempMean)){stop("Precip and TempMean must be vectors of numeric values \n");return(NULL);}
if(length(Precip)!=LLL|length(TempMean)!=LLL){stop("Precip, TempMean and DatesR must have the same length \n");return(NULL);}
if(length(Precip)!=LLL|length(TempMean)!=LLL){stop("Precip, TempMean and DatesR must have the same length \n");return(NULL);}
if(is.null(TempMin)!=is.null(TempMax)){stop("TempMin and TempMax must be both defined if not null \n");return(NULL);}
if(is.null(TempMin)!=is.null(TempMax)){stop("TempMin and TempMax must be both defined if not null \n");return(NULL);}
if(!is.null(TempMin)&!is.null(TempMax)){
if(!is.null(TempMin)&!is.null(TempMax)){
if(!is.vector(TempMin)|!is.vector(TempMax)){stop("TempMin and TempMax must be vectors of numeric values \n");return(NULL);}
if(!is.vector(TempMin)|!is.vector(TempMax)){stop("TempMin and TempMax must be vectors of numeric values \n");return(NULL);}
if(!is.numeric(TempMin)|!is.numeric(TempMax)){stop("TempMin and TempMax must be vectors of numeric values \n");return(NULL);}
if(!is.numeric(TempMin)|!is.numeric(TempMax)){stop("TempMin and TempMax must be vectors of numeric values \n");return(NULL);}
if(length(TempMin)!=LLL|length(TempMax)!=LLL){stop("TempMin, TempMax and DatesR must have the same length \n");return(NULL);}
if(length(TempMin)!=LLL|length(TempMax)!=LLL){stop("TempMin, TempMax and DatesR must have the same length \n");return(NULL);}
}
}
if(!is.null(HypsoData)){
if(!is.null(HypsoData)){
if(!is.vector(HypsoData)){stop("HypsoData must be a vector of numeric values if not null \n");return(NULL);}
if(!is.vector(HypsoData)){stop("HypsoData must be a vector of numeric values if not null \n");return(NULL);}
if(!is.numeric(HypsoData)){stop("HypsoData must be a vector of numeric values if not null \n");return(NULL);}
if(!is.numeric(HypsoData)){stop("HypsoData must be a vector of numeric values if not null \n");return(NULL);}
if(length(HypsoData)!=101){stop("HypsoData must be of length 101 if not null \n");return(NULL);}
if(length(HypsoData)!=101){stop("HypsoData must be of length 101 if not null \n");return(NULL);}
if(sum(is.na(HypsoData))!=0&sum(is.na(HypsoData))!=101){stop("HypsoData must not contain any NA if not null \n");return(NULL);}
if(sum(is.na(HypsoData))!=0&sum(is.na(HypsoData))!=101){stop("HypsoData must not contain any NA if not null \n");return(NULL);}
}
}
if(!is.null(ZInputs)){
if(!is.null(ZInputs)){
if(length(ZInputs)!=1){stop("\t ZInputs must be a single numeric value if not null \n");return(NULL);}
if(length(ZInputs)!=1){stop("\t ZInputs must be a single numeric value if not null \n");return(NULL);}
if(is.na(ZInputs)|!is.numeric(ZInputs)){stop("\t ZInputs must be a single numeric value if not null \n");return(NULL);}
if(is.na(ZInputs)|!is.numeric(ZInputs)){stop("\t ZInputs must be a single numeric value if not null \n");return(NULL);}
}
}
if(is.null(HypsoData)){
if(is.null(HypsoData)){
if(verbose){warning("\t HypsoData is missing => a single layer is used and no extrapolation is made \n");}
if(verbose){warning("\t HypsoData is missing => a single layer is used and no extrapolation is made \n");}
if(verbose&!identical(HypsoData,as.numeric(rep(NA,101)))){warning("\t ZInputs is missing => HypsoData[51] is used \n");}
if(verbose&!identical(HypsoData,as.numeric(rep(NA,101)))){warning("\t ZInputs is missing => HypsoData[51] is used \n");}
ZInputs<-HypsoData[51L];
ZInputs<-HypsoData[51L];
}
}
if(NLayers<=0){
stop("NLayers must be a positive integer value \n")
return(NULL)
}
}
}
##check_NA_values
##check_NA_values
BOOL_NA<-rep(FALSE,length(DatesR));
BOOL_NA<-rep(FALSE,length(DatesR));
if("GR"%in%ObjectClass){
if("GR"%in%ObjectClass){
BOOL_NA_TMP<-(Precip<0)|is.na(Precip);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < 0 or NA values detected in Precip series \n");}}
BOOL_NA_TMP<-(Precip<0)|is.na(Precip);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < 0 or NA values detected in Precip series \n");}}
BOOL_NA_TMP<-(PotEvap<0)|is.na(PotEvap);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < 0 or NA values detected in PotEvap series \n");}}
BOOL_NA_TMP<-(PotEvap<0)|is.na(PotEvap);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < 0 or NA values detected in PotEvap series \n");}}
}
}
if("CemaNeige"%in%ObjectClass){
if("CemaNeige"%in%ObjectClass){
BOOL_NA_TMP<-(Precip<0)|is.na(Precip);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < 0 or NA values detected in Precip series \n");}}
BOOL_NA_TMP<-(Precip<0)|is.na(Precip);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < 0 or NA values detected in Precip series \n");}}
BOOL_NA_TMP<-(TempMean<(-150))|is.na(TempMean);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < -150) or NA values detected in TempMean series \n");}}
BOOL_NA_TMP<-(TempMean<(-150))|is.na(TempMean);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < -150) or NA values detected in TempMean series \n");}}
if(!is.null(TempMin)&!is.null(TempMax)){
if(!is.null(TempMin)&!is.null(TempMax)){
BOOL_NA_TMP<-(TempMin<(-150))|is.na(TempMin);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < -150) or NA values detected in TempMin series \n");}}
BOOL_NA_TMP<-(TempMin<(-150))|is.na(TempMin);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < -150) or NA values detected in TempMin series \n");}}
BOOL_NA_TMP<-(TempMax<(-150))|is.na(TempMax);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < -150) or NA values detected in TempMax series \n");}}}
BOOL_NA_TMP<-(TempMax<(-150))|is.na(TempMax);if(sum(BOOL_NA_TMP)!=0){BOOL_NA<-BOOL_NA|BOOL_NA_TMP;if(verbose){warning("\t Values < -150) or NA values detected in TempMax series \n");}}}
}
}
if(sum(BOOL_NA)!=0){
if(sum(BOOL_NA)!=0){
WTxt<-NULL;
WTxt<-NULL;
WTxt<-paste(WTxt,"\t Missing values are not allowed in InputsModel \n",sep="");
WTxt<-paste(WTxt,"\t Missing values are not allowed in InputsModel \n",sep="");
Select<-(max(which(BOOL_NA))+1):length(BOOL_NA);
Select<-(max(which(BOOL_NA))+1):length(BOOL_NA);
if(Select[1L]>Select[2L]){stop(paste("time series could not be trunced since missing values were detected at the list time-step \n",sep=""));return(NULL);}
if(Select[1L]>Select[2L]){stop(paste("time series could not be trunced since missing values were detected at the list time-step \n",sep=""));return(NULL);}