diff --git a/src/CALLEXT/createVI.php b/src/CALLEXT/createVI.php index ce63e6d..10f0668 100755 --- a/src/CALLEXT/createVI.php +++ b/src/CALLEXT/createVI.php @@ -32,7 +32,7 @@ $verbose = true; - $LOGDIR = getenv("DDBASE")."../LOG/"); + $LOGDIR = getenv("DDBASE")."/../LOG/"; if (!is_dir($LOGDIR)) mkdir($LOGDIR, 0755, true); diff --git a/src/CALLEXT/getData.php b/src/CALLEXT/getData.php index a3302b9..5b94c47 100644 --- a/src/CALLEXT/getData.php +++ b/src/CALLEXT/getData.php @@ -33,15 +33,23 @@ putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH")); putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin"); set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT")); + $verbose = true; + + $LOGDIR = getenv("DDBASE")."/../LOG/"; + if (!is_dir($LOGDIR)) + mkdir($LOGDIR, 0755, true); + + define("log",$LOGDIR."/getData.log"); + define("err",$LOGDIR."/getData.err"); date_default_timezone_set('UTC'); $startStamp = strtotime($Start); $stopStamp = strtotime($Stop); - $start = date( "Ymd\THis\Z", $startStamp); - $stop = date( "Ymd\THis\Z", $stopStamp); + $start = date("Ymd\THis\Z", $startStamp); + $stop = date("Ymd\THis\Z", $stopStamp); - $startIso = date( "Y-m-d\TH:i:s\.000\Z", $startStamp); - $stopIso = date( "Y-m-d\TH:i:s\.000\Z", $stopStamp); + $startIso = date("Y-m-d\TH:i:s\.000\Z", $startStamp); + $stopIso = date("Y-m-d\TH:i:s\.000\Z", $stopStamp); // Get data and convert to nc $center = new $base(); diff --git a/src/DATA/MANAGER/DDBaseMgr.php b/src/DATA/MANAGER/DDBaseMgr.php index a805aa4..4f1a8d7 100644 --- a/src/DATA/MANAGER/DDBaseMgr.php +++ b/src/DATA/MANAGER/DDBaseMgr.php @@ -115,6 +115,27 @@ class DDBaseMgr $this->makeAllInLocation(); } + public function deleteVi($ViId, $baseId) + { + $XPath = new DOMXpath($this->DDsysDoc); + + $dataSet = $XPath->query("//NAME[.='$ViId']"); + + if ($dataSet->item(0)->getAttribute("base") != $baseId) + return; + + $ViToDelete = $dataSet->item(0)->parentNode; + $location = $ViToDelete->getElementsByTagName('LOCATION')->item(0)->nodeValue; + + $ViToDelete->parentNode->removeChild($ViToDelete); + + $this->DDsysDoc->save($this->DDsys); + system("makeDDsys"); + + foreach (glob($location."/*") as $file) unlink($file); + rmdir($location); + } + private function makeAllInLocation() { if (!is_dir($this->location)) @@ -179,12 +200,7 @@ class DDBaseMgr $this->DDsysDoc->save($this->DDsys); system("makeDDsys"); } - - public function deleteVi($ViId, $baseId) - { - - } - + // public function getRemoteLocation($base, $remoteVi) // { // $XPath = new DOMXpath($this->DDsysDoc); diff --git a/src/DATA/MANAGER/RemoveVI.php b/src/DATA/MANAGER/RemoveVI.php new file mode 100644 index 0000000..83bf40b --- /dev/null +++ b/src/DATA/MANAGER/RemoveVI.php @@ -0,0 +1,33 @@ +viExists($ViID, $BaseID)) + $baseMgr->deleteVi($ViID, $BaseID); + else + echo "NO $ViID in DDsys.xml".PHP_EOL; + +?> diff --git a/src/REMOTEDATA/CDAWEB.php b/src/REMOTEDATA/CDAWEB.php index 664aee6..c7dcaf6 100644 --- a/src/REMOTEDATA/CDAWEB.php +++ b/src/REMOTEDATA/CDAWEB.php @@ -8,16 +8,16 @@ class CDAWEB extends RemoteDataCenterClass { private $ch, $res, $dataViewUR; private $obsGroupsIds; - private $spase_res; + private $spase_res, $insXML; private $observatoryGroups, $instrumentTypes; private $CDAWEB = array(), $masterCDF = array(); // https://cdaweb.gsfc.nasa.gov/WS/cdasr/1/dataviews/sp_phys/instrumentTypes -/* private $validInstrumentTypes = [ "Activity%20Indices", "Electric%20Fields%20(space)","Gamma%20and%20X-Rays", + private $validInstrumentTypes = [ "Activity%20Indices", "Electric%20Fields%20(space)","Gamma%20and%20X-Rays", "Magnetic%20Fields%20(space)", "Particles%20(space)", "Plasma%20and%20Solar%20Wind", - "Radio%20and%20Plasma%20Waves%20(space)" ]; */ - private $validInstrumentTypes = [ "Magnetic%20Fields%20(space)" ]; + "Radio%20and%20Plasma%20Waves%20(space)" ]; + // private $validInstrumentTypes = [ "Magnetic%20Fields%20(space)" ]; // not used : $validInstrumentTypes = ["Ephemeris"]; @@ -619,8 +619,6 @@ class CDAWEB extends RemoteDataCenterClass // Create datasets nodes foreach ($dss as $ds){ $dsId = $this->baseID.":".$ds; -// $this->domAmda->save('temp.xml'); -// $this->domAmda->load('temp.xml'); if (!$this->domAmda->getElementById($dsId)){ $this->initDDServerXml($ds,$ins,$obs); $dsNode = $this->createDatasetNode($ds); @@ -636,10 +634,14 @@ class CDAWEB extends RemoteDataCenterClass if (!$insSpaseId ) $insSpaseId = $ins; - $insId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs).":".$this->param2dd($insSpaseId); + $obsSpaseId = $this->getObservatorySpase(); + if (!$obsSpaseId ) + $obsSpaseId = $obs; + + $insId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsSpaseId).":".$this->param2dd($insSpaseId); if (!($insNode = $this->domAmda->getElementById($insId))){ - $insNode = $this->createInstrumentNode($insSpaseId, $obs, $groupId); + $insNode = $this->createInstrumentNode($insSpaseId, $obsSpaseId, $groupId); $insNodes[] = $insNode; } foreach ($dsNodes as $dsNode){ @@ -648,10 +650,11 @@ class CDAWEB extends RemoteDataCenterClass } } // foreach ($inss as $ins => $dss) if ($insNodes){ - $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs); + + $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsSpaseId); if (!($obsNode = $this->domAmda->getElementById($obsId))){ - $obsNode = $this->createObservatoryNode($obs, $groupId); + $obsNode = $this->createObservatoryNode($obsSpaseId, $groupId); $obsNodes[] = $obsNode; } @@ -670,9 +673,21 @@ class CDAWEB extends RemoteDataCenterClass } foreach ($obsNodes as $obsNode){ - $missionNode->appendChild($obsNode); + // observatory == mission + if ($obsNode->getAttribute('name') == $missionNode->getAttribute('name')) { + $insNodes = $obsNode->getElementsByTagName("instrument"); + foreach ($insNodes as $insNode) + $missionNode->appendChild($insNode); + } + else + $missionNode->appendChild($obsNode); } - } + } + // getElemetByID doesn't work on newly created Document + $this->domAmda->save('temp.xml'); + $this->domAmda->load('temp.xml'); + + $this->dataCenter = $this->domAmda->getElementById($this->baseID); } } @@ -686,18 +701,19 @@ class CDAWEB extends RemoteDataCenterClass } protected function getInstrumentSpase(){ - $insXML = new DomDocument("1.0"); + + $this->insXML = new DomDocument("1.0"); if ($this->spase_res){ $instrument = $this->spase_res->getElementsByTagName('InstrumentID'); if ($instrument->length > 0) { + + curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$spaseResolver."id=".$instrument->item(0)->nodeValue); + + $this->insXML->loadXML(curl_exec($this->ch)); + return $this->getIdFromSpase($instrument->item(0)->nodeValue); -// curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$spaseResolver."id=".$instrument->item(0)->nodeValue); -// -// if (!$insXML->loadXML(curl_exec($this->ch))){ -// return null; -// } //InstrumentType //spase://SMWG/Observatory/ACE } @@ -706,6 +722,19 @@ class CDAWEB extends RemoteDataCenterClass return null; } + protected function getObservatorySpase(){ + + if ($this->insXML){ + $observatory = $this->insXML->getElementsByTagName('ObservatoryID'); + + if ($observatory->length > 0) { + return $this->getIdFromSpase($observatory->item(0)->nodeValue); + } + } + + return null; + } + protected function setDataCenterAttributes(){} protected function makeArgumentsList(){} } -- libgit2 0.21.2