/* test_dir_sun.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__9 = 9;

/* Main program */ int MAIN__(void)
{
    /* Format strings */
    static char fmt_200[] = "(a,4f10.3,2f10.3)";
    static char fmt_300[] = "(a,3i5)";
    static char fmt_100[] = "(a,4a10,2a10)";

    /* Builtin functions */
    integer s_wsle(cilist *), e_wsle(void), s_wsfe(cilist *), do_fio(integer *
	    , char *, ftnlen), e_wsfe(void), s_rsle(cilist *), do_lio(integer 
	    *, integer *, char *, ftnlen), e_rsle(void);
    /* Subroutine */ int s_stop(char *, ftnlen);

    /* Local variables */
    static real r__;
    extern /* Subroutine */ int g_gei_geo_sun_dir__(real *, real *, real *, 
	    real *, real *, real *);
    static integer ih, im, is, iday;
    static real rgei, xgei, teta, ygei, zgei, rgeo, rdis, xgeo, ygeo, zgeo, 
	    rgse, xgse, ygse, zgse, xvdh, yvdh, zvdh, rgsm, rvdh, xgsm, ygsm, 
	    zgsm;
    extern /* Subroutine */ int t_geo_to_gei__(real *, real *, real *, real *,
	     real *, real *), t_gei_to_gse__(real *, real *, real *, real *, 
	    real *, real *), t_geo_to_gse__(real *, real *, real *, real *, 
	    real *, real *), t_gei_to_gsm__(real *, real *, real *, real *, 
	    real *, real *), t_geo_to_vdh__(real *, real *, real *, real *, 
	    real *, real *, real *, real *), t_sph_to_car__(real *, real *, 
	    real *, real *, real *, real *), t_geo_to_gsm__(real *, real *, 
	    real *, real *, real *, real *), t_car_to_sph__(real *, real *, 
	    real *, real *, real *, real *);
    static real rlagr;
    static integer iyear;
    static real sxgei, sygei, szgei, rlogr, sxgeo, sygeo, szgeo, sxgse, sygse,
	     szgse, sxvdh, syvdh;
    extern /* Subroutine */ int cp_time_param__(integer *, integer *, integer 
	    *, integer *, integer *, integer *);
    static real szvdh, sxgsm, sygsm, szgsm;
    extern /* Subroutine */ int r_date__(integer *, integer *, integer *);
    static real rlagei, phigei, rlageo, phigeo, rlagse;
    extern /* Subroutine */ int r_time__(integer *, integer *, integer *);
    static real phigse, tetgei, phivdh, rlogei, rlavdh, rlagsm, rlogeo, 
	    tetgeo, phigsm, tetgse, rlogse;
    static integer imonth;
    static real tetvdh, rlovdh, tetgsm, rlogsm;
    extern /* Subroutine */ int convdeg_(real *, real *), colalon_(real *, 
	    real *, real *, real *);

    /* Fortran I/O blocks */
    static cilist io___1 = { 0, 6, 0, 0, 0 };
    static cilist io___2 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___3 = { 0, 6, 0, 0, 0 };
    static cilist io___4 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___5 = { 0, 6, 0, 0, 0 };
    static cilist io___12 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___13 = { 0, 5, 0, 0, 0 };
    static cilist io___17 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___55 = { 0, 6, 0, 0, 0 };
    static cilist io___56 = { 0, 6, 0, 0, 0 };
    static cilist io___57 = { 0, 6, 0, fmt_300, 0 };
    static cilist io___58 = { 0, 6, 0, fmt_300, 0 };
    static cilist io___59 = { 0, 6, 0, 0, 0 };
    static cilist io___60 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___61 = { 0, 6, 0, fmt_100, 0 };
    static cilist io___62 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___63 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___64 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___65 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___66 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___87 = { 0, 6, 0, 0, 0 };
    static cilist io___88 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___89 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___90 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___91 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___92 = { 0, 6, 0, fmt_200, 0 };
    static cilist io___93 = { 0, 6, 0, 0, 0 };
    static cilist io___94 = { 0, 6, 0, 0, 0 };
    static cilist io___95 = { 0, 6, 0, 0, 0 };
    static cilist io___96 = { 0, 6, 0, 0, 0 };



/*     ***************************************************************0** */
/* *   Test_Dir_Sun: Sun direction in various coordinate systems */
/*     P. Robert, CETP, June 2001 ; use Rocotlib library */
/*     ***************************************************************0** */


    s_wsle(&io___1);
    e_wsle();
    s_wsfe(&io___2);
    do_fio(&c__1, "*****************************************************", (
	    ftnlen)53);
    e_wsfe();
    s_wsle(&io___3);
    e_wsle();
    s_wsfe(&io___4);
    do_fio(&c__1, "Sun direction in various coordinate systems", (ftnlen)43);
    e_wsfe();
    s_wsle(&io___5);
    e_wsle();

/* *   reading date and time & compute general matrix */

    r_date__(&iyear, &imonth, &iday);
    r_time__(&ih, &im, &is);
    cp_time_param__(&iyear, &imonth, &iday, &ih, &im, &is);

/* *   reading position of point of observation in GEO */

    s_wsfe(&io___12);
    do_fio(&c__1, "latitude, longitude, distance in GEO ? (deg & any u.)", (
	    ftnlen)53);
    e_wsfe();
    s_rsle(&io___13);
    do_lio(&c__4, &c__1, (char *)&rlageo, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&rlogeo, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&rdis, (ftnlen)sizeof(real));
    e_rsle();
    s_wsfe(&io___17);
    do_fio(&c__1, " ", (ftnlen)1);
    do_fio(&c__1, (char *)&rlageo, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlogeo, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rdis, (ftnlen)sizeof(real));
    e_wsfe();

    rlagr = rlageo * 3.1415927f / 180.f;
    rlogr = rlogeo * 3.1415927f / 180.f;
    teta = (90.f - rlageo) * 3.1415927f / 180.f;

/* *   geographic cartesian coordinates */

    t_sph_to_car__(&rdis, &teta, &rlogr, &xgeo, &ygeo, &zgeo);

/* *   same in other systems */

    t_geo_to_gei__(&xgeo, &ygeo, &zgeo, &xgei, &ygei, &zgei);
    t_geo_to_gse__(&xgeo, &ygeo, &zgeo, &xgse, &ygse, &zgse);
    t_geo_to_gsm__(&xgeo, &ygeo, &zgeo, &xgsm, &ygsm, &zgsm);
    t_geo_to_vdh__(&xgeo, &ygeo, &zgeo, &rlagr, &rlogr, &xvdh, &yvdh, &zvdh);

/* *   latitude, longitude in other systems */

    t_car_to_sph__(&xgeo, &ygeo, &zgeo, &r__, &tetgeo, &phigeo);
    t_car_to_sph__(&xgei, &ygei, &zgei, &r__, &tetgei, &phigei);
    t_car_to_sph__(&xgse, &ygse, &zgse, &r__, &tetgse, &phigse);
    t_car_to_sph__(&xgsm, &ygsm, &zgsm, &r__, &tetgsm, &phigsm);
    t_car_to_sph__(&xvdh, &yvdh, &zvdh, &r__, &tetvdh, &phivdh);

    colalon_(&tetgeo, &phigeo, &rlageo, &rlogeo);
    colalon_(&tetgei, &phigei, &rlagei, &rlogei);
    colalon_(&tetgse, &phigse, &rlagse, &rlogse);
    colalon_(&tetgsm, &phigsm, &rlagsm, &rlogsm);
    colalon_(&tetvdh, &phivdh, &rlavdh, &rlovdh);

    s_wsle(&io___55);
    do_lio(&c__9, &c__1, "__________________________________________________"
	    "_______", (ftnlen)57);
    e_wsle();
    s_wsle(&io___56);
    e_wsle();
    s_wsfe(&io___57);
    do_fio(&c__1, "date: YY/MM/JJ=", (ftnlen)15);
    do_fio(&c__1, (char *)&iyear, (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&imonth, (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&iday, (ftnlen)sizeof(integer));
    e_wsfe();
    s_wsfe(&io___58);
    do_fio(&c__1, "time: HH/MM/SS=", (ftnlen)15);
    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_wsfe();
    s_wsle(&io___59);
    e_wsle();

    s_wsfe(&io___60);
    do_fio(&c__1, "            ", (ftnlen)12);
    do_fio(&c__1, "x", (ftnlen)1);
    do_fio(&c__1, "y", (ftnlen)1);
    do_fio(&c__1, "z", (ftnlen)1);
    do_fio(&c__1, "R", (ftnlen)1);
    do_fio(&c__1, "Lat", (ftnlen)3);
    do_fio(&c__1, "Long", (ftnlen)4);
    e_wsfe();
    s_wsfe(&io___61);
    e_wsfe();

    s_wsfe(&io___62);
    do_fio(&c__1, "Pos. in GEO :", (ftnlen)13);
    do_fio(&c__1, (char *)&xgeo, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&ygeo, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&zgeo, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&r__, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlageo, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlogeo, (ftnlen)sizeof(real));
    e_wsfe();
    s_wsfe(&io___63);
    do_fio(&c__1, "Pos. in GEI :", (ftnlen)13);
    do_fio(&c__1, (char *)&xgei, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&ygei, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&zgei, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&r__, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlagei, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlogei, (ftnlen)sizeof(real));
    e_wsfe();
    s_wsfe(&io___64);
    do_fio(&c__1, "Pos. in GSE :", (ftnlen)13);
    do_fio(&c__1, (char *)&xgse, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&ygse, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&zgse, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&r__, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlagse, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlogse, (ftnlen)sizeof(real));
    e_wsfe();
    s_wsfe(&io___65);
    do_fio(&c__1, "Pos. in GSM :", (ftnlen)13);
    do_fio(&c__1, (char *)&xgsm, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&ygsm, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&zgsm, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&r__, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlagsm, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlogsm, (ftnlen)sizeof(real));
    e_wsfe();
    s_wsfe(&io___66);
    do_fio(&c__1, "Pos. in VDH :", (ftnlen)13);
    do_fio(&c__1, (char *)&xvdh, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&yvdh, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&zvdh, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&r__, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlavdh, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rlovdh, (ftnlen)sizeof(real));
    e_wsfe();

/* *   Sun direction */

    g_gei_geo_sun_dir__(&sxgei, &sygei, &szgei, &sxgeo, &sygeo, &szgeo);
    t_gei_to_gse__(&sxgei, &sygei, &szgei, &sxgse, &sygse, &szgse);
    t_gei_to_gsm__(&sxgei, &sygei, &szgei, &sxgsm, &sygsm, &szgsm);
    t_geo_to_vdh__(&sxgeo, &sygeo, &szgeo, &rlagr, &rlogr, &sxvdh, &syvdh, &
	    szvdh);

    t_car_to_sph__(&sxgeo, &sygeo, &szgeo, &rgeo, &tetgeo, &phigeo);
    t_car_to_sph__(&sxgei, &sygei, &szgei, &rgei, &tetgei, &phigei);
    t_car_to_sph__(&sxgse, &sygse, &szgse, &rgse, &tetgse, &phigse);
    t_car_to_sph__(&sxgsm, &sygsm, &szgsm, &rgsm, &tetgsm, &phigsm);
    t_car_to_sph__(&sxvdh, &syvdh, &szvdh, &rvdh, &tetvdh, &phivdh);

    convdeg_(&tetgeo, &phigeo);
    convdeg_(&tetgei, &phigei);
    convdeg_(&tetgse, &phigse);
    convdeg_(&tetgsm, &phigsm);
    convdeg_(&tetvdh, &phivdh);

    s_wsle(&io___87);
    e_wsle();
    s_wsfe(&io___88);
    do_fio(&c__1, "Sun  in GEO :", (ftnlen)13);
    do_fio(&c__1, (char *)&sxgeo, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&sygeo, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&szgeo, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rgeo, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&tetgeo, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&phigeo, (ftnlen)sizeof(real));
    e_wsfe();
    s_wsfe(&io___89);
    do_fio(&c__1, "Sun  in GEI :", (ftnlen)13);
    do_fio(&c__1, (char *)&sxgei, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&sygei, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&szgei, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rgei, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&tetgei, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&phigei, (ftnlen)sizeof(real));
    e_wsfe();
    s_wsfe(&io___90);
    do_fio(&c__1, "Sun  in GSE :", (ftnlen)13);
    do_fio(&c__1, (char *)&sxgse, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&sygse, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&szgse, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rgse, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&tetgse, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&phigse, (ftnlen)sizeof(real));
    e_wsfe();
    s_wsfe(&io___91);
    do_fio(&c__1, "Sun  in GSM :", (ftnlen)13);
    do_fio(&c__1, (char *)&sxgsm, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&sygsm, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&szgsm, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rgsm, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&tetgsm, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&phigsm, (ftnlen)sizeof(real));
    e_wsfe();
    s_wsfe(&io___92);
    do_fio(&c__1, "Sun  in VDH :", (ftnlen)13);
    do_fio(&c__1, (char *)&sxvdh, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&syvdh, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&szvdh, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&rvdh, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&tetvdh, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&phivdh, (ftnlen)sizeof(real));
    e_wsfe();
    s_wsle(&io___93);
    e_wsle();
    s_wsle(&io___94);
    e_wsle();
    s_wsle(&io___95);
    do_lio(&c__9, &c__1, "**************************************************"
	    "******", (ftnlen)56);
    e_wsle();
    s_wsle(&io___96);
    e_wsle();

    s_stop("test_dir_sun.exe: normal termination", (ftnlen)36);
    return 0;
} /* MAIN__ */


/*     ---------------------------------------------------------------0-- */

/* Subroutine */ int convdeg_(real *x, real *y)
{
    static real pisd;


    pisd = .017453292777777778f;

    *x /= pisd;
    *y /= pisd;

    return 0;
} /* convdeg_ */


/*     ---------------------------------------------------------------0-- */

/* Subroutine */ int colalon_(real *teta, real *phi, real *rlat, real *rlon)
{
    static real pisd;


/* *   compute lat and long in degres from teta, phi in radians */

    pisd = .017453292777777778f;

    *rlat = 90.f - *teta / pisd;
    *rlon = *phi / pisd;

    return 0;
} /* colalon_ */

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