Code Snippets Fortran Free Form

Short texts Fortran Free Form 🧑‍💻 Code snippets Fortran Free Form ✍️ Reading lists Fortran Free Form 👀

Iterator Pattern

!> Reference: https://refactoringguru.cn/design-patterns/iterator/go/example module iterator_module use, intrinsic :: iso_fortran_env, only: int8 implicit none private public :: user_t, user_collection_t, user_iterator_t, iterator_t !> Abstract types !> Collection type, abstract :: collection_t contains procedure(collection_t_create_iterator), deferred :: create_iterator end type collection_t !> Iterator type, abstract :: iterator_t contains procedure(iterator_t_has_next), deferred :: has_next procedure(iterator_t_get_next), deferred :: get_next end type iterator_t […]

compile with `gfortran find_gcd.f90`

program main implicit none integer, dimension(5) :: case1 = [2, 5, 6, 9, 10] integer, dimension(5) :: case2 = [7, 5, 6, 8, 3] integer, dimension(2) :: case3 = [3, 3] print “(3i2)”, find_gcd(case1), find_gcd(case2), find_gcd(case3) ! prints 2 1 3 contains integer function gcd(x, y) result(res) ! https://pages.mtu.edu/~shene/COURSES/cs201/NOTES/chap04/gcd.html implicit none integer, intent(in) :: x, […]

Домашнее задание по курсу вычислительной теплопередачи и гидродинамики

! 2011.12.02 02.30 ! ================================= PROGRAM NEYAV ! ================================= IMPLICIT NONE ! ! ================================= ! ОБЪЯВЛЕНИЕ ПЕРЕМЕННЫХ ! ================================= LOGICAL :: Finish=.FALSE., Diff=.TRUE. ! Для автоматизации выбора режима записи данных и включения диффузии INTEGER :: m,n=1,skolko=10 INTEGER, PARAMETER :: Mm=500 REAL :: h, dudx, t=0, a_2, b_2, s_2 & &, slag1,slag2,fim,fip, vspom, fim0, fip0, sm, […]

main.f90

Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure –prefix=/usr –libdir=/usr/lib –libexecdir=/usr/lib –mandir=/usr/share/man –infodir=/usr/share/info –with-bugurl=https://bugs.archlinux.org/ –enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d –with-isl –with-linker-hash-style=gnu –with-system-zlib –enable-__cxa_atexit –enable-cet=auto –enable-checking=release –enable-clocale=gnu –enable-default-pie –enable-default-ssp –enable-gnu-indirect-function –enable-gnu-unique-object –enable-install-libiberty –enable-linker-build-id –enable-lto –enable-multilib –enable-plugin –enable-shared –enable-threads=posix –disable-libssp –disable-libstdcxx-pch –disable-libunwind-exceptions –disable-werror gdc_include_dir=/usr/include/dlang/gdc Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.1.0 (GCC) program main […]

fmincg minimization function ported to Fortran

real function fmincg(length, nn_params, input_layer_size, hidden_layer_size, num_labels, inputdata, y, lambda) implicit none ! Copyright (C) 2001 and 2002 by Carl Edward Rasmussen. Date 2002-02-13 ! (C) Copyright 1999, 2000 & 2001, Carl Edward Rasmussen ! ! Permission is granted for anyone to copy, use, or modify these ! programs and accompanying documents for purposes of […]