source /opt/dtk/cuda/env.sh

make VERBOSE=1 gpu=1 all 2>&1 | tee debug.log

realpath debug.log

# ./probtrackx2_gpu11.8 

# make install

export PATH=/datav/wkx/fsl/FSL-install-new/bin:$PATH

cd "/datav/wkx/fsl/FSL-install-new/src/fsl-ptx2-cuda-11.0/workspace/fsl_track/bedpostx_prepare/"
    if [ -f "data.nii.gz" ]; then
        gunzip -f data.nii.gz
    fi
    if [ -f "data.nii" ]; then
        fslroi data.nii B0.nii 0 1
        echo "B0图像提取完成"
    else
        echo "错误: 找不到data.nii文件"
        echo ""
        continue
    fi
    
    # 返回DTI目录
    cd "$DTI_DIR"
    
    # 创建输出目录
    OUTPUT_DIR="$PWD/fsl_track/WholeBrain_protrackx"
    mkdir -p "$OUTPUT_DIR"
    
    # 设置参数
    N_SAMPLES=5000
    DIS_COR="--pd"
    LEN_STEP=0.5
    N_STEPS=2000
    CUR_THRES=0.2
    
    # 处理每个坐标
    echo "开始处理坐标..."
    while read -r COORD; do
        if [ -z "$COORD" ]; then
            continue
        fi
        
        echo "处理坐标: $COORD"
        
        # 后台运行
        probtrackx2_gpu \
            --simple \
            --seedref="$PWD/fsl_track/bedpostx_prepare/B0.nii" \
            -o "single_voxel_${COORD%.*}" \
            -x "$PWD/fsl_track/WholeBrain_coord/$COORD" \
            -l $DIS_COR \
            -c $CUR_THRES \
            -S $N_STEPS \
            --steplength=$LEN_STEP \
            -P $N_SAMPLES \
            --forcedir \
            --opd \
            -s "$PWD/fsl_track/bedpostx_prepare.bedpostX/merged" \
            -m "$PWD/fsl_track/bedpostx_prepare.bedpostX/nodif_brain_mask" \
            --dir="$OUTPUT_DIR" &
        
    done < "$COORD_LIST"