Commit c0acbb46 authored by Franssen, Wietse's avatar Franssen, Wietse
Browse files

Variable check added

parent 6a898d91
# Generated by roxygen2 (4.1.0): do not edit by hand
export(ncLoad)
export(ncPlot)
\ No newline at end of file
export(ncPlot)
export(plotje)
#' @keywords internal
.PRINT_INFO<-TRUE
.PRINT_INFO<-FALSE
#' blabla a test primt message
#'
#' @param none (yet)
#' @details The function
#' @return blabla
#' Plot a simple map
#' @author Wietse Franssen \email{wietse.franssen@@wur.nl}
#' @export
#' @argument title
## "keywords internal": hide the fuction from the environment
#' @keywords internal
## "export": export the help and make it available
#' @export
plotje <-function(data, title = " ") {
image.plot(data$xyCoords$x,data$xyCoords$y,data$Data[,,1], asp = 1, main = title, xlab = '', ylab = '')
world(add = TRUE)
}
#' Shows a test primt message
#'
#' @param none (yet)
#' @details The function
#' @return blabla
#' @author Wietse Franssen \email{wietse.franssen@wur.nl}
#' @export
#' Make a image of the NetCDF data
#' @details Uses \code{\link{ncLoad}}
#' @return Nothing
#' @author Wietse Franssen \email{wietse.franssen@@wur.nl}
#' @keywords internal
ncPlot <-function(file, varName = "pr") {
#' @export
ncPlot <-function(file, varName = NULL) {
data<-ncLoad(file, varName)
plotje(data, title = paste0(data$Variable$varName, " (" ,data$Dates$start[1], ")"))
#return(data)
title=paste0(data$Variable$longName, " [",data$Variable$units,"]\n(" ,data$Dates$start[1], ")")
plotje(data, title = title)
}
#' Shows a test primt message
#'
#' @param none (yet)
#' @details The function
#' @return blabla
#' @author Wietse Franssen \email{wietse.franssen@wur.nl}
#' @export
#' @author Wietse Franssen \email{wietse.franssen@@wur.nl}
#' @keywords internal
rDataStructure <-function() {
rData<-NULL
......@@ -72,32 +62,46 @@ ncCheck <-function(ncFile, variable) {
return(result)
}
#' blabla a test primt message
#'
#' @param none (yet)
#' @details The function
#' @return blabla
# @examples
# data <- ncLoad( file = "./examples/data/example.nc4")
# data <- ncLoad( file = "~/Desktop/gg/wfd_pr_1974.nc", varName = "pr")
#' ncLoad
#' @description Loads a NetCDF file as a R-data structure
#' @param file Name of the NetCDF file
#' @param varName Variable name of the NetCDF file
#' @details Loads a NetCDF file as a R-data structure.
#' @return An object of class \code{WF}
#' @author Wietse Franssen \email{wietse.franssen@@wur.nl}
#' @export
#' @argument title
#' @keywords internal
ncLoad <-function(file, varName = "pr") {
#data<-ncLoad(file = "~/Desktop/gg/wfd_pr_1974.nc" )
#' @export
ncLoad <-function(file, varName = NULL) {
data<-rDataStructure()
ncFile <- nc_open( file )
## if no Variable is given then use the first one in the file
if (is.null(varName)) {
varName <- names(ncFile$var)[1]
if (length(names(ncFile$var))>1){
cat(paste0("loading the first variable: \"", names(ncFile$var[1]),"\"\n"))
cat(paste0("Also available:\n"))
for (i in 2:length(names(ncFile$var))){
cat(paste0("\t\"", names(ncFile$var[i]),"\"\n"))
}
} else {
cat(paste0("loading the variable: \"", names(ncFile$var[1]),"\"\n"))
}
}
ncCheckResult<-ncCheck(ncFile = ncFile, variable = varName)
data$xyCoords$x <- ncFile$dim$lon$vals
data$xyCoords$y <- ncFile$dim$lat$vals
if (.PRINT_INFO == TRUE) {
cat("Variables:\n")
print(names(ncFile$var))
cat("yeah!\n")
print(ncCheckResult)
#print(ncFile)
}
NCtime <- ncvar_get( ncFile, "time" )
......@@ -110,9 +114,22 @@ ncLoad <-function(file, varName = "pr") {
data$Dates$end <- format(firstTime + (86400 * (NCtime+1)), format="%Y-%m-%d %T %Z")
data$Data <- ncvar_get( ncFile, varName )
attr(data$Data,"dimensions") <- c("time","lat","lon")
data$Variable$varName <-varName
attr(data$Data,"dimensions") <- ncCheckResult$dims
data$Variable$varName <- varName
## Fill attributes
attTmp<-ncatt_get( ncFile, varName, "long_name" )
if (attTmp$hasatt == TRUE) {
data$Variable$longName <- attTmp$value
} else {
data$Variable$longName <- varName
}
attTmp<-ncatt_get( ncFile, varName, "units" )
if (attTmp$hasatt == TRUE) {
data$Variable$units <- attTmp$value
} else {
data$Variable$units <- "missing"
}
nc_close(ncFile)
return(data)
}
......
......@@ -15,3 +15,4 @@ LaTeX: pdfLaTeX
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/WFRTools.R
\name{ncLoad}
\alias{ncLoad}
\title{ncLoad}
\usage{
ncLoad(file, varName = NULL)
}
\arguments{
\item{file}{Name of the NetCDF file}
\item{varName}{Variable name of the NetCDF file}
}
\value{
An object of class \code{WF}
}
\description{
Loads a NetCDF file as a R-data structure
}
\details{
Loads a NetCDF file as a R-data structure.
}
\author{
Wietse Franssen \email{wietse.franssen@wur.nl}
}
\keyword{internal}
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/WFRTools.R
\name{ncPlot}
\alias{ncPlot}
\title{Make a image of the NetCDF data}
\usage{
ncPlot(file, varName = NULL)
}
\value{
Nothing
}
\description{
Make a image of the NetCDF data
}
\details{
Uses \code{\link{ncLoad}}
}
\author{
Wietse Franssen \email{wietse.franssen@wur.nl}
}
\keyword{internal}
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/WFRTools.R
\name{plotje}
\alias{plotje}
\title{Plot a simple map}
\usage{
plotje(data, title = " ")
}
\description{
Plot a simple map
}
\author{
Wietse Franssen \email{wietse.franssen@wur.nl}
}
\keyword{internal}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment