示例#1
0
void LinkSum::Program_Control (void)
{
	int i, field, ngroup, num;
	bool binary;
	String key, token;

	Location_File *location_file;
	Db_Field *fld;	
	Doubles dbl;
	Doubles_Itr itr;

	//---- set the equivalence flags ----

	Zone_Equiv_Flag (Check_Control_Key (NEW_GROUP_TRAVEL_FILE));

	group_select = Set_Control_Flag (SELECT_BY_LINK_GROUP);
	Link_Equiv_Flag (group_select || Report_Flag (LINK_GROUP) || Report_Flag (TRAVEL_TIME) || 
		Report_Flag (GROUP_REPORT) || Report_Flag (GROUP_SUMMARY) || Check_Control_Key (NEW_GROUP_SUMMARY_FILE));

	//---- open network files ----

	Data_Service::Program_Control ();

	Read_Select_Keys ();

	turn_flag = System_File_Flag (TURN_DELAY);
	
	Print (2, String ("%s Control Keys:") % Program ());	

	//---- open the compare performance file ----
	
	key = Get_Control_String (COMPARE_PERFORMANCE_FILE);

	if (!key.empty ()) {
		compare_file.File_Type ("Compare Performance File");
		Print (1);

		if (Check_Control_Key (COMPARE_PERFORMANCE_FORMAT)) {
			compare_file.Dbase_Format (Get_Control_String (COMPARE_PERFORMANCE_FORMAT));
		}
		compare_file.Open (Project_Filename (key));
		compare_flag = true;
	}
	num_inc = sum_periods.Num_Periods ();
	if (num_inc < 1) num_inc = 1;

	cap_factor = (double) sum_periods.Range_Length () / (Dtime (1, HOURS) * num_inc);
	if (cap_factor <= 0.0) cap_factor = 1.0;

	//---- open the compare link map file ----
	
	key = Get_Control_String (COMPARE_LINK_MAP_FILE);

	if (!key.empty ()) {
		link_map_file.File_Type ("Compare Link Map File");
		Print (1);

		if (Check_Control_Key (COMPARE_LINK_MAP_FORMAT)) {
			link_map_file.Dbase_Format (Get_Control_String (COMPARE_LINK_MAP_FORMAT));
		}
		link_map_file.Open (Project_Filename (key));
		link_map_flag = true;
	}

	//---- get minimum volume ----
	
	minimum_volume = Get_Control_Double (MINIMUM_LINK_VOLUME);

	//---- person-based statistics ----

	person_flag = Get_Control_Flag (PERSON_BASED_STATISTICS);

	//---- get the select by link group flag ----

	group_select = Get_Control_Flag (SELECT_BY_LINK_GROUP);
	if (group_select || select_subareas || select_polygon || select_facilities) select_flag = true;

	//---- turning movement data ----

	if (turn_flag) {

		//---- open the compare turn delays file ----
	
		key = Get_Control_String (COMPARE_TURN_DELAY_FILE);

		if (!key.empty ()) {
			turn_compare_file.File_Type ("Compare Turn Delay File");
			Print (1);

			if (Check_Control_Key (COMPARE_TURN_DELAY_FORMAT)) {
				turn_compare_file.Dbase_Format (Get_Control_String (COMPARE_TURN_DELAY_FORMAT));
			}
			turn_compare_file.Open (Project_Filename (key));
			turn_compare_flag = true;
		}

		//---- select turn nodes----
	
		key = exe->Get_Control_Text (TURN_NODE_RANGE);

		if (!key.empty () && !key.Equals ("ALL")) {
			if (!turn_range.Add_Ranges (key)) {
				exe->Error ("Adding Turn Node Ranges");
			}
		}
	}

	//---- create link activity file ----

	key = Get_Control_String (NEW_LINK_ACTIVITY_FILE);

	if (!key.empty ()) {
		if (!System_File_Flag (LOCATION)) {
			Error ("A Location File is needed for the Link Activity File");
		}
		location_file = System_Location_File ();
		binary = (location_file->Record_Format () == BINARY);

		Print (1);
		activity_file.File_Type ("New Link Activity File");

		if (Check_Control_Key (NEW_LINK_ACTIVITY_FORMAT)) {
			activity_file.Dbase_Format (Get_Control_String (NEW_LINK_ACTIVITY_FORMAT));
		}
		activity_file.Create (Project_Filename (key));

		//---- copy location field name ----

		key = Get_Control_Text (COPY_LOCATION_FIELDS);
		if (key.empty ()) {
			Error ("Location Field Names are Required for Link Activity File");
		}
		link_db.File_Type ("Link Location Database");

		//---- set required fields ----

		link_db.Add_Field ("LINK", DB_INTEGER, 10);
		activity_file.Add_Field ("LINK", DB_INTEGER, 10);

		//---- copy selected fields ----

		while (!key.Split (token)) {
			field = location_file->Field_Number (token);
			if (field < 0) {
				Error (String ("Field %s was Not Found in the Location File") % token);
			}
			field_list.push_back (field);

			fld = location_file->Field (field);

			link_db.Add_Field (fld->Name (), fld->Type (), fld->Size (), fld->Units (), binary);
			activity_file.Add_Field (fld->Name (), fld->Type (), fld->Size (), fld->Units (), binary);
		}
		activity_file.Write_Header ();
		activity_flag = true;
	}

	//---- create zone travel file ----

	key = Get_Control_String (NEW_ZONE_TRAVEL_FILE);

	if (!key.empty ()) {
		if (!System_File_Flag (LOCATION)) {
			Error ("A Location File is needed for the Zone Travel File");
		}
		Print (1);
		zone_file.File_Type ("New Zone Travel File");

		if (Check_Control_Key (NEW_ZONE_TRAVEL_FORMAT)) {
			zone_file.Dbase_Format (Get_Control_String (NEW_ZONE_TRAVEL_FORMAT));
		}
		zone_file.Create (Project_Filename (key));
		zone_flag = true;
	}

	//---- create zone group travel file ----

	key = Get_Control_String (NEW_GROUP_TRAVEL_FILE);

	if (!key.empty ()) {
		if (!System_File_Flag (LOCATION)) {
			Error ("A Location File is needed for the Group Travel File");
		}
		Print (1);
		group_file.File_Type ("New Group Travel File");

		if (Check_Control_Key (NEW_GROUP_TRAVEL_FORMAT)) {
			group_file.Dbase_Format (Get_Control_String (NEW_GROUP_TRAVEL_FORMAT));
		}
		group_file.Create (Project_Filename (key));
		group_flag = true;
	}

	if (!activity_flag && !zone_flag && !group_flag) {
		System_File_False (LOCATION);
	}

	//---- get the number of direction groups ----

	ngroup = Highest_Control_Group (NEW_LINK_DIRECTION_FILE, 0);

	if (ngroup > 0) {
		Dir_Group group, *group_ptr;

		//---- process each group ----

		for (i=1; i <= ngroup; i++) {
			key = Get_Control_String (NEW_LINK_DIRECTION_FILE, i);
			if (key.empty ()) continue;

			Print (1);
			dir_group.push_back (group);
			group_ptr = &dir_group.back ();

			group_ptr->group = i;
			group_ptr->file = new Link_Direction_File ();
			group_ptr->file->File_Type (String ("New Link Direction File #%d") % i);

			if (Check_Control_Key (NEW_LINK_DIRECTION_FORMAT, i)) {
				group_ptr->file->Dbase_Format (Get_Control_String (NEW_LINK_DIRECTION_FORMAT, i));
			}
			group_ptr->file->Lane_Use_Flows (Lane_Use_Flows ());
			group_ptr->file->Create (Project_Filename (key));

			//---- get the field name ----

			key = Get_Control_Text (NEW_LINK_DIRECTION_FIELD, i);
			if (key.empty ()) {
				Error (String ("New Link Direction Field #%d is Missing") % i);
			}
			group_ptr->field = Performance_Code (key);

			group_ptr->index = Get_Control_Flag (NEW_LINK_DIRECTION_INDEX, i);
			
			group_ptr->flip = Get_Control_Flag (NEW_LINK_DIRECTION_FLIP, i);

			if (group_ptr->flip && !compare_flag) {
				Warning ("Link Direction Flipping requires Comparison Data");
				group_ptr->flip = false;
			}
			Set_Link_Dir (group_ptr);
		}
	}

	//---- get the number of groups ----

	ngroup = Highest_Control_Group (NEW_LINK_DATA_FILE, 0);

	if (ngroup > 0) {
		Data_Group group, *group_ptr;

		//---- process each group ----

		for (i=1; i <= ngroup; i++) {
			key = Get_Control_String (NEW_LINK_DATA_FILE, i);
			if (key.empty ()) continue;

			Print (1);
			data_group.push_back (group);
			group_ptr = &data_group.back ();

			group_ptr->group = i;
			group_ptr->file = new Link_Data_File ();
			group_ptr->file->File_Type (String ("New Link Data File #%d") % i);

			if (Check_Control_Key (NEW_LINK_DATA_FORMAT, i)) {
				group_ptr->file->Dbase_Format (Get_Control_String (NEW_LINK_DATA_FORMAT, i));
			}
			group_ptr->file->Lane_Use_Flows (Lane_Use_Flows ());
			group_ptr->file->Create (Project_Filename (key));

			//---- get the field name ----

			key = Get_Control_Text (NEW_LINK_DATA_FIELD, i);
			if (key.empty ()) {
				Error (String ("New Link Data Field #%d is Missing") % i);
			}
			group_ptr->field = Performance_Code (key);

			Set_Link_Data (group_ptr);
		}
	}

	//---- data summary file ----

	key = Get_Control_String (NEW_DATA_SUMMARY_FILE);

	if (!key.empty ()) {
		Print (1);
		summary_file.File_Type ("New Data Summary File");

		if (Check_Control_Key (NEW_DATA_SUMMARY_FORMAT)) {
			summary_file.Dbase_Format (Get_Control_String (NEW_DATA_SUMMARY_FORMAT));
		}
		summary_file.Add_Field ("MEASURE", DB_STRING, 40);
		summary_file.Add_Field ("VALUE", DB_DOUBLE, 12.2);
		if (compare_flag) summary_file.Add_Field ("COMPARE", DB_DOUBLE, 12.2);

		summary_file.Create (Project_Filename (key));
		summary_flag = true;

		//---- data summary periods ----

		if (!Control_Key_Empty (NEW_DATA_SUMMARY_PERIODS)) {
			periods_flag = data_periods.Add_Ranges (Get_Control_Text (NEW_DATA_SUMMARY_PERIODS));
		}

		//---- data summary ratios ----

		if (Check_Control_Key (NEW_DATA_SUMMARY_RATIOS)) {
			Double_List list;
			Dbl_Itr itr;

			Get_Control_List (NEW_DATA_SUMMARY_RATIOS, list);

			for (i=0, itr = list.begin (); itr != list.end (); itr++, i++) {
				if (i > 0 && *itr >= 1.0) {
					data_ratios.push_back (Round (*itr * 100.0));
					ratios_flag = true;
				}
			}
		}
	}

	//---- group summary file ----

	key = Get_Control_String (NEW_GROUP_SUMMARY_FILE);

	if (!key.empty ()) {
		Print (1);
		group_sum_file.File_Type ("New Group Summary File");

		if (Check_Control_Key (NEW_GROUP_SUMMARY_FORMAT)) {
			group_sum_file.Dbase_Format (Get_Control_String (NEW_GROUP_SUMMARY_FORMAT));
		}
		group_sum_file.Add_Field ("MEASURE", DB_STRING, 40);
		group_sum_file.Add_Field ("VALUE", DB_DOUBLE, 12.2);
		if (compare_flag) group_sum_file.Add_Field ("COMPARE", DB_DOUBLE, 12.2);

		group_sum_file.Create (Project_Filename (key));
		group_sum_flag = true;
	}

	//---- read report types ----

	List_Reports ();

	if (!compare_flag && (Report_Flag (TIME_CHANGE) || Report_Flag (VOLUME_CHANGE) ||
		Report_Flag (TOP_TIME_CHANGE) || Report_Flag (TOP_VOL_CHANGE) || Report_Flag (RELATIVE_GAP))) {

		Error ("A Compare Performance File is Required for Change Reports");
	}

	//---- process support data ----

	if (Link_Equiv_Flag ()) {
		link_equiv.Read (Report_Flag (LINK_EQUIV));
	}

	if (group_flag) {
		zone_equiv.Read (Report_Flag (ZONE_EQUIV));
	}

	//---- allocate work space ----

	if (periods_flag || ratios_flag) {
		num = (periods_flag) ? (int) data_periods.size () : 1;
		num += (ratios_flag) ? (int) data_ratios.size () : 1;
		if (num_inc + 1 > num) {
			num = num_inc + 1;
		}
	} else {
		num = num_inc + 1;
	}
	sum_bin.assign (num, dbl);

	for (itr = sum_bin.begin (); itr != sum_bin.end (); itr++) {
		itr->assign (NUM_SUM_BINS, 0.0);
	}
} 
示例#2
0
void ZoneData::Program_Control (void)
{
	int i, size, num, decimal, existing;
	char *str_ptr, *format_ptr, name [FIELD_BUFFER], buffer [FIELD_BUFFER];
	Db_Code::Field_Type type;

	Db_Header *file;

	//---- open network files ----

	Network_Service::Program_Control ();

	input_file = (Zone_File *) Network_Db_File (ZONE);
	input_file->File_ID ("In");

	output_file = (Zone_File *) Network_Db_File (NEW_ZONE);
	output_file->File_ID ("Out");

	//---- copy existing fields ----

	str_ptr = Get_Control_String (COPY_EXISTING_FIELDS);

	if (str_ptr != NULL) {
		Print (2, "Copy Existing Fields = %s", str_ptr);

		copy_flag = Get_Control_Flag (COPY_EXISTING_FIELDS);

		if (copy_flag) {
			output_file->Clear_Fields ();
			output_file->Replicate_Fields (input_file, false);
		}
	}

	//---- get the new zone fields ----

	num = Highest_Control_Group (NEW_ZONE_FIELD_x, 0);

	if (num == 0) {
		if (Get_Control_String (NEW_ZONE_FIELD) != NULL) {
			num = 1;
		}
	} else {
		num++;
	}

	if (num == 0) {
		if (!copy_flag) {
			Warning ("No New Zone Fields");
		}
	} else {
		Print (1);

		for (i=0; i < num; i++) {
			if (i == 0) {
				str_ptr = Get_Control_String (NEW_ZONE_FIELD);
			} else {
				str_ptr = Get_Control_String (NEW_ZONE_FIELD_x, i);
			}
			if (str_ptr == NULL) continue;

			if (i == 0) {
				Print (1, "New Zone Field = %s", str_ptr);
			} else {
				Print (1, "New Zone Field #%d = %s", i, str_ptr);
			}
			str_ptr = Get_Token (str_ptr, name, sizeof (name));
			if (name [0] == '\0') goto data_error;

			existing = output_file->Field_Number (name);
			if (existing != 0) goto field_error;

			str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer));
			if (buffer [0] == '\0' || buffer [0] == 'I') {
				type = INTEGER;
			} else if (buffer [0] == 'R' || buffer [0] == 'D') {
				type = DOUBLE;
			} else if (buffer [0] == 'S' || buffer [0] == 'C') {
				type = STRING;
			} else {
				goto data_error;
			}
			str_ptr = Get_Token (str_ptr, buffer);
			if (buffer [0] == '\0') {
				size = 10;
				if (type == DOUBLE) {
					decimal = 2;
				} else {
					decimal = 0;
				}
			} else {
				size = atoi (buffer);

				if (type == DOUBLE) {
					str_ptr = strchr (buffer, '.');
					if (str_ptr != NULL) {
						decimal = atoi (str_ptr+1);
					} else {
						decimal = 2;
					}
				} else {
					decimal = 0;
				}
			}
			output_file->Add_Field (name, type, size, decimal);
		}
	}
	if (copy_flag && output_file->Notes_Flag ()) {
		if (output_file->Field_Number ("NOTES") == 0) {
			output_file->Add_Field ("NOTES", STRING, FIELD_BUFFER);
		}
	}
	output_file->Write_Header ();
	
	//---- check for data files ----

	num_data_files = Highest_Control_Group (DATA_FILE_x, 0);

	if (num_data_files == 0) {
		if (Get_Control_String (DATA_FILE) != NULL) {
			num_data_files = 1;
		}
	} else {
		num_data_files++;
	}
	if (num_data_files > 0) {
		data_flag = true;
	}

	//---- check for polygon files ----

	num_polygons = Highest_Control_Group (BOUNDARY_POLYGON_x, 0);

	if (num_polygons == 0) {
		if (Get_Control_String (BOUNDARY_POLYGON) != NULL) {
			num_polygons = 1;
		}
	} else {
		num_polygons++;
	}
	if (num_polygons > 0) {
		polygon_flag = true;
	}

	//---- read conversion script ----

	str_ptr = Get_Control_String (CONVERSION_SCRIPT);

	if (str_ptr == NULL) {
		if (data_flag || polygon_flag) {
			Error ("A Convertion Script is needed for Data Processing");
		}
	} else {
		script_flag = true;
		Print (1);
		program_file.File_Type ("Conversion Script");
		program_file.Open (Project_Filename (str_ptr));
		Print (1);
	}

	//---- read data files ----

	if (data_flag) {

		//---- allocate data files ----

		data_files = new Db_Header * [num_data_files];
		data_field = new int [num_data_files];
		zone_field = new int [num_data_files];

		if (data_files == NULL || data_field == NULL || zone_field == NULL) {
			Error ("Insufficient Memory for %d Data Files", num_data_files);
		}
		memset (data_files, '\0', num_data_files * sizeof (Db_Header *));
		memset (data_field, '\0', num_data_files * sizeof (int));
		memset (zone_field, '\0', num_data_files * sizeof (int));

		//---- open each file ----

		for (i=0; i < num_data_files; i++) {
			if (i == 0) {
				str_ptr = Get_Control_String (DATA_FILE);
			} else {
				str_ptr = Get_Control_String (DATA_FILE_x, i);
			}
			if (str_ptr == NULL) continue;

			//---- create a header file and file labels ----

			Print (1);
			data_files [i] = file = new Db_Header ();

			if (i == 0) {
				file->File_Type ("Data File");
				file->File_ID ("Data");
				format_ptr = Get_Control_String (DATA_FORMAT);
			} else {
				str_fmt (buffer, sizeof (buffer), "Data File #%d", i);
				file->File_Type (buffer);

				str_fmt (buffer, sizeof (buffer), "Data%d", i);
				file->File_ID (buffer);

				format_ptr = Get_Control_String (DATA_FORMAT_x, i);
			}

			//---- open the file ----

			if (format_ptr != NULL) {
				file->Dbase_Format (format_ptr);
			}
			file->Open (Project_Filename (str_ptr));

			//---- find the data join field ----

			if (i == 0) {
				str_ptr = Get_Control_String (DATA_JOIN_FIELD);
			} else {
				str_ptr = Get_Control_String (DATA_JOIN_FIELD_x, i);
			}
			if (str_ptr == NULL) goto control_error;

			data_field [i] = file->Field_Number (str_ptr);

			if (data_field [i] == 0) {
				Error ("Data Join Field %s was Not Found", str_ptr);
			}
			if (i == 0) {
				Print (1, "Data Join Field = %s, Number = %d", str_ptr, data_field [i]);
			} else {
				Print (1, "Data Join Field #%d = %s, Number = %d", i, str_ptr, data_field [i]);
			}

			//---- find the zone join field ----

			if (i == 0) {
				str_ptr = Get_Control_String (ZONE_JOIN_FIELD);
			} else {
				str_ptr = Get_Control_String (ZONE_JOIN_FIELD_x, i);
			}
			if (str_ptr == NULL) goto control_error;

			zone_field [i] = input_file->Field_Number (str_ptr);

			if (zone_field [i] == 0) {
				Error ("Zone Join Field %s was Not Found", str_ptr);
			}
			if (i == 0) {
				Print (1, "Zone Join Field = %s, Number = %d", str_ptr, zone_field [i]);
			} else {
				Print (1, "Zone Join Field #%d = %s, Number = %d", i, str_ptr, zone_field [i]);
			}
		}
	}

	//---- read the boundary polygons ----

	if (polygon_flag) {
		Arcview_File *poly_file;

		projection.Read_Control ();

		//---- allocate data files ----

		polygon_files = new Arcview_File * [num_polygons];
		polygons = new Index_Array * [num_polygons];
		polygon_db = new Db_Index_Array * [num_polygons];

		if (polygon_files == NULL || polygons == NULL || polygon_db == NULL) {
			Error ("Insufficient Memory for %d Polygon Files", num_polygons);
		}
		memset (polygon_files, '\0', num_polygons * sizeof (Arcview_File *));
		memset (polygons, '\0', num_polygons * sizeof (Index_Array *));
		memset (polygon_db, '\0', num_polygons * sizeof (Db_Index_Array *));

		//---- open each file ----

		for (i=0; i < num_polygons; i++) {
			if (i == 0) {
				str_ptr = Get_Control_String (BOUNDARY_POLYGON);
			} else {
				str_ptr = Get_Control_String (BOUNDARY_POLYGON_x, i);
			}
			if (str_ptr == NULL) continue;

			//---- open the file ----

			polygon_files [i] = poly_file = new Arcview_File ();
			polygons [i] = new Index_Array (sizeof (Boundary));

			poly_file->Set_Projection (projection.Input_Projection (), projection.Output_Projection ());

			Print (1);
			if (i == 0) {
				poly_file->File_Type ("Boundary Polygon File");
				poly_file->File_ID ("Polygon");
			} else {
				str_fmt (buffer, sizeof (buffer), "Boundary Polygon File #%d", i);
				poly_file->File_Type (buffer);

				str_fmt (buffer, sizeof (buffer), "Polygon%d", i);
				poly_file->File_ID (buffer);
			}
			poly_file->Open (Project_Filename (str_ptr));
		}
	}
	Show_Message (1);
	return;

control_error:
	Error ("Missing Control Key = %s", Current_Key ());

data_error:
	Error ("New Zone Field %d is Improperly Specified", i);

field_error:
	Error ("New Zone Field %s already exists as Field %d", name, existing);
}
示例#3
0
void ZoneData::Program_Control (void)
{
    int i, j, num, field;
    double size;
    bool flag;
    String key, name, buf;
    Field_Type type;

    Data_Group data_rec;
    Data_Itr data_itr;
    Polygon_Group poly_rec;
    Polygon_Itr poly_itr;
    Sum_Distance sum_rec;
    Sum_Itr sum_itr;
    Field_Ptr fld_ptr;

    field = 0;

    //---- open network files ----

    Data_Service::Program_Control ();

    input_file = (Zone_File *) System_File_Handle (ZONE);

    output_file = (Zone_File *) System_File_Handle (NEW_ZONE);

    flag = exe->Notes_Name_Flag ();
    exe->Notes_Name_Flag (false);

    output_file->Clear_Fields ();

    Print (2, String ("%s Control Keys:") % Program ());

    //---- copy existing fields ----

    copy_flag = Get_Control_Flag (COPY_EXISTING_FIELDS);

    if (copy_flag) {
        output_file->Replicate_Fields (input_file, false);
    } else if (Get_Control_Flag (CLEAR_ALL_FIELDS)) {
        output_file->Clear_Fields ();
    } else {
        output_file->Create_Fields ();
    }
    exe->Notes_Name_Flag (flag);

    if (Check_Control_Key (ZONE_FILE_HEADER)) {
        if (Get_Control_Flag (ZONE_FILE_HEADER)) {
            output_file->Header_Lines (1);
        } else {
            output_file->Header_Lines (0);
        }
    }

    //---- get the new zone fields ----

    num = Highest_Control_Group (NEW_ZONE_FIELD, 0);

    if (num == 0) {
        if (!copy_flag) {
            Warning ("No New Zone Fields");
        }
    } else {
        Print (1);

        for (i=1; i <= num; i++) {
            key = Get_Control_Text (NEW_ZONE_FIELD, i);
            if (key.empty ()) continue;

            key.Split (name, ",");
            if (name.empty ()) goto data_error;

            field = output_file->Field_Number (name);
            if (field >= 0) goto field_error;

            key.Split (buf, ",");
            if (buf.empty () || buf.Starts_With ("I")) {
                type = DB_INTEGER;
            } else if (buf.Starts_With ("D") || buf.Starts_With ("R")) {
                type = DB_DOUBLE;
            } else if (buf.Starts_With ("S") || buf.Starts_With ("C")) {
                type = DB_STRING;
            } else {
                goto data_error;
            }

            key.Split (buf, ",");
            if (buf.empty ()) {
                if (type == DB_DOUBLE) {
                    size = 10.2;
                } else {
                    size = 10.0;
                }
            } else {
                size = buf.Double ();
            }
            output_file->Add_Field (name, type, size);
        }
    }
    if (exe->Notes_Name_Flag ()) {
        if (output_file->Field_Number ("NOTES") < 0) {
            output_file->Add_Field ("NOTES", DB_STRING, STRING_FIELD_SIZE);
        }
    }
    output_file->Write_Header ();

    //---- check for data files ----

    num_data_files = Highest_Control_Group (DATA_FILE, 0);

    if (num_data_files > 0) {
        data_flag = true;
    }

    //---- check for polygon files ----

    num_polygons = Highest_Control_Group (BOUNDARY_POLYGON_FILE, 0);

    if (num_polygons > 0) {
        polygon_flag = true;
    }

    //---- check for sum distances ----

    num_sum_distance = Highest_Control_Group (SUM_ATTRIBUTE_DISTANCE, 0);

    if (num_sum_distance > 0) {
        sum_flag = true;
    }

    //---- read conversion script ----

    key = Get_Control_String (CONVERSION_SCRIPT);

    if (key.empty ()) {
        if (data_flag || sum_flag || polygon_flag) {
            Error ("A Convertion Script is needed for Data Processing");
        }
    } else {
        script_flag = true;
        Print (1);
        program_file.File_Type ("Conversion Script");
        program_file.Open (Project_Filename (key));
        Print (1);
    }

    //---- read data files ----

    if (data_flag) {

        //---- open each file ----

        for (i=1; i <= num_data_files; i++) {
            key = Get_Control_String (DATA_FILE, i);
            if (key.empty ()) continue;

            //---- create a header file and file labels ----

            Print (1);

            data_group.push_back (data_rec);
            data_itr = --data_group.end ();

            data_itr->group = i;
            data_itr->file = new Db_Header ();
            data_itr->data_db = new Db_Sort_Array ();

            data_itr->file->File_Type (String ("Data File #%d") % i);
            data_itr->file->File_ID (String ("Data%d") % i);

            if (Check_Control_Key (DATA_FORMAT, i)) {
                data_itr->file->Dbase_Format (Get_Control_String (DATA_FORMAT, i));
            }
            data_itr->file->Open (Project_Filename (key));

            //---- find the data join field ----

            key = Get_Control_Text (DATA_JOIN_FIELD, i);
            if (key.empty ()) goto control_error;

            field = data_itr->file->Field_Number (key);

            if (field < 0) {
                Error (String ("Data Join Field %s was Not Found") % key);
            }
            data_itr->join_field = field;
            Print (0, ", Number = ") << (field + 1);

            //---- find the zone join field ----

            key = Get_Control_Text (ZONE_JOIN_FIELD, i);
            if (key.empty ()) goto control_error;

            field = input_file->Field_Number (key);
            if (field < 0) {
                Error (String ("Zone Join Field %s was Not Found") % key);
            }
            data_itr->zone_field = field;
            Print (0, ", Number = ") << (field + 1);
        }
    }

    //---- read the projection information ----

    if (polygon_flag) {
        projection.Read_Control ();
    }

    //---- read the boundary polygons ----

    if (polygon_flag) {
        if (!script_flag) {
            Error ("Boundary Polygon processing Requires a Conversion Script");
        }

        //---- open each file ----

        for (i=1; i <= num_polygons; i++) {
            key = Get_Control_String (BOUNDARY_POLYGON_FILE, i);
            if (key.empty ()) continue;

            polygons.push_back (poly_rec);

            poly_itr = --polygons.end ();

            poly_itr->group = i;
            poly_itr->file = new Arcview_File ();
            poly_itr->data_db = new Db_Sort_Array ();
            poly_itr->file->Set_Projection (projection.Input_Projection (), projection.Output_Projection ());

            Print (1);
            poly_itr->file->File_Type (String ("Boundary Polygon File #%d") % i);
            poly_itr->file->File_ID (String ("Polygon%d") % i);

            poly_itr->file->Open (Project_Filename (key));
        }
    }

    //---- read sum distances ----

    if (sum_flag) {

        //---- open each group ----

        num = input_file->Num_Fields ();

        for (i=1; i <= num_sum_distance; i++) {
            if (!Check_Control_Key (SUM_ATTRIBUTE_DISTANCE, i)) continue;

            //---- create a header file and file labels ----

            Print (1);

            sum_group.push_back (sum_rec);
            sum_itr = --sum_group.end ();

            sum_itr->group = i;
            sum_itr->distance = Round (Get_Control_Double (SUM_ATTRIBUTE_DISTANCE, i));
            sum_itr->data_db = new Db_Sort_Array ();

            field = input_file->Zone_Field ();
            fld_ptr = input_file->Field (field);

            sum_itr->data_db->File_Type (String ("Sum Attribute Distance #%d") % i);
            sum_itr->data_db->File_ID (String ("SumZone%d") % i);

            sum_itr->data_db->Add_Field (fld_ptr->Name (), DB_INTEGER, 10);
            sum_itr->data_db->Add_Field ("Z_COUNT", DB_INTEGER, 10);

            sum_itr->field_map.push_back (field);
            sum_itr->field_map.push_back (-1);

            for (j=0; j < num; j++) {
                if (j == field) continue;
                fld_ptr = input_file->Field (j);

                if (fld_ptr->Type () == DB_INTEGER || fld_ptr->Type () == DB_DOUBLE) {
                    sum_itr->field_map.push_back (j);
                    sum_itr->data_db->Add_Field (fld_ptr->Name (), DB_DOUBLE, sizeof (double), NO_UNITS, true);
                }
            }
        }
    }
    Show_Message (1);
    return;

control_error:
    Error (String ("Missing Control Key = %s") % Current_Key ());

data_error:
    Error (String ("New Zone Field %d is Improperly Specified") % i);

field_error:
    Error (String ("New Zone Field %s already exists as Field %d") % name % field);
}
示例#4
0
void ConvertTours::Program_Control (void)
{
	int i, j, num_file, lvalue;
	double dvalue;
	bool factor_flag;
	char *str_ptr, buffer [FIELD_BUFFER], *format_ptr;

	File_Group *group;

	char *time_control [] = {"ORIGIN", "DESTINATION", "MID-TRIP", NULL};

	factor_flag = false;

	//---- open demand and network files ----

	Demand_Service::Program_Control ();

	//---- set the file points ----

	zone_flag = Network_File_Flag (ZONE);

	trip_file = (Trip_File *) Demand_Db_Base (NEW_TRIP);
	household_file = (Household_File *) Demand_Db_Base (NEW_HOUSEHOLD);
	population_file = (Population_File *) Demand_Db_Base (NEW_POPULATION);
	vehicle_file = (Vehicle_File *) Demand_Db_Base (NEW_VEHICLE);

	//---- check for copy commands ----

	if (Demand_File_Flag (TRIP)) {
		trip_file->Clear_Fields ();
		trip_file->Replicate_Fields (Demand_Db_Base (TRIP));
		trip_file->Write_Header ();
	}
	if (Demand_File_Flag (HOUSEHOLD)) {
		household_file->Clear_Fields ();
		household_file->Replicate_Fields (Demand_Db_Base (HOUSEHOLD));
		household_file->Write_Header ();
	}
	if (Demand_File_Flag (POPULATION)) {
		population_file->Clear_Fields ();
		population_file->Replicate_Fields (Demand_Db_Base (POPULATION));
		population_file->Write_Header ();
	}
	if (Demand_File_Flag (VEHICLE)) {
		vehicle_file->Clear_Fields ();
		vehicle_file->Replicate_Fields (Demand_Db_Base (VEHICLE));
		vehicle_file->Write_Header ();
	}

	//---- get the tour data file ----

	str_ptr = Get_Control_String (TOUR_DATA_FILE);

	if (str_ptr == NULL) goto control_error;

	Print (1);
	format_ptr = Get_Control_String (TOUR_DATA_FORMAT);

	if (format_ptr != NULL) {
		tour_file.Dbase_Format (format_ptr);
	}
	tour_file.Open (Project_Filename (str_ptr));

	tour_file_db.Add_Field ("SORTKEY", INTEGER, 10);

	tour_file_db.Replicate_Fields (&tour_file, true);
	tour_file_db.File_ID ("Tour");

	//---- set tour field numbers ----

	Print (1);

	str_ptr = Get_Control_String (TOUR_HOUSEHOLD_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.HHold_Field (str_ptr);
	} else {
		lvalue = tour_file.HHold_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Household Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}
	str_ptr = Get_Control_String (TOUR_PERSON_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.Person_Field (str_ptr);
	} else {
		lvalue = tour_file.Person_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Person Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}
	str_ptr = Get_Control_String (TOUR_NUMBER_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.Tour_Field (str_ptr);
	} else {
		lvalue = tour_file.Tour_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Number Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}
	str_ptr = Get_Control_String (TOUR_PURPOSE_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.Purpose_Field (str_ptr);
	} else {
		lvalue = tour_file.Purpose_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Purpose Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}
	str_ptr = Get_Control_String (TOUR_MODE_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.Mode_Field (str_ptr);
	} else {
		lvalue = tour_file.Mode_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Mode Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}
	str_ptr = Get_Control_String (TOUR_ORIGIN_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.Origin_Field (str_ptr);
	} else {
		lvalue = tour_file.Origin_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Origin Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}
	str_ptr = Get_Control_String (TOUR_DESTINATION_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.Dest_Field (str_ptr);
	} else {
		lvalue = tour_file.Dest_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Destination Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}
	str_ptr = Get_Control_String (TOUR_STOP_OUT_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.Stop_Out_Field (str_ptr);
	} else {
		lvalue = tour_file.Stop_Out_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Stop Out Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}
	str_ptr = Get_Control_String (TOUR_STOP_IN_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.Stop_In_Field (str_ptr);
	} else {
		lvalue = tour_file.Stop_In_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Stop In Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}
	str_ptr = Get_Control_String (TOUR_START_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.Start_Field (str_ptr);
	} else {
		lvalue = tour_file.Start_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Start Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}	
	str_ptr = Get_Control_String (TOUR_RETURN_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.Return_Field (str_ptr);
	} else {
		lvalue = tour_file.Return_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Return Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}
	str_ptr = Get_Control_String (TOUR_GROUP_FIELD);
	if (str_ptr != NULL) {
		lvalue = tour_file.Group_Field (str_ptr);
	} else {
		lvalue = tour_file.Group_Field ();
	}
	if (lvalue > 0) {
		Print (1, "Tour Group Field = %s, Number = %d", tour_file.Field (lvalue)->Name (), lvalue);
	}

	//---- get the tour group script -----

	str_ptr = Get_Control_String (TOUR_GROUP_SCRIPT);

	if (str_ptr != NULL) {
		script_file.File_Type ("Tour Group Script");

		script_file.Open (Project_Filename (str_ptr));
		script_flag = true;
	}

	//---- get the household list file -----

	str_ptr = Get_Control_String (HOUSEHOLD_LIST);

	if (str_ptr != NULL) {
		hhlist_file.File_Type ("Household List File");

		hhlist_file.Open (Project_Filename (str_ptr));
		hhlist_flag = true;
	}

	//---- get the starting hhold id ----
	
	str_ptr = Get_Control_String (STARTING_HOUSEHOLD_ID);

	if (str_ptr != NULL) {
		Get_Integer (str_ptr, &hhold_id);
		if (hhold_id < 1) {
			Error ("Starting Household ID %d is Out of Range", hhold_id);
		}
	} else {
		hhold_id = 1;
	}
    Print (2, "Starting Household ID = %d", hhold_id);

	//---- get the starting vehicle id ----
	
	str_ptr = Get_Control_String (STARTING_VEHICLE_ID);

	if (str_ptr != NULL) {
		Get_Integer (str_ptr, &vehicle_id);
		if (vehicle_id < 1) {
			Error ("Starting Vehicle ID %d is Out of Range", vehicle_id);
		}
	} else {
		vehicle_id = 1;
	}
	Print (1, "Starting Vehicle ID = %d", vehicle_id);

	//---- get the time of day format ----
	
	str_ptr = Get_Control_String (TIME_OF_DAY_FORMAT);

	if (str_ptr == NULL) {
		str_ptr = "24_HOUR_CLOCK";
	}
	if (!trip_time.Format (str_ptr)) {
		Error ("Time of Day Format %s was Unrecognized", str_ptr);
	}
	Print (2, "Time of Day Format = %s", str_ptr);

	//---- get the additional travel time ----
	
	str_ptr = Get_Control_String (ADDITIONAL_TRAVEL_TIME);

	if (str_ptr != NULL) {
		Get_Integer (str_ptr, &additional_time);

		if (additional_time < 0) {
			Error ("Additional Travel Time %d is Out of Range", additional_time);
		}
	}
	Print (2, "Additional Travel Time = %d seconds", additional_time);

	//---- open the zone location map ----

	str_ptr = Get_Control_String (ZONE_LOCATION_MAP_FILE);

	if (str_ptr != NULL) {
		zone_loc_flag = true;
		Print (1);

		zone_loc_map.Open (Project_Filename (str_ptr));
	}

	//---- random number seed ----

	str_ptr = Get_Control_String (RANDOM_NUMBER_SEED);

	if (str_ptr != NULL) {
		random_org.Seed (atoi (str_ptr));
	}
	Print (2, "Random Number Seed = %d", random_org.Seed ());
	
	random_des.Seed (random_org.Seed () + 1);
	random_tod.Seed (random_org.Seed () + 2);
	random_stop.Seed (random_org.Seed () + 3);

	//---- open the zone equivalence ----

	str_ptr = Get_Control_String (ZONE_EQUIVALENCE_FILE);

	if (str_ptr != NULL) {
		equiv_flag = true;
		Print (1);

		zone_equiv.Open (Project_Filename (str_ptr));
	}

	//---- open the travel time skim ----

	str_ptr = Get_Control_String (TRAVEL_TIME_FILE);

	if (str_ptr != NULL) {
		skim_flag = true;
		Print (1);

		skim_file.Open (Project_Filename (str_ptr));
	}

	//---- open the diurnal allocation file ----

	str_ptr = Get_Control_String (NEW_DIURNAL_FILE);

	if (str_ptr != NULL) {
		diurnal_flag = true;
		diurnal_file.File_Type ("New Diurnal File");
		Print (1);

		diurnal_file.Create (Project_Filename (str_ptr));
	}

	//---- write the report names ----

	List_Reports ();

	//---- get the number of files ----

	num_file = Highest_Control_Group (TRIP_TIME_FILE_x, 0);

	if (num_file == 0) {
		Error ("No Trip Time Files were Found");
	}

	//---- allocate file space ----

	if (!file_group.Max_Records (num_file)) {
		Error ("Insufficient Memory for %d File Groups", num_file);
	}

	//---- process each file ----

	for (i=1; i <= num_file; i++) {

		//---- get the trip time file ----

		str_ptr = Get_Control_String (TRIP_TIME_FILE_x, i);

		if (!Break_Check (15)) {
			Print (1);
		}
		if (str_ptr == NULL) continue;

		group = file_group.New_Record (true);

		group->Group (i);

		group->Time_File (new Diurnal_File ());

		str_fmt (buffer, sizeof (buffer), "Trip Time File #%d", i);

		group->Time_File ()->File_Type (buffer);

		format_ptr = Get_Control_String (TRIP_TIME_FORMAT_x, i);

		if (format_ptr != NULL) {
			group->Time_File ()->Dbase_Format (format_ptr);
		}
		group->Time_File ()->Open (Project_Filename (str_ptr));

		//---- get the trip time field ----

		if (!script_flag) {
			str_ptr = Get_Control_String (TRIP_TIME_FIELD_x, i);

			if (str_ptr != NULL) {
				if (!group->Time_Field (str_ptr)) {
					Error ("Trip Time Field %s was Not Found", str_ptr);
				}
				Print (1, "Trip Time Field Name = %s, Number = %d", str_ptr, group->Time_Field ());
			}
		}

		//---- get the time period range ----

		str_ptr = Get_Control_String (TIME_PERIOD_RANGE_x, i);

		if (str_ptr != NULL) {
			Print (1, "Time Period Range = %s", str_ptr);

			if (!group->Time_Periods (str_ptr)) {
				Error ("Time Period Range %s is Illogical", str_ptr);
			}
		}

		//---- get the time control point ----

		str_ptr = Get_Control_String (TIME_CONTROL_POINT_x, i);

		if (str_ptr != NULL) {
			for (j=0; time_control [j] != NULL; j++) {
				if (str_cmp (str_ptr, time_control [j]) == 0) break;
			}
			if (time_control [j] == NULL) {
				Error ("Time Control Point %s was Unrecognized", str_ptr);
			}
			group->Method (j);
		} else {
			group->Method (0);
		}
		Print (1, "Time Control Point = %s", time_control [group->Method ()]);

		//---- get the origin weight ----

		str_ptr = Get_Control_String (ORIGIN_WEIGHT_FIELD_x, i);

		if (str_ptr != NULL) {
			group->Org_Wt (Network_Db_Base (ACTIVITY_LOCATION)->Field_Number (str_ptr));

			if (group->Org_Wt () == 0) {
				Error ("Origin Weight Field %s was Not Found in the Activity Location File", str_ptr);
			}
			Print (1, "Origin Weight Field Name = %s, Number = %d", str_ptr, group->Org_Wt ());
		} else {
			group->Org_Wt (0);
			Print (1, "No Origin Weight Field --> Equal Weights");
		}

		//---- get the destination weight ----

		str_ptr = Get_Control_String (DESTINATION_WEIGHT_FIELD_x, i);

		if (str_ptr != NULL) {
			group->Des_Wt (Network_Db_Base (ACTIVITY_LOCATION)->Field_Number (str_ptr));

			if (group->Des_Wt () == 0) {
				Error ("Destination Weight Field %s was Not Found in the Activity Location File", str_ptr);
			}
			Print (1, "Destination Weight Field Name = %s, Number = %d", str_ptr, group->Des_Wt ());
		} else {
			group->Des_Wt (0);
			Print (1, "No Destination Weight Field --> Equal Weights");
		}

		//---- get the distance weight ----

		str_ptr = Get_Control_String (DISTANCE_WEIGHT_FLAG_x, i);

		if (str_ptr != NULL) {
			group->Dist_Wt (Get_Control_Flag (DISTANCE_WEIGHT_FLAG_x, i));

			Print (1, "Distance Weight Flag = %s", str_ptr);
		} else {
			group->Dist_Wt (true);
		}

		//---- get the stop weight ----

		str_ptr = Get_Control_String (STOP_WEIGHT_FIELD_x, i);

		if (str_ptr != NULL) {
			group->Stop_Wt (Network_Db_Base (ACTIVITY_LOCATION)->Field_Number (str_ptr));

			if (group->Stop_Wt () == 0) {
				Error ("Stop Weight Field %s was Not Found in the Activity Location File", str_ptr);
			}
			Print (1, "Stop Weight Field Name = %s, Number = %d", str_ptr, group->Stop_Wt ());
		} else {
			group->Stop_Wt (0);
			Print (1, "No Stop Weight Field --> Equal Weights");
		}

		//---- get the trip purpose ----

		str_ptr = Get_Control_String (TRIP_PURPOSE_CODE_x, i);

		if (str_ptr != NULL) {
			Get_Integer (str_ptr, &lvalue);
			
			if (lvalue < 0 || lvalue > 100) {
				Error ("Trip Purpose %d is Out of Range (0..100)", lvalue);
			}
			group->Purpose (lvalue);
		} else {
			group->Purpose (1);
		}
		Print (1, "Trip Purpose Code = %d", group->Purpose ());

		//---- get the travel mode ----

		str_ptr = Get_Control_String (TRAVEL_MODE_CODE_x, i);

		if (str_ptr != NULL) {
			Get_Integer (str_ptr, &lvalue);

			if (lvalue < 0 || lvalue >= MAX_MODE) {
				Error ("Travel Mode %d is Out of Range (0..%d)", lvalue, MAX_MODE);
			}
			group->Mode (lvalue);
		} else {
			group->Mode (DRIVE_ALONE);
		}
		Print (1, "Travel Mode Code = %d", group->Mode ());

		//---- stop duration ----

		str_ptr = Get_Control_String (TRIP_STOP_DURATION_x, i);

		if (str_ptr != NULL) {
			Get_Integer (str_ptr, &lvalue);

			if (lvalue < 1 || lvalue > 4 * 60) {
				Error ("Trip Stop Duration %d is Out of Range (1..240)", lvalue);
			}
		} else {
			lvalue = 5;
		}
		group->Duration (lvalue * 60);

		//---- average speed ----

		str_ptr = Get_Control_String (AVERAGE_TRAVEL_SPEED_x, i);

		if (str_ptr != NULL) {
			Get_Double (str_ptr, &dvalue);

			if (dvalue < 1.0 || dvalue > 50.0) {
				Error ("Average Travel Speed %.1lf is Out of Range (1..50)", dvalue);
			}
		} else {
			dvalue = 10.0;
		}
		group->Speed (Round (dvalue));

		Print (1, "Average Travel Speed = %.1lf (meters/second)", UnRound (group->Speed ()));

		//---- get the vehicle type ----

		str_ptr = Get_Control_String (VEHICLE_TYPE_x, i);

		if (str_ptr != NULL) {
			Get_Integer (str_ptr, &lvalue);

			if (lvalue < 1 || lvalue > 20) {
				Error ("Vehicle Type %d is Out of Range (1..20)", lvalue);
			}
			group->Type (lvalue);
		} else {
			group->Type (1);
		}

		//---- get the vehicle subtype ----

		str_ptr = Get_Control_String (VEHICLE_SUBTYPE_x, i);

		if (str_ptr != NULL) {
			Get_Integer (str_ptr, &lvalue);

			if (lvalue < 0 || lvalue > 20) {
				Error ("Vehicle Subtype %d is Out of Range (0..20)", lvalue);
			}
			group->SubType (lvalue);
		} else {
			group->SubType (0);
		}
		Print (1, "Vehicle Type = %d, Subtype = %d", group->Type (), group->SubType ());

		//---- get the trip scaling factor ----

		str_ptr = Get_Control_String (TRIP_SCALING_FACTOR_x, i);

		if (str_ptr != NULL) {
			Get_Double (str_ptr, &dvalue);
			
			if (dvalue < 0.001 || dvalue > 100.0) {
				Error ("Trip Scaling Factor %.2lf is Out of Range (0.001..100.0)", dvalue);
			}
			group->Scaling_Factor (dvalue);
			Print (1, "Trip Scaling Factor = %.3lf", dvalue);
		} else {
			group->Scaling_Factor (1.0);
		}

		//---- get the trip adjustment factors ----

		str_ptr = Get_Control_String (TRIP_ADJUSTMENT_FACTORS_x, i);

		if (str_ptr != NULL) {
			group->Trip_Factor (new Factor_File ());

			str_fmt (buffer, sizeof (buffer), "Trip Adjustment Factors #%d", i);

			group->Trip_Factor ()->File_Type (buffer);

			format_ptr = Get_Control_String (TRIP_ADJUSTMENT_FORMAT_x, i);

			if (format_ptr != NULL) {
				group->Trip_Factor ()->Dbase_Format (format_ptr);
			}
			if (!group->Trip_Factor ()->Open (Project_Filename (str_ptr))) {
				Error ("Opening Trip Adjustment Factors #%d", i);
			}
			factor_flag = true;
		}

		//---- time period equivalence ----

		//if (factor_flag || group->Trip_File ()->Period_Flag ()) {

		//	str_ptr = Get_Control_String (TIME_PERIOD_EQUIVALENCE_x, i);

		//	if (str_ptr != NULL) {
		//		if (!group->Time_Equiv_File (Project_Filename (str_ptr))) {
		//			Error ("Opening Time Period Equivalence #%d", i);
		//		}
		//	} else if (group->Trip_File ()->Period_Flag ()) {
		//		Warning ("Trip Table Time Periods will be Ignored");
		//	}
		//}

		//---- set the field map ----

		if (group->Org_Wt () != 0) {
			j = field_map.Get_Index (group->Org_Wt ());

			if (j == 0) {
				field_map.Add (group->Org_Wt ());

				group->Org_Wt (field_map.Record_Index ());
			} else {
				group->Org_Wt (j);
			}
		}
		if (group->Des_Wt () != 0) {
			j = field_map.Get_Index (group->Des_Wt ());

			if (j == 0) {
				field_map.Add (group->Des_Wt ());

				group->Des_Wt (field_map.Record_Index ());
			} else {
				group->Des_Wt (j);
			}
		}

		//---- add the group record to the list ----

		file_group.Add ();
	}
	Write (2, "Highest Trip Group Number = %d", num_file);
	Write (1, "Number of Trip Table Groups = %d", file_group.Num_Records ());

	if (field_map.Num_Records () > 0) {
		Print (2, "Number of Unique Activity Location Weight Fields = %d", field_map.Num_Records ());

		Convert_Location *loc_ptr = (Convert_Location *) location_data.New_Record ();

		loc_ptr->Num_Weight (field_map.Num_Records ());
	}
	Show_Message (1);

	//---- read the zone equiv ----

	if (factor_flag) {
		if (equiv_flag) {
			zone_equiv.Read (Report_Flag (ZONE_EQUIV));
		} else {
			Write (2, "Trip Adjustment Factors are Zone-Based");
		}
	}

	//---- read the zone location map ----

	if (zone_loc_flag) {
		zone_loc_map.Read (false);
	}
	return;

	//---- error message ----

control_error:
	Error ("Missing Control Key = %s", Current_Key ());
}
示例#5
0
void PlanSelect::Program_Control (void)
{
	int i, nsel, lvalue;
	char *str_ptr, buffer [FIELD_BUFFER];
	double dvalue;
	Box box;

	//---- open network files ----

	Demand_Service::Program_Control ();

	//---- open the plan file ----
	
	if (Get_Control_String (NODE_LIST_PATHS) != NULL) {
		type_flag = Get_Control_Flag (NODE_LIST_PATHS);
	}
	str_ptr = Get_Control_String (PLAN_FILE);

	if (str_ptr == NULL) goto control_error;

	str_ptr = Project_Filename (str_ptr, Extension ());

	Print_Filename (2, plan_file.File_Type (), str_ptr);

	plan_file.Filename (str_ptr);

	str_ptr = Get_Control_String (PLAN_FORMAT);

	if (str_ptr != NULL) {
		plan_file.File_Format (str_ptr);
		Print (1, "%s Format = %s", plan_file.File_Type (), str_ptr);
	}
	plan_file.Node_Based_Flag (type_flag);

	if (!plan_file.Open (0)) {
		File_Error ("Opening Plan File", plan_file.Filename ());
	}
	type_flag = plan_file.Node_Based_Flag ();

	//---- node list paths ----

	if (type_flag) {
		Print (1, "Plan File contains Node List Paths");
	} else {
		Print (1, "Plan File contains Link List Paths");
	}

	//---- check for a link delay file ----

	if (Demand_File_Flag (LINK_DELAY)) {
		Delay_File *file = (Delay_File *) Demand_Db_File (LINK_DELAY);

		if (!Network_File_Flag (LINK) || !Network_File_Flag (NODE)) {
			Error ("Link and Node files are Required for Link Delay Processing");
		}
		if (file->Dbase_Format () == VERSION3) {
			turn_flag = false;
			Network_File_False (LANE_CONNECTIVITY);
		} else if (!Network_File_Flag (LANE_CONNECTIVITY)) {
			Warning ("Lane Connectivity is required for Turning Delays");
			Show_Message (1);
			turn_flag = false;
		} else {
			turn_flag = true;
		}
		delay_flag = true;
	} else {
		Network_File_False (LANE_CONNECTIVITY);
	}

	//---- open the population file ----

	str_ptr = Get_Control_String (POPULATION_FILE);

	if (str_ptr != NULL) {
		pop_file.File_Type ("Population File");
		Print (1);

		pop_file.Open (str_ptr);
		pop_flag = true;
	}

	//---- get the household list ----

	str_ptr = Get_Control_String (NEW_HOUSEHOLD_LIST);

	if (str_ptr != NULL) {
		hhlist_file.File_Type ("New Household List");
		hhlist_file.File_Access (CREATE);

		str_ptr = Project_Filename (str_ptr, Extension ());
		hhlist_file.Filename (str_ptr);

		Print_Filename (2, hhlist_file.File_Type (), str_ptr);

		if (!hhlist_file.Open (0)) {
			File_Error ("Opening Household List File", hhlist_file.Filename ());
		}
		if (hhlist_file.Extend () == 0 && plan_file.Extend () != 0) {
			Warning ("Household List File is Not Partitioned");
		}
	} else {
		str_ptr = Get_Control_String (NEW_HOUSEHOLD_RECORD_FILE);

		if (str_ptr == NULL) {
			Error ("A New Household List or Household Record File is Required");
		}
		hhrec_flag = true;
		hhrec_file.File_Access (CREATE);

		str_ptr = Project_Filename (str_ptr, Extension ());
		hhrec_file.Filename (str_ptr);

		Print_Filename (2, hhrec_file.File_Type (), str_ptr);

		str_ptr = Get_Control_String (NEW_HOUSEHOLD_RECORD_FORMAT);

		if (str_ptr != NULL) {
			hhrec_file.Dbase_Format (str_ptr);
			Print (1, "%s Format = %s", hhrec_file.File_Type (), str_ptr);
		}
		if (!hhrec_file.Open (0)) {
			File_Error ("Opening Household Record file", hhrec_file.Filename ());
		}
		if (hhrec_file.Extend () == 0 && plan_file.Extend () != 0) {
			Warning ("Household Record File is Not Partitioned");
		}
	}

	//---- get the select travelers ----
	
	str_ptr = Get_Control_String (SELECT_TRAVELERS);

	if (str_ptr != NULL) {
		Print (2, "Select Traveler IDs = %s", str_ptr);

		if (!travelers.Add_Ranges (str_ptr)) {
			File_Error ("Traveler ID Range", str_ptr);
		}
	}
	
	//---- get the select nodes ----

	nsel = Highest_Control_Group (SELECT_NODES_x, 0);

	if (nsel > 0) {

		nodes.Max_Records (nsel);

		for (i=1; i <= nsel; i++) {
			str_ptr = Get_Control_String (SELECT_NODES_x, i);

			if (str_ptr == NULL) continue;

			Print (2, "Select Nodes for Group #%d = %s", i, str_ptr);

			Data_Range *ptr = new Data_Range ();

			if (!ptr->Add_Ranges (str_ptr)) {
				File_Error ("Path Node Numbers", str_ptr);
			}
			if (!nodes.Add (ptr)) {
				Error ("Adding Node Ranges to the List");
			}
		}
	}
	
	//---- get the select links ----

	nsel = Highest_Control_Group (SELECT_LINKS_x, 0);

	if (nsel > 0) {

		links.Max_Records (nsel);

		for (i=1; i <= nsel; i++) {
			str_ptr = Get_Control_String (SELECT_LINKS_x, i);

			if (str_ptr == NULL) continue;

			Print (2, "Select Links for Group #%d = %s", i, str_ptr);

			Data_Range *ptr = new Data_Range (1, -MAX_INTEGER, MAX_INTEGER, 0);

			if (!ptr->Add_Ranges (str_ptr)) {
				File_Error ("Path Link Numbers", str_ptr);
			}
			if (!links.Add (ptr)) {
				Error ("Adding Link Ranges to the List");
			}
		}
	}

	//---- get the select time periods ----
	
	str_ptr = Get_Control_String (SELECT_TIME_PERIODS);

	if (str_ptr != NULL) {
		Print (2, "Select Time Periods = %s", str_ptr);

		times.Format (Time_Step::HOURS);

		if (!times.Add_Ranges (str_ptr)) {
			File_Error ("Time Period Range", str_ptr);
		}
	}
	
	//---- get the select travel modes ----

	str_ptr = Get_Control_String (SELECT_TRAVEL_MODES);

	if (str_ptr != NULL) {

		Print (2, "Select Travel Modes = %s", str_ptr);

		memset (mode_flag, '\0', sizeof (mode_flag));
		nsel = 0;

		while (str_ptr != NULL) {
			char *old_ptr = str_ptr;

			str_ptr = Get_Integer (str_ptr, &i);

			if (i < 0 || i > DRIVER_MODE || (i == 0 && *old_ptr != '0')) {
				Error ("Selected Travel Mode %s is Out of Range (0..%d)", old_ptr, DRIVER_MODE);
			}
			mode_flag [i] = true;
			nsel++;
		}
		if (nsel == 0) {
			Error ("No Modes were Selected for Processing");
		}
	} else {
		for (i=0; i <= DRIVER_MODE; i++) {
			mode_flag [i] = true;
		}
	}

	//---- get the select facility types ----

	str_ptr = Get_Control_String (SELECT_FACILITY_TYPES);

	if (str_ptr != NULL) {

		Print (2, "Select Facility Types = %s", str_ptr);

		factype_flag = true;
		memset (facility_flag, '\0', sizeof (facility_flag));
		nsel = 0;

		while (str_ptr != NULL) {
			str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer));
			if (buffer [0] == '\0') break;

			i = Facility_Code (buffer);
			facility_flag [i] = true;
			nsel++;
		}
		if (nsel == 0) {
			Error ("No Facility Types were Selected for Processing");
		}
	}

	//---- get the select locations ----
	
	str_ptr = Get_Control_String (SELECT_LOCATIONS);

	if (str_ptr != NULL) {
		Print (2, "Select Activity Locations = %s", str_ptr);

		if (!locations.Add_Ranges (str_ptr)) {
			File_Error ("Activity Location Range", str_ptr);
		}
	}

	//---- get the select parking lots ----
	
	str_ptr = Get_Control_String (SELECT_PARKING_LOTS);

	if (str_ptr != NULL) {
		Print (2, "Select Parking Lots = %s", str_ptr);

		if (!parking_lots.Add_Ranges (str_ptr)) {
			File_Error ("Parking Lot Range", str_ptr);
		}
	}

	//---- get the select transit stops ----
	
	str_ptr = Get_Control_String (SELECT_TRANSIT_STOPS);

	if (str_ptr != NULL) {
		Print (2, "Select Transit Stops = %s", str_ptr);

		if (!transit_stops.Add_Ranges (str_ptr)) {
			File_Error ("Transit Stop Range", str_ptr);
		}
	}

	//---- get the select transit routes ----
	
	str_ptr = Get_Control_String (SELECT_TRANSIT_ROUTES);

	if (str_ptr != NULL) {
		Print (2, "Select Transit Routes = %s", str_ptr);

		if (!transit_routes.Add_Ranges (str_ptr)) {
			File_Error ("Transit Route Range", str_ptr);
		}
	}

	//---- get the select vc ratio ----

	str_ptr = Get_Control_String (SELECT_VC_RATIOS);

	if (str_ptr != NULL) {
		if (!delay_flag) {
			Error ("Select V/C Ratios requires a Link Delay file");
		}
		vc_flag = true;
		Get_Double (str_ptr, &vc_ratio);

		if (vc_ratio < 1.0) {
			Error ("Select V/C Ratios %.2lf is Out of Range (>= 1.0)", vc_ratio);
		}
		Print (2, "Select V/C Ratios >= %.2lf", vc_ratio);
	}

	//---- get the select time ratio ----

	str_ptr = Get_Control_String (SELECT_TIME_RATIOS);

	if (str_ptr != NULL) {
		if (!delay_flag) {
			Error ("Select Travel Time Ratios requires a Link Delay file");
		}
		ratio_flag = true;
		Get_Double (str_ptr, &time_ratio);

		if (time_ratio < 1.0) {
			Error ("Select Time Ratios %.2lf is Out of Range (>= 1.0)", time_ratio);
		}
		Print (2, "Select Time Ratios >= %.2lf", time_ratio);
	}

	//---- get the select coordinates ----

	nsel = Highest_Control_Group (SELECT_COORDINATES_x, 0);

	for (i=0; i <= nsel; i++) {
		if (i == 0) {
			str_ptr = Get_Control_String (SELECT_COORDINATES);
		} else {
			str_ptr = Get_Control_String (SELECT_COORDINATES_x, i);
		}
		if (str_ptr == NULL) continue;

		if (!Network_File_Flag (NODE)) {
			Error ("Select Coordinates requires a Node file");
		}
		coord_flag = true;

		if (i == 0) {
			Print (2, "Select Coordinates = %s", str_ptr);
		} else {
			if (coord_box.Num_Records () == 0) Print (1);

			Print (1, "Select Coordinates #%d = %s", i, str_ptr);
		}
		str_ptr = Get_Double (str_ptr, &dvalue);
		box.x1 = Round (dvalue);

		if (str_ptr == NULL) goto coord_error;

		str_ptr = Get_Double (str_ptr, &dvalue);
		box.y1 = Round (dvalue);

		if (str_ptr == NULL) goto coord_error;

		str_ptr = Get_Double (str_ptr, &dvalue);
		box.x2 = Round (dvalue);

		if (box.x2 < box.x1) {
			lvalue = box.x2;
			box.x2 = box.x1;
			box.x1 = lvalue;
		}
		if (str_ptr == NULL) goto coord_error;

		str_ptr = Get_Double (str_ptr, &dvalue);
		box.y2 = Round (dvalue);

		if (box.y2 < box.y1) {
			lvalue = box.y2;
			box.y2 = box.y1;
			box.y1 = lvalue;
		}
		if (!coord_box.Add (&box)) goto mem_error;
	}

	//---- get the select od coordinates ----

	nsel = Highest_Control_Group (SELECT_OD_COORDINATES_x, 0);

	for (i=0; i <= nsel; i++) {
		if (i == 0) {
			str_ptr = Get_Control_String (SELECT_OD_COORDINATES);
		} else {
			str_ptr = Get_Control_String (SELECT_OD_COORDINATES_x, i);
		}
		if (str_ptr == NULL) continue;

		if (!Network_File_Flag (NODE)) {
			Error ("Select OD Coordinates requires a Node file");
		}
		in_flag = true;

		if (i == 0) {
			Print (2, "Select OD Coordinates = %s", str_ptr);
		} else {
			if (od_box.Num_Records () == 0) Print (1);

			Print (1, "Select OD Coordinates #%d = %s", i, str_ptr);
		}
		str_ptr = Get_Double (str_ptr, &dvalue);
		box.x1 = Round (dvalue);

		if (str_ptr == NULL) goto coord_error;

		str_ptr = Get_Double (str_ptr, &dvalue);
		box.y1 = Round (dvalue);

		if (str_ptr == NULL) goto coord_error;

		str_ptr = Get_Double (str_ptr, &dvalue);
		box.x2 = Round (dvalue);

		if (box.x2 < box.x1) {
			lvalue = box.x2;
			box.x2 = box.x1;
			box.x1 = lvalue;
		}
		if (str_ptr == NULL) goto coord_error;

		str_ptr = Get_Double (str_ptr, &dvalue);
		box.y2 = Round (dvalue);

		if (box.y2 < box.y1) {
			lvalue = box.y2;
			box.y2 = box.y1;
			box.y1 = lvalue;
		}
		if (!od_box.Add (&box)) goto mem_error;
	}

	//---- get the exclude od coordinates ----

	nsel = Highest_Control_Group (EXCLUDE_OD_COORDINATES_x, 0);

	for (i=0; i <= nsel; i++) {
		if (i == 0) {
			str_ptr = Get_Control_String (EXCLUDE_OD_COORDINATES);
		} else {
			str_ptr = Get_Control_String (EXCLUDE_OD_COORDINATES_x, i);
		}
		if (str_ptr == NULL) continue;

		if (!Network_File_Flag (NODE)) {
			Error ("Excludet OD Coordinates requires a Node file");
		}
		out_flag =  true;

		if (i == 0) {
			Print (2, "Exclude OD Coordinates = %s", str_ptr);
		} else {
			if (exclude_box.Num_Records () == 0) Print (1);

			Print (1, "Excludet OD Coordinates #%d = %s", i, str_ptr);
		}
		str_ptr = Get_Double (str_ptr, &dvalue);
		box.x1 = Round (dvalue);

		if (str_ptr == NULL) goto od_coord_error;

		str_ptr = Get_Double (str_ptr, &dvalue);
		box.y1 = Round (dvalue);

		if (str_ptr == NULL) goto od_coord_error;

		str_ptr = Get_Double (str_ptr, &dvalue);
		box.x2 = Round (dvalue);

		if (box.x2 < box.x1) {
			lvalue = box.x2;
			box.x2 = box.x1;
			box.x1 = lvalue;
		}
		if (str_ptr == NULL) goto od_coord_error;

		str_ptr = Get_Double (str_ptr, &dvalue);
		box.y2 = Round (dvalue);

		if (box.y2 < box.y1) {
			lvalue = box.y2;
			box.y2 = box.y1;
			box.y1 = lvalue;
		}
		if (!exclude_box.Add (&box)) goto mem_error;
	}

	//---- get the select subarea polygon ----

	str_ptr = Get_Control_String (SELECT_SUBAREA_POLYGON);

	if (str_ptr != NULL) {
		if (!Network_File_Flag (LINK) || !Network_File_Flag (NODE)) {
			Error ("Link and Node files are Required for Subarea Polygon Selection");
		}
		Print (1);
		select_subarea.File_Type ("Select Subarea Polygon");

		select_subarea.Open (Project_Filename (str_ptr));
		
		if (!select_subarea.Read_Record ()) {
			Error ("Reading %s", select_subarea.File_Type ());
		}
		subarea_flag = true;
	}

	//---- get the select vehicle types ----
	
	str_ptr = Get_Control_String (SELECT_VEHICLE_TYPES);

	if (str_ptr != NULL) {
		Print (2, "Select Vehicle Types = %s", str_ptr);

		if (!vehicle_types.Add_Ranges (str_ptr)) {
			File_Error ("Vehicle Type Range", str_ptr);
		}
		vehicle_flag = true;
		if (!Demand_File_Flag (VEHICLE)) {
			Error ("A Vehicle File is Required for Vehicle Type Selection");
		}
	} else {
		Demand_File_False (VEHICLE);
	}

	//---- get the percent time difference ----

	str_ptr = Get_Control_String (PERCENT_TIME_DIFFERENCE);

	if (str_ptr != NULL) {
		if (!delay_flag) {
			Error ("Percent Time Difference requires a Link Delay file");
		}
		diff_flag = true;
        Get_Double (str_ptr, &percent_diff);

		if (percent_diff < 0.1 || percent_diff > 100.0) {
			Error ("Percent Time Difference %.2lf is Out of Range (0.1-100.0)", percent_diff);
		}
		Print (2, "Percent Time Difference = %.1lf%%", percent_diff);

		percent_diff /= 100.0;

		//---- get the minimum time difference ----

		str_ptr = Get_Control_String (MINIMUM_TIME_DIFFERENCE);

		if (str_ptr != NULL) {
			Get_Integer (str_ptr, &min_time);

			if (min_time < 0 || min_time > 120) {
				Error ("Minimum Time Difference %d is Out of Range (0-120)", min_time);
			}
		}
		Print (1, "Minimum Time Difference = %d minute%s", 
			min_time, ((min_time != 1) ? "s" : " "));

		//---- get the maximum time difference ----

		str_ptr = Get_Control_String (MAXIMUM_TIME_DIFFERENCE);

		if (str_ptr != NULL) {
			Get_Integer (str_ptr, &max_time);

			if (max_time < min_time || max_time > 1440) {
				Error ("Maximum Time Difference %d is Out of Range (%d-1440)", max_time, min_time);
			}
		}
		Print (1, "Maximum Time Difference = %d minutes", max_time);

		min_time *= 60;
		max_time *= 60;
	}

	//---- get the selection percentage ----

	str_ptr = Get_Control_String (SELECTION_PERCENTAGE);

	if (str_ptr != NULL) {
		Get_Double (str_ptr, &percent);

		if (percent < 0.1 || percent > 100.0) {
			Error ("Selection Percentage %.2lf is Out of Range (0.1-100.0)", percent);
		}
		select_flag = (percent != 100.0);
	}
	Print (2, "Selection Percentage = %.1lf%%", percent);

	percent /= 100.0;

	//---- get the max percent selected ----

	str_ptr = Get_Control_String (MAXIMUM_PERCENT_SELECTED);

	if (str_ptr != NULL) {
		Get_Double (str_ptr, &max_percent);

		if (max_percent < 1.0 || max_percent > 100.0) {
			Error ("Maximum Percent Selected %.1lf is Out of Range (1.0-100.0)", max_percent);
		}
	}
	Print (1, "Maximum Percent Selected = %.1lf%%", max_percent);

	max_percent /= 100.0;

	//---- random number seed ----

	str_ptr = Get_Control_String (RANDOM_NUMBER_SEED);

	if (str_ptr != NULL) {
		random.Seed (atoi (str_ptr));
	}
	if (str_ptr != NULL || percent != 1.0 || max_percent != 1.0) {
		Print (1, "Random Number Seed = %d", random.Seed ());
	}

	//---- reset the network flags ----

	if (!vc_flag && !diff_flag && !ratio_flag) {
		delay_flag = parking_flag = turn_flag = false;
		Demand_File_False (LINK_DELAY);
		Network_File_False (LANE_USE);
		Network_File_False (PARKING);
		Network_File_False (LANE_CONNECTIVITY);

		if (!coord_flag && !out_flag && !in_flag && !subarea_flag && !factype_flag && 
			nodes.Num_Records () == 0 && links.Num_Records () == 0) {
			Network_File_False (LINK);
			Network_File_False (NODE);
			Network_File_False (TRANSIT_STOP);
			Network_File_False (TRANSIT_DRIVER);
		} else if (!factype_flag && type_flag && links.Num_Records () == 0) {
			Network_File_False (LINK);
		}
	} else {
		parking_flag = Network_File_Flag (PARKING);

		if (!diff_flag) {
			turn_flag = false;
			Network_File_False (LANE_CONNECTIVITY);
		}
	}
	transit_flag = (Network_File_Flag (TRANSIT_STOP) && Network_File_Flag (TRANSIT_DRIVER));

	return;

	//---- error message ----

control_error:
	Error ("Missing Control Key = %s", Current_Key ());

coord_error:
	Error ("Select Coordinates are Incomplete");

od_coord_error:
	Error ("Exclude OD Coordinates are Incomplete");

mem_error:
	Error ("Insufficient Memory for Coordinate Groups");
} 
示例#6
0
void RunSetup::Program_Control (void)
{
	int i, num_group;
	char *str_ptr, buffer [STRING_BUFFER];

	Db_File setup_file;
	Setup_Group setup;

	//---- check for setup files ----

	num_group = Highest_Control_Group (SETUP_CONTROL_FILE_x, 0);

	setup_flag = (num_group > 0);

	//---- process the master control keys ----

	Key_Processing (true);

	//---- process each setup group ----

	for (i=1; i <= num_group; i++) {

		//---- get the setup control file ----

		str_ptr = Get_Control_String (SETUP_CONTROL_FILE_x, i);
		if (str_ptr == NULL) continue;

		Print (1);
		setup.group_num = i;

		//---- open setup control file ----

		str_fmt (buffer, sizeof (buffer), "Setup Control File #%d", i);
		setup_file.File_Type (buffer);

		if (!setup_file.Open (str_ptr)) {
			File_Error (setup_file.File_Type (), setup_file.Filename ());
		}
		str_cpy (setup.setup_file, sizeof (setup.setup_file), setup_file.Filename ());
		setup_file.Close ();

		//---- get the setup parameter ----

		str_ptr = Get_Control_String (SETUP_PARAMETER_x, i);

		if (str_ptr == NULL) {
			setup.parameter [0] = '\0';
		} else {
			str_cpy (setup.parameter, sizeof (setup.parameter), str_ptr);

			Print (1, "Setup Parameter #%d = %s", i, str_ptr);
		}

		//---- add the files to the group ----

		if (!setup_group.Add (&setup)) goto mem_error;
	}
	return;

mem_error:
	Error ("Insufficient Memory for Control Files");
} 
示例#7
0
void LineSum::Program_Control (void)
{
	int i, num_files, anode, bnode;
	bool arcview_flag, z_flag, m_flag;
	String key, format;
	Strings ab_strings, node_pairs;
	Str_Itr str_itr, ab_itr;
	Db_Header *fh = 0;
	File_Itr file_itr;
	Line_Report_Data line_report_data;
	Link_Report_Data link_report_data;
	On_Off_Report_Data on_off_report_data;
	Access_Report_Data access_report_data;
	Stop_Report_Data stop_report_data;
	Total_Report_Data total_report_data;
	Link_Rider_Data link_rider_data;
	Dtime hour;

	//---- process the global control keys ----

	Execution_Service::Program_Control ();

	Metric_Flag (false);
	hour.Hours (1.0);

	//---- get the projection data ----

	projection.Read_Control ();

	//---- get the z coordinate flag ----

	m_flag = projection.M_Flag ();
	z_flag = projection.Z_Flag ();

	Print (2, String ("%s Control Keys:") % Program ());

	//---- initialize the peak file list ----

	num_files = Highest_Control_Group (PEAK_RIDERSHIP_FILE, 0);

	if (num_files > 0) {
		peak_list.Initialize (num_files);
		Print (1);

		//---- open each file ----

		for (i=1; i <= num_files; i++) {

			//---- open the peak ridership file ----

			key = Get_Control_String (PEAK_RIDERSHIP_FILE, i);
			if (key.empty ()) continue;
	
			fh = peak_list [i-1];

			fh->File_Type (String ("Peak Ridership File #%d") % i);
			fh->File_ID (String ("Peak%d") % i);

			//---- get the file format ----

			if (Check_Control_Key (PEAK_RIDERSHIP_FORMAT, i)) {
				fh->Dbase_Format (Get_Control_String (PEAK_RIDERSHIP_FORMAT, i));
			}
			fh->Open (Project_Filename (key));
		}
	}

	//---- initialize the offpeak file list ----

	num_files = Highest_Control_Group (OFFPEAK_RIDERSHIP_FILE, 0);

	if (num_files > 0) {
		offpeak_list.Initialize (num_files);
		Print (1);

		//---- open each file ----

		for (i=1; i <= num_files; i++) {

			//---- open the offpeak ridership file ----

			key = Get_Control_String (OFFPEAK_RIDERSHIP_FILE, i);
			if (key.empty ()) continue;
	
			fh = offpeak_list [i-1];

			fh->File_Type (String ("Offpeak Ridership File #%d") % i);
			fh->File_ID (String ("Offpeak%d") % i);

			//---- get the file format ----

			if (Check_Control_Key (OFFPEAK_RIDERSHIP_FORMAT, i)) {
				fh->Dbase_Format (Get_Control_String (OFFPEAK_RIDERSHIP_FORMAT, i));
			}
			fh->Open (Project_Filename (key));
		}
	}
	if (peak_list.size () == 0 && offpeak_list.size () == 0) {
//		Error ("No Peak or Offpeak Ridership File Keys were Found");
	}

	//---- open the new peak ridership file ----

	key = Get_Control_String (NEW_PEAK_RIDERSHIP_FILE);

	if (!key.empty ()) {
		Print (1);
		if (peak_list.size () == 0) {
			Error ("Input Peak Ridership Files are Required");
		}
		fh = 0;

		for (file_itr = peak_list.begin (); file_itr != peak_list.end (); file_itr++) {
			if ((*file_itr)->Is_Open ()) {
				fh = *file_itr;
				break;
			}
		}
		if (fh == 0) Error ("Peak Input files are Not Open");

		new_peak_file.File_Type ("New Peak Ridership File");
		new_peak_file.File_ID ("NewPeak");

		//---- get the file format ----

		if (Check_Control_Key (NEW_PEAK_RIDERSHIP_FORMAT)) {
			new_peak_file.Dbase_Format (Get_Control_String (NEW_PEAK_RIDERSHIP_FORMAT));
		}
		new_peak_file.Header_Lines (fh->Header_Lines ());

		new_peak_file.Replicate_Fields (fh);

		new_peak_file.Create (Project_Filename (key));
	}

	//---- open the new offpeak ridership file ----

	key = Get_Control_String (NEW_OFFPEAK_RIDERSHIP_FILE);

	if (!key.empty ()) {
		Print (1);
		if (offpeak_list.size () == 0) {
			Error ("Input Offpeak Ridership Files are Required");
		}
		fh = 0;

		for (file_itr = offpeak_list.begin (); file_itr != offpeak_list.end (); file_itr++) {
			if ((*file_itr)->Is_Open ()) {
				fh = *file_itr;
				break;
			}
		}
		if (fh == 0) Error ("Offpeak Input files are Not Open");

		new_offpeak_file.File_Type ("New Offpeak Ridership File");
		new_offpeak_file.File_ID ("NewOffpeak");

		//---- get the file format ----

		if (Check_Control_Key (NEW_OFFPEAK_RIDERSHIP_FORMAT)) {
			new_offpeak_file.Dbase_Format (Get_Control_String (NEW_OFFPEAK_RIDERSHIP_FORMAT));
		}
		new_offpeak_file.Header_Lines (fh->Header_Lines ());

		new_offpeak_file.Replicate_Fields (fh);

		new_offpeak_file.Create (Project_Filename (key));
	}

	//---- open the new total ridership file ----

	key = Get_Control_String (NEW_TOTAL_RIDERSHIP_FILE);

	if (!key.empty ()) {
		Print (1);
		if (peak_list.size () == 0 || offpeak_list.size () == 0) {
			Error ("Input Peak and Offpeak Ridership Files are Required");
		}
		fh = 0;

		for (file_itr = peak_list.begin (); file_itr != peak_list.end (); file_itr++) {
			if ((*file_itr)->Is_Open ()) {
				fh = *file_itr;
				break;
			}
		}
		if (fh == 0) Error ("Peak Input files are Not Open");

		new_total_file.File_Type ("New Total Ridership File");
		new_total_file.File_ID ("NewTotal");

		//---- get the file format ----

		if (Check_Control_Key (NEW_TOTAL_RIDERSHIP_FORMAT)) {
			new_total_file.Dbase_Format (Get_Control_String (NEW_TOTAL_RIDERSHIP_FORMAT));
		}
		new_total_file.Header_Lines (fh->Header_Lines ());

		new_total_file.Replicate_Fields (fh);

		new_total_file.Create (Project_Filename (key));
	}

	//---- open the stop name file ----

	key = Get_Control_String (STOP_NAME_FILE);
	if (!key.empty ()) {
		Print (1);
		stop_name_file.File_Type ("Stop Name File");
		stop_name_file.File_ID ("StopName");
		station_flag = true;

		//---- get the file format ----

		if (Check_Control_Key (STOP_NAME_FORMAT)) {
			stop_name_file.Dbase_Format (Get_Control_String (STOP_NAME_FORMAT));
		}
		stop_name_file.Open (Project_Filename (key));
	}

	//---- line report data ----

	num_files = Highest_Control_Group (LINE_REPORT_LINES);

	if (num_files > 0) {

		//---- read the line report keys ----

		for (i=1; i <= num_files; i++) {
			if (!Check_Control_Key (LINE_REPORT_LINES, i)) continue;
			Print (1);

			//---- report number and title ----

			line_report_data.number = i;
			line_report_data.title = Get_Control_Text (LINE_REPORT_TITLE, i);

			//---- line range ----
			
			key = Get_Control_Text (LINE_REPORT_LINES, i);
			if (key.empty ()) continue;

			key.Parse (line_report_data.lines);

			//---- selected modes ----

			key = Get_Control_Text (LINE_REPORT_MODES, i);
			line_report_data.modes.clear ();

			if (!key.empty () && !key.Equals ("ALL")) {
				line_report_data.all_modes = false;
				if (!line_report_data.modes.Add_Ranges (key)) {
					exe->Error ("Adding Modes Ranges");
				}
			} else {
				line_report_data.all_modes = true;
			}

			//---- report all nodes ----

			line_report_data.node_flag = Get_Control_Flag (LINE_REPORT_ALL_NODES, i);

			//---- store the control data ----

			line_report_array.push_back (line_report_data);
		}
	}

	//---- link report data ----

	num_files = Highest_Control_Group (LINK_REPORT_LINKS);

	if (num_files > 0) {

		//---- read the link report keys ----

		for (i=1; i <= num_files; i++) {
			if (!Check_Control_Key (LINK_REPORT_LINKS, i)) continue;
			Print (1);

			//---- report number and title ----

			link_report_data.number = i;
			link_report_data.title = Get_Control_Text (LINK_REPORT_TITLE, i);

			//---- anode-bnode pairs ----
			
			key = Get_Control_Text (LINK_REPORT_LINKS, i);
			if (key.empty ()) continue;

			link_report_data.links = key;

			key.Parse (node_pairs);
			link_report_data.nodes.clear ();

			for (str_itr = node_pairs.begin (); str_itr != node_pairs.end (); str_itr++) {
				str_itr->Parse (ab_strings, "-");

				for (anode=0, ab_itr = ab_strings.begin (); ab_itr != ab_strings.end (); ab_itr++, anode = bnode) {
					bnode = ab_itr->Integer ();
					if (anode > 0) {
						link_report_data.nodes.push_back (anode);
						link_report_data.nodes.push_back (bnode);
					}
				}
			}

			//---- selected modes ----

			key = Get_Control_Text (LINK_REPORT_MODES, i);
			link_report_data.modes.clear ();

			if (!key.empty () && !key.Equals ("ALL")) {
				link_report_data.all_modes = false;
				if (!link_report_data.modes.Add_Ranges (key)) {
					exe->Error ("Adding Modes Ranges");
				}
			} else {
				link_report_data.all_modes = true;
			}

			//---- selected lines ----

			key = Get_Control_Text (LINK_REPORT_LINES, i);
			link_report_data.lines.clear ();

			if (!key.empty () && !key.Equals ("ALL")) {
				link_report_data.all_lines = false;
				key.Parse (link_report_data.lines);
			} else {
				link_report_data.all_lines = true;
			}

			//---- oneway/twoway flag ----

			link_report_data.dir_flag = Get_Control_Flag (LINK_REPORT_ONEWAY, i);

			//---- store the control data ----

			link_report_array.push_back (link_report_data);
		}
	}

	//---- on-off report data ----

	num_files = Highest_Control_Group (ON_OFF_REPORT_STOPS);

	if (num_files > 0) {
		on_off_flag = true;

		//---- read the boarding report keys ----

		for (i=1; i <= num_files; i++) {
			if (!Check_Control_Key (ON_OFF_REPORT_STOPS, i)) continue;
			Print (1);

			//---- report number and title ----

			on_off_report_data.number = i;
			on_off_report_data.title = Get_Control_Text (ON_OFF_REPORT_TITLE, i);

			//---- stop range ----

			key = Get_Control_Text (ON_OFF_REPORT_STOPS, i);
			if (key.empty ()) continue;

			on_off_report_data.stops.clear ();

			if (!key.empty () && !key.Equals ("ALL")) {
				on_off_report_data.all_stops = false;
				if (!on_off_report_data.stops.Add_Ranges (key)) {
					exe->Error ("Adding Stop Ranges");
				}
			} else {
				on_off_report_data.all_stops = true;
			}

			//---- select modes ----

			key = Get_Control_Text (ON_OFF_REPORT_MODES, i);

			on_off_report_data.modes.clear ();

			if (!key.empty () && !key.Equals ("ALL")) {
				on_off_report_data.all_modes = false;
				if (!on_off_report_data.modes.Add_Ranges (key)) {
					exe->Error ("Adding Modes Ranges");
				}
			} else {
				on_off_report_data.all_modes = true;
			}

			//---- level of detail ----

			key = Get_Control_Text (ON_OFF_REPORT_DETAILS, i);

			if (!key.empty ()) {
				char ch = key [0];
				if (ch >= 'a' && ch <= 'z') ch = ch - 'a' + 'A';

				if (ch == 'T' || ch == 'Y' || ch == '1') {
					on_off_report_data.details = 1;
				} else if (ch == 'M' || ch == '2') {
					on_off_report_data.details = 2;
				} else {
					on_off_report_data.details = 0;
				}
			} else {
				on_off_report_data.details = 0;
			}

			//---- output data file ----

			key = Get_Control_String (NEW_ON_OFF_REPORT_FILE, i);

			if (!key.empty ()) {
				if (Check_Control_Key (NEW_ON_OFF_REPORT_FORMAT, i)) {
					format = Get_Control_String (NEW_ON_OFF_REPORT_FORMAT, i);

					on_off_report_data.arcview_flag = format.Equals ("ARCVIEW");
				} else {
					on_off_report_data.arcview_flag = false;
				}
				Print (1);
				if (on_off_report_data.arcview_flag) {
					on_off_report_data.file = on_off_report_data.arc_file = new Arcview_File ();

					on_off_report_data.arc_file->File_Type (String ("New On-Off Report File #%d") % i);
					on_off_report_data.arc_file->Shape_Type (DOT);
					on_off_report_data.arc_file->Z_Flag (z_flag);
					on_off_report_data.arc_file->M_Flag (m_flag);

					on_off_report_data.arc_file->Create (Project_Filename (key));

					on_off_report_data.arc_file->Set_Projection (projection.Input_Projection (), projection.Output_Projection ());
					xy_flag = true;
				} else {
					on_off_report_data.file = new Db_Header ();

					if (Check_Control_Key (NEW_ON_OFF_REPORT_FORMAT, i)) {
						on_off_report_data.file->Dbase_Format (format);
					}
					on_off_report_data.file->File_Type (String ("New On-Off Report File #%d") % i);
					on_off_report_data.file->Create (Project_Filename (key));
				}
			} else {
				on_off_report_data.file = 0;
			}

			//---- store the control data ----

			on_off_report_array.push_back (on_off_report_data);
		}
	}

	//---- access report data ----

	num_files = Highest_Control_Group (ACCESS_REPORT_STOPS);

	if (num_files > 0) {
		access_flag = true;

		//---- read the access report keys ----

		for (i=1; i <= num_files; i++) {
			if (!Check_Control_Key (ACCESS_REPORT_STOPS, i)) continue;
			Print (1);

			//---- report number and title ----

			access_report_data.number = i;
			access_report_data.title = Get_Control_Text (ACCESS_REPORT_TITLE, i);

			//---- stop range ----

			key = Get_Control_Text (ACCESS_REPORT_STOPS, i);
			if (key.empty ()) continue;

			access_report_data.stops.clear ();

			if (!key.empty () && !key.Equals ("ALL")) {
				access_report_data.all_stops = false;
				if (!access_report_data.stops.Add_Ranges (key)) {
					exe->Error ("Adding Stop Ranges");
				}
			} else {
				access_report_data.all_stops = true;
			}

			//---- select modes ----

			key = Get_Control_Text (ACCESS_REPORT_MODES, i);

			access_report_data.modes.clear ();

			if (!key.empty () && !key.Equals ("ALL")) {
				access_report_data.all_modes = false;
				if (!access_report_data.modes.Add_Ranges (key)) {
					exe->Error ("Adding Modes Ranges");
				}
			} else {
				access_report_data.all_modes = true;
			}

			//---- level of detail ----

			key = Get_Control_Text (ACCESS_REPORT_DETAILS, i);

			if (!key.empty ()) {
				char ch = key [0];
				if (ch >= 'a' && ch <= 'z') ch = ch - 'a' + 'A';

				if (ch == 'T' || ch == 'Y' || ch == '1') {
					access_report_data.details = 1;
				} else if (ch == 'M' || ch == '2') {
					access_report_data.details = 2;
				} else {
					access_report_data.details = 0;
				}
			} else {
				access_report_data.details = 0;
			}

			//---- output data file ----

			key = Get_Control_String (NEW_ACCESS_REPORT_FILE, i);

			if (!key.empty ()) {
				access_report_data.file = new Db_Header ();
				access_report_data.file->File_Type (String ("New Access Report File #%d") % i);

				if (Check_Control_Key (NEW_ACCESS_REPORT_FORMAT, i)) {
					access_report_data.file->Dbase_Format (Get_Control_String (NEW_ACCESS_REPORT_FORMAT, i));
				}
				access_report_data.file->Create (Project_Filename (key));

				if (Check_Control_Key (NEW_ACCESS_REPORT_FORMAT, i)) {
					format = Get_Control_String (NEW_ACCESS_REPORT_FORMAT, i);

					access_report_data.arcview_flag = format.Equals ("ARCVIEW");
				} else {
					access_report_data.arcview_flag = false;
				}
				Print (1);
				if (access_report_data.arcview_flag) {
					access_report_data.file = access_report_data.arc_file = new Arcview_File ();

					access_report_data.arc_file->File_Type (String ("New Access Report File #%d") % i);
					access_report_data.arc_file->Shape_Type (DOT);
					access_report_data.arc_file->Z_Flag (z_flag);
					access_report_data.arc_file->M_Flag (m_flag);

					access_report_data.arc_file->Create (Project_Filename (key));

					access_report_data.arc_file->Set_Projection (projection.Input_Projection (), projection.Output_Projection ());
					xy_flag = true;
				} else {
					access_report_data.file = new Db_Header ();

					if (Check_Control_Key (NEW_ACCESS_REPORT_FORMAT, i)) {
						access_report_data.file->Dbase_Format (format);
					}
					access_report_data.file->File_Type (String ("New Access Report File #%d") % i);
					access_report_data.file->Create (Project_Filename (key));
				}
			} else {
				access_report_data.file = 0;
			}

			//---- store the control data ----

			access_report_array.push_back (access_report_data);
		}
	}

	//---- stop report data ----

	num_files = Highest_Control_Group (STOP_REPORT_STOPS);

	if (num_files > 0) {
		access_flag = true;

		//---- read the stop report keys ----

		for (i=1; i <= num_files; i++) {
			if (!Check_Control_Key (STOP_REPORT_STOPS, i)) continue;
			Print (1);

			//---- report number and title ----

			stop_report_data.number = i;
			stop_report_data.title = Get_Control_Text (STOP_REPORT_TITLE, i);

			//---- stop range ----
			
			key = Get_Control_Text (STOP_REPORT_STOPS, i);
			if (key.empty ()) continue;

			stop_report_data.stops.clear ();

			if (!stop_report_data.stops.Add_Ranges (key)) {
				exe->Error ("Adding Stop Ranges");
			}

			//---- select modes ----

			key = Get_Control_Text (STOP_REPORT_MODES, i);
			stop_report_data.modes.clear ();

			if (!key.empty () && !key.Equals ("ALL")) {
				stop_report_data.all_modes = false;
				if (!stop_report_data.modes.Add_Ranges (key)) {
					exe->Error ("Adding Modes Ranges");
				}
			} else {
				stop_report_data.all_modes = true;
			}

			//---- line range ----

			key = Get_Control_Text (STOP_REPORT_LINES, i);
			stop_report_data.lines.clear ();

			if (!key.empty () && !key.Equals ("ALL")) {
				stop_report_data.all_lines = false;
				key.Parse (stop_report_data.lines);
			} else {
				stop_report_data.all_lines = true;
			}

			//---- transfer modes ----

			key = Get_Control_Text (STOP_REPORT_TRANSFERS, i);
			stop_report_data.transfers.clear ();

			if (!key.empty () && !key.Equals ("NONE")) {
				if (!stop_report_data.transfers.Add_Ranges (key)) {
					exe->Error ("Adding Transfer Mode Ranges");
				}
			}

			//---- store the control data ----

			stop_report_array.push_back (stop_report_data);
		}
	}

	//---- total report data ----

	num_files = Highest_Control_Group (TOTAL_REPORT_LINES);

	if (num_files > 0) {

		//---- read the total report keys ----

		for (i=1; i <= num_files; i++) {
			if (!Check_Control_Key (TOTAL_REPORT_LINES, i)) continue;
			Print (1);

			//---- report number and title ----

			total_report_data.number = i;
			total_report_data.title = Get_Control_Text (TOTAL_REPORT_TITLE, i);

			//---- line range ----

			key = Get_Control_Text (TOTAL_REPORT_LINES, i);
			if (key.empty ()) continue;

			key.Parse (total_report_data.lines);

			//---- selected modes ----

			key = Get_Control_Text (TOTAL_REPORT_MODES, i);
			
			total_report_data.modes.clear ();

			if (!key.empty () && !key.Equals ("ALL")) {
				total_report_data.all_modes = false;
				if (!total_report_data.modes.Add_Ranges (key)) {
					exe->Error ("Adding Modes Ranges");
				}
			} else {
				total_report_data.all_modes = true;
			}

			//---- output data file ----

			key = Get_Control_String (NEW_TOTAL_REPORT_FILE, i);
			if (!key.empty ()) {
				total_report_data.file = new Db_Header ();
				total_report_data.file->File_Type (String ("New Total Report File #%d") % i);

				if (Check_Control_Key (NEW_TOTAL_REPORT_FORMAT, i)) {
					total_report_data.file->Dbase_Format (Get_Control_String (NEW_TOTAL_REPORT_FORMAT, i));
				}
				total_report_data.file->Create (Project_Filename (key));

				//---- peak hours ----

				total_report_data.peak_hours = (double) Get_Control_Time (TOTAL_REPORT_PEAK_HOURS, i) / hour;
			
				//---- offpeak hours ----

				total_report_data.offpeak_hours = (double) Get_Control_Time (TOTAL_REPORT_OFFPEAK_HOURS, i) / hour;
			} else {
				total_report_data.file = 0;
			}

			//---- store the control data ----

			total_report_array.push_back (total_report_data);
		}
	}

	//---- open the node XY file ----

	if (xy_flag) {
		key = Get_Control_String (NODE_XY_FILE);

		if (key.empty ()) {
			Error ("Node XY File is Required for Stop Shapefiles");
		}
		if (Check_Control_Key (NODE_XY_FORMAT)) {
			node_xy_file.Dbase_Format (Get_Control_String (NODE_XY_FORMAT));
		}
		node_xy_file.File_Type ("Node XY File");

		Print (1);
		node_xy_file.Open (Project_Filename (key));
	}

	//---- link rider file data ----

	num_files = Highest_Control_Group (NEW_LINK_RIDER_FILE);

	if (num_files > 0) {
		arcview_flag = false;

		//---- read the link rider keys ----

		for (i=1; i <= num_files; i++) {

			//---- output data file ---

			key = Get_Control_String (NEW_LINK_RIDER_FILE, i);
			if (key.empty ()) continue;
			
			link_rider_data.number = i;

			if (Check_Control_Key (NEW_LINK_RIDER_FORMAT, i)) {
				format = Get_Control_String (NEW_LINK_RIDER_FORMAT, i);

				link_rider_data.arcview_flag = format.Equals ("ARCVIEW");
			} else {
				link_rider_data.arcview_flag = false;
			}
			Print (1);
			if (link_rider_data.arcview_flag) {
				link_rider_data.file = link_rider_data.arc_file = new Arcview_File ();

				link_rider_data.arc_file->File_Type (String ("New Link Rider File #%d") % i);
				link_rider_data.arc_file->Shape_Type (VECTOR);
				link_rider_data.arc_file->Z_Flag (z_flag);
				link_rider_data.arc_file->M_Flag (m_flag);

				link_rider_data.arc_file->Create (Project_Filename (key));

				link_rider_data.arc_file->Set_Projection (projection.Input_Projection (), projection.Output_Projection ());
				arcview_flag = true;
			} else {
				link_rider_data.file = new Db_Header ();

				if (Check_Control_Key (NEW_LINK_RIDER_FORMAT, i)) {
					link_rider_data.file->Dbase_Format (format);
				}
				link_rider_data.file->File_Type (String ("New Link Rider File #%d") % i);
				link_rider_data.file->Create (Project_Filename (key));
			}

			//---- selected modes ----

			key = Get_Control_Text (LINK_RIDER_MODES, i);
			link_rider_data.modes.clear ();

			if (!key.empty () && !key.Equals ("ALL")) {
				link_rider_data.all_modes = false;
				if (!link_rider_data.modes.Add_Ranges (key)) {
					exe->Error ("Adding Modes Ranges");
				}
			} else {
				link_rider_data.all_modes = true;
			}

			//---- selected lines ----

			key = Get_Control_Text (LINK_RIDER_LINES, i);
			link_rider_data.lines.clear ();
			link_rider_data.all_lines = false;
			link_rider_data.each_line = false;

			if (key.empty ()) {
				link_rider_data.all_lines = true;
			} else if (key.Equals ("ALL")) {
				link_rider_data.all_lines = true;
			} else if (key.Equals ("EACH")) {
				link_rider_data.each_line = true;
			} else {
				key.Parse (link_rider_data.lines);
			}
			
			//---- peak hours ----

			link_rider_data.peak_hours = (double) Get_Control_Time (LINK_RIDER_PEAK_HOURS, i) / hour;

			//---- peak factor ----

			link_rider_data.peak_fac = Get_Control_Double (LINK_RIDER_PEAK_FACTOR, i);

			//---- peak capacity ----

			link_rider_data.peak_cap = Get_Control_Double (LINK_RIDER_PEAK_CAPACITY, i);
			
			//---- offpeak hours ----

			link_rider_data.offpeak = (double) Get_Control_Time (LINK_RIDER_OFFPEAK_HOURS, i) / hour;

			//---- open node file for arcview output ----

			if (link_rider_data.arcview_flag) {
				key = Get_Control_String (LINK_RIDER_XY_FILE, i);

				if (key.empty ()) {
					Error ("A Link Rider XY File is required for Arcview Output");
				}
				link_rider_data.xy_file = new Db_Header ();
				link_rider_data.xy_file->File_Type (String ("Link Rider XY File #%d") % i);

				if (Check_Control_Key (LINK_RIDER_XY_FORMAT, i)) {
					link_rider_data.xy_file->Dbase_Format (Get_Control_String (LINK_RIDER_XY_FORMAT, i));
				}
				link_rider_data.xy_file->Open (Project_Filename (key));

				link_rider_data.node_fld = link_rider_data.xy_file->Required_Field (NODE_FIELD_NAMES);
				link_rider_data.xcoord_fld = link_rider_data.xy_file->Required_Field (X_FIELD_NAMES);
				link_rider_data.ycoord_fld = link_rider_data.xy_file->Required_Field (Y_FIELD_NAMES);

				link_rider_data.offset = Get_Control_Double (LINK_RIDER_SIDE_OFFSET, i);
			} else {
				link_rider_data.offset = 0.0;
			}

			//---- store the control data ----

			link_rider_array.push_back (link_rider_data);
		}

		//---- open the link shape file ----

		if (arcview_flag) {
			key = Get_Control_String (LINK_SHAPE_FILE);

			if (!key.empty ()) {
				Print (1);
				shape_flag = true;

				link_shape.File_Type ("Link Shape File");
				link_shape.Set_Projection (projection.Input_Projection (), projection.Output_Projection ());

				link_shape.Open (Project_Filename (key));

				//---- get the field numbers ----

				key = Get_Control_Text (LINK_SHAPE_ANODE);

				anode_field = link_shape.Required_Field (key);
				Print (0, ", Number=") << anode_field;
				
				key = Get_Control_Text (LINK_SHAPE_BNODE);

				bnode_field = link_shape.Required_Field (key);
				Print (0, ", Number=") << bnode_field;
			}
		}

		//---- process service level files ----

		key = Get_Control_String (SERVICE_FILE);

		if (!key.empty ()) {
			Print (1);
			service_file.File_Type ("Service File");
			service_flag = true;

			//---- get the file format ----

			if (Check_Control_Key (SERVICE_FORMAT)) {
				service_file.Dbase_Format (Get_Control_String (SERVICE_FORMAT));
			}
			service_file.Open (Project_Filename (key));

			//---- get the field numbers ----

			key = Get_Control_Text (SERVICE_LINE_FIELD);

			line_fld = service_file.Required_Field (key);
			Print (0, ", Number=") << line_fld;

			if (Check_Control_Key (SERVICE_PEAK_FIELD)) {
				key = Get_Control_Text (SERVICE_PEAK_FIELD);

				peak_fld = service_file.Required_Field (key);
				Print (0, ", Number=") << peak_fld;
			}
			if (Check_Control_Key (SERVICE_OFFPEAK_FIELD)) {
				key = Get_Control_Text (SERVICE_OFFPEAK_FIELD);

				offpeak_fld = service_file.Required_Field (key);
				Print (0, ", Number=") << offpeak_fld;
			}
		}
	}

	//---- initialize the base routes ----

	num_files = Highest_Control_Group (BASE_ROUTE_FILE, 0);

	if (num_files > 0) {
		base_routes.Initialize (num_files);
		Print (1);

		//---- open each file ----

		for (i=1; i <= num_files; i++) {

			//---- open the base ridership file ----

			key = Get_Control_String (BASE_ROUTE_FILE, i);
			if (key.empty ()) continue;
	
			fh = base_routes [i-1];

			fh->File_Type (String ("Base Route File #%d") % i);
			fh->File_ID (String ("Base%d") % i);

			//---- get the file format ----

			if (Check_Control_Key (BASE_ROUTE_FORMAT, i)) {
				fh->Dbase_Format (Get_Control_String (BASE_ROUTE_FORMAT, i));
			}
			fh->Open (Project_Filename (key));
		}
	}

	//---- initialize the alternative routes ----

	num_files = Highest_Control_Group (ALTERNATIVE_ROUTE_FILE, 0);

	if (num_files > 0) {
		alt_routes.Initialize (num_files);
		Print (1);

		//---- open each file ----

		for (i=1; i <= num_files; i++) {

			//---- open the alternative ridership file ----

			key = Get_Control_String (ALTERNATIVE_ROUTE_FILE, i);
			if (key.empty ()) continue;
	
			fh = alt_routes [i-1];

			fh->File_Type (String ("Alternative Route File #%d") % i);
			fh->File_ID (String ("Alte%d") % i);

			//---- get the file format ----

			if (Check_Control_Key (ALTERNATIVE_ROUTE_FORMAT, i)) {
				fh->Dbase_Format (Get_Control_String (ALTERNATIVE_ROUTE_FORMAT, i));
			}
			fh->Open (Project_Filename (key));
		}
	}
}
示例#8
0
void SmoothData::Program_Control (void)
{
	int i, lvalue, nfile, nheader, nfield, increment, max_field;
	int naverage, default_average, niter, default_iter, max_size, max_iter;
	char *str_ptr, *format_ptr, buffer [FIELD_BUFFER];
	char input_data [FIELD_BUFFER], output_data [FIELD_BUFFER];
	char input_format [FIELD_BUFFER], output_format [FIELD_BUFFER];
	char initial_file [STRING_BUFFER], initial_format [FIELD_BUFFER];
	double dvalue, forward, backward, factor;
	bool loop_flag, initial_flag, replicate_flag;

	File_Group *group_ptr;

	nfile = 0;
	nheader = 1;
	nfield = 0;
	max_field = 100;
	increment = 0;
	default_average = 3;
	max_size = 9;
	forward = 20.0;
	backward = 20.0;
	default_iter = 0;
	max_iter = 25;
	loop_flag = true;
	initial_flag = false;
	replicate_flag = false;
	input_data [0] = output_data [0] = '\0';

	str_cpy (input_format, sizeof (input_format), "HOURS");
	str_cpy (output_format, sizeof (output_format), "HOURS");

	//---- number of input files ----

	nfile = Highest_Control_Group (INPUT_DATA_FILE_x, 0);

	if (nfile == 0) {
		Error ("No Input Data File Keys");
	}
	file_group.Max_Records (nfile);

	//---- get the default file format ----
	
	str_ptr = Get_Control_String (INPUT_DATA_FORMAT);

	if (str_ptr != NULL) {
		str_cpy (input_data, sizeof (input_data), str_ptr);
	}
	str_ptr = Get_Control_String (OUTPUT_DATA_FORMAT);

	if (str_ptr != NULL) {
		str_cpy (output_data, sizeof (output_data), str_ptr);
	}

	//---- get the default distribution filename ----

	str_ptr = Get_Control_String (DISTRIBUTION_FILE);

	if (str_ptr != NULL) {
		str_cpy (initial_file, sizeof (initial_file), str_ptr);
		initial_flag = true;

		str_ptr = Get_Control_String (DISTRIBUTION_FORMAT);

		if (str_ptr != NULL) {
			str_cpy (initial_format, sizeof (initial_format), str_ptr);
		} else {
			initial_format [0] = '\0';
		}
	}

	//---- get the time of day format ----
	
	str_ptr = Get_Control_String (INPUT_TIME_FORMAT);

	if (str_ptr != NULL) {
		str_cpy (input_format, sizeof (input_format), str_ptr);
	}
	str_ptr = Get_Control_String (OUTPUT_TIME_FORMAT);

	if (str_ptr != NULL) {
		str_cpy (output_format, sizeof (output_format), str_ptr);
	}

	//---- read the field number ----	

	str_ptr = Get_Control_String (SMOOTH_FIELD_NUMBER);

	if (str_ptr != NULL) {
		Get_Integer (str_ptr, &lvalue);
		if (lvalue < 1 || lvalue > max_field) goto field_error;
		nfield = lvalue;
	}

	//---- time increment ----

	str_ptr = Get_Control_String (SMOOTH_TIME_INCREMENT);

	if (str_ptr != NULL) {
		Get_Integer (str_ptr, &lvalue);
		if (lvalue < 0 || lvalue > 3600) goto increment_error;
		increment = lvalue;
	}
	if (increment > 0) {
		max_size = 2 * 3600 / increment + 1;
		max_iter = (max_size + 1) / 2;
		if (max_iter > 100) max_iter = 100;
		max_iter *= max_iter;
	} else {
		max_size = 9;
		max_iter = 25;
	}

	//---- read the number smooth records ----

	str_ptr = Get_Control_String (SMOOTH_GROUP_SIZE);

	if (str_ptr != NULL) {
		Get_Integer (str_ptr, &lvalue);
		if (lvalue < 3 || lvalue > max_size) goto size_error;
		if ((lvalue % 2) != 1) goto odd_error;
		default_average = lvalue;
	}

	//---- read the percent distributed forward ----

	factor = 100.0 - 50.0 / default_average;

	str_ptr = Get_Control_String (PERCENT_MOVED_FORWARD);

	if (str_ptr != NULL) {
		Get_Double (str_ptr, &dvalue);
		if (dvalue < 0.0 || dvalue > factor) goto forward_error;
		forward = dvalue;
	}

	//---- read the percent distributed backwarde ----
	
	str_ptr = Get_Control_String (PERCENT_MOVED_BACKWARD);

	if (str_ptr != NULL) {
		Get_Double (str_ptr, &dvalue);
		if (dvalue < 0.0 || dvalue > factor) goto backward_error;
		backward = dvalue;
	}

	factor = forward + backward;
	dvalue = 100.0 - 100.0 / default_average;
	if (factor < 5.0 || factor > dvalue) goto combined_error;

	//---- number of iterations ----

	str_ptr = Get_Control_String (NUMBER_OF_ITERATIONS);

	if (str_ptr != NULL) {
		Get_Integer (str_ptr, &lvalue);
		if (lvalue < 1 || lvalue > max_iter) goto iteration_error;
		default_iter = lvalue;
	}

	//---- read the circular smoothing flag ----
	
	str_ptr = Get_Control_String (CIRCULAR_GROUP_FLAG);

	if (str_ptr != NULL) {
		loop_flag = Get_Control_Flag (CIRCULAR_GROUP_FLAG);
	}

	//---- read the replicate fields flag ----
	
	str_ptr = Get_Control_String (REPLICATE_FIELDS_FLAG);

	if (str_ptr != NULL) {
		replicate_flag = Get_Control_Flag (REPLICATE_FIELDS_FLAG);
	}

	//---- open each file ----

	for (i=1; i <= nfile; i++) {

		//---- get the next filename ---
		
		str_ptr = Get_Control_String (INPUT_DATA_FILE_x, i);

		if (str_ptr == NULL) continue;

		group_ptr = file_group.New_Record (true);

		group_ptr->Group (i);

		//---- create the input file ----

		Print (1);
		group_ptr->Input_File (new Diurnal_File ());

		str_fmt (buffer, sizeof (buffer), "Input Data File #%d", i);

		group_ptr->Input_File ()->File_Type (buffer);

		format_ptr = Get_Control_String (INPUT_DATA_FORMAT_x, i);

		if (format_ptr != NULL) {
			group_ptr->Input_File ()->Dbase_Format (format_ptr);
		} else if (input_data [0] != '\0') {
			group_ptr->Input_File ()->Dbase_Format (input_data);
		}

		//---- open the file ----

		if (!group_ptr->Input_File ()->Open (Project_Filename (str_ptr))) {
			File_Error (buffer, group_ptr->Input_File ()->Filename ());
		}

		//---- open the output file ----

		str_ptr = Get_Control_String (OUTPUT_DATA_FILE_x, i);

		if (str_ptr == NULL) goto control_error;

		group_ptr->Output_File (new Diurnal_File (Db_Code::CREATE));
		
		str_fmt (buffer, sizeof (buffer), "Output Data File #%d", i);

		group_ptr->Output_File ()->File_Type (buffer);

		format_ptr = Get_Control_String (OUTPUT_DATA_FORMAT_x, i);

		if (format_ptr != NULL) {
			group_ptr->Output_File ()->Dbase_Format (format_ptr);
		} else if (output_data [0] != '\0') {
			group_ptr->Output_File ()->Dbase_Format (output_data);
		}
		if (!group_ptr->Output_File ()->Open (Project_Filename (str_ptr))) {
			File_Error (buffer, group_ptr->Output_File ()->Filename ());
		}

		//---- get the distribution file ----
		
		str_ptr = Get_Control_String (DISTRIBUTION_FILE_x, i);

		if (str_ptr == NULL) {
			if (initial_flag) {
				str_ptr = initial_file;
				if (initial_format [0] != '\0') {
					format_ptr = initial_format;
				} else {
					format_ptr = NULL;
				}
			}
		} else {
			format_ptr = Get_Control_String (DISTRIBUTION_FORMAT_x, i);
		}

		if (str_ptr != NULL) {
			group_ptr->Initial_File (new Diurnal_File ());

			str_fmt (buffer, sizeof (buffer), "Distribution File #%d", i);

			group_ptr->Initial_File ()->File_Type (buffer);

			if (format_ptr != NULL) {
				group_ptr->Initial_File ()->Dbase_Format (format_ptr);
			}
			if (!group_ptr->Initial_File ()->Open (Project_Filename (str_ptr))) {
				File_Error (buffer, group_ptr->Initial_File ()->Filename ());
			}
		} else {
			group_ptr->Initial_File (NULL);
		}

		//---- get the time of day format ----
		
		str_ptr = Get_Control_String (INPUT_TIME_FORMAT_x, i);

		if (str_ptr == NULL) {
			str_ptr = input_format;
		}
		if (!group_ptr->Input_Format (str_ptr)) {
			Error ("Input Time Format %s was Unrecognized", str_ptr);
		}
		Print (1, "Input Time Format = %s", str_ptr);
		
		str_ptr = Get_Control_String (OUTPUT_TIME_FORMAT_x, i);

		if (str_ptr == NULL) {
			str_ptr = output_format;
		}
		if (!group_ptr->Output_Format (str_ptr)) {
			Error ("Output Time Format %s was Unrecognized", str_ptr);
		}
		Print (1, "Output Time Format = %s", str_ptr);

		//---- read the field number ----	

		max_field = group_ptr->Input_File ()->Num_Fields ();

		str_ptr = Get_Control_String (SMOOTH_FIELD_NUMBER_x, i);

		if (str_ptr != NULL) {
			Get_Integer (str_ptr, &lvalue);
			if (lvalue < 1 || lvalue > max_field) goto field_error;
		} else {
			lvalue = nfield;
		}
		group_ptr->Field_Number (lvalue);

		if (lvalue > 0) {
			Print (1, "Smooth Field Number = %d", lvalue);
			group_ptr->Input_File ()->Share_Field (lvalue);
		}

		//---- time increment ----

		str_ptr = Get_Control_String (SMOOTH_TIME_INCREMENT_x, i);

		if (str_ptr != NULL) {
			Get_Integer (str_ptr, &lvalue);
			if (lvalue < 0 || lvalue > 3600) goto increment_error;
		} else {
			lvalue = increment;
		}
		if (lvalue > 0) {
			Print (1, "Smooth Time Increment = %d seconds", lvalue);

			max_size = 2 * 3600 / lvalue + 1;
			max_iter = (max_size + 1) / 2;
			if (max_iter > 100) max_iter = 100;
			max_iter *= max_iter;

			naverage = default_average;
			niter = default_iter;

			if (niter == 0) {
				niter = max_iter / 2;
			}
		} else {
			Print (1, "Smooth Based on Input Time Periods");

			max_size = 9;
			max_iter = 25;
			naverage = default_average; 
			niter = default_iter;
		}
		group_ptr->Increment (lvalue);

		//---- read the number smooth records ----

		str_ptr = Get_Control_String (SMOOTH_GROUP_SIZE_x, i);

		if (str_ptr != NULL) {
			Get_Integer (str_ptr, &lvalue);
			if (lvalue < 3 || lvalue > max_size) goto size_error;
			if ((lvalue % 2) != 1) goto odd_error;
		} else {
			lvalue = naverage;
		}
		Print (1, "Smooth Group Size = %d", lvalue);
		group_ptr->Num_Average (lvalue);

		//---- read the percent distributed forward ----

		factor = 100.0 - 50.0 / lvalue;

		str_ptr = Get_Control_String (PERCENT_MOVED_FORWARD_x, i);

		if (str_ptr != NULL) {
			Get_Double (str_ptr, &dvalue);
			if (dvalue < 0.0 || dvalue > factor) goto forward_error;
		} else {
			dvalue = forward;
		}
		Print (1, "Percent Distributed Forward = %.1lf percent", dvalue);
		group_ptr->Forward (dvalue);

		//---- read the percent distributed backwarde ----
		
		str_ptr = Get_Control_String (PERCENT_MOVED_BACKWARD_x, i);

		if (str_ptr != NULL) {
			Get_Double (str_ptr, &dvalue);
			if (dvalue < 0.0 || dvalue > factor) goto backward_error;
		} else {
			dvalue = backward;
		}
		Print (1, "Percent Distributed Backward = %.1lf percent", dvalue);
		group_ptr->Backward (dvalue);

		factor = group_ptr->Forward () + group_ptr->Backward ();
		dvalue = 100.0 - 100.0 / group_ptr->Num_Average ();
		if (factor < 5.0 || factor > dvalue) goto combined_error;

		//---- number of iterations ----

		str_ptr = Get_Control_String (NUMBER_OF_ITERATIONS_x, i);

		if (str_ptr != NULL) {
			Get_Integer (str_ptr, &lvalue);
			if (lvalue < 1 || lvalue > max_iter) goto iteration_error;
		} else {
			lvalue = niter;
		}
		Print (1, "Number of Iterations = %d", lvalue);
		group_ptr->Num_Iteration (lvalue);

		//---- read the circular smoothing flag ----
		
		str_ptr = Get_Control_String (CIRCULAR_GROUP_FLAG_x, i);

		if (str_ptr != NULL) {
			group_ptr->Loop_Flag (Get_Control_Flag (CIRCULAR_GROUP_FLAG_x, i));
		} else {
			group_ptr->Loop_Flag (loop_flag);
		}
		Print (1, "Circular Group Flag = %s", (group_ptr->Loop_Flag () ? "TRUE" : "FALSE"));

		//---- read the replicate fields flag ----
		
		if (Get_Control_String (REPLICATE_FIELDS_FLAG_x, i) != NULL) {
			group_ptr->Replicate_Flag (Get_Control_Flag (REPLICATE_FIELDS_FLAG_x, i));
		} else {
			group_ptr->Replicate_Flag (replicate_flag);
		}
		Print (1, "Replicate Fields Flag = %s", (group_ptr->Replicate_Flag () ? "TRUE" : "FALSE"));

		if (group_ptr->Replicate_Flag ()) {
			int field, num;
			bool binary;
			Db_Field *fld;
			Diurnal_File *file;

			group_ptr->Output_File ()->Share_Field (0);
			group_ptr->Output_File ()->Clear_Fields ();

			//---- copy all fields ----

			file = group_ptr->Input_File ();
			binary = (file->Record_Format () == Db_Code::BINARY);

			num = file->Num_Fields ();

			for (field=1; field <= num; field++) {
				fld = file->Field (field);
				if (fld == NULL) continue;

				if (field == file->Start_Field () || field == file->End_Field ()) {
					group_ptr->Output_File ()->Add_Field (fld->Name (), Db_Code::STRING, 20);
				} else {
					group_ptr->Output_File ()->Add_Field (fld->Name (), fld->Type (), fld->Size (), 
															fld->Decimal (), -1, binary);
				}
			}
			group_ptr->Output_File ()->Write_Header ();
			group_ptr->Output_File ()->Share_Field (group_ptr->Input_File ()->Share_Field ());
		}

		//---- add the group record ----

		if (!file_group.Add ()) {
			Error ("Adding File Group");
		}
	}
	return;

	//---- error message ----

control_error:
	Error ("Missing Control Key = %s", Current_Key ());

field_error:
	Error ("Field Number %d is Out of Range (1..%d)", lvalue, max_field);

increment_error:
	Error ("Smooth Time Increment %d is Out of Range (0..3600)", lvalue);

size_error:
	Error ("Smooth Group Size %d is Out of Range (1..%d)", lvalue, max_size);

odd_error:
	Error ("Smooth Group Size %d must be an Odd Number", lvalue);

forward_error:
	Error ("Forward Percentage %.1lf is Out of Range (0..%.1lf)", dvalue, factor);

backward_error:
	Error ("Backward Percentage %.1lf is Out of Range (0..%.1lf)", dvalue, factor);

combined_error:
	Error ("Combined Distribution Percentage %.1lf is Out of Range (5..%.0lf)", factor, dvalue);

iteration_error:
	Error ("Number of Iterations %d is Out of Range (1-%d)", lvalue, max_iter);
}
示例#9
0
void TransimsNet::Program_Control (void)
{
	int i, num, lvalue;
	double dvalue;
	char *str_ptr, buffer [FIELD_BUFFER];

	Area_Type *type_ptr;

	//---- open network files ----

	Network_Service::Program_Control ();

	//---- set the file flags ----

	shape_flag = Network_File_Flag (NEW_SHAPE);
	zone_flag = Network_File_Flag (ZONE);
	zout_flag = Network_File_Flag (NEW_ZONE);

	name_flag = (((Link_File *) Network_Db_Base (LINK))->Name_Flag () && 
				((Link_File *) Network_Db_Base (NEW_LINK))->Name_Flag ());

	turn_flag = Network_File_Flag (TURN_PROHIBITION);

	//---- set the zone fields ----

	if (zout_flag) {
		if (!zone_flag) {
			Print (2, "Zone Centroids Copied from Node File");
		} else {
			Zone_File *file = (Zone_File *) Network_Db_File (ZONE);
			Zone_File *new_file = (Zone_File *) Network_Db_File (NEW_ZONE);

			new_file->Clear_Fields ();
			new_file->Replicate_Fields (file);
			new_file->Write_Header ();
		}
	}

	//---- keep node list ----
	
	str_ptr = Get_Control_String (KEEP_NODE_LIST);

	if (str_ptr != NULL) {
		Print (1);
		keep_nodes.File_Type ("Keep Node List File");

		keep_nodes.Open (Network_Filename (str_ptr));
	}

	//---- link node equivalance ----
	
	str_ptr = Get_Control_String (LINK_NODE_EQUIVALENCE);

	if (str_ptr != NULL) {
		Print (1);
		node_string.File_Type ("Link Node Equivalence File");

		node_string.Create (New_Filename (str_ptr));
	}

	//---- get the pocket lane lengths ----

	Print (1);

	num = Highest_Control_Group (POCKET_LENGTHS_FOR_FACILITY_x, 0);

	if (num >= EXTERNAL) num = EXTERNAL - 1;

	for (i=1; i <= num; i++) {
		str_ptr = Get_Control_String (POCKET_LENGTHS_FOR_FACILITY_x, i);
	
		if (str_ptr != NULL) {
			Print (1, "Pocket Lengths for Facility Type %d = %s meters", i, str_ptr);

			while (str_ptr != NULL) {
				str_ptr = Get_Double (str_ptr, &dvalue);

				if (dvalue < 0.0 || dvalue > 2000.0) {
					Error ("Pocket Length %.1lf for Facility %d is Out of Range (0..2000)", dvalue, i);
				}
				if (!pocket_len [i].Add (Round (dvalue))) {
					Error ("Adding Pocket Lane Length");
				}
			}
		}
	}

	//---- get the pocket to facility ----

	str_ptr = Get_Control_String (POCKET_TO_FACILITY_BY_AREA_TYPE);

	if (str_ptr != NULL) {
		pocket_to_flag = true;

		Print (1, "Pocket To Facility Types by Area Type = %s", str_ptr);

		while (str_ptr != NULL) {
			str_ptr = Get_Integer (str_ptr, &lvalue);

			if (lvalue < 0 || lvalue > EXTERNAL) {
				Error ("Pocket To Facility %d is Out of Range (0..%d)", lvalue, EXTERNAL);
			}
			if (!pocket_to.Add (lvalue)) {
				Error ("Adding Pocket To Facility");
			}
		}
	}

	//---- get the signal warrants ----

	Print (1);

	num = Highest_Control_Group (SIGNAL_WARRANT_FOR_AREA_TYPE_x, 0);

	for (i=1; i <= num; i++) {
		str_ptr = Get_Control_String (SIGNAL_WARRANT_FOR_AREA_TYPE_x, i);

		if (str_ptr != NULL) {
			Area_Type type_rec (i);

			Print (1, "Signal Warrant for Area Type %d = %s", i, str_ptr);

            str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer));

			type_rec.Primary (Facility_Code (buffer));

			str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer));

			type_rec.Secondary (Facility_Code (buffer));

			str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer));

			if (*buffer == '\0') {
				str_cpy (buffer, sizeof (buffer), "ACTUATED");
			}

			type_rec.Signal_Type (Signal_Code (buffer));

			str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer));

			if (*buffer == '\0') {
				str_cpy (buffer, sizeof (buffer), "SINGLE_RING");
			}

			type_rec.Ring_Type (Ring_Code (buffer));

			if (!area_type.Add (&type_rec)) goto type_error;
		}
	}

	//---- get the sign warrants ----

	Print (1);

	num = Highest_Control_Group (STOP_WARRANT_FOR_AREA_TYPE_x, 0);

	for (i=1; i <= num; i++) {
		str_ptr = Get_Control_String (STOP_WARRANT_FOR_AREA_TYPE_x, i);

		if (str_ptr != NULL) {
			type_ptr = area_type.Get (i);

			lvalue = Facility_Code (str_ptr);

			if (type_ptr == NULL) {
				Area_Type type_rec (i);
				type_rec.All_Stop (lvalue);

				if (!area_type.Add (&type_rec)) goto type_error;
			} else {
				type_ptr->All_Stop (lvalue);
			}
			Print (1, "Stop Warrant for Area Type %d = %s", i, str_ptr);
		}
	}

	//---- activity location side offset ----

	str_ptr = Get_Control_String (ACTIVITY_LOCATION_SIDE_OFFSET);

	if (str_ptr != NULL) {
		Get_Double (str_ptr, &location_side);

		if (location_side < 0.0 || location_side > 100.0) {
			Error ("Activity Location Side Offset %.2lf is Out of Range (0..100)", location_side);
		}
	}
	Print (2, "Activity Location Side Offset = %.2lf meters", location_side);

	//---- get the facility type access flags ----

	str_ptr = Get_Control_String (FACILITY_TYPE_ACCESS_FLAGS);

	if (str_ptr != NULL) {
		for (i=1; str_ptr != NULL; i++) {
			str_ptr = Get_Token (str_ptr, buffer, sizeof (buffer));

			if (*buffer == '\0') break;

			access_flag [i] = (*buffer == '1' || *buffer == 't' || *buffer == 'T' || 
				*buffer == 'y' || *buffer == 'Y');
		}
	}
	Print (2, "Facility Type Access Flags = ");

	for (i=1; i <= EXTERNAL; i++) {
		if (i > 1) {
			Print (0, ", %d", access_flag [i]);
		} else {
			Print (0, "%d", access_flag [i]);
		}
	}

	//---- get the number of access points ----

	str_ptr = Get_Control_String (MAXIMUM_ACCESS_POINTS);

	if (str_ptr == NULL) goto control_error;

	Get_Integer (str_ptr, &max_splits);

	if (max_splits < 1 || max_splits > 20) {
		Error ("Maximum Number of Access Points %d is Out of Range", max_splits);
	}
	Print (2, "Maximum Number of Access Points Per Link = %d", max_splits);

	//---- get the min split length ----

	str_ptr = Get_Control_String (MINIMUM_SPLIT_LENGTHS);

	if (str_ptr == NULL) goto control_error;

	Print (2, "Minimum Split Lengths = %s meters", str_ptr);

	for (i=1; str_ptr != NULL; i++) {
		str_ptr = Get_Integer (str_ptr, &lvalue);

		if (lvalue == 0) continue;

		if (lvalue < 40 || lvalue > 4000) {
			Error ("Minimum Split Length %d is Out of Range (40-4000)", lvalue);
		}
		lvalue = Round (lvalue);

		type_ptr = area_type.Get (i);

		if (type_ptr == NULL) {
			Area_Type type_rec (i);
			type_rec.Split_Len (lvalue);

			if (!area_type.Add (&type_rec)) goto type_error;
		} else {
			type_ptr->Split_Len (lvalue);
		}
	}

	//---- get the cell size ----

	str_ptr = Get_Control_String (CELL_SIZE);

	if (str_ptr != NULL) {
		Get_Double (str_ptr, &cell_size);

		if (cell_size < 4.0 || cell_size > 9.0) {
			Error ("Cell Size %.2lf is Out of Range (4..9)", cell_size);
		}
	}
	Print (2, "Cell Size = %.2lf meters", cell_size);

	//---- get the minimum link length ----

	str_ptr = Get_Control_String (MINIMUM_LINK_LENGTH);

	if (str_ptr != NULL) {
		Get_Double (str_ptr, &dvalue);

		if (dvalue < cell_size || dvalue > 100.0) {
			Error ("Minimum Link Length %.1lf is Out of Range (%.1lf..100.0)", dvalue, cell_size);
		}
	} else {
		dvalue = cell_size * 5.0;
	}
	min_length = Round (dvalue);
	Print (2, "Minimum Link Length = %.1lf meters", UnRound (min_length));

	//---- get the maximum length factor ----

	str_ptr = Get_Control_String (MAXIMUM_LENGTH_TO_XY_RATIO);

	if (str_ptr != NULL) {
		Get_Double (str_ptr, &max_length_factor);

		if (max_length_factor < 1.0 || max_length_factor > 2.0) {
			Error ("Maximum Length to XY Ratio %.1lf is Out of Range (1.0..2.0)", max_length_factor);
		}
	}
	Print (2, "Maximum Length to XY Ratio = %.2lf", max_length_factor);

	//---- get the maximum connection angle ----

	str_ptr = Get_Control_String (MAXIMUM_CONNECTION_ANGLE);

	if (str_ptr != NULL) {
		Get_Integer (str_ptr, &lvalue);

		if (lvalue < 90 || lvalue > 180) {
			Error ("Maximum Connection Angle %d is Out of Range (90..180)", lvalue);
		}
		max_angle = compass.Num_Points () * lvalue / 360;
	}
	Print (2, "Maximum Connection Angle = %d degrees", max_angle * 360 / compass.Num_Points ());

	//---- uturn flag ----

	uturn_flag = Get_Control_Flag (ADD_UTURN_TO_DEADEND_LINKS);

	if (uturn_flag) {
		Print (1, "U-Turns will be added to Dead-End Links");
	} else {
		Print (1, "U-Turns will not be added to Dead-End Links");
	}

	//---- get the setback distance ----

	str_ptr = Get_Control_String (INTERSECTION_SETBACK_DISTANCE);

	if (str_ptr != NULL) {
		Get_Double (str_ptr, &dvalue);

		if (dvalue < 0.0 || dvalue > 20.0) {
			Error ("Intersection Setback Distance %.1lf is Out of Range (0.0..20.0)", dvalue);
		}
	} else {
		dvalue = 0.0;
	}
	setback = Round (dvalue);
	Print (2, "Intersection Setback Distance = %.1lf meters", UnRound (setback));

	//---- get the external zone number ----

	str_ptr = Get_Control_String (FIRST_EXTERNAL_ZONE_NUMBER);

	if (str_ptr != NULL) {
		Get_Integer (str_ptr, &ext_zone);

		if (ext_zone < 0 || ext_zone > 10000) {
			Error ("External Zone Number %d is Out of Range (0..10000)", ext_zone);
		}
	} else {
		ext_zone = 0;
	}
	Print (2, "First External Zone Number = %d", ext_zone);

	//---- get the zone connector flag ----

	str_ptr = Get_Control_String (KEEP_ZONE_CONNECTORS_AS_LOCALS);

	if (str_ptr != NULL) {
		Print (1, "Keep Zone Connectors as Locals = %s", str_ptr);

		connect_flag = Get_Control_Flag (KEEP_ZONE_CONNECTORS_AS_LOCALS);
	}

	//---- get the replicate MPO network ----

	str_ptr = Get_Control_String (REPLICATE_MPO_NETWORK);

	if (str_ptr != NULL) {
		Print (1, "Replication MPO Network = %s", str_ptr);

		replicate_flag = Get_Control_Flag (REPLICATE_MPO_NETWORK);
	}

	//---- collapse nodes flag ----

	if (Get_Control_String (COLLAPSE_NODES_FLAG) != NULL) {
		collapse_flag = Get_Control_Flag (COLLAPSE_NODES_FLAG);
	}
	if (collapse_flag) {
		Print (2, "Extra Nodes will be Removed from the Network");
	} else {
		Print (2, "All Nodes in the Network will be Kept");
	}

	//---- update node range ----

	str_ptr = Get_Control_String (UPDATE_NODE_RANGE);

	if (str_ptr != NULL) {
		update_flag = true;
		Print (2, "Update Node Range = %s", str_ptr);

		if (!update_nodes.Add_Ranges (str_ptr)) {
			Error ("Adding Update Nodes");
		}
	}

	//---- update node file ----

	str_ptr = Get_Control_String (UPDATE_NODE_FILE);

	if (str_ptr != NULL) {
		update_flag = update_node_flag = true;
		Print (1);
		update_node_file.File_Type ("Update Node File");

		if (!update_node_file.Open (Project_Filename (str_ptr))) {
			Error ("Opening %s", update_node_file.File_Type ());
		}
	}

	//---- update link range ----

	str_ptr = Get_Control_String (UPDATE_LINK_RANGE);

	if (str_ptr != NULL) {
		update_flag = true;
		Print (2, "Update Link Range = %s", str_ptr);

		if (!update_links.Add_Ranges (str_ptr)) {
			Error ("Adding Update Links");
		}
	}

	//---- update link file ----

	str_ptr = Get_Control_String (UPDATE_LINK_FILE);

	if (str_ptr != NULL) {
		update_flag = update_link_flag = true;
		Print (1);
		update_link_file.File_Type ("Update Link File");

		if (!update_link_file.Open (Project_Filename (str_ptr))) {
			Error ("Opening %s", update_link_file.File_Type ());
		}
	}

	//---- delete node range ----

	str_ptr = Get_Control_String (DELETE_NODE_RANGE);

	if (str_ptr != NULL) {
		delete_flag = true;
		Print (2, "Delete Node Range = %s", str_ptr);

		if (!delete_nodes.Add_Ranges (str_ptr)) {
			Error ("Adding Delete Nodes");
		}
	}

	//---- delete node file ----

	str_ptr = Get_Control_String (DELETE_NODE_FILE);

	if (str_ptr != NULL) {
		delete_flag = delete_node_flag = true;
		Print (1);
		delete_node_file.File_Type ("Delete Node File");

		if (!delete_node_file.Open (Project_Filename (str_ptr))) {
			Error ("Opening %s", delete_node_file.File_Type ());
		}
	}

	//---- delete link range ----

	str_ptr = Get_Control_String (DELETE_LINK_RANGE);

	if (str_ptr != NULL) {
		delete_flag = true;
		Print (2, "Delete Link Range = %s", str_ptr);

		if (!delete_links.Add_Ranges (str_ptr)) {
			Error ("Adding Delete Links");
		}
	}

	//---- delete link file ----

	str_ptr = Get_Control_String (DELETE_LINK_FILE);

	if (str_ptr != NULL) {
		delete_flag = delete_link_flag = true;
		Print (1);
		delete_link_file.File_Type ("Delete Link File");

		if (!delete_link_file.Open (Project_Filename (str_ptr))) {
			Error ("Opening %s", delete_link_file.File_Type ());
		}
	}

	//---- link detail file ----

	str_ptr = Get_Control_String (LINK_DETAIL_FILE);

	if (str_ptr != NULL) {
		Print (1);
		detail_flag = true;

		if (!detail_file.Open (Project_Filename (str_ptr))) {
			Error ("Opening %s", detail_file.File_Type ());
		}
		lane_use_flag = Network_File_Flag (NEW_LANE_USE);
	}

	//---- get the projection data ----

	projection.Read_Control ();

	coord.Set_Projection (projection.Input_Projection (), projection.Output_Projection ());

	Set_Projection (&coord);

	return;

	//---- error message ----

control_error:
	Error ("Missing Control Key = %s", Current_Key ());

type_error:
	Error ("Adding Area Type Record");
}