#include <cufft.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cuda_runtime.h>
#include <cuda.h>

#define NUM 1024//160//1024
#define NUM2 1024//7327//13981//128 
#define batch 64//10//30//512
#define fileNUM 8

int main(int argc,char *argv[])
{
	
	FILE *fp;
	FILE *file;
	FILE *fp2;
	unsigned char *f_h_re, *f_h_im;
	int h,i,t1,t2,t,k,v,p,a,c;
	float *f_hf_re, *f_hf_im;
	cufftComplex *f_hc;
	float psd[NUM*batch];
	//int time[NUM*batch];
	char *infile_name_real,*infile_name_imaginary, *outfile_name;
  char day[10];
	char time[10];
	char head[20],re[3],im[3],fft[5];
	char underbar[5],bin[5];
		
		
    sprintf(underbar,"_");

		sprintf(head,"crab_nasu_");

		sprintf(re,"_re");

		sprintf(im,"_im");

		sprintf(fft,"_fft");

		sprintf(bin,".bin");

		printf("日付を入力してください。(yyyymmdd)\n");
    scanf("%s", day);
		
		printf("時間を入力してください。(just,a1,b1 etc..)\n");
		scanf("%s", time);
		        	
	for(c = 0;c < fileNUM;c++){

		infile_name_real = (char *)malloc(sizeof(char)*100);
		infile_name_imaginary = (char *)malloc(sizeof(char)*100);
		outfile_name = (char *)malloc(sizeof(char)*100);
				
	
		sprintf(infile_name_real,"%s%s%s%s%s%d%s",head,day,underbar,time,re,c,bin);

		sprintf(infile_name_imaginary,"%s%s%s%s%s%d%s",head,day,underbar,time,im,c,bin);
		
		printf("%s\n%s\n",infile_name_real,infile_name_imaginary);		
		//ファイルオープン
		fp = fopen(infile_name_real,"rb");
		
		//ファイルが空だった場合の処理
		if(fp == NULL){

				printf("ファイルをオープンできませんでした。\n");

				return 1;

		}
		
		//imginaryファイルオープン
		fp2 = fopen(infile_name_imaginary,"rb");

		//ファイルが空だった場合の処理
		if(fp2 == NULL){

				printf("ファイルをオープンできませんでした。\n");

				return 1;

		}
		

		//6.6msごとに配列に入れていく
		for(h = 0;h < NUM2;h++){
				
				//realデータ用のホスト・メモリの確保
				f_h_re = (unsigned char *)malloc(sizeof(unsigned char)*NUM*batch);
				//realデータ用float型のメモリを確保
				f_hf_re = (float *)malloc(sizeof(float)*NUM*batch);
				
				//imaginaryデータ用のホスト・メモリを確保
				f_h_im = (unsigned char *)malloc(sizeof(unsigned char)*NUM*batch);
				//imaginaryデータ用のfloat型のメモリを確保
				f_hf_im = (float *)malloc(sizeof(float)*NUM*batch);
				
				//cufftComplex型のメモリを確保
				f_hc = (cufftComplex *)malloc(sizeof(cufftComplex)*NUM*batch);
				
				t1 = 0;
				t2 = 0;
				
				t1 = NUM*batch*h;
				t2 = NUM*batch*h + NUM*batch;
				
						//バイナリデータを配列に格納
						for(i = t1;i < t2;i++){
								//realdata
								fseek(fp, i * sizeof(unsigned char), SEEK_SET);

								fread(&f_h_re[i-t1],sizeof(unsigned char),1,fp);

								f_hf_re[i-t1] = f_h_re[i-t1]; //unsigned char型からfloat型への型変換
								
								f_hc[i-t1].x = f_hf_re[i-t1]; //float型からcufftComplex型への変換
								
  								//imdata
								
								fseek(fp2, i * sizeof(unsigned char), SEEK_SET);

								fread(&f_h_im[i-t1],sizeof(unsigned char),1,fp2);

								f_hf_im[i-t1] = f_h_im[i-t1];
								
								f_hc[i-t1].y = f_hf_im[i-t1];
								
						}
		
		free(f_hf_re);
		free(f_h_re);
		
		free(f_hf_im);
		free(f_h_im);
		
		//fclose(fp);
		

		cufftComplex *f_d;
		
		//デバイスメモリの確保
		cudaMalloc((void **)&f_d, sizeof(cufftComplex)*NUM*batch);
		

		//ホストからデバイスへの転送
		cudaMemcpy(f_d, f_hc, sizeof(cufftComplex)*NUM*batch, cudaMemcpyHostToDevice);
		
		cufftHandle plan;	
		
		//1次元FFTの準備
		cufftPlan1d(&plan, NUM, CUFFT_C2C, batch);

		//順方向への変換を実行
		cufftExecC2C(plan, f_d, f_d, CUFFT_FORWARD);
		
		//デバイスからホストへ転送
		cudaMemcpy(f_hc, f_d, sizeof(cufftComplex)*NUM*batch, cudaMemcpyDeviceToHost);
		
		cudaFree(f_d);
		
		cufftDestroy(plan);

		
		/*パワースペクトルの計算*/
		
		for(t = 0; t < batch*NUM ;t++){
				
				psd[t] = sqrt((f_hc[t].x * f_hc[t].x) + (f_hc[t].y * f_hc[t].y));

				
		}
		
		free(f_hc);

		sprintf(outfile_name,"%s%s%s%s%s%d%s",head,day,underbar,time,fft,c,bin);

		file = fopen(outfile_name,"ab");

		if(file == NULL){

				printf("ファイルをオープンできませんでした。\n");

				return 1;

		}
		
		
		for(k = 0; k < batch; k++){

			
			v = NUM*k+1;
			p = NUM*(k+1);
			/*
			z = 2*k + 1;
			p = (NUM/2)*z;
			*/
				for(a = v; a < p; a++){
		
					fwrite(&psd[a],sizeof(float),1,file);

				
				
				}	
				
		}
		
		fclose(file);
		
		
		}

		printf("%s\n",outfile_name);
		
		fclose(fp);
		fclose(fp2);
		free(infile_name_real);
		free(infile_name_imaginary);
		free(outfile_name);
	}
		return 0;
		
} 

	.file	"tmpxft_003515c1_00000000-6_fft_crab_nasu_kai.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2053:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2053:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_"
.LC1:
	.string	"crab_nasu_"
.LC2:
	.string	"_re"
.LC3:
	.string	"_im"
.LC4:
	.string	"_fft"
.LC5:
	.string	".bin"
.LC6:
	.string	"\346\227\245\344\273\230\343\202\222\345\205\245\345\212\233\343\201\227\343\201\246\343\201\217\343\201\240\343\201\225\343\201\204\343\200\202(yyyymmdd)\n"
.LC7:
	.string	"%s"
.LC8:
	.string	"\346\231\202\351\226\223\343\202\222\345\205\245\345\212\233\343\201\227\343\201\246\343\201\217\343\201\240\343\201\225\343\201\204\343\200\202(just,a1,b1 etc..)\n"
.LC9:
	.string	"%s%s%s%s%s%d%s"
.LC10:
	.string	"%s\n%s\n"
.LC11:
	.string	"rb"
.LC12:
	.string	"\343\203\225\343\202\241\343\202\244\343\203\253\343\202\222\343\202\252\343\203\274\343\203\227\343\203\263\343\201\247\343\201\215\343\201\276\343\201\233\343\202\223\343\201\247\343\201\227\343\201\237\343\200\202\n"
.LC13:
	.string	"ab"
.LC14:
	.string	"%s\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2050:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-262144(%rsp), %r11
	.cfi_def_cfa 11, 262200
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$184, %rsp
	.cfi_def_cfa_offset 262384
	leaq	.LC0(%rip), %rsi
	leaq	.LC7(%rip), %rbx
	xorl	%ebp, %ebp
	movq	%fs:40, %rax
	movq	%rax, 262312(%rsp)
	xorl	%eax, %eax
	leaq	262262(%rsp), %rdi
	call	strcpy@PLT
	leaq	262292(%rsp), %rdi
	leaq	.LC1(%rip), %rsi
	call	strcpy@PLT
	leaq	262251(%rsp), %rdi
	movl	$3, %edx
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rcx
	movl	$2, %esi
	call	__sprintf_chk@PLT
	leaq	.LC3(%rip), %rcx
	movl	$3, %edx
	xorl	%eax, %eax
	leaq	262254(%rsp), %rdi
	movl	$2, %esi
	call	__sprintf_chk@PLT
	leaq	262257(%rsp), %rdi
	leaq	.LC4(%rip), %rsi
	call	strcpy@PLT
	leaq	262267(%rsp), %rdi
	leaq	.LC5(%rip), %rsi
	call	strcpy@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	262272(%rsp), %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	262282(%rsp), %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
.L14:
	movl	$100, %edi
	call	malloc@PLT
	movl	$100, %edi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movl	$100, %edi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	leaq	262272(%rsp), %r9
	movl	$2, %esi
	leaq	262292(%rsp), %r8
	movq	%rax, 24(%rsp)
	leaq	.LC9(%rip), %rcx
	pushq	%rdx
	.cfi_def_cfa_offset 262392
	movl	$100, %edx
	leaq	262275(%rsp), %r13
	pushq	%r13
	.cfi_def_cfa_offset 262400
	pushq	%rbp
	.cfi_def_cfa_offset 262408
	leaq	262275(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 262416
	xorl	%eax, %eax
	leaq	262314(%rsp), %r12
	pushq	%r12
	.cfi_def_cfa_offset 262424
	leaq	262302(%rsp), %rbx
	pushq	%rbx
	.cfi_def_cfa_offset 262432
	movq	56(%rsp), %rdi
	movq	%r9, 88(%rsp)
	movq	%r8, 80(%rsp)
	call	__sprintf_chk@PLT
	addq	$40, %rsp
	.cfi_def_cfa_offset 262392
	movl	$100, %edx
	leaq	.LC9(%rip), %rcx
	pushq	%r13
	.cfi_def_cfa_offset 262400
	movl	$2, %esi
	pushq	%rbp
	.cfi_def_cfa_offset 262408
	leaq	262278(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 262416
	xorl	%eax, %eax
	pushq	%r12
	.cfi_def_cfa_offset 262424
	pushq	%rbx
	.cfi_def_cfa_offset 262432
	movq	88(%rsp), %r9
	leaq	.LC11(%rip), %rbx
	movq	80(%rsp), %r8
	movq	64(%rsp), %rdi
	call	__sprintf_chk@PLT
	movq	64(%rsp), %rcx
	addq	$48, %rsp
	.cfi_def_cfa_offset 262384
	xorl	%eax, %eax
	movq	8(%rsp), %rdx
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	movq	%rbx, %rsi
	call	fopen@PLT
	movq	%rax, 32(%rsp)
	testq	%rax, %rax
	je	.L25
	movq	16(%rsp), %rdi
	movq	%rbx, %rsi
	call	fopen@PLT
	movq	%rax, 40(%rsp)
	testq	%rax, %rax
	je	.L25
	xorl	%r14d, %r14d
.L13:
	movl	$65536, %edi
	xorl	%r15d, %r15d
	call	malloc@PLT
	movl	$262144, %edi
	movq	%rax, %r13
	call	malloc@PLT
	movl	$65536, %edi
	movq	%rax, 48(%rsp)
	call	malloc@PLT
	movl	$262144, %edi
	movq	%rax, %r12
	call	malloc@PLT
	movl	$524288, %edi
	movq	%rax, 56(%rsp)
	call	malloc@PLT
	movq	%rax, %rbx
.L6:
	leaq	(%r15,%r14), %rax
	movq	32(%rsp), %rdi
	xorl	%edx, %edx
	movq	%rax, %rsi
	movq	%rax, 72(%rsp)
	call	fseek@PLT
	movl	$65536, %eax
	movq	32(%rsp), %r8
	leaq	0(%r13,%r15), %rdi
	subq	%r15, %rax
	movl	$1, %ecx
	movl	$1, %edx
	movq	%rax, %rsi
	movq	%rax, 64(%rsp)
	call	__fread_chk@PLT
	movzbl	0(%r13,%r15), %eax
	movq	72(%rsp), %rsi
	xorl	%edx, %edx
	movq	40(%rsp), %rdi
	cvtsi2ssl	%eax, %xmm0
	movq	48(%rsp), %rax
	movss	%xmm0, (%rbx,%r15,8)
	movss	%xmm0, (%rax,%r15,4)
	call	fseek@PLT
	movq	40(%rsp), %r8
	movq	64(%rsp), %rsi
	leaq	(%r12,%r15), %rdi
	movl	$1, %ecx
	movl	$1, %edx
	call	__fread_chk@PLT
	movzbl	(%r12,%r15), %eax
	cvtsi2ssl	%eax, %xmm0
	movq	56(%rsp), %rax
	movss	%xmm0, 4(%rbx,%r15,8)
	movss	%xmm0, (%rax,%r15,4)
	incq	%r15
	cmpq	$65536, %r15
	jne	.L6
	movq	48(%rsp), %rdi
	call	free@PLT
	movq	%r13, %rdi
	xorl	%r13d, %r13d
	call	free@PLT
	movq	56(%rsp), %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	leaq	96(%rsp), %rdi
	movl	$524288, %esi
	call	cudaMalloc@PLT
	movq	96(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$524288, %edx
	call	cudaMemcpy@PLT
	leaq	92(%rsp), %rdi
	movl	$64, %ecx
	movl	$41, %edx
	movl	$1024, %esi
	call	cufftPlan1d@PLT
	movq	96(%rsp), %rsi
	movl	92(%rsp), %edi
	orl	$-1, %ecx
	movq	%rsi, %rdx
	call	cufftExecC2C@PLT
	movq	96(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	movl	$524288, %edx
	call	cudaMemcpy@PLT
	movq	96(%rsp), %rdi
	call	cudaFree@PLT
	movl	92(%rsp), %edi
	call	cufftDestroy@PLT
.L7:
	movss	(%rbx,%r13,8), %xmm0
	movss	4(%rbx,%r13,8), %xmm1
	leaq	104(%rsp), %r12
	mulss	%xmm1, %xmm1
	mulss	%xmm0, %xmm0
	addss	%xmm1, %xmm0
	call	sqrtf@PLT
	movss	%xmm0, (%r12,%r13,4)
	incq	%r13
	cmpq	$65536, %r13
	jne	.L7
	movq	%rbx, %rdi
	call	free@PLT
	movl	$100, %edx
	movl	$2, %esi
	leaq	.LC9(%rip), %rcx
	pushq	%rax
	.cfi_def_cfa_offset 262392
	leaq	262275(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 262400
	pushq	%rbp
	.cfi_def_cfa_offset 262408
	leaq	262281(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 262416
	leaq	262314(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 262424
	leaq	262302(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 262432
	movq	72(%rsp), %rdi
	xorl	%eax, %eax
	leaq	262320(%rsp), %r9
	leaq	262340(%rsp), %r8
	call	__sprintf_chk@PLT
	movq	72(%rsp), %rdi
	addq	$48, %rsp
	.cfi_def_cfa_offset 262384
	leaq	.LC13(%rip), %rsi
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L8
.L25:
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L2
.L8:
	movl	$1, %r15d
.L12:
	xorl	%r13d, %r13d
.L10:
	incq	%r13
	cmpq	$1024, %r13
	je	.L27
	leaq	(%r12,%r13,4), %rdi
	movq	%rbx, %rcx
	movl	$1, %edx
	movl	$4, %esi
	call	fwrite@PLT
	jmp	.L10
.L27:
	addl	$1024, %r15d
	addq	$4096, %r12
	cmpl	$65537, %r15d
	jne	.L12
	movq	%rbx, %rdi
	addq	$65536, %r14
	call	fclose@PLT
	cmpq	$67108864, %r14
	jne	.L13
	movq	24(%rsp), %rdx
	leaq	.LC14(%rip), %rsi
	xorl	%eax, %eax
	incl	%ebp
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	32(%rsp), %rdi
	call	fclose@PLT
	movq	40(%rsp), %rdi
	call	fclose@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	cmpl	$8, %ebp
	jne	.L14
	xorl	%eax, %eax
.L2:
	movq	262312(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$262328, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2050:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2076:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2076:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <hipfft/hipfft.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <hip/hip_runtime.h>


#define NUM 1024//160//1024
#define NUM2 1024//7327//13981//128 
#define batch 64//10//30//512
#define fileNUM 8

int main(int argc,char *argv[])
{
	
	FILE *fp;
	FILE *file;
	FILE *fp2;
	unsigned char *f_h_re, *f_h_im;
	int h,i,t1,t2,t,k,v,p,a,c;
	float *f_hf_re, *f_hf_im;
	hipfftComplex *f_hc;
	float psd[NUM*batch];
	//int time[NUM*batch];
	char *infile_name_real,*infile_name_imaginary, *outfile_name;
  char day[10];
	char time[10];
	char head[20],re[3],im[3],fft[5];
	char underbar[5],bin[5];
		
		
    sprintf(underbar,"_");

		sprintf(head,"crab_nasu_");

		sprintf(re,"_re");

		sprintf(im,"_im");

		sprintf(fft,"_fft");

		sprintf(bin,".bin");

		printf("日付を入力してください。(yyyymmdd)\n");
    scanf("%s", day);
		
		printf("時間を入力してください。(just,a1,b1 etc..)\n");
		scanf("%s", time);
		        	
	for(c = 0;c < fileNUM;c++){

		infile_name_real = (char *)malloc(sizeof(char)*100);
		infile_name_imaginary = (char *)malloc(sizeof(char)*100);
		outfile_name = (char *)malloc(sizeof(char)*100);
				
	
		sprintf(infile_name_real,"%s%s%s%s%s%d%s",head,day,underbar,time,re,c,bin);

		sprintf(infile_name_imaginary,"%s%s%s%s%s%d%s",head,day,underbar,time,im,c,bin);
		
		printf("%s\n%s\n",infile_name_real,infile_name_imaginary);		
		//ファイルオープン
		fp = fopen(infile_name_real,"rb");
		
		//ファイルが空だった場合の処理
		if(fp == NULL){

				printf("ファイルをオープンできませんでした。\n");

				return 1;

		}
		
		//imginaryファイルオープン
		fp2 = fopen(infile_name_imaginary,"rb");

		//ファイルが空だった場合の処理
		if(fp2 == NULL){

				printf("ファイルをオープンできませんでした。\n");

				return 1;

		}
		

		//6.6msごとに配列に入れていく
		for(h = 0;h < NUM2;h++){
				
				//realデータ用のホスト・メモリの確保
				f_h_re = (unsigned char *)malloc(sizeof(unsigned char)*NUM*batch);
				//realデータ用float型のメモリを確保
				f_hf_re = (float *)malloc(sizeof(float)*NUM*batch);
				
				//imaginaryデータ用のホスト・メモリを確保
				f_h_im = (unsigned char *)malloc(sizeof(unsigned char)*NUM*batch);
				//imaginaryデータ用のfloat型のメモリを確保
				f_hf_im = (float *)malloc(sizeof(float)*NUM*batch);
				
				//cufftComplex型のメモリを確保
				f_hc = (hipfftComplex *)malloc(sizeof(hipfftComplex)*NUM*batch);
				
				t1 = 0;
				t2 = 0;
				
				t1 = NUM*batch*h;
				t2 = NUM*batch*h + NUM*batch;
				
						//バイナリデータを配列に格納
						for(i = t1;i < t2;i++){
								//realdata
								fseek(fp, i * sizeof(unsigned char), SEEK_SET);

								fread(&f_h_re[i-t1],sizeof(unsigned char),1,fp);

								f_hf_re[i-t1] = f_h_re[i-t1]; //unsigned char型からfloat型への型変換
								
								f_hc[i-t1].x = f_hf_re[i-t1]; //float型からcufftComplex型への変換
								
  								//imdata
								
								fseek(fp2, i * sizeof(unsigned char), SEEK_SET);

								fread(&f_h_im[i-t1],sizeof(unsigned char),1,fp2);

								f_hf_im[i-t1] = f_h_im[i-t1];
								
								f_hc[i-t1].y = f_hf_im[i-t1];
								
						}
		
		free(f_hf_re);
		free(f_h_re);
		
		free(f_hf_im);
		free(f_h_im);
		
		//fclose(fp);
		

		hipfftComplex *f_d;
		
		//デバイスメモリの確保
		hipMalloc((void **)&f_d, sizeof(hipfftComplex)*NUM*batch);
		

		//ホストからデバイスへの転送
		hipMemcpy(f_d, f_hc, sizeof(hipfftComplex)*NUM*batch, hipMemcpyHostToDevice);
		
		hipfftHandle plan;	
		
		//1次元FFTの準備
		hipfftPlan1d(&plan, NUM, HIPFFT_C2C, batch);

		//順方向への変換を実行
		hipfftExecC2C(plan, f_d, f_d, HIPFFT_FORWARD);
		
		//デバイスからホストへ転送
		hipMemcpy(f_hc, f_d, sizeof(hipfftComplex)*NUM*batch, hipMemcpyDeviceToHost);
		
		hipFree(f_d);
		
		hipfftDestroy(plan);

		
		/*パワースペクトルの計算*/
		
		for(t = 0; t < batch*NUM ;t++){
				
				psd[t] = sqrt((f_hc[t].x * f_hc[t].x) + (f_hc[t].y * f_hc[t].y));

				
		}
		
		free(f_hc);

		sprintf(outfile_name,"%s%s%s%s%s%d%s",head,day,underbar,time,fft,c,bin);

		file = fopen(outfile_name,"ab");

		if(file == NULL){

				printf("ファイルをオープンできませんでした。\n");

				return 1;

		}
		
		
		for(k = 0; k < batch; k++){

			
			v = NUM*k+1;
			p = NUM*(k+1);
			/*
			z = 2*k + 1;
			p = (NUM/2)*z;
			*/
				for(a = v; a < p; a++){
		
					fwrite(&psd[a],sizeof(float),1,file);

				
				
				}	
				
		}
		
		fclose(file);
		
		
		}

		printf("%s\n",outfile_name);
		
		fclose(fp);
		fclose(fp2);
		free(infile_name_real);
		free(infile_name_imaginary);
		free(outfile_name);
	}
		return 0;
		
} 

	.text
	.file	"fft_crab_nasu_kai.hip"
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:                                # %.split
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$262344, %rsp                   # imm = 0x400C8
	.cfi_def_cfa_offset 262400
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	48(%rsp), %r13
	movw	$95, (%r13)
	movabsq	$8314047743054148195, %rax      # imm = 0x73616E5F62617263
	leaq	160(%rsp), %rcx
	movq	%rax, (%rcx)
	movl	$6255987, 7(%rcx)               # imm = 0x5F7573
	leaq	12(%rsp), %rax
	movl	$6648415, (%rax)                # imm = 0x65725F
	leaq	8(%rsp), %rax
	movl	$7170399, (%rax)                # imm = 0x6D695F
	xorl	%eax, %eax
	leaq	40(%rsp), %rcx
	movb	%al, 4(%rcx)
	movl	$1952867935, (%rcx)             # imm = 0x7466665F
	leaq	24(%rsp), %r15
	movb	%al, 4(%r15)
	movl	$1852400174, (%r15)             # imm = 0x6E69622E
	movl	$.Lstr, %edi
	callq	puts@PLT
	leaq	54(%rsp), %r12
	movl	$.L.str.7, %edi
	movq	%r12, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	leaq	134(%rsp), %r14
	movl	$.L.str.7, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	xorl	%eax, %eax
.LBB0_1:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_5 Depth 2
                                        #       Child Loop BB0_6 Depth 3
                                        #       Child Loop BB0_8 Depth 3
                                        #       Child Loop BB0_12 Depth 3
                                        #         Child Loop BB0_13 Depth 4
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	$100, %edi
	callq	malloc
	movq	%rax, %rbx
	movl	$100, %edi
	callq	malloc
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	movl	$100, %edi
	callq	malloc
	movq	%rax, 88(%rsp)                  # 8-byte Spill
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	$.L.str.9, %esi
	movq	%rbx, %rdi
	leaq	168(%rsp), %rbp
	movq	%rbp, %rdx
	movq	%r12, %rcx
	movq	%r13, %r8
	movq	%r14, %r9
	xorl	%eax, %eax
	pushq	%r15
	.cfi_adjust_cfa_offset 8
	movq	48(%rsp), %r12                  # 8-byte Reload
	pushq	%r12
	.cfi_adjust_cfa_offset 8
	leaq	36(%rsp), %r10
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	callq	sprintf
	addq	$24, %rsp
	.cfi_adjust_cfa_offset -24
	movl	$.L.str.9, %esi
	movq	72(%rsp), %rdi                  # 8-byte Reload
	movq	%rbp, %rdx
	leaq	62(%rsp), %rcx
	movq	%r13, %r8
	movq	%r14, %r9
	movq	%rdi, %r14
	xorl	%eax, %eax
	pushq	%r15
	.cfi_adjust_cfa_offset 8
	pushq	%r12
	.cfi_adjust_cfa_offset 8
	leaq	32(%rsp), %r10
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	callq	sprintf
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	movl	$.L.str.10, %edi
	movq	%rbx, %rsi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.11, %esi
	movq	%rbx, 144(%rsp)                 # 8-byte Spill
	movq	%rbx, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_2
# %bb.3:                                #   in Loop: Header=BB0_1 Depth=1
	movq	%rax, %rbx
	movl	$.L.str.11, %esi
	movq	%r14, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_2
# %bb.4:                                # %.preheader112.preheader
                                        #   in Loop: Header=BB0_1 Depth=1
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	movq	%rbx, 80(%rsp)                  # 8-byte Spill
	xorl	%eax, %eax
	xorl	%ebx, %ebx
.LBB0_5:                                # %.preheader112
                                        #   Parent Loop BB0_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB0_6 Depth 3
                                        #       Child Loop BB0_8 Depth 3
                                        #       Child Loop BB0_12 Depth 3
                                        #         Child Loop BB0_13 Depth 4
	movq	%rbx, 112(%rsp)                 # 8-byte Spill
	movq	%rax, 152(%rsp)                 # 8-byte Spill
	movl	$65536, %edi                    # imm = 0x10000
	callq	malloc
	movq	%rax, 104(%rsp)                 # 8-byte Spill
	movl	$65536, %edi                    # imm = 0x10000
	callq	malloc
	movq	%rax, 96(%rsp)                  # 8-byte Spill
	movl	$524288, %edi                   # imm = 0x80000
	callq	malloc
	movq	%rax, %r14
	xorl	%ebp, %ebp
	movq	80(%rsp), %rbx                  # 8-byte Reload
	movq	72(%rsp), %r15                  # 8-byte Reload
.LBB0_6:                                #   Parent Loop BB0_1 Depth=1
                                        #     Parent Loop BB0_5 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movq	112(%rsp), %rax                 # 8-byte Reload
	leaq	(%rax,%rbp), %r13
	movq	%rbx, %rdi
	movq	%r13, %rsi
	xorl	%edx, %edx
	callq	fseek
	movq	104(%rsp), %r12                 # 8-byte Reload
	leaq	(%r12,%rbp), %rdi
	movl	$1, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fread
	movzbl	(%r12,%rbp), %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r14,%rbp,8)
	movq	%r15, %rdi
	movq	%r13, %rsi
	xorl	%edx, %edx
	callq	fseek
	movq	96(%rsp), %r12                  # 8-byte Reload
	leaq	(%r12,%rbp), %rdi
	movl	$1, %esi
	movl	$1, %edx
	movq	%r15, %rcx
	callq	fread
	movzbl	(%r12,%rbp), %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, 4(%r14,%rbp,8)
	incq	%rbp
	cmpq	$65536, %rbp                    # imm = 0x10000
	jne	.LBB0_6
# %bb.7:                                #   in Loop: Header=BB0_5 Depth=2
	movq	112(%rsp), %rbx                 # 8-byte Reload
	movq	104(%rsp), %rdi                 # 8-byte Reload
	callq	free
	movq	96(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movl	$524288, %esi                   # imm = 0x80000
	leaq	16(%rsp), %rdi
	callq	hipMalloc
	movq	16(%rsp), %rdi
	movl	$524288, %edx                   # imm = 0x80000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	120(%rsp), %rdi
	movl	$1024, %esi                     # imm = 0x400
	movl	$41, %edx
	movl	$64, %ecx
	callq	hipfftPlan1d
	movq	120(%rsp), %rdi
	movq	16(%rsp), %rdx
	movq	%rdx, %rsi
	movl	$-1, %ecx
	callq	hipfftExecC2C
	movq	16(%rsp), %rsi
	movl	$524288, %edx                   # imm = 0x80000
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	120(%rsp), %rdi
	callq	hipfftDestroy
	xorl	%eax, %eax
.LBB0_8:                                #   Parent Loop BB0_1 Depth=1
                                        #     Parent Loop BB0_5 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%r14,%rax,8), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	4(%r14,%rax,8), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm0, %xmm0
	mulss	%xmm1, %xmm1
	addss	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	sqrtss	%xmm1, %xmm0
	movss	%xmm0, 192(%rsp,%rax,4)
	incq	%rax
	cmpq	$65536, %rax                    # imm = 0x10000
	jne	.LBB0_8
# %bb.9:                                #   in Loop: Header=BB0_5 Depth=2
	movq	%r14, %rdi
	callq	free
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	$.L.str.9, %esi
	movq	96(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	leaq	168(%rsp), %rdx
	leaq	62(%rsp), %rcx
	leaq	56(%rsp), %r13
	movq	%r13, %r8
	leaq	142(%rsp), %r9
	xorl	%eax, %eax
	leaq	32(%rsp), %r10
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	pushq	48(%rsp)                        # 8-byte Folded Reload
	.cfi_adjust_cfa_offset 8
	leaq	64(%rsp), %r10
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	callq	sprintf
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	movl	$.L.str.13, %esi
	movq	%r14, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_2
# %bb.10:                               # %.lr.ph.preheader.preheader
                                        #   in Loop: Header=BB0_5 Depth=2
	movq	%rax, %r14
	xorl	%ebp, %ebp
	leaq	192(%rsp), %r15
.LBB0_12:                               # %.lr.ph.preheader
                                        #   Parent Loop BB0_1 Depth=1
                                        #     Parent Loop BB0_5 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB0_13 Depth 4
	incl	%ebp
	movl	$4, %r12d
.LBB0_13:                               # %.lr.ph
                                        #   Parent Loop BB0_1 Depth=1
                                        #     Parent Loop BB0_5 Depth=2
                                        #       Parent Loop BB0_12 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	leaq	(%r15,%r12), %rdi
	movl	$4, %esi
	movl	$1, %edx
	movq	%r14, %rcx
	callq	fwrite
	addq	$4, %r12
	cmpq	$4096, %r12                     # imm = 0x1000
	jne	.LBB0_13
# %bb.11:                               # %.loopexit
                                        #   in Loop: Header=BB0_12 Depth=3
	addq	$4096, %r15                     # imm = 0x1000
	cmpl	$64, %ebp
	jne	.LBB0_12
# %bb.14:                               #   in Loop: Header=BB0_5 Depth=2
	movq	%r14, %rdi
	callq	fclose
	movq	152(%rsp), %rax                 # 8-byte Reload
	incq	%rax
	addq	$65536, %rbx                    # imm = 0x10000
	cmpq	$1024, %rax                     # imm = 0x400
	jne	.LBB0_5
# %bb.15:                               #   in Loop: Header=BB0_1 Depth=1
	movq	88(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	callq	puts@PLT
	movq	80(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	movq	72(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	movq	144(%rsp), %rdi                 # 8-byte Reload
	callq	free
	movq	64(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	32(%rsp), %rax                  # 8-byte Reload
	incl	%eax
	cmpl	$8, %eax
	leaq	24(%rsp), %r15
	leaq	54(%rsp), %r12
	leaq	134(%rsp), %r14
	jne	.LBB0_1
# %bb.16:
	xorl	%eax, %eax
	jmp	.LBB0_17
.LBB0_2:
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	movl	$1, %eax
.LBB0_17:                               # %.loopexit114
	addq	$262344, %rsp                   # imm = 0x400C8
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"crab_nasu_"
	.size	.L.str.1, 11

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"_fft"
	.size	.L.str.4, 5

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	".bin"
	.size	.L.str.5, 5

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%s"
	.size	.L.str.7, 3

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"%s%s%s%s%s%d%s"
	.size	.L.str.9, 15

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"%s\n%s\n"
	.size	.L.str.10, 7

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"rb"
	.size	.L.str.11, 3

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"ab"
	.size	.L.str.13, 3

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"\346\227\245\344\273\230\343\202\222\345\205\245\345\212\233\343\201\227\343\201\246\343\201\217\343\201\240\343\201\225\343\201\204\343\200\202(yyyymmdd)"
	.size	.Lstr, 47

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"\346\231\202\351\226\223\343\202\222\345\205\245\345\212\233\343\201\227\343\201\246\343\201\217\343\201\240\343\201\225\343\201\204\343\200\202(just,a1,b1 etc..)"
	.size	.Lstr.1, 55

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"\343\203\225\343\202\241\343\202\244\343\203\253\343\202\222\343\202\252\343\203\274\343\203\227\343\203\263\343\201\247\343\201\215\343\201\276\343\201\233\343\202\223\343\201\247\343\201\227\343\201\237\343\200\202"
	.size	.Lstr.4, 55

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
