if(is.null(TabSeries)){stop("TabSeries must be a dataframe containing the dates and data to be converted \n");return(NULL);}
if(!is.data.frame(TabSeries)){stop("TabSeries must be a dataframe containing the dates and data to be converted \n");return(NULL);}
if(ncol(TabSeries)<2){stop("TabSeries must contain at least two columns (including the coulmn of dates \n");return(NULL);}
if("POSIXlt"%in%class(TabSeries[,1])==FALSE&"POSIXct"%in%class(TabSeries[,1])==FALSE){stop("TabSeries first column must be a vector of class POSIXlt or POSIXct \n");return(NULL);}
for(iColin2:ncol(TabSeries)){
if(!is.numeric(TabSeries[,iCol])){stop("TabSeries columns (other than the first one) be of numeric class \n");return(NULL);}}
##check_TimeFormat
if(is.null(TimeFormat)){stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n");return(NULL);}
if(!is.vector(TimeFormat)){stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n");return(NULL);}
if(!is.character(TimeFormat)){stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n");return(NULL);}
if(length(TimeFormat)!=1){stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n");return(NULL);}
stop("NewTimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n");return(NULL);}
##check_ConvertFun
if(is.null(ConvertFun)){stop("ConvertFun must be a vector of character \n");return(NULL);}
if(!is.vector(ConvertFun)){stop("ConvertFun must be a vector of character \n");return(NULL);}
if(!is.character(ConvertFun)){stop("ConvertFun must be a vector of character \n");return(NULL);}
if(length(ConvertFun)!=(ncol(TabSeries)-1)){stop(paste("ConvertFun must be of length ",ncol(TabSeries)-1," (length=ncol(TabSeries)-1) \n",sep=""));return(NULL);}
if(sum(ConvertFun%in%c("sum","mean")==FALSE)!=0){stop("ConvertFun elements must be either 'sum' or 'mean' \n");return(NULL);}
##check_YearFirstMonth
if(is.null(YearFirstMonth)){stop("YearFirstMonth must be an integer between 1 and 12 \n");return(NULL);}
if(!is.vector(YearFirstMonth)){stop("YearFirstMonth must be an integer between 1 and 12 \n");return(NULL);}
if(!is.numeric(YearFirstMonth)){stop("YearFirstMonth must be an integer between 1 and 12 \n");return(NULL);}
YearFirstMonth<-as.integer(YearFirstMonth);
if(length(YearFirstMonth)!=1){stop(paste("YearFirstMonth must be only one integer between 1 and 12 \n",sep=""));return(NULL);}
if(YearFirstMonth%in%(1:12)==FALSE){stop(paste("YearFirstMonth must be only one integer between 1 and 12 \n",sep=""));return(NULL);}
if(!identical(TabSeries[,1],TmpDatesR)){stop("Problem detected in TabSeries dates vector (in comparison with seq(from=TabSeries[1,1],to=tail(TabSeries[,1],1))) \n");return(NULL);}
if(verbose){warning("\t The old and new format are identical \n\t -> no time-step conversion was performed \n");return(TabSeries);}}
##check_TabSeries
if(is.null(TabSeries)){stop("TabSeries must be a dataframe containing the dates and data to be converted \n");return(NULL);}
if(!is.data.frame(TabSeries)){stop("TabSeries must be a dataframe containing the dates and data to be converted \n");return(NULL);}
if(ncol(TabSeries)<2){stop("TabSeries must contain at least two columns (including the coulmn of dates \n");return(NULL);}
if("POSIXlt"%in%class(TabSeries[,1])==FALSE&"POSIXct"%in%class(TabSeries[,1])==FALSE){stop("TabSeries first column must be a vector of class POSIXlt or POSIXct \n");return(NULL);}
for(iColin2:ncol(TabSeries)){
if(!is.numeric(TabSeries[,iCol])){stop("TabSeries columns (other than the first one) be of numeric class \n");return(NULL);}}
##check_TimeFormat
if(is.null(TimeFormat)){stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n");return(NULL);}
if(!is.vector(TimeFormat)){stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n");return(NULL);}
if(!is.character(TimeFormat)){stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n");return(NULL);}
if(length(TimeFormat)!=1){stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n");return(NULL);}
stop("NewTimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n");return(NULL);}
##check_ConvertFun
if(is.null(ConvertFun)){stop("ConvertFun must be a vector of character \n");return(NULL);}
if(!is.vector(ConvertFun)){stop("ConvertFun must be a vector of character \n");return(NULL);}
if(!is.character(ConvertFun)){stop("ConvertFun must be a vector of character \n");return(NULL);}
if(length(ConvertFun)!=(ncol(TabSeries)-1)){stop(paste("ConvertFun must be of length ",ncol(TabSeries)-1," (length=ncol(TabSeries)-1) \n",sep=""));return(NULL);}
if(sum(ConvertFun%in%c("sum","mean")==FALSE)!=0){stop("ConvertFun elements must be either 'sum' or 'mean' \n");return(NULL);}
##check_YearFirstMonth
if(is.null(YearFirstMonth)){stop("YearFirstMonth must be an integer between 1 and 12 \n");return(NULL);}
if(!is.vector(YearFirstMonth)){stop("YearFirstMonth must be an integer between 1 and 12 \n");return(NULL);}
if(!is.numeric(YearFirstMonth)){stop("YearFirstMonth must be an integer between 1 and 12 \n");return(NULL);}
YearFirstMonth<-as.integer(YearFirstMonth);
if(length(YearFirstMonth)!=1){stop(paste("YearFirstMonth must be only one integer between 1 and 12 \n",sep=""));return(NULL);}
if(YearFirstMonth%in%(1:12)==FALSE){stop(paste("YearFirstMonth must be only one integer between 1 and 12 \n",sep=""));return(NULL);}
if(!identical(TabSeries[,1],TmpDatesR)){stop("Problem detected in TabSeries dates vector (in comparison with seq(from=TabSeries[1,1],to=tail(TabSeries[,1],1))) \n");return(NULL);}
\item{YearFirstMonth}{(optional) [numeric] integer used when NewTimeFormat = "yearly" to set when the starting month of the year (e.g. 01 for calendar year or 09 for hydrological year starting in september)}
\item{TimeLag}{(optional) [numeric] numeric indicating a time lag (in seconds) for the time series aggregation (especially useful to aggegate hourly time series in daily time series)}
\item{verbose}{(optional) [boolean] boolean indicating if the function is run in verbose mode or not, default = FALSE}