(*  spherical_harmonic_values.nb *)
(* *)
(*  Purpose: *)
(*    Evaluate the spherical harmonic *)
(*    function at selected argument values, *)
(*    and write the data to a file. *)
(* *)
(*  Modified:  10 February 2006 *)
(*  Author:  John Burkardt *)

lvec = {0,1,2,3,4,
          5, 5, 5, 5, 5,
         4, 4, 4, 4, 4,
        3, 3, 3, 3, 3};
mvec = {0, 0, 1, 2, 3, 
          5, 4, 3, 2, 1,
         2, 2, 2, 2, 2,
       -1, -1, -1, -1, -1};
thetavec = {Pi/6, Pi/6, Pi/6, Pi/6, Pi/6,
Pi/12, Pi/12, Pi/12, Pi/12, Pi/12,
 Pi/5, 3*Pi/5, Pi, 7*Pi/5, 9*Pi/5,
  Pi/8, Pi/8, Pi/8, Pi/8, Pi/8};
phivec = {Pi/3,Pi/3,Pi/3,Pi/3,Pi/3,
Pi/5,Pi/5,Pi/5,Pi/5,Pi/5,
 Pi/4, Pi/4, Pi/4, Pi/4, Pi/4,
  Pi/7, 2*Pi/7, 3*Pi/7, 4*Pi/7, 5*Pi/7};
fvec = {};
num = Length [ lvec ];

Do[ { l = lvec[[i]],
m=mvec[[i]],
theta=thetavec[[i]],
phi=phivec[[i]],
f = SphericalHarmonicY[l,m,theta,phi] ,
fvec = Append [ fvec, f ],
      Print["Y[",l,",",m,",",N[theta,16],",",N[phi,16],"]=",N[f,16]] },
{i,1,num,1}]

fileout=OpenWrite["C:\\Documents and Settings\\burkardt\\Desktop\\Misc\\mathematica\\spherical_harmonic_values.txt"];
SetOptions[fileout,FormatType->TextForm];
Write[fileout,"#  spherical_harmonic_values.txt"];today=DateList[];Write[fileout,"#  Created on ",today];Write[fileout,"#"];
Write[fileout,"#  l  m  theta  phi  f"];
Write[fileout,"#"];
Do[{l=lvec[[i]];m=mvec[[i]];theta=thetavec[[i]];phi=phivec[[i]];f=fvec[[i]];Write[fileout,l,"  ",m,"  ",N[theta,16],"  ",N[phi,16],"  ",N[f,16]]},{i,1,num,1}];Close[fileout];