function triangulation_boundary_nodes ( input_node_filename, ... input_triangulation_filename ) %% MAIN is the main program for TRIANGULATION_BOUNDARY_NODES. % % Discussion: % % TRIANGULATION_BOUNDARY_NODES outputs boundary nodes of a triangulation. % % Each connected segment of the boundary is written to a separate file. % % Modified: % % 01 April 2008 % % Author: % % John Burkardt % % Usage: % % triangulation_boundary ( 'node_file.txt'. 'triangle_file.txt' ) % timestamp; fprintf ( 1, '\n' ); fprintf ( 1, 'TRIANGULATION_BOUNDARY_NODES\n' ); fprintf ( 1, ' MATLAB version\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' Identify triangulation nodes on the boundary.\n' ); fprintf ( 1, '\n' ); fprintf ( 1, '* Read a dataset of NODE_NUM points in 2 dimensions;\n' ); fprintf ( 1, '\n' ); fprintf ( 1, '* Read an associated triangulation dataset of \n' ); fprintf ( 1, ' triangles using 3 or 6 nodes;\n' ); fprintf ( 1, '\n' ); fprintf ( 1, '* Determine which nodes are on the boundary;\n' ); fprintf ( 1, '\n' ); fprintf ( 1, '* Print a list of the node coordinates and indices;\n' ); fprintf ( 1, '\n' ); fprintf ( 1, '* Write a file of the boundary node indices.\n' ); fprintf ( 1, '* Write a file of the boundary node coordinates.\n' ); % % Get the number of command line arguments. % if ( nargin < 1 ) fprintf ( 1, '\n' ); fprintf ( 1, 'TRIANGULATION_BOUNDARY_NODES:\n' ); input_node_filename = input( ... ' Please enter the name of the node file (in ''quotes''!).\n' ); end % % If at least two command line arguments, % the second is the triangulation file. % if ( nargin < 2 ) fprintf ( 1, '\n' ); fprintf ( 1, 'TRIANGULATION_BOUNDARY_NODES:\n' ); input_triangulation_filename = input ( ... ' Please enter the name of the triangle file (in ''quotes''!).\n' ); end [ dim_num, node_num ] = dtable_header_read ( input_node_filename ); fprintf ( 1, '\n' ); fprintf ( 1, ' Read the header of "%s"\n.', input_node_filename ); fprintf ( 1, '\n' ); fprintf ( 1, ' Spatial dimension DIM_NUM = %d\n', dim_num ); fprintf ( 1, ' Number of nodes NODE_NUM = %d\n', node_num ); node_xy = dtable_data_read ( input_node_filename, dim_num, node_num ); fprintf ( 1, '\n' ); fprintf ( 1, ' Read the data in "%s"\n', input_node_filename ); r8mat_transpose_print_some ( dim_num, node_num, node_xy, 1, 1, ... dim_num, 5, ' Portion of coordinate data from file:' ); % % Read the triangulation data. % [ triangle_order, triangle_num ] = itable_header_read ( ... input_triangulation_filename ); fprintf ( 1, '\n' ); fprintf ( 1, ' Read the header of "%s"\n', ... input_triangulation_filename ); fprintf ( 1, '\n' ); fprintf ( 1, ' Triangle order = %d\n', triangle_order ); fprintf ( 1, ' Number of triangles = %d\n', triangle_num ); triangle_node = itable_data_read ( input_triangulation_filename, ... triangle_order, triangle_num ); fprintf ( 1, '\n' ); fprintf ( 1, ' Read the data in "%s".\n', ... input_triangulation_filename ); i4mat_transpose_print_some ( triangle_order, triangle_num, ... triangle_node, 1, 1, triangle_order, 5, ... ' Portion of triangle file:' ); % % Determine which nodes lie on the boundary. % if ( triangle_order == 3 ) node_boundary = triangulation_order3_boundary_node ( node_num, ... triangle_num, triangle_node ); elseif ( triangle_order == 6 ) node_boundary = triangulation_order6_boundary_node ( node_num, ... triangle_num, triangle_node ); end % % Write the output file. % node_boundary_num = 0; for node = 1 : node_num if ( node_boundary(node) ) node_boundary_num = node_boundary_num + 1; end end fprintf ( 1, '\n' ); fprintf ( 1, ' Boundary nodes:\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' # Index X Y\n' ); fprintf ( 1, '\n' ); node2 = 0; for node = 1 : node_num if ( node_boundary(node) ) node2 = node2 + 1; node_boundary_xy(1:2,node2) = node_xy(1:2,node); fprintf ( 1, ' %8d %8d %14f %14f\n', ... node2, node, node_xy(1:2,node) ); end end % % Write a file containing the boundary node indices. % node2 = 0; for node = 1 : node_num if ( node_boundary(node) ) node2 = node2 + 1; node_indices(node2) = node; end end node_indices_filename = 'boundary_node_indices.txt'; header = 0; itable_write ( node_indices_filename, 1, node_boundary_num, ... node_indices, header ); fprintf ( 1, '\n' ); fprintf ( 1, ' The file "%s" lists the boundary node indices.\n', ... node_indices_filename ); % % Write a file containing the boundary node coordinates. % output_filename = 'boundary_nodes.txt'; header = 0; dtable_write ( output_filename, dim_num, node_boundary_num, ... node_boundary_xy, header ); fprintf ( 1, '\n' ); fprintf ( 1, ' The file "%s" lists the boundary node coordinates.\n', ... output_filename ); fprintf ( 1, '\n' ); fprintf ( 1, 'TRIANGULATION_BOUNDARY_NODES\n' ); fprintf ( 1, ' Normal end of execution.\n' ); fprintf ( 1, '\n' ); timestamp;