Skip to content

Commit

Permalink
echon1
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisHeimbigner committed Sep 27, 2024
1 parent 89575c6 commit 1c0688b
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 61 deletions.
8 changes: 6 additions & 2 deletions ncdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 2015, 2016, 2017, 2018
# University Corporation for Atmospheric Research/Unidata.

# See netcdf-c/COPYRIGHT file for more info.
# See netcdffff-c/COPYRIGHT file for more info.
#IF(BUILD_SHARED_LIBS AND WIN32)
# remove_definitions(-DDLL_EXPORT)
# remove_definitions(-DDLL_NETCDF)
Expand All @@ -23,7 +23,8 @@ set(printfqn_FILES printfqn.c ${XGETOPTSRC})
set(ncpathcvt_FILES ncpathcvt.c ${XGETOPTSRC})
set(ncfilteravail_FILES ncfilteravail.c ${XGETOPTSRC})
set(nchdf5version_FILES nchdf5version.c)

set(echon_FILES echon.c ${XGETOPTSRC})

##
# Turn off inclusion of particular files when using the cmake-native
# option to turn on Unity Builds.
Expand All @@ -42,6 +43,7 @@ add_executable(nccopy ${nccopy_FILES})
add_executable(ncvalidator ${ncvalidator_FILES})
add_executable(ncpathcvt ${ncpathcvt_FILES})
add_executable(ncfilteravail ${ncfilteravail_FILES})
add_executable(echon ${echon_FILES})

if(USE_HDF5)
add_executable(nc4print nc4print.c nc4printer.c)
Expand All @@ -63,6 +65,7 @@ target_link_libraries(nccopy netcdf ${ALL_TLL_LIBS})
target_link_libraries(ncvalidator netcdf ${ALL_TLL_LIBS})
target_link_libraries(ncpathcvt netcdf ${ALL_TLL_LIBS})
target_link_libraries(ncfilteravail netcdf ${ALL_TLL_LIBS})
#target_link_libraries(echon netcdf ${ALL_TLL_LIBS})

if(NETCDF_ENABLE_DAP)
target_link_libraries(ocprint netcdf ${ALL_TLL_LIBS})
Expand Down Expand Up @@ -90,6 +93,7 @@ if(WIN32)
setbinprops(ncvalidator)
setbinprops(ncpathcvt)
setbinprops(ncfilteravail)
setbinprops(echon)

if(USE_HDF5)
setbinprops(printfqn)
Expand Down
4 changes: 4 additions & 0 deletions ncdump/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ utils.h utils.c dimmap.h dimmap.c list.c list.h
noinst_PROGRAMS += ncvalidator
ncvalidator_SOURCES = ncvalidator.c

# An equivalent to echo that always implements -n flag
noinst_PROGRAMS += echon
echon_SOURCES = echon.c

# A non-installed utility program to convert paths; similar to cygpath
noinst_PROGRAMS += ncpathcvt
ncpathcvt_SOURCES = ncpathcvt.c
Expand Down
94 changes: 94 additions & 0 deletions ncdump/echon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

#ifdef _WIN32
#include <windows.h>
#include <io.h>
#endif

#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif

#if defined(_WIN32) && ! defined(__MINGW32__)
#include "XGetopt.h"
#endif

int
main(int argc, char** argv)
{
int i;
int len;
char* result = NULL;
int noeol = 1; /* Default to -n vs -N */
int escape = 1; /* Ditto */
char* p = NULL;
char* q = NULL;
char c;

#ifdef _WIN32
_setmode(_fileno(stdout),_O_BINARY);
#endif

opterr = 1;
while ((c = getopt(argc, argv,"enEN")) != EOF) {
switch(c) {
case 'e': escape = 1; break;
case 'n': noeol = 1; break;
case 'E': escape = 0; break;
case 'N': noeol = 0; break;
case '?': default: break; /* ignore */
}
}

/* leave non-flag args */
argc -= optind;
argv += optind;

/* Compute the max possible length of output */
for(len=0,i=0;i<argc;i++) len += (int)strlen(argv[i]);
len += (argc - 1); /* inter-arg spacing */
result = (char*)malloc((size_t)len+1+1); /* +1 for nul term +1 for '\n' */
assert(result != NULL);
result[0] = '\0';
/* Concat all the arguments with ' ' between them */
for(i=0;i<argc;i++) {
if(i > 0) strcat(result," ");
strcat(result,argv[i]);
}
/* Optionally de-escape the result */
if(escape) {
for(p=result,q=result;*p;) {
switch (*p) {
default: *q++ = *p; break;
case '\\':
p++;
switch(*p) {
case 'a': *q++ = '\a'; break;
case 'b': *q++ = '\b'; break;
case 'f': *q++ = '\f'; break;
case 'r': *q++ = '\r'; break;
case 'n': *q++ = '\n'; break;
case 't': *q++ = '\t'; break;
case 'v': *q++ = '\v'; break;
default: *q++ = *p; break;
}
break;
}
p++;
}
} else
*q++ = *p++;
if(!noeol) *p++ = '\n';
*p = '\0';
fputs(result,stdout);
fflush(stdout);
free(result);
return 0;
}
19 changes: 2 additions & 17 deletions test_common.in
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ if test "x$SETX" = x1 ; then set -x ; fi
system=`uname`
if test "x${system##MINGW*}" = x; then
alias pwd='pwd -W'

fi

# We assume that TOPSRCDIR and TOPBUILDDIR are defined
Expand Down Expand Up @@ -198,32 +197,18 @@ fi
fi

# OS/X and windows apparently have no echo -n option, so fake it
echo "@@@FP_ISMSVC=${FP_ISMSVC}"
echo "@@@FP_ISOSX=${FP_ISOSX}"
if test "x${FP_ISMSVC}" = xyes || test "x${FP_ISOSX}" = xyes ; then
#echon() { echo "$@" | tr -d '\r\n' ; }
echo "@@@case true"
echon() {
echo "$@" | tr -d '\r\n'
}
else
echo "@@@case false"
#alias echon='echo -n'
echon() {
echo -n "$@"
${abs_top_builddir}/ncdump/echon -n $@
}
fi
declare -f echon

# Test for filter availability
avail() {
if test yes = `${execdir}/../ncdump/ncfilteravail $1` ; then return 0 ; else echo "filter $1 not available" ; return 1; fi
}


# Make sure we are in builddir (not execdir)
cd $builddir


# Parallel make can cause inter-test interference (mostly because of historical naming issues).
# As a protection against this, the isolate() function supports the creation of an
# isolation directory in which created products are stored.
Expand Down
71 changes: 29 additions & 42 deletions unit_test/run_pluginpaths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# Test the programmatic API for manipulating the plugin paths.
# This script is still full of cruft that needs to be removed

export SETX=1
set -x

if test "x$srcdir" = x ; then srcdir=`pwd`; fi
. ../test_common.sh

set -x
set -e

IMPLS=
if test "x$FEATURE_HDF5" = xyes ; then IMPLS="$IMPLS hdf5"; fi
if test "x$FEATURE_NCZARR" = xyes ; then IMPLS="$IMPLS nczarr"; fi
Expand All @@ -18,11 +18,10 @@ echo "IMPLS=|$IMPLS|"

#VERBOSE=1

# Watch out because bash will convert '/' to '\\' on windows
DFALT="\/zero;\/one;\/two;\/three;\/four"
DFALTSET="\/zero;\/one;\/mod;\/two;\/three;\/four"
DFALTHDF5="\/zero;\/one;\/two;\/hdf5;\/three;\/four"
DFALTNCZARR="\/zero;\/one;\/two;\/nczarr;three;\/four;\/five"
DFALT="/zero;/one;/two;/three;/four"
DFALTSET="/zero;/one;/mod;/two;/three;/four"
DFALTHDF5="/zero;/one;/two;/hdf5;/three;/four"
DFALTNCZARR="/zero;/one;/two;/nczarr;three;/four;/five"

if test "x$TESTNCZARR" = x1 ; then
. "$srcdir/test_nczarr.sh"
Expand Down Expand Up @@ -50,8 +49,8 @@ modfor() {
local formatx="$1"
local dfalt="$2"
case "$formatx" in
hdf5) mod="${dfalt};\/modhdf5" ;;
nczarr) mod="\/modnczarr;${dfalt}" ;;
hdf5) mod="${dfalt};/modhdf5" ;;
nczarr) mod="/modnczarr;${dfalt}" ;;
all) mode="${dfalt}" ;;
esac
}
Expand All @@ -62,46 +61,35 @@ modfor() {
# It is difficult to test for outside interference, so not attempted.
testget() {
filenamefor tmp get
# Accumulate the output to avoid use of echo
TMPGET=
# print out the global state
TMPGET="testget(global): "
TMP=`${TP} -x "set:${DFALT},get:global"`
TMPGET="${TMPGET}${TMP}"
echon "testget(global): " >> ${filename}.txt
${TP} -x "set:${DFALT},get:global" >> ${filename}.txt ;
# print out the HDF5 state
TMPGET="${TMPGET}testget(hdf5): "
TMP=`${TP} -x "set:${DFALT},get:hdf5"`
echon "testget(hdf5): " >> ${filename}.txt
${TP} -x "set:${DFALT},get:hdf5" >> ${filename}.txt ;
# print out the NCZarr state
TMPGET="${TMPGET}testget(nczarr): "
TMP=`${TP} -x "set:${DFALT},get:nczarr"`
TMPGET="${TMPGET}${TMP}"
echo "$TMPGET" | tr -d '\r' | cat >> ${filename}.txt
}
echon "testget(nczarr): " >> ${filename}.txt
${TP} -x "set:${DFALT},get:nczarr" >> ${filename}.txt ;
}

# Set the global state to some value and verify that it was sync'd to hdf5 and nczarr
testset() {
filenamefor tmp set
# print out the global state, modify it and print again
TMPSET=
TMPSET="testset(global): before: "
TMP=`${TP} -x "set:${DFALT},get:global"`
TMPSET="${TMPSET}testset(global): after: "
TMP=`${TP} -x "set:${DFALT},set:${DFALTSET},get:global"`
TMPSET="${TMPSET}${TMP}"
echon "testset(global): before: " >> ${filename}.txt
${TP} -x "set:${DFALT},get:global" >> ${filename}.txt ;
echon "testset(global): after: " >> ${filename}.txt
${TP} -x "set:${DFALT},set:${DFALTSET},get:global" >> ${filename}.txt ;
# print out the HDF5 state
TMPSET="${TMPSET}testset(hdf5): before: "
TMP=`${TP} -x "set:${DFALT},get:hdf5"`
TMPSET="${TMPSET}${TMP}"
TMPSET="${TMPSET}testset(hdf5): after: "
TMP=`${TP} -x "set:${DFALT},set:${DFALTSET},get:hdf5"`
TMPSET="${TMPSET}${TMP}"
echon "testset(hdf5): before: " >> ${filename}.txt
${TP} -x "set:${DFALT},get:hdf5" >> ${filename}.txt ;
echon "testset(hdf5): after: " >> ${filename}.txt
${TP} -x "set:${DFALT},set:${DFALTSET},get:hdf5" >> ${filename}.txt ;
# print out the NCZarr state
TMPSET="${TMPSET}testset(nczarr): before: "
TMP=`${TP} -x "set:${DFALT},get:nczarr"`
TMPSET="${TMPSET}testset(nczarr): after: "
TMP=`${TP} -x "set:${DFALT},set:${DFALTSET},get:nczarr"`
TMPSET="${TMPSET}${TMP}"
echo "$TMPGET" | tr -d '\r' | cat >> ${filename}.txt
echon "testset(nczarr): before: " >> ${filename}.txt
${TP} -x "set:${DFALT},get:nczarr" >> ${filename}.txt ;
echon "testset(nczarr): after: " >> ${filename}.txt
${TP} -x "set:${DFALT},set:${DFALTSET},get:nczarr" >> ${filename}.txt ;
}

#########################
Expand All @@ -116,8 +104,7 @@ init() {

# Verify output for a specific action
verify() {
# for action in get set ; do
for action in get ; do
for action in get set ; do
if diff -wBb ${srcdir}/ref_${action}.txt tmp_${action}.txt ; then
echo "***PASS: $action"
else
Expand Down

0 comments on commit 1c0688b

Please sign in to comment.