예제 #1
0
        private void ProcessSnapshot(short snap)
        {
            DebugOut.PrintLine("PROCESSING SNAPSHOT WITHOUT ARRAYS " + snap);
            // using this only if needed

            List <SnapFileSummary> results = new List <SnapFileSummary>();

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

            int curFile = firstSnapshotFile; // index of current read/write file
            int numFile = 0;

            if (lastSnapshotFile < firstSnapshotFile)
            {
                lastSnapshotFile = firstSnapshotFile;
                numFile          = -1;
            }
            while (curFile <= lastSnapshotFile)
            {
                //DebugOut.PrintLine("..file " + curFile + "/" + lastSnapshotFile);
                Console.WriteLine("..file " + curFile + "/" + lastSnapshotFile);
                SnapFileSummary currentFileSummary = new SnapFileSummary();
                results.Add(currentFileSummary);
                currentFileSummary.start = DateTime.Now;

                string filename = "";
                try
                {
                    filename = GetSnapFile(inPath, snap, snapshotFilePrefix, curFile);
                    currentFileSummary.inFileName = filename;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    currentFileSummary.badStatus     = true;
                    currentFileSummary.statusMessage = e.Message;
                    return;
                }

                // now load the file
                SnapFile curSnap = new SnapFile(filename);
                // and open the stream for writing
                using (BinaryWriter binwriter = new BinaryWriter(new FileStream(GetSnapDefault(outPath, snap, snapshotFilePrefix, curFile), FileMode.Create)))
                {
                    currentFileSummary.outFileName = GetSnapDefault(outPath, snap, snapshotFilePrefix, curFile);

                    Structs[] parts = new Structs[curSnap.numSample];
                    // now write each particle into the array
                    for (int i = 0; i < curSnap.numSample; i++)
                    {
                        parts[i].x       = curSnap.pos[i, 0];
                        parts[i].y       = curSnap.pos[i, 1];
                        parts[i].z       = curSnap.pos[i, 2];
                        parts[i].vx      = curSnap.vel[i, 0];
                        parts[i].vy      = curSnap.vel[i, 1];
                        parts[i].vz      = curSnap.vel[i, 2];
                        parts[i].snapnum = snap;
                        parts[i].id      = curSnap.id[i];
                        // add in highest-order bit
                        parts[i].id |= ((UInt64)curSnap.nLargeSims[1]) << 32;
                        // make ph-key
                        parts[i].phkey = GetPHKey(parts[i].x, parts[i].y, parts[i].z);
                        // read hsml, if desired
                    }
                    // now sort before writing files
                    Array.Sort <Structs>(parts, new ParticleComparator());
                    // and then write output
                    for (int i = 0; i < curSnap.numSample; i++)
                    {
                        parts[i].WriteBinaryNoHsml(binwriter);
                    }

                    // and add a bulk insert
                    //TODO sql commands file
                    DebugOut.AddCommand(GetSnapDefault(outPath, snap, snapshotFilePrefix, curFile), snapshotTable);

                    DebugOut.PrintLine("..wrote " + curSnap.numSample + "/" + curSnap.numTotals[1] + " points");
                }


                // and set numFiles
                if (numFile == -1)
                {
                    numFile          = (int)curSnap.numSubfiles - firstSnapshotFile + 1;
                    lastSnapshotFile = numFile - 1;
                }

                currentFileSummary.end          = DateTime.Now;
                currentFileSummary.duration     = results[curFile].start - results[curFile].end;
                currentFileSummary.numParticles = curSnap.numSample;

                curFile++;
                // avoid outofmemory errors
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            globals.summary.setFileSummaries(results);
        }
예제 #2
0
        private void ProcessSnapshotWithArrays(short snap)
        {
            //DebugOut.PrintLine("PROCESSING SNAPSHOT WITH ARRAYS" + snap);
            // using this only if needed

            List <SnapFileSummary> results = new List <SnapFileSummary>();

            //and make the directory, just to be safe
            try
            {
                Directory.CreateDirectory(outPath);
            }
            catch (IOException e)
            {
                globals.summary.addError(e.Message);
                return;
            }

            int curFile = firstSnapshotFile; // index of current read/write file
            int numFile = 0;

            if (lastSnapshotFile < firstSnapshotFile)
            {
                lastSnapshotFile = firstSnapshotFile;
                numFile          = -1;
            }

            while (curFile <= lastSnapshotFile)
            {
                //DebugOut.PrintLine("..file " + curFile + "/" + lastSnapshotFile);
                Console.WriteLine("..file " + curFile + "/" + lastSnapshotFile);
                SnapFileSummary currentFileSummary = new SnapFileSummary();
                results.Add(currentFileSummary);
                currentFileSummary.start      = DateTime.Now;
                currentFileSummary.fileNumber = curFile;

                string filename = "";
                try
                {
                    filename = GetSnapFile(inPath, snap, snapshotFilePrefix, curFile);
                    currentFileSummary.inFileName = filename;
                }

                catch (Exception e)
                {
                    currentFileSummary.badStatus     = true;
                    currentFileSummary.statusMessage = e.Message;
                    globals.summary.setFileSummaries(results);
                    return;
                }
                // now load the file
                try
                {
                    SnapFile curSnap = new SnapFile(filename);
                    // and open the stream for writing
                    using (SqlBinaryWriter binwriter = new SqlBinaryWriter(new FileStream(GetSnapDefault(outPath, snap, snapshotFilePrefix, curFile), FileMode.Create)))
                    {
                        Structs[] parts = new Structs[curSnap.numSample];
                        //record destination path in file summary
                        currentFileSummary.outFileName = GetSnapDefault(outPath, snap, snapshotFilePrefix, curFile);
                        // now write each particle into the array
                        for (int i = 0; i < curSnap.numSample; i++)
                        {
                            parts[i].x       = curSnap.pos[i, 0];
                            parts[i].y       = curSnap.pos[i, 1];
                            parts[i].z       = curSnap.pos[i, 2];
                            parts[i].vx      = curSnap.vel[i, 0];
                            parts[i].vy      = curSnap.vel[i, 1];
                            parts[i].vz      = curSnap.vel[i, 2];
                            parts[i].snapnum = snap;
                            parts[i].id      = curSnap.id[i];
                            // add in highest-order bit
                            parts[i].id |= ((UInt64)curSnap.nLargeSims[1]) << 32;
                            // make ph-key
                            parts[i].phkey = GetPHKey(parts[i].x, parts[i].y, parts[i].z);
                        }
                        // now sort before writing files
                        // TODO
                        //TBD this may not be necessary if the particles
                        // are sorted in the files already.
                        Array.Sort <Structs>(parts, new ParticleComparator());

                        Cell cell         = new Cell(snap);
                        int  currentPHkey = -1;
                        for (int i = 0; i < curSnap.numSample; i++)
                        {
                            if (parts[i].phkey != currentPHkey)
                            {
                                if (cell.Count > 0)
                                {
                                    binwriter.WriteCell(cell);
                                }
                                currentPHkey = parts[i].phkey;
                                cell.Init(currentPHkey);
                            }
                            cell.AddToCell(parts[i]);
                        }
                        if (cell.Count > 0)
                        {
                            binwriter.WriteCell(cell);
                        }


                        // and add a bulk insert
                        //DebugOut.AddCommand(GetSnapDefault(outPath, snap, snapshotFilePrefix, curFile), snapshotTable);
                        Console.WriteLine("..wrote " + curSnap.numSample + "/" + curSnap.numTotals[1] + " points");
                        DebugOut.PrintLine("..wrote " + curSnap.numSample + "/" + curSnap.numTotals[1] + " points");
                    }


                    // and set numFiles
                    if (numFile == -1)
                    {
                        numFile          = (int)curSnap.numSubfiles - firstSnapshotFile;
                        lastSnapshotFile = (int)curSnap.numSubfiles - 1;
                    }

                    currentFileSummary.end          = DateTime.Now;
                    currentFileSummary.duration     = results[curFile].end - results[curFile].start;
                    currentFileSummary.numParticles = curSnap.numSample;

                    if (curSnap.numSample < (int)(0.01 * LoaderConstants.particlesPerSnap))
                    {
                        currentFileSummary.warning        = true;
                        currentFileSummary.warningMessage = "Less than 1% of particles in snapshot in this file";
                    }
                    if (curSnap.numSample > LoaderConstants.particlesPerSnap)
                    {
                        currentFileSummary.warning        = true;
                        currentFileSummary.warningMessage = "More particles in file than are supposed to be in snapshot";
                    }

                    if (currentFileSummary.outFileName != null)
                    {
                        globals.summary.AddSnapBCPCommand(currentFileSummary.outFileName);
                    }
                    curFile++;
                    // avoid outofmemory errors
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                catch (Exception e)
                {
                    currentFileSummary.badStatus     = true;
                    currentFileSummary.statusMessage = e.Message;
                    globals.summary.setFileSummaries(results);
                    return;
                }
            }
            globals.summary.setFileSummaries(results);
        }