How to resolve the algorithm Averages/Mean time of day step by step in the PL/I programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Averages/Mean time of day step by step in the PL/I programming language

Table of Contents

Problem Statement

A particular activity of bats occurs at these times of the day: Using the idea that there are twenty-four hours in a day, which is analogous to there being 360 degrees in a circle, map times of day to and from angles; and using the ideas of Averages/Mean angle compute and show the average time of the nocturnal activity to an accuracy of one second of time.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Averages/Mean time of day step by step in the PL/I programming language

Source code in the pl/i programming language

*process source attributes xref;
 avt: Proc options(main);
 /*--------------------------------------------------------------------
 * 25.06.2014 Walter Pachl taken from REXX
 *-------------------------------------------------------------------*/
 Dcl (addr,hbound,sin,cos,atan) Builtin;
 Dcl sysprint Print;
 Dcl times(4) Char(8) Init('23:00:17','23:40:20','00:12:45','00:17:19');
 Dcl time Char(8);
 Dcl (alpha,x,y,ss,ww) Dec Float(18) Init(0);
 Dcl day Bin Fixed(31) Init(86400);
 Dcl pi Dec Float(18) Init(3.14159265358979323846);
 Dcl (i,h,m,s) bin Fixed(31) Init(0);
 Do i=1 To hbound(times);              /* loop over times            */
  time=times(i);                       /* pick a time                */
  alpha=t2a(time);                     /* convert to angle (radians) */
  x=x+sin(alpha);                      /* accumulate sines           */
  y=y+cos(alpha);                      /* accumulate cosines         */
  End;
 ww=atan(x/y);                         /* compute average angle      */
 ss=ww*day/(2*pi);                     /* convert to seconds         */
 If ss<0 Then ss=ss+day;               /* avoid negative value       */
 m=ss/60;                              /* split into hh mm ss        */
 s=ss-m*60;
 h=m/60;
 m=m-h*60;
 Put Edit(h,':',m,':',s)(Skip,3(p'99',a));

 t2a: Procedure(t) Returns(Bin Float(18)); /* convert time to angle  */
 Dcl t Char(8);
 Dcl 1 tt Based(addr(t)),
      2 hh Pic'99',
      2 * Char(1),
      2 mm Pic'99',
      2 * Char(1),
      2 ss Pic'99';
 Dcl sec Bin Fixed(31);
 Dcl a   Bin Float(18);
 sec=(hh*60+mm)*60+ss;
 If sec>(day/2) Then
   sec=sec-day;
 a=2*pi*sec/day;
 Return (a);
 End;

 End;

  

You may also check:How to resolve the algorithm Pi step by step in the RPL programming language
You may also check:How to resolve the algorithm Van Eck sequence step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Filter step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Pascal's triangle step by step in the Ada programming language
You may also check:How to resolve the algorithm Longest string challenge step by step in the Yabasic programming language