AFNI Message Board

Dear AFNI users-

We are very pleased to announce that the new AFNI Message Board framework is up! Please join us at:

https://discuss.afni.nimh.nih.gov

Existing user accounts have been migrated, so returning users can login by requesting a password reset. New users can create accounts, as well, through a standard account creation process. Please note that these setup emails might initially go to spam folders (esp. for NIH users!), so please check those locations in the beginning.

The current Message Board discussion threads have been migrated to the new framework. The current Message Board will remain visible, but read-only, for a little while.

Sincerely, AFNI HQ

History of AFNI updates  

|
June 02, 2015 02:45PM
There are two things going wrong here. One of them is that I screwed up and gave you a program that works with GNU sed but fails with BSD sed (Are you by any chance using OS X?). I think you can fix that by adding a $ immediately before each opening single quote, so that the escapes are interpreted by the shell instead of by sed:
$ cat testdrive_afni.bash
#!/bin/bash

afni -yesplugouts "$@" > >(sed $'s/.*/\x1b\[31m&\x1b\[0m/') \
                       2> >(sed $'s/.*/\x1b\[1;31m&\x1b\[0m/' 1>&2) &
plugout_drive -v 2> >(sed $'s/.*/\x1b\[1m&\x1b\[0m/' 1>&2)
("<ESC> [ n m" is a terminal escape code, where n is some comma-separated sequence of numbers describing the attributes you want the following text to have. 1 means bold, 31 means red, and 0 means return to normal. The sed commands just tack appropriate terminal escapes onto the beginning and end of each line coming from either program; the problem was that GNU sed interprets \x1b as <ESC>, while BSD sed interprets it as x1b. The fix here makes it so that by the time the command gets to sed, it's already an <ESC> character.)

The other problem is that for some reason, AFNI doesn't flush the stream (i.e., actually write the output that it has queued up for writing) when it executes a GET_DICOM_XYZ command, so that output won't be written until some other command (like GETENV or closing the stream on QUIT) causes the stream to flush. Also, because this solution pipes output through sed, AFNI's output is line-buffered (i.e., save up output until you can send an entire line into the pipe) instead of unbuffered (i.e., print it as soon as you have it, as it would do if the output were directly to the terminal), which is why you get the cruft about NLfit & NLerr on the same line-- AFNI wrote that a while ago, but it didn't get printed until the line was finished. You can see this effect by running something like "3dClustSim -options -go -here | cat"; the progress bar won't appear until the program is finished.

I think the easiest way to deal with this is to include a dummy "GETENV bogus" at the beginning and end of your script, so that the partial line will be flushed. So you could do something like this:
afni -yesplugouts | grep 'RAI xyz' > coords.txt&
{
    echo GETENV bogus
    while :; do
        read -n1 -r -p $'\nPress "q" to quit or any other key to dump coordinates' 1>&2
        if [ "$REPLY" == q ]; then
             break
        fi
        echo GET_DICOM_XYZ
    done
    echo GETENV bogus
} | plugout_drive &>/dev/null
And then click around in the viewer between keypresses in the terminal.

HTH,
ijs



Edited 1 time(s). Last edit at 06/02/2015 02:52PM by Isaac Schwabacher.
Subject Author Posted

Plugout_Drive GET_DICOM_XYZ output

rollom June 01, 2015 05:22PM

Re: Plugout_Drive GET_DICOM_XYZ output

Isaac Schwabacher June 01, 2015 06:29PM

Re: Plugout_Drive GET_DICOM_XYZ output

rollom June 02, 2015 12:54PM

Re: Plugout_Drive GET_DICOM_XYZ output

Isaac Schwabacher June 02, 2015 02:45PM

Re: Plugout_Drive GET_DICOM_XYZ output

rollom June 02, 2015 04:21PM

Re: Plugout_Drive GET_DICOM_XYZ output

Daniel Glen June 02, 2015 05:37PM

Re: Plugout_Drive GET_DICOM_XYZ output

Isaac Schwabacher June 02, 2015 05:41PM

Re: Plugout_Drive GET_DICOM_XYZ output

rollom June 03, 2015 10:33AM

Re: Plugout_Drive GET_DICOM_XYZ output

Daniel Glen June 03, 2015 01:47PM

Re: Plugout_Drive GET_DICOM_XYZ output

rollom June 03, 2015 02:21PM