Skip to content

Commit

Permalink
clase2 fortran
Browse files Browse the repository at this point in the history
  • Loading branch information
fedebenelli committed Nov 24, 2022
1 parent 6907cac commit a8de962
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 15 deletions.
65 changes: 64 additions & 1 deletion unidad6/fortran/clase2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ un Makefile.

### Makefiles: Ejemplo básico

- Ejemplo
- Ejemplo: `makefiles` dir

Algo mejor:

Expand Down Expand Up @@ -114,6 +114,10 @@ Contiene
- flinter.
- fortran-linter.

Un set de guidelines de estilo:

[https://flinter.readthedocs.io/en/latest/fortran_guidelines.html](https://flinter.readthedocs.io/en/latest/fortran_guidelines.html)

### Linters: fprettify

- No es un linter, es un formateador
Expand Down Expand Up @@ -279,8 +283,67 @@ También permite agregar páginas estáticas, ya sean html o markdown.
`Ford` se maneja con un único archivo de configuración donde se especifican los
detalles de qué documentar y cómo.

- Ejemplo: `feos`

## Otras cosas
Existen varias herramientas para mejorar Fortran en mal estado. No se puede
llegar a evaluarlas dentro del scope del curso (ni yo llegué a usarlas), pero
dejo el link a una compilación por si es de utilidad para alguien:


\small
- Roquefort: transforma bloques `common` a módulos y solo importa
variables/rutinas que se usan
- [https://github.com/NLESC-JCER/roquefort](https://github.com/NLESC-JCER/roquefort)

- f90wrap: Genera wrappers para objetos que no son compatibles con f2py (lo que sigue)
- [https://github.com/jameskermode/f90wrap](https://github.com/jameskermode/f90wrap)

Más herramietnas:

- [https://github.com/Beliavsky/Fortran-Tools#refactoring](https://github.com/Beliavsky/Fortran-Tools#refactoring)
\normalsize

# Interfaces con otros lenguajes

## C

\tiny
A partir de Fortran 2003 se puede correr código Fortran desde C (y viceversa)

#### Fortran
```fortran
!function.f09
subroutine f(x, y) bind(C, name="f_fortran")
use iso_c_binding, only: c_double
real(c_double), intent(in) :: x
real(c_double), intent(out) :: y
y = x**2
end subroutine f
```

#### C
```C
// cside.c
#include <stdio.h>
extern double f_fortran(double [], double []);
main()
{
double x=2.0; double y=5.0; double z;
z = f_fortran(&x, &y);
printf("x: %f, y: %f, z: %f",
x, y, z);
}
```
\Tiny
#### Compilación
```bash
gfortran -c function.f90
gcc -o exec cside.c function.f90
```
\normalsize

## Python

### f2py
Expand Down
4 changes: 2 additions & 2 deletions unidad6/fortran/clase2/f2py/noandaposta.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module noanda
contains

subroutine noanda_sub(x, y)
type(obj) :: x
real :: y
type(obj), intent(in) :: x
real, intent(out) :: y

y = sum(x%att)
end subroutine noanda_sub
Expand Down
24 changes: 12 additions & 12 deletions unidad6/fortran/clase2/linters/bad.f90
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
program main
!comment
implicit none
real*8 x
real*4 y(3)
integer i
! comment
implicit none
real(8) x
real(4) y(3)
integer i

x = 2.3
y =[2, 3, 1]
x = 2.3
y =[2, 3, 1]

x = x + x + x + 2 + 3 + 2 + 1 + 2 + 4 + 2341 + x + x + 123 + 4 + 5 + 2 + x + 1 + 3 + 1 + 2 + 5 + 2 + 10
x = x + x + x + 2 + 3 + 2 + 1 + 2 + 4 + 2341 + x + x + 123 + 4 + 5 + 2 + x + 1 + 3 + 1 + 2 + 5 + 2 + 10

do i = 1 , 3
y( i) = 2 * i ** 2
end do

do i = 1 , 3
y( i) = 2 * i ** 2
end do

end program main
Binary file modified unidad6/fortran/clase2/slides.pdf
Binary file not shown.

0 comments on commit a8de962

Please sign in to comment.