while (1) {
	// Load and check all the end flags
	
	file_flag_read.open("flag1_end.m", ios::in);
	file_flag_read >> flag1_end;
	file_flag_read.close();
	
	file_flag_read.open("flag2_end.m", ios::in);
	file_flag_read >> flag2_end;
	file_flag_read.close();
	
	file_flag_read.open("flag3_end.m", ios::in);
	file_flag_read >> flag3_end;
	file_flag_read.close();
	
	file_flag_read.open("flag4_end.m", ios::in);
	file_flag_read >> flag4_end;
	file_flag_read.close();
	
	//cout << "The flags are [" << flag1_end << ", " << flag2_end << ", " << flag3_end << ", " << flag4_end << "]" << endl;
	sleep(1);
	cout << "still waiting for the flags to change" << endl;
	
	// If all end flags are 1 then exit the loop
	if (flag1_end == 1 && flag2_end == 1 && flag3_end == 1 && flag4_end == 1) {
		break;
	}
	
}
	
	
