Exemple #1
0
bool TransimsNet::Get_Phasing_Data (Phasing_File &file, Phasing_Record &phasing_rec)
{
	int link, dir, node, dir_index, to_index, num, detector, signal;
	String svalue;
	
	Int_Map_Itr map_itr;
	Int2_Map_Itr map2_itr;
	Link_Data *link_ptr;
	Dir_Data *dir_ptr;

	Phasing_Data *phasing_ptr = &(phasing_rec.phasing_data);

	//---- process the header record ----
	
	if (!file.Nested ()) {
		signal = file.Signal ();
		if (signal == 0) return (false);

		map_itr = signal_map.find (signal);
		if (map_itr == signal_map.end ()) {
			Warning (String ("Phasing Signal %d was Not Found") % signal);
			return (false);
		}
		phasing_rec.Signal (map_itr->second);

		phasing_ptr->Phasing (file.Phasing ());
		phasing_ptr->Phase (file.Phase ());

		//---- process the detectors ----

		svalue = file.Detectors ();

		if (!svalue.empty ()) {
			Strings detect;
			Str_Itr itr;

			num = svalue.Parse (detect, "|+/");

			for (itr = detect.begin (); itr != detect.end (); itr++) {
				detector = itr->Integer ();
				if (detector <= 0) break;

				map_itr = detector_map.find (detector);
				if (map_itr == detector_map.end ()) {
					Warning (String ("Signal %d Detector %d was Not Found") % file.Signal () % detector);
					break;
				}
				phasing_ptr->detectors.push_back (map_itr->second);
			}
		}
		if (file.Version () > 40) return (phasing_rec.Signal () >= 0);
	}
	Movement_Data move_rec;

	move_rec.Movement (file.Movement ());

	//---- convert the link direction ----
	
	link = file.Link ();
	dir = file.Dir ();

	link_ptr = Set_Link_Direction (file, link, dir);

	if (link_ptr == 0) return (false);

	if (dir) {
		dir_index = link_ptr->BA_Dir ();
		node = link_ptr->Anode ();
	} else {
		dir_index = link_ptr->AB_Dir ();
		node = link_ptr->Bnode ();
	}
	if (dir_index < 0) {
		Warning (String ("Phasing Plan %d Link %d Direction %s was Not Found") % Progress_Count () % 
			link_ptr->Link () % ((dir) ? "BA" : "AB"));
		return (false);
	}

	//---- convert the to-link number ----

	link = file.To_Link ();

	map_itr = link_map.find (link);
	if (map_itr == link_map.end ()) {
		Warning (String ("Phasing Plan %d Link %d was Not Found") % Progress_Count () % link);
		return (false);
	}
	link = map_itr->second;

	link_ptr = &link_array [link];

	if (link_ptr->Anode () == node) {
		to_index = link_ptr->AB_Dir ();
	} else if (link_ptr->Bnode () == node) {
		to_index = link_ptr->BA_Dir ();
	} else {
		Node_Data *ptr = &node_array [node];
		Warning (String ("Phasing Plan %d Node %d is Not on Link %d") % Progress_Count () % ptr->Node () % link_ptr->Link ());
		return (false);
	}

	//---- check the link connection ----

	map2_itr = connect_map.find (Int2_Key (dir_index, to_index));

	if (map2_itr == connect_map.end ()) {
		to_index = link_ptr->Link ();

		dir_ptr = &dir_array [dir_index];
		link_ptr = &link_array [dir_ptr->Link ()];
		dir_index = link_ptr->Link ();

		if (file.Version () > 40) {
			Warning (String ("No Link Connection between %d and %d") % dir_index % to_index);
		}
		return (false);
	}

	//---- save the data ----

	move_rec.Connection (map2_itr->second);

	move_rec.Protection (file.Protection ());

	if (file.Version () <= 40 && move_rec.Movement () == 0) {
		Connect_Data *connect_ptr;
		const char *direction;

		dir_ptr = &dir_array [dir_index];
		direction = compass.Point_Text (dir_ptr->In_Bearing (), 4);

		if (*direction == 'N') {
			dir = NB_TH;
		} else if (*direction == 'S') {
			dir = SB_TH;
		} else if (*direction == 'E') {
			dir = EB_TH;
		} else {
			dir = WB_TH;
		}
		connect_ptr = &connect_array [map2_itr->second];
		num = connect_ptr->Type ();
		
		if (num == RIGHT || num == R_SPLIT) {
			dir += NB_RT - NB_TH;
		} else if (num == LEFT || num == L_SPLIT) {
			dir += NB_LT - NB_TH;
		} else if (num == UTURN) {
			dir += NB_UT - NB_TH;
		}
		move_rec.Movement (dir);
	}
	phasing_ptr->push_back (move_rec);

	return (phasing_rec.Signal () >= 0);
}
Exemple #2
0
bool Network_Service::Phasing_Processing (Db_File *fh)
{
	bool node_flag, link_flag, timing_flag, detector_flag;
	int lvalue, index, node_num, num;
	char *svalue, *ptr;

	Link_Data *link_ptr = NULL;
	Phasing_Data *phasing_ptr = NULL;
	Timing_Data timing_rec;

	Phasing_File *file = (Phasing_File *) fh;

	node_flag = Network_Data_Flag (NODE);
	link_flag = Network_Data_Flag (LINK);
	timing_flag = Network_Data_Flag (TIMING_PLAN);
	detector_flag = Network_Data_Flag (DETECTOR);

	//---- reserve memory ----

	if (phasing_data.Max_Records () == 0) {
		if (!phasing_data.Max_Records (file->Num_Records ())) goto mem_error;
	}

	//---- read and save the data ----

	phasing_ptr = phasing_data.New_Record ();
	if (phasing_ptr == NULL) goto mem_error;
	phasing_ptr->Reset ();

	node_num = file->Node ();

	if (node_num == 0) return (false);

	//---- store the node ----

	if (node_flag) {
		num = node_data.Get_Index (node_num);

		if (num == 0) {
			return (Check_Message ("Phasing Plan Node %d was Not Found in the Node file", node_num));
		}
		if (!Renumber ()) {
			num = node_num;
		}
	} else {
		num = node_num;
	}
	phasing_ptr->Node (num);

	//---- check the timing plan ----

	if (timing_flag) {
		timing_rec.Timing (file->Timing ());
		timing_rec.Phase (file->Phase ());

		if (timing_data.Get_Index (&timing_rec) == 0) {
			return (Check_Message ("Timing Plan %d-%d was Not Found in the Timing Plan file", file->Timing (), file->Phase ()));
		}
	}
	phasing_ptr->Timing (file->Timing ());
	phasing_ptr->Phase (file->Phase ());

	//---- check/convert the in-link number ----
	
	lvalue = file->In_Link ();
	if (lvalue <= 0) goto link_error;

	if (link_flag) {
		index = link_data.Get_Index (lvalue);
		if (index == 0) goto link_error;

		link_ptr = link_data [index];

		if (!Renumber ()) {
			index = lvalue;
		}
		phasing_ptr->In_Link (index);
		
		if (link_ptr->Anode () == num) {
			phasing_ptr->In_Dir (1);
			index = link_ptr->BA_Dir ();
		} else if (link_ptr->Bnode () == num) {
			phasing_ptr->In_Dir (0);
			index = link_ptr->AB_Dir ();
		} else {
			index = 0;
		}
		if (index == 0) goto link_error;
	} else {
		phasing_ptr->In_Link (lvalue);
	}

	//---- check/convert the out-link number ----
	
	lvalue = file->Out_Link ();
	if (lvalue <= 0) goto link_error;

	if (link_flag) {
        index = link_data.Get_Index (lvalue);
		if (index == 0) goto link_error;

		link_ptr = link_data [index];

		if (!Renumber ()) {
			index = lvalue;
		}
		phasing_ptr->Out_Link (index);

		if (link_ptr->Bnode () == num) {
			phasing_ptr->Out_Dir (1);
			index = link_ptr->BA_Dir ();
        } else if (link_ptr->Anode () == num) {
			phasing_ptr->Out_Dir (0);
			index = link_ptr->AB_Dir ();
		} else {
			index = 0;
		}
		if (index == 0) goto link_error;
	} else {
		phasing_ptr->Out_Link (lvalue);
	}

	//---- convert the protection code ----

	phasing_ptr->Protection (Protection_Code (file->Protection ()));

	//---- process the detectors ----

	svalue = file->Detectors ();

	if (*svalue == '\0' || atoi (svalue) == 0) {
		phasing_ptr->Num_Detectors (0);
		return (true);
	}
	num = 1;
	ptr = svalue;

	while ((ptr = strchr (ptr, '/')) != NULL) {
		num++;
		ptr++;
	}
	if (!phasing_ptr->Num_Detectors (num)) {
		Error ("Insufficient Memory for %d Detectors on Phasing Plan %d", num, Progress_Count ());
	}
	num = 0;

	while (svalue != NULL) {
		ptr = strchr (svalue, '/');

		if (ptr != NULL) {
			*ptr++ = '\0';
		}
		lvalue = atoi (svalue);

		if (lvalue <= 0) break;
		num++;

		if (detector_flag) {
			index = detector_data.Get_Index (lvalue);

			if (index == 0) {
				return (Check_Message ("Phasing Plan Detector %d was Not Found in the Detector file", lvalue));
			}
			if (!Renumber ()) {
				index = lvalue;
			}
			phasing_ptr->Detector (num, index);
		} else {
			phasing_ptr->Detector (num, lvalue);
		}
		svalue = ptr;
	}
	if (phasing_ptr->Num_Detectors () != num) {
		return (Check_Message ("Phasing Plan %d Detector Numbers are Not Valid", Progress_Count ()));
	}
	return (true);

link_error:
	return (Check_Message ("Phasing Plan Node %d Link %d was Not Found", node_num, lvalue));

mem_error:
	Error ("Insufficient Memory for Phasing Plan Data");
	return (false);
}