I'm trying to read a file which is in "Touchstone" format. In at least the version of Mathematica I am using (7), the Import[] command does not know about Touchstone format files. This is used by electronics engineers. A typical file is this. ! This is a Touchstone .s1p format file ! HEWLETT PACKARD,8720D,0,7.74 ! Date = 8 Jan 2015 ! Time = 23:00:59 ! Start frequency = 0.050000000 GHz ! Stop frequency = 20.049999872 GHz ! Port extensions = OFF ! Port extension 1 = 0.000000 ps ! Port extension 2 = 0.000000 ps # MHz S DB R 50 50.00000 0.07349 179.64844 62.50000 -0.00239 179.21094
It contains 3 types of lines
1) Those that begin with an exclamation mark (!) are comments, and for the moment at least I am going to ignore them.
2) The line beginning with a hash character (#) contains information about the format of the numerical data in the rest of the file. Again I can ignore that for now, as all mine are in the same format.
3) The numerical values, which are in the form of frequency in the first column, an amplitude in the second column and a phase in the third column.
I've taken to pre-processing the file in a Unix shell script to remove the things I don't want, and to add some commas to make it a comma separated list, so Mathematica can handle it. That is incredibly simple on Unix using the "awk" and "grep" tools.
grep -v "#" | grep -v \! | awk '{print $1,",",$2,",",$3}'
so I get an output like
50.00000 , 0.07349 , 179.64844 62.50000 , -0.00239 , 179.21094
Then I can use Import[], and do things with the data.
But rather than pre-process the file on a Unix system, which would obviously break if I used Mathematica on Windows, I'd like Mathematica to strip out all the irrelevant things, before putting the data in a list.