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

added missing value and changed dimensions orders

parent 25fe2a0e
......@@ -396,17 +396,19 @@ ncLoad <-function(file, varName = NULL, lonlatbox = NULL, timesteps = NULL, z =
##WFF
if (length(dim(data$Data))==2) {
data$Data<-aperm(data$Data, c(2,1))
# data$Data<-aperm(data$Data, c(2,1))
if(ncCheckResult$yFlip) data$Data<-apply(data$Data,2,rev)
attr(data$Data,"dimensions") <- rev(ncCheckResult$dims[1:2])
# attr(data$Data,"dimensions") <- rev(ncCheckResult$dims[1:2])
attr(data$Data,"dimensions") <- ncCheckResult$dims[1:2]
} else if (length(dim(data$Data))==3) {
data$Data<-aperm(data$Data, c(3,2,1))
# data$Data<-aperm(data$Data, c(3,2,1))
if(ncCheckResult$yFlip) {
for (iTime in 1:dim(data$Data)[1]) {
data$Data[iTime,,]<-apply(data$Data[iTime,,],2,rev)
}
}
attr(data$Data,"dimensions") <- rev(ncCheckResult$dims)
# attr(data$Data,"dimensions") <- rev(ncCheckResult$dims)
attr(data$Data,"dimensions") <- ncCheckResult$dims
}
#attr(data$Data,"dimensions") <- rev(ncCheckResult$dims)
data$Variable$varName <- varName
......@@ -499,9 +501,11 @@ ncWrite <-function(outFile = "~/out.nc", rData = data) {
FillValue <- 1e20
if (!is.null(rData$Variable$units)) {
datavar <- ncvar_def( rData$Variable$varName, rData$Variable$units, list(dimT,dimY,dimX), FillValue, prec="float")
# datavar <- ncvar_def( rData$Variable$varName, rData$Variable$units, list(dimT,dimY,dimX), FillValue, prec="float")
datavar <- ncvar_def( rData$Variable$varName, rData$Variable$units, list(dimX,dimY,dimT), FillValue, prec="float")
} else {
datavar <- ncvar_def( rData$Variable$varName, " ", list(dimT,dimY,dimX), FillValue, prec="float")
# datavar <- ncvar_def( rData$Variable$varName, " ", list(dimT,dimY,dimX), FillValue, prec="float")
datavar <- ncvar_def( rData$Variable$varName, " ", list(dimX,dimY,dimT), FillValue, prec="float")
}
ncid_out <- nc_create(outFile, datavar)
......@@ -519,7 +523,8 @@ ncWrite <-function(outFile = "~/out.nc", rData = data) {
ncatt_put( ncid_out, "time", "calendar", "standard")
ncatt_put( ncid_out, rData$Variable$varName, "long_name", rData$Variable$longName)
ncatt_put( ncid_out, rData$Variable$varName, "_FillValue", FillValue)
ncatt_put( ncid_out, rData$Variable$varName, "missing_value", FillValue)
ncvar_put( ncid_out, datavar, rData$Data )
nc_close(ncid_out)
......
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