Add a line to the top of a comma delimited file?
- To: mathgroup at smc.vnet.net
- Subject: [mg32674] Add a line to the top of a comma delimited file?
- From: "1.156" <rob at piovere.com>
- Date: Wed, 6 Feb 2002 03:41:26 -0500 (EST)
- Organization: Internet America (using Airnews.net!)
- Sender: owner-wri-mathgroup at wolfram.com
Greetings to all you Mathematica gurus.... I'm using ver 4.0 and I was led to using the following scheme to output a comma delimited file of x,y points for plotting in AutoCAD. First, I had to thread two lists in order to make a list of x,y values to plot, then I called the writeArray routine to put in the commas that AutoCAD needs. After the file is made by Mathematica, I manually insert the text string "PLINE" at the top of this text file and it runs nicely as a script file in AutoCAD. ************** wList = Thread[{zz, ww}]; writeArray[filename_, arrayname_] := Module[{makeStringList, outfile}, outfile = OpenWrite[filename]; makeDepth3[lst_] := Module[{x}, x = lst; While[Depth[x] < 3, x = {x}]; While[Depth[x] > 3, x = Flatten[x, 1]]; x]; makeStringList[lst_] := Flatten[{Drop[ Flatten[Transpose[{Map[ToString, lst], Table[",", {Length[lst]}]}]], -1], {"\n"}}]; Scan[WriteString[outfile, Sequence @@ makeStringList[#]] &, makeDepth3[arrayname], {1}]; Close[outfile]] writeArray["Half_Width.scr", wList]; ********************** But, being on the leading edge of technology, I really would like to get Mathematica to put this "PLINE" at the top of this file all by itself (saving me the effort of doing it each time) but so far my attempts have failed. All I can think of is to Prepend "PLINE" to the list before plotting: wList = Thread[{zz, ww}]; wList1= Prepend["PLINE", wList]; writeArray["Half_Width.scr", wList1]; For some reason, this doesn't work: I get this error: Prepend::"normal": "Nonatomic expression expected at position \!\(1\) in \ \!\(Prepend[\(\(\"PLINE\", \(\({\(\({0, 0.2778433382100995`}\)\), \ \(\({0.1375`, 0.3875218669690084`}\)\), \(\({0.275`, \ 0.4969825003326075`}\)\), \(\(\[LeftSkeleton] 195 \[RightSkeleton]\)\), \ \(\({27.225`, 0.09070154268959256`}\)\), \(\({27.3625`, 0.08382268678151675`}\ \)\), \(\({27.500000000000004`, 0.07663144276237456`}\)\)}\)\)\)\)]\)." I'm guessing that the string screws up the writeArray routine. But I can think of no other way to stuff another line into this file. I would appreciate any suggestions. Thanks, Rob