Commit 217c83f2801eb9ffefe506ebc55a3a15d7a54d69

Authored by Elena.Budnik
1 parent 7216c535

correct CDAWEB tree construction

Showing 1 changed file with 214 additions and 241 deletions   Show diff stats
src/REMOTEDATA/CDAWEB.php
... ... @@ -17,12 +17,9 @@ class CDAWEB extends RemoteDataCenterClass
17 17 // https://cdaweb.gsfc.nasa.gov/WS/cdasr/1/dataviews/sp_phys/instrumentTypes
18 18 private $validInstrumentTypes = [ "Activity%20Indices", "Electric%20Fields%20(space)","Gamma%20and%20X-Rays",
19 19 "Magnetic%20Fields%20(space)", "Particles%20(space)", "Plasma%20and%20Solar%20Wind",
20   - "Radio%20and%20Plasma%20Waves%20(space)" ];
21   -// private $validInstrumentTypes = [ "Radio%20and%20Plasma%20Waves%20(space)" ];
22   -
23   -// not used : $validInstrumentTypes = ["Ephemeris"];
24   -
25   - private $excludeIns = ["GIFWALK", "Unknown"], $excludeGroup = ["THEMIS", "ARTEMIS", "NOAA", "GPS", "TSS-1R", "IBEX", "SOHO"];
  20 + "Radio%20and%20Plasma%20Waves%20(space)"]; //, "Ephemeris/Attitude/Ancillary" ];
  21 +
  22 + private $excludeIns = ["GIFWALK", "Unknown"], $excludeGroup = ["THEMIS", "ARTEMIS", "MMS", "Apollo"]; // "NOAA", "GPS", "TSS-1R", "IBEX"];
26 23  
27 24 // not in "https://heliophysicsdata.sci.gsfc.nasa.gov/queries/CDAWeb_SPASE.xql" List;
28 25 // FOR INFO : Excluded automatically
... ... @@ -38,11 +35,20 @@ class CDAWEB extends RemoteDataCenterClass
38 35 return strtr($param,$pairs);
39 36 }
40 37  
  38 + public function html_decode($param)
  39 + {
  40 + $pairs = array("%20" => " ");
  41 +
  42 + return strtr($param,$pairs);
  43 + }
  44 +
41 45 public function init()
42 46 {
43 47 error_log("CDAWEB Proxy creation on ".date("Y-m-d\TH:i:s").PHP_EOL,3,log);
44 48 error_log("CDAWEB Proxy creation on ".date("Y-m-d\TH:i:s").PHP_EOL,3,err);
45   -
  49 +
  50 + error_reporting(ALL);
  51 +
46 52 $this->initStreamContext();
47 53  
48 54 $this->getAllSpaseDatasets();
... ... @@ -110,104 +116,62 @@ class CDAWEB extends RemoteDataCenterClass
110 116 $this->dataViewURL = $this->res->getElementsByTagName('EndpointAddress')->item(0)->nodeValue;
111 117 }
112 118  
113   - // Using CDAS REST APIs get all CDAWEB dataset descriptions
  119 + /**
  120 + * Using CDAS REST APIs get ALL CDAWEB dataset descriptions
  121 + * Create an array obsGroupsIds[$obsGroupId][$obsId][$insId][$dsId]
  122 + */
114 123 protected function getRemoteTree()
115   - {
116   - $this->openConnection();
  124 + {
  125 + $this->openConnection();
117 126  
118 127 $this->setDataViewURL();
119   - $this->obsGroupsIds = array();
120   -
121   - foreach ($this->validInstrumentTypes as $insType)
122   - {
123   - curl_setopt($this->ch, CURLOPT_URL, $this->dataViewURL."/observatoryGroupsAndInstruments?instrumentType=".$insType);
124   - echo $insType.PHP_EOL;
125   - $this->res->loadXML(curl_exec($this->ch));
  128 + $this->obsGroupsIds = array();
  129 +
  130 + curl_setopt($this->ch, CURLOPT_URL, $this->dataViewURL."/datasets");
126 131  
127   - $observatoryGroups = $this->res->getElementsByTagName("ObservatoryGroupInstrumentDescription");
128   -
129   - foreach ($observatoryGroups as $obsGroup)
130   - {
131   - $obsGroupId = $obsGroup->getElementsByTagName('Name')->item(0)->nodeValue;
132   -
133   - // Exclude some Missions
134   - if (in_array ($obsGroupId, $this->excludeGroup )) continue;
135   -
136   - echo " ".$obsGroupId.PHP_EOL;
137   - $observatories = $obsGroup->getElementsByTagName("ObservatoryInstruments");
138   - if ( $observatories->length == 0 )
139   - {
140   - echo ' No observatories '.PHP_EOL;
141   - if ($obsGroup->getElementsByTagName("InstrumentDescription")->length > 0) {
142   - echo ' CHECK INSTRUMENTS '.PHP_EOL;
143   - error_log(" CHECK INSTRUMENTS ".$obsGroup.PHP_EOL, 3, err);
144   - }
145   - continue;
146   - }
147   - $obsIds = array();
148   - foreach ( $observatories as $obs )
149   - {
150   - $obsId = $obs->getElementsByTagName('Name')->item(0)->nodeValue;
151   - echo " ".$obsId.PHP_EOL;
152   -// <InstrumentDescription>
153   -// <Name>MAG</Name>
154   -// <ShortDescription>ACE Magnetic Field Instrument</ShortDescription>
155   -// <LongDescription>ACE Magnetic Field Instrument</LongDescription>
156   -// </InstrumentDescription>
157   - $instruments = $obs->getElementsByTagName("InstrumentDescription");
158   -
159   - $insIds = array();
160   -
161   - foreach ( $instruments as $ins )
162   - {
163   - $insId = $ins->getElementsByTagName('Name')->item(0)->nodeValue;
164   -
165   - // Exclude some 'non-AMDA' staff
166   - if (in_array ($insId, $this->excludeIns )) continue;
167   -
168   - $dsIds = $this->getDatasetByObservatoryAndInstrument($obsGroupId, $obsId, $insId);
169   -
170   - $insIds[$insId] = $dsIds;
171   -
172   - }
173   -
174   - $obsIds[$obsId] = $insIds;
175   - }
176   -
177   - $this->obsGroupsIds[$insType][$obsGroupId] = $obsIds;
178   - }
179   - }
180   - }
181   -
182   - protected function getDatasetByObservatoryAndInstrument($obsGroupId, $obsId, $insId)
183   - {
184   - $grpEncodedId = $this->html_encode($obsGroupId);
185   - $insEncodedId = $this->html_encode($insId);
186   - $obsEncodedId = $this->html_encode($obsId);
187   -
188   - $res = new DomDocument("1.0");
189   - // curl_setopt($this->ch, CURLOPT_URL, $this->dataViewURL."/datasets?observatoryGroup=$grpEncodedId&instrument=$insEncodedId");
190   -
191   - curl_setopt($this->ch, CURLOPT_URL, $this->dataViewURL."/datasets?observatory=$obsEncodedId&instrument=$insEncodedId");
192   -
193   - $res->loadXML(curl_exec($this->ch));
  132 + $this->res->loadXML(curl_exec($this->ch));
  133 + // $this->res->save("datasets.xml");
  134 + // $this->res->load("datasets.xml");
  135 + $datasets = $this->res->getElementsByTagName("DatasetDescription");
  136 +
  137 + echo "All CDAWeb datasets : ".$datasets->length.PHP_EOL;
194 138  
195   - $datasets = $res->getElementsByTagName('DatasetDescription');
196   - $dsIds = array();
197   -
198   - foreach ( $datasets as $ds)
199   - {
200   - // $obs = $ds->getElementsByTagName('Observatory')->item(0)->nodeValue;
201   - // if ($obs != $obsId ) continue;
202   - $dsIds[] = $ds->getElementsByTagName('Id')->item(0)->nodeValue;
203   - }
204   -
205   - return $dsIds;
  139 + foreach ($datasets as $ds) {
  140 +
  141 + $insType = $ds->getElementsByTagName("InstrumentType")->item(0)->nodeValue;
  142 +
  143 + if (in_array ($this->html_encode($insType), $this->validInstrumentTypes )) {
  144 +
  145 + $id = $ds->getElementsByTagName("Id")->item(0)->nodeValue;
  146 +
  147 + $insId = $ds->getElementsByTagName("Instrument")->item(0)->nodeValue;
  148 + if (! in_array ($insId, $this->excludeIns )) {
  149 + $obsId = "UNKNOWN";
  150 + if ($ds->getElementsByTagName("Observatory")->length > 0)
  151 + $obsId = $ds->getElementsByTagName("Observatory")->item(0)->nodeValue;
  152 +
  153 + $obsGroupId = "UNKNOWN";
  154 + if ($ds->getElementsByTagName("ObservatoryGroup")->length > 0)
  155 + $obsGroupId = $ds->getElementsByTagName("ObservatoryGroup")->item(0)->nodeValue;
  156 +
  157 + if ($obsId == "UNKNOWN") {
  158 + $obsId = $obsGroupId;
  159 + }
  160 +
  161 + if ( $obsGroupId == "UNKNOWN" ) {
  162 + $obsGroupId = $obsId;
  163 + }
  164 +
  165 + if ( $obsGroupId != "UNKNOWN" ) {
  166 + $this->obsGroupsIds[$obsGroupId][$obsId][$insId][] = $id;
  167 + }
  168 + }
  169 + }
  170 + }
206 171 }
207   -
208   - protected function createObservatoryNode($id, $grpId)
209   - {
210   -
  172 +
  173 + protected function createObservatoryNode($id, $grpId)
  174 + {
211 175 $obsNode = $this->domAmda->createElement('observatory');
212 176  
213 177 $obsNode->setAttribute("xml:id",$this->baseID.":".$this->param2dd($grpId).":".$this->param2dd($id));
... ... @@ -216,9 +180,8 @@ class CDAWEB extends RemoteDataCenterClass
216 180 return $obsNode;
217 181 }
218 182  
219   - protected function createInstrumentNode($id, $obsId, $groupId)
220   - {
221   -
  183 + protected function createInstrumentNode($id, $obsId, $groupId)
  184 + {
222 185 $insNode = $this->domAmda->createElement('instrument');
223 186  
224 187 $insNode->setAttribute("xml:id",$this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsId).":".$id);
... ... @@ -230,6 +193,9 @@ class CDAWEB extends RemoteDataCenterClass
230 193  
231 194 protected function createDatasetNode($dsId)
232 195 {
  196 + if ( !array_key_exists($dsId, $this->CDAWEB ))
  197 + return null; // no description in SpaseRegistry => we do not add this dataset
  198 +
233 199 $dsNode = $this->domAmda->createElement('dataset');
234 200  
235 201 curl_setopt($this->ch, CURLOPT_HTTPHEADER, array("Accept: application/json"));
... ... @@ -251,15 +217,11 @@ class CDAWEB extends RemoteDataCenterClass
251 217 $this->updateDDServerXml("GlobalStart",$startTime);
252 218 $this->updateDDServerXml("GlobalStop",$endTime);
253 219  
254   - // no general description - strange dataset
255   - if ($sampling == -1) {
256   - error_log("! No general description : ".$dsId.PHP_EOL,3,err);
257   - return null;
258   - }
259   -
  220 + // no SPASE description
  221 + if ($sampling == -1) return null;
  222 +
260 223 if ($sampling <= 0) {
261 224 // check if there is file with predefined samplings
262   - echo " !!! $dsId sampling = $sampling".PHP_EOL;
263 225 if ($this->xp) {
264 226 $set = $this->xp->query("//dataset[@xml:id='".$dsId."']");
265 227 if ($set->length > 0) {
... ... @@ -267,7 +229,7 @@ class CDAWEB extends RemoteDataCenterClass
267 229 echo "from samplingCDAWEB : ".$dsId." : ".$sampling.PHP_EOL;
268 230 $this->updateDDServerXml("MinSampling",$sampling);
269 231 } else {
270   - echo " No dataset in samplingCDAWEB defined".PHP_EOL;
  232 + echo " No sampling : ".$dsId.PHP_EOL;
271 233 error_log("! No sampling and No dataset in samplingCDAWEB defined : ".$dsId." : ".$sampling.PHP_EOL,3,err);
272 234 }
273 235 } else {
... ... @@ -286,7 +248,7 @@ class CDAWEB extends RemoteDataCenterClass
286 248 $dsNode->setAttribute("dataStop", $endTime);
287 249  
288 250 $parameterNodes = $this->createParameterNodes($dsId);
289   - foreach ( $parameterNodes as $parameterNode)
  251 + foreach ($parameterNodes as $parameterNode)
290 252 {
291 253 $dsNode->appendChild($parameterNode);
292 254 }
... ... @@ -303,7 +265,7 @@ class CDAWEB extends RemoteDataCenterClass
303 265 $parameters = $obj->VariableDescription;
304 266  
305 267 $paramNodes = array();
306   -
  268 +
307 269 foreach ($parameters as $param)
308 270 {
309 271 $paramNode = $this->domAmda->createElement('parameter');
... ... @@ -317,29 +279,27 @@ class CDAWEB extends RemoteDataCenterClass
317 279 }
318 280  
319 281 protected function getDatasetSpaseDescription($dsID)
320   - {
321   - // $this->openConnection();
  282 + {
322 283 curl_setopt($this->ch, CURLOPT_HTTPHEADER, array("Accept: application/xml"));
323   -
  284 +
324 285 if ( !array_key_exists($dsID, $this->CDAWEB ))
325 286 return -1; // no description in SpaseRegistry
326 287  
327 288 curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$spaseResolver."id=".$this->CDAWEB[$dsID]);
328 289  
329   - if (!$this->spase_res->loadXML(curl_exec($this->ch)))
330   - return -100;
  290 + if (!$this->spase_res->loadXML(curl_exec($this->ch))) return -100;
331 291  
332 292 $messages = $this->spase_res->getElementsByTagName('Message');
333 293  
334 294 if ($messages->length > 0)
335 295 {
336   - foreach ($messages as $message)
337   - echo $message->nodeValue.PHP_EOL;
  296 + // foreach ($messages as $message)
  297 + // echo $message->nodeValue.PHP_EOL;
338 298 return -2; // no description in www-spase
339 299 }
340 300  
341   -// $instrument = $this->spase_res->getElementsByTagName('InstrumentID');
342   -// echo " instrument ".$instrument->item(0)->nodeValue.PHP_EOL;
  301 +// $instrument = $this->spase_res->getElementsByTagName('InstrumentID');
  302 +// echo " SPASE : instrument ".$instrument->item(0)->nodeValue.PHP_EOL;
343 303  
344 304 $cadence = $this->spase_res->getElementsByTagName('Cadence');
345 305  
... ... @@ -354,17 +314,17 @@ class CDAWEB extends RemoteDataCenterClass
354 314 public function cadence2sampling($cadence)
355 315 {
356 316 $scale = array('S' => 1, 'M' => 60, 'H' => '3600');
357   -
358 317 $value = substr($cadence,2,strlen($cadence)-3);
359   -
360 318 $units = substr($cadence,-1);
361   -
362 319 $sampling = floatval($value)*$scale[$units];
363 320  
364 321 return $sampling;
365 322 }
366 323  
367   - // Get IDs and SPASE URLs of all CDAWEB SPASE-defined datasets
  324 + /**
  325 + * Get IDs and SPASE URLs of all CDAWEB SPASE-defined datasets ( SPASEql )
  326 + * Create an array $CDAWEB[$ID] = SpaseID
  327 + */
368 328 protected function getAllSpaseDatasets()
369 329 {
370 330 require_once "simple_html_dom.php";
... ... @@ -381,14 +341,15 @@ class CDAWEB extends RemoteDataCenterClass
381 341  
382 342 foreach ($ids as $id)
383 343 {
384   -
385   - if ($id->next_sibling()) {
386   - $ref = $id->next_sibling()->find('a');
387   - $key = $id->find('a');
388   - $this->CDAWEB[$key[0]->innertext] = $ref[0]->innertext;
389   - }
390   -
  344 + if ($id->next_sibling()) {
  345 + $ref = $id->next_sibling()->find('a');
  346 + $key = $id->find('a');
  347 + if (strlen($ref[0]->innertext) > 25)
  348 + $this->CDAWEB[$key[0]->innertext] = $ref[0]->innertext; // if SPASE description exists
  349 +
  350 + }
391 351 }
  352 +
392 353 error_log("SPASE-defined CDAWEB datasets from ".CDAWebConfigClass::$spaseRegistry." : ".count($this->CDAWEB).PHP_EOL,3,log);
393 354 echo "SPASE-defined CDAWEB datasets : ".count($this->CDAWEB).PHP_EOL;
394 355 }
... ... @@ -542,7 +503,7 @@ class CDAWEB extends RemoteDataCenterClass
542 503 }
543 504  
544 505 public function makeProxy()
545   - {
  506 + {
546 507 $this->spase_res = new DomDocument("1.0");
547 508 $this->domAmda = new DOMDocument('1.0', 'utf-8');
548 509 $this->domAmda->formatOutput = TRUE;
... ... @@ -556,108 +517,106 @@ class CDAWEB extends RemoteDataCenterClass
556 517 $this->setDataCenterAttributes();
557 518  
558 519 $dataRoot->appendChild($this->dataCenter);
559   -
560   - $first = true;
561   -
562   - foreach ($this->obsGroupsIds as $insType => $groupIds)
563   - {
564   - // getElementByID doesn't work on newly created Document
565   - if (!$first) {
566   - $this->domAmda->loadXML($this->domAmda->saveXML());
567   - $this->dataCenter = $this->domAmda->getElementById($this->baseID);
568   - }
569   -
570   - foreach ($groupIds as $groupId => $obss)
571   - {
572   - $obsNodes = array();
573   -
574   - foreach ($obss as $obs => $inss)
575   - {
576   - // ! observatory OMNI is taken for observatoriesGroup OMNI only !
577   - if (substr($obs,0,4) == "OMNI" && substr($groupId,0,4) != "OMNI"){
578   - echo 'OMNI '.$obs.' '.$missionId.PHP_EOL;
579   - continue;
580   - }
581   - $insNodes = array();
582   - // Create instrument nodes
583   - foreach ($inss as $ins => $dss)
584   - {
585   - $dsNodes = array();
586   - // Create datasets nodes
587   - foreach ($dss as $ds)
588   - {
589   - $dsId = $this->baseID.":".$ds;
590   - if (!$this->domAmda->getElementById($dsId)){
591   - $this->initDDServerXml($ds,$ins,$obs);
592   - $dsNode = $this->createDatasetNode($ds);
593   - if ($dsNode){
594   - $this->saveDDServerXml();
595   - $dsNodes[] = $dsNode;
596   - }
597   - }
598   - } // foreach ($dss as $ds)
599   - if ($dsNodes)
600   - {
601   - // last $spase_res : instrument should be the same
602   - $insSpaseId = $this->getInstrumentSpase();
603   - if (!$insSpaseId )
604   - $insSpaseId = $ins;
605   -
606   - $obsSpaseId = strtolower($this->getObservatorySpase());
607   - if (!$obsSpaseId )
608   - $obsSpaseId = strtolower($obs);
609   -
610   - $insId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsSpaseId).":".$this->param2dd($insSpaseId);
611   -
612   - if (!($insNode = $this->domAmda->getElementById($insId))){
613   - $insNode = $this->createInstrumentNode($insSpaseId, $obsSpaseId, $groupId);
614   - }
615   - foreach ($dsNodes as $dsNode){
616   - $insNode->appendChild($dsNode);
617   - }
618   - $insNodes[] = $insNode;
619   - }
620   - } // foreach ($inss as $ins => $dss)
621   - if ($insNodes)
622   - {
623   - $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsSpaseId);
624   -
625   - if (!($obsNode = $this->domAmda->getElementById($obsId))){
626   - $obsNode = $this->createObservatoryNode($obsSpaseId, $groupId);
627   - }
628   -
629   - foreach ($insNodes as $insNode){
630   - $obsNode->appendChild($insNode);
631   - }
632   -
633   - $obsNodes[] = $obsNode;
634   - }
635   - } // foreach ($obss as $obs => $inss)
636   -
637   - if ($obsNodes)
638   - {
639   - $missionId = $this->baseID.":".$this->param2dd($groupId);
640   -
641   - if (!($missionNode = $this->domAmda->getElementById($missionId))){
642   - $missionNode = $this->createMissionNode($groupId);
643   - $this->dataCenter->appendChild($missionNode);
644   - }
645   -
646   - foreach ($obsNodes as $obsNode)
647   - {
648   - // observatory == mission
649   - if (strtolower($obsNode->getAttribute('name')) == strtolower($missionNode->getAttribute('name'))) {
650   - $insNodes = $obsNode->getElementsByTagName("instrument");
651   - foreach ($insNodes as $insNode)
652   - $missionNode->appendChild($insNode);
653   - }
654   - else
655   - $missionNode->appendChild($obsNode);
656   - }
657   - }
658   - }
659   - $first = false;
660   - }
  520 +
  521 + foreach ($this->obsGroupsIds as $groupId => $obss)
  522 + {
  523 + if (in_array($groupId, $this->excludeGroup)) continue;
  524 + echo $groupId.PHP_EOL;
  525 + $obsNodes = array();
  526 + foreach ($obss as $obs => $inss)
  527 + {
  528 + // ! observatory OMNI is taken for observatoriesGroup OMNI only !
  529 + if (substr($obs,0,4) == "OMNI" && substr($groupId,0,4) != "OMNI"){
  530 + echo 'OMNI '.$obs.' '.$missionId.PHP_EOL;
  531 + continue;
  532 + }
  533 + $insNodes = array();
  534 + // Create instrument nodes
  535 + foreach ($inss as $ins => $dss)
  536 + {
  537 + $dsNodes = array();
  538 + // Create datasets nodes
  539 + foreach ($dss as $ds)
  540 + {
  541 + $dsId = $this->baseID.":".$ds;
  542 +
  543 + if (!$this->domAmda->getElementById($dsId)){
  544 + $this->initDDServerXml($ds,$ins,$obs);
  545 + $dsNode = $this->createDatasetNode($ds);
  546 +
  547 + if ($dsNode){
  548 + $this->saveDDServerXml();
  549 + $dsNodes[] = $dsNode;
  550 + }
  551 + }
  552 + } // foreach ($dss as $ds)
  553 +
  554 + if (!empty($dsNodes))
  555 + {
  556 + // last $spase_res : instrument should be the same
  557 + $insSpaseId = $this->getInstrumentSpase();
  558 +
  559 + if (!$insSpaseId || is_array($insSpaseId))
  560 + $insSpaseId = $ins;
  561 +
  562 + $obsSpaseId = strtolower($this->getObservatorySpase());
  563 + if (!$obsSpaseId )
  564 + $obsSpaseId = strtolower($obs);
  565 +
  566 + $insId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsSpaseId).":".$this->param2dd($insSpaseId);
  567 +
  568 + if (!($insNode = $this->domAmda->getElementById($insId))){
  569 + $insNode = $this->createInstrumentNode($insSpaseId, $obsSpaseId, $groupId);
  570 + }
  571 +
  572 + foreach ($dsNodes as $dsNode){
  573 + $insNode->appendChild($dsNode);
  574 + }
  575 +
  576 + $insNodes[] = $insNode;
  577 + }
  578 + } // foreach ($inss as $ins => $dss)
  579 +
  580 + if (!empty($insNodes))
  581 + {
  582 + $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsSpaseId);
  583 +
  584 + if (!($obsNode = $this->domAmda->getElementById($obsId))){
  585 + $obsNode = $this->createObservatoryNode($obsSpaseId, $groupId);
  586 + }
  587 +
  588 + foreach ($insNodes as $insNode){
  589 + $obsNode->appendChild($insNode);
  590 + }
  591 + $obsNodes[] = $obsNode;
  592 + }
  593 + } // foreach ($obss as $obs => $inss)
  594 +
  595 + if (!empty($obsNodes))
  596 + {
  597 + $missionId = $this->baseID.":".$this->param2dd($groupId);
  598 +
  599 + if (!($missionNode = $this->domAmda->getElementById($missionId))){
  600 + $missionNode = $this->createMissionNode($groupId);
  601 + }
  602 +
  603 + foreach ($obsNodes as $obsNode)
  604 + {
  605 + // observatory == mission
  606 + if (strtolower($obsNode->getAttribute('name')) == strtolower($missionNode->getAttribute('name'))) {
  607 + $insNodes = $obsNode->getElementsByTagName("instrument");
  608 + foreach ($insNodes as $insNode) {
  609 + $missionNode->appendChild($insNode->cloneNode(true));
  610 + }
  611 + }
  612 + else
  613 + $missionNode->appendChild($obsNode);
  614 + }
  615 +
  616 + $this->dataCenter->appendChild($missionNode);
  617 + }
  618 + }
  619 +
661 620  
662 621 $this->closeConnection();
663 622 }
... ... @@ -680,12 +639,26 @@ class CDAWEB extends RemoteDataCenterClass
680 639 $instrument = $this->spase_res->getElementsByTagName('InstrumentID');
681 640  
682 641 if ($instrument->length > 0) {
683   -
684   - curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$spaseResolver."id=".$instrument->item(0)->nodeValue);
685   -
686   - $this->insXML->loadXML(curl_exec($this->ch));
687   -
688   - return $this->getIdFromSpase($instrument->item(0)->nodeValue);
  642 + if ($instrument->length == 1) {
  643 + curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$spaseResolver."id=".$instrument->item(0)->nodeValue);
  644 + $this->insXML->loadXML(curl_exec($this->ch));
  645 +
  646 + return $this->getIdFromSpase($instrument->item(0)->nodeValue);
  647 + }
  648 + else {
  649 + // $insIds = "";
  650 + $insIds = array();
  651 + for ($i = 0; $i < $instrument->length; $i++ ) {
  652 +// $insIds .= $this->getIdFromSpase($instrument->item($i)->nodeValue);
  653 +// if ($i < $instrument->length - 1)
  654 +// $insIds .= "/";
  655 + $insIds[] = $this->getIdFromSpase($instrument->item($i)->nodeValue);
  656 + }
  657 +
  658 + curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$spaseResolver."id=".$instrument->item($i)->nodeValue);
  659 + $this->insXML->loadXML(curl_exec($this->ch));
  660 + return $insIds;
  661 + }
689 662 //InstrumentType
690 663 //spase://SMWG/Observatory/ACE
691 664 }
... ...