MkNcdf: List based creation of netcdf files.

Description Usage Arguments Value See Also Examples

View source: R/ncdf_make.R

Description

MkNcdf List based creation of netCDF files. Works for most cases. Creates netcdf version 4 files by default. Appends to unlimited dimensions in existing files.

Usage

1
2
MkNcdf(varList, filename, globalAttList = NULL, overwrite = FALSE,
  force_v4 = TRUE, compLev = -1)

Arguments

varList

List, the variable list. See structure in examples.

filename

Character, the name of the netcdf file to be created.

globalAttList

List, the global attribute list. See structure in examples.

overwrite

Logical, overwrite (i.e. clobber in netcdf parlance) existing file? Otherwise, the file will be appended if existing and correct (unlimited) dims are extended.

force_v4

Logical, make netcdf version 4 files.

compLev

integer, Optional compression level. If not specified, no compression used.

Value

Returns the filename invisibly, if successful.

See Also

Other ncdf: GetNcdfFile, MkFrcAdjFromLdasin, ncdump

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Example 1 - Basic write. 
varList = list()
varList[[1]] <- list( name='precipMult',
                      longname='Precipitation Multiplier',
                      units='-',
                      precision = 'double',
                      missing = -9999,
                      dimensionList = list(scalar=list(name='scalar',values=1,
                                             units='-', unlimited=FALSE,
                                             create_dimvar=FALSE)),
                      data = 1:1 )
varList[[2]] <- list( name='precipMult22',
                      longname='Precipitation Multiplier22',
                      units='-',
                      precision = 'double',
                      missing = -9999,
                      dimensionList =
                          list(  # n.b. the dimension order: charlen,z,y,x,t
                                y=list(name='y',values=2.5+((0:6)*5),
                                       units='lat', unlimited=FALSE,
                                       create_dimvar=TRUE),
                                x=list(name='x',values=c(10,20),
                                       units='lon', unlimited=FALSE,
                                       create_dimvar=TRUE)
                               ),
                     data = matrix( 1:7, nrow=7, ncol=2 ) )
globalAttList <- list()
globalAttList[[1]] <- list(name='Restart_Time',value='2012-07-05_00:00:00', precision="text")
globalAttList[[2]] <- list(name='Some reall atts',value='#$%^!!', precision="text" )

outFile1 <- path.expand('~/test1.nc')
dum <- MkNcdf( varList, globalAttList=globalAttList, filename=outFile1, overwrite=TRUE )
ncdump(outFile1)
unlink(outFile1)

#Example 2 - append to an existing file's variable.
varList1 = list()
varList1[[1]] <- list( name='precipMult22',
                      longname='Precipitation Multiplier22',
                      units='-',
                      precision = 'double',
                      missing = -9999,
                      dimensionList =
                          list(  # n.b. the dimension order: charlen,z,y,x,t
                                y=list(name='y',values=2.5+((0:6)*5),
                                       units='lat', unlimited=TRUE,
                                       create_dimvar=TRUE),
                                x=list(name='x',values=c(10,20),
                                       units='lon', unlimited=FALSE,
                                       create_dimvar=TRUE)
                               ),
                     data = matrix( 1:7, nrow=7, ncol=2 ) )

varList2 = list()
varList2[[1]] <- list( name='precipMult22',
                      longname='Precipitation Multiplier22',
                      units='-',
                      precision = 'double',
                      missing = -9999,
                      dimensionList =
                          list(  # n.b. the dimension order: charlen,z,y,x,t
                                y=list(name='y',values=99,
                                       units='lat', unlimited=TRUE,
                                       create_dimvar=TRUE),
                                x=list(name='x',values=c(10,20),
                                       units='lon', unlimited=FALSE,
                                       create_dimvar=TRUE)
                               ),
                     data =  c(1:2)+10 )

globalAttList <- list()
globalAttList[[1]] <- list(name='Some reall atts',value='#$%^!!', precision="text" )
outFile2 <- path.expand('~/test2.nc')
MkNcdf( varList1, globalAttList=globalAttList, 
        filename=outFile2, overwrite=TRUE)
ncdump(outFile2)
MkNcdf( varList2, globalAttList=globalAttList, 
        filename=outFile2 )
ncdump(outFile2)
unlink(outFile2)

mccreigh/rwrfhydro documentation built on May 12, 2018, 3:08 a.m.