Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

get-USNO-sunmoon.php

Discussion of Ken True's web site templates

Moderator: saratogaWX

Post Reply
n9mfk
Posts: 845
Joined: Sun 10 May 2009 8:52 pm
Weather Station: davis vp2 Serial datalogger
Operating System: Windows 7 64-bit
Location: Springfield, IL

get-USNO-sunmoon.php

Post by n9mfk »

Hi Ken,
I have some question about get-USNO-sunmoon.php

Code: Select all

<!-- cGetMoonInfo returns
stdClass Object
(
    [date] => 1368068229
    [datetxt] => Thu, 09-May-2013 02:57 GMT
    [age] => 28 days, 17 hours, 22 minutes
    [ill] => 1
    [pic] => 27
    [phase] => Waning Crescent
    [NM] => 1365586500
    [NMGMT] => Wed, 10-Apr-2013 09:35 GMT
    [NMWD] => 09:35 GMT 10 April 2013
    [Q1] => 1366288260
    [Q1GMT] => Thu, 18-Apr-2013 12:31 GMT
    [Q1WD] => 12:31 GMT 18 April 2013
    [FM] => 1366919820
    [FMGMT] => Thu, 25-Apr-2013 19:57 GMT
    [FMWD] => 19:57 GMT 25 April 2013
    [Q3] => 1367493240
    [Q3GMT] => Thu, 02-May-2013 11:14 GMT
    [Q3WD] => 11:14 GMT 02 May 2013
    [Q4] => 1368145680
    [Q4GMT] => Fri, 10-May-2013 00:28 GMT
    [Q4WD] => 00:28 GMT 10 May 2013
    [FM2] => 1369455900
    [FM2GMT] => Sat, 25-May-2013 04:25 GMT
    [FM2WD] => 04:25 GMT 25 May 2013
    [moons] => Array
        (
            [0] => Array
                (
                    [0] => New Moon
                    [1] => 1368145680
                    [2] => NM
                    [3] => Thu, 09 May 2013 19:28:00 -0500
                )

            [1] => Array
                (
                    [0] => First Quarter
                    [1] => 1368851640
                    [2] => Q1
                    [3] => Fri, 17 May 2013 23:34:00 -0500
                )

            [2] => Array
                (
                    [0] => Full Moon
                    [1] => 1369455900
                    [2] => FM
                    [3] => Fri, 24 May 2013 23:25:00 -0500
                )

            [3] => Array
                (
                    [0] => Last Quarter
                    [1] => 1370026680
                    [2] => Q3
                    [3] => Fri, 31 May 2013 13:58:00 -0500
                )

        )

)
 -->
<!-- get-USNO-sunmoon.php - Version 1.02 - 03-Dec-2011 -->
<!-- loading ./cache/USNO-moondata.txt from http://aa.usno.navy.mil/cgi-bin/aa_pap.pl -->
<!-- POST /cgi-bin/aa_pap.pl HTTP/1.1 
      Host: aa.usno.navy.mil  Port: 80 IP=199.211.133.93-->
<!-- Sending:
POST /cgi-bin/aa_pap.pl HTTP/1.1
Host: aa.usno.navy.mil
Connection: Close
Accept: text/plain,text/html
Accept-Encoding: gzip;q=0,compress;q=0
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Referer: http://aa.usno.navy.mil/data/docs/RS_OneDay.php
Content-Length: 125
Content-Type: application/x-www-form-urlencoded

FFX=2&ID=AA&xxy=2013&xxm=5&xxd=8&place=Springfield%2C+IL%2C+USA&xx0=-1&xx1=89&xx2=37&yy0=1&yy1=39&yy2=42&zz1=5&zz0=-1&ZZZ=END

-->
<!-- HTTP stats:  dns=0.046 conn=0.042 put=0.000 get(63 blocks)=0.086 close=0.000 total=0.175 secs -->
<!-- fetch function elapsed= 0 secs. -->
<!-- loading finished. -->
<!-- USNOdata
Array
(
    [beginciviltwilight] => 05:21
    [beginciviltwilightdate] => 05/08/2013
    [sunrise] => 05:51
    [sunrisedate] => 05/08/2013
    [suntransit] => 12:55
    [suntransitdate] => 05/08/2013
    [sunset] => 20:00
    [sunsetdate] => 05/08/2013
    [endciviltwilight] => 20:30
    [endciviltwilightdate] => 05/08/2013
    [moonsetprior] => 17:59
    [moonsetpriordate] => 05/07/2013
    [moonrise] => 04:59
    [moonrisedate] => 05/08/2013
    [moontransit] => 11:55
    [moontransitdate] => 05/08/2013
    [moonset] => 18:58
    [moonsetdate] => 05/08/2013
    [moonrisenext] => 05:34
    [moonrisenextdate] => 05/09/2013
    [moonphase] => Waning Crescent
    [illumination] => 2%
    [hoursofpossibledaylight] => 14:09
)
ill show 1
but if you print $moonphase i get 2

Any ideas?
Thanks Beau

http://99.148.148.51/
User avatar
saratogaWX
Posts: 1238
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: get-USNO-sunmoon.php

Post by saratogaWX »

I'm not sure what you are asking about, Beau.

In the ajax-dashboard.php it has

Code: Select all

    if(file_exists("get-USNO-sunmoon.php")) { 
      include_once("get-USNO-sunmoon.php");
	  $USNOdata = getUSNOsunmoon();
   }
   if(isset($USNOdata['sunrise']))                 {$sunrise =     $USNOdata['sunrise']; }  
   if(isset($USNOdata['sunrisedate']))             {$sunrisedate = $USNOdata['sunrisedate']; }  
   if(isset($USNOdata['sunset']))                  {$sunset =      $USNOdata['sunset']; }  
   if(isset($USNOdata['sunsetdate']))              {$sunsetdate =  $USNOdata['sunsetdate']; }  
   if(isset($USNOdata['moonrise']))                {$moonrise =    $USNOdata['moonrise']; }  
   if(isset($USNOdata['moonrisedate']))            {$moonrisedate= $USNOdata['moonrisedate']; }  
   if(isset($USNOdata['moonset']))                 {$moonset =     $USNOdata['moonset']; }  
   if(isset($USNOdata['moonsetdate']))             {$moonsetdate = $USNOdata['moonsetdate']; }  
   if(isset($USNOdata['moonphase']))               {$moonphasename = $USNOdata['moonphase']; }  
   if(isset($USNOdata['illumination']))            {$moonphase = $USNOdata['illumination']; }  
   if(isset($USNOdata['hoursofpossibledaylight'])) {$hoursofpossibledaylight = $USNOdata['hoursofpossibledaylight'];} 
which shows how the get-USNO-sunmoon.php is called and data returned is assigned to $variables corresponding to the Weather-Display tag names used throughout the dashboard.

$moonphase will contain the percentage illumination (0 at new moon, 100 at full moon)
$moonphasename will contain the text of the current moon phase name

Puzzled,
Ken
n9mfk
Posts: 845
Joined: Sun 10 May 2009 8:52 pm
Weather Station: davis vp2 Serial datalogger
Operating System: Windows 7 64-bit
Location: Springfield, IL

Re: get-USNO-sunmoon.php

Post by n9mfk »

Hi Ken,
My Question Was my [ill] => 1 but when I printed $moonphase i get 2
but it should have been 1
Beau
User avatar
saratogaWX
Posts: 1238
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: get-USNO-sunmoon.php

Post by saratogaWX »

I think you just didn't see in the code that there are two methods for doing the moon calcs .. one built-in (with approximations and not quite exact for data) and the second method using get-USNO-sunmoon.php which overrides the approximate calculations if available.

The get-USNO-sunmoon.php results are exact for the latitude/longitude and are the preferred displays .. that's why they override the built-in approximations.

Since you have get-USNO-sunmoon.php available and functional, it is the latter results that are shown and used in the page.
n9mfk
Posts: 845
Joined: Sun 10 May 2009 8:52 pm
Weather Station: davis vp2 Serial datalogger
Operating System: Windows 7 64-bit
Location: Springfield, IL

Re: get-USNO-sunmoon.php

Post by n9mfk »

Ken,
use the example for above were [ill] => 1 if i wanted to display that what wood I print in php?
thanks Beau
User avatar
saratogaWX
Posts: 1238
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: get-USNO-sunmoon.php

Post by saratogaWX »

I am not understanding why you would want to display the approximated value (from [ill]) instead of the accurate value (from the USNO), but I suppose you have your reasons.

To display it, you just have go look at the code in ajax-dashboard where these are done

Code: Select all

	$mooninfo = cGetMoonInfo();  /* Note:  getMoonInfo() is located in common.php */
/* returns $mooninfo of:
    [age] => 9 days, 11 hours, 57 minutes
    [ill] => 65
    [pic] => 8
    [phase] => Waxing Gibbous
    [NM] => 1294131882
    [NMGMT] => Tue, 04-Jan-2011 09:04 GMT
    [NMWD] => 09:04 GMT 04 January 2011
    [Q1] => 1294831983
    [Q1GMT] => Wed, 12-Jan-2011 11:33 GMT
    [Q1WD] => 11:33 GMT 12 January 2011
    [FM] => 1295472210
    [FMGMT] => Wed, 19-Jan-2011 21:23 GMT
    [FMWD] => 21:23 GMT 19 January 2011
    [Q3] => 1298590089
    [Q3GMT] => Thu, 24-Feb-2011 23:28 GMT
    [Q3WD] => 23:28 GMT 24 February 2011
    [Q4] => 1296700310
    [Q4GMT] => Thu, 03-Feb-2011 02:31 GMT
    [Q4WD] => 02:31 GMT 03 February 2011
    [FM2] => 1298018189
    [FM2GMT] => Fri, 18-Feb-2011 08:36 GMT
    [FM2WD] => 08:36 GMT 18 February 2011
*/
	print "<!-- cGetMoonInfo returns\n".print_r($mooninfo,true)." -->\n";
	if(!isset($moonphase)) {$moonphase = $mooninfo->ill.'%'; }
So if you really want to just print the [ill] return, then

Code: Select all

<?php print $mooninfo->ill; ?>
would do that directly.
n9mfk
Posts: 845
Joined: Sun 10 May 2009 8:52 pm
Weather Station: davis vp2 Serial datalogger
Operating System: Windows 7 64-bit
Location: Springfield, IL

Re: get-USNO-sunmoon.php

Post by n9mfk »

Ken,
this code from the dashboard
can you enplane why If you print $moonphase wha the output wood not be the value of $mooninfo->ill

Code: Select all

if(!isset($moonphase)) {$moonphase = $mooninfo->ill.'%'; }
Thanks Beau
User avatar
saratogaWX
Posts: 1238
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: get-USNO-sunmoon.php

Post by saratogaWX »

Simple... PHP executes code in a sequential order starting at the top of the page and proceeding downward, statement by statement until all the code is executed. If an assignment to $moonphase is done further down the page, then that is the value used.

Here's an excerpt from ajax-dashboard.php where it shows this for $moonphase
if($SITE['WXsoftware'] == 'WD') {
// Sample from WD: $moonage = "Moon age: 10 days,10 hours,41 minutes,80%"; // current age of the moon (days since new moon)
// Sample from WD: $moonphase = "80%"; // Moon phase %
$moonagedays = preg_replace('|^Moon age:\s+(\d+)\s.*$|is',"\$1",$moonage);
if($moonphase == '') { // MAC version of WD is missing this value
preg_match_all('|(\d+)|is',$moonage,$matches);
$moonphase = $matches[1][3];
if(isset($matches[1][4])) {
$moonphase .= '.' . $matches[1][4]; // pick up decimal;
$moonphase = round($moonphase,0);
}
$moonphase .= '%';
}
} else { // perform non-WD moon stuff
$mooninfo = cGetMoonInfo(); /* Note: getMoonInfo() is located in common.php */
/* returns $mooninfo of:
[age] => 9 days, 11 hours, 57 minutes
[ill] => 65
[pic] => 8
[phase] => Waxing Gibbous
[NM] => 1294131882
[NMGMT] => Tue, 04-Jan-2011 09:04 GMT
[NMWD] => 09:04 GMT 04 January 2011
[Q1] => 1294831983
[Q1GMT] => Wed, 12-Jan-2011 11:33 GMT
[Q1WD] => 11:33 GMT 12 January 2011
[FM] => 1295472210
[FMGMT] => Wed, 19-Jan-2011 21:23 GMT
[FMWD] => 21:23 GMT 19 January 2011
[Q3] => 1298590089
[Q3GMT] => Thu, 24-Feb-2011 23:28 GMT
[Q3WD] => 23:28 GMT 24 February 2011
[Q4] => 1296700310
[Q4GMT] => Thu, 03-Feb-2011 02:31 GMT
[Q4WD] => 02:31 GMT 03 February 2011
[FM2] => 1298018189
[FM2GMT] => Fri, 18-Feb-2011 08:36 GMT
[FM2WD] => 08:36 GMT 18 February 2011
*/
print "<!-- cGetMoonInfo returns\n".print_r($mooninfo,true)." -->\n";
if(!isset($moonphase)) {$moonphase = $mooninfo->ill.'%'; }
if(!isset($newmoon)) {$newmoon = $mooninfo->NMWD; }
if(!isset($nextnewmoon)) {$nextnewmoon = $mooninfo->Q4WD; } /*check this! */
if(!isset($firstquarter)) {$firstquarter = $mooninfo->Q1WD; }
if(!isset($lastquarter)) {$lastquarter = $mooninfo->Q3WD; }
if(!isset($fullmoon)) {$fullmoon = $mooninfo->FMWD; }
if(!isset($moonphasename)) {$moonphasename = $mooninfo->phase;}
if(!isset($moonagedays)) {$moonagedays = $mooninfo->pic; }
if(!isset($moonage)) {$moonage = 'Moon age: '.$mooninfo->age.','.$mooninfo->ill.'%'; }
if(file_exists("get-USNO-sunmoon.php")) {
include_once("get-USNO-sunmoon.php");
$USNOdata = getUSNOsunmoon();
}
if(isset($USNOdata['sunrise'])) {$sunrise = $USNOdata['sunrise']; }
if(isset($USNOdata['sunrisedate'])) {$sunrisedate = $USNOdata['sunrisedate']; }
if(isset($USNOdata['sunset'])) {$sunset = $USNOdata['sunset']; }
if(isset($USNOdata['sunsetdate'])) {$sunsetdate = $USNOdata['sunsetdate']; }
if(isset($USNOdata['moonrise'])) {$moonrise = $USNOdata['moonrise']; }
if(isset($USNOdata['moonrisedate'])) {$moonrisedate= $USNOdata['moonrisedate']; }
if(isset($USNOdata['moonset'])) {$moonset = $USNOdata['moonset']; }
if(isset($USNOdata['moonsetdate'])) {$moonsetdate = $USNOdata['moonsetdate']; }
if(isset($USNOdata['moonphase'])) {$moonphasename = $USNOdata['moonphase']; }
if(isset($USNOdata['illumination'])) {$moonphase = $USNOdata['illumination']; }
if(isset($USNOdata['hoursofpossibledaylight'])) {$hoursofpossibledaylight = $USNOdata['hoursofpossibledaylight'];}
}
Follow the logic:
1) if the weather software is Weather-Display, the native tag $moonage is parsed to extract $moonphase, otherwise
2) the built-in function cGetMoonInfo() returns an approximation of the illumination in $mooninfo->ill and that becomes $moonphase

if get-USNO-sunmoon.php is installed and successfully returns data, then the $USNOdata['illumination'] becomes $moonphase

It's always best to read the code to understand how something works.
n9mfk
Posts: 845
Joined: Sun 10 May 2009 8:52 pm
Weather Station: davis vp2 Serial datalogger
Operating System: Windows 7 64-bit
Location: Springfield, IL

Re: get-USNO-sunmoon.php

Post by n9mfk »

Thanks ken, i understand now
Thanks Beau
Post Reply