-- ULGY FIX
execute' mode program list = exec
    where 
      exec = do 
        tmp_dir <- getTemporaryDirectory
        let fullpath = tmp_dir ++ pathSeparator : "GPU-HASKELL"
        createDirectoryIfMissing False fullpath
        -- genCudaProjectL n (div n threads) fullpath name program list
        writeFile (fullpath ++ (pathSeparator : name) ++ ".cu") 
                      (test program list) 
        writeFile (fullpath ++ (pathSeparator : "Makefile")) 
                      (genMakefile name)
        working_dir <- getCurrentDirectory 
        setCurrentDirectory fullpath
        pid1 <- case mode of 
                  GPU -> runCommand "make -s 2> messages.txt"
                  EMU -> runCommand "make emulation -s 2> messages.txt"
        waitForProcess pid1 -- make sure the executable is generated
        pid2 <- runCommand (fullpath ++ pathSeparator:name ++ " > output.txt")
        waitForProcess pid2 -- make sure output is generated 
        result <- readOutput (fullpath ++ pathSeparator:"output.txt" )
        setCurrentDirectory working_dir
        --removeDirectoryRecursive fullpath
        return result
      n = length list
      name = "generated"
      readOutput file = 
          do 
            string  <- readFile file 
            let strings = words string 
            return (map scan strings)
-- -----------------------------------------------------------------------------

    --"CUDA_INSTALL_PATH := /usr/local/cuda\n" ++       
    --"CUDA_SDK_PATH := /home/ian/NVIDIA_CUDA_SDK\n" ++ 

-- -----------------------------------------------------------------------------
-- genMakefile now uses env variables CUDA_INSTALL_PATH and 
--   CUDA_SDK_PATH(not used at the moment, maybe remove)
execute' mode program list = exec
    where 
      exec = do 
        tmp_dir <- getTemporaryDirectory
        let fullpath = tmp_dir ++ pathSeparator : "GPU-HASKELL"
        createDirectoryIfMissing False fullpath
        -- genCudaProjectL n (div n threads) fullpath name program list
        writeFile (fullpath ++ (pathSeparator : name) ++ ".cu") 
                      (test program list) 
        writeFile (fullpath ++ (pathSeparator : "Makefile")) 
                      (genMakefile name)
        working_dir <- getCurrentDirectory 
        setCurrentDirectory fullpath
        pid1 <- case mode of 
                  GPU -> runCommand "make -s 2> messages.txt"
                  EMU -> runCommand "make emulation -s 2> messages.txt"
        waitForProcess pid1 -- make sure the executable is generated
        pid2 <- runCommand (fullpath ++ pathSeparator:name ++ " > output.txt")
        waitForProcess pid2 -- make sure output is generated 
        result <- readOutput (fullpath ++ pathSeparator:"output.txt" )
        setCurrentDirectory working_dir
        --removeDirectoryRecursive fullpath
        return result
      n = length list
      name = "generated"
      readOutput file = 
          do 
            string  <- readFile file 
            let strings = words string 
            return (map scan strings)
-- -----------------------------------------------------------------------------

    --"CUDA_INSTALL_PATH := /usr/local/cuda\n" ++       
    --"CUDA_SDK_PATH := /home/ian/NVIDIA_CUDA_SDK\n" ++ 

-- -----------------------------------------------------------------------------
-- genMakefile now uses env variables CUDA_INSTALL_PATH and 
--   CUDA_SDK_PATH(not used at the moment, maybe remove)
execute' mode program list = exec
    where 
      exec = do 
        tmp_dir <- getTemporaryDirectory
        let fullpath = tmp_dir ++ pathSeparator : "GPU-HASKELL"
        createDirectoryIfMissing False fullpath
        -- genCudaProjectL n (div n threads) fullpath name program list
        writeFile (fullpath ++ (pathSeparator : name) ++ ".cu") 
                      (test program list) 
        writeFile (fullpath ++ (pathSeparator : "Makefile")) 
                      (genMakefile name)
        working_dir <- getCurrentDirectory 
        setCurrentDirectory fullpath
        pid1 <- case mode of 
                  GPU -> runCommand "make -s 2> messages.txt"
                  EMU -> runCommand "make emulation -s 2> messages.txt"
        waitForProcess pid1 -- make sure the executable is generated
        pid2 <- runCommand (fullpath ++ pathSeparator:name ++ " > output.txt")
        waitForProcess pid2 -- make sure output is generated 
        result <- readOutput (fullpath ++ pathSeparator:"output.txt" )
        setCurrentDirectory working_dir
        --removeDirectoryRecursive fullpath
        return result
      n = length list
      name = "generated"
      readOutput file = 
          do 
            string  <- readFile file 
            let strings = words string 
            return (map scan strings)
-- -----------------------------------------------------------------------------

    --"CUDA_INSTALL_PATH := /usr/local/cuda\n" ++       
    --"CUDA_SDK_PATH := /home/ian/NVIDIA_CUDA_SDK\n" ++ 

-- -----------------------------------------------------------------------------
-- genMakefile now uses env variables CUDA_INSTALL_PATH and 
--   CUDA_SDK_PATH(not used at the moment, maybe remove)