Blame view

php/classes/VOTableMgr.php 11.7 KB
16035364   Benjamin Renard   First commit
1
2
3
<?php
/**
 * @class VOTableMgr
10200969   Roipoussiere   Remove whitespace...
4
 * @version $Id: VOTableMgr.php 2916 2015-05-19 13:08:33Z elena $
16035364   Benjamin Renard   First commit
5
6
 */

16035364   Benjamin Renard   First commit
7
8
9
10
//set DEBUG_MODE to TRUE to have some log information in user data dir
define("DEBUG_MODE",FALSE);


10200969   Roipoussiere   Remove whitespace...
11
class VOTableMgr
bf74fc2d   Elena.Budnik   IMPEX
12
13
14
{
  public  $xml = null;
  private $log, $xp;
10200969   Roipoussiere   Remove whitespace...
15
16

  function __construct()
16035364   Benjamin Renard   First commit
17
18
19
20
  {
  	 if (DEBUG_MODE)
  	   $this->log = fopen(USERDATADIR."logVOTable","w");
  }
10200969   Roipoussiere   Remove whitespace...
21

16035364   Benjamin Renard   First commit
22
23
24
25
26
  function addLog($msg)
  {
  	 if (DEBUG_MODE)
  	   fprintf($this->log,$msg);
  }
10200969   Roipoussiere   Remove whitespace...
27

16035364   Benjamin Renard   First commit
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  function load($fileName)
  {
  	 $this->xml =  new DomDocument("1.0");
    if (!$this->xml->load($fileName))
    {
      $this->addLog("Cannot load file ".$fileName."\n");
      return FALSE;
    }

    $this->checkIDAttribute();
    /*if ($this->xml->namespaceURI == '')
    {
    	 $this->addLog("File don't have a namespace defined\n");
      if (!$this->xml->createAttributeNS('http://www.ivoa.net/xml/VOTable/v1.1','xmlns'))
        $this->addLog("Cannot create namespace attribute\n");
    }
10200969   Roipoussiere   Remove whitespace...
44

16035364   Benjamin Renard   First commit
45
    $this->addLog($this->xml->namespaceURI."\n");*/
10200969   Roipoussiere   Remove whitespace...
46

16035364   Benjamin Renard   First commit
47
    $rootNamespace = $this->xml->lookupNamespaceUri($this->xml->namespaceURI);
10200969   Roipoussiere   Remove whitespace...
48

16035364   Benjamin Renard   First commit
49
    $this->xp = new domxpath($this->xml);
10200969   Roipoussiere   Remove whitespace...
50

16035364   Benjamin Renard   First commit
51
    $this->xp->registerNameSpace('x', $rootNamespace);
10200969   Roipoussiere   Remove whitespace...
52

16035364   Benjamin Renard   First commit
53
54
    return TRUE;
  }
10200969   Roipoussiere   Remove whitespace...
55

16035364   Benjamin Renard   First commit
56
57
58
59
  function isValidSchema()
  {
  	 if (!$this->xml)
  	   return FALSE;
10200969   Roipoussiere   Remove whitespace...
60
61


16035364   Benjamin Renard   First commit
62
63
  	 //ToDo - BRE - add validation!!
  	 return TRUE;
10200969   Roipoussiere   Remove whitespace...
64

16035364   Benjamin Renard   First commit
65
66
  	 if (DEBUG_MODE)
  	   libxml_use_internal_errors(true);
10200969   Roipoussiere   Remove whitespace...
67

16035364   Benjamin Renard   First commit
68
  	 $vers = $this->getVersion();
10200969   Roipoussiere   Remove whitespace...
69

16035364   Benjamin Renard   First commit
70
  	 $this->addLog("VOTable version : ".$vers."\n");
10200969   Roipoussiere   Remove whitespace...
71

16035364   Benjamin Renard   First commit
72
  	 $result = FALSE;
10200969   Roipoussiere   Remove whitespace...
73

16035364   Benjamin Renard   First commit
74
75
76
77
78
79
80
81
82
  	 switch ($vers)
  	 {
  	 	 case '1.2' :
  	 	 	 $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.2.xsd');
  	 	 case '1.0' :
  	 	 	 $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.0.xsd');
  	 	 default :
  	 	   $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.1.xsd');
  	 }
10200969   Roipoussiere   Remove whitespace...
83

16035364   Benjamin Renard   First commit
84
85
86
  	 if (DEBUG_MODE)
  	 {
  	   $errors = libxml_get_errors();
10200969   Roipoussiere   Remove whitespace...
87
88

  	   foreach ($errors as $error)
16035364   Benjamin Renard   First commit
89
  	   {
10200969   Roipoussiere   Remove whitespace...
90
91
  	   	 $msg = '';

16035364   Benjamin Renard   First commit
92
93
94
95
96
97
98
99
100
101
102
103
104
        switch ($error->level)
        {
          case LIBXML_ERR_WARNING:
            $msg .= ("WARNING ".$error->code.": ");
            break;
          case LIBXML_ERR_ERROR:
            $msg .= ("ERROR ".$error->code.": ");
            break;
          case LIBXML_ERR_FATAL:
            $msg .= ("FATAL ".$error->code.": ");
            break;
        }
        $msg .= ($error->message." - In line : ".$error->line." - Of file : ".$error->file."\n");
10200969   Roipoussiere   Remove whitespace...
105

16035364   Benjamin Renard   First commit
106
107
        $this->addLog($msg);
  	   }
10200969   Roipoussiere   Remove whitespace...
108

16035364   Benjamin Renard   First commit
109
110
  	   libxml_use_internal_errors(false);
  	 }
10200969   Roipoussiere   Remove whitespace...
111

16035364   Benjamin Renard   First commit
112
113
    return $result;
  }
10200969   Roipoussiere   Remove whitespace...
114

16035364   Benjamin Renard   First commit
115
116
117
118
  protected function queryResource()
  {
  	 return "//x:RESOURCE";
  }
10200969   Roipoussiere   Remove whitespace...
119

16035364   Benjamin Renard   First commit
120
121
122
123
  protected function queryTable()
  {
  	 return $this->queryResource()."/x:TABLE";
  }
10200969   Roipoussiere   Remove whitespace...
124

16035364   Benjamin Renard   First commit
125
126
127
128
  protected function queryDescription()
  {
  	 return $this->queryTable()."/x:DESCRIPTION";
  }
10200969   Roipoussiere   Remove whitespace...
129

16035364   Benjamin Renard   First commit
130
131
132
133
  protected function queryFields()
  {
  	 return $this->queryTable()."/x:FIELD";
  }
10200969   Roipoussiere   Remove whitespace...
134

16035364   Benjamin Renard   First commit
135
136
137
138
139
140
141
142
143
144
145
146
147
  protected function queryField($field_id)
  {
  	 return $this->queryFields()."[@ID='".$field_id."']";
  }

  protected function queryFieldByName($field_id)
  {
  	 return $this->queryFields()."[@name='".$field_id."']";
  }
  protected function queryFieldDescription($field_id)
  {
  	 return $this->queryField($field_id)."/x:DESCRIPTION";
  }
10200969   Roipoussiere   Remove whitespace...
148

16035364   Benjamin Renard   First commit
149
150
151
152
  protected function queryData()
  {
  	 return $this->queryTable()."/x:DATA";
  }
10200969   Roipoussiere   Remove whitespace...
153

16035364   Benjamin Renard   First commit
154
155
156
157
  protected function queryTableData()
  {
  	 return $this->queryData()."/x:TABLEDATA";
  }
10200969   Roipoussiere   Remove whitespace...
158

16035364   Benjamin Renard   First commit
159
160
161
162
  protected function queryTR()
  {
  	 return $this->queryTableData()."/x:TR";
  }
10200969   Roipoussiere   Remove whitespace...
163

16035364   Benjamin Renard   First commit
164
  //
10200969   Roipoussiere   Remove whitespace...
165

16035364   Benjamin Renard   First commit
166
167
168
169
170
  public function getVersion()
  {
  	 if (!$this->xml)
  	 		return '';
  	 $root = $this->xml->documentElement;
10200969   Roipoussiere   Remove whitespace...
171

16035364   Benjamin Renard   First commit
172
173
  	 return $root->getAttribute('version');
  }
10200969   Roipoussiere   Remove whitespace...
174

16035364   Benjamin Renard   First commit
175
176
177
178
  public function getDescription()
  {
  	 if (!$this->xp)
  	   return '';
10200969   Roipoussiere   Remove whitespace...
179

16035364   Benjamin Renard   First commit
180
  	 $desc = $this->xp->query($this->queryDescription());
10200969   Roipoussiere   Remove whitespace...
181

16035364   Benjamin Renard   First commit
182
183
  	 if ($desc->length < 1)
  	   return '';
10200969   Roipoussiere   Remove whitespace...
184

16035364   Benjamin Renard   First commit
185
186
  	 return $desc->item(0)->nodeValue;
  }
10200969   Roipoussiere   Remove whitespace...
187

bf74fc2d   Elena.Budnik   IMPEX
188
189
190
191
  public function isData()
  {
    $trs =  $this->xml->getElementsByTagName('TR');
    if ($trs->length > 0) return true;
10200969   Roipoussiere   Remove whitespace...
192

bf74fc2d   Elena.Budnik   IMPEX
193
194
    return false;
  }
10200969   Roipoussiere   Remove whitespace...
195

16035364   Benjamin Renard   First commit
196
197
198
199
  public function getFirstTR()
  {
  	 if (!$this->xp)
  	   return NULL;
10200969   Roipoussiere   Remove whitespace...
200
201
202

  	 /*$trs = $this->xp->query($this->queryTR());

16035364   Benjamin Renard   First commit
203
204
  	 if ($trs->length < 1)
  	   return NULL;
10200969   Roipoussiere   Remove whitespace...
205

16035364   Benjamin Renard   First commit
206
  	 return $trs->item(0);*/
10200969   Roipoussiere   Remove whitespace...
207

16035364   Benjamin Renard   First commit
208
  	 $tabledatas = $this->xp->query($this->queryTableData());
10200969   Roipoussiere   Remove whitespace...
209

16035364   Benjamin Renard   First commit
210
211
  	 if ($tabledatas->length < 1)
  	   return NULL;
10200969   Roipoussiere   Remove whitespace...
212

16035364   Benjamin Renard   First commit
213
  	 $tabledata = $tabledatas->item(0);
10200969   Roipoussiere   Remove whitespace...
214

16035364   Benjamin Renard   First commit
215
  	 $node = $tabledata->firstChild;
10200969   Roipoussiere   Remove whitespace...
216

16035364   Benjamin Renard   First commit
217
218
  	 while($node && ($node->nodeType != 1) && ($node->nodeName != "TR"))
      $node = $node->nextSibling;
10200969   Roipoussiere   Remove whitespace...
219

16035364   Benjamin Renard   First commit
220
221
    return $node;
  }
10200969   Roipoussiere   Remove whitespace...
222

16035364   Benjamin Renard   First commit
223
224
225
226
  public function getNextTR($tr)
  {
  	 if (!$this->xp)
  	   return NULL;
10200969   Roipoussiere   Remove whitespace...
227

16035364   Benjamin Renard   First commit
228
229
230
231
    while($tr->nextSibling && ($tr->nextSibling->nodeType != 1) && ($node->nodeName != "TR"))
      $tr = $tr->nextSibling;
				return $tr->nextSibling;
  }
10200969   Roipoussiere   Remove whitespace...
232

16035364   Benjamin Renard   First commit
233
234
235
236
  public function getTDValueByFieldIndex($tr,$field_index)
  {
  	 if (!$this->xp)
  	   return NULL;
10200969   Roipoussiere   Remove whitespace...
237

16035364   Benjamin Renard   First commit
238
  	 $tds = $tr->getElementsByTagName("TD");
10200969   Roipoussiere   Remove whitespace...
239

16035364   Benjamin Renard   First commit
240
241
  	 if (($tds->length < 1) || ($field_index >= $tds->length))
  	   return NULL;
10200969   Roipoussiere   Remove whitespace...
242

16035364   Benjamin Renard   First commit
243
244
  	 return $tds->item($field_index)->nodeValue;
  }
10200969   Roipoussiere   Remove whitespace...
245

16035364   Benjamin Renard   First commit
246
247
248
249
  protected function isTimeField($field)
  {
    if (!$this->xp)
  	   return FALSE;
10200969   Roipoussiere   Remove whitespace...
250

16035364   Benjamin Renard   First commit
251
252
  	 return (($field->getAttribute("ucd") == "time.epoch") && ($field->getAttribute("xtype") == "dateTime"));
  }
10200969   Roipoussiere   Remove whitespace...
253

16035364   Benjamin Renard   First commit
254
255
256
257
  public function getTimeFieldIndex()
  {
  	 if (!$this->xp)
  	   return -1;
10200969   Roipoussiere   Remove whitespace...
258

16035364   Benjamin Renard   First commit
259
  	 $fields = $this->xp->query($this->queryFields());
10200969   Roipoussiere   Remove whitespace...
260

16035364   Benjamin Renard   First commit
261
262
  	 if ($fields->length < 1)
  	   return -1;
10200969   Roipoussiere   Remove whitespace...
263

16035364   Benjamin Renard   First commit
264
265
266
  	 for ($i = 0; $i < $fields->length; $i++)
  	   if ($this->isTimeField($fields->item($i)))
  	     return $i;
10200969   Roipoussiere   Remove whitespace...
267

16035364   Benjamin Renard   First commit
268
269
  	 return -1;
  }
10200969   Roipoussiere   Remove whitespace...
270

bf74fc2d   Elena.Budnik   IMPEX
271
272
273
274
	protected function getFieldByID($field_id)
	{
		if (!$this->xp)
			return NULL;
16035364   Benjamin Renard   First commit
275

bf74fc2d   Elena.Budnik   IMPEX
276
		$fields = $this->xp->query($this->queryFields());
10200969   Roipoussiere   Remove whitespace...
277

bf74fc2d   Elena.Budnik   IMPEX
278
279
		if ($fields->length < 1)
			return NULL;
10200969   Roipoussiere   Remove whitespace...
280

bf74fc2d   Elena.Budnik   IMPEX
281
282
283
		foreach ($fields as $field)
			if ($field->getAttribute("ID") == $field_id)
				return $field;
10200969   Roipoussiere   Remove whitespace...
284

bf74fc2d   Elena.Budnik   IMPEX
285
286
		return NULL;
	}
16035364   Benjamin Renard   First commit
287

bf74fc2d   Elena.Budnik   IMPEX
288
289
290
291
	protected function getFieldByName($field_id)
	{
		if (!$this->xp)
			return NULL;
10200969   Roipoussiere   Remove whitespace...
292

bf74fc2d   Elena.Budnik   IMPEX
293
		$fields = $this->xp->query($this->queryFieldByName($field_id));
10200969   Roipoussiere   Remove whitespace...
294

bf74fc2d   Elena.Budnik   IMPEX
295
296
		if ($fields->length < 1)
			return NULL;
10200969   Roipoussiere   Remove whitespace...
297

bf74fc2d   Elena.Budnik   IMPEX
298
299
300
		foreach ($fields as $field)
			if ($field->getAttribute("name") == $field_id)
			return $field;
10200969   Roipoussiere   Remove whitespace...
301

bf74fc2d   Elena.Budnik   IMPEX
302
		return NULL;
16035364   Benjamin Renard   First commit
303
	}
16035364   Benjamin Renard   First commit
304

bf74fc2d   Elena.Budnik   IMPEX
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
	protected function checkIDAttribute()
	{

		$fields = $this->xml->getElementsByTagName('FIELD');
		$i = 0;
		foreach ($fields as $field)
		{
			$i++;
			if (!$field->hasAttribute("ID"))
			{
				$field->setAttribute("ID", "col".$i);
			}
		}
		$this->xml->saveXML();
	}
16035364   Benjamin Renard   First commit
320
321
322
323
324

  public function getFieldIndexByID($field_id)
  {
  	 if (!$this->xp)
  	   return -1;
10200969   Roipoussiere   Remove whitespace...
325

16035364   Benjamin Renard   First commit
326
  	 $fields = $this->xp->query($this->queryFields());
10200969   Roipoussiere   Remove whitespace...
327

16035364   Benjamin Renard   First commit
328
329
  	 if ($fields->length < 1)
  	   return -1;
10200969   Roipoussiere   Remove whitespace...
330

16035364   Benjamin Renard   First commit
331
332
333
  	 for ($i = 0; $i < $fields->length; $i++)
  	   if ($fields->item($i)->getAttribute("ID") == $field_id)
  	     return $i;
10200969   Roipoussiere   Remove whitespace...
334

16035364   Benjamin Renard   First commit
335
336
  	 return -1;
  }
10200969   Roipoussiere   Remove whitespace...
337
338

  public function getStartStop()
16035364   Benjamin Renard   First commit
339
340
341
  {
  	 if (!$this->xp)
  	   return '0 0';
10200969   Roipoussiere   Remove whitespace...
342

16035364   Benjamin Renard   First commit
343
344
345
    $timeIndex = $this->getTimeFieldIndex();
    if ($timeIndex < 0)
      return '0 0';
10200969   Roipoussiere   Remove whitespace...
346

16035364   Benjamin Renard   First commit
347
    $tr = $this->getFirstTR();
10200969   Roipoussiere   Remove whitespace...
348

16035364   Benjamin Renard   First commit
349
350
    if (!$tr)
      return '0 0';
10200969   Roipoussiere   Remove whitespace...
351

16035364   Benjamin Renard   First commit
352
    $start = $this->getTDValueByFieldIndex($tr,$timeIndex);
10200969   Roipoussiere   Remove whitespace...
353

16035364   Benjamin Renard   First commit
354
355
356
357
358
359
    $stop = $start;
    while ($tr)
    {
      $stop = $this->getTDValueByFieldIndex($tr,$timeIndex);
      $tr = $this->getNextTR($tr);
    }
10200969   Roipoussiere   Remove whitespace...
360

16035364   Benjamin Renard   First commit
361
362
363
364
    if (!$start)
      $start = 0;
    else
      $start = strtotime($start);
10200969   Roipoussiere   Remove whitespace...
365

16035364   Benjamin Renard   First commit
366
367
368
369
    if (!$stop)
      $stop = 0;
    else
      $stop = strtotime($stop);
10200969   Roipoussiere   Remove whitespace...
370
371

    return $start." ".$stop;
16035364   Benjamin Renard   First commit
372
  }
10200969   Roipoussiere   Remove whitespace...
373

bf74fc2d   Elena.Budnik   IMPEX
374
375
376
377
	public function getFieldInfoByID($field_id)
	{
		if (!$this->xp)
			return array("id"    => $field_id, "error" => "No file loaded");
10200969   Roipoussiere   Remove whitespace...
378

bf74fc2d   Elena.Budnik   IMPEX
379
		$field = $this->getFieldByID($field_id);
10200969   Roipoussiere   Remove whitespace...
380

bf74fc2d   Elena.Budnik   IMPEX
381
382
		if (!$field)
			$field = $this->getFieldByName($field_id);
16035364   Benjamin Renard   First commit
383

bf74fc2d   Elena.Budnik   IMPEX
384
385
		if (!$field)
			return array("id" => $field_id, "error" => "This field doesn't exist");
10200969   Roipoussiere   Remove whitespace...
386

bf74fc2d   Elena.Budnik   IMPEX
387
388
		return $this->getFieldInfo($field);
	}
10200969   Roipoussiere   Remove whitespace...
389
390


bf74fc2d   Elena.Budnik   IMPEX
391
392
393
394
	public function getFieldInfo($field)
	{
		if (!$this->xp)
			return array("id"    => $field_id, "error" => "No file loaded");
10200969   Roipoussiere   Remove whitespace...
395

bf74fc2d   Elena.Budnik   IMPEX
396
397
398
399
		$description = '';
		$desc = $field->getElementsByTagName("DESCRIPTION");
		if ($desc->length >= 1)
			$description = $desc->item(0)->nodeValue;
16035364   Benjamin Renard   First commit
400

bf74fc2d   Elena.Budnik   IMPEX
401
402
403
404
405
		$size = $field->getAttribute("arraysize");
		if ($size == '')
			$size = 1;
		else
			$size = intval($size);
16035364   Benjamin Renard   First commit
406

bf74fc2d   Elena.Budnik   IMPEX
407
408
409
410
411
412
413
414
415
416
417
418
419
		switch ($field->getAttribute("datatype"))
		{
			case "short" :
				$type = "SHORT";
				break;
			case "int" :
				$type = "INTEGER";
				break;
			case "long"   :
			case "double" :
				$type = "DOUBLE";
				break;
			default :
10200969   Roipoussiere   Remove whitespace...
420
				$type = "FLOAT";
bf74fc2d   Elena.Budnik   IMPEX
421
		}
10200969   Roipoussiere   Remove whitespace...
422

bf74fc2d   Elena.Budnik   IMPEX
423
424
		if (!$field->getAttribute("ID"))
			$id = "col".$n;
10200969   Roipoussiere   Remove whitespace...
425
		else
bf74fc2d   Elena.Budnik   IMPEX
426
			$id = $field->getAttribute("ID");
10200969   Roipoussiere   Remove whitespace...
427

bf74fc2d   Elena.Budnik   IMPEX
428
429
430
431
432
433
434
435
436
		return array("id"     => $field->getAttribute("ID"),
						"type"        => $type,
						"name"        => $field->getAttribute("name"),
						"ucd"         => $field->getAttribute("ucd"),
						"unit"        => $field->getAttribute("unit"),
						"size"        => $size,
						"description" => $description
						);
	}
10200969   Roipoussiere   Remove whitespace...
437

16035364   Benjamin Renard   First commit
438
439
440
441
  public function getFieldsInfo()
  {
   	 if (!$this->xp)
  	   return array("error" => "No file loaded");
10200969   Roipoussiere   Remove whitespace...
442

16035364   Benjamin Renard   First commit
443
    $fields_info = array();
10200969   Roipoussiere   Remove whitespace...
444

16035364   Benjamin Renard   First commit
445
  	 $fields = $this->xp->query($this->queryFields());
10200969   Roipoussiere   Remove whitespace...
446

16035364   Benjamin Renard   First commit
447
448
  	 if ($fields->length < 1)
  	   return $fields_info;
10200969   Roipoussiere   Remove whitespace...
449

16035364   Benjamin Renard   First commit
450
451
452
453
    foreach ($fields as $field)
    {
     	if ($this->isTimeField($field))
        continue;
10200969   Roipoussiere   Remove whitespace...
454

16035364   Benjamin Renard   First commit
455
456
      array_push($fields_info,$this->getFieldInfo($field));
    }
10200969   Roipoussiere   Remove whitespace...
457

16035364   Benjamin Renard   First commit
458
459
    return $fields_info;
  }
10200969   Roipoussiere   Remove whitespace...
460
461

  public function getSamplings()
16035364   Benjamin Renard   First commit
462
463
464
465
  {
  	 if (!$this->xp)
  	   return array("minSampling" => 0,
                   "maxSampling" => 0);
10200969   Roipoussiere   Remove whitespace...
466

16035364   Benjamin Renard   First commit
467
468
469
470
  	 $timeIndex = $this->getTimeFieldIndex();
    if ($timeIndex < 0)
      return array("minSampling" => 0,
                   "maxSampling" => 0);
10200969   Roipoussiere   Remove whitespace...
471

16035364   Benjamin Renard   First commit
472
473
474
475
476
477
478
479
480
481
    $tr = $this->getFirstTR();

    if (!$tr)
      return array("minSampling" => 0,
                   "maxSampling" => 0);

    $prevTime = 0;
    while ($tr)
    {
      $time = $this->getTDValueByFieldIndex($tr,$timeIndex);
10200969   Roipoussiere   Remove whitespace...
482

16035364   Benjamin Renard   First commit
483
484
485
486
487
488
489
      if ($time)
      {
        $time = strtotime($time);
        if (($prevTime > 0) && ($time-$prevTime > 0))
          $deltaT[$time-$prevTime]++;
        $prevTime = $time;
      }
10200969   Roipoussiere   Remove whitespace...
490

16035364   Benjamin Renard   First commit
491
492
      $tr = $this->getNextTR($tr);
    }
10200969   Roipoussiere   Remove whitespace...
493

16035364   Benjamin Renard   First commit
494
495
    $minSampling = +1.e31;
    $maxSampling = 0.0;
10200969   Roipoussiere   Remove whitespace...
496
497

    foreach ($deltaT as $key => $value)
16035364   Benjamin Renard   First commit
498
    {
10200969   Roipoussiere   Remove whitespace...
499

16035364   Benjamin Renard   First commit
500
501
     if ($value/count($deltaT) < 0.10)
        continue;
10200969   Roipoussiere   Remove whitespace...
502

16035364   Benjamin Renard   First commit
503
504
505
      if ($key < $minSampling) $minSampling = $key;
      if ($key > $maxSampling) $maxSampling = $key;
    }
10200969   Roipoussiere   Remove whitespace...
506

16035364   Benjamin Renard   First commit
507
508
509
    return array("minSampling" => $minSampling,
                 "maxSampling" => $maxSampling);
  }
10200969   Roipoussiere   Remove whitespace...
510

bf74fc2d   Elena.Budnik   IMPEX
511
512
513
514
515
516
  /*
	* Add vector data made from components to IMPEX VOT
	*/
	public function addVectorToVot($paramID, $fileName)
	{
		$argsArr = explode(',', $paramID);
10200969   Roipoussiere   Remove whitespace...
517

bf74fc2d   Elena.Budnik   IMPEX
518
519
520
		$fields = $this->xml->getElementsByTagName('FIELD');
		$table = $this->xml->getElementsByTagName('TABLE')->item(0);
		$data = $this->xml->getElementsByTagName('DATA')->item(0);
10200969   Roipoussiere   Remove whitespace...
521

bf74fc2d   Elena.Budnik   IMPEX
522
		$i=0;
10200969   Roipoussiere   Remove whitespace...
523
		$find = false;
bf74fc2d   Elena.Budnik   IMPEX
524
		foreach ($fields as $field)
10200969   Roipoussiere   Remove whitespace...
525
		{
bf74fc2d   Elena.Budnik   IMPEX
526
			if ($field->getAttribute('name') == $argsArr[0])
10200969   Roipoussiere   Remove whitespace...
527
			{
bf74fc2d   Elena.Budnik   IMPEX
528
529
530
531
532
533
534
				$unit = $field->getAttribute('unit');
				$ucd  = $field->getAttribute('ucd');
				$datatype  = $field->getAttribute('datatype');
				$firstTD = $i;
				$find = true;
				break;
			}
10200969   Roipoussiere   Remove whitespace...
535
			$i++;
bf74fc2d   Elena.Budnik   IMPEX
536
		}
16035364   Benjamin Renard   First commit
537

bf74fc2d   Elena.Budnik   IMPEX
538
		if ($find)
10200969   Roipoussiere   Remove whitespace...
539
		{
bf74fc2d   Elena.Budnik   IMPEX
540
541
542
543
544
545
			$new_field = $this->xml->createElement('FIELD');
			$new_field->setAttribute('ID', $paramID);
			$new_field->setAttribute('name', $paramID);
			$new_field->setAttribute('datatype', $datatype);
			$new_field->setAttribute('arraysize', '3');
			$new_field->setAttribute('unit', $unit);
10200969   Roipoussiere   Remove whitespace...
546
547
			$new_field->setAttribute('ucd', $ucd);
			$colN = $fields->length + 1;
bf74fc2d   Elena.Budnik   IMPEX
548
			$new_field->setAttribute('ID', 'col'.$colN);
10200969   Roipoussiere   Remove whitespace...
549

bf74fc2d   Elena.Budnik   IMPEX
550
			$table->insertBefore($new_field,$data);
10200969   Roipoussiere   Remove whitespace...
551

bf74fc2d   Elena.Budnik   IMPEX
552
553
554
555
556
557
558
559
			$trs = $this->xml->getElementsByTagName('TR');
			foreach($trs as $tr)
			{
				$tds = $tr->getElementsByTagName('TD');
				$value = trim($tds->item($firstTD)->nodeValue).' '.trim($tds->item($firstTD + 1)->nodeValue).' '.trim($tds->item($firstTD + 2)->nodeValue);
				$td = $this->xml->createElement('TD', $value);
				$tr->appendChild($td);
			}
10200969   Roipoussiere   Remove whitespace...
560
561

			$this->xml->save($fileName);
bf74fc2d   Elena.Budnik   IMPEX
562
		}
16035364   Benjamin Renard   First commit
563
	}
16035364   Benjamin Renard   First commit
564
}
10200969   Roipoussiere   Remove whitespace...
565
?>