Commit d680a61c04daab76d1626a877f54055bade2e237

Authored by Benjamin Renard
1 parent 531fafe7

Add UpdateInfoVI

CMakeLists.txt
... ... @@ -58,6 +58,7 @@ add_subdirectory(tests)
58 58 install(FILES "scripts/StartServer" DESTINATION . PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
59 59 install(FILES "scripts/DDServer.env" DESTINATION . PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
60 60 install(FILES "scripts/AddLocalVI.sh" DESTINATION . PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
  61 +install(FILES "scripts/UpdateInfoVI.sh" DESTINATION . PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
61 62 install(DIRECTORY "src/CALLEXT/" DESTINATION bin/CALLEXT)
62 63 install(DIRECTORY "src/DATA/MANAGER/" DESTINATION bin/DATAMANAGER)
63 64  
... ...
scripts/UpdateInfoVI.sh 0 → 100755
... ... @@ -0,0 +1,8 @@
  1 +#!/bin/sh
  2 +
  3 +BASEDIR=$(dirname "$0")
  4 +
  5 +. ${BASEDIR}/DDServer.env
  6 +
  7 +php ${DATAMANAGER}/UpdateInfo.php $@
  8 +
... ...
src/DATA/MANAGER/AddLocalVI.php
... ... @@ -87,9 +87,9 @@
87 87 if (!is_dir(location)) mkdir(location, 0775, true);
88 88 echo location."\n";
89 89 chdir(location);
90   - if (!file_exists($times)) system("TimesUpdate -r ".$times." ".brief."_0*.nc");
  90 + if (!file_exists($times)) system(DDBASEBIN."/TimesUpdate -r ".$times." ".brief."_[0-9]*.nc");
91 91 if (!file_exists($info_xml)) makeInfoXml();
92   - if (!file_exists($info)) system("infoLocal2nc ".$info_xml." ".$info);
  92 + if (!file_exists($info)) system(DDBASEBIN."/infoLocal2nc ".$info_xml." ".$info);
93 93 if (!file_exists("clean")) {
94 94 copy (DDLIB."/Cash.template", $cache);
95 95 $SED = "sed 's/NAME/".brief."/g' ".DDLIB."/Clean.template > clean";
... ...
src/DATA/MANAGER/UpdateInfo.php 0 → 100644
... ... @@ -0,0 +1,108 @@
  1 +<?php
  2 +/** @file updateInfo.php
  3 +* @brief Stand-Alone application Updates Start - Stop Info in DD Base info files in workng directory
  4 +* @arg full prefix of info and times files
  5 +*
  6 +*
  7 +* @version $Id: UpdateInfo.php 100 2016-04-20 08:26:17Z elena $
  8 +*/
  9 +
  10 +
  11 +date_default_timezone_set('UTC');
  12 +
  13 + function days2MonthDay($oldDate)
  14 + {
  15 + $year = substr($oldDate, 0, 4);
  16 + $day = substr($oldDate, 4, 3);
  17 + $hour = substr($oldDate, 7, 2);
  18 + $min = substr($oldDate, 9, 2);
  19 + $sec = substr($oldDate, 11, 2);
  20 + $msec = substr($oldDate, 13, 3);
  21 + $newDate = date("Y-m-d",
  22 + strtotime("+$day days",strtotime("$year-01-01")))."T".$hour.":".$min.":".$sec.".".$msec."Z";
  23 +
  24 + return $newDate;
  25 + }
  26 +
  27 + function updateTag($tagName, $tagValue)
  28 + {
  29 +
  30 + global $dom;
  31 +
  32 + $vi = $dom->getElementsByTagName("VI");
  33 +
  34 + $Old = $vi->item(0)->getElementsByTagName($tagName)->item(0);
  35 + $New = $dom->createElement($tagName, $tagValue);
  36 + $vi->item(0)->replaceChild($New, $Old);
  37 + }
  38 +
  39 +/*
  40 +* MAIN
  41 +*/
  42 + if($argc == 2) $infoXml = "$argv[1]_info.xml";
  43 + else exit(" info FULL prefix should be specified");
  44 +
  45 + global $dom;
  46 +
  47 + define("DDBASEBIN",getenv("DDBASEBIN"));
  48 + $dom = new DomDocument();
  49 +
  50 + $path_parts = pathinfo($argv[1]);
  51 + $path = $path_parts['dirname']."/";
  52 + $currDir = getcwd();
  53 +
  54 + if (!$dom->load($infoXml)) {
  55 + chdir($path);
  56 + $dom->loadXML(file_get_contents($path_parts['basename']."_info.xml")); // NFS connection doesn't load
  57 + chdir($currDir);
  58 + }
  59 +
  60 +// Read *_times.nc
  61 + $res = system(DDBASEBIN."/StartStopLocal $argv[1]_times.nc");
  62 + $Time = explode("-",$res);
  63 + // Start
  64 + $Start = days2MonthDay($Time[0]);
  65 + updateTag('GlobalStart', $Start);
  66 + updateTag('LocalStart', $Start);
  67 +
  68 +// Stop
  69 + $Stop = days2MonthDay($Time[1]);
  70 + updateTag('GlobalStop', $Stop);
  71 + updateTag('LocalStop', $Stop);
  72 +
  73 + $dom->save($infoXml);
  74 +
  75 +// make *_info.nc
  76 + system(DDBASEBIN."/infoLocal2nc $infoXml $argv[1]_info.nc");
  77 +
  78 +// check if there is TimeRestriction
  79 +
  80 + if (file_exists($path."TimeRestriction")) {
  81 + chdir($path);
  82 + $restr = file("./TimeRestriction", FILE_IGNORE_NEW_LINES);
  83 +
  84 + // $days = $restr[0];
  85 + $n = sscanf($restr[0], "%d-%d-%d", $yy, $mm, $dd);
  86 +
  87 + $infoXmlRestr = $restr[1].".xml";
  88 + $infoNcRestr = $restr[1].".nc";
  89 +
  90 + if ($n == 1) {
  91 + $restrStop = date("Y-m-d", strtotime("-$yy days"))."T23:59:59.999Z";
  92 + }
  93 + else {
  94 + $restrStop = $restr[0]."T23:59:59.999Z";
  95 + }
  96 +
  97 + if ($restrStop < $Stop) {
  98 + updateTag('GlobalStop', $restrStop);
  99 + updateTag('LocalStop', $restrStop);
  100 + }
  101 +
  102 + $dom->save($infoXmlRestr);
  103 +
  104 + system(DDBASEBIN."/infoLocal2nc $infoXmlRestr $infoNcRestr");
  105 + chdir($currDir);
  106 + }
  107 +
  108 + ?>
... ...