Programming

Adding a new process

This section describes how to add a new process to sedflux-2.0. The code includes a template for a new process called 'new process'. The main files for this process are run_new_process.c and run_new_process.h. You will also need to make additions to a few other files as well.

run_new_process.c

First, you will need to create a file that will define how sedflux will initialize your process as well as run it. For our example, this is done is run_new_process.c.

Define the name of the process as well as it's log domain. This is necessary so that logging messages will be written to the correct file.

#define SED_NEW_PROCESS_PROC_NAME "new process"
#define EH_LOG_DOMAIN SED_NEW_PROCESS_PROC_NAME

Define the function that is called everytime the process is run. The first argument is a pointer to the instance data of this process and the second is the Sed_cube that the process acts on. Initialize the mass balance information.

run_new_process( Sed_process proc , Sed_cube prof )
{
   New_process_t*   data = sed_process_user_data(proc);
   Sed_process_info info = SED_EMPTY_INFO;

When a process is destroyed, it's run function is called with prof == NULL to indicate that any allocated resources should be freed.

         /* Free resources used by data ... */

         /* ... and the data itself */
         eh_free( data );
      }
   }

If the instance data has not yet been initialized (and it needs to be), do it here.

}

The process now acts on the Sed_cube. In this case, we change sea level by a user specified amount.

The mass of the Sed_cube is measured before and after the process is run. If any sediment is (intentionally) added or removed from the system, it should be included here.

Define an init_func for your new process. This function is called everytime sedflux initializes a new instance of your process.

run_new_process.h

Define a structure to hold data for each instance of the new process. In this case, the member param is unique for each instance of the process. Thus, sedflux is able to run different version of the same process.

Declare the functions to run and initialize the new process.

init.c

Now that we have created functions to run and initialize our process, we must add it to the list of processes that sedflux will run. We do this in init.c. All that needs to be done here is to add our new process to the process_list variable,

This variable is a list of all the process that sedflux will run (in the order that they will be run!). Each element of the array tells sedflux the name of the process, the size of the process-specific data structure, the function used to initialize the process, and the function used to run the process.

Add the new process to the list. The new process is run after the river process and before the bed load dumping process.

The remainder of the processes.

Note:
Where you add the new process is important! sedflux will run the processes in the order they are listed here.

processes.h

Finally, we need to add our new header file to the list of process header files in processes.h.

Include the header file for the new process.

Makefile.am

To make sure that our new files are compiled, we must add them to the list of source file in Makefile.am. Include the new .c file in the package
sedflux_SOURCES    += run_new_process.c

as well as its header file.

noinst_HEADERS     += run_new_process.h

Generated on Fri Jan 4 18:04:19 2008 for sedflux by  doxygen 1.5.2