diff --git a/php/RemoteDataCenter/CDAWEB.php b/php/RemoteDataCenter/CDAWEB.php index fee3806..96e6bab 100644 --- a/php/RemoteDataCenter/CDAWEB.php +++ b/php/RemoteDataCenter/CDAWEB.php @@ -6,7 +6,8 @@ class CDAWEB extends RemoteDataCenterClientClass { - + //public $defaultFillValue = -1.e31; + protected function dataset2dd($id) { return $id; @@ -14,7 +15,7 @@ class CDAWEB extends RemoteDataCenterClientClass public function getParamSize() { - $cmd = "ncinfo_remote ".RemoteData.$this->baseID."/".$this->infoFile." ".$this->ParamId; + $cmd = "ncinfo_remote ".RemoteData.$this->baseID."/".$this->infoFile." ".$this->ParamId." 0"; $res = shell_exec($cmd); return $res; @@ -28,6 +29,22 @@ class CDAWEB extends RemoteDataCenterClientClass return $res; } + public function getParamUnits() + { + $cmd = "ncinfo_remote ".RemoteData.$this->baseID."/".$this->infoFile." ".$this->ParamId." 2"; + $res = shell_exec($cmd); + + return $res; + } + + public function getParamFillValue() + { + $cmd = "ncinfo_remote ".RemoteData.$this->baseID."/".$this->infoFile." ".$this->ParamId." 3"; + $res = shell_exec($cmd); + + return $res; + } + public function setInfoFile() { $this->infoFile = strtolower($this->ViId).".nc"; diff --git a/php/RemoteDataCenter/RemoteDataCenterClientClass.php b/php/RemoteDataCenter/RemoteDataCenterClientClass.php index 10f1094..17f48f8 100644 --- a/php/RemoteDataCenter/RemoteDataCenterClientClass.php +++ b/php/RemoteDataCenter/RemoteDataCenterClientClass.php @@ -9,7 +9,7 @@ class RemoteDataCenterClientClass public $baseDom = null, $dataCenter = null; public $baseDomName; public $baseID = null; - public $ViId = null, $ParamId = null; + public $ViId = null, $ParamId = null, $defaultFillValue; protected $client; public $infoFile = null; diff --git a/php/RemoteDataCenter/RemoteParamManager.php b/php/RemoteDataCenter/RemoteParamManager.php index ba2741b..9d6658d 100644 --- a/php/RemoteDataCenter/RemoteParamManager.php +++ b/php/RemoteDataCenter/RemoteParamManager.php @@ -61,17 +61,30 @@ class RemoteParamManager $this->center = new $baseId(); } - -/* - <param xml:id="ace_r"> - <get> - <vi name="ace:orb:all"> - <baseParam name="R"/> - </vi></get> - <process>$ace_orb_all_R/RADIUS_EARTH</process> - <output/> - </param> -*/ + +// <param xml:id="imf"> +// <info> +// <name>imf</name> +// <short_name>b_gse</short_name> +// <components>bx,by,bz</components> +// <units>nT</units> +// <coordinates_system>GSE</coordinates_system> +// <tensor_order/> +// <si_conversion>1e-9>T</si_conversion> +// <fill_value>-1.0E31</fill_value> +// <ucd>phys.magField</ucd> +// <dataset_id>ace-imf-all</dataset_id> +// <instrument_id>ACE_MAG</instrument_id> +// </info> +// <get> +// <vi name="ace:imf:all"> +// <baseParam name="IMF"/> +// </vi> +// </get> +// <process/> +// <output/> +// </param> + public function makeInternalParamXml() { if (!$this->center->ViId) return false; @@ -91,13 +104,44 @@ class RemoteParamManager $xml->appendChild($paramNode); $paramNode->setAttribute("xml:id", $this->paramId); - $getNode = $xml->createElement("get"); - $viNode = $xml->createElement("vi"); + + $infoNode = $xml->createElement("info"); + $infoNode->appendChild($xml->createElement("name",strtolower($this->center->ParamId))); + $infoNode->appendChild($xml->createElement("short_name",strtolower($this->center->ParamId))); + + $size = $this->center->getParamSize(); + //TODO spectra components + if ($size > 1) + { + $components = strtolower($this->center->getParamComponents()); + } + else { + $components = null; + } + + $fillValue = $this->center->getParamFillValue(); + if (!$fillValue) + $fillValue = null; + + $infoNode->appendChild($xml->createElement("components",$components)); + $infoNode->appendChild($xml->createElement("units",$this->center->getParamUnits())); + $infoNode->appendChild($xml->createElement("coordinates_system")); + $infoNode->appendChild($xml->createElement("tensor_order")); + $infoNode->appendChild($xml->createElement("si_conversion")); + $infoNode->appendChild($xml->createElement("fill_value", $fillValue)); + $infoNode->appendChild($xml->createElement("ucd")); + $infoNode->appendChild($xml->createElement("dataset_id")); + $infoNode->appendChild($xml->createElement("instrument_id")); + + $getNode = $xml->createElement("get"); + $viNode = $xml->createElement("vi"); $baseParamNode = $xml->createElement("baseParam"); $baseParamNode->setAttribute("name", $this->center->ParamId); $viNode->setAttribute("name", strtolower(strtr($this->center->ViId,"_", ":"))); $viNode->appendChild($baseParamNode); - $getNode->appendChild($viNode); + $getNode->appendChild($viNode); + + $paramNode->appendChild($infoNode); $paramNode->appendChild($getNode); $paramNode->appendChild($xml->createElement("process")); $paramNode->appendChild($xml->createElement("output")); @@ -111,7 +155,7 @@ class RemoteParamManager protected function makeComponents($node, $size, $components) { - $compArray = explode(";",$components); + $compArray = explode(",",$components); for ($i = 0; $i < $size; $i++) { @@ -158,7 +202,7 @@ class RemoteParamManager $this->center->setInfoFile(); if (!$this->makeInternalParamXml()) return false; - + if (($size = $this->center->getParamSize()) > 1) { // make components and args diff --git a/php/src/ncinfo_remote.c b/php/src/ncinfo_remote.c index cb30ad0..921d76c 100644 --- a/php/src/ncinfo_remote.c +++ b/php/src/ncinfo_remote.c @@ -1,3 +1,13 @@ +/* + * get parameter info from CDAWEB dataset nc file + * args : ncfile varId infoId + * infoId : + * 0 - dimension + * 1 - labels + * 2 - units + * 3 - fillvalue + */ + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -22,16 +32,23 @@ main(int argc, char **argv) size_t start[] = {0, 0}; size_t count[] = {1, 0}; size_t size, length; - - if (argc <= 2) { + int infoId; + float number_attr; + + const char *info[2]; + info[0] = "UNITS"; + info[1] = "_FillValue"; + + if (argc <= 3) { printf("Incorrect number of arguments\n"); exit(1); } - + + infoId = atoi(argv[3]); + stat = nc_open(argv[1],NC_WRITE|NC_SHARE,&ncID); check(stat); stat = nc_inq_varid(ncID, argv[2], &varID); check(stat); - stat = nc_inq_varndims(ncID, varID, &ndims); check(stat); stat = nc_inq_vardimid(ncID, varID, dimids); check(stat); @@ -40,39 +57,32 @@ main(int argc, char **argv) if (ndims > 1) for (i = 1; i < ndims; i++) { stat = nc_inq_dimlen(ncID, dimids[i], &len); check(stat); - if (argc == 3) + if (infoId == 0) { fprintf(stdout, "%d ", len); } } else - if (argc == 3) + if (infoId == 0) { fprintf(stdout,"%d ", len); } - if (argc == 4) + if (infoId == 1) { size_t attlen = 0; - stat = nc_inq_attlen(ncID, varID, "LABL_PTR_1", &attlen); check(stat); - // stat = nc_inq_atttype(ncID, varID, "LABL_PTR_1", &xtype); check(stat); + stat = nc_inq_attlen(ncID, varID, "LABL_PTR_1", &attlen); check(stat); unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*)); stat = nc_get_att(ncID, varID, "LABL_PTR_1", string_attr); check(stat); - - // printf("attribute = %s\n", string_attr); + stat = nc_inq_varid(ncID, string_attr, &labelID); check(stat); - // stat = nc_inq_vartype(ncID, labelID, &xtype); check(stat); - - // printf("%d \n", xtype); - stat = nc_inq_varndims(ncID, labelID, &ndims); check(stat); stat = nc_inq_vardimid(ncID, labelID, dimids); check(stat); for (i = 0; i < ndims; i++) { - stat = nc_inq_dimlen(ncID, dimids[i], &len); check(stat); - // printf("%d \n", len); + stat = nc_inq_dimlen(ncID, dimids[i], &len); check(stat); if (i == 0) size = len; if (i == 1) length = len; } @@ -82,13 +92,32 @@ main(int argc, char **argv) for (i = 0; i < size; i++) { stat = nc_get_vara(ncID, labelID, start, count, string_var); check(stat); - fprintf(stdout, "%s;", string_var); + fprintf(stdout, "%s", string_var); + if (i < size -1) fprintf(stdout,","); start[0]++; } free(string_attr); free(string_var); } + if (infoId == 2) + { + size_t attlen = 0; + stat = nc_inq_attlen(ncID, varID, info[infoId-2], &attlen); check(stat); + + unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*)); + stat = nc_get_att(ncID, varID, info[infoId-2], string_attr); check(stat); + fprintf(stdout, "%s", string_attr); + free(string_attr); + } + + if (infoId == 3) + { + stat = nc_get_att(ncID, varID, info[infoId-2], &number_attr); check(stat); + fprintf(stdout, "%e", number_attr); + + } + stat = nc_close(ncID); exit(0); } -- libgit2 0.21.2