General function to write text files with selected waves and variable sperators
Mike German
Thu, 10/26/2017 - 08:34 am
I am trying to write a general function to write to a text a row of comma or tab or colon etc separated variables from a selection of 1d waves of the same length. I have done this for a fixed number of waves with the wave references hard wired into to the code. The fprintf operation has enough flexibility to specify the format needed. But I cannot see a way of doing this with a user specified number of waves. My thoughts have been to build a text wave with the strings containing the names of the waves to be output, and then put it in a loop to set up the wave referencing for each wave. But I can't see how to do using straightforward wave referencing. I have considered perhaps using duplicate or make to set up dummy waves in the function and deleting them at the end but this seems very clunky. I also think I could probably do it in a macro ... any advice welcome
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
October 26, 2017 at 11:03 am - Permalink
DisplayHelpTopic "The Execute Operation"
October 26, 2017 at 01:38 pm - Permalink
Wave/WAVE ww
Variable row
Variable numWaves = numpnts(ww)
String text = ""
Variable i
for(i=0; i<numWaves; i+=1)
String temp
Wave w = ww[i]
Variable value = w[row]
sprintf temp, "%g", value
text += temp
if (i < (numWaves-1))
text += ","
endif
endfor
Printf "%s\r", text
End
Function Demo()
Make/O/N=5 wave0=p, wave1=p+1, wave2=p+2
Make/FREE/WAVE/N=3 ww
ww[0] = wave0
ww[1] = wave1
ww[2] = wave2
PrintRow(ww,1)
End
October 26, 2017 at 02:16 pm - Permalink
October 28, 2017 at 07:14 am - Permalink