Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cifti/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ if(NIFTI_BUILD_APPLICATIONS)
install_nifti_target(${NIFTI_PACKAGE_PREFIX}afni_xml_tool)
install_nifti_target(${NIFTI_PACKAGE_PREFIX}cifti_tool)
endif()

if(NIFTI_BUILD_TESTING)
add_executable(${NIFTI_PACKAGE_PREFIX}test_axml_recur_find_xml test_axml_recur_find_xml.c)
target_link_libraries(${NIFTI_PACKAGE_PREFIX}test_axml_recur_find_xml PRIVATE ${NIFTI_CIFTILIB_NAME})
add_test(NAME ${NIFTI_PACKAGE_PREFIX}axml_recur_find_xml
COMMAND $<TARGET_FILE:${NIFTI_PACKAGE_PREFIX}test_axml_recur_find_xml>)
endif()
2 changes: 1 addition & 1 deletion cifti/afni_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ afni_xml_t * axml_recur_find_xml(int(*func)(afni_xml_t *, int), afni_xml_t * ax,
/* search deeper */
if( ax->nchild > 0 && ax->xchild )
for( ind=0; ind < ax->nchild; ind++ ) {
rv = axml_recur_find_xml(func, ax, depth+1, max_depth);
rv = axml_recur_find_xml(func, ax->xchild[ind], depth+1, max_depth);
if( rv ) return rv;
}

Expand Down
2 changes: 2 additions & 0 deletions cifti/afni_xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ int axml_free_xlist(afni_xml_list * axlist);

char * axml_attr_value(afni_xml_t * ax, const char * name);
int axml_recur(int(*func)(FILE*,afni_xml_t*,int), afni_xml_t * ax);
afni_xml_t * axml_recur_find_xml(int (*func)(afni_xml_t *, int), afni_xml_t * ax,
Comment thread
hjmjohnson marked this conversation as resolved.
Resolved
int depth, int max_depth);


/* control API */
Expand Down
55 changes: 55 additions & 0 deletions cifti/test_axml_recur_find_xml.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <stdio.h>
#include <string.h>

#include "afni_xml.h"

static int is_target(afni_xml_t * ax, int depth)
{
(void)depth;
return ax->name && strcmp(ax->name, "target") == 0;
}

static int check(const char * label, afni_xml_t * got, afni_xml_t * want)
{
if( got == want ) return 0;
fprintf(stderr, "FAIL %s: got %p, want %p\n", label, (void *)got, (void *)want);
return 1;
}

int main(void)
{
char root_name[] = "root", mid_name[] = "mid";
char other_name[] = "other", target_name[] = "target";
afni_xml_t root, mid, other, target;
afni_xml_t * root_kids[2];
afni_xml_t * mid_kids[1];
int nfail = 0;

memset(&root, 0, sizeof(root));
memset(&mid, 0, sizeof(mid));
memset(&other, 0, sizeof(other));
memset(&target, 0, sizeof(target));

root.name = root_name;
other.name = other_name;
mid.name = mid_name;
target.name = target_name;

root_kids[0] = &other;
root_kids[1] = &mid;
root.nchild = 2;
root.xchild = root_kids;

mid_kids[0] = &target;
mid.nchild = 1;
mid.xchild = mid_kids;

nfail += check("depth limit reaches target", axml_recur_find_xml(is_target, &root, 0, 2), &target);
nfail += check("depth limit stops short", axml_recur_find_xml(is_target, &root, 0, 1), NULL);
nfail += check("unlimited depth", axml_recur_find_xml(is_target, &root, 0, 0), &target);
nfail += check("leaf without match", axml_recur_find_xml(is_target, &other, 0, 0), NULL);

if( nfail ) return 1;
printf("axml_recur_find_xml: all checks passed\n");
return 0;
}
59 changes: 19 additions & 40 deletions fsliolib/fslio.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
#include "fslio.h"
#include "assert.h"

/* Internal: no header declares these and nothing outside this file calls them. */
static int FslIsValidFileType(int filetype);
static int FslGetFileType2(const FSLIO *fslio, int quiet);
static int FslFileType(const char *fname);
static int FslGetReadFileType(const FSLIO *fslio);
static void FslInit4Write(FSLIO* fslio, const char* filename, int ft);
static int fsl_fileexists(const char* fname);
static int check_for_multiple_filenames(const char* filename);

static int FslIgnoreMFQ=0;
static int FslOverrideOutputType=-1;

Expand Down Expand Up @@ -56,7 +65,7 @@ const char* FslFileTypeString(int filetype)
}


int FslIsValidFileType(int filetype)
static int FslIsValidFileType(int filetype)
{
if ( (filetype!=FSL_TYPE_ANALYZE) && (filetype!=FSL_TYPE_ANALYZE_GZ) &&
(filetype!=FSL_TYPE_NIFTI) && (filetype!=FSL_TYPE_NIFTI_GZ) &&
Expand Down Expand Up @@ -85,7 +94,7 @@ int FslBaseFileType(int filetype)
}


int FslGetFileType2(const FSLIO *fslio, int quiet)
static int FslGetFileType2(const FSLIO *fslio, int quiet)
{
if (fslio==NULL) FSLIOERR("FslGetFileType: Null pointer passed for FSLIO");
if ( (fslio->file_mode==FSL_TYPE_MINC) || (fslio->file_mode==FSL_TYPE_MINC_GZ) ) {
Expand Down Expand Up @@ -188,7 +197,7 @@ int FslGetEnvOutputType(void)
}


int FslFileType(const char* fname)
static int FslFileType(const char* fname)
{
/* return type is FSL_TYPE_* or -1 to indicate undetermined */
/* use name as first priority but if that is ambiguous then resolve using environment */
Expand Down Expand Up @@ -222,7 +231,7 @@ int FslFileType(const char* fname)
/************************************************************
* FslGetReadFileType
************************************************************/
/*! \fn int FslGetReadFileType(const FSLIO *fslio)
/*! \fn static int FslGetReadFileType(const FSLIO *fslio)
\brief return the best estimate of the true file type

This function is used to return the best estimate of the true file type once
Expand Down Expand Up @@ -387,7 +396,7 @@ void FslSetInit(FSLIO* fslio)



void FslInit4Write(FSLIO* fslio, const char* filename, int ft)
static void FslInit4Write(FSLIO* fslio, const char* filename, int ft)
{
/* ft determines filetype if ft>=0*/
int imgtype;
Expand Down Expand Up @@ -500,7 +509,7 @@ void FslCloneHeader(FSLIO *dest, const FSLIO *src)
}


int fsl_fileexists(const char* fname)
static int fsl_fileexists(const char* fname)
{
znzFile fp;
fp = znzopen( fname , "rb" , 1 ) ;
Expand Down Expand Up @@ -557,7 +566,7 @@ int FslCheckForMultipleFileNames(const char* filename)



int check_for_multiple_filenames(const char* filename)
static int check_for_multiple_filenames(const char* filename)
{
char *basename, *tmpname;
char *otype;
Expand Down Expand Up @@ -1340,8 +1349,9 @@ void FslGetAuxFile(FSLIO *fslio,char *aux_file)
{
if (fslio==NULL) FSLIOERR("FslGetAuxFile: Null pointer passed for FSLIO");
if (fslio->niftiptr!=NULL) {
strncpy(aux_file,fslio->niftiptr->aux_file, 24);
aux_file[24-1] = '\0';
/* the caller's buffer must hold as many bytes as nifti_image aux_file */
strncpy(aux_file,fslio->niftiptr->aux_file,sizeof(fslio->niftiptr->aux_file)-1);
aux_file[sizeof(fslio->niftiptr->aux_file)-1] = '\0';
}
if (fslio->mincptr!=NULL) {
fprintf(stderr,"Warning:: Minc is not yet supported\n");
Expand All @@ -1362,37 +1372,6 @@ void FslSetAuxFile(FSLIO *fslio,const char *aux_file)
}


void FslSetVoxUnits(FSLIO *fslio, const char *units)
{
int unitcode=0;
if (fslio==NULL) FSLIOERR("FslSetVoxUnits: Null pointer passed for FSLIO");
if (fslio->niftiptr!=NULL) {
if (strcmp(units,nifti_units_string(NIFTI_UNITS_METER))==0) {
unitcode = NIFTI_UNITS_METER;
} else if (strcmp(units,nifti_units_string(NIFTI_UNITS_MM))==0) {
unitcode = NIFTI_UNITS_MM;
} else if (strcmp(units,nifti_units_string(NIFTI_UNITS_MICRON))==0) {
unitcode = NIFTI_UNITS_MICRON;
}
fslio->niftiptr->xyz_units = unitcode;
}
if (fslio->mincptr!=NULL) {
fprintf(stderr,"Warning:: Minc is not yet supported\n");
}
}


void FslGetVoxUnits(FSLIO *fslio, char *units)
{
if (fslio==NULL) FSLIOERR("FslGetVoxUnits: Null pointer passed for FSLIO");
if (fslio->niftiptr!=NULL) {
strcpy(units,nifti_units_string(fslio->niftiptr->xyz_units));
}
if (fslio->mincptr!=NULL) {
fprintf(stderr,"Warning:: Minc is not yet supported\n");
}
}

void FslSetTimeUnits(FSLIO *fslio, const char *units)
{
int unitcode=0;
Expand Down
3 changes: 3 additions & 0 deletions fsliolib/fslio.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ FSL_API void FslWriteHeader(FSLIO *fslio);

FSL_API int FslFileExists(const char *filename);
FSL_API char *FslMakeBaseName(const char *fname);
FSL_API void FslGetHdrImgNames(const char* filename, const FSLIO* fslio,
char** hdrname, char** imgname);
FSL_API int FslCheckForMultipleFileNames(const char* filename);
FSL_API int FslGetEnvOutputType(void);

Expand Down Expand Up @@ -233,6 +235,7 @@ FSL_API void FslGetTimeUnits(FSLIO *fslio, char *units);
FSL_API void FslSetDataType(FSLIO *fslio, short t);
FSL_API size_t FslGetDataType(FSLIO *fslio, short *t);
FSL_API int FslGetIntensityScaling(FSLIO *fslio, float *slope, float *intercept);
FSL_API void FslSetIntensityScaling(FSLIO *fslio, float slope, float intercept);
FSL_API void FslSetIntent(FSLIO *fslio, short intent_code, float p1, float p2, float p3);
FSL_API short FslGetIntent(FSLIO *fslio, short *intent_code, float *p1, float *p2,
float *p3);
Expand Down
7 changes: 5 additions & 2 deletions nifti2/nifti2_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ static const nifti_type_ele nifti_type_list[] = {
{ 2304, 4, 0, "NIFTI_TYPE_RGBA32" },
};

/* also defined in libniftiio; both export it */
int nifti_fileexists(const char* fname);
Comment thread
hjmjohnson marked this conversation as resolved.
Resolved

/*---------------------------------------------------------------------------*/
/* prototypes for internal functions - not part of exported library */

Expand Down Expand Up @@ -7867,7 +7870,7 @@ znzFile nifti_image_write_hdr_img2(nifti_image *nim, int write_opts,

#ifdef PIGZ
#ifdef HAVE_ZLIB
int doPigz2(nifti_image *nim, struct nifti_2_header nhdr, const nifti_brick_list * NBL) {
static int doPigz2(nifti_image *nim, struct nifti_2_header nhdr, const nifti_brick_list * NBL) {
FILE *pigzPipe;
char command[768];
strcpy(command, "pigz" );
Expand Down Expand Up @@ -7899,7 +7902,7 @@ int doPigz2(nifti_image *nim, struct nifti_2_header nhdr, const nifti_brick_list
return 0;
}

int doPigz(nifti_image *nim, struct nifti_1_header nhdr, const nifti_brick_list * NBL) {
static int doPigz(nifti_image *nim, struct nifti_1_header nhdr, const nifti_brick_list * NBL) {
FILE *pigzPipe;
char command[768];
strcpy(command, "pigz" );
Expand Down
37 changes: 4 additions & 33 deletions niftilib/nifti1_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ static const nifti_type_ele nifti_type_list[] = {
{ 2304, 4, 0, "NIFTI_TYPE_RGBA32" },
};

/* also defined in libnifti2; both export it */
int nifti_fileexists(const char* fname);

/*---------------------------------------------------------------------------*/
/* prototypes for internal functions - not part of exported library */

Expand Down Expand Up @@ -5776,39 +5779,7 @@ znzFile nifti_image_write_hdr_img2(nifti_image *nim, int write_opts,

#ifdef PIGZ
#ifdef HAVE_ZLIB
int doPigz2(nifti_image *nim, struct nifti_1_header nhdr, const nifti_brick_list * NBL) {
FILE *pigzPipe;
char command[768];
strcpy(command, "pigz" );
strcat(command, " -n -f > \"");
strcat(command, nim->fname);
strcat(command, "\"");
#ifdef _MSC_VER
if (( pigzPipe = _popen(command, "w")) == NULL)
return -1;
#else
if (( pigzPipe = popen(command, "w")) == NULL)
return -1;
#endif
znzFile fp;
fp = (znzFile) calloc(1,sizeof(struct znzptr));
fp->zfptr = NULL;
fp->withz = 0;
fp->nzfptr = pigzPipe;
fwrite(&nhdr, sizeof(nhdr), 1, pigzPipe);
if( nim->nifti_type != NIFTI_FTYPE_ANALYZE )
nifti_write_extensions(fp,nim);
nifti_write_all_data(fp,nim,NBL);
#ifdef _MSC_VER
_pclose(pigzPipe);
#else
pclose(pigzPipe);
#endif
free(fp);
return 0;
}

int doPigz(nifti_image *nim, struct nifti_1_header nhdr, const nifti_brick_list * NBL) {
static int doPigz(nifti_image *nim, struct nifti_1_header nhdr, const nifti_brick_list * NBL) {
FILE *pigzPipe;
char command[768];
strcpy(command, "pigz" );
Expand Down
Loading