5.1 Building a Fortran plugin
dinverfor is a library to help the development of dinver plugins written in Fortran.
First install dinver and dinverfor. dinverfor contains examples of Fortran and C codes in share/:
- test.f: only if you want to develop in Fortran
- test.c: only if you want to develop in C
- testplugin.cpp: needed in all cases, just edit the strings. They control only the texts displayed in the user interface (tag, title, version and description).
- test.pro: project management, see below
test.f or test.c contains three functions (see also comments in source file):
- dinver_init_global(): global initialization
- dinver_init_run( run ): initialization of a particular inversion run, number of parameters, ranges.
- dinver_forward( nd, model, ok, misfit ): computation of forward problem and misfit value.
test.pro must be edited to fit your path configuration (see comments inside the file). By default, Fortran code is used. Follow comments to switch to C code.
| Compilation |
$ qmake
$ make
gcc -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_PLUGIN -DQT_CORE_LIB -DQT_SHARED
-I/usr/local/Trolltech/Qt-shared/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-shared/include/QtCore
-I/usr/local/Trolltech/Qt-shared/include/QtCore -I/usr/local/Trolltech/Qt-shared/include
-I/usr/local/sesarray/include -I. -I. -o test.o test.f
In file test.f:20
subroutine dinver_forward( nd, model, ok, misfit )
1
Warning: Unused parameter ok declared at (1)
test.f:20: warning: unused parameter 'ok'
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_PLUGIN -DQT_CORE_LIB -DQT_SHARED
-I/usr/local/Trolltech/Qt-shared/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-shared/include/QtCore
-I/usr/local/Trolltech/Qt-shared/include/QtCore -I/usr/local/Trolltech/Qt-shared/include
-I/usr/local/sesarray/include -I. -I. -o testplugin.o testplugin.cpp
rm -f libtest.so
g++ -Wl,-rpath,/usr/local/Trolltech/Qt-shared/lib -shared -o libtest.so test.o testplugin.o
-L/usr/local/Trolltech/Qt-shared/lib -Wl,-rpath,/usr/local/sesarray/lib -L/usr/local/sesarray/lib
-lqtbtools -ldinvercore -ldinverfor -lgfortran -lQtCore -L/usr/local/Trolltech/Qt-shared/lib -lz
-lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
|
A file libtest.so is now ready. Start dinver. In plugin selector (first dialog box at startup), click on "Search". Add the path containing the new plugin. The new plugin should appear in the list of available plugins. You can get more debug messages in case of trouble with option '-g'.