Posts

Showing posts from May, 2014

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