new function to save to HDF5

source("VLP.R")

#' Save the well parameters in an HDF5 file
#' 
save.well.data <- function() {

    # well.data <- as.data.frame(well.params())
    params <- well.params()         # get the core well parameters
    well.data <- params$out.data    # get only the input data
    well.calc <- params$out.calc    # get the core calculations. no iterations here

    well.name <- well.data$well.name  # extract the well name

    # build the full filename
    wells.dir <- "./"
    wellFile <- file.path(wells.dir, "WOODLIB.01.hdf5")

    # add FIELD group and WELL group
    field <- "HAGBR"            # field name

    # add a well record
    hg <- add.wellRecord(wellFile, field, well.name)

    ds.well.data <- paste(hg, "well.data", sep = "/")
    ds.well.calc <- paste(hg, "well.calc", sep = "/")

    h5write(well.data, wellFile, ds.well.data)
    h5write(well.calc, wellFile, ds.well.calc)
    H5close()
    return(hg)
}   

save.well.data()

Code that works

source("Rutils.R")

# get well parameters: input and calculated
params <- well.params()

# extract only the list with data
well.data <- params$out.data
well.calc <- params$out.calc

# get the well name from the parameters
well.name <- well.data$well.name
# wellFile <- paste(paste("./data", well.name, sep = "/"), "hdf5", sep = ".")
# save(well.data, file = well.file)

# build the full filename
wells.dir <- "./"
wellFile <- file.path(wells.dir, "WOODLIB.01.hdf5")

# add FIELD group and WELL group
field <- "HAGBR"            # field name

# add a well record
hg <- add.wellRecord(wellFile, field, well.name)
hg

ds.well.data <- paste(hg, "well.data", sep = "/")
ds.well.calc <- paste(hg, "well.calc", sep = "/")

h5write(well.data, wellFile, ds.well.data)
h5write(well.calc, wellFile, ds.well.calc)
H5close()

old save.well.data

#' Save the well parameters in an HDF5 file
#' 
save.well.data <- function() {
    # 
    # well.data <- as.data.frame(well.params())
    params <- well.params()         # get the core well parameters
    well.data <- params$out.data    # get only the input data
    well.calc <- params$out.calc    # get the core calculations. no iterations here

    well.name <- well.data$well.name  # extract the well name

    # the HDF5 file name with extension .hdf5
    wellFile <- paste(paste("./data", well.name, sep = "/"), "hdf5", sep = ".")

    # if the HDF file does not exist it will create one
    if (!file.exists(wellFile)) {
        H5Fcreate(wellFile) 
    } else {
        H5Fopen(wellFile)  
    }    

    # h5createFile(well.file)
    h5save(well.data, well.calc, file = wellFile)
    #h5write(well.data, file = wellFile, "well.data")
    H5close()
}


f0nzie/rNodal documentation built on May 6, 2019, 10:14 a.m.