0% found this document useful (0 votes)
5 views

CH332_16Jan

The document outlines a computational chemistry course focusing on FORTRAN format statements, pseudocode, and flowcharts. It explains the syntax and usage of format statements for input/output, along with examples of edit descriptors for various data types. Additionally, it covers the Arrhenius equation and the calculation of activation energy using kinetic data and gnuplot for data visualization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

CH332_16Jan

The document outlines a computational chemistry course focusing on FORTRAN format statements, pseudocode, and flowcharts. It explains the syntax and usage of format statements for input/output, along with examples of edit descriptors for various data types. Additionally, it covers the Arrhenius equation and the calculation of activation energy using kinetic data and gnuplot for data visualization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

CH 332

Computational Chemistry

Course Instructor: Dr. Debdas Dhabal

Department of Chemistry, IIT Guwahati


16 January 2024
Outline

ØFORTRAN Format statements


ØPseudocode and Flowcharts
FORTRAN Format statements

o So far, we have used a free format input/output

o This uses default rules

o No control over the appearance of the input and output

o Often the programmer wants to specify some particular input/output format

No worries! FORTRAN has a


solution

Use “format” statement


Syntax of “format” statement
Let’s say we want to input/output from/to the terminal

free format:
read(*,*)
write(*,*)
a user-defined
format:

read(*, ’(format-code)’) list-of-variable read(*,label) list-of-variable


write(*, ‘(format-code)’) list-of-variable write(*,label) list-of-variable
label format (format-code)

read(*, ’(2i3,2f10.5)’) i1,i2,f1,f2 read(*,11) i1,i2,f1,f2


write(*, ‘(2i3,2f10.5)’) i1,i2,f1,f2 write(*,11) i1,i2,f1,f2
11 format (2i3,2f10.5)
Format edit descriptors

Edit descriptor tells the system how to handle certain types of input/output values

Common format codes


The most common format code letters are:
A (or e) - text string/characters
D (or d) - double precision numbers, exponent notation
E (or e) - real numbers, exponent notation
F (or f) - real numbers, fixed point format
I (or i) - integer
X (or x) - horizontal skip (space)
/ - vertical skip (newline)
Format edit descriptors
Purpose Edit Descriptors
Reading/writing INTEGERs Iw Iw.m nIw
Reading/writing REALs Decimal form Fw.d nFw.d
Exponential form Ew.d nEw.d Ew.dEe
Characters A Aw nAw
Positioning Horizontal nX
Tabbing Tn TLn TRn
Vertical /

Symbols: You can write field


o n: optional repeat count descriptors A, D, E, F, G, and
o w: the number of characters in the external field I without the n, w, m, d, or e field
o m: the minimum number of characters to be used indicators
o d: the number of decimal points
o e: the number of digits in the exponent part Then, default values are used based on data type
A few examples

Ø Format code in the read/write statement Ø Using a label read/write statement and
directly separately write the format code

Output: both “c” and “d” are written with 10 characters and
3 decimal points (look at the “fort.20” file formed
0.025 0.005
by these codes to understand it better
Different variants of edit descriptors of real numbers

Output:

0.025 0.005
0.02500 0.00500
0.025 0.005
0.250E-01 0.500E-02
0.250E-0001 0.500E-0002

Edit descriptor: nFw.d, with n=2, w=10, and d=3


Edit descriptor: nFw.d, with n=2, w=10, and d=5
Edit descriptor: nFw.d, with n=2, w=15, and d=3
Edit descriptor: nEw.d, with n=2, w=15, and d=3
Edit descriptor: nEw.dEe, with n=2, w=15, d=3, and e=4
Different variants of edit descriptors of integer numbers

Output:
24102 10
24102 10
24102 10
0000024102 0000000010

Edit descriptor: nIw, with n=2 and w=5


Edit descriptor: nIw, with n=2 and w=10
Edit descriptor: nIw, with n=2 and w=15
Edit descriptor: nIw.m, with n=2, w=15, and m=10
Different variants of edit descriptors of character

Output:
Test Hello
Test Hello World
Test Hello World
Test Hello World

Edit descriptor: nAw, with n=2 and w=5


Edit descriptor: nAw, with n=2 and w=11
Edit descriptor: nAw, with n=2 and w=15
Edit descriptor: nAw, with n=2 and w=20
Different variant of edit descriptors of positioning

Output:
Test Hello World
Test Hello World
Hello World Test
Hello World

Edit descriptors: two separate nAw and one nX


Edit descriptor: two nAw and one TRn
Edit descriptor: one nAw, one nX, and one TLn
Edit descriptor: one nAw, and one TLn
Notes on Formatting

Output:

24102
10
*** 10
3.14159265359
3.1416
3.14159274101
**********

Why do these appear?

Note the use of d0: d stands for "times ten to the


power”. In this example, it signifies
3.14159265359 x 100
Flowchart and Pseudocode

vThe flowchart and pseudocode help programmers organize the proposed problem
and write/debug the program.

vThe flowchart and pseudocode are written from top to bottom in the way the program
flows

vWe use a few shapes to draw a flowchart: Some common shapes are

An oval represents a start or end point of the program

A parallelogram represents the point of input or output of the program


Flowchart and Pseudocode

A rectangle represents a process/operations, assignment of a value to a variable

A diamond indicates a point where a decision is made

A hexagon represents the beginning of a repetition

A double-lined rectangle references another program/subprogram/subroutine/modules that


is written outside the main program.

An arrow indicates the direction of the flow of the algorithm

A circle or a pentagon are used as a connector, or to combine flow line

An open-ended rectangle is used to annotate or comment


There are two types of connector

On-page connector Off-page connector

We use this to connect the flow on


We use this to connect the flow on a different page
the same page
Pseudocode
o An outline or rough draft of the program
o It describes computer algorithms with a correct flow using a combination of natural language
and programming language
o You don’t need to follow the exact coding syntax
o No set of rules for its exact implementation

Let’s understand this by considering an example of A humanized version of the computer code
Ø Deciding what to do when approaching a stop light: Drive through it, slow down in preparation to stop, or stop
fully.
If the light is red, come to a quick
stop before the intersection

Your decision
depends upon Your thought If the light is green, drive through
process might go the intersection
which color the
light is. something like this:
If the light is yellow, slow down
and prepare to stop
Some rules (not so strict) of pseudocode

o The usual Fortran symbols are used for arithmetic operations (+, -, *, /, **).

o Symbolic names are used to indicate the quantities being processed.

o Certain Fortran keywords can be used, such as PRINT, WRITE, READ, etc.

o Indentation should be used to indicate branches and loops of instruction.


An example problem
For a given value, ’’Limit’’, what is the smallest positive integer Number for which
the sum
Sum = 1 + 2 + ... + Number
is greater than ’’Limit’’. What is the value of this Sum?

FORTRAN Code:
Pseudocode of the above problem
Program find_num
Declare Integer limit, num, sumnum

Display "Enter the value for which the sum is to exceed"


Input limit

Set num = 0
Set sumnum = 0

Loop i from 1 to limit


If sumnum <= limit Then
num = num + 1
sumnum = sumnum + num
Else
Display "The limit you used=", limit
Display "Smallest num=", num
Display "The value of sum=", sumnum
Exit Loop
End If
End Loop

Stop
End Procedure
Flowchart of the above problem
Start

if sumnum
<= limit
Enter limit

True
False
increment
Initilize sum by 1
num=0 add num by
sumnum=0 sumnum

Do loop (i= display


1 to limit sumnum
and num

End
Flowchart and pseudocode
for single-alternative
selection (IF/THEN)

Numerical Methods for Engineers by Chapra and Canale


Flowchart and pseudocode for supplementary selection or
branching constructs

Numerical Methods for Engineers by Chapra and Canale


The Arrhenius Equation

Let’s take an example of a simple


first-order reaction
A → Product

Rate= k*[A] k is the rate constant

How rate constant depend on the temperature?


!"!
𝑘= 𝐴𝑒 #$

kà rate constant
Aà pre-exponential factor (frequency factor)
Eaà Activation energy
Rà gas constant
Tà Temperature

increase in T à increase in k
Calculation of activation energy

Kinetic data

#k(s-1) T(K)
0.022 1400
0.07 1460
0.21 1520
0.686 1580
1.578 1620

Using the equation:

T1=1400 K
T2=1620 K
Ea = 366226.850979 J/Mol
Calculation of activation energy
Kinetic data
#k(s-1) T(K) Ea can also be calculated from the slope of the ln k versus
0.022 1400 1/T graph
0.07 1460
0.21 1520
0.686 1580
1.578 1620

# lnk 1/T
-3.816713 0.000714
-2.659260 0.000685
-1.560648 0.000658
-0.376878 0.000633
Using gnuplot package you can
0.456158 0.000617 fit these data
gnuplot

A portable command line and GUI-


based program to plot functions It works on the most common OS:
and data. It can generate both 2- Linux, Windows, and Mac.
and 3-dimensional plots.

You can download the latest


version from Alternatively in Linux: apt-get
http://www.gnuplot.info/downloa install gnuplot
d.html

To check if Gnuplot is already installed: which gnuplot


Or to check gnuplot version: gnuplot --version
Calculation of activation energy
To plot a data file:

plot filename using with linepoints


To fit a data file:
gnuplot> f(x)=m*x+c
gnuplot> fit f(x) 'lnk_1byT.dat' u 2:1 via m,c

Final set of parameters Asymptotic Standard Error


======================= ==========================
m = -43800.5 +/- 1336 (3.051%)
c = 27.3782 +/- 0.885 (3.233%)
Comparison of fitted data and the raw data

1
Raw data
Fitted line
0

−1

ln (k)
−2

−3

−4
6.0x10−4 6.4x10−4 6.8x10−4 7.2x10−4
1/T
Activation energy from this method:

m = -Ea/R = -43800.5 K

Ea = 364157.357 J/Mol
How to create a pdf file of the image in gnuplot?

o Plot datafile
o Set x/y-label; can be updated at a later stage

o save the above operations in a script with an extension “.par” and quit
gnuplot

o Open “.par” file and add these lines to save the output to a postscript
file
o set term enhanced post color
o set out “test.ps”
Process and Job-control

THANK YOU!

You might also like