Skip to content

Instantly share code, notes, and snippets.

View shane5ul's full-sized avatar

Sachin Shanbhag shane5ul

View GitHub Profile
@shane5ul
shane5ul / loopBASH.sh
Last active December 20, 2015 06:59
Loops through files in a directory that match a certain pattern
# matches files/directories with patterns
# like NL300/L0.1, NL10/L0.4 etc
for i in NL*/L*
do
cd $i
echo $i
# do something else
cd ..
done
@shane5ul
shane5ul / loopOctave.m
Last active December 20, 2015 06:59
Loops through files in a directory that match a certain pattern
% matches pattern NL300/L0.1 etc
% stores the result in a cell structure
dirList = glob("NL*/L*");
% Loop through the elements of the cell
for i = 1:length(dirList)
dirname = dirList{i,1}; % pick out individual item
@shane5ul
shane5ul / autocorr.m
Last active December 20, 2015 12:00
Given a vector "x", computes the autocorrelation function A = <x(t) x(0)>/<x(0) x(0)>. If a second argument NA is specified, only the first NA elements of "A" are computed; otherwise, NA = N - 1 by default.
function A = autocorr(x, NA)
%
% Given a vector "x", computes the autocorrelation function A = <x(t) x(0)>/<x(0) x(0)>
%
% If a second argument NA is specified, only the first NA elements of "A" are computed
% Otherwise, NA = N - 1 by default.
%
x = x - mean(x); % subtract mean from "x"
N = length(x); % size of "x"
@shane5ul
shane5ul / blockAverage.m
Created August 1, 2013 02:59
This program computes the block average of a potentially correlated timeseries "x", and provides error bounds for the estimated mean <x>. As input provide a vector or timeseries "x", and the largest block size.
function [v blockVar blockMean] = blockAverage(datastream, maxBlockSize, isplot)
Nobs = length(datastream) % total number of observations in datastream
minBlockSize = 1; % min: 1 observation/block
if(nargin < 2)
maxBlockSize = floor(Nobs/4); % max: 4 blocs (otherwise can't calc variance)
end
if(nargin < 3)
@shane5ul
shane5ul / fooName.f90
Last active December 20, 2015 23:29
write to a file with a variable filename
program foo
character(len=12) :: filename
integer :: i
i = 10
write (filename, "(A4,i0.4,A4)") "file", i,".dat"
print*, trim(filename)
@shane5ul
shane5ul / fooWrite.m
Last active December 20, 2015 23:29
write to files with variable filename
filename = sprintf('file%04d.txt',i) % say i = 10
f1 = fopen(filename, 'w')
% write stuff to the file, ex: fprintf(f1,"%d",25)
fclose(f1)
@shane5ul
shane5ul / exOctave1.m
Created September 18, 2013 16:06
Example of a simple plot in Octave
% Generate Data
x = linspace(0,1);
f1 = x.^2;
f2 = x.^3;
% plot it
h = figure;
plot(x,f1, 'r-', 'LineWidth', 4); hold on;
plot(x,f2, 'b-', 'LineWidth', 4); hold off;
@shane5ul
shane5ul / testCyclicTridiag.f90
Created February 17, 2014 22:46
Program to test solution of cyclic tridiagonal matrix using the Sherman-Morrison formula
!
! Program to test solution of cyclic tridiagonal matrix
!
program testCyclicTridiag
integer, parameter :: n=5
integer :: i, j
double precision :: a(5), b(5), c(5), d(5), x(5)
!
@shane5ul
shane5ul / latexCodeHighlight.tex
Last active August 29, 2015 13:56
Minimal Example of LaTeX file using lstlistings to produce formatted Octave code with highlighting
\documentclass[xcolor=dvipsnames]{beamer}
\usepackage{graphics, listings}
\definecolor{gray}{rgb}{0.85,0.85,0.85}
\lstset{frame=single,
basicstyle=\tiny,backgroundcolor=\color{gray},
language=Octave,
keywordstyle=\color{blue},
stringstyle=\color{BrickRed},
commentstyle=\color{OliveGreen}}
@shane5ul
shane5ul / tridiag_pretty.f90
Created March 5, 2014 19:59
Prettified f90ppr example
!
!--------------------------------------------------------------------------------------------------
subroutine tridiag (a, b, c, r, u, n, code)
! Solves for a vector u of length n the tridiagonal linear set ! from numerical recipes
! m u = r, where a, b and c are the three main diagonals of matrix !
! m(n,n), the other terms are 0. r is the right side vector. !
!--------------------------------------------------------------------------------------------------
integer, parameter :: nmax = 100
integer, intent (in) :: n
double precision, intent (in) :: a (n), b (n), c (n), r (n)