Exemplo n.º 1
0
    /*
     *  ReadOML
     *
     * Read an OML or ZML file.
     * Takes in the path of the file, an array of OilIDs, a reference to 3D particles, and a pointer to which record in the array
     * of OilIDs should be used.
     *
     * Copied whole-cloth from code originally provided by ASA.
     *
     */
    public static string ReadOML(string file,OilID[] recs, ref Particle3D[] parts, int trjver, int oilptr)
    {
        int fpos = 0;
        FileStream fs_oml = null;
        BinaryReader reader = null;
        try
        {
            fs_oml = File.Open(file,FileMode.Open,FileAccess.Read);
            reader = new BinaryReader(fs_oml);
            System.Array.Resize(ref parts, recs[oilptr].nRecs);

            fpos = (recs[oilptr].rec-1)*40;

            reader.BaseStream.Seek(fpos,SeekOrigin.Begin);

            for(int i = 0; i < recs[oilptr].nRecs;i++)
            {

                parts[i] = new Particle3D(reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadInt32(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle());
            }
            reader.Close();
            fs_oml.Close();
            fs_oml.Dispose();
        }
        catch (Exception ex)
        {
            return "Error: ReadOML: " + ex.Message;
        }
        finally
        {
            if(reader != null)
                reader.Close();
            if(fs_oml != null)
            {
                fs_oml.Close();
            }
        }
        return "READ OK";
    }
Exemplo n.º 2
0
    /**
     * ReadOMP
     * Read a .OMP or .ZMP binary file.  Takes in the path of the file and a reference to an OilID array
     * to populate the pointer records.
     * This function was pretty much written directly from provided code by ASA.
     *
     */
    public static string ReadOMP(string file, ref OilID[] refID)
    {
        int trjver;
        long numBytes = -1;
        int ntSteps = -1;
        FileStream fs = null;
        BinaryReader reader = null;
        int pos = 0;

        try
        {
            fs = File.Open(file,FileMode.Open,FileAccess.Read);
            numBytes = fs.Length;
            if(numBytes <= 0)
                return "Empty OMP file.";

            reader = new BinaryReader(fs);
            trjver = reader.ReadInt32(); // Get Traj version indicator
            if(trjver == 1002)
                ntSteps = Convert.ToInt32(numBytes/12)-1;
            else
            {
                fs.Close();
                return "Oilmap version is not supported";
            }
            pos = 12;
            reader.BaseStream.Seek(pos,SeekOrigin.Begin); // Jump ahead 12 bytes.
            System.Array.Resize(ref refID,ntSteps);

            for(int i = 0; i < ntSteps; i++)
            {
                // Read into an array, getting Index, Timestep, and Record#
                refID[i] = new OilID(reader.ReadInt32(),reader.ReadInt32(),reader.ReadInt32());
            }

            reader.Close();
            fs.Close();
            fs.Dispose();
        }
        catch (Exception ex)
        {
            return "Error: " + ex.Message;
        }
        finally
        {
            if(fs != null)
                fs.Close();
            if(reader != null)
                reader.Close();
        }
        return "OMP file read!";
    }