From 1b0e06315b034208de6f14c271ab6ac033a9c142 Mon Sep 17 00:00:00 2001 From: Elena.Budnik Date: Thu, 7 Dec 2017 16:57:47 +0100 Subject: [PATCH] unique name for obs --- src/REMOTEDATA/CDAWEB.php | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/src/REMOTEDATA/CDAWEB.php b/src/REMOTEDATA/CDAWEB.php index 607c6d9..786a314 100644 --- a/src/REMOTEDATA/CDAWEB.php +++ b/src/REMOTEDATA/CDAWEB.php @@ -14,10 +14,10 @@ class CDAWEB extends RemoteDataCenterClass 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)", "Radio%20and%20Plasma%20Waves%20(space)" ]; // not used : $validInstrumentTypes = ["Ephemeris"]; @@ -125,7 +125,7 @@ class CDAWEB extends RemoteDataCenterClass $obsIds[$obsId] = $insIds; } - $this->obsGroupsIds[$obsGroupId][$insType] = $obsIds; + $this->obsGroupsIds[$insType][$obsGroupId] = $obsIds; } } @@ -330,7 +330,7 @@ class CDAWEB extends RemoteDataCenterClass $sampling = $this->getDatasetSpaseDescription($dsId); $this->updateDDServerXml("GlobalStart",$startTime); $this->updateDDServerXml("GlobalStop",$endTime); - + // no general description - strange dataset if ($sampling == -1) return null; @@ -339,7 +339,7 @@ class CDAWEB extends RemoteDataCenterClass echo " !!! $dsId $sampling".PHP_EOL; else $this->updateDDServerXml("MinSampling",$sampling); - + $dsNode->setAttribute('spaseUrl',$this->CDAWEB[$dsId]); // $dsNode->setAttribute('masterCdf',$this->existsMasterCdf($dsId)); $dsNode->setAttribute("desc", "$label; $startTime - $endTime"); @@ -462,7 +462,9 @@ class CDAWEB extends RemoteDataCenterClass $rootNode->appendChild($this->DDserverXml->createElement("DataSetID", $ds)); $rootNode->appendChild($this->DDserverXml->createElement("GlobalStart")); $rootNode->appendChild($this->DDserverXml->createElement("GlobalStop")); - $rootNode->appendChild($this->DDserverXml->createElement("MinSampling")); + $rootNode->appendChild($this->DDserverXml->createElement("MinSampling")); + // fill value by default - if different - add into param description + $rootNode->appendChild($this->DDserverXml->createElement("FillValue"), -1.0E31); } protected function updateDDServerXml($target, $value) @@ -607,11 +609,25 @@ class CDAWEB extends RemoteDataCenterClass $dataRoot->appendChild($this->dataCenter); $this->setDataCenterAttributes(); - - foreach ($this->obsGroupsIds as $groupId => $insTypes){ - foreach ($insTypes as $insType => $obss){ + $first = true; + + foreach ($this->obsGroupsIds as $insType => $groupIds){ + // getElementByID doesn't work on newly created Document + if (!$first) { + $this->domAmda->loadXML($this->domAmda->saveXML()); + $this->dataCenter = $this->domAmda->getElementById($this->baseID); + } + foreach ($groupIds as $groupId => $obss){ + $obsNodes = array(); - foreach ($obss as $obs => $inss){ + + foreach ($obss as $obs => $inss) + { + if (substr($obs,0,4) == "OMNI" && substr($groupId,0,4) != "OMNI"){ + echo 'OMNI '.$obs.' '.$missionId.PHP_EOL; + continue; + } + $insNodes = array(); // Create instrument nodes foreach ($inss as $ins => $dss){ @@ -653,8 +669,12 @@ class CDAWEB extends RemoteDataCenterClass $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsSpaseId); - if (!($obsNode = $this->domAmda->getElementById($obsId))){ + if (!($obsNode = $this->domAmda->getElementById($obsId))){ $obsNode = $this->createObservatoryNode($obsSpaseId, $groupId); + +// if (!$first){ +// echo "NEW OBS ".$obsId.PHP_EOL; +// } $obsNodes[] = $obsNode; } @@ -663,31 +683,28 @@ class CDAWEB extends RemoteDataCenterClass } } } // 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){ - // observatory == mission - if ($obsNode->getAttribute('name') == $missionNode->getAttribute('name')) { - $insNodes = $obsNode->getElementsByTagName("instrument"); - foreach ($insNodes as $insNode) - $missionNode->appendChild($insNode); + if ($obsNodes){ + $missionId = $this->baseID.":".$this->param2dd($groupId); + + if (!($missionNode = $this->domAmda->getElementById($missionId))){ + $missionNode = $this->createMissionNode($groupId); + $this->dataCenter->appendChild($missionNode); } - else - $missionNode->appendChild($obsNode); + + foreach ($obsNodes as $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); + } + $first = false; } } -- libgit2 0.21.2