Loading waves from csv consist of random number of text and data
linepic
I have a csv data file that contains various number of texts and data.
I tried to load it with every function in Igor, but I cannot pick it up.
can any experts suggest some way to load it?
I attach the example of my data.
Thanks you so much
To understand what it is doing, execute this:
and
To load the other information, if you want it, would require that you write a custom file loader. This would require a fair amount of Igor programming skill.
February 22, 2017 at 04:01 pm - Permalink
When you need to get the data in to Igor right away, the fastest method might be ...
* load the data file in to a spreadsheet
* copy the three columns of data to a separate worksheet by themselves
* export just that worksheet as a CSV file
* load the data in to Igor
You could also copy the worksheet directly in to a table in Igor. Or, you could import the spreadsheet directly in to Igor.
Someone here may eventually be willing to provide you with the Igor code for a basic file loader to get you started. Another option is to determine whether your instrument can export just the data without all the extra text stuff.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
February 22, 2017 at 07:29 pm - Permalink
// Creates a path to "D:Temp:" I am lazy and that is where I placed the file.
NewPath/Q/O/Z CSVDataPath "D:Temp:"
// Will use CSVDataPath with the next Open command. This is identical to Open/P=CSVDataPath, but it prevents a bug in Igor 6.36 or, most likely, Windows 10
PathInfo/S CSVDataPath
// Display an open file dialog, showing only files with the extension .csv
String FileExtension="CSV Files (*.csv):.csv;All Files (*.*):.*;"
Open/D/F=FileExtension /R/MULT=0 /P=CSVDataPath RefNum
String FullFileName=S_FileName
// Checks that a file was actually selected
if (StrLen(FullFileName)!=0)
// Loads the file as a one long text wave
LoadWave /O/N=LoadedTextWave /K=2 /Q /J /M FullFileName
Wave/T LoadedTextWave=LoadedTextWave0
Variable NumberOfLines=DimSize(LoadedTextWave, 0)
// Creates a table with the loaded text wave
DoWindow/K LoadedTextTable
Edit/N=LoadedTextTable LoadedTextWave
// Searches the first column for "DataValue"
Duplicate/O/FREE/R=[][0] LoadedTextWave, Loaded1stColumn
FindValue /S=0 /TEXT="DataValue" /TXOP=5 /Z Loaded1stColumn
if (V_value!=-1)
// Loads DataValue part the file as a three-column numeric wave
LoadWave /O/N=LoadedNumericWave /K=1 /L={0, V_value, NumberOfLines-V_value, 1, 3} /Q /J /M FullFileName
Wave LoadedNumericWave=LoadedNumericWave0
// Creates a table with the loaded numeric wave
DoWindow/K LoadedNumericTable
Edit/N=LoadedNumericTable LoadedNumericWave
endif
endif
end
February 23, 2017 at 01:06 am - Permalink
The loader reads the data first line by line to find a keyword (defined here as string constant "DataKey"), which separates header and data. The line number where this occurs can be used for the subsequent LoadWave command. Attached is also an example text file. You may be able to adjust this to your needs if you inspect the file and the code below.
strConstant EnergyKey ="*XPERCHAN*"
function LoadEMSA()
variable refNum
Open/D/R/F="*.txt" refNum
if (strlen(S_FileName) == 0)
return -1
endif
Open/R refNum as S_fileName
string wNote=""
variable i=0
variable Scaling, DataStart
do
// read file line by line
string line
FReadLine refNum, line
if(strlen(line) == 0)
break
endif
// save header line to string
wNote += line
// extract value for x-scaling
if(StringMatch(line, EnergyKey))
sscanf line, "#XPERCHAN :%f", Scaling
endif
// stop reading when DataKey is hit
if(StringMatch(line, DataKey))
DataStart = i+1
break
endif
i+=1
while(1)
Close refNum
// load the spectral part of the data, scale wave and add header as wave note
LoadWave/B="N='_skip_'; N=Counts;"/O/A/G/D/L={0,DataStart,0,0,0} S_fileName
wave Counts
SetScale/P x 0, Scaling, "keV", Counts
Note/K Counts, wNote
return 1
end
February 23, 2017 at 01:07 am - Permalink
While data loading could certainly be simplified in Igor, this is not entirely true. From the Data menu, choose "Load Waves - Load Waves...". In the dialog, choose file type Delimited Text, and click Tweaks. For your specific file, you'll have to enter 215 for "Line containing column labels" and 216 for "First line containing data." That should load your data. It also prints out the actual command used in the history (the path will be specific to your computer):
February 23, 2017 at 08:04 am - Permalink
The 'information at the end of the file in a tabular form' can be loaded that way. The 'additional information about the experimental conditions' cannot be loaded directly into variables (into a text wave is possible though).
HJ
February 23, 2017 at 12:59 pm - Permalink
It is helpful to me a lot.
I start with the way you guys suggested.
I just loaded them by copy and paste, but the advanced method might be needed for the batch analysis.
Thanks for great help and will post the result.
February 23, 2017 at 03:20 pm - Permalink