diff --git a/src/CALLEXT/createVI.php b/src/CALLEXT/createVI.php index 198b21c..ce63e6d 100755 --- a/src/CALLEXT/createVI.php +++ b/src/CALLEXT/createVI.php @@ -30,12 +30,15 @@ putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin"); set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT")); - define("verbose", true); + $verbose = true; - define("INFODIR",getenv("DDBASE")."../INFO/"); - define ("log",INFODIR."addVI.log"); - define ("err",INFODIR."addVI.err"); - + $LOGDIR = getenv("DDBASE")."../LOG/"); + if (!is_dir($LOGDIR)) + mkdir($LOGDIR, 0755, true); + + define("log",$LOGDIR."/addVI.log"); + define("err",$LOGDIR."/addVI.err"); + if ($argc != 4) { // error_log("Usage: php createVI.php ".PHP_EOL, 3, err); @@ -60,9 +63,10 @@ if ($status === 0) { $baseMgr->createVi(); -// if (verbose) -// error_log("request to add Data Set ".$base.":".$remSetID." as ".$ViId.PHP_EOL, 3, log); -// + + if ($verbose) + error_log("Request to add Data Set ".$base.":".$remSetID." as ".$ViId.PHP_EOL, 3, log); + $center = new $base(); $startStamp = strtotime($baseMgr->globalStart); @@ -90,9 +94,8 @@ } $baseMgr->addRemoteData($remSetID, $ncFiles, $startIso, $stopIso); - // echo "START-STOP ".$start." ".$stop.PHP_EOL; -// if (verbose) error_log("Get dataset info for ".$remSetID." from ".$dataBaseID." returns ".$res.PHP_EOL, 3, log); +// if ($verbose) error_log("Get dataset info for ".$remSetID." from ".$dataBaseID." returns ".$res.PHP_EOL, 3, log); @@ -106,7 +109,7 @@ } else { - if (verbose) error_log("No DDServer Info File for $base $ViId".PHP_EOL, 3, log); + if ($verbose) error_log("No DDServer Info File for $base $ViId".PHP_EOL, 3, log); } ?> \ No newline at end of file diff --git a/src/DATA/MANAGER/DDBaseMgr.php b/src/DATA/MANAGER/DDBaseMgr.php index 08f29b5..a805aa4 100644 --- a/src/DATA/MANAGER/DDBaseMgr.php +++ b/src/DATA/MANAGER/DDBaseMgr.php @@ -226,8 +226,7 @@ class DDBaseMgr } system("TimesUpdateNoData ".strtolower($id)."_times.nc ".$start." ".$stop); - - echo strtolower($id)."_times.nc ".$start." ".$stop.PHP_EOL; + chdir($WORKING_DIR); $this->unlockVi(); } diff --git a/src/REMOTEDATA/CDAWEB.php b/src/REMOTEDATA/CDAWEB.php index 73ffbc8..664aee6 100644 --- a/src/REMOTEDATA/CDAWEB.php +++ b/src/REMOTEDATA/CDAWEB.php @@ -8,14 +8,17 @@ class CDAWEB extends RemoteDataCenterClass { private $ch, $res, $dataViewUR; private $obsGroupsIds; + private $spase_res; 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)" ]; + "Radio%20and%20Plasma%20Waves%20(space)" ]; */ + private $validInstrumentTypes = [ "Magnetic%20Fields%20(space)" ]; + // not used : $validInstrumentTypes = ["Ephemeris"]; private $excludeIns = ["GIFWALK", "Unknown"], $excludeGroup = ["THEMIS", "ARTEMIS", "NOAA"]; @@ -183,84 +186,80 @@ class CDAWEB extends RemoteDataCenterClass $newNode = false; } - foreach ($insTypes as $insType => $obss) - { + foreach ($insTypes as $insType => $obss){ // echo $insType.PHP_EOL; - foreach ( $obss as $obs => $inss) - { + foreach ( $obss as $obs => $inss){ // echo $obs.PHP_EOL; // OMNI ONLY ONCE - if (substr($obs,0,4) == "OMNI" && substr($missionId,0,4) != "OMNI") - { + if (substr($obs,0,4) == "OMNI" && substr($missionId,0,4) != "OMNI"){ //echo ' '.$obs.' '.$missionId.PHP_EOL; continue; } - $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs); + if (file_exists(RemoteData."/".CDAWebConfigClass::$mapXML)) { + $obsAMDA = $this->alias(RemoteData."/".CDAWebConfigClass::$mapXML, $obs); + } + else { + $obsAMDA = $obs; + } + + $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsAMDA); $obsNodes = $missionNode->getElementsByTagName('observatory'); $newObsNode = true; - foreach ($obsNodes as $node) - { + foreach ($obsNodes as $node){ $id = $node->getAttribute("xml:id"); - if ($id == $obsId) - { + if ($id == $obsId) { $obsNode = $node; $newObsNode = false; break; } } - if ( $newObsNode ) - { + + if ( $newObsNode ){ $obsNode = $this->createObservatoryNode($obs, $groupId); } - foreach ( $inss as $ins => $dss) - { + + foreach ($inss as $ins => $dss){ $insId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs).":".$this->param2dd($ins); $insNodes = $obsNode->getElementsByTagName('instrument'); $newInsNode = true; - foreach ($insNodes as $node) - { + foreach ($insNodes as $node){ $id = $node->getAttribute("xml:id"); - if ($id == $insId) - { + if ($id == $insId) { $insNode = $node; $newInsNode = false; break; } } + if ( $newInsNode ) $insNode = $this->createInstrumentNode($ins, $obs, $groupId); - foreach ($dss as $ds) - { + foreach ($dss as $ds){ $dsId = $this->baseID.":".$ds; $dsNodes = $insNode->getElementsByTagName('dataset'); $newDsNode = true; - foreach ($dsNodes as $node) - { + foreach ($dsNodes as $node){ $id = $node->getAttribute("xml:id"); - if ($id == $dsId) - { + if ($id == $dsId){ $dsNode = $node; $newDsNode = false; break; } } - if ($newDsNode) - { + if ($newDsNode) { $this->initDDServerXml($ds,$ins,$obs); $dsNode = $this->createDatasetNode($ds); - if ($dsNode) - { + if ($dsNode){ $insNode->appendChild($dsNode); $this->saveDDServerXml(); } @@ -271,8 +270,7 @@ class CDAWEB extends RemoteDataCenterClass $obsNode->appendChild($insNode); } - if ($newObsNode && $obsNode->hasChildNodes()) - { + if ($newObsNode && $obsNode->hasChildNodes()){ $missionNode->appendChild($obsNode); } } @@ -290,13 +288,12 @@ class CDAWEB extends RemoteDataCenterClass protected function createObservatoryNode($id, $grpId) { - $insNode = $this->domAmda->createElement('observatory'); + $obsNode = $this->domAmda->createElement('observatory'); - $insNode->setAttribute("xml:id",$this->baseID.":".$this->param2dd($grpId).":".$this->param2dd($id)); - $insNode->setAttribute("name",$id); - // $insNode->setAttribute("description",$ins[1]); + $obsNode->setAttribute("xml:id",$this->baseID.":".$this->param2dd($grpId).":".$this->param2dd($id)); + $obsNode->setAttribute("name",$id); - return $insNode; + return $obsNode; } protected function createInstrumentNode($id, $obsId, $groupId) @@ -343,8 +340,11 @@ class CDAWEB extends RemoteDataCenterClass else $this->updateDDServerXml("MinSampling",$sampling); - $dsNode->setAttribute('spaseUrl',$this->CDAWEB[$dsId]); + $dsNode->setAttribute('spaseUrl',$this->CDAWEB[$dsId]); // $dsNode->setAttribute('masterCdf',$this->existsMasterCdf($dsId)); + $dsNode->setAttribute("desc", "$label; $startTime - $endTime"); + $dsNode->setAttribute("start", $startTime); + $dsNode->setAttribute("stop", $stopTime); $parameterNodes = $this->createParameterNodes($dsId); foreach ( $parameterNodes as $parameterNode) @@ -386,10 +386,11 @@ class CDAWEB extends RemoteDataCenterClass return -1; // no description in SpaseRegistry curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$spaseResolver."id=".$this->CDAWEB[$dsID]); - - $this->res->loadXML(curl_exec($this->ch)); - //TODO errors - $messages = $this->res->getElementsByTagName('Message'); + + if (!$this->spase_res->loadXML(curl_exec($this->ch))) + return -100; + + $messages = $this->spase_res->getElementsByTagName('Message'); if ($messages->length > 0) { @@ -398,12 +399,12 @@ class CDAWEB extends RemoteDataCenterClass return -2; // no description in www-spase } - $instrument = $this->res->getElementsByTagName('InstrumentID'); - echo " instrument ".$instrument->item(0)->nodeValue.PHP_EOL; +// $instrument = $this->spase_res->getElementsByTagName('InstrumentID'); +// echo " instrument ".$instrument->item(0)->nodeValue.PHP_EOL; - $cadence = $this->res->getElementsByTagName('Cadence'); + $cadence = $this->spase_res->getElementsByTagName('Cadence'); - if ( $cadence->length == 0) + if ($cadence->length == 0) return -3; // no cadence in spase xml $sampling = $this->cadence2sampling($cadence->item(0)->nodeValue); @@ -585,6 +586,126 @@ class CDAWEB extends RemoteDataCenterClass return $infoFile; } + + public function makeProxy() + { + $this->spase_res = new DomDocument("1.0"); + $this->domAmda = new DOMDocument('1.0', 'utf-8'); + $this->domAmda->formatOutput = TRUE; + $this->domAmda->preserveWhiteSpace = FALSE; + + $dataRoot = $this->domAmda->createElement('dataRoot'); + $dataRoot->setAttribute('xml:id', 'myRemoteData-treeRootNode'); + $this->domAmda->appendChild($dataRoot); + + $this->dataCenter=$this->domAmda->createElement('dataCenter'); + + $this->dataCenter->setAttribute('xml:id', $this->baseID); + // $this->dataCenter->setIdAttribute('xml:id', true); + $this->dataCenter->setAttribute('name', $this->baseID); + + $dataRoot->appendChild($this->dataCenter); + + $this->setDataCenterAttributes(); + + foreach ($this->obsGroupsIds as $groupId => $insTypes){ + foreach ($insTypes as $insType => $obss){ + $obsNodes = array(); + foreach ($obss as $obs => $inss){ + $insNodes = array(); + // Create instrument nodes + foreach ($inss as $ins => $dss){ + $dsNodes = array(); + // 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); + if ($dsNode){ + $this->saveDDServerXml(); + $dsNodes[] = $dsNode; + } + } + } // foreach ($dss as $ds) + if ($dsNodes){ + // last $spase_res : instrument should be the same + $insSpaseId = $this->getInstrumentSpase(); + if (!$insSpaseId ) + $insSpaseId = $ins; + + $insId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs).":".$this->param2dd($insSpaseId); + + if (!($insNode = $this->domAmda->getElementById($insId))){ + $insNode = $this->createInstrumentNode($insSpaseId, $obs, $groupId); + $insNodes[] = $insNode; + } + foreach ($dsNodes as $dsNode){ + $insNode->appendChild($dsNode); + } + } + } // foreach ($inss as $ins => $dss) + if ($insNodes){ + $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs); + + if (!($obsNode = $this->domAmda->getElementById($obsId))){ + $obsNode = $this->createObservatoryNode($obs, $groupId); + $obsNodes[] = $obsNode; + } + + foreach ($insNodes as $insNode){ + $obsNode->appendChild($insNode); + } + } + } // foreach ($obss as $obs => $inss) + } + if ($obsNodes){ + $missionId = $this->baseID.":".$this->param2dd($groupId); + + if (!($missionNode = $this->domAmda->getElementById($missionId))){ + $missionNode = $this->createMissionNode($groupId); + $this->dataCenter->appendChild($missionNode); + } + + foreach ($obsNodes as $obsNode){ + $missionNode->appendChild($obsNode); + } + } + } + } + + protected function createMissionNode($groupId){ + $missionId = $this->baseID.":".$this->param2dd($groupId); + $missionNode = $this->domAmda->createElement('mission'); + $missionNode->setAttribute("xml:id",$missionId); + $missionNode->setAttribute("name",$groupId); + + return $missionNode; + } + + protected function getInstrumentSpase(){ + $insXML = new DomDocument("1.0"); + + if ($this->spase_res){ + $instrument = $this->spase_res->getElementsByTagName('InstrumentID'); + + if ($instrument->length > 0) { + 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 + } + } + + return null; + } + protected function setDataCenterAttributes(){} protected function makeArgumentsList(){} } diff --git a/src/REMOTEDATA/RemoteDataCenterClass.php b/src/REMOTEDATA/RemoteDataCenterClass.php index 874a81b..b35b821 100644 --- a/src/REMOTEDATA/RemoteDataCenterClass.php +++ b/src/REMOTEDATA/RemoteDataCenterClass.php @@ -28,7 +28,23 @@ abstract class RemoteDataCenterClass function __construct() { $this->baseID = get_class($this); - } + } + + /* Function to change External Bases stuff in case of existing AMDA aliases. + Uses file DICTIONARY_DIR.mapBaseID.xml */ + + protected function alias($Dictionary, $name) { + + $xmldoc = new DomDocument("1.0"); + $xmldoc->load($DictionaryFile); + $item = $xmldoc->getElementById(strtoupper($name)); + + if (!$item) return $name; + $alias = $item->nodeValue; + + return $alias; + } + public function param2dd($paramID) { @@ -94,7 +110,13 @@ abstract class RemoteDataCenterClass foreach ($missionNodes as $missionNode) $this->dataCenter->appendChild($missionNode); } - + + protected function getIdFromSpase($spaseId) + { + $temp = explode('/',$spaseId); + return $temp[count($temp)-1]; + } + public function monitor() { $ch = curl_init($this->url."/".$this->WSDL); -- libgit2 0.21.2