This file is indexed.

/usr/include/magics/InputData.cc is in libmagics++-dev 2.18.15-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/******************************** LICENSE ********************************

 Copyright 2007 European Centre for Medium-Range Weather Forecasts (ECMWF)

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

 ******************************** LICENSE ********************************/

/*! \file InputData.cc
    \brief Implementation of the Template class InputData.
    
    Magics Team - ECMWF 2004
    
    Started: Thu 6-May-2004
    
    Changes:
    
*/

#include "InputData.h"
#include "SciMethods.h"




/*!
 Class information are given to the output-stream.
*/		

void InputData::print(ostream& out)  const
{
	out << "InputData[";
    InputDataAttributes::print(out);
	out << "]";
}


void  InputData::dateSetting(vector<string>& dates, vector<double>& values, DateTime& base)
{
	if ( dates.empty() )
		return;
	base = DateTime(dates.front());
	for (vector<string>:: iterator date = dates.begin(); date != dates.end(); ++ date ) {
		DateTime d(*date);
		values.push_back(d-base);
	}
}


void  InputData::numberSetting(vector<double>& from, vector<double>& values)
{
	std::copy(from.begin(), from.end(), back_inserter(values));
}


void  InputData::prepare()
{
    if ( !x_values_.empty() ) return;

    if ( magCompare(x_type_, "date" ) ) {
    	dateSetting(date_x_, x_values_, baseDateX_);
    	dateSetting(date_x2_, x2_values_, baseDateX_);
    }
    else {
    	numberSetting(x_,  x_values_);
    	numberSetting(x2_,  x2_values_);
    	numberSetting(longitudes_,  x_values_);
    }
    if ( magCompare(y_type_, "date" ) ) {
      	dateSetting(date_y_, y_values_, baseDateY_);
      	dateSetting(date_y2_, y2_values_, baseDateY_);
     }
     else {
      	numberSetting(y_,  y_values_);
      	numberSetting(y2_,  y2_values_);
      	numberSetting(latitudes_,  y_values_);
     }
    
    vector<double>::iterator x = x_values_.begin();
	vector<double>::iterator y = y_values_.begin();
	vector<double>::iterator v = values_.begin();
	vector<double>::reverse_iterator x2 = x2_values_.rbegin();
	vector<double>::reverse_iterator y2 = y2_values_.rbegin();

    while ( x != x_values_.end() && y != y_values_.end() ) {
    	double val = 0;
    	if ( v != values_.end() ) {
    		val = *v;
    		++v;
    	}
    	push_back(new UserPoint(*x, *y, val));
    	++x;
    	++y;

    }
    while ( x2 != x2_values_.rend() && y2 != y2_values_.rend() ) {
        	double val = 0;
        	if ( v != values_.end() ) {
        		val = *v;
        		++v;
        	}
        	push_back(new UserPoint(*x2, *y2, val));
        	++x2;
        	++y2;
        }
}
 
void InputData::customisedPoints(const Transformation& transformation, const std::set<string>& needs, CustomisedPointsList& out, bool)
{
	customisedPoints(transformation, needs, out);
}
void InputData::customisedPoints(const Transformation& transformation, const std::set<string>& needs, CustomisedPointsList& out)
{
	prepare();
	vector<double>::const_iterator x = x_values_.begin();
	vector<double>::const_iterator x2 = x2_values_.begin();
	vector<double>::const_iterator y = y_values_.begin();
	vector<double>::const_iterator y2 = y2_values_.begin();
	vector<double>::const_iterator xc = x_component_.begin();
	vector<double>::const_iterator yc = y_component_.begin();
	vector<double>::const_iterator v = values_.begin();
	while (  x != x_values_.end() && y != y_values_.end()  ) {
		double valx = *x;
		double valy = *y;
		if ( magCompare(x_type_, "date" ) ) {
			DateTime ref(transformation.getReferenceX());
			double shift = ref - baseDateX_;
			valx -= shift;
		}
		if ( magCompare(y_type_, "date" ) ) {
			DateTime ref(transformation.getReferenceY());
			double shift = ref - baseDateY_;
			valy -= shift;
		}

		CustomisedPoint* point = new CustomisedPoint();


		point->longitude(*x);
		point->latitude(*y);
		out.push_back(point);



		if ( same(*x, x_missing_) )
			point->missing(true);
		(*point)["x"] = valx;
		(*point)["x_lower"] = valx;
		x++;

		if ( same(*y, y_missing_) )
			point->missing(true);
		(*point)["y"] = valy;
		(*point)["y_lower"] = valy;
		y++;

		double speed = 0;
		double angle = 0;
		if ( xc != x_component_.end() && yc != y_component_.end() ) {
			speed = sqrt( (*xc * *xc)  +  (*yc * *yc) );
			angle = ( atan2(*xc, *yc)*(180/M_PI) );
			if ( angle == 0 ) angle =0.1;
			(*point)["x_component"] = *(xc++);
			(*point)["y_component"] = *(yc++);
			(*point)["intensity"] = speed;
			(*point)["direction"] = angle;
		}
		if ( v != values_.end() ) {
			(*point)["colour_component"] = *(v++);
		}
		else
			(*point)["colour_component"] = speed;

		if (needs.find("bar")  != needs.end()) {

			if ( y2 != y2_values_.end() ) {
				(*point)["y_upper"] = *(y2++);
			}
			if ( x2 != x2_values_.end() ) {

				(*point)["x_upper"] = *(x2++);
			}

		}
	}



	if ( needs.find("area")  == needs.end() )
		return;
	vector<double>::reverse_iterator xr2 = x2_values_.rbegin();
	vector<double>::reverse_iterator yr2 = y2_values_.rbegin();
	while (  xr2 != x2_values_.rend() && yr2 != y2_values_.rend()  ) {
		CustomisedPoint* point = new CustomisedPoint();
		if ( same(*xr2, x_missing_) )
			point->missing(true);
		(*point)["x"] = *(xr2++);

		if ( same(*yr2, y_missing_) )
			point->missing(true);
		(*point)["y"] = *(yr2++);
		out.push_back(point);
	}
}

void InputData::customisedPoints(const std::set<string>&, CustomisedPointsList& out)
{
	prepare();
	vector<double>::const_iterator x = x_values_.begin();
	vector<double>::const_iterator y = y_values_.begin();
	vector<double>::const_iterator xc = x_component_.begin();
	vector<double>::const_iterator yc = y_component_.begin();
	vector<double>::const_iterator v = values_.begin();
	while (  x != x_values_.end() || y != y_values_.end()  ) {
		    	CustomisedPoint* point = new CustomisedPoint();


		    		point->longitude(*x);
		    		point->latitude(*y);
		    		out.push_back(point);

		    	if ( x != x_.end() ) (*point)["x"] = *(x++);
		    	if ( y != y_.end() ) (*point)["y"] = *(y++);
		        double speed = 0;
		    	if ( xc != x_component_.end() && yc != y_component_.end() ) {
		    		speed = sqrt( (*xc * *xc)  +  (*yc * *yc) );
		    		(*point)["x_component"] = *(xc++);
		    		(*point)["y_component"] = *(yc++);
		    	}
		    	if ( v != values_.end() ) {
		    		(*point)["colour_component"] = *(v++);
		    	}
		    	else
		    		(*point)["colour_component"] = speed;



		    }
}

MatrixHandler& InputData::matrix()
{
	if  ( !matrix_ ) {
		prepare();
		matrix_ = (*binning_)(*this);
	}

	matrixHandlers_.push_back(new MatrixHandler(*matrix_));
	return *(matrixHandlers_.back());
}


void InputData::getReady(const Transformation& transformation)
{
	try {
		for ( vector<string>::const_iterator x = date_x_.begin(); x != date_x_.end(); ++x )
			x_.push_back(transformation.x(*x));
		}
	catch (...) {}
	try {
		for ( vector<string>::const_iterator y = date_y_.begin(); y != date_y_.end(); ++y )
			y_.push_back(transformation.y(*y));
	}
	catch (...) {}
	
}

void InputData::visit(Transformation& transformation)
{
	// get the data ...
	try {
		prepare();
		if ( transformation.getAutomaticX() ) {
			double min = INT_MAX;
			double max = -INT_MAX;
			for (vector<double>::iterator x = x_values_.begin(); x != x_values_.end(); ++x) {
				if ( same(*x, x_missing_) ) continue;
				if ( min > *x ) min = *x;
				if ( max < *x ) max = *x;
			}
			for (vector<double>::iterator x = x2_values_.begin(); x != x2_values_.end(); ++x) {
				if ( same(*x, x_missing_) ) continue;
				if ( min > *x ) min = *x;
				if ( max < *x ) max = *x;
			}
			if ( magCompare(x_type_, "date" ) ) {

				transformation.setDataMinX(min, baseDateX_);
				transformation.setDataMaxX(max, baseDateX_);
			}
			else {
				transformation.setMinX(min);
				transformation.setMaxX(max);
			}
		}
		if ( transformation.getAutomaticY() ) {
			double min = INT_MAX;
			double max = -INT_MAX;
			for (vector<double>::iterator y = y_values_.begin(); y != y_values_.end(); ++y) {
				if ( same(*y, y_missing_) ) continue;
				if ( min > *y ) min = *y;
				if ( max < *y ) max = *y;
			}
			for (vector<double>::iterator y = y2_values_.begin(); y != y2_values_.end(); ++y) {
				if ( same(*y, y_missing_) ) continue;
				if ( min > *y ) min = *y;
				if ( max < *y ) max = *y;
			}
			if ( magCompare(y_type_, "date" ) ) {
				transformation.setDataMinY(min, baseDateY_);
				transformation.setDataMaxY(max, baseDateY_);
			}
			else {
				transformation.setMinY(min);
				transformation.setMaxY(max);
			}
		}

	}
	catch ( ... ) {}
}


PointsHandler& InputData::points(const Transformation& transformation, bool all)  {
	 prepare();

	 if ( magCompare(x_type_, "date" ) || magCompare(y_type_, "date" )) {
// create a new points list!
		PointsList*  points = new PointsList();
		for (PointsList::iterator pt = begin(); pt != end(); ++pt) {
			UserPoint* point = *pt;
			if ( magCompare(x_type_, "date" ) ) {
				DateTime ref(transformation.getReferenceX());
				double shift = ref - baseDateX_;
				point->x_ -= shift;
			}
			if ( magCompare(y_type_, "date" ) ) {
				DateTime ref(transformation.getReferenceY());
				double shift = ref - baseDateY_;
				point->y_ -= shift;
			}
			if ( !transformation.in(*point) ) {
				point->flagMissing();
				if ( all )
					points->push_back(point);
				else
					delete point;
			}
			else {
				points->push_back(point);
			}
		}
		PointsHandler* handler;
		if (all)
			handler = new PointsHandler(*points);
		else
			handler = new BoxPointsHandler(*points, transformation, false);
		pointsHandlers_.push_back(handler);
	}
	else {
		if ( all)
			pointsHandlers_.push_back(new PointsHandler(*this));
		else
			pointsHandlers_.push_back(new BoxPointsHandler(*this, transformation, false));
	}

	return *(pointsHandlers_.back());
  }


void InputData::visit(ValuesCollector& points)
{
	const Transformation& transformation = points.transformation();
	
	points.setCollected(true);
  	 
	if(points.size() <=0 || size() == 0)
	  	return;
	
	if(values_.empty())
		points.setHasValue(false);
		
	for (ValuesCollector::iterator point =  points.begin(); point != points.end(); ++point)
	{
	  	double y=(*point).y(); //lat
	  	double x=(*point).x(); //lon
		
		vector<int> idxV;		
		for(int i=0; i < size(); i++)
		{
			if(fabs(at(i)->y()-y) < points.searchRadiusY() &&
			   fabs(at(i)->x()-x) <  points.searchRadiusX())
			{
			  	idxV.push_back(i);
			}
		}
		
		if(idxV.size() ==0)
			continue;  
		
		double dist=10000000.;
		int minIdx=-1;
		
		//MagLog::debug() << "odb collect idxV : " << lat << " " << lon << " " << idxV.size() << endl;
 		
		for(int i=0; i < idxV.size(); i++)
		{  			
		  	int idx=idxV[i];
			double d;
			if(transformation.coordinateType() == Transformation::GeoType )
			{  
				d=magics::geoDistanceInKm(at(idx)->y(),at(idx)->x(),y,x);
			}
			else
			{
			  	d=(at(idx)->x()-x)*(at(idx)->x()-x) +
			        	 (at(idx)->y()-y)*(at(idx)->y()-y);
			}
			  					
			if(d < dist)
			{
			  	minIdx=idx;
				dist=d;
			}			
		}	
		if(minIdx>=0)  
			(*point).push_back(new ValuesCollectorData(at(minIdx)->x(),
							       at(minIdx)->y(),
							       at(minIdx)->value(),
							       dist));					     			
	}	  
}