Exporting single integer above columns of data.

I'm exporting data from igor to a text file for another program to grab. Unfortunately, that other program is... picky with how it wants the data. It wants the data in the following format.

Quote:

NumItems
Column0(0),Column1(0),Column2(0)
Column0(1),Column1(1),Column2(1)
...
...
...
Column0(NumItems-1),Column1(NumItems-1),Column2(NumItems-1)
Column0(NumItems),Column1(NumItems),Column2(NumItems)



Now, exporting the data in delimited columns is easy, however I'm not sure how to get the "NumItems" at the top of the list. Sure, I could do this in bash pretty quickly, but I'd like not to have to. I already have access to NumItems in the procedure, I just don't know how to export it to a file ahead of other columns.

My current code. Only works with my specific data, since it has 3 columns with "_0", "_1", and "_2" at the end of the wavenames.
Function EISExporter()

    String listWave, listWave1, listWave2, wList=tracenamelist("",";",1)
    Variable stringlength,i,numItems = ItemsInList(wList)
//  print wList
    For(i=0;i<numItems;i+=1)
        listWave = stringfromlist(i,wList,";")
        stringlength = strlen(listWave) - 3
        listWave = listWave[1,stringlength] + "0"
        listWave1 = listWave[0,stringlength-1] + "1"
        listWave2 = listWave[0,stringlength-1] + "2"
//      print listWave + " " + listWave1 + " " + listWave2 + ":"
//      print "!!" + listWave + "!!"
        wave w0 = $listWave
        wave w1 = $listWave1
        wave w2 = $listWave2
        Save/J/M="\r\n"/I w2,w1,w0 as listWave[0,stringlength-2]+".txt"
    endfor
End
[quote=hrodstein]You can use Open, fprintf, and Close to write the header lines. Then use Save/A to append the data to the file.

This is not what you need but might be a good starting point: http://www.igorexchange.com/node/2397[/quote]

Thanks! I THINK I can get away with using tab delimited, if not I may download the igor 7 beta. :) (Makes me really surprised that igor currently CAN'T export CSV format.) Actually, I may just create a wave of commas and export it between the other waves if spaces are ignored by the other program.

I was just reading up on SaveData, trying to save an individual variable the appending with save/A. I think your way may work better.

Heck, if I have the file open for writing, why don't I just export the data, line by line as CSV? It'll take marginally longer (each file only has ~60 rows) but I'll get pretty CSVs out of it. That's probably what the above link did...

Screw it. It's easier in bash. 5 line script, even programming non-ideally.
In addition to the methods mentioned, you could do one of these ...

Option 1
* Add an additional point at the start of each wave.
* In the first wave, set the point to the number of points.
* In all other waves, set the value of the first point to NaN
* Export/Save the waves.

Option 2
* Write the header + waves to a text string or notebook
* Save the text string or notebook

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH