Module: NC

Included in:
NCDim, NCFile, NCFileWriter, NCFileWriter::Dim, NCFileWriter::Var, NCObject, NCVar
Defined in:
lib/io/netcdf.rb

Class Method Summary collapse

Class Method Details

.nc_decode(fd, varid, data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/io/netcdf.rb', line 8

def nc_decode (fd, varid, data)
  if fill_value = nc_get_att(fd, varid, "_FillValue")
    data[:eq, fill_value] = UNDEF
  end
  if scale_factor = nc_get_att(fd, varid, "scale_factor")
    data *= scale_factor
  end
  if add_offset = nc_get_att(fd, varid, "add_offset")
    data += add_offset
  end
  return data
end

.nc_put_att_simple(fd, varid, name, val) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/io/netcdf.rb', line 21

def nc_put_att_simple (fd, varid, name, val)
  case val
  when Float
    nc_put_att(fd, varid, name, CA_DOUBLE(val))
  when Integer
    nc_put_att(fd, varid, name, CA_INT(val))
  else
    nc_put_att(fd, varid, name, val)
  end
end

.nc_put_var_all(fd, varid, val) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/io/netcdf.rb', line 32

def nc_put_var_all (fd, varid, val)
  data_type = NC.ca_type(nc_inq_vartype(fd, varid))
  dim = (0...nc_inq_varndims(fd, varid)).collect do |dimid| 
    nc_inq_dimlen(fd, dimid)
  end
  data = CArray.new(data_type, dim) { val }
  nc_put_var(fd, varid, data)
end