SoFiA 2 Source Code Documentation
SoFiA 2 Source Code Documentation

The Source Finding Application (SoFiA) is a 3D source finding pipeline for radio astronomical data cubes. The source code is freely available on GitLab at https://gitlab.com/SoFiA-Admin/SoFiA-2/. The purpose of this page is to document the source code of SoFiA 2 and provide instructions for reusing source code in other software projects. Please use the menu at the top of this page or click on the following links to access the documentation.

The information on this page is solely directed at programmers who intend to utilise or modify the SoFiA 2 source code. General users of SoFiA 2 will instead want to read the SoFiA 2 user manual and usage instructions which are available on our GitLab wiki at https://gitlab.com/SoFiA-Admin/SoFiA-2/-/wikis/.

General usage of SoFiA 2 classes

SoFiA 2 is entirely written in the C programming language using the C99 standard. The code is written in such a way that it can in principle also be compiled using a C++ compiler. The SoFiA source code is highly modular and fully object-oriented, allowing its individual components to be easily reused in other software projects. Classes are readily identifiable by the fact that their source and header file names start with a capital letter, e.g. String.h and String.c define the class String used for storing and handling character strings. Procedural code is kept in files starting with a lower-case letter, e.g. common.h and common.c define routines that are commonly required by all classes. All header and source files are located in the src/ folder of the SoFiA 2 base directory.

A brief example of how to use SoFiA 2 classes in custom software project is given below:

#include <stdio.h>
#include "String.h"
int main()
{
String *s = String_new("Hello");
String_append(s, ", world!");
printf("%s\n", String_get(s));
return 0;
}
void String_delete(String *self)
Destructor.
Definition String.c:120
String * String_append(String *self, const char *string)
Append string.
Definition String.c:375
String * String_new(const char *string)
Standard constructor.
Definition String.c:73
const char * String_get(const String *self)
Return pointer to C string.
Definition String.c:155
Container class for handling strings (header).
Container class for handling strings.
Definition String.c:55

Here we include the header file String.h which contains the declarations of the String class. We then create a new String object, named s, by calling the constructor, String_new(). Next, the String_append() method is called to append characters to the initial string. Lastly, we print the content of s and then call the destructor, String_delete(), to delete the String object again and release all of its memory.

All classes follow the same naming scheme. For example, to use a class named Foo, include the Foo.h header file and then create new objects as pointers to Foo by by calling the constructor, e.g. Foo *obj = Foo_new(args). Methods will always start with the name of the class and will always require the name of the object to which the method should be applied as their first argument, e.g. Foo_method(obj, args). Most importantly, objects that are no longer required must be explicitly deleted by calling the destructor, Foo_delete(obj), as there is no automatic garbage collection in C. Failure to call the destructor on a object before it gets out of scope will result in a memory leak!

Further information

Contact

tobias.westmeier [at] uwa.edu.au