diff --git a/update_amda/makeHAPIMetadata.php b/update_amda/makeHAPIMetadata.php index 1ea72cf..af2608f 100644 --- a/update_amda/makeHAPIMetadata.php +++ b/update_amda/makeHAPIMetadata.php @@ -100,18 +100,25 @@ foreach ($dataset_nodes as $dataset_node) { //type $parameter->{"type"} = "double"; + //Load info_file if exists + $infofile_path = $infofiles_path . "/info_".$parameter_node->getAttribute("xml:id").".xml"; + $info_doc = NULL; + if (file_exists($infofile_path)) { + $info_doc = new DOMDocument(); + if (!@$info_doc->load($infofile_path)) { + $info_doc = NULL; + } + } + //size $size = $parameter_node->getAttribute("size"); if (empty($size)) { if ($parameter_node->getAttribute("display_type") == "spectrogram") { - //Load info_file if exists and retrieve dimensions - $infofile_path = $infofiles_path . "/info_".$parameter_node->getAttribute("xml:id").".xml"; - if (!file_exists($infofile_path)) { + //Retrieve dimensions in info file + if (!isset($info_doc)) { echo "[WARNING] Parameter ".$param_id." defines as a spectrogram but cannot retrieve info file => Skip this parameter".PHP_EOL; continue; } - $info_doc = new DOMDocument(); - @$info_doc->load($infofile_path); $dimensions_node = $info_doc->getElementsByTagName("dimensions"); if ($dimensions_node->length == 0) { echo "[WARNING] Cannot retrieve size for ".$param_id.PHP_EOL; @@ -144,6 +151,47 @@ foreach ($dataset_nodes as $dataset_node) { $parameter->{"size"} = $size; } + //bins + $bins = NULL; + if (!empty($size) && isset($info_doc)) { + $tables_node = $info_doc->getElementsByTagName("tables"); + if ($tables_node->length > 0) { + $bins = array(); + $tables_node = $tables_node->item(0); + $table_nodes = $tables_node->getElementsByTagName("table"); + if ($table_nodes->length > 0) { + foreach ($table_nodes as $table_node) { + $relatedDim = $table_node->getAttribute("relatedDim"); + $bin_index = ($relatedDim == "dim_1") ? 0 : 1; + $nameBin = $table_node->getAttribute("name"); + $unitsBin = $table_node->getAttribute("units"); + $channel_nodes = $table_node->getElementsByTagName("channel"); + $ranges = array(); + foreach ($channel_nodes as $channel_node) { + $min_range = $channel_node->getAttribute("min"); + $max_range = $channel_node->getAttribute("max"); + $ranges[] = array(floatval($min_range), floatval($max_range)); + } + if (!empty($ranges)) { + $bin_info = (Object)array(); + $bin_info->{"name"} = $nameBin; + $bin_info->{"units"} = $unitsBin; + $bin_info->{"ranges"} = $ranges; + if ($bin_index == 0) { + array_unshift($bins, $bin_info); + } + else { + array_push($bins, $bin_info); + } + } + } + } + } + } + if (!empty($bins)) { + $parameter->{"bins"} = $bins; + } + //units $units = $parameter_node->getAttribute("units"); if (empty($units)) -- libgit2 0.21.2