OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
write_ncdf_data_object.py
Go to the documentation of this file.
1 def write_ncdf_data_object(ngid,dname,data,start=0):
2  # procedure to write data to a NetCDF data object
3 
4  # Arguments
5  #
6  # Name Type I/O Description
7  # ---- ---- --- -----------
8  # ngid int I Group ID for data object
9  # dname string I Data object name
10  # data I Data array to write
11  # start int(*) I Optional array of dimension offsets
12  # Ported from write_ncdf_data_object.pro by Fred Patt
13  # Liang Hong, 2/25/2020
14 
15  import numpy as np
16 
17  # Open data object
18  did = ngid.variables[dname]
19  orig_data = np.copy(did[:].data)
20 
21  # Check for start array
22  if (start==0):
23  if orig_data.ndim==1:
24  did[0:np.size(data)]=data
25  else:
26  did[0:np.shape(data)[0],:]=data
27  else:
28  if orig_data.ndim==1:
29  did[:] = np.stack(orig_data[0:start],data)
30  else:
31  did[0:np.shape(data)[0],:] = np.stack(orig_data[0:start,:],data)
32  return
def write_ncdf_data_object(ngid, dname, data, start=0)