# include # include # include "triangle_nodefile_random.h" /******************************************************************************/ double *triangle_node_random ( int m, int n ) /******************************************************************************/ /* Purpose: triangle_node_random() generates N random nodes in M dimensions. Licensing: This code is distributed under the GNU LGPL license. Modified: 15 August 2024 Author: John Burkardt */ { int i; int j; double *x; x = ( double * ) malloc ( m * n * sizeof ( double ) ); for ( j = 0; j < n; j++ ) { for ( i = 0; i < m; i++ ) { x[i+j*m] = drand48 ( ); } } return x; } /******************************************************************************/ void triangle_node_write ( char *filename, int m, int n, double x[] ) /******************************************************************************/ /* Purpose: triangle_node_write() writes a triangle node file. Licensing: This code is distributed under the GNU LGPL license. Modified: 15 August 2024 Author: John Burkardt Input: char *FILENAME, the output filename. int M, the spatial dimension. int N, the number of points. double X[M*N], the data. */ { int i; int j; FILE *output; /* Open the file. */ output = fopen ( filename, "wt" ); if ( ! output ) { fprintf ( stderr, "\n" ); fprintf ( stderr, "triangle_node_write(): Fatal error!\n" ); fprintf ( stderr, " Could not open the file '%s'.\n", filename ); exit ( 1 ); } /* triangle() requires a header line. vertices dimension attributes markers */ fprintf ( output, "%d %d 0 0\n", n, m ); /* Write the data. */ for ( j = 0; j < n; j++ ) { fprintf ( output, "%d", j ); for ( i = 0; i < m; i++ ) { fprintf ( output, " %24.16g", x[i+j*m] ); } fprintf ( output, "\n" ); } /* Close the file. */ fclose ( output ); return; }