Commit aabef776 authored by Blodgett, David L.'s avatar Blodgett, David L.

fixes #56

parent 2ac30163
......@@ -17,6 +17,7 @@
#' @param data_metadata \code{list} A named list of strings: list(name='ShortVarName', long_name='A Long Name')
#' @param attributes list An optional list of attributes that will be added at the global level.
#' See details for useful attributes.
#' @param time_units \code{character} units string in udunits format to use for time. Defaults to 'days since 1970-01-01 00:00:00'
#' @param add_to_existing \code{boolean} If TRUE and the file already exists,
#' variables will be added to the existing file. See details for more.
#' @param overwrite boolean error if file exists.
......@@ -58,6 +59,7 @@
#' @export
write_timeseries_dsg = function(nc_file, instance_names, lats, lons, times, data, alts=NA, data_unit='',
data_prec='double',data_metadata=list(name='data',long_name='unnamed data'),
time_units = 'days since 1970-01-01 00:00:00',
attributes=list(), add_to_existing=FALSE, overwrite = FALSE){
if(!overwrite && !add_to_existing && file.exists(nc_file)) stop("File already exists and overwrite is false.")
......@@ -143,7 +145,7 @@ write_timeseries_dsg = function(nc_file, instance_names, lats, lons, times, data
data = instance_names)
add_var(nc, pkg.env$time_var_name, pkg.env$time_dim_name, "NC_DOUBLE",
'days since 1970-01-01 00:00:00', -999, 'time of measurement')
time_units, -999, 'time of measurement')
add_var(nc, pkg.env$lat_coord_var_name, pkg.env$instance_dim_name, "NC_DOUBLE",
'degrees_north', -999, 'latitude of the observation')
......@@ -190,7 +192,7 @@ write_timeseries_dsg = function(nc_file, instance_names, lats, lons, times, data
}
#Put data in NC file
var.put.nc(nc, pkg.env$time_var_name, as.numeric(times)/86400) #convert to days since 1970-01-01
var.put.nc(nc, pkg.env$time_var_name, RNetCDF::utinvcal.nc(time_units, times))
var.put.nc(nc, pkg.env$lat_coord_var_name, lats)
var.put.nc(nc, pkg.env$lon_coord_var_name, lons)
......
......@@ -6,7 +6,7 @@ NetCDF-CF Geometry and Timeseries Tools for R
It implements the NetCDF-CF Spatial Geometries specification and the timeSeries feature type of the [Discrete Sampling Geometry](http://cfconventions.org/cf-conventions/cf-conventions.html#discrete-sampling-geometries) NetCDF-CF specification.
**Visit the [`pkgdown` site](http://usgs-r.github.io/ncdfgeom/dev/articles/ncdfgeom.html) for a complete overview of the package.**
**Visit the [`pkgdown` site](http://usgs-r.github.io/ncdfgeom/articles/ncdfgeom.html) for a complete overview of the package.**
Given that this package is fairly new and in active development, please test it out
and consider [submitting issues and/or contributions!](https://github.com/USGS-R/ncdfgeom/issues)
......
......@@ -7,7 +7,8 @@
write_timeseries_dsg(nc_file, instance_names, lats, lons, times, data,
alts = NA, data_unit = "", data_prec = "double",
data_metadata = list(name = "data", long_name = "unnamed data"),
attributes = list(), add_to_existing = FALSE, overwrite = FALSE)
time_units = "days since 1970-01-01 00:00:00", attributes = list(),
add_to_existing = FALSE, overwrite = FALSE)
}
\arguments{
\item{nc_file}{\code{character} file path to the nc file to be created.}
......@@ -35,6 +36,8 @@ Valid options: 'short' 'integer' 'float' 'double' 'char'.}
\item{data_metadata}{\code{list} A named list of strings: list(name='ShortVarName', long_name='A Long Name')}
\item{time_units}{\code{character} units string in udunits format to use for time. Defaults to 'days since 1970-01-01 00:00:00'}
\item{attributes}{list An optional list of attributes that will be added at the global level.
See details for useful attributes.}
......
Markdown is supported
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