// File: richardposner[P]BioNetFit2/src/code/Utils.cpp
// Function: generate_gdat_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
int generate_gdat_file(string exp_file, string gdat_path, int seed){ //razi added to generate artificial gdat files
	//read exp-file
	//copy to gdat file
cout<<"\nUtils::generate_gdat_file: PiD["<<seed <<"] Starts generating file: "<< gdat_path << "   from file :" << exp_file<<"\n.";
try{
	std::ifstream ifs(exp_file);
	std::ofstream ofs(gdat_path);
	std::string line, oline;
	std::string word;
	int wcnt, linecnt;
	int val, rnd1; //Raquel removed unused, rnd;
	std::string::size_type pos = 0;
	std::string::size_type prev = 0;
	boost::random::mt19937 generalRand;

//cout<<"Utils:g-1   try to generate file:" <<gdat_path << " from file: " << exp_file<< endl;
	if ((ifs.is_open()) && (ofs.is_open())) {


		linecnt=0;
		while (getline(ifs, line)) {
			if (line.length() > 0){
				linecnt++;
				if (line.at(0) == '#'){
					oline=line;
//cout<<"Utils:g-2   A header line is read:" <<line << endl;
				}else{

//cout<<"Utils:g-3   A valid line is read:" <<line << endl;
					//data line break line into smaller pieces

					pos = 0; prev = 0; wcnt=0; oline=""; line=line+"\t"; //add tab to the end

					srand(time(0)+seed);
					while ((pos = line.find("\t", prev)) != std::string::npos)
					{
						if (pos != prev) //otherwise, most likely the first tab
						{
							wcnt++;
							word = line.substr(prev, pos - prev);


//cout<<"Utils:g-4   A word is read:" <<word << endl;
							if (wcnt == 1){  //the first word is time, don't touch it
								oline=oline + "\t" + word;
							}else{
								//for all pieces, if numerical value , change all of it except the first one
								val = atoi(word.c_str());


								rnd1 = rand()%100;
								val = val + (int) (rnd1);
								if (val < 0){ val=-val;}

//cout<<"Utils:g-6  the new value is :" <<val<< endl;
								oline = oline +"\t" + toString(val);
//cout<<"Utils:g-7  output line is :" <<oline <<endl;

							}
						}
						prev = pos + 1;
					}
					//write the output line into the output file
				}
//cout<<"Utils:g-9  try to dump output line:" <<oline <<endl;
				ofs << oline << std::endl;
			}
		}
		ifs.close();
		ofs.close();
//cout<<"Utils:g-10   finished generating file:" <<gdat_path << " from file: " << exp_file<< " successfully." <<endl;
		return 0;  //successful
	}else{
//cout<<"Utils:g-11   try to generate file:" <<gdat_path << " from file: " << exp_file<< ", Can't open input or output file !!!" <<endl;
		return -1;
	}
}
catch(int err){
	cout<< "Error occurred when generating artificial gdata file....\n\n"; return -1;
}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xfa0, %rsp            # imm = 0xFA0
movq %rdi, -0xf70(%rbp)
movq %rsi, -0xf78(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq 0x158795(%rip), %rdi    # 0x2d4f50
leaq 0x8860d(%rip), %rsi     # 0x204dcf
callq 0x2ff50
movq %rax, %rdi
movl -0x1c(%rbp), %esi
callq 0x2f800
movq %rax, %rdi
leaq 0x88614(%rip), %rsi     # 0x204df0
callq 0x2ff50
movq -0xf78(%rbp), %rsi
movq %rax, %rdi
callq 0x2f780
movq %rax, %rdi
leaq 0x5ec25(%rip), %rsi     # 0x1db41f
callq 0x2ff50
movq -0xf70(%rbp), %rsi
movq %rax, %rdi
callq 0x2f780
movq %rax, %rdi
leaq 0x65204(%rip), %rsi     # 0x1e1a1c
callq 0x2ff50
movq -0xf70(%rbp), %rsi
leaq -0x228(%rbp), %rdi
movl $0x8, %edx
callq 0x30d80
jmp 0x17c837
movq -0xf78(%rbp), %rsi
leaq -0x438(%rbp), %rdi
movl $0x10, %edx
callq 0x2f360
jmp 0x17c851
leaq -0x458(%rbp), %rdi
callq 0x2f880
leaq -0x478(%rbp), %rdi
callq 0x2f880
leaq -0x498(%rbp), %rdi
callq 0x2f880
movq $0x0, -0x4b0(%rbp)
movq $0x0, -0x4b8(%rbp)
leaq -0xe80(%rbp), %rdi
callq 0x120c00
jmp 0x17c899
leaq -0x228(%rbp), %rdi
callq 0x30980
movb %al, -0xf79(%rbp)
jmp 0x17c8ad
movb -0xf79(%rbp), %al
testb $0x1, %al
jne 0x17c8bc
jmp 0x17cd2e
leaq -0x438(%rbp), %rdi
callq 0x30530
movb %al, -0xf7a(%rbp)
jmp 0x17c8d0
movb -0xf7a(%rbp), %al
testb $0x1, %al
jne 0x17c8df
jmp 0x17cd2e
movl $0x0, -0x4a0(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x458(%rbp), %rsi
callq 0x2fcb0
movq %rax, -0xf88(%rbp)
jmp 0x17c905
movq -0xf88(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2f8e0
movb %al, -0xf89(%rbp)
jmp 0x17c923
movb -0xf89(%rbp), %al
testb $0x1, %al
jne 0x17c932
jmp 0x17ccff
leaq -0x458(%rbp), %rdi
callq 0x2ff30
cmpq $0x0, %rax
jbe 0x17ccfa
movl -0x4a0(%rbp), %eax
incl %eax
movl %eax, -0x4a0(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x458(%rbp), %rdi
callq 0x30840
movq %rax, -0xf98(%rbp)
jmp 0x17c96f
movq -0xf98(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x17c9dd
leaq -0x478(%rbp), %rdi
leaq -0x458(%rbp), %rsi
callq 0x30fa0
jmp 0x17c993
jmp 0x17ccc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x17cdbc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x17cdb0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x17cd80
movq $0x0, -0x4b0(%rbp)
movq $0x0, -0x4b8(%rbp)
movl $0x0, -0x49c(%rbp)
leaq 0x5cafc(%rip), %rsi     # 0x1d9500
leaq -0x478(%rbp), %rdi
callq 0x2f9d0
jmp 0x17ca12
leaq 0x5cae6(%rip), %rdx     # 0x1d94ff
leaq -0xea0(%rbp), %rdi
leaq -0x458(%rbp), %rsi
callq 0x447b0
jmp 0x17ca2e
leaq -0x458(%rbp), %rdi
leaq -0xea0(%rbp), %rsi
callq 0x2fd80
leaq -0xea0(%rbp), %rdi
callq 0x311e8
xorl %eax, %eax
movl %eax, %edi
callq 0x303a0
movslq -0x1c(%rbp), %rcx
addq %rcx, %rax
movl %eax, %edi
callq 0x31020
movq -0x4b8(%rbp), %rdx
leaq -0x458(%rbp), %rdi
leaq 0x5ca86(%rip), %rsi     # 0x1d94ff
callq 0x2f060
movq %rax, -0x4b0(%rbp)
cmpq $-0x1, %rax
je 0x17ccc5
movq -0x4b0(%rbp), %rax
cmpq -0x4b8(%rbp), %rax
je 0x17ccae
movl -0x49c(%rbp), %eax
incl %eax
movl %eax, -0x49c(%rbp)
movq -0x4b8(%rbp), %rdx
movq -0x4b0(%rbp), %rcx
subq %rdx, %rcx
leaq -0xec0(%rbp), %rdi
leaq -0x458(%rbp), %rsi
callq 0x30b40
jmp 0x17cad7
leaq -0x498(%rbp), %rdi
leaq -0xec0(%rbp), %rsi
callq 0x2fd80
leaq -0xec0(%rbp), %rdi
callq 0x311e8
cmpl $0x1, -0x49c(%rbp)
jne 0x17cb8e
leaq 0x5c9f5(%rip), %rdx     # 0x1d94ff
leaq -0xf00(%rbp), %rdi
leaq -0x478(%rbp), %rsi
callq 0x447b0
jmp 0x17cb1f
leaq -0xee0(%rbp), %rdi
leaq -0xf00(%rbp), %rsi
leaq -0x498(%rbp), %rdx
callq 0x44760
jmp 0x17cb3b
leaq -0x478(%rbp), %rdi
leaq -0xee0(%rbp), %rsi
callq 0x2fd80
leaq -0xee0(%rbp), %rdi
callq 0x311e8
leaq -0xf00(%rbp), %rdi
callq 0x311e8
jmp 0x17ccac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0xf00(%rbp), %rdi
callq 0x311e8
jmp 0x17cd80
leaq -0x498(%rbp), %rdi
callq 0x2f290
movq %rax, %rdi
callq 0x2f810
movl %eax, -0x4a4(%rbp)
callq 0x30b00
movl $0x64, %ecx
cltd
idivl %ecx
movl %edx, -0x4a8(%rbp)
movl -0x4a4(%rbp), %eax
addl -0x4a8(%rbp), %eax
movl %eax, -0x4a4(%rbp)
cmpl $0x0, -0x4a4(%rbp)
jge 0x17cbe4
xorl %eax, %eax
subl -0x4a4(%rbp), %eax
movl %eax, -0x4a4(%rbp)
leaq 0x5c914(%rip), %rdx     # 0x1d94ff
leaq -0xf40(%rbp), %rdi
leaq -0x478(%rbp), %rsi
callq 0x447b0
jmp 0x17cc00
movl -0x4a4(%rbp), %esi
leaq -0xf60(%rbp), %rdi
callq 0x17ce40
jmp 0x17cc14
leaq -0xf20(%rbp), %rdi
leaq -0xf40(%rbp), %rsi
leaq -0xf60(%rbp), %rdx
callq 0x9c7d0
jmp 0x17cc30
leaq -0x478(%rbp), %rdi
leaq -0xf20(%rbp), %rsi
callq 0x2fd80
leaq -0xf20(%rbp), %rdi
callq 0x311e8
leaq -0xf60(%rbp), %rdi
callq 0x311e8
leaq -0xf40(%rbp), %rdi
callq 0x311e8
jmp 0x17ccac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x17cc9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0xf60(%rbp), %rdi
callq 0x311e8
leaq -0xf40(%rbp), %rdi
callq 0x311e8
jmp 0x17cd80
jmp 0x17ccae
movq -0x4b0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4b8(%rbp)
jmp 0x17ca64
jmp 0x17ccc7
leaq -0x438(%rbp), %rdi
leaq -0x478(%rbp), %rsi
callq 0x2f780
movq %rax, -0xfa0(%rbp)
jmp 0x17cce3
movq -0xfa0(%rbp), %rdi
movq 0x1582d7(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x17ccf8
jmp 0x17ccfa
jmp 0x17c8e9
leaq -0x228(%rbp), %rdi
callq 0x300d0
jmp 0x17cd0d
leaq -0x438(%rbp), %rdi
callq 0x30910
jmp 0x17cd1b
movl $0x0, -0x4(%rbp)
movl $0x1, -0xf64(%rbp)
jmp 0x17cd3f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0xf64(%rbp)
leaq -0x498(%rbp), %rdi
callq 0x311e8
leaq -0x478(%rbp), %rdi
callq 0x311e8
leaq -0x458(%rbp), %rdi
callq 0x311e8
leaq -0x438(%rbp), %rdi
callq 0x304f0
leaq -0x228(%rbp), %rdi
callq 0x2f0e0
jmp 0x17ce25
leaq -0x498(%rbp), %rdi
callq 0x311e8
leaq -0x478(%rbp), %rdi
callq 0x311e8
leaq -0x458(%rbp), %rdi
callq 0x311e8
leaq -0x438(%rbp), %rdi
callq 0x304f0
leaq -0x228(%rbp), %rdi
callq 0x2f0e0
movl -0x234(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x17ce31
movq -0x230(%rbp), %rdi
callq 0x2f160
movl (%rax), %eax
movl %eax, -0xf68(%rbp)
movq 0x15816a(%rip), %rdi    # 0x2d4f50
leaq 0x8801e(%rip), %rsi     # 0x204e0b
callq 0x2ff50
jmp 0x17cdf4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0xf64(%rbp)
callq 0x304d0
jmp 0x17ce25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
callq 0x304d0
jmp 0x17ce31
movl -0x4(%rbp), %eax
addq $0xfa0, %rsp            # imm = 0xFA0
popq %rbp
retq
movq -0x230(%rbp), %rdi
callq 0x30170
nopl (%rax)