rules :: Rules ()
rules = do
    [nodif_brain,
     nodif_brain_mask]
      *>> \_ -> do
      need [hifib0]
      command [] "bet" [hifib0, nodif_brain, "-m", "-f", "0.2"]

    hifib0
      %> \_ -> do
      need [Preprocessing.posb0s
           ,Preprocessing.negb0s
           ,Preprocessing.acqparams_txt
           ,fieldcoef
           ,movpar_txt]
      dimt <- (+1) <$> getDim4 Preprocessing.posb0s
      withTempFile $ \posb01 ->
        withTempFile $ \negb01 -> do
          extractVol_ posb01 Preprocessing.posb0s 1
          extractVol_ negb01 Preprocessing.negb0s 1
          command_ [] "applytopup" [printf "--imain=%s,%s" posb01 negb01
                                 ,"--topup=" ++ outprefix
                                 ,"--datain="++Preprocessing.acqparams_txt
                                 ,"--inindex=1,"++ show dimt
                                 ,"--out="++hifib0]

    [fieldcoef,
     movpar_txt]
      *>> \_ -> do
      need [Preprocessing.posnegb0s
           ,Preprocessing.acqparams_txt
           ,topupcfg]
      command [] "topup" ["--imain="++Preprocessing.posnegb0s
                         ,"--datain="++Preprocessing.acqparams_txt
                         ,"--config="++topupcfg
                         ,"--out=" ++ outprefix
                         ,"-v"]
rules :: Rules ()
rules = do
    [nodif_brain,
     nodif_brain_mask]
      *>> \_ -> do
      need [hifib0]
      command [] "bet" [hifib0, nodif_brain, "-m", "-f", "0.2"]

    hifib0
      %> \_ -> do
      need [Preprocessing.posb0s
           ,Preprocessing.negb0s
           ,Preprocessing.acqparams_txt
           ,fieldcoef
           ,movpar_txt]
      dimt <- (+1) <$> getDim4 Preprocessing.posb0s
      withTempFile $ \posb01 ->
        withTempFile $ \negb01 -> do
          extractVol_ posb01 Preprocessing.posb0s 1
          extractVol_ negb01 Preprocessing.negb0s 1
          command_ [] "applytopup" [printf "--imain=%s,%s" posb01 negb01
                                 ,"--topup=" ++ outprefix
                                 ,"--datain="++Preprocessing.acqparams_txt
                                 ,"--inindex=1,"++ show dimt
                                 ,"--out="++hifib0]

    [fieldcoef,
     movpar_txt]
      *>> \_ -> do
      need [Preprocessing.posnegb0s
           ,Preprocessing.acqparams_txt
           ,topupcfg]
      command [] "topup" ["--imain="++Preprocessing.posnegb0s
                         ,"--datain="++Preprocessing.acqparams_txt
                         ,"--config="++topupcfg
                         ,"--out=" ++ outprefix
                         ,"-v"]
rules = do
    [nodif_brain,
     nodif_brain_mask]
      *>> \_ -> do
      need [hifib0]
      command [] "bet" [hifib0, nodif_brain, "-m", "-f", "0.2"]

    hifib0
      %> \_ -> do
      need [Preprocessing.posb0s
           ,Preprocessing.negb0s
           ,Preprocessing.acqparams_txt
           ,fieldcoef
           ,movpar_txt]
      dimt <- (+1) <$> getDim4 Preprocessing.posb0s
      withTempFile $ \posb01 ->
        withTempFile $ \negb01 -> do
          extractVol_ posb01 Preprocessing.posb0s 1
          extractVol_ negb01 Preprocessing.negb0s 1
          command_ [] "applytopup" [printf "--imain=%s,%s" posb01 negb01
                                 ,"--topup=" ++ outprefix
                                 ,"--datain="++Preprocessing.acqparams_txt
                                 ,"--inindex=1,"++ show dimt
                                 ,"--out="++hifib0]

    [fieldcoef,
     movpar_txt]
      *>> \_ -> do
      need [Preprocessing.posnegb0s
           ,Preprocessing.acqparams_txt
           ,topupcfg]
      command [] "topup" ["--imain="++Preprocessing.posnegb0s
                         ,"--datain="++Preprocessing.acqparams_txt
                         ,"--config="++topupcfg
                         ,"--out=" ++ outprefix
                         ,"-v"]