|
From: Ethan A M. <sf...@us...> - 2012-06-12 18:20:22
|
Revisiting a discussion from last month... I had a go at implemented data blocks defined as a "here document". The patch is on SourceForge <https://sourceforge.net/tracker/?func=detail&aid=3534646&group_id=2055&atid=302055> In brief it adds perl-like syntax $Mydata << EOD 1 2 3 4 5 ? 7 8 9 # comments or anything else legal in a data file 10 11 12 EOD stats $Mydata using 3 plot $Mydata using 1:3, $Mydata using 0:2, '' using 1:2 Notes: - The data block name must begin with a '$'. This allows the named data blocks to be tracked internally using the same code as other user-defined variables, but prevents a data block name from being used in an expression, function, or other places that a normal variable would be accepted. - The end-of-data marker (EOD in the example) can be any arbitrary string of alphanumerics beginning with a letter. I'm don't know what advantage this gives over requiring a fixed character sequence like EOD, but this seems to be how here documents are defined in other programming languages. - The in-line data is read with no interpretation or processing. It is simply stored for later use in a "plot" "splot" or "stats" command. - Any plot command that works with a normal text input file should work also with an in-line data block. - The "show variables" command will report $Mydata = <5 line datablock> - Do you think there needs to be a special command to clear all existing datablocks? Right now the only way to clear one is to redefine it as a zero-length block: $Mydata << EOD EOD Known problems: - It doesn't work to include a here document definition inside a curly-brace delimited clause. Not that it should ever be necessary to do so, but the program should at least not crash if you try it. - I didn't look into using a data block as input to "fit". Do you think this would be useful? - Ethan |