Пример #1
0
 public void PutVar(Int32[] index, byte[] dataValues, bool strictChecking=true) {
     CheckNull();
     CheckData();
     if(strictChecking){
         DimCheck(index.Length);
         if(dataValues.Length < 1)
             throw new exceptions.NcBufferOverflow("Value buffer must have at least 1 value");
     }
     if(GetNcType().GetTypeClass() == NcTypeEnum.NC_VLEN) {
         NcCheck.Check(NetCDF.nc_put_var1_vlen<byte>(groupId, myId, index, dataValues));
         return;
     }
     if(GetNcType().GetTypeClass() == NcTypeEnum.NC_OPAQUE) {
         NcOpaqueType tmp = new NcOpaqueType(GetNcType());
         if(strictChecking && dataValues.Length < tmp.GetTypeSize())
             throw new exceptions.NcBufferOverflow("Value buffer be at least as large as the opaque type size");
         NcCheck.Check(NetCDF.nc_put_var1(groupId, myId, index, dataValues));
         return;
     }
     if(NcChar.Instance.Equals(GetNcType()))
         NcCheck.Check(NetCDF.nc_put_var1_text(groupId, myId, index, dataValues));
     else
         NcCheck.Check(NetCDF.nc_put_var1_uchar(groupId, myId, index, dataValues));
 }
Пример #2
0
 public int GetVar(Int32[] index, byte[] dataValues, bool strictChecking=true) {
     CheckNull();
     CheckData();
     NcType type = GetNcType();
     NcTypeEnum typeClass = type.GetTypeClass();
     if(strictChecking) {
         DimCheck(index.Length);
         if(dataValues.Length < 1) 
             throw new exceptions.NcBufferOverflow("Array is not large enough to represent variable");
     }
     if(typeClass == NcTypeEnum.NC_VLEN) {
         byte[] buffer;
         NcCheck.Check(NetCDF.nc_get_var1_vlen(groupId, myId, index, out buffer));
         Array.Copy(buffer, dataValues, Math.Min(dataValues.Length, buffer.Length));
         return Math.Min(dataValues.Length, buffer.Length);
     }
     if(typeClass == NcTypeEnum.NC_OPAQUE) {
         NcOpaqueType tmp = new NcOpaqueType(type);
         if(strictChecking && dataValues.Length < tmp.GetTypeSize())
             throw new exceptions.NcBufferOverflow("Array is not large enough to represent variable");
         NcCheck.Check(NetCDF.nc_get_var1(groupId, myId, index, dataValues));
         return tmp.GetTypeSize();
     }
     NcCheck.Check(NetCDF.nc_get_var1_uchar(groupId, myId, index, dataValues));
     return 1;
 }
Пример #3
0
        public bool TestOpaque() {
            NcFile file = null;
            NcVar var = null;
            NcDim dim = null;
            NcType type = null;
            NcOpaqueType opaqueType = null;

            byte[] opaqueBuffer = new byte[32];
            byte[] readBuffer = new byte[32];
            for(int i=0;i<32;i++) opaqueBuffer[i] = (byte)i;

            try {
                file = TestHelper.NewFile(filePath);
                type = file.AddOpaqueType("opaque", 32);
                opaqueType = new NcOpaqueType(type);

                Assert.Equals(type.GetTypeClass(), NcTypeEnum.NC_OPAQUE);
                Assert.Equals(opaqueType.GetTypeSize(), 32);

                dim = file.AddDim("time", 1);
                var = file.AddVar("opaqueVar", opaqueType, dim);
                int iLen = 0;
                var.PutVar(new Int32[] { 0 }, opaqueBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, readBuffer);
                Assert.Equals(iLen, 32);
                for(int i=0;i<32;i++)
                    Assert.Equals(readBuffer[i], opaqueBuffer[i]);


            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return true;
        }