100 Days of Code Log R1d7

Today, I found this amazing site for Fortran tutorials - https://masuday.github.io/fortran_tutorial/index.html

I went through the tutorials which was organized in a very neat way. Then I proceeded to implement the following simple code.

Make a tridiagonal matrix with 1 on diagonal and 0 or on off-diagonal with an arbitrary $n$. See the following example for $n=5$. $$ \displaystyle{\begin{bmatrix} 1 & 0 & 0 & 0 & 0 \ 0 & 1 & 0 & 0 & 0 \ 0 & 0 & 1 & 0 & 0 \ 0 & 0 & 0 & 1 & 0 \ 0 & 0 & 0 & 0 & 1 \end{bmatrix} } $$ The following is my implementation.

100 Days of Code Log R1D6

Today had been two part work. Initially, I did some Data Structures lessons from Udacity course. Then, at night, I tried to implement the Single objective optimisation method called fibonacci method using Fortran. There is some mistake that I need to correct. I will share the updated code tmw. Here’s the faulty one!

100 Days of Code Log R1D5

Today I was able to cover a lot of stuff - mainly the exercises and some Gnuplot basics.

I’ve already made a blog post on the first exercise I worked on - Generate Logistic Map in Fortran. It was fun. Also, later I took a look at the solution available at the mooc’s repository. I was really impressed by how the code is organized. Everything looked neat and debuggable. Inspiring code, one could say! Here’s the link to the Julia set code in MOOC Github repository. This is where I came to know that functions in fortran can act upon an array without being specially defined for arrays.

100 Days of Code Log R1D4

Today, I was introduced to I/O in Fortran. Its a little complex for seemingly simple task. But, its good to have all the bells and whistles known upfront. Here is a sample program on input output.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
program inputoutput
    use, intrinsic :: iso_fortran_env, only : sp=>real32, dp=>real64, error_unit, input_unit
    implicit none
    integer :: unit_nr, istat
    integer :: a, b
    character(len=1024) :: msg
    ! IO Opening a file
    open(newunit=unit_nr, file='text.txt', access='sequential', action='write', &
    status='new', form='formatted', iostat=istat, iomsg=msg)
    if (istat /= 0 ) then ! Handling Error
        write (unit=error_unit, fmt='(3A)') 'error: ', trim(msg), istat
        stop 1
    end if
    ! Writing to a file
    write (unit=unit_nr, fmt='(A)') 'hello world'
    write (unit=unit_nr, fmt='(F4.2)') x
    close(unit=unit_nr)
    
    print *, "Enter the number"
    ! Reading input from user
    read(unit=input_unit, fmt='(I2)', iostat=istat, iomsg=msg) a
    print *, a+5

end program inputoutput

In Fortran IO, there are few points to note.

100 Days of Code Log R1D3

Today I had learnt about the procedures and intrinsic procedures in Fortran. Basically, a procedure can be of two types

  • function
  • subroutine

Functions

The functions are procedures which return a value which can either be

  1. Given the same name as function name in which case the syntax will be.
1
2
3
4
5
6
7
integer function function_name(inputname)
	implicit none
	integer, intent(in) :: inputname
	.
	.
	function_name = 1234..
end function function_name

In this case, the return type is given before function keyword. Also, note that in fortran, values are passed by reference by default. Hence, if the input is only an input, intent(in) needs to be mentioned. Other intents are out, inout.

100 Days of Code Log R1D1

This is my first day in the 100 Days of Code challenge. Today, I had started with the “Fortran for Scientific Computing” course in Future Learn. It had been a great start.

I had learnt about the precision available in fortran for various number data types. For example, the follow program deals with the single and double precision for real numbers.

Fix White Flash in Dark Mode in Firefox

I use the dark mode plugin for firefox so that there’s less eye strain at night times. But, since the new UI change of firefox, there’s flash of white light before the dark mode kicks in, even when the firefox theme is set to dark. I was looking for a solution and found the following in reddit.