home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_client_object.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  11.6 KB  |  675 lines

  1. unit ntc_client_object;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     SysUtils;
  27.  
  28. const
  29.     no_value=999;
  30.  
  31. type
  32.     hms=record
  33.         hours,
  34.         minutes,
  35.         seconds,
  36.         tens:integer;
  37.         high,
  38.         low:string;
  39.     end;
  40.  
  41.     dms=record
  42.         degrees,
  43.         minutes,
  44.         seconds,
  45.         tens:integer;
  46.         high,
  47.         low:string;
  48.     end;
  49.  
  50.     ams=record
  51.         degrees,
  52.         minutes,
  53.         seconds,
  54.         tens:integer;
  55.         high,
  56.         low:string;
  57.     end;
  58.  
  59.     tscope_object=class(tobject)
  60.  
  61.         constructor create;
  62.  
  63.     private
  64.         { private declarations }
  65.     public
  66.         { Public declarations }
  67.         name:string;
  68.         magnitude,
  69.         magnification:integer;
  70.         high_precision:boolean;
  71.         { parameters to control scope }
  72.         ra,
  73.         dec:double;
  74.         alt,
  75.         az:double;
  76.         speed,
  77.         dir:string[16];
  78.         info:string;
  79.         { debug }
  80.         input:string;
  81.         { end debug }
  82.  
  83.         { binary to text }
  84.         procedure right_ascension_str(
  85.                     h,m,s:integer;
  86.             var ra_rec:hms); overload;
  87.  
  88.         procedure right_ascension_str(
  89.                     f:double;
  90.             var ra_rec:hms); overload;
  91.  
  92.         procedure declination_str(
  93.                     d,m,s:integer;
  94.             var dec_rec:dms); overload;
  95.  
  96.         procedure declination_str(
  97.                     f:double;
  98.             var dec_rec:dms); overload;
  99.  
  100.         procedure azimuth_str(
  101.                     f:double;
  102.             var az_rec:dms); overload;
  103.  
  104.         procedure altitude_str(
  105.                     f:double;
  106.             var alt_rec:ams); overload;
  107.  
  108.         procedure right_ascension_str(
  109.             var ra_rec:hms); overload;
  110.  
  111.         procedure declination_str(
  112.             var dec_rec:dms); overload;
  113.  
  114.         procedure azimuth_str(
  115.             var az_rec:dms); overload;
  116.  
  117.         procedure altitude_str(
  118.             var alt_rec:ams); overload;
  119.  
  120.         { text to binary }
  121.         function str_right_ascension(
  122.             var f:double;
  123.             var ra_rec:hms)
  124.                     :boolean; overload;
  125.  
  126.         function str_declination(
  127.             var f:double;
  128.             var dec_rec:dms)
  129.                     :boolean; overload;
  130.  
  131.         function str_azimuth(
  132.             var f:double;
  133.             var az_rec:dms)
  134.                     :boolean; overload;
  135.  
  136.         function str_altitude(
  137.             var f:double;
  138.             var alt_rec:ams)
  139.                     :boolean; overload;
  140.  
  141.         function str_right_ascension(
  142.             var ra_rec:hms)
  143.                     :boolean; overload;
  144.  
  145.         function str_declination(
  146.             var dec_rec:dms)
  147.                     :boolean; overload;
  148.  
  149.         function str_azimuth(
  150.             var az_rec:dms)
  151.                     :boolean; overload;
  152.  
  153.         function str_altitude(
  154.             var alt_rec:ams)
  155.                     :boolean; overload;
  156.  
  157.     end;
  158.  
  159. var
  160.     current_object:tscope_object;
  161.  
  162. implementation
  163.  
  164. uses
  165.     ntc_client_form;
  166.  
  167.     { -------------
  168.         form handling
  169.         ------------- }
  170.  
  171. constructor tscope_object.create;
  172. begin
  173.     name:='';
  174.     ra:=4.7;
  175.     dec:=51.5;
  176.     alt:=51.38;
  177.     az:=4.08;
  178.     magnitude:=1;
  179.     magnification:=1;
  180.     high_precision:=true;
  181. end;
  182.  
  183. procedure sinc(
  184.     var s:string;
  185.             t:string);
  186. begin
  187.     s:=s+t;
  188. end;
  189.  
  190.     { --------------
  191.         binary to text
  192.         -------------- }
  193.  
  194. { HH:MM:SS
  195.     HH:MM.T }
  196. procedure tscope_object.right_ascension_str(
  197.             h,m,s:integer;
  198.     var ra_rec:hms);
  199. begin
  200.     with ra_rec do
  201.         begin
  202.             hours:=h;
  203.             seconds:=s;
  204.             minutes:=m;
  205.             tens:=seconds div 10;
  206.             high:='';
  207.             if hours<10 then
  208.                 high:='0';
  209.             sinc(high,inttostr(hours)+':');
  210.             if minutes<10 then
  211.                 sinc(high,'0');
  212.             sinc(high,inttostr(minutes));
  213.             sinc(high,':');
  214.             low:=high;
  215.             if seconds<10 then
  216.                 sinc(high,'0');
  217.             sinc(high,inttostr(seconds));
  218.             sinc(low,'.'+inttostr(seconds div 10));
  219.         end;
  220. end;
  221.  
  222. { HH:MM:SS
  223.     HH:MM.T }
  224. procedure tscope_object.right_ascension_str(
  225.             f:double;
  226.     var ra_rec:hms);
  227. var
  228.     m:double;
  229. begin
  230.     ra:=f;
  231.     with ra_rec do
  232.         begin
  233.             hours:=trunc(f);
  234.             m:=frac(f)*60;
  235.             seconds:=trunc(frac(m)*60);
  236.             minutes:=trunc(m);
  237.             right_ascension_str(hours,minutes,seconds,ra_rec);
  238.         end;
  239. end;
  240.  
  241. { sDDflMM:SS
  242.     sDDflMM }
  243. procedure tscope_object.declination_str(
  244.             d,m,s:integer;
  245.     var dec_rec:dms);
  246. begin
  247.     with dec_rec do
  248.         begin
  249.             degrees:=d;
  250.             seconds:=s;
  251.             minutes:=m;
  252.             tens:=seconds div 10;
  253.             if degrees<0 then
  254.                 high:='-'
  255.             else
  256.                 high:='+';
  257.             if degrees<10 then
  258.                 sinc(high,'0');
  259.             sinc(high,inttostr(degrees)+'fl');
  260.             if minutes<10 then
  261.                 sinc(high,'0');
  262.             sinc(high,inttostr(minutes));
  263.             low:=high;
  264.             sinc(high,':');
  265.             if seconds<10 then
  266.                 sinc(high,'0');
  267.             sinc(high,inttostr(seconds));
  268.         end;
  269. end;
  270.  
  271. { sDDflMM:SS
  272.     sDDflMM }
  273. procedure tscope_object.declination_str(
  274.             f:double;
  275.     var dec_rec:dms);
  276. var
  277.     m:double;
  278. begin
  279.     dec:=f;
  280.     with dec_rec do
  281.         begin
  282.             degrees:=trunc(f);
  283.             m:=abs(frac(f)*60);
  284.             seconds:=trunc(frac(m)*60);
  285.             minutes:=trunc(m);
  286.             declination_str(degrees,minutes,seconds,dec_rec);
  287.         end;
  288. end;
  289.  
  290. { DDDflMM:SS
  291.     DDDflMM.T }
  292. procedure tscope_object.azimuth_str(
  293.             f:double;
  294.     var az_rec:dms);
  295. var
  296.     m:double;
  297. begin
  298.     az:=f;
  299.     with az_rec do
  300.         begin
  301.             degrees:=trunc(f);
  302.             m:=frac(f)*60;
  303.             seconds:=trunc(frac(m)*60);
  304.             minutes:=trunc(m);
  305.             tens:=seconds div 10;
  306.             if degrees<10 then
  307.                 high:='0'
  308.             else
  309.                 high:='';
  310.             sinc(high,inttostr(degrees)+'fl');
  311.             if minutes<10 then
  312.                 sinc(high,'0');
  313.             sinc(high,inttostr(minutes));
  314.             low:=high+'.'+inttostr(tens);
  315.             sinc(high,':');
  316.             if seconds<10 then
  317.                 sinc(high,'0');
  318.             sinc(high,inttostr(seconds));
  319.         end;
  320. end;
  321.  
  322. { sDDflMM:SS
  323.     sDDflMM }
  324. procedure tscope_object.altitude_str(
  325.             f:double;
  326.     var alt_rec:ams);
  327. var
  328.     t_dec:double;
  329. begin
  330.     t_dec:=dec;
  331.     alt:=f;
  332.     declination_str(f,dms(alt_rec));
  333.     dec:=t_dec;
  334. end;
  335.  
  336. procedure tscope_object.right_ascension_str(
  337.     var ra_rec:hms);
  338. begin
  339.     right_ascension_str(ra,ra_rec);
  340. end;
  341.  
  342. procedure tscope_object.declination_str(
  343.     var dec_rec:dms);
  344. begin
  345.     declination_str(dec,dec_rec);
  346. end;
  347.  
  348. procedure tscope_object.azimuth_str(
  349.     var az_rec:dms);
  350. begin
  351.     azimuth_str(az,az_rec);
  352. end;
  353.  
  354. procedure tscope_object.altitude_str(
  355.     var alt_rec:ams);
  356. begin
  357.     altitude_str(alt,alt_rec);
  358. end;
  359.  
  360.     { --------------
  361.         text to binary
  362.         -------------- }
  363.  
  364. { HH:MM:SS
  365.     HH:MM.T }
  366. function tscope_object.str_right_ascension(
  367.     var f:double;
  368.     var ra_rec:hms)
  369.             :boolean;
  370. var
  371.     s,r:string;
  372.     i:integer;
  373.     h,n:boolean;
  374. begin
  375.     result:=false;
  376.     with ra_rec do
  377.         begin
  378.             if high<>'' then
  379.                 r:=high
  380.             else
  381.                 r:=low;
  382.             input:=r;
  383.             while r[length(r)]='#' do
  384.                 r:=copy(r,1,length(r)-1);
  385.             i:=pos(':',r);
  386.             if i=0 then
  387.                 exit;
  388.             s:=copy(r,1,i-1);
  389.             hours:=strtointdef(s,no_value);
  390.             if hours=no_value then
  391.                 exit;
  392.             r:=copy(r,i+1,length(r)-i);
  393.             i:=pos(':',r);
  394.             if i=0 then
  395.                 begin
  396.                     i:=pos('.',r);
  397.                     h:=false;
  398.                     if i=0 then
  399.                         begin
  400.                             i:=length(r)+1;
  401.                             n:=true;
  402.                         end
  403.                     else
  404.                         begin
  405.                             low:=high;
  406.                             n:=false;
  407.                         end;
  408.                 end
  409.             else
  410.                 begin
  411.                     low:='';
  412.                     h:=true;
  413.                     n:=false;
  414.                 end;
  415.             s:=copy(r,1,i-1);
  416.             minutes:=strtointdef(s,no_value);
  417.             if minutes=no_value then
  418.                 exit;
  419.             if n then
  420.                 begin
  421.                     tens:=0;
  422.                     seconds:=0;
  423.                 end
  424.             else
  425.                 begin
  426.                     r:=copy(r,i+1,length(r)-i);
  427.                     if not h then
  428.                         begin
  429.                             tens:=strtointdef(r,no_value);
  430.                             if tens=no_value then
  431.                                 exit;
  432.                             seconds:=tens*10;
  433.                         end
  434.                     else
  435.                         begin
  436.                             seconds:=strtointdef(r,no_value);
  437.                             if seconds=no_value then
  438.                                 exit;
  439.                             tens:=seconds div 10;
  440.                         end;
  441.                 end;
  442.             f:=seconds/60;
  443.             f:=(f+minutes)/60;
  444.             f:=f+hours;
  445.         end;
  446.     ra:=f;
  447.     result:=true;
  448. end;
  449.  
  450. { sDDflMM:SS
  451.     sDDflMM }
  452. function tscope_object.str_declination(
  453.     var f:double;
  454.     var dec_rec:dms)
  455.             :boolean;
  456. var
  457.     s:string;
  458.     i,j:integer;
  459.     r:string;
  460. begin
  461.     result:=false;
  462.     with dec_rec do
  463.         begin
  464.             if high<>'' then
  465.                 r:=high
  466.             else
  467.                 r:=low;
  468.             input:=r;
  469.             while r[length(r)]='#' do
  470.                 r:=copy(r,1,length(r)-1);
  471.             i:=pos('fl',r);
  472.             if i=0 then
  473.                 exit;
  474.             j:=pos(':',r);
  475.             if j>0 then
  476.                 low:=''
  477.             else
  478.                 low:=high;
  479.             s:=copy(r,1,i-1);
  480.             degrees:=strtointdef(s,no_value);
  481.             if degrees=no_value then
  482.                 exit;
  483.             s:=copy(r,i+1,j-i-1);
  484.             minutes:=strtointdef(s,no_value);
  485.             if minutes=no_value then
  486.                 exit;
  487.             if j>0 then
  488.                 begin
  489.                     s:=copy(r,j+1,length(r)-j);
  490.                     seconds:=strtointdef(s,no_value);
  491.                     if seconds=no_value then
  492.                         exit;
  493.                     tens:=seconds div 10;
  494.                 end
  495.             else
  496.                 begin
  497.                     tens:=0;
  498.                     seconds:=0;
  499.                 end;
  500.             f:=seconds/60;
  501.             f:=(f+minutes)/60;
  502.             f:=f+degrees;
  503.         end;
  504.     dec:=f;
  505.     result:=true;
  506. end;
  507.  
  508. { DDDMM:SS
  509.     DDDflMM.T }
  510. function tscope_object.str_azimuth(
  511.     var f:double;
  512.     var az_rec:dms)
  513.             :boolean;
  514. var
  515.     s,r:string;
  516.     t,u:char;
  517.     i,j:integer;
  518.     h,n:boolean;
  519.  
  520.     procedure bug;
  521.     begin
  522.         if copy(s,1,1)='0' then
  523.             s:=copy(s,2,length(s)-1);
  524.         if length(s)>1 then
  525.             begin
  526.                 t:=s[1];
  527.                 u:=s[2];
  528.             end
  529.         else if length(s)>0 then
  530.             begin
  531.                 t:='0';
  532.                 u:=s[1];
  533.             end
  534.         else
  535.             begin
  536.                 az_rec.degrees:=0;
  537.                 exit;
  538.             end;
  539.         j:=(ord(t)-ord('0'))*10;
  540.         az_rec.degrees:=ord(u)-ord('0')+j;
  541.     end;
  542.  
  543. begin
  544.     result:=false;
  545.     with az_rec do
  546.         begin
  547.             if high<>'' then
  548.                 r:=high
  549.             else
  550.                 r:=low;
  551.             input:=r;
  552.             while r[length(r)]='#' do
  553.                 r:=copy(r,1,length(r)-1);
  554.             if pos('.',high)>0 then
  555.                 low:=high
  556.             else
  557.                 low:='';
  558.             i:=pos('fl',r);
  559.             if i=0 then
  560.                 exit;
  561.             s:=copy(r,1,i-1);
  562.             if (strtointdef(s,no_value)=no_value) then
  563.                 bug
  564.             else
  565.                 begin
  566.                     degrees:=strtointdef(s,no_value);
  567.                     if degrees=no_value then
  568.                         exit;
  569.                 end;
  570.             r:=copy(r,i+1,length(r)-i);
  571.             i:=pos(':',r);
  572.             if i=0 then
  573.                 begin
  574.                     i:=pos('.',r);
  575.                     h:=false;
  576.                     if i=0 then
  577.                         begin
  578.                             i:=length(r)+1;
  579.                             n:=true;
  580.                         end
  581.                     else
  582.                         begin
  583.                             low:=high;
  584.                             n:=false;
  585.                         end;
  586.                 end
  587.             else
  588.                 begin
  589.                     low:='';
  590.                     h:=true;
  591.                     n:=false;
  592.                 end;
  593.             s:=copy(r,1,i-1);
  594.             minutes:=strtointdef(s,no_value);
  595.             if minutes=no_value then
  596.                 exit;
  597.             if n then
  598.                 begin
  599.                     tens:=0;
  600.                     seconds:=0;
  601.                 end
  602.             else
  603.                 begin
  604.                     r:=copy(r,i+1,length(r)-i);
  605.                     if not h then
  606.                         begin
  607.                             tens:=strtointdef(r,no_value);
  608.                             if tens=no_value then
  609.                                 exit;
  610.                             seconds:=tens*10;
  611.                         end
  612.                     else
  613.                         begin
  614.                             seconds:=strtointdef(r,no_value);
  615.                             if seconds=no_value then
  616.                                 exit;
  617.                             tens:=seconds div 10;
  618.                         end;
  619.                 end;
  620.             f:=seconds/60;
  621.             f:=(f+minutes)/60;
  622.             f:=f+degrees;
  623.         end;
  624.     az:=f;
  625.     result:=true;
  626. end;
  627.  
  628. { sDDflMM:SS
  629.     sDDflMM }
  630. function tscope_object.str_altitude(
  631.     var f:double;
  632.     var alt_rec:ams)
  633.             :boolean;
  634. var
  635.     t_dec:double;
  636. begin
  637.     t_dec:=dec;
  638.     result:=str_declination(f,dms(alt_rec));
  639.     alt:=f;
  640.     dec:=t_dec;
  641. end;
  642.  
  643. function tscope_object.str_right_ascension(
  644.     var ra_rec:hms)
  645.             :boolean;
  646. begin
  647.     result:=str_right_ascension(ra,ra_rec);
  648. end;
  649.  
  650. function tscope_object.str_declination(
  651.     var dec_rec:dms)
  652.             :boolean;
  653. begin
  654.     result:=str_declination(dec,dec_rec);
  655. end;
  656.  
  657. function tscope_object.str_azimuth(
  658.     var az_rec:dms)
  659.             :boolean;
  660. begin
  661.     result:=str_azimuth(az,az_rec);
  662. end;
  663.  
  664. function tscope_object.str_altitude(
  665.     var alt_rec:ams)
  666.             :boolean;
  667. begin
  668.     result:=str_altitude(alt,alt_rec);
  669. end;
  670.  
  671. begin
  672.     current_object:=nil;
  673.     current_object:=tscope_object.create;
  674. end.
  675.