Commit 88a88fcc75d9cd44436011d86a0757f5b632a015

Authored by Benjamin Renard
1 parent acefa41c

Add script to convert DDTime to double from a VI Id

scripts/ConvertVIDDTimeToDouble.sh 0 → 100755
... ... @@ -0,0 +1,14 @@
  1 +#!/bin/sh
  2 +
  3 +if [ $# -eq 0 ]
  4 + then
  5 + echo "ViId should be defined"
  6 + exit
  7 + fi
  8 +
  9 +BASEDIR=$(dirname "$0")
  10 +
  11 +. ${BASEDIR}/DDServer.env
  12 +
  13 +php ${DATAMANAGER}/ConvertVIDDTimeToDouble.php $1
  14 +
... ...
src/DATA/MANAGER/ConvertVIDDTimeToDouble.php 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +<?php
  2 +
  3 +if ($argc < 2) {
  4 + echo "[ERROR] Usage : php ".$argv[0]." ViId".PHP_EOL;
  5 + exit(1);
  6 +}
  7 +$ViId = $argv[1];
  8 +
  9 +if (!function_exists('__autoload'))
  10 +{
  11 + function __autoload($class_name) {
  12 + require_once $class_name . '.php';
  13 + }
  14 +}
  15 +
  16 +putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH"));
  17 +putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin");
  18 +set_include_path("./:".getenv("DATAMANAGER"));
  19 +
  20 +
  21 +
  22 +$baseMgr = new DDBaseMgr();
  23 +
  24 +$baseMgr->convertVIDDTimeToDouble($ViId);
  25 +
  26 +?>
... ...
src/DATA/MANAGER/DDBaseMgr.php
... ... @@ -359,6 +359,48 @@ class DDBaseMgr
359 359 $this->DDsysDoc->save($this->DDsys);
360 360 system("makeDDsys");
361 361 }
  362 +
  363 + function convertVIDDTimeToDouble($ViId) {
  364 + $XPath = new DOMXpath($this->DDsysDoc);
  365 +
  366 + $dataSet = $XPath->query("//NAME[.='$ViId']");
  367 +
  368 + if ($dataSet->length == 0) {
  369 + echo "[ERROR] NO $ViId in DDsys.xml".PHP_EOL;
  370 + return FALSE;
  371 + }
  372 +
  373 + $dataSet = $dataSet->item(0);
  374 +
  375 + $locationNodes = $dataSet->parentNode->getElementsByTagName('LOCATION');
  376 +
  377 + if ($locationNodes->length == 0) {
  378 + echo "[ERROR] Cannot retrieve LOCATION for $ViId in DDsys.xml".PHP_EOL;
  379 + return FALSE;
  380 + }
  381 +
  382 + $location = $locationNodes->item(0)->nodeValue;
  383 +
  384 +
  385 + if (file_exists($location."/LOCK")) {
  386 + echo "[ERROR] VI $ViId already locked by another process".PHP_EOL;
  387 + return FALSE;
  388 + }
  389 +
  390 + echo "[INFO] Lock VI $ViId".PHP_EOL;
  391 + touch($location."/LOCK");
  392 +
  393 + $WORKING_DIR = getcwd();
  394 + chdir($location);
  395 +
  396 + echo "[INFO] Cleanup VI $ViId".PHP_EOL;
  397 + system("./clean");
  398 + echo "[INFO] Convert data files".PHP_EOL;
  399 + system("ConvertDDTimeToDouble *.nc.gz");
  400 +
  401 + unlink($location."/LOCK");
  402 +
  403 + }
362 404 }
363 405 ?>
364 406  
... ...