 	char	**argv )		// Pointer to Arguments
 {
 	int		shrd_param_id;				// Shared Memory ID
+	int		seg_index;					// Index for Segment
 	struct	SHM_PARAM	*param_ptr;		// Pointer to the Shared Param
 	struct	sembuf		sops;			// Semaphore for data access
 	float	*segdata_ptr;				// Pointer to sampled data
+	float	*xspec_ptr;					// Pointer to 1-sec-integrated Power Spectrum
 
 	cufftHandle		cufft_plan;
 	cufftComplex	*cuSpec_data;
 	cufftReal		*cuReal_data;
+	float			*cuPowerSpec;
 /*
 -------------------------------------------- Prepare for CuFFT
 */
-	cudaMalloc( (void **)&cuReal_data, SEGDATA_SIZE/2 );
-	cudaMalloc( (void **)&cuSpec_data, SEGDATA_SIZE/2 );
+	cudaMalloc( (void **)&cuReal_data, MAX_IF* MAX_seg_sec/2* MAX_seg_len * sizeof(cufftReal) );
+	cudaMalloc( (void **)&cuSpec_data, MAX_IF* MAX_seg_sec/2* (MAX_seg_len/2+1)* sizeof(cufftComplex) );
+	cudaMalloc( (void **)&cuPowerSpec, MAX_IF* (MAX_seg_len/2+1)* sizeof(float));
 	if(cudaGetLastError() != cudaSuccess){
 		fprintf(stderr, "Cuda Error : Failed to allocate memory.\n"); return(-1);
 	}
 
-	if(cufftPlan1d(&cufft_plan, NFFT, CUFFT_R2C, NSEG) != CUFFT_SUCCESS){
+	if(cufftPlan1d(&cufft_plan, NFFT, CUFFT_R2C, NSEG* MAX_IF / 2) != CUFFT_SUCCESS){
 		fprintf(stderr, "Cuda Error : Failed to create plan.\n"); return(-1);
 	}
 	

	while(param_ptr->validity & ACTIVE){
		if( param_ptr->validity & (FINISH + ABSFIN) ){  break; }

		printf("FFT status EW\r");
		sops.sem_num = (ushort)8; sops.sem_op = (short)-4; sops.sem_flg = (short)0;
        semop( param_ptr->sem_data_id, &sops, 1);

		printf("FFT status ES\r");
		cudaMemcpy( cuReal_data, segdata_ptr, SEGDATA_SIZE/2, cudaMemcpyHostToDevice);
		printf("FFT status EF\r");
		cufftExecR2C(cufft_plan, cuReal_data, cuSpec_data);

		printf("FFT status OW\r");
		segdata_ptr += MAX_IF* MAX_seg_len* MAX_seg_sec / 2;
		sops.sem_num = (ushort)9; sops.sem_op = (short)-4; sops.sem_flg = (short)0;
        semop( param_ptr->sem_data_id, &sops, 1);
		printf("FFT status OS\r");
		cudaMemcpy( cuReal_data, segdata_ptr, SEGDATA_SIZE/2, cudaMemcpyHostToDevice);
		segdata_ptr -= MAX_IF* MAX_seg_len* MAX_seg_sec / 2;
		printf("FFT status OF\r");

		cufftExecR2C(cufft_plan, cuReal_data, cuSpec_data);
	}
/*
-------------------------------------------- RELEASE the SHM

	shrd_param_id = shmget( SHM_PARAM_KEY, sizeof(struct SHM_PARAM), 0444);
	param_ptr = (struct SHM_PARAM *)shmat(shrd_param_id, NULL, 0);
	segdata_ptr = (float *)shmat(param_ptr->shrd_seg_id, NULL, SHM_RDONLY);
	xspec_ptr   = (float *)shmat(param_ptr->shrd_xspec_id, NULL, 0);
/*
-------------------------------------------- K5 Header and Data
*/
