Commit bf74fc2dafbc9dbd816fff061bb2bb5fe0f432b3

Authored by Elena.Budnik
1 parent 3e80c968

IMPEX

js/app/models/InteractiveNode.js
... ... @@ -483,7 +483,7 @@ Ext.define('amdaModel.InteractiveNode', {
483 483 // edit newNode into Plot Module with node as contextNode
484 484 newNode.editInModule();
485 485 if(node.get('globalStart') != 'depending on mission' && ( node.get('nodeType') == 'localParam' ||
486   - node.get('nodeType') == 'myDataParam')) {
  486 + node.get('nodeType') == 'myDataParam' || node.get('nodeType') == 'remoteSimuParam')) {
487 487 module.getUiContent().setTimeFromData(node.getTimeFromNode(node));
488 488 }
489 489 }
... ... @@ -506,8 +506,8 @@ Ext.define('amdaModel.InteractiveNode', {
506 506 amdaModel.DownloadNode.set('object',request);
507 507 // singleton!
508 508 amdaModel.DownloadNode.editInModule();
509   - if(node.get('globalStart') != 'depending on mission' && ( node.get('nodeType') == 'localParam' ||
510   - node.get('nodeType') == 'myDataParam')) {
  509 + if (node.get('globalStart') != 'depending on mission' && ( node.get('nodeType') == 'localParam' ||
  510 + node.get('nodeType') == 'myDataParam' || node.get('nodeType') == 'remoteSimuParam')) {
511 511 module.getUiContent().setTimeFromData(node.getTimeFromNode(node));
512 512 }
513 513 }
... ...
js/app/models/RemoteSimuParamNode.js
... ... @@ -86,7 +86,15 @@ Ext.define('amdaModel.RemoteSimuParamNode', {
86 86 fnId : 'leaf-downParam',
87 87 text : 'Download Parameter',
88 88 hidden : true
89   - }
  89 + }, {
  90 + fnId : 'para-plotParam',
  91 + text : 'Plot Parameter',
  92 + hidden : true
  93 + }, {
  94 + fnId : 'para-downParam',
  95 + text : 'Download Parameter',
  96 + hidden : true
  97 + }
90 98 ];
91 99  
92 100 return menuItems;
... ...
php/AmdaUpdate.php
... ... @@ -57,20 +57,14 @@
57 57 $ok = $amda->updateStartStop($locBases);
58 58  
59 59 /*
60   - * Create EPNResource files
61   - */
62   - $epnMgr = new EPNResourcesManager($amda);
63   - $epnMgr->createResources();
64   - }
65   -/*
66 60 * Create/update Orbites.xml file
67 61 */
68   - if (!$updateOnly) {
69   - $postProcessing = new PostProcessing();
70   - $postProcessing->createOrbites();
71   - $postProcessing->createOrbites(LocalDataParam.'InternalParams.xml');
72   - $postProcessing->createOrbitesInfoFiles($locBases);
73   - }
  62 +// if (!$updateOnly) {
  63 +// $postProcessing = new PostProcessing();
  64 +// $postProcessing->createOrbites();
  65 +// $postProcessing->createOrbites(LocalDataParam.'InternalParams.xml');
  66 +// $postProcessing->createOrbitesInfoFiles($locBases);
  67 +// }
74 68  
75 69 /*
76 70 * Get available external bases if exist
... ...
php/RemoteDataCenter/FMI_GUMICS.php 0 โ†’ 100644
... ... @@ -0,0 +1,45 @@
  1 +<?php
  2 +/**
  3 + * @class FMI_GUMICS
  4 + * @brief
  5 + * @details
  6 + */
  7 +class FMI_GUMICS extends SimulationDataCenterClass
  8 +{
  9 + protected $url = "http://impex-fp7.fmi.fi/ws";
  10 + protected $treeXML = "Tree_FMI_GUMICS.xml";
  11 + protected $WSDL = "Methods_FMI.wsdl";
  12 +
  13 + protected $templateFile = "FMI_GUMICS_Templates.xml";
  14 + protected $needsArgs = true;
  15 +
  16 + public $soapMethod = "getDataPointValue";
  17 + // OutputFormat netCDF, VOTable, ASCII
  18 + public $outputFormat = "VOTable";
  19 +
  20 + protected function createSimulationRegionNodes($id)
  21 + {
  22 + $simulationRegionNodes = array();
  23 + $simReg = "Earth.Magnetosphere";
  24 +
  25 + $simuRegion = $this->domAmda->createElement('simulationRegion');
  26 + $simuRegion->setAttribute('xml:id', $this->param2dd("FMI_GUMICS_$simReg"));
  27 + $simuRegion->setAttribute('name', $simReg);
  28 + $simuRegion->setAttribute('isAddable', true);
  29 + $simuRegion->setAttribute('rank', "5");
  30 + $simuRegion->setAttribute('att', "simu/simu$simReg");
  31 +
  32 + $this->addSimulatedRegionToTargetsFile($simReg, "GSE");
  33 +
  34 + $simulationRegionNodes[] = $simuRegion;
  35 +
  36 + return $simulationRegionNodes;
  37 + }
  38 +
  39 + protected function setModelHelp($node, $helpFile)
  40 + {
  41 + $node->setAttribute('att', 'simu/Gumics');
  42 + }
  43 +}
  44 +?>
  45 +
0 46 \ No newline at end of file
... ...
php/RemoteDataCenter/FMI_HYBRID.php 0 โ†’ 100644
... ... @@ -0,0 +1,67 @@
  1 +<?php
  2 +/**
  3 + * @class FMI_HYBRID
  4 + * @brief
  5 + * @details
  6 + */
  7 +class FMI_HYBRID extends SimulationDataCenterClass
  8 +{
  9 + protected $url = "http://impex-fp7.fmi.fi/ws";
  10 + protected $treeXML = "Tree_FMI_HYB.xml";
  11 + protected $WSDL = "Methods_FMI.wsdl";
  12 +
  13 + protected $needsArgs = true;
  14 + protected $templateFile = "FMI_HYBRID_Templates.xml";
  15 + public $interpolationMethod = array('Linear', 'NearestGridPoint');
  16 +
  17 + public $soapMethod = "getDataPointValue";
  18 + public $soapMethodSpectra = "getDataPointSpectra";
  19 +
  20 + public $energyTableName = "EnergyRange", $tableTitle="Energy";
  21 +
  22 + //<xs:element minOccurs="0" maxOccurs="1" ref="EnergyChannel"/>
  23 +
  24 + // OutputFormat netCDF, VOTable, ASCII
  25 + public $outputFormat = "VOTable";
  26 +
  27 + protected function getDatasetName($no)
  28 + {
  29 + $name = explode("/",trim($no->ResourceID));
  30 + return end($name);
  31 + }
  32 +
  33 +
  34 + protected function setSimulationRunNodeDescription($runNode,$sr)
  35 + {
  36 + $coords = $this->getCoordinateSystem($sr->SimulationDomain->CoordinateSystem);
  37 + $domain = $this->getRegionBoundaries($sr->SimulationDomain,$sr->RegionParameter);
  38 + $properties = $this->getProperties($sr);
  39 +
  40 + $runNode->setAttribute('desc', $coords.$domain.$properties);
  41 + }
  42 +
  43 + protected function getProperties($sr)
  44 + {
  45 +
  46 +
  47 + }
  48 +
  49 + protected function createSpecialArgs($dom)
  50 + {
  51 + $node = $dom->createElement('argument');
  52 + $node->setAttribute('key', 'InterpolationMethod');
  53 + $node->setAttribute('name', 'Interpolation Method');
  54 + $node->setAttribute('type', 'list');
  55 + $node->setAttribute('default', $this->interpolationMethod[0]);
  56 + for ($i = 0; $i < 2; $i++)
  57 + {
  58 + $item = $dom->createElement('item');
  59 + $item->setAttribute('key', $this->interpolationMethod[$i]);
  60 + $item->setAttribute('name', $this->interpolationMethod[$i]);
  61 + $node->appendChild($item);
  62 + }
  63 + return array($node);
  64 + }
  65 +
  66 +}
  67 +?>
... ...
php/RemoteDataCenter/IPIM.php 0 โ†’ 100644
... ... @@ -0,0 +1,166 @@
  1 +<?php
  2 +/**
  3 + * @class IPIM
  4 + * @brief
  5 + * @details
  6 + */
  7 +class IPIM extends SimulationDataCenterClass
  8 +{
  9 + protected $url = "http://transplanet.irap.omp.eu";
  10 + protected $treeXML = "impex.xml";
  11 +
  12 + public $alongOrbit = false;
  13 +
  14 + protected $hasAccessUrl = true;
  15 +
  16 + public $outputFormat = 'CDF';
  17 + // altitude curvilinear_abscissa surface volume
  18 + public $energyTableName = "curvilinear_abscissa";
  19 + protected $energyTableWidth = 200;
  20 +
  21 +
  22 + protected function addSimulatedRegionToTargetsFile($reg=null,$reg=null){}
  23 +
  24 + protected function getDatasetName($no)
  25 + {
  26 + $name = explode("/",trim($no->ResourceID));
  27 + return end($name);
  28 + }
  29 +
  30 + protected function setHelpAttribute($node, $helpFile)
  31 + {
  32 + $node->setAttribute('att', "");
  33 + }
  34 +
  35 + protected function setSimulationRunNodeDescription($runNode,$sr)
  36 + {
  37 + $coords = $this->getCoordinateSystem($sr->SimulationDomain->CoordinateSystem);
  38 + $domain = $this->getRegionBoundaries($sr->SimulationDomain, null);
  39 + $properties = $this->getProperties($sr);
  40 +
  41 + $runNode->setAttribute('desc', $coords.$domain.$properties);
  42 + }
  43 +
  44 + protected function getAccessUrl($no)
  45 + {
  46 + $url = $no->AccessInformation->AccessURL->URL;
  47 + $resourceID = $no->ResourceID;
  48 +
  49 + if ($url == '')
  50 + {
  51 + foreach ($this->tree->Granule as $granule)
  52 + {
  53 + $granuleID = $granule->ParentID;
  54 +
  55 + if ("$granuleID" == "$resourceID")
  56 + {
  57 + $url = $granule->Source->URL;
  58 + break;
  59 + }
  60 + }
  61 + }
  62 +
  63 + return $url;
  64 + }
  65 +
  66 + protected function getStartTime($no)
  67 + {
  68 + $start = $no->TemporalDescription->TimeSpan->StartDate;
  69 + $stpos = strpos($start, '+');
  70 + if ($stpos > 0)
  71 + $start = substr($start,0,$stpos);
  72 +
  73 + return $start."Z";
  74 + }
  75 +
  76 + protected function getStopTime($no)
  77 + {
  78 + $stop = $no->TemporalDescription->TimeSpan->StopDate;
  79 + $stpos = strpos($stop, '+');
  80 + if ($stpos > 0)
  81 + $stop = substr($stop,0,$stpos);
  82 +
  83 + return $stop."Z";
  84 + }
  85 +
  86 + protected function getProperties($sr)
  87 + {
  88 + $descInternal = "<b><br/>Internal Magnetic Field : </b> : ";
  89 + $inputFields = $sr->InputField;
  90 +
  91 + foreach ($inputFields as $field)
  92 + {
  93 + $descInternal .= $field->Name."<br/>";
  94 + }
  95 + $descInternal .= "<b>Input Neutrals : </b>";
  96 + $inputPopulations = $sr->InputPopulation;
  97 + foreach ($inputPopulations as $population)
  98 + {
  99 + $descInternal .= $population->Name.";";
  100 + }
  101 + return $descInternal;
  102 + }
  103 +
  104 + protected function getRegionBoundaries($domain, $region = null)
  105 + {
  106 + $desc = "<b><br/>Domain: </b><br/>";
  107 +
  108 + $spatialDimension = $domain->SpatialDimension;
  109 +
  110 + $ValidMinsDom = preg_split ("/\s+/", $domain->ValidMin);
  111 + $ValidMaxsDom = preg_split ("/\s+/", $domain->ValidMax);
  112 + $unitsDomain = preg_split ("/\s+/", $domain->Units);
  113 + $coordLabel = preg_split ("/\s+/",$domain->CoordinatesLabel);
  114 +
  115 + for($j=0; $j< $spatialDimension; $j++)
  116 + {
  117 + $desc .= $coordLabel[$j]." : [ ".$ValidMinsDom[$j].", ".$ValidMaxsDom[$j]."] ".$unitsDomain[$j]."<br/>";
  118 + }
  119 + return $desc;
  120 + }
  121 +
  122 + public function getFileName($resourceID, $templateArgs = null, $start = null)
  123 + {
  124 + $strpos = strrpos($resourceID, "/");
  125 +
  126 + if ($strpos > 0)
  127 + $fileName = substr(strtr($resourceID, $this->impex_pairs),0,$strpos);
  128 +
  129 + $fileName .= ".cdf";
  130 +
  131 + return $fileName;
  132 + }
  133 +
  134 + public function getMask($resourceID, $templateArgs = null)
  135 + {
  136 + return $this->getFileName($resourceID);
  137 + }
  138 +
  139 + public function getData($params)
  140 + {
  141 +// $r = print_r($params,true);
  142 + // error_log($params['accessUrl'],3,'/home/budnik/LOG');
  143 +
  144 + return $params['accessUrl'];
  145 + }
  146 +
  147 + public function getTableDefinition($viID = null)
  148 + {
  149 + $res = array();
  150 + if ($viID)
  151 + {
  152 + // amdaParam (like EISCAT)
  153 + }
  154 + else
  155 + {
  156 + $res["tableDefType"] = "SELECT";
  157 + $res["channelsDefType"] = "CENTER";
  158 + $res["data"] = array();
  159 + $res["data"]["center"] = $this->energyTableName;
  160 + $res["data"]["width"] = $this->energyTableWidth;
  161 + }
  162 +
  163 + return $res;
  164 + }
  165 +}
  166 +?>
... ...
php/RemoteDataCenter/ImpexParamManager.php 0 โ†’ 100644
... ... @@ -0,0 +1,567 @@
  1 +<?php
  2 +/**
  3 +* @class ImpexParamManager.php
  4 +* @brief Simations parameters Manager (Simulations db client)
  5 +*
  6 +*/
  7 +
  8 +class ImpexParamManager
  9 +{
  10 + // input parameters
  11 + protected $extraParam, $sampling;
  12 + protected $dataProducer, $argStartTime, $argStopTime;
  13 + protected $parameterID, $resourceID, $parameterKey, $parameterSize;
  14 + protected $vectorList = null, $isSpectra = false;
  15 +
  16 + protected $orbitTempFolder = null;
  17 + protected $center = null;
  18 +
  19 + protected $requestManager = null;
  20 + protected $baseManager = null;
  21 + protected $votManager = null;
  22 + protected $impex_pairs = array("/" => "_", ":" => "_");
  23 +
  24 + public $startTime, $stopTime;
  25 +
  26 + private $impexParamInfo = null;
  27 +
  28 + //TODO
  29 + private $scale = array("km" => 1, "Rme" => 2438, "Rv" => 6052, "Re" => 6371, "Rma" => 3396, "Rm" => 3396,
  30 + "Rj" => 71492, "Rs" => 60268, "Ru" => 25559, "Rn" => 24764);
  31 +
  32 + function __construct()
  33 + {
  34 + $this->baseManager= new BaseManager();
  35 +
  36 + date_default_timezone_set('UTC');
  37 + ini_set("soap.wsdl_cache_enabled", "0");
  38 + }
  39 +
  40 + public function getImpexFullParamId($param_id, $templateArgs = NULL) {
  41 +
  42 + if (!$templateArgs)
  43 + return $param_id;
  44 +
  45 + $fullParamId = $param_id;
  46 + foreach ($templateArgs as $key => $value)
  47 + $fullParamId .= "_".$value;
  48 +
  49 + return $fullParamId;
  50 + }
  51 +
  52 + private function initParam($param, $templateArgs = NULL)
  53 + {
  54 + $this->impexParamInfo = new IHMImpexParamClass();
  55 +
  56 + $this->parameterID = $this->getImpexFullParamId($param, $templateArgs);
  57 + $this->dataProducer = $this->impexParamInfo->getDataProducer($param);
  58 + $this->resourceID = $this->impexParamInfo->getResourceID($param);
  59 + $this->parameterSize = $this->impexParamInfo->getParameterSize($param);
  60 + $this->vectorList = $this->impexParamInfo->getVectorList($this->resourceID);
  61 + $this->isSpectra = $this->impexParamInfo->isSpectra($param);
  62 + }
  63 +
  64 + public function createImpexParameter($param, $intervals, $templateArgs = NULL)
  65 + {
  66 + $this->initParam($param, $templateArgs);
  67 + $this->parameterKey = $this->impexParamInfo->getParameterKey($param);
  68 +
  69 + if (!$this->center)
  70 + $this->center = new $this->dataProducer();
  71 +
  72 + $mask = $this->center->getMask($this->resourceID, $templateArgs);
  73 +
  74 + // if VI exists (i.e. another parameter from this dataset has been already created)
  75 + if ($this->baseManager->existsVi($mask))
  76 + {
  77 + $result = $this->addImpexData($param, $intervals, $templateArgs);
  78 + $viID = $result['VIID'];
  79 +
  80 + $localFile = $this->baseManager->getFirstFileName($viID);
  81 +
  82 + if ($this->center->outputFormat == "VOTable")
  83 + {
  84 + if (!$this->votManager)
  85 + $this->votManager = new VOTableMgr();
  86 +
  87 + if (!$this->votManager->load(IHMConfigClass::getLocalBasePath().$localFile))
  88 + throw new Exception('Cannot load '.$localFile);
  89 + }
  90 + }
  91 + else
  92 + {
  93 + $start = $intervals[0]->getStart();
  94 + $duration = $intervals[0]->getDuration();
  95 +
  96 + $startTime = CommonClass::DDTimeToIso($start);
  97 + $stopTime = CommonClass::DDStartIntervalToStopIso($start,$duration);
  98 + $this->argStartTime = $startTime;
  99 + $this->argStopTime = $stopTime;
  100 +
  101 + if (is_array($templateArgs))
  102 + $templateArgs = (object) $templateArgs;
  103 +
  104 + if ($templateArgs->url_XYZ)
  105 + {
  106 + $url_XYZ = $this->getOrbit($startTime, $stopTime, $templateArgs->url_XYZ);
  107 + $params = $this->makeRequest($templateArgs, $url_XYZ);
  108 + }
  109 + else
  110 + {
  111 + $params = $this->makeRequest($templateArgs);
  112 + }
  113 +
  114 + $remoteFile = $this->center->getData($params, $this->isSpectra);
  115 +
  116 + $localFile = $this->center->getFileName($this->resourceID, $templateArgs,$start);
  117 +
  118 + if (!copy($remoteFile, IHMConfigClass::getLocalBasePath().$localFile)) {
  119 + throw new Exception('Cannot wget '.$remoteFile);
  120 + }
  121 +
  122 + if ($this->center->outputFormat == "VOTable")
  123 + {
  124 + if (!$this->votManager)
  125 + $this->votManager = new VOTableMgr();
  126 +
  127 + if (!$this->votManager->load(IHMConfigClass::getLocalBasePath().$localFile))
  128 + throw new Exception('Cannot load '.$localFile);
  129 +
  130 + if (!$this->votManager->isData())
  131 + {
  132 + unlink(IHMConfigClass::getLocalBasePath().$localFile);
  133 + throw new Exception('Empty file '.$localFile);
  134 + }
  135 +
  136 + if ($this->vectorList)
  137 + {
  138 + //TODO if it is needed to reload xml in case of several vectors
  139 + foreach ($this->vectorList as $vector)
  140 + {
  141 + $this->votManager->addVectorToVot($vector,IHMConfigClass::getLocalBasePath().$localFile);
  142 + }
  143 + }
  144 + $viID = $this->addFileToDb($mask, $localFile, $startTime, $stopTime);
  145 + }
  146 + elseif ($this->center->outputFormat == "CDF")
  147 + {
  148 + $viID = $this->addFileToDb($mask, $localFile, $startTime, $stopTime, 'cdf');
  149 + }
  150 +
  151 + if ($this->orbitTempFolder)
  152 + CommonClass::rrmdir($this->orbitTempFolder);
  153 + }
  154 +
  155 + $res = $this->getInfoFromFile($localFile);
  156 +
  157 + $res["success"] = true;
  158 + $res["param"]["id"] = $this->parameterID;
  159 + $res["param"]["dateModif"] = time();
  160 + $res["param"]["info"]["viId"] = $viID;
  161 + $res["param"]["info"]["name"] = $this->parameterKey;
  162 + $res["param"]["info"]["yTitle"] = $this->parameterKey;
  163 + $res["param"]["info"]["units"] = $this->impexParamInfo->getUnits($param);
  164 +
  165 +
  166 + //TODO define in DataCenter Class
  167 + // special info on EnergyRange Table for Spectra : LATMOS, FMI_HYBRID
  168 + if ($this->isSpectra)
  169 + {
  170 + $res["param"]["info"]["tableDef"] = $this->center->getTableDefinition();
  171 + $res["param"]["info"]["yTitle"] = $this->center->tableTitle;
  172 + $res["param"]["info"]["yUnits"] = $this->impexParamInfo->getEnergyUnits($param);
  173 + }
  174 + if ($this->dataProducer == "IPIM")
  175 + {
  176 + $res["param"]["info"]["tableDef"] = $this->center->getTableDefinition(); // ($viID);
  177 + $res["param"]["info"]["yTitle"] = $this->center->energyTableName;
  178 + $res["param"]["info"]["yUnits"] = 'km';
  179 + }
  180 + return $res;
  181 + }
  182 +
  183 + public function addImpexData($param, $intervals, $templateArgs = NULL)
  184 + {
  185 + $this->initParam($param, $templateArgs);
  186 +
  187 + $start = $intervals[0]->getStart();
  188 + $duration = $intervals[0]->getDuration();
  189 +
  190 + if (!$this->center)
  191 + $this->center = new $this->dataProducer();
  192 +
  193 + $mask = $this->center->getMask($this->resourceID, $templateArgs);
  194 +
  195 + $startStamp = CommonClass::DDTimeToTimeStamp($start);
  196 + $stopStamp = $startStamp + CommonClass::DDTimeToTimeStamp($duration);
  197 +
  198 + $intervalsToGet = $this->baseManager->intervalsToGet($startStamp, $stopStamp, $mask);
  199 +
  200 + $startT = $intervalsToGet['start'];
  201 + $stopT = $intervalsToGet['stop'];
  202 +
  203 + if ( is_array($templateArgs) )
  204 + $templateArgs = (object) $templateArgs;
  205 +
  206 + if (count($startT) > 0)
  207 + {
  208 + for ( $i = 0; $i < count($startT); $i++ )
  209 + {
  210 + $startTime = date("Y-m-d\TH:i:s",$startT[$i]);
  211 + $stopTime = date("Y-m-d\TH:i:s",$stopT[$i]);
  212 +
  213 + $this->argStartTime = $startTime;
  214 + $this->argStopTime = $stopTime;
  215 +
  216 + if ($templateArgs->url_XYZ)
  217 + {
  218 + $url_XYZ = $this->getOrbit($startTime, $stopTime, $templateArgs->url_XYZ);
  219 + $params = $this->makeRequest($templateArgs, $url_XYZ);
  220 + }
  221 + else
  222 + {
  223 + $params = $this->makeRequest($templateArgs);
  224 + }
  225 +
  226 +
  227 + $remoteFile = $this->center->getData($params, $this->isSpectra);
  228 +
  229 + $localFile = $this->center->getFileName($this->resourceID,$templateArgs,$start);
  230 +
  231 + if (!copy($remoteFile, IHMConfigClass::getLocalBasePath().$localFile)) {
  232 + throw new Exception('Cannot wget '.$remoteFile);
  233 + }
  234 +
  235 + if ($this->center->outputFormat == "VOTable")
  236 + {
  237 + if (!$this->votManager)
  238 + $this->votManager = new VOTableMgr();
  239 +
  240 + if (!$this->votManager->load(IHMConfigClass::getLocalBasePath().$localFile))
  241 + throw new Exception('Cannot load '.$localFile);
  242 +
  243 + if (!$this->votManager->isData())
  244 + {
  245 + unlink(IHMConfigClass::getLocalBasePath().$localFile);
  246 + throw new Exception('Empty file '.$localFile);
  247 + }
  248 +
  249 + if ($this->vectorList)
  250 + {
  251 + foreach ($this->vectorList as $vector)
  252 + {
  253 + $this->votManager->addVectorToVot($vector,IHMConfigClass::getLocalBasePath().$localFile);
  254 + }
  255 + }
  256 +
  257 + $viID = $this->addFileToDb($mask, $localFile, $startTime, $stopTime);
  258 + }
  259 + else if ($this->center->outputFormat == "CDF")
  260 + {
  261 + $viID = $this->addFileToDb($mask, $localFile, $startTime, $stopTime, 'cdf');
  262 + }
  263 + if ($this->orbitTempFolder)
  264 + CommonClass::rrmdir($this->orbitTempFolder);
  265 + }
  266 + }
  267 + // nothing to add
  268 + else
  269 + {
  270 + $viID = $this->baseManager->getVI($mask);
  271 + }
  272 +
  273 + $startStop = $this->baseManager->getViDesc($viID);
  274 +
  275 + $res = array('VIID' => $viID, 'StartStop' => $startStop);
  276 +
  277 + return $res;
  278 + }
  279 +
  280 + private function getInfoFromFile($localFile)
  281 + {
  282 + $res = array();
  283 + $res["param"] = array();
  284 + $res["param"]["info"] = array();
  285 +
  286 + if ($this->center->outputFormat == "VOTable")
  287 + {
  288 + if (!$this->votManager)
  289 + $this->votManager = new VOTableMgr();
  290 +
  291 + // reload xml after adding vector field
  292 + if (!$this->votManager->load(IHMConfigClass::getLocalBasePath().$localFile))
  293 + throw new Exception('Cannot load '.$localFile);
  294 +
  295 + $infos = $this->votManager->getFieldInfoByID($this->parameterKey);
  296 + $samplings = $this->votManager->getSamplings();
  297 + $res["param"]["info"]["realVar"] = $infos["id"];
  298 + $res["param"]["info"]["type"] = $infos["type"];
  299 + $res["param"]["info"]["unit"] = $infos["unit"];
  300 + $res["param"]["info"]["ucd"] = $infos["ucd"];
  301 + $res["param"]["info"]["size"] = $infos["size"];
  302 + $res["param"]["info"]["minSampling"] = $samplings["minSampling"];
  303 + $res["param"]["info"]["maxSampling"] = $samplings["maxSampling"];
  304 + $res["param"]["info"]["plotType"] = "Time Series";
  305 + }
  306 + else if ($this->center->outputFormat == "CDF")
  307 + {
  308 + $filesMgr = new FilesMgr();
  309 + $filesMgr->setFileName($localFile);
  310 +
  311 + $varInfo = $filesMgr->getCdfVarInfo($this->parameterKey);
  312 + $varSampling = $filesMgr->getCdfSampling();
  313 +
  314 + $res["param"]["info"]["realVar"] = $this->parameterKey;
  315 + $res["param"]["info"]["type"] = $varInfo['type'];
  316 + $res["param"]["info"]["minSampling"] = $varSampling[4];
  317 + $res["param"]["info"]["maxSampling"] = $varSampling[4];
  318 + $res["param"]["info"]["plotType"] = "Spectro";
  319 + $res["param"]["info"]["size"] = $varInfo['size'];
  320 + }
  321 + return $res;
  322 + }
  323 +
  324 + private function addFileToDb($maskName, $fileName, $startTime, $stopTime, $format = null)
  325 + {
  326 + if (!$format)
  327 + $format = "vot";
  328 +
  329 + if (!$this->baseManager->existsVi($maskName))
  330 + {
  331 + $viID = $this->baseManager->addVI($maskName, $format);
  332 + }
  333 + else
  334 + {
  335 + $viID = $this->baseManager->getVI($maskName);
  336 + }
  337 +
  338 + $start = strtotime($startTime);
  339 + $stop = strtotime($stopTime);
  340 +
  341 + $mask = $this->baseManager->addFile($fileName, $start, $stop);
  342 +
  343 + return $viID;
  344 + }
  345 +
  346 + public function getOrbit($startTime, $stopTime, $paramId)
  347 + {
  348 + $params = array();
  349 + $params[] = (object)array("paramid" => $paramId);
  350 +
  351 + $obj = (object)array(
  352 + "nodeType" => "download",
  353 + "downloadSrc" => "0",
  354 + "structure" => 2,
  355 + "refparamSampling" => false,
  356 + "sampling" => 60,
  357 + "timesrc" => "Interval",
  358 + "startDate" => $startTime,
  359 + "stopDate" => $stopTime,
  360 + "list" => $params,
  361 + "fileformat" => "vot",
  362 + "timeformat" => "YYYY-MM-DDThh:mm:ss",
  363 + "compression" => "gzip" ,
  364 + "disablebatch" => true
  365 + );
  366 +
  367 + if (!isset($this->requestManager))
  368 + $this->requestManager = new RequestManagerClass();
  369 +
  370 + $userID = IHMConfigClass::getUserName();
  371 + $userHost = IHMConfigClass::getUserHost();
  372 +
  373 + try
  374 + {
  375 + $downloadResult = $this->requestManager->runIHMRequest($userID, $userHost, FunctionTypeEnumClass::PARAMS, $obj);
  376 + }
  377 + catch (Exception $e)
  378 + {
  379 + throw new Exception($e->getMessage());
  380 + }
  381 +
  382 + $this->orbitTempFolder = IHMConfigClass::getRequestPath().$downloadResult['folder'];
  383 +
  384 + try
  385 + {
  386 + $this->convertVot($paramId, $downloadResult['result']);
  387 + $orbitURL = "http://apus.irap.omp.eu/NEWAMDA/data/budnik/RES/".$downloadResult['folder']."/".$downloadResult['result'].".vot";
  388 +
  389 + return $orbitURL;
  390 + }
  391 + catch (Exception $e)
  392 + {
  393 + throw new Exception($e->getMessage());
  394 + }
  395 + }
  396 +
  397 + public function makeRequest($templateArgs = null, $url_XYZ = null)
  398 + {
  399 + $params = array();
  400 +
  401 + if ($templateArgs)
  402 + {
  403 + $extraParams = array();
  404 +
  405 + foreach ($templateArgs as $key => $value)
  406 + {
  407 + if ($key != 'url_XYZ')
  408 + $extraParams[$key] = $value;
  409 + }
  410 +
  411 + $extraParams['OutputFileType'] = $this->center->outputFormat;
  412 +
  413 + if ($this->center->additionalArgs)
  414 + {
  415 + $args = $this->center->additionalArgs[$this->resourceID];
  416 + foreach ($args as $key => $type)
  417 + {
  418 + if ($key == "StartTime") $params[$key] = $this->argStartTime;
  419 + if ($key == "StopTime") $params[$key] = $this->argStopTime;
  420 + if ($key == "Sampling") $params[$key] = 60;
  421 + }
  422 + }
  423 +
  424 + if ($url_XYZ)
  425 + {
  426 + $params['url_XYZ'] = $url_XYZ;
  427 + }
  428 +
  429 + $params['extraParams'] = $extraParams;
  430 + }
  431 + else
  432 + {
  433 + $params['accessUrl'] = $this->impexParamInfo->getAccessUrl($this->resourceID);
  434 + }
  435 +
  436 + $params['ResourceID'] = $this->resourceID;
  437 +
  438 + return $params;
  439 + }
  440 +
  441 + private function convertVot($paramID, $fileName)
  442 + {
  443 + $comps = array('x', 'y', 'z');
  444 +
  445 + $xmlFile = $this->orbitTempFolder."/".$fileName.'.vot';
  446 +
  447 + exec("gunzip ".$xmlFile.".gz");
  448 +
  449 + $dom = new DomDocument("1.0");
  450 + $dom->formatOutput = false;
  451 + $dom->preserveWhiteSpace = false;
  452 + $dom->load($xmlFile);
  453 + $xp = new domxpath($dom);
  454 +
  455 + $fields = $dom->getElementsByTagName('FIELD');
  456 + $table = $dom->getElementsByTagName('TABLE')->item(0);
  457 + $data = $dom->getElementsByTagName('DATA')->item(0);
  458 +
  459 + $i=0;
  460 +
  461 + foreach ($fields as $field)
  462 + {
  463 + if ($field->getAttribute('ID') == $paramID)
  464 + {
  465 + $unit = $field->getAttribute('unit');
  466 + $ucd = $field->getAttribute('ucd');
  467 + $datatype = $field->getAttribute('datatype');
  468 + $firstTD = $i;
  469 + }
  470 + $i++;
  471 + }
  472 + //TODO unit from output VOT file
  473 + /*----------------- temporary-----------------*/
  474 + $temp = new DomDocument("1.0");
  475 + $temp->load(IHMConfigClass::getLocalParamDBPath().$paramID.".xml");
  476 + $unit = $temp->getElementsByTagName('units')->item(0)->nodeValue;
  477 +
  478 + /*----------------- temporary-----------------*/
  479 + if ($firstTD > 0)
  480 + {
  481 + if (array_key_exists($unit, $this->scale))
  482 + $unitScale = $this->scale[$unit];
  483 + else
  484 + throw new Exception("Undefined unit ".$unit);
  485 +
  486 + $table->removeChild($fields->item($firstTD));
  487 +
  488 + foreach ($comps as $comp)
  489 + {
  490 + $new_field = $dom->createElement('FIELD');
  491 + $new_field->appendChild(new DOMAttr('ID', $comp));
  492 + $new_field->appendChild(new DOMAttr('name', $comp));
  493 + $new_field->appendChild(new DOMAttr('datatype', $datatype));
  494 + $new_field->appendChild(new DOMAttr('unit', 'km')); // $unit
  495 + $new_field->appendChild(new DOMAttr('ucd', 'pos.cartesian.'.$comp));
  496 +
  497 + $table->insertBefore($new_field,$data);
  498 + }
  499 +
  500 + $trs = $dom->getElementsByTagName('TR');
  501 + foreach($trs as $tr)
  502 + {
  503 + $tds = $tr->getElementsByTagName('TD');
  504 + $values = explode(' ',$tds->item($firstTD)->nodeValue);
  505 + $toRemote = $tds->item($firstTD);
  506 + $tr->removeChild($toRemote);
  507 +
  508 + foreach ($values as $value)
  509 + {
  510 + $td = $dom->createElement('TD', $value*$unitScale); //3400
  511 + $tr->appendChild($td);
  512 + }
  513 + }
  514 +
  515 + $dom->save($xmlFile);
  516 + }
  517 + }
  518 +
  519 + /*
  520 + * Delete impex params descriptions in User WS dir (and in Plot?)
  521 + */
  522 + public function deleteImpexParams()
  523 + {
  524 + $dom = new DomDocument("1.0");
  525 + $params = glob(IHMConfigClass::getUserWSPath().IHMImpexParamClass::$paramPrefix.'*.xml');
  526 +
  527 + $vis = array();
  528 + foreach ($params as $param)
  529 + {
  530 + $dom->load($param);
  531 + $vi = $dom->getElementsByTagName('localvi');
  532 + if ($vi->length == 0) {
  533 + // throw new Exception('No localVi tag in '.$param);
  534 + continue;
  535 + }
  536 + $viId = $vi->item(0)->getAttribute('id');
  537 + if (!in_array ($viId, $vis))
  538 + $vis[] = $viId;
  539 + }
  540 +
  541 + foreach ($params as $param)
  542 + {
  543 + unlink($param);
  544 + }
  545 +
  546 + // Delete params in Plot/params
  547 + foreach (glob(IHMConfigClass::getRequestPath().'Plot_/params/'.IHMImpexParamClass::$paramPrefix.'*.xml') as $param)
  548 + {
  549 + unlink($param);
  550 + }
  551 +
  552 + return $vis;
  553 + }
  554 +
  555 + /*
  556 + * Delete impex VIs and Files in User DATA dir
  557 + */
  558 + public function deleteImpexStaff()
  559 + {
  560 + $vis = $this->deleteImpexParams();
  561 +
  562 + foreach ($vis as $vi)
  563 + {
  564 + $this->baseManager->deleteViTotal($vi);
  565 + }
  566 + }
  567 +}
0 568 \ No newline at end of file
... ...
php/RemoteDataCenter/LATMOS.php 0 โ†’ 100644
... ... @@ -0,0 +1,72 @@
  1 +<?php
  2 +/**
  3 + * @class LATMOS
  4 + * @brief
  5 + * @details
  6 + */
  7 +class LATMOS extends SimulationDataCenterClass
  8 +{
  9 + protected $url = "http://impex.latmos.ipsl.fr";
  10 + protected $treeXML = "tree.xml";
  11 + protected $WSDL = "Methods_LATMOS.wsdl";
  12 +
  13 + protected $templateFile = "LATMOS_Templates.xml";
  14 + protected $needsArgs = true;
  15 + public $soapMethod = "getDataPointValue";
  16 + public $soapMethodSpectra = "getDataPointSpectra";
  17 +
  18 + public $energyTableName = "EnergyRange", $tableTitle="Energy";
  19 +
  20 + //<xs:element minOccurs="0" maxOccurs="1" ref="EnergyChannel"/>
  21 + //Extraparam: OutputFormat => netCDF, VOTable
  22 +
  23 + public $outputFormat = "VOTable";
  24 +
  25 + protected function setSimulationRunNodeDescription($runNode,$sr)
  26 + {
  27 + $coords = $this->getCoordinateSystem($sr->SimulationDomain->CoordinateSystem);
  28 + $domain = $this->getRegionBoundaries($sr->SimulationDomain,$sr->RegionParameter);
  29 + $properties = $this->getProperties($sr);
  30 +
  31 + $runNode->setAttribute('desc', $coords.$domain.$properties);
  32 + }
  33 +
  34 + protected function getProperties($sr)
  35 + {
  36 + $descUpstream = "<b><br/>Upstream Conditions: </b><br/>";
  37 + $descInternal = "<b><br/>Internal Conditions: </b><br/>";
  38 +
  39 + $inputPopulations = $sr->InputPopulation;
  40 + $inputFields = $sr->InputField;
  41 +
  42 + foreach ($inputPopulations as $population)
  43 + {
  44 + if ($population->SimulatedRegion == "Heliosphere") {
  45 + $descUpstream .= "<u>".$population->Name."</u><br/>";
  46 + }
  47 + }
  48 +
  49 + foreach ($inputFields as $field)
  50 + {
  51 + if ($field->SimulatedRegion == "Heliosphere") {
  52 + $descUpstream .= "<u>".$field->Name."</u> : ";
  53 + $descUpstream .= $field->Units." <i>[".$field->FieldValue."]</i> ".$field->Units."<br/>";
  54 + }
  55 + }
  56 +
  57 + return $descUpstream;
  58 + }
  59 +
  60 + protected function createSpecialArgs($dom)
  61 + {
  62 + $node = $dom->createElement('argument');
  63 + $node->setAttribute('key', 'IMFClockAngle');
  64 + $node->setAttribute('name', 'IMF Clock Angle');
  65 + $node->setAttribute('type', 'float');
  66 + $node->setAttribute('default', '0');
  67 +
  68 + return array($node);
  69 + }
  70 +
  71 +}
  72 +?>
... ...
php/RemoteDataCenter/LESIA.php 0 โ†’ 100644
... ... @@ -0,0 +1,346 @@
  1 +<?php
  2 +/**
  3 + * @class LESIA
  4 + * @brief
  5 + * @details
  6 + */
  7 +class LESIA extends SimulationDataCenterClass
  8 +{
  9 + protected $url = "http://maser.obspm.fr/IMPExWS";
  10 + protected $treeXML = "tree_Mag.xml";
  11 + protected $WSDL = "Methods_LESIA-Mag.wsdl";
  12 +
  13 + protected $templateFile = "LESIA_Templates.xml";
  14 +
  15 + protected $needsArgs = true;
  16 +
  17 + //TODO temporary
  18 + protected $prefix = "spase://IMPEX/NumericalOutput/LESIA/MAG/Jupiter";
  19 + protected $resourceID ="impex://LESIA/MAG/Jupiter";
  20 + /*
  21 + public $soapMethod = "calculateDataPointValue_Spacecraft";
  22 + <xs:element minOccurs="1" maxOccurs="1" ref="Spacecraft_name"/>
  23 + <xs:enumeration value="Cassini"/>
  24 + <xs:enumeration value="Galileo"/>
  25 + <xs:element minOccurs="1" maxOccurs="1" ref="StartTime"/>
  26 + <xs:element minOccurs="1" maxOccurs="1" ref="StopTime"/>
  27 + <xs:element minOccurs="1" maxOccurs="1" ref="Sampling"/>
  28 +
  29 + */
  30 +
  31 + public $soapMethods = array("calculateDataPointValue", "calculateDataPointValue_Spacecraft");
  32 +// <xs:element minOccurs="1" maxOccurs="1" ref="url_XYZ"/>
  33 +// <xs:element minOccurs="1" maxOccurs="1" ref="StartTime"/>
  34 +
  35 + public $additionalArgs = array("spase://IMPEX/NumericalOutput/LESIA/MAG/Jupiter/sc" => array("StartTime" => "dateTime", "StopTime" => "dateTime", "Sampling"=> "float" ),
  36 + "spase://IMPEX/NumericalOutput/LESIA/MAG/Jupiter/xyz" => array("StartTime" => "dateTime"));
  37 +
  38 + private $calculateDataPointValue_Args = null;
  39 +
  40 + private $spacecraft = array("Cassini", "Galileo");
  41 +
  42 + private $internalModel = array("O6", "VIP4", "VIT4", "VIPAL");
  43 + private $currentSheet = array("None", "Connerney", "Khurana");
  44 + private $coordinateSystem = array("JSO", "JSM", "JSS", "PlanetaryCartesian","PlanetarySpherical","Planetarographic");
  45 +
  46 + /*
  47 + <xs:sequence>
  48 + <xs:element minOccurs="0" maxOccurs="1" ref="IMF"/>
  49 +
  50 + */
  51 + //Extraparam: OutputFormat => netCDF, VOTable
  52 + public $outputFormat = "VOTable";
  53 +
  54 + private function initArgs()
  55 + {
  56 + if ($this->calculateDataPointValue_Args) return;
  57 +
  58 + $this->calculateDataPointValue_Args = array();
  59 + $this->calculateDataPointValue_Args["InternalModel"] = $this->internalModel;
  60 + $this->calculateDataPointValue_Args["CurrentSheet"] = $this->currentSheet;
  61 + $this->calculateDataPointValue_Args["CoordinateSystem"] = $this->coordinateSystem;
  62 +
  63 + }
  64 +
  65 + protected function createMissionNodes()
  66 + {
  67 + $missionNodes = array();
  68 +
  69 + foreach ($this->tree->SimulationModel as $sm)
  70 + {
  71 + $ResourceID = trim($sm->ResourceID);
  72 +
  73 + $simulationModel = $this->domAmda->createElement('simulationModel');
  74 + $simReg = $sm->SimulatedRegion;
  75 + $simulationModel->setAttribute('xml:id', $sm->ResourceID);
  76 +
  77 + $simulationModel->setAttribute('name', $sm->ResourceHeader->ResourceName." : ".$simReg);
  78 +
  79 + $simulationModel->setAttribute('desc', $sm->ResourceHeader->Description.'<br/> ReleaseDate: '.$sm->ResourceHeader->ReleaseDate);
  80 +
  81 + if (file_exists(DATAPATH.'rank.json'))
  82 + $cmpArr = json_decode(file_get_contents(DATAPATH.'rank.json'), true);
  83 + else
  84 + $cmpArr = null;
  85 +
  86 + $index = $cmpArr["$simReg"];
  87 + if ($index)
  88 + $simulationModel->setAttribute('rank',$index);
  89 + else
  90 + $simulationModel->setAttribute('rank', 999);
  91 +
  92 + $simulationModel->setAttribute('att', "simu/simu$simReg");
  93 +// $this->setModelHelp($simulationModel,"");
  94 +
  95 + $this->addSimulatedRegionToTargetsFile($simReg, "JSM"); //TODO check this
  96 +
  97 + $datasetNodes = $this->createDatasetNodes($simReg);
  98 +
  99 + foreach ($datasetNodes as $ds)
  100 + {
  101 + $parameterNodes = $this->createParameterNodes($sm->OutputParameters->Parameter, $ds->getAttribute('xml:id'));
  102 +
  103 + foreach ($parameterNodes as $node )
  104 + $ds->appendChild($node);
  105 +
  106 + $simulationModel->appendChild($ds);
  107 + }
  108 + $missionNodes[] = $simulationModel;
  109 + }
  110 +
  111 + return $missionNodes;
  112 + }
  113 +
  114 + protected function createDatasetNodes()
  115 + {
  116 + $datasetNodes = array();
  117 +
  118 + foreach ($this->soapMethods as $soapMethod)
  119 + {
  120 + $datasetNode = $this->domAmda->createElement('dataset');
  121 + $datasetNode->setAttribute('name', $soapMethod);
  122 + if ($soapMethod == "calculateDataPointValue_Spacecraft")
  123 + $datasetNode->setAttribute('xml:id', $this->prefix."/sc");
  124 + else
  125 + $datasetNode->setAttribute('xml:id', $this->prefix."/xyz");
  126 +
  127 + $datasetNode->setAttribute('globalStart', 'depending on mission');
  128 + $datasetNodes[] = $datasetNode;
  129 + }
  130 + return $datasetNodes;
  131 + }
  132 +
  133 + protected function createParameterNodes($params, $dsid)
  134 + {
  135 + $paramNodes = array();
  136 +
  137 + foreach ($params as $param)
  138 + {
  139 + $paramNode = $this->domAmda->createElement('parameter');
  140 + $id = $this->param2dd($dsid."/".$param->ParameterKey);
  141 + $paramNode->setAttribute('xml:id',$id);
  142 + $paramNode->setAttribute('name', $param->ParameterKey);
  143 + $paramNode->setAttribute('desc', 'Units: '.$param->Units);
  144 + $paramNode->setAttribute('shortName',$param->ParameterKey);
  145 + $paramNode->setAttribute('needsArgs', $this->needsArgs);
  146 +
  147 + if ($this->hasComponents($param))
  148 + {
  149 + if (strpos(trim($param->ParameterKey), ',') === false)
  150 + $comps = explode(' ',trim($param->ParameterKey));
  151 + else
  152 + $comps = explode(',',trim($param->ParameterKey));
  153 +
  154 + $paramNode->setAttribute('size', count($comps));
  155 +
  156 + foreach ($comps as $comp)
  157 + {
  158 + $compNode = $this->domAmda->createElement('component');
  159 + // $compNode->setAttribute('xml:id', $id."_".$comp);
  160 +
  161 + $compNode->setAttribute('xml:id',$this->param2dd($dsid."_".$comp));
  162 +
  163 + $compNode->setAttribute('name', $comp);
  164 + $compNode->setAttribute('needsArgs', $this->needsArgs);
  165 + $compNode->setAttribute('shortName',$comp);
  166 +
  167 + $paramNode->appendChild($compNode);
  168 + }
  169 + }
  170 + $paramNodes[] = $paramNode;
  171 + }
  172 +
  173 + return $paramNodes;
  174 + }
  175 +
  176 + protected function createSpecialArgs($dom)
  177 + {
  178 + $this->initArgs();
  179 + $nodes = array();
  180 +
  181 + foreach ($this->calculateDataPointValue_Args as $key => $values)
  182 + {
  183 + $node = $dom->createElement('argument');
  184 + $node->setAttribute('key', $key);
  185 + $node->setAttribute('name', $key);
  186 + $node->setAttribute('type', 'list');
  187 + foreach ($values as $value)
  188 + {
  189 + $item = $dom->createElement('item');
  190 + $item->setAttribute('name',$value);
  191 + $item->setAttribute('key', $value);
  192 +
  193 + $node->appendChild($item);
  194 + }
  195 + $node->setAttribute('default', $values[0]);
  196 +
  197 + $nodes[] = $node;
  198 + }
  199 +
  200 + $node = $dom->createElement('argument');
  201 +
  202 + return $nodes;
  203 + }
  204 +
  205 + protected function createSpecialScArgs($dom)
  206 + {
  207 + $node = $dom->createElement('argument');
  208 + $node->setAttribute('key', 'Spacecraft_name');
  209 + $node->setAttribute('name', $key);
  210 + $node->setAttribute('type', 'list');
  211 + foreach ($this->spacecraft as $value)
  212 + {
  213 + $item = $dom->createElement('item');
  214 + $item->setAttribute('name',$value);
  215 + $item->setAttribute('key', $value);
  216 +
  217 + $node->appendChild($item);
  218 + }
  219 + $node->setAttribute('default', $this->spacecraft[0]);
  220 +
  221 + return $node;
  222 + }
  223 +
  224 + public function makeArgumentsList()
  225 + {
  226 + if (!file_exists(SimuTargetsXml))
  227 + exit('NOT YET!'.PHP_EOL);
  228 +
  229 + if (file_exists($this->templateFile))
  230 + unlink($this->templateFile);
  231 +
  232 + $TemplatesXml = new DomDocument("1.0");
  233 + $TemplatesXml->formatOutput = TRUE;
  234 + $TemplatesXml->preserveWhiteSpace = FALSE;
  235 +
  236 + $rootNode = $TemplatesXml->createElement('paramTemplateList');
  237 + $TemplatesXml->appendChild($rootNode);
  238 +
  239 + $TargetsXml = new DomDocument("1.0");
  240 + $TargetsXml->load(SimuTargetsXml);
  241 + $targets = $TargetsXml->getElementsByTagName('Target');
  242 + foreach ($targets as $target)
  243 + {
  244 + if ($target->hasAttribute($this->baseID))
  245 + {
  246 + echo $target->getAttribute('xml:id').PHP_EOL;
  247 + foreach ($this->soapMethods as $soapMethod)
  248 + {
  249 + $paramNode = $TemplatesXml->createElement('paramTemplate');
  250 +
  251 + $paramNode->setAttribute('fileName','##internalField####currentSheet##');
  252 + $argsNode = $TemplatesXml->createElement('arguments');
  253 + $paramNode->appendChild($argsNode);
  254 + $specialNodes = $this->createSpecialArgs($TemplatesXml);
  255 +
  256 + foreach ($specialNodes as $specialNode)
  257 + $argsNode->appendChild($specialNode);
  258 +
  259 + if ($soapMethod == "calculateDataPointValue")
  260 + {
  261 + $missionGrps = json_decode(file_get_contents(RemoteData.$target->nodeValue.".json"), true);
  262 + $node = $TemplatesXml->createElement('argument');
  263 + $node->setAttribute('key', 'url_XYZ');
  264 + $node->setAttribute('name', 'Mission Name');
  265 + $node->setAttribute('type', 'list');
  266 +
  267 + foreach ($missionGrps as $grp => $missions)
  268 + {
  269 + foreach ( $missions as $mission => $datasets)
  270 + {
  271 + echo 'MISSION: '.$mission.PHP_EOL;
  272 + foreach ($datasets as $dataset => $parameters)
  273 + {
  274 + echo " ".$dataset.PHP_EOL;
  275 + foreach ($parameters as $param => $value)
  276 + {
  277 + $item = $TemplatesXml->createElement('item');
  278 + $item->setAttribute('name', $mission);
  279 + $item->setAttribute('key', $value);
  280 +
  281 + $node->appendChild($item);
  282 + }
  283 + }
  284 + }
  285 + }
  286 + //TODO select default s/c for each target
  287 + $node->setAttribute('default', $value);
  288 + $argsNode->appendChild($node);
  289 + $paramNode->setAttribute('paramId', $this->prefix."/xyz");
  290 + }
  291 + else // calculateDataPointValue_Spacecraft
  292 + {
  293 + $scNode = $this->createSpecialScArgs($TemplatesXml);
  294 + $argsNode->appendChild($scNode);
  295 + $paramNode->setAttribute('paramId', $this->prefix."/sc");
  296 + }
  297 +
  298 + $rootNode->appendChild($paramNode);
  299 + }
  300 + }
  301 + }
  302 + $TemplatesXml->save(RemoteData.$this->baseID."/".$this->templateFile);
  303 + }
  304 +
  305 + public function getData($params)
  306 + {
  307 +// $r = print_r($params,true);
  308 +// error_log($r,3,'/home/budnik/LOG');
  309 +
  310 + if (strpos('xyz', $params['ResourceID']) > 0)
  311 + $realSoapMethod = $this->soapMethods[0];
  312 + else
  313 + $realSoapMethod = $this->soapMethods[1];
  314 +
  315 + $params['ResourceID'] = $this->resourceID;
  316 +
  317 + try
  318 + {
  319 + $client = new SoapClient($this->url."/".$this->WSDL,
  320 + array(
  321 + 'wsdl_cache' => 0,
  322 + 'trace' => 1,
  323 + 'soap_version'=>SOAP_1_2
  324 + ));
  325 + }
  326 + catch (SoapFault $exception)
  327 + {
  328 + throw new Exception($exception->getMessage()." ".$exception->getTraceAsString());
  329 + }
  330 +
  331 + $realSoapMethod = $this->soapMethods[0];
  332 +
  333 + try
  334 + {
  335 + $file = $client->__soapCall($realSoapMethod, array($params));
  336 + }
  337 + catch (SoapFault $exception)
  338 + {
  339 + throw new Exception($exception->getMessage()." ".$exception->getTraceAsString());
  340 + }
  341 +
  342 + return $file;
  343 +
  344 + }
  345 +}
  346 +?>
... ...
php/RemoteDataCenter/RemoteDataCenterClass.php 0 โ†’ 100644
... ... @@ -0,0 +1,86 @@
  1 +<?php
  2 +/**
  3 + * @class RemoteDataCenterClass
  4 + * @brief
  5 + * @details
  6 + */
  7 +abstract class RemoteDataCenterClass
  8 +{
  9 + protected $url = null, $treeXML = null;
  10 + protected $baseID = null;
  11 +
  12 + protected $needsArgs = false;
  13 + protected $hasAccessUrl = false;
  14 +
  15 + public $domAmda = null, $dataCenter = null;
  16 + public $domAmdaName = "base.xml";
  17 + public $additionalArgs = null;
  18 +
  19 + public $tree = null;
  20 +
  21 + /*
  22 + * @brief Constructor
  23 + */
  24 + function __construct()
  25 + {
  26 + $this->baseID = get_class($this);
  27 + }
  28 +
  29 + public function param2dd($paramID)
  30 + {
  31 + $pairs = array(" " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_","#" => "_","@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_", ")" => "", "(" => "_");
  32 + return strtr($paramID,$pairs);
  33 + }
  34 +
  35 + public function saveProxy()
  36 + {
  37 + $this->domAmda->save(RemoteData.$this->baseID."/".$this->domAmdaName);
  38 + }
  39 +
  40 + abstract public function init();
  41 +
  42 +
  43 + abstract protected function getRemoteTree();
  44 + abstract protected function setDataCenterAttributes();
  45 + abstract protected function createMissionNodes();
  46 + abstract protected function makeArgumentsList();
  47 +// abstract protected function createDatasetNodes();
  48 +// abstract protected function createParameterNodes();
  49 +// abstract protected function createDatasetGroupNodes($data);
  50 +
  51 + public function initProxy()
  52 + {
  53 + if (!is_dir(RemoteData.$this->baseID))
  54 + mkdir(RemoteData.$this->baseID);
  55 +
  56 + chmod(RemoteData.$this->baseID,0775);
  57 +
  58 + $this->getRemoteTree();
  59 + }
  60 +
  61 + public function makeProxy()
  62 + {
  63 + $this->domAmda = new DOMDocument('1.0', 'utf-8');
  64 + $this->domAmda->formatOutput = TRUE;
  65 + $this->domAmda->preserveWhiteSpace = FALSE;
  66 +
  67 + $dataRoot = $this->domAmda->createElement('dataRoot');
  68 + $dataRoot->setAttribute('xml:id', 'myRemoteData-treeRootNode');
  69 + $this->domAmda->appendChild($dataRoot);
  70 +
  71 + $this->dataCenter=$this->domAmda->createElement('dataCenter');
  72 +
  73 + $this->dataCenter->setAttribute('xml:id', $this->baseID);
  74 + $this->dataCenter->setAttribute('name', $this->baseID);
  75 +
  76 + $dataRoot->appendChild($this->dataCenter);
  77 +
  78 + $this->setDataCenterAttributes();
  79 +
  80 + $missionNodes = $this->createMissionNodes();
  81 +
  82 + foreach ($missionNodes as $missionNode)
  83 + $this->dataCenter->appendChild($missionNode);
  84 + }
  85 +}
  86 +?>
... ...
php/RemoteDataCenter/SINP.php 0 โ†’ 100644
... ... @@ -0,0 +1,51 @@
  1 +<?php
  2 +/**
  3 + * @class SINP
  4 + * @brief
  5 + * @details
  6 + */
  7 +class SINP extends SimulationDataCenterClass
  8 +{
  9 + protected $url = "http://smdc.sinp.msu.ru/impex";
  10 + protected $treeXML = "SINP_tree.xml";
  11 + protected $WSDL = "SINP_methods.wsdl";
  12 +
  13 + protected $needsArgs = true;
  14 + protected $soapMethod = 'calculateDataPointValue';
  15 + protected $templateFile = "SINP_Templates.xml";
  16 +
  17 + // OutputFormat netCDF VOTable
  18 + public $outputFormat = "VOTable";
  19 +
  20 + protected function createMissionNodes()
  21 + {
  22 + $missionNodes = array();
  23 +
  24 + foreach ($this->tree->SimulationModel as $sm)
  25 + {
  26 + $ResourceID = trim($sm->ResourceID);
  27 + if (strpos($ResourceID, 'Static') === false)
  28 + {
  29 + $simulationModel = $this->domAmda->createElement('simulationModel');
  30 +
  31 + $simulationModel->setAttribute('xml:id', $sm->ResourceID);
  32 + $simulationModel->setAttribute('name', $sm->ResourceHeader->ResourceName);
  33 +
  34 + $simulationModel->setAttribute('desc', $sm->ResourceHeader->Description.'<br/> ReleaseDate: '.$sm->ResourceHeader->ReleaseDate);
  35 + $this->setModelHelp($simulationModel,"");
  36 +
  37 + if ($this->tree->SimulationRun->count() > 0)
  38 + {
  39 + $simulationRegionNodes = $this->createSimulationRegionNodes(trim($simulationModel->getAttribute('xml:id')));
  40 + foreach ( $simulationRegionNodes as $node )
  41 + $simulationModel->appendChild($node);
  42 + }
  43 + $missionNodes[] = $simulationModel;
  44 + }
  45 + }
  46 +
  47 + return $missionNodes;
  48 + }
  49 +
  50 +}
  51 +?>
... ...
php/RemoteDataCenter/SimulationDataCenterClass.php 0 โ†’ 100644
... ... @@ -0,0 +1,499 @@
  1 +<?php
  2 +/**
  3 + * @class SimulationDataCenterClass
  4 + * @brief
  5 + * @details
  6 + */
  7 +class SimulationDataCenterClass extends RemoteDataCenterClass
  8 +{
  9 +
  10 + protected $paramPrefix = "spase___IMPEX_NumericalOutput_";
  11 +
  12 + protected $impex_pairs = array("/" => "_", ":" => "_", "?" => "_", '+' => "_");
  13 +
  14 + public $alongOrbit = true;
  15 + /*
  16 + * @brief init
  17 + */
  18 + protected function getRemoteTree()
  19 + {
  20 + $this->tree = simplexml_load_file($this->url."/".$this->treeXML);
  21 + }
  22 +
  23 + protected function setDataCenterAttributes()
  24 + {
  25 + $this->dataCenter->setAttribute('desc', $this->tree->Repository->ResourceHeader->Description.'<br/> ReleaseDate: '.$this->tree->Repository->ResourceHeader->ReleaseDate);
  26 + $this->dataCenter->setAttribute('isSimulation', "true");
  27 + }
  28 +
  29 + public function init() {}
  30 +
  31 + // 1-st level : "Mission" : SimulationModel
  32 + protected function createMissionNodes()
  33 + {
  34 + $missionNodes = array();
  35 +
  36 + foreach ($this->tree->SimulationModel as $sm)
  37 + {
  38 + $ResourceID = trim($sm->ResourceID);
  39 +
  40 + $simulationModel = $this->domAmda->createElement('simulationModel');
  41 +
  42 + $simulationModel->setAttribute('xml:id', $sm->ResourceID);
  43 + $simulationModel->setAttribute('name', $sm->ResourceHeader->ResourceName);
  44 +
  45 + $simulationModel->setAttribute('desc', $sm->ResourceHeader->Description.'<br/> ReleaseDate: '.$sm->ResourceHeader->ReleaseDate);
  46 + $this->setModelHelp($simulationModel,"");
  47 +
  48 + if ($this->tree->SimulationRun->count() > 0)
  49 + {
  50 + $simulationRegionNodes = $this->createSimulationRegionNodes(trim($simulationModel->getAttribute('xml:id')));
  51 + foreach ( $simulationRegionNodes as $node )
  52 + $simulationModel->appendChild($node);
  53 + }
  54 + $missionNodes[] = $simulationModel;
  55 + }
  56 +
  57 + return $missionNodes;
  58 + }
  59 +
  60 + protected function setModelHelp($node, $helpFile){}
  61 +
  62 + protected function setHelpAttribute($node, $helpFile)
  63 + {
  64 + $node->setAttribute('att', $helpFile);
  65 + }
  66 +
  67 + // 2-nd level : SimulatedRegion of SimulationRun
  68 + protected function createSimulationRegionNodes($modelId)
  69 + {
  70 + if (file_exists(DATAPATH.'rank.json'))
  71 + $cmpArr = json_decode(file_get_contents(DATAPATH.'rank.json'), true);
  72 + else
  73 + $cmpArr = null;
  74 +
  75 + $simRegions = array();
  76 + $simulationRegionNodes = array();
  77 +
  78 + foreach($this->tree->SimulationRun as $sr)
  79 + {
  80 + if (trim($sr->Model->ModelID) == $modelId)
  81 + {
  82 + $simReg = trim($sr->SimulatedRegion);
  83 + if (! in_array($simReg, $simRegions))
  84 + {
  85 + $simRegions[] = $simReg;
  86 + // add SimReg to TargetsSimu.xml
  87 + $this->addSimulatedRegionToTargetsFile($simReg,
  88 + $sr->SimulationDomain->CoordinateSystem->CoordinateSystemName);
  89 +
  90 + echo '$simRegions =>'.$sr->SimulatedRegion.PHP_EOL;
  91 + $simuRegion=$this->domAmda->createElement('simulationRegion');
  92 + $simuRegion->setAttribute('xml:id', $this->baseID.'_'.$simReg);
  93 + $simuRegion->setAttribute('name', $simReg);
  94 + if (is_array($cmpArr))
  95 + {
  96 + $target = explode('.',$simReg);
  97 + $index = $cmpArr[$target[0]];
  98 + if ($index)
  99 + $simuRegion->setAttribute('rank',$index);
  100 + else
  101 + $simuRegion->setAttribute('rank', 999);
  102 + }
  103 + $this->setHelpAttribute($simuRegion, "simu/simu$simReg");
  104 + $simulationRegionNodes[] = $simuRegion;
  105 + }
  106 +
  107 + $runNode = $this->createSimulationRunNode($sr);
  108 + $this->setSimulationRunNodeDescription($runNode,$sr);
  109 +
  110 + foreach ($simulationRegionNodes as $node)
  111 + {
  112 + if ($node->getAttribute('xml:id') == $this->baseID.'_'.$simReg)
  113 + {
  114 + $node->appendChild($runNode);
  115 + }
  116 + }
  117 + }
  118 + }
  119 + return $simulationRegionNodes;
  120 + }
  121 +
  122 + // 3-rd level : SimulationRun
  123 + protected function createSimulationRunNode($sr)
  124 + {
  125 + //$idSimulationRun = $sr->ResourceID;
  126 + $runNode = $this->domAmda->createElement('runID');
  127 + $runNode->setAttribute('xml:id', $sr->ResourceID);
  128 + $runNode->setAttribute('name', $sr->ResourceHeader->ResourceName);
  129 +
  130 + foreach ($this->tree->NumericalOutput as $no)
  131 + {
  132 + if (((trim($no->InputResourceID) == $sr->ResourceID) || (trim($no->SimulationRunID) == $sr->ResourceID))
  133 + && ((trim($no->SimulationProduct) == "3DCubes") || (trim($no->SimulationProduct) == "Spectra")))
  134 + {
  135 + if (trim($no->SimulationProduct) == "Spectra")
  136 + $isSpectra = true;
  137 + else
  138 + $isSpectra = false;
  139 +
  140 + $datasetNode = $this->createDatasetNode($no, $isSpectra);
  141 + $runNode->appendChild($datasetNode);
  142 + }
  143 + }
  144 + return $runNode;
  145 + }
  146 +
  147 + // 4-th level : NumericalOutput (dataset)
  148 + protected function createDatasetNode($no, $isSpectra = false)
  149 + {
  150 + $dsNode = $this->domAmda->createElement('dataset');
  151 + $dsNode->setAttribute('xml:id', trim($no->ResourceID));
  152 + $dsName = $this->getDatasetName($no);
  153 + $dsNode->setAttribute('name', $dsName);
  154 +
  155 + $paramNodes = $this->createParameterNodes($no->Parameter, trim($no->ResourceID), $isSpectra);
  156 +
  157 + foreach ($paramNodes as $node)
  158 + {
  159 + $dsNode->appendChild($node);
  160 + }
  161 +
  162 + // Special case of IPIM
  163 + if ($this->hasAccessUrl)
  164 + {
  165 + $dsNode->setAttribute('accessUrl', $this->getAccessUrl($no));
  166 + $dsNode->setAttribute('globalStart', $this->getStartTime($no));
  167 + $dsNode->setAttribute('globalStop', $this->getStopTime($no));
  168 + $dsNode->setAttribute('desc', 'TimeRange : '.$this->getStartTime($no)."-".$this->getStopTime($no));
  169 +
  170 + }
  171 + else
  172 + {
  173 + $dsNode->setAttribute('globalStart', 'depending on mission');
  174 + }
  175 +
  176 + return $dsNode;
  177 + }
  178 +
  179 + protected function getDatasetName($no)
  180 + {
  181 + if (trim($no->ResourceHeader->ResourceName) != '')
  182 + return trim($no->ResourceHeader->ResourceName);
  183 + else
  184 + return trim($no->ResourceID);
  185 + }
  186 +
  187 + protected function hasComponents($param)
  188 + {
  189 + if ($param->Particle->Qualifier)
  190 + {
  191 + return $param->Particle->Qualifier != "Scalar" && $param->Particle->Qualifier != "Total";
  192 +
  193 + }
  194 + if ($param->Field->Qualifier)
  195 + {
  196 + return $param->Field->Qualifier != "Scalar" && $param->Field->Qualifier != "Total";
  197 + }
  198 +
  199 + if (strpos(trim($param->ParameterKey), ',') === false)
  200 + $comps = explode(' ',trim($param->ParameterKey));
  201 + else
  202 + $comps = explode(',',trim($param->ParameterKey));
  203 +
  204 + return count($comps) > 1;
  205 + }
  206 +
  207 + // 5-th level : Parameters & Components
  208 + protected function createParameterNodes($params, $dsid, $isSpectra = false)
  209 + {
  210 + $paramNodes = array();
  211 + foreach ($params as $param)
  212 + {
  213 + $paramNode = $this->domAmda->createElement('parameter');
  214 + //$p = trim($sm->ResourceID).'/'.$argumentsParameterKey;
  215 + $id = $this->param2dd($dsid."/".$param->ParameterKey);
  216 + $paramNode->setAttribute('xml:id',$id);
  217 + $paramNode->setAttribute('name', $param->Name);
  218 + $paramNode->setAttribute('desc', 'Units: '.$param->Units);
  219 + $paramNode->setAttribute('needsArgs', $this->needsArgs);
  220 + $paramNode->setAttribute('units', $param->Units);
  221 +
  222 + if (!$isSpectra)
  223 + {
  224 + if ($this->hasComponents($param))
  225 + {
  226 + if (strpos(trim($param->ParameterKey), ',') === false)
  227 + $comps = explode(' ',trim($param->ParameterKey));
  228 + else
  229 + $comps = explode(',',trim($param->ParameterKey));
  230 +
  231 + $paramNode->setAttribute('size', count($comps));
  232 +
  233 + foreach ($comps as $comp)
  234 + {
  235 + $compNode = $this->domAmda->createElement('component');
  236 + // $compNode->setAttribute('xml:id', $id."_".$comp);
  237 + $compNode->setAttribute('xml:id', $this->param2dd($dsid."_".$comp));
  238 + $compNode->setAttribute('name', $comp);
  239 + $compNode->setAttribute('shortName',$comp);
  240 + $compNode->setAttribute('needsArgs', $this->needsArgs);
  241 +
  242 + $paramNode->appendChild($compNode);
  243 + }
  244 + }
  245 + $paramNode->setAttribute('shortName',$param->ParameterKey);
  246 + }
  247 + else
  248 + {
  249 + $paramNode->setAttribute('size', $this->getEnergyBinsNumber($param));
  250 + $paramNode->setAttribute('display_type', 'spectrogram');
  251 + $paramNode->setAttribute('isSpectra', true);
  252 + $paramNode->setAttribute('energyRange', 'EnergyRange'); // check if it allways so - should be ! SPASE
  253 + $paramNode->setAttribute('shortName','ParticleFlux');
  254 + $paramNode->setAttribute('energyUnits',$param->Particle->EnergyRange->Units);
  255 + }
  256 +
  257 + $paramNodes[] = $paramNode;
  258 + }
  259 +
  260 + return $paramNodes;
  261 + }
  262 +
  263 + // EnergyBinsNumber
  264 + protected function getEnergyBinsNumber($param)
  265 + {
  266 + return count($param->Particle->EnergyRange->Bin);
  267 + }
  268 +
  269 + // Run Description
  270 + protected function getCoordinateSystem($coordSystem)
  271 + {
  272 + return "<b>Reference Frame :</b><br/>".$coordSystem->CoordinateSystemName.",".$coordSystem->CoordinateRepresentation;
  273 + }
  274 + //
  275 + protected function getRegionBoundaries($domain, $region)
  276 + {
  277 + $simReg = explode(".", $region->SimulatedRegion);
  278 + $desc = "<b><br/>Domain: </b>Units: radius of ".$simReg[0]."<br/>";
  279 + // Recalcul domain from km or m to rad
  280 + $unitsDomain = $domain->Units;
  281 +
  282 + $spatialDimension = $domain->SpatialDimension;
  283 + $radius = $region->Radius;
  284 +
  285 + $regionParameterRadius = trim($region->Radius['Units']);
  286 + $radiusUnits = trim($domain->Units);
  287 +
  288 + $ValidMinsDom = preg_split ("/\s+/", $domain->ValidMin);
  289 + $ValidMaxsDom = preg_split ("/\s+/", $domain->ValidMax);
  290 + $coordLabel = preg_split ("/\s+/",$domain->CoordinatesLabel);
  291 + // Transform Simulation Domain to Martian radius from km & m
  292 + for($j=0; $j< $spatialDimension; $j++)
  293 + {
  294 + if ((strtolower($radiusUnits) == 'km') || (strtolower($radiusUnits)== 'm'))
  295 + {
  296 + if ($regionParameterRadius != $radiusUnits)
  297 + {
  298 + if (strtolower($radiusUnits) == 'km') $radius = ($region->Radius)/1000;
  299 + else $radius = ($region->Radius) * 1000;
  300 + }
  301 +
  302 + $ValidMinsDom[$j] = number_format($ValidMinsDom[$j]/$radius,2);
  303 + $ValidMaxsDom[$j] = number_format($ValidMaxsDom[$j]/$radius,2);
  304 + }
  305 +
  306 + $desc .= $coordLabel[$j]."=[".$ValidMinsDom[$j].', '.$ValidMaxsDom[$j]."]<br/>";
  307 +
  308 + }
  309 + return $desc;
  310 + }
  311 +
  312 + protected function setSimulationRunNodeDescription($runNode,$sr)
  313 + {
  314 + }
  315 +
  316 + protected function getProperties($sr)
  317 + {
  318 + }
  319 +
  320 + protected function addSimulatedRegionToTargetsFile($simReg, $coordName)
  321 + {
  322 + $TargetsXml = new DomDocument("1.0");
  323 + $TargetsXml->formatOutput = TRUE;
  324 + $TargetsXml->preserveWhiteSpace = FALSE;
  325 +
  326 + if (file_exists(SimuTargetsXml))
  327 + {
  328 + $TargetsXml->load(SimuTargetsXml);
  329 + $rootElement = $TargetsXml->documentElement;
  330 + }
  331 + else
  332 + {
  333 + $rootElement = $TargetsXml->createElement('Targets');
  334 + $TargetsXml->appendChild($rootElement);
  335 + }
  336 +
  337 + $targetNode = $TargetsXml->getElementById($simReg);
  338 +
  339 + if ($targetNode == null)
  340 + {
  341 + $simRegMain = explode(".",$simReg);
  342 + $targetNode = $TargetsXml->createElement("Target", $simReg);
  343 + $targetNode->setAttribute('CoordName',$coordName);
  344 + $targetNode->setAttribute('TargetMain',$simRegMain[0]);
  345 + $targetNode->setAttribute('xml:id',$simReg);
  346 + $targetNode->setAttribute($this->baseID,true);
  347 + $rootElement->appendChild($targetNode);
  348 + }
  349 + // add Simulation Data Center to existing target
  350 + else
  351 + {
  352 + $targetNode = $targetNode->setAttribute($this->baseID,true);
  353 + }
  354 +
  355 + $TargetsXml->save(SimuTargetsXml);
  356 + }
  357 +
  358 + public function getFileName($resourceID, $templateArgs, $start)
  359 + {
  360 + $fileName = strtr($resourceID, $this->impex_pairs);
  361 + foreach ($templateArgs as $key => $value)
  362 + $fileName .= "_".$value;
  363 +
  364 +
  365 + $fileName .= "_".$start.'.xml';
  366 +
  367 + return $fileName;
  368 + }
  369 +
  370 + public function getMask($resourceID, $templateArgs)
  371 + {
  372 + $fileMask = strtr($resourceID, $this->impex_pairs);
  373 + foreach ($templateArgs as $key => $value)
  374 + $fileMask .= "_".$value;
  375 +
  376 + $fileMask .= '*.xml';
  377 +
  378 + return $fileMask;
  379 + }
  380 +
  381 + public function makeArgumentsList()
  382 + {
  383 + if (!file_exists(SimuTargetsXml))
  384 + exit('NOT YET!'.PHP_EOL);
  385 +
  386 + if (file_exists($this->templateFile))
  387 + unlink($this->templateFile);
  388 +
  389 + $TemplatesXml = new DomDocument("1.0");
  390 + $TemplatesXml->formatOutput = TRUE;
  391 + $TemplatesXml->preserveWhiteSpace = FALSE;
  392 +
  393 + $rootNode = $TemplatesXml->createElement('paramTemplateList');
  394 + $TemplatesXml->appendChild($rootNode);
  395 +
  396 + $TargetsXml = new DomDocument("1.0");
  397 + $TargetsXml->load(SimuTargetsXml);
  398 + $targets = $TargetsXml->getElementsByTagName('Target');
  399 + foreach ($targets as $target)
  400 + {
  401 + if ($target->hasAttribute($this->baseID))
  402 + {
  403 + echo $target->getAttribute('xml:id').PHP_EOL;
  404 + $paramNode = $TemplatesXml->createElement('paramTemplate');
  405 + $paramNode->setAttribute('paramId',$this->baseID."_".$this->param2dd($target->getAttribute('xml:id')));
  406 + $paramNode->setAttribute('fileName','##orbit##');
  407 + $argsNode = $TemplatesXml->createElement('arguments');
  408 + $paramNode->appendChild($argsNode);
  409 + $specialNodes = $this->createSpecialArgs($TemplatesXml);
  410 +
  411 + foreach ($specialNodes as $specialNode)
  412 + $argsNode->appendChild($specialNode);
  413 +
  414 + $missionGrps = json_decode(file_get_contents(RemoteData.$target->nodeValue.".json"), true);
  415 + $node = $TemplatesXml->createElement('argument');
  416 + $node->setAttribute('key', 'url_XYZ');
  417 + $node->setAttribute('name', 'Mission Name');
  418 + $node->setAttribute('type', 'list');
  419 + foreach ($missionGrps as $grp => $missions)
  420 + {
  421 + foreach ( $missions as $mission => $datasets)
  422 + {
  423 + echo 'MISSION: '.$mission.PHP_EOL;
  424 + foreach ($datasets as $dataset => $parameters)
  425 + {
  426 + echo " ".$dataset.PHP_EOL;
  427 + foreach ($parameters as $param => $value)
  428 + {
  429 + $item = $TemplatesXml->createElement('item');
  430 + $item->setAttribute('name', $mission);
  431 + $item->setAttribute('key', $value);
  432 +
  433 + $node->appendChild($item);
  434 + }
  435 + }
  436 + }
  437 + }
  438 + //TODO select default s/c for each target
  439 + $node->setAttribute('default', $value);
  440 + $argsNode->appendChild($node);
  441 + $rootNode->appendChild($paramNode);
  442 + }
  443 + }
  444 + $TemplatesXml->save(RemoteData.$this->baseID.'/'.$this->templateFile);
  445 + }
  446 +
  447 + protected function createSpecialArgs($dom = null)
  448 + {
  449 + return array();
  450 + }
  451 +
  452 + public function getTableDefinition()
  453 + {
  454 + $res = array();
  455 + $res["tableDefType"] = "SELECT";
  456 + $res["channelsDefType"] = "BOUND";
  457 + $res["data"] = array();
  458 + $res["data"]["bound"] = $this->energyTableName;
  459 +
  460 + return $res;
  461 + }
  462 +
  463 + public function getData($params, $isSpectra = false)
  464 + {
  465 +// $r = print_r($params,true);
  466 +// error_log($r,3,'/home/budnik/LOG');
  467 +
  468 + try
  469 + {
  470 + $client = new SoapClient($this->url."/".$this->WSDL,
  471 + array(
  472 + 'wsdl_cache' => 0,
  473 + 'trace' => 1,
  474 + 'soap_version'=>SOAP_1_2
  475 + ));
  476 + }
  477 + catch (SoapFault $exception)
  478 + {
  479 + throw new Exception($exception->getMessage()." ".$exception->getTraceAsString());
  480 + }
  481 +
  482 + if ($isSpectra)
  483 + $soapMethod = $this->soapMethodSpectra;
  484 + else
  485 + $soapMethod = $this->soapMethod;
  486 +
  487 + try
  488 + {
  489 + $file = $client->__soapCall($soapMethod, array($params));
  490 + }
  491 + catch (SoapFault $exception)
  492 + {
  493 + throw new Exception($exception->getMessage()." ".$exception->getTraceAsString());
  494 + }
  495 +
  496 + return $file;
  497 + }
  498 +}
  499 +?>
... ...
php/RemoteDataCenter/makeArgs.php 0 โ†’ 100644
... ... @@ -0,0 +1,27 @@
  1 +<?php
  2 +/*
  3 +* Executable to make arguments lists for IMPEX
  4 +* Uses target.json
  5 +*/
  6 + require_once "../config.php";
  7 +
  8 + if (!defined('SimuTargetsXml'))
  9 + exit('SimuTargetsXml is not defined in config.php'.PHP_EOL);
  10 +
  11 + if (!function_exists('__autoload')) {
  12 + function __autoload($class_name) {
  13 + require_once $class_name . '.php';
  14 + }
  15 + }
  16 +
  17 + $simuBases = array("LATMOS", "FMI_HYBRID", "FMI_GUMICS", "LESIA");
  18 +
  19 + foreach ($simuBases as $class)
  20 + {
  21 + echo PHP_EOL.$class.PHP_EOL;
  22 + $center = new $class();
  23 +
  24 + $center->makeArgumentsList();
  25 + }
  26 +
  27 +?>
0 28 \ No newline at end of file
... ...
php/RemoteDataCenter/makeOrbitsArgs.php 0 โ†’ 100644
... ... @@ -0,0 +1,82 @@
  1 +<?php
  2 +/*
  3 +* Executable to make target.json files for IMPEX url_XYZ args
  4 +* is launched AFTER makeProxy and makeOrbitsList
  5 +*/
  6 +
  7 + require_once "../config.php";
  8 +
  9 + if (!defined('orbitsXml'))
  10 + exit("orbitsXml is not defined in config.php".PHP_EOL);
  11 +
  12 + if (!defined('SimuTargetsXml'))
  13 + exit('SimuTargetsXml is not defined in config.php'.PHP_EOL);
  14 +
  15 + if (!file_exists(orbitsXml))
  16 + exit("ERROR : NO Orbites.xml FILE !!! Run makeOrbitsList.php".PHP_EOL);
  17 +
  18 + if (!file_exists(SimuTargetsXml))
  19 + exit("ERROR : NO TargetsSimu FILE !!! Run makeProxy.php".PHP_EOL);
  20 +
  21 + $targetXml = simplexml_load_file(SimuTargetsXml);
  22 + $orbitsXml = new DomDocument("1.0");
  23 + $orbitsXml->load(orbitsXml);
  24 + $xpath = new DOMXpath($orbitsXml);
  25 +
  26 + $targets = $targetXml->Target;
  27 +
  28 + foreach ($targets as $target)
  29 + {
  30 + if (file_exists(RemoteData."$target.json"))
  31 + unlink(RemoteData."$target.json");
  32 +
  33 + $targetMain = $target['TargetMain'];
  34 + $coordImpex = $target['CoordName'];
  35 +
  36 + // Mecrury double definition
  37 + if ($coordImpex == "HSM")
  38 + $coordImpex == "MSM";
  39 +
  40 + // general case
  41 + $params = $xpath->query('//orbites[@target="'.$target.'" and @coordinate_system="'.$coordImpex.'"]');
  42 +
  43 + // case of targetImpex = Jupiter.Magnetosphere; targetAmda = Jupiter
  44 + if ($params->length == 0)
  45 + $params = $xpath->query('//orbites[@target="'.$targetMain.'" and @coordinate_system="'.$coordImpex.'"]');
  46 +
  47 + // case of targetImpex = Ganymede; targetAmda = Jupiter.Ganymede
  48 + if ($params->length == 0)
  49 + // $params = $xpath->query('//orbites[contains(@target,"'.$target.')" and @coordinate_system="'.$coordImpex.'"]');
  50 + $params = $xpath->query('//orbites[contains(@target,"'.$target.'")]');
  51 +
  52 + if ($params->length > 0)
  53 + {
  54 + $dsArr = array();
  55 + $misArr = array();
  56 + $misGrpArr = array();
  57 +
  58 + foreach ($params as $param)
  59 + {
  60 + $dsId = $param->getAttribute('dataset');
  61 +
  62 + if (!is_array($dsArr[$dsId])) $dsArr[$dsId] = array();
  63 + $dsArr[$dsId][] = $param->getAttribute('xml:id');
  64 +
  65 + $misId = $param->getAttribute('mission');
  66 + if (!is_array($misArr[$misId])) $misArr[$misId] = array();
  67 + $misArr[$misId][$dsId] = $dsArr[$dsId];
  68 +
  69 + // Mission Group
  70 + if ($param->hasAttribute('missionGroup'))
  71 + $misGrpId = $param->getAttribute('missionGroup');
  72 + else
  73 + $misGrpId = 'None';
  74 +
  75 + if (!is_array($misGrpArr[$misGrpId])) $misGrpArr[$misGrpId] = array();
  76 + $misGrpArr[$misGrpId][$misId] = $misArr[$misId];
  77 + }
  78 +
  79 + file_put_contents(RemoteData.$target.'.json', json_encode($misGrpArr));
  80 + }
  81 + }
  82 +?>
0 83 \ No newline at end of file
... ...
php/RemoteDataCenter/makeOrbitsList.php 0 โ†’ 100644
... ... @@ -0,0 +1,76 @@
  1 +<?php
  2 +/*
  3 +* Executable to make Orbits.xml with the description for all Ephemeris parameters
  4 +* Uses LocalParams.xml and AMDA params descriptions
  5 +*/
  6 + require_once "../config.php";
  7 +
  8 + if (!defined('orbitsXml'))
  9 + exit("orbitsXml is not defined in config.php".PHP_EOL);
  10 +
  11 + $pairs = array("-" => "_" );
  12 +
  13 + $amdaXml = new DomDocument("1.0");
  14 + $amdaXml->load(DATAPATH."LocalParams.xml");
  15 +
  16 + $xpath = new DOMXpath($amdaXml);
  17 +
  18 + $amdaParamDir = DATAPATH."newKernelDDBase";
  19 +
  20 + $orbitsXml = new DomDocument("1.0");
  21 + $orbitsXml->formatOutput = TRUE;
  22 + $orbitsXml->preserveWhiteSpace = FALSE;
  23 +
  24 + $orbitsRoot = $orbitsXml->createElement('orbitesList');
  25 + $orbitsXml->appendChild($orbitsRoot);
  26 +
  27 + $nodesAmda = $xpath->query('//*[@target]');
  28 +
  29 + foreach ($nodesAmda as $node)
  30 + {
  31 + $target = $node->getAttribute('target');
  32 +
  33 + if ( (($node->tagName == 'mission' && $node->getElementsByTagName('observatory')->length == 0) ||
  34 + ($node->tagName == 'observatory') ) && $node->getAttribute('name') != $target )
  35 + {
  36 + $instruments = $node->getElementsByTagName('instrument');
  37 + foreach ($instruments as $ins)
  38 + {
  39 + if ($ins->getAttribute('name') != 'Ephemeris') continue;
  40 + $parameters = $ins->getElementsByTagName('parameter');
  41 + foreach ($parameters as $parameter)
  42 + {
  43 + if ($parameter->hasAttribute('size') && $parameter->getAttribute('size') == '3')
  44 + {
  45 + $param_file = $amdaParamDir."/".$parameter->getAttribute('xml:id').".xml";
  46 + if (file_exists($param_file))
  47 + {
  48 + $paramXml = simplexml_load_file($param_file);
  49 +
  50 + $orbitNode = $orbitsXml->createElement('orbites');
  51 + $dsId = strtr($paramXml->info->dataset_id,$pairs);
  52 + $orbitNode->setAttribute('xml:id',$parameter->getAttribute('xml:id'));
  53 + $orbitNode->setAttribute('coordinate_system', $paramXml->info->coordinates_system);
  54 + $orbitNode->setAttribute('units', $paramXml->info->units);
  55 + $orbitNode->setAttribute('mission', $node->getAttribute('name'));
  56 +
  57 + if ( $node->tagName == 'observatory' )
  58 + $orbitNode->setAttribute('missionGroup',$node->parentNode->getAttribute('name'));
  59 +
  60 + $orbitNode->setAttribute('dataset', $dsId);
  61 + $ds = $amdaXml->getElementById($paramXml->info->dataset_id);
  62 + if ($ds->hasAttribute('target'))
  63 + $orbitNode->setAttribute('target', $ds->getAttribute('target'));
  64 + else
  65 + $orbitNode->setAttribute('target', $target);
  66 +
  67 + $orbitsRoot->appendChild($orbitNode);
  68 + }
  69 + }
  70 + }
  71 + }
  72 + }
  73 + }
  74 +
  75 + $orbitsXml->save(orbitsXml);
  76 +?>
... ...
php/RemoteDataCenter/makeProxy.php 0 โ†’ 100644
... ... @@ -0,0 +1,31 @@
  1 +<?php
  2 +/*
  3 +* Executable to make 'base.xml' proxies for IMPEX centers from IMPEX original trees
  4 +*/
  5 +
  6 + if (!function_exists('__autoload')) {
  7 + function __autoload($class_name) {
  8 + require_once $class_name . '.php';
  9 + }
  10 + }
  11 +
  12 + require_once "../config.php";
  13 +
  14 + if (!defined('SimuTargetsXml')
  15 + exit('SimuTargetsXml is not defined in config.php'.PHP_EOL);
  16 +
  17 + if (file_exists(SimuTargetsXml)) unlink(SimuTargetsXml);
  18 +
  19 + $simuBases = array("IPIM", "LATMOS", "FMI_HYBRID", "FMI_GUMICS", "SINP", "LESIA");
  20 +
  21 + foreach ($simuBases as $class)
  22 + {
  23 + echo PHP_EOL.$class.PHP_EOL;
  24 + $center = new $class();
  25 +
  26 + $center->initProxy();
  27 + $center->makeProxy();
  28 + $center->saveProxy();
  29 + }
  30 +
  31 +?>
0 32 \ No newline at end of file
... ...
php/classes/AmdaAction.php
... ... @@ -352,10 +352,13 @@ class AmdaAction
352 352 break;
353 353  
354 354 case 'remoteSimuParam' :
355   -
  355 +
  356 + $globalStart = null;
  357 +
356 358 $isSimulation = true;
357   -
358   - if ($id == 'spase://IMPEX/SimulationModel/FMI/GUMICS' )
  359 +
  360 + if ($child->getAttribute('isAddable'))
  361 + //if ($id == 'spase://IMPEX/SimulationModel/FMI/GUMICS' )
359 362 {
360 363 $isLeaf = false;
361 364 $isAddable = true;
... ... @@ -375,7 +378,25 @@ class AmdaAction
375 378 {
376 379 $rank = $child->getAttribute('rank');
377 380 }
378   -
  381 +
  382 + if ( $child->tagName == 'parameter')
  383 + {
  384 + if ($child->parentNode->hasAttribute('globalStart'))
  385 + {
  386 + $globalStart = $child->parentNode->getAttribute('globalStart');
  387 + $globalStop = $child->parentNode->getAttribute('globalStop');
  388 + }
  389 + }
  390 +
  391 + if ( $child->tagName == 'component')
  392 + {
  393 + if ($child->parentNode->parentNode->hasAttribute('dataStart'))
  394 + {
  395 + $globalStart = $child->parentNode->parentNode->getAttribute('dataStart');
  396 + $globalStop = $child->parentNode->parentNode->getAttribute('dataStop');
  397 + }
  398 + }
  399 +
379 400 case 'remoteParam' :
380 401  
381 402 if ($child->getAttribute('isSimulation') && $child->tagName == 'dataCenter')
... ... @@ -446,11 +467,16 @@ class AmdaAction
446 467 $isScatter = false;
447 468 $isSpectra = true;
448 469 }
449   -
450   - $childrenToReturn[] = array('text' => $name,'alias' => $alias,
451   - 'id' => $id,'nodeType' => $nodeType, 'info' => $info, 'help' => $help,
452   - 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter,
453   - 'isScatter' => $isScatter, 'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info);
  470 + if ($globalStart)
  471 + $childrenToReturn[] = array('text' => $name,'alias' => $alias,
  472 + 'id' => $id,'nodeType' => $nodeType, 'info' => $info, 'help' => $help, 'globalStart' => $globalStart,
  473 + 'globalStop' => $globalStop, 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter,
  474 + 'isScatter' => $isScatter, 'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info);
  475 + else
  476 + $childrenToReturn[] = array('text' => $name,'alias' => $alias,
  477 + 'id' => $id,'nodeType' => $nodeType, 'info' => $info, 'help' => $help,
  478 + 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter,
  479 + 'isScatter' => $isScatter, 'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info);
454 480 }
455 481 else
456 482 {
... ... @@ -579,7 +605,7 @@ class AmdaAction
579 605 default:
580 606 return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
581 607 }
582   - return $objectMgr -> getUploadedObject($name, $format, true);
  608 + return $objectMgr->getUploadedObject($name, $format, true);
583 609  
584 610 }
585 611  
... ... @@ -589,13 +615,13 @@ class AmdaAction
589 615 public function getAsciiFile($obj)
590 616 {
591 617 $objectMgr = new FilesMgr();
592   - return $objectMgr -> getAsciiFile($obj->fileName);
  618 + return $objectMgr->getAsciiFile($obj->fileName);
593 619 }
594 620  
595   - public function getMyParamInfo($object)
  621 + public function getMyParamInfo($object)
596 622 {
597 623 $objectMgr = new FilesMgr();
598   - return $objectMgr -> getParamInfo($object);
  624 + return $objectMgr->getParamInfo($object);
599 625 }
600 626  
601 627 /*
... ... @@ -614,7 +640,7 @@ class AmdaAction
614 640 default:
615 641 return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
616 642 }
617   - return $objectMgr -> getTmpObject($folderId, $name, true);
  643 + return $objectMgr->getTmpObject($folderId, $name, true);
618 644 }
619 645  
620 646  
... ... @@ -639,7 +665,7 @@ class AmdaAction
639 665 $objectMgr = new RequestMgr($nodeType);
640 666 break;
641 667 case 'bkgWorks' :
642   - require_once(INTEGRATION_SRC_DIR."RequestManager.php");
  668 + require_once(INTEGRATION_SRC_DIR."RequestManager.php");
643 669 return $this->executeRequest($id, FunctionTypeEnumClass::PROCESSGETINFO);
644 670 break;
645 671 case 'myData' :
... ... @@ -648,7 +674,7 @@ class AmdaAction
648 674 default:
649 675 return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
650 676 }
651   - return $objectMgr -> getObject($id, $nodeType);
  677 + return $objectMgr->getObject($id, $nodeType);
652 678 }
653 679  
654 680 /*
... ... @@ -677,7 +703,7 @@ class AmdaAction
677 703 $obj->id = substr($obj->id,strlen('alias_'));
678 704 break;
679 705 case 'bkgWorks' :
680   - require_once(INTEGRATION_SRC_DIR."RequestManager.php");
  706 + require_once(INTEGRATION_SRC_DIR."RequestManager.php");
681 707 return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSDELETE);
682 708  
683 709 case 'myData' :
... ... @@ -1224,10 +1250,6 @@ class AmdaAction
1224 1250 }
1225 1251 else
1226 1252 {
1227   - $myBaseMgr = new BaseManager();
1228   - $myBaseMgr->delSimuFiles('mysimudata');
1229   - $myBaseMgr->delSimuFiles('mywsrdata');
1230   -
1231 1253 $this->cleanUserWS();
1232 1254 }
1233 1255 return;
... ... @@ -1269,19 +1291,28 @@ class AmdaAction
1269 1291 public function addRun($obj)
1270 1292 {
1271 1293 $myBestRunsMgr = new BestRunsMgr();
1272   - $myBestRunsMgr->init();
  1294 +
  1295 + $ok = $myBestRunsMgr->init();
  1296 +
  1297 + if (!$ok)
  1298 + return array('success'=>false,'message'=>'cannot init addRun');
  1299 +
1273 1300 $myBestRunsMgr->addRuns($obj);
1274   -
1275   - $res = array('success' => true,'addedRuns' => $obj);
1276   - return $res;
  1301 +
  1302 + return array('success'=>true,'addedRuns'=>$obj);
1277 1303 }
1278 1304  
1279 1305 //AKKA - New action to clean user WS
1280 1306 public function cleanUserWS()
1281 1307 {
1282 1308 $this->rrmdir(USERDIR.'DOWNLOAD.TEMP');
1283   -
1284 1309 require_once(INTEGRATION_SRC_DIR."RequestManager.php");
  1310 + IHMConfigClass::setUserName($this->user);
  1311 +
  1312 + // delete impex params and data
  1313 + $impexParamMgr = new ImpexParamManager();
  1314 + $impexParamMgr->deleteImpexStaff();
  1315 +
1285 1316 return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSCLEAN);
1286 1317 }
1287 1318  
... ... @@ -1321,19 +1352,31 @@ class AmdaAction
1321 1352 public function getParamPlotInit($obj)
1322 1353 {
1323 1354 require_once(INTEGRATION_SRC_DIR."RequestManager.php");
  1355 + // IMPEX param
  1356 + if (preg_match("#^spase___IMPEX_#",$obj->paramId))
  1357 + $type = 'impex_plot_init';
  1358 + else
  1359 + $type = 'plot_init';
  1360 +
1324 1361 $inputobj = (Object)array(
1325 1362 'paramId' => $obj->paramId,
1326   - 'type' => 'plot_init'
  1363 + 'type' => $type
1327 1364 );
1328 1365 return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
1329 1366 }
1330 1367  
1331 1368 public function getParamInfo($obj)
1332 1369 {
1333   - require_once(INTEGRATION_SRC_DIR."RequestManager.php");
  1370 + require_once(INTEGRATION_SRC_DIR."RequestManager.php");
  1371 + // IMPEX param
  1372 + if (preg_match("#^spase___IMPEX_#",$obj->paramId))
  1373 + $type = 'impex_param_info';
  1374 + else
  1375 + $type = 'param_info';
  1376 +
1334 1377 $inputobj = (Object)array(
1335 1378 'paramId' => $obj->paramId,
1336   - 'type' => 'param_info'
  1379 + 'type' => $type
1337 1380 );
1338 1381 return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
1339 1382 }
... ...
php/classes/BaseManager.php 100755 โ†’ 100644
... ... @@ -7,254 +7,203 @@
7 7 *
8 8 */
9 9  
10   -class BaseManager {
11   -
12   - public $xp, $xslt;
13   - public $baseDom;
14   - private $fileDomName, $baseDomName;
15   -
16   - function __construct()
17   - {
18   - if (getenv('USER_DATA_PATH') != "")
19   - $this->baseDomName = getenv('USER_DATA_PATH')."base.xml";
20   - else
21   - $this->baseDomName = USERDATADIR."base.xml";
22   -
23   - $this->fileDomName = USERWSDIR."Files.xml";
24   - $this->baseDom = new DomDocument("1.0");
25   -
26   - if (file_exists($this->baseDomName))
27   - $this->baseDom->load($this->baseDomName);
28   - else {
29   - $baseElement = $this->baseDom->createElement("base");
30   - $this->baseDom->appendChild($baseElement);
31   - }
32   -
33   - $this->xp = new domxpath($this->baseDom);
34   - $this->xslt = new XSLTProcessor();
35   -
36   - $xsl = new DomDocument("1.0");
37   - $xsl->load(XMLPATH."base.xsl");
38   -
39   - $this->xslt->importStylesheet($xsl);
40   - }
  10 +class BaseManager
  11 +{
  12 + public $xp, $xslt;
  13 + public $baseDom;
  14 + private $fileDomName, $baseDomName;
  15 +
  16 + function __construct()
  17 + {
  18 + define("DELTA", 120); // minumum file size in secs
  19 +
  20 + if (getenv('USER_DATA_PATH') != "")
  21 + $this->baseDomName = getenv('USER_DATA_PATH')."base.xml";
  22 + else
  23 + $this->baseDomName = USERDATADIR."base.xml";
  24 +
  25 + $this->fileDomName = USERWSDIR."Files.xml";
  26 +
  27 + $this->baseDom = new DomDocument("1.0");
  28 +
  29 + if (file_exists($this->baseDomName))
  30 + $this->baseDom->load($this->baseDomName);
  31 + else {
  32 + $baseElement = $this->baseDom->createElement("base");
  33 + $this->baseDom->appendChild($baseElement);
  34 + }
  35 +
  36 + $this->xp = new domxpath($this->baseDom);
  37 + $this->xslt = new XSLTProcessor();
  38 +
  39 + $xsl = new DomDocument("1.0");
  40 + $xsl->load(XMLPATH."base.xsl");
  41 + $this->xslt->importStylesheet($xsl);
  42 + }
41 43  
42 44 /*
43 45 * Provide an unique ID
44 46 */
45   - public function getNewId()
46   - {
47   - // Get all ID attributes
48   - $vis = $this->xp->query("//vi/@id");
49   -
50   - if ($vis->length > 0) {
51   - $idList = array();
52   - if($vis->length > 0) for ($i = 0; $i < $vis->length; $i++)
53   - $idList[] = $vis->item($i)->nodeValue;
54   - sort($idList);
55   -
56   - for ($i = 0; $i < count($idList); $i++) {
57   - if ($idList[$i] > $i) {
58   - $newID = $i;
59   - break;
60   - }
61   - $newID = $i+1;
62   - }
63   - } else
64   - $newID = 0;
65   -
66   - return $newID;
67   - }
  47 + public function getNewId()
  48 + {
  49 + // Get all ID attributes
  50 + $vis = $this->xp->query("//vi/@id");
  51 +
  52 + if ($vis->length > 0) {
  53 + $idList = array();
  54 + if($vis->length > 0) for ($i = 0; $i < $vis->length; $i++)
  55 + $idList[] = $vis->item($i)->nodeValue;
  56 + sort($idList);
  57 +
  58 + for ($i = 0; $i < count($idList); $i++) {
  59 + if ($idList[$i] > $i) {
  60 + $newID = $i;
  61 + break;
  62 + }
  63 + $newID = $i+1;
  64 + }
  65 + } else
  66 + $newID = 0;
  67 +
  68 + return $newID;
  69 + }
68 70  
69   - public function fileMask($fileName, $maskName)
70   - {
71   - $mask = explode("*", $maskName);
72   -
73   - for ($i = 0; $i < count($mask); $i++)
74   - if ($mask[$i] != null)
75   - if (strpos($fileName, $mask[$i]) === false) return false;
76   - return true;
77   - }
78   -
79   -/*
80   -* new file is uploaded -> check if it should be added into MASK
81   -*/
82   - public function addFile($fileName)
83   - {
84   - $fileDom = new DomDocument("1.0");
85   - $fileDom->load($this->fileDomName);
86   - $file = $fileDom->getElementById($fileName);
87   - $lastMask = null;
88   -
89   - $masks = $this->baseDom->getElementsByTagName("mask");
90   -
91   - if ($masks->length > 0)
92   - {
93   - foreach ($masks as $mask)
94   - if ($this->fileMask($fileName, $mask->nodeValue))
95   - {
96   - $lastMask = $mask->nodeValue;
97   -
98   - $newFile = $this->baseDom->createElement("file");
99   - $newFile->setAttribute('name', $fileName);
100   - $start = $file->getAttribute('start');
101   - $stop = $file->getAttribute('stop');
102   - $newFile->setAttribute('start', $start);
103   - $newFile->setAttribute('stop', $stop);
104   -
105   - $vi = $mask->parentNode;
106   - $vi->appendChild($newFile);
107   -
108   - $vi_start = $vi->getAttribute('start');
109   - if ($vi_start > $start) $vi->setAttribute('start',$start);
110   - $vi_stop = $vi->getAttribute('stop');
111   - if ($vi_stop < $stop) $vi->setAttribute('stop',$stop);
112   - }
113   - }
114   -
115   - $this->xslt->transformToDoc($this->baseDom)->save($this->baseDomName);
116   -
117   - return $lastMask;
118   - }
119   -
120   -/*
121   -* special add method for "simulation" files
122   -*/
123   - public function addWsFile($fileName, $start, $stop)
124   - {
125   - // add file description to base.xml file
126   - $masks = $this->baseDom->getElementsByTagName("mask");
127   -
128   - if ($masks->length > 0)
129   - {
130   - foreach ($masks as $mask)
131   - if ($this->fileMask($fileName, $mask->nodeValue))
132   - {
133   - $lastMask = $mask->nodeValue;
134   - $newFile = $this->baseDom->createElement("file");
135   - $newFile->setAttribute('name', $fileName);
136   - $newFile->setAttribute('start', $start);
137   - $newFile->setAttribute('stop', $stop);
138   - $vi = $mask->parentNode;
139   - $vi->appendChild($newFile);
140   -
141   - $vi_start = $vi->getAttribute('start');
142   - if ($vi_start > $start) $vi->setAttribute('start',$start);
143   - $vi_stop = $vi->getAttribute('stop');
144   - if ($vi_stop < $stop) $vi->setAttribute('stop',$stop);
145   - }
146   - }
147   -
148   - $this->xslt->transformToDoc($this->baseDom)->save($this->baseDomName);
149   -
150   - return $lastMask;
151   - }
  71 + /*
  72 + * Get filename to create IMPEX parameter if VI exists already
  73 + */
  74 + public function getFirstFileName($viID)
  75 + {
  76 + $vis = $this->xp->query("//vi[@id = '".$viID."']");
  77 + if ($vis->length > 0)
  78 + $vi = $vis->item(0);
  79 + else
  80 + throw new Exception('No VI '.$viID);
  81 +
  82 + $files = $vi->getElementsByTagName('file');
  83 + if ($files->length > 0)
  84 + return $files->item(0)->getAttribute('name');
  85 +
  86 + throw new Exception('Empty VI '.$viID);
  87 + }
  88 +
  89 +
  90 + public function fileMask($fileName, $maskName)
  91 + {
  92 + $mask = explode("*", $maskName);
  93 +
  94 + for ($i = 0; $i < count($mask); $i++)
  95 + if ($mask[$i] != null)
  96 + if (strpos($fileName, $mask[$i]) === false) return false;
  97 +
  98 + return true;
  99 + }
152 100  
  101 + /*
  102 + * New file is uploaded -> check if it should be added into MASK
  103 + */
  104 + public function addFile($fileName, $start = null, $stop = null)
  105 + {
  106 + // standard file upload : start / stop get from file
  107 + if (!$start)
  108 + {
  109 + $fileDom = new DomDocument("1.0");
  110 + $fileDom->load($this->fileDomName);
  111 + $file = $fileDom->getElementById($fileName);
  112 + $start = $file->getAttribute('start');
  113 + $stop = $file->getAttribute('stop');
  114 + }
  115 +
  116 + $lastMask = null;
  117 +
  118 + $masks = $this->baseDom->getElementsByTagName("mask");
  119 +
  120 + if ($masks->length > 0)
  121 + {
  122 + foreach ($masks as $mask)
  123 + if ($this->fileMask($fileName, $mask->nodeValue))
  124 + {
  125 + $lastMask = $mask->nodeValue;
  126 +
  127 + $newFile = $this->baseDom->createElement("file");
  128 + $newFile->setAttribute('name', $fileName);
  129 +
  130 + $newFile->setAttribute('start', $start);
  131 + $newFile->setAttribute('stop', $stop);
  132 +
  133 + $vi = $mask->parentNode;
  134 + $vi->appendChild($newFile);
  135 +
  136 + $vi_start = $vi->getAttribute('start');
  137 + if (!$vi_start || $vi_start > $start)
  138 + $vi->setAttribute('start',$start);
  139 +
  140 + $vi_stop = $vi->getAttribute('stop');
  141 + if (!$vi_stop || $vi_stop < $stop)
  142 + $vi->setAttribute('stop',$stop);
  143 + }
  144 + }
  145 + // sort by time
  146 + $this->xslt->transformToDoc($this->baseDom)->save($this->baseDomName);
  147 +
  148 + return $lastMask;
  149 + }
  150 +
153 151 /*
154 152 * File was deleted
155 153 */
156   - public function delFile($fileObj)
157   - {
158   - $start = $fileObj->getAttribute($start);
159   - $stop = $fileObj->getAttribute($stop);
160   - $vi = $fileObj->parentNode;
161   - $vi->removeChild($fileObj);
162   - $mask = $vi->getElementsByTagName("mask")->item(0)->nodeValue;
163   - $length = $vi->getElementsByTagName("file")->length;
164   -
165   - if ($length == 0)
166   - {
167   - $this->baseDom->getElementsByTagName("base")->item(0)->removeChild($vi);
168   - }
169   - else
170   - {
171   - $vi->setAttribute('start', $this->updateStart($vi));
172   - $vi->setAttribute('stop',$this->updateStop($vi));
173   - }
174   -
175   - $this->baseDom->save($this->baseDomName);
176   -
177   - return array('mask' => $mask, 'length' => $length);
178   - }
179   -
180   -/*
181   -* Delete simu VI and simu Download Files
182   -*/
183   - public function delSimuFiles($data)
184   - {
185   - if (file_exists(USERWSDIR.'WsParams.xml'))
186   - {
187   - $simuVIs = $this->xp->query("//vi[@moreData = 'true']");
188   - $dom = new DomDocument("1.0");
189   - $dom->load(USERWSDIR.'WsParams.xml');
190   - $xp = new domxpath($dom);
191   - $dataList = $data.'List';
192   - $mysimudataList = $dom->getElementsByTagName($dataList);
193   - foreach ($simuVIs as $simuVI)
194   - {
195   - $files = $simuVI->getElementsByTagName('file');
196   - foreach ($files as $file)
197   - {
198   - $fileName = $file->getAttribute('name');
199   - if (file_exists(USERDATADIR.$fileName)) unlink(USERDATADIR.$fileName);
200   - }
201   - $vi = $simuVI->getAttribute("id");
202   - $mask = $simuVI->getElementsByTagName('mask')->item(0)->nodeValue;
203   - if ((strpos($mask, 'CLWEB_') !== false && $data == "mywsrdata") || (strpos($mask, 'CLWEB_') === false && $data == "mysimudata")) {
204   - $mysimdata = $xp->query("//".$data."[@mask='".$mask."']/@*[namespace-uri()='http://www.w3.org/XML/1998/namespace' and local-name()='id']");
205   - $sumuParamName = $mysimdata->item(0)->nodeValue;
206   - $base = $simuVI->parentNode;
207   - $base->removeChild($simuVI);
208   -
209   - if (file_exists(USERWSDIR.$sumuParamName.'.xml'))
210   - unlink(USERWSDIR.$sumuParamName.'.xml');
211   - }
212   - }
213   -
214   - $mysimudata = $xp->query("//".$data."");
215   -
216   - if ($mysimudata->length > 0)
217   - {
218   - foreach($mysimudata as $simudata)
219   - $mysimudataList->item(0)->removeChild($simudata);
220   - }
221   -
222   - $dom->save(USERWSDIR.'WsParams.xml');
223   - $this->baseDom->save($this->baseDomName);
224   - }
225   -
226   - return;
227   - }
  154 + public function delFile($fileObj)
  155 + {
  156 + $start = $fileObj->getAttribute($start);
  157 + $stop = $fileObj->getAttribute($stop);
  158 + $vi = $fileObj->parentNode;
  159 + $vi->removeChild($fileObj);
  160 + $mask = $vi->getElementsByTagName("mask")->item(0)->nodeValue;
  161 + $length = $vi->getElementsByTagName("file")->length;
  162 +
  163 + if ($length == 0)
  164 + {
  165 + $this->baseDom->getElementsByTagName("base")->item(0)->removeChild($vi);
  166 + }
  167 + else
  168 + {
  169 + $vi->setAttribute('start', $this->updateStart($vi));
  170 + $vi->setAttribute('stop',$this->updateStop($vi));
  171 + }
  172 +
  173 + $this->baseDom->save($this->baseDomName);
  174 +
  175 + return array('mask' => $mask, 'length' => $length);
  176 + }
228 177  
229   -/*
230   -*
231   -*/
232   - public function updateStart($vi)
233   - {
234   - $files = $vi->getElementsByTagName("file");
235   - if ($files->length == 0) return "EMPTY";
  178 + /*
  179 + *
  180 + */
  181 + public function updateStart($vi)
  182 + {
  183 + $files = $vi->getElementsByTagName("file");
  184 + if ($files->length == 0) return "EMPTY";
236 185  
237   - $starts = Array();
238   - foreach ($files as $file)
239   - $starts[] = $file->getAttribute("start");
  186 + $starts = Array();
  187 + foreach ($files as $file)
  188 + $starts[] = $file->getAttribute("start");
240 189  
241   - return min($starts);
242   - }
  190 + return min($starts);
  191 + }
243 192  
244 193 /*
245 194 *
246 195 */
247   - public function updateStop($vi)
248   - {
249   - $files = $vi->getElementsByTagName("file");
250   - if ($files->length == 0) return "EMPTY";
  196 + public function updateStop($vi)
  197 + {
  198 + $files = $vi->getElementsByTagName("file");
  199 + if ($files->length == 0) return "EMPTY";
251 200  
252   - $stops = Array();
253   - foreach ($files as $file)
254   - $stops[] = $file->getAttribute("stop");
  201 + $stops = Array();
  202 + foreach ($files as $file)
  203 + $stops[] = $file->getAttribute("stop");
255 204  
256   - return max($stops);
257   - }
  205 + return max($stops);
  206 + }
258 207  
259 208 /*
260 209 * New mask was added
... ... @@ -287,248 +236,188 @@ class BaseManager {
287 236 }
288 237 }
289 238  
290   - $newVi->setAttribute("start", min($starts));
291   - $newVi->setAttribute("stop", max($stops));
  239 + $newVi->setAttribute("start", min($starts));
  240 + $newVi->setAttribute("stop", max($stops));
292 241 }
293 242 }
294 243  
295 244 /*
296 245 *
297 246 */
298   - public function getOldMask($fileMask)
299   - {
300   - $masks = $this->baseDom->getElementsByTagName("mask");
301   -
302   - if ($masks->length > 0)
303   - {
304   - foreach ($masks as $mask) {
305   - // mask exists
306   - if (strcmp($mask->nodeValue, $fileMask) == 0) return null;
307   -
308   - if (strncmp($mask->nodeValue, $fileMask, 5) == 0)
309   - {
310   - // less common
311   - if (strlen($mask->nodeValue) <= strlen($fileMask)) return null;
312   - // more common - delete old, create new
313   - return $mask->nodeValue;
314   - }
315   - }
316   - }
317   - return null;
318   - }
319   -
  247 + public function getOldMask($fileMask)
  248 + {
  249 + $masks = $this->baseDom->getElementsByTagName("mask");
  250 +
  251 + if ($masks->length > 0)
  252 + {
  253 + foreach ($masks as $mask) {
  254 + // mask exists
  255 + if (strcmp($mask->nodeValue, $fileMask) == 0) return null;
  256 +
  257 + if (strncmp($mask->nodeValue, $fileMask, 5) == 0)
  258 + {
  259 + // less common
  260 + if (strlen($mask->nodeValue) <= strlen($fileMask)) return null;
  261 + // more common - delete old, create new
  262 + return $mask->nodeValue;
  263 + }
  264 + }
  265 + }
  266 + return null;
  267 + }
320 268 /*
321 269 *
322 270 */
323   - public function addVI($fileMask, $format)
324   - {
325   - $newVi = $this->baseDom->createElement("vi");
326   - $newId = $this->getNewId();
327   - $newVi->setAttribute('id', $newId);
328   - if ($format == 'txt') $format = 'ascii';
329   - $newVi->setAttribute('format', strtoupper($format));
330   - $newVi->appendChild($this->baseDom->createElement("mask",$fileMask));
331   - $this->appendFiles($newVi, $fileMask);
332   -
333   - $this->baseDom->getElementsByTagName("base")->item(0)->appendChild($newVi);
334   - /* SORT files by Start Time */
335   - $this->xslt->transformToDoc($this->baseDom)->save($this->baseDomName);
336   -
337   - return $newId;
338   - }
339   -
340   -/*
341   -*
342   -*/
343   - public function addSimuVI($p)
344   - {
345   - $newVi = $this->baseDom->createElement("vi");
346   - $newId = $this->getNewId();
347   - $newVi->setAttribute('id', $newId);
348   - $newVi->appendChild($this->baseDom->createElement("mask",$p->mask));
349   - $newVi->appendChild($this->baseDom->createElement("param",$p->name));
350   - $newVi->setAttribute("start", $p->start);
351   - $newVi->setAttribute("stop", $p->stop);
352   - $newVi->setAttribute("moreData", "true");
353   -
354   -// $this->appendFiles($newVi, $fileMask);
355   - $newFile = $this->baseDom->createElement("file");
356   - $newFile->setAttribute('name', $p->file);
357   - $newFile->setAttribute('start', $p->start);
358   - $newFile->setAttribute('stop', $p->stop);
359   - $this->baseDom->getElementsByTagName("base")->item(0)->appendChild($newVi);
360   -
361   - if (strpos($p->mask,'___CCMC_')=== FALSE){
362   - $arguments = $this->baseDom->createElement("arguments");
363   -
364   - foreach ($p->args[$p->name] AS $key => $val) {
365   - $arguments->appendChild($this->baseDom->createElement($key,$val));
366   - }
367   - $newVi->appendChild($arguments);
368   - }
369   -
370   - $newVi->appendChild($newFile);
371   -// $this->baseDom->getElementsByTagName("base")->item(0)->appendChild($newFile);
372   - /* SORT files by Start Time */
373   - $this->xslt->transformToDoc($this->baseDom)->save($this->baseDomName);
374   - return $newId;
375   - }
376   -
377   - public function delVI($fileMask)
378   - {
379   - $vi = $this->xp->query("//vi[mask='".$fileMask."']");
  271 + public function addVI($fileMask, $format)
  272 + {
  273 + $newVi = $this->baseDom->createElement("vi");
  274 + $newId = $this->getNewId();
  275 + $newVi->setAttribute('id', $newId);
  276 +
  277 + if ($format == 'txt') $format = 'ascii';
  278 +
  279 + $newVi->setAttribute('format', strtoupper($format));
  280 + $newVi->appendChild($this->baseDom->createElement("mask",$fileMask));
  281 + $this->appendFiles($newVi, $fileMask);
  282 +
  283 + $this->baseDom->documentElement->appendChild($newVi);
  284 + return $newId;
  285 + }
  286 +
  287 + public function delVI($fileMask)
  288 + {
  289 + $vi = $this->xp->query("//vi[mask='".$fileMask."']");
380 290  
381   - if ($vi->length > 0)
382   - $vi->item(0)->parentNode->removeChild($vi->item(0));
  291 + if ($vi->length > 0)
  292 + $vi->item(0)->parentNode->removeChild($vi->item(0));
383 293  
384   - $this->baseDom->save($this->baseDomName);
385   - }
  294 + $this->baseDom->save($this->baseDomName);
  295 + }
386 296  
387   - public function getVI($fileMask)
388   - {
389   - $vi = $this->xp->query("//vi[mask='".$fileMask."']");
  297 + public function getVI($fileMask)
  298 + {
  299 + $vi = $this->xp->query("//vi[mask='".$fileMask."']");
390 300  
391   - if ($vi->length > 0)
392   - return $vi->item(0)->getAttribute("id");
  301 + if ($vi->length > 0)
  302 + return $vi->item(0)->getAttribute("id");
393 303  
394   - return -1;
395   - }
  304 + return -1;
  305 + }
396 306  
397   - public function existsSimuMask($start,$stop,$mask)
398   - {
399   - $vi = $this->xp->query("//vi[mask='".$mask."' and @start<=".$start." and @stop>=".$stop."]");
400   -
401   - if ($vi->length > 0)
402   - return true;
403   - else
404   - return false;
405   - }
406   -
407   - public function existsWsrMask($start,$stop,$mask)
408   - {
409   - $vi = $this->xp->query("//vi[mask='".$mask."' and @start<=".$start." and @stop>=".$stop."]");
410   -
411   - if ($vi->length > 0)
412   - return true;
413   - else
414   - return false;
415   - }
416   -
417   - public function intervalsToGet($requestStart, $requestStop, $mask)
418   - {
419   - $vis = $this->xp->query("//vi[mask='".$mask."']");
420   - if ($vis->length == 0) return false;
421   -
422   - $vi = $vis->item(0);
423   - $files = $vi->getElementsByTagName('file');
424   -
425   - $start = array();
426   - $stop = array();
427   -
428   - $globalStart = (int)$vi->getAttribute("start");
429   - $globalStop = (int)$vi->getAttribute("stop");
430   -
431   - if ($requestStart > $globalStop || $requestStop < $globalStart)
432   - {
433   - $start[] = $requestStart;
434   - $stop[] = $requestStop;
435   - }
436   - else
437   - {
438   - if ($requestStart < $globalStart - DELTA ) {
439   - $start[] = $requestStart;
440   - $stop[] = $globalStart;
441   - }
442   -
443   - if ($requestStop > $globalStop + DELTA ) {
444   - $start[] = $globalStop;
445   - $stop[] = $requestStop;
446   - }
447   -
448   - for ($i = 0; $i < $files->length; $i++)
449   - if ((int)$files->item($i)->getAttribute("stop") >= $requestStart) break;
450   -
451   - for ($j = $i; $j < $files->length; $j++)
452   - if ((int)$files->item($j)->getAttribute("start") >= $requestStop) break;
  307 + public function existsVi($mask)
  308 + {
  309 + $vi = $this->xp->query("//vi[mask='".$mask."']");
  310 + if ($vi->length > 0)
  311 + return true;
  312 + else
  313 + return false;
  314 + }
453 315  
454   - $d = $j+1 < $files->length -1 ? $j+1 : $files->length - 1;
455   -
456   - for ($k = $i; $k < $d ; $k++) {
457   - $stopT = (int)$files->item($k)->getAttribute("stop");
458   - $startT = (int)$files->item($k+1)->getAttribute("start");
459   - if ($startT - $stopT > DELTA) {
460   - $start[] = $stopT;
461   - $stop[] = $startT;
462   - }
463   - }
464   - }
465   -
466   - return array('start' => $start, 'stop' => $stop);
467   - }
468   -
469   - public function getStartStopParam ($start,$stop,$mask) {
470   - $vi = $this->xp->query("//vi[mask='".$mask."']");
471   - $isData = $this->xp->query("//vi[mask='".$mask."' and @start<=".$start." and @stop>=".$stop."]");
472   -
473   - if ($isData->length > 0)
474   - return true;
475   - else {
476   - if ($vi->length > 0) {
477   - $viStart = $vi->item(0)->getAttribute('start');
478   - $viStop = $vi->item(0)->getAttribute('stop');
479   - if ($start < $viStart){
480   - if (($viStart - $start) > 60){
481   - $newStart = $start;
482   - $newStop = $viStart;
483   - }
484   - }
485   - elseif ($start >= $viStop){
486   - $newStart = $start;
487   - $newStop = $stop;
488   - }
489   - elseif (($start = $viStart) && ($stop > $viStop)){
490   - $newStart = $viStop;
491   - $newStop = $stop;
492   - }
493   - else {
494   - if ($stop <= $viStart){
495   - $newStart = $start;
496   - $newStop = $stop;
  316 + /*
  317 + * Check intervals to be ordered in the Remote Centers (IMPEX)
  318 + */
  319 + public function intervalsToGet($requestStart, $requestStop, $mask)
  320 + {
  321 + $vis = $this->xp->query("//vi[mask='".$mask."']");
  322 + if ($vis->length == 0) return false;
  323 +
  324 + $vi = $vis->item(0);
  325 + $files = $vi->getElementsByTagName('file');
  326 +
  327 + $start = array();
  328 + $stop = array();
  329 + // otherwise - the case of IPIM - only one file
  330 + if (strpos($mask, "*") > 0)
  331 + {
  332 + $globalStart = (int)$vi->getAttribute("start");
  333 + $globalStop = (int)$vi->getAttribute("stop");
  334 +
  335 + if ($requestStart > $globalStop || $requestStop < $globalStart)
  336 + {
  337 + $start[] = $requestStart;
  338 + $stop[] = $requestStop;
  339 + }
  340 + else
  341 + {
  342 + if ($requestStart < $globalStart - DELTA ) {
  343 + $start[] = $requestStart;
  344 + $stop[] = $globalStart;
  345 + }
  346 +
  347 + if ($requestStop > $globalStop + DELTA ) {
  348 + $start[] = $globalStop;
  349 + $stop[] = $requestStop;
  350 + }
  351 +
  352 + for ($i = 0; $i < $files->length; $i++)
  353 + if ((int)$files->item($i)->getAttribute("stop") >= $requestStart) break;
  354 +
  355 + for ($j = $i; $j < $files->length; $j++)
  356 + if ((int)$files->item($j)->getAttribute("start") >= $requestStop) break;
  357 +
  358 + $d = $j+1 < $files->length -1 ? $j+1 : $files->length - 1;
  359 +
  360 + for ($k = $i; $k < $d ; $k++) {
  361 + $stopT = (int)$files->item($k)->getAttribute("stop");
  362 + $startT = (int)$files->item($k+1)->getAttribute("start");
  363 + if ($startT - $stopT > DELTA) {
  364 + $start[] = $stopT;
  365 + $stop[] = $startT;
  366 + }
  367 + }
  368 + }
497 369 }
498   - elseif ($stop > $viStop){
499   - $newStart = $viStop;
500   - $newStop = $stop;
501   - }
502   - }
503   - }
504   - return array('start' => $newStart, 'stop' => $newStop);
  370 + return array('start' => $start, 'stop' => $stop);
505 371 }
506   -
507   - }
508   -
509   - public function getStartStop($id)
510   - {
511   - $this->baseDom->load($this->baseDomName);
512   - $xpath = new DOMXpath($this->baseDom);
513   -
514   - $vis = $xpath->query("//vi[@id=".$id."]");
515   -
516   - if ($vis->length == 0)
  372 +
  373 + /*
  374 + * Get VI Start - Stop
  375 + */
  376 + public function getStartStop($id)
  377 + {
  378 + $this->baseDom->load($this->baseDomName);
  379 + $xpath = new DOMXpath($this->baseDom);
  380 +
  381 + $vis = $xpath->query("//vi[@id=".$id."]");
  382 +
  383 + if ($vis->length == 0)
517 384 return "nodata";
518   -
519   - $vi = $vis->item(0);
520   -
521   - $start = $vi->getAttribute("start");
522   - $stop = $vi->getAttribute("stop");
523 385  
524   - return date("Y-m-d", $start)."T".date("H:i:s", $start)."-".date("Y-m-d", $stop)."T".date("H:i:s", $stop);
525   - }
526   -
  386 + $vi = $vis->item(0);
  387 +
  388 + $start = $vi->getAttribute("start");
  389 + $stop = $vi->getAttribute("stop");
527 390  
528   - public function getViDesc($vi)
529   - {
530   - return $this->getStartStop($vi);
531   - }
532   -
  391 + return date("Y-m-d", $start)."T".date("H:i:s", $start)."-".date("Y-m-d", $stop)."T".date("H:i:s", $stop);
  392 + }
  393 +
  394 + /*
  395 + * Return VI Description (Start - Stop)
  396 + */
  397 + public function getViDesc($vi)
  398 + {
  399 + return $this->getStartStop($vi);
  400 + }
  401 +
  402 + /*
  403 + * Delete Vi in base.xml and delete corresponding files in User DATA dir
  404 + */
  405 + public function deleteViTotal($viId)
  406 + {
  407 + $vi = $this->xp->query("//vi[@id=".$viId."]");
  408 +
  409 + if ($vi->length > 0) {
  410 + $files = $vi->item(0)->getElementsByTagName('file');
  411 + foreach ($files as $file)
  412 + {
  413 + $fileName = USERDATADIR.$file->getAttribute('name');
  414 + if (file_exists($fileName)) unlink($fileName);
  415 + }
  416 +
  417 + $vi->item(0)->parentNode->removeChild($vi->item(0));
  418 + $this->baseDom->save($this->baseDomName);
  419 + }
  420 + }
  421 +
533 422 }
534 423 ?>
... ...
php/classes/BestRunsMgr.php
... ... @@ -5,213 +5,247 @@
5 5 *
6 6 */
7 7  
8   -
9   - class BestRunsMgr {
10   -
11   - protected $runs;
12   - protected $domRemoteData, $domTemplate;
13   - protected $xpRemoteData, $xpTemplate;
14   - protected $runsTemplate;
15   - protected $json;
16   - protected $factors;
  8 +class BestRunsMgr
  9 +{
  10 + protected $runs;
  11 + protected $domRemoteData, $domTemplate;
  12 + protected $xpRemoteData, $xpTemplate;
  13 + protected $runsTemplate;
  14 + protected $json;
  15 + protected $factors = array("SW_Density"=>1e6,
  16 + "SW_Utot"=>1e3,
  17 + // "SW_Temperature"=>1e3,
  18 + "SW_Temperature"=>1.16e4, // ev => K
  19 + "SW_Btot"=>1e-9,
  20 + "SW_Bx"=>1e-9,
  21 + "SW_By"=>1e-9,
  22 + "SW_Bz"=>1e-9
  23 + );
17 24  
  25 + function __construct() {}
18 26  
19   - function __construct() {
20   - $this->factors = array("SW_Density"=>1e6,
21   - "SW_Utot"=>1e3,
22   - "SW_Temperature"=>1e3,
23   - "SW_Btot"=>1e-9,
24   - "SW_Bx"=>1e-9,
25   - "SW_By"=>1e-9,
26   - "SW_Bz"=>1e-9
27   - );
28   -
29   - }
30   -
31   -/*****************************************************************
32   -* PUBLIC FUNCTIONS
33   -*****************************************************************/
34 27  
35   - public function init() {
  28 + public function init()
  29 + {
  30 + // DOM of SIMU RUNs template
  31 + $this->domTemplate = new DomDocument("1.0");
  32 + if (!$this->domTemplate->load(DATAPATH.'SimuTemplate/templateGUMICS.xml'))
  33 + return false;
  34 +
  35 + $this->xpTemplate = new domxpath($this->domTemplate);
  36 + $this->runTemplate = $this->xpTemplate->query("//runID")->item(0);
  37 +
  38 + // DOM of user RemoteParams
  39 + $this->domRemoteData = new DomDocument("1.0");
  40 +
  41 + if (!$this->domRemoteData->load(USERWSDIR.'RemoteParams.xml'))
  42 + return false;
36 43  
37   -
38   - // DOM of SIMU RUNs chablon
39   - $this->domTemplate = new DomDocument();
40   - if (!$this->domTemplate->load( tmplGUMICS ))
41   - return false;
42   - $this->xpTemplate = new domxpath($this->domTemplate);
43   - $this->runTemplate = $this->xpTemplate->query("//runID")->item(0);
44   -
45   - // DOM of user RemoteParams
46   - $this->domRemoteData = new DomDocument();
47   - if (!$this->domRemoteData->load( USERWSDIR.'RemoteParams.xml' ))
48   - return false;
49   - $this->xpRemoteData = new domxpath($this->domRemoteData);
50   -
51   - $this->json = file_get_contents(USERWSDIR.'runs.json');
52   -
53   - }
54   -
55   - // $obj ={"Object":"Earth","RunCount":"2",
56   -// "SW_Density_value":"10","SW_Density_weight":"1","SW_Density_scale":"7","SW_Temperature_value":"100", ....}
57   - public function getRun($obj)
58   - {
  44 + $this->xpRemoteData = new domxpath($this->domRemoteData);
  45 +
  46 + $this->json = file_get_contents(USERWSDIR.'runs.json');
  47 +
  48 + return true;
  49 + }
59 50  
60   - $params = $this->makeParams($obj);
61   - try {
62   - $client = new SoapClient(wsdl_FMI,
63   - array(
64   - 'wsdl_cache' => 0,
65   - 'trace' => 1,
66   - 'exceptions' => 0,
67   - 'soap_version'=>SOAP_1_2
68   - ));
69   - }
70   - catch (SoapFault $exception) {
71   - error_log("Problem with WSDL".PHP_EOL.$exception->getMessage().PHP_EOL.$exception->getTraceAsString().PHP_EOL."File = ".$exception->getFile(),1,email);
72   - $res = array('success' => false,'error' => $exception->getMessage());
73   - }
74   - try {
75   - $data_json = $client->getMostRelevantRun($params);
76   - $result = json_decode($data_json,true);
  51 + // $obj ={"Object":"Earth","RunCount":"2",
  52 + // "SW_Density_value":"10","SW_Density_weight":"1","SW_Density_scale":"7","SW_Temperature_value":"100", ....}
  53 + public function getRun($obj)
  54 + {
  55 + $params = $this->makeParams($obj);
  56 + try
  57 + {
  58 + $client = new SoapClient("http://impex-fp7.fmi.fi/ws/Methods_FMI.wsdl",
  59 + array(
  60 + 'wsdl_cache' => 0,
  61 + 'trace' => 1,
  62 + 'exceptions' => 0,
  63 + 'soap_version'=>SOAP_1_2
  64 + ));
  65 + }
  66 + catch (SoapFault $exception)
  67 + {
  68 + $res = array('success' => false,'error' => $exception->getMessage());
  69 + }
  70 +
  71 + try
  72 + {
  73 + $data_json = $client->getMostRelevantRun($params);
  74 + $result = json_decode($data_json,true);
77 75  
78   - if (count($result["runs"]) > 0) {
79   - $result = $this->changeJson($result);
80   - $res = array('success' => true,'runs' => $result["runs"]);
81   - file_put_contents(USERWSDIR.'runs.json',json_encode($res));
82   -
  76 + if (count($result["runs"]) > 0)
  77 + {
  78 + $result = $this->changeJson($result);
  79 + $res = array('success' => true,'runs' => $result["runs"]);
  80 + file_put_contents(USERWSDIR.'runs.json',json_encode($res));
  81 + }
83 82 }
84   - }
85   - catch (Exception $e) {
86   - error_log ($e->getMessage(),1,email);
87   - $res = array('success' => false,'error' => $e->getMessage());
88   - }
89   -
90   - return $res;
91   - }
92   -
  83 + catch (Exception $e)
  84 + {
  85 + //error_log ($e->getMessage(),1,email);
  86 + $res = array('success' => false,'error' => $e->getMessage());
  87 + }
  88 + return $res;
  89 + }
  90 +
  91 + public function addRuns($obj)
  92 + {
  93 + if (!$obj) return false;
  94 + else
  95 + {
  96 + $this->runsId = (array)$obj;
  97 + $object = json_decode($this->json,true);
93 98  
94   -
95   - public function addRuns($obj){
96   -
97   - if (!$obj) return false;
98   - else {
99   - $this->runsId = (array)$obj;
100   - $object = json_decode($this->json,true);
101   - $simuRegion = $this->domRemoteData->getElementById('FMI_GUMICS_Earth_Magnetosphere');
  99 + $simuRegion = $this->domRemoteData->getElementById('FMI_GUMICS_Earth_Magnetosphere');
102 100  
103   - foreach ( $this->runsId as $runId){
104   - if ($this->domRemoteData->getElementById($runId) == null){
  101 + foreach ($this->runsId as $runId)
  102 + {
  103 + if ($this->domRemoteData->getElementById($runId) == null)
  104 + {
  105 + $newRun = $this->domRemoteData->importNode($this->runTemplate, true);
  106 + foreach ($object['runs'] as $r)
  107 + {
  108 + if ($r['ResourceID'] == $runId) $run=$r;
  109 + }
  110 + $newRun->setAttribute('xml:id', $run['ResourceID']);
  111 + $newRun->setAttribute('name', $run['ResourceName']);
  112 + $desc = $this->runTemplate->getAttribute('start_desc'). "<b>Param_values: </b><br/>";
  113 + foreach ($run['Param_values'] as $key => $value)
  114 + {
  115 + $desc = $desc."<u>".$key." </u>".$value."<br/>";
  116 + }
  117 + $newRun->setAttribute('desc', $desc);
  118 + $newRun->removeAttribute('start_desc');
  119 + $datasets = $newRun->getElementsByTagName('dataset');
  120 +
  121 + $numericalOutputs = $run['NumericalOutput']; // array !
  122 +
  123 + foreach ($datasets as $dataset)
  124 + {
  125 + $name = $dataset->getAttribute('name');
  126 + $find = false;
  127 +
  128 + foreach ($numericalOutputs as $no)
  129 + {
  130 + if (strpos($no, $name) > 0)
  131 + {
  132 +
  133 + $datasetId = $no;
  134 + $find = true;
  135 + break;
  136 + }
  137 + }
  138 +
  139 + if (!$find)
  140 + throw new Exception($name." is not found in FMI_GUMICS response");
  141 +
  142 + // $datasetId = str_replace('SimulationRun','NumericalOutput',$run['ResourceID'].'/'.$name);
  143 + $dataset->setAttribute('xml:id', $datasetId);
  144 + $dataset->setAttribute('desc');
  145 + $dataset->setAttribute('globalStart', 'depending on mission');
  146 + $params = $dataset->getElementsByTagName('parameter');
  147 + foreach($params as $param)
  148 + {
  149 + $paramName = $param->getAttribute('name');
  150 + // $datasetId = str_replace('SimulationRun','NumericalOutput',$datasetId);
  151 + switch ($paramName)
  152 + {
  153 + case "H+ number density" : $paramName = "Density"; break;
  154 + case "H+ velocity" : $paramName = "Ux,Uy,Uz"; break;
  155 + case "H+ total velocity" : $paramName = "Utot"; break;
  156 + case "H+ thermal pressure" : $paramName = "Pressure"; break;
  157 + case "H+ temperature" : $paramName = "Temperature"; break;
  158 + }
105 159  
106   - $newRun = $this->domRemoteData->importNode($this->runTemplate, true);
107   - foreach ($object['runs'] as $r){
108   - if ($r['ResourceID'] == $runId) $run=$r;
109   - }
110   - $newRun->setAttribute('xml:id', $run['ResourceID']);
111   - $newRun->setAttribute('name', $run['ResourceName']);
112   - $desc = $this->runTemplate->getAttribute('start_desc'). "<b>Param_values: </b><br/>";
113   - foreach ($run['Param_values'] as $key => $value) {
114   - $desc = $desc."<u>".$key." </u>".$value."<br/>";
115   - }
116   - $newRun->setAttribute('desc', $desc);
117   - $newRun->removeAttribute('start_desc');
118   - $datasets = $newRun->getElementsByTagName('dataset');
119   -
120   - foreach ($datasets as $dataset){
121   - $name = $dataset->getAttribute('name');
122   - $datasetId = str_replace('SimulationRun','NumericalOutput',$run['ResourceID'].'/'.$name);
123   - $dataset->setAttribute('xml:id', $datasetId);
124   - $dataset->setAttribute('desc');
125   - $params = $dataset->getElementsByTagName('parameter');
126   - foreach($params as $param){
127   - $paramName = $param->getAttribute('name');
128   -// $datasetId = str_replace('SimulationRun','NumericalOutput',$datasetId);
129   - switch ($paramName) {
130   - case "H+ number density" : $paramName = "Density"; break;
131   - case "H+ velocity" : $paramName = "Ux,Uy,Uz"; break;
132   - case "H+ total velocity" : $paramName = "Utot"; break;
133   - case "H+ thermal pressure" : $paramName = "Pressure"; break;
134   - case "H+ temperature" : $paramName = "Temperature"; break;
135   - }
136   -
137   -
138   - $paramId = $this->param2ddSimu($datasetId.'/'.$paramName);
139   - $param->setAttribute('xml:id', str_replace('_EARTH___n_T_Vx_Bx_By_Bz','',str_replace('earth_synth_stationary_','',$paramId)));
140   - $param->setAttribute('parentID',$datasetId);
141   - $param->setAttribute('needsArgs','1');
142   - if ($param->hasChildNodes()) {
143   - $components = $param->getElementsByTagName('component');
144   - foreach ($components as $component){
145   - $compName = $component->getAttribute('name');
146   - $component->setAttribute('xml:id', str_replace('_EARTH___n_T_Vx_Bx_By_Bz','',str_replace('earth_synth_stationary_','',$paramId.'_'.$compName)));
147   - $component->setAttribute('parentID',$datasetId);
148   - $component->setAttribute('needsArgs','1');
149   - }
150   - }
151   - }
152   - }
153   - $simuRegion->appendChild($newRun);
154   - $this->domRemoteData->save(USERWSDIR.'RemoteParams.xml');
155   - }
156   - }
157   -
  160 + $paramId = $this->param2ddSimu($datasetId.'/'.$paramName);
  161 + $param->setAttribute('xml:id', str_replace('_EARTH___n_T_Vx_Bx_By_Bz','',str_replace('earth_synth_stationary_','',$paramId)));
  162 + // $param->setAttribute('parentID',$datasetId);
  163 + $param->setAttribute('needsArgs','1');
  164 + if ($param->hasChildNodes())
  165 + {
  166 + $components = $param->getElementsByTagName('component');
  167 +
  168 + foreach ($components as $component)
  169 + {
  170 + $compName = $component->getAttribute('name');
  171 + $component->setAttribute('xml:id', str_replace('_EARTH___n_T_Vx_Bx_By_Bz','',str_replace('earth_synth_stationary_','',$paramId.'_'.$compName)));
  172 + // $component->setAttribute('parentID',$datasetId);
  173 + $component->setAttribute('needsArgs','1');
  174 + }
  175 + }
  176 + }
  177 + }
  178 + $simuRegion->appendChild($newRun);
  179 + $this->domRemoteData->save(USERWSDIR.'RemoteParams.xml');
  180 + }
  181 + }
  182 + }
158 183 }
159   - }
160 184  
161   - protected function makeParams($json)
162   - {
163   - $obj = (array)$json;
164   - $SW_parameters = array();
165   - foreach ($obj as $k => $v) {
166   - if (empty($v))
167   - unset($obj[$k]);
168   - }
169   - foreach ($obj as $k => $v) {
170   - if (strpos($k,'_value') !== FALSE ) {
171   - $sw= str_replace ('_value', '', $k);
172   - $SW_val = array();
173   - $SW_val['value'] = $obj[$sw.'_value'] * $this->factors[$sw];
174   - if ($obj[$sw.'_weight'] != '') $SW_val['weight'] = $obj[$sw.'_weight'];
175   - if ($obj[$sw.'_scale'] != '') $SW_val['scale'] = $obj[$sw.'_scale']* $this->factors[$sw];
176   - $SW_parameters[$sw] = $SW_val;
  185 + protected function makeParams($json)
  186 + {
  187 + $obj = (array)$json;
  188 + $SW_parameters = array();
  189 +
  190 + foreach ($obj as $k => $v)
  191 + {
  192 + if (empty($v))
  193 + unset($obj[$k]);
  194 + }
  195 +
  196 + foreach ($obj as $k => $v)
  197 + {
  198 + if (strpos($k,'_value') !== FALSE )
  199 + {
  200 + $sw= str_replace ('_value', '', $k);
  201 + $SW_val = array();
  202 + $SW_val['value'] = $obj[$sw.'_value'] * $this->factors[$sw];
  203 + if ($obj[$sw.'_weight'] != '') $SW_val['weight'] = $obj[$sw.'_weight'];
  204 + if ($obj[$sw.'_scale'] != '') $SW_val['scale'] = $obj[$sw.'_scale']* $this->factors[$sw];
  205 + $SW_parameters[$sw] = $SW_val;
  206 + }
177 207 }
178   - }
179   - $params = array (
180   - 'Object' => 'Earth', // Mandatory
181   - 'RunCount' => $obj['RunCount'], // Number of runs returned. Optional, default = 1
182   - 'SW_parameters' => $SW_parameters);
  208 + $params = array (
  209 + 'Object' => 'Earth', // Mandatory
  210 + 'RunCount' => $obj['RunCount'], // Number of runs returned. Optional, default = 1
  211 + 'SW_parameters' => $SW_parameters);
  212 +
183 213 return $params;
184   -
185   - }
  214 + }
186 215  
187   - protected function changeJson($object){
188   -
189   - $i=0;
190   - foreach ($object['runs'] as $run){
191   - $run['S_diff'] = round($run['S_diff'],3);
192   -
193   -
194   - foreach ($run['S_diff_n'] as $k => $v){
195   - $v = round($v,3);
196   - $run['S_diff_n'][$k] = $v;
197   - }
198   - foreach ($run['Param_values'] as $k => $v){
199   - if ($this->factors[$k]){
200   - $newValue = round($v / $this->factors[$k], 3);
201   - $run['Param_values'][$k] = $newValue;
202   - }
203   - }
204   - $object['runs'][$i] = $run;
205   - $i++;
206   - }
207   -
208   - return $object;
209   - }
  216 + protected function changeJson($object)
  217 + {
  218 + $i=0;
  219 + foreach ($object['runs'] as $run)
  220 + {
  221 + $run['S_diff'] = round($run['S_diff'],1);
  222 +
  223 + foreach ($run['S_diff_n'] as $k => $v)
  224 + {
  225 + $v = round($v,3);
  226 + $run['S_diff_n'][$k] = $v;
  227 + }
  228 +
  229 + foreach ($run['Param_values'] as $k => $v)
  230 + {
  231 + if ($this->factors[$k])
  232 + {
  233 + $newValue = round($v / $this->factors[$k], 3);
  234 + $run['Param_values'][$k] = $newValue;
  235 + }
  236 + }
  237 + $object['runs'][$i] = $run;
  238 + $i++;
  239 + }
  240 + return $object;
  241 + }
210 242  
211   - protected function param2ddSimu($paramID) {
212   - $pairs = array(" " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_","#" => "_","@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_");
213   - return strtr($paramID,$pairs);
214   - }
215   - }
216   -
  243 + protected function param2ddSimu($paramID)
  244 + {
  245 + $pairs = array("?" => "_", " " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_",
  246 + "#" => "_","@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_");
  247 + return strtr($paramID,$pairs);
  248 + }
  249 +
  250 +}
217 251 ?>
... ...
php/classes/EPNResourcesManager.php deleted
... ... @@ -1,1042 +0,0 @@
1   -<?php
2   -/** @class EPNResourcesManager
3   -* @version $Id: EPNResourcesManager.php 2183 2014-03-13 14:59:19Z elena $
4   -* @brief Manager to create EPN resources from AMDA descriptors files
5   -*
6   -*/
7   -
8   -define("EPNRES_IVOID_CDPP","ivo://cdpp");
9   -define("EPNRES_IVOID_IRAP",EPNRES_IVOID_CDPP."/irap");
10   -define("EPNRES_IVOID_AMDA",EPNRES_IVOID_IRAP."/amda");
11   -define("EPNRES_IVOID_DATA",EPNRES_IVOID_AMDA."/dataset");
12   -define("EPNRES_IVOID_INST",EPNRES_IVOID_AMDA."/instrument");
13   -define("EPNRES_IVOID_MIS",EPNRES_IVOID_AMDA."/mission");
14   -
15   -
16   -define("EPNRES_PUBLISHER","CDPP - Centre de Donnรฉes de la Physique des Plasma");
17   -
18   -define("EPNRES_CONTACT_NAME","CDPP/AMDA Team");
19   -define("EPNRES_CONTACT_ADDRESS","IRAP, 9 avenue du Colonel Roche, 31028 TOULOUSE, CEDEX 4, FRANCE");
20   -define("EPNRES_CONTACT_EMAIL","amda@irap.omp.eu");
21   -define("EPNRES_CONTACT_TELEPHONE","");
22   -
23   -define("EPNRES_REFERENCE_URL","http://cdpp-amda.cesr.fr/DDHTML/index.html");
24   -
25   -define("EPNRES_INSTRUMENTS_FILE",EPNResources."instruments.xml");
26   -define("EPNRES_TARGETS_FILE",LocalData."targets.xml");
27   -
28   -
29   -class EPNResourcesManager
30   -{
31   - protected $infoMgr;
32   - protected $amdaClient;
33   - protected $inst_doc;
34   - protected $inst_xp;
35   - protected $targ_doc;
36   - protected $targ_xp;
37   -
38   - function __construct($amdaClient)
39   - {
40   - $this->infoMgr = new ParamsInfoMgr();
41   - $this->amdaClient = $amdaClient;
42   - }
43   -
44   - private function initInstrumentsFile()
45   - {
46   - $this->inst_doc = new DOMDocument();
47   - $this->inst_doc->formatOutput = TRUE;
48   -
49   - $node = $this->inst_doc->createElement('Instruments');
50   - $this->inst_doc->appendChild($node);
51   -
52   - $this->inst_xp = new DOMXPath($this->inst_doc);
53   - }
54   -
55   - private function loadTargetsFile()
56   - {
57   - $this->targ_doc = new DOMDocument();
58   - $this->targ_doc->formatOutput = TRUE;
59   -
60   - if (!$this->targ_doc->load(EPNRES_TARGETS_FILE))
61   - {
62   - printf("[ERROR] Cannot load tagets file %s\n",EPNRES_TARGETS_FILE);
63   - return false;
64   - }
65   -
66   - $this->targ_xp = new DOMXPath($this->targ_doc);
67   -
68   - return true;
69   - }
70   -
71   - public function createResources()
72   - {
73   - $this->initInstrumentsFile();
74   -
75   - if (!$this->loadTargetsFile())
76   - return false;
77   -
78   - $this->infoMgr->forEachAllDDDatasets(array($this,'createResource'));
79   -
80   - $this->inst_doc->save(EPNRES_INSTRUMENTS_FILE);
81   - }
82   -
83   - function createResource($infos)
84   - {
85   - $dataset_id = $infos["dataset"]["id"];
86   -
87   - $newres_doc = new DOMDocument();
88   - $newres_doc->formatOutput = TRUE;
89   -
90   - $epn_id = str_replace(":","_",$dataset_id);
91   - $newres_path = EPNResources."EPNresource_".$epn_id.".xml";
92   -
93   - // create skeleton
94   -
95   - $this->getDataCollection($newres_doc);
96   - $this->getAccessURL($newres_doc);
97   - $this->getTitle($newres_doc);
98   - $this->getShortName($newres_doc);
99   - $this->getIdentifier($newres_doc);
100   - $this->getCuration($newres_doc);
101   - $this->getPublisher($newres_doc);
102   - $this->getCreator($newres_doc);
103   - $this->getCreatorName($newres_doc);
104   - $this->getCreatorLogo($newres_doc);
105   - $this->getContact($newres_doc);
106   - $this->getContactName($newres_doc);
107   - $this->getContactAddress($newres_doc);
108   - $this->getContactEmail($newres_doc);
109   - $this->getContactTelephone($newres_doc);
110   - $this->getContent($newres_doc);
111   - $this->getSubject($newres_doc);
112   - $this->getDescription($newres_doc);
113   - $this->getReferenceURL($newres_doc);
114   - $this->getContributor($newres_doc);
115   - $this->getResource($newres_doc);
116   - $this->getDataset($newres_doc);
117   - $this->getGeneralMetadata($newres_doc);
118   - $this->getFormat($newres_doc);
119   - $this->getRight($newres_doc);
120   - $this->getCalibration($newres_doc);
121   - $this->getResourceType($newres_doc);
122   - $this->getInstrument($newres_doc);
123   - $this->getFacility($newres_doc);
124   - $this->getResourceName($newres_doc);
125   - $this->getInstrumentName($newres_doc);
126   - $this->getAlternateInstrumentName($newres_doc);
127   - $this->getInstrumentClass($newres_doc);
128   - $this->getInstrumentReferenceURL($newres_doc);
129   - $this->getAnyURI($newres_doc);
130   - $this->getTargets($newres_doc);
131   - $this->getTargetType($newres_doc);
132   - $this->getTargetClass($newres_doc);
133   - $this->getCoverage($newres_doc);
134   - $this->getMeasurementType($newres_doc);
135   - $this->getAstroCoordSystem($newres_doc);
136   - $this->getTimeFrame($newres_doc);
137   - $this->getTimeScale($newres_doc);
138   - $this->getAstroCoordArea($newres_doc);
139   - $this->getTimeInterval($newres_doc);
140   - $this->getIntegrationTime($newres_doc);
141   - $this->getMinIntegrationTime($newres_doc);
142   - $this->getMaxIntegrationTime($newres_doc);
143   - $this->getSamplingStep($newres_doc);
144   - $this->getMinSamplingStep($newres_doc);
145   - $this->getMaxSamplingStep($newres_doc);
146   - $this->getStartTime($newres_doc);
147   - $this->getStartTimeISO($newres_doc);
148   - $this->getStopTime($newres_doc);
149   - $this->getStopTimeISO($newres_doc);
150   - $this->getSpectralInterval($newres_doc);
151   - $this->getSpectralResolution($newres_doc);
152   - $this->getSpectralMinResolution($newres_doc);
153   - $this->getSpectralMaxResolution($newres_doc);
154   - $this->getSpectralLoLimit($newres_doc);
155   - $this->getSpectralHiLimit($newres_doc);
156   - $this->getSpectralSamplingStep($newres_doc);
157   - $this->getMinSpectralSamplingStep($newres_doc);
158   - $this->getMaxSpectralSamplingStep($newres_doc);
159   - $this->getSpectralParticles($newres_doc);
160   - $this->getParticlesResolution($newres_doc);
161   - $this->getParticlesMinResolution($newres_doc);
162   - $this->getParticlesMaxResolution($newres_doc);
163   - $this->getParticlesLoLimit($newres_doc);
164   - $this->getParticlesHiLimit($newres_doc);
165   - $this->getParticlesSamplingStep($newres_doc);
166   - $this->getMinParticlesSamplingStep($newres_doc);
167   - $this->getMaxParticlesSamplingStep($newres_doc);
168   - $this->getTableset($newres_doc);
169   - $this->getSchema($newres_doc);
170   - $this->getSchemaColumn($newres_doc);
171   - $this->getSchemaColumnName($newres_doc);
172   - $this->getSchemaColumnDescription($newres_doc);
173   - $this->getSchemaColumnUnit($newres_doc);
174   - $this->getSchemaColumnUCD($newres_doc);
175   - $this->getSchemaColumnDataproductType($newres_doc);
176   - $this->getSchemaColumnDataType($newres_doc);
177   -
178   - // fill
179   - $date = date("Y-m-d\TH:i:s");
180   -
181   - $this->setDataCollection($newres_doc,$epn_id,$date,$date,"");
182   -
183   - $accessURL = EPNTAP_AMDA."?REQUEST=doQuery&amp;LANG=ADQL&amp;QUERY=SELECT * FROM amdadb.epn_core WHERE dataset_id = '".$epn_id."' AND resource_type = 'granule' ORDER BY time_min&amp;FORMAT=votable/td";
184   - $this->setAccessURL($newres_doc,$accessURL);
185   -
186   - $this->setTitle($newres_doc,$infos['dataset']['infos']['title']);
187   -
188   - $this->setShortName($newres_doc,$epn_id);
189   -
190   - $this->setIdentifier($newres_doc,EPNRES_IVOID_DATA,$epn_id);
191   -
192   - $this->setPublisher($newres_doc,EPNRES_PUBLISHER);
193   -
194   - $this->setCreator($newres_doc,$infos['dataset']['infos']['creator'],"");
195   -
196   - $this->setContact($newres_doc,EPNRES_IVOID_AMDA,EPNRES_CONTACT_NAME,EPNRES_CONTACT_ADDRESS,EPNRES_CONTACT_EMAIL,EPNRES_CONTACT_TELEPHONE);
197   -
198   - foreach ($infos['dataset']['infos']['subject'] as $s)
199   - $this->addSubject($newres_doc,$s);
200   -
201   - $this->setDescription($newres_doc,$infos['dataset']['infos']['description']);
202   -
203   - $this->setReferenceURL($newres_doc,$infos['submission']['infos']['help'],$infos['instrument']['infos']['help'],$infos['dataset']['infos']['help']);
204   -
205   - foreach ($infos['dataset']['infos']['contributor'] as $c)
206   - $this->addContributor($newres_doc,$c);
207   -
208   - $this->setCalibration($newres_doc,$infos['dataset']['infos']['calibration']);
209   -
210   - $this->setFormat($newres_doc,"votable");
211   -
212   - if (!isset($infos['mission']['infos']['group']) || ($infos['mission']['infos']['group'] == ""))
213   - $this->setRight($newres_doc,"secure");
214   - else
215   - $this->setRight($newres_doc,"proprietary");
216   -
217   - $this->setResourceType($newres_doc,"dataset");
218   -
219   - $this->setInstrument($newres_doc,$infos['mission']['id'],$infos['submission']['name'],$infos['submission']['infos']['class'],
220   - $infos['instrument']['infos']['id'],$infos['instrument']['name'],$infos['instrument']['infos']['alternamename'],
221   - $infos['instrument']['infos']['class'],$infos['instrument']['infos']['refURL']);
222   -
223   - foreach ($infos['dataset']['infos']['target'] as $t)
224   - $this->addTarget($newres_doc,$t);
225   -
226   - $this->setMeasurementType($newres_doc,$infos['dataset']['infos']['parameters']);
227   -
228   - $this->setTimeInterval($newres_doc,$dataset_id,$infos['dataset']['infos']['minsampling'],$infos['dataset']['infos']['maxsampling'],
229   - $infos['dataset']['infos']['starttime'],$infos['dataset']['infos']['stoptime']);
230   -
231   - foreach ($infos['dataset']['infos']['parameters'] as $param)
232   - $this->addColumn($newres_doc,$param['name'],$param['description'],$param['units'],$param['ucd'],$param['type'],'float');
233   -
234   - $newres_doc->save($newres_path);
235   - // printf("[INFO] Create new EPN resource file %s\n",$newres_path);
236   - }
237   -
238   - function setDataCollection($res_doc,$id,$created,$updated,$status)
239   - {
240   - $node = $this->getDataCollection($res_doc);
241   - $node->setAttribute('id',$id);
242   - $node->setAttribute('created',$created);
243   - $node->setAttribute('updated',$updated);
244   - $node->setAttribute('status',$status);
245   - }
246   -
247   - function setPublisher($res_doc,$publisher)
248   - {
249   - $node = $this->getPublisher($res_doc);
250   - $node->nodeValue = $publisher;
251   - }
252   -
253   - function setContact($res_doc,$ivo_id,$name,$address,$email,$telephone)
254   - {
255   - $node = $this->getContactName($res_doc);
256   - $node->setAttribute('ivo-id',$ivo_id);
257   - $node->nodeValue = $name;
258   - $node = $this->getContactAddress($res_doc);
259   - $node->nodeValue = $address;
260   - $node = $this->getContactEmail($res_doc);
261   - $node->nodeValue = $email;
262   - $node = $this->getContactTelephone($res_doc);
263   - $node->nodeValue = $telephone;
264   - }
265   -
266   - function setReferenceURL($res_doc,$mission_help,$instrument_help,$dataset_help)
267   - {
268   - $node = $this->getReferenceURL($res_doc);
269   - if (isset($dataset_help) && ($dataset_help != ''))
270   - $node->nodeValue = $dataset_help;
271   - else if (isset($instrument_help) && ($instrument_help != ''))
272   - $node->nodeValue = $instrument_help;
273   - else if (isset($mission_help) && ($mission_help != ''))
274   - $node->nodeValue = $mission_help;
275   - else
276   - $node->nodeValue = EPNRES_REFERENCE_URL;
277   - }
278   -
279   - function getRealSampling($sampling)
280   - {
281   - list($val,$unit) = sscanf($sampling,"%f%s");
282   - if ($unit == "s")
283   - $sampling = 1*$sampling;
284   - else if ($unit == "m")
285   - $sampling = 60*$sampling;
286   - else if ($unit == "h")
287   - $sampling = 3600*$sampling;
288   - else if ($unit == "Hz")
289   - $sampling = 1./$sampling;
290   - else
291   - printf("[WARNING] EPNResource : Unknown sampling unit %s\n",$unit);
292   - return $sampling;
293   - }
294   -
295   - function getRealStartStop($name)
296   - {
297   - return $this->amdaClient->client->getStartStop($name);
298   - }
299   -
300   - function days2MonthDay($oldDate)
301   - {
302   - list($year, $day, $hour, $min, $sec) = sscanf($oldDate, "%04d%03d%02d%02d%02d");
303   - $newDate = date("Y-m-d\TH:i:s",strtotime("+$day days",strtotime("$year-01-01 $hour:$min:$sec")));
304   - return $newDate;
305   - }
306   -
307   - function setTimeInterval($res_doc,$dataset_id,$minres,$maxres,$start,$stop)
308   - {
309   - $node = $this->getTimeInterval($res_doc);
310   - $node->setAttribute('ucd','time.epoch');
311   - $node = $this->getSamplingStep($res_doc);
312   - if ($minres == $maxres)
313   - $node->setAttribute('type','constant');
314   - else
315   - $node->setAttribute('type','variable');
316   - $node->setAttribute('unit','secondes');
317   - $node = $this->getMinSamplingStep($res_doc);
318   - $node->nodeValue = $this->getRealSampling($minres);
319   - $node = $this->getMaxSamplingStep($res_doc);
320   - $node->nodeValue = $this->getRealSampling($maxres);
321   -
322   - $startstop = $this->getRealStartStop($dataset_id);
323   - $Time = explode("-",$startstop);
324   -
325   - $node = $this->getStartTimeISO($res_doc);
326   - $node->nodeValue = $this->days2MonthDay($Time[0]);
327   - $node = $this->getStopTimeISO($res_doc);
328   - $node->nodeValue = $this->days2MonthDay($Time[1]);
329   - $node = $this->getTimeScale($res_doc);
330   - $node->nodeValue = 'UTC';
331   - }
332   -
333   - function setAccessURL($res_doc,$access_url)
334   - {
335   - $node = $this->getAccessURL($res_doc);
336   - $node->nodeValue = $access_url;
337   - }
338   -
339   - function setTitle($res_doc,$title)
340   - {
341   - $node = $this->getTitle($res_doc);
342   - $node->nodeValue = $title;
343   - }
344   -
345   - function setShortName($res_doc,$shortName)
346   - {
347   - $node = $this->getShortName($res_doc);
348   - $node->nodeValue = $shortName;
349   - }
350   -
351   - function setIdentifier($res_doc,$ivo_id,$dataset_id)
352   - {
353   - $node = $this->getIdentifier($res_doc);
354   - $node->nodeValue = $ivo_id."/".$dataset_id;
355   - }
356   -
357   - function setCreator($res_doc,$name,$logo)
358   - {
359   - $node = $this->getCreatorName($res_doc);
360   - $node->nodeValue = $name;
361   -
362   - $node = $this->getCreatorLogo($res_doc);
363   - $node->nodeValue = $logo;
364   - }
365   -
366   - function setCalibration($res_doc,$cal)
367   - {
368   - $node = $this->getCalibration($res_doc);
369   - $node->nodeValue = $cal;
370   - }
371   -
372   - function setResourceType($res_doc,$type)
373   - {
374   - $node = $this->getResourceType($res_doc);
375   - $node->nodeValue = $type;
376   - }
377   -
378   - function setInstrument($res_doc,$mis_id,$submis_name,$mis_class,$inst_id,$inst_name,$inst_altname,$inst_class,$inst_refurl)
379   - {
380   - $node = $this->getInstrument($res_doc);
381   -
382   - $node->setAttribute('id',$inst_id);
383   -
384   - $node = $this->getFacility($res_doc);
385   - $node->setAttribute('ivo-id',EPNRES_IVOID_MIS."/".$submis_name);
386   - $node->setAttribute('class',$mis_class);
387   -
388   - $node = $this->getResourceName($res_doc);
389   - $node->nodeValue = $mis_id;
390   -
391   - $node = $this->getInstrumentName($res_doc);
392   - $node->setAttribute('ivo-id',EPNRES_IVOID_INST."/".$inst_id);
393   - $node->nodeValue = $inst_name;
394   -
395   - foreach ($inst_altname as $a)
396   - $this->addInstAltName($res_doc,$a);
397   -
398   - foreach ($inst_class as $c)
399   - $this->addInstClass($res_doc,$c);
400   -
401   - $node = $this->getInstrumentReferenceURL($res_doc);
402   - $node->setAttribute('use','full');
403   -
404   - $node = $this->getAnyURI($res_doc);
405   - $node->nodeValue = $inst_refurl;
406   -
407   - $instnode = $this->inst_xp->query("//Instruments/instrument[@id='".$inst_id."']");
408   - if ($instnode->length < 1)
409   - {
410   - $instnode = $this->inst_doc->importNode($this->getInstrument($res_doc),true);
411   - $this->inst_doc->documentElement->appendChild($instnode);
412   - }
413   - }
414   -
415   - function setMeasurementType($res_doc,$params)
416   - {
417   - $node = $this->getMeasurementType($res_doc);
418   -
419   - $ucds = array();
420   - foreach ($params as $param)
421   - {
422   - $param_ucds = explode($param['ucd'],";");
423   - foreach ($param_ucds as $param_ucd)
424   - {
425   - if ($param_ucd == 'ToDo')
426   - continue;
427   - $toadd = true;
428   - foreach ($ucds as $ucd)
429   - if ($ucd == $param_ucd)
430   - {
431   - $toadd = false;
432   - break;
433   - }
434   - if ($toadd)
435   - array_push($ucds,$param['ucd']);
436   - }
437   - }
438   -
439   - $ucd_str = "";
440   - foreach ($ucds as $ucd)
441   - {
442   - if ($ucd_str != "")
443   - $ucd_str .= ";";
444   - $ucd_str .= $ucd;
445   - }
446   -
447   - $node->nodeValue = $ucd_str;
448   - }
449   -
450   - function setFormat($res_doc,$format)
451   - {
452   - $node = $this->getFormat($res_doc);
453   - $node->nodeValue = $format;
454   - }
455   -
456   - function setRight($res_doc,$right)
457   - {
458   - $node = $this->getRight($res_doc);
459   - $node->nodeValue = $right;
460   - }
461   -
462   - function setDescription($res_doc,$description)
463   - {
464   - $node = $this->getDescription($res_doc);
465   - $node->nodeValue .= $description;
466   - }
467   -
468   - function addTarget($res_doc,$target_id)
469   - {
470   - //find target in targets file
471   - $tar_info = $this->targ_xp->query("//Targets/TargetType[@id='".$target_id."']");
472   - if ($tar_info->length < 1)
473   - {
474   - printf("[WARNING] Cannot find target info %s\n",$target_id);
475   - return;
476   - }
477   - $tar_info = $tar_info->item(0);
478   -
479   - //add target in epn resource
480   - $targets = $this->getTargets($res_doc);
481   -
482   - $targetnodes = $targets->getElementsByTagName("TargetType");
483   - foreach ($targetnodes as $targetnode)
484   - if ($targetnode->getAttribute("id") == $target_id)
485   - return;
486   -
487   - foreach ($targetnodes as $targetnode)
488   - if ($targetnode->getAttribute("id") == '')
489   - $targets->removeChild($targetnode);
490   -
491   - $node = $res_doc->importNode($tar_info,true);
492   - $targets->appendChild($node);
493   - }
494   -
495   - function addColumn($res_doc,$param_name,$param_des,$param_unit,$param_ucd,$param_datatype,$param_prodtype)
496   - {
497   - $schema = $this->getSchema($res_doc);
498   -
499   - $columns = $schema->getElementsByTagName("column");
500   - foreach ($columns as $column)
501   - {
502   - $names = $column->getElementsByTagName("name");
503   - if ($names->length < 1)
504   - continue;
505   - if (($names->item(0)->nodeValue == $param_name) || ($names->item(0)->nodeValue == ''))
506   - {
507   - $param_column = $column;
508   - break;
509   - }
510   - }
511   - if (!isset($param_column))
512   - {
513   - //create new column
514   - $param_column = $this->addToNode($res_doc,$schema,'column');
515   - $this->addToNode($res_doc,$param_column,'name');
516   - $this->addToNode($res_doc,$param_column,'description');
517   - $this->addToNode($res_doc,$param_column,'unit');
518   - $this->addToNode($res_doc,$param_column,'ucd');
519   - $this->addToNode($res_doc,$param_column,'dataproduct_type');
520   - $this->addToNode($res_doc,$param_column,'dataType');
521   - }
522   - //set param info
523   - $node = $this->getFromNode($res_doc,$param_column,'name');
524   - $node->nodeValue = $param_name;
525   - $node = $this->getFromNode($res_doc,$param_column,'description');
526   - $node->nodeValue = $param_des;
527   - $node = $this->getFromNode($res_doc,$param_column,'unit');
528   - $node->nodeValue = $param_unit;
529   - $node = $this->getFromNode($res_doc,$param_column,'ucd');
530   - $node->nodeValue = $param_ucd;
531   - $node = $this->getFromNode($res_doc,$param_column,'dataproduct_type');
532   - $node->nodeValue = $param_datatype;
533   - $node = $this->getFromNode($res_doc,$param_column,'dataType');
534   - $node->nodeValue = $param_prodtype;
535   - }
536   -
537   - function addSubject($res_doc,$subject)
538   - {
539   - $content = $this->getContent($res_doc);
540   -
541   - $subjects = $content->getElementsByTagName("subject");
542   - foreach($subjects as $s)
543   - if ($s->nodeValue == $subject)
544   - return;
545   -
546   - foreach($subjects as $s)
547   - if ($s->nodeValue == '')
548   - {
549   - $s->nodeValue = $subject;
550   - return;
551   - }
552   -
553   - $s = $this->addToNode($res_doc,$content,'subject');
554   - $s->nodeValue = $subject;
555   - }
556   -
557   - function addContributor($res_doc,$contributor)
558   - {
559   - $content = $this->getContent($res_doc);
560   -
561   - $contributors = $content->getElementsByTagName("contributor");
562   - foreach($contributors as $c)
563   - if ($c->nodeValue == $contributor)
564   - return;
565   -
566   - foreach($contributors as $c)
567   - if ($c->nodeValue == '')
568   - {
569   - $c->nodeValue = $contributor;
570   - return;
571   - }
572   -
573   - $c = $this->addToNode($res_doc,$content,'contributor');
574   - $c->nodeValue = $contributor;
575   - }
576   -
577   - function addInstAltName($res_doc,$altName)
578   - {
579   - $content = $this->getInstrument($res_doc);
580   -
581   - $altnames = $content->getElementsByTagName("alternateInstrumentName");
582   - foreach($altnames as $a)
583   - if ($a->nodeValue == $altName)
584   - return;
585   -
586   - foreach($altnames as $a)
587   - if ($a->nodeValue == '')
588   - {
589   - $a->nodeValue = $altName;
590   - return;
591   - }
592   -
593   - $a = $this->addToNode($res_doc,$content,'alternateInstrumentName');
594   - $a->nodeValue = $altName;
595   - }
596   -
597   - function addInstClass($res_doc,$class)
598   - {
599   - $content = $this->getInstrument($res_doc);
600   -
601   - $classes = $content->getElementsByTagName("instrumentClass");
602   - foreach($classes as $c)
603   - if ($c->nodeValue == $class)
604   - return;
605   -
606   - foreach($classes as $c)
607   - if ($c->nodeValue == '')
608   - {
609   - $c->nodeValue = $class;
610   - return;
611   - }
612   -
613   - $c = $this->addToNode($res_doc,$content,'instrumentClass');
614   - $c->nodeValue = $class;
615   - }
616   -
617   - function addToNode($res_doc,$node,$tagname)
618   - {
619   - $newnode = $res_doc->createElement($tagname);
620   - $node->appendChild($newnode);
621   - return $newnode;
622   - }
623   -
624   - function getFromNode($res_doc,$node,$tagname)
625   - {
626   - $nodes = $node->getElementsByTagName($tagname);
627   - if ($nodes->length == 0)
628   - return $this->addToNode($res_doc,$node,$tagname);
629   - return $nodes->item(0);
630   - }
631   -
632   - function getDataCollection($res_doc)
633   - {
634   - return $this->getFromNode($res_doc,$res_doc,'DataCollection');
635   - }
636   -
637   - function getAccessURL($res_doc)
638   - {
639   - return $this->getFromNode($res_doc,$this->getDataCollection($res_doc),'accessURL');
640   - }
641   -
642   - function getTitle($res_doc)
643   - {
644   - return $this->getFromNode($res_doc,$this->getDataCollection($res_doc),'title');
645   - }
646   -
647   - function getShortName($res_doc)
648   - {
649   - return $this->getFromNode($res_doc,$this->getDataCollection($res_doc),'shortName');
650   - }
651   -
652   - function getIdentifier($res_doc)
653   - {
654   - return $this->getFromNode($res_doc,$this->getDataCollection($res_doc),'Identifier');
655   - }
656   -
657   - function getCuration($res_doc)
658   - {
659   - return $this->getFromNode($res_doc,$this->getDataCollection($res_doc),'curation');
660   - }
661   -
662   - function getPublisher($res_doc)
663   - {
664   - return $this->getFromNode($res_doc,$this->getCuration($res_doc),'publisher');
665   - }
666   -
667   - function getCreator($res_doc)
668   - {
669   - return $this->getFromNode($res_doc,$this->getCuration($res_doc),'creator');
670   - }
671   -
672   - function getCreatorName($res_doc)
673   - {
674   - return $this->getFromNode($res_doc,$this->getCreator($res_doc),'name');
675   - }
676   -
677   - function getCreatorLogo($res_doc)
678   - {
679   - return $this->getFromNode($res_doc,$this->getCreator($res_doc),'logo');
680   - }
681   -
682   - function getContact($res_doc)
683   - {
684   - return $this->getFromNode($res_doc,$this->getCuration($res_doc),'contact');
685   - }
686   -
687   - function getContactName($res_doc)
688   - {
689   - return $this->getFromNode($res_doc,$this->getContact($res_doc),'name');
690   - }
691   -
692   - function getContactAddress($res_doc)
693   - {
694   - return $this->getFromNode($res_doc,$this->getContact($res_doc),'address');
695   - }
696   -
697   - function getContactEmail($res_doc)
698   - {
699   - return $this->getFromNode($res_doc,$this->getContact($res_doc),'email');
700   - }
701   -
702   - function getContactTelephone($res_doc)
703   - {
704   - return $this->getFromNode($res_doc,$this->getContact($res_doc),'telephone');
705   - }
706   -
707   - function getContent($res_doc)
708   - {
709   - return $this->getFromNode($res_doc,$this->getDataCollection($res_doc),'content');
710   - }
711   -
712   - function getSubject($res_doc)
713   - {
714   - return $this->getFromNode($res_doc,$this->getContent($res_doc),'subject');
715   - }
716   -
717   - function getDescription($res_doc)
718   - {
719   - return $this->getFromNode($res_doc,$this->getContent($res_doc),'description');
720   - }
721   -
722   - function getReferenceURL($res_doc)
723   - {
724   - return $this->getFromNode($res_doc,$this->getContent($res_doc),'referenceURL');
725   - }
726   -
727   - function getContributor($res_doc)
728   - {
729   - return $this->getFromNode($res_doc,$this->getContent($res_doc),'contributor');
730   - }
731   -
732   - function getResource($res_doc)
733   - {
734   - return $this->getFromNode($res_doc,$this->getDataCollection($res_doc),'resource');
735   - }
736   -
737   - function getDataset($res_doc)
738   - {
739   - return $this->getFromNode($res_doc,$this->getResource($res_doc),'dataset');
740   - }
741   -
742   - function getGeneralMetadata($res_doc)
743   - {
744   - return $this->getFromNode($res_doc,$this->getDataset($res_doc),'generalMetadata');
745   - }
746   -
747   - function getFormat($res_doc)
748   - {
749   - return $this->getFromNode($res_doc,$this->getGeneralMetadata($res_doc),'format');
750   - }
751   -
752   - function getRight($res_doc)
753   - {
754   - return $this->getFromNode($res_doc,$this->getGeneralMetadata($res_doc),'right');
755   - }
756   -
757   - function getResourceType($res_doc)
758   - {
759   - return $this->getFromNode($res_doc,$this->getGeneralMetadata($res_doc),'resource_type');
760   - }
761   -
762   - function getCalibration($res_doc)
763   - {
764   - return $this->getFromNode($res_doc,$this->getGeneralMetadata($res_doc),'calibration');
765   - }
766   -
767   - function getInstrument($res_doc)
768   - {
769   - return $this->getFromNode($res_doc,$this->getDataset($res_doc),'instrument');
770   - }
771   -
772   - function getFacility($res_doc,$inst)
773   - {
774   - return $this->getFromNode($res_doc,(isset($inst) ? $inst : $this->getInstrument($res_doc)),'facility');
775   - }
776   -
777   - function getResourceName($res_doc,$inst)
778   - {
779   - return $this->getFromNode($res_doc,$this->getFacility($res_doc,$inst),'ResourceName');
780   - }
781   -
782   - function getInstrumentName($res_doc,$inst)
783   - {
784   - return $this->getFromNode($res_doc,(isset($inst) ? $inst : $this->getInstrument($res_doc)),'InstrumentName');
785   - }
786   -
787   - function getAlternateInstrumentName($res_doc,$inst)
788   - {
789   - return $this->getFromNode($res_doc,(isset($inst) ? $inst : $this->getInstrument($res_doc)),'alternateInstrumentName');
790   - }
791   -
792   - function getInstrumentClass($res_doc,$inst)
793   - {
794   - return $this->getFromNode($res_doc,(isset($inst) ? $inst : $this->getInstrument($res_doc)),'instrumentClass');
795   - }
796   -
797   - function getInstrumentReferenceURL($res_doc,$inst)
798   - {
799   - return $this->getFromNode($res_doc,(isset($inst) ? $inst : $this->getInstrument($res_doc)),'referenceURL');
800   - }
801   -
802   - function getAnyURI($res_doc,$inst)
803   - {
804   - return $this->getFromNode($res_doc,$this->getInstrumentReferenceURL($res_doc,$inst),'anyURI');
805   - }
806   -
807   - function getTargets($res_doc)
808   - {
809   - return $this->getFromNode($res_doc,$this->getDataset($res_doc),'targets');
810   - }
811   -
812   - function getTargetType($res_doc)
813   - {
814   - return $this->getFromNode($res_doc,$this->getTargets($res_doc),'TargetType');
815   - }
816   -
817   - function getTargetClass($res_doc)
818   - {
819   - return $this->getFromNode($res_doc,$this->getTargetType($res_doc),'targetClass');
820   - }
821   -
822   - function getCoverage($res_doc)
823   - {
824   - return $this->getFromNode($res_doc,$this->getDataCollection($res_doc),'coverage');
825   - }
826   -
827   - function getMeasurementType($res_doc)
828   - {
829   - return $this->getFromNode($res_doc,$this->getCoverage($res_doc),'measurementType');
830   - }
831   -
832   - function getAstroCoordSystem($res_doc)
833   - {
834   - return $this->getFromNode($res_doc,$this->getCoverage($res_doc),'AstroCoordSystem');
835   - }
836   -
837   - function getTimeFrame($res_doc)
838   - {
839   - return $this->getFromNode($res_doc,$this->getAstroCoordSystem($res_doc),'TimeFrame');
840   - }
841   -
842   - function getTimeScale($res_doc)
843   - {
844   - return $this->getFromNode($res_doc,$this->getTimeFrame($res_doc),'TimeScale');
845   - }
846   -
847   - function getAstroCoordArea($res_doc)
848   - {
849   - return $this->getFromNode($res_doc,$this->getCoverage($res_doc),'AstroCoordArea');
850   - }
851   -
852   - function getTimeInterval($res_doc)
853   - {
854   - return $this->getFromNode($res_doc,$this->getAstroCoordArea($res_doc),'TimeInterval');
855   - }
856   -
857   - function getIntegrationTime($res_doc)
858   - {
859   - return $this->getFromNode($res_doc,$this->getTimeInterval($res_doc),'resolution');
860   - }
861   -
862   - function getMinIntegrationTime($res_doc)
863   - {
864   - return $this->getFromNode($res_doc,$this->getIntegrationTime($res_doc),'minResolution');
865   - }
866   -
867   - function getMaxIntegrationTime($res_doc)
868   - {
869   - return $this->getFromNode($res_doc,$this->getIntegrationTime($res_doc),'maxResolution');
870   - }
871   -
872   - function getSamplingStep($res_doc)
873   - {
874   - return $this->getFromNode($res_doc,$this->getTimeInterval($res_doc),'SamplingStep');
875   - }
876   -
877   - function getMinSamplingStep($res_doc)
878   - {
879   - return $this->getFromNode($res_doc,$this->getSamplingStep($res_doc),'minSamplingStep');
880   - }
881   -
882   - function getMaxSamplingStep($res_doc)
883   - {
884   - return $this->getFromNode($res_doc,$this->getSamplingStep($res_doc),'maxSamplingStep');
885   - }
886   -
887   - function getStartTime($res_doc)
888   - {
889   - return $this->getFromNode($res_doc,$this->getTimeInterval($res_doc),'StartTime');
890   - }
891   -
892   - function getStartTimeISO($res_doc)
893   - {
894   - return $this->getFromNode($res_doc,$this->getStartTime($res_doc),'ISOTime');
895   - }
896   -
897   - function getStopTime($res_doc)
898   - {
899   - return $this->getFromNode($res_doc,$this->getTimeInterval($res_doc),'StopTime');
900   - }
901   -
902   - function getStopTimeISO($res_doc)
903   - {
904   - return $this->getFromNode($res_doc,$this->getStopTime($res_doc),'ISOTime');
905   - }
906   -
907   - function getSpectralInterval($res_doc)
908   - {
909   - return $this->getFromNode($res_doc,$this->getAstroCoordArea($res_doc),'SpectralInterval');
910   - }
911   -
912   - function getSpectralResolution($res_doc)
913   - {
914   - return $this->getFromNode($res_doc,$this->getSpectralInterval($res_doc),'resolution');
915   - }
916   -
917   - function getSpectralMinResolution($res_doc)
918   - {
919   - return $this->getFromNode($res_doc,$this->getSpectralResolution($res_doc),'minResolution');
920   - }
921   -
922   - function getSpectralMaxResolution($res_doc)
923   - {
924   - return $this->getFromNode($res_doc,$this->getSpectralResolution($res_doc),'maxResolution');
925   - }
926   -
927   - function getSpectralLoLimit($res_doc)
928   - {
929   - return $this->getFromNode($res_doc,$this->getSpectralInterval($res_doc),'LoLimit');
930   - }
931   -
932   - function getSpectralHiLimit($res_doc)
933   - {
934   - return $this->getFromNode($res_doc,$this->getSpectralInterval($res_doc),'HiLimit');
935   - }
936   -
937   - function getSpectralSamplingStep($res_doc)
938   - {
939   - return $this->getFromNode($res_doc,$this->getSpectralInterval($res_doc),'SamplingStep');
940   - }
941   -
942   - function getMinSpectralSamplingStep($res_doc)
943   - {
944   - return $this->getFromNode($res_doc,$this->getSpectralSamplingStep($res_doc),'minSamplingStep');
945   - }
946   -
947   - function getMaxSpectralSamplingStep($res_doc)
948   - {
949   - return $this->getFromNode($res_doc,$this->getSpectralSamplingStep($res_doc),'maxSamplingStep');
950   - }
951   -
952   - function getSpectralParticles($res_doc)
953   - {
954   - return $this->getFromNode($res_doc,$this->getAstroCoordArea($res_doc),'SpectralParticles');
955   - }
956   -
957   - function getParticlesResolution($res_doc)
958   - {
959   - return $this->getFromNode($res_doc,$this->getSpectralParticles($res_doc),'resolution');
960   - }
961   -
962   - function getParticlesMinResolution($res_doc)
963   - {
964   - return $this->getFromNode($res_doc,$this->getParticlesResolution($res_doc),'minResolution');
965   - }
966   -
967   - function getParticlesMaxResolution($res_doc)
968   - {
969   - return $this->getFromNode($res_doc,$this->getParticlesResolution($res_doc),'maxResolution');
970   - }
971   -
972   - function getParticlesLoLimit($res_doc)
973   - {
974   - return $this->getFromNode($res_doc,$this->getSpectralParticles($res_doc),'LoLimit');
975   - }
976   -
977   - function getParticlesHiLimit($res_doc)
978   - {
979   - return $this->getFromNode($res_doc,$this->getSpectralParticles($res_doc),'HiLimit');
980   - }
981   -
982   - function getParticlesSamplingStep($res_doc)
983   - {
984   - return $this->getFromNode($res_doc,$this->getSpectralParticles($res_doc),'SamplingStep');
985   - }
986   -
987   - function getMinParticlesSamplingStep($res_doc)
988   - {
989   - return $this->getFromNode($res_doc,$this->getParticlesSamplingStep($res_doc),'minSamplingStep');
990   - }
991   -
992   - function getMaxParticlesSamplingStep($res_doc)
993   - {
994   - return $this->getFromNode($res_doc,$this->getParticlesSamplingStep($res_doc),'maxSamplingStep');
995   - }
996   -
997   - function getTableset($res_doc)
998   - {
999   - return $this->getFromNode($res_doc,$this->getDataCollection($res_doc),'tableset');
1000   - }
1001   -
1002   - function getSchema($res_doc)
1003   - {
1004   - return $this->getFromNode($res_doc,$this->getTableset($res_doc),'schema');
1005   - }
1006   -
1007   - function getSchemaColumn($res_doc)
1008   - {
1009   - return $this->getFromNode($res_doc,$this->getSchema($res_doc),'column');
1010   - }
1011   -
1012   - function getSchemaColumnName($res_doc)
1013   - {
1014   - return $this->getFromNode($res_doc,$this->getSchemaColumn($res_doc),'name');
1015   - }
1016   -
1017   - function getSchemaColumnDescription($res_doc)
1018   - {
1019   - return $this->getFromNode($res_doc,$this->getSchemaColumn($res_doc),'description');
1020   - }
1021   -
1022   - function getSchemaColumnUnit($res_doc)
1023   - {
1024   - return $this->getFromNode($res_doc,$this->getSchemaColumn($res_doc),'unit');
1025   - }
1026   -
1027   - function getSchemaColumnUCD($res_doc)
1028   - {
1029   - return $this->getFromNode($res_doc,$this->getSchemaColumn($res_doc),'ucd');
1030   - }
1031   -
1032   - function getSchemaColumnDataType($res_doc)
1033   - {
1034   - return $this->getFromNode($res_doc,$this->getSchemaColumn($res_doc),'dataType');
1035   - }
1036   -
1037   - function getSchemaColumnDataproductType($res_doc)
1038   - {
1039   - return $this->getFromNode($res_doc,$this->getSchemaColumn($res_doc),'dataproduct_type');
1040   - }
1041   -}
1042   -?>
1043 0 \ No newline at end of file
php/classes/FilesMgr.php
1 1 <?php
2 2 /**
3   - * @class FilesMgr
  3 + * @class NewFilesMgr
4 4 * @brief
5 5 * @author Elena
6 6 * @version $Id: FilesMgr.php 2830 2015-03-26 10:33:05Z elena $
... ... @@ -9,1224 +9,1240 @@
9 9 // private $userDirs = array('USERWSDIR' => 'WS', 'USERREQDIR' => 'REQ', 'USERDATADIR' => 'DATA',
10 10 // 'USERWORKINGDIR' =>'RES', 'USERTTDIR' => 'TT', 'USERJOBDIR' => 'JOBS');
11 11  
12   -class FilesMgr extends AmdaObjectMgr {
13   -
14   - private $fileName, $fileId, $theFile;
15   - public $xp;
16   - private $fileMgr = NULL; //used when a file format needs to use a specific manager
17   - private $sampling = -100.0, $maxSampling = -100.0;
18   - private $ncID = NULL;
19   - private $simuContentRootId;
20   -
21   - function __construct()
22   - {
23   - parent::__construct('Files.xml');
24   - $this->contentRootId = 'myData-treeRootNode';
25   - $this->contentRootTag = 'fileList';
26   - $this->attributes = array('name' => '', 'start' => '', 'stop' => '');
27   - $this->optionalAttributes = array();
28   - $this->objTagName = 'file';
29   -
30   - if (!file_exists($this->xmlName)) {
31   - $this->createDom();
32   - $this->xp = new domxpath($this->contentDom);
33   - }
34   - }
  12 +class FilesMgr extends AmdaObjectMgr
  13 +{
  14 +
  15 + private $fileName, $fileId, $theFile;
  16 +
  17 + public $xp;
  18 + private $fileMgr = NULL; //used when a file format needs to use a specific manager
  19 + private $sampling = -100.0, $maxSampling = -100.0;
  20 + private $ncID = NULL;
  21 + private $simuContentRootId;
  22 +
  23 + function __construct()
  24 + {
  25 + parent::__construct('Files.xml');
  26 + $this->contentRootId = 'myData-treeRootNode';
  27 + $this->contentRootTag = 'fileList';
  28 + $this->attributes = array('name' => '', 'start' => '', 'stop' => '');
  29 + $this->optionalAttributes = array();
  30 + $this->objTagName = 'file';
  31 +
  32 + if (!file_exists($this->xmlName))
  33 + {
  34 + $this->createDom();
  35 + $this->xp = new domxpath($this->contentDom);
  36 + }
  37 + }
35 38  
36 39 /*
37 40 * Create Content Dom 'Files.xml' if it doesn't exist
38 41 */
39   - protected function createDom()
40   - {
41   - $rootElement = $this->contentDom->createElement('ws');
42   -
43   - $typeElement = $this->contentDom->createElement($this->contentRootTag);
44   - $typeElement->setAttribute('xml:id', $this->contentRootId);
45   - $rootElement->appendChild($typeElement);
46   - $this->contentDom->appendChild($rootElement);
47   -
48   - // $typeElement = $this->contentDom->createElement($this->contentRootTag);
49   - // $rootElement->appendChild($typeElement);
50   - // $this->contentDom->appendChild($rootElement);
51   -
52   - $this->contentDom->save($this->xmlName);
53   - }
54   -
  42 + protected function createDom()
  43 + {
  44 + $rootElement = $this->contentDom->createElement('ws');
  45 +
  46 + $typeElement = $this->contentDom->createElement($this->contentRootTag);
  47 + $typeElement->setAttribute('xml:id', $this->contentRootId);
  48 + $rootElement->appendChild($typeElement);
  49 + $this->contentDom->appendChild($rootElement);
  50 +
  51 + $this->contentDom->save($this->xmlName);
  52 + }
  53 +
55 54 /*
56 55 * VOTable format processing done by an instance of VOTableMgr
57 56 */
58   -
59   - protected function getVotFileMgr()
60   - {
61   - if (!$this->fileMgr)
62   - {
63   - $this->fileMgr = new VOTableMgr();
64   - $this->fileMgr->load($this->fileName);
65   - }
66   -
67   - return $this->fileMgr;
68   - }
69   -
70   -
  57 + protected function getVotFileMgr()
  58 + {
  59 + if (!$this->fileMgr)
  60 + {
  61 + $this->fileMgr = new VOTableMgr();
  62 + $this->fileMgr->load($this->fileName);
  63 + }
  64 + return $this->fileMgr;
  65 + }
  66 +
71 67 /*
72 68 * CDF format processing
73 69 */
74   - protected function getCdfStartStop()
75   - {
76   - exec('cdfstartstopfromdata '.$this->fileName, $start_stop);
77   - return $start_stop[0];
78   - }
79   -
80   - protected function getCdfVars()
81   - {
82   - exec('cdfinfo '.$this->fileName, $results);
83   - return $results;
84   - }
85   -
86   -
87   - protected function getCdfVarInfo($cdfVarId)
88   - {
89   - exec('cdfvarinfo '.$this->fileName.' '.$cdfVarId, $results);
90   - $tempArr = explode(' ', $results[0]);
91   - // data type
92   - switch ($tempArr[0])
93   - {
94   - case "CDF_FLOAT" :
95   - case "CDF_REAL4" : $data_type = 'FLOAT';
96   - break;
97   - case "CDF_INT2":
98   - case "CDF_UCHAR":
99   - case "CDF_UINT1" : $data_type = 'SHORT';
100   - break;
101   - case "CDF_UINT2":
102   - case "CDF_INT4" : $data_type = 'INTEGER';
103   - break;
104   - case "CDF_DOUBLE":
105   - case "CDF_REAL8":
106   - case "CDF_UINT4": $data_type = 'DOUBLE';
107   - break;
108   - default : $data_type = 'FLOAT';
109   - }
110   - // data dimensions & number of records
111   - $n_recs = $tempArr[2];
112   -
113   - if ($tempArr[1] != 0) {
114   - $size = $tempArr[3];
115   - //TODO 2D,3D,4D array no processing
116   - // if ($tempArr[1] > 1)
117   - }
118   - else {
119   - $size = 1;
120   - }
121   -
122   - return array('type' => $data_type, 'size' => $size, 'n_records' => $n_recs);
123   - }
  70 + protected function getCdfStartStop()
  71 + {
  72 + exec('cdfstartstopfromdata '.$this->fileName, $start_stop);
  73 + return $start_stop[0];
  74 + }
  75 +
  76 + protected function getCdfVars()
  77 + {
  78 + exec('cdfinfo '.$this->fileName, $results);
  79 + return $results;
  80 + }
  81 +
  82 + public function getCdfVarInfo($cdfVarId)
  83 + {
  84 + exec('cdfvarinfo '.$this->fileName.' '.$cdfVarId, $results);
  85 + $tempArr = explode(' ', $results[0]);
  86 + // data type
  87 + switch ($tempArr[0])
  88 + {
  89 + case "CDF_FLOAT" :
  90 + case "CDF_REAL4" : $data_type = 'FLOAT';
  91 + break;
  92 + case "CDF_INT2":
  93 + case "CDF_UCHAR":
  94 + case "CDF_UINT1" : $data_type = 'SHORT';
  95 + break;
  96 + case "CDF_UINT2":
  97 + case "CDF_INT4" : $data_type = 'INTEGER';
  98 + break;
  99 + case "CDF_DOUBLE":
  100 + case "CDF_REAL8":
  101 + case "CDF_UINT4": $data_type = 'DOUBLE';
  102 + break;
  103 + default : $data_type = 'FLOAT';
  104 + }
  105 + // data dimensions & number of records
  106 + $n_recs = $tempArr[2];
  107 +
  108 + if ($tempArr[1] != 0) {
  109 + $size = $tempArr[3];
  110 + //TODO 2D,3D,4D array no processing
  111 + // if ($tempArr[1] > 1)
  112 + }
  113 + else {
  114 + $size = 1;
  115 + }
124 116  
125   - protected function getCdfSampling()
126   - {
127   - copy($this->fileName, "temp.cdf");
128   - exec('cdfsamplingfromdata ', $results);
129   - unlink("temp.cdf");
  117 + return array('type' => $data_type, 'size' => $size, 'n_records' => $n_recs);
  118 + }
130 119  
131   - return $results;
132   - }
  120 + public function getCdfSampling()
  121 + {
  122 + copy($this->fileName, "temp.cdf");
  123 + exec('cdfsamplingfromdata ', $results);
  124 + unlink("temp.cdf");
133 125  
  126 + return $results;
  127 + }
134 128  
135 129 /*
136 130 * CEF format processing
137 131 */
138   - protected function getCefStartStop() {
139   - exec("cefstartstop ".$this->fileName, $start_stop);
140   - return $start_stop[0];
141   - }
142   -
143   - protected function getCefTimeInfo() {
144   -
145   - $timeinfo = exec("ceftimeinfo ".$this->fileName);
146   -
147   - return $timeinfo;
148   - }
149   -
150   - protected function getCefVars() {
151   - exec('cefinfo '.$this->fileName, $results);
152   - return $results;
153   - }
154   -
155   - protected function getCefVarInfo($cdfVarId) {
156   - exec('cefvarinfo '.$this->fileName." ".$cdfVarId, $results);
157   -
158   - $tempArr = explode(' ', $results[0]);
159   - // data type
160   - switch ($tempArr[0]) {
161   - case "CEF_FLOAT" : $data_type = 'FLOAT';
162   - break;
163   - case "CEF_SHORT": $data_type = 'SHORT';
164   - break;
165   - case "CEF_INT": $data_type = 'INTEGER';
166   - break;
167   - case "CEF_DOUBLE": $data_type = 'DOUBLE';
168   - break;
169   - default : $data_type = 'FLOAT';
170   - }
171   - // data dimensions & number of records3
172   - $n_recs = $tempArr[2];
173   -
174   - if ($tempArr[1] != 0) {
175   - $size = $tempArr[3];
176   - //TODO 2D,3D,4D array no processing
177   - // if ($tempArr[1] > 1)
178   - }
179   - else {
180   - $size = 1;
181   - }
182   -
183   - return array('type' => $data_type, 'size' => $size, 'n_records' => 'TBD');
184   - }
  132 + protected function getcefstartstop()
  133 + {
  134 + exec("cefstartstop ".$this->filename, $start_stop);
  135 + return $start_stop[0];
  136 + }
185 137  
186   - protected function getCefSampling() {
187   - exec('cefsampling '.$this->fileName, $results);
188   - return $results;
189   - }
  138 + protected function getCefTimeInfo()
  139 + {
  140 + $timeinfo = exec("ceftimeinfo ".$this->fileName);
  141 + return $timeinfo;
  142 + }
  143 +
  144 + protected function getCefVars()
  145 + {
  146 + exec('cefinfo '.$this->fileName, $results);
  147 + return $results;
  148 + }
  149 +
  150 + protected function getCefVarInfo($cdfVarId)
  151 + {
  152 + exec('cefvarinfo '.$this->fileName." ".$cdfVarId, $results);
  153 +
  154 + $tempArr = explode(' ', $results[0]);
  155 + // data type
  156 + switch ($tempArr[0]) {
  157 + case "CEF_FLOAT" : $data_type = 'FLOAT';
  158 + break;
  159 + case "CEF_SHORT": $data_type = 'SHORT';
  160 + break;
  161 + case "CEF_INT": $data_type = 'INTEGER';
  162 + break;
  163 + case "CEF_DOUBLE": $data_type = 'DOUBLE';
  164 + break;
  165 + default : $data_type = 'FLOAT';
  166 + }
  167 + // data dimensions & number of records3
  168 + $n_recs = $tempArr[2];
  169 +
  170 + if ($tempArr[1] != 0) {
  171 + $size = $tempArr[3];
  172 + //TODO 2D,3D,4D array no processing
  173 + // if ($tempArr[1] > 1)
  174 + }
  175 + else {
  176 + $size = 1;
  177 + }
  178 + return array('type' => $data_type, 'size' => $size, 'n_records' => 'TBD');
  179 + }
  180 +
  181 + protected function getCefSampling()
  182 + {
  183 + exec('cefsampling '.$this->fileName, $results);
  184 + return $results;
  185 + }
190 186  
191 187 /*
192 188 * netCDF format processing if needed
193 189 */
194   - protected function reformatNcTime() {
195   - exec('nctimestring2double '.$this->fileName, $results);
196   - return $results[0];
197   - }
  190 + protected function reformatNcTime()
  191 + {
  192 + exec('nctimestring2double '.$this->fileName, $results);
  193 + return $results[0];
  194 + }
198 195  
199   - protected function getNcTimeInfo() {
200   - exec('nctimeinfo '.$this->fileName, $result);
201   - return $result[0];
202   - }
203   -
204   - protected function getNcVars(){
205   - exec('getncvars '.$this->fileName, $result);
206   - if ($result[0] < 0)
207   - return $result[0];
208   - $varsArr = explode("#",$result[0]);
209   -
210   - return $varsArr;
211   - }
212   -
213   - protected function getNcVarInfo($varId) {
214   -
215   - exec('ncvarinfo '.$this->fileName.' '.$this->param2dd($varId), $results);
216   - $tempArr = explode(' ', $results[0]);
217   - // data type
218   - switch ($tempArr[0]) {
219   - case "5": $data_type = 'FLOAT';
220   - break;
221   - case "3": $data_type = 'SHORT';
222   - break;
223   - case "4" : $data_type = 'INTEGER';
224   - break;
225   - case "6": $data_type = 'DOUBLE';
226   - break;
227   - default: $data_type = 'FLOAT';
228   - }
229   - // data dimensions & number of records
230   - $n_recs = $tempArr[2];
231   -
232   - if (count($tempArr) > 3) {
233   - $size = $tempArr[3];
234   - //TODO 2D,3D,4D array no processing
235   - // if ($tempArr[1] > 1)
236   - }
237   - else {
238   - $size = 1;
239   - }
240   - return array('type' => $data_type, 'size' => $size, 'n_records' => $n_recs);
241   - }
242   -
243   - protected function param2dd($paramID)
244   - {
245   - $pairs = array("-" => "_", "%" => "_","\\" => "_","$" => "_",":" => "_","+" =>" _","-" => "_","#" => "_","@" => "_", "." => "_",">" => "_", "<" => "_");
246   - return strtr($paramID, $pairs);
247   - }
  196 + protected function getNcTimeInfo()
  197 + {
  198 + exec('nctimeinfo '.$this->fileName, $result);
  199 + return $result[0];
  200 + }
  201 +
  202 + protected function getNcVars()
  203 + {
  204 + exec('getncvars '.$this->fileName, $result);
  205 +
  206 + if ($result[0] < 0)
  207 + return $result[0];
  208 + $varsArr = explode("#",$result[0]);
  209 +
  210 + return $varsArr;
  211 + }
  212 +
  213 + protected function getNcVarInfo($varId)
  214 + {
  215 + exec('ncvarinfo '.$this->fileName.' '.$this->param2dd($varId), $results);
  216 + $tempArr = explode(' ', $results[0]);
  217 + // data type
  218 + switch ($tempArr[0]) {
  219 + case "5": $data_type = 'FLOAT';
  220 + break;
  221 + case "3": $data_type = 'SHORT';
  222 + break;
  223 + case "4" : $data_type = 'INTEGER';
  224 + break;
  225 + case "6": $data_type = 'DOUBLE';
  226 + break;
  227 + default: $data_type = 'FLOAT';
  228 + }
  229 + // data dimensions & number of records
  230 + $n_recs = $tempArr[2];
  231 +
  232 + if (count($tempArr) > 3) {
  233 + $size = $tempArr[3];
  234 + //TODO 2D,3D,4D array no processing
  235 + // if ($tempArr[1] > 1)
  236 + }
  237 + else {
  238 + $size = 1;
  239 + }
  240 +
  241 + return array('type' => $data_type, 'size' => $size, 'n_records' => $n_recs);
  242 + }
  243 +
  244 + protected function param2dd($paramID)
  245 + {
  246 + $pairs = array("-" => "_", "%" => "_","\\" => "_","$" => "_",":" => "_","+" =>" _","-" => "_","#" => "_","@" => "_", "." => "_",">" => "_", "<" => "_");
  247 + return strtr($paramID, $pairs);
  248 + }
248 249  
249 250 /*
250 251 * ascii format processing
251 252 */
252   - protected function getTxtSampling() {
253   -
254   - $StartTime = null;
255   - if (!file_exists($this->fileName)) return -100;
256   - $i = 0;
257   - $dt = -10;
258   -
259   - $handler = fopen($this->fileName, 'r');
260   - if ($handler) {
261   - while (!feof($handler) && !$StartTime) {
262   - $oneLine = trim(fgets($handler));
263   - $elems = explode(" ", preg_replace('/\s+/', ' ', $oneLine));
264   - if ((strlen($elems[0]) < 16) || !($time = strtotime($elems[0]))) {
265   - $i++;
266   - continue;
267   - }
268   - $StartTime = $time;
269   - if (is_numeric($elems[1])) $dt = $elems[1];
270   - //else Array for sure !!!
271   - }
272   - }
273   -
274   - if (feof($handle)) return -10;
275   -
276   - $oneLine = trim(fgets($handler));
277   - $elems = explode(" ",$oneLine);
278   - if (count($elems) < 2) return -10;
279   -
280   - // dT else Array
281   - if (!($time = strtotime($elems[0]))) {
282   - return $dt;
283   - }
284   -
285   - return $time - $StartTime;
286   - }
  253 + protected function getTxtSampling()
  254 + {
  255 + $StartTime = null;
  256 + if (!file_exists($this->fileName)) return -100;
  257 + $i = 0;
  258 + $dt = -10;
  259 +
  260 + $handler = fopen($this->fileName, 'r');
  261 + if ($handler) {
  262 + while (!feof($handler) && !$StartTime) {
  263 + $oneLine = trim(fgets($handler));
  264 + $elems = explode(" ", preg_replace('/\s+/', ' ', $oneLine));
  265 + if ((strlen($elems[0]) < 16) || !($time = strtotime($elems[0]))) {
  266 + $i++;
  267 + continue;
  268 + }
  269 + $StartTime = $time;
  270 + if (is_numeric($elems[1])) $dt = $elems[1];
  271 + //else Array for sure !!!
  272 + }
  273 + }
  274 +
  275 + if (feof($handle)) return -10;
  276 +
  277 + $oneLine = trim(fgets($handler));
  278 + $elems = explode(" ",$oneLine);
  279 + if (count($elems) < 2) return -10;
  280 +
  281 + // dT else Array
  282 + if (!($time = strtotime($elems[0]))) {
  283 + return $dt;
  284 + }
  285 +
  286 + return $time - $StartTime;
  287 + }
287 288  
288 289  
289   - public function getTxtSamplings() {
290   -
291   - $StartTime = null;
292   - if (!file_exists($this->fileName)) return array(-100);
293   -
294   - $handler = fopen($this->fileName, 'r');
295   - if ($handler) {
296   - $i = 0;
297   - while (!feof($handler) && !$StartTime) {
298   - $oneLine = trim(fgets($handler));
299   - $elems = explode(" ", preg_replace('/\s+/', ' ', $oneLine));
300   - if (strlen($elems[0]) < 16 || !($time = strtotime($elems[0]))) {
301   - $i++;
302   - continue;
303   - }
304   -
305   - $StartTime = $time;
306   - if (!(is_numeric($elems[1]))) return array(-10);
307   - $dt = $elems[1];
308   - }
309   - }
310   -
311   - if (feof($handle)) return array(-10);
312   - $oneLine = trim(fgets($handler));
313   - $elems = explode(" ",$oneLine);
314   - if (count($elems) < 2) return array (-1);
  290 + public function getTxtSamplings()
  291 + {
  292 + $StartTime = null;
  293 + if (!file_exists($this->fileName)) return array(-100);
  294 +
  295 + $handler = fopen($this->fileName, 'r');
  296 + if ($handler) {
  297 + $i = 0;
  298 + while (!feof($handler) && !$StartTime) {
  299 + $oneLine = trim(fgets($handler));
  300 + $elems = explode(" ", preg_replace('/\s+/', ' ', $oneLine));
  301 + if (strlen($elems[0]) < 16 || !($time = strtotime($elems[0]))) {
  302 + $i++;
  303 + continue;
  304 + }
  305 +
  306 + $StartTime = $time;
  307 + if (!(is_numeric($elems[1]))) return array(-10);
  308 + $dt = $elems[1];
  309 + }
  310 + }
  311 +
  312 + if (feof($handle)) return array(-10);
  313 + $oneLine = trim(fgets($handler));
  314 + $elems = explode(" ",$oneLine);
  315 + if (count($elems) < 2) return array (-1);
315 316 // dT else Array
316   - if (!($time = strtotime($elems[0]))) return array($dt);
317   - else {
318   - $minSampling = +1.e31;
319   - $maxSampling = 0.0;
320   -
321   - while (!feof($handler)) {
322   - $oneLine = trim(fgets($handler));
323   - $elems = explode(" ",$oneLine);
324   - if (count($elems) < 2) continue;
325   - $StartTime = $time;
326   - if (!($time = strtotime($elems[0]))) return array(-1);
327   - $deltaT[$time - $StartTime]++;
328   - }
329   -
330   - foreach ($deltaT as $key => $value) {
331   - if ($value < 5) continue;
332   - if ($key < $minSampling) $minSampling = $key;
333   - if ($key > $maxSampling) $maxSampling = $key;
334   - }
335   -
336   - return array($minSampling,$maxSampling);
337   - }
338   - }
  317 + if (!($time = strtotime($elems[0])))
  318 + return array($dt);
  319 + else
  320 + {
  321 + $minSampling = +1.e31;
  322 + $maxSampling = 0.0;
  323 +
  324 + while (!feof($handler))
  325 + {
  326 + $oneLine = trim(fgets($handler));
  327 + $elems = explode(" ",$oneLine);
  328 + if (count($elems) < 2) continue;
  329 + $StartTime = $time;
  330 + if (!($time = strtotime($elems[0]))) return array(-1);
  331 + $deltaT[$time - $StartTime]++;
  332 + }
  333 +
  334 + foreach ($deltaT as $key => $value)
  335 + {
  336 + if ($value < 5) continue;
  337 + if ($key < $minSampling) $minSampling = $key;
  338 + if ($key > $maxSampling) $maxSampling = $key;
  339 + }
  340 +
  341 + return array($minSampling,$maxSampling);
  342 + }
  343 + }
339 344  
340 345 /*
341 346 * Delete comments and convert time into double
342 347 */
343   - public function reformatTxt() {
344   -
345   - $StartTime = null;
346   - if (!file_exists($this->fileName)) return -100;
347   -
348   - $handler = fopen($this->fileName, 'r');
349   - if ($handler) {
350   - $offset = ftell($handle);
351   - $i = 0;
352   - while (!$StartTime && !feof($handler)) {
353   - $oneLine = trim(fgets($handler));
354   - $elems = explode(" ", preg_replace('/\s+/', ' ', $oneLine));
355   - if (!($time = strtotime($elems[0]))) {
356   - $offset = ftell($handle);
357   - $i++;
358   - continue;
359   - }
360   - $StartTime = $time;
361   - $dt = $elems[1];
362   - }
363   - }
  348 + public function reformatTxt()
  349 + {
  350 + $StartTime = null;
  351 + if (!file_exists($this->fileName)) return -100;
  352 +
  353 + $handler = fopen($this->fileName, 'r');
  354 + if ($handler)
  355 + {
  356 + $offset = ftell($handle);
  357 + $i = 0;
  358 + while (!$StartTime && !feof($handler))
  359 + {
  360 + $oneLine = trim(fgets($handler));
  361 + $elems = explode(" ", preg_replace('/\s+/', ' ', $oneLine));
  362 + if (!($time = strtotime($elems[0])))
  363 + {
  364 + $offset = ftell($handle);
  365 + $i++;
  366 + continue;
  367 + }
  368 + $StartTime = $time;
  369 + $dt = $elems[1];
  370 + }
  371 + }
364 372  
365   - $newfile = fopen(USERDATADIR."temp", "w");
366   -
367   - $oneLine = trim(fgets($handler));
368   - $elems = explode(" " , $oneLine);
369   - // dT
370   - if (!($time = strtotime($elems[0]))) {
371   -
372   - $newtime = $StartTime;
373   - settype($dt, "float");
374   - if ($oneLine != PHP_EOL && count($elems) > 0) fwrite($newfile, $newtime." ".$oneLine.PHP_EOL);
375   - $newtime += $dt;
376   -
377   - while (!feof($handler)) {
378   - $oneLine = trim(fgets($handler));
379   - if ($oneLine != PHP_EOL && count($elems) > 0) fwrite($newfile, $newtime." ".$oneLine.PHP_EOL);
380   - $newtime += $dt;
381   - }
382   - }
383   - // Array
384   - else {
385   - fseek($handler, $offset);
386   - while (!feof($handler)) {
387   - $oneLine = trim(fgets($handler));
388   - $elems = explode(" " ,$oneLine);
389   - // empty lines
390   - if (count($elems) < 2) continue;
391   - $newtime = strtotime($elems[0]);
392   - //TODO Error message if wrong time format...???
393   - if (!$newtime) continue;
394   - unset($elems[0]);
395   - $newline = join($elems," ");
396   - fwrite($newfile,$newtime." ". $newline.PHP_EOL);
397   - }
398   - }
399   - fclose($newfile);
400   -
401   - rename(USERDATADIR."temp",$this->fileName);
402   -
403   - return $StartTime." ".$newtime;
404   - }
  373 + $newfile = fopen(USERDATADIR."temp", "w");
  374 +
  375 + $oneLine = trim(fgets($handler));
  376 + $elems = explode(" " , $oneLine);
  377 + // dT
  378 + if (!($time = strtotime($elems[0])))
  379 + {
  380 + $newtime = $StartTime;
  381 + settype($dt, "float");
  382 + if ($oneLine != PHP_EOL && count($elems) > 0) fwrite($newfile, $newtime." ".$oneLine.PHP_EOL);
  383 + $newtime += $dt;
  384 +
  385 + while (!feof($handler))
  386 + {
  387 + $oneLine = trim(fgets($handler));
  388 + if ($oneLine != PHP_EOL && count($elems) > 0) fwrite($newfile, $newtime." ".$oneLine.PHP_EOL);
  389 + $newtime += $dt;
  390 + }
  391 + }
  392 + // Array
  393 + else
  394 + {
  395 + fseek($handler, $offset);
  396 + while (!feof($handler))
  397 + {
  398 + $oneLine = trim(fgets($handler));
  399 + $elems = explode(" " ,$oneLine);
  400 + // empty lines
  401 + if (count($elems) < 2) continue;
  402 + $newtime = strtotime($elems[0]);
  403 + //TODO Error message if wrong time format...???
  404 + if (!$newtime) continue;
  405 + unset($elems[0]);
  406 + $newline = join($elems," ");
  407 + fwrite($newfile,$newtime." ". $newline.PHP_EOL);
  408 + }
  409 + }
  410 + fclose($newfile);
  411 +
  412 + rename(USERDATADIR."temp",$this->fileName);
  413 +
  414 + return $StartTime." ".$newtime;
  415 + }
405 416  
406 417 /*
407 418 * Convert time into ISO
408 419 */
409   - protected function reformatTime($timeFormat, $timeLength, $doy) {
410   -
411   - $formatLength = $timeLength == 'auto' ? strlen($timeFormat) + (strpos($timeFormat,"Y") !== false)*3 + (strpos($timeFormat,"y") !== false)
412   - + (strpos($timeFormat,"M") !== false)*2 + (strpos($timeFormat,"m") !== false)
413   - + (strpos($timeFormat,"d") !== false) + (strpos($timeFormat,"H") !== false)
414   - + (strpos($timeFormat,"i") !== false) + (strpos($timeFormat,"s") !== false)
415   - + (strpos($timeFormat,".u") !== false)*2 : $timeLength;
  420 + protected function reformatTime($timeFormat, $timeLength, $doy)
  421 + {
  422 + $formatLength = $timeLength == 'auto' ? strlen($timeFormat) + (strpos($timeFormat,"Y") !== false)*3 + (strpos($timeFormat,"y") !== false)
  423 + + (strpos($timeFormat,"M") !== false)*2 + (strpos($timeFormat,"m") !== false)
  424 + + (strpos($timeFormat,"d") !== false) + (strpos($timeFormat,"H") !== false)
  425 + + (strpos($timeFormat,"i") !== false) + (strpos($timeFormat,"s") !== false)
  426 + + (strpos($timeFormat,".u") !== false)*2 : $timeLength;
416 427  
417   - if (strpos($timeFormat,".u") !== false) {
418   - $formatLength = $formatLength - 4;
419   - $timeFormat = substr($timeFormat, 0, strlen($timeFormat)-2);
420   - }
  428 + if (strpos($timeFormat,".u") !== false)
  429 + {
  430 + $formatLength = $formatLength - 4;
  431 + $timeFormat = substr($timeFormat, 0, strlen($timeFormat)-2);
  432 + }
421 433  
422   - if (strpos($timeFormat,".k") !== false) {
423   - $formatLength = $formatLength - 2;
424   - $timeFormat = substr($timeFormat, 0, strlen($timeFormat)-2);
425   - }
  434 + if (strpos($timeFormat,".k") !== false)
  435 + {
  436 + $formatLength = $formatLength - 2;
  437 + $timeFormat = substr($timeFormat, 0, strlen($timeFormat)-2);
  438 + }
426 439  
427   - $handle = fopen($this->fileName,'r');
  440 + $handle = fopen($this->fileName,'r');
428 441  
429   - if ($handle) {
430   - $newfile = fopen(USERDATADIR."temp", "w");
431   - while (!feof($handle)) {
432   - if (($oneLine = fgets($handle)) !== false) {
433   - $line = $timeLength == 'auto' ? $line = trim(preg_replace('/\s+/', ' ', $oneLine)) : trim($oneLine);
434   -
435   - if (strlen($line) > $formatLength) {
436   - try
437   - {
438   - $date = DateTime::createFromFormat($timeFormat, trim(substr($line,0,$formatLength)));
439   - if (!$date) {
440   - if (strpos($line,'#') === 0) fwrite($newfile, $line.PHP_EOL);
441   - }
442   - else {
443   - // DOY starts from 1
444   - if ($doy) {
445   - $date->modify('-1 day');
446   - }
447   - $suffix = preg_replace('/\s+/', ' ',substr($line, $formatLength));
448   - fwrite($newfile,$date->format('Y-m-d')."T".$date->format('H:i:s').$suffix.PHP_EOL);
449   - }
450   - }
451   - catch (Exception $e)
452   - {
453   - // fwrite($newfile,$line.PHP_EOL);
454   - }
455   - }
456   - else
457   - if (strpos($line,'#') === 0) fwrite($newfile,$line.PHP_EOL);
458   - }
459   - }
460   - }
461   - else {
462   - if (file_exists($this->fileName)) {
463   - fclose($handle);
464   - unlink($this->fileName);
465   - }
466   - return $false;
467   - }
468   -
469   - fclose($newfile);
470   - fclose($handle);
471   -
472   - rename(USERDATADIR."temp", $this->fileName);
473   - return true;
474   - }
  442 + if ($handle)
  443 + {
  444 + $newfile = fopen(USERDATADIR."temp", "w");
  445 + while (!feof($handle))
  446 + {
  447 + if (($oneLine = fgets($handle)) !== false)
  448 + {
  449 + $line = $timeLength == 'auto' ? $line = trim(preg_replace('/\s+/', ' ', $oneLine)) : trim($oneLine);
  450 +
  451 + if (strlen($line) > $formatLength)
  452 + {
  453 + try
  454 + {
  455 + $date = DateTime::createFromFormat($timeFormat, trim(substr($line,0,$formatLength)));
  456 + if (!$date)
  457 + {
  458 + if (strpos($line,'#') === 0) fwrite($newfile, $line.PHP_EOL);
  459 + }
  460 + else
  461 + {
  462 + // DOY starts from 1
  463 + if ($doy) {
  464 + $date->modify('-1 day');
  465 + }
  466 + $suffix = preg_replace('/\s+/', ' ',substr($line, $formatLength));
  467 + fwrite($newfile,$date->format('Y-m-d')."T".$date->format('H:i:s').$suffix.PHP_EOL);
  468 + }
  469 + }
  470 + catch (Exception $e)
  471 + {
  472 + // fwrite($newfile,$line.PHP_EOL);
  473 + }
  474 + }
  475 + else
  476 + if (strpos($line,'#') === 0) fwrite($newfile,$line.PHP_EOL);
  477 + }
  478 + }
  479 + }
  480 + else
  481 + {
  482 + if (file_exists($this->fileName))
  483 + {
  484 + fclose($handle);
  485 + unlink($this->fileName);
  486 + }
  487 + return $false;
  488 + }
  489 +
  490 + fclose($newfile);
  491 + fclose($handle);
  492 +
  493 + rename(USERDATADIR."temp", $this->fileName);
  494 + return true;
  495 + }
475 496  
476 497  
477 498 /*
478   -* Returns number of columns in text file to create data model fields in MyDataUI.js
  499 +* Returns number of columns in text file to create data model fields in MyDataUI.js
479 500 */
480   - protected function getTxtColNumber($timeDouble) {
481   -
482   - if (!file_exists($this->fileName)) return -100;
483   - $handle = fopen($this->fileName,'r');
484   -
485   - if ($handle) {
486   - $found = false;
487   - $i = 0;
488   - while (($line = trim(fgets($handle))) !== false && $i < 100) {
489   - $elems = explode(" ", preg_replace('/\s+/', ' ', $line));
490   - $i++;
491   - if (count($elems) < 2 || strpos($elems[0], '#') === 0) continue;
492   -
493   - if (!$timeDouble) {
494   - if (strlen($elems[0]) >= 16 && ($time = strtotime($elems[0]))) {
495   - $found = true;
496   - break;
497   - }
498   - }
499   - else {
500   - $found = true;
501   - break;
502   - }
503   - }
504   -
505   - if (!feof($handle) && !$found) {
506   - fclose($handle);
507   - unlink($this->fileName);
508   - return -1;
509   - }
510   - }
511   - fclose($handle);
512   -
513   - if (!$found) {
514   - unlink($this->fileName);
515   - return 0;
516   - }
517   - return count($elems);
518   - }
  501 + protected function getTxtColNumber($timeDouble)
  502 + {
  503 + if (!file_exists($this->fileName)) return -100;
  504 + $handle = fopen($this->fileName,'r');
  505 +
  506 + if ($handle)
  507 + {
  508 + $found = false;
  509 + $i = 0;
  510 + while (($line = trim(fgets($handle))) !== false && $i < 100)
  511 + {
  512 + $elems = explode(" ", preg_replace('/\s+/', ' ', $line));
  513 + $i++;
  514 + if (count($elems) < 2 || strpos($elems[0], '#') === 0) continue;
  515 +
  516 + if (!$timeDouble)
  517 + {
  518 + if (strlen($elems[0]) >= 16 && ($time = strtotime($elems[0])))
  519 + {
  520 + $found = true;
  521 + break;
  522 + }
  523 + }
  524 + else
  525 + {
  526 + $found = true;
  527 + break;
  528 + }
  529 + }
  530 +
  531 + if (!feof($handle) && !$found)
  532 + {
  533 + fclose($handle);
  534 + unlink($this->fileName);
  535 + return -1;
  536 + }
  537 + }
  538 + fclose($handle);
  539 +
  540 + if (!$found)
  541 + {
  542 + unlink($this->fileName);
  543 + return 0;
  544 + }
  545 +
  546 + return count($elems);
  547 + }
519 548  
520 549 /*
521 550 * new file tag in Files.xml
522 551 */
523   - protected function createSimuFile($format) {
524   -
525   - $newFile = $this->contentDom->createElement('file');
526   - $newFile->setAttribute('xml:id', $this->fileId);
527   - $newFile->setAttribute('name', $this->fileId);
528   - $newFile->setAttribute('format', $format);
529   -
530   - $start_stop = explode(" ",$this->getVotFileMgr()->getStartStop());
531   - $samplings = $this->getVotFileMgr()->getSamplings();
532   - $minSamp = $samplings["minSampling"];
533   - $maxSamp = $samplings["maxSampling"];
534   - $desc = $this->getVotFileMgr()->getDescription();
535   -
536   - $start = $start_stop[0];
537   - $stop = $start_stop[1];
  552 + protected function createSimuFile($format)
  553 + {
  554 + $newFile = $this->contentDom->createElement('file');
  555 + $newFile->setAttribute('xml:id', $this->fileId);
  556 + $newFile->setAttribute('name', $this->fileId);
  557 + $newFile->setAttribute('format', $format);
  558 +
  559 + $start_stop = explode(" ",$this->getVotFileMgr()->getStartStop());
  560 + $samplings = $this->getVotFileMgr()->getSamplings();
  561 + $minSamp = $samplings["minSampling"];
  562 + $maxSamp = $samplings["maxSampling"];
  563 + $desc = $this->getVotFileMgr()->getDescription();
  564 +
  565 + $start = $start_stop[0];
  566 + $stop = $start_stop[1];
538 567  
539   - $newFile->setAttribute("start",$start);
540   - $newFile->setAttribute("stop",$stop);
541   - $newFile->setAttribute('minsampling',$minSamp);
542   - $newFile->setAttribute('maxsampling',$maxSamp);
543   - $newFile->setAttribute('uploaded', date('Y-m-d H:i:s'));
  568 + $newFile->setAttribute("start",$start);
  569 + $newFile->setAttribute("stop",$stop);
  570 + $newFile->setAttribute('minsampling',$minSamp);
  571 + $newFile->setAttribute('maxsampling',$maxSamp);
  572 + $newFile->setAttribute('uploaded', date('Y-m-d H:i:s'));
544 573  
545   -// generic MASK without datas for simu params
546   - if ((strncmp($this->fileId, "impex___", 8) == 0) || (strncmp($this->fileId, "spase___", 8) == 0))
547   - $newFile->setAttribute('mask', $this->getGenericMask());
548   -
549   - $newFile->nodeValue = date('Y-m-d',$start)."T".date('H:i:s',$start)."-".date('Y-m-d',$stop)."T".date('H:i:s',$stop);
550   - if ($desc != '')
551   - $newFile->nodeValue .= (PHP_EOL.$desc);
552   - return $newFile;
553   - }
554   -
555   -
556   - protected function createFile($format) {
557   -
558   - $newFile = $this->contentDom->createElement('file');
559   - $newFile->setAttribute('xml:id', $this->fileId);
560   - $newFile->setAttribute('name', $this->fileId);
561   - $newFile->setAttribute('format', $format);
562   -
563   - switch ($format){
564   - case "cdf":
565   - $start_stop = explode(" ",$this->getCdfStartStop());
566   - $result = $this->getCdfSampling();
567   -//TODO process errors
568   - $minSamp = $result[count($result)-1];
569   -//TODO if min & max
570   - $maxSamp = $minSamp;
571   - break;
572   - case "txt":
573   - $start_stop = explode(" ",$this->reformatTxt());
574   - if ($start_stop[0] < 0) return $start_stop;
575   - $minSamp = $this->sampling;
576   - $maxSamp = $this->maxSampling;
577   - break;
578   - case "cef":
579   -
580   - // Test if 'standard' meta exist in CEF
581   - $cefMetaTest = $this->getCefStartStop();
582   -
583   - if ($cefMetaTest != -1) {
584   - $cefStartStop = explode("/",$cefMetaTest);
585   - $start_stop[] = strtotime($cefStartStop[0]);
586   - $start_stop[] = strtotime($cefStartStop[1]);
587   - $result = $this->getCefSampling();
588   - $minSamp = $result[count($result)-1];
589   - }
590   - else {
591   - // no META data - so time processing
592   - $timeInfo = $this->getCefTimeInfo();
593   - $timeInfoArr = explode(" ", $timeInfo);
594   - $start_stop[] = $timeInfoArr[0];
595   - $start_stop[] = $timeInfoArr[1];
596   - $minSamp = $timeInfoArr[2];
597   - }
598   -//TODO if min & max
599   - $maxSamp = $minSamp;
600   - break;
601   - case "vot" :
602   - $start_stop = explode(" ",$this->getVotFileMgr()->getStartStop());
603   - $samplings = $this->getVotFileMgr()->getSamplings();
604   - $minSamp = $samplings["minSampling"];
605   - $maxSamp = $samplings["maxSampling"];
606   - $desc = $this->getVotFileMgr()->getDescription();
607   - break;
608   - case "nc":
609   - $ncInfo = $this->getNcTimeInfo();
610   - if ($ncInfo < 0) {
611   - unlink($this->fileName);
612   - return $ncInfo;
613   - }
614   - $ncInfoArr = explode("#",$ncInfo);
615   - $start_stop = explode(":",$ncInfoArr[0]);
616   -//TODO process errors
617   - $minSamp = $ncInfoArr[1];
618   -//TODO if min & max
619   - $maxSamp = $minSamp;
620   - break;
621   - default:
622   -
623   - }
624   - $start = $start_stop[0];
625   - $stop = $start_stop[1];
626   -
627   - $newFile->setAttribute("start",$start);
628   - $newFile->setAttribute("stop",$stop);
629   - $newFile->setAttribute('minsampling',$minSamp);
630   - $newFile->setAttribute('maxsampling',$maxSamp);
631   - $newFile->setAttribute('uploaded', date('Y-m-d H:i:s'));
  574 + // generic MASK without datas for simu params
  575 + if ((strncmp($this->fileId, "impex___", 8) == 0) || (strncmp($this->fileId, "spase___", 8) == 0))
  576 + $newFile->setAttribute('mask', $this->getGenericMask());
  577 +
  578 + $newFile->nodeValue = date('Y-m-d',$start)."T".date('H:i:s',$start)."-".date('Y-m-d',$stop)."T".date('H:i:s',$stop);
  579 + if ($desc != '')
  580 + $newFile->nodeValue .= (PHP_EOL.$desc);
  581 +
  582 + return $newFile;
  583 + }
  584 +
  585 +
  586 + protected function createFile($format)
  587 + {
  588 + $newFile = $this->contentDom->createElement('file');
  589 + $newFile->setAttribute('xml:id', $this->fileId);
  590 + $newFile->setAttribute('name', $this->fileId);
  591 + $newFile->setAttribute('format', $format);
  592 +
  593 + switch ($format)
  594 + {
  595 + case "cdf":
  596 + $start_stop = explode(" ",$this->getCdfStartStop());
  597 + $result = $this->getCdfSampling();
  598 + //TODO process errors
  599 + $minSamp = $result[count($result)-1];
  600 + //TODO if min & max
  601 + $maxSamp = $minSamp;
  602 + break;
  603 + case "txt":
  604 + $start_stop = explode(" ",$this->reformatTxt());
  605 + if ($start_stop[0] < 0) return $start_stop;
  606 + $minSamp = $this->sampling;
  607 + $maxSamp = $this->maxSampling;
  608 + break;
  609 + case "cef":
  610 + // Test if 'standard' meta exist in CEF
  611 + $cefMetaTest = $this->getCefStartStop();
  612 +
  613 + if ($cefMetaTest != -1)
  614 + {
  615 + $cefStartStop = explode("/",$cefMetaTest);
  616 + $start_stop[] = strtotime($cefStartStop[0]);
  617 + $start_stop[] = strtotime($cefStartStop[1]);
  618 + $result = $this->getCefSampling();
  619 + $minSamp = $result[count($result)-1];
  620 + }
  621 + else
  622 + {
  623 + // no META data - so time processing
  624 + $timeInfo = $this->getCefTimeInfo();
  625 + $timeInfoArr = explode(" ", $timeInfo);
  626 + $start_stop[] = $timeInfoArr[0];
  627 + $start_stop[] = $timeInfoArr[1];
  628 + $minSamp = $timeInfoArr[2];
  629 + }
  630 + //TODO if min & max
  631 + $maxSamp = $minSamp;
  632 + break;
  633 + case "vot" :
  634 + $start_stop = explode(" ",$this->getVotFileMgr()->getStartStop());
  635 + $samplings = $this->getVotFileMgr()->getSamplings();
  636 + $minSamp = $samplings["minSampling"];
  637 + $maxSamp = $samplings["maxSampling"];
  638 + $desc = $this->getVotFileMgr()->getDescription();
  639 + break;
  640 + case "nc":
  641 + $ncInfo = $this->getNcTimeInfo();
  642 + if ($ncInfo < 0) {
  643 + unlink($this->fileName);
  644 + return $ncInfo;
  645 + }
  646 + $ncInfoArr = explode("#",$ncInfo);
  647 + $start_stop = explode(":",$ncInfoArr[0]);
  648 + //TODO process errors
  649 + $minSamp = $ncInfoArr[1];
  650 + //TODO if min & max
  651 + $maxSamp = $minSamp;
  652 + break;
  653 + default:
  654 + }
  655 + $start = $start_stop[0];
  656 + $stop = $start_stop[1];
  657 +
  658 + $newFile->setAttribute("start",$start);
  659 + $newFile->setAttribute("stop",$stop);
  660 + $newFile->setAttribute('minsampling',$minSamp);
  661 + $newFile->setAttribute('maxsampling',$maxSamp);
  662 + $newFile->setAttribute('uploaded', date('Y-m-d H:i:s'));
632 663  
633   -// generic MASK without datas for simu params
634   - if ((strncmp($this->fileId, "impex___", 8) === 0) || (strncmp($this->fileId, "spase___", 8) === 0))
635   - $newFile->setAttribute('mask', $this->getGenericMask());
636   - else
637   - $newFile->setAttribute('mask', $this->fileId);
638   -
639   - $newFile->nodeValue = date('Y-m-d',$start)."T".date('H:i:s',$start)."-".date('Y-m-d',$stop)."T".date('H:i:s',$stop);
640   - if ($desc != '')
641   - $newFile->nodeValue .= (PHP_EOL.$desc);
642   -
643   - return $newFile;
644   - }
  664 + // generic MASK without datas for simu params
  665 + if ((strncmp($this->fileId, "impex___", 8) === 0) || (strncmp($this->fileId, "spase___", 8) === 0))
  666 + $newFile->setAttribute('mask', $this->getGenericMask());
  667 + else
  668 + $newFile->setAttribute('mask', $this->fileId);
  669 +
  670 + $newFile->nodeValue = date('Y-m-d',$start)."T".date('H:i:s',$start)."-".date('Y-m-d',$stop)."T".date('H:i:s',$stop);
  671 + if ($desc != '')
  672 + $newFile->nodeValue .= (PHP_EOL.$desc);
  673 +
  674 + return $newFile;
  675 + }
645 676  
646   - protected function getGenericMask() {
647   - if (strncmp($this->fileId, "impex___", 8) == 0) {
648   - $prefix = "impex___";
649   - $tmpFileName = str_replace ("impex___", "", $this->fileId);
650   - }
651   - elseif (strncmp($this->fileId, "spase___", 8) == 0) {
652   - $prefix = "spase___";
653   - $tmpFileName = str_replace ("spase___", "", $this->fileId);
654   - }
655   - $tmpFileArray = explode( '.', $tmpFileName);
656   - $tmpParamArray = explode( '_', $tmpFileArray[0]);
657   - array_pop($tmpParamArray);
658   - array_pop($tmpParamArray);
659   - $tmpName = implode("_", $tmpParamArray);
660   -
661   - $mask = $prefix.$tmpName."_*.xml";
662   - return $mask;
663   - }
  677 + protected function getGenericMask()
  678 + {
  679 + if (strncmp($this->fileId, "impex___", 8) == 0) {
  680 + $prefix = "impex___";
  681 + $tmpFileName = str_replace ("impex___", "", $this->fileId);
  682 + }
  683 + elseif (strncmp($this->fileId, "spase___", 8) == 0) {
  684 + $prefix = "spase___";
  685 + $tmpFileName = str_replace ("spase___", "", $this->fileId);
  686 + }
  687 + $tmpFileArray = explode( '.', $tmpFileName);
  688 + $tmpParamArray = explode( '_', $tmpFileArray[0]);
  689 + array_pop($tmpParamArray);
  690 + array_pop($tmpParamArray);
  691 + $tmpName = implode("_", $tmpParamArray);
  692 +
  693 + $mask = $prefix.$tmpName."_*.xml";
  694 + return $mask;
  695 + }
664 696  
665 697 /*
666 698 //TODO check how to upgrade this
667 699 */
668   - protected function getFormat() {
669   -
670   - $ext = pathinfo($this->fileName, PATHINFO_EXTENSION);
  700 + protected function getFormat()
  701 + {
  702 + $ext = pathinfo($this->fileName, PATHINFO_EXTENSION);
  703 +
  704 + if (PHP_VERSION_ID < 50300)
  705 + {
  706 + $finfo = new finfo(FILEINFO_MIME, MAGIC_FILE);
  707 + $file_info = explode(";", $finfo->file($this->fileName));
  708 + }
  709 + else
  710 + {
  711 + // PHP v >= 5.3 comes with its own magic file !!!!
  712 + $finfo = finfo_open(FILEINFO_MIME);
  713 + $file_info = explode(";",finfo_file($finfo, $this->fileName));
  714 + }
671 715  
672   - if (PHP_VERSION_ID < 50300) {
673   - $finfo = new finfo(FILEINFO_MIME, MAGIC_FILE);
674   - $file_info = explode(";", $finfo->file($this->fileName));
675   - }
676   - else {
677   - // PHP v >= 5.3 comes with its own magic file !!!!
678   - $finfo = finfo_open(FILEINFO_MIME);
679   - $file_info = explode(";",finfo_file($finfo, $this->fileName));
680   - }
  716 + if (strpos($file_info[0],"plain") !== false)
  717 + {
  718 + if (strpos($ext,"cef") !== false) return "cef";
  719 + return "txt";
  720 + }
681 721  
682   - if (strpos($file_info[0],"plain") !== false) {
683   - if (strpos($ext,"cef") !== false) return "cef";
684   - return "txt";
685   - }
686   -
687   - if (strpos($file_info[0],"application/x-gzip") !== false) {
688   - if (strpos($this->fileName,"cef.gz") !== false) return "cef";
689   - }
690   -
691   - if (strpos($file_info[0],"application/xml") !== false)
692   - {
693   - //if ($this->getVotFileMgr()->isValidSchema()) //BRE : No schema validation for the moment due to some trouble with Topcat (it can create not valid VOTable)
694   - return "vot";
695   - }
696   -
697   - // check binary at different machines - if it works.....
698   - if (strpos($file_info[0],"octet-stream") !== false) {
699   - if (strpos($ext,"cdf") !== false) return "cdf";
700   - if (strpos($ext,"nc") !== false) return "nc";
701   -
702   - }
703   - return "unknown";
704   - }
  722 + if (strpos($file_info[0],"application/x-gzip") !== false)
  723 + {
  724 + if (strpos($this->fileName,"cef.gz") !== false) return "cef";
  725 + }
  726 +
  727 + if (strpos($file_info[0],"application/xml") !== false)
  728 + {
  729 + //if ($this->getVotFileMgr()->isValidSchema()) //BRE : No schema validation for the moment due to some trouble with Topcat (it can create not valid VOTable)
  730 + return "vot";
  731 + }
  732 +
  733 + // check binary at different machines - if it works.....
  734 + if (strpos($file_info[0],"octet-stream") !== false)
  735 + {
  736 + if (strpos($ext,"cdf") !== false) return "cdf";
  737 + if (strpos($ext,"nc") !== false) return "nc";
  738 + }
  739 +
  740 + return "unknown";
  741 + }
705 742  
706 743 /*
707 744 * PUBLIC FUNCTIONS
708   -*/
709   -
710   - public function getAsciiFile($name) {
711   -
712   - $this->fileName = USERDATADIR.$name;
  745 +*/
  746 + public function getAsciiFile($name)
  747 + {
  748 + $this->fileName = USERDATADIR.$name;
713 749  
714   - if (!file_exists(USERDATADIR.$name))
715   - return array('success' => false, 'error' => 'No such file');
  750 + if (!file_exists(USERDATADIR.$name))
  751 + return array('success' => false, 'error' => 'No such file');
716 752  
717   - $handle = fopen($this->fileName, "r");
718   - $fileToReturn = array();
719   - $index = 0;
720   - $tempFileToReturn = array();
721   -
722   - while (!feof($handle)) {
723   - $line = trim(fgets($handle));
724   - $tempArr = explode(' ', preg_replace('/\s+/', ' ', $line));
725   - if (count($tempArr) > 1) {
726   - for ($i = 0; $i < count($tempArr); $i++) {
727   - $name = $i === 0 ? 'Time' : 'n'.$i;
728   -//transform double time to ISO
729   - if ($name == 'Time') {
730   - $temp = $tempArr[0];
731   - settype($temp, 'double');
732   - $tempArr[0] = date('Y-m-d H:i:s', $temp);
733   - }
734   - $tempFileToReturn[$name] = $tempArr[$i];
735   - }
736   - $fileToReturn[$index] = $tempFileToReturn;
737   - $index++;
738   - if ($index > MAX_FILE_INDEX_TO_SHOW) break;
739   - }
740   - }
741   - return $fileToReturn;
742   - }
743   -
744   -
  753 + $handle = fopen($this->fileName, "r");
  754 + $fileToReturn = array();
  755 + $index = 0;
  756 + $tempFileToReturn = array();
  757 +
  758 + while (!feof($handle))
  759 + {
  760 + $line = trim(fgets($handle));
  761 + $tempArr = explode(' ', preg_replace('/\s+/', ' ', $line));
  762 + if (count($tempArr) > 1)
  763 + {
  764 + for ($i = 0; $i < count($tempArr); $i++)
  765 + {
  766 + $name = $i === 0 ? 'Time' : 'n'.$i;
  767 + //transform double time to ISO
  768 + if ($name == 'Time')
  769 + {
  770 + $temp = $tempArr[0];
  771 + settype($temp, 'double');
  772 + $tempArr[0] = date('Y-m-d H:i:s', $temp);
  773 + }
  774 + $tempFileToReturn[$name] = $tempArr[$i];
  775 + }
  776 +
  777 + $fileToReturn[$index] = $tempFileToReturn;
  778 + $index++;
  779 + if ($index > MAX_FILE_INDEX_TO_SHOW) break;
  780 + }
  781 + }
  782 + return $fileToReturn;
  783 + }
745 784 /*
746 785 * Get info on parameter
747 786 */
748   - public function getParamInfo($obj){
749   -
750   - $this->fileName = USERDATADIR.$obj->file;
751   - $varId = $obj->varName;
752   - $format = $obj->format;
753   -
754   -// at first info from Files.xml
755   - $file = $this->contentDom->getElementById($obj->file);
756   - if ($file) {
757   - if ($file->parentNode->tagName == 'folder')
758   - $mask = $file->parentNode->getAttribute('name');
759   - else
760   - $mask = $file->getAttribute('mask');
761   - $dom_info = array( 'name' => $varId,
762   - 'minsampling' => $file->getAttribute('minsampling'),
763   - 'maxsampling' => $file->getAttribute('maxsampling'),
764   - 'mask' => $mask);
765   - }
766   - else {
767   - if ($format == "nc"){
768   - $status = $this->reformatNcTime();
769   - if ($status <= 0) {
770   - unlink($this->fileName);
771   - return array('success' => false, 'error' => 'error '.$timeFormat.PHP_EOL.'Time Format problem');
772   - }
773   - $ncInfo = $this->getNcTimeInfo();
774   - $ncVars = $this->getNcVars();
775   - if ($ncInfo < 0) {
776   - unlink($this->fileName);
777   - return $ncInfo;
778   - }
779   - $ncInfoArr = explode("#",$ncInfo);
780   - $start_stop = explode(":",$ncInfoArr[0]);
781   - //TODO process errors
782   - $minSamp = $ncInfoArr[1];
783   - //TODO if min & max
784   - $maxSamp = $minSamp;
  787 + public function getParamInfo($obj)
  788 + {
  789 + $this->fileName = USERDATADIR.$obj->file;
  790 + $varId = $obj->varName;
  791 + $format = $obj->format;
  792 +
  793 + // at first info from Files.xml
  794 + $file = $this->contentDom->getElementById($obj->file);
  795 + if ($file)
  796 + {
  797 + if ($file->parentNode->tagName == 'folder')
  798 + $mask = $file->parentNode->getAttribute('name');
  799 + else
  800 + $mask = $file->getAttribute('mask');
  801 +
  802 + $dom_info = array( 'name' => $varId,
  803 + 'minsampling' => $file->getAttribute('minsampling'),
  804 + 'maxsampling' => $file->getAttribute('maxsampling'),
  805 + 'mask' => $mask);
  806 + }
  807 + else
  808 + {
  809 + if ($format == "nc")
  810 + {
  811 + $status = $this->reformatNcTime();
  812 + if ($status <= 0)
  813 + {
  814 + unlink($this->fileName);
  815 + return array('success' => false, 'error' => 'error '.$timeFormat.PHP_EOL.'Time Format problem');
  816 + }
  817 + $ncInfo = $this->getNcTimeInfo();
  818 + $ncVars = $this->getNcVars();
  819 +
  820 + if ($ncInfo < 0)
  821 + {
  822 + unlink($this->fileName);
  823 + return $ncInfo;
  824 + }
  825 +
  826 + $ncInfoArr = explode("#",$ncInfo);
  827 + $start_stop = explode(":",$ncInfoArr[0]);
  828 + //TODO process errors
  829 + $minSamp = $ncInfoArr[1];
  830 + //TODO if min & max
  831 + $maxSamp = $minSamp;
785 832  
786   - $dom_info = array( 'name' => $varId,
787   - 'minsampling' => $minSamp,
788   - 'maxsampling' => $maxSamp,
789   - 'mask' => $obj->mask);
790   - }
791   - }
792   -
793   - switch ($format){
794   - case "cdf":
795   - $info = $this->getCdfVarInfo($varId);
796   - break;
797   - case "txt":
798   - break;
799   - case "cef":
800   - $info = $this->getCefVarInfo($varId);
801   - break;
802   - case "nc":
803   - $info = $this->getNcVarInfo($varId);
804   - break;
805   - case "vot":
806   - $info = $this->getVotFileMgr()->getFieldInfoByID($varId);
807   - break;
808   - default:
809   -
810   - }
811   - return array('success' => true, 'info' => array_merge($dom_info,$info));
812   - }
813   -
814   -
815   - public function deleteObject($obj)
816   - {
817   - $myBaseManager = new BaseManager();
818   -
819   - $paramMgr = new DerivedParamMgr('myDataParam');
820   - $xpd = new domxpath($paramMgr->contentDom);
  833 + $dom_info = array( 'name' => $varId,
  834 + 'minsampling' => $minSamp,
  835 + 'maxsampling' => $maxSamp,
  836 + 'mask' => $obj->mask);
  837 + }
  838 + }
821 839  
822   - //File, not a folder
823   - if ($obj->leaf) {
824   - $this->fileName = USERDATADIR.$obj->id;
  840 + switch ($format)
  841 + {
  842 + case "cdf":
  843 + $info = $this->getCdfVarInfo($varId);
  844 + break;
  845 + case "txt":
  846 + break;
  847 + case "cef":
  848 + $info = $this->getCefVarInfo($varId);
  849 + break;
  850 + case "nc":
  851 + $info = $this->getNcVarInfo($varId);
  852 + break;
  853 + case "vot":
  854 + $info = $this->getVotFileMgr()->getFieldInfoByID($varId);
  855 + break;
  856 + default:
825 857  
826   - if (file_exists($this->fileName))
827   - unlink($this->fileName);
  858 + }
  859 + return array('success' => true, 'info' => array_merge($dom_info,$info));
  860 + }
828 861  
829   - $theFile = $this->contentDom->getElementById($obj->id);
830   -
831   -
832   - // Update data base
833   - $fileInBase = $myBaseManager->xp->query("//file[@name='".$obj->id."']");
834 862  
835   - if ($fileInBase->length > 0) {
836   - $viInfo = $myBaseManager->delFile($fileInBase->item(0));
837   -
838   - $mask = $viInfo['mask'];
839   - $length = $viInfo['length'];
840   -
841   - $params = $xpd->query("//mydata[@mask='".$mask."']");
  863 + public function deleteObject($obj)
  864 + {
  865 + $myBaseManager = new BaseManager();
842 866  
843   - if ($params->length > 0) {
844   - // NO FILES in the mask; corresponding parameters are to be deleted
845   - if ($length == 0) {
846   - $paramsToDelete = array();
847   - for ($i = $params->length; --$i >= 0; ) {
848   - $id = $params->item($i)->getAttribute('xml:id');
849   - $paramMgr->deleteParameter($id);
850   - $paramMgr->deleteFromContent($params->item($i));
851   - $paramsToDelete[] = $id;
852   - }
853   - }
854   - // update params description in Content Dom
855   - else {
856   - $vi = $myBaseManager->getVi($mask);
857   - $desc = $myBaseManager->getStartStop($vi);
858   - foreach ($params as $param) $param->setAttribute("desc",$desc);
859   - $paramMgr->saveContent();
860   - }
861   - }
862   - }
863   - // WS/Files.xml
864   - if ($theFile) {
865   - if ($desc)
866   - $theFile->parentNode->setAttribute('info', $desc);
867   - $theFile->parentNode->removeChild($theFile);
868   - $this->contentDom->save($this->xmlName);
869   - }
870   - }
871   - // Folder
872   - else {
873   - $mask = $obj->id;
874   - $theMask = $this->contentDom->getElementById($obj->id);
875   - $files = $theMask->getElementsByTagName('file');
876   -
877   - foreach ($files as $file) {
878   - $fileName = USERDATADIR.$file->getAttribute('name');
879   - if (file_exists($fileName)) unlink($fileName);
880   - }
881   -
882   - $this->deleteFromContent($theMask);
883   - $myBaseManager->delVI($mask);
884   -
885   - $params = $xpd->query("//mydata[@mask='".$mask."']");
886   - $paramsToDelete = array();
887   - for ($i = $params->length; --$i >= 0; ) {
888   - $id = $params->item($i)->getAttribute('xml:id');
889   - $paramMgr->deleteParameter($id);
890   - $paramMgr->deleteFromContent($params->item($i));
891   - $paramsToDelete[] = $id;
892   - }
893   - }
894   - // No more files for myDataParams
895   - if ($paramsToDelete)
896   - return array('id' => $obj->id, 'params' => $paramsToDelete);
897   -
898   - // update info for myDataParams Start Stop were changed
899   - return array('id' => $obj->id, 'mask' => $mask, 'maskDesc' => $desc);
900   - }
901   -
902   -
903   - public function deleteSimuObject($obj) {
  867 + $paramMgr = new DerivedParamMgr('myDataParam');
  868 + $xpd = new domxpath($paramMgr->contentDom);
904 869  
905   - $myBaseManager = new BaseManager();
906   - $paramMgr = new DerivedParamMgr('mySimuParam');
907   - $xpd = new domxpath($paramMgr->contentDom);
  870 + //File, not a folder
  871 + if ($obj->leaf)
  872 + {
  873 + $this->fileName = USERDATADIR.$obj->id;
908 874  
909   - if ($obj->leaf) {
910   - $this->fileName = USERDATADIR.$obj->id;
  875 + if (file_exists($this->fileName))
  876 + unlink($this->fileName);
  877 +
  878 + $theFile = $this->contentDom->getElementById($obj->id);
  879 + // Update data base
  880 + $fileInBase = $myBaseManager->xp->query("//file[@name='".$obj->id."']");
911 881  
912   - if (file_exists($this->fileName)) unlink($this->fileName);
913   - $theFile = $this->contentDom->getElementById($obj->id);
914   - if ($theFile) {
915   - $theFile->parentNode->removeChild($theFile);
916   - $this->contentDom->save($this->xmlName);
917   - }
918   -
919   -// update base data
920   -
921   - $fileInBase = $myBaseManager->xp->query("//file[@name='".$obj->id."']");
922   - if ($fileInBase->length > 0) {
923   - $mask = $myBaseManager->delFile($fileInBase->item(0));
924   -
925   - $params = $xpd->query("//mydata[@mask='".$mask."']");
926   - if ($params->length > 0) {
927   -// NO FILES in the mask; corresponding parameters are to be deleted
928   - if (strcmp($mask, "NONEMPTY") != 0) {
929   - $paramsToDelete = array();
930   - for ($i = $params->length; --$i >= 0; ) {
931   - $id = $params->item($i)->getAttribute('xml:id');
932   - $paramMgr->deleteParameter($id);
933   - $paramMgr->deleteFromContent($params->item($i));
934   - $paramsToDelete[] = $id;
935   - }
936   - }
937   -// update params description in Content Dom
938   - else {
939   - $vi = $myBaseManager->getVi($mask);
940   - $desc = $myBaseManager->getStartStop($vi);
941   - foreach ($params as $param) $param->setAttribute("desc",$desc);
942   - $paramMgr->saveContent();
943   - }
944   - }
945   - }
946   - }
947   - else {
948   - $mask = $obj->id;
949   - $theMask = $this->contentDom->getElementById($obj->id);
950   - $files = $theMask->getElementsByTagName('file');
951   - foreach ($files as $file) {
952   - $fileName = USERDATADIR.$file->getAttribute('name');
953   - if (file_exists($fileName)) unlink($fileName);
  882 + if ($fileInBase->length > 0)
  883 + {
  884 + $viInfo = $myBaseManager->delFile($fileInBase->item(0));
  885 +
  886 + $mask = $viInfo['mask'];
  887 + $length = $viInfo['length'];
  888 +
  889 + $params = $xpd->query("//mydata[@mask='".$mask."']");
  890 +
  891 + if ($params->length > 0)
  892 + {
  893 + // NO FILES in the mask; corresponding parameters are to be deleted
  894 + if ($length == 0)
  895 + {
  896 + $paramsToDelete = array();
  897 + for ($i = $params->length; --$i >= 0; )
  898 + {
  899 + $id = $params->item($i)->getAttribute('xml:id');
  900 + $paramMgr->deleteParameter($id);
  901 + $paramMgr->deleteFromContent($params->item($i));
  902 + $paramsToDelete[] = $id;
  903 + }
  904 + }
  905 + // update params description in Content Dom
  906 + else
  907 + {
  908 + $vi = $myBaseManager->getVi($mask);
  909 + $desc = $myBaseManager->getStartStop($vi);
  910 + foreach ($params as $param) $param->setAttribute("desc",$desc);
  911 + $paramMgr->saveContent();
  912 + }
  913 + }
  914 + }
  915 + // WS/Files.xml
  916 + if ($theFile)
  917 + {
  918 + if ($desc)
  919 + $theFile->parentNode->setAttribute('info', $desc);
  920 + $theFile->parentNode->removeChild($theFile);
  921 + $this->contentDom->save($this->xmlName);
  922 + }
954 923 }
955   - $this->deleteFromContent($theMask);
956   - $myBaseManager->delVI($mask);
957   -
958   - $params = $xpd->query("//mydata[@mask='".$mask."']");
959   - $paramsToDelete = array();
960   - for ($i = $params->length; --$i >= 0; ) {
961   - $id = $params->item($i)->getAttribute('xml:id');
962   - $paramMgr->deleteParameter($id);
963   - $paramMgr->deleteFromContent($params->item($i));
964   - $paramsToDelete[] = $id;
965   - }
966   - }
967   -
968   - if ($paramsToDelete) return array('id' => $obj->id, 'params' => $paramsToDelete);
969   - else return array('id' => $obj->id);
  924 + // Folder
  925 + else
  926 + {
  927 + $mask = $obj->id;
  928 + $theMask = $this->contentDom->getElementById($obj->id);
  929 + $files = $theMask->getElementsByTagName('file');
  930 +
  931 + foreach ($files as $file)
  932 + {
  933 + $fileName = USERDATADIR.$file->getAttribute('name');
  934 + if (file_exists($fileName)) unlink($fileName);
  935 + }
  936 +
  937 + $this->deleteFromContent($theMask);
  938 + $myBaseManager->delVI($mask);
  939 +
  940 + $params = $xpd->query("//mydata[@mask='".$mask."']");
  941 + $paramsToDelete = array();
  942 + for ($i = $params->length; --$i >= 0; )
  943 + {
  944 + $id = $params->item($i)->getAttribute('xml:id');
  945 + $paramMgr->deleteParameter($id);
  946 + $paramMgr->deleteFromContent($params->item($i));
  947 + $paramsToDelete[] = $id;
  948 + }
  949 + }
  950 + // No more files for myDataParams
  951 + if ($paramsToDelete)
  952 + return array('id' => $obj->id, 'params' => $paramsToDelete);
  953 +
  954 + // update info for myDataParams Start Stop were changed
  955 + return array('id' => $obj->id, 'mask' => $mask, 'maskDesc' => $desc);
970 956 }
971   -
  957 +
972 958 /*
973 959 * recombine files in Files.xml according to new Mask
974 960 */
975   - public function addMask($fileMask, $type) {
976   - if ($this->contentDom ->getElementById($fileMask) != null) return false;
977   - $filesInRoot = $this->xp->query("/ws/fileList/file");
978   - $newMask = $this->contentDom->createElement("folder");
979   - $newMask->setAttribute('xml:id', $fileMask);
980   - $newMask->setAttribute('name', $fileMask);
  961 + public function addMask($fileMask, $type)
  962 + {
  963 + if ($this->contentDom ->getElementById($fileMask) != null) return false;
  964 + $filesInRoot = $this->xp->query("/ws/fileList/file");
  965 + $newMask = $this->contentDom->createElement("folder");
  966 + $newMask->setAttribute('xml:id', $fileMask);
  967 + $newMask->setAttribute('name', $fileMask);
981 968  
982   - for ($i = $filesInRoot->length; --$i >= 0;) {
983   - $aFile = $filesInRoot->item($i);
984   -
985   -// mask corresponds to file name
986   - if ($this->fileMask($aFile->getAttribute("name"),$fileMask)) {
987   - $newMask->appendChild($aFile);
988   - }
989   - }
990   -
991   - $files = $newMask->getElementsByTagName("file");
992   - if ($files->length == 0) return false;
  969 + for ($i = $filesInRoot->length; --$i >= 0;)
  970 + {
  971 + $aFile = $filesInRoot->item($i);
  972 + // mask corresponds to file name
  973 + if ($this->fileMask($aFile->getAttribute("name"),$fileMask))
  974 + {
  975 + $newMask->appendChild($aFile);
  976 + }
  977 + }
  978 +
  979 + $files = $newMask->getElementsByTagName("file");
  980 + if ($files->length == 0) return false;
993 981  
994   - foreach ($files as $file) {
995   - $starts[] = $file->getAttribute("start");
996   - $stops[] = $file->getAttribute("stop");
997   - }
  982 + foreach ($files as $file)
  983 + {
  984 + $starts[] = $file->getAttribute("start");
  985 + $stops[] = $file->getAttribute("stop");
  986 + }
998 987  
999   - $newMask->setAttribute('info',date('Y-m-d',min($starts))."T".date('H:i:s',min($starts))."-".date('Y-m-d',max($stops))."T".date('H:i:s',max($stops)));
  988 + $newMask->setAttribute('info',date('Y-m-d',min($starts))."T".date('H:i:s',min($starts))."-".date('Y-m-d',max($stops))."T".date('H:i:s',max($stops)));
1000 989  
1001   - $fileList = $this->contentDom->getElementById($this->contentRootId);
  990 + $fileList = $this->contentDom->getElementById($this->contentRootId);
1002 991  
1003   - $fileList->appendChild($newMask);
1004   - $this->contentDom->save($this->xmlName);
1005   - return true;
1006   - }
  992 + $fileList->appendChild($newMask);
  993 + $this->contentDom->save($this->xmlName);
  994 + return true;
  995 + }
1007 996  
1008 997 /*
1009 998 * check correspondence FleName <=> Mask
1010 999 * returns true if Mask fits FileName
1011 1000 */
1012   - public function fileMask($fileName, $maskName) {
1013   -
1014   - $mask = explode("*", $maskName);
1015   - if (strpos($fileName, $mask[0]) !== 0) return false;
1016   - if (count($mask) == 1) return true;
  1001 + public function fileMask($fileName, $maskName)
  1002 + {
  1003 + $mask = explode("*", $maskName);
  1004 + if (strpos($fileName, $mask[0]) !== 0) return false;
  1005 + if (count($mask) == 1) return true;
1017 1006  
1018   - for ($i = 1; $i < count($mask); $i++)
1019   - if ($mask[$i] != null)
1020   - if (strpos($fileName, $mask[$i]) === false) return false;
  1007 + for ($i = 1; $i < count($mask); $i++)
  1008 + if ($mask[$i] != null)
  1009 + if (strpos($fileName, $mask[$i]) === false) return false;
1021 1010  
1022   - return true;
1023   - }
  1011 + return true;
  1012 + }
1024 1013  
1025 1014 /*
1026 1015 * Delete Mask
1027 1016 */
1028   - public function delMask($oldMask) {
1029   -
1030   - $mask = $this->contentDom->getElementById($oldMask);
1031   -
1032   - if ($mask != null && $mask->tagName == "folder") {
1033   - $filesInMask = $mask->getElementsByTagName("file");
1034   - $fileList = $this->contentDom->getElementById($this->contentRootId);
1035   -
1036   - while ($filesInMask->length > 0)
1037   - $fileList->appendChild($filesInMask->item(0));
1038   -
1039   - $fileList->removeChild($mask);
1040   - $this->contentDom->save($this->xmlName);
1041   -
1042   - return true;
1043   - }
  1017 + public function delMask($oldMask)
  1018 + {
  1019 + $mask = $this->contentDom->getElementById($oldMask);
  1020 +
  1021 + if ($mask != null && $mask->tagName == "folder")
  1022 + {
  1023 + $filesInMask = $mask->getElementsByTagName("file");
  1024 + $fileList = $this->contentDom->getElementById($this->contentRootId);
  1025 +
  1026 + while ($filesInMask->length > 0)
  1027 + $fileList->appendChild($filesInMask->item(0));
  1028 +
  1029 + $fileList->removeChild($mask);
  1030 + $this->contentDom->save($this->xmlName);
  1031 +
  1032 + return true;
  1033 + }
1044 1034  
1045   - return false;
1046   - }
  1035 + return false;
  1036 + }
1047 1037  
1048 1038 /*
1049 1039 * mask or file
1050 1040 */
1051   - public function getObject($name) {
1052   -
1053   - $object = $this->contentDom->getElementById($name);
1054   -
1055   - if (is_object($object)) {
1056   - // mask
1057   - if ($object->tagName == 'folder') {
1058   - $file = $object->getElementsByTagName('file');
1059   - if ($file->length > 0)
1060   - return $this->getUploadedObject($file->item(0)->getAttribute('name'));
1061   - else
1062   - return array('success' => false, 'error' => 'Mask is empty');
1063   - }
1064   - }
1065   - else
1066   - return array('success' => false, 'error' => 'No such mask in DOM');
1067   - // file
1068   - return $this->getUploadedObject($name);
1069   - }
  1041 + public function getObject($name)
  1042 + {
  1043 + $object = $this->contentDom->getElementById($name);
  1044 +
  1045 + if (is_object($object))
  1046 + {
  1047 + // mask
  1048 + if ($object->tagName == 'folder')
  1049 + {
  1050 + $file = $object->getElementsByTagName('file');
  1051 + if ($file->length > 0)
  1052 + return $this->getUploadedObject($file->item(0)->getAttribute('name'));
  1053 + else
  1054 + return array('success' => false, 'error' => 'Mask is empty');
  1055 + }
  1056 + }
  1057 + else
  1058 + return array('success' => false, 'error' => 'No such mask in DOM');
  1059 + // file
  1060 + return $this->getUploadedObject($name);
  1061 + }
1070 1062  
1071 1063 /*
1072 1064 * Get generic info on uploaded file
1073 1065 */
1074   - public function getUploadedObject($name) {
1075   -
1076   - $this->fileName = USERDATADIR.$name;
1077   - $file = $this->contentDom->getElementById($name);
1078   - if (!$file)
1079   - return array('success' => false, 'error' => 'No such file in DOM');
1080   -
1081   - $format = $file->getAttribute('format');
1082   - $minSamp = $file->getAttribute('minsampling');
1083   - $maxSamp = $file->getAttribute('maxsampling');
1084   -
1085   - $mask = $file->parentNode->tagName == "folder" ? $file->parentNode->getAttribute("name") : null;
1086   - $maskDesc = $mask ? $file->parentNode->getAttribute('info') : null;
1087   - $desc = $file->nodeValue;
1088   -
1089   - $foundTime = true;
  1066 + public function getUploadedObject($name)
  1067 + {
  1068 + $this->fileName = USERDATADIR.$name;
  1069 + $file = $this->contentDom->getElementById($name);
  1070 + if (!$file)
  1071 + return array('success' => false, 'error' => 'No such file in DOM');
  1072 +
  1073 + $format = $file->getAttribute('format');
  1074 + $minSamp = $file->getAttribute('minsampling');
  1075 + $maxSamp = $file->getAttribute('maxsampling');
  1076 +
  1077 + $mask = $file->parentNode->tagName == "folder" ? $file->parentNode->getAttribute("name") : null;
  1078 + $maskDesc = $mask ? $file->parentNode->getAttribute('info') : null;
  1079 + $desc = $file->nodeValue;
  1080 +
  1081 + $foundTime = true;
1090 1082  
1091   - switch ($format){
1092   - case "cdf":
1093   - $vars = $this->getCdfVars();
1094   - break;
1095   - case "txt":
1096   - $vars = $this->getTxtColNumber(true);
1097   - break;
1098   - case "nc" :
1099   - $vars = $this->getNcVars();
1100   - break;
1101   - case "cef":
1102   - $vars = $this->getCefVars();
1103   - break;
1104   - case "vot" :
1105   - $vars = $this->getVotFileMgr()->getFieldsInfo();
1106   - $foundTime = ($this->getVotFileMgr()->getTimeFieldIndex() > -1);
1107   - break;
1108   - default:
1109   - }
1110   -
1111   - return array('success' => true, 'format' => $format, 'vars' => $vars, 'fileName' => $name,
1112   - 'minsampling' => $minSamp, 'maxsampling' => $maxSamp, 'mask' => $mask, 'maskDesc' => $maskDesc,
1113   - 'description' => $desc, 'foundTime' => $foundTime);
1114   - }
  1083 + switch ($format)
  1084 + {
  1085 + case "cdf":
  1086 + $vars = $this->getCdfVars();
  1087 + break;
  1088 + case "txt":
  1089 + $vars = $this->getTxtColNumber(true);
  1090 + break;
  1091 + case "nc" :
  1092 + $vars = $this->getNcVars();
  1093 + break;
  1094 + case "cef":
  1095 + $vars = $this->getCefVars();
  1096 + break;
  1097 + case "vot" :
  1098 + $vars = $this->getVotFileMgr()->getFieldsInfo();
  1099 + $foundTime = ($this->getVotFileMgr()->getTimeFieldIndex() > -1);
  1100 + break;
  1101 + default:
  1102 + }
  1103 +
  1104 + return array('success' => true, 'format' => $format, 'vars' => $vars, 'fileName' => $name,
  1105 + 'minsampling' => $minSamp, 'maxsampling' => $maxSamp, 'mask' => $mask, 'maskDesc' => $maskDesc,
  1106 + 'description' => $desc, 'foundTime' => $foundTime);
  1107 + }
1115 1108  
1116 1109 /*
1117 1110 * The very first processing of newly uploaded file file
1118 1111 * $formats = array('fileFormat', 'timeFormat', 'timeSampling', 'nonStandard', 'doy');
1119 1112 */
1120   - public function addFile($fileName, $formats) {
1121   -
1122   - $this->fileName = USERDATADIR.$fileName;
1123   - $this->fileId = $fileName;
1124   -
1125   - $format = $this->getFormat();
1126   -
1127   - if ($format === 'unknown'){
1128   - unlink($this->fileName);
1129   - return array('success' => false, 'error' => 'Sorry, unknown format of '.$fileName);
1130   - }
1131   -
1132   - if ($format == 'txt') {
1133   - if ($formats["timeFormat"] == "user") {
1134   - $res = $this->reformatTime($formats["nonStandard"], $formats["timeLength"], $formats["doy"]);
1135   -
1136   - if (!$res) {
1137   - unlink($this->fileName);
1138   - return array('success' => false, 'error' => 'can\'t reformat time');
1139   - }
1140   - }
1141   - // check if file is not empty
1142   - $vars = $this->getTxtColNumber(false);
1143   -
1144   - if ($vars == -100) {
1145   - return array('success' => false, 'error' => 'no such file');
1146   - }
1147   - if ($vars == -1) {
1148   - unlink($this->fileName);
1149   - return array('success' => false, 'error' => 'while reading file');
1150   - }
1151   -
1152   - if ($vars === 0) {
1153   - unlink($this->fileName);
1154   - return array('success' => false, 'error' => 'file contains no data');
1155   - }
1156   -
1157   - if ($formats["timeSampling"] == "constant") {
1158   - $this->sampling = $this->getTxtSampling();
1159   - $this->maxSampling = $this->sampling;
1160   - }
1161   - else {
1162   - $samplings = $this->getTxtSamplings();
1163   - $this->sampling = $samplings[0];
1164   - $this->maxSampling = $samplings[1];
1165   - }
1166   -
1167   - if ($this->sampling <= 0) {
1168   - unlink($this->fileName);
1169   - if ($this->sampling == -10) {
1170   - return array('success' => false, 'error' => 'Sorry, can\'t process'.$fileName.PHP_EOL.'. Check if there are non numeric chars in the data');
1171   - }
1172   - return array('success' => false, 'error' => 'Sorry, can\'t process Time for '.$fileName.PHP_EOL.'. Check time format, start time (> 1970-01-01) or sampling time (>= 1s)');
1173   - }
1174   - }
1175   -
1176   - if ($format == 'nc') {
1177   - $status = $this->reformatNcTime();
1178   - if ($status <= 0) {
1179   - unlink($this->fileName);
1180   - return array('success' => false, 'error' => 'error '.$timeFormat.PHP_EOL.'Time Format problem');
1181   - }
1182   - }
1183   -
1184   - //create new file tag with all attributes and add it to the content DOM
1185   - $newFile = $this->createFile($format);
1186   - if ($newFile < 0) {
1187   - unlink($this->fileName);
1188   - return array( 'success' => false, 'file' => $fileName);
1189   - }
1190   -
1191   - $isMask = false;
1192   - $masks = $this->contentDom->getElementsByTagName("folder");
1193   -
1194   - foreach ($masks as $mask) {
  1113 + public function addFile($fileName, $formats)
  1114 + {
  1115 + $this->fileName = USERDATADIR.$fileName;
  1116 + $this->fileId = $fileName;
1195 1117  
1196   - $folderMask = $mask->getAttribute("name");
1197   - if ($this->fileMask($fileName, $folderMask)) {
1198   - $mask->appendChild($newFile);
1199   -
1200   - $files = $mask->getElementsByTagName("file");
1201   - foreach ($files as $file) {
1202   - $starts[] = $file->getAttribute("start");
1203   - $stops[] = $file->getAttribute("stop");
1204   - }
1205   - $mask->setAttribute("info", date('Y-m-d',min($starts))."T".date('H:i:s',min($starts))."-".date('Y-m-d',max($stops))."T".date('H:i:s',max($stops)));
1206   -
1207   - $isMask = true;
1208   - break;
1209   - }
1210   - }
1211   - // no corresponding masks => add to fileList
1212   - if (!$isMask) {
1213   - $filesList = $this->contentDom->getElementById($this->contentRootId);
1214   - $filesList->appendChild($newFile);
1215   - }
1216   -
1217   - $this->contentDom->save($this->xmlName);
1218   -
1219   - //if mask exists - add to data base
1220   - $myBaseManager = new BaseManager();
1221   - $mask = $myBaseManager->addFile($fileName);
1222   - if ($mask != null) {
1223   - $startstop = $myBaseManager->getStartStop($myBaseManager->getVi($mask));
1224   - $myParamMgr = new DerivedParamMgr('myDataParam');
1225   - $myParamMgr->updateMydata($mask,$startstop);
1226   - }
1227   -
1228   - return array( 'success' => true, 'file' => $fileName);
1229   - }
  1118 + $format = $this->getFormat();
  1119 +
  1120 + if ($format === 'unknown')
  1121 + {
  1122 + unlink($this->fileName);
  1123 + return array('success' => false, 'error' => 'Sorry, unknown format of '.$fileName);
  1124 + }
  1125 +
  1126 + if ($format == 'txt')
  1127 + {
  1128 + if ($formats["timeFormat"] == "user")
  1129 + {
  1130 + $res = $this->reformatTime($formats["nonStandard"], $formats["timeLength"], $formats["doy"]);
  1131 +
  1132 + if (!$res)
  1133 + {
  1134 + unlink($this->fileName);
  1135 + return array('success' => false, 'error' => 'can\'t reformat time');
  1136 + }
  1137 + }
  1138 + // check if file is not empty
  1139 + $vars = $this->getTxtColNumber(false);
  1140 +
  1141 + if ($vars == -100)
  1142 + {
  1143 + return array('success' => false, 'error' => 'no such file');
  1144 + }
  1145 +
  1146 + if ($vars == -1)
  1147 + {
  1148 + unlink($this->fileName);
  1149 + return array('success' => false, 'error' => 'while reading file');
  1150 + }
  1151 +
  1152 + if ($vars === 0)
  1153 + {
  1154 + unlink($this->fileName);
  1155 + return array('success' => false, 'error' => 'file contains no data');
  1156 + }
  1157 +
  1158 + if ($formats["timeSampling"] == "constant")
  1159 + {
  1160 + $this->sampling = $this->getTxtSampling();
  1161 + $this->maxSampling = $this->sampling;
  1162 + }
  1163 + else
  1164 + {
  1165 + $samplings = $this->getTxtSamplings();
  1166 + $this->sampling = $samplings[0];
  1167 + $this->maxSampling = $samplings[1];
  1168 + }
  1169 +
  1170 + if ($this->sampling <= 0)
  1171 + {
  1172 + unlink($this->fileName);
  1173 + if ($this->sampling == -10)
  1174 + {
  1175 + return array('success' => false, 'error' => 'Sorry, can\'t process'.$fileName.PHP_EOL.'. Check if there are non numeric chars in the data');
  1176 + }
  1177 + return array('success' => false, 'error' => 'Sorry, can\'t process Time for '.$fileName.PHP_EOL.'. Check time format, start time (> 1970-01-01) or sampling time (>= 1s)');
  1178 + }
  1179 + }
  1180 +
  1181 + if ($format == 'nc')
  1182 + {
  1183 + $status = $this->reformatNcTime();
  1184 + if ($status <= 0)
  1185 + {
  1186 + unlink($this->fileName);
  1187 + return array('success' => false, 'error' => 'error '.$timeFormat.PHP_EOL.'Time Format problem');
  1188 + }
  1189 + }
  1190 +
  1191 + //create new file tag with all attributes and add it to the content DOM
  1192 + $newFile = $this->createFile($format);
  1193 + if ($newFile < 0)
  1194 + {
  1195 + unlink($this->fileName);
  1196 + return array( 'success' => false, 'file' => $fileName);
  1197 + }
  1198 +
  1199 + $isMask = false;
  1200 + $masks = $this->contentDom->getElementsByTagName("folder");
  1201 +
  1202 + foreach ($masks as $mask)
  1203 + {
  1204 + $folderMask = $mask->getAttribute("name");
  1205 + if ($this->fileMask($fileName, $folderMask))
  1206 + {
  1207 + $mask->appendChild($newFile);
  1208 +
  1209 + $files = $mask->getElementsByTagName("file");
  1210 + foreach ($files as $file)
  1211 + {
  1212 + $starts[] = $file->getAttribute("start");
  1213 + $stops[] = $file->getAttribute("stop");
  1214 + }
  1215 + $mask->setAttribute("info", date('Y-m-d',min($starts))."T".date('H:i:s',min($starts))."-".date('Y-m-d',max($stops))."T".date('H:i:s',max($stops)));
  1216 +
  1217 + $isMask = true;
  1218 + break;
  1219 + }
  1220 + }
  1221 + // no corresponding masks => add to fileList
  1222 + if (!$isMask)
  1223 + {
  1224 + $filesList = $this->contentDom->getElementById($this->contentRootId);
  1225 + $filesList->appendChild($newFile);
  1226 + }
1230 1227  
  1228 + $this->contentDom->save($this->xmlName);
  1229 +
  1230 + //if mask exists - add to data base
  1231 + $myBaseManager = new BaseManager();
  1232 + $mask = $myBaseManager->addFile($fileName);
  1233 + if ($mask != null)
  1234 + {
  1235 + $startstop = $myBaseManager->getStartStop($myBaseManager->getVi($mask));
  1236 + $myParamMgr = new DerivedParamMgr('myDataParam');
  1237 + $myParamMgr->updateMydata($mask,$startstop);
  1238 + }
  1239 +
  1240 + return array( 'success' => true, 'file' => $fileName);
  1241 + }
  1242 +
  1243 + public function setFileName($name)
  1244 + {
  1245 + $this->fileName = USERDATADIR.$name;
  1246 + }
1231 1247 }
1232 1248 ?>
... ...
php/classes/VOTableMgr.php
... ... @@ -4,14 +4,14 @@
4 4 * @version $Id: VOTableMgr.php 2916 2015-05-19 13:08:33Z elena $
5 5 */
6 6  
7   -
8 7 //set DEBUG_MODE to TRUE to have some log information in user data dir
9 8 define("DEBUG_MODE",FALSE);
10 9  
11 10  
12   -class VOTableMgr {
13   - private $xml, $xp;
14   - private $log;
  11 +class VOTableMgr
  12 +{
  13 + public $xml = null;
  14 + private $log, $xp;
15 15  
16 16 function __construct()
17 17 {
... ... @@ -185,6 +185,14 @@ class VOTableMgr {
185 185 return $desc->item(0)->nodeValue;
186 186 }
187 187  
  188 + public function isData()
  189 + {
  190 + $trs = $this->xml->getElementsByTagName('TR');
  191 + if ($trs->length > 0) return true;
  192 +
  193 + return false;
  194 + }
  195 +
188 196 public function getFirstTR()
189 197 {
190 198 if (!$this->xp)
... ... @@ -260,53 +268,55 @@ class VOTableMgr {
260 268 return -1;
261 269 }
262 270  
263   - protected function getFieldByID($field_id)
264   - {
265   - if (!$this->xp)
266   - return NULL;
267   -
268   - $fields = $this->xp->query($this->queryFields());
269   -
270   - if ($fields->length < 1)
271   - return NULL;
272   -
273   - foreach ($fields as $field)
274   - if ($field->getAttribute("ID") == $field_id)
275   - return $field;
276   -
277   - return NULL;
278   - }
  271 + protected function getFieldByID($field_id)
  272 + {
  273 + if (!$this->xp)
  274 + return NULL;
279 275  
280   - protected function getFieldByName($field_id)
281   - {
282   - if (!$this->xp)
283   - return NULL;
284   -
285   - $fields = $this->xp->query($this->queryFieldByName($field_id));
286   -
287   - if ($fields->length < 1)
288   - return NULL;
289   -
290   - foreach ($fields as $field)
291   - if ($field->getAttribute("name") == $field_id)
292   - return $field;
293   -
294   - return NULL;
295   - }
296   -
297   - protected function checkIDAttribute(){
  276 + $fields = $this->xp->query($this->queryFields());
  277 +
  278 + if ($fields->length < 1)
  279 + return NULL;
  280 +
  281 + foreach ($fields as $field)
  282 + if ($field->getAttribute("ID") == $field_id)
  283 + return $field;
  284 +
  285 + return NULL;
  286 + }
298 287  
299   - $fields = $this->xml->getElementsByTagName('FIELD');
300   - $i = 0;
301   - foreach ($fields as $field){
302   - $i++;
303   - if (!$field->hasAttribute("ID")){
304   - $field->setAttribute("ID", "col".$i);
  288 + protected function getFieldByName($field_id)
  289 + {
  290 + if (!$this->xp)
  291 + return NULL;
  292 +
  293 + $fields = $this->xp->query($this->queryFieldByName($field_id));
  294 +
  295 + if ($fields->length < 1)
  296 + return NULL;
  297 +
  298 + foreach ($fields as $field)
  299 + if ($field->getAttribute("name") == $field_id)
  300 + return $field;
  301 +
  302 + return NULL;
305 303 }
306   - }
307   - $this->xml->saveXML();
308 304  
309   - }
  305 + protected function checkIDAttribute()
  306 + {
  307 +
  308 + $fields = $this->xml->getElementsByTagName('FIELD');
  309 + $i = 0;
  310 + foreach ($fields as $field)
  311 + {
  312 + $i++;
  313 + if (!$field->hasAttribute("ID"))
  314 + {
  315 + $field->setAttribute("ID", "col".$i);
  316 + }
  317 + }
  318 + $this->xml->saveXML();
  319 + }
310 320  
311 321 public function getFieldIndexByID($field_id)
312 322 {
... ... @@ -361,67 +371,69 @@ class VOTableMgr {
361 371 return $start." ".$stop;
362 372 }
363 373  
364   - public function getFieldInfoByID($field_id)
365   - {
366   - if (!$this->xp)
367   - return array("id" => $field_id,
368   - "error" => "No file loaded");
369   - $field = $this->getFieldByID($field_id);
370   -
371   - if (!$field)
372   - $field = $this->getFieldByName($field_id);
  374 + public function getFieldInfoByID($field_id)
  375 + {
  376 + if (!$this->xp)
  377 + return array("id" => $field_id, "error" => "No file loaded");
  378 +
  379 + $field = $this->getFieldByID($field_id);
  380 +
  381 + if (!$field)
  382 + $field = $this->getFieldByName($field_id);
373 383  
374   - if (!$field)
375   - return array("id" => $field_id,
376   - "error" => "This field doesn't exist");
377   - return $this->getFieldInfo($field);
378   - }
  384 + if (!$field)
  385 + return array("id" => $field_id, "error" => "This field doesn't exist");
  386 +
  387 + return $this->getFieldInfo($field);
  388 + }
379 389  
380 390  
381   - public function getFieldInfo($field)
382   - {
383   - if (!$this->xp)
384   - return array("id" => $field_id,
385   - "error" => "No file loaded");
386   - $description = '';
387   - $desc = $field->getElementsByTagName("DESCRIPTION");
388   - if ($desc->length >= 1)
389   - $description = $desc->item(0)->nodeValue;
  391 + public function getFieldInfo($field)
  392 + {
  393 + if (!$this->xp)
  394 + return array("id" => $field_id, "error" => "No file loaded");
  395 +
  396 + $description = '';
  397 + $desc = $field->getElementsByTagName("DESCRIPTION");
  398 + if ($desc->length >= 1)
  399 + $description = $desc->item(0)->nodeValue;
390 400  
391   - $size = $field->getAttribute("arraysize");
392   - if ($size == '')
393   - $size = 1;
394   - else
395   - $size = intval($size);
  401 + $size = $field->getAttribute("arraysize");
  402 + if ($size == '')
  403 + $size = 1;
  404 + else
  405 + $size = intval($size);
396 406  
397   - switch ($field->getAttribute("datatype"))
398   - {
399   - case "short" :
400   - $type = "SHORT";
401   - break;
402   - case "int" :
403   - $type = "INTEGER";
404   - break;
405   - case "long" :
406   - case "double" :
407   - $type = "DOUBLE";
408   - break;
409   - default :
410   - $type = "FLOAT";
411   - }
412   - if (!$field->getAttribute("ID"))
413   - $id = "col".$n;
414   - else $id = $field->getAttribute("ID");
415   -
416   - return array("id" => $field->getAttribute("ID"),
417   - "type" => $type,
418   - "name" => $field->getAttribute("name"),
419   - "ucd" => $field->getAttribute("ucd"),
420   - "unit" => $field->getAttribute("unit"),
421   - "size" => $size,
422   - "description" => $description
423   - );
424   - }
  407 + switch ($field->getAttribute("datatype"))
  408 + {
  409 + case "short" :
  410 + $type = "SHORT";
  411 + break;
  412 + case "int" :
  413 + $type = "INTEGER";
  414 + break;
  415 + case "long" :
  416 + case "double" :
  417 + $type = "DOUBLE";
  418 + break;
  419 + default :
  420 + $type = "FLOAT";
  421 + }
  422 +
  423 + if (!$field->getAttribute("ID"))
  424 + $id = "col".$n;
  425 + else
  426 + $id = $field->getAttribute("ID");
  427 +
  428 + return array("id" => $field->getAttribute("ID"),
  429 + "type" => $type,
  430 + "name" => $field->getAttribute("name"),
  431 + "ucd" => $field->getAttribute("ucd"),
  432 + "unit" => $field->getAttribute("unit"),
  433 + "size" => $size,
  434 + "description" => $description
  435 + );
  436 + }
425 437  
426 438 public function getFieldsInfo()
427 439 {
... ... @@ -496,81 +508,58 @@ class VOTableMgr {
496 508 "maxSampling" => $maxSampling);
497 509 }
498 510  
499   - public function args2vector($file, $paramID){
  511 + /*
  512 + * Add vector data made from components to IMPEX VOT
  513 + */
  514 + public function addVectorToVot($paramID, $fileName)
  515 + {
  516 + $argsArr = explode(',', $paramID);
  517 +
  518 + $fields = $this->xml->getElementsByTagName('FIELD');
  519 + $table = $this->xml->getElementsByTagName('TABLE')->item(0);
  520 + $data = $this->xml->getElementsByTagName('DATA')->item(0);
  521 +
  522 + $i=0;
  523 + $find = false;
  524 + foreach ($fields as $field)
  525 + {
  526 + if ($field->getAttribute('name') == $argsArr[0])
  527 + {
  528 + $unit = $field->getAttribute('unit');
  529 + $ucd = $field->getAttribute('ucd');
  530 + $datatype = $field->getAttribute('datatype');
  531 + $firstTD = $i;
  532 + $find = true;
  533 + break;
  534 + }
  535 + $i++;
  536 + }
500 537  
501   - $argsArr = explode('_', $paramID);
502   -
503   - $dom = new DOMDocument();
504   - $dom->load($file);
505   - $fields = $dom->getElementsByTagName('FIELD');
506   - $table = $dom->getElementsByTagName('TABLE')->item(0);
507   - $i=0;
508   - foreach ($fields as $field){
509   - if ($field->getAttribute('name') == $argsArr[0]){
510   - $unit = $field->getAttribute('unit');
511   - $ucd = $field->getAttribute('ucd');
512   - $datatype = $field->getAttribute('datatype');
513   - $firstTD = $i;
514   - }
515   - $i++;
516   - }
517   - if ($firstTD > 0){
518   - $table->removeChild($fields->item($firstTD + 2));
519   - $table->removeChild($fields->item($firstTD + 1));
520   - $table->removeChild($fields->item($firstTD));
521   -
522   - $i = 0;
523   - foreach ($fields as $field){
524   - $i++;
525   - if (strpos($field->getAttribute('ID'),'col') !== FALSE){
526   - $field->setAttribute('ID', 'col'.$i);
527   - $dom->saveXML();
  538 + if ($find)
  539 + {
  540 + $new_field = $this->xml->createElement('FIELD');
  541 + $new_field->setAttribute('ID', $paramID);
  542 + $new_field->setAttribute('name', $paramID);
  543 + $new_field->setAttribute('datatype', $datatype);
  544 + $new_field->setAttribute('arraysize', '3');
  545 + $new_field->setAttribute('unit', $unit);
  546 + $new_field->setAttribute('ucd', $ucd);
  547 + $colN = $fields->length + 1;
  548 + $new_field->setAttribute('ID', 'col'.$colN);
  549 +
  550 + $table->insertBefore($new_field,$data);
  551 +
  552 + $trs = $this->xml->getElementsByTagName('TR');
  553 + foreach($trs as $tr)
  554 + {
  555 + $tds = $tr->getElementsByTagName('TD');
  556 + $value = trim($tds->item($firstTD)->nodeValue).' '.trim($tds->item($firstTD + 1)->nodeValue).' '.trim($tds->item($firstTD + 2)->nodeValue);
  557 + $td = $this->xml->createElement('TD', $value);
  558 + $tr->appendChild($td);
  559 + }
  560 +
  561 + $this->xml->save($fileName);
  562 + }
528 563 }
529   - }
530   -
531   - $group = $dom->createElement('GROUP');
532   - $group->appendChild(new DOMAttr('ID', 'info_'.$paramID));
533   - $table->appendChild($group);
534   -
535   - $param = $dom->createElement('PARAM');
536   - $param->appendChild(new DOMAttr('ID', 'components_'.$paramID));
537   - $param->appendChild(new DOMAttr('name', 'components_'.$paramID));
538   - $param->appendChild(new DOMAttr('datatype', 'char'));
539   - $param->appendChild(new DOMAttr('arraysize', '*'));
540   - $param->appendChild(new DOMAttr('value', $argsArr[0].' '.$argsArr[1].' '.$argsArr[2] ));
541   - $group->appendChild($param);
542   -
543   - $new_field = $dom->createElement('FIELD');
544   - $new_field->appendChild(new DOMAttr('ID', $paramID));
545   - $new_field->appendChild(new DOMAttr('name', $paramID));
546   - $new_field->appendChild(new DOMAttr('datatype', $datatype));
547   - $new_field->appendChild(new DOMAttr('arraysize', '3'));
548   - $new_field->appendChild(new DOMAttr('unit', $unit));
549   - $new_field->appendChild(new DOMAttr('ucd', $ucd));
550   - $new_field->appendChild(new DOMAttr('ref', 'info_'.$paramID));
551   - $table->appendChild($new_field);
552   -
553   - $trs = $dom->getElementsByTagName('TR');
554   - foreach($trs as $tr){
555   - $tds = $tr->getElementsByTagName('TD');
556   - $value = trim($tds->item($firstTD)->nodeValue).' '.trim($tds->item($firstTD + 1)->nodeValue).' '.trim($tds->item($firstTD + 2)->nodeValue);
557   - $toRemote = $tds->item($firstTD);
558   - $tr->removeChild($toRemote);
559   - $toRemote = $tds->item($firstTD);
560   - $tr->removeChild($toRemote);
561   - $toRemote = $tds->item($firstTD);
562   - $tr->removeChild($toRemote);
563   -
564   - $td = $dom->createElement('TD', $value);
565   - $tr->appendChild($td);
566   - }
567   -
568   - $dom->save($file);
569   - }
570   - }
571   -
572 564 }
573   -
574   -
575   -
576 565 ?>
577 566 \ No newline at end of file
... ...
php/config.php
... ... @@ -3,385 +3,209 @@
3 3 * @file config.php
4 4 * @version $Id: config.php 2368 2014-05-21 08:46:23Z elena $
5 5 *
6   - *
7 6 */
8   -
9   -$useFirePHP = false;
10   -// require FirePHP files
11   -if($useFirePHP) {
12   - require_once("firephp/FirePHP.class.php");
13   - require_once("firephp/fb.php");
14   -}
15   -
16   -// define empty fb() function so code does not break
17   -// on any forgotten fb() calls later
18   -else {
19   - function fb() {};
20   -}
21 7  
22   -ob_start();
23   -
24   -// all installation dependent staff
  8 +/*
  9 + * ob_start
  10 + * This function will turn output buffering on.
  11 + * While output buffering is active no output is sent from the script (other than headers),
  12 + * instead the output is stored in an internal buffer.
  13 + * The contents of this internal buffer may be copied into a string variable using ob_get_contents().
  14 + * To output what is stored in the internal buffer, use ob_end_flush().
  15 + * Alternatively, ob_end_clean() will silently discard the buffer contents.
  16 +*/
  17 +// ob_start();
  18 +
  19 +/*
  20 +* Installation-dependent settings
  21 +*/
25 22 require_once 'my_config.php';
26 23  
27   -if (is_file('php/amda_version.php') || is_file('amda_version.php'))
28   - require_once 'amda_version.php';
29   -
30   -// all impex dependent staff
31   -// if (is_file('php/impex_config.php') || is_file('impex_config.php'))
32   -// require_once 'impex_config.php';
33   -if (is_file('php/impex_config.php'))
34   - require_once 'php/impex_config.php';
35   -else require_once 'impex_config.php';
36   -//---------------------------------------
37   -
38   -if (!defined('PHP_VERSION_ID'))
39   - {
40   - $version = explode('.', PHP_VERSION);
41   - define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
  24 +if (is_file('amda_version.php'))
  25 + require_once 'amda_version.php';
  26 +
  27 +if (is_file('errors.php'))
  28 + require_once 'errors.php';
  29 +
  30 +/*----------------------- SYSTEM config section --------*/
  31 +if (!defined('PHP_VERSION_ID'))
  32 +{
  33 + $version = explode('.', PHP_VERSION);
  34 + define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
42 35 }
43 36  
44   -if (!defined('MAGIC_FILE'))
45   - define('MAGIC_FILE','/usr/share/misc/magic');
  37 +if (!defined('MAGIC_FILE'))
  38 + define('MAGIC_FILE','/usr/share/misc/magic');
  39 +
  40 +date_default_timezone_set('UTC');
  41 +/*-----------------------END SYSTEM config section --------*/
46 42  
47   -define("MaxGuests", 10);
  43 +/*----------------------- GUESTS LOGIN section --------*/
  44 +define("MaxGuests", 10); // Max Guests number
48 45 define("GuestSessionDuration", 300); //300 minutes
49 46 define("MaxGuestTimeInterval", 10); // days
  47 +/*-----------------------END GUESTS LOGIN section --------*/
50 48  
51   -ini_set('upload_max_filesize',30000000);
52   -// SHOULD BE DEFINED IN MASTER php.ini !!!
53   -// ini_set('post_max_size',40000000);
54   -ini_set('memory_limit',128000000);
55   -
56   -// max lines of uploaded ascii file to show
57   -define('MAX_FILE_INDEX_TO_SHOW', 100);
58 49 // user WS size limit
59 50 define('DISK_QUOTA', 1024*1024*200); // 200MB
60   -
61   -// to avoid 403 error while copying from URL
62   -ini_set('user_agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:7.0) Gecko/201001012 Firefox/7.0');
63   -
  51 +// max lines of uploaded ascii file to show
  52 +define('MAX_FILE_INDEX_TO_SHOW', 100);
64 53 // private key used to be considerate as a trust client for some functions of DD web service
65 54 define('DDSERVICE_PRIVATEKEY','!%p856Dc');
66   -
67   -date_default_timezone_set('UTC');
68   -// time restriction suffix
69   -define('restricted', '_restr');
70 55  
71   -// one cycle secs to sleep to allow job be executed
72   -define('JOBTIMEOUT', '1');
  56 +/*----------------------- BATCH JOBS section --------*/
  57 +define('JOBTIMEOUT', '1'); // one cycle secs to sleep to allow job be executed
73 58 define('PLOT_CYCLES_NUMBER', 500); // cycles number for PNG
74 59 define('JOB_CYCLES_NUMBER', 5); // cycles number for all the jobs
75   -
76   -//TODO secs wait before job is killed OR 'max_execution_time' - kill automatic?
77   -//define('TIMEOUT', '100');
78   -//TODO define max PHP execution
79   -ini_set('max_execution_time',600);
80   -
81   -//Error codes
82   -define('-1','NAME_EXISTS');
83   -define('-2','ID_CREATION_ERROR');
84   -define('-3','NO_SUCH_ID');
85   -define('-4','NO_SUCH_PARENT_ID');
86   -define('-5','NO_OBJECT_FILE');
87   -
88   -// SVN Repository for local parameters files (DD_*.xml, LocalParams.xml, ...)
89   -define('SVN_DDMISSIONSINFO', 'svn://cdpp1.cesr.fr/depotINFO/');
90   -define('SVN_LOCALPARAMSINFO', SVN_DDMISSIONSINFO.'LocalParam/');
91   -define('SVN_TEMPLATES', SVN_DDMISSIONSINFO.'Templates/');
92   -
93   -// EPN-TAP services
94   -define('EPNTAP_APIS','http://voparis-tap.obspm.fr/__system__/tap/run/tap/sync');
95   -define('EPNTAP_AMDA','http://cdpp-epntap.cesr.fr/__system__/tap/run/tap/sync');
96   -
97   -// General Info dirs; old AMDA
98   -define('INFODIR', ROOT_PATH.'INFO/');
99   -define('XMLDIR', ROOT_PATH.'XML/');
  60 +//define('TIMEOUT', '100'); //TODO secs wait before job is killed OR 'max_execution_time' - kill automatic?
  61 +/*-----------------------END BATCH JOBS section --------*/
100 62  
101   -// General Info files; old AMDA
102   -define('userGroupsXml',XMLDIR.'AMDA_Users.xml');
103   -
104   -// PHP classes : new AMDA
105   -define('CLASSPATH', BASE_PATH.'php/classes/');
106   -define('OLD_CLASSPATH', BASE_PATH.'php/old_amda/');
107   -define('XMLPATH', BASE_PATH.'php/XML/');
  63 +/*----------------------- PHP run-time settings --------*/
  64 +ini_set('memory_limit',128000000);
  65 +ini_set('max_execution_time',600); // max PHP execution
  66 +ini_set('default_socket_timeout', 600); //TODO if this is needed ? IMPEX LONG DURATION WEBSERVICES
  67 +// to avoid 403 error while copying from URL
  68 +ini_set('user_agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:7.0) Gecko/201001012 Firefox/7.0');
  69 +// SHOULD BE DEFINED IN MASTER /etc/php.ini !!!
  70 +// ini_set('upload_max_filesize',100000000);
  71 +// ini_set('post_max_size',1050000000);
  72 +/*-----------------------END PHP run-time settings --------*/
108 73  
109   -// General Info dirs : new AMDA
110   -define('DATAPATH', BASE_PATH.'generic_data/');
111 74  
112   -define('Param', DATAPATH.'Param/');
113   -define('ParamArgs', Param.'Args/');
114   -define('LocalData', DATAPATH.'LocalData/');
115   -define('LocalDataParam', LocalData.'Param/');
116   -define('EPNResources', DATAPATH.'EPNResources/');
117   -define('LocalDataTemplate', LocalData.'Templates/');
  75 +// General Info dirs
  76 +define('DATAPATH', IHM_SRC_DIR.'generic_data/');
  77 +//define('Param', DATAPATH.'Param/');
  78 +define('LocalData', DATAPATH.'LocalData/');
118 79 define('RemoteData', DATAPATH.'RemoteData/');
119 80 define('Functions', DATAPATH.'Functions/');
120   -define('Plot', DATAPATH.'Plot/');
  81 +//define('Plot', DATAPATH.'Plot/');
121 82 define('Hst', DATAPATH.'Hst/');
122   -define('GeneralInfo', DATAPATH.'Info/');
123 83 define('SpecialSettingsDir',DATAPATH.'SpecialSettings/');
124 84  
125   -// General Info files; new AMDA
126   -define('paramListXml',Param.'LocalParamsList.xml');
127   -define('paramXml',Param.'LocalParams.xml');
128   -define('orbitesXml',Param.'Orbites.xml');
129   -define('spectraXml',Param.'SpectraParamList.xml');
130   -define('targetsXml',LocalData.'targets.xml');
131   -
132   -define('missionXml',LocalData.'Missions.xml');
133   -define('internalParams', LocalData.'DD_InternalParams.xml');
  85 +// General Info files
  86 +define('orbitsXml',LocalData.'Orbites.xml');
  87 +// define('targetsXml',LocalData.'targets.xml');
134 88 define('FeedbackXml', DATAPATH.'Feedback/Feedback.xml');
135   -define('TEMPLATES',BASE_PATH.'amda_plus/templates/');
136   -define('PREDEFINED',BASE_PATH.'amda_plus/predefined/');
137   -define('PRO',BASE_PATH.'amda_plus/pro/');
138 89 define('specialGrpsXml',SpecialSettingsDir.'Groups.xml');
  90 +define('specialSettingsXml',SpecialSettingsDir.'Settings.xml');
139 91  
140 92 //Help info dirs
141   -define('HELPPATH', BASE_PATH."help/");
142   -define('targetsSimu',HELPPATH.'simu/TargetsSimu.xml');
  93 +define('HELPPATH', IHM_SRC_DIR."help/");
143 94  
144   -//Root User dir : new AMDA
145   -// All user dirs are defined in UserMgr.php
146   -define('USERPATH', BASE_PATH.'data/');
  95 +// IMPEX special files
  96 +define('SimuTargetsXml', DATAPATH.'SimuTemplate/TargetsSimu.xml');
147 97  
148   -// Shared dir
149   -define('SHAREDPATH', BASE_PATH.'shared_data/');
  98 +// Root User dir : All user dirs are defined in UserMgr.php
  99 +define('USERPATH', IHM_SRC_DIR.'data/');
150 100  
151   -// Web Services result directory
152   -define('WSRESULT', USERPATH.'WSRESULT/');
  101 +// Shared dir
  102 +define('SHAREDPATH', IHM_SRC_DIR.'shared_data/');
153 103  
154   -// Web Service result file
155   -define('wsResultsXml',WSRESULT.'WSresults.xml');
  104 +/*------------------- WEB SERVICES section ---------*/
  105 +define('WSRESULT', USERPATH.'WSRESULT/'); // Web Services result directory
  106 +define('wsResultsXml',WSRESULT.'WSresults.xml'); // Web Service result file
156 107  
157   -// Web Service getPlot : list of parameters to plot
158   -define('plotsXml', BASE_PATH.'public/WebServices/XML/AmdaPlots.xml');
159   -// Web Service serveurs WSDL
  108 +define('plotsXml', IHM_SRC_DIR.'public/WebServices/XML/AmdaPlots.xml'); // Web Service getPlot : list of parameters to plot
160 109  
161   -// $_SERVER['SERVER_NAME'] (par apache) gethostname() (par command)
  110 +// Web Service servers WSDL : $_SERVER['SERVER_NAME'] (par apache) gethostname() (par command)
162 111 $SERVER_NAME = $_SERVER['SERVER_NAME'] ? $_SERVER['SERVER_NAME'] : gethostname();
163 112 define('wsdl_AMDA', "http://".$SERVER_NAME.APACHE_ALIAS."public/wsdl/Methods_AMDA.wsdl");
164   -
  113 +/*-------------------END WEB SERVICES section ---------*/
  114 +
165 115 // AKKA - KERNELBIN is now the new kernel bin dir
166 116 define('KERNELBIN',NEWKERNEL_INSTALL_DIR.'bin/');
167 117  
168 118 putenv("LD_LIBRARY_PATH=".SYS_LIBS.":".DDLIB.":".CEFLIB.":".CDFLIB);
169   -putenv("PATH=./:".DDBIN.":".SYS_BIN.":".BASE_PATH."php/bin");
  119 +putenv("PATH=./:".DDBIN.":".SYS_BIN.":".IHM_SRC_DIR."php/bin");
170 120  
171 121 putenv("DDPATH=".DDRES_DIR);
172   -
  122 +
  123 +// PHP classes
  124 +define('XMLPATH', IHM_SRC_DIR.'php/XML/');
  125 +define('CLASSPATH', IHM_SRC_DIR.'php/classes/');
  126 +define('OLD_CLASSPATH', IHM_SRC_DIR.'php/old_amda/');
  127 +
173 128 set_include_path(".:".CLASSPATH.":".OLD_CLASSPATH);
174 129  
175   -global $API;
176   -
177   -if (!function_exists('__autoload')) {
178   - function __autoload($class_name) {
179   - require_once $class_name . '.php';
180   - }
  130 +if (!function_exists('__autoload'))
  131 +{
  132 + function __autoload($class_name) {
  133 + require_once $class_name . '.php';
  134 + }
181 135 }
182   -
183 136  
  137 +global $API;
184 138 $API = array(
185   - 'AmdaAction'=>array(
186   - 'methods'=>array(
187   - 'getTree'=>array(
188   - 'len'=>1
189   - ),
190   - 'saveTree'=>array(
191   - 'len'=>1
192   - ),
193   - 'getInfo'=>array(
194   - 'len'=>1
195   - ),
196   - 'doNothing'=>array(
197   - 'len'=>1
198   - ),
199   - 'deleteFromTree'=>array(
200   - 'len'=>1
201   - ),
202   - 'getObject'=>array(
203   - 'len'=>2
204   - ),
205   - 'getAsciiFile'=>array(
206   - 'len'=>1
207   - ),
208   - 'getTmpObject'=>array(
209   - 'len'=>3
210   - ),
211   - 'getUploadedObject'=>array(
212   - 'len'=>3
213   - ),
214   - 'getMyParamInfo'=>array(
215   - 'len'=>1
216   - ),
217   - 'deleteObject'=>array(
218   - 'len'=>1
219   - ),
220   - 'renameObject'=>array(
221   - 'len'=>1
222   - ),
223   - 'createObject'=>array(
224   - 'len'=>2
225   - ),
226   - 'modifyObject'=>array(
227   - 'len'=>1
228   - ),
229   - 'validNameObject'=>array(
230   - 'len'=>1
231   - ),
232   - 'getJobs'=>array(
233   - 'len'=>0
234   - ),
235   - 'execute'=>array(
236   - 'len'=>2
237   - // 'formHandler'=>true
238   - ),
239   - 'compilParam' => array(
240   - 'len'=>1
241   - ),
242   - 'compilParamDelete' => array(
243   - 'len'=>1
244   - ),
245   - 'killPlotRequest' =>array(
246   - 'len'=>0
247   - ),
248   - 'merge'=>array(
249   - 'len'=>1
250   - ),
251   - 'intersect'=>array(
252   - 'len'=>1
253   - ),
254   - 'loadTTIntervals'=>array(
255   - 'len'=>1
256   - ),
257   - 'saveTTCacheIntervalsInTT'=>array(
258   - 'len'=>1
259   - ),
260   - 'initTTCache' => array (
261   - 'len'=>2
262   - ) ,
263   - 'initTTCacheFromTT' => array(
264   - 'len'=>2
265   - ),
266   - 'initForChart' => array(
267   - 'len'=>4
268   - ),
269   - 'initTTCacheFromTmpObject' => array(
270   - 'len'=>3
271   - ),
272   - 'initTTCacheFromUploadedFile' => array(
273   - 'len'=>2
274   - ),
275   - 'readTTCacheIntervals'=>array(
276   - 'len'=>1
277   - ),
278   - 'readIntervalsForChart'=>array(
279   - 'len'=>1
280   - ),
281   - 'addTTCacheInterval'=>array (
282   - 'len'=>1
283   - ),
284   - 'removeTTCacheIntervalFromId'=>array (
285   - 'len'=>2
286   - ),
287   - 'modifyTTCacheInterval' => array(
288   - 'len'=>1
289   - ),
290   - 'operationTTCacheIntervals' => array(
291   - 'len'=>2
292   - ),
293   - 'mergeTTCacheIntervals' => array (
294   - 'len'=>0
295   - ),
296   - 'getTTCacheStatistics' => array (
297   - 'len'=>0
298   - ),
299   - 'sendFeedback'=>array(
300   - 'len'=>1
301   - ),
302   - 'saveState'=>array(
303   - 'len'=>1
304   - ),
305   - 'loadState'=>array(
306   - 'len'=>1
307   - ),
308   - 'sendToSAMP'=>array(
309   - 'len'=>1
310   - ),
311   - 'getHstImagesUrl'=>array(
312   - 'len'=>1
313   - ),
314   - 'getAPISImagesUrl'=>array(
315   - 'len'=>1
316   - ),
317   - 'loadFilterList'=>array(
318   - 'len'=>0
319   - ),
320   - 'loadFilters'=>array(
321   - 'len'=>1
322   - ),
323   - 'saveFilter'=>array(
324   - 'len'=>1
325   - ),
326   - 'createFilter'=>array(
327   - 'len'=>1
328   - ),
329   - 'destroyFilter'=>array(
330   - 'len'=>1
331   - ),
332   - 'getCrtFilterId'=>array(
333   - 'len'=>0
334   - ),
335   - 'getCrtFilterResult'=>array(
336   - 'len'=>0
337   - ),
338   - 'setCrtFilterId'=>array(
339   - 'len'=>1
340   - ),
341   - 'resetFilter'=>array(
342   - 'len'=>0
343   - ),
344   - 'logout'=>array(
345   - 'len'=>1
346   - ),
347   - 'getUserInfo'=>array(
348   - 'len'=>0
349   - ),
350   - 'convertWS'=>array(
351   - 'len'=>0
352   - ),
353   - 'getRun'=>array(
354   - 'len'=>1
355   - ),
356   - 'addRun'=>array(
357   - 'len'=>1
358   - ),
359   - //AKKA - New action to clean user WS
360   - 'cleanUserWS'=>array(
361   - 'len'=>0
362   - ),
363   - 'deleteSpecialInfo'=>array(
364   - 'len'=>1
365   - ),
366   - 'interactivePlot'=>array(
367   - 'len'=>2
368   - ),
369   - 'getParamPlotInit'=>array(
370   - 'len'=>1
371   - ),
372   - 'getParamInfo'=>array(
373   - 'len'=>1
374   - ),
375   - 'getSharedObjectFolders' => array(
376   - 'len'=>1
377   - ),
378   - 'shareObjects' => array(
379   - 'len'=>1
380   - ),
381   - 'isSharedObjectNameAlreadyUsed' => array(
382   - 'len'=>1
383   - )
384   - )
385   - )
  139 + 'AmdaAction'=>array(
  140 + 'methods'=>array(
  141 + 'getTree'=>array('len'=>1),
  142 + 'saveTree'=>array('len'=>1),
  143 + 'getInfo'=>array('len'=>1),
  144 + 'doNothing'=>array('len'=>1),
  145 + 'deleteFromTree'=>array('len'=>1),
  146 + 'getObject'=>array('len'=>2),
  147 + 'getAsciiFile'=>array('len'=>1),
  148 + 'getTmpObject'=>array('len'=>3),
  149 + 'getUploadedObject'=>array('len'=>3),
  150 + 'getMyParamInfo'=>array('len'=>1),
  151 + 'deleteObject'=>array('len'=>1),
  152 + 'renameObject'=>array('len'=>1),
  153 + 'createObject'=>array('len'=>2),
  154 + 'modifyObject'=>array('len'=>1),
  155 + 'validNameObject'=>array('len'=>1),
  156 + 'getJobs'=>array('len'=>0),
  157 + 'execute'=>array('len'=>2),
  158 + //'formHandler'=>true
  159 + 'compilParam'=>array('len'=>1),
  160 + 'compilParamDelete'=>array('len'=>1),
  161 + 'killPlotRequest'=>array('len'=>0),
  162 + 'merge'=>array('len'=>1),
  163 + 'intersect'=>array('len'=>1),
  164 + 'loadTTIntervals'=>array('len'=>1),
  165 + 'saveTTCacheIntervalsInTT'=>array('len'=>1),
  166 + 'initTTCache'=>array ('len'=>2),
  167 + 'initTTCacheFromTT'=>array('len'=>2),
  168 + 'initForChart'=>array('len'=>4),
  169 + 'initTTCacheFromTmpObject'=>array('len'=>3),
  170 + 'initTTCacheFromUploadedFile'=>array('len'=>2),
  171 + 'readTTCacheIntervals'=>array('len'=>1),
  172 + 'readIntervalsForChart'=>array('len'=>1),
  173 + 'addTTCacheInterval'=>array('len'=>1),
  174 + 'removeTTCacheIntervalFromId'=>array('len'=>2),
  175 + 'modifyTTCacheInterval'=>array('len'=>1),
  176 + 'operationTTCacheIntervals'=>array('len'=>2),
  177 + 'mergeTTCacheIntervals'=>array('len'=>0),
  178 + 'getTTCacheStatistics'=>array('len'=>0),
  179 + 'sendFeedback'=>array('len'=>1),
  180 + 'saveState'=>array('len'=>1),
  181 + 'loadState'=>array('len'=>1),
  182 + 'sendToSAMP'=>array('len'=>1),
  183 + 'getHstImagesUrl'=>array('len'=>1),
  184 + 'getAPISImagesUrl'=>array('len'=>1),
  185 + 'loadFilterList'=>array('len'=>0),
  186 + 'loadFilters'=>array('len'=>1),
  187 + 'saveFilter'=>array('len'=>1),
  188 + 'createFilter'=>array('len'=>1),
  189 + 'destroyFilter'=>array('len'=>1),
  190 + 'getCrtFilterId'=>array('len'=>0),
  191 + 'getCrtFilterResult'=>array('len'=>0),
  192 + 'setCrtFilterId'=>array('len'=>1),
  193 + 'resetFilter'=>array('len'=>0),
  194 + 'logout'=>array('len'=>1),
  195 + 'getUserInfo'=>array('len'=>0),
  196 + 'convertWS'=>array('len'=>0),
  197 + 'getRun'=>array('len'=>1),
  198 + 'addRun'=>array('len'=>1),
  199 + //AKKA - New action to clean user WS
  200 + 'cleanUserWS'=>array('len'=>0),
  201 + 'deleteSpecialInfo'=>array('len'=>1),
  202 + 'interactivePlot'=>array('len'=>2),
  203 + 'getParamPlotInit'=>array('len'=>1),
  204 + 'getParamInfo'=>array('len'=>1),
  205 + 'getSharedObjectFolders' => array('len'=>1),
  206 + 'shareObjects' => array('len'=>1),
  207 + 'isSharedObjectNameAlreadyUsed' => array('len'=>1)
  208 + )
  209 + )
386 210 );
387 211 ?>
... ...