Skip to content

Commit

Permalink
nifti 2021-10-26 (53f295cf)
Browse files Browse the repository at this point in the history
Code extracted from:

    https://github.com/NIFTI-Imaging/nifti_clib.git

at commit 53f295cf78963058347757bbbae9584a6a8feede (master).
  • Loading branch information
NIFTI Upstream authored and thewtex committed Oct 27, 2021
1 parent 9c2c9fa commit af75181
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 48 deletions.
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ option( BUILD_SHARED_LIBS "Toggle building shared libraries." OFF)
option(NIFTI_BUILD_APPLICATIONS "Build various utility tools" ON)
mark_as_advanced(NIFTI_BUILD_APPLICATIONS)

#When including nifti as a subpackage, a prefix is often needed to avoid conflicts with sytem installed libraries.
#When including nifti as a subpackage, a prefix is often needed to avoid conflicts with system installed libraries.
set_if_not_defined(NIFTI_PACKAGE_PREFIX "")
set(PACKAGE_NAME ${NIFTI_PACKAGE_PREFIX}NIFTI)
set_if_not_defined(NIFTI_INSTALL_EXPORT_NAME ${PACKAGE_NAME}Targets)

# Set default shared library version
# This library version will be applied to all libraries in the package
# unless it is not explicitely for a certain lib.
# unless it is not explicitly for a certain lib.
set(NIFTI_SHAREDLIB_VERSION ${GIT_REPO_VERSION} )
if(BUILD_SHARED_LIBS AND NOT NIFTI_LIBRARY_PROPERTIES)
set(NIFTI_LIBRARY_PROPERTIES ${DEFAULT_SHARED_LIBS}
Expand Down Expand Up @@ -150,7 +150,9 @@ endif()

#######################################################################
# Find unix math libraries
if(NOT WIN32)
if(EMSCRIPTEN OR WASI)
set(NIFTI_SYSTEM_MATH_LIB m)
elseif(NOT WIN32)
find_library(NIFTI_SYSTEM_MATH_LIB m)
else()
set(NIFTI_SYSTEM_MATH_LIB "")
Expand Down Expand Up @@ -179,7 +181,7 @@ endif()

option(USE_FSL_CODE "If OFF, The copyright of this code is questionable for inclusion with nifti." OFF)
mark_as_advanced(USE_FSL_CODE)
# the order of add_subdirectory is important! fsliolob has to preceed examples
# the order of add_subdirectory is important! fsliolob has to precede, examples
# as otherwise FSLIOLIB_SOURCE_DIR is undefined and hence the examples
# will fail to compile
if(USE_FSL_CODE)
Expand All @@ -202,7 +204,7 @@ endif()

# Report installed targets
get_property(nifti_installed_targets GLOBAL PROPERTY nifti_installed_targets)
message("nifti_installed_targets: ${nifti_installed_targets}")
message(STATUS "nifti_installed_targets: ${nifti_installed_targets}")

if(CMAKE_VER_AT_LEAST_3_13)
# Target installation for CMake versions >=3.13
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ hope it is also a useful i/o library.
`Nifti_clib` code is released into the public domain,
developers are encouraged to incorporate niftilib code into their applications,
and, to contribute changes and enhancements to niftilib. Please contact us if
you would like to contribute additonal functionality to the i/o library.
you would like to contribute additional functionality to the i/o library.

The main webpage for this project is [hosted on github](https://nifti-imaging.github.io/).
This web site provde historical information. Additional informaiton from the [NIFTI DFWG](http://nifti.nimh.nih.gov)
This web site provde historical information. Additional information from the [NIFTI DFWG](http://nifti.nimh.nih.gov)

The testing dashboard for monitoring the health of the libraries is at
[my.cdash.org](https://my.cdash.org/index.php?project=nifti_clib).
Expand Down
4 changes: 2 additions & 2 deletions cmake/local_dashboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ set(dashboard_cache "
# Eventually USE_NIFTI1_CODE:BOOL=ON must be added.

string(TIMESTAMP build_date "%Y-%m-%d")
message("CDash Build Identifier: ${build_date} ${CTEST_BUILD_NAME}")
message("CTEST_SITE = ${CTEST_SITE}")
message(STATUS "CDash Build Identifier: ${build_date} ${CTEST_BUILD_NAME}")
message(STATUS "CTEST_SITE = ${CTEST_SITE}")
include("${CTEST_SCRIPT_DIRECTORY}/nifti_common.cmake")
8 changes: 4 additions & 4 deletions cmake/nifti_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ if(EXISTS ${CTEST_SOURCE_DIRECTORY})
set(vcs_refresh "because it is not managed by git.")
endif()
if(vcs_refresh AND "${CTEST_SOURCE_DIRECTORY}" MATCHES "/(NIFTI|nifti_clib)[^/]*")
message("Deleting source tree\n ${CTEST_SOURCE_DIRECTORY}\n${vcs_refresh}")
message(STATUS "Deleting source tree\n ${CTEST_SOURCE_DIRECTORY}\n${vcs_refresh}")
file(REMOVE_RECURSE "${CTEST_SOURCE_DIRECTORY}")
endif()
endif()
Expand Down Expand Up @@ -314,7 +314,7 @@ foreach(v
)
set(vars "${vars} ${v}=[${${v}}]\n")
endforeach(v)
message("Dashboard script configuration:\n${vars}\n")
message(STATUS "Dashboard script configuration:\n${vars}\n")

# Avoid non-ascii characters in tool output.
set(ENV{LC_ALL} C)
Expand Down Expand Up @@ -347,7 +347,7 @@ if(NOT EXISTS "${CTEST_BINARY_DIRECTORY}")
file(MAKE_DIRECTORY "${CTEST_BINARY_DIRECTORY}")
elseif(NOT "${CTEST_SOURCE_DIRECTORY}" STREQUAL "${CTEST_BINARY_DIRECTORY}"
AND NOT dashboard_no_clean)
message("Clearing build tree...")
message(STATUS "Clearing build tree...")
ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
endif()

Expand Down Expand Up @@ -425,7 +425,7 @@ while(NOT dashboard_done)
dashboard_hook_test()
endif()
ctest_test(${CTEST_TEST_ARGS} RETURN_VALUE test_return)
set(safe_message_skip 1) # Block furhter messages
set(safe_message_skip 1) # Block further messages

if(dashboard_do_coverage)
if(COMMAND dashboard_hook_coverage)
Expand Down
2 changes: 1 addition & 1 deletion cmake/nifti_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function(get_lib_version_vars version_header libver libver_major)
# Check that a valid version has been specified (of the form XX.XX.XX)
string(REGEX MATCH "^[0-9]*\.[0-9]*\.[0-9]*$" VER_MATCHED "${LIB_VERSION}" )
if("" STREQUAL "${VER_MATCHED}")
message("matched ${VER_MATCHED}")
message(STATUS "matched ${VER_MATCHED}")
message(FATAL_ERROR "Cannot find a valid version in the version header file ${version_header} (Found: '${LIB_VERSION}')")
endif()
# Set outputs in calling scope
Expand Down
4 changes: 2 additions & 2 deletions cmake/travis_dashboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ set(dashboard_cache "
# Eventually USE_NIFTI1_CODE:BOOL=ON must be added.

string(TIMESTAMP build_date "%Y-%m-%d")
message("CDash Build Identifier: ${build_date} ${CTEST_BUILD_NAME}")
message("CTEST_SITE = ${CTEST_SITE}")
message(STATUS "CDash Build Identifier: ${build_date} ${CTEST_BUILD_NAME}")
message(STATUS "CTEST_SITE = ${CTEST_SITE}")
include("${CTEST_SCRIPT_DIRECTORY}/nifti_common.cmake")
2 changes: 1 addition & 1 deletion niftilib/nifti1.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ typedef struct { unsigned char r,g,b; } rgb_byte ;
as a displacement field or vector:
- dataset must have a 5th dimension
- intent_code must be NIFTI_INTENT_DISPVECT
- dim[5] must be the dimensionality of the displacment
- dim[5] must be the dimensionality of the displacement
vector (e.g., 3 for spatial displacement, 2 for in-plane) */

#define NIFTI_INTENT_DISPVECT 1006 /* specifically for displacements */
Expand Down
28 changes: 14 additions & 14 deletions niftilib/nifti1_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static char const * const gni_history[] =
" (FMRIB Centre, University of Oxford, UK)\n"
" - Mainly adding low-level IO and changing things to allow gzipped\n"
" files to be read and written\n"
" - Full backwards compatability should have been maintained\n"
" - Full backwards compatibility should have been maintained\n"
"\n",
"0.2 16 Nov 2004 [rickr]\n"
" (Rick Reynolds of the National Institutes of Health, SSCC/DIRP/NIMH)\n"
Expand Down Expand Up @@ -265,7 +265,7 @@ static char const * const gni_history[] =
"1.12b 25 August 2005 [rickr] - changes by Hans Johnson\n",
"1.13 25 August 2005 [rickr]\n",
" - finished changes by Hans for Insight\n"
" - added const in all appropraite parameter locations (30-40)\n"
" - added const in all appropriate parameter locations (30-40)\n"
" (any pointer referencing data that will not change)\n"
" - shortened all string constants below 509 character limit\n"
"1.14 28 October 2005 [HJohnson]\n",
Expand Down Expand Up @@ -771,7 +771,7 @@ int nifti_image_load_bricks( nifti_image * nim , int nbricks,

if( rv != 0 ){
nifti_free_NBL( NBL ); /* failure! */
NBL->nbricks = 0; /* repetative, but clear */
NBL->nbricks = 0; /* repetitive, but clear */
}

if( slist ){ free(slist); free(sindex); }
Expand Down Expand Up @@ -1048,7 +1048,7 @@ int valid_nifti_brick_list(nifti_image * nim , int nbricks,

if( nim->dim[0] < 3 ){
if( disp_error || g_opts.debug > 1 )
fprintf(stderr,"** cannot read explict brick list from %d-D dataset\n",
fprintf(stderr,"** cannot read explicit brick list from %d-D dataset\n",
nim->dim[0]);
return 0;
}
Expand Down Expand Up @@ -1945,7 +1945,7 @@ mat33 nifti_mat33_polar( mat33 A )
}

/*---------------------------------------------------------------------------*/
/*! compute the (closest) orientation from a 4x4 ijk->xyz tranformation matrix
/*! compute the (closest) orientation from a 4x4 ijk->xyz transformation matrix
<pre>
Input: 4x4 matrix that transforms (i,j,k) indexes to (x,y,z) coordinates,
Expand Down Expand Up @@ -2136,7 +2136,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod )
/*! swap each byte pair from the given list of n pairs
*
* Due to alignment of structures at some architectures (e.g. on ARM),
* stick to char varaibles.
* stick to char variables.
* Fixes http://bugs.debian.org/446893 Yaroslav <debian@onerussian.com>
*
*//*--------------------------------------------------------------------*/
Expand Down Expand Up @@ -2781,7 +2781,7 @@ char * nifti_findhdrname(const char* fname)

/* note: efirst is 0 in the case of ".img" */

/* if the user passed an uppercase entension (.IMG), search for uppercase */
/* if the user passed an uppercase extension (.IMG), search for uppercase */
if( eisupper ) {
make_uppercase(elist[0]);
make_uppercase(elist[1]);
Expand Down Expand Up @@ -3107,11 +3107,11 @@ int nifti_set_filenames( nifti_image * nim, const char * prefix, int check,
- if type 1, expect .nii (and names must match)
\param nim given nifti_image
\param show_warn if set, print a warning message for any mis-match
\param show_warn if set, print a warning message for any mismatch
\return
- 1 if the values seem to match
- 0 if there is a mis-match
- 0 if there is a mismatch
- -1 if there is not sufficient information to create file(s)
\sa NIFTI_FTYPE_* codes in nifti1_io.h
Expand Down Expand Up @@ -3163,7 +3163,7 @@ int nifti_type_and_names_match( nifti_image * nim, int show_warn )
errs++;
}

if( errs ) return 0; /* do not proceed, but this is just a mis-match */
if( errs ) return 0; /* do not proceed, but this is just a mismatch */

/* general tests */
if( nim->nifti_type == NIFTI_FTYPE_NIFTI1_1 ){ /* .nii */
Expand Down Expand Up @@ -3676,7 +3676,7 @@ nifti_image* nifti_convert_nhdr2nim(struct nifti_1_header nhdr,
if( nhdr.dim[ii] <= 0 ) nhdr.dim[ii] = 1 ;

/* fix any remaining bad dim[] values, so garbage does not propagate */
/* (only values 0 or 1 seem rational, otherwise set to arbirary 1) */
/* (only values 0 or 1 seem rational, otherwise set to arbitrary 1) */
for( ii=nhdr.dim[0]+1 ; ii <= 7 ; ii++ )
if( nhdr.dim[ii] != 1 && nhdr.dim[ii] != 0) nhdr.dim[ii] = 1 ;

Expand Down Expand Up @@ -5374,7 +5374,7 @@ nifti_1_header * nifti_make_new_header(const int arg_dims[], int arg_dtype)
/*! basic creation of a nifti_image struct
Create a nifti_image from the given dimensions and data type.
Optinally, allocate zero-filled data.
Optionally, allocate zero-filled data.
\param dims : optional dim[8] (default {3,1,1,1,0,0,0,0})
\param datatype : optional datatype (default DT_FLOAT32)
Expand Down Expand Up @@ -5578,7 +5578,7 @@ int nifti_copy_extensions(nifti_image * nim_dest, const nifti_image * nim_src)
/* data length is size-8, as esize includes space for esize and ecode */
data = (char *)calloc(size-8,sizeof(char)); /* maybe size > old */
if( !data ){
fprintf(stderr,"** failed to alloc %d bytes for extention\n", size);
fprintf(stderr,"** failed to alloc %d bytes for extension\n", size);
if( c == 0 ) { free(nim_dest->ext_list); nim_dest->ext_list = NULL; }
/* otherwise, keep what we have (a.o.t. deleting them all) */
return -1;
Expand Down Expand Up @@ -6852,7 +6852,7 @@ compute_strides(int *strides,const int *size,int nbyper)
/*---------------------------------------------------------------------------*/
/*! read an arbitrary subregion from a nifti image
This function may be used to read a single arbitary subregion of any
This function may be used to read a single arbitrary subregion of any
rectangular size from a nifti dataset, such as a small 5x5x5 subregion
around the center of a 3D image.
Expand Down
4 changes: 2 additions & 2 deletions niftilib/nifti1_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern "C" {
Mainly adding low-level IO and changing things to allow gzipped files
to be read and written
Full backwards compatability should have been maintained
Full backwards compatibility should have been maintained
Modified by: Rick Reynolds (SSCC/DIRP/NIMH, National Institutes of Health)
Date: December 2004
Expand Down Expand Up @@ -515,7 +515,7 @@ typedef struct {
char const * const name; /* text string to match #define */
} nifti_type_ele;

#undef LNI_FERR /* local nifti file error, to be compact and repetative */
#undef LNI_FERR /* local nifti file error, to be compact and repetitive */
#define LNI_FERR(func,msg,file) \
fprintf(stderr,"** ERROR (%s): %s '%s'\n",func,msg,file)

Expand Down
24 changes: 12 additions & 12 deletions niftilib/nifti1_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static const char * g_history[] =
"\n",
"1.1 14 January 2005 [rickr]\n"
" - changed all non-error/non-debug output from stderr to stdout\n"
" note: creates a mis-match between normal output and debug messages\n"
" note: creates a mismatch between normal output and debug messages\n"
" - modified act_diff_hdrs and act_diff_nims to do the processing in\n"
" lower-level functions\n",
" - added functions diff_hdrs, diff_hdrs_list, diff_nims, diff_nims_list\n"
Expand Down Expand Up @@ -229,7 +229,7 @@ int main( int argc, char * argv[] )
if((opts.swap_hdr || opts.swap_ana || opts.swap_old )
&& ((rv = act_swap_hdrs (&opts)) != 0) ) FREE_RETURN(rv);

/* if a diff, return wither a difference exists (like the UNIX command) */
/* if a diff, return whether, a difference exists (like the UNIX command) */
if( opts.diff_hdr && ((rv = act_diff_hdrs(&opts)) != 0) ) FREE_RETURN(rv);
if( opts.diff_nim && ((rv = act_diff_nims(&opts)) != 0) ) FREE_RETURN(rv);

Expand Down Expand Up @@ -341,7 +341,7 @@ int process_opts( int argc, char * argv[], nt_opts * opts )
for( index = 1; index < 8; index++ )
{
ac++;
CHECK_NEXT_OPT_MSG(ac,argc,"-cci","7 dimension values are requred");
CHECK_NEXT_OPT_MSG(ac,argc,"-cci","7 dimension values are required");
if( ! isdigit(argv[ac][0]) && strcmp(argv[ac],"-1") ){
fprintf(stderr,"** -cci param %d (= '%s') is not a valid\n"
" consider: 'nifti_tool -help'\n",index,argv[ac]);
Expand Down Expand Up @@ -385,7 +385,7 @@ int process_opts( int argc, char * argv[], nt_opts * opts )
{
ac++;
CHECK_NEXT_OPT_MSG(ac,argc,"-disp_ci",
"7 dimension values are requred");
"7 dimension values are required");
if( ! isdigit(argv[ac][0]) && strcmp(argv[ac],"-1") ){
fprintf(stderr,"** -disp_ci param %d (= '%s') is not a valid\n"
" consider: 'nifti_tool -help'\n",index,argv[ac]);
Expand All @@ -404,7 +404,7 @@ int process_opts( int argc, char * argv[], nt_opts * opts )
for( index = 1; index <= 3; index++ )
{
ac++;
CHECK_NEXT_OPT_MSG(ac,argc,"-dts","i,j,k indices are requied\n");
CHECK_NEXT_OPT_MSG(ac,argc,"-dts","i,j,k indices are required\n");
if( ! isdigit(argv[ac][0]) ){
fprintf(stderr,"** -dts param %d (= '%s') is not a number\n"
" consider: 'nifti_tool -help'\n",index,argv[ac]);
Expand Down Expand Up @@ -460,7 +460,7 @@ int process_opts( int argc, char * argv[], nt_opts * opts )
for( index = 0; index < 8; index++ )
{
ac++;
CHECK_NEXT_OPT_MSG(ac,argc,"-new_dim","8 dim values are requred");
CHECK_NEXT_OPT_MSG(ac,argc,"-new_dim","8 dim values are required");
if( ! isdigit(argv[ac][0]) && strcmp(argv[ac],"-1") ){
fprintf(stderr,"** -new_dim param %d (= '%s') is not a valid\n"
" consider: 'nifti_tool -help'\n",index,argv[ac]);
Expand Down Expand Up @@ -1061,7 +1061,7 @@ int use_full(const char * prog )
" nifti_tool -check_hdr -infiles dset0.nii dset1.nii\n"
" nifti_tool -check_hdr -infiles *.nii *.hdr\n"
" \n"
" e.g. add the -quiet option, so that only errros are reported\n"
" e.g. add the -quiet option, so that only errors are reported\n"
" nifti_tool -check_hdr -quiet -infiles *.nii *.hdr\n"
"\n");
printf(
Expand Down Expand Up @@ -2581,7 +2581,7 @@ int act_mod_hdrs( nt_opts * opts )
}
if( opts->keep_hist && nifti_add_extension(nim, opts->command,
strlen(opts->command), NIFTI_ECODE_COMMENT) )
fprintf(stderr,"** failed to add command to image as exten\n");
fprintf(stderr,"** failed to add command to image as extension\n");
if( nifti_set_filenames(nim, opts->prefix, 1, 1) )
{
NTL_FERR(func,"failed to set prefix for new file: ",opts->prefix);
Expand Down Expand Up @@ -2696,7 +2696,7 @@ int act_swap_hdrs( nt_opts * opts )
}
if( opts->keep_hist && nifti_add_extension(nim, opts->command,
strlen(opts->command), NIFTI_ECODE_COMMENT) )
fprintf(stderr,"** failed to add command to image as exten\n");
fprintf(stderr,"** failed to add command to image as extension\n");
if( nifti_set_filenames(nim, opts->prefix, 1, 1) )
{
NTL_FERR(func,"failed to set prefix for new file: ",opts->prefix);
Expand Down Expand Up @@ -4067,7 +4067,7 @@ nifti_image * nt_image_read( nt_opts * opts, const char * fname, int doread )
return nifti_image_read(fname, doread);
}

/* so generate an emtpy image */
/* so generate an empty image */
if(g_debug > 1) {
fprintf(stderr,"+d NT_IR: generating EMPTY IMAGE from %s...\n",fname);
if(g_debug > 2) {
Expand Down Expand Up @@ -4106,7 +4106,7 @@ nifti_1_header * nt_read_header(nt_opts * opts, const char * fname, int * swappe
return nifti_read_header(fname, swapped, check);
}

/* so generate an emtpy image */
/* so generate an empty image */
if(g_debug > 1) {
fprintf(stderr,"+d NT_RH: generating EMPTY IMAGE from %s...\n",fname);
if(g_debug > 2) {
Expand Down Expand Up @@ -4149,7 +4149,7 @@ nifti_image * nt_read_bricks(nt_opts * opts, const char * fname, int len, int *
return nifti_image_read_bricks(fname, len, list, NBL);
}

/* so generate an emtpy image */
/* so generate an empty image */
if(g_debug > 1) {
fprintf(stderr,"+d NT_RB: generating EMPTY IMAGE from %s...\n",fname);
if(g_debug > 2) {
Expand Down
6 changes: 3 additions & 3 deletions niftilib/nifti_tester001.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ nifti_image * generate_reference_image( const char * write_image_filename , int
reference_header.dim[3]=11;
reference_header.dim[4]=7;
reference_header.dim[5]=3;
reference_header.dim[6]=1; //This MUST be 1 anything else is invalid due to code that usees huristics to fix other possible problems;
reference_header.dim[7]=1; //This MUST be 1 anything else is invalid due to code that usees huristics to fix other possible problems;
reference_header.dim[6]=1; //This MUST be 1 anything else is invalid due to code that uses heuristics to fix other possible problems;
reference_header.dim[7]=1; //This MUST be 1 anything else is invalid due to code that uses heuristics to fix other possible problems;
reference_header.intent_p1=10101010.101F;
reference_header.intent_p2=987654321.0F;
reference_header.intent_p3=-1234.0F;
Expand Down Expand Up @@ -84,7 +84,7 @@ nifti_image * generate_reference_image( const char * write_image_filename , int
reference_header.magic[3]='\0';
/* String is purposfully too long */
strncpy(reference_header.intent_name,"PHANTOM_DATA to be used for regression testing the nifti reader/writer",16);
strncpy(reference_header.descrip,"This is a very long dialog here to use up more than 80 characters of space to test to see if the code is robust enough to deal appropriatly with very long and obnoxious lines.",80);
strncpy(reference_header.descrip,"This is a very long dialog here to use up more than 80 characters of space to test to see if the code is robust enough to deal appropriately with very long and obnoxious lines.",80);

{
int nbyper;
Expand Down

0 comments on commit af75181

Please sign in to comment.