Posts

Showing posts from 2014

Usefull tips for FORTRAN

Few tips for FORTRAN: Get arguments from command line character (len = 20) :: arg1 call getarg (1, arg1) if (len_trim(arg1) == 0) then     print*,'No Arg1 provided' stop endif read (arg1, *) nsteps In this example FORTRAN takes the first arguments and read as number of steps. Always use the warning if loop for multiple argument, sometimes one might miss to give inputs of one argument and it becomes difficult to debug the code. Use bash shell command in FORTRAN character (len = 1024) :: command command = 'cp file1 folder1/' call system ( trim(command)) In this example file1 is copied to folder1/ Print integer padded by zeros Let say we would like to print 4 digit integer as 0001 0002 .... 9999 only thing we have use a formatting string I4.4 and we are done. Get number of lines in a data file open(unit,file='filename') nline = 0 do     read (unit, *, end = 10)     nlines = nlines + 1 end do 10 close(unit)

VMD TIPS

LOAD MULTIPLE TRAJECTORIES IN VMD set filelist [glob *.pdb] foreach file $filelist {mol new $file waitfor all}  

Mac - OS and VIM Tips

Mac - OS and VIM Tips To get the desired feature edit ~/.vimrc file Enable text color filetype plugin indent on  syntax on Jump to beginning/end of a line using Shift Home/End  :map <ESC>[H <Home>  :map <ESC>[F <End>  :imap <ESC>[H <C-O><Home>  :imap <ESC>[F <C-O><End>  :cmap <ESC>[H <Home>  :cmap <ESC>[F <End> Jump from one word to another using the option + forward arrow and backword arrow combinations  :map <ESC>f el  :imap <ESC>b <C-o>b  :imap <ESC>f <C-o>el  :cmap <ESC>f el

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          end if      end do     if (count == (state - 1)) not_sorted = .FALSE. end do end program sort_data

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