How can I combine all the waves in a folder into a csv and export it?

Hi!

I am a user of Igor 8. I am not good at coding now so I can only edit the button and add coustomized function in an existing macro.

Recently I have a folder contains multiple subfolder, each corresoponding to one sample. In each subfolder, 4 waves are saved plus a string for that sample name. To export the data to another fitting software I need to create one csv file for each sample. So I want a function to help me.

1) Get the 4 waves and export it to a CSV file naming as a existing string variable.

2) Loop through the entire folder SAS.

3) (Extra function) In some cases, I need to do a simple manipulation to the wave before I export it to csv. For example, substract sample567_wave1 to background_wave1 and then save it to sample567_sub.csv. And do it for all samples.

I have no clue how to do it after I read some posts, like Save Waves as Comma-Delimited Text and Load all wave files save as tx. So I am here for any suggestion. Thanks in advance!

 

I want to export all the wave in eaching subfolder in SAS folder

I have a question- you say you want to do this in order "To export the data to another fitting software"; why not do the fitting within Igor?

Hi johnweeks,

I thought there is no package in Igor that can do the fitting. (I might be wrong) That fitting requires some modeling with some complex parameters and model built by other community. They use SasView specifically. So I think I have to import data to there, following their data format.

Igor 9 can fit models with complex inputs. older versions can fake it.

You will need to write a user-defined function that implements the model. How complicated is the model?

Not sure. It is another giant software that including all the existing models and graph capability. Finially I figured that out by myself and I learned a lot! Here is my script. Second function is copied from other user.

Function SaveWavesFromCurrentDF(matchStr)
    String matchStr // As for the WaveList function.
   
    String list
    String name_here
    name_here = getdatafolder(0)
    name_here = ReplaceString("'", name_here, "")
    name_here +=".csv"
    list = WaveList(matchStr, ";", "")
    list = sortList(list)   //// first two col are flipped so here sort is called
    Save/O/J/W/B/DLIM=","/P=home list as name_here
   
End


// this function goes into each datafolder and run some code in there
Function Sace_cvs_InFolders(matchStr)
     String matchStr
    SetDataFolder root:SAS:    // relies on earlier load
    DFREF dfr = GetDataFolderDFR()
    String folderName
    Variable numDataFolders = CountObjectsDFR(dfr, 4)
   
    Variable i
       
    for(i = 0; i < numDataFolders; i += 1)
        folderName = GetIndexedObjNameDFR(dfr, 4, i)
        SetDataFolder ":'" + folderName + "':"
        // you can write some code here or use another function to do what you want
        SaveWavesFromCurrentDF(matchStr)
        SetDataFolder root:SAS:
    endfor
    SetDataFolder root:
End

 

Some of the Small-angle scattering models which are in sasView are in Igor package Irena. Irena should read your data directly, since they follow qrs naming structure. Actually, looking at the data, makes me wonder if these did not come from Nika, Irena's little sister for data reduction. 

And if you use Irena, it has Export data function, which will save ASCII (aka csv) or HDF5 (Nexus) data which sasView reads without any issues. I have tested that specifically so users can export data easily when Irena is not enough. I suggest using Nexus data with sasView as you get some metadata through.