getGranulesSize.php
1.36 KB
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
<?php
/**
* @file getGranulesSize.php
* @brief
* @version $Id: $
*/
if (!$_GET['id']) exit('INPUT ERROR');
require_once './DDserverWeb_ini.php';
$alias = array(baseDir => webAlias);
$replace = array("-" => "_");
$dataSet = strtr($_GET['id'], $replace);
if (file_exists("GRANULES/$dataSet.json")) {
echo file_get_contents("GRANULES/$dataSet.json");
exit();
}
$ddSys = new DOMDocument('1.0');
$ddSys->load(baseDir."/DDsys.xml");
$xp = new DOMXpath($ddSys);
$VI = $xp->query("//NAME[.='".$dataSet."']");
if ( $VI->item(0)->nodeValue == NULL ) exit('NO SUCH DATASET');
$main = array();
$index = array();
$location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue;
if (file_exists($location."RestrictedAccess")) exit(); // PrivateAccess
foreach (glob($location."*.nc.gz") as $granule) {
$cmd = 'stat --printf="%s" '. $granule;
$file = basename($granule,".nc.gz");
$index[$file] = exec($cmd);
}
$main[substr($location,strlen(baseDir))] = $index;
$json = json_encode($main);
file_put_contents("GRANULES/$dataSet.json", $json);
exit($json);
?>