program NN
    implicit none

    integer, parameter     :: input_size  = 2
    integer, parameter     :: hidden_size = 6
    integer, parameter     :: num_layer   = 9

    real*8                 :: LN  (hidden_size, hidden_size, num_layer)
    real*8                 :: LN0 (hidden_size, input_size)
    real*8                 :: LNL (1, hidden_size)
    real*8                 :: BL  (1,1)
    real*8                 :: RL  (1,1)
    real*8                 :: B   (hidden_size, 1, 0:num_layer)

print *, BB([-2.2d0, 0.4d0])

contains

    function BB(x)
        real*8, intent(in)  :: x(input_size)
        real*8              :: BB
        integer             :: i
        real*8              :: inp (hidden_size, 1)
        real*8              :: tmp (hidden_size, 1)

        LN  = 1
        B   = 1
        LN0 = 1
        BL  = 1
        LNL = 1
        tmp = matmul(LN0, reshape(x, [input_size, 1])) + B(:,:, 0)
        inp = sin(tmp)

        do i = 1, num_layer
            tmp             = matmul(LN(:, :, i), inp) + B(:,:,i)
            inp             = tanh(tmp)
        end do

        RL = tanh( matmul(LNL, inp) + BL)
        BB = RL(1,1)
    end function

end program NN
