Problem loading text files: no data found in file

Hello, 

I would like to load the following attached text file (Dec22_op_id_4...txt). The file contains 6 lines of text. The first column contains date and time and the subseqent columns contain numeric data.

None of the IGOR text load options seem to work. I tried the general text loader but I keep getting the error that no data was found in the file. 

I would like to adapt the attached procedure file (OPC_load.ipf   function loadopc_spd()) to load several of these files into a single matrix.

Any suggestions are welcome

Thank you

Dec22_op_id_4_run_id_2_opc_spd.txt OPC_LOAD.ipf

Use the load wave dialog: Data > Load Waves > Load Waves...

Pay attention to the tweaks settings, and choose the format for each column in the dialog.

The resulting command is something like

LoadWave/J/D/K=0/L={0,6,0,0,0} StrPathToFile

In reply to by tony

Note that your timestamp is split into two columns. One way to deal with that is to load the data ignoring the column headings, then add the resulting date wave to the time wave and rename the waves as needed.

You will also need to construct a /B flag for loadwave to force the first columns to be read as date and time.

Hi Tony, 

Thanks very much for your suggestions.

Already using the Loadwave settings you sent allowed me to load the data. However, I do not manage to correctly use the /B flag. My first column includes only the year (my date format is yyyy/mm/dd) the second column does load the time.

I have tried using the /v flag, but I have not much luck.

LoadWave/J/D/K=0/v={"\t","\",0,1}/L={0,7,0,0,0}/O/M/N=Temp_opc_spdDataMatrix/Q filename

 

In reply to by LaMP

Hi,

You might need to tweak the date code to get it to read correctly

In the tweaks dialog look to the date format option and adjust it to your format.

It used this to bring it in correctly

LoadWave/J/D/W/K=0/L={5,6,0,0,0}/R={English,2,2,2,2,"Year/Month/DayOfMonth",40} pathtofile

At this point you can create a new wave which is the sum of the timestamp and channel values.

Andy

Hello, 

Thank you all for your help and suggestions. The solutions proposed worked very well.

However, when trying to load several files using the load procedure, the loaded data do not correspond to the raw text file. 

In the command line, I see each file being loaded but the subsequent waves contain what appears to be a repeated time wave. I have attached in the ZIP file 4 example files (as well as the updated procedure files) but I have more than 1000 of these text files to load. 

 

Thanks again

 

OPC.zip

In your original OPC_Load.ipf file, you have something like this:

For(filenum=0;filenum<numfiles;filenum+=1) // loops through each file name
    filename=s_path+StringFromList...
    Load_opc_spd_File(filename, refnum)
    Wave Temp_opc_spdDataMatrix0
   
    //  add loaded waves to loaded data
    InsertPoints DimSize(opc_spdDataMatrix,0),DimSize(Temp_opc_spdDataMatrix0,0), opc_spdDataMatrix

    opc_spdDataMatrix[DimSize(opc_spdDataMatrix,0)-DimSize(Temp_opc_spdDataMatrix0,0),*][]=Temp_opc_spdDataMatrix0[p-DimSize(opc_spdDataMatrix,0)+DimSize(Temp_opc_spdDataMatrix0,0)][q]
EndFor

That last line is too complicated for my aging brain to understand, so I rewrote it like this:

For(filenum=0;filenum<numfiles;filenum+=1) // loops through each file name
    filename=s_path+StringFromList...
    Load_opc_spd_File(filename, refnum)
    Wave Temp_opc_spdDataMatrix0
   
    //  add loaded waves to loaded data
    int numRowsAlreadyLoaded = DimSize(opc_spdDataMatrix,0)
    int numNewRowsToAppend = DimSize(Temp_opc_spdDataMatrix0,0)
    InsertPoints numRowsAlreadyLoaded,numNewRowsToAppend, opc_spdDataMatrix

    opc_spdDataMatrix[numRowsAlreadyLoaded,*][]=Temp_opc_spdDataMatrix0[p-numRowsAlreadyLoaded][q]
EndFor

[ I think my new code is equivalent to what you wrote but you should check it. ]

At least for me, the use of temporary variables (numRowsAlreadyLoaded and numNewRowsToAppend) whose names clearly indicate what they represent makes the statement a lot easier to understand compared to the use of inline expressions (DimSize(opc_spdDataMatrix,0) and DimSize(Temp_opc_spdDataMatrix0,0)).

So I can now see that you are concatenating the data from the new wave, in Temp_opc_spdDataMatrix0, to the final wave, opc_spdDataMatrix. (You could use the Concatenate/NP operation for this. It would do the InsertPoints and data transfer for you.)

I will take a look at your new OPC_LOAD.ipf file which is in your recent OPC.zip attachment.

 

First I see that you forgot to add /O/M to the new LoadWave command in your Load_opc_spd_File function so I added those flags:

LoadWave/J/D/W/v={"\t","\ ",0,0}/K=0/L={5,6,0,0,0}/R={English,2,2,2,2,"Year-Month-DayOfMonth",40}/O/M/N=temp_opc_spdDatamatrix/Q filename

Next, using Igor's debugger, I noticed that this line is always jumping straight to the endif and therefore not loading anything:

If(Stringmatch(FileName,"*opc_spd")==1)

You need to change it to this:

If(Stringmatch(FileName,"*opc_spd*")==1)

(If you are not familiar with Igor's debugger, execute this:

DisplayHelpTopic "The Debugger"

)

Now I'm getting some data in the output wave.

I am getting a Choose Text Encoding dialog each time LoadWave runs. This is because the file contains a non-ASCII character (μ) in either MacRoman or Windows-1252 text encoding, and my default text encoding (Misc->Text Encoding) is set to UTF-8. To fix this, add /ENCG=3 to your LoadWave command. /ENCG requires Igor Pro 7 or later.

I have debugging enabled so Igor is dropping into the debugger with the error message Index out of range for wave "temp_opc_spdDatamatrix0" on the assignment statement:

opc_spdDataMatrix[numRowsAlreadyLoaded,*][]=Temp_opc_spdDataMatrix0[p-numRowsAlreadyLoaded][q]

I see that you are making opc_spdDataMatrix with 10 columns but temp_opc_spdDataMatrix0 contain only 4 columns. So I changed the assignment statement and related code to this:

int numRowsAlreadyLoaded = DimSize(opc_spdDataMatrix,0)
int numNewRowsToAppend = DimSize(Temp_opc_spdDataMatrix0,0)
int numNewColumns = DimSize(Temp_opc_spdDataMatrix0,1)  // *** This is new ***
InsertPoints numRowsAlreadyLoaded,numNewRowsToAppend,opc_spdDataMatrix

opc_spdDataMatrix[numRowsAlreadyLoaded,*][0,numNewColumns-1]=Temp_opc_spdDataMatrix0[p-numRowsAlreadyLoaded][q]

Now it runs without error.

There are still some issue (e.g., the data is loaded into the root data folder, not the data folder that I select) but hopefully this will get you started.

Hello, Thank you for this help. That combination of codes worked very well.