Exemplo n.º 1
0
        /// <summary>
        /// Read out the entire variable from the file
        /// </summary>
        /// <param name="ncVariable"></param>
        /// <returns></returns>
        public Array Read(NetCdfVariable ncVariable)
        {
            var type  = GetDataType(ncVariable);
            var size  = GetSize(ncVariable);
            var shape = GetShape(ncVariable);

            switch (type)
            {
            case NetCdfDataType.NC_BYTE:
                var byteArray = new byte[size];
                CheckResult(NetCdfWrapper.nc_get_var(id, ncVariable, byteArray));
                return(NetCdfFileHelper.CreateArrayFromShape(byteArray, shape));

            case NetCdfDataType.NC_CHAR:
                var charArray = new byte[size];
                CheckResult(NetCdfWrapper.nc_get_var_text(id, ncVariable, charArray));
                return(NetCdfFileHelper.CreateCharArrayFromShape(charArray, shape));

            case NetCdfDataType.NC_INT:
                var intArray = new int[size];
                CheckResult(NetCdfWrapper.nc_get_var_int(id, ncVariable, intArray));
                return(NetCdfFileHelper.CreateArrayFromShape(intArray, shape));

            case NetCdfDataType.NC_FLOAT:
                var floatArray = new float[size];
                CheckResult(NetCdfWrapper.nc_get_var_float(id, ncVariable, floatArray));
                return(NetCdfFileHelper.CreateArrayFromShape(floatArray, shape));

            case NetCdfDataType.NC_DOUBLE:
                var doubleArray = new double[size];
                CheckResult(NetCdfWrapper.nc_get_var_double(id, ncVariable, doubleArray));
                return(NetCdfFileHelper.CreateArrayFromShape(doubleArray, shape));

            default:
                throw new Exception(
                          String.Format("Unknown type for reading NetCDF variable from file: type {0} from file {1}",
                                        type, path));
            }
        }