2014年3月27日木曜日

プログラミングメモ

Bash

ncview Quick visualization tool for netCDF.
ncdump Quick literal visualization too for netCDF.

ls -alhtr display the contents in the present directory in details and in order of last modified time.
nohup COMMAND & Keep Linux command running even if disconnected.
[Ctrl] + [c] terminate the process.
top monitor CPU and RAM usage.

LaTeX

Assume you have two files:

paper.tex
ref.bib

Then compile the paper (4 steps in the command line):

pdflatex paper
bibtex paper
pdflatex paper
pdflatex paper

Specify the width of the table (so that it does not exceed from the paper):
\begin{tabular}{|p{5cm}|l|l|l|l|}

MATLAB

Ocean-land map: contourf(map, 0); %where 'map' contains data with NaNs for no data (e.g. land).

"squeeze"
"numel" (instead of "length" or "size")

Cells become really useful when dealing with multiple variable names in a file. For example, the output of PISCES NPZD contains 12 state variables in carbon units. To plot all of them in one figure, use cells and for-loop:

names={'NH4' 'NO3' 'PO4' 'Fer' 'Si' 'PHY' 'PHY2' 'ZOO' 'ZOO2' 'DOC' 'POC' 'GOC'};
for it=1:length(names)
    p1=ncread(file1.nc,names{it});
    p11=squeeze(p1(2,2,1,:));
    plot(p11);
end
legend(names{:})

TEOS-10 Toolbox
A handy matlab functions to calculate thermodynamic properties of seawater. Probably the most useful feature is the calculation of seawater density from temperature, salinity, and pressure, since models do not compute density.

addpath(genpath('~/path2folder/GSW/');

Example: Modeled AR7W cross section

T and S in NEMO output (grid_T file) are potential temperature and practical salinity. Therefore, you need to convert them into conservative temperature and absolute salinity using "gsw_SA_from_SP" and "gsw_CT_from_pt" to calculate potential density anomaly (sigma0) using "gsw_sigma0".

Constants/Unit conversion factor/IDs

id_col='brgkmcy'; %Color IDs
abc='abcdefghijklmnopqrstuvwxyz'; %
sec2day=86400; % # of seconds in a day

Colorbar

colorbar('location','southoutside') % Put the colorbar below the figure

xlabel(colorbar,'titlegoeshere'); % Label Below the colorbar
ylabel(colorbar,'titlegoeshere') % Label on the right of the colorbar
title(colorbar,'titlegoeshere') % Label above the colorbar

Regular Expression

. : A character
[0-9] : A number between 0 and 9
\s : A space
\n : A new line
() : Reserve a block of text
\1 : The first block of text reserved by ()

Vi/Vim

dd Cut
d#d Cut # lines.
yy Copy
y#y Copy # lines.
p Paste
r Replace a single word.
u Undo.
0 Start of line.
$ End of line.
. Repeat the last action.
/dog123 Search for "dog123".
n Search for next matching word (in the previous case, "dog123").
N Search for next matching word in reverse direction.
:%s/before/after/gc Replace "before" with "after" (it will ask for confirmation before the change(s). If you exclude "c" at the end, it will not ask for confirmation).
:w Write (save).
:q Quit. 
:q! Quit without saving.
:wq Write (save) and quit.

0 件のコメント:

コメントを投稿