Index: trunk/SophyaExt/XephemAstroLib/riset_cir.c
===================================================================
--- trunk/SophyaExt/XephemAstroLib/riset_cir.c	(revision 1719)
+++ trunk/SophyaExt/XephemAstroLib/riset_cir.c	(revision 2551)
@@ -3,20 +3,16 @@
 #include <stdio.h>
 #include <math.h>
-#if defined(__STDC__)
 #include <stdlib.h>
 #include <string.h>
-#endif
-
-#include "P_.h"
+
 #include "astro.h"
-#include "circum.h"
 
 #define	TMACC	(10./3600./24.0)	/* convergence accuracy, days */
 
-static void e_riset_cir P_((Now *np, Obj *op, double dis, RiseSet *rp));
-static int find_0alt P_((double dt, double dis, Now *np, Obj *op));
-static int find_transit P_((double dt, Now *np, Obj *op));
-static int find_max P_((Now *np, Obj *op, double tr, double ts, double *tp,
-    double *alp));
+static void e_riset_cir (Now *np, Obj *op, double dis, RiseSet *rp);
+static int find_0alt (double dt, double dis, Now *np, Obj *op);
+static int find_transit (double dt, Now *np, Obj *op);
+static int find_max (Now *np, Obj *op, double tr, double ts, double *tp,
+    double *alp);
 
 /* find where and when an object, op, will rise and set and
@@ -26,9 +22,5 @@
  */
 void
-riset_cir (np, op, dis, rp)
-Now *np;
-Obj *op;
-double dis;
-RiseSet *rp;
+riset_cir (Now *np, Obj *op, double dis, RiseSet *rp)
 {
 	double mjdn;	/* mjd of local noon */
@@ -64,6 +56,6 @@
 	/* first approximation is to find rise/set times of a fixed object
 	 * at the current epoch in its position at local noon.
-	 * N.B. add typical refraction for initial go/no-go test. if it
-	 *   passes, real code does refraction rigorously.
+	 * N.B. add typical refraction if dis is above horizon for initial
+	 *   go/no-go test. if it passes, real code does refraction rigorously.
 	 */
 	n.n_mjd = mjdn;
@@ -73,5 +65,6 @@
 	}
 	ran = o.s_gaera;
-	riset (o.s_gaera, o.s_gaedec, lat, dis+.01, &lr, &ls, &ar, &as, &rss);
+	riset (o.s_gaera, o.s_gaedec, lat, dis+(dis>.01 ? 0 : .01), &lr, &ls,
+								&ar, &as, &rss);
 	switch (rss) {
 	case  0:  break;
@@ -133,15 +126,12 @@
  */
 void
-twilight_cir (np, dis, dawn, dusk, status)
-Now *np;
-double dis;
-double *dawn, *dusk;
-int *status;
+twilight_cir (Now *np, double dis, double *dawn, double *dusk, int *status)
 {
 	RiseSet rs;
 	Obj o;
 
+	memset (&o, 0, sizeof(o));
 	o.o_type = PLANET;
-	o.pl.pl_code = SUN;
+	o.pl_code = SUN;
 	(void) strcpy (o.o_name, "Sun");
 	riset_cir (np, &o, dis, &rs);
@@ -160,9 +150,5 @@
  */
 static void
-e_riset_cir (np, op, dis, rp)
-Now *np;
-Obj *op;
-double dis;
-RiseSet *rp;
+e_riset_cir (Now *np, Obj *op, double dis, RiseSet *rp)
 {
 #define	DEGSTEP	5		/* time step is about this many degrees */
@@ -272,9 +258,9 @@
  */
 static int
-find_0alt (dt, dis, np, op)
-double dt;	/* hours from noon to first guess at event */
-double dis;	/* horizon displacement, rads */
-Now *np;	/* working Now -- starts with mjd is noon, returns as answer */
-Obj *op;	/* working object -- returns as answer */
+find_0alt (
+double dt,	/* hours from noon to first guess at event */
+double dis,	/* horizon displacement, rads */
+Now *np,	/* working Now -- starts with mjd is noon, returns as answer */
+Obj *op)	/* working object -- returns as answer */
 {
 #define	MAXPASSES	20		/* max iterations to try */
@@ -286,8 +272,10 @@
 
 	/* insure initial guess is today -- if not, move by 24 hours */
-	if (dt < -12.0)
-	    dt += 24.0;
-	if (dt > 12.0)
-	    dt -= 24.0;
+	if (dt < -12.0 && !find_0alt (dt+24, dis, np, op))
+	    return (0);
+	mjd = mjdn;
+	if (dt > 12.0 && !find_0alt (dt-24, dis, np, op))
+	    return (0);
+	mjd = mjdn;
 	
 	/* convert dt to days for remainder of algorithm */
@@ -325,8 +313,5 @@
  */
 static int
-find_transit (dt, np, op)
-double dt;
-Now *np;
-Obj *op;
+find_transit (double dt, Now *np, Obj *op)
 {
 #define	MAXLOOPS	10
@@ -370,9 +355,9 @@
  */
 static int
-find_max (np, op, tr, ts, tp, alp)
-Now *np;
-Obj *op;
-double tr, ts;		/* times of rise and set */
-double *tp, *alp;	/* time of max altitude, and that altitude */
+find_max (
+Now *np,
+Obj *op,
+double tr, double ts,		/* times of rise and set */
+double *tp, double *alp)	/* time of max altitude, and that altitude */
 {
 	mjd = (ts + tr)/2;
@@ -385,3 +370,3 @@
 
 /* For RCS Only -- Do Not Edit */
-static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: riset_cir.c,v $ $Date: 2001-10-22 12:08:28 $ $Revision: 1.2 $ $Name: not supported by cvs2svn $"};
+static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: riset_cir.c,v $ $Date: 2004-06-15 16:52:40 $ $Revision: 1.3 $ $Name: not supported by cvs2svn $"};
