MathGroup Archive 2001

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

Search the Archive

Re: Name of a list

  • To: mathgroup at
  • Subject: [mg26669] Re: Name of a list
  • From: "John M. Jowett" <John.Jowett at>
  • Date: Wed, 17 Jan 2001 00:47:22 -0500 (EST)
  • Organization: CERN
  • References: <93r73j$>
  • Sender: owner-wri-mathgroup at

Hello James,
        You are clearly trying to transform Mathematica definitions of beam
lines into MAD format.  It so happens I once wrote a function to do this.  Here
it is, adapted slightly for the form of your list.

SetAttributes[madForm, HoldFirst];

madForm[line_] :=
    ToString[Unevaluated[HoldForm[line]]] <> ": LINE=(" <>
      StringDrop[StringJoin @@ (ToString[First[#] <> ","] & /@ line), -1] <>

With the definition in your example

madFile = OpenWrite["test.mad"];
Write[madFile, madForm[SRS]];

The file test.mad then contains

SRS: LINE=(quad1,sb1,bpm1);

or you can simply evaluate


It needs some further definitions to take care of the last "bpm" element whose
definition appears to be elsewhere but that's easy to do.

John Jowett

"" wrote:

> Hi,
> Could someone provide some help with a small problem I have??
> I have a list of formatted data with a title. This list is made up of other
> elements seperately defined. I need to output, to a seperate file, the
> element data from the list in a formatted way, on seperate lines. Then I
> need to define the list in terms of the names of the elements within it and
> its title.
> Currently I apply the element name as part of the list and read it out when
> needed, as the elements aren't defined as variables, just elements in a
> seperate list.
> However, how do I then print a line with the list title and then the element
> names? Obviously the element names are read from the list individually, but
> the list name is a variable representing the list. I can't specify the list
> name as a seperate variable as it is representative of a list, and it is
> very unwieldy to have to define a list in terms of elements and call it
> something, and then rename it when it is written to a file.
> The crux of my question is, can you take the name of a list and output it as
> a string??
> For reference, the list would like:
> SRS = {{"quad1", Quadrupole, 1.2, -2.9, "---", "---", "qd"}, {"sb1",
> SectorBend, 3.6, 0.007, "---", 2, "bend"}, {"bpm1", BPM, 0, "---", "---",
> "---", "bpm"}}
> and the file text should look like:
> SRS:  Line = quad1, sb1, bpm1
> Any help would be much appreciated,
> James Jones
> Daresbury Lab.
> j.k.jones at

mailto:John.Jowett at
My home page:

  • Prev by Date: Re: Infinite loop while generating gcc.1
  • Next by Date: Re: Partial Differential Equation
  • Previous by thread: Re: Name of a list
  • Next by thread: RE: RE: Fast Integration of a product of 2 interpolating function s