#!/bin/tcsh -f if ("$1" == '' || "$1" == '-h' || "$1" == "-help" || "$2" == '') then goto HELP endif set ana = $1 set ana_pref = $ana:r set ana_ext = $ana:e set ref_pref = `@GetAfniPrefix $2` set ref_view = `@GetAfniView $2` set ref = ${ref_pref}${ref_view} if ( ! -f $ana ) then echo "Error: Analyze file $ana not found" goto END endif if ( ${ana_ext} != "hdr") then echo "Error: Analyze file $ana must end with .hdr" goto END endif if ( ! -f ${ref}.HEAD || ! -f ${ref}.BRIK) then echo "Error: AFNI_reference_volume ${ref} (.HEAD or .BRIK) not found" goto END endif if ( ${ref_view} != "+orig") then echo "Error: AFNI_reference_volume should be in +orig view" goto END endif #Create AFNI dataset from .hdr rm -f ${ana_pref}_tmp+????.???? echo "++ Changing format " 3dcopy $ana ${ana_pref}_tmp if ( -f ${ana_pref}_tmp+orig.HEAD) then set ana_view = "+orig" else if ( -f ${ana_pref}_tmp+acpc.HEAD) then set ana_view = "+acpc" else if ( -f ${ana_pref}_tmp+tlrc.HEAD) then set ana_view = "+tlrc" else echo "Error: 3dcopy command failed!" goto END endif if ($ana_view != "+orig") then echo "++ Refitting to +orig" 3drefit -view orig ${ana_pref}_tmp${ana_view} set ana_view = "+orig" endif #Now reslice the cursed dset set ana_orcode = `@GetAfniOrient $ref` if ( $#ana_orcode != 1) then echo "Error: Failed to get orientation code, got $ana_orcode !" goto END endif echo "++ Reslicing to $ana_orcode" 3daxialize -orient $ana_orcode -prefix ${ana_pref} ${ana_pref}_tmp${ana_view} rm -f ${ana_pref}_tmp+????.???? #make origins match echo "++ Matching origins" 3drefit -duporigin $ref ${ana_pref}${ana_view} if ( ! -f ${ana_pref}${ana_view}.HEAD ) then echo "Error: Failed to create output dataset!" goto END endif echo "" echo "Datasets ${ana_pref}${ana_view} should now be in full alignment with $ref" echo "Verify results in AFNI" goto END HELP: echo "`basename $0` <DTI_Studio_volume> <AFNI_reference_volume>" echo "This script reslices and repositions a DTI Studio Analyze format" echo "volume to match an AFNI volume used as input data for DTI Studio." echo "Check realignment with AFNI to be sure all went well." echo "" echo "Example:" echo "Fibers.hdr is an Analyze volume from DTI Studio that contains" echo " fiber tract volume data. The Analyze format data will have two files -" echo " Fibers.hdr with the header data and Fibers.img with the data" echo " DTI Studio allows saving the fibers as volumes in the Fiber panel," echo " disk icon in the lower right" echo "FA+orig is an AFNI volume to which to match the Analyze volume" echo "To create an AFNI brick version of Fibers that is in alignment" echo " with FA+orig (output is Fibers+orig):" echo "" echo "`basename $0` Fibers.hdr FA+orig" echo "" goto END END: