 	for (int i = 0; i < 100; i++) {
 		if (cufftExecR2C(fwd_plan_2k, (cufftReal*)d1, (cufftComplex*)d1_complex) != CUFFT_SUCCESS){
 			fprintf(stderr, "CUFFT error: ExecR2C 2K Forward failed");
-			return -4;	
+			int myErr = err;
+			err = err -1;
+			return myErr;	
 		}
 	}
 


	fftsize = 4096;
	int n1[] = {fftsize};
	if (cufftPlan1d(&fwd_plan_4k, 4096, CUFFT_R2C, 64) != CUFFT_SUCCESS){
		fprintf(stderr, "CUFFT error: 4k Plan creation failed");
		return -2;	
	}	

	if (cufftPlanMany(&fwd_plan_4k,
					  1, // 1d transform

					  NULL, 1, fftsize/2 + 1,
					  CUFFT_R2C,
					  batch) != CUFFT_SUCCESS){
		fprintf(stderr, "CUFFT Error: Unable to create cufftPlanMany for 4k\n");
		int myErr = err;
		err = err -1;
		return myErr;	
	}

	// 2k fft on 4k data size
	printf("[planmany] 2k fft on 4k data.\n");
	cufftHandle fwd_plan_2k_4k;

	fftsize =2048;
	batch = 64;
	int n2[] = {fftsize};

	if (cufftPlanMany(&fwd_plan_2k_4k,
					  1, // 1d transform
					  n2, // fft size 
					  NULL, 1, fftsize,
					  NULL, 1, fftsize/2 + 1,
					  CUFFT_R2C,
					  batch) != CUFFT_SUCCESS){
		fprintf(stderr, "CUFFT Error: Unable to create cufftPlanMany for 2k on 4k\n");
		int myErr = err;
		err = err -1;
		return myErr;	
	}


	//------------------------------------------------------------------------//
	// run forward FFT
