LoadWave problem: loading a matrix and dealing with case of header only
I am loading delimited text files into Igor. I would like to store each file as a 2D wave. There are hundreds and some may have headers but no data. How can I best handle this scenario?
Ideally for the no-data file, I'd like to make a 2D wave that is empty. This is because for each experiment I have three different files and I need to be able to do calculations between the resulting 2D waves using a naming convention to do so. Right now I do for one type of file:
LoadWave/M/O/J/K=1/L={0,1,0,0,0}/P=csvDiskFolder/A=$wName/Q fileName
and I get an error for files with no data rows.
I previously asked a similar question https://www.wavemetrics.com/forum/general/telling-igor-skip-empty-data-…
But that solution doesn't work here because the file has a header row, plus I don't know how to use GetRTError correctly to handle error suppression. Any help appreciated!
See the FindFirstDataLine function at https://www.wavemetrics.com/code-snippet/finding-first-line-data-plain-….
It returns -1 if no data is found. You will need to customize the code that decides if it has found the first data line.
March 5, 2020 at 10:40 am - Permalink
Thank you! For anyone else that runs into this. Here is my solution.
// header (column names) is the first line
// check that first data row is not blank
String pathName // Name of symbolic path or ""
String filePath // Name of file or partial path relative to symbolic path.
Variable refNum
Open/R/P=$pathName refNum as filePath
String buffer, text
Variable line = 0
do
FReadLine refNum, buffer
if (strlen(buffer) == 0)
return line
endif
line += 1
while(line < 2)
return line // returns 2 if there was at least 1 data row
End
Using an if-else-endif I check whether this function returns > 1 and if so, load using LoadWave, otherwise make a dummy wave with the same name.
March 6, 2020 at 01:06 am - Permalink