generateGranulesIndex.php 1.3 KB
<?php
/** 
*   @file generateGranulesIndex.php
*   @brief
*   @version $Id:  $ 
*/
       
       define('BASE','/data/DDBASE/');

       require_once BASE.'DDService/DDserverWeb_ini.php';

        if (!getenv('DDBASE')) 
            define('DDBASE', BASE.'DATA');
        else
            define('DDBASE', getenv('DDBASE'));

        $ddSys = new DOMDocument('1.0');
        $ddSys->load(DDBASE.'/DDsys.xml');
        $dataSets = $ddSys->getElementsByTagName('VI');
      
        foreach ($dataSets as $VI) 
        {
            $vi_ = $VI->getElementsByTagName("NAME")->item(0);
            // only local bases
            if ($vi_->getAttribute("base") != "LOCAL") continue;
            $id = $vi_->nodeValue;

            $main = array();
            $index = array();  
            $location = $VI->getElementsByTagName("LOCATION")->item(0)->nodeValue;  
                                          
            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(DDBASE))] = $index;
            file_put_contents(BASE."GRANULES/$id.json", json_encode($main));
        } 
?>