Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion ScientificDataSet/Providers/NetCDF/NetCDFDataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ private Variable CreateNetCdfVariable(string name, string[] dims, Type dataType)
Invoke(null, new object[] { this, name, dims });
return v;
}

internal object ReadNetCdfAttribute(int varid, string aname, AttributeTypeMap atm)
{
NcType type;
Expand Down Expand Up @@ -1149,6 +1149,27 @@ public void SetChunkSizes(int[] sizes)
internal int[] ChunkSizes { get { return chunkSizes; } }

#endregion

/// <summary>
/// Create a new Dimension of length N (N = 0 unlimited)
/// </summary>
public void CreateDimension(string dim, int len)
{
int res;
int id;
res = NetCDF.nc_inq_dimid(this.NcId, dim, out id);
if (res == (int)ResultCode.NC_EBADDIM)
{
StartChanges();
res = NetCDF.nc_def_dim(this.NcId, dim, new IntPtr(len), out id);
Commit();
HandleResult(res);
}
else
{
HandleResult(res);
}
}
}

internal class AttributeTypeMap
Expand Down
25 changes: 19 additions & 6 deletions ScientificDataSet/Providers/NetCDF/NetCdfVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,26 @@ internal static NetCdfVariable<DataType> Create(NetCDFDataSet dataSet, string na

/* Getting exsting dims and creating new */
int[] dimids = new int[dims.Length];
int[] dimlen = new int[dims.Length];
for (int i = 0; i < dims.Length; i++)
{
int id;
res = NetCDF.nc_inq_dimid(dataSet.NcId, dims[i], out id);
if (res == (int)ResultCode.NC_NOERR)
{
IntPtr lenp;
res = NetCDF.nc_inq_dimlen(dataSet.NcId, id, out lenp);
NetCDFDataSet.HandleResult(res);
dimids[i] = id;
dimlen[i] = lenp.ToInt32();
}
else if (res == (int)ResultCode.NC_EBADDIM)
{
// Creating new dimension
res = NetCDF.nc_def_dim(dataSet.NcId, dims[i], new IntPtr(NcConst.NC_UNLIMITED), out id);
NetCDFDataSet.HandleResult(res);
dimids[i] = id;
dimlen[i] = NcConst.NC_UNLIMITED;
}
else
{
Expand Down Expand Up @@ -197,7 +203,14 @@ internal static NetCdfVariable<DataType> Create(NetCDFDataSet dataSet, string na

for (int i = 0; i < dims.Length; i++)
{
chunksizes[i] = new IntPtr(chunk);
if (dimlen[i] < chunk)
{
chunksizes[i] = new IntPtr(dimlen[i]);
}
else
{
chunksizes[i] = new IntPtr(chunk);
}
}
}

Expand Down Expand Up @@ -339,7 +352,7 @@ private int NcId
#region Transactions

/// <summary>
///
///
/// </summary>
/// <param name="proposedChanges"></param>
internal protected override void OnPrecommit(Variable.Changes proposedChanges)
Expand Down Expand Up @@ -381,7 +394,7 @@ internal protected override void OnPrecommit(Variable.Changes proposedChanges)
* Common netCDF model supports for only one such attribute,
* so all others CS except first are not compatible with that model.
* Their attribute names are "coordinates2","coordinates3" etc.
* Names of coordinate systems are provided with corresponed
* Names of coordinate systems are provided with corresponed
* attributes "coordinatesName","coordinates2Name",...
*/
if (proposedChanges.CoordinateSystems != null)
Expand Down Expand Up @@ -642,7 +655,7 @@ private static Array ToMultidimArrayDateTime(double[] ncArray, int[] shape)
#region Data Access

/// <summary>
///
///
/// </summary>
/// <returns></returns>
protected override int[] ReadShape()
Expand Down Expand Up @@ -698,7 +711,7 @@ private IntPtr[] ConvertToIntPtr(int[] array)
return result;
}
/// <summary>
///
///
/// </summary>
/// <param name="origin"></param>
/// <param name="shape"></param>
Expand Down Expand Up @@ -973,7 +986,7 @@ protected override Array ReadData(int[] origin, int[] stride, int[] shape)
}
}
/// <summary>
///
///
/// </summary>
/// <param name="origin"></param>
/// <param name="a"></param>
Expand Down