sex2float

Convert a sexigecimal format to floating point.


%  sex2float.sh -32:14:15.444
  -32.23762333

%  sex2float.sh -00:00:1.000
   -0.00027778

%  sex2float.sh +22:1:2.2
   22.01727778

%  sex2float.sh +22:0001:002.2
   22.01727778

A Good Test

The routine sex2float takes a sexigecimal string and makes a floating point expression. The float2sex script takes a float and creates the sexigecimal string (not that this routine "wants" to know if it is using units of HOURS or DEGREES). I wrote a test for both routines in my Test_Data_for_Codes section.The test script (TEST1) runs both sex2float and float2sex to verify that they work.

Go to Test dir (got) 
% cd ./T_runs/cdproj/ex0
% cp S/TEST1 .

To test the HOURS mode 
% ./TEST1 12:33:33.0001 h
sex in       = 12:33:33.0001
float answer = 12.55916671 
new form     = 12:33:33.0002 
 
NOTE: Does not work yet!!!!!!   The answer---> stupid fortran 

-------------------------------------------------------
12:33:33.0001
I'll use my calculator set to 9 decimal places
                       123456789
  12 --->           12.000000000
  33 /60             0.550000000
  33.0001 /3600      0.009166694
  Final_calculator  12.559166694   --->  12.55916669

So, I changed fortran code:
      double precision xx1,xx2,xx3,xnum,xo,sign
      double precision x60, x3600

c This works:
      x60   =   60.000000000
      x3600 = 3600.000000000
      xx2 = x2/x60
      xx3 = x3/x3600

c This does NOT work:
      xx2 = x2/60.0
      xx3 = x3/3600.0

Now I get:
% !se
sex2float.sh 12:33:33.0001
   12.55916669
   12.55916669   -----> This is my hand-calculation value!

Now, I get good agreement to the 8th decimal place:
% TEST1 12:33:33.0001 h
sex in       = 12:33:33.0001
float answer = 12.55916669
new form     = 12:33:33.0001





Back to SCO CODES page