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(); } } }
public unsafe void TestVData() { StringBuilder vdata_name = new StringBuilder(); StringBuilder vdata_class = new StringBuilder(); StringBuilder fields; int file_id, vdata_id, istat; int n_records, interlace, vdata_size, vdata_ref; string filename = @"E:\Smart\CloudArgs\cloudsat\2007101034511_05065_CS_2B-GEOPROF_GRANULE_P_R04_E02.hdf"; file_id = HDF4API.Hopen(filename, DFACC.DFACC_READ, 0); istat = HDF4API.Vstart(file_id); vdata_ref = -1; vdata_ref = HDF4API.VSgetid(file_id, vdata_ref); vdata_id = HDF4API.VSattach(file_id, vdata_ref, "r"); fields = new StringBuilder(60); istat = HDF4API.VSinquire(vdata_id, out n_records, out interlace, fields, out vdata_size, vdata_name); istat = HDF4API.VSgetclass(vdata_id, vdata_class); istat = HDF4API.VSsetfields(vdata_id, fields.ToString()); //fixed (float* bp = databuf) //{ // IntPtr ptr = (IntPtr)bp; // istat = HDF4API.VSread(vdata_id, ptr, n_records, INTERLACE_MODE.FULL_INTERLACE); //} IntPtr ptr = Marshal.AllocHGlobal(n_records * vdata_size * 8); //GCHandle handle = GCHandle.Alloc(databuf); istat = HDF4API.VSread(vdata_id, ptr, n_records, INTERLACE_MODE.FULL_INTERLACE); //handle.Free(); float[] databuf = new float[vdata_size]; Marshal.Copy(ptr, databuf, 0, vdata_size); Marshal.FreeHGlobal(ptr); istat = HDF4API.VSdetach(vdata_id); istat = HDF4API.Vend(file_id); istat = HDF4API.Hclose(file_id); Console.WriteLine(istat); }