Blame view

src/DATA/MANAGER/UpdateInfo.php 3.43 KB
d680a61c   Benjamin Renard   Add UpdateInfoVI
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
<?php
/** @file    updateInfo.php 
*   @brief   Stand-Alone application Updates Start - Stop Info in  DD Base info files in workng directory
*   @arg     full  prefix of info and times files
*   
*     
*   @version  $Id: UpdateInfo.php 100 2016-04-20 08:26:17Z elena $
*/ 


date_default_timezone_set('UTC');

 function days2MonthDay($oldDate)
 { 
      $year = substr($oldDate, 0, 4);
      $day =  substr($oldDate, 4, 3);
      $hour = substr($oldDate, 7, 2);
      $min =  substr($oldDate, 9, 2);
      $sec =  substr($oldDate, 11, 2);
      $msec = substr($oldDate, 13, 3);
      $newDate = date("Y-m-d",
          strtotime("+$day days",strtotime("$year-01-01")))."T".$hour.":".$min.":".$sec.".".$msec."Z";

  return $newDate;
 } 

 function updateTag($tagName, $tagValue)
 {

    global $dom;

     $vi = $dom->getElementsByTagName("VI");
 
     $Old = $vi->item(0)->getElementsByTagName($tagName)->item(0);
     $New = $dom->createElement($tagName, $tagValue);
     $vi->item(0)->replaceChild($New, $Old); 
 }

/*
*           MAIN 
*/
            if($argc == 2) $infoXml = "$argv[1]_info.xml";
            else exit(" info FULL prefix should be specified");

            global $dom;        
            
            define("DDBASEBIN",getenv("DDBASEBIN")); 
            $dom = new DomDocument();
  
            $path_parts = pathinfo($argv[1]);
            $path = $path_parts['dirname']."/";
            $currDir = getcwd();

            if (!$dom->load($infoXml)) {             
                chdir($path);
                $dom->loadXML(file_get_contents($path_parts['basename']."_info.xml"));  // NFS connection doesn't load 
                chdir($currDir);    
            }
 
// Read *_times.nc          
            $res = system(DDBASEBIN."/StartStopLocal $argv[1]_times.nc");  
            $Time = explode("-",$res);
 // Start   
            $Start = days2MonthDay($Time[0]);
            updateTag('GlobalStart', $Start);
            updateTag('LocalStart', $Start);        
                             
// Stop              
            $Stop = days2MonthDay($Time[1]);
            updateTag('GlobalStop', $Stop);
            updateTag('LocalStop', $Stop);     
                 
            $dom->save($infoXml);
 
// make *_info.nc                      
            system(DDBASEBIN."/infoLocal2nc $infoXml $argv[1]_info.nc"); 
                          
// check if there is TimeRestriction
	  
            if (file_exists($path."TimeRestriction")) {
                    chdir($path); 
                    $restr = file("./TimeRestriction", FILE_IGNORE_NEW_LINES);
   
    //                 $days = $restr[0];
                    $n = sscanf($restr[0], "%d-%d-%d", $yy, $mm, $dd);
 
                    $infoXmlRestr = $restr[1].".xml";
                    $infoNcRestr = $restr[1].".nc";
                 
                    if ($n == 1) {
                        $restrStop = date("Y-m-d", strtotime("-$yy days"))."T23:59:59.999Z";
                    }
                    else {
                        $restrStop = $restr[0]."T23:59:59.999Z";
                    }

                    if ($restrStop <  $Stop) {
                        updateTag('GlobalStop', $restrStop);
                        updateTag('LocalStop', $restrStop); 
                    } 
                
                    $dom->save($infoXmlRestr);
 
                    system(DDBASEBIN."/infoLocal2nc $infoXmlRestr $infoNcRestr");
                    chdir($currDir);
                }    
        
    ?>