public void Dispose() { if (_file_id != -1) { //释放内存 } int istat = HDF4Helper.SDend(_sd_id); istat = HDF4API.Vend(_file_id); istat = HDF4API.Hclose(_file_id); if (_datasets != null) { foreach (H4SDS sds in _datasets) { sds.Dispose(); } } if (_vdatas != null) { foreach (H4Vdata vdata in _vdatas) { vdata.Dispose(); } } }
private void GetFileAttrInfos(FileListItem fli) { if (HDF4Helper.IsHdf4(fli.FileName)) { Hdf4Operator oper = new Hdf4Operator(fli.FileName); try { Dictionary <string, string> fileAtrr = null; if (oper != null) { fileAtrr = oper.GetAttributes(); if (fileAtrr != null) { InitFileAttr(fileAtrr); } else { ClearFileAtrr(); } InitDataset(oper.GetDatasetNames, oper); } } catch (Exception ex) { AddLog(fli.FileName + "文件读取失败:" + ex.Message); } finally { if (oper != null) { oper.Dispose(); } } } }
public void Load(string filename, DFACC dfacc) { sw.Start(); _filename = filename; int file_id, sd_id; try { _fileOpenState = false; file_id = HDF4API.Hopen(filename, DFACC.DFACC_READ, 0); HDF4API.Vstart(file_id); //_gr_id = HDF4API.GRstart(file_id); } catch { string strErrInfo = "HDF4打开文件异常"; throw new Exception(strErrInfo); } _fileOpenState = true; sd_id = HDF4Helper.SDstart(filename, HDF4Helper.AccessCodes.DFACC_READ); if (sd_id == -1) { //打开失败 } _file_id = file_id; _sd_id = sd_id; sw.Stop(); em = sw.ElapsedMilliseconds; Console.WriteLine("打开" + em + "毫秒"); // load the file hierarchy getRootGroup(); }
public override bool IsSupport(string fname, byte[] header1024, Dictionary <string, string> datasetNames) { string ext = Path.GetExtension(fname).ToUpper(); if (ext != ".HDF" || !HDF4Helper.IsHdf4(header1024)) { return(false); } return(HasDatasets(fname)); }
public void Close(int sds_id) { try { HDF4Helper.SDendaccess(sds_id); } catch { Console.WriteLine("Error,SDendaccess:" + sds_id); } }
public override bool IsSupport(string fname, byte[] header1024, Dictionary <string, string> datasetNames) { string ext = Path.GetExtension(fname).ToUpper(); if (ext != ".HDF" || !HDF4Helper.IsHdf4(header1024)) { return(false); } TryGetBandProviderDefinition(fname, datasetNames); return(_matchedBandProviderDef != null); }
/** get the root group and all the alone objects */ private void getRootGroup() { sw.Restart(); //LoadVgroups(_file_id);//暂时取消加载整个树结构,目前这个加载比较慢,暂时也用不着。 sw.Stop(); em = sw.ElapsedMilliseconds; Console.WriteLine("LoadVgroups" + em + "毫秒"); sw.Restart(); int num_ds = 0; int num_global = 0; status = HDF4Helper.SDfileinfo(_sd_id, out num_ds, out num_global); _num_datasets = num_ds; _num_global_attrs = num_global; for (int i = 0; i < num_ds; i++) { H4SDS ds = H4SDS.Load(_sd_id, i); _datasets.Add(ds); } for (int i = 0; i < num_global; i++) { HDFAttribute global_attr = HDFAttribute.Load(_sd_id, i); _global_attrs.Add(global_attr); } sw.Stop(); em = sw.ElapsedMilliseconds; Console.WriteLine("SDfileinfo" + em + "毫秒"); sw.Restart(); //Finding All Vdatas that are Not Members of a Vgroup: VSlone //初始化Vdata(读取表格数据,表格列名称参数) int[] ref_array = new int[1024]; HDF4API.VSlone(_file_id, ref_array, 1024); //初始化Vdata(读取表格数据,表格列名称参数) istat; int vdata_ref; int istat = HDF4API.Vstart(_file_id); vdata_ref = -1; List <H4Vdata> vdatas = new List <H4Vdata>(); while ((vdata_ref = HDF4API.VSgetid(_file_id, vdata_ref)) != HDFConstants.FAIL) { H4Vdata vdata = LoadVdata(_file_id, vdata_ref); vdatas.Add(vdata); } _vdatas = vdatas; sw.Stop(); em = sw.ElapsedMilliseconds; Console.WriteLine("VSlone" + em + "毫秒"); }
private IHdfOperator HdfOperatorFactory(string filename) { if (HDF5Helper.IsHdf5(filename)) { return(new Hdf5Operator(filename)); } if (HDF4Helper.IsHdf4(filename)) { return(new Hdf4Operator(filename)); } return(null); }
private void lstDataSets_SelectedIndexChanged(object sender, EventArgs e) { ClearDataSetCombox(); if (lstDataSets.SelectedItems.Count == 0 || lstDataSets.SelectedItems[0].Tag == null || lstFileInfoList.SelectedItems.Count == 0 || (lstFileInfoList.SelectedItems[0]).Tag == null) { return; } FileListItem fli = (lstFileInfoList.SelectedItems[0]).Tag as FileListItem; DataSetMosaicInfo dsi = lstDataSets.SelectedItems[0].Tag as DataSetMosaicInfo; if (fli == null) { return; } if (HDF4Helper.IsHdf4(fli.FileName)) { Hdf4Operator oper = new Hdf4Operator(fli.FileName); try { Dictionary <string, string> datasetAtrr = new Dictionary <string, string>(); if (oper != null) { datasetAtrr = oper.GetAttributes(dsi.DataSetName); if (datasetAtrr != null) { InitDataSetAttr(datasetAtrr, ref dsi); } Size size = Size.Empty; int bandCount = 0; Type datatype; int datatypeSize = 0; HDF4Helper.DataTypeDefinitions hdf4DataType = HDF4Helper.DataTypeDefinitions.DFNT_NUINT16; if (GetDataSetSize(dsi.DataSetName, oper, out size, out bandCount, out hdf4DataType, out datatype, out datatypeSize)) { InitHeigthWidth(size.Width, size.Height, bandCount, ref dsi); if (dsi != null) { dsi.HDF4DataType = hdf4DataType; } } } } finally { if (oper != null) { oper.Dispose(); } } } }
protected override bool IsCompatible(string fileName, byte[] header1024, params object[] args) { if (args == null || args.Length == 0) { return(false); } string ext = Path.GetExtension(fileName).ToUpper(); if (ext != ".HDF" || !HDF4Helper.IsHdf4(header1024)) { return(false); } return(true); }
public static HDFAttribute Load(int sd_id, int attr_index) { int status = 0; StringBuilder attr_name = new StringBuilder(); GeoDo.HDF4.HDF4Helper.DataTypeDefinitions data_type; int count; status = HDF4Helper.SDattrinfo(sd_id, attr_index, attr_name, out data_type, out count); HDFAttribute ds = new HDFAttribute(); ds._sd_id = sd_id; ds._attr_index = attr_index; ds._name = attr_name.ToString(); ds._data_type = data_type; ds._count = count; return(ds); }
/// <summary> /// 读取数据集值 /// </summary> /// <param name="start"></param> /// <param name="stride"></param> /// <param name="edges"></param> /// <param name="?"></param> /// <returns></returns> public bool Read(int[] start, int[] stride, int[] edges, IntPtr ptr) { int sds_id = -1; try { sds_id = Open(); if (sds_id == -1) { return(false); } int status = 0; status = HDF4Helper.SDreaddata(sds_id, start, stride, edges, ptr); return(true); } finally { Close(sds_id); } }
public static bool IsSupport(string filename, byte[] header1024) { bool status = false; if (header1024 != null) { status = HDF4Helper.IsHdf4(header1024); } else { status = HDF4Helper.IsHdf4(filename); } if (status) { DateTime dt; string ptname; status = TryParseFileName(filename, out dt, out ptname); } return(status); }
public static bool IsCompatible(string fileName, byte[] header1024) { if (header1024 == null) { header1024 = new byte[1024]; using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { fs.Read(header1024, 0, 1024); fs.Close(); } } if (!HDF5Helper.IsHdf5(header1024) && !HDF4Helper.IsHdf4(header1024)) { return(false); } L2ProductDefind[] l2Pros = L2ProductDefindParser.GetL2ProductDefs(fileName); if (l2Pros == null || l2Pros.Length == 0) { return(false); } return(true); }
public static H4SDS Load(int sd_id, int sds_index) { int status = 0; int sds_id = 0; int sds_ref = 0; StringBuilder sds_name = new StringBuilder(); int rank = 0; int[] dimsizes = new int[MAX_DIMSIZES]; HDF4Helper.DataTypeDefinitions datatype; int num_attrs = 0; sds_id = H4SDAPI.SDselect(sd_id, sds_index); sds_ref = HDF4API.SDidtoref(sds_id); int sds_index2 = HDF4API.SDreftoindex(sd_id, sds_ref); //HDF4Helper.SDreaddata status = HDF4Helper.SDgetinfo(sds_id, sds_name, out rank, dimsizes, out datatype, out num_attrs); status = HDF4Helper.SDendaccess(sds_id); int[] dims = new int[rank]; for (int i = 0; i < rank; i++) { dims[i] = dimsizes[i]; } H4SDS ds = new H4SDS(); ds._sd_id = sd_id; ds._sds_ref = sds_ref; ds._sds_id = sds_id; ds._sds_name = sds_name.ToString(); ds._rank = rank; ds._dimsizes = dims; ds._datatype = datatype; ds._num_attrs = num_attrs; return(ds); }
public int Open() { int id = -1; try { int index = 0; //int tag = (int)oid[0]; //if (tag == H4SDS.DFTAG_NDG_NETCDF) //{ // index = (int)oid[1]; //HDFLibrary.SDidtoref(id) fails for netCDF //} //else //{ index = HDF4API.SDreftoindex(_sd_id, _sds_ref);//(int)oid[1] //} id = HDF4Helper.SDselect(_sd_id, index); } catch (Exception ex) { id = -1; } return(id); }
private void GetValue() { int status = 0; switch (_data_type) { case HDF4Helper.DataTypeDefinitions.DFNT_CHAR8: //string //case HDF4Helper.DataTypeDefinitions.DFNT_CHAR: case HDF4Helper.DataTypeDefinitions.DFNT_UCHAR8: //case HDF4Helper.DataTypeDefinitions.DFNT_UCHAR: { IntPtr ptr = Marshal.AllocHGlobal(_count * 8); status = HDF4Helper.SDreadattr(_sd_id, _attr_index, ptr); var buffer = new byte[_count]; Marshal.Copy(ptr, buffer, 0, _count); Marshal.FreeHGlobal(ptr); _value = Encoding.ASCII.GetString(buffer); //new ASCIIEncoding() } break; case HDF4Helper.DataTypeDefinitions.DFNT_INT8: case HDF4Helper.DataTypeDefinitions.DFNT_UINT8: { IntPtr ptr = Marshal.AllocHGlobal(_count * 8); status = HDF4Helper.SDreadattr(_sd_id, _attr_index, ptr); var buffer = new byte[_count]; Marshal.Copy(ptr, buffer, 0, _count); Marshal.FreeHGlobal(ptr); _value = buffer; } break; case HDF4Helper.DataTypeDefinitions.DFNT_INT16: case HDF4Helper.DataTypeDefinitions.DFNT_UINT16: { IntPtr ptr = Marshal.AllocHGlobal(_count * 16); status = HDF4Helper.SDreadattr(_sd_id, _attr_index, ptr); var buffer = new short[_count]; Marshal.Copy(ptr, buffer, 0, _count); Marshal.FreeHGlobal(ptr); _value = buffer; } break; case HDF4Helper.DataTypeDefinitions.DFNT_INT32: case HDF4Helper.DataTypeDefinitions.DFNT_UINT32: { IntPtr ptr = Marshal.AllocHGlobal(_count * 32); status = HDF4Helper.SDreadattr(_sd_id, _attr_index, ptr); var buffer = new int[_count]; Marshal.Copy(ptr, buffer, 0, _count); Marshal.FreeHGlobal(ptr); _value = buffer; } break; case HDF4Helper.DataTypeDefinitions.DFNT_FLOAT32: { IntPtr ptr = Marshal.AllocHGlobal(_count * 32); status = HDF4Helper.SDreadattr(_sd_id, _attr_index, ptr); var buffer = new float[_count]; Marshal.Copy(ptr, buffer, 0, _count); Marshal.FreeHGlobal(ptr); _value = buffer; } break; case HDF4Helper.DataTypeDefinitions.DFNT_FLOAT64: { IntPtr ptr = Marshal.AllocHGlobal(_count * 64); status = HDF4Helper.SDreadattr(_sd_id, _attr_index, ptr); var buffer = new double[_count]; Marshal.Copy(ptr, buffer, 0, _count); Marshal.FreeHGlobal(ptr); _value = buffer; } break; case HDF4Helper.DataTypeDefinitions.DFNT_NINT8: break; case HDF4Helper.DataTypeDefinitions.DFNT_NUINT8: break; case HDF4Helper.DataTypeDefinitions.DFNT_NINT16: break; case HDF4Helper.DataTypeDefinitions.DFNT_NUINT16: break; case HDF4Helper.DataTypeDefinitions.DFNT_NINT32: break; case HDF4Helper.DataTypeDefinitions.DFNT_NUINT32: break; case HDF4Helper.DataTypeDefinitions.DFNT_NFLOAT32: break; case HDF4Helper.DataTypeDefinitions.DFNT_NFLOAT64: break; default: break; } }
public HObject Get(string path) { //if (objList == null) { // objList = new Vector(); //} if (string.IsNullOrWhiteSpace(path)) { return(null); } path = path.Replace('\\', '/'); if (!path.StartsWith("/")) { path = "/" + path; } string name = null, pPath = null; bool isRoot = false; if (path.Equals("/")) { name = "/"; // the root isRoot = true; } else { if (path.EndsWith("/")) { path = path.Substring(0, path.Length - 2); } int idx = path.LastIndexOf('/'); name = path.Substring(idx + 1); if (idx == 0) { pPath = "/"; } else { pPath = path.Substring(0, idx); } } HObject obj = null; bool isReadOnly = false; if (_file_id < 0) { _file_id = HDF4API.Hopen(_filename, DFACC.DFACC_WRITE, 0); if (_file_id < 0) { isReadOnly = true; _file_id = HDF4API.Hopen(_filename, DFACC.DFACC_READ, 0); } HDF4API.Vstart(_file_id); //grid = HDF4API.GRstart(_file_id); _sd_id = HDF4Helper.SDstart(_filename, HDF4Helper.AccessCodes.DFACC_READ); } //if (isRoot) //{ // obj = getRootGroup(); //} //else //{ // obj = getAttachedObject(pPath, name); //} return(obj); }