use strict; use Win32::OLE; use Win32::OLE::Variant qw(:DEFAULT nothing ); Win32::OLE->Option( Warn => 3 ); # Create MSFileReader object, must have MSFileReader dll installed my $thermo_raw_file = eval{Win32::OLE->new('MSFileReader.XRawfile.1', sub{$_[0]->Close;})}; if($@){ die "Could not create XRawfile object. This function requires Thermo MSFileReader\n"; } # Open raw file and set controller to first(1) mass spec device (0) $thermo_raw_file->Open("RSK2017C.RAW"); $thermo_raw_file->SetCurrentController(0,1); my @TempScan = (); my $NumberOfSpectra = Win32::OLE::Variant->new(VT_I4 | VT_BYREF, 0); $thermo_raw_file->GetNumSpectra($NumberOfSpectra); my $scan_num; for ($scan_num = 1; $scan_num <= $NumberOfSpectra; $scan_num++) { my $CurrentScanFilter = Variant(VT_BSTR | VT_BYREF); $thermo_raw_file->GetFilterForScanNum($scan_num, $CurrentScanFilter); if ($CurrentScanFilter =~ m/ms /) { my $pnScanNumber = Win32::OLE::Variant->new(VT_I4 | VT_BYREF, $scan_num); my $szFilter = Win32::OLE::Variant->new(VT_BSTR | VT_BYREF); my $nIntensityCutoffType = Win32::OLE::Variant->new(VT_I4 | VT_BYREF, 0); my $nIntensityCutoffValue = Win32::OLE::Variant->new(VT_I4 | VT_BYREF, 0); my $nMaxNumberOfPeaks = Win32::OLE::Variant->new(VT_I4 | VT_BYREF, 0); my $bCentroidResult = Win32::OLE::Variant->new(VT_BOOL, 0); my $pdCentroidPeakWidth = Win32::OLE::Variant->new(VT_R8 | VT_BYREF, 0); my $pvarMassList = Win32::OLE::Variant->new(VT_VARIANT | VT_BYREF); my $pvarPeakFlags = Win32::OLE::Variant->new(VT_VARIANT | VT_BYREF); my $pnArraySize = Win32::OLE::Variant->new(VT_I4 | VT_BYREF, 0); $thermo_raw_file->GetMassListFromScanNum($pnScanNumber, $szFilter, $nIntensityCutoffType, $nIntensityCutoffValue, $nMaxNumberOfPeaks, $bCentroidResult, $pdCentroidPeakWidth, $pvarMassList, $pvarPeakFlags, $pnArraySize); @TempScan = @{$pvarMassList->Value()}; # undef @TempScan; does not clear memory # Need to deallocate $pvarMassList from memory # Help here!!!! print "Scan number: $scan_num Size: $#{$TempScan[0]}\n"; } } Win32::OLE->Uninitialize; print "Press any key to exit.\n"; ; exit;