 int nfft_of_plan;
 int size_of_plan;
 
+void cufft_check_error(const char* file_name, const int line_number, cufftResult result)
+{
+    if (result == CUFFT_SUCCESS) return;
+    
+    printf("CUFFT error at line %i of file %s: ", line_number, file_name);
+    switch (result)
+    {
+        case CUFFT_INVALID_PLAN:
+        {
+            printf("CUFFT_INVALID_PLAN\n");
+            break;
+        }
+        case CUFFT_ALLOC_FAILED:
+        {
+            printf("CUFFT_ALLOC_FAILED\n");
+            break;
+        }
+        case CUFFT_INVALID_VALUE:
+        {
+            printf("CUFFT_INVALID_VALUE\n");
+            break;
+        }
+        case CUFFT_INTERNAL_ERROR:
+        {
+            printf("CUFFT_INTERNAL_ERROR\n");
+            break;
+        }
+        case CUFFT_SETUP_FAILED:
+        {
+            printf("CUFFT_SETUP_FAILED\n");
+            break;
+        }
+        case CUFFT_INVALID_SIZE:
+        {
+            printf("CUFFT_INVALID_SIZE\n");
+            break;
+        }
+        default:
+        {
+            printf("unknown error code %i\n", result);
+            break;
+        }
+    }
+    exit(-100);
+}
+
 extern "C" void cufft_create_plan_handle(void)
 {
-    if (cufftCreate(&plan) != CUFFT_SUCCESS)
-    {
-        printf("failed to execute cufftCreate()\n");
-        exit(0);
-    }
+    cufftResult result = cufftCreate(&plan);
+    cufft_check_error(__FILE__, __LINE__, result);
 }
 
 extern "C" size_t cufft_get_size(int nx, int ny, int nz, int nfft)

    int fft_size = nx * ny * nz;
    int n[] = {nz, ny, nx};

    if (cufftSetAutoAllocation(plan, false) != CUFFT_SUCCESS)
    {
        printf("failed to execute cufftSetAutoAllocation()\n");
        exit(0);
    }

    if (cufftPlanMany(&plan, 3, n, n, 1, fft_size, n, 1, fft_size, CUFFT_Z2Z, nfft) != CUFFT_SUCCESS)
    {
        printf("failed to execute cufftPlanMany()\n");
        exit(0);
    }

    nfft_of_plan = nfft;
    size_of_plan = fft_size;

extern "C" void cuda_device_info()
{
    int count;
    cudaGetDeviceCount(&count);
    cuda_check_last_error(__FILE__, __LINE__);

    if (count == 0)
    {
