private void LoadVgroups(int file_id) { int vgroup_ref = -1; int[] lone_array = new int[HDFConstants.NLONE]; int lone_count; // get top level VGroup int[] tmpN = new int[HDFConstants.NLONE]; try { // first call to get the number of lone Vgroup lone_count = HDF4API.Vlone(file_id, tmpN, HDFConstants.NLONE); lone_array = new int[lone_count]; // second call to get the references of all lone Vgroup lone_count = HDF4API.Vlone(file_id, lone_array, lone_count); } catch (Exception ex) { Console.WriteLine(ex.Message); lone_count = 0; return; } Console.WriteLine(lone_count); List <H4Vgroup> vgroups = new List <H4Vgroup>(); for (int i = 0; i < lone_count; i++) { vgroup_ref = lone_array[i]; H4Vgroup vgroup = LoadVgroup(file_id, vgroup_ref, null); Console.WriteLine(vgroup); vgroups.Add(vgroup); } //while ((vgroup_ref = HDF4API.Vgetid(file_id, vgroup_ref)) != HDFConstants.FAIL) //{ // if ((vgroup_id = HDF4API.Vattach(file_id, vgroup_ref, "r")) == HDFConstants.FAIL) // break; // vgroup_class = new StringBuilder(HDFConstants.VGCLASSLENMAX); // vgroup_name = new StringBuilder(HDFConstants.VGNAMELENMAX); // status = HDF4API.Vgetname(vgroup_id, vgroup_name); // status = HDF4API.Vgetclass(vgroup_id, vgroup_class); /* get Vgroup classname */ // int ntag = HDF4API.Vntagrefs(vgroup_id); //} _vgroups = vgroups.ToArray(); //status = HDF4API.Vdetach(vgroup_id); //status = HDF4API.Vend(file_id); //status = HDF4API.Hclose(file_id); }
internal void AddVgroup(H4Vgroup vgroup) { _vgroups.Add(vgroup); }
private H4Vgroup LoadVgroup(int file_id, int vgroup_ref, H4Vgroup pgroup) { int vgroup_id = 0; int vgroup_tag = 0; int n_vgroup_attr = 0; int n_entries = 0; int n_tagrefs = 0; int[] tag_array = new int[HDFConstants.NLONE]; int[] ref_array = new int[HDFConstants.NLONE]; StringBuilder vgroup_class = null; StringBuilder vgroup_name = null; vgroup_id = HDF4API.Vattach(file_id, vgroup_ref, "r"); vgroup_tag = HDF4API.VQuerytag(vgroup_id); vgroup_class = new StringBuilder(HDFConstants.VGCLASSLENMAX); vgroup_name = new StringBuilder(HDFConstants.VGNAMELENMAX); status = HDF4API.Vgetclass(vgroup_id, vgroup_class); if ((status = HDF4API.Vinquire(vgroup_id, out n_entries, vgroup_name)) == HDFConstants.FAIL)//整个文件fullname也会作为一个lone的group,这时vgroup_name是带路径的文件全名fullname { HDF4API.Vdetach(vgroup_id); return(null); } // ignore the Vgroups created by the GR interface if (string.Equals(vgroup_class.ToString(), HDFConstants.GR_NAME, StringComparison.OrdinalIgnoreCase) ||// do not display Vdata named "Attr0.0" string.Equals(vgroup_class.ToString(), HDFConstants.RI_NAME, StringComparison.OrdinalIgnoreCase) || string.Equals(vgroup_class.ToString(), HDFConstants.RIGATTRNAME, StringComparison.OrdinalIgnoreCase) || string.Equals(vgroup_class.ToString(), HDFConstants.RIGATTRCLASS, StringComparison.OrdinalIgnoreCase) || string.Equals(vgroup_class.ToString(), HDFConstants.HDF_CDF, StringComparison.OrdinalIgnoreCase) ) { HDF4API.Vdetach(vgroup_id); return(null); } n_vgroup_attr = HDF4API.Vnattrs(vgroup_id); n_tagrefs = HDF4API.Vntagrefs(vgroup_id); H4Vgroup vgroup = new H4Vgroup(this, vgroup_name.ToString(), "/", pgroup, new long[] { vgroup_tag, vgroup_ref }); vgroup.Vgroup_ref = vgroup_ref; vgroup.Vgroup_id = vgroup_id; vgroup.Vgroup_tag = vgroup_tag; vgroup.Vgroup_name = vgroup_name.ToString(); vgroup.Vgroup_class = vgroup_class.ToString(); vgroup.N_attrs = n_vgroup_attr; vgroup.N_entries = n_entries; vgroup.N_tagrefs = n_tagrefs; if (n_tagrefs == 0) { if ((status = HDF4API.Vdetach(vgroup_id)) == HDFConstants.FAIL) { return(null); } return(vgroup); } int tag = 0; int ref_id = 0; int sds_index = 0; for (int index = 0; index < n_tagrefs; index++) { if ((status = HDF4API.Vgettagref(vgroup_id, index, out tag, out ref_id)) == HDFConstants.FAIL) { //Vdetach( break; } switch (tag) { case HDFConstants.DFTAG_VG: H4Vgroup vg = LoadVgroup(file_id, ref_id, vgroup); Console.WriteLine(vg); vgroup.AddVgroup(vg); break; case HDFConstants.DFTAG_VH: case HDFConstants.DFTAG_VS: { H4Vdata vdata = LoadVdata(file_id, ref_id); Console.WriteLine(vdata); vgroup.AddVdata(vdata); break; } case HDFConstants.DFTAG_NDG: //数据集 case HDFConstants.DFTAG_SDG: case HDFConstants.DFTAG_SD: { try { sds_index = HDF4API.SDreftoindex(_sd_id, ref_id); } catch (Exception ex) { sds_index = HDFConstants.FAIL; } if (sds_index != HDFConstants.FAIL) { //H4SDS sds = getSDS(tag, index, fullPath, true); //pgroup.addToMemberList(sds); //if ((sds != null) && (pnode != null)) //{ // node = new DefaultMutableTreeNode(sds); // pnode.add(node); //} } Console.WriteLine(string.Format("TAG:{0},{1},{2}", tag, ref_id, sds_index)); H4SDS sd = H4SDS.Load(_sd_id, sds_index); vgroup.AddVdata(sd); Console.WriteLine(sd); } break; case HDFConstants.DFTAG_RIG: case HDFConstants.DFTAG_RI: case HDFConstants.DFTAG_RI8: #region //try //{ // index = HDF4API.GRreftoindex(grid, (short) ref); //} //catch (Exception ex) //{ // index = HDFConstants.FAIL; //} //if (index != HDFConstants.FAIL) //{ // H4GRImage gr = getGRImage(tag, index, fullPath, true); // pgroup.addToMemberList(gr); // if ((gr != null) && (pnode != null)) // { // node = new DefaultMutableTreeNode(gr); // pnode.add(node); // } //} #endregion break; default: Console.WriteLine(string.Format("TAG:{0},{1},{2}", tag, ref_id, index)); break; } /* end of switch */ //if (ret != NO_OBJECT) break; } /* end of for loop */ if ((status = HDF4API.Vdetach(vgroup_id)) == HDFConstants.FAIL) { return(null); } return(vgroup); }