netcdfinfo <- function(file) { # Extract data structure, names of variables and dimension information # form netcdf file # # Description: # # Returns a summary of the data structure, a list of dimensions, # a list of variables and the lengths (size) of each dimension. # # Usage: # # netcdfinfo(file) # # Arguments: # # file: String containing the full path and netcdf file name. # # Output: # # $dims: dimension names # $vars: Variable names # $lenghts: dimension lenghts (size) # # # Author: # # Chris Ferro 9 June 2005 # Dag Johan Steinskog # Caio Coelho # # Examples: # # netcdfinfo("netcdf_file_name.nc") # netcdfinfo("/home/username/netcdf_file_name.nc") # # Note: The user should use a netcdf file to be able to run these examples # open a netcdf file ncfile <- open.nc(file) # print details print.nc(ncfile) # store dimension names dims <- character(file.inq.nc(ncfile)$ndims) for(i in 1:length(dims)) dims[i] <- dim.inq.nc(ncfile, i - 1)$name # store variables names vars <- character(file.inq.nc(ncfile)$nvars) for(i in 1:length(vars)) vars[i] <- var.inq.nc(ncfile, i - 1)$name # store lenghts of each dimension lenghts <- as.vector(seq(1:file.inq.nc(ncfile)$ndims)) for(i in 1:length(dims)) lenghts[i] <- dim.inq.nc(ncfile, i - 1)$length list(dims=dims,vars=vars,lenghts=lenghts) }