# include <math.h>
# include <stdlib.h>
# include <stdio.h>
# include <string.h>
# include <time.h>
# include "freefem_msh_io.h"
/******************************************************************************/
char ch_cap ( char ch )
/******************************************************************************/
/*
Purpose:
CH_CAP capitalizes a single character.
Discussion:
This routine should be equivalent to the library "toupper" function.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
19 July 1998
Author:
John Burkardt
Parameters:
Input, char CH, the character to capitalize.
Output, char CH_CAP, the capitalized character.
*/
{
if ( 97 <= ch && ch <= 122 )
{
ch = ch - 32;
}
return ch;
}
/******************************************************************************/
int ch_eqi ( char ch1, char ch2 )
/******************************************************************************/
/*
Purpose:
CH_EQI is TRUE (1) if two characters are equal, disregarding case.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
13 June 2003
Author:
John Burkardt
Parameters:
Input, char CH1, CH2, the characters to compare.
Output, int CH_EQI, is TRUE (1) if the two characters are equal,
disregarding case and FALSE (0) otherwise.
*/
{
int value;
if ( 97 <= ch1 && ch1 <= 122 )
{
ch1 = ch1 - 32;
}
if ( 97 <= ch2 && ch2 <= 122 )
{
ch2 = ch2 - 32;
}
if ( ch1 == ch2 )
{
value = 1;
}
else
{
value = 0;
}
return value;
}
/******************************************************************************/
int ch_to_digit ( char ch )
/******************************************************************************/
/*
Purpose:
CH_TO_DIGIT returns the integer value of a base 10 digit.
Example:
CH DIGIT
--- -----
'0' 0
'1' 1
... ...
'9' 9
' ' 0
'X' -1
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
13 June 2003
Author:
John Burkardt
Parameters:
Input, char CH, the decimal digit, '0' through '9' or blank are legal.
Output, int CH_TO_DIGIT, the corresponding integer value. If the
character was 'illegal', then DIGIT is -1.
*/
{
int digit;
if ( '0' <= ch && ch <= '9' )
{
digit = ch - '0';
}
else if ( ch == ' ' )
{
digit = 0;
}
else
{
digit = -1;
}
return digit;
}
/******************************************************************************/
void ffmsh_2d_data_example ( int v_num, int e_num, int t_num, double v_xy[],
int v_l[], int e_v[], int e_l[], int t_v[], int t_l[] )
/******************************************************************************/
/*
Purpose:
FFMSH_2D_DATA_EXAMPLE returns example FFMSH data.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
21 December 2014
Author:
John Burkardt
Parameters:
Input, int V_NUM, the number of vertices.
Input, int E_NUM, the number of boundary edges.
Input, int T_NUM, the number of triangles.
Output, double V_XY[2*V_NUM], vertex coordinates.
Output, int V_L[V_NUM], vertex labels.
Output, int E_V[2*E_NUM], edge vertices.
Output, int E_L[E_NUM], vertex labels.
Output, int T_V[3*T_NUM], triangle vertices.
Output, int T_L[T_NUM], triangle labels.
*/
{
int e_l_save[10] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
int e_v_save[2*10] = {
11, 6,
6, 4,
4, 1,
1, 2,
2, 5,
5, 9,
9, 13,
13, 15,
15, 14,
14, 11 };
int t_l_save[18] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int t_v_save[3*18] = {
1, 3, 4,
7, 2, 5,
9, 7, 5,
8, 6, 4,
12, 8, 7,
12, 11, 8,
3, 1, 2,
7, 3, 2,
7, 8, 3,
4, 3, 8,
6, 8, 11,
12, 7, 10,
11, 12, 14,
10, 9, 13,
12, 10, 13,
7, 9, 10,
12, 13, 15,
14, 12, 15 };
int v_l_save[15] = {
1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 };
double v_xy_save[2*15] = {
-0.309016994375, 0.951056516295,
-0.809016994375, 0.587785252292,
-0.321175165867, 0.475528256720,
0.309016994375, 0.951056516295,
-1.000000000000, 0.000000000000,
0.809016994375, 0.587785252292,
-0.333333334358, 0.000000000000,
0.237841829972, 0.293892623813,
-0.809016994375, -0.587785252292,
-0.321175165867, -0.475528259963,
1.000000000000, 0.000000000000,
0.206011327827, -0.391856835534,
-0.309016994375, -0.951056516295,
0.809016994375, -0.587785252292,
0.309016994375, -0.951056516295 };
i4vec_copy ( v_num, v_l_save, v_l );
r8mat_copy ( 2, v_num, v_xy_save, v_xy );
i4vec_copy ( e_num, e_l_save, e_l );
i4mat_copy ( 2, e_num, e_v_save, e_v );
i4vec_copy ( t_num, t_l_save, t_l );
i4mat_copy ( 3, t_num, t_v_save, t_v );
return;
}
/******************************************************************************/
void ffmsh_2d_data_print ( char *title, int v_num, int e_num, int t_num,
double v_xy[], int v_l[], int e_v[], int e_l[], int t_v[], int t_l[] )
/******************************************************************************/
/*
Purpose:
FFMSH_2D_DATA_PRINT prints FFMSH data.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
21 December 2014
Author:
John Burkardt
Parameters:
Input, char *TITLE, a title.
Input, int V_NUM, the number of vertices.
Input, int E_NUM, the number of boundary edges.
Input, int T_NUM, the number of triangles.
Input, double V_XY[2*V_NUM], vertex coordinates.
Input, int V_L[V_NUM], vertex labels.
Input, int E_V[2*E_NUM], edge vertices.
Input, int E_L[E_NUM], vertex labels.
Input, int T_V[3*T_NUM], triangle vertices.
Input, int T_L[T_NUM], triangle labels.
*/
{
printf ( "\n" );
printf ( "%s\n", title );
i4vec_print ( v_num, v_l, " Vertex labels:" );
r8mat_transpose_print ( 2, v_num, v_xy, " Vertex coordinates:" );
i4vec_print ( e_num, e_l, " Edge labels:" );
i4mat_transpose_print ( 2, e_num, e_v, " Edge vertices:" );
i4vec_print ( t_num, t_l, " Triangle labels:" );
i4mat_transpose_print ( 3, t_num, t_v, " Triangle vertices:" );
return;
}
/******************************************************************************/
void ffmsh_2d_data_read ( char *ffmsh_filename, int v_num, int e_num, int t_num,
double v_xy[], int v_l[], int e_v[], int e_l[], int t_v[], int t_l[] )
/******************************************************************************/
/*
Purpose:
FFMSH_2D_DATA_READ reads data from an FFMSH file.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
22 December 2014
Author:
John Burkardt
Parameters:
Input, char *FFMSH_FILENAME, the FFMSH filename.
Input, int V_NUM, the number of vertices.
Input, int E_NUM, the number of boundary edges.
Input, int T_NUM, the number of triangles.
Output, double V_XY[2*V_NUM], vertex coordinates.
Output, int V_L[V_NUM], vertex labels.
Output, int E_V[2*E_NUM], edge vertices.
Output, int E_L[E_NUM], vertex labels.!
Output, int T_V[3*T_NUM], triangle vertices.
Output, int T_L[T_NUM], triangle labels.
*/
{
FILE *ffmsh_unit;
int i1;
int i2;
int i3;
int i4;
int ierror;
int j;
int length;
double r1;
double r2;
char text[255];
char *text_pointer;
ffmsh_unit = fopen ( ffmsh_filename, "rt" );
if ( ! ffmsh_unit )
{
fprintf ( stderr, "\n" );
fprintf ( stderr, "FFMSH_2D_DATA_READ - Fatal error!\n" );
fprintf ( stderr, " Could not open input file \"%s\"\n", ffmsh_filename );
exit ( 1 );
}
/*
Re