Beispiel #1
0
    /// true if equal
    bool messages_diff ( gpb::Message const &templ,
                         gpb::Message &src,
                         gpb::FieldDescriptor const *fld )
    {
        gpb::Reflection const *treflect( templ.GetReflection( ) );
        gpb::Reflection const *sreflect(   src.GetReflection( ) );

        if( message_has_repeated( fld ) ) {
            gpb::Message const &tmpl_next( treflect->GetMessage( templ, fld ) );
            gpb::Message     *src_next( sreflect->MutableMessage( &src, fld ) );

            std::string tmpls(tmpl_next.SerializeAsString());
            std::string srss(src_next->SerializeAsString());

            return tmpls == srss;
        }

        if( !fld->is_repeated(  ) ) {

            gpb::Message const &tmpl_next( treflect->GetMessage( templ, fld ) );
            gpb::Message     *src_next( sreflect->MutableMessage( &src, fld ) );

            bool equal = false;
            if( make_message_diff( tmpl_next, *src_next, *src_next ) ) {
                sreflect->ClearField( &src, fld );
                equal = true;
            }
            return equal;
        }

        int tsize( templ.GetReflection( )->FieldSize( templ, fld ) );
        int ssize( src.GetReflection( )->FieldSize( src, fld ) );

        if( tsize != ssize ) return false;

        for( int i(0); i<tsize; ++i ) {
            std::string tmess( treflect->GetRepeatedMessage( templ, fld, i )
                               .SerializeAsString( ) );
            std::string smess( sreflect->GetRepeatedMessage( src, fld, i )
                               .SerializeAsString( ) );
            if( tmess.compare(smess) != 0 ) return false;
        }
        sreflect->ClearField( &src, fld );
        return true;
    }
Beispiel #2
0
/*============================================================================
*    Long integer function S_solpos, adapted from the VAX solar libraries
*
*    This function calculates the apparent solar position and the
*    intensity of the sun (theoretical maximum solar energy) from
*    time and place on Earth.
*
*    Requires (from the struct posdata parameter):
*        Date and time:
*            year
*            daynum   (requirement depends on the S_DOY switch)
*            month    (requirement depends on the S_DOY switch)
*            day      (requirement depends on the S_DOY switch)
*            hour
*            minute
*            second
*            interval  DEFAULT 0
*        Location:
*            latitude
*            longitude
*        Location/time adjuster:
*            timezone
*        Atmospheric pressure and temperature:
*            press     DEFAULT 1013.0 mb
*            temp      DEFAULT 10.0 degrees C
*        Tilt of flat surface that receives solar energy:
*            aspect    DEFAULT 180 (South)
*            tilt      DEFAULT 0 (Horizontal)
*        Function Switch (codes defined in solpos.h)
*            function  DEFAULT S_ALL
*
*    Returns (via the struct posdata parameter):
*        everything defined in the struct posdata in solpos.h.
*----------------------------------------------------------------------------*/
long S_solpos(struct posdata *pdat)
{
    long int retval;

    struct trigdata trigdat, *tdat;

    tdat = &trigdat;		/* point to the structure */

    /* initialize the trig structure */
    tdat->sd = -999.0;		/* flag to force calculation of trig data */
    tdat->cd = 1.0;
    tdat->ch = 1.0;		/* set the rest of these to something safe */
    tdat->cl = 1.0;
    tdat->sl = 1.0;

    if ((retval = validate(pdat)) != 0)	/* validate the inputs */
	return retval;


    if (pdat->function & L_DOY)
	doy2dom(pdat);		/* convert input doy to month-day */
    else
	dom2doy(pdat);		/* convert input month-day to doy */

    if (pdat->function & L_GEOM)
	geometry(pdat);		/* do basic geometry calculations */

    if (pdat->function & L_ZENETR)	/* etr at non-refracted zenith angle */
	zen_no_ref(pdat, tdat);

    if (pdat->function & L_SSHA)	/* Sunset hour calculation */
	ssha(pdat, tdat);

    if (pdat->function & L_SBCF)	/* Shadowband correction factor */
	sbcf(pdat, tdat);

    if (pdat->function & L_TST)	/* true solar time */
	tst(pdat);

    if (pdat->function & L_SRSS)	/* sunrise/sunset calculations */
	srss(pdat);

    if (pdat->function & L_SOLAZM)	/* solar azimuth calculations */
	sazm(pdat, tdat);

    if (pdat->function & L_REFRAC)	/* atmospheric refraction calculations */
	refrac(pdat);

    if (pdat->function & L_AMASS)	/* airmass calculations */
	amass(pdat);

    if (pdat->function & L_PRIME)	/* kt-prime/unprime calculations */
	prime(pdat);

    if (pdat->function & L_ETR)	/* ETR and ETRN (refracted) */
	etr(pdat);

    if (pdat->function & L_TILT)	/* tilt calculations */
	tilt(pdat);

    return 0;
}