SCM-NV / ftl

The Fortran Template Library
GNU General Public License v3.0
114 stars 13 forks source link

How to use the library (I'm a beginner) in order to an interface by a template? #11

Open Hakimo2 opened 3 years ago

Hakimo2 commented 3 years ago

I'm trying to use the Fortran template library as show here. I don't know if there's some needed installation in order to use it. Should I download the zip file ? I created a file called task.F90_template as shown in the link and it contains:

T function task(self,ww,pas,cpt ,nb_element,cpt1,dt,dx,p_element,u_prime,u_prime_moins,u_prime_plus,&
&taux,grad_x_u,grad_t_u,grad_x_f,grad_t_f,ax_plus,ax_moins,ux_plus,ux_moins,sm,flux,tab0,tab)
T::self,ww,pas,cpt,nb_element,cpt1,dt,dx,p_element,u_prime,u_prime_moins,u_prime_plus,&
&taux,grad_x_u,grad_t_u,grad_x_f,grad_t_f,ax_plus,ax_moins,ux_plus,ux_moins,sm,flux,tab0,tab
end function task

I don't understand also where to instantiate the template manually using the C preprocessor

#define T integer
#include "task.F90_template"

#define T real
#include "task.F90_template"

I want also to ask about the extension of the file tasks.F90_template since it doesn't get automatically colored.

This is the makefile I am using to compile my code:

all: test
test: tasks.o app_management.o test.o
    gfortran tasks.o app_management.o test.o -o test
tasks.o: tasks.f90
    gfortran -cpp -L/usr/local/lib -lftl -c tasks.f90
app_management.o: app_management.f90
    gfortran -c app_management.f90
test.o: test.f90
    gfortran -c test.f90
clean:
    rm *o test

I am a little bit lost.

robertrueger commented 3 years ago

What you are trying to do there isn't directly related to the Fortran Template library. You made your own template (the task.F90_template file) and are now trying to instantiate for integers and reals. The FTL is a collection of ready made templates, that you can use as they are. It provides templates for commonly used things like dynamically sized arrays, dictionaries, and other popular containers. But you are not using any of those templates, and instead making your own. That is perfectly fine of course, and you can probably draw some inspiration from how the FTL does things for your own templates.

The code you pasted looks pretty much correct to me. Just skip all the FTL related things like "-lftl" and such. If you want to see the preprocessed source code your template instantiations have generated, the "-E" flag of gfortran is quite useful. Try "gfortran -cpp -E tasksf90". That should show you the source code of the instantiations of the "task" function template for integers and reals.