Example #1
0
void LineSum::Combine (int period, File_List &list, Db_Header &output)
{
	int i, j, num_out, node, vol;
	String name, name_key;
	double freq;
	bool stat;
	Db_Header *fh;
	File_Itr file_itr;
	Sort_Key sort_key;
	Leg_Data leg_data;
	Line_Map_Stat map_stat;
	On_Off_Data on_off_data;
	Access_Key access_key;
	Access_Map_Stat access_stat;
	On_Off_Key on_off_key;
	On_Off_Map_Stat on_off_stat;
	Line_Map *map;
	Str_ID_Itr service_itr;

	if (list.size () == 0) return;

	if (period == 0) {
		name = "Peak";
		map = &peak_map;
	} else if (period == 1) {
		name = "Offpeak";
		map = &offpeak_map;
	} else {
		name = "Total";
		map = 0;
	}
	Show_Message (String ("Reading %s Ridership Files -- Record") % name);
	Set_Progress ();
	num_out = 0;

	memset (&on_off_data, '\0', sizeof (on_off_data));

	if (list.size () == 1) {
		fh = *list.begin ();

		while (fh->Read ()) {
			Show_Progress ();

			//---- copy fields to the output file ----

			if (output.Is_Open ()) {
				output.Copy_Fields (*fh);
				output.Write ();
			}

			//---- save the data to the line map ----

			if (map == 0) continue;

			name = fh->Get_String ("NAME");
			name.Trim ();
			if (name.Ends_With ("-")) continue;

			if (name [0] == '*') {
				if (access_flag) {
					vol = fh->Get_Integer ("AB_VOL");
					if (vol == 0) continue;

					access_key.stop = fh->Get_Integer ("A");
					access_key.mode = fh->Get_Integer ("MODE");
					access_key.node = fh->Get_Integer ("B");

					access_stat = access_map.insert (Access_Map_Data (access_key, on_off_data));

					if (period == 0) {
						access_stat.first->second.pk_off += vol;
					} else {
						access_stat.first->second.op_off += vol;
					}
					node = access_key.node;
					access_key.node = access_key.stop;
					access_key.stop = node;

					access_stat = access_map.insert (Access_Map_Data (access_key, on_off_data));

					if (period == 0) {
						access_stat.first->second.pk_on += vol;
					} else {
						access_stat.first->second.op_on += vol;
					}
				}
				continue;
			}
			sort_key.mode = (short) fh->Get_Integer ("MODE");
			sort_key.name = name;
			sort_key.leg = (short) fh->Get_Integer ("SEQ");

			if (fh->Get_Integer ("STOP_A") == 0) {
				leg_data.a = -fh->Get_Integer ("A");;
			} else {
				leg_data.a = fh->Get_Integer ("A");;
			}
			if (fh->Get_Integer ("STOP_B") == 0) {
				leg_data.b = -fh->Get_Integer ("B");;
			} else {
				leg_data.b = fh->Get_Integer ("B");;
			}
			leg_data.time = (short) fh->Get_Integer ("TIME");
			leg_data.dist = (short) fh->Get_Integer ("DIST");
			freq = fh->Get_Double ("FREQ");
			if (freq > 0.0) {
				leg_data.runs = 60.0 / freq;
			} else {
				leg_data.runs = 0.0;
			}
			leg_data.ab.ride = fh->Get_Integer ("AB_VOL");
			leg_data.ab.on = fh->Get_Integer ("AB_BRDA");
			leg_data.ab.off = fh->Get_Integer ("AB_XITB");
			leg_data.ba.ride = fh->Get_Integer ("BA_VOL");
			leg_data.ba.on = fh->Get_Integer ("BA_BRDB");
			leg_data.ba.off = fh->Get_Integer ("BA_XITA");

			if (service_flag && period < 2) {
				name_key = name;
				name_key.To_Upper ();

				service_itr = service_map.find (name_key);
				if (service_itr != service_map.end ()) {
					if (period == 0) {
						leg_data.service = service_itr->second >> 16;
					} else {
						leg_data.service = service_itr->second & 0xFFFF;
					}
				}