void ZoneData::Read_Data (int num) { int id, field, count; Db_Index_Array *data; Db_Header *file; //---- set the file pointers ---- file = data_files [num]; if (file == NULL) return; data = data_db [num]; field = data_field [num]; if (!data->Max_Records (file->Num_Records ())) { Error ("Insufficient Memory for Data File Database"); } //---- read the data file ---- Show_Message ("Reading %s -- Record", file->File_Type ()); Set_Progress (1000); count = 0; while (file->Read ()) { Show_Progress (); //---- get the join field id ---- file->Get_Field (field, &id); if (id == 0) continue; //---- copy the data fields ---- data->Copy_Fields (file); //---- set the record index and location count ---- data->Put_Field (1, id); data->Put_Field (2, 0); //---- save the database record ---- if (!data->Add_Record ()) { Error ("Writing Data File Database"); } count++; } End_Progress (); Print (2, "Number of %s Records = %d", file->File_Type (), count); file->Close (); }
void ZoneData::Read_Data (void) { int id, field, count; Db_Sort_Array *data; Db_Header *file; Data_Itr data_itr; for (data_itr = data_group.begin (); data_itr != data_group.end (); data_itr++) { file = data_itr->file; data = data_itr->data_db; field = data_itr->join_field; //---- read the data file ---- Show_Message (String ("Reading %s -- Record") % file->File_Type ()); Set_Progress (); count = 0; while (file->Read ()) { Show_Progress (); //---- get the join field id ---- id = file->Get_Integer (field); if (id == 0) continue; //---- copy the data fields ---- data->Copy_Fields (*file); //---- set the record index and zone count ---- data->Put_Field (0, id); data->Put_Field (1, 0); //---- save the database record ---- if (!data->Write_Record (id)) { Error ("Writing Data File Database"); } count++; } End_Progress (); Print (2, String ("Number of Data #%d Records = %d") % data_itr->group % count); file->Close (); } }
void LineSum::Compare (void) { int mode; Dtime time; Db_Header *fh; File_Itr file_itr; Sort_Key sort_key; Route_Data route_rec, *base_ptr, *alt_ptr; Route_Map_Itr route_itr, base_itr; Route_Map_Stat route_stat; Route_Map base_map, alt_map; //---- compare files ---- Show_Message ("Reading Base Route Files -- Record"); Set_Progress (); for (mode=1, file_itr = base_routes.begin (); file_itr != base_routes.end (); file_itr++, mode++) { fh = *file_itr; while (fh->Read ()) { Show_Progress (); sort_key.mode = (short) mode; //(short) fh->Get_Integer ("MODE"); sort_key.leg = (short) 1; sort_key.name = fh->Get_String ("NAME"); time = fh->Get_Time ("HEADWAY1"); route_rec.headway1 = (int) time.Minutes (); time = fh->Get_Time ("HEADWAY2"); route_rec.headway2 = (int) time.Minutes (); time = fh->Get_Time ("TTIME1"); route_rec.ttime1 = (int) time.Minutes (); time = fh->Get_Time ("TTIME2"); route_rec.ttime2 = (int) time.Minutes (); route_rec.nodes = fh->Get_Integer ("NODES"); route_rec.notes = fh->Get_String ("NOTES"); route_rec.match = 0; route_stat = base_map.insert (Route_Map_Data (sort_key, route_rec)); if (!route_stat.second) { sort_key.leg = (short) 2; route_stat = base_map.insert (Route_Map_Data (sort_key, route_rec)); } } } End_Progress (); //---- compare files ---- Show_Message ("Reading Alternative Route Files -- Record"); Set_Progress (); New_Page (); Header_Number (DIFFERENCE_REPORT); Compare_Header (); for (mode=1, file_itr = alt_routes.begin (); file_itr != alt_routes.end (); file_itr++, mode++) { fh = *file_itr; while (fh->Read ()) { Show_Progress (); sort_key.mode = (short) mode; //(short) fh->Get_Integer ("MODE"); sort_key.leg = (short) 1; sort_key.name = fh->Get_String ("NAME"); time = fh->Get_Time ("HEADWAY1"); route_rec.headway1 = (int) time.Minutes (); time = fh->Get_Time ("HEADWAY2"); route_rec.headway2 = (int) time.Minutes (); time = fh->Get_Time ("TTIME1"); route_rec.ttime1 = (int) time.Minutes (); time = fh->Get_Time ("TTIME2"); route_rec.ttime2 = (int) time.Minutes (); route_rec.nodes = fh->Get_Integer ("NODES"); route_rec.notes = fh->Get_String ("NOTES"); route_rec.match = 0; route_stat = alt_map.insert (Route_Map_Data (sort_key, route_rec)); if (!route_stat.second) { sort_key.leg = (short) 2; route_stat = alt_map.insert (Route_Map_Data (sort_key, route_rec)); } } } End_Progress (); for (route_itr = alt_map.begin (); route_itr != alt_map.end (); route_itr++) { sort_key = route_itr->first; alt_ptr = &route_itr->second; base_itr = base_map.find (route_itr->first); if (base_itr == base_map.end ()) { Print (1, String ("%3d %-12.12s") % sort_key.mode % sort_key.name); Print (0, String (" %6.1lf %6.1lf %6.1lf %6.1lf %5d %6.1lf %6.1lf %6.1lf %6.1lf %5d ") % 0 % 0 % 0 % 0 % 0 % alt_ptr->headway1 % alt_ptr->ttime1 % alt_ptr->headway2 % alt_ptr->ttime2 % alt_ptr->nodes); Print (0, alt_ptr->notes); } else { base_ptr = &base_itr->second; base_ptr->match = 1; if (base_ptr->headway1 != alt_ptr->headway1 || base_ptr->headway2 != alt_ptr->headway2 || base_ptr->ttime1 != alt_ptr->ttime1 || base_ptr->ttime2 != alt_ptr->ttime2 || base_ptr->nodes != alt_ptr->nodes) { Print (1, String ("%3d %-12.12s") % sort_key.mode % sort_key.name); Print (0, String (" %6.1lf %6.1lf %6.1lf %6.1lf %5d %6.1lf %6.1lf %6.1lf %6.1lf %5d ") % base_ptr->headway1 % base_ptr->ttime1 % base_ptr->headway2 % base_ptr->ttime2 % base_ptr->nodes % alt_ptr->headway1 % alt_ptr->ttime1 % alt_ptr->headway2 % alt_ptr->ttime2 % alt_ptr->nodes); Print (0, base_ptr->notes); } } } for (base_itr = base_map.begin (); base_itr != base_map.end (); base_itr++) { if (base_itr->second.match == 0) { sort_key = base_itr->first; base_ptr = &base_itr->second; Print (1, String ("%3d %-12.12s") % sort_key.mode % sort_key.name); Print (0, String (" %6.1lf %6.1lf %6.1lf %6.1lf %5d %6.1lf %6.1lf %6.1lf %6.1lf %5d ") % base_ptr->headway1 % base_ptr->ttime1 % base_ptr->headway2 % base_ptr->ttime2 % base_ptr->nodes % 0 % 0 % 0 % 0 % 0); Print (0, base_ptr->notes); } } Header_Number (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; } }