Commit 0ec2128107ca399ddb45dc7b6b171d0740ba35a2

Authored by Elena.Budnik
1 parent 9ac916e7

reorganization + completition

Showing 41 changed files with 3028 additions and 177 deletions   Show diff stats
ATTENTION 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +Attention ! apus case
  2 +
  3 +In glibc 2.17 the crypt function implementation was tightened up
  4 +to allow for future implementation improvements, standards
  5 +conformance, and FIPS compliance. From the 2.17 NEWS:
  6 +
  7 +* The `crypt' function now fails if passed salt bytes that violate the
  8 + specification for those values. On Linux, the `crypt' function will
  9 + consult /proc/sys/crypto/fips_enabled to determine if "FIPS mode" is
  10 + enabled, and fail on encrypted strings using the MD5 or DES algorithm
  11 + when the mode is enabled.
  12 +
  13 +In this particular case the salt is an invalid POSIX salt that
  14 +contains an ASCII space "#" in character 0 outside of the allowed
  15 +alphabet for salts which is `./0-9a-zA-Z' and therefore crypt will
  16 +reject that salt as invalid, return NULL, and set errno.
  17 +
  18 +Previous to glibc 2.17 a call to crypt would accept invalid POSIX
  19 +salts.
... ...
CMakeLists.txt
... ... @@ -47,12 +47,7 @@ add_subdirectory(src/DECODERS/themis/esafull2nc)
47 47 add_subdirectory(src/DECODERS/themis/esamom2nc)
48 48 add_subdirectory(src/DECODERS/themis/fgm2nc)
49 49 add_subdirectory(src/DECODERS/themis/sst2nc)
50   -add_subdirectory(src/DATA/TIMESUPDATE)
51   -add_subdirectory(src/DATA/TIMESUPDATENODATA)
52   -add_subdirectory(src/DATA/STARTSTOPLOCAL)
53   -add_subdirectory(src/DATA/INFOLOCAL2NC)
54   -add_subdirectory(src/DATA/MAKEDDSYS)
55   -add_subdirectory(src/DATA/JOIN_NC)
  50 +add_subdirectory(src/DATA/TOOLS)
56 51 add_subdirectory(tests)
57 52  
58 53 install(FILES "scripts/StartServer" DESTINATION . PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
... ... @@ -61,5 +56,6 @@ install(FILES "scripts/AddLocalVI.sh" DESTINATION . PERMISSIONS OWNER_READ OWNER
61 56 install(FILES "scripts/UpdateInfoVI.sh" DESTINATION . PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
62 57 install(DIRECTORY "src/CALLEXT/" DESTINATION bin/CALLEXT)
63 58 install(DIRECTORY "src/DATA/MANAGER/" DESTINATION bin/DATAMANAGER)
  59 +install(DIRECTORY "src/REMOTEDATA/" DESTINATION bin/REMOTEDATA)
64 60  
65 61 SET(CMAKE_VERBOSE_MAKEFILE ON)
... ...
cmake/modules/FindLibXML2.cmake
... ... @@ -5,9 +5,9 @@
5 5 # LIBXML2_LIBRARIES - The libraries needed to use LibXml2
6 6 # LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2
7 7  
8   -FIND_PATH(LIBXML2_INCLUDE_DIR libxml/xinclude.h PATHS ${USERLOCAL_ROOT}/include/libxml2 /opt/local/include/libxml2)
  8 +FIND_PATH(LIBXML2_INCLUDE_DIR libxml/xinclude.h PATHS /usr/include/libxml2 ${USERLOCAL_ROOT}/include/libxml2 /opt/local/include/libxml2)
9 9  
10   -FIND_LIBRARY(LIBXML2_LIBRARIES NAMES xml2 libxml2 PATHS ${USERLOCAL_ROOT}/lib /opt/local/lib NO_DEFAULT_PATH)
  10 +FIND_LIBRARY(LIBXML2_LIBRARIES NAMES xml2 libxml2 PATHS /usr/lib64 ${USERLOCAL_ROOT}/lib /opt/local/lib NO_DEFAULT_PATH)
11 11  
12 12 IF(LIBXML2_INCLUDE_DIR AND LIBXML2_LIBRARIES)
13 13 SET(LibXML2_FOUND 1)
... ...
scripts/DDServer.env.in
1 1 #!/bin/bash
2 2  
3   -DDBASE=/home/budnik/AMDA-NG.core/DDBASE/DATA
4   -DDPATH=/home/budnik/AMDA-NG.core/DDBASE
5   -DDLIB=@DDCLIENTLIB_DIR@
  3 +DDBASE=/home/budnik/DDBASE/DATA
  4 +DDPATH=/home/budnik/DDBASE
  5 +DDLIB=@DDCLIENTLIB_DIR@/
6 6 DDBASEBIN=@CMAKE_INSTALL_PREFIX@/bin
7 7 LD_LIBRARY_PATH=$DDLIB/:@NETCDFLIB_DIR@:@libcdf_LIBRARY_DIR@:@USRLIB_DIR@
8 8 DATAMANAGER=@CMAKE_INSTALL_PREFIX@/bin/DATAMANAGER
  9 +REMOTEDATA=@CMAKE_INSTALL_PREFIX@/bin/REMOTEDATA
  10 +CALLEXT=@CMAKE_INSTALL_PREFIX@/bin/CALLEXT
  11 +
9 12 export DDBASE DDPATH DDBASEBIN DDLIB LD_LIBRARY_PATH
  13 +export DATAMANAGER REMOTEDATA CALLEXT
... ...
src/CALLEXT/createVI.php
... ... @@ -62,25 +62,35 @@
62 62 $baseMgr->createVi();
63 63 // if (verbose)
64 64 // error_log("request to add Data Set ".$base.":".$remSetID." as ".$ViId.PHP_EOL, 3, log);
65   -//
66   -//-------------- Get Full Dataset Info file from distant database-------------
67   -//
  65 +//
68 66 $center = new $base();
69 67  
70 68 $startStamp = strtotime($baseMgr->globalStart);
71 69 $stopStamp = strtotime($baseMgr->globalStart."+1 day");
72 70 $start = date( "Ymd\THis\Z", $startStamp);
73   - $stop = date( "Ymd\THis\Z", $stopStamp);
  71 + $stop = date( "Ymd\THis\Z", $stopStamp-60.0);
74 72  
75 73 $startIso = date( "Y-m-d\TH:i:s\.000\Z", $startStamp);
76 74 $stopIso = date( "Y-m-d\TH:i:s\.000\Z", $stopStamp);
77   -
  75 + // Get Full Dataset Info file from distant database
  76 + $infoFile = $center->getDatasetInfo($remSetID);
  77 +
  78 + if ($infoFile)
  79 + {
  80 + echo "INFO ".$infoFile.PHP_EOL;
  81 + $baseMgr->setInfo($infoFile);
  82 + }
  83 +
78 84 $ncFiles = $center->getData($remSetID, $start, $stop);
79 85  
80   - $baseMgr->addRemoteData($remSetID, $ncFiles, $startIso, $stopIso);
81   - echo " START-STOP ".$start." ".$stop.PHP_EOL;
82   -// if (!$res)
83   -// error_log("Error: Can't get dataset info for ".$remSetID." from ".$dataBaseID.PHP_EOL, 3, err);
  86 + if (!$infoFile && $ncFiles)
  87 + {
  88 + echo "INFO ".$ncFiles[0].PHP_EOL;
  89 + $baseMgr->setInfo($ncFiles[0]);
  90 + }
  91 +
  92 + $baseMgr->addRemoteData($remSetID, $ncFiles, $startIso, $stopIso);
  93 + // echo "START-STOP ".$start." ".$stop.PHP_EOL;
84 94  
85 95 // if (verbose) error_log("Get dataset info for ".$remSetID." from ".$dataBaseID." returns ".$res.PHP_EOL, 3, log);
86 96  
... ...
src/CALLEXT/getData.php
... ... @@ -26,25 +26,26 @@
26 26 if (!function_exists('__autoload'))
27 27 {
28 28 function __autoload($class_name) {
29   - require_once $class_name . '.php';
  29 + require_once $class_name.'.php';
30 30 }
31 31 }
32 32  
33 33 putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH"));
34 34 putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin");
35 35 set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT"));
  36 +
36 37 date_default_timezone_set('UTC');
37 38 $startStamp = strtotime($Start);
38 39 $stopStamp = strtotime($Stop);
39 40 $start = date( "Ymd\THis\Z", $startStamp);
40 41 $stop = date( "Ymd\THis\Z", $stopStamp);
41   -
  42 +
42 43 $startIso = date( "Y-m-d\TH:i:s\.000\Z", $startStamp);
43 44 $stopIso = date( "Y-m-d\TH:i:s\.000\Z", $stopStamp);
44 45 // Get data and convert to nc
45 46 $center = new $base();
46 47  
47   - $ncFiles = $base->getData($id, $start, $stop);
  48 + $ncFiles = $center->getData($id, $start, $stop);
48 49  
49 50 // Add nc to Vi
50 51 $baseMgr = new DDBaseMgr();
... ...
src/DATA/INFOLOCAL2NC/CMakeLists.txt deleted
... ... @@ -1,26 +0,0 @@
1   -
2   -PROJECT(infoLocal2nc)
3   -
4   -include_directories(
5   - ${DDCLIENTINCLUDE_DIR}
6   - ${NETCDFINCLUDE_DIR}
7   - ${LIBXML2_INCLUDE_DIR}
8   -)
9   -
10   -#ConLIBXML2_INCLUDE_DIRfiguration de l'exécutable
11   -file(
12   - GLOB_RECURSE
13   - source_files
14   - ./*
15   -)
16   -
17   -ADD_EXECUTABLE (infoLocal2nc ${source_files} )
18   -
19   -target_link_libraries(
20   - infoLocal2nc
21   - ${DDCLIENTLIBRARY}
22   - ${NETCDFLIBRARY}
23   - ${LIBXML2_LIBRARIES}
24   -)
25   -
26   -install (TARGETS infoLocal2nc DESTINATION bin)
src/DATA/JOIN_NC/CMakeLists.txt deleted
... ... @@ -1,24 +0,0 @@
1   -
2   -PROJECT(join_nc)
3   -
4   -include_directories(
5   - ${DDCLIENTINCLUDE_DIR}
6   - ${NETCDFINCLUDE_DIR}
7   -)
8   -
9   -#Configuration de l'exécutable
10   -file(
11   - GLOB_RECURSE
12   - source_files
13   - ./*
14   -)
15   -
16   -ADD_EXECUTABLE (join_nc ${source_files} )
17   -
18   -target_link_libraries(
19   - join_nc
20   - ${DDCLIENTLIBRARY}
21   - ${NETCDFLIBRARY}
22   -)
23   -
24   -install (TARGETS join_nc DESTINATION bin)
src/DATA/MAKEDDSYS/CMakeLists.txt deleted
... ... @@ -1,26 +0,0 @@
1   -
2   -PROJECT(makeDDsys)
3   -
4   -include_directories(
5   - ${DDCLIENTINCLUDE_DIR}
6   - ${NETCDFINCLUDE_DIR}
7   - ${LIBXML2_INCLUDE_DIR}
8   -)
9   -
10   -#Configuration de l'exécutable
11   -file(
12   - GLOB_RECURSE
13   - source_files
14   - ./*
15   -)
16   -
17   -ADD_EXECUTABLE (makeDDsys ${source_files} )
18   -
19   -target_link_libraries(
20   - makeDDsys
21   - ${DDCLIENTLIBRARY}
22   - ${NETCDFLIBRARY}
23   - ${LIBXML2_LIBRARIES}
24   -)
25   -
26   -install (TARGETS makeDDsys DESTINATION bin)
src/DATA/MANAGER/DDBaseMgr.php
... ... @@ -227,9 +227,24 @@ class DDBaseMgr
227 227  
228 228 system("TimesUpdateNoData ".strtolower($id)."_times.nc ".$start." ".$stop);
229 229  
  230 + echo strtolower($id)."_times.nc ".$start." ".$stop.PHP_EOL;
230 231 chdir($WORKING_DIR);
231 232 $this->unlockVi();
232 233 }
  234 +
  235 + public function setInfo($infoFile)
  236 + {
  237 + $fullInfoName = getenv("DDBASE")."/../INFO/bases/".$this->base."/$infoFile";
  238 +
  239 + if (file_exists($fullInfoName)) unlink($fullInfoName);
  240 + //TODO errors
  241 + //if (!file_exists($infoFile))
  242 + $WORKING_DIR = getcwd();
  243 + echo "$WORKING_DIR/$infoFile, $fullInfoName".PHP_EOL;
  244 + rename("$WORKING_DIR/$infoFile", $fullInfoName);
  245 +
  246 + //system("gunzip -c ".$this->ViDir."/$ncFile.gz > $fullAliasName");
  247 + }
233 248 }
234 249 ?>
235 250  
236 251 \ No newline at end of file
... ...
src/DATA/STARTSTOPLOCAL/CMakeLists.txt deleted
... ... @@ -1,24 +0,0 @@
1   -
2   -PROJECT(StartStopLocal)
3   -
4   -include_directories(
5   - ${DDCLIENTINCLUDE_DIR}
6   - ${NETCDFINCLUDE_DIR}
7   -)
8   -
9   -#Configuration de l'exécutable
10   -file(
11   - GLOB_RECURSE
12   - source_files
13   - ./*
14   -)
15   -
16   -ADD_EXECUTABLE (StartStopLocal ${source_files} )
17   -
18   -target_link_libraries(
19   - StartStopLocal
20   - ${DDCLIENTLIBRARY}
21   - ${NETCDFLIBRARY}
22   -)
23   -
24   -install (TARGETS StartStopLocal DESTINATION bin)
src/DATA/TIMESUPDATE/CMakeLists.txt deleted
... ... @@ -1,24 +0,0 @@
1   -
2   -PROJECT(TimesUpdate)
3   -
4   -include_directories(
5   - ${DDCLIENTINCLUDE_DIR}
6   - ${NETCDFINCLUDE_DIR}
7   -)
8   -
9   -#Configuration de l'exécutable
10   -file(
11   - GLOB_RECURSE
12   - source_files
13   - ./*
14   -)
15   -
16   -ADD_EXECUTABLE (TimesUpdate ${source_files} )
17   -
18   -target_link_libraries(
19   - TimesUpdate
20   - ${DDCLIENTLIBRARY}
21   - ${NETCDFLIBRARY}
22   -)
23   -
24   -install (TARGETS TimesUpdate DESTINATION bin)
src/DATA/TIMESUPDATENODATA/CMakeLists.txt deleted
... ... @@ -1,24 +0,0 @@
1   -
2   -PROJECT(TimesUpdateNoData)
3   -
4   -include_directories(
5   - ${DDCLIENTINCLUDE_DIR}
6   - ${NETCDFINCLUDE_DIR}
7   -)
8   -
9   -#Configuration de l'exécutable
10   -file(
11   - GLOB_RECURSE
12   - source_files
13   - ./*
14   -)
15   -
16   -ADD_EXECUTABLE (TimesUpdateNoData ${source_files} )
17   -
18   -target_link_libraries(
19   - TimesUpdateNoData
20   - ${DDCLIENTLIBRARY}
21   - ${NETCDFLIBRARY}
22   -)
23   -
24   -install (TARGETS TimesUpdateNoData DESTINATION bin)
src/DATA/TOOLS/CMakeLists.txt 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +
  2 +PROJECT(TOOLS)
  3 +
  4 +include_directories(
  5 + ${DDCLIENTINCLUDE_DIR}
  6 + ${NETCDFINCLUDE_DIR}
  7 + ${LIBXML2_INCLUDE_DIR}
  8 +)
  9 +
  10 +#Configuration de l'exécutable
  11 +
  12 +file( GLOB SOURCE_FILES ./*.c )
  13 +
  14 +foreach( sourcefile ${SOURCE_FILES} )
  15 + get_filename_component( source ${sourcefile} NAME)
  16 + string( REPLACE ".c" "" exefile ${source} )
  17 + add_executable( ${exefile} ${source} )
  18 + target_link_libraries( ${exefile} ${DDCLIENTLIBRARY} ${NETCDFLIBRARY} ${LIBXML2_LIBRARIES})
  19 + install (TARGETS ${exefile} DESTINATION bin)
  20 +endforeach( sourcefile ${SOURCE_FILE} )
... ...
src/DATA/TOOLS/CleanNoData.c 0 → 100644
... ... @@ -0,0 +1,130 @@
  1 +/* $Id: CleanNoData.c,v 1.1 2008/09/16 15:26:27 elena Exp $*/
  2 +/*=====================================================================
  3 + * DD SYSTEM base package
  4 + * DD_Server library
  5 + * CleanNoData.c
  6 + *
  7 + *
  8 + * usage CleanNoData nc_times_file
  9 + * Note that at the end of activity you have to run ClearTimes nc_times_file
  10 + *=====================================================================*/
  11 + /*=====================================================================
  12 + * Description:
  13 + * Program reads nc_times_file and remove NODATA intervals
  14 + *
  15 + *
  16 + * Dimensions:
  17 + * TimeLingth TIMELENGTH
  18 + * NameLength NAME_DIM
  19 + * Record Unlimited
  20 + * Variables:
  21 + *
  22 + * char StartTime[TIMELENGTH]
  23 + * char EndTime[TIMELENGTH]
  24 + *
  25 + * Attributes:
  26 + * none
  27 + *======================================================================*/
  28 +#include <stdio.h>
  29 +#include <stdlib.h>
  30 +#include <string.h>
  31 +#include <ctype.h>
  32 +#include <dirent.h>
  33 +#include <netcdf.h>
  34 +#include <math.h>
  35 +#include <DD.h>
  36 +
  37 +/* Global Constant definitions */
  38 +
  39 +#define TIME_LENGTH_NAME "TimeLength"
  40 +#define TIME_LENGTH 17L
  41 +#define REC_DIM_NAME "record"
  42 +#define REC_DIM NC_UNLIMITED
  43 +#define NAME_DIM_NAME "NameLength"
  44 +#define NAME_DIM 32L
  45 +#define NAME_LENGTH 100
  46 +
  47 +#define STARTTIME "StartTime"
  48 +#define STOPTIME "StopTime"
  49 +#define FILENAME "FileName"
  50 +
  51 +#define TIME_TYPE NC_CHAR
  52 +
  53 +#define NODATA "NODATA\0"
  54 +#define TEMPORARY_NAME "temporary_name\0"
  55 +
  56 +/*----------- Type definition ------------------------------*/
  57 +typedef struct
  58 +{
  59 + char Name[NAME_LENGTH]; // current data file
  60 + char StartS[TIME_LENGTH]; // Start Time String
  61 + char StopS[TIME_LENGTH]; // Stop Time String
  62 + double StartD; // Start double
  63 + double StopD; // Stop double
  64 +} t_StartStop;
  65 +
  66 +
  67 + int tmID, StartID, StopID, NameID;
  68 + size_t RecordsNumber = 0; // Records Number of the existing times file
  69 + static char ZeroTime[TIME_LENGTH] = "0000000000000000\0";
  70 +
  71 +
  72 +/*==================================================================================
  73 + * MAIN
  74 + *==================================================================================*/
  75 +main(int argc, char **argv)
  76 +{
  77 + static char usage[] = "usage: CleanNoData nc_times_file ";
  78 +
  79 + char Name[NAME_DIM];
  80 +
  81 +/* NC definitions */
  82 + int RecDimID; /* ID of dimensions */
  83 + static size_t TimeStart[2] = {0,0};
  84 + static size_t TimeCount[2] = {1,TIME_LENGTH};
  85 + static size_t NameCount[2] = {1, NAME_DIM};
  86 + int i;
  87 + int status;
  88 +
  89 +
  90 +/*=================================================================
  91 + * Check arguments and options
  92 + *=================================================================*/
  93 + if(argc < 2) {fprintf(stderr,"%s\n",usage); exit(1); }
  94 +
  95 +/*-----------------------------------------------------------------*/
  96 +
  97 +/*====== open existing file ===================*/
  98 +
  99 +
  100 + if((status = nc_open(argv[1],NC_WRITE|NC_SHARE,&tmID)) != NC_NOERR)
  101 + {
  102 + fprintf(stderr,"Can not open file %s to write\n",argv[1]);
  103 + exit(0);
  104 + }
  105 + status = nc_inq_dimid(tmID,REC_DIM_NAME,&RecDimID);
  106 + status = nc_inq_varid(tmID, STARTTIME,&StartID);
  107 + status = nc_inq_varid(tmID, STOPTIME,&StopID);
  108 + status = nc_inq_varid(tmID, FILENAME,&NameID);
  109 + status = nc_inq_dimlen(tmID,RecDimID, &RecordsNumber);
  110 +
  111 +/*==========================================================================*/
  112 +
  113 + /*==========================================================================
  114 + * For Each record in the nc_times_file
  115 + *=========================================================================*/
  116 + for (i = 0; i < RecordsNumber; i++) {
  117 +
  118 + TimeStart[0] = i;
  119 + nc_get_vara_text(tmID,NameID,TimeStart,NameCount,(void *)Name);
  120 + if(strncmp(Name,NODATA,6) == 0) { /* The record is NODATA */
  121 + status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)ZeroTime);
  122 + status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)ZeroTime);
  123 + status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)TEMPORARY_NAME);
  124 + }
  125 +
  126 + }
  127 + nc_sync(tmID);
  128 + status = nc_close(tmID);
  129 +}
  130 +/*=========================================================================================================*/
... ...
src/DATA/TOOLS/ClearTimes.c 0 → 100644
... ... @@ -0,0 +1,190 @@
  1 +/*----------------- ClearTimes ------------------------------*/
  2 +/* name: ClearTimes.c
  3 + * V.3.0
  4 + * author: Andrey Fedorov
  5 + * modification list:
  6 + * Jan 6, 2006, V.1.0
  7 + * Aug 3, 2007, V.2.0 , Merging NODATA records
  8 + * Aug 28, 2009 V.3.0 new netCDF
  9 + *
  10 + * Descriptions: Remove all zero records from times.nc file after
  11 + * DDrechash processing.
  12 + * usage : ClearTimes file_name
  13 +*------------------------------------------------------------*/
  14 +
  15 +#include <stdio.h>
  16 +#include <stdlib.h>
  17 +#include <string.h>
  18 +#include <ctype.h>
  19 +#include <netcdf.h>
  20 +#include <DD.h>
  21 +#include <DD_comm.h>
  22 +
  23 +/* Global Constant definitions */
  24 +#define TIMELENGTH_NAME "TimeLength"
  25 +#define REC_DIM_NAME "record"
  26 +#define REC_DIM NC_UNLIMITED
  27 +#define NAME_DIM_NAME "NameLength"
  28 +
  29 +#define STARTTIME "StartTime"
  30 +#define STOPTIME "StopTime"
  31 +#define FILENAME "FileName"
  32 +
  33 +#define DATAOK "DATAOK"
  34 +#define TEMPNAME "temptimes.nc"
  35 +
  36 +#define TIME_TYPE NC_CHAR
  37 +
  38 +main(int argc, char **argv)
  39 +{
  40 + static char description[] = "usage: DDClearTimes nc_times_file";
  41 +
  42 + char Start[TIMELENGTH], Stop[TIMELENGTH], Name[MAXFILENAME];
  43 + char StartPrevious[TIMELENGTH], StopPrevious[TIMELENGTH], NamePrevious[MAXFILENAME];
  44 +
  45 +/* NC definitions */
  46 + int SourceID; /* nc Source descriptor */
  47 + int DestID; /* nc Destination descriptor */
  48 + int SStartID, SStopID, SNameID; /* Sources variables ID */
  49 + int DStartID, DStopID, DNameID; /* Destination variables ID */
  50 + int STlDimID,SRecDimID, SNlDimID; /* Source ID of dimensions */
  51 + int DTlDimID,DRecDimID, DNlDimID; /* Destination ID of dimensions */
  52 +
  53 + size_t DRecordNumber = 0; // Current record number destination
  54 + size_t SRecordNumber; // Total record number source
  55 + long ics; // current source record
  56 +
  57 +/*---------- Universal counters and offsets -----------------*/
  58 + size_t TimeStart[2] = {0L,0L};
  59 + size_t TimeCount[2] = {1L,TIMELENGTH};
  60 + size_t NameCount[2] = {1L, MAXFILENAME};
  61 + int DimVector[2];
  62 +
  63 + char command[100];
  64 + char name[100];
  65 + int compress = 0;
  66 + int status;
  67 +
  68 +/*------------ Set value of global variables ------------------*/
  69 + // ncopts = NC_VERBOSE;
  70 +
  71 +/*-----------------------------------------------------------------*/
  72 +/*
  73 + * Check arguments
  74 + */
  75 + if(argc < 2) {fprintf(stderr,"%s\n",description); exit(1); }
  76 +/*-----------------------------------------------------------------*/
  77 +/*
  78 + * Creating temporay file to write (destination)
  79 + */
  80 + status = nc_create(TEMPNAME,NC_CLOBBER,&DestID);
  81 + status = nc_def_dim(DestID,TIMELENGTH_NAME,TIMELENGTH,&DTlDimID);
  82 + status = nc_def_dim(DestID,NAME_DIM_NAME,MAXFILENAME,&DNlDimID);
  83 + status = nc_def_dim(DestID,REC_DIM_NAME,REC_DIM,&DRecDimID);
  84 +
  85 + DimVector[0] = DRecDimID;
  86 + DimVector[1] = DTlDimID;
  87 + status = nc_def_var(DestID, STARTTIME, TIME_TYPE,2,DimVector,&DStartID);
  88 + status = nc_def_var(DestID, STOPTIME, TIME_TYPE,2,DimVector,&DStopID);
  89 + DimVector[1] = DNlDimID;
  90 + status = nc_def_var(DestID, FILENAME, TIME_TYPE,2,DimVector,&DNameID);
  91 + DRecordNumber = 0;
  92 + nc_enddef(DestID);
  93 +
  94 +/*====== Open source file ===================*/
  95 + status = nc_open(argv[1],NC_WRITE,&SourceID);
  96 + status = nc_inq_dimid(SourceID,REC_DIM_NAME,&SRecDimID);
  97 + status = nc_inq_varid(SourceID, STARTTIME,&SStartID);
  98 + status = nc_inq_varid(SourceID, STOPTIME,&SStopID);
  99 + status = nc_inq_varid(SourceID, FILENAME,&SNameID);
  100 + status = nc_inq_dim(SourceID,SRecDimID,(char *)0, &SRecordNumber);
  101 +
  102 +/*--------------- Start Value ----------------------*/
  103 + strcpy(NamePrevious,DATAOK);
  104 +
  105 +/*============ Loop to read Source and to write destination =======*/
  106 + for(ics = 0; ics < SRecordNumber; ics++)
  107 + {
  108 + TimeStart[0] = ics;
  109 + status = nc_get_vara_text(SourceID,SStopID, TimeStart,TimeCount,Stop);
  110 + status = nc_get_vara_text(SourceID,SStartID,TimeStart,TimeCount,Start);
  111 + status = nc_get_vara_text(SourceID,SNameID, TimeStart,NameCount,Name);
  112 +
  113 + if((Start[0] != '0') && (Stop[0] != '0')) // Correct time
  114 + {
  115 +/*=================== Data exists==========================*/
  116 + if(strncmp(Name,NODATASTR,6) != 0) /* Real data file */
  117 + {
  118 + TimeStart[0] = DRecordNumber;
  119 +
  120 +/*=================Regular Case =======================*/
  121 + if(strncmp(NamePrevious,NODATASTR,6) != 0) /* The previous record was with real data */
  122 + {
  123 + status = nc_put_vara_text(DestID,DStartID,TimeStart,TimeCount,Start);
  124 + status = nc_put_vara_text(DestID,DStopID,TimeStart,TimeCount,Stop);
  125 + status = nc_put_vara_text(DestID,DNameID,TimeStart,NameCount,Name);
  126 + DRecordNumber++;
  127 + continue;
  128 + }
  129 + else /* The previous record has no real data */
  130 + {
  131 + status = nc_put_vara_text(DestID,DStartID,TimeStart,TimeCount,StartPrevious);
  132 + status = nc_put_vara_text(DestID,DStopID,TimeStart,TimeCount,StopPrevious);
  133 + status = nc_put_vara_text(DestID,DNameID,TimeStart,NameCount,NODATASTR);
  134 + TimeStart[0]++;
  135 + status = nc_put_vara_text(DestID,DStartID,TimeStart,TimeCount,Start);
  136 + status = nc_put_vara_text(DestID,DStopID,TimeStart,TimeCount,Stop);
  137 + status = nc_put_vara_text(DestID,DNameID,TimeStart,NameCount,Name);
  138 + DRecordNumber += 2;
  139 +
  140 + strcpy(NamePrevious,DATAOK);
  141 + continue;
  142 + }
  143 + } /* End if currend record has no data */
  144 +
  145 +/*============= NODATA First Occurrence: Prepare to Check Next Record ==============*/
  146 + if(strncmp(NamePrevious,NODATASTR,6) != 0) /* Current record has no data, but previous one was OK */
  147 + {
  148 + strncpy(NamePrevious,NODATASTR,6);
  149 + strcpy(StartPrevious,Start);
  150 + strcpy(StopPrevious,Stop);
  151 + continue;
  152 + }
  153 +/*=================== Merge NODATA records ========================*/
  154 + if((DD_Time2Double(Start)-DD_Time2Double(StopPrevious) < MINGAP)) /* No Data in previous record, No Data in the current one*/
  155 + {
  156 + strcpy(StopPrevious,Stop);
  157 + }
  158 +/*=================== No Merging Write PREVIOUS NODATA record ===================?=*/
  159 + else /* There is BIG gap between NODATA records */
  160 + {
  161 + TimeStart[0] = DRecordNumber;
  162 + status = nc_put_vara_text(DestID,DStartID,TimeStart,TimeCount,StartPrevious);
  163 + status = nc_put_vara_text(DestID,DStopID,TimeStart,TimeCount,StopPrevious);
  164 + status = nc_put_vara_text(DestID,DNameID,TimeStart,NameCount,NODATASTR);
  165 + DRecordNumber++;
  166 + strcpy(StartPrevious,Start);
  167 + strcpy(StopPrevious,Stop);
  168 + }
  169 + }
  170 + } /* FOR all recored */
  171 +
  172 + if(strncmp(Name,NODATASTR,6) == 0) /* The last record has no data */
  173 + {
  174 + TimeStart[0] = DRecordNumber;
  175 + status = nc_put_vara_text(DestID,DStartID,TimeStart,TimeCount,StartPrevious);
  176 + status = nc_put_vara_text(DestID,DStopID,TimeStart,TimeCount,StopPrevious);
  177 + status = nc_put_vara_text(DestID,DNameID,TimeStart,NameCount,NODATASTR);
  178 + }
  179 +
  180 + nc_close(SourceID);
  181 + nc_close(DestID);
  182 +
  183 +/*=============== rename of temporary file ===================*/
  184 + sprintf(command,"mv %s %s",TEMPNAME,argv[1]);
  185 + system(command);
  186 +}
  187 +/*=============== END OF PROGRAM =============================*/
  188 +
  189 +
  190 +
... ...
src/DATA/TOOLS/DDtimedump.c 0 → 100755
... ... @@ -0,0 +1,127 @@
  1 +/*----------------- REFRESH ------------------------------*/
  2 +/* v.2.0
  3 + * authors: Andrey O. Fedorov, V.Grushin
  4 + * Insitution:
  5 + * date : aug 28,1997
  6 + * sinopsis:
  7 + * aug 28, 2009 - New netCDF
  8 +
  9 + * usage DDtimedump nc_times_file
  10 + *
  11 + * Description:
  12 + * The program reads the output of the rehash program and reformats
  13 + * the data for more conveniet reading form:
  14 + *
  15 + *
  16 + * Dimensions:
  17 + *
  18 + * TimeLength 17
  19 + * NameLength
  20 + * Record Unlimited
  21 + * Variables:
  22 + *
  23 + * char StartTime[TIMELENGTH]
  24 + * char EndTime[TIMELENGTH]
  25 + *
  26 + * Attributes:
  27 + * none
  28 + */
  29 +
  30 +#include <stdio.h>
  31 +#include <stdlib.h>
  32 +#include <string.h>
  33 +#include <ctype.h>
  34 +#include <netcdf.h>
  35 +
  36 +/* Global Constant definitions */
  37 +
  38 +#define TIME_LENGTH_NAME "TimeLength"
  39 +#define TIME_LENGTH 17L
  40 +#define REC_DIM_NAME "record"
  41 +#define REC_DIM NC_UNLIMITED
  42 +#define NAME_DIM_NAME "NameLength"
  43 +#define NAME_DIM 32L
  44 +
  45 +#define SUM_DIM_NAME "SummaryLength"
  46 +#define SUM_DIM 68L
  47 +
  48 +#define STARTTIME "StartTime"
  49 +#define STOPTIME "StopTime"
  50 +#define FILENAME "FileName"
  51 +
  52 +#define SUMMARY "Summary"
  53 +
  54 +#define TIME_TYPE NC_CHAR
  55 +
  56 +/*--------------------- MAIN --------------------------------*/
  57 +
  58 +main(int argc, char **argv)
  59 +
  60 +{
  61 + static char description[] = "usage: DDtimedump nc_times_file ";
  62 +
  63 + char Start[TIME_LENGTH],
  64 + Stop [TIME_LENGTH],
  65 + Name [NAME_DIM],
  66 + Sum [SUM_DIM];
  67 +
  68 +/* NC definitions */
  69 + int tmID, sumID; /* nc file descriptor */
  70 + int TlDimID,RecDimID, NlDimID, SumDimID; /* ID of dimensions */
  71 +
  72 + size_t TimeStart[2] = {0L,0L};
  73 + size_t DataStart[1] = {0L};
  74 + size_t DataCount[1] = {TIME_LENGTH};
  75 + size_t TimeCount[2] = {1L,TIME_LENGTH};
  76 + size_t NameCount[2] = {1L, NAME_DIM};
  77 + size_t SumCount[2] = {1L, SUM_DIM};
  78 + int DimVector[2];
  79 + long RN = 0;
  80 +
  81 +/* Times files definitions */
  82 + int StartID, StopID,NameID;
  83 + int DataStartID, DataStopID;
  84 + int SumInfoID;
  85 + char tmName[NAME_DIM];
  86 + int i,okget,status;
  87 +
  88 + // ncopts = NC_VERBOSE;
  89 +/*-----------------------------------------------------------------*/
  90 +/*
  91 + * Check arguments
  92 + */
  93 + if(argc != 2) {fprintf(stderr,"argc=%d \n %s\n",
  94 + argc,description); exit(1); }
  95 +/*-----------------------------------------------------------------*/
  96 +/*
  97 + * Opening the rehash-created ncdf file
  98 + */
  99 +
  100 + status = nc_open(argv[1],NC_NOWRITE,&tmID);
  101 +
  102 + status = nc_inq_varid(tmID, STARTTIME, &StartID);
  103 + status = nc_inq_varid(tmID, STOPTIME, &StopID);
  104 + status = nc_inq_varid(tmID, FILENAME, &NameID);
  105 +
  106 + do
  107 + {
  108 +
  109 + status = nc_get_vara_text(tmID,StartID,TimeStart,TimeCount, Start);
  110 + status = nc_get_vara_text(tmID,StopID ,TimeStart,TimeCount, Stop );
  111 + status = nc_get_vara_text(tmID,NameID ,TimeStart,NameCount, Name );
  112 +
  113 + strcpy(Sum,Start);
  114 + strcat(Sum," ");
  115 + strcat(Sum,Stop);
  116 + strcat(Sum," ");
  117 + strcat(Sum,Name);
  118 + printf("%s \n",Sum);
  119 +
  120 +
  121 + TimeStart[0]++;
  122 + } while(status == NC_NOERR);
  123 +
  124 + nc_close(tmID);
  125 +
  126 + return(0);
  127 +}
... ...
src/DATA/STARTSTOPLOCAL/StartStopLocal.c renamed to src/DATA/TOOLS/StartStopLocal.c
src/DATA/TIMESUPDATE/TimesUpdate.c renamed to src/DATA/TOOLS/TimesUpdate.c
src/DATA/TIMESUPDATENODATA/TimesUpdateNoData.c renamed to src/DATA/TOOLS/TimesUpdateNoData.c
src/DATA/INFOLOCAL2NC/infoLocal2nc.c renamed to src/DATA/TOOLS/infoLocal2nc.c
src/DATA/JOIN_NC/join_nc.c renamed to src/DATA/TOOLS/join_nc.c
src/DATA/MAKEDDSYS/makeDDsys.c renamed to src/DATA/TOOLS/makeDDsys.c
src/DDADMIN/DDadmin.c 0 → 100755
... ... @@ -0,0 +1,758 @@
  1 +/*
  2 + *-------------------- DD_ADMIN -------------------------------
  3 + * V.1.1
  4 +*/
  5 +/* name: DDadmin.c
  6 + * author: Alexandr Grigoriev
  7 + * Insitution: IKI RAN lab.546 aug@afed.iki.rssi.ru
  8 + * date : March 1999
  9 + * sinopsis:
  10 + *
  11 + * usage:
  12 + *
  13 + * Description: Program is to adding users into DD access list.
  14 + * Nov 30 2009 - V.1.1 - netCDF-3
  15 + Nov 08 2011 -
  16 + */
  17 +
  18 +
  19 +#define _XOPEN_SOURCE
  20 +#include <stdio.h>
  21 +#include <stdlib.h>
  22 +#include <string.h>
  23 +#include <limits.h>
  24 +#include <unistd.h>
  25 +#include <time.h>
  26 +#include <DD.h>
  27 +#include <netcdf.h>
  28 +#include <DD_Access.h>
  29 +
  30 +#define FILE_PATH_LEN 1024
  31 +#define LOGIN_MIN_LEN 2
  32 +#define LOGIN_MAX_LEN 10
  33 +#define PWD_HASHED_LEN 13
  34 +#define PWD_MIN_LEN 5
  35 +#define PWD_MAX_LEN 80
  36 +#define PWD_GEN_SIZE 6
  37 +
  38 +#define NC_USER_NAME "user"
  39 +#define NC_USER_LEN_NAME "UserLength"
  40 +#define NC_PWD_LEN_NAME "PasswdLength"
  41 +#define NC_MEMBER_NAME "member"
  42 +#define NC_PWD_NAME "passwd"
  43 +
  44 +#define ERR_BAD_REQUEST 1
  45 +#define ERR_DDBASE_UNDEFINED 2
  46 +#define ERR_FILE_UNREACHABLE 3
  47 +#define ERR_FILE_BAD_INFO 4
  48 +#define ERR_MANUAL_ABORTED 5
  49 +#define ERR_REQUEST_FAILED 6
  50 +
  51 +typedef enum {OP_ADD_MANUAL,
  52 + OP_ADD_AUTO,
  53 + OP_MODIFY,
  54 + OP_DELETE,
  55 + OP_RESET,
  56 + OP_GET_SALT,
  57 + OP_GET_LIST
  58 + } t_Op;
  59 +
  60 +typedef struct {
  61 + t_Op op;
  62 + char login[LOGIN_MAX_LEN+1];
  63 + char pwd_hash[PWD_HASHED_LEN+1];
  64 + char pwd_hash_new[PWD_HASHED_LEN+1];
  65 +} t_Request;
  66 +
  67 +typedef struct {
  68 + int ncID;
  69 + int UserID;
  70 + int UserLenID;
  71 + int PwdLenID;
  72 + int MemberID;
  73 + int PwdID;
  74 + long MaxRecords;
  75 + long UserLen;
  76 + long PwdLen;
  77 +} t_UserFileInfo;
  78 +
  79 +//---------------------------------------------------------------------------
  80 +void Usage(void)
  81 +{
  82 + printf("DDadmin [-option] [login] [pwd_hash] [pwd_hash_new]\n");
  83 + printf(" * without arguments: add new user manually\n");
  84 + printf(" * -option :\n");
  85 + printf(" -a : add new user [login] with the hashed password [pwd_hash]\n");
  86 + printf(" -m : modify the password of user [login]. [pwd_hash] is checked, and replace by [pwd_hash_new]\n");
  87 + printf(" -r : reset the password of user [login]. A new one is generated\n");
  88 + printf(" -d : delete the user [login]\n");
  89 + printf(" -s : return salt used to crypt the password of user [login]\n");
  90 + printf(" -l : return a list of users\n");
  91 + printf(" -h : this help\n");
  92 +}
  93 +//---------------------------------------------------------------------------
  94 +unsigned char GetRandomChar(void)
  95 +{
  96 + return (unsigned char)(rand()%26+'a');
  97 +}
  98 +//--------------------------------------------------------------------------
  99 +int TestLogin(char *login)
  100 +{
  101 + int j = strlen(login);
  102 + if(j<LOGIN_MIN_LEN)
  103 + {
  104 + printf("login is too short.\n");
  105 + return 0;
  106 + }
  107 + if(j>LOGIN_MAX_LEN)
  108 + {
  109 + printf("login is too long.\n");
  110 + return 0;
  111 + }
  112 + return 1;
  113 +}
  114 +//-------------------------------------------------------------------------
  115 +int GetLogin(char *login)
  116 +{
  117 + printf("login:");
  118 +
  119 + char l = '\0';
  120 + int j = 0;
  121 +
  122 + while((l!='\n'))
  123 + {
  124 + l=getchar();
  125 + if(j < LOGIN_MAX_LEN)
  126 + login[j] = l;
  127 + j++;
  128 + }
  129 +
  130 + login[j-1] = '\0';
  131 +
  132 + if (!TestLogin(login))
  133 + return 0;
  134 +
  135 + return 1;
  136 +}
  137 +//--------------------------------------------------------------------
  138 +int TestPwd(char *pwd)
  139 +{
  140 + int j = strlen(pwd);
  141 + if(j < PWD_MIN_LEN)
  142 + {
  143 + printf("Password is too short.\n");
  144 + return 0;
  145 + }
  146 + if(j > PWD_MAX_LEN)
  147 + {
  148 + printf("Password is too long.\n");
  149 + return 0;
  150 + }
  151 + return 1;
  152 +}
  153 +//--------------------------------------------------------------------
  154 +int GetNewPwd(char *pwd)
  155 +{
  156 + char pas1[PWD_MAX_LEN+1];
  157 + char pas2[PWD_MAX_LEN+1];
  158 +
  159 + int isFinish = 0;
  160 + while (!isFinish)
  161 + {
  162 + strcpy(pas1,getpass("New password:"));
  163 + pas1[strlen(pas1)] = '\0';
  164 + isFinish = TestPwd(pas1);
  165 + }
  166 +
  167 + strcpy(pas2,getpass("Retype new password:"));
  168 + pas2[strlen(pas2)] = '\0';
  169 +
  170 + int ok = (strcmp(pas1,pas2) == 0);
  171 +
  172 + if (ok)
  173 + strcpy(pwd,pas1);
  174 +
  175 + memset(pas1,0,(PWD_MAX_LEN+1)*sizeof(char));
  176 + memset(pas2,0,(PWD_MAX_LEN+1)*sizeof(char));
  177 +
  178 + if (!ok)
  179 + {
  180 + printf("Error - Passwords mismatch\n");
  181 + return 0;
  182 + }
  183 +
  184 + return 1;
  185 +}
  186 +//--------------------------------------------------------------------
  187 +int GeneratePwd(char *pwd)
  188 +{
  189 + int i = 0;
  190 + for (i = 0; i < PWD_GEN_SIZE; i++)
  191 + pwd[i] = GetRandomChar();
  192 + return 1;
  193 +}
  194 +//--------------------------------------------------------------------
  195 +int GetRequest(int argc, char *argv[], t_Request *request)
  196 +{
  197 + memset(request,0,sizeof(t_Request));
  198 +
  199 + if (argc < 2)
  200 + {
  201 + request->op = OP_ADD_MANUAL;
  202 + return 1;
  203 + }
  204 +
  205 + if ((strlen(argv[1]) != 2) || (argv[1][0] != '-'))
  206 + {
  207 + printf("Error - Bad option\n");
  208 + Usage();
  209 + return 0;
  210 + }
  211 +
  212 + //option
  213 + switch (argv[1][1])
  214 + {
  215 + case 'a' :
  216 + request->op = OP_ADD_AUTO;
  217 + break;
  218 + case 'm' :
  219 + request->op = OP_MODIFY;
  220 + break;
  221 + case 'd' :
  222 + request->op = OP_DELETE;
  223 + break;
  224 + case 'r' :
  225 + request->op = OP_RESET;
  226 + break;
  227 + case 'h' :
  228 + Usage();
  229 + return 0;
  230 + case 's' :
  231 + request->op = OP_GET_SALT;
  232 + break;
  233 + case 'l' :
  234 + request->op = OP_GET_LIST;
  235 + return 1;
  236 + default :
  237 + printf("Error - Bad option\n");
  238 + Usage();
  239 + return 0;
  240 + }
  241 +
  242 + //login
  243 + if (argc < 3)
  244 + {
  245 + printf("Error - Cannot get login\n");
  246 + Usage();
  247 + return 0;
  248 + }
  249 +
  250 + if (!TestLogin(argv[2]))
  251 + {
  252 + Usage();
  253 + return 0;
  254 + }
  255 +
  256 + strcpy(request->login, argv[2]);
  257 +
  258 + if ((request->op == OP_ADD_AUTO) || (request->op == OP_MODIFY))
  259 + {
  260 + //password hash code
  261 + if (argc < 4)
  262 + {
  263 + printf("Error - Cannot get password hash code\n");
  264 + Usage();
  265 + return 0;
  266 + }
  267 + if (strlen(argv[3]) != PWD_HASHED_LEN)
  268 + {
  269 + printf("Error - Incorrect password hash code\n");
  270 + Usage();
  271 + return 0;
  272 + }
  273 + strcpy(request->pwd_hash, argv[3]);
  274 +
  275 + if (request->op == OP_MODIFY)
  276 + {
  277 + //new password hash code
  278 + if (argc < 5)
  279 + {
  280 + printf("Error - Cannot get new password hash code\n");
  281 + Usage();
  282 + return 0;
  283 + }
  284 + if (strlen(argv[4]) != PWD_HASHED_LEN)
  285 + {
  286 + printf("Error - Incorrect new password hash code\n");
  287 + Usage();
  288 + return 0;
  289 + }
  290 + strcpy(request->pwd_hash_new, argv[4]);
  291 + }
  292 + }
  293 +
  294 + return 1;
  295 +}
  296 +//--------------------------------------------------------------------------
  297 +int GetUserFilePath(char *path)
  298 +{
  299 + path[0]='\0';
  300 + char *ddbase;
  301 + if((ddbase = getenv("DDBASE")) == NULL)
  302 + {
  303 + printf("No DDBASE info \n");
  304 + return 0;
  305 + }
  306 + strcpy(path,ddbase);
  307 + strcat(path,USERREFNAME);
  308 + return 1;
  309 +}
  310 +//--------------------------------------------------------------------------
  311 +int OpenUserFile(char *path, t_UserFileInfo *fileInfo)
  312 +{
  313 + int status;
  314 + if((status = nc_open(path, NC_WRITE, &fileInfo->ncID)) != NC_NOERR)
  315 + {
  316 + printf("Error in opening file = %u\n", fileInfo->ncID);
  317 + return 0;
  318 + }
  319 + return 1;
  320 +}
  321 +//--------------------------------------------------------------------------
  322 +int CloseUserFile(t_UserFileInfo *fileInfo)
  323 +{
  324 + nc_close(fileInfo->ncID);
  325 + memset(fileInfo,0,sizeof(t_UserFileInfo));
  326 + return 1;
  327 +}
  328 +//---------------------------------------------------------------------------
  329 +int GetFileInfo(t_UserFileInfo *fileInfo)
  330 +{
  331 + int status;
  332 +
  333 + if (((status = nc_inq_unlimdim(fileInfo->ncID, (size_t *)&fileInfo->UserID)) != NC_NOERR) ||
  334 + ((status = nc_inq_dimlen(fileInfo->ncID, fileInfo->UserID, (size_t *)&fileInfo->MaxRecords)) != NC_NOERR) ||
  335 + ((status = nc_inq_dimid(fileInfo->ncID, NC_USER_LEN_NAME, &fileInfo->UserLenID)) != NC_NOERR) ||
  336 + ((status = nc_inq_dimid(fileInfo->ncID, NC_PWD_LEN_NAME, &fileInfo->PwdLenID)) != NC_NOERR) ||
  337 + ((status = nc_inq_dimlen(fileInfo->ncID, fileInfo->UserLenID, (size_t *)&fileInfo->UserLen)) != NC_NOERR) ||
  338 + ((status = nc_inq_dimlen(fileInfo->ncID, fileInfo->PwdLenID, (size_t *)&fileInfo->PwdLen)) != NC_NOERR) ||
  339 + ((status = nc_inq_varid(fileInfo->ncID, NC_MEMBER_NAME, &fileInfo->MemberID)) != NC_NOERR) ||
  340 + ((status = nc_inq_varid(fileInfo->ncID, NC_PWD_NAME, &fileInfo->PwdID)) != NC_NOERR))
  341 + {
  342 + printf("Error - Cannot get file information\n");
  343 + return 0;
  344 + }
  345 +
  346 + fileInfo->UserLen = LOGIN_MAX_LEN;
  347 + fileInfo->PwdLen = PWD_HASHED_LEN;
  348 +
  349 + return 1;
  350 +}
  351 +//--------------------------------------------------------------------------
  352 +int CreateUserFile(char *filePath, t_UserFileInfo *fileInfo)
  353 +{
  354 + int status;
  355 + fileInfo->UserLen = LOGIN_MAX_LEN;
  356 + fileInfo->PwdLen = PWD_HASHED_LEN;
  357 +
  358 + if (((status = nc_create (filePath,NC_SHARE,&fileInfo->ncID)) != NC_NOERR) ||
  359 + ((status = nc_def_dim (fileInfo->ncID, NC_USER_NAME, NC_UNLIMITED, &fileInfo->UserID)) != NC_NOERR) ||
  360 + ((status = nc_def_dim (fileInfo->ncID, NC_USER_LEN_NAME, fileInfo->UserLen+1, &fileInfo->UserLenID)) != NC_NOERR) ||
  361 + ((status = nc_def_dim (fileInfo->ncID, NC_PWD_LEN_NAME, fileInfo->PwdLen+1, &fileInfo->PwdLenID)) != NC_NOERR))
  362 + {
  363 + printf("Error - Cannot create users file\n");
  364 + return 0;
  365 + }
  366 +
  367 + int MemberDimVector[2] = {fileInfo->UserID,fileInfo->UserLenID};
  368 + int PwdDimVector[2] = {fileInfo->UserID,fileInfo->PwdLenID};
  369 + if (((status = nc_def_var (fileInfo->ncID, NC_MEMBER_NAME,NC_CHAR,2, MemberDimVector,&fileInfo->MemberID)) != NC_NOERR) ||
  370 + ((status = nc_def_var (fileInfo->ncID, NC_PWD_NAME, NC_CHAR, 2, PwdDimVector, &fileInfo->PwdID)) != NC_NOERR))
  371 + {
  372 + printf("Error - Cannot create users file\n");
  373 + return 0;
  374 + }
  375 +
  376 + nc_enddef(fileInfo->ncID);
  377 +
  378 + return 1;
  379 +}
  380 +//--------------------------------------------------------------------------
  381 +int CleanUserFile(void)
  382 +{
  383 + t_UserFileInfo fileInfo, tmpFileInfo;
  384 + memset(&fileInfo,0,sizeof(t_UserFileInfo));
  385 + memset(&tmpFileInfo,0,sizeof(t_UserFileInfo));
  386 +
  387 + char refname[FILE_PATH_LEN], tmpname[FILE_PATH_LEN];
  388 + if (!GetUserFilePath(refname))
  389 + return 0;
  390 + strcpy(tmpname,refname);
  391 + strcat(tmpname,".tmp");
  392 +
  393 + if (!OpenUserFile(refname,&fileInfo))
  394 + return 0;
  395 +
  396 + if (!GetFileInfo(&fileInfo))
  397 + return 0;
  398 +
  399 + if (!CreateUserFile(tmpname,&tmpFileInfo))
  400 + return 0;
  401 +
  402 + int i;
  403 + int c = 0;
  404 + char crtLogin[LOGIN_MAX_LEN+1];
  405 + char crtPwd[PWD_MAX_LEN+1];
  406 + for(i = 0; i < fileInfo.MaxRecords; i++)
  407 + {
  408 + if (!GetLoginFromIndex(i,&fileInfo,crtLogin) || !GetPwdFromIndex(i,&fileInfo,crtPwd))
  409 + continue;
  410 +
  411 + //clean login string
  412 + memset(crtLogin+strlen(crtLogin),0,(LOGIN_MAX_LEN+1-strlen(crtLogin))*sizeof(char));
  413 +
  414 + if ((strcmp(crtLogin,"") == 0) || (strcmp(crtPwd,"") == 0))
  415 + continue;
  416 +
  417 + if (!SetLoginToIndex(c, &tmpFileInfo, crtLogin))
  418 + {
  419 + printf("Error - Cannot add a login on the temporary file\n");
  420 + return 0;
  421 + }
  422 +
  423 + if (!SetPwdToIndex(c, &tmpFileInfo, crtPwd))
  424 + {
  425 + printf("Error - Cannot add a password on the temporary file\n");
  426 + return 0;
  427 + }
  428 +
  429 + c++;
  430 + }
  431 +
  432 + CloseUserFile(&fileInfo);
  433 + CloseUserFile(&tmpFileInfo);
  434 +
  435 + char cmd[2048];
  436 + sprintf(cmd,"cp %s %s",tmpname,refname);
  437 + system(cmd);
  438 + sprintf(cmd,"rm %s",tmpname);
  439 + system(cmd);
  440 +
  441 + return 1;
  442 +}
  443 +//---------------------------------------------------------------------------
  444 +int CreateSaveUserFile(void)
  445 +{
  446 + char refname[FILE_PATH_LEN];
  447 + char savename[FILE_PATH_LEN];
  448 +
  449 + if (!GetUserFilePath(refname))
  450 + return 0;
  451 + strcpy(savename,refname);
  452 + strcat(savename,"~");
  453 +
  454 + char cmd[2048];
  455 + sprintf(cmd,"cp %s %s",refname,savename);
  456 + system(cmd);
  457 +
  458 + return 1;
  459 +}
  460 +//---------------------------------------------------------------------------
  461 +int GetPwdFromIndex(int index, t_UserFileInfo *fileInfo, char *pwd_hash)
  462 +{
  463 + long start[2] = {0L,0L}, count[2]={1L,1L};
  464 + start[0] = index;
  465 + count[1] = fileInfo->PwdLen;
  466 + return (nc_get_vara_text(fileInfo->ncID,fileInfo->PwdID,(size_t *)start,(size_t *)count, pwd_hash) == NC_NOERR);
  467 +}
  468 +//---------------------------------------------------------------------------
  469 +int GetLoginFromIndex(int index, t_UserFileInfo *fileInfo, char *login)
  470 +{
  471 + long start[2] = {0L,0L}, count[2]={1L,1L};
  472 + start[0] = index;
  473 + count[1] = fileInfo->UserLen;
  474 + return (nc_get_vara_text(fileInfo->ncID,fileInfo->MemberID,(size_t *)start,(size_t *)count, login) == NC_NOERR);
  475 +}
  476 +//--------------------------------------------------------------------------
  477 +int SetPwdToIndex(int index, t_UserFileInfo *fileInfo, char *pwd_hash)
  478 +{
  479 + long start[2] = {0L,0L}, count[2]={1L,1L};
  480 + start[0] = index;
  481 + count[1] = fileInfo->PwdLen;
  482 + return (nc_put_vara_text(fileInfo->ncID,fileInfo->PwdID,(size_t *)start,(size_t *)count, pwd_hash) == NC_NOERR);
  483 +}
  484 +//---------------------------------------------------------------------------
  485 +int SetLoginToIndex(int index, t_UserFileInfo *fileInfo, char *login)
  486 +{
  487 + long start[2] = {0L,0L}, count[2]={1L,1L};
  488 + start[0] = index;
  489 + count[1] = fileInfo->UserLen;
  490 + return (nc_put_vara_text(fileInfo->ncID,fileInfo->MemberID,(size_t *)start,(size_t *)count, login) == NC_NOERR);
  491 +}
  492 +//---------------------------------------------------------------------------
  493 +int SearchLoginIndex(char *login, t_UserFileInfo *fileInfo)
  494 +{
  495 + char crtLogin[LOGIN_MAX_LEN+1];
  496 + int i;
  497 +
  498 + for(i = 0; i < fileInfo->MaxRecords; i++)
  499 + {
  500 + if (!GetLoginFromIndex(i,fileInfo,crtLogin))
  501 + continue;
  502 + crtLogin[fileInfo->UserLen] = '\0';
  503 +
  504 + if(strcmp(crtLogin,login) == 0)
  505 + return i;
  506 + }
  507 +
  508 + return -1;
  509 +}
  510 +
  511 +//--------------------------------------------------------------------------
  512 +int AddUser(t_Request request, t_UserFileInfo *fileInfo)
  513 +{
  514 + if (!SetLoginToIndex(fileInfo->MaxRecords,fileInfo,request.login))
  515 + {
  516 + printf("Error to add new login user");
  517 + return 0;
  518 + }
  519 +
  520 + if (!SetPwdToIndex(fileInfo->MaxRecords,fileInfo,request.pwd_hash))
  521 + {
  522 + printf("Error to add new login user");
  523 + return 0;
  524 + }
  525 +
  526 + return 1;
  527 +}
  528 +//-------------------------------------------------------------------------
  529 +int ModifyUser(t_Request request, t_UserFileInfo *fileInfo, int check)
  530 +{
  531 + int index = SearchLoginIndex(request.login, fileInfo);
  532 +
  533 + if (index < 0)
  534 + {
  535 + printf("User %s not found\n",request.login);
  536 + return 0;
  537 + }
  538 +
  539 + if (check)
  540 + {
  541 + char pwd_hash[PWD_HASHED_LEN+1];
  542 + if (!GetPwdFromIndex(index,fileInfo,pwd_hash))
  543 + {
  544 + printf("Error to get user password\n");
  545 + return 0;
  546 + }
  547 + if (strcmp(pwd_hash,request.pwd_hash) != 0)
  548 + {
  549 + printf("Bad password\n");
  550 + return 0;
  551 + }
  552 + }
  553 +
  554 + if (!SetPwdToIndex(index,fileInfo,request.pwd_hash_new))
  555 + {
  556 + printf("Error to set new user password\n");
  557 + return 0;
  558 + }
  559 +
  560 + return 1;
  561 +}
  562 +//--------------------------------------------------------------------------
  563 +int DeleteUser(t_Request request, t_UserFileInfo *fileInfo)
  564 +{
  565 + int index = SearchLoginIndex(request.login, fileInfo);
  566 +
  567 + if (index < 0)
  568 + {
  569 + printf("User %s not found\n",request.login);
  570 + return 0;
  571 + }
  572 +
  573 + char login[LOGIN_MAX_LEN+1];
  574 + memset(login,0,(LOGIN_MAX_LEN+1)*sizeof(char));
  575 +
  576 + if (!SetLoginToIndex(index,fileInfo,login))
  577 + {
  578 + printf("Error to delete user password\n");
  579 + return 0;
  580 + }
  581 +
  582 + char pwd_hash[PWD_HASHED_LEN+1];
  583 + memset(pwd_hash,0,(PWD_HASHED_LEN+1)*sizeof(char));
  584 +
  585 + if (!SetPwdToIndex(index,fileInfo,pwd_hash))
  586 + {
  587 + printf("Error to delete user password\n");
  588 + return 0;
  589 + }
  590 +
  591 + return 1;
  592 +}
  593 +//--------------------------------------------------------------------------
  594 +int ResetUser(t_Request request, t_UserFileInfo *fileInfo)
  595 +{
  596 + char salt[2];
  597 + salt[0] = GetRandomChar();
  598 +
  599 + char pwd[PWD_GEN_SIZE+1];
  600 + memset(pwd,0,(PWD_GEN_SIZE+1)*sizeof(char));
  601 + GeneratePwd(pwd);
  602 +
  603 + printf("%s\n",pwd);
  604 +
  605 + salt[1] = GetRandomChar();
  606 +
  607 + //hash pwd
  608 + strcpy(request.pwd_hash_new,crypt(pwd,salt));
  609 + memset(pwd,0,(PWD_GEN_SIZE+1)*sizeof(char));
  610 +
  611 + return ModifyUser(request, fileInfo, 0);
  612 +}
  613 +//--------------------------------------------------------------------------
  614 +int GetSalt(t_Request request, t_UserFileInfo *fileInfo)
  615 +{
  616 + int index = SearchLoginIndex(request.login, fileInfo);
  617 +
  618 + if (index < 0)
  619 + {
  620 + printf("User %s not found\n",request.login);
  621 + return 0;
  622 + }
  623 +
  624 + char pwd_hash[PWD_HASHED_LEN+1];
  625 + if (!GetPwdFromIndex(index,fileInfo,pwd_hash))
  626 + {
  627 + printf("Error to get user password\n");
  628 + return 0;
  629 + }
  630 +
  631 + char salt[3];
  632 + strncpy(salt,pwd_hash,2);
  633 + salt[2] = '\0';
  634 + printf("%s\n",salt);
  635 +
  636 + return 1;
  637 +}
  638 +//---------------------------------------------------------------------------
  639 +int GetUsersList(t_Request request, t_UserFileInfo *fileInfo)
  640 +{
  641 + char crtLogin[LOGIN_MAX_LEN+1];
  642 + int i;
  643 +
  644 + int addComa = 0;
  645 +
  646 + for(i = 0; i < fileInfo->MaxRecords; i++)
  647 + {
  648 + if (!GetLoginFromIndex(i,fileInfo,crtLogin))
  649 + continue;
  650 + if (addComa)
  651 + printf(",");
  652 + printf("%s",crtLogin);
  653 + addComa = 1;
  654 + }
  655 +
  656 + printf("\n");
  657 +
  658 + return 1;
  659 +
  660 +}
  661 +//---------------------------------------------------------------------------
  662 +int CompleteRequest(t_Request *request, t_UserFileInfo *fileInfo)
  663 +{
  664 + char salt[2];
  665 + salt[0] = GetRandomChar();
  666 +
  667 + //get login
  668 + int isFinish = 0;
  669 + while (!isFinish)
  670 + {
  671 + GetLogin(request->login);
  672 + if (SearchLoginIndex(request->login, fileInfo) > -1)
  673 + printf("User login not available. Change your login please.\n");
  674 + else
  675 + isFinish = 1;
  676 + }
  677 +
  678 + //get password
  679 + char pwd[PWD_MAX_LEN+1];
  680 + if (!GetNewPwd(pwd))
  681 + return 0;
  682 +
  683 + salt[1] = GetRandomChar();
  684 +
  685 + //hash pwd
  686 + strcpy(request->pwd_hash,crypt(pwd,salt));
  687 + memset(pwd,0,(PWD_MAX_LEN+1)*sizeof(char));
  688 +
  689 + return 1;
  690 +}
  691 +//---------------------------------------------------------------------------
  692 +main (int argc, char *argv[])
  693 +{
  694 + srand(time(NULL));
  695 +
  696 + t_Request request;
  697 + if (!GetRequest(argc, argv, &request))
  698 + exit(ERR_BAD_REQUEST);
  699 +
  700 + char refname[FILE_PATH_LEN];
  701 + if (!GetUserFilePath(refname))
  702 + exit(ERR_DDBASE_UNDEFINED);
  703 +
  704 + t_UserFileInfo fileInfo;
  705 + memset(&fileInfo,0,sizeof(t_UserFileInfo));
  706 +
  707 + if (!OpenUserFile(refname,&fileInfo))
  708 + exit(ERR_FILE_UNREACHABLE);
  709 +
  710 +
  711 + if (!GetFileInfo(&fileInfo))
  712 + exit(ERR_FILE_BAD_INFO);
  713 +
  714 + if (request.op == OP_ADD_MANUAL)
  715 + if (!CompleteRequest(&request,&fileInfo))
  716 + {
  717 + CloseUserFile(&fileInfo);
  718 + exit(ERR_MANUAL_ABORTED);
  719 + }
  720 +
  721 + int res = 0;
  722 + if ((request.op != OP_GET_SALT) && (request.op != OP_GET_LIST))
  723 + CreateSaveUserFile();
  724 + switch (request.op)
  725 + {
  726 + case OP_ADD_MANUAL :
  727 + case OP_ADD_AUTO :
  728 + res = AddUser(request,&fileInfo);
  729 + break;
  730 + case OP_MODIFY :
  731 + res = ModifyUser(request,&fileInfo,1);
  732 + break;
  733 + case OP_DELETE :
  734 + res = DeleteUser(request,&fileInfo);
  735 + break;
  736 + case OP_RESET :
  737 + res = ResetUser(request,&fileInfo);
  738 + break;
  739 + case OP_GET_SALT :
  740 + res = GetSalt(request,&fileInfo);
  741 + break;
  742 + case OP_GET_LIST :
  743 + res = GetUsersList(request,&fileInfo);
  744 + break;
  745 + }
  746 +
  747 + CloseUserFile(&fileInfo);
  748 +
  749 + if (res && (request.op == OP_DELETE))
  750 + CleanUserFile();
  751 +
  752 + memset(&request,0,sizeof(t_Request));
  753 +
  754 + if (!res)
  755 + exit(ERR_REQUEST_FAILED);
  756 +
  757 + return 0;
  758 +}
... ...
src/DDSERVICES/REST/generateGranulesIndex.php 0 → 100644
... ... @@ -0,0 +1,38 @@
  1 +<?php
  2 +/**
  3 +* @file generateGranulesIndex.php
  4 +* @brief
  5 +* @version $Id: $
  6 +*/
  7 +
  8 + require_once 'DDService/DDserverWeb_ini.php';
  9 +
  10 + if (!getenv('DDBASE'))
  11 + define('DDBASE', '/data/DDBASE/DATA');
  12 + else
  13 + define('DDBASE', getenv('DDBASE'));
  14 +
  15 + $ddSys = new DOMDocument('1.0');
  16 + $ddSys->load(DDBASE.'/DDsys.xml');
  17 + $dataSets = $ddSys->getElementsByTagName('VI');
  18 +
  19 + foreach ($dataSets as $VI)
  20 + {
  21 + $id = $VI->getElementsByTagName('NAME')->item(0)->nodeValue;
  22 + $main = array();
  23 + $index = array();
  24 + $location = $VI->getElementsByTagName("LOCATION")->item(0)->nodeValue;
  25 +
  26 + foreach (glob($location."*.nc.gz") as $granule)
  27 + {
  28 + $cmd = 'stat --printf="%s" '. $granule;
  29 + $file = basename($granule,".nc.gz");
  30 + $index[$file] = exec($cmd);
  31 + }
  32 +
  33 + $main[substr($location,strlen(DDBASE))] = $index;
  34 + file_put_contents("GRANULES/$id.json", json_encode($main));
  35 +
  36 + }
  37 +
  38 +?>
... ...
src/DDSERVICES/REST/getGranulesIndex.php 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +<?php
  2 +
  3 +/**
  4 +* @file getGranulesIndex.php
  5 +* @brief Returns JSON with URLs of *_times.nc for all DataSets
  6 +* @version $Id: $
  7 +*/
  8 +
  9 + require_once './DDserverWeb_ini.php';
  10 +
  11 + $alias = array(baseDir => webAlias);
  12 + $replace = array("_" => "-");
  13 +
  14 + // $dataSet = strtr($_GET['id'], $replace);
  15 +
  16 + $referXML = baseDir."DDsys.xml";
  17 + $DDsys = new DOMDocument("1.0");
  18 + $DDsys->load($referXML);
  19 +
  20 + $VIs = $DDsys->getElementsByTagName("VI");
  21 + $main = array();
  22 + $index = array();
  23 + foreach ( $VIs as $VI )
  24 + {
  25 + if ($VI->getElementsByTagName("NAME")->item(0)->getAttribute('base') == "LOCAL")
  26 + {
  27 + $id = $VI->getElementsByTagName("NAME")->item(0)->nodeValue;
  28 + $location = $VI->getElementsByTagName("LOCATION")->item(0)->nodeValue;
  29 + $times = $VI->getElementsByTagName("TIMES")->item(0)->nodeValue;
  30 + if (!file_exists($location.$times)) continue;
  31 +
  32 + $index[strtr($id,$replace)] = substr($location.$times,strlen(baseDir));
  33 + }
  34 + }
  35 +
  36 + $main[webAlias] = $index;
  37 + $json = json_encode($main);
  38 +
  39 + file_put_contents("../GRANULES/allDatasets.json", $json);
  40 + exit($json);
  41 +?>
  42 +
  43 +
... ...
src/DDSERVICES/REST/getGranulesSize.php 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +<?php
  2 +/**
  3 +* @file getGranulesSize.php
  4 +* @brief
  5 +* @version $Id: $
  6 +*/
  7 +
  8 + if (!$_GET['id']) exit('INPUT ERROR');
  9 + require_once './DDserverWeb_ini.php';
  10 +
  11 + $alias = array(baseDir => webAlias);
  12 + $replace = array("-" => "_");
  13 +
  14 + $dataSet = strtr($_GET['id'], $replace);
  15 +
  16 + if (file_exists("../GRANULES/$dataSet.json")) {
  17 + echo file_get_contents("../GRANULES/$dataSet.json");
  18 + exit();
  19 + }
  20 + $ddSys = new DOMDocument('1.0');
  21 + $ddSys->load(baseDir."DDsys.xml");
  22 + $xp = new DOMXpath($ddSys);
  23 +
  24 + $VI = $xp->query("//NAME[.='".$dataSet."']");
  25 + if ( $VI->item(0)->nodeValue == NULL ) exit('NO SUCH DATASET');
  26 +
  27 + $main = array();
  28 + $index = array();
  29 +
  30 + $location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue;
  31 + foreach (glob($location."*.nc.gz") as $granule) {
  32 + $cmd = 'stat --printf="%s" '. $granule;
  33 + $file = basename($granule,".nc.gz");
  34 + $index[$file] = exec($cmd);
  35 + }
  36 + $main[substr($location,strlen(baseDir))] = $index;
  37 +
  38 + $json = json_encode($main);
  39 + file_put_contents("../GRANULES/$dataSet.json", $json);
  40 + exit($json);
  41 +?>
... ...
src/DDSERVICES/REST/get_cdf.php 0 → 100755
... ... @@ -0,0 +1,70 @@
  1 +<?php
  2 +
  3 +/**
  4 +* Look for a NetCDF file in the local base dir, then convert it using the NetCDF to CDF Python converter.
  5 +*/
  6 +
  7 +$converterPath = './nc2cdf.py';
  8 +$tmpDir = '/tmp/';
  9 +$log_path = $tmpDir . 'get_cdf.log';
  10 +
  11 +if (!$_GET['id']) {
  12 + exit('INPUT ERROR');
  13 +}
  14 +
  15 +require_once './DDserverWeb_ini.php';
  16 +
  17 +$name = preg_replace('/\..*/', '', $_GET['id']); // ie. ACE/SW/sw19980204
  18 +$inputFilePath = baseDir . $name . '.nc.gz'; // ie. /data/DDBASE/DATA/ACE/SW/sw19980204.nc.gz
  19 +$outputFilePath = $tmpDir . str_replace('/', '_', $name) . '.cdf'; // ie. /tmp/ACE_SW_sw19980204.cdf
  20 +
  21 +function send_file($mime_type, $send_file_path) {
  22 + header('Content-Description: File Transfer');
  23 + header('Content-Type: ' . $mime_type);
  24 + header('Content-Disposition: attachment; filename="' . basename($send_file_path) . '"');
  25 + header('Expires: 0');
  26 + header('Cache-Control: must-revalidate');
  27 + header('Pragma: public');
  28 + header('Content-Length: ' . filesize($send_file_path));
  29 + readfile($send_file_path);
  30 +}
  31 +
  32 +function error($log_msg) {
  33 + global $inputFilePath, $log_path;
  34 + file_put_contents($log_path, date("Y-m-d H:i:s") . " with id='" . $_GET['id'] . "': $log_msg\n", FILE_APPEND);
  35 + // If the file can not be converted, return the NetCDF file.
  36 + send_file('application/x-gzip', basename($inputFilePath));
  37 + exit;
  38 +}
  39 +
  40 +if (!file_exists($inputFilePath)) {
  41 + exit('NO SUCH FILE');
  42 +}
  43 +
  44 +if (!is_dir(pathinfo($outputFilePath, PATHINFO_DIRNAME))) {
  45 + error("Can not create $outputFilePath because the folder does not exist.");
  46 +}
  47 +
  48 +try {
  49 + $res = shell_exec("$converterPath $inputFilePath $outputFilePath");
  50 +} catch (Exception $e) {
  51 + error("Error on shell_exec():\n$e");
  52 +}
  53 +
  54 +
  55 +// The converter is not supposed to output something if the file has been successfully converted
  56 +if(trim($res) != '') {
  57 + error("The converter said:\n$res");
  58 +}
  59 +
  60 +if(! file_exists($outputFilePath)) {
  61 + error("The output file $outputFilePath has not been created.");
  62 +}
  63 +
  64 +send_file('application/x-cdf', $outputFilePath);
  65 +
  66 +sleep(600); // Wait 10 minutes before to delete the converted file.
  67 +unlink($outputFilePath);
  68 +
  69 +exit;
  70 +?>
... ...
src/DDSERVICES/REST/get_services.php 0 → 100755
... ... @@ -0,0 +1,47 @@
  1 +<?php
  2 +include(realpath(dirname(__FILE__) . "/../php/config.php"));
  3 +include(BASE_PATH . "/php/classes/EpnTapMgr.php");
  4 +
  5 +$EpnTapMgr = new EpnTapMgr;
  6 +$services = json_decode(file_get_contents(EpnTapDataPath . "/EpnTapServices.json"), TRUE);
  7 +
  8 +$services_content = Array();
  9 +
  10 +foreach($services as $s) {
  11 + //// -- To display columns names for each service --
  12 + // $query = "SELECT TOP 1 * FROM " . $s["schema"] . ".epn_core";
  13 + // $rows = $EpnTapMgr->request($s["accessurl"], $query);
  14 + // echo $s["schema"] . "\n\"columns\": \"" . join(',', array_keys($rows[0])) . "\"\n\n";
  15 +
  16 + $query = "SELECT dataproduct_type as dp_type,
  17 + target_class as t_class,
  18 + target_name as t_name,
  19 + COUNT(granule_uid) as nb_res,
  20 + MIN(time_min) as time_min,
  21 + MAX(time_max) as time_max
  22 + FROM " . $s["schema"] . ".epn_core GROUP BY dp_type, t_class, t_name";
  23 +
  24 + $rows = $EpnTapMgr->request($s["accessurl"], $query);
  25 + if($rows == NULL)
  26 + continue;
  27 +
  28 + foreach ($rows as $r) {
  29 + $r['dp_type'] = $r['dp_type'];
  30 + $r['t_class'] = $r['t_class'];
  31 + $r['t_name'] = $r['t_name'];
  32 +
  33 + if(!isset($services_content[$r['dp_type']]))
  34 + $services_content[$r['dp_type']] = Array();
  35 +
  36 + if(!isset($services_content[$r['dp_type']][$r['t_class']]))
  37 + $services_content[$r['dp_type']][$r['t_class']] = Array();
  38 +
  39 + if(!isset($services_content[$r['dp_type']][$r['t_class']][$r['t_name']]))
  40 + $services_content[$r['dp_type']][$r['t_class']][$r['t_name']] = Array();
  41 +
  42 + $services_content[$r['dp_type']][$r['t_class']][$r['t_name']][$s["schema"]] = [$r['nb_res'], $r['time_min'], $r['time_max']];
  43 + }
  44 +}
  45 +
  46 +fwrite(fopen(EpnTapDataPath . "metadata.json", "w+"), json_encode($services_content));
  47 +?>
... ...
src/DDSERVICES/REST/nc2cdf.py 0 → 100755
... ... @@ -0,0 +1,210 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*
  3 +
  4 +# Resources:
  5 +# - http://pythonhosted.org/SpacePy/pycdf.html
  6 +# - http://unidata.github.io/netcdf4-python/
  7 +
  8 +import os
  9 +import os.path as op
  10 +from datetime import datetime
  11 +
  12 +os.environ['SPACEPY'] = '/tmp'
  13 +
  14 +import netCDF4
  15 +from spacepy import pycdf
  16 +
  17 +AMDA_DICT_PATH = './amda.json'
  18 +TEMP_FILE = '/tmp'
  19 +
  20 +
  21 +def error(error_message, e=None):
  22 + """ Display an `error_message` and exit the program. """
  23 +
  24 + import sys
  25 +
  26 + with open(op.join(TEMP_FILE, 'converter.log'), 'a') as f_log:
  27 + f_log.write('With arguments ' + ', '.join(sys.argv))
  28 + f_log.write(error_message)
  29 +
  30 + sys.stderr.write(error_message + ((':\n %s\n' % e) if e else '\n'))
  31 + sys.exit(1)
  32 +
  33 +
  34 +class NetCdf:
  35 + SPASE_DATE_FORMAT = '%Y%j%H%M%S' # ex: 2016238000000
  36 +
  37 + def __init__(self, input_path):
  38 + """Constructor. Load a NetCDF file from `self.netcdf_path`, return a NetCDF4 object."""
  39 +
  40 + self.cdf_path = None
  41 + self.cdf = None
  42 + self.temp_nc = None
  43 +
  44 + extension = input_path.split('/')[-1].split('.', 1)[1]
  45 + if extension == 'nc.gz':
  46 + self.unzip(input_path)
  47 + elif extension == 'nc':
  48 + self.netcdf_path = input_path
  49 + else:
  50 + error('Unknown file extension "%s".' % extension)
  51 +
  52 + try:
  53 + self.netcdf = netCDF4.Dataset(self.netcdf_path)
  54 + except Exception as e:
  55 + error('Can not open netCDF file %s' % self.netcdf_path, e)
  56 +
  57 + if self.temp_nc:
  58 + os.remove(self.temp_nc)
  59 +
  60 + def unzip(self, ncgz_input_path):
  61 + import gzip
  62 + from shutil import copyfileobj
  63 +
  64 + netcdf_temp_path = self.build_temp_path(ncgz_input_path, '.nc')
  65 +
  66 + if not op.exists(ncgz_input_path):
  67 + error('Compressed Net-CDF file is not found in "%s".' % ncgz_input_path)
  68 +
  69 + try:
  70 + with gzip.open(ncgz_input_path, 'rb') as f_in, open(netcdf_temp_path, 'wb') as f_out:
  71 + copyfileobj(f_in, f_out)
  72 + except Exception as e:
  73 + error('Can not unzip compressed Net-CDF from %s to %s' % (ncgz_input_path, netcdf_temp_path), e)
  74 +
  75 + self.temp_nc = netcdf_temp_path
  76 + self.netcdf_path = netcdf_temp_path
  77 +
  78 + def parse_date(self, str_date):
  79 + """ Parse the string `str_date` and return the date."""
  80 +
  81 + return datetime.strptime(str_date[:4] + str(int(str_date[4:7]) + 1) + str_date[7:13], self.SPASE_DATE_FORMAT)
  82 +
  83 + # NetCDF methods
  84 +
  85 + def get_netcdf_path(self):
  86 + """Return the NetCDF path."""
  87 +
  88 + return self.netcdf_path
  89 +
  90 + def get_netcdf(self):
  91 + """Return the NetCDF object."""
  92 +
  93 + return self.netcdf
  94 +
  95 + def describe(self):
  96 + """Display all NetCDF variables of the NetCF file"""
  97 +
  98 + def describe_var(var):
  99 + """Describe an net-cdf variable."""
  100 +
  101 + print('== %s ==' % var.name)
  102 + print(' - numpy type: %s ^ %s ' % (str(var.dtype), str(var.ndim)))
  103 + print(' - dimension(s): %s' % ', '.join(list(var.dimensions)))
  104 + print(' - size: %s = %d' % ('x'.join([str(n) for n in var.shape]), var.size))
  105 + if var.ndim == 1 and str(var.dtype) == '|S1':
  106 + print(' - values: \'%s\', ...' % ''.join([c.decode('utf-8') for c in var[:]]))
  107 +
  108 + if var.ncattrs():
  109 + print(' - Attributes:')
  110 + for var_attr_name in var.ncattrs():
  111 + print(' - %s: %s' % (var_attr_name, getattr(var, var_attr_name)))
  112 +
  113 + for (key, value) in self.netcdf.variables.items():
  114 + describe_var(value)
  115 +
  116 + print('== Global attributes ==')
  117 + for global_attr_name in self.netcdf.ncattrs():
  118 + print(' - %s: %s' % (global_attr_name, getattr(self.netcdf, global_attr_name)))
  119 +
  120 + # CDF methods
  121 +
  122 + @staticmethod
  123 + def create_new_cdf(cdf_path):
  124 + """
  125 + Create a new empty CDF file in `self.cdf_path`, return a pyCDF object.
  126 + """
  127 +
  128 + # Create and clean a new directory for the CDF file.
  129 + cdf_dir = op.dirname(cdf_path)
  130 + if not op.exists(cdf_dir):
  131 + try:
  132 + os.makedirs(cdf_dir)
  133 + except IOError as e:
  134 + error('Can not create directory %s' % cdf_dir, e)
  135 + if op.exists(cdf_path):
  136 + try:
  137 + os.remove(cdf_path)
  138 + except IOError as e:
  139 + error('A CDF file already exist in %s and it can not be removed' % cdf_path, e)
  140 +
  141 + # Make the pyCDF object
  142 + try:
  143 + return pycdf.CDF(cdf_path, '')
  144 + except pycdf.CDFError as e:
  145 + error('Can not create CDF file on %s, check that the directory exists and its writing access' % cdf_path, e)
  146 +
  147 + @staticmethod
  148 + def build_temp_path(path, extension):
  149 + return op.abspath(op.join(TEMP_FILE, op.basename(path).split('.')[0] + extension))
  150 +
  151 + def get_cdf(self, cdf_path=None):
  152 + """
  153 + Convert and return the CDF object (only return it if it's already converted)
  154 + - `cdf_path`: The path of the CDF file (needed for CDF creation), or a temp path if not specified.
  155 + """
  156 +
  157 + if self.cdf:
  158 + return self.cdf
  159 +
  160 + self.cdf_path = op.abspath(cdf_path) if cdf_path else self.build_temp_path(self.netcdf_path, '.cdf')
  161 + self.cdf = self.create_new_cdf(self.cdf_path)
  162 +
  163 + for global_attr_name in self.netcdf.ncattrs():
  164 + self.cdf.attrs[global_attr_name] = getattr(self.netcdf, global_attr_name)
  165 +
  166 + for key, var in self.netcdf.variables.items():
  167 + dimensions = list(var.dimensions)
  168 +
  169 + if str(var.dtype) == '|S1':
  170 + if len(dimensions) == 1:
  171 + var_str = str(netCDF4.chartostring(var[:]).astype(str, copy=False))
  172 + self.cdf.attrs[key] = self.parse_date(var_str) if dimensions[0] == 'TimeLength' else var_str
  173 + elif len(dimensions) == 2:
  174 + var_strs = map(str, netCDF4.chartostring(var[:]).astype(str, copy=False))
  175 + self.cdf[key] = list(map(self.parse_date, var_strs) if dimensions[1] == 'TimeLength' else var_strs)
  176 + else:
  177 + self.cdf[key] = var[:]
  178 + for var_attr_name in var.ncattrs():
  179 + self.cdf[key].attrs[var_attr_name] = getattr(var, var_attr_name)
  180 +
  181 + return self.cdf
  182 +
  183 + def get_cdf_path(self):
  184 + return self.cdf_path
  185 +
  186 +
  187 +if __name__ == '__main__':
  188 + import sys
  189 +
  190 + if len(sys.argv) not in (2, 3):
  191 + print('usage:')
  192 + print('- `%s path/to/file.nc.gz` # Convert a Net-CDF file, '
  193 + 'save it in a temp directory, then display its path.' % sys.argv[0])
  194 + print('- `%s -i path/to/file.nc.gz` # Display information about a Net-CDF file.' % sys.argv[0])
  195 + print('- `%s path/to/file.nc.gz path/to/file.cdf` # Convert a Net-CDF file.'
  196 + 'and save it in the specified path.' % sys.argv[0])
  197 + print('This script can also be used as a Python library.')
  198 + exit(1)
  199 +
  200 + if len(sys.argv) == 2:
  201 + netcdf = NetCdf(sys.argv[1])
  202 + netcdf.get_cdf()
  203 + print('File stored in "%s".' % netcdf.get_cdf_path())
  204 + elif len(sys.argv) == 3:
  205 + if sys.argv[1] == '-i':
  206 + netcdf = NetCdf(sys.argv[2])
  207 + netcdf.describe()
  208 + else:
  209 + netcdf = NetCdf(sys.argv[1])
  210 + netcdf.get_cdf(sys.argv[2])
... ...
src/DDSERVICES/REST/utils/generateGranulesIndex.php 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +<?php
  2 +/**
  3 +* @file generateGranulesIndex.php
  4 +* @brief
  5 +* @version $Id: $
  6 +*/
  7 +
  8 + define('BASE','/data/DDBASE/');
  9 +
  10 + require_once BASE.'DDService/DDserverWeb_ini.php';
  11 +
  12 + if (!getenv('DDBASE'))
  13 + define('DDBASE', BASE.'DATA');
  14 + else
  15 + define('DDBASE', getenv('DDBASE'));
  16 +
  17 + $ddSys = new DOMDocument('1.0');
  18 + $ddSys->load(DDBASE.'/DDsys.xml');
  19 + $dataSets = $ddSys->getElementsByTagName('VI');
  20 +
  21 + foreach ($dataSets as $VI)
  22 + {
  23 + $vi_ = $VI->getElementsByTagName("NAME")->item(0);
  24 + // only local bases
  25 + if ($vi_->getAttribute("base") != "LOCAL") continue;
  26 + $id = $vi_->nodeValue;
  27 +
  28 + $main = array();
  29 + $index = array();
  30 + $location = $VI->getElementsByTagName("LOCATION")->item(0)->nodeValue;
  31 +
  32 + foreach (glob($location."*.nc.gz") as $granule)
  33 + {
  34 + $cmd = 'stat --printf="%s" '. $granule;
  35 + $file = basename($granule,".nc.gz");
  36 + $index[$file] = exec($cmd);
  37 + }
  38 +
  39 + $main[substr($location,strlen(DDBASE))] = $index;
  40 + file_put_contents(BASE."GRANULES/$id.json", json_encode($main));
  41 + }
  42 +?>
... ...
src/DDSERVICES/SOAP/DDserverWeb.php 0 → 100644
... ... @@ -0,0 +1,453 @@
  1 +<?php
  2 +
  3 +/**
  4 +* @file DDserverWeb.php
  5 +* @brief PHP SoapServer for DD WebServices
  6 +*
  7 +* @date 27.05.2008
  8 +* @version $Id: DDserverWeb.php,v 1.11 2013/04/18 06:54:39 benjamin Exp $
  9 +*/
  10 +
  11 +
  12 + class DDService
  13 +
  14 + {
  15 + private $alias = array(baseDir => webAlias);
  16 + private $extAlias = array(extBaseDir => extWebAlias);
  17 +
  18 +/**
  19 +* Checks if Remote Data Set has been already added
  20 +*/
  21 +
  22 + function isRemoteViAdded($baseId, $viId)
  23 + {
  24 + $referXML = baseDir."DDsys.xml";
  25 + $DDsys = new DOMDocument("1.0");
  26 +
  27 + $DDsys->load($referXML);
  28 + $xp = new domxpath($DDsys);
  29 + $VI = $xp->query("//NAME[.='".$viId."']");
  30 +
  31 + if ($VI->item(0)->nodeValue != NULL)
  32 + {
  33 + $base = $VI->item(0)->getAttribute("base");
  34 + if ($base != $baseId) return false;
  35 +
  36 + return true;
  37 + }
  38 + return false;
  39 + }
  40 +
  41 +/**
  42 +* Returns contents of 'Version' file from VI Location dir
  43 +*/
  44 +
  45 + function getVersion($dataSet)
  46 + {
  47 + $referXML = baseDir."DDsys.xml";
  48 + $DDsys = new DOMDocument("1.0");
  49 + $DDsys->load($referXML);
  50 + $xp = new domxpath($DDsys);
  51 + $VI = $xp->query("//NAME[.='".$dataSet."']");
  52 + if ($VI->item(0)->nodeValue != NULL)
  53 + {
  54 + $location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue;
  55 + }
  56 + if (file_exists($location."Version")) return file_get_contents($location."Version");
  57 + return null;
  58 + }
  59 +
  60 +/**
  61 +* Returns restricted TimeRestriction and GlobalStop in case of time restriction
  62 +*/
  63 +
  64 + function getTimeRestriction($dataSet)
  65 + {
  66 + $referXML = baseDir."DDsys.xml";
  67 + $DDsys = new DOMDocument("1.0");
  68 + $DDsys->load($referXML);
  69 + $xp = new domxpath($DDsys);
  70 + $VI = $xp->query("//NAME[.='".$dataSet."']");
  71 +
  72 + if ($VI->item(0)->nodeValue != NULL)
  73 + {
  74 + $location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue;
  75 + } else {
  76 + return array("success" => FALSE,
  77 + "days" => "NOSUCHVI",
  78 + "globalstop" => NULL
  79 + );
  80 + }
  81 + if (file_exists($location."TimeRestriction")) {
  82 + $restr = file($location."TimeRestriction", FILE_IGNORE_NEW_LINES);
  83 + $infoXmlRestr = $location.$restr[1].".xml";
  84 + if (file_exists($infoXmlRestr)) {
  85 +
  86 + if (!$DDsys->load($infoXmlRestr)) {
  87 + $currDir = getcwd();
  88 + chdir($location);
  89 + $DDsys->loadXML(file_get_contents($restr[1].".xml")); // NFS connection doesn't load
  90 + chdir($currDir);
  91 + }
  92 +
  93 + $globalStop = $DDsys->getElementsByTagName("GlobalStop")->item(0)->nodeValue;
  94 + }
  95 + else {
  96 + $globalStop = NULL;
  97 + }
  98 + return array("success" => TRUE,
  99 + "days" => $restr[0],
  100 + "globalstop" => $globalStop
  101 + );
  102 +
  103 + }
  104 + return array("success" => FALSE,
  105 + "days" => "NORESTRICTIONFILE",
  106 + "globalstop" => NULL
  107 + );
  108 + }
  109 +
  110 +
  111 +/** Just returns URL addres of AMDA_Users.xml -
  112 +* droits d'access
  113 +*/
  114 +
  115 + function getUserGroups()
  116 + {
  117 + if (file_exists(extBaseDir."AMDA_Users.xml")) return extWebAlias."AMDA_Users.xml";
  118 + else return NOUSERGROUPSSPECIFIED;
  119 + }
  120 +
  121 +/*
  122 +* Return info about a user
  123 +*/
  124 +
  125 + function getUserInfo($login,$hash)
  126 + {
  127 + if (md5(PRIVATEKEY.$login.__FUNCTION__) != $hash)
  128 + return array("success" => FALSE,
  129 + "login" => $login,
  130 + "name" => "undefined",
  131 + "first_name" => "undefined",
  132 + "group" => "undefined",
  133 + "email" => "undefined",
  134 + "date" => "undefined",
  135 + "news" => "0");
  136 +
  137 + $UsrDom = new DomDocument("1.0");
  138 + $UsrDom->load(extWebAlias."AMDA_Users_Info.xml");
  139 + $xp = new domxpath($UsrDom);
  140 + $theUser = $xp->query("//user[@login='".$login."']");
  141 +
  142 + return array("success" => TRUE,
  143 + "login" => $login,
  144 + "name" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("name") : "undefined",
  145 + "first_name" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("first_name") : "undefined",
  146 + "group" => $this->getUserMemberGroups($login),
  147 + "email" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("email") : "undefined",
  148 + "date" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("date") : "undefined",
  149 + "news" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("news") : "0");
  150 + }
  151 +
  152 +/*
  153 +* Return a list of group for which a user is a member
  154 +*/
  155 +
  156 + function getUserMemberGroups($user)
  157 + {
  158 + //get user
  159 + $user_dom = new DomDocument("1.0");
  160 + if (!file_exists(extBaseDir."AMDA_Users.xml"))
  161 + return array();
  162 + $user_dom->load(extBaseDir."AMDA_Users.xml");
  163 +
  164 + $user_nodes = $user_dom->getElementsByTagName('user');
  165 +
  166 + foreach ($user_nodes as $user_node)
  167 + {
  168 + if ($user_node->nodeValue == $user)
  169 + return $user_node->getAttribute('group');
  170 + }
  171 +
  172 + return "";
  173 + }
  174 +
  175 +/** Return the list of available local missions for
  176 +* a given user
  177 +*/
  178 +
  179 + function getUserAvailableLocalMissions($user)
  180 + {
  181 + //get user groups
  182 + $user_groups = explode(",",preg_replace('/\s+/', '',$this->getUserMemberGroups($user)));
  183 +
  184 + //get local missions
  185 + $mis_dom = new DomDocument("1.0");
  186 + if (!file_exists(extBaseDir."Missions.xml"))
  187 + return array();
  188 + $mis_dom->load(extBaseDir."Missions.xml");
  189 +
  190 + $local_nodes = $mis_dom->getElementsByTagName('Local');
  191 + if ($local_nodes->length < 1)
  192 + return array();
  193 +
  194 + $mis_nodes = $local_nodes->item(0)->getElementsByTagName("MissionID");
  195 +
  196 + $user_missions = array();
  197 +
  198 + foreach ($mis_nodes as $mis_node)
  199 + {
  200 + if (!$mis_node->hasAttribute('group') || ($mis_node->getAttribute('group') == ''))
  201 + {
  202 + //public mission
  203 + array_push($user_missions,$mis_node->nodeValue);
  204 + }
  205 + else
  206 + {
  207 + // private mission
  208 + $mis_group = $mis_node->getAttribute('group');
  209 + if (array_search($mis_group,$user_groups) === FALSE)
  210 + continue;
  211 + array_push($user_missions,$mis_node->nodeValue);
  212 + }
  213 + }
  214 +
  215 + return $user_missions;
  216 + }
  217 +
  218 +/** Return the list of available external missions for
  219 +* a given user
  220 +*/
  221 +
  222 + function getUserAvailableExternalMissions($user)
  223 + {
  224 + //get user groups
  225 + $user_groups = explode(",",$this->getUserMemberGroups($user));
  226 +
  227 + //get external missions
  228 + $mis_dom = new DomDocument("1.0");
  229 + if (!file_exists(extBaseDir.extBaseXml))
  230 + return array();
  231 + $mis_dom->load(extBaseDir.extBaseXml);
  232 +
  233 + $external_nodes = $mis_dom->getElementsByTagName('External');
  234 + if ($external_nodes->length < 1)
  235 + return array();
  236 +
  237 + $mis_nodes = $external_nodes->item(0)->getElementsByTagName("CenterID");
  238 +
  239 + $user_missions = array();
  240 +
  241 + foreach ($mis_nodes as $mis_node)
  242 + {
  243 + if (!$mis_node->hasAttribute('group') || ($mis_node->getAttribute('group') == ''))
  244 + {
  245 + //public mission
  246 + array_push($user_missions,$mis_node->nodeValue);
  247 + }
  248 + else
  249 + {
  250 + // private mission
  251 + $mis_group = $mis_node->getAttribute('group');
  252 + if (array_search($mis_group,$user_groups) === FALSE)
  253 + continue;
  254 + array_push($user_missions,$mis_node->nodeValue);
  255 + }
  256 + }
  257 +
  258 + return $user_missions;
  259 + }
  260 +
  261 +/** Just returns URL addres of Missions.xml -
  262 +* description of AMDA local data
  263 +*/
  264 +
  265 + function getAvailableMissions()
  266 + {
  267 + if (file_exists(extBaseDir."Missions.xml")) return extWebAlias."Missions.xml";
  268 + else return NOLOCALDATA;
  269 + }
  270 +
  271 +/** Just returns URL addres of Bases.xml -
  272 +* description of available external bases
  273 +*/
  274 +
  275 + function getAvailableExternalBases()
  276 + {
  277 + if (file_exists(extBaseDir.extBaseXml)) return extWebAlias.extBaseXml;
  278 + else return NOEXTERNALBASES;
  279 + }
  280 +
  281 +/** Just returns URL addres of base.xml -
  282 +* description of available data for particular External Base
  283 +* produced by DataCenterMgr
  284 +*/
  285 +
  286 + function getAvailableExternalData($baseID)
  287 + {
  288 + if (file_exists(extBaseDir.$baseID."/base.xml"))
  289 + return extWebAlias.$baseID."/base.xml";
  290 + else return NOEXTERNALDATA;
  291 + }
  292 +
  293 +/** Returns URL addres of dataSet.xml -
  294 +* description of particular external DataSet
  295 +* if there is no such a description
  296 +* contacts External Base and gets it
  297 +*/
  298 +
  299 + function getDataSetDescription($baseID, $remDataSetID)
  300 + {
  301 + if (file_exists(extBaseDir.$baseID."/".$remDataSetID.".xml"))
  302 + return extWebAlias.$baseID."/".$remDataSetID.".xml";
  303 + else
  304 + {
  305 +
  306 +
  307 + }
  308 + }
  309 +
  310 +
  311 +/**
  312 +* Returns String Start-Stop for local DataSet in DD Base
  313 +*/
  314 +
  315 + function getStartStop($dataSet)
  316 + {
  317 + if ($dataSet != "compound") {
  318 + $referFile = baseDir."refer.nc";
  319 + $cmd = DDBASEBIN."/StartStop ".$referFile." ".$dataSet;
  320 + $res = system($cmd);
  321 +
  322 + return $res;
  323 + }
  324 + }
  325 +
  326 +/**
  327 +* Returns String INFO for local DataSet in DD Base
  328 +*/
  329 +
  330 + function getInfo($dataSet, $infoID)
  331 + {
  332 + $referFile = baseDir."refer.nc";
  333 + $cmd = DDBASEBIN."/GetInfo ".$referFile." ".$dataSet." ".$infoID;
  334 + $res = system($cmd);
  335 +
  336 + return $res;
  337 + }
  338 +
  339 +/**
  340 +* Returns Desc attribute for Remote DataSet in DD Base
  341 +*/
  342 +
  343 + function getRemoteStartStop($baseID, $dataSet)
  344 + {
  345 + $domName = extBaseDir.$baseID."/base.xml";
  346 + if (!file_exists($domName))
  347 + return NOEXTERNALDATA;
  348 +
  349 + $dom = new DomDocument("1.0");
  350 + $dom->load($domName);
  351 + $vi = $dom->getElementById($dataSet);
  352 + if (!$vi)
  353 + return NODATASET;
  354 +
  355 + $res = $vi->getAttribute('desc');
  356 + return $res;
  357 + }
  358 +
  359 +/**
  360 +* Check Remote Connection
  361 +*/
  362 +
  363 + function checkRemoteConnection($extBaseID){
  364 +
  365 + switch ($extBaseID) {
  366 + case "THEMIS" : return is_dir(THEMIS_DIR);
  367 +
  368 + case "MAPSKP" : if (fsockopen(MAPSKP_HTTP_SERVER, 80, $errno, $errstr, 30)) return true;
  369 + else return false;
  370 +
  371 + case "CDAWEB" : if (ftp_connect(CDAWEB_FTP_SERVER)) return true;
  372 + else return false;
  373 +
  374 + case "VEXGRAZ" : if (fsockopen(VEXGRAZ_HTTP_SERVER, 80, $errno, $errstr, 30)) return true;
  375 + else return false;
  376 +
  377 + case "LATMOS" : if (fsockopen(LATMOS_HTTP_SERVER, 80, $errno, $errstr, 30)) return true;
  378 + else return false;
  379 +
  380 + case "LESIA" : if (fsockopen(LESIA_HTTP_SERVER, 80, $errno, $errstr, 30)) return true;
  381 + else return false;
  382 +
  383 + case "SINP" : if (fsockopen(SINP_HTTP_SERVER, 80, $errno, $errstr, 30)) return true;
  384 + else return false;
  385 +
  386 + case "FMI_HYBRID" : if (fsockopen(FMI_HYBRID_HTTP_SERVER, 80, $errno, $errstr, 30)) return true;
  387 + else return false;
  388 +
  389 + case "FMI_GUMICS" : if (fsockopen(FMI_GUMICS_HTTP_SERVER, 80, $errno, $errstr, 30)) return true;
  390 + else return false;
  391 +
  392 + case "CCMC" : if (fsockopen(CCMC_HTTP_SERVER, 80, $errno, $errstr, 30)) return true;
  393 + else return false;
  394 +
  395 + case "CLWeb" : if (fsockopen(CLWeb_HTTP_SERVER, 80, $errno, $errstr, 30)) return true;
  396 + else return false;
  397 +
  398 + default: return false;
  399 + }
  400 + }
  401 +/**
  402 +* Returns Array of Data Urls for a given DataSet
  403 +* in StartTime - StopTime interval
  404 +*/
  405 +
  406 + function getDataUrl($dataSet, $StartTime, $StopTime)
  407 + {
  408 + $tempFile = uniqid("temp");
  409 + if (file_exists($tempFile)) unlink($tempFile);
  410 +
  411 + $referXML = baseDir."DDsys.xml";
  412 + $DDsys = new DOMDocument("1.0");
  413 + $DDsys->load($referXML);
  414 + $xp = new domxpath($DDsys);
  415 + $VI = $xp->query("//NAME[.='".$dataSet."']");
  416 + if ($VI->item(0)->nodeValue != NULL)
  417 + {
  418 + $location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue;
  419 + $times = $VI->item(0)->parentNode->getElementsByTagName("TIMES")->item(0)->nodeValue;
  420 + $timesFile = $location.$times;
  421 + $cmd = DDBASEBIN."/GetFileNames ".$timesFile." ".strtotime($StartTime)." ".strtotime($StopTime)." > $tempFile";
  422 + system($cmd);
  423 + if (!file_exists($tempFile)) return 'ERROR';
  424 +
  425 + $res = file($tempFile);
  426 + if ($res[0] == OUTOFTIME) {
  427 + unlink($tempFile);
  428 + return $res;
  429 + }
  430 +
  431 + $urls = explode(";",$res[0]);
  432 + $url_location = strtr($location, $this->alias);
  433 + if (count($urls) > 0) {
  434 + unset($urls[count($urls)-1]);
  435 + for ($i = 0; $i < count($urls); $i++) $urls[$i] = $url_location.$urls[$i].".gz";
  436 + }
  437 + unlink($tempFile);
  438 +
  439 + return $urls;
  440 + }
  441 + return NODATASET;
  442 + }
  443 + }
  444 +
  445 +
  446 + require_once 'DDserverWeb_ini.php';
  447 +
  448 + ini_set("soap.wsdl_cache_enabled", "0");
  449 + // use_soap_error_handler(false);
  450 + $server = new SoapServer("./dd.wsdl");
  451 + $server->setClass("DDService");
  452 + $server->handle();
  453 +?>
... ...
src/DDSERVICES/SOAP/DDserverWeb_ini.php 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +<?php
  2 +/**
  3 +* @file DDserverWeb_ini.php
  4 +* @version $Id: DDserverWeb_ini.php,v 1.4 2013/04/09 09:07:39 benjamin Exp $
  5 +* @brief All necessary SETUP for DD WebServices
  6 +*
  7 +*/
  8 +
  9 +/* MAIN DEFINITIONS SHOULD BE MODIFIED!!!!!! */
  10 +
  11 + define("rootDir", "/home/budnik/DDBASE");
  12 + define("rootAlias", "http://apus.irap.omp.eu/NEWAMDA/DDService");
  13 + // define("DDLIBHOME","/home/budnik/AMDANEW/DDLIB");
  14 + define("DDLIB", "/opt/local/lib/");
  15 +
  16 + putenv("LD_LIBRARY_PATH=/usr/lib:/usr/local/lib:".DDLIB);
  17 +
  18 +/* Compound Definitions: Nothing to modify */
  19 +
  20 + define("baseDir", rootDir."/DATA/");
  21 +// define("extBaseDir",rootDir."/INFO/");
  22 +// define("extBaseXml", "Bases.xml");
  23 +
  24 + define("webAlias", rootAlias."/DATA/");
  25 + define("extWebAlias", rootAlias."/INFO/");
  26 + define("DDBASEBIN", "/opt/local/bin");
  27 +
  28 +// Errors
  29 + define("UNKNOWNBASEID","UNKNOWNBASEID");
  30 + define("OUTOFTIME","OUTOFTIME");
  31 + define("NODATASET","NODATASET");
  32 + define("NOEXTERNALBASES","NOEXTERNALBASES");
  33 + define("NOEXTERNALDATA","NOEXTERNALDATA");
  34 + define("NOLOCALDATA","NOLOCALDATA");
  35 + define("NOUSERGROUPSSPECIFIED","NOUSERGROUPSSPECIFIED");
  36 +
  37 +// A private key use to check if a request comes from a trust client
  38 + define("PRIVATEKEY","!%p856Dc");
  39 +
  40 +?>
... ...
src/DDSERVICES/SOAP/dd.wsdl 0 → 100644
... ... @@ -0,0 +1,372 @@
  1 +<?xml version ='1.0' encoding ='UTF-8' ?>
  2 +<definitions name='amda'
  3 + targetNamespace='http://amda.cdpp.irap.omp.eu'
  4 + xmlns:tns='http://amda.cdpp.irap.omp.eu'
  5 + xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
  6 + xmlns:xsd='http://www.w3.org/2001/XMLSchema'
  7 + xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
  8 + xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
  9 + xmlns='http://schemas.xmlsoap.org/wsdl/'>
  10 +
  11 +<types>
  12 + <tns:complexType name="UserInfoData">
  13 + <tns:sequence>
  14 + <tns:element minOccurs="1" maxOccurs="1" name="success" type="xsd:boolean"/>
  15 + <tns:element minOccurs="1" maxOccurs="1" name="login" type="xsd:string"/>
  16 + <tns:element minOccurs="1" maxOccurs="1" name="name" type="xsd:string"/>
  17 + <tns:element minOccurs="1" maxOccurs="1" name="first_name" type="xsd:string"/>
  18 + <tns:element minOccurs="1" maxOccurs="1" name="group" type="xsd:string"/>
  19 + <tns:element minOccurs="1" maxOccurs="1" name="email" type="xsd:string"/>
  20 + <tns:element minOccurs="1" maxOccurs="1" name="date" type="xsd:string"/>
  21 + <tns:element minOccurs="1" maxOccurs="1" name="news" type="xsd:string"/>
  22 + </tns:sequence>
  23 + </tns:complexType>
  24 + <tns:complexType name="TimeRestrictionData">
  25 + <tns:sequence>
  26 + <tns:element minOccurs="1" maxOccurs="1" name="success" type="xsd:boolean"/>
  27 + <tns:element minOccurs="1" maxOccurs="1" name="days" type="xsd:string"/>
  28 + <tns:element minOccurs="1" maxOccurs="1" name="globalstop" type="xsd:string"/>
  29 + </tns:sequence>
  30 + </tns:complexType>
  31 + <tns:complexType name="ArrayOfStrings">
  32 + <complexContent>
  33 + <restriction base="soap11-enc:Array">
  34 + <attribute ref="soap11-enc:arrayType" wsdl:arrayType="string[]"/>
  35 + </restriction>
  36 + </complexContent>
  37 + </tns:complexType>
  38 +</types>
  39 +
  40 +<message name='isRemoteViAddedRequest'>
  41 + <part name='baseId' type='xsd:string'/>
  42 + <part name='viId' type='xsd:string'/>
  43 +</message>
  44 +<message name='isRemoteViAddedResponse'>
  45 + <part name='Result' type='xsd:boolean'/>
  46 +</message>
  47 +<message name='getVersionRequest'>
  48 + <part name='dataSet' type='xsd:string'/>
  49 +</message>
  50 +<message name='getVersionResponse'>
  51 + <part name='Result' type='xsd:string'/>
  52 +</message>
  53 +<message name='checkRemoteConnectionRequest'>
  54 + <part name='dataSet' type='xsd:string'/>
  55 +</message>
  56 +<message name='checkRemoteConnectionResponse'>
  57 + <part name='Result' type='xsd:boolean'/>
  58 +</message>
  59 +<message name='getStartStopRequest'>
  60 + <part name='dataSet' type='xsd:string'/>
  61 +</message>
  62 +<message name='getStartStopResponse'>
  63 + <part name='Result' type='xsd:string'/>
  64 +</message>
  65 +<message name='getInfoRequest'>
  66 + <part name='dataSet' type='xsd:string'/>
  67 + <part name='infoName' type='xsd:string'/>
  68 +</message>
  69 +<message name='getInfoResponse'>
  70 + <part name='Result' type='xsd:string'/>
  71 +</message>
  72 +<message name='getRemoteStartStopRequest'>
  73 + <part name='baseID' type='xsd:string'/>
  74 + <part name='dataSet' type='xsd:string'/>
  75 +</message>
  76 +<message name='getRemoteStartStopResponse'>
  77 + <part name='Result' type='xsd:string'/>
  78 +</message>
  79 +<message name='getDataUrlRequest'>
  80 + <part name='dataSet' type='xsd:string'/>
  81 + <part name="startDate" type="xsd:dateTime"/>
  82 + <part name="stopDate" type="xsd:dateTime"/>
  83 +</message>
  84 +<message name='getDataUrlResponse'>
  85 + <part name='Result' type='tns:ArrayOfStrings'/>
  86 +</message>
  87 +<message name='getAvailableExternalBasesRequest'>
  88 +</message>
  89 +<message name='getAvailableExternalBasesResponse'>
  90 + <part name='Result' type='xsd:string'/>
  91 +</message>
  92 +<message name='getUserGroupsRequest'>
  93 +</message>
  94 +<message name='getUserGroupsResponse'>
  95 + <part name='Result' type='xsd:string'/>
  96 +</message>
  97 +<message name='getUserAvailableLocalMissionsRequest'>
  98 + <part name='user' type='xsd:string'/>
  99 +</message>
  100 +<message name='getUserAvailableLocalMissionsResponse'>
  101 + <part name='Result' type='tns:ArrayOfStrings'/>
  102 +</message>
  103 +<message name='getUserAvailableExternalMissionsRequest'>
  104 + <part name='user' type='xsd:string'/>
  105 +</message>
  106 +<message name='getUserAvailableExternalMissionsResponse'>
  107 + <part name='Result' type='tns:ArrayOfStrings'/>
  108 +</message>
  109 +<message name='getAvailableMissionsRequest'>
  110 +</message>
  111 +<message name='getAvailableMissionsResponse'>
  112 + <part name='Result' type='xsd:string'/>
  113 +</message>
  114 +<message name='getAvailableExternalDataRequest'>
  115 + <part name='daseID' type='xsd:string'/>
  116 +</message>
  117 +<message name='getAvailableExternalDataResponse'>
  118 + <part name='Result' type='xsd:string'/>
  119 +</message>
  120 +<message name='getUserInfoRequest'>
  121 + <part name='login' type='xsd:string'/>
  122 + <part name='hash' type='xsd:string'/>
  123 +</message>
  124 +<message name='getUserInfoResponse'>
  125 + <part name='Result' type='tns:UserInfoData'/>
  126 +</message>
  127 +<message name='getTimeRestrictionRequest'>
  128 + <part name='dataSet' type='xsd:string'/>
  129 +</message>
  130 +<message name='getTimeRestrictionResponse'>
  131 + <part name='Result' type='tns:TimeRestrictionData'/>
  132 +</message>
  133 +
  134 +<portType name='AmdaPortType'>
  135 + <operation name='isRemoteViAdded'>
  136 + <input message='tns:isRemoteViAddedRequest'/>
  137 + <output message='tns:isRemoteViAddedResponse'/>
  138 + </operation>
  139 + <operation name='getVersion'>
  140 + <input message='tns:getVersionRequest'/>
  141 + <output message='tns:getVersionResponse'/>
  142 + </operation>
  143 + <operation name='checkRemoteConnection'>
  144 + <input message='tns:checkRemoteConnectionRequest'/>
  145 + <output message='tns:checkRemoteConnectionResponse'/>
  146 + </operation>
  147 + <operation name='getStartStop'>
  148 + <input message='tns:getStartStopRequest'/>
  149 + <output message='tns:getStartStopResponse'/>
  150 + </operation>
  151 + <operation name='getInfo'>
  152 + <input message='tns:getInfoRequest'/>
  153 + <output message='tns:getInfoResponse'/>
  154 + </operation>
  155 + <operation name='getRemoteStartStop'>
  156 + <input message='tns:getRemoteStartStopRequest'/>
  157 + <output message='tns:getRemoteStartStopResponse'/>
  158 + </operation>
  159 + <operation name='getDataUrl'>
  160 + <input message='tns:getDataUrlRequest'/>
  161 + <output message='tns:getDataUrlResponse'/>
  162 + </operation>
  163 + <operation name='getAvailableExternalBases'>
  164 + <input message='tns:getAvailableExternalBasesRequest'/>
  165 + <output message='tns:getAvailableExternalBasesResponse'/>
  166 + </operation>
  167 + <operation name='getUserGroups'>
  168 + <input message='tns:getUserGroupsRequest'/>
  169 + <output message='tns:getUserGroupsResponse'/>
  170 + </operation>
  171 + <operation name='getUserAvailableLocalMissions'>
  172 + <input message='tns:getUserAvailableLocalMissionsRequest'/>
  173 + <output message='tns:getUserAvailableLocalMissionsResponse'/>
  174 + </operation>
  175 + <operation name='getUserAvailableExternalMissions'>
  176 + <input message='tns:getUserAvailableExternalMissionsRequest'/>
  177 + <output message='tns:getUserAvailableExternalMissionsResponse'/>
  178 + </operation>
  179 + <operation name='getAvailableMissions'>
  180 + <input message='tns:getAvailableMissionsRequest'/>
  181 + <output message='tns:getAvailableMissionsResponse'/>
  182 + </operation>
  183 + <operation name='getAvailableExternalData'>
  184 + <input message='tns:getAvailableExternalDataRequest'/>
  185 + <output message='tns:getAvailableExternalDataResponse'/>
  186 + </operation>
  187 + <operation name='getUserInfo'>
  188 + <input message='tns:getUserInfoRequest'/>
  189 + <output message='tns:getUserInfoResponse'/>
  190 + </operation>
  191 + <operation name='getTimeRestriction'>
  192 + <input message='tns:getTimeRestrictionRequest'/>
  193 + <output message='tns:getTimeRestrictionResponse'/>
  194 + </operation>
  195 +</portType>
  196 +
  197 +<binding name='AmdaBinding' type='tns:AmdaPortType'>
  198 + <soap:binding style='rpc'
  199 + transport='http://schemas.xmlsoap.org/soap/http'/>
  200 + <operation name='isRemoteViAdded'>
  201 + <soap:operation soapAction='isRemoteViAdded'/>
  202 + <input>
  203 + <soap:body use='encoded'
  204 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  205 + </input>
  206 + <output>
  207 + <soap:body use='encoded'
  208 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  209 + </output>
  210 + </operation>
  211 + <operation name='getVersion'>
  212 + <soap:operation soapAction='getVersion'/>
  213 + <input>
  214 + <soap:body use='encoded'
  215 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  216 + </input>
  217 + <output>
  218 + <soap:body use='encoded'
  219 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  220 + </output>
  221 + </operation>
  222 + <operation name='checkRemoteConnection'>
  223 + <soap:operation soapAction='checkRemoteConnection'/>
  224 + <input>
  225 + <soap:body use='encoded'
  226 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  227 + </input>
  228 + <output>
  229 + <soap:body use='encoded'
  230 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  231 + </output>
  232 + </operation>
  233 + <operation name='getStartStop'>
  234 + <soap:operation soapAction='getStartStop'/>
  235 + <input>
  236 + <soap:body use='encoded'
  237 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  238 + </input>
  239 + <output>
  240 + <soap:body use='encoded'
  241 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  242 + </output>
  243 + </operation>
  244 + <operation name='getInfo'>
  245 + <soap:operation soapAction='getSInfo'/>
  246 + <input>
  247 + <soap:body use='encoded'
  248 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  249 + </input>
  250 + <output>
  251 + <soap:body use='encoded'
  252 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  253 + </output>
  254 + </operation>
  255 + <operation name='getRemoteStartStop'>
  256 + <soap:operation soapAction='getRemoteStartStop'/>
  257 + <input>
  258 + <soap:body use='encoded'
  259 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  260 + </input>
  261 + <output>
  262 + <soap:body use='encoded'
  263 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  264 + </output>
  265 + </operation>
  266 + <operation name='getDataUrl'>
  267 + <soap:operation soapAction='getDataUrl'/>
  268 + <input>
  269 + <soap:body use='encoded'
  270 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  271 + </input>
  272 + <output>
  273 + <soap:body use='encoded'
  274 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  275 + </output>
  276 + </operation>
  277 + <operation name='getAvailableExternalBases'>
  278 + <soap:operation soapAction='getAvailableExternalBases'/>
  279 + <input>
  280 + <soap:body use='encoded'
  281 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  282 + </input>
  283 + <output>
  284 + <soap:body use='encoded'
  285 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  286 + </output>
  287 + </operation>
  288 + <operation name='getAvailableExternalData'>
  289 + <soap:operation soapAction='getAvailableExternalData'/>
  290 + <input>
  291 + <soap:body use='encoded'
  292 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  293 + </input>
  294 + <output>
  295 + <soap:body use='encoded'
  296 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  297 + </output>
  298 + </operation>
  299 + <operation name='getUserGroups'>
  300 + <soap:operation soapAction='getUserGroups'/>
  301 + <input>
  302 + <soap:body use='encoded'
  303 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  304 + </input>
  305 + <output>
  306 + <soap:body use='encoded'
  307 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  308 + </output>
  309 + </operation>
  310 + <operation name='getUserAvailableLocalMissions'>
  311 + <soap:operation soapAction='getUserAvailableLocalMissions'/>
  312 + <input>
  313 + <soap:body use='encoded'
  314 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  315 + </input>
  316 + <output>
  317 + <soap:body use='encoded'
  318 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  319 + </output>
  320 + </operation>
  321 + <operation name='getUserAvailableExternalMissions'>
  322 + <soap:operation soapAction='getUserAvailableExternalMissions'/>
  323 + <input>
  324 + <soap:body use='encoded'
  325 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  326 + </input>
  327 + <output>
  328 + <soap:body use='encoded'
  329 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  330 + </output>
  331 + </operation>
  332 + <operation name='getAvailableMissions'>
  333 + <soap:operation soapAction='getAvailableMissions'/>
  334 + <input>
  335 + <soap:body use='encoded'
  336 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  337 + </input>
  338 + <output>
  339 + <soap:body use='encoded'
  340 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  341 + </output>
  342 + </operation>
  343 + <operation name='getUserInfo'>
  344 + <soap:operation soapAction='getUserInfo'/>
  345 + <input>
  346 + <soap:body use='encoded'
  347 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  348 + </input>
  349 + <output>
  350 + <soap:body use='encoded'
  351 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  352 + </output>
  353 + </operation>
  354 + <operation name='getTimeRestriction'>
  355 + <soap:operation soapAction='getTimeRestriction'/>
  356 + <input>
  357 + <soap:body use='encoded'
  358 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  359 + </input>
  360 + <output>
  361 + <soap:body use='encoded'
  362 + encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
  363 + </output>
  364 + </operation>
  365 +</binding>
  366 +
  367 +<service name='AmdaService'>
  368 + <port name='AmdaPort' binding='AmdaBinding'>
  369 + <soap:address location='http://apus.irap.omp.eu/NEWAMDA/DDService/DDserverWeb.php'/>
  370 + </port>
  371 +</service>
  372 +</definitions>
... ...
src/DDSERVICES/SOAP/src/GetFileNames.c 0 → 100644
... ... @@ -0,0 +1,127 @@
  1 +/* $Id: GetFileNames.c,v 1.2 2008/06/16 12:11:58 elena Exp $ */
  2 +
  3 +/**
  4 +* @file GetFileNames.c
  5 +* @brief Print File names
  6 +* @arg dataSetID, StartTime, StopTime
  7 +*
  8 +*
  9 +*/
  10 +
  11 +#include <stdlib.h>
  12 +#include <stdio.h>
  13 +#include <string.h>
  14 +#include <time.h>
  15 +#include <math.h>
  16 +#include <netcdf.h>
  17 +#include <DD.h>
  18 +
  19 +
  20 +#define NAME_LENGTH 100
  21 +#define NAME_DIM 32L
  22 +
  23 +int DataID, RecID, StartID, StopID, NameID;;
  24 +size_t RecNum;
  25 +char StartT[TIMELENGTH], StopT[TIMELENGTH];
  26 +size_t count[2] = {1L,TIMELENGTH};
  27 +size_t start[2] = {0L,0L};
  28 +size_t NameCount[2] = {1, NAME_DIM};
  29 +double StartTime, StopTime;
  30 +char Name[NAME_LENGTH];
  31 +
  32 +/*---------------- NC ERROR --------------------------------------*/
  33 +void nc_handle_error(int status)
  34 +{
  35 + fprintf(stderr, "%s\n", nc_strerror(status));
  36 + exit(1);
  37 +}
  38 +
  39 +/* ----------------------- MAIN ------------------------------------*/
  40 + int main(int argc, char *argv[])
  41 +{
  42 +
  43 + int status, len, StartRecord, StopRecord;
  44 + int i, hi, lo = 0;
  45 + double StartD0, StartD1 = 0.0, StopD0, StopD1;
  46 +
  47 + if (argc < 4)
  48 + {
  49 + fprintf(stderr,"Usage: GetFileNames ViId StartTime StopTime\n");
  50 + exit(0);
  51 + }
  52 +
  53 +/* find VI in reference file */
  54 +
  55 +
  56 + StartTime = atof(argv[2]);
  57 + StopTime = atof(argv[3]);
  58 +
  59 +/* Open VI_times.nc */
  60 +
  61 + if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR)
  62 + nc_handle_error(status);
  63 +
  64 + if ((status = nc_inq_dimid(DataID, "record", &RecID)) != NC_NOERR)
  65 + nc_handle_error(status);
  66 +
  67 +/* Get Number of Records */
  68 +
  69 + if ((status = nc_inq_dimlen(DataID, RecID, &RecNum)) != NC_NOERR)
  70 + nc_handle_error(status);
  71 +
  72 + if ((status = nc_inq_varid(DataID, "StartTime", &StartID)) != NC_NOERR)
  73 + nc_handle_error(status);
  74 + if ((status = nc_inq_varid(DataID, "StopTime", &StopID)) != NC_NOERR)
  75 + nc_handle_error(status);
  76 +
  77 + if ((status = nc_inq_varid(DataID, "FileName", &NameID)) != NC_NOERR)
  78 + nc_handle_error(status);
  79 +/* Get The First Start and The Last Stop Times */
  80 + start[0] = 0;
  81 +
  82 + if((status = nc_get_vara_text(DataID, StartID, start, count, StartT)) != NC_NOERR)
  83 + nc_handle_error(status);
  84 +
  85 + start[0] = RecNum-1;
  86 + if((status = nc_get_vara_text(DataID, StopID, start, count, StopT)) != NC_NOERR)
  87 + nc_handle_error(status);
  88 +
  89 + if (StartTime > DD_Time2Double(StopT) || StopTime < DD_Time2Double(StartT))
  90 + {
  91 + fprintf(stdout, "OUTOFTIME\0");
  92 + nc_close(DataID);
  93 + exit(0);
  94 + }
  95 +
  96 + hi = RecNum;
  97 +
  98 + /* Find Start Record */
  99 + while (lo < hi)
  100 + {
  101 + i = (lo+hi)/2;
  102 + start[0] = i + 1;
  103 + status = nc_get_vara_text(DataID,StartID,start,count,(char *)StartT);
  104 + StartD1 = DD_Time2Double(StartT);
  105 + if (StartD1 > StartTime) hi--;
  106 + start[0] = i;
  107 + status = nc_get_vara_text(DataID,StartID,start,count,(char *)StartT);
  108 + StartD0 = DD_Time2Double(StartT);
  109 + if (StartD0 < StartTime) lo++;
  110 + if (StartD1 <= StartTime && StartD0 >= StartTime) break;
  111 + }
  112 + status = nc_get_vara_text(DataID, NameID, start, NameCount,(char *)Name);
  113 + fprintf(stdout, "%s;",Name);
  114 + status = nc_get_vara_text(DataID,StopID,start,count,(char *)StopT);
  115 + StopD0 = DD_Time2Double(StopT);
  116 +
  117 + while (StopTime > StopD0 && start[0] <= RecNum) {
  118 + status = nc_get_vara_text(DataID,StopID,start,count,(char *)StopT);
  119 + status = nc_get_vara_text(DataID, NameID, start, NameCount,(char *)Name);
  120 + if (start[0] > i) fprintf(stdout, "%s;", Name);
  121 + StopD0 = DD_Time2Double(StopT);
  122 + start[0]++;
  123 + }
  124 +
  125 + nc_close(DataID);
  126 +
  127 +}
... ...
src/DDSERVICES/SOAP/src/GetInfo.c 0 → 100644
... ... @@ -0,0 +1,102 @@
  1 +
  2 +/** @file GetInfo.c
  3 +* @version $Id: GetInfo.c,v 1.1 2013/05/22 13:33:52 budnik Exp $
  4 +*/
  5 +
  6 +
  7 +#include <stdlib.h>
  8 +#include <stdio.h>
  9 +#include <string.h>
  10 +#include <time.h>
  11 +#include <math.h>
  12 +#include <netcdf.h>
  13 +#include <DD.h>
  14 +
  15 +
  16 +int DataID, RecID, VarID;
  17 +size_t RecNum;
  18 +char Var[128];
  19 +size_t count[2] = {1L,TIMELENGTH};
  20 +size_t start[2] = {0L,0L};
  21 +size_t countVar[2] = {1L,128L};
  22 +
  23 +/*---------------- NC ERROR --------------------------------------*/
  24 +void nc_handle_error(int status)
  25 +{
  26 + fprintf(stderr, "%s\n", nc_strerror(status));
  27 + exit(1);
  28 +}
  29 +
  30 +/* ----------------------- MAIN ------------------------------------*/
  31 + int main(int argc, char *argv[])
  32 +{
  33 +
  34 + int status, len, infoID, i;
  35 +
  36 + char Project[50],Instrument[50],Mode[50], RInstrName[100], INFO_ID[50];
  37 + int dims[10];
  38 + size_t lenp, total_length;
  39 + float *value;
  40 + int ndimsp;
  41 +
  42 + if (argc < 4)
  43 + {
  44 + fprintf(stderr,"Usage: GetInfo reference_file_name VI_ID INFO_ID\n");
  45 + exit(0);
  46 + }
  47 +
  48 +
  49 + if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR)
  50 + nc_handle_error(status);
  51 +
  52 + sscanf(argv[2], "%[^:]%*c%[^:]%*c%[^:]%*c",Project,
  53 + Instrument,
  54 + Mode);
  55 +
  56 + sprintf(RInstrName,"%s_%s_%s\0",Project,Instrument,Mode);
  57 + sprintf(INFO_ID,"%s\0",argv[3]);
  58 +
  59 + if ((status = nc_inq_varid(DataID,RInstrName,&VarID)) != NC_NOERR)
  60 + nc_handle_error(status);
  61 +
  62 + start[0] = 2;
  63 + if((status = nc_get_vara_text(DataID, VarID, start, countVar, Var)) != NC_NOERR)
  64 + nc_handle_error(status);
  65 +
  66 + len = strcspn(Var," "); Var[len] = '\0';
  67 +
  68 + if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status);
  69 +
  70 +// Open VI_info.nc
  71 +
  72 + if ((status = nc_open(Var, NC_NOWRITE, &DataID)) != NC_NOERR)
  73 + nc_handle_error(status);
  74 +
  75 +
  76 +// Get Number of Records
  77 +
  78 +
  79 + if ((status = nc_inq_varid(DataID, INFO_ID, &infoID)) != NC_NOERR)
  80 + nc_handle_error(status);
  81 +
  82 + if ((status = nc_inq_varndims(DataID, infoID, &ndimsp)) != NC_NOERR)
  83 + nc_handle_error(status);
  84 +
  85 + if ((status = nc_inq_vardimid(DataID, infoID, &dims)) != NC_NOERR)
  86 + nc_handle_error(status);
  87 + total_length = 0;
  88 + for ( i = 0; i < ndimsp; i++) {
  89 + if ((status = nc_inq_dimlen (DataID, dims[i], &lenp))!= NC_NOERR)
  90 + nc_handle_error(status);
  91 + total_length += lenp;
  92 + }
  93 + value = malloc(total_length*sizeof(float));
  94 +
  95 + if ((status =nc_get_var_float(DataID, infoID, value)) != NC_NOERR)
  96 + nc_handle_error(status);
  97 + printf("%f", value[0]);
  98 + for (i = 1; i < lenp; i++) printf(";%f", value[i]);
  99 +
  100 + if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status);
  101 +
  102 +}
... ...
src/DDSERVICES/SOAP/src/Makefile 0 → 100755
... ... @@ -0,0 +1,30 @@
  1 +#-----------------------------------------------------
  2 +# MAKEFILE for DD SERVER Services
  3 +#---------------------------------------------------------
  4 +
  5 +EXE = StartStop GetFileNames GetInfo
  6 +
  7 +lib: $(EXE)
  8 +
  9 +install:
  10 + install -d -m a+rx,ug+w ../bin
  11 + cp $(EXE) ../bin
  12 +
  13 +clean:
  14 + tag="*.o" ${EXE};\
  15 + for file in $$tag; do \
  16 + echo $$file; rm -f $$file;\
  17 + done
  18 + find -name \*~ -delete
  19 +
  20 +deinstall:
  21 + echo "Do nothing"
  22 +
  23 +StartStop: StartStop.c
  24 + ${CC} ${CFLAGS} -o StartStop StartStop.c ${INC} ${LIB} -lnetcdf
  25 +
  26 +GetInfo: GetInfo.c
  27 + ${CC} ${CFLAGS} -o GetInfo GetInfo.c ${INC} ${LIB} -lnetcdf
  28 +
  29 +GetFileNames: GetFileNames.c
  30 + ${CC} ${CFLAGS} -o GetFileNames GetFileNames.c ${INC} ${LIB} -lnetcdf -lDD
... ...
src/DDSERVICES/SOAP/src/StartStop.c 0 → 100644
... ... @@ -0,0 +1,104 @@
  1 +
  2 +/** @file StartStop.c
  3 +* @brief Stand-alone executable <br> Returns real Start-Stop for VI in DDBase <br>
  4 +* Is used in DD Server WebServices <br>
  5 +* @details StartStop(string *, string *) <br>
  6 +* @arg \c argv[1] Full name of DDBase reference file <br>
  7 +* @arg \c argv[2] Virtual Instrument ID (DD notation) <br>
  8 +* Output: YYYYDDdayHHMMSSMLS-YYYYDDdayHHMMSSMLS
  9 +*
  10 +* @date 10.10.2007
  11 +* @version $Id: StartStop.c,v 1.3 2011/09/05 11:27:34 budnik Exp $
  12 +*/
  13 +
  14 +
  15 +#include <stdlib.h>
  16 +#include <stdio.h>
  17 +#include <string.h>
  18 +#include <time.h>
  19 +#include <math.h>
  20 +#include <netcdf.h>
  21 +#include <DD.h>
  22 +
  23 +
  24 +int DataID, RecID, VarID, StartID, StopID;
  25 +size_t RecNum;
  26 +char StartT[TIMELENGTH], StopT[TIMELENGTH], Var[128];
  27 +size_t count[2] = {1L,TIMELENGTH};
  28 +size_t start[2] = {0L,0L};
  29 +size_t countVar[2] = {1L,128L};
  30 +
  31 +/*---------------- NC ERROR --------------------------------------*/
  32 +void nc_handle_error(int status)
  33 +{
  34 + fprintf(stderr, "%s\n", nc_strerror(status));
  35 + exit(1);
  36 +}
  37 +
  38 +/* ----------------------- MAIN ------------------------------------*/
  39 + int main(int argc, char *argv[])
  40 +{
  41 +
  42 + int status, len;
  43 +
  44 + char Project[50],Instrument[50],Mode[50], RInstrName[100];
  45 +
  46 +
  47 + if (argc < 3)
  48 + {
  49 + fprintf(stderr,"Usage: StartStop reference_file_name DD_VI_ID\n");
  50 + exit(0);
  51 + }
  52 +
  53 +
  54 + if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR)
  55 + nc_handle_error(status);
  56 +
  57 + sscanf(argv[2], "%[^:]%*c%[^:]%*c%[^:]%*c",Project,
  58 + Instrument,
  59 + Mode);
  60 + sprintf(RInstrName,"%s_%s_%s\0",Project,Instrument,Mode);
  61 +
  62 + if ((status = nc_inq_varid(DataID,RInstrName,&VarID)) != NC_NOERR)
  63 + nc_handle_error(status);
  64 +
  65 + start[0] = 1;
  66 + if((status = nc_get_vara_text(DataID, VarID, start, countVar, Var)) != NC_NOERR)
  67 + nc_handle_error(status);
  68 +
  69 + len = strcspn(Var," "); Var[len] = '\0';
  70 +
  71 + if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status);
  72 +
  73 +// Open VI_times.nc
  74 +
  75 + if ((status = nc_open(Var, NC_NOWRITE, &DataID)) != NC_NOERR)
  76 + nc_handle_error(status);
  77 +
  78 + if ((status = nc_inq_dimid(DataID, "record", &RecID)) != NC_NOERR)
  79 + nc_handle_error(status);
  80 +
  81 +// Get Number of Records
  82 +
  83 + if ((status = nc_inq_dimlen(DataID, RecID, &RecNum)) != NC_NOERR)
  84 + nc_handle_error(status);
  85 +
  86 + if ((status = nc_inq_varid(DataID, "StartTime", &StartID)) != NC_NOERR)
  87 + nc_handle_error(status);
  88 + if ((status = nc_inq_varid(DataID, "StopTime", &StopID)) != NC_NOERR)
  89 + nc_handle_error(status);
  90 +
  91 +// Get The First Start and The Last Stop Times
  92 + start[0] = 0;
  93 +
  94 + if((status = nc_get_vara_text(DataID, StartID, start, count, StartT)) != NC_NOERR)
  95 + nc_handle_error(status);
  96 +
  97 + start[0] = RecNum-1;
  98 + if((status = nc_get_vara_text(DataID, StopID, start, count, StopT)) != NC_NOERR)
  99 + nc_handle_error(status);
  100 +
  101 + printf("%s-%s\n", StartT, StopT);
  102 + if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status);
  103 +
  104 +}
... ...
src/DECODERS/cdf2nc/cdf2nc.c
... ... @@ -503,6 +503,7 @@ void get_cdf_attr_data (char *attrName, /* in - attribute name */
503 503  
504 504 switch (datatype) {
505 505 case CDF_CHAR:
  506 + case CDF_UCHAR:
506 507 cPtr = (char *) malloc(numElements * sizeof(char) + 1);
507 508 if (cPtr == NULL) memory_error("get_cdf_attr_data", "NC_CHAR");
508 509 status = CDFlib (GET_, entryData, cPtr, NULL_);
... ... @@ -534,7 +535,6 @@ void get_cdf_attr_data (char *attrName, /* in - attribute name */
534 535 break;
535 536  
536 537 case CDF_INT2:
537   - case CDF_UCHAR:
538 538 case CDF_UINT1:
539 539 sPtr = (short *) malloc (sizeof(short) * numElements);
540 540 if (sPtr == NULL) memory_error("get_cdf_attr_data", "NC_SHORT");
... ...
src/REMOTEDATA/CDAWEB.php
... ... @@ -449,7 +449,7 @@ class CDAWEB extends RemoteDataCenterClass
449 449 if (file_exists("NumericalData.html")) rename("NumericalData.html","NumericalData.html.bak");
450 450 // exec("wget -O NumericalData.html ".CDAWebConfigClass::$spaseRegistry);
451 451 //TODO errors
452   - copy("NumericalData.html", CDAWebConfigClass::$spaseRegistry);
  452 + copy(CDAWebConfigClass::$spaseRegistry, "NumericalData.html");
453 453  
454 454 $html = file_get_html('NumericalData.html');
455 455 $ids = $html->find('td[class="Spase.URL.ProductID"]');
... ... @@ -583,13 +583,23 @@ class CDAWEB extends RemoteDataCenterClass
583 583 system("cdf2nc $file");
584 584 $ncFile = str_replace(".cdf", ".nc", $file);
585 585  
586   -// if (!file_exists($ncFile))
587   -// exit(" NO nc file $ncFile");
  586 + if (!file_exists($ncFile)) return false;
588 587 unlink($file);
589 588  
590 589 return $ncFile;
591 590 }
592 591  
  592 + public function getDatasetInfo($ds)
  593 + {
  594 + $masterCdf = strtolower($ds)."_00000000_v01.cdf";
  595 + $localCdf = strtolower($ds).".cdf";
  596 +
  597 + if (!copy(CDAWebConfigClass::$masterUrl."/".$masterCdf, strtolower($ds).".cdf")) return false;
  598 +
  599 + $infoFile = $this->convert2nc($localCdf);
  600 +
  601 + return $infoFile;
  602 + }
593 603 protected function setDataCenterAttributes(){}
594 604 protected function makeArgumentsList(){}
595 605 }
... ...
src/REMOTEDATA/RemoteDataCenterClass.php
... ... @@ -16,7 +16,7 @@ abstract class RemoteDataCenterClass
16 16 public $additionalArgs = null;
17 17 public $templateFile, $plotSettings;
18 18 public $baseID = null;
19   -
  19 +
20 20 public $tree = null;
21 21  
22 22 public static $MAX_NAME_LENGTH = 31;
... ... @@ -48,7 +48,7 @@ abstract class RemoteDataCenterClass
48 48 abstract protected function setDataCenterAttributes();
49 49 abstract protected function createMissionNodes();
50 50 abstract protected function makeArgumentsList();
51   -
  51 +// abstract public function getDatasetInfo($ds);
52 52 // abstract public function getData($ds, $start, $stop);
53 53 // abstract protected function convert2nc();
54 54 // abstract protected function createDatasetNodes();
... ...