Example #1
0
void hoa_map_float(t_hoa_map *x, double f)
{
    if(x->f_map->getNumberOfSources() == 1)
    {
		if(x->f_mode == hoa_sym_polar)
		{
			if(proxy_getinlet((t_object *)x) == 1)
			{
				x->f_lines->setRadius(0, clip_min(f, 0.));
			}
			else if(proxy_getinlet((t_object *)x) == 2)
			{
				x->f_lines->setAzimuth(0, f);
			}
		}
		else if(x->f_mode == hoa_sym_cartesian)
		{
			if(proxy_getinlet((t_object *)x) == 1)
			{
                float ord = ordinate(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0));
				x->f_lines->setRadius(0, radius(f, ord));
                x->f_lines->setAzimuth(0, azimuth(f, ord));
			}
			else if(proxy_getinlet((t_object *)x) == 2)
			{
				float abs = abscissa(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0));
                x->f_lines->setRadius(0, radius(abs, f));
				x->f_lines->setAzimuth(0, azimuth(abs, f));
			}
		}
    }
}
void draw_vectors(t_hoa_meter *x, t_object *view, t_rect *rect)
{
	double x1, y1, size;
	t_matrix transform;
	t_elayer *g = ebox_start_layer((t_ebox *)x,  hoa_sym_vector_layer, rect->width, rect->height);
	
	if (g)
	{
		egraphics_matrix_init(&transform, 1, 0, 0, -1, rect->width / 2., rect->width / 2.);
		egraphics_set_matrix(g, &transform);
		size = 1. / 64. * rect->width;
    
        if(x->f_vector_type == hoa_sym_both || x->f_vector_type == hoa_sym_energy)
        {
            egraphics_set_color_rgba(g, &x->f_color_energy_vector);
            if(x->f_clockwise == hoa_sym_anticlock)
            {
                x1 = x->f_vector_coords[2] * x->f_radius_center * 0.85;
                y1 = x->f_vector_coords[3] * x->f_radius_center * 0.85;
            }
            else
            {
                double rad = radius(x->f_vector_coords[2], x->f_vector_coords[3]) * x->f_radius_center * 0.85;
                double ang = -azimuth(x->f_vector_coords[2], x->f_vector_coords[3]);
                x1 = abscissa(rad, ang);
                y1 = ordinate(rad, ang);
            }
            egraphics_arc(g, x1, y1, size, 0., HOA_2PI);
            egraphics_fill(g);
		}
        if(x->f_vector_type == hoa_sym_both || x->f_vector_type == hoa_sym_velocity)
        {
            egraphics_set_color_rgba(g, &x->f_color_velocity_vector);
            if(x->f_clockwise == hoa_sym_anticlock)
            {
                x1 = x->f_vector_coords[0] * x->f_radius_center * 0.85;
                y1 = x->f_vector_coords[1] * x->f_radius_center * 0.85;
            }
            else
            {
                double rad = radius(x->f_vector_coords[0], x->f_vector_coords[1]) * x->f_radius_center * 0.85;
                double ang = -azimuth(x->f_vector_coords[0], x->f_vector_coords[1]);
                x1 = abscissa(rad, ang);
                y1 = ordinate(rad, ang);
            }
            egraphics_arc(g, x1, y1, size, 0., HOA_2PI);
            egraphics_fill(g);
		}
        
		ebox_end_layer((t_ebox*)x,  hoa_sym_vector_layer);
	}
	ebox_paint_layer((t_ebox *)x, hoa_sym_vector_layer, 0., 0.);
}
void
az_el(char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    extern int str_dbl();  /* function to convert string to double */
    int i = 0;      /* current position on the *buffer */
    int rc = 0;     /* the return code value from str_dbl()   */
    double az;
    double el;

    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) == '\0') {
	/* display current az and el values */
	bu_log("(az, el) = (%4.2f, %4.2f)\n",
	       azimuth(), elevation());
	return;
    }
    if ((rc = str_dbl(buffer+i, &az)) == 0) {
	/* get az value */
	com_usage(ctp);
	return;
    }
    if (fabs(az) > 360) {
	/* check for valid az value */

	bu_log("Error:  |azimuth| <= 360\n");
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if ((rc = str_dbl(buffer+i, &el)) == 0) {
	/* get el value */
	com_usage(ctp);
	return;
    }
    if (fabs(el) > 90) {
	/* check for valid el value */
	bu_log("Error:  |elevation| <= 90\n");
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) != '\0') {
	/* check for garbage at the end of the line */
	com_usage(ctp);
	return;
    }
    azimuth() = az;
    elevation() = el;
    ae2dir();
}
Example #4
0
void hoa_map_3D_tilde_float(t_hoa_map_3D_tilde *x, float f)
{
    if(x->f_map->getNumberOfSources() == 1)
    {
		if(x->f_mode == 0)
		{
			if(eobj_getproxy((t_object *)x) == 1)
			{
				x->f_lines->setRadius(0, clip_min(f, 0.));
			}
			else if(eobj_getproxy((t_object *)x) == 2)
			{
				x->f_lines->setAzimuth(0, f);
			}
            else if(eobj_getproxy((t_object *)x) == 3)
			{
				x->f_lines->setElevation(0, f);
			}
		}
		else if(x->f_mode == 1)
		{
			if(eobj_getproxy((t_object *)x) == 1)
			{
                float abs = f;
                float ord = ordinate(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0));
                float hei = height(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0));
				x->f_lines->setRadius(0, radius(abs, ord, hei));
                x->f_lines->setAzimuth(0, azimuth(abs, ord, hei));
                x->f_lines->setElevation(0, elevation(abs, ord, hei));
			}
			else if(eobj_getproxy((t_object *)x) == 2)
			{
				float abs = abscissa(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0));
                float ord = f;
                float hei = height(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0));
				x->f_lines->setRadius(0, radius(abs, ord, hei));
                x->f_lines->setAzimuth(0, azimuth(abs, ord, hei));
                x->f_lines->setElevation(0, elevation(abs, ord, hei));
			}
            else if(eobj_getproxy((t_object *)x) == 3)
			{
				float abs = abscissa(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0));
                float ord = ordinate(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0));
                float hei = f;
                x->f_lines->setRadius(0, radius(abs, ord, hei));
                x->f_lines->setAzimuth(0, azimuth(abs, ord, hei));
                x->f_lines->setElevation(0, elevation(abs, ord, hei));
			}
		}
    }
}
Example #5
0
void hoa_map_3D_tilde_list(t_hoa_map_3D_tilde *x, t_symbol* s, long argc, t_atom* argv)
{
    if(argc > 2 && argv && atom_gettype(argv) == A_LONG && atom_gettype(argv+1) == A_SYM)
    {
        int index = atom_getlong(argv);
        if(index < 1 || index > x->f_map->getNumberOfSources())
            return;
        
        if(argc > 4 && (atom_getsym(argv+1) == hoa_sym_polar || atom_getsym(argv+1) == hoa_sym_pol))
        {
            x->f_lines->setRadius(index-1, atom_getfloat(argv+2));
            x->f_lines->setAzimuth(index-1, atom_getfloat(argv+3));
            x->f_lines->setElevation(index-1, atom_getfloat(argv+4));
        }
        else if(argc > 4 && (atom_getsym(argv+1) == hoa_sym_cartesian || atom_getsym(argv+1) == hoa_sym_car))
        {
            x->f_lines->setRadius(index-1, radius(atom_getfloat(argv+2), atom_getfloat(argv+3), atom_getfloat(argv+4)));
            x->f_lines->setAzimuth(index-1, azimuth(atom_getfloat(argv+2), atom_getfloat(argv+3), atom_getfloat(argv+4)));
            x->f_lines->setElevation(index-1, elevation(atom_getfloat(argv+2), atom_getfloat(argv+3), atom_getfloat(argv+4)));
        }
        else if(argc > 2 && atom_getsym(argv+1) == hoa_sym_mute)
        {
            x->f_map->setMute(index-1, atom_getlong(argv+2));
        }
    }
}
void AzimuthZenithController::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if((not m_isDragging) &&
       (event->buttons().testFlag(Qt::LeftButton)) &&
       (m_dragStart - event->scenePos()).manhattanLength() > 3) {
        qDebug() << (m_dragStart - event->scenePos()).manhattanLength();
        m_isDragging = true;
    }

    if(not m_isDragging)
        return;

    m_azimuthAnimation.stop();
    m_zenithAnimation.stop();

    // for now, we're just gonna calculate current and
    // last to emulate the events we used to get.
    QPointF current = event->scenePos();
    QPointF last = event->lastScenePos();

    setAzimuth(azimuth() + (float)(current.x() - last.x())/2.0);
    setZenith(zenith() - (float)(current.y() - last.y())/2.0);

    m_targetAzimuth = m_azimuth;
    m_targetZenith = m_zenith;

    event->accept();
}
Example #7
0
void hoa_map_perform64_in1_in2(t_hoa_map *x, t_object *dsp64, double **ins, long numins, double **outs, long numouts, long sampleframes, long flags, void *userparam)
{
	if (x->f_map->getMute(0))
	{
		for(int i = 0; i < numouts; i++)
			memset(outs[i], 0, sizeof(double)*sampleframes);
		return;
	}
    for(int i = 0; i < sampleframes; i++)
    {
		if(x->f_mode == hoa_sym_polar)
		{
			x->f_map->setRadius(0, ins[1][i]);
			x->f_map->setAzimuth(0, ins[2][i]);
		}
		else if(x->f_mode == hoa_sym_cartesian)
		{
			x->f_map->setAzimuth(0, azimuth(ins[1][i], ins[2][i]));
			x->f_map->setRadius(0, radius(ins[1][i], ins[2][i]));
		}
        x->f_map->process(&ins[0][i], x->f_sig_outs + numouts * i);
    }
    for(int i = 0; i < numouts; i++)
    {
        cblas_dcopy(sampleframes, x->f_sig_outs+i, numouts, outs[i], 1);
    }
}
TextStream& DistantLightSource::externalRepresentation(TextStream& ts) const
{
    ts << "[type=DISTANT-LIGHT] ";
    ts << "[azimuth=\"" << azimuth() << "\"]";
    ts << "[elevation=\"" << elevation() << "\"]";
    return ts;
}
Example #9
0
    void DiK2World::Load(const DiString& path)
    {
        DI_LOG("Loading world: %s", path.c_str());

        DiK2WorldSerial serial;
        serial.Load(path,this);
        mRootNode->AttachObject(mTerrain);
        
        // sun light
        mSun = make_shared<DiDirLight>();
        DiSceneManager* sm = DiBase::Driver->GetSceneManager();
        DiCullNode* dirNode = sm->GetRootNode()->CreateChild();
        dirNode->AttachObject(mSun);
        mSun->SetColor(DiColor());
        
        DiRadian altitude(DiDegree(mConfigs.mSunAltitude));
        DiVec3 dir(0,-DiMath::Sin(altitude),DiMath::Cos(altitude));
        
        DiRadian azimuth(DiDegree(mConfigs.mSunAzimuth));
        DiQuat rot(azimuth, DiVec3::UNIT_Y);
        dir = rot * dir;
        mSun->SetDirection(dir);
        
        sm->SetAmbientColor(DiColor());
    
        Demi::DiRenderBatchGroup* group = Driver->GetPipeline()->GetBatchGroup(Demi::BATCH_MODEL);
        group->SetPreProcess([this](){
            Driver->GetPipeline()->GetShaderEnvironment()->globalAmbient = mConfigs.mEntityAmbient;
            Driver->GetPipeline()->GetShaderEnvironment()->dirLightsColor[0] = mConfigs.mEntitySunColor;
        });
    }
Example #10
0
static int
Xhoming(struct place *place, double *x, double *y)
{
	if(!azimuth(place))
		return 0;
	*x = -rad.l*az.s;
	*y = -rad.l*az.c;
	return place->wlon.c<0? 0: 1;
}
Example #11
0
void
dir2ae(void)
{
    double square;
    int zeroes = ZERO(direct(Y)) && ZERO(direct(X));

    azimuth() = zeroes ? 0.0 : atan2 (-(direct(Y)), -(direct(X))) / DEG2RAD;

    square = sqrt(direct(X) * direct(X) + direct(Y) * direct(Y));
    elevation() = atan2 (-(direct(Z)), square) / DEG2RAD;
}
Example #12
0
void
dir2ae(void)
{
    double square;

    azimuth() = ((direct(Y) == 0) && (direct(X) == 0)) ? 0.0 :
	atan2 ( -(direct(Y)), -(direct(X)) ) / DEG2RAD;

    square = sqrt(direct(X) * direct(X) + direct(Y) * direct(Y));
    elevation() = atan2 (-(direct(Z)), square) / DEG2RAD;
}
Example #13
0
static int
Xmecca(struct place *place, double *x, double *y)
{
	if(!azimuth(place))
		return 0;
	*x = -place->wlon.l;
	*y = fabs(az.s)<.02? -az.c*rad.s/p0.c: *x*az.c/az.s;
	return fabs(*y)>2? -1:
	       rad.c<0? 0:
	       1;
}
Example #14
0
/*!
  Draw lines

  \param painter Painter
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param from index of the first point to be painted
  \param to index of the last point to be painted.
  \sa draw(), drawLines(), setCurveFitter()
*/
void QwtPolarCurve::drawLines( QPainter *painter,
                               const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
                               const QwtDoublePoint &pole, int from, int to ) const
{
  int size = to - from + 1;
  if ( size <= 0 )
    return;

  QwtPolygon polyline;
  if ( d_data->curveFitter )
  {
#if QT_VERSION < 0x040000
    QwtArray<QwtDoublePoint> points( size );
#else
    QwtPolygonF points( size );
#endif
    for ( int j = from; j <= to; j++ )
      points[j - from] = QwtDoublePoint( azimuth( j ), radius( j ) );

    points = d_data->curveFitter->fitCurve( points );

    polyline.resize( points.size() );
    for ( int i = 0; i < ( int )points.size(); i++ )
    {
      const QwtPolarPoint point( points[i].x(), points[i].y() );

      double r = radialMap.xTransform( point.radius() );
      const double a = azimuthMap.xTransform( point.azimuth() );
      polyline.setPoint( i, qwtPolar2Pos( pole, r, a ).toPoint() );
    }
  }
  else
  {
    polyline.resize( size );

    for ( int i = from; i <= to; i++ )
    {
      const QwtPolarPoint point = sample( i );

      double r = radialMap.xTransform( point.radius() );
      const double a = azimuthMap.xTransform( point.azimuth() );
      polyline.setPoint( i - from, qwtPolar2Pos( pole, r, a ).toPoint() );
    }
  }

  QRect clipRect = painter->window();
  clipRect.setRect( clipRect.x() - 1, clipRect.y() - 1,
                    clipRect.width() + 2, clipRect.height() + 2 );

  polyline = QwtClipper::clipPolygon( clipRect, polyline );

  QwtPainter::drawPolyline( painter, polyline );
}
Example #15
0
File: plot.c Project: aahud/harvey
double
rot(struct place center, struct place zenith)
{
	Xyz cen = ptov(center);
	Xyz zen = ptov(zenith);

	if(cen.z > 1-FUZZ) 	/* center at N pole */
		return PI + zenith.wlon.l;
	if(cen.z < FUZZ-1)		/* at S pole */
		return -zenith.wlon.l;
	if(fabs(dot(cen,zen)) > 1-FUZZ)	/* at zenith */
		return 0;
	return azimuth(cen, zen);
}
Example #16
0
void
grid2targ(void)
{
    double	ar = azimuth() * DEG2RAD;
    double	er = elevation() * DEG2RAD;

    target(X) = - grid(HORZ) * sin(ar)
	- grid(VERT) * cos(ar) * sin(er)
	+ grid(DIST) * cos(ar) * cos(er);
    target(Y) =   grid(HORZ) * cos(ar)
	- grid(VERT) * sin(ar) * sin(er)
	+ grid(DIST) * sin(ar) * cos(er);
    target(Z) =   grid(VERT) * cos(er)
	+ grid(DIST) * sin(er);
}
Example #17
0
void
targ2grid(void)
{
    double	ar = azimuth() * DEG2RAD;
    double	er = elevation() * DEG2RAD;

    grid(HORZ) = - target(X) * sin(ar)
	+ target(Y) * cos(ar);
    grid(VERT) = - target(X) * cos(ar) * sin(er)
	- target(Y) * sin(er) * sin(ar)
	+ target(Z) * cos(er);
    grid(DIST) =   target(X) * cos(er) * cos(ar)
	+ target(Y) * cos(er) * sin(ar)
	+ target(Z) * sin(er);
}
Example #18
0
void
ae2dir(void)
{
    double	ar = azimuth() * DEG2RAD;
    double	er = elevation() * DEG2RAD;

    int		i;
    vect_t	dir;

    dir[X] = -cos(ar) * cos(er);
    dir[Y] = -sin(ar) * cos(er);
    dir[Z] = -sin(er);
    VUNITIZE( dir );
    for (i = 0; i < 3; ++i)
	direct(i) = dir[i];
}
Example #19
0
/**
 * Displays the data in a comprehensible way.
 */
void displayInfo() {
    Serial.print(F("Loc: ")); 
    Serial.print(lat_dbl, 6);
    Serial.print(F(","));
    Serial.print(lng_dbl, 6);

    Serial.print(F("   Alt: ")); 
    Serial.print(alt_dbl, 1);
    Serial.print(F(" [m]"));

    Serial.print(F("   Dist: ")); 
    Serial.print(realDistance(lat_dbl, lng_dbl, alt_dbl));
    Serial.print(F(" [m]"));

    Serial.print(F("   Course: ")); 
    Serial.print(crse_dbl);

    Serial.print(F("   Speed: ")); 
    Serial.print(spd_dbl);
    Serial.print(F(" [mps]"));

    Serial.print(F("   Time: "));
    if (hh < 10) {
        Serial.print(F("0"));
    }
    Serial.print(hh);
    Serial.print(F(":"));
    if (mm < 10) {
        Serial.print(F("0"));
    }
    Serial.print(mm);
    Serial.print(F(":"));
    if (ss < 10) {
        Serial.print(F("0"));
    }
    Serial.print(ss);
  
    Serial.print(F("   Sat: ")); 
    Serial.print(sat);

    Serial.print(F("   Az/El: "));
    Serial.print(azimuth(lat_dbl, lng_dbl), 1);
    Serial.print(F("/"));
    Serial.println(elevation(lat_dbl, lng_dbl, alt_dbl), 1);
}
Example #20
0
//
//#############################################################################
//#############################################################################
//
Vector3D&
	Vector3D::operator=(const YawPitchRange &polar)
{
	Check_Object(this);
	Check_Object(&polar);

	Verify(
		Vector3D::Forward.z == 1.0f
		 && Vector3D::Left.x == 1.0f
		 && Vector3D::Up.y == 1.0f
	);
	SinCosPair azimuth(polar.yaw);
	SinCosPair altitude(polar.pitch);
	y = -polar.range * altitude.sine;

	Scalar len = polar.range * altitude.cosine;
	x = len * azimuth.sine;
	z = len * azimuth.cosine;
	return *this;
}
Example #21
0
void hoa_map_3D_tilde_perform_in1_in2_in3(t_hoa_map_3D_tilde *x, t_object *dsp64, float **ins, long numins, float **outs, long numouts, long sampleframes, long flags, void *userparam)
{
    for(int i = 0; i < sampleframes; i++)
    {
        if(x->f_mode == 0)
		{
			x->f_map->setRadius(0, ins[1][i]);
			x->f_map->setAzimuth(0, ins[2][i]);
            x->f_map->setElevation(0, ins[3][i]);
		}
		else if(x->f_mode == 1)
		{
			x->f_map->setAzimuth(0, azimuth(ins[1][i], ins[2][i], ins[3][i]));
			x->f_map->setRadius(0, radius(ins[1][i], ins[2][i], ins[3][i]));
            x->f_map->setElevation(0,elevation(ins[1][i], ins[2][i], ins[3][i]));
		}
        x->f_map->process(&ins[0][i], x->f_sig_outs + numouts * i);
    }
    for(int i = 0; i < numouts; i++)
    {
        cblas_scopy(sampleframes, x->f_sig_outs+i, numouts, outs[i], 1);
    }
}
Example #22
0
laser_return get_laser_return( const packet& packet
                               , unsigned int block
                               , unsigned int laser
                               , const boost::posix_time::ptime& timestamp
                               , double angularSpeed
                               , bool legacy)
{
    laser_return r;
    r.id = laser + ( is_upper( block ) ? 0 : 32 );
    r.intensity = packet.blocks[block].lasers[laser].intensity();
    r.range = double( packet.blocks[block].lasers[laser].range() ) / 500;
    if (legacy)
    {
        r.timestamp = timestamp + time_offset( block, laser );
        r.azimuth = azimuth( packet, block, laser, angularSpeed );
    }
    else
    {
        r.timestamp = timestamp - hdl64_s2_fw_v48::time_delay( block, laser );
        r.azimuth = hdl64_s2_fw_v48::azimuth(packet, block, laser, angularSpeed);
    }
    return r;
}
Example #23
0
void hoa_map_list(t_hoa_map *x, t_symbol* s, long argc, t_atom* argv)
{
    if(argc > 2 && argv && atom_gettype(argv) == A_LONG && atom_gettype(argv+1) == A_SYM)
    {
        int index = atom_getlong(argv) -1;
        if(index < 0 || index >= x->f_map->getNumberOfSources())
            return;
        
        if(argc > 3 && (atom_getsym(argv+1) == hoa_sym_polar || atom_getsym(argv+1) == hoa_sym_pol))
        {
            x->f_lines->setRadius(index, atom_getfloat(argv+2));
            x->f_lines->setAzimuth(index, atom_getfloat(argv+3));
        }
        else if(argc > 3 && (atom_getsym(argv+1) == hoa_sym_cartesian || atom_getsym(argv+1) == hoa_sym_car))
        {
            x->f_lines->setRadius(index, radius(atom_getfloat(argv+2), atom_getfloat(argv+3)));
            x->f_lines->setAzimuth(index, azimuth(atom_getfloat(argv+2), atom_getfloat(argv+3)));
        }
        else if(argc > 2 && atom_getsym(argv+1) == hoa_sym_mute)
        {
            x->f_map->setMute(index, atom_getlong(argv+2));
        }
    }
}
Example #24
0
double azimuth(double deg, double min)
{
    return azimuth(deg, min, 0.0);
}
Example #25
0
/**
 * R E A D _ M A T
 */
void read_mat (struct rt_i *rtip)
{
    double scan[16] = MAT_INIT_ZERO;
    char	*buf;
    int		status = 0x0;
    mat_t	m;
    mat_t       q;

    while ((buf = rt_read_cmd(stdin)) != (char *) 0) {
	if (bu_strncmp(buf, "eye_pt", 6) == 0) {
	    if (sscanf(buf + 6, "%lf%lf%lf", &scan[X], &scan[Y], &scan[Z]) != 3) {
		bu_exit(1, "nirt: read_mat(): Failed to read eye_pt\n");
	    }
	    target(X) = scan[X];
	    target(Y) = scan[Y];
	    target(Z) = scan[Z];
	    status |= RMAT_SAW_EYE;
	} else if (bu_strncmp(buf, "orientation", 11) == 0) {
	    if (sscanf(buf + 11,
		       "%lf%lf%lf%lf",
		       &scan[X], &scan[Y], &scan[Z], &scan[W]) != 4) {
		bu_exit(1, "nirt: read_mat(): Failed to read orientation\n");
	    }
	    MAT_COPY(q, scan);
	    quat_quat2mat(m, q);
	    if (nirt_debug & DEBUG_MAT)
		bn_mat_print("view matrix", m);
	    azimuth() = atan2(-m[0], m[1]) / DEG2RAD;
	    elevation() = atan2(m[10], m[6]) / DEG2RAD;
	    status |= RMAT_SAW_ORI;
	} else if (bu_strncmp(buf, "viewrot", 7) == 0) {
	    if (sscanf(buf + 7,
		       "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
		       &scan[0], &scan[1], &scan[2], &scan[3],
		       &scan[4], &scan[5], &scan[6], &scan[7],
		       &scan[8], &scan[9], &scan[10], &scan[11],
		       &scan[12], &scan[13], &scan[14], &scan[15]) != 16) {
		bu_exit(1, "nirt: read_mat(): Failed to read viewrot\n");
	    }
	    MAT_COPY(m, scan);
	    if (nirt_debug & DEBUG_MAT)
		bn_mat_print("view matrix", m);
	    azimuth() = atan2(-m[0], m[1]) / DEG2RAD;
	    elevation() = atan2(m[10], m[6]) / DEG2RAD;
	    status |= RMAT_SAW_VR;
	}
    }

    if ((status & RMAT_SAW_EYE) == 0) {
	bu_exit(1, "nirt: read_mat(): Was given no eye_pt\n");
    }
    if ((status & (RMAT_SAW_ORI | RMAT_SAW_VR)) == 0) {
	bu_exit(1, "nirt: read_mat(): Was given no orientation or viewrot\n");
    }

    direct(X) = -m[8];
    direct(Y) = -m[9];
    direct(Z) = -m[10];

    dir2ae();

    targ2grid();
    shoot("", 0, rtip);
}
int main(int argc, char *argv[])
{ 
  struct bildinfo geoinfo;        /* alles zum Bildbearbeiten aus dem Header*/ 
  struct bildattribut{
      char name[128];          /* Struktur, um fuer jedes Bild die geo-  */
      int doy;                 /* zu verarbeiten                         */
      double time;
      double gamma; 
      double f;
      double dec;
      double EOT;
      double lon_sun;  
      unsigned char headline[HDL];  /* Recordlaenge fuer "echte" Groesse    */ 
      short int **imagedata;  /* matrix; msg data are assigned to imagedata */
      byte **Bimagedata; /* Matrix, mfg data are assigned to Bimagedata */
  };
  struct bildattribut bildfolge[BILDANZ]; /* Zahl der Listenelemente: Monat = BILDANZ */

  int rho_max=0;           /* maximale Reflektivitaet bei Met-8 Bildern   */
                             /* Cosinuskorrektur                            */
  double GMT;                /* Abscannzeitpunkt                            */
  int quiet=0;               /* Bildschirminformationen ?                   */
  int accm;                  /* parameter for MFG GMT calculation           */
  int lin, col;              /* Zaehlvariablen fuer Zeile und Spalte        */
  int n=0;                   /* Anzahl der verarbeiteten  Bilder            */
  int decide;                /* ausserhalb der Erde oder nicht              */
  double lat,lon;            /* latitude and longitude in radians !         */
  double corr;               /* normalisierte Radianz                       */
  double coszen;             /* Cosinus des Zenitwinkels                    */
  /* ---> SELFCALIBRATION: declarations */
  /* RM May 2008: added file pointer frhomax,fstatrho */
  FILE *out_image,*list,*f,*frhomax,*fstatrho;
  /* RM May 2008: fper and kend1 is needed for the caclulation of the percentile */
  short int *fper = NULL;  
  int kend1=0;
  /* RM May 2008: added averaged angles used for the caclculation of the scatter angle scata */
  float msza=0;  /* average of the solar zenith angle over time and space within the calibration region */
  float mazi=0;  /* average of the solar azimuth angle over time and space within the calibration region */
  float msatazi=0; /* average of the sat azimuth angle .... */
  float msatzen=0; /* average of the satellite zenith angle */
  float scata=0;   /* the mean scattering angle */
  double satazi, satzen;     /* geometry of MSG, satellite zenith and azimuth  */
  float r2d=180.0/3.1416;
  float esd;      /* variable for the geometric correction of rho_max */
  float dpos=0.0; /* dpos is the position of Meteosat relativ to lon=0, West is negative, East positive */
  /* <--- SELFCALIBRATION declarations */

                              /* Dateinamen von Bildern                      */ 
  char out_imagefile[160],groundpathname[128],
       cloudpathname[128],bild[128],bildpathname[128];            
  short int **out;           /* Matrix fuer die Ausgabewerte       	    */
  short int reflectivity_vector[BILDANZ]; 
  short int min, hour;

  char *cp;                         /* temporaere Werte                     */
  char zeitname[4];                 /* temporaerer ASCII-String der Zeit    */
         
  long zahl,anzahl;
  double cloudindex ;
  double db_hours_per_line; /* added in order to caclulate the timeoffset */
  char *channel="MFGVIS"; /* added, currently hard wired, shoul be provided via heliosat call once the thermal irradiance is
			included */
  short int MFG=1; /* added, currently hard wired, should be provided via heliosat call, once the routine is successfully tested for 
                   MFG and MSG !! */
  int i,k,laenge;
  char quite='\0';
  short int sig_ground, sig_shadow=0; /* width of distribution of cloudfree pixels 
                                        and shaded pixels */
  /* sig_shadow is zero, the shadow module will not be used, it is too slow and probably not needed if 
  the fuzzy logic Heliosat version is used*/

  short int(temp);
  float doffset=0; /* the dark/space offset of the instrument */

  slope=(BYTE_MAX-BYTE_MIN)/(CLOUDI_MAX-CLOUDI_MIN);
  y_intercept=BYTE_MAX-CLOUDI_MAX*slope;                   /* DEFINE */
  *out_imagefile = '\0';
  for(i = 0;i <= BILDANZ;i++){*bildfolge[i].name = '\0';}
  

/*** optionale Argumente von der command line lesen... ***/

  if (argc<4)             /* wenn nicht mindestens zwei opt.Parameter.. */
    exit_print_usage();   /* .. dann schliesse das Programm */

  for (i=1; i<argc; i++)  /* fuer alle Argumente..                          */
  {
    cp=argv[i];
    if (*cp!='-' && *cp!='/') /* pruefe ob Argument mit '-' oder '/' beginnt */
    {
      fprintf(stderr,"bodenalbedo: no option specified (%s)\n",cp);
      exit_print_usage();
    }
    cp++;
    if (*(cp+1))            /* pruefe ob an uebernaechster Stelle ein Blank  */
    {
      fprintf(stderr,"bodenalbedo: missing blank. Usage: -%c <arg>\n",*cp);
      exit(1);
    }
    *cp=(char) tolower((int) *cp); /* es wird nicht zwischen Klein- und      *
				    * Grossschreibung unterschieden          */

    if (*cp=='l') list=fopen(argv[++i],"rt");
    else if (*cp=='b') strcpy(bildpathname,argv[++i]);
    else if (*cp=='c') strcpy(cloudpathname,argv[++i]);
    else if (*cp=='g') strcpy(groundpathname,argv[++i]);
    /* ---> SELFCALIBRATION dpos instead of sig_ground !!! */
    else if (*cp=='s') dpos=atof(argv[++i]); /*dpos instead of sig_ground, see  program header for details */
    else if (*cp=='z') MFG=atoi(argv[++i]); 
    /* MFG instead of sig_shadow MFG=1: MFG data expected MFG=0: MSG data */ 
    else if (*cp=='q') quite='q';
    else {
      fprintf(stderr,"bodenalbedo: unknown option: %s\n",cp);
      exit_print_usage();
    }
  }
  if (dpos != 0.0) 
  {printf("Meteosat position not at longitude=0 ! Please check -s in the heliosat call & set it to 0 if Met is at lon=0 \n");}

  if(MFG==1)
  {printf("assume MFG image data as input !! \n please check if you realy use MFG: -z has to be 0 for MSG \n");}
  else{
      printf("assume MSG image data as input !! \n please check if you realy use MSG: -z has to be 1 for MFG \n");
  }


 /* oeffnen aller Dateien, die in Liste stehen, Header auswerten, Matrizen zuweisen */
 zahl=0;
 while(!feof(list) && anzahl < BILDANZ )
       /* CaP - inserting the limit of BILDANZ to avoid coredumps*/
       /* ||  anzahl < BILDANZ )        */
 { 
   anzahl=zahl;
   fscanf(list,"%s\r",bildfolge[anzahl].name);
   strcpy(bild,bildpathname);
   strcat(bild,"/");
   strcat(bild,bildfolge[anzahl].name);
   
   if(!quite)printf("%d %s\n",anzahl,bild);
   
   read_xpif_header(HDL,bild,&bildfolge[anzahl].headline[0]); /* store header for output XPIF-images */
   
   
    if(HDL==256)
    {
     bildfolge[anzahl].headline[11]=(unsigned char) 0;          /* no additional headers wanted !      */
    }
    if (MFG==1)
    { 
      bildfolge[anzahl].Bimagedata=read_xpif_to_Bmatrix(HDL,bild,&geoinfo);
      bildfolge[anzahl].imagedata=smatrix(0,geoinfo.nrlines-1,0,geoinfo.nrcolumns-1);
      /* RM 17.07.09: dark offset and snanning time is different for MFG and MSG */
      db_hours_per_line=(25./geoinfo.nrlines/60.);
      doffset=4.5*4;
      for (lin = 0;lin < geoinfo.nrlines;lin++) {  /* change type and rotate the image, afterwards free bmatrix */
	  for(col = 0;col < geoinfo.nrcolumns;col++){ 
	      /* temp=(short int)bildfolge[anzahl].Bimagedata[geoinfo.nrlines-lin-1][geoinfo.nrcolumns-col-1]; */
	      /* correct if old openMTP converter is used */
	  bildfolge[anzahl].imagedata[lin][col]=4*(short int)bildfolge[anzahl].Bimagedata[geoinfo.nrlines-lin-1][geoinfo.nrcolumns-col-1]; 
	  /* correct if new openMTP to XPIF converter is used */
          /* bildfolge[anzahl].imagedata[lin][col]=4*(short int)bildfolge[anzahl].Bimagedata[lin][col]; */

	  /* multiplication with factor 4 needed in order to have only one BYTE MAX definition */  
           /* (short int)bildfolge[anzahl].Bimagedata[lin][col]; */
	      /* (short int)bildfolge[anzahl].Bimagedata[geoinfo.nrlines-lin-1][geoinfo.nrcolumns-col-1]; */
            /*       printf("i,j,temp= %d %d %d",lin, col, temp); */
	  }
      }
      free_bmatrix(bildfolge[anzahl].Bimagedata,0,geoinfo.nrlines-1,0,geoinfo.nrcolumns-1); 
	/* bildfolge[anzahl].Bimagedata=read_xpif_to_Bmatrix(HDL,bild,&geoinfo); */ 
    } 
    else{
	bildfolge[anzahl].imagedata=read_xpif_to_matrix(HDL,bild,&geoinfo);
	db_hours_per_line=(12./geoinfo.nrlines/60.);
	doffset=51;
    }
    printf("Iam here 1 %d %d \n",geoinfo.nrlines, geoinfo.nrcolumns); 
    bildfolge[anzahl].doy=geoinfo.doy;
    hour=geoinfo.aq_time /100;
    min=fmod(geoinfo.aq_time,100);
    bildfolge[anzahl].time=hour+min/60.0;
    bildfolge[anzahl].EOT=equation_of_time(bildfolge[anzahl].doy,&bildfolge[anzahl].gamma,&bildfolge[anzahl].f,&bildfolge[anzahl].dec);
    zahl++; 
  } 
 n=anzahl;    
 printf ("n= %d \n",n);
 /*  printf("doy is %04d %04d \n",geoinfo.doy, geoinfo.aq_time );   
    printf("nrs is %d %d %d %d \n",geoinfo.nrlines,geoinfo.nrcolbig,geoinfo.nrcolumns, geoinfo.nrlines );
    printf("nrs is %d %d %d %d \n",geoinfo.line_off,geoinfo.col_off,geoinfo.nav_lres, geoinfo.nav_cres );  */
  
 /* orig out=smatrix(0,geoinfo.nrlines-1,0,geoinfo.nrcolbig-1); RM 24.02->*/
  out=smatrix(0,geoinfo.nrlines-1,0,geoinfo.nrcolumns-1);
 
 /***  Normalize images   ---------------------------------------- ***/
 
 /* allocate memory for fper 42610*/
/* fper = malloc(45000 * (n+1) * sizeof(short int));
 if(fper == NULL)
 {
     fprintf(stderr, "not enough memory for array fper, needed for automatic calibration \n");
     exit;
     } */
  /* CaP - allocating only 2 bytes for now. Using realloc later in the loop below (line 719).
The former memory allocation (previous line) causes severe memory errors and 
program crashes */
 
  /* --> SELFCALIBRATION: initial allocation of field needed for the percentiles */
  fper = malloc(sizeof(short int));
  /* <-- */
  printf("Iam here 2 \n");
  accm=0;
 for (lin = 0;lin < geoinfo.nrlines;lin++)   /* fuer alle Zeilen */
 { 
/* 12.10.09 included new lines for the calculation of GMT. Now MFG and MSg can be processed */
 /* old, orig for MSG GMT=bildfolge[anzahl].time+timeoffset(geoinfo.nav_lres,geoinfo.line_off,lin,15); */
     /* GMT : Abscannzeitpunkt dieser Zeile bestimmen */
      /* 17.07.09 fixed GMT bug, accm needed to consider that two subsequent lines are scanned in || */
     accm=accm+abs((lin-1)%2); 
     GMT=bildfolge[anzahl].time+(double)lin*db_hours_per_line; 
     /* printf("now here vv \n");*/
    if ((strcmp(channel,"MFGVIS")==0) && MFG==1)
     {  /* CaP 29.04.2009 - in the vis imagery adjacent lines are scanned in couples */
	 GMT=bildfolge[anzahl].time+(double)(accm-1)*db_hours_per_line;
	 /*  printf("GMT,accm= %f %d \n",GMT ,accm); */
     }
     /* orig  GMT=bildfolge[anzahl].time+timeoffset(geoinfo.nav_lres,geoinfo.line_off,lin,15); */  
     /* GMT=bildfolge[anzahl].time+timeoffset(geoinfo.nav_lres,geoinfo.line_off,lin,15);  */

     for (k = 0 ;k <= n;k++)  /* fuer alle Bilder */
     {
	 /* fuer Abscannzeit dieser Zeile und jeden Tag den Sonnenstand bestimmen */
	 bildfolge[k].lon_sun=(12.0-GMT-(bildfolge[k].EOT/60.0))*15*(PI/180.0);
     }
     /* printf("ere re re %d \n",k); */
     for(col = 0;col < geoinfo.nrcolumns;col++)  /* fuer alle Spalten */
     { 
         if(MFG==1){
	     decide=geoloc(lin,col,geoinfo.nrlines,&lat,&lon);
         }
         else{
	decide=geomsg(geoinfo.nav_cres,geoinfo.nav_lres,geoinfo.col_off,geoinfo.line_off,lin,col,&lat,&lon);
	 }
         /* if (decide == 0){
         printf("the geoloc i,j,lat,lon %d %d %f %f \n", lin, col,lat*180/pi,lon*180/pi);
         } */
	     /* orig decide=geomsg(geoinfo.nav_cres,geoinfo.nav_lres,geoinfo.col_off,geoinfo.line_off,lin,col,&lat,&lon); */

	 /* ---> SELFCALIBRATION: calculation of additional angles */
         /* RM Jul 2008: added equations for the calculation of satellite zenith and azimuth 
		  !! it is assumed that the satellite is at lat=lon=0
		  h=42164.0 height of geostationary Satellite */
	 satazi = atan(sin(lon-dpos/r2d)/tan(lat)); /* rm 072008 modified formular, covers all positions of Meteosat now */
	 /* old satzen = fabs(atan(sin(lat) * h/(cos(lat) * h - R_E))); */
    satzen=90/r2d-atan((cos(dpos/r2d-lon)*cos(lat)-0.1512)/sqrt(1-pow(cos(dpos/r2d-lon),2)*pow(cos(lat),2)));     /* <--- SELFCALIBRATION: calculation of additional angles */         
	 if (decide==0)
	 {
	     for(k = 0 ;k <= n;k++)  /* fuer alle Bilder */
	     {
		 corr=0;
		 coszen=cos_zenit(lat,lon,bildfolge[k].dec,bildfolge[k].lon_sun);
		 if(coszen>0.02)
		     corr = (int)((bildfolge[k].imagedata[lin][col]-doffset)/coszen); /* orig 51 instead of doffset */
		 corr = mini(corr,BYTE_MAX);
		 corr = maxi(corr,BYTE_MIN); 
		 bildfolge[k].imagedata[lin][col] = corr;
		 /* RM 20.11.07:  automatic calculation of rho_max starts, sort vector content according 
		    to the value, in ascending order using heapsort, Numerical Recipies in C 
		    the 95 percentil * 1.1 is than the desired rhomax value */
		 /* ---> SELFCALIBRATION: Calculate the percentile and additional angles
                         needed for the calculation of the scatter angle */
	  if(lat > -0.92 && lat < -0.8 && lon  < (-0.01 + dpos/r2d) && lon > (-0.262+dpos/r2d)) /* -0.436*/     
		/* RM 072008: added +dpos in order to shift the reference region for Meteosat-East
		dpos=position of Meteosat relative to lon=0 in degree, west is negative */  
               {
		
		fper[kend1]=(short int)bildfolge[k].imagedata[lin][col]; /* assign values within region to fper */
		kend1=kend1+1;
		/* calculate the mean angles as basis for the caclulation of the scatter angle, 
		   needed for the geometric correction of rhomax */
		fper = realloc(fper,(kend1+1)*sizeof(short int));
		msza=((kend1-1)*msza+acos(coszen))/kend1; 
		mazi=((kend1-1)*mazi+azimuth(lat,lon,bildfolge[k].dec,acos(coszen),bildfolge[k].lon_sun))/kend1;
		msatazi=((kend1-1)*msatazi+satazi)/kend1;
		msatzen=((kend1-1)*msatzen+satzen)/kend1;
	        }
            /* <--- end of SELFCALIBRATION: Calculate the percentile and additional angles
                         needed for the calculation of the scatter angle */
	     }
	 }
         if (decide==1){
	     out[lin][col] = (int) 0;
	     for(k=1;k<=n;k++){
		 /*  if(geoinfo.nrlines<200){doffset=doffset+ bildfolge[15].imagedata[lin][col];} */
		     bildfolge[k].imagedata[lin][col] = 0;
	     }
	 }
     }
 }
 printf("doffset= %f \n", doffset);
 printf("now I am here \n"); 

 /* ---> SELFCALIBRATION: sorting the fper field and assignment of the percentiles */
 heapsort(kend1, fper); /* order the counts */
 int p1=(int)(0.1*(kend1+1));
 int p3=(int)(0.3*(kend1+1));
 int p5=(int)(0.5*(kend1+1));
 int p7=(int)(0.7*(kend1+1));
 int p8=(int)(0.8*(kend1+1));
 int p9=(int)(0.9*(kend1+1));
 int pm=(int)(0.95*(kend1+1));
 /* <--- SELFCALIBRATION: sorting the fper field and assignment of the percentiles */
 /* ---> SELFCALIBRATION: empirical correction of anisotropy for rho_max */
 /* RM 28.05.08 empirical correction for scatter angle effect, so far formula only proven for 3 - 33 degree,
    RM 30.07.08 implemented new formula, correction works from 3-70 degree (scata), but probably only for 
             the reference regions and not everywhere, above scattering angle of 32 the uncertainty of
             the geometric corrections is significnat higher */
 scata=scatt_angle(msza, mazi, msatzen, msatazi);
 /* added new correction for rho_max, seems that the dominant effect comes from the
   sza dependent change of the cloud albedo, the clouds seems to reflect pretty well
   isotropic for a given SZA and rel AZA lower than 60 degree
   the correction formula results from a linear fit (gnuplot) applied to a 
   2.5 year time series for all slots with SZA>60 */
   if (msza*r2d > 80.0 && msza*r2d <0.0) esd=1.0;  /* gcor =1 for SZA>80 and <0*/
   else
   {esd=1+0.0017*(45.0-msza*r2d); }

 /* <--- SELFCALIBRATION: empirical correction of anisotropic cloud reflection for rho_max */
 /* ---> SELFCALIBRATION: Open and write the output files for information  related to  the 
         self calibration approach */
  fstatrho=fopen("rhostat.out","a") ;
 fprintf(fstatrho, "# kend1= %d doy= %d hour= %d min = %d \n",kend1,geoinfo.doy, hour,min);
 fprintf(fstatrho, " gcor= %f msza= %f mazi= %f satazi= %f satzen= %f scattangle= %f rhomax %f pm= %d \n", esd, msza*r2d, (mazi)*r2d, msatazi*r2d, msatzen*r2d, scata*r2d, fper[pm]*esd*1.1, fper[pm]);
 fprintf(fstatrho, "# ESD= %f rho(10,30,50,70,80,90,95)= %d  %d %d %d %d %d  %d rhomax %f \n",esd,fper[p1],fper[p3],fper[p5],fper[p7], fper[p8],fper[p9],fper[pm], fper[pm]*esd*1.1);
   if (hour==13 && min==0)
   {
       frhomax=fopen("rhomax.out","w");  /* RM 072008 changed r+ to w, r+ does not work properly on my machine */
       rho_max=fper[pm]*esd*1.1;
       fprintf(frhomax, "%d \n", rho_max);
       fprintf(fstatrho,"## The noon rho_may is %d \n",rho_max );
       fclose(frhomax); 
   }
   else
   {
       /* if((frhomax=fopen("rhomax.out","r")) == NULL) */
       if(file_exists("rhomax.out")) 
       {
           frhomax=fopen("rhomax.out","r");
	   fscanf(frhomax, "%d", &rho_max);	   
	   fprintf(fstatrho,"# Use noon rhomax from rhomax.out %d \n",rho_max );
	   printf("Use noon rhomax from rhomax,out %d \n",rho_max );
	   fclose(frhomax); 
       }
       else
       {
	   fprintf(fstatrho,"# WARNING Cannot open rhomax file, hence instead of the noon rhomax that of the actual slot is used,which might lead to higher uncertainty.\n");
	   rho_max=(int)fper[pm]*esd*1.1;
	   fprintf(fstatrho,"# Use rhomax of actual slot %d \n",rho_max );
	   /*fclose(frhomax);*/
       }  
   }
   sig_ground=(short int)(0.035 * rho_max);
   fprintf(fstatrho,"#  sig_ground =%d \n \n",sig_ground );
   fclose(fstatrho);
   free(fper);
   /* <--- SELFCALIBRATION: Open and write the output files for information  related to  the 
      self calibration approach */  
   printf("Finished normalizing images and automatic calibration \n");
 /*
  *  Grundalbedo and Cloud Index  ----------------------------------------
  */

 for (lin = 0;lin < geoinfo.nrlines;lin++)   /* fuer alle Pixel (Zeilen ... */
 {
   for(col = 0; col < geoinfo.nrcolumns; col++)  /* ... und Spalten)            */
   { 
     for(k = 0; k<=n; k++)
     {
       /* copy all values to a vector, from these values ground albedo will de determined 
          reflectivity_vector contains all reflectivity values for one location */
        reflectivity_vector[k]=bildfolge[k].imagedata[lin][col]/bildfolge[k].f;
	/* /f correct for earth sun-distance **/
     } 
	 /* calculation of ground albedo: 
	    out[lin][col]contains ground albedo
	    reflectivity_vector contains cloud index values */
     out[lin][col]=groundreflectivity_and_cloudindex(&reflectivity_vector[0], n, sig_ground, sig_shadow, rho_max);
     for(k = 0; k<=n; k++)
     { 
       /* copy all cloud index values from vector back to matrix */
       bildfolge[k].imagedata[lin][col]=reflectivity_vector[k];

     }   
   }
  }
 
/***********************************************************************
  *  Ausgeben aller Bilder und Freisetzung des Speicherplatzes...
 ***********************************************************************/ 
  
  /* Bodenalbedonamen zusammensetzen  */
  /* RM changed the naming of the reflectance files, mothly means for every slot are calculated and has to be saved,
     with the old naming they are  overriden */ 
     strcpy(out_imagefile,groundpathname);
     strcat(out_imagefile,"/");
     sprintf(zeitname,"%04d",geoinfo.aq_time);
     strncat(out_imagefile,bildfolge[1].name,6); /* added string for year and month */
     /*strncat(out_imagefile,zeitname,4);*/
     strcat(out_imagefile,zeitname);
     /* printf("out_imagefile = %s bildfolge.name= %s\n",out_imagefile, bildfolge[1].name); */ 
     if(HDL==256)strcat(out_imagefile,"hhmm.REF"); 
     if(HDL==260)strcat(out_imagefile,"hhmm.REF.X260"); 
  /* Grundalbedo speichern */
     
   printf("nrbytes= %d",geoinfo.nrbytes) ;
  if (!(out_image=fopen(out_imagefile,"wb"))) 
     exit_no_write(out_imagefile);
    
  if (MFG==1) 
  {geoinfo.nrbytes=geoinfo.nrbytes*2;}   /* dangerous, only for testing */

   fwrite(&bildfolge[1].headline[0],HDL,1,out_image);    

   /* orig fwrite(&out[0][0],geoinfo.nrcolbig*geoinfo.nrlines*(long)geoinfo.nrbytes,1,out_image);  
   fclose(out_image);
   free_smatrix(out,0,geoinfo.nrlines-1,0,geoinfo.nrcolbig-1); */
   fwrite(&out[0][0],geoinfo.nrcolumns*geoinfo.nrlines*(long)geoinfo.nrbytes,1,out_image);  
   fclose(out_image);
   free_smatrix(out,0,geoinfo.nrlines-1,0,geoinfo.nrcolumns-1);
  
  for(k=0;k<=n;k++)             
  {  
     strcpy(out_imagefile,cloudpathname);
     strcat(out_imagefile,"/");
     strncat(out_imagefile,bildfolge[k].name,strlen(bildfolge[k].name)-4);
     if(HDL==256)strcat(out_imagefile,"CI.XPIF");
     if(HDL==260)strcat(out_imagefile,"CI.X260"); 
     if (!(out_image=fopen(out_imagefile,"wb"))) 
         exit_no_write(out_imagefile);
     fwrite(&bildfolge[k].headline[0],HDL,1,out_image);   
     /*  orig
	 fwrite(&bildfolge[k].imagedata[0][0],geoinfo.nrcolbig*geoinfo.nrlines*(long)geoinfo.nrbytes,1,out_image);  */
   
     /* memcpy(void *dest, const void *src, size_t n);*/
     bildfolge[k].Bimagedata=bmatrix(0,geoinfo.nrlines-1,0,geoinfo.nrcolumns-1);
     for (lin = 0;lin < geoinfo.nrlines;lin++) {  
	 for(col = 0;col < geoinfo.nrcolumns;col++){ 
	     bildfolge[k].Bimagedata[lin][col]=(byte)(bildfolge[k].imagedata[lin][col]/4);
	 }
     }
	 fwrite(&bildfolge[k].Bimagedata[0][0],geoinfo.nrcolumns*geoinfo.nrlines,1,out_image);
	 free_bmatrix(bildfolge[k].Bimagedata,0,geoinfo.nrlines-1,0,geoinfo.nrcolumns-1);
	 fclose(out_image);
	 free_smatrix(bildfolge[k].imagedata,0,geoinfo.nrlines-1,0,geoinfo.nrcolumns-1); /* orig geoinfo.nrcolbig-1 */
  }

  return(0);
}
LightSource* SVGFEDistantLightElement::lightSource() const
{
    return new DistantLightSource(azimuth(), elevation());
}
Example #28
0
double azimuth( const packet& packet, unsigned int block, unsigned int laser, double angularSpeed )
{
    return azimuth( double( packet.blocks[block].rotation() ) / 100, laser, angularSpeed );
}
Example #29
0
void test_all()
{
    // See:
    //  - http://www.ga.gov.au/geodesy/datums/vincenty_inverse.jsp
    //  - http://www.ga.gov.au/geodesy/datums/vincenty_direct.jsp
    // Values in the comments below was calculated using the above pages
    // in some cases distances may be different, previously used values was left

    // use km
    double gda_a = 6378.1370;
    double gda_f = 1.0 / 298.25722210;
    double gda_b = gda_a * ( 1.0 - gda_f );
    bg::srs::spheroid<double> gda_spheroid(gda_a, gda_b);

    // Test fractional coordinates only for non-integral types
    if ( BOOST_GEOMETRY_CONDITION(
            ! boost::is_integral<typename bg::coordinate_type<P1>::type>::value
         && ! boost::is_integral<typename bg::coordinate_type<P2>::type>::value  ) )
    {
        // Flinders Peak -> Buninyong
        test_vincenty<P1, P2>(azimuth(144,25,29.52440), azimuth(-37,57,3.72030),
                              azimuth(143,55,35.38390), azimuth(-37,39,10.15610),
                              54.972271, azimuth(306,52,5.37), azimuth(127,10,25.07),
                              gda_spheroid);
    }

    // Lodz -> Trondheim
    test_vincenty<P1, P2>(azimuth(19,28), azimuth(51,47),
                          azimuth(10,21), azimuth(63,23),
                          1399.032724, azimuth(340,54,25.14), azimuth(153,10,0.19),
                          gda_spheroid);
    // London -> New York
    test_vincenty<P1, P2>(azimuth(0,7,39), azimuth(51,30,26),
                          azimuth(-74,0,21), azimuth(40,42,46),
                          5602.044851, azimuth(288,31,36.82), azimuth(51,10,33.43),
                          gda_spheroid);

    // Shanghai -> San Francisco
    test_vincenty<P1, P2>(azimuth(121,30), azimuth(31,12),
                          azimuth(-122,25), azimuth(37,47),
                          9899.698550, azimuth(45,12,44.76), azimuth(309,50,20.88),
                          gda_spheroid);

    test_vincenty<P1, P2>(0, 0, 0, 50, 5540.847042, 0, 180, gda_spheroid); // N
    test_vincenty<P1, P2>(0, 0, 0, -50, 5540.847042, 180, 0, gda_spheroid); // S
    test_vincenty<P1, P2>(0, 0, 50, 0, 	5565.974540, 90, -90, gda_spheroid); // E
    test_vincenty<P1, P2>(0, 0, -50, 0, 5565.974540, -90, 90, gda_spheroid); // W
    
    test_vincenty<P1, P2>(0, 0, 50, 50, 7284.879297, azimuth(32,51,55.87), azimuth(237,24,50.12), gda_spheroid); // NE
    
    // The original distance values, azimuths calculated using the web form mentioned above
    // Using default spheroid units (meters)
    test_vincenty<P1, P2>(0, 89, 1, 80, 1005153.5769, azimuth(178,53,23.85), azimuth(359,53,18.35)); // sub-polar
    test_vincenty<P1, P2>(4, 52, 4, 52, 0.0, 0, 0); // no point difference
    test_vincenty<P1, P2>(4, 52, 3, 40, 1336039.890, azimuth(183,41,29.08), azimuth(2,58,5.13)); // normal case

    test_side<P1, P2>(0, 0, 0, 1, 0, 2, 0);
    test_side<P1, P2>(0, 0, 0, 1, 0, -2, 0);
    test_side<P1, P2>(10, 0, 10, 1, 10, 2, 0);
    test_side<P1, P2>(10, 0, 10, -1, 10, 2, 0);

    test_side<P1, P2>(10, 0, 10, 1, 0, 2, 1); // left
    test_side<P1, P2>(10, 0, 10, -1, 0, 2, -1); // right

    test_side<P1, P2>(-10, -10, 10, 10, 10, 0, -1); // right
    test_side<P1, P2>(-10, -10, 10, 10, -10, 0, 1); // left
    test_side<P1, P2>(170, -10, -170, 10, -170, 0, -1); // right
    test_side<P1, P2>(170, -10, -170, 10, 170, 0, 1); // left
}
PassRefPtr<LightSource> SVGFEDistantLightElement::lightSource() const
{
    return DistantLightSource::create(azimuth(), elevation());
}