Skip to content

Commit

Permalink
fixes to get netcdf to work for webinterface
Browse files Browse the repository at this point in the history
  • Loading branch information
robkooper committed Jul 19, 2012
1 parent bdc8d47 commit 7af76fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 5 additions & 5 deletions models/ed/R/model2netcdf.ED2.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ for(i in 1:length(flist)){
}

## set up storage
block <- 48
block <- 24
add <- function(dat,col,row){

## first clone and fill data
Expand All @@ -49,11 +49,11 @@ add <- function(dat,col,row){
## Option 1 - add data anew
if(length(out) < col){
bdim <- dims
bdim[1] <- 366*48
bdim[1] <- 366*block
# if(length(dat) > 1){
# out[[col]] <- matrix(NA,366*48,length(dat))
# out[[col]] <- matrix(NA,366*block,length(dat))
# } else {
# out[[col]] <- rep(NA,366*48)
# out[[col]] <- rep(NA,366*block)
# }
##array(NA,dim=dims)
out[[col]] <- array(NA,dim=bdim)
Expand Down Expand Up @@ -252,7 +252,7 @@ out <- add(dat$BASEFLOW,46,row) ## Qsb

## declare variables
## need to SHIFT for partial years **********************
t <- dim.def.ncdf("time","seconds",(1:dim(out[[1]])[1])*1800.0)
t <- dim.def.ncdf("time","seconds",(1:dim(out[[1]])[1])*3600.0*24.0/block)
zg <- dim.def.ncdf("SoilLayerMidpoint","meters",z[1:length(dz)]+dz/2)

var <- list()
Expand Down
11 changes: 6 additions & 5 deletions web/plot.netcdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ data.fetch <- function(var, nc, start, end, values, fun=mean) {
# values extracted from the hdf data

if (var == "time") {
val <- start:end
val <- unique(floor(nc$dim[['time']]$vals / (24*3600)))
attr(val, "lbl") <- "Day of the year"
return(val)
}
Expand All @@ -80,9 +80,11 @@ data.fetch <- function(var, nc, start, end, values, fun=mean) {
}

# some precomputations
lastval <- (values_day*(1+end-start))
indices <- c(lapply(start:(end),function(x) {seq(1+x*values_day+starttime, 1+x*values_day+endtime)}), recursive=TRUE)
aggrlist <- list(rep(start:(end), each=(1 + endtime - starttime)))
# lastval <- (values_day*(1+end-start))
# indices <- c(lapply(start:(end),function(x) {seq(1+x*values_day+starttime, 1+x*values_day+endtime)}), recursive=TRUE)
# aggrlist <- list(rep(start:(end), each=(1 + endtime - starttime)))
indices <- 0:length(nc$dim[['time']]$vals)
aggrlist <- list(floor(nc$dim[['time']]$vals / (24*3600)))

# aggregate the data
data <- get.var.ncdf(nc, useme)
Expand Down Expand Up @@ -147,7 +149,6 @@ plot.netcdf <- function(datafile, year, yvar, xvar='time', width=800, height=600

# open netcdf file
nc <- open.ncdf(paste(settings$run$host$outdir, datafile, sep="/"))
print(nc)

# compute variables
xval_mean <- data.fetch(xvar, nc, start_day, end_day, values_day, mean)
Expand Down

0 comments on commit 7af76fa

Please sign in to comment.