MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How can I import a file wiht a space as a separator?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg129416] Re: How can I import a file wiht a space as a separator?
  • From: "Hans Michel" <hmichel at cox.net>
  • Date: Fri, 11 Jan 2013 22:26:24 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <20130111024157.2E79C6930@smc.vnet.net>

David:
In Mathematica version 9
Using examples from the PDF file in the link:
Example 4:
# GHZ S RI R 50.0
!freq RelS11 ImS11 ReS21 ImS21 ReS12 ImS12 ReS22 ImS22
1.0000 0.3926 -0.1211 -0.0003 -0.0021 -0.0003 -0.0021 0.3926 -0.1211
2.0000 0.3517 -0.3054 -0.0096 -0.0298 -0.0096 -0.0298 0.3517 -0.3054
10.000 0.3419 0.3336 -0.0134 0.0379 -0.0134 0.0379 0.3419 0.3336

To import in Mathematica I saved the data to a file

In[10]:= Import["E:\\Stuff\\touchstone4.txt", "Table", "HeaderLines"->2,
"FieldSeparators"->{" ","\t"}]
Out[10]=
{{1.,0.3926,-0.1211,-0.0003,-0.0021,-0.0003,-0.0021,0.3926,-0.1211},{2.,0.35
17,-0.3054,-0.0096,-0.0298,-0.0096,-0.0298,0.3517,-0.3054},{10.,0.3419,0.333
6,-0.0134,0.0379,-0.0134,0.0379,0.3419,0.3336}}

Example 5:
# GHZ S MA R 50
5.00000 0.60 161.24 0.40 -42.20 0.42 -66.58 0.53 -79.34 !row 1
0.40 -42.20 0.60 161.20 0.53 -79.34 0.42 -66.58 !row 2
0.42 -66.58 0.53 -79.34 0.60 161.24 0.40 -42.20 !row 3
0.53 -79.34 0.42 -66.58 0.40 -42.20 0.60 161.24 !row 4
6.00000 0.57 150.37 0.40 -44.34 0.41 -81.24 0.57 -95.77 !row 1
0.40 -44.34 0.57 150.37 0.57 -95.77 0.41 -81.24 !row 2
0.41 -81.24 0.57 -95.77 0.57 150.37 0.40 -44.34 !row 3
0.57 -95.77 0.41 -81.24 0.40 -44.34 0.57 150.37 !row 4
7.00000 0.50 136.69 0.45 -46.41 0.37 -99.09 0.62 -114.19 !row 1
0.45 -46.41 0.50 136.69 0.62 -114.19 0.37 -99.09 !row 2
0.37 -99.09 0.62 -114.19 0.50 136.69 0.45 -46.41 !row 3
0.62 -114.19 0.37 -99.09 0.45 -46.41 0.50 136.69 !row 4

To import in Mathematica I saved the data to a file

In[11]:=
Import["E:\\Stuff\\touchstone5.txt","Table","HeaderLines"->1,"FieldSeparator
s"->{" ","\t","!row"}]
Out[11]=
{{5.,0.6,161.24,0.4,-42.2,0.42,-66.58,0.53,-79.34,1},{0.4,-42.2,0.6,161.2,0.
53,-79.34,0.42,-66.58,2},{0.42,-66.58,0.53,-79.34,0.6,161.24,0.4,-42.2,3},{0
.53,-79.34,0.42,-66.58,0.4,-42.2,0.6,161.24,4},{6.,0.57,150.37,0.4,-44.34,0.
41,-81.24,0.57,-95.77,1},{0.4,-44.34,0.57,150.37,0.57,-95.77,0.41,-81.24,2},
{0.41,-81.24,0.57,-95.77,0.57,150.37,0.4,-44.34,3},{0.57,-95.77,0.41,-81.24,
0.4,-44.34,0.57,150.37,4},{7.,0.5,136.69,0.45,-46.41,0.37,-99.09,0.62,-114.1
9,1},{0.45,-46.41,0.5,136.69,0.62,-114.19,0.37,-99.09,2},{0.37,-99.09,0.62,-
114.19,0.5,136.69,0.45,-46.41,3},{0.62,-114.19,0.37,-99.09,0.45,-46.41,0.5,1
36.69,4}}

You can try "Table" with the Import options tweaked to your format.

Hans

-----Original Message-----
From: David Kirkby [mailto:drkirkby at gmail.com] 
Sent: Thursday, January 10, 2013 8:42 PM
To: mathgroup at smc.vnet.net
Subject: [mg129416] How can I import a file wiht a space as a separator?

You might see from my previous post I'm looking for a function to read a
Touchsone file format, which is defined by this "draft" standard,

http://vhdl.org/ibis/connector/touchstone_spec11.pdf

which has been draft for 30 years, but is still used as the standard. The
main point is a header (which I can skip), but then 9 data points on each
line, but with a space separating them, so not something simple like a
comma. Every attmpt I've made so far to read these in results in one string
per line, rather than 9 data points per line.

Dave 




  • Prev by Date: Export with append??
  • Next by Date: Re: List:{1}, {2,3},{4,5,6}....
  • Previous by thread: How can I import a file wiht a space as a separator?
  • Next by thread: Parallel computing in version 7 Vs version 8