예제 #1
0
        /** 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 + "毫秒");
        }
예제 #2
0
        private H4Vdata LoadVdata(int file_id, int vdata_ref)
        {
            StringBuilder vdata_name  = new StringBuilder();
            StringBuilder vdata_class = new StringBuilder();
            StringBuilder fields;
            int           vdata_id = -1, istat, vdata_tag;
            int           n_records, interlace, vdata_size;

            try
            {
                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);
                vdata_tag = HDF4API.VSQuerytag(vdata_id);
                //HDF4API.VSgetinterlace(vdata_id);
                //HDF4API.VSsizeof(vdata_id, char *field_name_list);
                //HDF4API.VSgetname(vdata_id, vdata_name);
                H4Vdata vdata = new H4Vdata(this, vdata_name.ToString(), null, new long[] { 0, vdata_ref });
                vdata.Vdata_ref  = vdata_ref;
                vdata.Vdata_id   = vdata_id;
                vdata.N_records  = n_records;
                vdata.Interlace  = interlace;
                vdata.Fields     = fields.ToString().Split(',');
                vdata.Vdata_size = vdata_size;
                vdata.Vdata_name = vdata_name.ToString();
                vdata.Vdata_tag  = vdata_tag;
                _vdatas.Add(vdata);
                return(vdata);
            }
            finally
            {
                if (vdata_id >= 0)
                {
                    HDF4API.VSdetach(vdata_id);
                }
            }
        }
예제 #3
0
 internal void AddVdata(H4Vdata vdata)
 {
     _vdatas.Add(vdata);
 }
예제 #4
0
        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);
        }