Skip to content

Instantly share code, notes, and snippets.

View ivan-pi's full-sized avatar

Ivan Pribec ivan-pi

View GitHub Profile
@ivan-pi
ivan-pi / integer_list_mod.f90
Created March 5, 2021 18:11
Fortran experiment with a fixed-size integer list
module integer_list_mod
implicit none
private
public :: integer_list
type :: index_t
private
integer :: idx
@ivan-pi
ivan-pi / chkend.f90
Created February 16, 2021 09:43
Check processor endianess in Fortran
!> Check Endianess
!>
!> Inspect the endianess of the platform.
!>
!> Based on a program posted by @urbanjost ([email protected])
!> posted at https://github.com/fortran-lang/stdlib/issues/323. The original
!> program was based on ideas from the Code Tuning co-guide, 1998 Lahey Fortran
!> Users' Conference.
!>
!> Author: Ivan Pribec ([email protected])
@ivan-pi
ivan-pi / pcg32.f90
Last active July 12, 2022 10:21
Attempt of porting the PCG random number generator by Melissa O'Neill to Fortran. The code is not tested. Signed integers are used for the state.
!
! PCG Random Number Generation for Fortran
! Ported from the minimal C version by Melissa O'Neill
!
! Copyright 2020 Ivan Pribec <[email protected]>
!
!
! Copyright 2014 Melissa O'Neill <[email protected]>
!
@ivan-pi
ivan-pi / test_spblas.f90
Last active December 25, 2020 23:36
Intel MKL Sparse BLAS matrix-vector product example
! Sparse BLAS matrix-vector product example
!
! The following code demonstrates the creation of
! a CSR matrix, and the sparse matrix-vector product
! using the sparse BLAS functions in Intel MKL.
!
! For linking options for your specific platform see
! the Intel MKL link line advisor located at:
! https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/onemkl/link-line-advisor.html
!
@ivan-pi
ivan-pi / btree_mod.f90
Created December 8, 2020 13:04
Ball tree in Fortran following the one by Jake Vanderplas (see https://gist.github.com/jakevdp/5216193). Construction appears to work, querying is broken!
module nheap_mod
implicit none
private
public :: nheap
integer, parameter :: wp = kind(1.0d0)
@ivan-pi
ivan-pi / qtree_example.f90
Created December 8, 2020 12:56
Quadtree example in Fortran with gnuplot output
module quadtree
! Adapted from the tutorial at https://scipython.com/blog/quadtrees-2-implementation-in-python/
implicit none
integer, parameter :: wp = kind(1.0d0)
type :: qtnode
real(wp) :: c(2)
@ivan-pi
ivan-pi / aoc_day4.f90
Created December 4, 2020 23:20
Advent of Code - Day 4
module day4
use fortran202x_split, only: split
!! The `fortran202x_split` module can be downloaded from:
!! https://github.com/milancurcic/fortran202x_split
implicit none
private
public :: count_passports
module polyfit_mod
implicit none
contains
function vander(x,N,increasing) result(v)
real, intent(in) :: x(:)
integer, intent(in) :: N
logical, intent(in), optional :: increasing
@ivan-pi
ivan-pi / polynomial_companion_matrix.f90
Created November 18, 2020 20:59
Solve the roots of a cubic polynomial using the polynomial companion matrix (depends on LAPACK routine SGEEV)
! Compile with:
! $ gfortran -Wall polynomial_companion_matrix.f90 -o polynomial_companion_matrix -llapack
!
! To run the code:
! $ ./polynomial_companion_matrix
!
program main
implicit none
integer, parameter :: sp = kind(1.0)
integer, parameter :: n = 3
@ivan-pi
ivan-pi / spline_test_driver.f90
Created November 13, 2020 01:28
Example for scicomp.stackexchange thread "Factorization of cubic spline interpolation matrix"
! For an explanation see:
! https://scicomp.stackexchange.com/questions/36261/factorization-of-cubic-spline-interpolation-matrix
!
! compile with:
! gfortran -Wall spline_test_driver.f90 -o spline_test_driver -llapack
!
module spline_test
implicit none