-
Notifications
You must be signed in to change notification settings - Fork 1
Nifti image conflicted names #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3740,7 +3740,23 @@ char * nifti_findhdrname(const char* fname) | |
|
|
||
| strcpy(hdrname,basename); | ||
| strcat(hdrname,elist[efirst]); | ||
| #ifdef FSLSTYLE | ||
| if (nifti_fileexists(hdrname)) { | ||
| free(basename); | ||
| char *gzname = (char *)calloc(sizeof(char),strlen(hdrname)+8); | ||
| strcpy(gzname, hdrname); | ||
| strcat(gzname,extzip); | ||
|
Comment on lines
+3747
to
+3748
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. strcpy and strcat should not be used in new code |
||
| if (nifti_fileexists(gzname)) { | ||
| fprintf(stderr,"Image Exception : Multiple possible filenames detected for basename (*.nii, *.nii.gz): %s\n", basename); | ||
| free(gzname); | ||
| exit(134); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 134? Also, it doesn't seem appropriate for library code to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compile directive
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So that's a SIGABRT. If we really need to emulate that, better to call But what would happen if we just |
||
| } | ||
| free(gzname); | ||
| return hdrname; | ||
| } | ||
| #else | ||
| if (nifti_fileexists(hdrname)) { free(basename); return hdrname; } | ||
| #endif | ||
| #ifdef HAVE_ZLIB | ||
| strcat(hdrname,extzip); | ||
| if (nifti_fileexists(hdrname)) { free(basename); return hdrname; } | ||
|
|
@@ -5288,14 +5304,14 @@ nifti_1_header * nifti_read_n1_hdr(const char * hname, int *swapped, int check) | |
| hfile = nifti_findhdrname(hname); | ||
| if( hfile == NULL ){ | ||
| if( g_opts.debug > 0 ) | ||
| LNI_FERR(fname,"failed to find header file for", hname); | ||
| LNI_FERR(fname,"failed to find N1 header file for", hname); | ||
| return NULL; | ||
| } else if( g_opts.debug > 1 ) | ||
| fprintf(stderr,"-d %s: found header filename '%s'\n",fname,hfile); | ||
|
|
||
| fp = znzopen( hfile, "rb", nifti_is_gzfile(hfile) ); | ||
| if( znz_isnull(fp) ){ | ||
| if( g_opts.debug > 0 ) LNI_FERR(fname,"failed to open header file",hfile); | ||
| if( g_opts.debug > 0 ) LNI_FERR(fname,"failed to open N1 header file",hfile); | ||
| free(hfile); | ||
| return NULL; | ||
| } | ||
|
|
@@ -5389,7 +5405,7 @@ nifti_2_header * nifti_read_n2_hdr(const char * hname, int * swapped, | |
| hfile = nifti_findhdrname(hname); | ||
| if( hfile == NULL ){ | ||
| if( g_opts.debug > 0 ) | ||
| LNI_FERR(fname,"failed to find header file for", hname); | ||
| LNI_FERR(fname,"failed to find N2 header file for", hname); | ||
| return NULL; | ||
| } else if( g_opts.debug > 1 ) | ||
| fprintf(stderr,"-d %s: found N2 header filename '%s'\n",fname,hfile); | ||
|
|
@@ -5731,7 +5747,7 @@ void * nifti_read_header( const char *hname, int *nver, int check ) | |
| hfile = nifti_findhdrname(hname); | ||
| if( hfile == NULL ){ | ||
| if(g_opts.debug > 0) | ||
| LNI_FERR(fname,"failed to find header file for", hname); | ||
| LNI_FERR(fname,"failed to find any header file for", hname); | ||
| return NULL; /* check return */ | ||
| } else if( g_opts.debug > 2 ) | ||
| fprintf(stderr,"-d %s: found header filename '%s'\n",fname,hfile); | ||
|
|
@@ -5742,7 +5758,7 @@ void * nifti_read_header( const char *hname, int *nver, int check ) | |
| /**- open file, separate reading of header, extensions and data */ | ||
| fp = znzopen(hfile, "rb", nifti_is_gzfile(hfile)); | ||
| if( znz_isnull(fp) ){ | ||
| if( g_opts.debug > 0 ) LNI_FERR(fname,"failed to open header file",hfile); | ||
| if( g_opts.debug > 0 ) LNI_FERR(fname,"failed to open any header file",hfile); | ||
| free(hfile); | ||
| return NULL; | ||
| } | ||
|
|
@@ -5885,7 +5901,7 @@ nifti_image *nifti_image_read( const char *hname , int read_data ) | |
| /**- open file, separate reading of header, extensions and data */ | ||
| fp = znzopen(hfile, "rb", nifti_is_gzfile(hfile)); | ||
| if( znz_isnull(fp) ){ | ||
| if( g_opts.debug > 0 ) LNI_FERR(fname,"failed to open header file",hfile); | ||
| if( g_opts.debug > 0 ) LNI_FERR(fname,"failed to open a header file",hfile); | ||
| free(hfile); | ||
| return NULL; | ||
| } | ||
|
|
@@ -5949,6 +5965,13 @@ nifti_image *nifti_image_read( const char *hname , int read_data ) | |
| znzclose(fp); free(hfile); return NULL; | ||
| } | ||
|
|
||
| #ifdef REJECT_COMPLEX | ||
| if ((nim->datatype == DT_COMPLEX64) || (nim->datatype == DT_COMPLEX128) || (nim->datatype == DT_COMPLEX256)) { | ||
| fprintf(stderr,"Image Exception Unsupported datatype (COMPLEX64): use fslcomplex to manipulate: %s\n", hname); | ||
|
seanm marked this conversation as resolved.
|
||
| exit(13); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 13? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a few years ago, perhaps that was the output of fsl tools at the time. Feel free to change this to 134 as that is what I get with the current version of fslmaths (the FSL error is odd, the tools work fine with float 32, so the error really refers to the enumeration for DT_COMPLEX64 which is 32. $ fslmaths complex.nii.gz -add 0 sfsf
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And you actually need that exact error code? As I said in another comment, it's not ideal IMHO to call exit() in a library... |
||
| } | ||
| #endif | ||
|
|
||
| if( nim == NULL ){ | ||
| znzclose( fp ) ; /* close the file */ | ||
| if( g_opts.debug > 0 ) | ||
|
|
@@ -7473,6 +7496,10 @@ int nifti_convert_nim2n1hdr(const nifti_image * nim, nifti_1_header * hdr) | |
| nhdr.qoffset_z = nim->qoffset_z ; | ||
| nhdr.pixdim[0] = (nim->qfac >= 0.0) ? 1.0F : -1.0F ; | ||
| } | ||
| #ifdef FSLSTYLE | ||
| else //this helps for regression testing between this library and fsl, there is no other purpose. Without this you get false alarms | ||
| nhdr.pixdim[0] = 1.0; //default if unknown and not needed | ||
| #endif | ||
|
|
||
| if( nim->sform_code > 0 ){ | ||
| nhdr.sform_code = nim->sform_code ; | ||
|
|
@@ -7584,6 +7611,10 @@ int nifti_convert_nim2n2hdr(const nifti_image * nim, nifti_2_header * hdr) | |
| nhdr.qoffset_z = nim->qoffset_z ; | ||
| nhdr.pixdim[0] = (nim->qfac >= 0.0) ? 1.0F : -1.0F ; | ||
| } | ||
| #ifdef FSLSTYLE | ||
| else //this helps for regression testing between this library and fsl, there is no other purpose. Without this you get false alarms | ||
| nhdr.pixdim[0] = 1.0; //default if unknown and not needed | ||
| #endif | ||
|
|
||
| if( nim->sform_code > 0 ){ | ||
| nhdr.sform_code = nim->sform_code ; | ||
|
|
@@ -7807,6 +7838,73 @@ znzFile nifti_image_write_hdr_img2(nifti_image *nim, int write_opts, | |
| if( imgfile ) *imgfile = fp; \ | ||
| return 1 ; } while(0) | ||
|
|
||
| #ifdef PIGZ | ||
| #ifdef HAVE_ZLIB | ||
| int doPigz2(nifti_image *nim, struct nifti_2_header nhdr, const nifti_brick_list * NBL) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| FILE *pigzPipe; | ||
| char command[768]; | ||
| strcpy(command, "pigz" ); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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; | ||
|
seanm marked this conversation as resolved.
|
||
| 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) { | ||
| 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; | ||
| } | ||
| #endif //HAVE_ZLIB | ||
| #endif //PIGZ | ||
|
|
||
| /* ----------------------------------------------------------------------*/ | ||
| /*! This writes the header (and optionally the image data) to file | ||
|
|
@@ -7915,6 +8013,28 @@ static int nifti_image_write_engine(nifti_image *nim, int write_opts, | |
| /* we will write the header to a new file */ | ||
| if( g_opts.debug > 2 ) | ||
| fprintf(stderr,"+d opening output file %s [%s]\n",nim->fname,opts); | ||
|
|
||
| #ifdef PIGZ | ||
| #ifdef HAVE_ZLIB | ||
| if ((( nim->nifti_type == NIFTI_FTYPE_NIFTI1_1 ) || (nim->nifti_type == NIFTI_FTYPE_NIFTI2_1 )) && (nifti_is_gzfile(nim->fname)) && (!leave_open) && (write_data) ) { | ||
| const char *key = "AFNI_COMPRESSOR"; | ||
| char *value; | ||
| value = getenv(key); | ||
| //export AFNI_COMPRESSOR=PIGZ | ||
| char pigzKey[5] = "PIGZ"; | ||
| if ((value != NULL) && (strstr(value,pigzKey))) { | ||
| if( nver == 2 ) { | ||
| if (doPigz2(nim, n2hdr, NBL) == 0) | ||
| return 0; | ||
| } else { | ||
| if (doPigz(nim, n1hdr, NBL) == 0) //success writing with pigz | ||
| return 0; | ||
| } | ||
| } | ||
| } | ||
| #endif //HAVE_ZLIB | ||
| #endif //PIGZ | ||
|
|
||
| fp = znzopen( nim->fname , opts , nifti_is_gzfile(nim->fname) ) ; | ||
| if( znz_isnull(fp) ){ | ||
| LNI_FERR(func,"cannot open output file",nim->fname); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the
JPEGLSconnection...