Commit b90099f71d9dfe356d9b03f7ce0f376849845bd3

Authored by Benjamin Renard
1 parent 15ee6c97
Exists in master and in 1 other branch WIP

Try to improve get release date

src/DATA/TOOLS/GetReleaseDate.c 0 → 100644
... ... @@ -0,0 +1,96 @@
  1 +
  2 +/** @file GetReleaseDate.c
  3 +* @brief Stand-alone executable <br> Returns release date for given VI in DDBase <br>
  4 +*
  5 +* @details GetReleaseDate(string *) <br>
  6 +* @arg \c argv[1] Full name of *_times.nc
  7 +*
  8 +*/
  9 +
  10 +
  11 +#include <stdlib.h>
  12 +#include <stdio.h>
  13 +#include <string.h>
  14 +#include <time.h>
  15 +#include <sys/stat.h>
  16 +#include <math.h>
  17 +#include <netcdf.h>
  18 +#include <DD.h>
  19 +
  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, len;
  33 +
  34 + if (argc < 3){
  35 + fprintf(stderr,"Usage: GetReleaseDate 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 FileID;
  51 + if ((status = nc_inq_varid(DataID, "FileName", &FileID)) != NC_NOERR)
  52 + nc_handle_error(status);
  53 +
  54 + int Filedims[2];
  55 + if ((status = nc_inq_var(DataID, FileID, NULL, NULL, NULL, Filedims, NULL)) != NC_NOERR)
  56 + nc_handle_error(status);
  57 +
  58 + size_t nb_records;
  59 + if ((nc_inq_dimlen(DataID, Filedims[0], &nb_records)) != NC_NOERR)
  60 + nc_handle_error(status);
  61 +
  62 + int i;
  63 + char FileName[32];
  64 + char filePath[512];
  65 + size_t count[2] = {1L,32L};
  66 + size_t start[2] = {0L,0L};
  67 + struct stat attrib;
  68 +
  69 + time_t releaseDate = 0;
  70 + for (i = 0; i < nb_records; ++i) {
  71 + count[1] = 32;
  72 + if ((status = nc_get_vara_text(DataID, FileID, start, count, FileName)) != NC_NOERR)
  73 + nc_handle_error(status);
  74 + memset(filePath, 0, 512*sizeof(char));
  75 + strcat(filePath, argv[1]);
  76 + strcat(filePath, "/");
  77 + strcat(filePath, FileName);
  78 + strcat(filePath, ".gz");
  79 + stat(filePath, &attrib);
  80 + if (releaseDate < attrib.st_mtime)
  81 + releaseDate = attrib.st_mtime;
  82 + }
  83 +
  84 +
  85 + nc_close(DataID);
  86 +
  87 + if (releaseDate == 0)
  88 + exit(1);
  89 +
  90 + char releaseDateISO[21];
  91 + memset(releaseDateISO, 0, 21*sizeof(char));
  92 + strftime(releaseDateISO, 21, "%Y-%m-%dT%H:%M:%SZ", localtime( &releaseDate));
  93 +
  94 + printf("%s\n", releaseDateISO);
  95 + exit(0);
  96 +}
... ...
src/DDSERVICES/SOAP/DDserverWeb.php
... ... @@ -137,6 +137,7 @@ function getVIInfo($viId)
137 137 $viName = $nameNode->nodeValue;
138 138 $timesNode = $timesNode->item(0);
139 139 $timesFile = $location.$timesNode->nodeValue;
  140 +
140 141 if (!empty($location) && !empty($viName)) {
141 142  
142 143 // Start / Stop Date
... ... @@ -146,12 +147,11 @@ function getVIInfo($viId)
146 147  
147 148 // Release date
148 149 $releaseDate = NULL;
149   - $find = 'find '.$location.' -name \'*.nc.gz\' -type f -printf \'%T@ %p\n\' | sort -n | tail -1 | cut -f2- -d" "';
150   - $lastFile = exec($find);
151   - if (file_exists($lastFile)) {
152   - $cmd = 'date "+%Y-%m-%dT%H:%M:%SZ" -u -r '.$lastFile; // for NFS
153   - $releaseDate = exec($cmd);
154   - }
  150 + $cmd = "/opt/tools/DDServer/bin/GetReleaseDate ".$location." ".$timesNode->nodeValue;
  151 + $output = array();
  152 + exec($cmd, $output, $result_code);
  153 + if ($result_code == 0)
  154 + $releaseDate = $output[0];
155 155  
156 156 // Modification date
157 157 $cmd = "/opt/tools/DDServer/bin/GetModificationDate ".$timesFile;
... ...