# include <float.h>
# include <math.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <time.h>
# include "fem_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 fem_data_read ( char *node_coord_file_name, char *element_file_name,
char *node_data_file_name, int dim_num, int node_num, int element_num,
int element_order, int node_data_num, double **node_coord, int **element_node,
double **node_data )
/******************************************************************************/
/*
Purpose:
FEM_DATA_READ reads data from a set of FEM files.
Discussion:
This program reads the node, element and data files that define
a finite element geometry and data based on that geometry:
* a set of nodes,
* a set of elements based on those nodes,
* a set of data values associated with each node.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
22 March 2006
Author:
John Burkardt
Parameters:
Input, char *NODE_COORD_FILE_NAME, the name of the node
coordinate file. If this argument is not supplied, the
program terminates.
Input, char *ELEMENT_FILE_NAME, the name of the element
file.
Input, char *NODE_DATA_FILE_NAME, the name of the node
data file.
Input, int DIM_NUM, the spatial dimension.
Input, int NODE_NUM, the number of nodes.
Input, int ELEMENT_NUM, the number of elements.
Input, int ELEMENT_ORDER, the order of the elements.
Input, int NODE_DATA_NUM, the number of data items per node.
Output, double **NODE_COORD. a pointer to a double[DIM_NUM*NODE_NUM],
the coordinates of nodes.
Output, int **ELEMENT_NODE, a point to int[ELEMENT_ORDER*ELEMENT_NUM];
the global index of local node I in element J.
Output, double **NODE_DATA, a pointer to a double[NODE_DATA_NUM*NODE_NUM],
the data values associated with each node.
*/
{
if ( s_len_trim ( node_coord_file_name ) <= 0 )
{
printf ( "\n" );
printf ( "FEM_DATA_READ - Fatal error!\n" );
printf ( " No node coordinate file name was supplied!\n" );
exit ( 1 );
}
*node_coord = r8mat_data_read ( node_coord_file_name, dim_num, node_num );
if ( 0 < s_len_trim ( element_file_name ) )
{
*element_node = i4mat_data_read ( element_file_name, element_order,
element_num );
}
if ( 0 < s_len_trim ( node_data_file_name ) )
{
*node_data = r8mat_data_read ( node_data_file_name, node_data_num,
node_num );
}
return;
}
/******************************************************************************/
void fem_header_print ( int dim_num, int node_num, int element_num,
int element_order, int node_data_num )
/******************************************************************************/
/*
Purpose:
FEM_HEADER_PRINT prints the header to set of FEM files.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
22 March 2006
Author:
John Burkardt
Parameters:
Input, int DIM_NUM, the spatial dimension.
Input, int NODE_NUM, the number of nodes.
Input, int ELEMENT_NUM, the number of elements.
Input, int ELEMENT_ORDER, the order of the elements.
Input, int NODE_DATA_NUM, the number of data items per node.
*/
{
printf ( "\n" );
printf ( " Spatial dimension = %d\n", dim_num );
printf ( " Number of nodes = %d\n", node_num );
printf ( " Number of elements = %d\n", element_num );
printf ( " Element order = %d\n", element_order );
printf ( " Number of node data items = %d\n", node_data_num );
return;
}
/******************************************************************************/
void fem_header_read ( char *node_coord_file_name, char *element_file_name,
char *node_data_file_name, int *dim_num, int *node_num, int *element_num,
int *element_order, int *node_data_num )
/******************************************************************************/
/*
Purpose:
FEM_HEADER_READ reads the sizes of arrays in a set of FEM files.
Discussion:
This program reads the node, element and data files that define
a finite element geometry and data based on that geometry:
* a set of nodes,
* a set of elements based on those nodes,
* a set of data values associated with each node.
and returns the sizes DIM_NUM, NODE_NUM, ELEMENT_NUM, ELEMENT_ORDER,
and NODE_DATA_NUM required to allocate space for these arrays.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
22 March 2006
Author:
John Burkardt
Parameters:
Input, char *NODE_COORD_FILE_NAME, the name of the node
coordinate file. If this argument is not supplied, the
program terminates.
Input, char *ELEMENT_FILE_NAME, the name of the element
file.
Input, char *NODE_DATA_FILE_NAME, the name of the node
data file.
Output, int *DIM_NUM, the spatial dimension, inferred from the
"shape" of the data in the node file.
Output, int *NODE_NUM, the number of nodes, inferred from the
number of lines of data in the node coordinate file.
Output, int *ELEMENT_NUM, the number of elements, inferred from the
number of lines of data in the element file.
Output, int *ELEMENT_ORDER, the order of the elements, inferred from
the number of items in the first line of the element file.
Output, int *NODE_DATA_NUM, the number of data items per node,
inferred from the numbe