		cvInitFont( &font_1, CV_FONT_HERSHEY_COMPLEX, 0.3, 0.3, 0.0, 1, line_type );
		
		char previous_state=state;
		char temp_char=cvWaitKey(5);
		if(temp_char>0){
			//Yaw angle=0
			x_angle=0;

			if(temp_char=='i'||temp_char=='n'||temp_char=='p'||temp_char=='s'||temp_char=='r'||temp_char=='q')//q:quit
				state=temp_char;
				log_event=TRUE;
		}

		switch((char)state){
			
			case 'i' :
				pt_1.x=(int)(700/scaling);
				pt_1.y=(int)(10/scaling);
				cvPutText( image, "iddle",pt_1, &font_1, CV_RGB(255,100,100));
				pt_1.y=(int)(20/scaling);cvPutText( image, "n: start new log file",pt_1, &font_1, CV_RGB(255,100,100));
			break; 
			case 'n':
				pt_1.x=(int)(700/scaling);
				pt_1.y=(int)(10/scaling);
				cvPutText( image, "logging",pt_1, &font_1, CV_RGB(255,100,100));
				pt_1.y=(int)(20/scaling);cvPutText( image, "s: stop logging",pt_1, &font_1, CV_RGB(255,100,100));
				pt_1.y=(int)(30/scaling);cvPutText( image, "p: pause logging",pt_1, &font_1, CV_RGB(255,100,100));
				
				if(temp_char>0){//New input given
					pt_1.y=(int)(40/scaling);cvPutText( image, "Exp_name(.):",pt_1, &font_1, CV_RGB(255,100,100));
					cvShowImage(wndname,image);

					int temp_counter=12;
					while(temp_counter<30&&temp_char!='.'){
						temp_char=cvWaitKey();

						experiment_name[temp_counter]=temp_char;
						pt_1.x=(int)(790/scaling);
						cvPutText( image, experiment_name,pt_1, &font_1, CV_RGB(255,100,100));
						cvShowImage(wndname,image);
						temp_counter++;
					}
					// Create directory
					//http://msdn.microsoft.com/en-us/library/2fkk4dzw(VS.80).aspx
					_mkdir(experiment_name);					

					strcpy(log_filename,experiment_name);
					strcat (&log_filename[temp_counter],"/log.txt");
					/*
					//
					strcpy(log_filename_avr,experiment_name);
					strcat (&log_filename_avr[temp_counter],"/avr.txt");
					*/
					//Make 3 folder for each cam
					strcpy(cam1_folder,experiment_name);
					//strcpy(cam2_folder,experiment_name);
					//strcpy(cam3_folder,experiment_name);
					
					strcat(cam1_folder,"/cam");
					_mkdir(cam1_folder);
					//strcat(cam1_folder,"/cam1");
					//strcat(cam2_folder,"/cam2");
					//strcat(cam3_folder,"/cam3");

					//_mkdir(cam1_folder);
					//_mkdir(cam2_folder);
					//_mkdir(cam3_folder);
					fflush(log_File);
					log_File = fopen (log_filename,"w");
					if (log_File!=NULL){
						//fputs ("fopen example",log_File);
						//fclose (log_File);
					}
					
					/*
					fflush(log_File_avr);
					log_File_avr = fopen (log_filename_avr,"w");					
					if (log_File_avr!=NULL){
						//fputs ("fopen example",log_File_vbox);
						//fclose (log_File);
					}*/
					
					for(int temp_cnt=12;temp_cnt<60;temp_cnt++){
						experiment_name[temp_cnt]=0;
						log_filename[temp_cnt]=0;
					}
					//Initiate new count
					QueryPerformanceCounter(&tstart);
					//Zero sample number
					sample_number=0;
					
				}
			break;
			case 'p':
				pt_1.x=(int)(700/scaling);
				pt_1.y=(int)(10/scaling);
				cvPutText( image, "paused",pt_1, &font_1, CV_RGB(255,100,100));
				pt_1.y=(int)(20/scaling);cvPutText( image, "n: start new log file",pt_1, &font_1, CV_RGB(255,100,100));
				pt_1.y=(int)(30/scaling);cvPutText( image, "s: stop logging",pt_1, &font_1, CV_RGB(255,100,100));
				pt_1.y=(int)(40/scaling);cvPutText( image, "r: resume logging",pt_1, &font_1, CV_RGB(255,100,100));
			break;
			case 's':
				cvWaitKey(100);

				pt_1.x=(int)(700/scaling);
				pt_1.y=(int)(10/scaling);
				cvPutText( image, "Stopped",pt_1, &font_1, CV_RGB(255,100,100));
				pt_1.y=(int)(20/scaling);cvPutText( image, "n: start new log file",pt_1, &font_1, CV_RGB(255,100,100));
				cvShowImage(wndname,image);
				if (log_File!=NULL){
					fflush(log_File);
					fclose (log_File);
					log_File=NULL;
				}
				/*
				if (log_File_avr!=NULL){
					fflush(log_File_avr);
					fclose (log_File_avr);
					log_File_avr=NULL;
				}*/
				state='i';
				state='i';
			break;
			case 'r':
				pt_1.x=(int)(700/scaling);
				pt_1.y=(int)(10/scaling);
				cvPutText( image, "Resumed",pt_1, &font_1, CV_RGB(255,100,100));
				pt_1.y=(int)(20/scaling);cvPutText( image, "n: start new log file",pt_1, &font_1, CV_RGB(255,100,100));
				pt_1.y=(int)(30/scaling);cvPutText( image, "s: stop logging",pt_1, &font_1, CV_RGB(255,100,100));
				pt_1.y=(int)(40/scaling);cvPutText( image, "p: pause logging",pt_1, &font_1, CV_RGB(255,100,100));
			break;
			case 'q' :
				pt_1.x=(int)(700/scaling);
				pt_1.y=(int)(10/scaling);
				cvPutText( image, "quit(y/n)",pt_1, &font_1, CV_RGB(255,100,100));
				cvShowImage(wndname,image);
				//pt_1.y=(int)(20/scaling);cvPutText( image, "n: start new log file",pt_1, &font_1, CV_RGB(255,100,100));
				temp_char=cvWaitKey();
				if(temp_char=='y'){
					goto _cleanup_;
				}
				else
					state=previous_state;
			break; 
		}
		log_event=FALSE;