Commit 920f6512089373d492ed8940319e529e7669c1bf

Authored by Benjamin Renard
2 parents 84b4b63d c30a5897
Exists in master and in 2 other branches WIP, ubuntu

Merge branch 'epntap'

src/DATA/TOOLS/GetGranules.c 0 → 100644
... ... @@ -0,0 +1,118 @@
  1 +
  2 +/** @file GetGranules.c
  3 +* @brief Stand-alone executable <br> Returns granules for given VI in DDBase <br>
  4 +*
  5 +* @details GetGranules(string *) <br>
  6 +* @arg \c argv[1] Path to VI
  7 +* @arg \c argv[2] Times file name
  8 +*
  9 +*/
  10 +
  11 +
  12 +#include <stdlib.h>
  13 +#include <stdio.h>
  14 +#include <string.h>
  15 +#include <time.h>
  16 +#include <math.h>
  17 +#include <sys/stat.h>
  18 +#include <netcdf.h>
  19 +#include <DD.h>
  20 +
  21 +
  22 +/*---------------- NC ERROR --------------------------------------*/
  23 +void nc_handle_error(int status)
  24 +{
  25 + fprintf(stderr, "%s\n", nc_strerror(status));
  26 + exit(1);
  27 +}
  28 +
  29 +/* ----------------------- MAIN ------------------------------------*/
  30 +int main(int argc, char *argv[])
  31 +{
  32 + int status;
  33 +
  34 + if (argc < 3){
  35 + fprintf(stderr,"Usage: GetGranules path_to_vi times_file_name\n");
  36 + exit(1);
  37 + }
  38 +
  39 + char timesPath[512];
  40 + memset(timesPath, 0, 512*sizeof(char));
  41 + strcat(timesPath, argv[1]);
  42 + strcat(timesPath, "/");
  43 + strcat(timesPath, argv[2]);
  44 +
  45 + // Open VI_times.nc
  46 + int DataID;
  47 + if ((status = nc_open(timesPath, NC_NOWRITE, &DataID)) != NC_NOERR)
  48 + nc_handle_error(status);
  49 +
  50 + int StartID;
  51 + if ((status = nc_inq_varid(DataID, "StartTime", &StartID)) != NC_NOERR)
  52 + nc_handle_error(status);
  53 +
  54 + int ndims;
  55 + int Startdims[NC_MAX_VAR_DIMS];
  56 + if ((status = nc_inq_var(DataID, StartID, 0, 0, &ndims, Startdims, NULL)) != NC_NOERR)
  57 + nc_handle_error(status);
  58 +
  59 + int StopID;
  60 + if ((status = nc_inq_varid(DataID, "StopTime", &StopID)) != NC_NOERR)
  61 + nc_handle_error(status);
  62 +
  63 + int Stopdims[2];
  64 + if ((status = nc_inq_var(DataID, StopID, NULL, NULL, NULL, Stopdims, NULL)) != NC_NOERR)
  65 + nc_handle_error(status);
  66 +
  67 + int FileID;
  68 + if ((status = nc_inq_varid(DataID, "FileName", &FileID)) != NC_NOERR)
  69 + nc_handle_error(status);
  70 +
  71 + int Filedims[2];
  72 + if ((status = nc_inq_var(DataID, FileID, NULL, NULL, NULL, Filedims, NULL)) != NC_NOERR)
  73 + nc_handle_error(status);
  74 +
  75 + if ((Startdims[0] != Stopdims[0]) || (Startdims[0] != Filedims[0])) {
  76 + fprintf(stderr, "Error in variables definition\n");
  77 + exit(1);
  78 + }
  79 +
  80 + size_t nb_records;
  81 + if ((nc_inq_dimlen(DataID, Startdims[0], &nb_records)) != NC_NOERR)
  82 + nc_handle_error(status);
  83 +
  84 + int i;
  85 + char StartTime[TIMELENGTH];
  86 + char StopTime[TIMELENGTH];
  87 + char FileName[32];
  88 + double StartTimestamp;
  89 + double StopTimestamp;
  90 + size_t count[2] = {1L,TIMELENGTH};
  91 + size_t start[2] = {0L,0L};
  92 + char filePath[512];
  93 + struct stat attrib;
  94 +
  95 + for (i = 0; i < nb_records; ++i) {
  96 + count[1] = TIMELENGTH;
  97 + start[0] = i;
  98 + if ((status = nc_get_vara_text(DataID, StartID, start, count, StartTime)) != NC_NOERR)
  99 + nc_handle_error(status);
  100 + StartTimestamp = DD_Time2Double(StartTime);
  101 + if ((status = nc_get_vara_text(DataID, StopID, start, count, StopTime)) != NC_NOERR)
  102 + nc_handle_error(status);
  103 + StopTimestamp = DD_Time2Double(StopTime);
  104 + count[1] = 32;
  105 + if ((status = nc_get_vara_text(DataID, FileID, start, count, FileName)) != NC_NOERR)
  106 + nc_handle_error(status);
  107 + memset(filePath, 0, 512*sizeof(char));
  108 + strcat(filePath, argv[1]);
  109 + strcat(filePath, "/");
  110 + strcat(filePath, FileName);
  111 + strcat(filePath, ".gz");
  112 + stat(filePath, &attrib);
  113 +
  114 + printf("%f %f %s %d\n", StartTimestamp, StopTimestamp, FileName, attrib.st_mtime);
  115 + }
  116 +
  117 + if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status);
  118 +}
... ...
src/DDSERVICES/REST/getGranules.php 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +<?php
  2 +
  3 +/**
  4 +* @file getGranules.php
  5 +* @brief Returns Granules for a given DataSet
  6 +* @version $Id: $
  7 +*/
  8 +
  9 + if (!isset($_GET['id'])) exit('INPUT ERROR');
  10 +
  11 + require_once './DDserverWeb_ini.php';
  12 +
  13 + error_reporting(E_ERROR | E_WARNING | E_PARSE);
  14 +
  15 + $replace = array("-" => "_");
  16 +
  17 + $dataSet = strtr($_GET['id'], $replace);
  18 +
  19 + $referXML = baseDir."/DDsys.xml";
  20 + $DDsys = new DOMDocument("1.0");
  21 + $DDsys->load($referXML);
  22 + $xp = new domxpath($DDsys);
  23 + $VI = $xp->query("//NAME[.='".$dataSet."']");
  24 +
  25 + if ($VI->item(0)->nodeValue != NULL)
  26 + {
  27 + $location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue;
  28 + $times = $VI->item(0)->parentNode->getElementsByTagName("TIMES")->item(0)->nodeValue;
  29 + $cmd = "/opt/tools/DDServer/bin/GetGranules ".$location." ".$times;
  30 + exec($cmd, $output, $result_code);
  31 + if ($result_code === 0)
  32 + exit(implode("\n",$output));
  33 + }
  34 + exit('ERROR');
  35 +?>
... ...
src/DDSERVICES/SOAP/DDserverWeb.php
... ... @@ -492,6 +492,26 @@
492 492 return null;
493 493 }
494 494  
  495 +
  496 + function getGranules($dataSet)
  497 + {
  498 + $referXML = baseDir."/DDsys.xml";
  499 + $DDsys = new DOMDocument("1.0");
  500 + $DDsys->load($referXML);
  501 + $xp = new domxpath($DDsys);
  502 + $VI = $xp->query("//NAME[.='".$dataSet."']");
  503 +
  504 + if ($VI->item(0)->nodeValue != NULL)
  505 + {
  506 + $location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue;
  507 + $times = $VI->item(0)->parentNode->getElementsByTagName("TIMES")->item(0)->nodeValue;
  508 + $cmd = "/opt/tools/DDServer/bin/GetGranules ".$location." ".$times;
  509 + exec($cmd, $output, $result_code);
  510 + if ($result_code === 0)
  511 + return implode("\n",$output);
  512 + }
  513 + return NULL;
  514 + }
495 515  
496 516 /**
497 517 * Returns String Start-Stop for local DataSet in DD Base
... ...
src/DDSERVICES/SOAP/dd.wsdl.in
... ... @@ -86,6 +86,12 @@
86 86 <message name='getLastRealUpdateResponse'>
87 87 <part name='Result' type='xsd:string'/>
88 88 </message>
  89 +<message name='getGranulesRequest'>
  90 + <part name='dataSet' type='xsd:string'/>
  91 +</message>
  92 +<message name='getGranulesResponse'>
  93 + <part name='Result' type='xsd:string'/>
  94 +</message>
89 95 <message name='getInfoRequest'>
90 96 <part name='dataSet' type='xsd:string'/>
91 97 <part name='infoName' type='xsd:string'/>
... ... @@ -193,6 +199,10 @@
193 199 <operation name='getLastRealUpdate'>
194 200 <input message='tns:getLastRealUpdateRequest'/>
195 201 <output message='tns:getLastRealUpdateResponse'/>
  202 + </operation>
  203 + <operation name='getGranules'>
  204 + <input message='tns:getGranulesRequest'/>
  205 + <output message='tns:getGranulesResponse'/>
196 206 </operation>
197 207 <operation name='getInfo'>
198 208 <input message='tns:getInfoRequest'/>
... ... @@ -316,7 +326,18 @@
316 326 <soap:body use='encoded'
317 327 encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
318 328 </output>
319   - </operation>
  329 + </operation>
  330 + <operation name='getGranules'>
  331 + <soap:operation soapAction='getGranules'/>
  332 + <input>
  333 + <soap:body use='encoded'
  334 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  335 + </input>
  336 + <output>
  337 + <soap:body use='encoded'
  338 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  339 + </output>
  340 + </operation>
320 341 <operation name='getInfo'>
321 342 <soap:operation soapAction='getSInfo'/>
322 343 <input>
... ...