diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d5ffb4..a612331 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ add_subdirectory(src/DECODERS/themis/esamom2nc) add_subdirectory(src/DECODERS/themis/fgm2nc) add_subdirectory(src/DECODERS/themis/sst2nc) add_subdirectory(src/DATA/TOOLS) +add_subdirectory(src/DDSERVICES/TOOLS) add_subdirectory(tests) install(FILES "scripts/StartServer" DESTINATION . PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) @@ -58,5 +59,7 @@ install(FILES "scripts/UpdateInfoVI.sh" DESTINATION . PERMISSIONS OWNER_READ OWN install(DIRECTORY "src/CALLEXT/" DESTINATION bin/CALLEXT) install(DIRECTORY "src/DATA/MANAGER/" DESTINATION bin/DATAMANAGER) install(DIRECTORY "src/REMOTEDATA/" DESTINATION bin/REMOTEDATA) +install(DIRECTORY "src/DDSERVICES/SOAP/" DESTINATION DDService) +install(DIRECTORY "src/DDSERVICES/REST/" DESTINATION DDService) SET(CMAKE_VERBOSE_MAKEFILE ON) diff --git a/src/DATA/MANAGER/RemoveVI.php b/src/DATA/MANAGER/RemoveVI.php index 83bf40b..c2f79cb 100644 --- a/src/DATA/MANAGER/RemoveVI.php +++ b/src/DATA/MANAGER/RemoveVI.php @@ -4,7 +4,7 @@ * @file RemoveVI.php * @version $Id: RemoveVI.php 14 2013-09-23 11:23:28Z elena $ * @brief DD Server Tools: -* @arg ViID , [BaseID] +* @arg ViID [ BaseID ] */ if (!function_exists('__autoload')) { diff --git a/src/DATA/TOOLS/StartStop.c b/src/DATA/TOOLS/StartStop.c deleted file mode 100644 index d58a329..0000000 --- a/src/DATA/TOOLS/StartStop.c +++ /dev/null @@ -1,104 +0,0 @@ - -/** @file StartStop.c -* @brief Stand-alone executable <br> Returns real Start-Stop for VI in DDBase <br> -* Is used in DD Server WebServices <br> -* @details StartStop(string *, string *) <br> -* @arg \c argv[1] Full name of DDBase reference file <br> -* @arg \c argv[2] Virtual Instrument ID (DD notation) <br> -* Output: YYYYDDdayHHMMSSMLS-YYYYDDdayHHMMSSMLS -* -* @date 10.10.2007 -* @version $Id: StartStop.c,v 1.3 2011/09/05 11:27:34 budnik Exp $ -*/ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <math.h> -#include <netcdf.h> -#include <DD.h> - - -int DataID, RecID, VarID, StartID, StopID; -size_t RecNum; -char StartT[TIMELENGTH], StopT[TIMELENGTH], Var[128]; -size_t count[2] = {1L,TIMELENGTH}; -size_t start[2] = {0L,0L}; -size_t countVar[2] = {1L,128L}; - -/*---------------- NC ERROR --------------------------------------*/ -void nc_handle_error(int status) -{ - fprintf(stderr, "%s\n", nc_strerror(status)); - exit(1); -} - -/* ----------------------- MAIN ------------------------------------*/ - int main(int argc, char *argv[]) -{ - - int status, len; - - char Project[50],Instrument[50],Mode[50], RInstrName[100]; - - - if (argc < 3) - { - fprintf(stderr,"Usage: StartStop reference_file_name DD_VI_ID\n"); - exit(0); - } - - - if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR) - nc_handle_error(status); - - sscanf(argv[2], "%[^:]%*c%[^:]%*c%[^:]%*c",Project, - Instrument, - Mode); - sprintf(RInstrName,"%s_%s_%s\0",Project,Instrument,Mode); - - if ((status = nc_inq_varid(DataID,RInstrName,&VarID)) != NC_NOERR) - nc_handle_error(status); - - start[0] = 1; - if((status = nc_get_vara_text(DataID, VarID, start, countVar, Var)) != NC_NOERR) - nc_handle_error(status); - - len = strcspn(Var," "); Var[len] = '\0'; - - if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); - -// Open VI_times.nc - - if ((status = nc_open(Var, NC_NOWRITE, &DataID)) != NC_NOERR) - nc_handle_error(status); - - if ((status = nc_inq_dimid(DataID, "record", &RecID)) != NC_NOERR) - nc_handle_error(status); - -// Get Number of Records - - if ((status = nc_inq_dimlen(DataID, RecID, &RecNum)) != NC_NOERR) - nc_handle_error(status); - - if ((status = nc_inq_varid(DataID, "StartTime", &StartID)) != NC_NOERR) - nc_handle_error(status); - if ((status = nc_inq_varid(DataID, "StopTime", &StopID)) != NC_NOERR) - nc_handle_error(status); - -// Get The First Start and The Last Stop Times - start[0] = 0; - - if((status = nc_get_vara_text(DataID, StartID, start, count, StartT)) != NC_NOERR) - nc_handle_error(status); - - start[0] = RecNum-1; - if((status = nc_get_vara_text(DataID, StopID, start, count, StopT)) != NC_NOERR) - nc_handle_error(status); - - printf("%s-%s\n", StartT, StopT); - if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); - -} diff --git a/src/DDSERVICES/SOAP/src/GetFileNames.c b/src/DDSERVICES/SOAP/src/GetFileNames.c deleted file mode 100644 index f8075b8..0000000 --- a/src/DDSERVICES/SOAP/src/GetFileNames.c +++ /dev/null @@ -1,127 +0,0 @@ -/* $Id: GetFileNames.c,v 1.2 2008/06/16 12:11:58 elena Exp $ */ - -/** -* @file GetFileNames.c -* @brief Print File names -* @arg dataSetID, StartTime, StopTime -* -* -*/ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <math.h> -#include <netcdf.h> -#include <DD.h> - - -#define NAME_LENGTH 100 -#define NAME_DIM 32L - -int DataID, RecID, StartID, StopID, NameID;; -size_t RecNum; -char StartT[TIMELENGTH], StopT[TIMELENGTH]; -size_t count[2] = {1L,TIMELENGTH}; -size_t start[2] = {0L,0L}; -size_t NameCount[2] = {1, NAME_DIM}; -double StartTime, StopTime; -char Name[NAME_LENGTH]; - -/*---------------- NC ERROR --------------------------------------*/ -void nc_handle_error(int status) -{ - fprintf(stderr, "%s\n", nc_strerror(status)); - exit(1); -} - -/* ----------------------- MAIN ------------------------------------*/ - int main(int argc, char *argv[]) -{ - - int status, len, StartRecord, StopRecord; - int i, hi, lo = 0; - double StartD0, StartD1 = 0.0, StopD0, StopD1; - - if (argc < 4) - { - fprintf(stderr,"Usage: GetFileNames ViId StartTime StopTime\n"); - exit(0); - } - -/* find VI in reference file */ - - - StartTime = atof(argv[2]); - StopTime = atof(argv[3]); - -/* Open VI_times.nc */ - - if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR) - nc_handle_error(status); - - if ((status = nc_inq_dimid(DataID, "record", &RecID)) != NC_NOERR) - nc_handle_error(status); - -/* Get Number of Records */ - - if ((status = nc_inq_dimlen(DataID, RecID, &RecNum)) != NC_NOERR) - nc_handle_error(status); - - if ((status = nc_inq_varid(DataID, "StartTime", &StartID)) != NC_NOERR) - nc_handle_error(status); - if ((status = nc_inq_varid(DataID, "StopTime", &StopID)) != NC_NOERR) - nc_handle_error(status); - - if ((status = nc_inq_varid(DataID, "FileName", &NameID)) != NC_NOERR) - nc_handle_error(status); -/* Get The First Start and The Last Stop Times */ - start[0] = 0; - - if((status = nc_get_vara_text(DataID, StartID, start, count, StartT)) != NC_NOERR) - nc_handle_error(status); - - start[0] = RecNum-1; - if((status = nc_get_vara_text(DataID, StopID, start, count, StopT)) != NC_NOERR) - nc_handle_error(status); - - if (StartTime > DD_Time2Double(StopT) || StopTime < DD_Time2Double(StartT)) - { - fprintf(stdout, "OUTOFTIME\0"); - nc_close(DataID); - exit(0); - } - - hi = RecNum; - - /* Find Start Record */ - while (lo < hi) - { - i = (lo+hi)/2; - start[0] = i + 1; - status = nc_get_vara_text(DataID,StartID,start,count,(char *)StartT); - StartD1 = DD_Time2Double(StartT); - if (StartD1 > StartTime) hi--; - start[0] = i; - status = nc_get_vara_text(DataID,StartID,start,count,(char *)StartT); - StartD0 = DD_Time2Double(StartT); - if (StartD0 < StartTime) lo++; - if (StartD1 <= StartTime && StartD0 >= StartTime) break; - } - status = nc_get_vara_text(DataID, NameID, start, NameCount,(char *)Name); - fprintf(stdout, "%s;",Name); - status = nc_get_vara_text(DataID,StopID,start,count,(char *)StopT); - StopD0 = DD_Time2Double(StopT); - - while (StopTime > StopD0 && start[0] <= RecNum) { - status = nc_get_vara_text(DataID,StopID,start,count,(char *)StopT); - status = nc_get_vara_text(DataID, NameID, start, NameCount,(char *)Name); - if (start[0] > i) fprintf(stdout, "%s;", Name); - StopD0 = DD_Time2Double(StopT); - start[0]++; - } - - nc_close(DataID); - -} diff --git a/src/DDSERVICES/SOAP/src/GetInfo.c b/src/DDSERVICES/SOAP/src/GetInfo.c deleted file mode 100644 index cc6676a..0000000 --- a/src/DDSERVICES/SOAP/src/GetInfo.c +++ /dev/null @@ -1,102 +0,0 @@ - -/** @file GetInfo.c -* @version $Id: GetInfo.c,v 1.1 2013/05/22 13:33:52 budnik Exp $ -*/ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <math.h> -#include <netcdf.h> -#include <DD.h> - - -int DataID, RecID, VarID; -size_t RecNum; -char Var[128]; -size_t count[2] = {1L,TIMELENGTH}; -size_t start[2] = {0L,0L}; -size_t countVar[2] = {1L,128L}; - -/*---------------- NC ERROR --------------------------------------*/ -void nc_handle_error(int status) -{ - fprintf(stderr, "%s\n", nc_strerror(status)); - exit(1); -} - -/* ----------------------- MAIN ------------------------------------*/ - int main(int argc, char *argv[]) -{ - - int status, len, infoID, i; - - char Project[50],Instrument[50],Mode[50], RInstrName[100], INFO_ID[50]; - int dims[10]; - size_t lenp, total_length; - float *value; - int ndimsp; - - if (argc < 4) - { - fprintf(stderr,"Usage: GetInfo reference_file_name VI_ID INFO_ID\n"); - exit(0); - } - - - if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR) - nc_handle_error(status); - - sscanf(argv[2], "%[^:]%*c%[^:]%*c%[^:]%*c",Project, - Instrument, - Mode); - - sprintf(RInstrName,"%s_%s_%s\0",Project,Instrument,Mode); - sprintf(INFO_ID,"%s\0",argv[3]); - - if ((status = nc_inq_varid(DataID,RInstrName,&VarID)) != NC_NOERR) - nc_handle_error(status); - - start[0] = 2; - if((status = nc_get_vara_text(DataID, VarID, start, countVar, Var)) != NC_NOERR) - nc_handle_error(status); - - len = strcspn(Var," "); Var[len] = '\0'; - - if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); - -// Open VI_info.nc - - if ((status = nc_open(Var, NC_NOWRITE, &DataID)) != NC_NOERR) - nc_handle_error(status); - - -// Get Number of Records - - - if ((status = nc_inq_varid(DataID, INFO_ID, &infoID)) != NC_NOERR) - nc_handle_error(status); - - if ((status = nc_inq_varndims(DataID, infoID, &ndimsp)) != NC_NOERR) - nc_handle_error(status); - - if ((status = nc_inq_vardimid(DataID, infoID, &dims)) != NC_NOERR) - nc_handle_error(status); - total_length = 0; - for ( i = 0; i < ndimsp; i++) { - if ((status = nc_inq_dimlen (DataID, dims[i], &lenp))!= NC_NOERR) - nc_handle_error(status); - total_length += lenp; - } - value = malloc(total_length*sizeof(float)); - - if ((status =nc_get_var_float(DataID, infoID, value)) != NC_NOERR) - nc_handle_error(status); - printf("%f", value[0]); - for (i = 1; i < lenp; i++) printf(";%f", value[i]); - - if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); - -} diff --git a/src/DDSERVICES/SOAP/src/Makefile b/src/DDSERVICES/SOAP/src/Makefile deleted file mode 100755 index 754b434..0000000 --- a/src/DDSERVICES/SOAP/src/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -#----------------------------------------------------- -# MAKEFILE for DD SERVER Services -#--------------------------------------------------------- - -EXE = StartStop GetFileNames GetInfo - -lib: $(EXE) - -install: - install -d -m a+rx,ug+w ../bin - cp $(EXE) ../bin - -clean: - tag="*.o" ${EXE};\ - for file in $$tag; do \ - echo $$file; rm -f $$file;\ - done - find -name \*~ -delete - -deinstall: - echo "Do nothing" - -StartStop: StartStop.c - ${CC} ${CFLAGS} -o StartStop StartStop.c ${INC} ${LIB} -lnetcdf - -GetInfo: GetInfo.c - ${CC} ${CFLAGS} -o GetInfo GetInfo.c ${INC} ${LIB} -lnetcdf - -GetFileNames: GetFileNames.c - ${CC} ${CFLAGS} -o GetFileNames GetFileNames.c ${INC} ${LIB} -lnetcdf -lDD diff --git a/src/DDSERVICES/SOAP/src/StartStop.c b/src/DDSERVICES/SOAP/src/StartStop.c deleted file mode 100644 index d58a329..0000000 --- a/src/DDSERVICES/SOAP/src/StartStop.c +++ /dev/null @@ -1,104 +0,0 @@ - -/** @file StartStop.c -* @brief Stand-alone executable <br> Returns real Start-Stop for VI in DDBase <br> -* Is used in DD Server WebServices <br> -* @details StartStop(string *, string *) <br> -* @arg \c argv[1] Full name of DDBase reference file <br> -* @arg \c argv[2] Virtual Instrument ID (DD notation) <br> -* Output: YYYYDDdayHHMMSSMLS-YYYYDDdayHHMMSSMLS -* -* @date 10.10.2007 -* @version $Id: StartStop.c,v 1.3 2011/09/05 11:27:34 budnik Exp $ -*/ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <math.h> -#include <netcdf.h> -#include <DD.h> - - -int DataID, RecID, VarID, StartID, StopID; -size_t RecNum; -char StartT[TIMELENGTH], StopT[TIMELENGTH], Var[128]; -size_t count[2] = {1L,TIMELENGTH}; -size_t start[2] = {0L,0L}; -size_t countVar[2] = {1L,128L}; - -/*---------------- NC ERROR --------------------------------------*/ -void nc_handle_error(int status) -{ - fprintf(stderr, "%s\n", nc_strerror(status)); - exit(1); -} - -/* ----------------------- MAIN ------------------------------------*/ - int main(int argc, char *argv[]) -{ - - int status, len; - - char Project[50],Instrument[50],Mode[50], RInstrName[100]; - - - if (argc < 3) - { - fprintf(stderr,"Usage: StartStop reference_file_name DD_VI_ID\n"); - exit(0); - } - - - if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR) - nc_handle_error(status); - - sscanf(argv[2], "%[^:]%*c%[^:]%*c%[^:]%*c",Project, - Instrument, - Mode); - sprintf(RInstrName,"%s_%s_%s\0",Project,Instrument,Mode); - - if ((status = nc_inq_varid(DataID,RInstrName,&VarID)) != NC_NOERR) - nc_handle_error(status); - - start[0] = 1; - if((status = nc_get_vara_text(DataID, VarID, start, countVar, Var)) != NC_NOERR) - nc_handle_error(status); - - len = strcspn(Var," "); Var[len] = '\0'; - - if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); - -// Open VI_times.nc - - if ((status = nc_open(Var, NC_NOWRITE, &DataID)) != NC_NOERR) - nc_handle_error(status); - - if ((status = nc_inq_dimid(DataID, "record", &RecID)) != NC_NOERR) - nc_handle_error(status); - -// Get Number of Records - - if ((status = nc_inq_dimlen(DataID, RecID, &RecNum)) != NC_NOERR) - nc_handle_error(status); - - if ((status = nc_inq_varid(DataID, "StartTime", &StartID)) != NC_NOERR) - nc_handle_error(status); - if ((status = nc_inq_varid(DataID, "StopTime", &StopID)) != NC_NOERR) - nc_handle_error(status); - -// Get The First Start and The Last Stop Times - start[0] = 0; - - if((status = nc_get_vara_text(DataID, StartID, start, count, StartT)) != NC_NOERR) - nc_handle_error(status); - - start[0] = RecNum-1; - if((status = nc_get_vara_text(DataID, StopID, start, count, StopT)) != NC_NOERR) - nc_handle_error(status); - - printf("%s-%s\n", StartT, StopT); - if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); - -} diff --git a/src/DDSERVICES/TOOLS/CMakeLists.txt b/src/DDSERVICES/TOOLS/CMakeLists.txt new file mode 100644 index 0000000..ed3f630 --- /dev/null +++ b/src/DDSERVICES/TOOLS/CMakeLists.txt @@ -0,0 +1,20 @@ + +PROJECT(DDSERVICS_SOAP_TOOLS) + +include_directories( + ${DDCLIENTINCLUDE_DIR} + ${NETCDFINCLUDE_DIR} + ${LIBXML2_INCLUDE_DIR} +) + +#Configuration de l'exécutable + +file( GLOB SOURCE_FILES ./*.c ) + +foreach( sourcefile ${SOURCE_FILES} ) + get_filename_component( source ${sourcefile} NAME) + string( REPLACE ".c" "" exefile ${source} ) + add_executable( ${exefile} ${source} ) + target_link_libraries( ${exefile} ${DDCLIENTLIBRARY} ${NETCDFLIBRARY} ${LIBXML2_LIBRARIES}) + install (TARGETS ${exefile} DESTINATION bin) +endforeach( sourcefile ${SOURCE_FILE} ) diff --git a/src/DDSERVICES/TOOLS/GetFileNames.c b/src/DDSERVICES/TOOLS/GetFileNames.c new file mode 100644 index 0000000..f8075b8 --- /dev/null +++ b/src/DDSERVICES/TOOLS/GetFileNames.c @@ -0,0 +1,127 @@ +/* $Id: GetFileNames.c,v 1.2 2008/06/16 12:11:58 elena Exp $ */ + +/** +* @file GetFileNames.c +* @brief Print File names +* @arg dataSetID, StartTime, StopTime +* +* +*/ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <time.h> +#include <math.h> +#include <netcdf.h> +#include <DD.h> + + +#define NAME_LENGTH 100 +#define NAME_DIM 32L + +int DataID, RecID, StartID, StopID, NameID;; +size_t RecNum; +char StartT[TIMELENGTH], StopT[TIMELENGTH]; +size_t count[2] = {1L,TIMELENGTH}; +size_t start[2] = {0L,0L}; +size_t NameCount[2] = {1, NAME_DIM}; +double StartTime, StopTime; +char Name[NAME_LENGTH]; + +/*---------------- NC ERROR --------------------------------------*/ +void nc_handle_error(int status) +{ + fprintf(stderr, "%s\n", nc_strerror(status)); + exit(1); +} + +/* ----------------------- MAIN ------------------------------------*/ + int main(int argc, char *argv[]) +{ + + int status, len, StartRecord, StopRecord; + int i, hi, lo = 0; + double StartD0, StartD1 = 0.0, StopD0, StopD1; + + if (argc < 4) + { + fprintf(stderr,"Usage: GetFileNames ViId StartTime StopTime\n"); + exit(0); + } + +/* find VI in reference file */ + + + StartTime = atof(argv[2]); + StopTime = atof(argv[3]); + +/* Open VI_times.nc */ + + if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR) + nc_handle_error(status); + + if ((status = nc_inq_dimid(DataID, "record", &RecID)) != NC_NOERR) + nc_handle_error(status); + +/* Get Number of Records */ + + if ((status = nc_inq_dimlen(DataID, RecID, &RecNum)) != NC_NOERR) + nc_handle_error(status); + + if ((status = nc_inq_varid(DataID, "StartTime", &StartID)) != NC_NOERR) + nc_handle_error(status); + if ((status = nc_inq_varid(DataID, "StopTime", &StopID)) != NC_NOERR) + nc_handle_error(status); + + if ((status = nc_inq_varid(DataID, "FileName", &NameID)) != NC_NOERR) + nc_handle_error(status); +/* Get The First Start and The Last Stop Times */ + start[0] = 0; + + if((status = nc_get_vara_text(DataID, StartID, start, count, StartT)) != NC_NOERR) + nc_handle_error(status); + + start[0] = RecNum-1; + if((status = nc_get_vara_text(DataID, StopID, start, count, StopT)) != NC_NOERR) + nc_handle_error(status); + + if (StartTime > DD_Time2Double(StopT) || StopTime < DD_Time2Double(StartT)) + { + fprintf(stdout, "OUTOFTIME\0"); + nc_close(DataID); + exit(0); + } + + hi = RecNum; + + /* Find Start Record */ + while (lo < hi) + { + i = (lo+hi)/2; + start[0] = i + 1; + status = nc_get_vara_text(DataID,StartID,start,count,(char *)StartT); + StartD1 = DD_Time2Double(StartT); + if (StartD1 > StartTime) hi--; + start[0] = i; + status = nc_get_vara_text(DataID,StartID,start,count,(char *)StartT); + StartD0 = DD_Time2Double(StartT); + if (StartD0 < StartTime) lo++; + if (StartD1 <= StartTime && StartD0 >= StartTime) break; + } + status = nc_get_vara_text(DataID, NameID, start, NameCount,(char *)Name); + fprintf(stdout, "%s;",Name); + status = nc_get_vara_text(DataID,StopID,start,count,(char *)StopT); + StopD0 = DD_Time2Double(StopT); + + while (StopTime > StopD0 && start[0] <= RecNum) { + status = nc_get_vara_text(DataID,StopID,start,count,(char *)StopT); + status = nc_get_vara_text(DataID, NameID, start, NameCount,(char *)Name); + if (start[0] > i) fprintf(stdout, "%s;", Name); + StopD0 = DD_Time2Double(StopT); + start[0]++; + } + + nc_close(DataID); + +} diff --git a/src/DDSERVICES/TOOLS/GetInfo.c b/src/DDSERVICES/TOOLS/GetInfo.c new file mode 100644 index 0000000..cc6676a --- /dev/null +++ b/src/DDSERVICES/TOOLS/GetInfo.c @@ -0,0 +1,102 @@ + +/** @file GetInfo.c +* @version $Id: GetInfo.c,v 1.1 2013/05/22 13:33:52 budnik Exp $ +*/ + + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <time.h> +#include <math.h> +#include <netcdf.h> +#include <DD.h> + + +int DataID, RecID, VarID; +size_t RecNum; +char Var[128]; +size_t count[2] = {1L,TIMELENGTH}; +size_t start[2] = {0L,0L}; +size_t countVar[2] = {1L,128L}; + +/*---------------- NC ERROR --------------------------------------*/ +void nc_handle_error(int status) +{ + fprintf(stderr, "%s\n", nc_strerror(status)); + exit(1); +} + +/* ----------------------- MAIN ------------------------------------*/ + int main(int argc, char *argv[]) +{ + + int status, len, infoID, i; + + char Project[50],Instrument[50],Mode[50], RInstrName[100], INFO_ID[50]; + int dims[10]; + size_t lenp, total_length; + float *value; + int ndimsp; + + if (argc < 4) + { + fprintf(stderr,"Usage: GetInfo reference_file_name VI_ID INFO_ID\n"); + exit(0); + } + + + if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR) + nc_handle_error(status); + + sscanf(argv[2], "%[^:]%*c%[^:]%*c%[^:]%*c",Project, + Instrument, + Mode); + + sprintf(RInstrName,"%s_%s_%s\0",Project,Instrument,Mode); + sprintf(INFO_ID,"%s\0",argv[3]); + + if ((status = nc_inq_varid(DataID,RInstrName,&VarID)) != NC_NOERR) + nc_handle_error(status); + + start[0] = 2; + if((status = nc_get_vara_text(DataID, VarID, start, countVar, Var)) != NC_NOERR) + nc_handle_error(status); + + len = strcspn(Var," "); Var[len] = '\0'; + + if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); + +// Open VI_info.nc + + if ((status = nc_open(Var, NC_NOWRITE, &DataID)) != NC_NOERR) + nc_handle_error(status); + + +// Get Number of Records + + + if ((status = nc_inq_varid(DataID, INFO_ID, &infoID)) != NC_NOERR) + nc_handle_error(status); + + if ((status = nc_inq_varndims(DataID, infoID, &ndimsp)) != NC_NOERR) + nc_handle_error(status); + + if ((status = nc_inq_vardimid(DataID, infoID, &dims)) != NC_NOERR) + nc_handle_error(status); + total_length = 0; + for ( i = 0; i < ndimsp; i++) { + if ((status = nc_inq_dimlen (DataID, dims[i], &lenp))!= NC_NOERR) + nc_handle_error(status); + total_length += lenp; + } + value = malloc(total_length*sizeof(float)); + + if ((status =nc_get_var_float(DataID, infoID, value)) != NC_NOERR) + nc_handle_error(status); + printf("%f", value[0]); + for (i = 1; i < lenp; i++) printf(";%f", value[i]); + + if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); + +} diff --git a/src/DDSERVICES/TOOLS/StartStop.c b/src/DDSERVICES/TOOLS/StartStop.c new file mode 100644 index 0000000..d58a329 --- /dev/null +++ b/src/DDSERVICES/TOOLS/StartStop.c @@ -0,0 +1,104 @@ + +/** @file StartStop.c +* @brief Stand-alone executable <br> Returns real Start-Stop for VI in DDBase <br> +* Is used in DD Server WebServices <br> +* @details StartStop(string *, string *) <br> +* @arg \c argv[1] Full name of DDBase reference file <br> +* @arg \c argv[2] Virtual Instrument ID (DD notation) <br> +* Output: YYYYDDdayHHMMSSMLS-YYYYDDdayHHMMSSMLS +* +* @date 10.10.2007 +* @version $Id: StartStop.c,v 1.3 2011/09/05 11:27:34 budnik Exp $ +*/ + + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <time.h> +#include <math.h> +#include <netcdf.h> +#include <DD.h> + + +int DataID, RecID, VarID, StartID, StopID; +size_t RecNum; +char StartT[TIMELENGTH], StopT[TIMELENGTH], Var[128]; +size_t count[2] = {1L,TIMELENGTH}; +size_t start[2] = {0L,0L}; +size_t countVar[2] = {1L,128L}; + +/*---------------- NC ERROR --------------------------------------*/ +void nc_handle_error(int status) +{ + fprintf(stderr, "%s\n", nc_strerror(status)); + exit(1); +} + +/* ----------------------- MAIN ------------------------------------*/ + int main(int argc, char *argv[]) +{ + + int status, len; + + char Project[50],Instrument[50],Mode[50], RInstrName[100]; + + + if (argc < 3) + { + fprintf(stderr,"Usage: StartStop reference_file_name DD_VI_ID\n"); + exit(0); + } + + + if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR) + nc_handle_error(status); + + sscanf(argv[2], "%[^:]%*c%[^:]%*c%[^:]%*c",Project, + Instrument, + Mode); + sprintf(RInstrName,"%s_%s_%s\0",Project,Instrument,Mode); + + if ((status = nc_inq_varid(DataID,RInstrName,&VarID)) != NC_NOERR) + nc_handle_error(status); + + start[0] = 1; + if((status = nc_get_vara_text(DataID, VarID, start, countVar, Var)) != NC_NOERR) + nc_handle_error(status); + + len = strcspn(Var," "); Var[len] = '\0'; + + if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); + +// Open VI_times.nc + + if ((status = nc_open(Var, NC_NOWRITE, &DataID)) != NC_NOERR) + nc_handle_error(status); + + if ((status = nc_inq_dimid(DataID, "record", &RecID)) != NC_NOERR) + nc_handle_error(status); + +// Get Number of Records + + if ((status = nc_inq_dimlen(DataID, RecID, &RecNum)) != NC_NOERR) + nc_handle_error(status); + + if ((status = nc_inq_varid(DataID, "StartTime", &StartID)) != NC_NOERR) + nc_handle_error(status); + if ((status = nc_inq_varid(DataID, "StopTime", &StopID)) != NC_NOERR) + nc_handle_error(status); + +// Get The First Start and The Last Stop Times + start[0] = 0; + + if((status = nc_get_vara_text(DataID, StartID, start, count, StartT)) != NC_NOERR) + nc_handle_error(status); + + start[0] = RecNum-1; + if((status = nc_get_vara_text(DataID, StopID, start, count, StopT)) != NC_NOERR) + nc_handle_error(status); + + printf("%s-%s\n", StartT, StopT); + if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); + +} diff --git a/src/REMOTEDATA/CDAWEB.php b/src/REMOTEDATA/CDAWEB.php index 786a314..64da79f 100644 --- a/src/REMOTEDATA/CDAWEB.php +++ b/src/REMOTEDATA/CDAWEB.php @@ -12,6 +12,7 @@ class CDAWEB extends RemoteDataCenterClass private $observatoryGroups, $instrumentTypes; private $CDAWEB = array(), $masterCDF = array(); + private $header; // https://cdaweb.gsfc.nasa.gov/WS/cdasr/1/dataviews/sp_phys/instrumentTypes private $validInstrumentTypes = [ "Activity%20Indices", "Electric%20Fields%20(space)","Gamma%20and%20X-Rays", @@ -38,7 +39,10 @@ class CDAWEB extends RemoteDataCenterClass } public function init() - { + { + + error_log("CDAWEB Proxy creation on ".date("Y-m-d").PHP_EOL,3,log); + $this->getAllSpaseDatasets(); } @@ -127,10 +131,7 @@ class CDAWEB extends RemoteDataCenterClass $this->obsGroupsIds[$insType][$obsGroupId] = $obsIds; } - } - - // print_r($this->obsGroupsIds); - // $this->closeConnection(); + } } protected function getDatasetByObservatoryAndInstrument($obsGroupId, $obsId, $insId) @@ -139,19 +140,22 @@ class CDAWEB extends RemoteDataCenterClass $grpEncodedId = $this->html_encode($obsGroupId); $insEncodedId = $this->html_encode($insId); + $obsEncodedId = $this->html_encode($obsId); $res = new DomDocument("1.0"); - curl_setopt($this->ch, CURLOPT_URL, $this->dataViewURL."/datasets?observatoryGroup=$grpEncodedId&instrument=$insEncodedId"); + // curl_setopt($this->ch, CURLOPT_URL, $this->dataViewURL."/datasets?observatoryGroup=$grpEncodedId&instrument=$insEncodedId"); + + curl_setopt($this->ch, CURLOPT_URL, $this->dataViewURL."/datasets?observatory=$obsEncodedId&instrument=$insEncodedId"); $res->loadXML(curl_exec($this->ch)); -// $this->res->save('dataset.xml'); -// exit(); +exit ($res->saveXML()); + $datasets = $res->getElementsByTagName('DatasetDescription'); $dsIds = array(); foreach ( $datasets as $ds) { - $obs = $ds->getElementsByTagName('Observatory')->item(0)->nodeValue; + // $obs = $ds->getElementsByTagName('Observatory')->item(0)->nodeValue; if ($obs != $obsId ) continue; $dsIds[] = $ds->getElementsByTagName('Id')->item(0)->nodeValue; } @@ -159,132 +163,6 @@ class CDAWEB extends RemoteDataCenterClass return $dsIds; } - protected function createMissionNodes() - { - $missionNodes = array(); - $missionIds = array(); - // unique values - // $this->obsGroupsIds = array_map("unserialize", array_unique(array_map("serialize", $this->obsGroupsIds))); - - foreach ($this->obsGroupsIds as $groupId => $insTypes) - { - // echo ' GroupID '.$groupId.PHP_EOL; - $missionId = $this->baseID.":".$this->param2dd($groupId); - - if (!in_array($missionId, $missionIds)) - { - $missionNode = $this->domAmda->createElement('mission'); - $missionNode->setAttribute("xml:id",$missionId); - $missionNode->setAttribute("name",$groupId); - - $missionIds[] = $missionId; - $newNode = true; - } - else { - $key = array_search($missionId, $missionIds); - $missionNode = $missionNodes[$key]; - $newNode = false; - } - - foreach ($insTypes as $insType => $obss){ - // echo $insType.PHP_EOL; - - foreach ( $obss as $obs => $inss){ - // echo $obs.PHP_EOL; - // OMNI ONLY ONCE - if (substr($obs,0,4) == "OMNI" && substr($missionId,0,4) != "OMNI"){ - //echo ' '.$obs.' '.$missionId.PHP_EOL; - continue; - } - - if (file_exists(RemoteData."/".CDAWebConfigClass::$mapXML)) { - $obsAMDA = $this->alias(RemoteData."/".CDAWebConfigClass::$mapXML, $obs); - } - else { - $obsAMDA = $obs; - } - - $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsAMDA); - $obsNodes = $missionNode->getElementsByTagName('observatory'); - $newObsNode = true; - - foreach ($obsNodes as $node){ - $id = $node->getAttribute("xml:id"); - - if ($id == $obsId) { - $obsNode = $node; - $newObsNode = false; - break; - } - } - - if ( $newObsNode ){ - $obsNode = $this->createObservatoryNode($obs, $groupId); - } - - foreach ($inss as $ins => $dss){ - $insId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs).":".$this->param2dd($ins); - $insNodes = $obsNode->getElementsByTagName('instrument'); - $newInsNode = true; - - foreach ($insNodes as $node){ - $id = $node->getAttribute("xml:id"); - - if ($id == $insId) { - $insNode = $node; - $newInsNode = false; - break; - } - } - - if ( $newInsNode ) - $insNode = $this->createInstrumentNode($ins, $obs, $groupId); - - foreach ($dss as $ds){ - $dsId = $this->baseID.":".$ds; - $dsNodes = $insNode->getElementsByTagName('dataset'); - $newDsNode = true; - - foreach ($dsNodes as $node){ - $id = $node->getAttribute("xml:id"); - - if ($id == $dsId){ - $dsNode = $node; - $newDsNode = false; - break; - } - } - - if ($newDsNode) { - $this->initDDServerXml($ds,$ins,$obs); - - $dsNode = $this->createDatasetNode($ds); - if ($dsNode){ - $insNode->appendChild($dsNode); - $this->saveDDServerXml(); - } - } - } - - if ($newInsNode && $insNode->hasChildNodes()) - $obsNode->appendChild($insNode); - } - - if ($newObsNode && $obsNode->hasChildNodes()){ - $missionNode->appendChild($obsNode); - } - } - - } - - if ($newNode) - $missionNodes[] = $missionNode; - } - - return $missionNodes; - - } - protected function createObservatoryNode($id, $grpId) { @@ -447,7 +325,7 @@ class CDAWEB extends RemoteDataCenterClass $this->CDAWEB[$key[0]->innertext] = $ref[0]->innertext; } - echo "SPASE-defined CDAWEB datasets : ".count($this->CDAWEB).PHP_EOL; + echo "SPASE-defined CDAWEB datasets : ".count($this->CDAWEB).PHP_EOL; } protected function initDDServerXml($ds, $ins, $obs) @@ -706,6 +584,8 @@ class CDAWEB extends RemoteDataCenterClass } $first = false; } + + $this->closeConnection(); } protected function createMissionNode($groupId){ @@ -754,6 +634,7 @@ class CDAWEB extends RemoteDataCenterClass protected function setDataCenterAttributes(){} protected function makeArgumentsList(){} + } ?> diff --git a/src/REMOTEDATA/RemoteDataCenterClass.php b/src/REMOTEDATA/RemoteDataCenterClass.php index b35b821..7c19d5c 100644 --- a/src/REMOTEDATA/RemoteDataCenterClass.php +++ b/src/REMOTEDATA/RemoteDataCenterClass.php @@ -62,7 +62,6 @@ abstract class RemoteDataCenterClass abstract public function init(); abstract protected function getRemoteTree(); abstract protected function setDataCenterAttributes(); - abstract protected function createMissionNodes(); abstract protected function makeArgumentsList(); // abstract public function getDatasetInfo($ds); // abstract public function getData($ds, $start, $stop); @@ -110,11 +109,11 @@ abstract class RemoteDataCenterClass foreach ($missionNodes as $missionNode) $this->dataCenter->appendChild($missionNode); } - + protected function getIdFromSpase($spaseId) { - $temp = explode('/',$spaseId); - return $temp[count($temp)-1]; + $temp = explode('/',$spaseId); + return $temp[count($temp)-1]; } public function monitor() -- libgit2 0.21.2