Posts

Fortran code for sorting a data array

This program can be used to sort a set of data array either in ascending or descending order. program sort_data implicit none integer, parameter :: array_length = 100 integer :: i, count double precision, dimension(1:array_length) :: data double precision :: temp logical :: not_sorted open(unit=1, file='data.input', action='read', status='old') read(1,*) (data(i), i=1, array_length) not_sorted = .TRUE. do while (not_sorted)      count = 0      do i = 1, state - 1           temp = data(i) ! if one needs to get ascending order need to change here .LT. to .GT.          if (data(i) .LT. data(i + 1)) then             data(i) = data(i+1)             data(i+1) = temp             count = count          else             count = count + 1         ...

Bash Shell Scripting for file handling

Add two single column file side by side Of same length   awk 'NR==FNR{_[NR]=$0;next}{print $1,$2,_[FNR]}' file2 file1 Of different length awk 'NR==FNR { a[c=FNR]=$0; next }{ printf "%-8s \t %s\n", a[FNR], $0 } END { for(i=FNR+1;i<=c;i++) print a[i] }' file2 file1 Cut n-th column of a file to separate file   awk < infile '{print $n}' > outfile

VIM-Search-TIPS

Image
Search and replace globally :%s/search-string/replace-string/g Search and replace within a range of particular row and column :1,4 /\%1cYYY/ZZZ/g   Search using case sensitive string /abCdEf\C          "Case sensitive /abCdEf\c          "Case insensitive Search and replace interactively :%s/search-string/replace-string/gc

Printf and awk

AWK cat input | awk '{printf "%9.6f %9.6f %9.6f\n", $1, $2, $3}' > output

Handle large statically allocated data in fortran (> 2GB)

Typical error occurs in this case fortranfile.f:someline numbe: relocation truncated to fit: R_X86_64_PC32 against `.bss' fortranfile.f:someline numbe: additional relocation overflows omitted from the output Solution: Compile the fortran file with the following option -mcmodel medium -shared-intel Source Link: Intel Forum

Grace Type Settings

Control code Description \f{x} switch to font named "x" \f{n} switch to font number n \f{} return to original font \R{x} switch to color named "x" \R{n} switch to color number n \R{} return to original color \#{x} treat "x" (must be of even length) as list of hexadecimal char codes \t{xx xy yx yy} apply transformation matrix \t{} reset transformation matrix \z{x} zoom x times \z{} return to original zoom \r{x} rotate by x degrees \l{x} slant by factor x \v{x} shift vertically by x \v{} return to unshifted baseline \V{x} shift baseline by x \V{} reset baseline \h{x} horizontal shift by x \n new line \u begin underline \U stop underline \o begin overline \O stop overline \Fk enable kerning \FK disable kerning \...

Draw dipole vector of a tagged molecule in VMD

Image
It is often needed to visualize the dipole orientation of a tagged molecule. The following steps will guide to achieve this Select the molecule by its resid  Open Tk console from drop down menu of Extensions → Tk Console  Select every atom of the molecule by separate nicknames, by using the following command. Let say we would like to see the dipole moment vector of water molecules, in that case, the following codes need to be used  set ow [atomselect top "type OW"]  set hw1 [atomselect top "type HW1"] set hw2 [atomselect top "type HW2"]  Then set charge of every atom by using the following commands  $ow set charge -1.00 $hw1 set charge -0.5 $hw2 set charge -0.5 Finally open the Etensions → Visualizations → Dipole Moment Watcher The following window will pop up Then select the molecules by its resid and change the color of the dipoles according to your need. One can select maximum of six dipoles to show at a time. The final snap will...