Personal tools
You are here: Home / cmgui / Wiki / Reading exnode and exelem files
Navigation
Log in


Forgot your password?
 

Reading exnode and exelem files

Introduction

The following is a brief overview of some of the code base used for reading in data from exnode and exelem files. The overview is based on what I learnt when updating Cmgui so that it could read in files created on windows systems (which have carriage return characters as well as line feeds).

cmgui.c

The main routine for Cmgui is in 'cmgui.c'. It is a short routine that takes care of reading in any command line options and then creates a Cmiss_command_data object based on the command line arguments. The routine 'Cmiss_command_data_main_loop' is then executed, which is the main program loop which handles reading in commands and executing them.

command/cmiss.c

The 'Cmiss_command_data_main_loop' source is in 'command/cmiss.c'. This is a key file which includes the .h files for most of the cmgui source. When new commands, computed fields, etc are added into cmgui then 'cmiss.c' must be edited so that cmgui is aware of the new commands.

The 'Cmiss_command_data_main_loop' runs the routine 'Event_dispatcher_main_loop'.

When a command is typed, program flow cascades down from routine to routine. For example the line 'gfx read node bob.exnode' results in an event being dispatched which then makes a call to the 'execute_command' routine in 'cmiss.c'. This in turn calls 'execute_command_gfx' which calls 'execute_command_gfx_read'. This is the main routine concerned with reading in data from files. It calls the appropriate routine for dealing with reading in curves, data, elements, nodes, objects, regions and wave_front_objs. In our case we are reading in nodes so a call is made to 'gfx_read_nodes'.

The 'gfx_read_nodes' routine includes a bunch of code to check the file extension, set the correct directory for the file, create a region for the new nodes and eventually if all is well it creates an IO_stream object to take care of the actual reading. This IO_stream object is called 'input_file'. After the input_file object is created it is opened for reading using 'IO_stream_open_for_read' and then reading is done by the 'read_exregion_file' routine.

finite_element/import_finite_element.c

The 'read_exregion_file' routine can be found in the source file 'finite_element/import_finite_element.c'. This routine is concerned with reading in nodes and elements from a stream (usually a file on the file system but possibly a file stored in Cmgui memory as is the way zinc does it). The read_exregion_file routine calls other routines like 'read_FE_node' as well as lower level IO stream routines such as 'IO_stream_scan', 'IO_stream_read_string', 'IO_Stream_getc' and 'IO_stream_get_location_string'. The read_FE_node routine and others like it also end up making calls to the various IO_stream functions.

general/io_stream.c

The io stream routines that deal with scanning a stream, reading in strings and the like are found in 'general/io_stream.c'. The routines in this file create a nice interface to the io stream manipulation functions while taking care of the details of working with different stream types (eg memory, gzip, bz2 or a normal file). IO_stream_scan is designed to be equivalent to a standard fscanf on a stream. IO_stream_getc is an equivalent to the standard gfetc on a stream.