예제 #1
0
        public int next(TreedataInfo[] trees)
        {
            //            trees = new TreedataInfo[num];
            int num=Math.Min(totnhalos-current,trees.Length);
            for (int i = 0; i < num; i++)
            {
                    trees[i] = new TreedataInfo();
                    // skip descendant, firstProg, nextprog, firstfof, nextfof
                    treeReader.ReadBytes(20);
                    trees[i].length = treeReader.ReadInt32();
                    trees[i].M_Mean200 = treeReader.ReadSingle();
                    trees[i].M_Crit200 = treeReader.ReadSingle();
                    trees[i].M_TopHat = treeReader.ReadSingle();
                    trees[i].x = treeReader.ReadSingle();
                    trees[i].y = treeReader.ReadSingle();
                    trees[i].z = treeReader.ReadSingle();
                    trees[i].vx = treeReader.ReadSingle();
                    trees[i].vy = treeReader.ReadSingle();
                    trees[i].vz = treeReader.ReadSingle();
                    trees[i].VelDisp = treeReader.ReadSingle();
                    trees[i].Vmax = treeReader.ReadSingle();
                    trees[i].sx = treeReader.ReadSingle();
                    trees[i].sy = treeReader.ReadSingle();
                    trees[i].sz = treeReader.ReadSingle();
                    trees[i].mostboundid = treeReader.ReadInt64();
                    trees[i].snapnum = treeReader.ReadInt32();

                    trees[i].fileNr = treeReader.ReadInt32();
                    trees[i].subhaloindex = treeReader.ReadInt32();
                    trees[i].subhalfmass = treeReader.ReadSingle();

                    // read DB-IDs
                    trees[i].haloId = treeIdsReader.ReadInt64();
                    trees[i].treeid = treeIdsReader.ReadInt64();
                    trees[i].firstProgenitorId = treeIdsReader.ReadInt64();
                    trees[i].lastProgenitorId = treeIdsReader.ReadInt64();
                    trees[i].nextProgenitorId = treeIdsReader.ReadInt64();
                    trees[i].descendantId = treeIdsReader.ReadInt64();
                    trees[i].firstHaloInFOFGroupId = treeIdsReader.ReadInt64();
                    trees[i].nextHaloInFOFGroupId = treeIdsReader.ReadInt64();
                    if (process.hasMainLeafId)
                        trees[i].mainLeafId = treeIdsReader.ReadInt64();
                    else
                        trees[i].mainLeafId = -1L;
                    trees[i].redshift = (float)treeIdsReader.ReadDouble();
                    trees[i].phkey = treeIdsReader.ReadInt32(); // dummy ???
                    trees[i].dummy2 = treeIdsReader.ReadInt32(); // dummy ???

                    trees[i].fofId = -1L;
                    trees[i].subhaloFOFId = -1L;
                    trees[i].vMaxRad = 0;

                    trees[i].ix = process.GetZone(trees[i].x);
                    trees[i].iy = process.GetZone(trees[i].y);
                    trees[i].iz = process.GetZone(trees[i].z);
                    // could use dummy1 for this
            //                    int phkey = process.GetPHKey(trees[i].x, trees[i].y, trees[i].z);
            //                    if (phkey != trees[i].phkey)
            //                        DebugOut.PrintLine("PhKey incompatibility in halo " + i+", "+phkey+" vs. "+trees[i].phkey);
                    trees[i].phkey = process.GetPHKey(trees[i].x, trees[i].y, trees[i].z); ;
                    trees[i].RandomInt = process.globals.random.Next(process.globals.maxRandom);

                    trees[i].subhaloFileId = process.MakeSubhaloFileID(trees[i].snapnum, trees[i].fileNr, trees[i].subhaloindex);

                current++;
            }
            return num;
        }
예제 #2
0
        /// <summary>
        /// TODO update so that each tree is written immediately after the tree is read
        /// </summary>
        /// <param name="ivol"></param>
        public void ProcessTreedata(int ivol)
        {
            DebugOut.PrintLine("PROCESSING TREEDATA " + ivol);

            // and make the directory, just to be safe
            try
            {
                Directory.CreateDirectory(outPath);
            }
            catch (IOException e)
            {
                System.Console.WriteLine(e.Message);
            }

            //
            string treesFile = inPath+"\\"+treesPrefix+ivol;
            string treeIdsFile = inPath+"\\"+treeIdsPrefix+ivol;
            string treesOutFile = GetTreesOutFile(outPath, ivol);

            TreedataFile tdf = new TreedataFile(this, treesFile, treeIdsFile);
            DebugOut.PrintLine("Opened " + treesFile);
            DebugOut.PrintLine(" numtot =  "+ tdf.numtot );
            DebugOut.PrintLine(" ntrees =  " + tdf.ntrees);
            DebugOut.PrintLine(" totnhalos =  " + tdf.totnhalos);

            // post-process
            int count = 0;
            int step = 1000000;
            int totnhalos = tdf.totnhalos;
            TreedataInfo[] trees = new TreedataInfo[step];

            using (BinaryWriter binwriter = new BinaryWriter(
                new FileStream(GetTreesOutFile(outPath, ivol), FileMode.Create)))
            {
                while (true)
                {
                    int numRead = tdf.next(trees);
                    count += numRead;
                    for (int i = 0; i < numRead; i++)
                        trees[i].WriteBinary(binwriter);
                    DebugOut.PrintLine("Read and wrote " + numRead + " tree halos");
                    if (numRead < step)
                        break;
                }

                DebugOut.PrintLine("Read and wrote total " + count + " tree halos (expected " + totnhalos+")");
            }
            tdf.Close();
            // and add a bulk insert
            DebugOut.AddCommand(GetTreesOutFile(outPath, ivol), haloTreeTable);
        }