public static PrimaryStructureTrajectory GetTrajectory(string filename, int startFrame, int numFrames, int frameFrequency)
        {
            StreamReader sr = null;
            PrimaryStructureTrajectory trajectory = new PrimaryStructureTrajectory();

            try {
                sr = new StreamReader(filename);

                // discard first frame, which should be the structure
                getFrame(sr); // discard frame

                for (int i = 0; i < startFrame; i++)
                {
                    getFrame(sr); // discard frame
                }

                int framesAdded  = 0;
                int currentFrame = 0;

                while (framesAdded < numFrames)
                {
                    currentFrame++;

                    if (currentFrame % frameFrequency == 0)
                    {
                        PrimaryStructureFrame frame = getFrame(sr);

                        if (frame == null)  // end of file, no more frames in file
                        {
                            break;
                        }

                        trajectory.AddFrame(frame);
                        framesAdded++;
                    }
                    else
                    {
                        PrimaryStructureFrame frame = getFrame(sr); // discard frame
                        if (frame == null)                          // end of file, no more frames in file
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception e) {
                throw new FileParseException(e.Message);
            }
            finally {
                if (sr != null)
                {
                    sr.Close();
                }
            }

            return(trajectory);
        }
        public static PrimaryStructureTrajectory GetTrajectory(string filename, int startFrame, int numFrames, int frameFrequency)
        {
            PrimaryStructureTrajectory trajectory = new PrimaryStructureTrajectory();
            BinaryReader reader = null;

            try {
                int    frameCount;
                int    atomCount;
                bool   cellInfo;
                string title;

                reader = new BinaryReader(new FileStream(filename, FileMode.Open));
                parseDCDHeader(reader, out frameCount, out atomCount, out cellInfo, out title);

                for (int i = 0; i < startFrame; i++)
                {
                    discardFrame(reader, cellInfo, atomCount);
                }

                int frameIndex   = 0;
                int currentFrame = 0;

                while (reader.BaseStream.Position != reader.BaseStream.Length && frameIndex < numFrames)
                {
                    currentFrame++;

                    if (currentFrame % frameFrequency == 0)
                    {
                        PrimaryStructureFrame frame = new PrimaryStructureFrame();
                        frame.AtomCount = atomCount;
                        //frame.Step = ;
                        //frame.Time = ;

                        parseFrame(reader, cellInfo, frame);
                        trajectory.AddFrame(frame);
                        frameIndex++;
                    }
                    else
                    {
                        discardFrame(reader, cellInfo, atomCount);
                    }
                }
            }
            catch (Exception e) {
                throw new FileParseException(e.Message);
            }
            finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(trajectory);
        }
        public static PrimaryStructureTrajectory GetTrajectory(string filename, int startFrame, int numFrames, int frameFrequency)
        {
            PrimaryStructureTrajectory trajectory = new PrimaryStructureTrajectory();

            BinaryReader reader = null;

            try {
                reader = new BinaryReader(new FileStream(filename, FileMode.Open));

                for (int i = 0; i < startFrame; i++)
                {
                    discardFrame(reader);
                }

                int framesAdded  = 0;
                int currentFrame = 0;

                while (reader.BaseStream.Position != reader.BaseStream.Length && framesAdded < numFrames)
                {
                    currentFrame++;

                    if (currentFrame % frameFrequency == 0)
                    {
                        trajectory.AddFrame(getFrame(reader));
                        framesAdded++;
                    }
                    else
                    {
                        discardFrame(reader);
                    }
                }
            }
            catch (Exception e) {
                // handle end of file corruption gracefully.
                if (trajectory.FrameCount() > 0)
                {
                    return(trajectory);
                }
                else
                {
                    throw new FileParseException(e.Message);
                }
            }
            finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(trajectory);
        }