From 531fafe75e1659897c30954b0085e2c976e9d582 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sun, 27 Aug 2017 17:36:11 +0200 Subject: [PATCH] Install AddLocalVI + some other tools with DDServer --- .gitignore | 3 ++- CMakeLists.txt | 16 ++++++++++++---- cmake/modules/FindCDF.cmake | 4 ++-- cmake/modules/FindLibXML2.cmake | 25 +++++++++++++++++++++++++ compil.sh | 9 +++++++++ scripts/AddLocalVI.sh | 8 ++++++++ scripts/DDServer.env.in | 9 +++++++++ scripts/StartServer | 11 +++++++++++ scripts/StartServer.in | 13 ------------- src/DATA/INFOLOCAL2NC/CMakeLists.txt | 26 ++++++++++++++++++++++++++ src/DATA/INFOLOCAL2NC/infoLocal2nc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DATA/JOIN_NC/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/DATA/JOIN_NC/join_nc.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DATA/MAKEDDSYS/CMakeLists.txt | 26 ++++++++++++++++++++++++++ src/DATA/MAKEDDSYS/makeDDsys.c | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DATA/MANAGER/AddLocalVI.php | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DATA/MANAGER/mgr_ini.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DATA/STARTSTOPLOCAL/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/DATA/STARTSTOPLOCAL/StartStopLocal.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DATA/TIMESUPDATE/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/DATA/TIMESUPDATE/TimesUpdate.c | 431 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DATA/TIMESUPDATENODATA/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/DATA/TIMESUPDATENODATA/TimesUpdateNoData.c | 330 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/TIMESUPDATE/CMakeLists.txt | 24 ------------------------ src/TIMESUPDATE/TimesUpdate.c | 431 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/TIMESUPDATENODATA/CMakeLists.txt | 24 ------------------------ src/TIMESUPDATENODATA/TimesUpdateNoData.c | 330 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 27 files changed, 1696 insertions(+), 829 deletions(-) create mode 100644 cmake/modules/FindLibXML2.cmake create mode 100755 compil.sh create mode 100755 scripts/AddLocalVI.sh create mode 100644 scripts/DDServer.env.in create mode 100755 scripts/StartServer delete mode 100755 scripts/StartServer.in create mode 100644 src/DATA/INFOLOCAL2NC/CMakeLists.txt create mode 100755 src/DATA/INFOLOCAL2NC/infoLocal2nc.c create mode 100644 src/DATA/JOIN_NC/CMakeLists.txt create mode 100644 src/DATA/JOIN_NC/join_nc.c create mode 100644 src/DATA/MAKEDDSYS/CMakeLists.txt create mode 100755 src/DATA/MAKEDDSYS/makeDDsys.c create mode 100644 src/DATA/MANAGER/AddLocalVI.php create mode 100644 src/DATA/MANAGER/mgr_ini.php create mode 100644 src/DATA/STARTSTOPLOCAL/CMakeLists.txt create mode 100644 src/DATA/STARTSTOPLOCAL/StartStopLocal.c create mode 100644 src/DATA/TIMESUPDATE/CMakeLists.txt create mode 100755 src/DATA/TIMESUPDATE/TimesUpdate.c create mode 100644 src/DATA/TIMESUPDATENODATA/CMakeLists.txt create mode 100644 src/DATA/TIMESUPDATENODATA/TimesUpdateNoData.c delete mode 100644 src/TIMESUPDATE/CMakeLists.txt delete mode 100755 src/TIMESUPDATE/TimesUpdate.c delete mode 100644 src/TIMESUPDATENODATA/CMakeLists.txt delete mode 100644 src/TIMESUPDATENODATA/TimesUpdateNoData.c diff --git a/.gitignore b/.gitignore index 394045f..43ece97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .project build/ -scripts/StartServer +scripts/DDServer.env +log diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b88931..1cddb3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,13 +27,14 @@ find_package( CRYPT REQUIRED ) find_package( NetCDF REQUIRED ) find_package( DDClient REQUIRED ) find_package( CDF REQUIRED ) +find_package( LibXML2 REQUIRED ) get_filename_component(NETCDFLIB_DIR ${NETCDFLIBRARIES} PATH) get_filename_component(DDCLIENTLIB_DIR ${DDCLIENTLIBRARIES} PATH) configure_file ( - "${CMAKE_SOURCE_DIR}/scripts/StartServer.in" - "${CMAKE_SOURCE_DIR}/scripts/StartServer" + "${CMAKE_SOURCE_DIR}/scripts/DDServer.env.in" + "${CMAKE_SOURCE_DIR}/scripts/DDServer.env" ) MESSAGE( STATUS "Build DD_Server Project" ) @@ -46,11 +47,18 @@ add_subdirectory(src/DECODERS/themis/esafull2nc) add_subdirectory(src/DECODERS/themis/esamom2nc) add_subdirectory(src/DECODERS/themis/fgm2nc) add_subdirectory(src/DECODERS/themis/sst2nc) -add_subdirectory(src/TIMESUPDATE) -add_subdirectory(src/TIMESUPDATENODATA) +add_subdirectory(src/DATA/TIMESUPDATE) +add_subdirectory(src/DATA/TIMESUPDATENODATA) +add_subdirectory(src/DATA/STARTSTOPLOCAL) +add_subdirectory(src/DATA/INFOLOCAL2NC) +add_subdirectory(src/DATA/MAKEDDSYS) +add_subdirectory(src/DATA/JOIN_NC) add_subdirectory(tests) install(FILES "scripts/StartServer" DESTINATION . PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) +install(FILES "scripts/DDServer.env" DESTINATION . PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) +install(FILES "scripts/AddLocalVI.sh" DESTINATION . PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) install(DIRECTORY "src/CALLEXT/" DESTINATION bin/CALLEXT) +install(DIRECTORY "src/DATA/MANAGER/" DESTINATION bin/DATAMANAGER) SET(CMAKE_VERBOSE_MAKEFILE ON) diff --git a/cmake/modules/FindCDF.cmake b/cmake/modules/FindCDF.cmake index 785cb08..8f02d6a 100644 --- a/cmake/modules/FindCDF.cmake +++ b/cmake/modules/FindCDF.cmake @@ -5,8 +5,8 @@ # libcdf_INCLUDE_DIR - the libcdf include directory # libcdf_LIBRARIES - the libcdf library directory -FIND_PATH(libcdf_INCLUDE_DIR cdf.h PATHS /include /usr/include /usr/local/include /usr/local/cdf/include ${USERLOCAL_ROOT}/include) -FIND_LIBRARY(libcdf_LIBRARIES NAMES cdf PATHS /lib /usr/lib /usr/local/lib /usr/local/cdf/lib ${USERLOCAL_ROOT}/lib ) +FIND_PATH(libcdf_INCLUDE_DIR cdf.h PATHS /include /usr/include /usr/local/include /usr/local/cdf/include ${USERLOCAL_ROOT}/include /opt/local/include ) +FIND_LIBRARY(libcdf_LIBRARIES NAMES cdf PATHS /lib /usr/lib /usr/local/lib /usr/local/cdf/lib ${USERLOCAL_ROOT}/lib /opt/local/lib) # set FOUND flag IF(libcdf_INCLUDE_DIR AND libcdf_LIBRARIES) diff --git a/cmake/modules/FindLibXML2.cmake b/cmake/modules/FindLibXML2.cmake new file mode 100644 index 0000000..6744730 --- /dev/null +++ b/cmake/modules/FindLibXML2.cmake @@ -0,0 +1,25 @@ +# - Try to find LibXml2 +# Once done this will define +# LIBXML2_FOUND - System has LibXml2 +# LIBXML2_INCLUDE_DIRS - The LibXml2 include directories +# LIBXML2_LIBRARIES - The libraries needed to use LibXml2 +# LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2 + +FIND_PATH(LIBXML2_INCLUDE_DIR libxml/xinclude.h PATHS ${USERLOCAL_ROOT}/include/libxml2 /opt/local/include/libxml2) + +FIND_LIBRARY(LIBXML2_LIBRARIES NAMES xml2 libxml2 PATHS ${USERLOCAL_ROOT}/lib /opt/local/lib NO_DEFAULT_PATH) + +IF(LIBXML2_INCLUDE_DIR AND LIBXML2_LIBRARIES) + SET(LibXML2_FOUND 1) + #remove last /libxml2 string + STRING(REGEX REPLACE "/libxml2" "" LIBXML2_INCLUDE_DIR_SUP_LEVEL ${LIBXML2_INCLUDE_DIR}) + SET (LIBXML2_INCLUDE_DIR ${LIBXML2_INCLUDE_DIR_SUP_LEVEL} ${LIBXML2_INCLUDE_DIR} ) + if(NOT LibXML2_FIND_QUIETLY) + message(STATUS "Found libXML2: ${LIBXML2_LIBRARIES}") + endif(NOT LibXML2_FIND_QUIETLY) +ELSE(LIBXML2_INCLUDE_DIR AND LIBXML2_LIBRARIES) + SET(LibXML2_FOUND 0 CACHE BOOL "Not found libxml2 library") + message(STATUS "NOT Found libxml2, disabling it") +ENDIF(LIBXML2_INCLUDE_DIR AND LIBXML2_LIBRARIES) + +MARK_AS_ADVANCED(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES) diff --git a/compil.sh b/compil.sh new file mode 100755 index 0000000..950c542 --- /dev/null +++ b/compil.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +export NETCDF_ROOT="/opt/local" +export DDCLIENT_ROOT="/opt/local" + +cmake -E make_directory build +cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/local .. +cmake --build build +sudo make -C build install VERBOSE=1 diff --git a/scripts/AddLocalVI.sh b/scripts/AddLocalVI.sh new file mode 100755 index 0000000..dc350cf --- /dev/null +++ b/scripts/AddLocalVI.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +BASEDIR=$(dirname "$0") + +. ${BASEDIR}/DDServer.env + +php ${DATAMANAGER}/AddLocalVI.php + diff --git a/scripts/DDServer.env.in b/scripts/DDServer.env.in new file mode 100644 index 0000000..ea4eb51 --- /dev/null +++ b/scripts/DDServer.env.in @@ -0,0 +1,9 @@ +#!/bin/bash + +DDBASE=/home/budnik/AMDA-NG.core/DDBASE/DATA +DDPATH=/home/budnik/AMDA-NG.core/DDBASE +DDLIB=@DDCLIENTLIB_DIR@ +DDBASEBIN=@CMAKE_INSTALL_PREFIX@/bin +LD_LIBRARY_PATH=$DDLIB/:@NETCDFLIB_DIR@:@libcdf_LIBRARY_DIR@:@USRLIB_DIR@ +DATAMANAGER=@CMAKE_INSTALL_PREFIX@/bin/DATAMANAGER +export DDBASE DDPATH DDBASEBIN DDLIB LD_LIBRARY_PATH diff --git a/scripts/StartServer b/scripts/StartServer new file mode 100755 index 0000000..4a240d8 --- /dev/null +++ b/scripts/StartServer @@ -0,0 +1,11 @@ +#!/bin/bash +#------------------------------------------------------------------- +# StartServer +#------------------------------------------------------------------- + +BASEDIR=$(dirname "$0") + +. ${BASEDIR}/DDServer.env + +#$DDBASEBIN/DD_Server 1>/dev/null 2>/dev/null& +$DDBASEBIN/DD_Server -V diff --git a/scripts/StartServer.in b/scripts/StartServer.in deleted file mode 100755 index d4eceb9..0000000 --- a/scripts/StartServer.in +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -#------------------------------------------------------------------- -# StartServer -#------------------------------------------------------------------- -DDBASE=/home/budnik/AMDA-NG.core/DDBASE/DATA -DDPATH=/home/budnik/AMDA-NG.core/DDBASE -DDLIB=@DDCLIENTLIB_DIR@ -DDBASEBIN=@CMAKE_INSTALL_PREFIX@/bin -LD_LIBRARY_PATH=$DDLIB/:@NETCDFLIB_DIR@:@libcdf_LIBRARY_DIR@:@USRLIB_DIR@ -export DDBASE DDPATH DDBASEBIN DDLIB LD_LIBRARY_PATH - -#$DDBASEBIN/DD_Server 1>/dev/null 2>/dev/null& -$DDBASEBIN/DD_Server -V diff --git a/src/DATA/INFOLOCAL2NC/CMakeLists.txt b/src/DATA/INFOLOCAL2NC/CMakeLists.txt new file mode 100644 index 0000000..7cf3ec9 --- /dev/null +++ b/src/DATA/INFOLOCAL2NC/CMakeLists.txt @@ -0,0 +1,26 @@ + +PROJECT(infoLocal2nc) + +include_directories( + ${DDCLIENTINCLUDE_DIR} + ${NETCDFINCLUDE_DIR} + ${LIBXML2_INCLUDE_DIR} +) + +#ConLIBXML2_INCLUDE_DIRfiguration de l'exécutable +file( + GLOB_RECURSE + source_files + ./* +) + +ADD_EXECUTABLE (infoLocal2nc ${source_files} ) + +target_link_libraries( + infoLocal2nc + ${DDCLIENTLIBRARY} + ${NETCDFLIBRARY} + ${LIBXML2_LIBRARIES} +) + +install (TARGETS infoLocal2nc DESTINATION bin) diff --git a/src/DATA/INFOLOCAL2NC/infoLocal2nc.c b/src/DATA/INFOLOCAL2NC/infoLocal2nc.c new file mode 100755 index 0000000..89e3abd --- /dev/null +++ b/src/DATA/INFOLOCAL2NC/infoLocal2nc.c @@ -0,0 +1,132 @@ +/** +* @file infoLocal2nc.c +* @version $Id: infoLocal2nc.c,v 1.4 2012/11/12 09:55:15 budnik Exp $ +* @brief DD Server Tools: Stand alone executable to convert info.xml to info.nc +* @arg xml_name nc_name +* +*/ +/*================================================================================ + * DD + * Server Manager + * infoLocal2nc.c + * V.1.0 + * args -> XML name and nc name + * Modification of info2nc + *================================================================================*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*----------- General constants ----------------------------*/ +#define MAXVAR 100 +#define BASEDIR "DDBASE" + +/*------------- Global variables ---------------------------*/ +char temp[MAXVAR][PATHLENGTH]; + +int main(int argc, char **argv) +{ + char *ncname; + xmlDocPtr doc; + int i = 0, status; + xmlNodePtr cur; + size_t length; + + int fileID; + int InfoDimID, VarID[MAXVAR]; + double number; + char DocPath[PATHLENGTH], *BasePathP; + /*---------- Get Target name from arguments -------------*/ + if (argc < 3) + { + fprintf(stderr,"Usage: infoLocal2nc SourceName TargetName\n"); + exit(0); + } + + /*------- Get full source name --------------------*/ + if((BasePathP = getenv(BASEDIR)) == NULL) + { + fprintf(stderr,"infoLocal2nc: no %s environment\n",BASEDIR); + exit(0); + } + strcpy(DocPath,argv[1]); + + ncname = argv[2]; + doc = xmlParseFile(DocPath); + + if(doc == NULL ) + { + fprintf(stderr,"infoLocal2nc: Source document %s is not parsed successfully.\n",DocPath); + exit(0); + } + + cur = xmlDocGetRootElement(doc); //GO the first node + if (cur == NULL) + { + fprintf(stderr,"info2nc: empty Source Document %s\n",DocPath); + xmlFreeDoc(doc); + exit(0); + } + +// Define nc file + ncopts = NC_VERBOSE; + + if((status = nc_create(ncname,NC_CLOBBER, &fileID)) != NC_NOERR) + { + fprintf(stderr,"info2nc: Could not create file %s\n",ncname); + exit(1); + } + status = nc_def_dim(fileID,"info",PATHLENGTH, &InfoDimID); + status = nc_enddef(fileID); + +// Now treat info.xml + cur = cur->xmlChildrenNode; + while (cur != NULL) + { + if (xmlStrcmp(cur->name, (const xmlChar *)"text")) + { + status = nc_redef(fileID); + if ((!xmlStrcmp(cur->name, (const xmlChar *)"MinSampling")) || + (!xmlStrcmp(cur->name, (const xmlChar *)"MaxSampling")) || + (!xmlStrcmp(cur->name, (const xmlChar *)"FillValue"))) + + status = nc_def_var(fileID, (char *)cur->name, NC_DOUBLE, 0, &InfoDimID, &VarID[i]); + + else + status = nc_def_var(fileID, (char *)cur->name, NC_CHAR, 1, &InfoDimID, &VarID[i]); + status = nc_enddef(fileID); + + if ((cur->xmlChildrenNode) != NULL) + { + length = strlen((char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); + strcpy(temp[i], (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); + temp[i][length]='\0'; + + if ((!xmlStrcmp(cur->name, (const xmlChar *)"MinSampling")) || + (!xmlStrcmp(cur->name, (const xmlChar *)"MaxSampling")) || + (!xmlStrcmp(cur->name, (const xmlChar *)"FillValue"))) + { + number = atof(temp[i]); + status = nc_put_var_double(fileID, VarID[i], &number); + } else status = nc_put_var_text(fileID,VarID[i],temp[i]); + } + i++; + + } + cur = cur->next; + } + + xmlFree(cur); + xmlFreeDoc(doc); + status=nc_close(fileID); + exit(1); +} +/*==========================================================================================================*/ diff --git a/src/DATA/JOIN_NC/CMakeLists.txt b/src/DATA/JOIN_NC/CMakeLists.txt new file mode 100644 index 0000000..6c4703c --- /dev/null +++ b/src/DATA/JOIN_NC/CMakeLists.txt @@ -0,0 +1,24 @@ + +PROJECT(join_nc) + +include_directories( + ${DDCLIENTINCLUDE_DIR} + ${NETCDFINCLUDE_DIR} +) + +#Configuration de l'exécutable +file( + GLOB_RECURSE + source_files + ./* +) + +ADD_EXECUTABLE (join_nc ${source_files} ) + +target_link_libraries( + join_nc + ${DDCLIENTLIBRARY} + ${NETCDFLIBRARY} +) + +install (TARGETS join_nc DESTINATION bin) diff --git a/src/DATA/JOIN_NC/join_nc.c b/src/DATA/JOIN_NC/join_nc.c new file mode 100644 index 0000000..82e4b5e --- /dev/null +++ b/src/DATA/JOIN_NC/join_nc.c @@ -0,0 +1,139 @@ +/* $Id: join_nc.c,v 1.2 2008/06/13 09:17:30 elena Exp $ */ +/** +* @file join_nc.c +* @brief append input nc file to output nc file +* @arg input-file output-file +* @todo Process errors - if needed ? +* @date 03.01.2008 +*/ + +#include +#include +#include +#include + +void handle_error(int status) +{ + fprintf(stderr, "%s\n", nc_strerror(status)); + exit(1); +} + +int main(int argc, char *argv[]) +{ + int status, ncID, infoID; + int ndims, nvars, ngatts, unlimdimid; + size_t dimlength, totalDimension = 1; + size_t *start, *count; + char dimname[NC_MAX_NAME], varname[NC_MAX_NAME], attname[NC_MAX_NAME]; + int i, j; + int dimID[NC_MAX_DIMS]; + int varID[NC_MAX_DIMS]; + char constantInfoFile[NC_MAX_ATTRS]; + char infoFile[NC_MAX_ATTRS]; + nc_type var_type; /* variable type */ + int var_ndims; /* number of dims */ + int var_dimids[NC_MAX_VAR_DIMS]; /* dimension ids */ + int var_natts; /* number of attributes */ + void *variable; + + + if (argc < 3) + { + fprintf(stderr,"Usage: join_nc inputName outputName\n"); + exit(0); + } + + strcpy(constantInfoFile,argv[1]); + strcpy(infoFile,argv[2]); + + if ((status = nc_open(infoFile, NC_WRITE, &ncID)) != NC_NOERR) + handle_error(status); + + if ((status = nc_open(constantInfoFile, NC_NOWRITE, &infoID)) != NC_NOERR) + handle_error(status); + + if ((status = nc_inq(infoID, &ndims, &nvars, &ngatts, &unlimdimid)) != NC_NOERR) + handle_error(status); +// file into DEFINITION mode + nc_redef(ncID); + +// Start with adding dimensions + for (i = 0; i < ndims; i++) { + status = nc_inq_dim(infoID, i, dimname, &dimlength); + if (status == NC_NOERR) nc_def_dim(ncID, dimname, dimlength, &dimID[i]); + } + +// adding Global Attributes + + if (ngatts > 0) + for (i = 0; i < ngatts; i++) { + status = nc_inq_attname(infoID, NC_GLOBAL, i, attname); + if (status == NC_NOERR) nc_copy_att(infoID, NC_GLOBAL, attname, ncID, NC_GLOBAL); + } + nc_enddef(ncID); + +// adding variables + for (i = 0; i < nvars; i++) { + nc_redef(ncID); + + + status = nc_inq_var (infoID, i, varname, &var_type, &var_ndims, var_dimids, &var_natts); + start = (size_t *) malloc(var_ndims*sizeof(size_t)); + count = (size_t *) malloc(var_ndims*sizeof(size_t)); + for (j = 0; j < var_ndims; j++) { + status = nc_inq_dimlen(infoID, var_dimids[j], &dimlength); + if (status == NC_NOERR) totalDimension *= dimlength; + start[j] = 0; + count[j] = dimlength; + var_dimids[j] = dimID[var_dimids[j]]; + } + if (status == NC_NOERR) nc_def_var(ncID, varname, var_type, var_ndims, var_dimids, &varID[i]); + if (var_natts > 0) + for (j = 0; j < var_natts; j++) { + status = nc_inq_attname(infoID, i, j, attname); + if (status == NC_NOERR) nc_copy_att(infoID, i, attname, ncID, varID[i]); + } + nc_enddef(ncID); + + switch(var_type){ + case NC_FLOAT: { + variable = (float *) malloc(totalDimension*sizeof(float)); + status = nc_get_vara_float(infoID, i, start, count, variable); + if (status == NC_NOERR) nc_put_vara_float(ncID, varID[i], start, count, variable); + break; + } + case NC_DOUBLE: { + variable = (double *) malloc(totalDimension*sizeof(double)); + status = nc_get_vara_double(infoID, i, start, count, variable); + if (status == NC_NOERR) nc_put_vara_double(ncID, varID[i], start, count, variable); + break; + } + case NC_SHORT: { + variable = (short *) malloc(totalDimension*sizeof(short)); + status = nc_get_vara_short(infoID, i, start, count, variable); + if (status == NC_NOERR) nc_put_vara_short(ncID, varID[i], start, count, variable); + break; + } + case NC_INT: { + variable = (int *) malloc(totalDimension*sizeof(int)); + status = nc_get_vara_int(infoID, i, start, count, variable); + if (status == NC_NOERR) nc_put_vara_int(ncID, varID[i], start, count, variable); + break; + } + case NC_CHAR: { + variable = (char *) malloc(totalDimension*sizeof(char)); + status = nc_get_vara_text(infoID, i, start, count, variable); + if (status == NC_NOERR) nc_put_vara_text(ncID, varID[i], start, count, variable); + } + } + totalDimension = 1; + free(variable); free(start); free(count); + } + + + if ((status = nc_close(ncID)) != NC_NOERR) + handle_error(status); + + if ((status = nc_close(infoID)) != NC_NOERR) + handle_error(status); +} diff --git a/src/DATA/MAKEDDSYS/CMakeLists.txt b/src/DATA/MAKEDDSYS/CMakeLists.txt new file mode 100644 index 0000000..6603d9a --- /dev/null +++ b/src/DATA/MAKEDDSYS/CMakeLists.txt @@ -0,0 +1,26 @@ + +PROJECT(makeDDsys) + +include_directories( + ${DDCLIENTINCLUDE_DIR} + ${NETCDFINCLUDE_DIR} + ${LIBXML2_INCLUDE_DIR} +) + +#Configuration de l'exécutable +file( + GLOB_RECURSE + source_files + ./* +) + +ADD_EXECUTABLE (makeDDsys ${source_files} ) + +target_link_libraries( + makeDDsys + ${DDCLIENTLIBRARY} + ${NETCDFLIBRARY} + ${LIBXML2_LIBRARIES} +) + +install (TARGETS makeDDsys DESTINATION bin) diff --git a/src/DATA/MAKEDDSYS/makeDDsys.c b/src/DATA/MAKEDDSYS/makeDDsys.c new file mode 100755 index 0000000..f83f05c --- /dev/null +++ b/src/DATA/MAKEDDSYS/makeDDsys.c @@ -0,0 +1,204 @@ +/*================================================================================ + * DD + * Server Package + * makeDDsys.c + * V.4.2 + * Stand-alone executable to create refer.nc file form DDsys.xml file + * Program search the DDsys.xml in the directory $DDBASE, and creates + * refer.nc in this directory. See structure of DDsys.xml in + * ../DOC/TECHDOC/DDBaseStruc.html + * + * Versions: + * Apr 23 1997, V.2.0 Adding CASH into refer.nc file + * Jun 18 2007, V.3.0 Length 128 + * 1 Aug 2007, V.4.0 XML version + * 6 Sep 2007, V.4.1 Knizhnikova-Fedorova, small changes + * 9 Nov 2009, V.4.2 netCDF 3 + *================================================================================*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*----------- General constants ----------------------------*/ +#define MAXVIRIN 1000 +#define SOURCENAME "/DDsys.xml" +#define BASEDIR "DDBASE" + +/*----------- Global variables ------------------------------*/ +char varname[MAXVIRIN][PATHLENGTH]; +char datadirname[MAXVIRIN][PATHLENGTH]; +char timesname[MAXVIRIN][PATHLENGTH]; +char infoname[MAXVIRIN][PATHLENGTH]; +char cashname[MAXVIRIN][PATHLENGTH]; + +int basenumber; /* number of virtual instruments */ + +/*---------------------- REFER CREATE ------------------------*/ +void ReferCreate(char *BasePathP) +{ + int fileID; + int InfoDimID, LengthDimID; + int VarDimVector[2]; + int VarID[MAXVIRIN]; + size_t DirStart[2] = {0L,0L}; + size_t TimesStart[2] = {1L,0L}; + size_t InfoStart[2] = {2L,0L}; + size_t CashStart[2] = {3L,0L}; + size_t VarCount[2] = {1L,PATHLENGTH}; + int i, status; + char DestPath[PATHLENGTH]; + + // ncopts = NC_VERBOSE; + + /* + * Full path name + */ + + strcpy(DestPath,BasePathP); + strcat(DestPath,REFNAME); + + if((status = nc_create( DestPath, NC_CLOBBER, &fileID)) != NC_NOERR) + { + fprintf(stderr,"makeDDsys: Could not create file %s\n",DestPath); + exit(1); + } + + nc_def_dim(fileID, "info", 4L, &InfoDimID); + nc_def_dim(fileID, "length", PATHLENGTH, &LengthDimID); + + VarDimVector[0] = InfoDimID; + VarDimVector[1] = LengthDimID; + + for(i = 0; i < basenumber; i++) + nc_def_var(fileID, varname[i], NC_CHAR, 2, VarDimVector, &VarID[i]); + + nc_enddef(fileID); + + for(i = 0; i < basenumber; i++) + { + nc_put_vara_text(fileID,VarID[i],DirStart,VarCount,(void *)datadirname[i]); + nc_put_vara_text(fileID,VarID[i],TimesStart,VarCount,(void *)timesname[i]); + nc_put_vara_text(fileID,VarID[i],InfoStart,VarCount,(void *)infoname[i]); + nc_put_vara_text(fileID,VarID[i],CashStart,VarCount,(void *)cashname[i]); + + } + status = nc_close(fileID); +} +/*--------------------------------------------------------------------------*/ + + int main(int argc, char **argv) +{ + + xmlDocPtr doc; + xmlChar *xpath = (xmlChar*) "//VI"; + xmlNodeSetPtr nodeset; + xmlXPathObjectPtr result; + int i, j, size = 2, length; + xmlChar *name, *argsNr; + xmlXPathContextPtr context; + xmlNodePtr cur; + char BasePath[PATHLENGTH], *BasePathP; + + /* + * Create full Source Name + */ + if((BasePathP = getenv(BASEDIR)) == NULL) + { + fprintf(stderr,"makeDDsys: no %s environment\n",BASEDIR); + exit(0); + } + strcpy(BasePath,BasePathP); + strcat(BasePath,SOURCENAME); + + doc = xmlParseFile(BasePath); + if (doc == NULL ) + { + fprintf(stderr,"Document not parsed successfully. \n"); + exit(0); + } + + context = xmlXPathNewContext(doc); + if (context == NULL) + { + fprintf(stderr,"Error in xmlXPathNewContext\n"); + exit(0); + } + result = xmlXPathEvalExpression(xpath, context); + + if (result == NULL) + { + fprintf(stderr,"Error in xmlXPathEvalExpression\n"); + exit(0); + } + + if(xmlXPathNodeSetIsEmpty(result->nodesetval)) + { + xmlXPathFreeObject(result); + fprintf(stderr,"No result\n"); + exit(0); + } + if (result) + { + nodeset = result->nodesetval; + fprintf(stderr," VI number: %d\n", nodeset->nodeNr); + basenumber = nodeset->nodeNr; + for (i = 0; i < nodeset->nodeNr; i++) + { + cur = nodeset->nodeTab[i]->xmlChildrenNode; + while (cur != NULL) + { + if((xmlStrcmp(cur->name, (const xmlChar *)"text"))){ + length = strlen((char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); + + } + if (!(xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) + { + + strncpy(varname[i], (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1), length); + } + if (!(xmlStrcmp(cur->name, (const xmlChar *)"LOCATION"))) + { + strncpy(datadirname[i], (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1), length); + } + if (!(xmlStrcmp(cur->name, (const xmlChar *)"TIMES"))) + { + strncpy(timesname[i],datadirname[i], strlen(datadirname[i])); + strncpy(×name[i][strlen(datadirname[i])], (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1), length); + + } + if (!(xmlStrcmp(cur->name, (const xmlChar *)"INFO"))) + { + strncpy(infoname[i],datadirname[i], strlen(datadirname[i])); + strncpy(&infoname[i][strlen(datadirname[i])], (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1), length); + } + if (!(xmlStrcmp(cur->name, (const xmlChar *)"CACHE"))) + { + strncpy(cashname[i],datadirname[i], strlen(datadirname[i])); + strncpy(&cashname[i][strlen(datadirname[i])], (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1), length); + } + + cur = cur->next; + } + } + xmlFree(cur); + xmlXPathFreeObject(result); + } + + xmlXPathFreeContext(context); + xmlFreeDoc(doc); + xmlCleanupParser(); + + ReferCreate(BasePathP); + return (1); +} +/*================================================================================*/ + diff --git a/src/DATA/MANAGER/AddLocalVI.php b/src/DATA/MANAGER/AddLocalVI.php new file mode 100644 index 0000000..81c8299 --- /dev/null +++ b/src/DATA/MANAGER/AddLocalVI.php @@ -0,0 +1,100 @@ + createElement("VI"); + $rootElement -> appendChild($xml_dom -> createElement("Mission",mission)); + $rootElement -> appendChild($xml_dom -> createElement("Instrument",instrument)); + $rootElement -> appendChild($xml_dom -> createElement("GlobalStart")); + $rootElement -> appendChild($xml_dom -> createElement("GlobalStop")); + $rootElement -> appendChild($xml_dom -> createElement("MinSampling", MinSampling)); + if (MaxSampling > MinSampling) $rootElement -> appendChild($xml_dom -> createElement("MaxSampling", MaxSampling)); + $rootElement -> appendChild($xml_dom -> createElement("LocalStart")); + $rootElement -> appendChild($xml_dom -> createElement("LocalStop")); + $xml_dom -> appendChild($rootElement); + $xml_dom -> save(brief."_info.xml"); + +} + + require_once 'mgr_ini.php'; + define("CURRDIR",dirname(__FILE__)); + +/* +* DEFINITIONS TO FILL +*/ + define("brief", "jedi"); // prefix + define("ViId", "juno_jedi_i180"); + define("mission", "JUNO"); + define("instrument", "JEDI"); + define("MISSION_DIR", DDBASE."JUNO/"); + define("location", MISSION_DIR."JEDI/I_180"); + define("MinSampling", 2); + define("MaxSampling", 3); // 0 if constant sampling +/* +* DO NOT TOUCH +*/ + + $times = brief."_times.nc"; + $info = brief."_info.nc"; + $info_xml = brief."_info.xml"; + $cache = brief."_cache.nc"; + + $DDsysDoc = new DomDocument(); + $DDsysDoc->preserveWhiteSpace = false; + $DDsysDoc->formatOutput = true; + $DDsysDoc->load(DDBASE.DDsys); + $dataSet = $DDsysDoc->getElementsByTagName("VI"); +/* +* Check if there is already such VI +*/ + foreach ($dataSet as $theDataSet) + if (strcmp($theDataSet->getElementsByTagName("NAME")->item(0)->nodeValue, ViId) == 0) + die(ViId." Already Exists!!!\n"); + + $refNode = $dataSet->item(0); + $newNode = $DDsysDoc->createElement("VI"); + $name = $newNode->appendChild($DDsysDoc->createElement("NAME",ViId)); + $name->setAttributeNode(new DOMAttr('base', 'LOCAL')); + $name->setAttributeNode(new DOMAttr('mission', mission)); + $name->setAttributeNode(new DOMAttr('instrument', instrument)); + + if (substr(location, -1) !== "/") $newNode->appendChild($DDsysDoc->createElement("LOCATION",location."/")); + else $newNode->appendChild($DDsysDoc->createElement("LOCATION",location)); + + $newNode->appendChild($DDsysDoc->createElement("TIMES",$times)); + $newNode->appendChild($DDsysDoc->createElement("INFO",$info)); + $newNode->appendChild($DDsysDoc->createElement("CACHE",$cache)); + + $newNode = $refNode->parentNode->insertBefore($newNode, $refNode); + + $DDsysDoc->save(DDBASE.DDsys); + system(DDBASEBIN."/makeDDsys"); + +/* +* Create Real Stuff +* +*/ + + if (!is_dir(MISSION_DIR)) mkdir(MISSION_DIR); + if (!is_dir(location)) mkdir(location, 0775, true); + echo location."\n"; + chdir(location); + if (!file_exists($times)) system("TimesUpdate -r ".$times." ".brief."_0*.nc"); + if (!file_exists($info_xml)) makeInfoXml(); + if (!file_exists($info)) system("infoLocal2nc ".$info_xml." ".$info); + if (!file_exists("clean")) { + copy (DDLIB."/Cash.template", $cache); + $SED = "sed 's/NAME/".brief."/g' ".DDLIB."/Clean.template > clean"; + exec($SED); + exec('chmod ugo+x clean'); + } + chdir(CURRDIR); +?> diff --git a/src/DATA/MANAGER/mgr_ini.php b/src/DATA/MANAGER/mgr_ini.php new file mode 100644 index 0000000..326854c --- /dev/null +++ b/src/DATA/MANAGER/mgr_ini.php @@ -0,0 +1,59 @@ + diff --git a/src/DATA/STARTSTOPLOCAL/CMakeLists.txt b/src/DATA/STARTSTOPLOCAL/CMakeLists.txt new file mode 100644 index 0000000..0bf8470 --- /dev/null +++ b/src/DATA/STARTSTOPLOCAL/CMakeLists.txt @@ -0,0 +1,24 @@ + +PROJECT(StartStopLocal) + +include_directories( + ${DDCLIENTINCLUDE_DIR} + ${NETCDFINCLUDE_DIR} +) + +#Configuration de l'exécutable +file( + GLOB_RECURSE + source_files + ./* +) + +ADD_EXECUTABLE (StartStopLocal ${source_files} ) + +target_link_libraries( + StartStopLocal + ${DDCLIENTLIBRARY} + ${NETCDFLIBRARY} +) + +install (TARGETS StartStopLocal DESTINATION bin) diff --git a/src/DATA/STARTSTOPLOCAL/StartStopLocal.c b/src/DATA/STARTSTOPLOCAL/StartStopLocal.c new file mode 100644 index 0000000..7941906 --- /dev/null +++ b/src/DATA/STARTSTOPLOCAL/StartStopLocal.c @@ -0,0 +1,75 @@ + +/** @file StartStopLocal.c +* @brief Stand-alone executable
Returns real Start-Stop for VI in DDBase
+* Update Start-Stop times in INFO files for LOCAL data
+* @details StartStopLocal(string *)
+* @arg @c argv[1] Virtual Instrument ID (DD notation)
+* Output: YYYYDDdayHHMMSSMLS-YYYYDDdayHHMMSSMLS +* +* @date 10.10.2007 +* @version $Id: StartStopLocal.c,v 1.4 2011/09/05 11:27:34 budnik Exp $ +*/ + + +#include +#include +#include +#include +#include +#include +#include + + +int DataID, RecID, 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; + + +/* 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); + +/* 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/DATA/TIMESUPDATE/CMakeLists.txt b/src/DATA/TIMESUPDATE/CMakeLists.txt new file mode 100644 index 0000000..1713a7d --- /dev/null +++ b/src/DATA/TIMESUPDATE/CMakeLists.txt @@ -0,0 +1,24 @@ + +PROJECT(TimesUpdate) + +include_directories( + ${DDCLIENTINCLUDE_DIR} + ${NETCDFINCLUDE_DIR} +) + +#Configuration de l'exécutable +file( + GLOB_RECURSE + source_files + ./* +) + +ADD_EXECUTABLE (TimesUpdate ${source_files} ) + +target_link_libraries( + TimesUpdate + ${DDCLIENTLIBRARY} + ${NETCDFLIBRARY} +) + +install (TARGETS TimesUpdate DESTINATION bin) diff --git a/src/DATA/TIMESUPDATE/TimesUpdate.c b/src/DATA/TIMESUPDATE/TimesUpdate.c new file mode 100755 index 0000000..0f02a70 --- /dev/null +++ b/src/DATA/TIMESUPDATE/TimesUpdate.c @@ -0,0 +1,431 @@ +/* $Id: TimesUpdate.c,v 1.3 2008/02/19 16:24:58 elena Exp $*/ +/*===================================================================== + * DD SYSTEM base package + * DD_Server library + * TimesUpdate.c + * V.4.6 + * + * usage TimesUpdate -r/-i[-u]/-d nc_times_file nc_data_file[*.gz] nc_data_file[*.gz] .... + * Note that in most of cases at the end of activity you have to run ClearTimes nc_times_file + * + * Versions: + * Apr 23 1997, Usung *.gz files V.2.0 + * Jan 4, 2006, V.3.0 - insert file and check overlaping + * Jan 13,2006, V.3.1 - error is corrected + * Feb 02,2006, V.3.2 - Corrected removing database in case of error + * Sep 20, 2007, V.4.0, Fedorov, from rehash.nc. New NetCDF V.3, syncronization + * Sep 25, 2007 V.4.1 The very first file and first file insert + * Nov 29, 2007 V.4.2 If several first records - bug correction + * Feb 17, 2008 V.4.5 Fedorov: New options , remake, insert, delete + * Feb 19, 2008 V.4.6 delete bugs corrected + *=====================================================================*/ + /*===================================================================== + * Description: + * Program reads list of nc_data_files, probabbly gzipped, reads StartTime and Stop time + * and create or update nc_times_file. The sequence of data files are not important + * -r remove nc_times_file and create new one + * -i insert new file(s) + * -d remove file(s) from nc_times + * + * Dimensions: + * TimeLingth TIMELENGTH + * NameLength NAME_DIM + * Record Unlimited + * Variables: + * + * char StartTime[TIMELENGTH] + * char EndTime[TIMELENGTH] + * + * Attributes: + * none + *======================================================================*/ +#include +#include +#include +#include +#include +#include +#include +#include + +/* Global Constant definitions */ + +#define TIME_LENGTH_NAME "TimeLength" +#define TIME_LENGTH 17L +#define REC_DIM_NAME "record" +#define REC_DIM NC_UNLIMITED +#define NAME_DIM_NAME "NameLength" +#define NAME_DIM 32L +#define NAME_LENGTH 100 + +#define STARTTIME "StartTime" +#define STOPTIME "StopTime" +#define FILENAME "FileName" + +#define TIME_TYPE NC_CHAR + +#define TEMPUNZIP "TimesUpdateTemp.nc\0" +#define NODATA "NODATA\0" + +/*----------- Conditions --------------------------*/ +enum Conditions {ALLLEFT,LEFTOVER,WELLIN,RIGHTOVER,ALLRIGHT,LEFTRIGHTOVER,LEFTIN}; + +/*----------- Modes -------------------------------*/ +enum Modes {REMAKE, INSERT, DELETE}; + +/*----------- Type definition ------------------------------*/ +typedef struct +{ + char Name[NAME_LENGTH]; // current data file + char StartS[TIME_LENGTH]; // Start Time String + char StopS[TIME_LENGTH]; // Stop Time String + double StartD; // Start double + double StopD; // Stop double +} t_StartStop; + +/*---------- Global variables (IDs) of open times file -------------*/ + int tmID; /* nc file descriptor */ + int StartID, StopID, NameID; + size_t RecordsNumber = 0; // Records Number of the existing times file + static char ZeroTime[TIME_LENGTH] = "0000000000000000\0"; + static int ToZipFlag = 0; + static char UnzipName[NAME_LENGTH]; + +/*======================================================================== + * FUNCTIONS + *=======================================================================*/ +/*======================================================================== + * GetFileInfo + *=======================================================================*/ +t_StartStop *GetFileInfo(char *FileName) +{ + static t_StartStop StartStop; + int dataID; + int DataStartID, DataStopID; + static size_t DataStart[1] = {0}; + static size_t DataCount[1] = {TIME_LENGTH}; + char command[200]; + int Status; + + /*---- Check if this file exist ------------*/ + if(strcmp(FileName+strlen(FileName)-3,".gz") == 0) // Zipped file + { + strcpy(UnzipName, TEMPUNZIP); + sprintf(command,"gunzip -c %s > %s",FileName,UnzipName); + system(command); + ToZipFlag = 0; + strncpy(StartStop.Name,FileName,strlen(FileName)-3); + } else + { + ToZipFlag = 1; + strcpy(UnzipName,FileName); + strcpy(StartStop.Name,FileName); + } + + if((Status = nc_open(UnzipName,NC_NOWRITE,&dataID)) == NC_NOERR) + { + Status = nc_inq_varid(dataID,STARTTIME,&DataStartID); + Status = nc_inq_varid(dataID,STOPTIME, &DataStopID); + + Status = nc_get_vara_text(dataID,DataStartID,DataStart,DataCount,(char *)StartStop.StartS); + Status = nc_get_vara_text(dataID,DataStopID,DataStart,DataCount,(char *)StartStop.StopS); + Status = nc_close(dataID); + } + else if(Status == 2) + { + fprintf(stderr,"File %s does not exist\n",UnzipName); + return NULL; + } + else + { + fprintf(stderr,"File %s is corrupted, Error = %d\n",UnzipName,Status); + sprintf(command,"rm %s*",StartStop.Name); + system(command); + return NULL; + } + + if((isdigit(StartStop.StartS[0]) == 0) || (isdigit(StartStop.StopS[0]) == 0)) + { + fprintf(stderr,"File %s is corrupted\n",UnzipName); + sprintf(command,"rm %s*",StartStop.Name); + system(command); + return NULL; + } + + StartStop.StartD = DD_Time2Double(StartStop.StartS); + StartStop.StopD = DD_Time2Double(StartStop.StopS); + + return &StartStop; +} +/*-----------------------------------------------------------*/ + +/*------------------------------------------------------------ + * RemoveRecord() + *-----------------------------------------------------------*/ +int RemoveRecord(size_t RecordPos, t_StartStop *StartStop) +{ + static size_t TimeStart[2] = {0,0}; + static size_t TimeCount[2] = {1,TIME_LENGTH}; + static size_t NameCount[2] = {1, NAME_DIM}; + char CStart[TIME_LENGTH],CStop[TIME_LENGTH], CName[NAME_DIM]; + size_t Crec; + char command[200]; + int status; + char NewName[NAME_LENGTH]; + +/*------- Remove corresponding file -------------------*/ + TimeStart[0] = RecordPos; + nc_get_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CName); + if(StartStop == NULL) NewName[0] = '\0'; else strcpy(NewName,StartStop->Name); + if((strcmp(CName,NODATA) != 0)&&(strcmp(CName,NewName) != 0)) + { // Remove old file which overlap with new one */ + sprintf(command,"rm %s*",CName); + system(command); + } + +/*--- replacing Variable -----------------------*/ + for(Crec = RecordPos + 1; Crec < RecordsNumber; Crec++) + { + TimeStart[0] = Crec; + status = nc_get_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)CStart); + status = nc_get_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)CStop); + status = nc_get_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CName); + TimeStart[0]--; + status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)CStart); + status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)CStop); + status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CName); + } + +/*----- Set Zero at the end -------------------------*/ + TimeStart[0] = RecordsNumber - 1; + status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)ZeroTime); + status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)ZeroTime); + + RecordsNumber--; + nc_sync(tmID); + return 1; +} +/*-----------------------------------------------------------*/ + +/*------------------------------------------------------------ + * InsertRecord() + *-----------------------------------------------------------*/ +int InsertRecord(size_t RecordPos, t_StartStop *StartStop) +{ + static size_t TimeStart[2] = {0,0}; + static size_t TimeCount[2] = {1,TIME_LENGTH}; + static size_t NameCount[2] = {1, NAME_DIM}; + char CStart[TIME_LENGTH],CStop[TIME_LENGTH], CName[NAME_DIM]; + int Crec; + int status; + +/*--- Scrall all wariables down-----------------------*/ + for(Crec = RecordsNumber - 1; Crec >= (int)RecordPos; Crec--) + { + TimeStart[0] = (size_t)Crec; + status = nc_get_vara_text (tmID,StartID,TimeStart,TimeCount,(char *)CStart); + status = nc_get_vara_text (tmID,StopID,TimeStart,TimeCount,(char *)CStop); + status = nc_get_vara_text (tmID,NameID,TimeStart,NameCount,(char *)CName); + TimeStart[0]++; + status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)CStart); + status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)CStop); + status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CName); + } + +/*------ Put the new record to empty space -----------------*/ + TimeStart[0] = RecordPos; + status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)StartStop->StartS); + status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)StartStop->StopS); + status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)StartStop->Name); + + RecordsNumber++; + nc_sync(tmID); + return 1; +} +/*==================================================================================*/ + +/*================================================================================== + * MAIN + *==================================================================================*/ +main(int argc, char **argv) +{ + static char usage[] = "usage: TimesUpdate -r/-i[-u]/-d nc_times_file nc_data_file[*.gz] nc_data_file[*.gz]"; + + char Start[TIME_LENGTH], Stop[TIME_LENGTH], Name[NAME_DIM]; + +/* NC definitions */ + int TlDimID,RecDimID, NlDimID; /* ID of dimensions */ + + static size_t TimeStart[2] = {0,0}; + static size_t TimeCount[2] = {1,TIME_LENGTH}; + static size_t NameCount[2] = {1, NAME_DIM}; + + int DimVector[2]; + + char tmName[NAME_DIM]; + int i, InsertFlag, FindFlag, ihole; + + char command[100]; + char name[100]; + int compress = 0; + int status; + + double LastTime = 0.0, FirstTime = 0.0; // Times of the hall between files + + t_StartStop *CurrentRecord; // pointer to the internal static structure + enum Modes CurrMode; + enum Conditions condition; + +/*================================================================= + * Check arguments and options + *=================================================================*/ + if(argc < 4) {fprintf(stderr,"%s\n",usage); exit(1); } + if((strcmp(argv[1], "-r")) == 0) CurrMode = REMAKE; + else if((strcmp(argv[1], "-i")) == 0) CurrMode = INSERT; + else if((strcmp(argv[1], "-u")) == 0) CurrMode = INSERT; + else if((strcmp(argv[1], "-d")) == 0) CurrMode = DELETE; + else {fprintf(stderr,"Unknown option %s\n",argv[1]); exit(1);} +/*-----------------------------------------------------------------*/ + +/*================================================================= + * Creating Times ncdf file if we have to make a new file + *=================================================================*/ + switch(CurrMode) + { + case REMAKE: /* Create New File */ + if((status = nc_create(argv[2],NC_SHARE,&tmID)) != NC_NOERR) + { + fprintf(stderr,"Can not create file %s\n",argv[2]); + exit(0); + } + status = nc_def_dim(tmID,TIME_LENGTH_NAME,TIME_LENGTH,&TlDimID); + status = nc_def_dim(tmID,NAME_DIM_NAME,NAME_DIM,&NlDimID); + status = nc_def_dim(tmID,REC_DIM_NAME,REC_DIM,&RecDimID); + + DimVector[0] = RecDimID; + DimVector[1] = TlDimID; + status = nc_def_var(tmID, STARTTIME,TIME_TYPE,2,DimVector,&StartID); + status = nc_def_var(tmID, STOPTIME,TIME_TYPE,2,DimVector,&StopID); + DimVector[1] = NlDimID; + status = nc_def_var(tmID, FILENAME,TIME_TYPE,2,DimVector,&NameID); + RecordsNumber = 0; + TimeStart[0] = (size_t)RecordsNumber; + status = nc_enddef(tmID); + break; +/*====== Or just open existing file ===================*/ + case INSERT: + case DELETE: /* Open existing file */ + if((status = nc_open(argv[2],NC_WRITE|NC_SHARE,&tmID)) != NC_NOERR) + { + fprintf(stderr,"Can not open file %s to write\n",argv[2]); + exit(0); + } + status = nc_inq_dimid(tmID,REC_DIM_NAME,&RecDimID); + status = nc_inq_varid(tmID, STARTTIME,&StartID); + status = nc_inq_varid(tmID, STOPTIME,&StopID); + status = nc_inq_varid(tmID, FILENAME,&NameID); + status = nc_inq_dimlen(tmID,RecDimID, &RecordsNumber); + break; + } +/*==========================================================================*/ + + /*========================================================================== + * For Each file in the argument list + *=========================================================================*/ + for(i = 3; i < argc; i++) + { + switch(CurrMode) + { + case DELETE: + TimeStart[0] = 0; + FindFlag = 0; + while((FindFlag == 0) && (TimeStart[0] < RecordsNumber)) + { + status = nc_get_vara_text(tmID,NameID,TimeStart,NameCount,(char *)tmName); + + if(strncmp(tmName, argv[i], strlen(tmName)) == 0) + { /* Record is found */ + FindFlag = 1; + RemoveRecord((size_t)TimeStart[0],(t_StartStop *)NULL); + } + else TimeStart[0]++; + } + break; + case REMAKE: + case INSERT: + if((CurrentRecord = GetFileInfo(argv[i])) != NULL) /* Read current file information */ + { + /*----------------- The very first file in VI DIR -------------------*/ + if (RecordsNumber == 0) + { + TimeStart[0] = (size_t)0; + status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)CurrentRecord->StartS); + status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)CurrentRecord->StopS); + status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CurrentRecord->Name); + RecordsNumber++; + } else + { + /*--------------------------------------------------------- + * Searchig the same file or a hole to insert + *-------------------------------------------------------*/ + InsertFlag = 0; + ihole = 0; + while((InsertFlag == 0) && (ihole <= RecordsNumber)) + { + if(ihole > 0) /* Get the Left Time of the hole */ + { + TimeStart[0] = (size_t)(ihole-1); + status = nc_get_vara_text (tmID,StopID,TimeStart,TimeCount,(char *)Stop); + FirstTime = DD_Time2Double(Stop); + } else FirstTime = 0.0; + + if(ihole < RecordsNumber) /* Get the Right Time of the hole */ + { + TimeStart[0] = (size_t)ihole; + status = nc_get_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)Start); + LastTime = DD_Time2Double(Start); + } + else LastTime = 1.0e16; + + /*--------- Look the conditions ---------------*/ + condition = ALLRIGHT; + if((CurrentRecord->StartD < FirstTime - 60.0) && + (CurrentRecord->StopD > LastTime + 60.0)) condition = LEFTRIGHTOVER; + else if((CurrentRecord->StartD < FirstTime - 60.0) && + (CurrentRecord->StopD < FirstTime + 60.0)) condition = ALLLEFT; + else if((CurrentRecord->StartD < FirstTime - 60.0) && + (CurrentRecord->StopD > FirstTime) && + (CurrentRecord->StopD < LastTime + 60.0)) condition = LEFTOVER; + else if((CurrentRecord->StartD >= FirstTime - 60.0) && + (CurrentRecord->StopD <= LastTime + 60.0)) condition = WELLIN; + else if((CurrentRecord->StartD >= FirstTime - 60.0) && + (CurrentRecord->StartD < LastTime) && + (CurrentRecord->StopD > LastTime + 60.0))condition = RIGHTOVER; + else if((CurrentRecord->StartD > LastTime - 60.0) && (CurrentRecord->StopD > LastTime + 60.0)) + condition = ALLRIGHT; + + /* What to do with these conditions ----------------*/ + switch(condition) + { + case WELLIN : InsertRecord((size_t)ihole, CurrentRecord); InsertFlag = 1; break; + case ALLLEFT : RemoveRecord((size_t)(ihole-1),CurrentRecord); ihole--; break; + case ALLRIGHT : ihole++; break; + case LEFTOVER : RemoveRecord((size_t)(ihole-1),CurrentRecord); ihole--; break; + case RIGHTOVER : RemoveRecord((size_t)ihole,CurrentRecord); break; + case LEFTRIGHTOVER : RemoveRecord((size_t)(ihole-1),CurrentRecord); + RemoveRecord((size_t)(ihole-1),CurrentRecord); + ihole--; break; + } + } // While InsertFlag + } // if RecordsNumber > 0 + /*---------- Zip or remove new nc file -----------------*/ + if(ToZipFlag) sprintf(command,"gzip -f %s",CurrentRecord->Name); + else sprintf(command,"rm %s",UnzipName); + system(command); + } // If current argument file is OK + } // CASE + } // For several arguments + status = nc_close(tmID); + return(0); +} +/*=========================================================================================================*/ diff --git a/src/DATA/TIMESUPDATENODATA/CMakeLists.txt b/src/DATA/TIMESUPDATENODATA/CMakeLists.txt new file mode 100644 index 0000000..9bdfe5c --- /dev/null +++ b/src/DATA/TIMESUPDATENODATA/CMakeLists.txt @@ -0,0 +1,24 @@ + +PROJECT(TimesUpdateNoData) + +include_directories( + ${DDCLIENTINCLUDE_DIR} + ${NETCDFINCLUDE_DIR} +) + +#Configuration de l'exécutable +file( + GLOB_RECURSE + source_files + ./* +) + +ADD_EXECUTABLE (TimesUpdateNoData ${source_files} ) + +target_link_libraries( + TimesUpdateNoData + ${DDCLIENTLIBRARY} + ${NETCDFLIBRARY} +) + +install (TARGETS TimesUpdateNoData DESTINATION bin) diff --git a/src/DATA/TIMESUPDATENODATA/TimesUpdateNoData.c b/src/DATA/TIMESUPDATENODATA/TimesUpdateNoData.c new file mode 100644 index 0000000..f881b1b --- /dev/null +++ b/src/DATA/TIMESUPDATENODATA/TimesUpdateNoData.c @@ -0,0 +1,330 @@ +/** +* @file TimesUpdateNoData.c +* @version $Id: TimesUpdateNoData.c,v 1.6 2009/07/07 11:37:40 budnik Exp $ +* @brief Program reads StartTime and StopTime and add to nc_times_file NODATA intervals +* +* @arg nc_times_file OrderedStartTime OrderedStopTime +*/ + +/*===================================================================== + * DD SYSTEM base package + * DD_Server library + * TimesUpdateNoData.c + * V.1.5 + * + * usage TimesUpdateNoData nc_times_file OrderedStartTime OrderedStopTime + * + *=====================================================================*/ + /*===================================================================== + * Description: + * Program reads StartTime and StopTime and add to nc_times_file NODATA intervals + * + * + * + * Dimensions: + * TimeLingth TIMELENGTH + * NameLength NAME_DIM + * Record Unlimited + * Variables: + * + * char StartTime[TIMELENGTH] + * char EndTime[TIMELENGTH] + * + * Attributes: + * none + *======================================================================*/ +#include +#include +#include +#include +#include +#include +#include +#include + + +/* Global Constant definitions */ +#define ISOTIMER "%d-%d-%dT%d:%d:%d.%dZ" /* Format to READ time in ISO format */ +#define TIME_LENGTH_NAME "TimeLength" +#define TIME_LENGTH 17L +#define REC_DIM_NAME "record" +#define REC_DIM NC_UNLIMITED +#define NAME_DIM_NAME "NameLength" +#define NAME_DIM 32L +#define NAME_LENGTH 100 +#define ISO_LENGTH 25 + +#define STARTTIME "StartTime" +#define STOPTIME "StopTime" +#define FILENAME "FileName" + +#define TIME_TYPE NC_CHAR + + +#define DATAGAP 7200 +#define NODATA "NODATA\0" + + +/*----------- Type definition ------------------------------*/ +typedef struct +{ + char Name[NAME_LENGTH]; // current data file + char StartS[TIME_LENGTH]; // Start Time String + char StopS[TIME_LENGTH]; // Stop Time String + + double StartD; // Start double + double StopD; // Stop double +} t_StartStop; + +/*---------- Global variables (IDs) of open times file -------------*/ + int tmID; /* nc file descriptor */ + int StartID, StopID, NameID; + size_t RecordsNumber = 0; // Records Number of the existing times file + static char ZeroTime[TIME_LENGTH] = "0000000000000000\0"; + + +/*======================================================================== + * FUNCTIONS + *=======================================================================*/ +/*===================================================================== + * ISOTime2Double() + * Covert double time to ISO time to Double + * + *=====================================================================*/ +double ISOTime2Double(char* ISO) +{ + unsigned UT[7]; + dd_tmstr_t *Time; + sscanf(ISO, ISOTIMER, &UT[0], &UT[1], &UT[2], &UT[3], &UT[4], &UT[5], &UT[6]); + Time = (dd_tmstr_t *)UT2double(UT); + return Time->times; +} + +/*-----------------------------------------------------------*/ + +/*------------------------------------------------------------ + * InsertRecord() + *-----------------------------------------------------------*/ +int InsertRecord(size_t RecordPos, t_StartStop *StartStop) +{ + static size_t TimeStart[2] = {0,0}; + static size_t TimeCount[2] = {1,TIME_LENGTH}; + static size_t NameCount[2] = {1, NAME_DIM}; + char CStart[TIME_LENGTH],CStop[TIME_LENGTH], CName[NAME_DIM]; + int Crec; + int status; + +/*--- Scroll all variables down-----------------------*/ + for(Crec = RecordsNumber - 1; Crec >= (int)RecordPos; Crec--) + { + TimeStart[0] = (size_t)Crec; + status = nc_get_vara_text (tmID,StartID,TimeStart,TimeCount,(char *)CStart); + status = nc_get_vara_text (tmID,StopID,TimeStart,TimeCount,(char *)CStop); + status = nc_get_vara_text (tmID,NameID,TimeStart,NameCount,(char *)CName); + TimeStart[0]++; + status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)CStart); + status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)CStop); + status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CName); + } + +/*------ Put the new record to empty space -----------------*/ + TimeStart[0] = RecordPos; + status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)StartStop->StartS); + status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)StartStop->StopS); + status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)StartStop->Name); + + RecordsNumber++; + nc_sync(tmID); + return 1; +} +/*==================================================================================*/ + +/*================================================================================== + * MAIN + *==================================================================================*/ +main(int argc, char **argv) +{ + static char usage[] = "usage: TimesUpdateNoData nc_times_file StartTime StopTime"; + + char Start[TIME_LENGTH], Stop[TIME_LENGTH], Name[NAME_DIM]; + +/* NC definitions */ + int TlDimID,RecDimID, NlDimID; /* ID of dimensions */ + + static size_t TimeStart[2] = {0,0}; + static size_t TimeCount[2] = {1,TIME_LENGTH}; + static size_t NameCount[2] = {1, NAME_DIM}; + + int DimVector[2]; + + char tmName[NAME_DIM]; + int InsertFlag; + + int i, hi, lo = 0; + double StartD0, StartD1 = 0.0, StopD0, StopD1, STARTD, STOPD, CurrentStart; + int StartRecord, StopRecord; + + char command[100]; + char name[100]; + + int status; + + double LastTime = 0.0, FirstTime = 0.0; // Times of the hole between files + + t_StartStop CurrentRecord; // + + +/*================================================================= + * Check arguments and options + *=================================================================*/ + if(argc < 4) {fprintf(stderr,"%s\n",usage); exit(1); } + +/*-----------------------------------------------------------------*/ + + + /* Open existing file */ + if((status = nc_open(argv[1],NC_WRITE|NC_SHARE,&tmID)) != NC_NOERR) + { + fprintf(stderr,"Can not open file %s to write\n",argv[2]); + exit(0); + } + status = nc_inq_dimid(tmID,REC_DIM_NAME,&RecDimID); + status = nc_inq_varid(tmID, STARTTIME,&StartID); + status = nc_inq_varid(tmID, STOPTIME,&StopID); + status = nc_inq_varid(tmID, FILENAME,&NameID); + status = nc_inq_dimlen(tmID,RecDimID, &RecordsNumber); + +/*==========================================================================*/ + + hi = RecordsNumber; + + STARTD = ISOTime2Double(argv[2]); + STOPD = ISOTime2Double(argv[3]); + + while (lo <= hi) + { + i = (lo+hi)/2; + TimeStart[0] = i + 1; + status = nc_get_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)Start); + StartD1 = DD_Time2Double(Start); + if (StartD1 > STARTD) hi--; + TimeStart[0] = i; + status = nc_get_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)Start); + StartD0 = DD_Time2Double(Start); + if (StartD0 < STARTD) lo++; + + if (StartD1 <= STARTD && StartD0 >= STARTD) break; + } + + StartRecord = i; + status = nc_get_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)Stop); + StopD0 = DD_Time2Double(Stop); + + while (STOPD > StopD0 && TimeStart[0] <= RecordsNumber) { + status = nc_get_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)Stop); + if (status != NC_NOERR) fprintf(stderr," %s\n", nc_strerror(status)); + StopD0 = DD_Time2Double(Stop); + TimeStart[0]++; + } + + StopRecord = TimeStart[0]-1; + +// if NODATA is the very FIRST - insert NODATA + if (StartRecord == 0 && (StartD0 - STARTD) > DATAGAP) { + + TimeStart[0] = 0; + status = nc_get_vara_text(tmID, NameID, TimeStart, NameCount,(char *)Name); + if (strcmp(Name,NODATA) == 0 && (StartD0 - STOPD) < DATAGAP) { + status = nc_put_vara_text(tmID,StartID, TimeStart, TimeCount, Double2DD_Time(STARTD)); + } + else { + strncpy(CurrentRecord.Name, NODATA, 7); + strncpy(CurrentRecord.StartS,Double2DD_Time(STARTD),TIMELENGTH); + if ((StartD0 - STOPD) < DATAGAP) strncpy(CurrentRecord.StopS,Start,TIMELENGTH); + else strncpy(CurrentRecord.StopS,Double2DD_Time(STOPD),TIMELENGTH); + InsertRecord((size_t)(0), &CurrentRecord); + } + } + + for (i = StartRecord; i < StopRecord ; i++) { + + InsertFlag = 0; + TimeStart[0] = i; + status = nc_get_vara_text(tmID,StopID, TimeStart, TimeCount,(char *)Stop); + StopD0 = DD_Time2Double(Stop); + TimeStart[0] = i+1; + status = nc_get_vara_text(tmID,StartID, TimeStart, TimeCount, (char *)Start); + StartD1 = DD_Time2Double(Start); + + +// Data Gap -> NODATA + + if ((StartD1 - StopD0) > DATAGAP) { + strncpy(CurrentRecord.Name, NODATA,7); + + TimeStart[0] = i; + status = nc_get_vara_text(tmID, NameID, TimeStart, NameCount,(char *)Name); + + if (strcmp(Name,NODATA) == 0) { + strncpy(Stop,Start,TIMELENGTH); + status = nc_get_vara_text(tmID,StartID, TimeStart, TimeCount, (char *)Start); + status = nc_put_vara_text(tmID,StartID, TimeStart, TimeCount, (char *)Start); + if ((StartD1 - STOPD) < DATAGAP) + status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)Stop); + else status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,Double2DD_Time(STOPD)); + status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CurrentRecord.Name); + + InsertFlag = 1; + } + + if (!InsertFlag) { + if ((i == StartRecord) && (StopD0 < STARTD)) + strncpy(CurrentRecord.StartS,Double2DD_Time(STARTD),TIMELENGTH); + else strncpy(CurrentRecord.StartS,Stop,TIMELENGTH); + if ((i == StopRecord-1) && (StartD1 > STOPD)) + strncpy(CurrentRecord.StopS,Double2DD_Time(STOPD),TIMELENGTH); + else strncpy(CurrentRecord.StopS,Start,TIMELENGTH); + + if ((DD_Time2Double(CurrentRecord.StopS) - + DD_Time2Double(CurrentRecord.StartS)) > DATAGAP) + InsertRecord((size_t)(i+1), &CurrentRecord); + + } + } + + } + +// if NODATA is the very LAST - add NODATA + + if (StopRecord == RecordsNumber) { + TimeStart[0] = StopRecord-1; + status = nc_get_vara_text(tmID,StopID, TimeStart, TimeCount, (char *)Stop); + StopD0 = DD_Time2Double(Stop); + + if (STOPD > StopD0) { + status = nc_get_vara_text(tmID, NameID, TimeStart, NameCount,(char *)Name); + + if (strcmp(Name,NODATA) == 0 && (STARTD - StopD0) < DATAGAP) { + status = nc_get_vara_text(tmID,StartID, TimeStart, TimeCount, (char *)Start); + strncpy(Stop,Start,TIMELENGTH); + } + else { + strncpy(Name, NODATA, 7); + TimeStart[0]++; + } + if ((STARTD - StopD0) < DATAGAP) CurrentStart = DD_Time2Double(Stop); + else CurrentStart = STARTD; + if ((STOPD - CurrentStart) > DATAGAP) { + status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount, Double2DD_Time(CurrentStart)); + status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount, Double2DD_Time(STOPD)); + status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)Name); + } + } + } + + + nc_sync(tmID); + status = nc_close(tmID); + exit(0); +} +/*=========================================================================================================*/ diff --git a/src/TIMESUPDATE/CMakeLists.txt b/src/TIMESUPDATE/CMakeLists.txt deleted file mode 100644 index 1713a7d..0000000 --- a/src/TIMESUPDATE/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ - -PROJECT(TimesUpdate) - -include_directories( - ${DDCLIENTINCLUDE_DIR} - ${NETCDFINCLUDE_DIR} -) - -#Configuration de l'exécutable -file( - GLOB_RECURSE - source_files - ./* -) - -ADD_EXECUTABLE (TimesUpdate ${source_files} ) - -target_link_libraries( - TimesUpdate - ${DDCLIENTLIBRARY} - ${NETCDFLIBRARY} -) - -install (TARGETS TimesUpdate DESTINATION bin) diff --git a/src/TIMESUPDATE/TimesUpdate.c b/src/TIMESUPDATE/TimesUpdate.c deleted file mode 100755 index 0f02a70..0000000 --- a/src/TIMESUPDATE/TimesUpdate.c +++ /dev/null @@ -1,431 +0,0 @@ -/* $Id: TimesUpdate.c,v 1.3 2008/02/19 16:24:58 elena Exp $*/ -/*===================================================================== - * DD SYSTEM base package - * DD_Server library - * TimesUpdate.c - * V.4.6 - * - * usage TimesUpdate -r/-i[-u]/-d nc_times_file nc_data_file[*.gz] nc_data_file[*.gz] .... - * Note that in most of cases at the end of activity you have to run ClearTimes nc_times_file - * - * Versions: - * Apr 23 1997, Usung *.gz files V.2.0 - * Jan 4, 2006, V.3.0 - insert file and check overlaping - * Jan 13,2006, V.3.1 - error is corrected - * Feb 02,2006, V.3.2 - Corrected removing database in case of error - * Sep 20, 2007, V.4.0, Fedorov, from rehash.nc. New NetCDF V.3, syncronization - * Sep 25, 2007 V.4.1 The very first file and first file insert - * Nov 29, 2007 V.4.2 If several first records - bug correction - * Feb 17, 2008 V.4.5 Fedorov: New options , remake, insert, delete - * Feb 19, 2008 V.4.6 delete bugs corrected - *=====================================================================*/ - /*===================================================================== - * Description: - * Program reads list of nc_data_files, probabbly gzipped, reads StartTime and Stop time - * and create or update nc_times_file. The sequence of data files are not important - * -r remove nc_times_file and create new one - * -i insert new file(s) - * -d remove file(s) from nc_times - * - * Dimensions: - * TimeLingth TIMELENGTH - * NameLength NAME_DIM - * Record Unlimited - * Variables: - * - * char StartTime[TIMELENGTH] - * char EndTime[TIMELENGTH] - * - * Attributes: - * none - *======================================================================*/ -#include -#include -#include -#include -#include -#include -#include -#include - -/* Global Constant definitions */ - -#define TIME_LENGTH_NAME "TimeLength" -#define TIME_LENGTH 17L -#define REC_DIM_NAME "record" -#define REC_DIM NC_UNLIMITED -#define NAME_DIM_NAME "NameLength" -#define NAME_DIM 32L -#define NAME_LENGTH 100 - -#define STARTTIME "StartTime" -#define STOPTIME "StopTime" -#define FILENAME "FileName" - -#define TIME_TYPE NC_CHAR - -#define TEMPUNZIP "TimesUpdateTemp.nc\0" -#define NODATA "NODATA\0" - -/*----------- Conditions --------------------------*/ -enum Conditions {ALLLEFT,LEFTOVER,WELLIN,RIGHTOVER,ALLRIGHT,LEFTRIGHTOVER,LEFTIN}; - -/*----------- Modes -------------------------------*/ -enum Modes {REMAKE, INSERT, DELETE}; - -/*----------- Type definition ------------------------------*/ -typedef struct -{ - char Name[NAME_LENGTH]; // current data file - char StartS[TIME_LENGTH]; // Start Time String - char StopS[TIME_LENGTH]; // Stop Time String - double StartD; // Start double - double StopD; // Stop double -} t_StartStop; - -/*---------- Global variables (IDs) of open times file -------------*/ - int tmID; /* nc file descriptor */ - int StartID, StopID, NameID; - size_t RecordsNumber = 0; // Records Number of the existing times file - static char ZeroTime[TIME_LENGTH] = "0000000000000000\0"; - static int ToZipFlag = 0; - static char UnzipName[NAME_LENGTH]; - -/*======================================================================== - * FUNCTIONS - *=======================================================================*/ -/*======================================================================== - * GetFileInfo - *=======================================================================*/ -t_StartStop *GetFileInfo(char *FileName) -{ - static t_StartStop StartStop; - int dataID; - int DataStartID, DataStopID; - static size_t DataStart[1] = {0}; - static size_t DataCount[1] = {TIME_LENGTH}; - char command[200]; - int Status; - - /*---- Check if this file exist ------------*/ - if(strcmp(FileName+strlen(FileName)-3,".gz") == 0) // Zipped file - { - strcpy(UnzipName, TEMPUNZIP); - sprintf(command,"gunzip -c %s > %s",FileName,UnzipName); - system(command); - ToZipFlag = 0; - strncpy(StartStop.Name,FileName,strlen(FileName)-3); - } else - { - ToZipFlag = 1; - strcpy(UnzipName,FileName); - strcpy(StartStop.Name,FileName); - } - - if((Status = nc_open(UnzipName,NC_NOWRITE,&dataID)) == NC_NOERR) - { - Status = nc_inq_varid(dataID,STARTTIME,&DataStartID); - Status = nc_inq_varid(dataID,STOPTIME, &DataStopID); - - Status = nc_get_vara_text(dataID,DataStartID,DataStart,DataCount,(char *)StartStop.StartS); - Status = nc_get_vara_text(dataID,DataStopID,DataStart,DataCount,(char *)StartStop.StopS); - Status = nc_close(dataID); - } - else if(Status == 2) - { - fprintf(stderr,"File %s does not exist\n",UnzipName); - return NULL; - } - else - { - fprintf(stderr,"File %s is corrupted, Error = %d\n",UnzipName,Status); - sprintf(command,"rm %s*",StartStop.Name); - system(command); - return NULL; - } - - if((isdigit(StartStop.StartS[0]) == 0) || (isdigit(StartStop.StopS[0]) == 0)) - { - fprintf(stderr,"File %s is corrupted\n",UnzipName); - sprintf(command,"rm %s*",StartStop.Name); - system(command); - return NULL; - } - - StartStop.StartD = DD_Time2Double(StartStop.StartS); - StartStop.StopD = DD_Time2Double(StartStop.StopS); - - return &StartStop; -} -/*-----------------------------------------------------------*/ - -/*------------------------------------------------------------ - * RemoveRecord() - *-----------------------------------------------------------*/ -int RemoveRecord(size_t RecordPos, t_StartStop *StartStop) -{ - static size_t TimeStart[2] = {0,0}; - static size_t TimeCount[2] = {1,TIME_LENGTH}; - static size_t NameCount[2] = {1, NAME_DIM}; - char CStart[TIME_LENGTH],CStop[TIME_LENGTH], CName[NAME_DIM]; - size_t Crec; - char command[200]; - int status; - char NewName[NAME_LENGTH]; - -/*------- Remove corresponding file -------------------*/ - TimeStart[0] = RecordPos; - nc_get_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CName); - if(StartStop == NULL) NewName[0] = '\0'; else strcpy(NewName,StartStop->Name); - if((strcmp(CName,NODATA) != 0)&&(strcmp(CName,NewName) != 0)) - { // Remove old file which overlap with new one */ - sprintf(command,"rm %s*",CName); - system(command); - } - -/*--- replacing Variable -----------------------*/ - for(Crec = RecordPos + 1; Crec < RecordsNumber; Crec++) - { - TimeStart[0] = Crec; - status = nc_get_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)CStart); - status = nc_get_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)CStop); - status = nc_get_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CName); - TimeStart[0]--; - status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)CStart); - status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)CStop); - status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CName); - } - -/*----- Set Zero at the end -------------------------*/ - TimeStart[0] = RecordsNumber - 1; - status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)ZeroTime); - status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)ZeroTime); - - RecordsNumber--; - nc_sync(tmID); - return 1; -} -/*-----------------------------------------------------------*/ - -/*------------------------------------------------------------ - * InsertRecord() - *-----------------------------------------------------------*/ -int InsertRecord(size_t RecordPos, t_StartStop *StartStop) -{ - static size_t TimeStart[2] = {0,0}; - static size_t TimeCount[2] = {1,TIME_LENGTH}; - static size_t NameCount[2] = {1, NAME_DIM}; - char CStart[TIME_LENGTH],CStop[TIME_LENGTH], CName[NAME_DIM]; - int Crec; - int status; - -/*--- Scrall all wariables down-----------------------*/ - for(Crec = RecordsNumber - 1; Crec >= (int)RecordPos; Crec--) - { - TimeStart[0] = (size_t)Crec; - status = nc_get_vara_text (tmID,StartID,TimeStart,TimeCount,(char *)CStart); - status = nc_get_vara_text (tmID,StopID,TimeStart,TimeCount,(char *)CStop); - status = nc_get_vara_text (tmID,NameID,TimeStart,NameCount,(char *)CName); - TimeStart[0]++; - status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)CStart); - status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)CStop); - status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CName); - } - -/*------ Put the new record to empty space -----------------*/ - TimeStart[0] = RecordPos; - status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)StartStop->StartS); - status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)StartStop->StopS); - status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)StartStop->Name); - - RecordsNumber++; - nc_sync(tmID); - return 1; -} -/*==================================================================================*/ - -/*================================================================================== - * MAIN - *==================================================================================*/ -main(int argc, char **argv) -{ - static char usage[] = "usage: TimesUpdate -r/-i[-u]/-d nc_times_file nc_data_file[*.gz] nc_data_file[*.gz]"; - - char Start[TIME_LENGTH], Stop[TIME_LENGTH], Name[NAME_DIM]; - -/* NC definitions */ - int TlDimID,RecDimID, NlDimID; /* ID of dimensions */ - - static size_t TimeStart[2] = {0,0}; - static size_t TimeCount[2] = {1,TIME_LENGTH}; - static size_t NameCount[2] = {1, NAME_DIM}; - - int DimVector[2]; - - char tmName[NAME_DIM]; - int i, InsertFlag, FindFlag, ihole; - - char command[100]; - char name[100]; - int compress = 0; - int status; - - double LastTime = 0.0, FirstTime = 0.0; // Times of the hall between files - - t_StartStop *CurrentRecord; // pointer to the internal static structure - enum Modes CurrMode; - enum Conditions condition; - -/*================================================================= - * Check arguments and options - *=================================================================*/ - if(argc < 4) {fprintf(stderr,"%s\n",usage); exit(1); } - if((strcmp(argv[1], "-r")) == 0) CurrMode = REMAKE; - else if((strcmp(argv[1], "-i")) == 0) CurrMode = INSERT; - else if((strcmp(argv[1], "-u")) == 0) CurrMode = INSERT; - else if((strcmp(argv[1], "-d")) == 0) CurrMode = DELETE; - else {fprintf(stderr,"Unknown option %s\n",argv[1]); exit(1);} -/*-----------------------------------------------------------------*/ - -/*================================================================= - * Creating Times ncdf file if we have to make a new file - *=================================================================*/ - switch(CurrMode) - { - case REMAKE: /* Create New File */ - if((status = nc_create(argv[2],NC_SHARE,&tmID)) != NC_NOERR) - { - fprintf(stderr,"Can not create file %s\n",argv[2]); - exit(0); - } - status = nc_def_dim(tmID,TIME_LENGTH_NAME,TIME_LENGTH,&TlDimID); - status = nc_def_dim(tmID,NAME_DIM_NAME,NAME_DIM,&NlDimID); - status = nc_def_dim(tmID,REC_DIM_NAME,REC_DIM,&RecDimID); - - DimVector[0] = RecDimID; - DimVector[1] = TlDimID; - status = nc_def_var(tmID, STARTTIME,TIME_TYPE,2,DimVector,&StartID); - status = nc_def_var(tmID, STOPTIME,TIME_TYPE,2,DimVector,&StopID); - DimVector[1] = NlDimID; - status = nc_def_var(tmID, FILENAME,TIME_TYPE,2,DimVector,&NameID); - RecordsNumber = 0; - TimeStart[0] = (size_t)RecordsNumber; - status = nc_enddef(tmID); - break; -/*====== Or just open existing file ===================*/ - case INSERT: - case DELETE: /* Open existing file */ - if((status = nc_open(argv[2],NC_WRITE|NC_SHARE,&tmID)) != NC_NOERR) - { - fprintf(stderr,"Can not open file %s to write\n",argv[2]); - exit(0); - } - status = nc_inq_dimid(tmID,REC_DIM_NAME,&RecDimID); - status = nc_inq_varid(tmID, STARTTIME,&StartID); - status = nc_inq_varid(tmID, STOPTIME,&StopID); - status = nc_inq_varid(tmID, FILENAME,&NameID); - status = nc_inq_dimlen(tmID,RecDimID, &RecordsNumber); - break; - } -/*==========================================================================*/ - - /*========================================================================== - * For Each file in the argument list - *=========================================================================*/ - for(i = 3; i < argc; i++) - { - switch(CurrMode) - { - case DELETE: - TimeStart[0] = 0; - FindFlag = 0; - while((FindFlag == 0) && (TimeStart[0] < RecordsNumber)) - { - status = nc_get_vara_text(tmID,NameID,TimeStart,NameCount,(char *)tmName); - - if(strncmp(tmName, argv[i], strlen(tmName)) == 0) - { /* Record is found */ - FindFlag = 1; - RemoveRecord((size_t)TimeStart[0],(t_StartStop *)NULL); - } - else TimeStart[0]++; - } - break; - case REMAKE: - case INSERT: - if((CurrentRecord = GetFileInfo(argv[i])) != NULL) /* Read current file information */ - { - /*----------------- The very first file in VI DIR -------------------*/ - if (RecordsNumber == 0) - { - TimeStart[0] = (size_t)0; - status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)CurrentRecord->StartS); - status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)CurrentRecord->StopS); - status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CurrentRecord->Name); - RecordsNumber++; - } else - { - /*--------------------------------------------------------- - * Searchig the same file or a hole to insert - *-------------------------------------------------------*/ - InsertFlag = 0; - ihole = 0; - while((InsertFlag == 0) && (ihole <= RecordsNumber)) - { - if(ihole > 0) /* Get the Left Time of the hole */ - { - TimeStart[0] = (size_t)(ihole-1); - status = nc_get_vara_text (tmID,StopID,TimeStart,TimeCount,(char *)Stop); - FirstTime = DD_Time2Double(Stop); - } else FirstTime = 0.0; - - if(ihole < RecordsNumber) /* Get the Right Time of the hole */ - { - TimeStart[0] = (size_t)ihole; - status = nc_get_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)Start); - LastTime = DD_Time2Double(Start); - } - else LastTime = 1.0e16; - - /*--------- Look the conditions ---------------*/ - condition = ALLRIGHT; - if((CurrentRecord->StartD < FirstTime - 60.0) && - (CurrentRecord->StopD > LastTime + 60.0)) condition = LEFTRIGHTOVER; - else if((CurrentRecord->StartD < FirstTime - 60.0) && - (CurrentRecord->StopD < FirstTime + 60.0)) condition = ALLLEFT; - else if((CurrentRecord->StartD < FirstTime - 60.0) && - (CurrentRecord->StopD > FirstTime) && - (CurrentRecord->StopD < LastTime + 60.0)) condition = LEFTOVER; - else if((CurrentRecord->StartD >= FirstTime - 60.0) && - (CurrentRecord->StopD <= LastTime + 60.0)) condition = WELLIN; - else if((CurrentRecord->StartD >= FirstTime - 60.0) && - (CurrentRecord->StartD < LastTime) && - (CurrentRecord->StopD > LastTime + 60.0))condition = RIGHTOVER; - else if((CurrentRecord->StartD > LastTime - 60.0) && (CurrentRecord->StopD > LastTime + 60.0)) - condition = ALLRIGHT; - - /* What to do with these conditions ----------------*/ - switch(condition) - { - case WELLIN : InsertRecord((size_t)ihole, CurrentRecord); InsertFlag = 1; break; - case ALLLEFT : RemoveRecord((size_t)(ihole-1),CurrentRecord); ihole--; break; - case ALLRIGHT : ihole++; break; - case LEFTOVER : RemoveRecord((size_t)(ihole-1),CurrentRecord); ihole--; break; - case RIGHTOVER : RemoveRecord((size_t)ihole,CurrentRecord); break; - case LEFTRIGHTOVER : RemoveRecord((size_t)(ihole-1),CurrentRecord); - RemoveRecord((size_t)(ihole-1),CurrentRecord); - ihole--; break; - } - } // While InsertFlag - } // if RecordsNumber > 0 - /*---------- Zip or remove new nc file -----------------*/ - if(ToZipFlag) sprintf(command,"gzip -f %s",CurrentRecord->Name); - else sprintf(command,"rm %s",UnzipName); - system(command); - } // If current argument file is OK - } // CASE - } // For several arguments - status = nc_close(tmID); - return(0); -} -/*=========================================================================================================*/ diff --git a/src/TIMESUPDATENODATA/CMakeLists.txt b/src/TIMESUPDATENODATA/CMakeLists.txt deleted file mode 100644 index 9bdfe5c..0000000 --- a/src/TIMESUPDATENODATA/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ - -PROJECT(TimesUpdateNoData) - -include_directories( - ${DDCLIENTINCLUDE_DIR} - ${NETCDFINCLUDE_DIR} -) - -#Configuration de l'exécutable -file( - GLOB_RECURSE - source_files - ./* -) - -ADD_EXECUTABLE (TimesUpdateNoData ${source_files} ) - -target_link_libraries( - TimesUpdateNoData - ${DDCLIENTLIBRARY} - ${NETCDFLIBRARY} -) - -install (TARGETS TimesUpdateNoData DESTINATION bin) diff --git a/src/TIMESUPDATENODATA/TimesUpdateNoData.c b/src/TIMESUPDATENODATA/TimesUpdateNoData.c deleted file mode 100644 index f881b1b..0000000 --- a/src/TIMESUPDATENODATA/TimesUpdateNoData.c +++ /dev/null @@ -1,330 +0,0 @@ -/** -* @file TimesUpdateNoData.c -* @version $Id: TimesUpdateNoData.c,v 1.6 2009/07/07 11:37:40 budnik Exp $ -* @brief Program reads StartTime and StopTime and add to nc_times_file NODATA intervals -* -* @arg nc_times_file OrderedStartTime OrderedStopTime -*/ - -/*===================================================================== - * DD SYSTEM base package - * DD_Server library - * TimesUpdateNoData.c - * V.1.5 - * - * usage TimesUpdateNoData nc_times_file OrderedStartTime OrderedStopTime - * - *=====================================================================*/ - /*===================================================================== - * Description: - * Program reads StartTime and StopTime and add to nc_times_file NODATA intervals - * - * - * - * Dimensions: - * TimeLingth TIMELENGTH - * NameLength NAME_DIM - * Record Unlimited - * Variables: - * - * char StartTime[TIMELENGTH] - * char EndTime[TIMELENGTH] - * - * Attributes: - * none - *======================================================================*/ -#include -#include -#include -#include -#include -#include -#include -#include - - -/* Global Constant definitions */ -#define ISOTIMER "%d-%d-%dT%d:%d:%d.%dZ" /* Format to READ time in ISO format */ -#define TIME_LENGTH_NAME "TimeLength" -#define TIME_LENGTH 17L -#define REC_DIM_NAME "record" -#define REC_DIM NC_UNLIMITED -#define NAME_DIM_NAME "NameLength" -#define NAME_DIM 32L -#define NAME_LENGTH 100 -#define ISO_LENGTH 25 - -#define STARTTIME "StartTime" -#define STOPTIME "StopTime" -#define FILENAME "FileName" - -#define TIME_TYPE NC_CHAR - - -#define DATAGAP 7200 -#define NODATA "NODATA\0" - - -/*----------- Type definition ------------------------------*/ -typedef struct -{ - char Name[NAME_LENGTH]; // current data file - char StartS[TIME_LENGTH]; // Start Time String - char StopS[TIME_LENGTH]; // Stop Time String - - double StartD; // Start double - double StopD; // Stop double -} t_StartStop; - -/*---------- Global variables (IDs) of open times file -------------*/ - int tmID; /* nc file descriptor */ - int StartID, StopID, NameID; - size_t RecordsNumber = 0; // Records Number of the existing times file - static char ZeroTime[TIME_LENGTH] = "0000000000000000\0"; - - -/*======================================================================== - * FUNCTIONS - *=======================================================================*/ -/*===================================================================== - * ISOTime2Double() - * Covert double time to ISO time to Double - * - *=====================================================================*/ -double ISOTime2Double(char* ISO) -{ - unsigned UT[7]; - dd_tmstr_t *Time; - sscanf(ISO, ISOTIMER, &UT[0], &UT[1], &UT[2], &UT[3], &UT[4], &UT[5], &UT[6]); - Time = (dd_tmstr_t *)UT2double(UT); - return Time->times; -} - -/*-----------------------------------------------------------*/ - -/*------------------------------------------------------------ - * InsertRecord() - *-----------------------------------------------------------*/ -int InsertRecord(size_t RecordPos, t_StartStop *StartStop) -{ - static size_t TimeStart[2] = {0,0}; - static size_t TimeCount[2] = {1,TIME_LENGTH}; - static size_t NameCount[2] = {1, NAME_DIM}; - char CStart[TIME_LENGTH],CStop[TIME_LENGTH], CName[NAME_DIM]; - int Crec; - int status; - -/*--- Scroll all variables down-----------------------*/ - for(Crec = RecordsNumber - 1; Crec >= (int)RecordPos; Crec--) - { - TimeStart[0] = (size_t)Crec; - status = nc_get_vara_text (tmID,StartID,TimeStart,TimeCount,(char *)CStart); - status = nc_get_vara_text (tmID,StopID,TimeStart,TimeCount,(char *)CStop); - status = nc_get_vara_text (tmID,NameID,TimeStart,NameCount,(char *)CName); - TimeStart[0]++; - status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)CStart); - status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)CStop); - status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CName); - } - -/*------ Put the new record to empty space -----------------*/ - TimeStart[0] = RecordPos; - status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)StartStop->StartS); - status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)StartStop->StopS); - status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)StartStop->Name); - - RecordsNumber++; - nc_sync(tmID); - return 1; -} -/*==================================================================================*/ - -/*================================================================================== - * MAIN - *==================================================================================*/ -main(int argc, char **argv) -{ - static char usage[] = "usage: TimesUpdateNoData nc_times_file StartTime StopTime"; - - char Start[TIME_LENGTH], Stop[TIME_LENGTH], Name[NAME_DIM]; - -/* NC definitions */ - int TlDimID,RecDimID, NlDimID; /* ID of dimensions */ - - static size_t TimeStart[2] = {0,0}; - static size_t TimeCount[2] = {1,TIME_LENGTH}; - static size_t NameCount[2] = {1, NAME_DIM}; - - int DimVector[2]; - - char tmName[NAME_DIM]; - int InsertFlag; - - int i, hi, lo = 0; - double StartD0, StartD1 = 0.0, StopD0, StopD1, STARTD, STOPD, CurrentStart; - int StartRecord, StopRecord; - - char command[100]; - char name[100]; - - int status; - - double LastTime = 0.0, FirstTime = 0.0; // Times of the hole between files - - t_StartStop CurrentRecord; // - - -/*================================================================= - * Check arguments and options - *=================================================================*/ - if(argc < 4) {fprintf(stderr,"%s\n",usage); exit(1); } - -/*-----------------------------------------------------------------*/ - - - /* Open existing file */ - if((status = nc_open(argv[1],NC_WRITE|NC_SHARE,&tmID)) != NC_NOERR) - { - fprintf(stderr,"Can not open file %s to write\n",argv[2]); - exit(0); - } - status = nc_inq_dimid(tmID,REC_DIM_NAME,&RecDimID); - status = nc_inq_varid(tmID, STARTTIME,&StartID); - status = nc_inq_varid(tmID, STOPTIME,&StopID); - status = nc_inq_varid(tmID, FILENAME,&NameID); - status = nc_inq_dimlen(tmID,RecDimID, &RecordsNumber); - -/*==========================================================================*/ - - hi = RecordsNumber; - - STARTD = ISOTime2Double(argv[2]); - STOPD = ISOTime2Double(argv[3]); - - while (lo <= hi) - { - i = (lo+hi)/2; - TimeStart[0] = i + 1; - status = nc_get_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)Start); - StartD1 = DD_Time2Double(Start); - if (StartD1 > STARTD) hi--; - TimeStart[0] = i; - status = nc_get_vara_text(tmID,StartID,TimeStart,TimeCount,(char *)Start); - StartD0 = DD_Time2Double(Start); - if (StartD0 < STARTD) lo++; - - if (StartD1 <= STARTD && StartD0 >= STARTD) break; - } - - StartRecord = i; - status = nc_get_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)Stop); - StopD0 = DD_Time2Double(Stop); - - while (STOPD > StopD0 && TimeStart[0] <= RecordsNumber) { - status = nc_get_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)Stop); - if (status != NC_NOERR) fprintf(stderr," %s\n", nc_strerror(status)); - StopD0 = DD_Time2Double(Stop); - TimeStart[0]++; - } - - StopRecord = TimeStart[0]-1; - -// if NODATA is the very FIRST - insert NODATA - if (StartRecord == 0 && (StartD0 - STARTD) > DATAGAP) { - - TimeStart[0] = 0; - status = nc_get_vara_text(tmID, NameID, TimeStart, NameCount,(char *)Name); - if (strcmp(Name,NODATA) == 0 && (StartD0 - STOPD) < DATAGAP) { - status = nc_put_vara_text(tmID,StartID, TimeStart, TimeCount, Double2DD_Time(STARTD)); - } - else { - strncpy(CurrentRecord.Name, NODATA, 7); - strncpy(CurrentRecord.StartS,Double2DD_Time(STARTD),TIMELENGTH); - if ((StartD0 - STOPD) < DATAGAP) strncpy(CurrentRecord.StopS,Start,TIMELENGTH); - else strncpy(CurrentRecord.StopS,Double2DD_Time(STOPD),TIMELENGTH); - InsertRecord((size_t)(0), &CurrentRecord); - } - } - - for (i = StartRecord; i < StopRecord ; i++) { - - InsertFlag = 0; - TimeStart[0] = i; - status = nc_get_vara_text(tmID,StopID, TimeStart, TimeCount,(char *)Stop); - StopD0 = DD_Time2Double(Stop); - TimeStart[0] = i+1; - status = nc_get_vara_text(tmID,StartID, TimeStart, TimeCount, (char *)Start); - StartD1 = DD_Time2Double(Start); - - -// Data Gap -> NODATA - - if ((StartD1 - StopD0) > DATAGAP) { - strncpy(CurrentRecord.Name, NODATA,7); - - TimeStart[0] = i; - status = nc_get_vara_text(tmID, NameID, TimeStart, NameCount,(char *)Name); - - if (strcmp(Name,NODATA) == 0) { - strncpy(Stop,Start,TIMELENGTH); - status = nc_get_vara_text(tmID,StartID, TimeStart, TimeCount, (char *)Start); - status = nc_put_vara_text(tmID,StartID, TimeStart, TimeCount, (char *)Start); - if ((StartD1 - STOPD) < DATAGAP) - status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,(char *)Stop); - else status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount,Double2DD_Time(STOPD)); - status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)CurrentRecord.Name); - - InsertFlag = 1; - } - - if (!InsertFlag) { - if ((i == StartRecord) && (StopD0 < STARTD)) - strncpy(CurrentRecord.StartS,Double2DD_Time(STARTD),TIMELENGTH); - else strncpy(CurrentRecord.StartS,Stop,TIMELENGTH); - if ((i == StopRecord-1) && (StartD1 > STOPD)) - strncpy(CurrentRecord.StopS,Double2DD_Time(STOPD),TIMELENGTH); - else strncpy(CurrentRecord.StopS,Start,TIMELENGTH); - - if ((DD_Time2Double(CurrentRecord.StopS) - - DD_Time2Double(CurrentRecord.StartS)) > DATAGAP) - InsertRecord((size_t)(i+1), &CurrentRecord); - - } - } - - } - -// if NODATA is the very LAST - add NODATA - - if (StopRecord == RecordsNumber) { - TimeStart[0] = StopRecord-1; - status = nc_get_vara_text(tmID,StopID, TimeStart, TimeCount, (char *)Stop); - StopD0 = DD_Time2Double(Stop); - - if (STOPD > StopD0) { - status = nc_get_vara_text(tmID, NameID, TimeStart, NameCount,(char *)Name); - - if (strcmp(Name,NODATA) == 0 && (STARTD - StopD0) < DATAGAP) { - status = nc_get_vara_text(tmID,StartID, TimeStart, TimeCount, (char *)Start); - strncpy(Stop,Start,TIMELENGTH); - } - else { - strncpy(Name, NODATA, 7); - TimeStart[0]++; - } - if ((STARTD - StopD0) < DATAGAP) CurrentStart = DD_Time2Double(Stop); - else CurrentStart = STARTD; - if ((STOPD - CurrentStart) > DATAGAP) { - status = nc_put_vara_text(tmID,StartID,TimeStart,TimeCount, Double2DD_Time(CurrentStart)); - status = nc_put_vara_text(tmID,StopID,TimeStart,TimeCount, Double2DD_Time(STOPD)); - status = nc_put_vara_text(tmID,NameID,TimeStart,NameCount,(char *)Name); - } - } - } - - - nc_sync(tmID); - status = nc_close(tmID); - exit(0); -} -/*=========================================================================================================*/ -- libgit2 0.21.2