Re: Angular format
- To: mathgroup at smc.vnet.net
- Subject: [mg20905] Re: Angular format
- From: phbrf at t-online.de (Peter Breitfeld)
- Date: Sun, 21 Nov 1999 15:12:49 -0500 (EST)
- References: <8103i4$5u4@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Alan W.Hopper <awhopper at hermes.net.au> schrieb: > I have an output angle in decimal degrees; a = 174.87625, > > now with , > > In[1] := dms[n_]:=Module[{d,m,s,a}, > d=IntegerPart[n]; > a=60*FractionalPart[n]; > m=IntegerPart[a]; > s=60*FractionalPart[a]; > {d,m,s}] > > In[2] := dms[174.87625] > > Out[3] = {174, 52, 34.5} > > The output is converted to degree, arcminute, arcsecond (list)form > but I want a fully symbolic result using the single and double quotes > if possible, for arcminute and arcsecond symbols, > or alternatively like this , > > 174\[Degree] 52\[CloseCurlyQuote] 34\[CloseCurlyDoubleQuote].5 > > as the standard double quotes are 'protected' by Mathematica. > > > I have tried using strings, > > "174\[Degree]" <> "52\[CloseCurlyQuote]" <> > "34\[CloseCurlyDoubleQuote].5" > > and this works O.K, but I can not seem to get everything together > into a workable program, so far. > Alan, I have two functions to convert vom decimal to HMS form and back. There are two Options: 1. inStunden: Output is 12^h15^m11.3^s instead of 12°15'11.3'' 2. nurGanz: No decimals in seconds ----------------8<----------------8<---------------- Options[toHMS]={inStunden->False,nurGanz->False}; SetAttributes[toHMS,Listable]; toHMS[wink_,opt___?OptionQ] := Module[{hs, h, m, s, nG, iH}, iH=inStunden/.{opt}/.Options[toHMS]; nG=nurGanz/.{opt}/.Options[toHMS]; h = Floor[Abs[wink]]; m = Chop[(Abs[wink]-h)*60,10^-6]; s = Chop[(m-Floor[m])*60,10^-6]; m = Floor[m]; If[nG===True, s=Round[s]]; If[Abs[s-60.]<10^-4,++m;s=0]; If[m==60,++h;m=0]; s=Chop[s,10^-4]; If[iH===False, hs=StringJoin[ If[Sign[wink] === -1, "-", ""], ToString[h]<>"°", "\!\("<>ToString[m]<>"\^\[Prime]\)", "\!\("<>ToString[s]<>"\^\[DoublePrime]\)"], hs=StringJoin[ If[Sign[wink]===-1,"-",""], "\!\("<>ToString[h]<>"\^h\)", "\!\("<>ToString[m]<>"\^m\)", "\!\("<>ToString[s]<>"\^s\)"]]; hs ] SetAttributes[fromHMS,Listable]; fromHMS[hms_String] := Module[{p, hs, h, m, s, vz}, hs = hms; hs = StringReplace[hs, {"°"->"h","''" -> "s", "'" -> "m"}]; hs = StringReplace[hs, {"\^h"->"h","\^m"->"m","\^s"->"s"}]; hs = StringReplace[hs, {"\^\[Prime]"->"m", "\^\[DoublePrime]"->"s"}]; hs = StringReplace[hs, {"\!" -> "", "\(" -> "", "\^" -> "", "\)" -> ""}]; p = StringPosition[hs, "h"]; If[StringPosition[hs,"-"]=!={},vz=-1,vz=1]; If[p =!= {}, h = Abs[ToExpression[StringTake[hs, p[[1, 1]] - 1]]]; hs = StringDrop[hs, p[[1, 1]]], h = 0]; p = StringPosition[hs, "m"]; If[p =!= {}, m = Abs[ToExpression[StringTake[hs, p[[1, 1]] - 1]]]; hs = StringDrop[hs, p[[1, 1]]], m = 0]; p = StringPosition[hs, "s"]; If[p =!= {}, hs = StringDrop[hs, -1]; s = Abs[ToExpression[hs]], s = 0]; (h + m/60.0 + s/3600.0)*vz ] ----------------8<----------------8<---------------- Peter -- =--=--=--=--=--=--=--=--=--=--=--=--= http://home.t-online.de/home/phbrf =--= =--= Peter Breitfeld, Saulgau, Germany PGP public key: 08548045 =--=--=