/* co_sunset.f -- translated by f2c (version 20100827).
   You must link the resulting object file with libf2c:
	on Microsoft Windows system, link with libf2c.lib;
	on Linux or Unix systems, link with .../path/to/libf2c.a -lm
	or, if you install libf2c.a in a standard place, with -lf2c -lm
	-- in that order, at the end of the command line, as in
		cc *.o -lf2c -lm
	Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,

		http://www.netlib.org/f2c/libf2c.zip
*/

#include "f2c.h"

/* Table of constant values */

static integer c__1 = 1;
static integer c__4 = 4;
static integer c_n1 = -1;
static integer c__9 = 9;
static integer c__3 = 3;

/* Main program */ int MAIN__(void)
{
    /* Format strings */
    static char fmt_200[] = "(4a)";
    static char fmt_300[] = "(2f10.3,2a)";
    static char fmt_100[] = "(\002 merid. time (UT)= \002,a8,\002 sunrise="
	    " \002,a8,\002 sunset= \002,a8,\002 durd= \002,a8)";

    /* System generated locals */
    integer i__1;

    /* Builtin functions */
    integer s_wsfe(cilist *), e_wsfe(void), do_fio(integer *, char *, ftnlen),
	     s_rsfe(cilist *), e_rsfe(void), s_rsli(icilist *), do_lio(
	    integer *, integer *, char *, ftnlen), e_rsli(void);
    /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen), s_stop(char *
	    , ftnlen);

    /* Local variables */
    extern /* Subroutine */ int cchapos___(char *, char *, integer *, integer 
	    *, ftnlen, ftnlen), cp_sunrise_sunset__(integer *, integer *, 
	    integer *, real *, real *, char *, char *, char *, char *, real *,
	     real *, real *, real *, real *, real *, integer *, ftnlen, 
	    ftnlen, ftnlen, ftnlen);
    static integer iday, icor;
    static char lieu[32], durd[8];
    static integer imon;
    static real rlat;
    static char tmer[8];
    static real rlon;
    static char tset[8];
    static integer npos;
    static char tris[8], ligne[80];
    static integer iyear;
    extern /* Subroutine */ int r_date__(integer *, integer *, integer *);
    static real elemer, eleset, eleris, azimer, aziset, aziris;

    /* Fortran I/O blocks */
    static cilist io___1 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___2 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___3 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___4 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___5 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___6 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___7 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___11 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___12 = { 0, 5, 1, fmt_200, 0 };
    static icilist io___14 = { 0, ligne, 0, 0, 80, 1 };
    static cilist io___19 = { 0, 6, 0, fmt_300, 0 };
    static cilist io___20 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___32 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___33 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___34 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___35 = { 0, 6, 0, fmt_200, 0 };



/*     ***************************************************************0** */
/* *   Compute_Sunset: computation of sunrise and sunset time */
/*     P. Robert, Dec 2011 */
/*     ***************************************************************0** */


    s_wsfe(&io___1);
    e_wsfe();
    s_wsfe(&io___2);
    do_fio(&c__1, "****************************************************", (
	    ftnlen)52);
    e_wsfe();
    s_wsfe(&io___3);
    e_wsfe();
    s_wsfe(&io___4);
    do_fio(&c__1, "sunset: computation of sunrise and sunset time", (ftnlen)
	    46);
    e_wsfe();
    s_wsfe(&io___5);
    do_fio(&c__1, "        assuming spherical Earth", (ftnlen)32);
    e_wsfe();
    s_wsfe(&io___6);
    e_wsfe();

L10:
    s_wsfe(&io___7);
    do_fio(&c__1, "-----------------------------------------------------", (
	    ftnlen)53);
    e_wsfe();

    r_date__(&iyear, &imon, &iday);

    s_wsfe(&io___11);
    do_fio(&c__1, "lat et long en degre, et lieu ? (blank separator, 0 or q "
	    "to quit)", (ftnlen)65);
    e_wsfe();

    i__1 = s_rsfe(&io___12);
    if (i__1 != 0) {
	goto L20;
    }
    i__1 = do_fio(&c__1, ligne, (ftnlen)80);
    if (i__1 != 0) {
	goto L20;
    }
    i__1 = e_rsfe();
    if (i__1 != 0) {
	goto L20;
    }
    if (*(unsigned char *)ligne == '0' || *(unsigned char *)ligne == 'q') {
	goto L20;
    }
    s_rsli(&io___14);
    do_lio(&c__4, &c__1, (char *)&rlat, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&rlon, (ftnlen)sizeof(real));
    e_rsli();

    cchapos___(ligne, " ", &c_n1, &npos, (ftnlen)80, (ftnlen)1);
    i__1 = npos;
    s_copy(lieu, ligne + i__1, (ftnlen)32, 32 - i__1);

    s_wsfe(&io___19);
    do_fio(&c__1, (char *)&rlat, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlon, (ftnlen)sizeof(real));
    do_fio(&c__1, "   ", (ftnlen)3);
    do_fio(&c__1, lieu, (ftnlen)32);
    e_wsfe();
    s_wsfe(&io___20);
    e_wsfe();


    rlat = rlat * 3.1415927f / 180.f;
    rlon = rlon * 3.1415927f / 180.f;

    icor = 3;

    cp_sunrise_sunset__(&iyear, &imon, &iday, &rlat, &rlon, tmer, tris, tset, 
	    durd, &elemer, &azimer, &eleris, &aziris, &eleset, &aziset, &icor,
	     (ftnlen)8, (ftnlen)8, (ftnlen)8, (ftnlen)8);

    s_wsfe(&io___32);
    do_fio(&c__1, tmer, (ftnlen)8);
    do_fio(&c__1, tris, (ftnlen)8);
    do_fio(&c__1, tset, (ftnlen)8);
    do_fio(&c__1, durd, (ftnlen)8);
    e_wsfe();
    goto L10;
L20:


    s_wsfe(&io___33);
    e_wsfe();
    s_wsfe(&io___34);
    do_fio(&c__1, "****************************************************", (
	    ftnlen)52);
    e_wsfe();
    s_wsfe(&io___35);
    e_wsfe();
    s_stop("co_sunset: normal termination", (ftnlen)29);
    return 0;
} /* MAIN__ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int cchapos___(char *chast, char *cha, integer *isens, 
	integer *npos, ftnlen chast_len, ftnlen cha_len)
{
    /* System generated locals */
    integer i__1;

    /* Builtin functions */
    integer i_len(char *, ftnlen), s_wsle(cilist *), do_lio(integer *, 
	    integer *, char *, ftnlen), e_wsle(void);
    /* Subroutine */ int s_stop(char *, ftnlen);
    integer s_cmp(char *, char *, ftnlen, ftnlen);

    /* Local variables */
    static integer i__, ii, nbc, nbcha;

    /* Fortran I/O blocks */
    static cilist io___37 = { 0, 6, 0, 0, 0 };
    static cilist io___38 = { 0, 6, 0, 0, 0 };
    static cilist io___39 = { 0, 6, 0, 0, 0 };
    static cilist io___40 = { 0, 6, 0, 0, 0 };
    static cilist io___44 = { 0, 6, 0, 0, 0 };
    static cilist io___45 = { 0, 6, 0, 0, 0 };



/*     ---------------------------------------------------------------+-- */
/* *   Object : compute_character_position without end blanks */
/* *   Class  : compute modules of Rogralib Software */
/* *   Author : P. Robert, PatCie, 1992 */
/*     ---------------------------------------------------------------+-- */


    nbc = i_len(cha, cha_len);
    if (nbc != 1) {
	s_wsle(&io___37);
	do_lio(&c__9, &c__1, "***cha=", (ftnlen)7);
	do_lio(&c__9, &c__1, cha, nbc);
	do_lio(&c__9, &c__1, " must be 1 character", (ftnlen)20);
	e_wsle();
	s_wsle(&io___38);
	do_lio(&c__9, &c__1, "   program aborted", (ftnlen)18);
	e_wsle();
	s_stop("*** program aborted", (ftnlen)19);
    }


    nbc = i_len(chast, chast_len);
    if (nbc > 255) {
	s_wsle(&io___39);
	do_lio(&c__9, &c__1, "***nbc=", (ftnlen)7);
	do_lio(&c__3, &c__1, (char *)&nbc, (ftnlen)sizeof(integer));
	do_lio(&c__9, &c__1, " > 255", (ftnlen)6);
	e_wsle();
	s_wsle(&io___40);
	do_lio(&c__9, &c__1, "   program aborted", (ftnlen)18);
	e_wsle();
	s_stop("*** program aborted", (ftnlen)19);
    }

/* *** dernier caractere non blanc */

    i__1 = nbc;
    for (i__ = 1; i__ <= i__1; ++i__) {
	ii = nbc - i__ + 1;
	if (*(unsigned char *)&chast[ii - 1] != ' ') {
	    goto L12;
	}
/* L10: */
    }
    ii = 0;
L12:

    nbcha = ii;

/* *** recherche du caratere cha */

    i__1 = nbcha;
    for (i__ = 1; i__ <= i__1; ++i__) {
	if (*isens < 0) {
	    ii = nbcha - i__ + 1;
	} else {
	    ii = 1;
	}

	if (s_cmp(chast + (ii - 1), cha, (ftnlen)1, cha_len) == 0) {
	    goto L22;
	}
/* L20: */
    }
    s_wsle(&io___44);
    do_lio(&c__9, &c__1, "* cchapos: char. ", (ftnlen)17);
    do_lio(&c__9, &c__1, cha, cha_len);
    do_lio(&c__9, &c__1, " not found in ", (ftnlen)14);
    do_lio(&c__9, &c__1, chast, nbcha);
    e_wsle();
    s_wsle(&io___45);
    do_lio(&c__9, &c__1, "           npos set to zero", (ftnlen)27);
    e_wsle();
    *npos = 0;
L22:
    *npos = ii;

    return 0;
} /* cchapos___ */

/* Main program alias */ int co_sunset__ () { MAIN__ (); return 0; }
