Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/interkosmos/fortran-nginx
Fortran 2003 interface bindings to nginx-link-function
https://github.com/interkosmos/fortran-nginx
fortran nginx nginx-link-function openresty
Last synced: 2 months ago
JSON representation
Fortran 2003 interface bindings to nginx-link-function
- Host: GitHub
- URL: https://github.com/interkosmos/fortran-nginx
- Owner: interkosmos
- License: isc
- Created: 2020-06-05T12:59:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-15T12:23:05.000Z (about 4 years ago)
- Last Synced: 2024-01-30T09:09:48.285Z (12 months ago)
- Topics: fortran, nginx, nginx-link-function, openresty
- Language: Fortran
- Homepage:
- Size: 1.01 MB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# fortran-nginx
A collection of ISO C binding interfaces to the 3rd party module
[nginx-link-function](https://github.com/Taymindis/nginx-link-function/) for
[nginx](https://nginx.org/), to write server-side web applications in Fortran
2003.Shared memory features (`cache`, `palloc`, `shm`, `shmtx`) that allow resource
sharing between nginx workers are not supported.## Dependencies
Either install [nginx](https://nginx.org/) or
[OpenResty](https://openresty.org/) with the
[nginx-link-function](https://github.com/Taymindis/nginx-link-function/) module.On FreeBSD, build [www/nginx](https://www.freshports.org/www/nginx) with the
`LINK` option enabled from ports:```
# cd /usr/local/ports/www/nginx/
# make config
# make
# make install
```Or, just install a package that has been compiled with `LINK`:
```
# pkg install www/nginx
# pkg info www/nginx
```## Build
Use the provided `Makefile` to build the static library `libfortran-nginx.a`.## Example
Your Fortran web application must implement at least the routines
`ngx_link_func_init_cycle()` and `ngx_link_func_exit_cycle()`. All routines
callable from outside must have the `bind(c)` attribute.```fortran
! webapp.f90
module webapp
use, intrinsic :: iso_c_binding, only: c_null_char
use :: ngx_link_func
implicit none
logical, save :: is_service_on = .false.
contains
subroutine ngx_hello(ctx) bind(c)
character(len=*), parameter :: str = 'Hello, from Fortran!'
type(ngx_link_func_ctx_t), intent(in) :: ctxcall ngx_link_func_log_info(ctx, 'Sending response ...' // c_null_char)
call ngx_link_func_write_resp(ctx = ctx, &
status_code = int(200, kind=8), &
status_line = '200 OK' // c_null_char, &
content_type = 'text/plain' // c_null_char, &
resp_content = str // c_null_char, &
resp_len = int(len(str), kind=8))
end subroutine ngx_hellosubroutine ngx_link_func_exit_cycle(cyc) bind(c)
type(ngx_link_func_cycle_t), intent(in) :: cyccall ngx_link_func_cyc_log_info(cyc, 'Shutting down the web app ...' // c_null_char)
is_service_on = .false.
end subroutine ngx_link_func_exit_cyclesubroutine ngx_link_func_init_cycle(cyc) bind(c)
type(ngx_link_func_cycle_t), intent(in) :: cyccall ngx_link_func_cyc_log_info(cyc, 'Starting the web app ...' // c_null_char)
is_service_on = .true.
end subroutine ngx_link_func_init_cycle
end module webapp
```Compile the shared library `webapp.so` with:
```
$ gfortran -shared -fPIC -o webapp.so webapp.f90 libfortran-nginx.a
```If you use GNU Fortran, make sure that nginx can find the run-time library
`libgfortran.so`.Load the shared library by setting `ngx_link_func_lib` and `ngx_link_func_call`
in your `nginx.conf`:```nginx
# Load shared library if module is not linked statically:
load_module "/usr/local/libexec/nginx/ngx_http_link_func_module.so";server {
listen 80;
server_name localhost;
ngx_link_func_lib "/usr/local/etc/nginx/webapp.so";location / {
ngx_link_func_call "ngx_hello";
}
}
```Start the nginx daemon:
```
# service nginx start
```Then, open `http://localhost/` in your web browser.
## Further Examples
Additional examples can be found in `examples/`:* **hello** returns a basic HTML response.
* **laas** (LAPACK as a Service) solves a system of linear equations *A · x = B* using [LAPACK95](https://www.netlib.org/lapack95/).
* **plot** returns a plot of the [Lotka-Volterra](https://en.wikipedia.org/wiki/Lotka–Volterra_equations) ODEs in PNG format, using the [DISLIN](http://dislin.de/) library. Pass the initial population sizes through HTTP GET parameters `u` and `v` ([example output](examples/plot/output.png)).
* **post** parses HTTP POST parameters.Build the examples with:
```
$ make
```## Licence
ISC