Giter VIP home page Giter VIP logo

Comments (9)

neurolabusc avatar neurolabusc commented on June 6, 2024

Curious, when I try to replicate your issue on MacOS 10.11.6 I get
./dcm2niix -b y -z i -x n -t n -m n -f fmap -o "~/tst_t1/j" -s n -v n ~/tst_t1
Chris Rorden's dcm2niiX version 1Jan2017 (64-bit MacOS)
Error: Output folder invalid: ~/tst_t1/j
which one would expect due to line 1943 of nii_dicom_batch.cpp. Is it possible that the is_dir function does not work on your operating system (e.g. what does "stat" return when given an invalid path name, should be -1). Should be an easy patch if we can replicate your problem.

While not related to this issue, in general I would suggest -o "/tmp/A00012$A" instead of -o /tmp/A00012$A/. The quote marks ensure that if your variable contains a space the function will still work. Even more pedantically, while my software can handle either a path or a directory, you are specifying an output directory, so the trailing '/' is not required.

from dcm2niix.

neurolabusc avatar neurolabusc commented on June 6, 2024

I am also unable to replicate your problem using NeuroDebian 8.0. Anything unusual about your /tmp file system?

from dcm2niix.

yarikoptic avatar yarikoptic commented on June 6, 2024

re stat:

(venv)mvdoc@smaug /tmp $ stat nonexisting/;  echo $?
stat: cannot stat ‘nonexisting/’: No such file or directory
1
(venv)mvdoc@smaug /tmp $ stat nonexisting;  echo $? 
stat: cannot stat ‘nonexisting’: No such file or directory
1

but I guess you meant syscall? lazy me just did strace on a stat call

(venv)mvdoc@smaug /tmp $ strace stat nonexisting 2>&1 | grep 'stat(.*nonex'          
lstat("nonexisting", 0x7fff6a4a4c40)    = -1 ENOENT (No such file or directory)

re spaces -- you are totally correct, but here I was saving keystrokes and was aware of having no spaces in the variables

re trailing '/' -- I like having those for my own sake -- at times saw -o used as a prefix not necessarily directory specification. Having / guarantees it and in spoiled-by-Python world os.path.join takes care about those ;)

if needed -- could check with minimalistic c program later on...

from dcm2niix.

neurolabusc avatar neurolabusc commented on June 6, 2024

Rather than make a minimal program, I would suggest modifying dcm2niix to have it tell you (1) if it recognizes you have used the -o option (e.g. set an output folder) and (2) tell you the folder it will check with stat(). The modifications below should do it:

@@ -1930,11 +1930,14 @@
     if (isFile) //if user passes ~/dicom/mr1.dcm we will look at all files in ~/dicom
         dropFilenameFromPath(opts->indir);//getParentFolder(opts.indir, opts.indir);
     dropTrailingFileSep(opts->indir);
-    if (strlen(opts->outdir) < 1)
-        strcpy(opts->outdir,opts->indir);
+    if (strlen(opts->outdir) < 1) {
+    	printWarning("Output folder not specified using input folder '%s'\n",opts->indir);
+    	strcpy(opts->outdir,opts->indir);
+    }
     dropTrailingFileSep(opts->outdir);
     if (is_fileNotDir(opts->outdir)) //if user passes ~/dicom/mr1.dcm we will look at all files in ~/dicom
         dropFilenameFromPath(opts->outdir);//getParentFolder(opts.indir, opts.indir);
+    printWarning("Checking existence of output folder '%s'\n",opts->outdir);
     if (!is_dir(opts->outdir,true)) {
 		#ifdef myUseInDirIfOutDirUnavailable
 		printWarning("Output folder invalid %s will try %s\n",opts->outdir,opts->indir);

from dcm2niix.

yarikoptic avatar yarikoptic commented on June 6, 2024

ok -- will do... meanwhile -- seems to be a regression:

new:

(venv)mvdoc@smaug /tmp $ rm -rf nonexisting fmap*;  dcm2niix -b y -z i -x n -t n -m n -f fmap -o /tmp/nonexisting -s n -v n /mnt/btrfs/dbic/inbox/DICOM/2016/12/04/A000122/006*fmap*/000001.dcm; echo "exited with $?"; ls -lta | head                                   
Chris Rorden's dcm2niiX version 1Jan2017 (64-bit Linux)
Found 64 DICOM image(s)
Convert 64 DICOM as /tmp/fmap (90x90x64x1)
Conversion required 0.103971 seconds.
exited with 0
total 121284
-rw-r--r--  1 mvdoc       mvdoc         628504 Jan 11 13:02 fmap.nii.gz
drwxrwxrwt 48 root        root           12288 Jan 11 13:02 .
-rw-r--r--  1 mvdoc       mvdoc            378 Jan 11 13:02 fmap.json
drwx------  2 neurodebian neurodebian     4096 Jan 11 11:57 ssh-f6P5rL2ySh
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:09 A000122__
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:09 A000121__
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:03 A000122_
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:03 A000121_
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 10:56 A000122

old(er) the one from neurodebian

(venv)mvdoc@smaug /tmp $ rm -rf nonexisting fmap*;  dcm2niix -b y -z i -x n -t n -m n -f fmap -o /tmp/nonexisting -s n -v n /mnt/btrfs/dbic/inbox/DICOM/2016/12/04/A000122/006*fmap*/000001.dcm; echo "exited with $?"; ls -lta | head
Chris Rorden's dcm2niiX version 29Sept2016 (64-bit Linux)
Error: output folder invalid: /tmp/nonexisting
exited with 1
total 120664
drwxrwxrwt 48 root        root           12288 Jan 11 13:02 .
drwx------  2 neurodebian neurodebian     4096 Jan 11 11:57 ssh-f6P5rL2ySh
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:09 A000122__
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:09 A000121__
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:03 A000122_
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:03 A000121_
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 10:56 A000122
-rw-r--r--  1 mvdoc       mvdoc          36282 Jan 11 10:56 dcm2niix-v.log
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 10:56 A000121

from dcm2niix.

yarikoptic avatar yarikoptic commented on June 6, 2024
(venv)mvdoc@smaug /tmp $ rm -rf nonexisting fmap*;  dcm2niix -b y -z i -x n -t n -m n -f fmap -o /tmp/nonexisting -s n -v n /mnt/btrfs/dbic/inbox/DICOM/2016/12/04/A000122/006*fmap*/000001.dcm; echo "exited with $?"; ls -lta | head
zsh: no matches found: fmap*
Chris Rorden's dcm2niiX version 1Jan2017 (64-bit Linux)
Warning: Checking existence of output folder '/tmp'
Found 64 DICOM image(s)
Convert 64 DICOM as /tmp/fmap (90x90x64x1)
Conversion required 0.098941 seconds.
exited with 0
total 121400
drwxrwxrwt 48 root        root           12288 Jan 11 13:27 .
-rw-r--r--  1 mvdoc       mvdoc         628504 Jan 11 13:27 fmap.nii.gz
-rw-r--r--  1 mvdoc       mvdoc            378 Jan 11 13:27 fmap.json
-rw-r--r--  1 yoh         yoh           115612 Jan 11 13:26 dcm2niix_20160921+git59-gbd1b713-1+p1_amd64.deb
drwx------  2 neurodebian neurodebian     4096 Jan 11 11:57 ssh-f6P5rL2ySh
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:09 A000122__
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:09 A000121__
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:03 A000122_
drwxr-xr-x  2 mvdoc       mvdoc           4096 Jan 11 11:03 A000121_

patch was (so I didn't screw it up since had to manually paste -- simple diff/patch didn't work out):

$> cat debian/patches/up_verbose_outdir_analysis 
--- a/console/nii_dicom_batch.cpp
+++ b/console/nii_dicom_batch.cpp
@@ -1930,11 +1930,14 @@ int nii_loadDir(struct TDCMopts* opts) {
     if (isFile) //if user passes ~/dicom/mr1.dcm we will look at all files in ~/dicom
         dropFilenameFromPath(opts->indir);//getParentFolder(opts.indir, opts.indir);
     dropTrailingFileSep(opts->indir);
-    if (strlen(opts->outdir) < 1)
+    if (strlen(opts->outdir) < 1) {
+        printWarning("Output folder not specified using input folder '%s'\n",opts->indir);
         strcpy(opts->outdir,opts->indir);
+    }
     dropTrailingFileSep(opts->outdir);
     if (is_fileNotDir(opts->outdir)) //if user passes ~/dicom/mr1.dcm we will look at all files in ~/dicom
         dropFilenameFromPath(opts->outdir);//getParentFolder(opts.indir, opts.indir);
+    printWarning("Checking existence of output folder '%s'\n",opts->outdir);
     if (!is_dir(opts->outdir,true)) {
 		#ifdef myUseInDirIfOutDirUnavailable
 		printWarning("Output folder invalid %s will try %s\n",opts->outdir,opts->indir);

from dcm2niix.

neurolabusc avatar neurolabusc commented on June 6, 2024

OK, so it looks like the issue is not with stat() but with how the outdir is set - perhaps due to the expansion of the inputs *fmap*. What does this do:

--- ./console/main_console.cpp	2016-12-14 11:54:19.000000000 -0500
+++ ./main_console.cpp	2017-01-11 13:40:02.000000000 -0500
@@ -186,6 +186,7 @@
                 i++;
                 isCustomOutDir = true;
                 strcpy(opts.outdir,argv[i]);
+                printf("customOutDir set to %s\n", opts.outdir);
             }
             lastCommandArg = i;
         } //if parameter is a command
@@ -204,7 +205,10 @@
     clock_t start = clock();
     for (i = (lastCommandArg+1); i < argc; i++) {
     	strcpy(opts.indir,argv[i]); // [argc-1]
+    	printf("inDir %s\n", opts.indir);
+    	printf("outDir %s\n", opts.outdir);
     	if (!isCustomOutDir) strcpy(opts.outdir,opts.indir);
+    	printf("outDir(again) set to %s\n", opts.outdir);
     	if (nii_loadDir(&opts) != EXIT_SUCCESS)
     		return EXIT_FAILURE;
     }

from dcm2niix.

yarikoptic avatar yarikoptic commented on June 6, 2024

here is more ;) may be tomorrow finally will debug it properly to point the location of the problem

mvdoc@smaug /tmp $ rm -rf nonexisting fmap*;  /tmp/dcm2niix -b y -z i -x n -t n -m n -f fmap -o /tmp/nonexisting -s n -v n /mnt/btrfs/dbic/inbox/DICOM/2016/12/04/A000122/006*fmap*/000001.dcm; echo "exited with $?"; ls -lta | head
Chris Rorden's dcm2niiX version 1Jan2017 (64-bit Linux)
customOutDir set to /tmp/nonexisting
inDir /mnt/btrfs/dbic/inbox/DICOM/2016/12/04/A000122/006-fmap_acq-2.4mm/000001.dcm
outDir /tmp/nonexisting
outDir(again) set to /tmp/nonexisting
Warning: Checking existence of output folder '/tmp'
...

from dcm2niix.

neurolabusc avatar neurolabusc commented on June 6, 2024

Fixed in latest release

from dcm2niix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.