/* co_sunset_year.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__3 = 3;
static integer c__4 = 4;
static integer c_n1 = -1;
static integer c__9 = 9;

/* Main program */ int MAIN__(void)
{
    /* Format strings */
    static char fmt_200[] = "(a)";
    static char fmt_400[] = "(i4,\002-\002,i2.2,\002-\002,i2.2,3(2x,a5,2a8),"
	    "2x,a4)";
    static char fmt_300[] = "(2f10.3,2a)";
    static char fmt_100[] = "(a7,2x,3(a7,2a8),2x,a5)";

    /* System generated locals */
    integer i__1;
    char ch__1[8];

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

    /* Local variables */
    extern /* Subroutine */ int cchapos___(char *, char *, integer *, integer 
	    *, ftnlen, ftnlen), cp_en_month_name__(integer *, char *, integer 
	    *, ftnlen), cp_nbday_in_month__(integer *, integer *, integer *), 
	    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 ncha, iday;
    static char cmon[12];
    static integer icor;
    static char lieu[32], durd[8];
    static real rlat;
    static integer imon;
    extern /* Character */ VOID conv_(char *, ftnlen, real *);
    static char tmer[8];
    static real rlon;
    static char tset[8];
    static integer npos;
    static char tris[8];
    static integer nbday;
    static char ligne[80];
    static integer iyear;
    static real elemer;
    extern /* Subroutine */ int arondi_(char *, ftnlen);
    static real eleset, eleris, azimer, aziset, aziris;
    static char celemer[8], celeset[8], celeris[8], cazimer[8], caziset[8], 
	    caziris[8];

    /* 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___8 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___9 = { 0, 5, 0, 0, 0 };
    static cilist io___11 = { 0, 6, 0, fmt_400, 0 };
    static cilist io___12 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___13 = { 0, 5, 0, fmt_200, 0 };
    static icilist io___15 = { 0, ligne, 0, 0, 80, 1 };
    static cilist io___20 = { 0, 6, 0, fmt_300, 0 };
    static cilist io___25 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___26 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___27 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___28 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___47 = { 0, 6, 0, fmt_400, 0 };
    static cilist io___48 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___49 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___50 = { 0, 6, 0, fmt_200, 0 };



/*     ------------------------------------------------------------------ */
/* *   calcul des heures de lever et de coucher de Soleil en un point */
/*     et pour chaque jour d'une annee. */
/*     ------------------------------------------------------------------ */


    s_wsfe(&io___1);
    e_wsfe();
    s_wsfe(&io___2);
    do_fio(&c__1, "=====================================================", (
	    ftnlen)53);
    e_wsfe();
    s_wsfe(&io___3);
    do_fio(&c__1, "Computation of sunrise and sunset time for one year ;", (
	    ftnlen)53);
    e_wsfe();
    s_wsfe(&io___4);
    do_fio(&c__1, "Spherical Earth and constant light refaction assumed.", (
	    ftnlen)53);
    e_wsfe();
    s_wsfe(&io___5);
    do_fio(&c__1, "Patrick ROBERT, Rocotlib tools, Jan. 2017.", (ftnlen)42);
    e_wsfe();
    s_wsfe(&io___6);
    do_fio(&c__1, "=====================================================", (
	    ftnlen)53);
    e_wsfe();
    s_wsfe(&io___7);
    e_wsfe();

    s_wsfe(&io___8);
    do_fio(&c__1, "year ? ex: 2001", (ftnlen)15);
    e_wsfe();
    s_rsle(&io___9);
    do_lio(&c__3, &c__1, (char *)&iyear, (ftnlen)sizeof(integer));
    e_rsle();
    s_wsfe(&io___11);
    do_fio(&c__1, (char *)&iyear, (ftnlen)sizeof(integer));
    e_wsfe();

    s_wsfe(&io___12);
    do_fio(&c__1, "lat et long en degre, et lieu ? (blank separator)", (
	    ftnlen)49);
    e_wsfe();

    s_rsfe(&io___13);
    do_fio(&c__1, ligne, (ftnlen)80);
    e_rsfe();
    s_rsli(&io___15);
    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___20);
    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();

    rlat = rlat * 3.1415927f / 180.f;
    rlon = rlon * 3.1415927f / 180.f;
    for (imon = 1; imon <= 12; ++imon) {

	cp_nbday_in_month__(&iyear, &imon, &nbday);
	cp_en_month_name__(&imon, cmon, &ncha, (ftnlen)12);

	s_wsfe(&io___25);
	e_wsfe();
	s_wsfe(&io___26);
	do_fio(&c__1, cmon, ncha);
	e_wsfe();
	s_wsfe(&io___27);
	e_wsfe();
	s_wsfe(&io___28);
	do_fio(&c__1, "date", (ftnlen)4);
	do_fio(&c__1, "tris", (ftnlen)4);
	do_fio(&c__1, "eleris", (ftnlen)6);
	do_fio(&c__1, "aziris", (ftnlen)6);
	do_fio(&c__1, "tmer", (ftnlen)4);
	do_fio(&c__1, "elemer", (ftnlen)6);
	do_fio(&c__1, "azimer", (ftnlen)6);
	do_fio(&c__1, "tset", (ftnlen)4);
	do_fio(&c__1, "eleset", (ftnlen)6);
	do_fio(&c__1, "aziset", (ftnlen)6);
	do_fio(&c__1, "durd", (ftnlen)4);
	e_wsfe();

	icor = 3;

	i__1 = nbday;
	for (iday = 1; iday <= i__1; ++iday) {

	    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);

/* *** arondi a la minute la plus proche */

	    arondi_(tris, (ftnlen)8);
	    arondi_(tset, (ftnlen)8);
	    arondi_(tmer, (ftnlen)8);
	    arondi_(durd, (ftnlen)8);

	    conv_(ch__1, (ftnlen)8, &eleris);
	    s_copy(celeris, ch__1, (ftnlen)8, (ftnlen)8);
	    conv_(ch__1, (ftnlen)8, &aziris);
	    s_copy(caziris, ch__1, (ftnlen)8, (ftnlen)8);
	    conv_(ch__1, (ftnlen)8, &elemer);
	    s_copy(celemer, ch__1, (ftnlen)8, (ftnlen)8);
	    conv_(ch__1, (ftnlen)8, &azimer);
	    s_copy(cazimer, ch__1, (ftnlen)8, (ftnlen)8);
	    conv_(ch__1, (ftnlen)8, &eleset);
	    s_copy(celeset, ch__1, (ftnlen)8, (ftnlen)8);
	    conv_(ch__1, (ftnlen)8, &aziset);
	    s_copy(caziset, ch__1, (ftnlen)8, (ftnlen)8);
	    if (s_cmp(durd, "00:00", (ftnlen)5, (ftnlen)5) == 0) {
		s_copy(celeris, " no Sun ", (ftnlen)8, (ftnlen)8);
		s_copy(celeset, " no Sun ", (ftnlen)8, (ftnlen)8);
		s_copy(caziris, "    -   ", (ftnlen)8, (ftnlen)8);
		s_copy(caziset, "    -   ", (ftnlen)8, (ftnlen)8);
	    }
	    if (s_cmp(durd, "24:00", (ftnlen)5, (ftnlen)5) == 0) {
		s_copy(celeris, " Sun day", (ftnlen)8, (ftnlen)8);
		s_copy(celeset, " Sun day", (ftnlen)8, (ftnlen)8);
		s_copy(caziris, "    -   ", (ftnlen)8, (ftnlen)8);
		s_copy(caziset, "    -   ", (ftnlen)8, (ftnlen)8);
	    }
	    s_wsfe(&io___47);
	    do_fio(&c__1, (char *)&iyear, (ftnlen)sizeof(integer));
	    do_fio(&c__1, (char *)&imon, (ftnlen)sizeof(integer));
	    do_fio(&c__1, (char *)&iday, (ftnlen)sizeof(integer));
	    do_fio(&c__1, tris, (ftnlen)8);
	    do_fio(&c__1, celeris, (ftnlen)8);
	    do_fio(&c__1, caziris, (ftnlen)8);
	    do_fio(&c__1, tmer, (ftnlen)8);
	    do_fio(&c__1, celemer, (ftnlen)8);
	    do_fio(&c__1, cazimer, (ftnlen)8);
	    do_fio(&c__1, tset, (ftnlen)8);
	    do_fio(&c__1, celeset, (ftnlen)8);
	    do_fio(&c__1, caziset, (ftnlen)8);
	    do_fio(&c__1, durd, (ftnlen)8);
	    e_wsfe();
/* L10: */
	}
    }


    s_wsfe(&io___48);
    e_wsfe();
    s_wsfe(&io___49);
    do_fio(&c__1, "****************************************************", (
	    ftnlen)52);
    e_wsfe();
    s_wsfe(&io___50);
    e_wsfe();
    s_stop("co_sunset_year: normal termination", (ftnlen)34);
    return 0;
} /* MAIN__ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Character */ VOID conv_(char *ret_val, ftnlen ret_val_len, real *angle)
{
    /* Format strings */
    static char fmt_100[] = "(i4,a1,i2.2,a1)";

    /* Builtin functions */
    /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
    integer s_wsfi(icilist *), do_fio(integer *, char *, ftnlen), e_wsfi(void)
	    ;

    /* Local variables */
    static real dec;
    static char com[8];
    static integer ideg, imin;

    /* Fortran I/O blocks */
    static icilist io___55 = { 0, com, 0, fmt_100, 8, 1 };


    if (*angle < 0.f) {
	*angle += 360.f;
    }
    if (*angle > 360.f) {
	*angle += -360.f;
    }
    if (*angle < 0.f || *angle > 360.f) {
	s_copy(ret_val, "    -   ", (ftnlen)8, (ftnlen)8);
	return ;
    }
    ideg = (integer) (*angle);
    dec = *angle - (real) ideg;
    imin = (integer) (dec * 60.f);
/*     write(com,100) ideg,char(176),imin,"'" */
    s_wsfi(&io___55);
    do_fio(&c__1, (char *)&ideg, (ftnlen)sizeof(integer));
    do_fio(&c__1, "d", (ftnlen)1);
    do_fio(&c__1, (char *)&imin, (ftnlen)sizeof(integer));
    do_fio(&c__1, "'", (ftnlen)1);
    e_wsfi();
    s_copy(ret_val, com, (ftnlen)8, (ftnlen)8);
    return ;
} /* conv_ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int arondi_(char *tris, ftnlen tris_len)
{
    extern /* Subroutine */ int cchatim___(char *, integer *, integer *, 
	    integer *, ftnlen), ctimcha___(integer *, integer *, integer *, 
	    char *, ftnlen);
    static integer i__, ih, im, is;


/* *** arondi tris a la minute la plus proche */


    for (i__ = 1; i__ <= 8; ++i__) {
	if (*(unsigned char *)&tris[i__ - 1] != '0' && *(unsigned char *)&
		tris[i__ - 1] != '1' && *(unsigned char *)&tris[i__ - 1] != 
		'2' && *(unsigned char *)&tris[i__ - 1] != '3' && *(unsigned 
		char *)&tris[i__ - 1] != '4' && *(unsigned char *)&tris[i__ - 
		1] != '5' && *(unsigned char *)&tris[i__ - 1] != '6' && *(
		unsigned char *)&tris[i__ - 1] != '7' && *(unsigned char *)&
		tris[i__ - 1] != '8' && *(unsigned char *)&tris[i__ - 1] != 
		'9' && *(unsigned char *)&tris[i__ - 1] != ':') {
	    return 0;
	}
    }

    cchatim___(tris, &ih, &im, &is, (ftnlen)8);

    if (is >= 30) {
	++im;
	if (im > 59) {
	    ++ih;
	    im += -60;
	}
    }
    is = 0;

    ctimcha___(&ih, &im, &is, tris, (ftnlen)8);
    return 0;
} /* arondi_ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int cchatim___(char *ctime, integer *ih, integer *im, 
	integer *is, ftnlen ctime_len)
{
    /* Format strings */
    static char fmt_100[] = "(i2,1x,i2,1x,i2)";

    /* System generated locals */
    icilist ici__1;

    /* Builtin functions */
    integer s_rsfi(icilist *), do_fio(integer *, char *, ftnlen), e_rsfi(void)
	    ;


/*     ---------------------------------------------------------------+-- */
/* *   Object : convert_time_character_to_time '13:03:05' to 13 03 05 */
/* *   Class  : convert modules of Rogralib Software */
/* *   Author : P. Robert, PatCie, 1992 */
/*     ---------------------------------------------------------------+-- */


    ici__1.icierr = 0;
    ici__1.iciend = 0;
    ici__1.icirnum = 1;
    ici__1.icirlen = ctime_len;
    ici__1.iciunit = ctime;
    ici__1.icifmt = fmt_100;
    s_rsfi(&ici__1);
    do_fio(&c__1, (char *)&(*ih), (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&(*im), (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&(*is), (ftnlen)sizeof(integer));
    e_rsfi();


    return 0;
} /* cchatim___ */


/*     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX */

/* Subroutine */ int ctimcha___(integer *ih, integer *im, integer *is, char *
	ctime, ftnlen ctime_len)
{
    /* Format strings */
    static char fmt_100[] = "(i2.2,\002:\002,i2.2,\002:\002,i2.2)";

    /* System generated locals */
    icilist ici__1;

    /* Builtin functions */
    integer s_wsfi(icilist *), do_fio(integer *, char *, ftnlen), e_wsfi(void)
	    ;


/*     ---------------------------------------------------------------+-- */
/* *   Object : convert_time_number_to_char  '13:03:05' */
/* *   Class  : convert modules of Rogralib Software */
/* *   Author : P. Robert, PatCie, 1992 */
/*     ---------------------------------------------------------------+-- */


    ici__1.icierr = 0;
    ici__1.icirnum = 1;
    ici__1.icirlen = ctime_len;
    ici__1.iciunit = ctime;
    ici__1.icifmt = fmt_100;
    s_wsfi(&ici__1);
    do_fio(&c__1, (char *)&(*ih), (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&(*im), (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&(*is), (ftnlen)sizeof(integer));
    e_wsfi();

    if (*(unsigned char *)ctime == ' ') {
	*(unsigned char *)ctime = '0';
    }
    if (*(unsigned char *)&ctime[3] == ' ') {
	*(unsigned char *)&ctime[3] = '0';
    }
    if (*(unsigned char *)&ctime[6] == ' ') {
	*(unsigned char *)&ctime[6] = '0';
    }


    return 0;
} /* ctimcha___ */


/*     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___61 = { 0, 6, 0, 0, 0 };
    static cilist io___62 = { 0, 6, 0, 0, 0 };
    static cilist io___63 = { 0, 6, 0, 0, 0 };
    static cilist io___64 = { 0, 6, 0, 0, 0 };
    static cilist io___68 = { 0, 6, 0, 0, 0 };
    static cilist io___69 = { 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___61);
	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___62);
	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___63);
	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___64);
	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___68);
    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___69);
    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_year__ () { MAIN__ (); return 0; }
