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
I suspect a loop will be needed at some point. Perhaps you are writing the values of the waves as a CSV row, one row per wave. Iterative over the wave names. Write each wave to a string and concatenate the strings. Alternatively, perhaps you are writing the values of the waves as a CSV column, one column per wave. I'd consider putting the waves in to a (FREE) matrix wave, transpose the matrix, and use the method described above to write contiguous rows.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
If you've figured out a way to do it with fprintf and the wave names hardwired, then the trick may just be to use the Execute operation. You'd create a string that contains the full fprintf command, including the user-specified waves, then Execute that string. You might run into string length limits. DisplayHelpTopic"The Execute Operation"
Thanks for all the suggestions and comments that have led to me successfully writing a very flexible function that does all the things I wanted of it! I built the text wave with names of waves I wanted to output and applied these in a loop to fill a multidimensional wave containing each of the waves for output as columns. I then loop the multidimensional wave a row at a time with sprintl formatting of each data item including the file separators, concatenate these together and output with a fprintf.
--
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
October 26, 2017 at 02:16 pm - Permalink
October 28, 2017 at 07:14 am - Permalink