private int DoWritePeakList(IRawFile2 rawReader, int scan, string fileName, List <string> returnFiles, string experimental, int lastSpectrumNumber, List <int> ignoreScans, ref bool bReadAgain)
        {
            var result = scan + 1;

            if (ignoreScans.Contains(scan))
            {
                return(result);
            }

            SetPosition(scan);

            int msLevel = rawReader.GetMsLevel(scan);

            if (!DoAcceptMsLevel(msLevel))
            {
                return(result);
            }

            //Console.WriteLine("Reading scan {0}", scan);

            PeakList <Peak> pkl;

            try
            {
                pkl = rawReader.GetPeakList(scan);
            }
            catch (RawReadException ex)
            {
                ignoreScans.Add(ex.Scan);
                File.WriteAllLines(GetIgnoreScanFile(fileName), (from i in ignoreScans
                                                                 let s = i.ToString()
                                                                         select s).ToArray());
                bReadAgain = true;
                return(result);
            }

            pkl.MsLevel      = msLevel;
            pkl.Experimental = experimental;
            pkl.ScanTimes.Add(new ScanTime(scan, rawReader.ScanToRetentionTime(scan)));

            pkl.ScanMode = rawReader.GetScanMode(scan);

            PeakList <Peak> pklProcessed;

            if (msLevel > 1)
            {
                pkl.Precursor = new PrecursorPeak(rawReader.GetPrecursorPeak(scan));

                if (pkl.PrecursorCharge == 0)
                {
                    pkl.PrecursorCharge = PrecursorUtils.GuessPrecursorCharge(pkl, pkl.PrecursorMZ);
                }

                if (options.ExtractRawMS3 && pkl.MsLevel == 3)
                {
                    pklProcessed = pkl;
                }
                else
                {
                    pklProcessed = this.PeakListProcessor.Process(pkl);
                }
            }
            else
            {
                pklProcessed = pkl;
            }

            if (null != pklProcessed && pklProcessed.Count > 0)
            {
                DoWritePeakList(rawReader, pklProcessed, fileName, returnFiles);

                if (!options.MzXmlNestedScan)
                {
                    var intent = GetScanIntent(pkl.MsLevel);
                    sw.WriteLine(intent + "</scan>");
                }

                while (result < lastSpectrumNumber && rawReader.GetMsLevel(result) > msLevel)
                {
                    result = DoWritePeakList(rawReader, result, fileName, returnFiles, experimental, lastSpectrumNumber, ignoreScans, ref bReadAgain);
                    if (bReadAgain)
                    {
                        return(result);
                    }
                }

                if (options.MzXmlNestedScan)
                {
                    var intent = GetScanIntent(pkl.MsLevel);
                    sw.WriteLine(intent + "</scan>");
                }
            }

            return(result);
        }
 public RCPA.Proteomics.Spectrum.Peak GetPrecursorPeak(int scan)
 {
     return(rawFile.GetPrecursorPeak(scan));
 }