Skip to content

Instantly share code, notes, and snippets.

View tenomoto's full-sized avatar

Takeshi Enomoto tenomoto

View GitHub Profile
@tenomoto
tenomoto / dont_show_height_label.ncl
Created December 19, 2013 03:37
gsn_csm_pres_hgt() shows height labels and "Height (km)" on the YR axis by default. To get rid of them, set gsnPresHgtHeightLabelOn to False.
res@gsnPresHgtHeightLabelOn = False
@tenomoto
tenomoto / pdf2eps
Created April 28, 2015 07:59
Create EPS from PDF with white margin cropped using pdfcrop and pdftoeps
#!/bin/sh
if [ $# -lt 1 ]; then
echo "Usage :: $0 input.pdf [p1 p2 ...]"
exit
fi
in=${1}
shift
pdfcrop ${in}
crop=`basename -s .pdf ${in}`-crop
if [ $# -eq 0 ]; then
@tenomoto
tenomoto / glatwgt.awk
Last active June 12, 2016 23:39
Calculate Gaussian points and weights at arbitrary precision with the Fourier-Newton method in MPFR enabled GNU Awk
# gawk -M -v PREC=100 -v lgaqd=1 -v nlat=120 -f glatwgt.awk
function abs(x)
{
return (x > 0) ? x : -x
}
function gamma(y, c)
{
c[1] = 1 / 12
@tenomoto
tenomoto / ann.awk
Last active October 29, 2021 00:34
Scaling factor for the Fourier coefficients of Legendre polynomials
function abs(n)
{
return (n>0)? n : -n
}
function f1(n, i)
{
return sqrt(1 - 1 / (4 * n * n))
}
@tenomoto
tenomoto / pdfextract
Created December 8, 2015 08:37
Extract pages from PDF and save them to separate files
#!/bin/sh
FNAME=$1
shift
for PAGE in $@; do
gs -q -dBATCH -dNOPAUSE -dFirstPage=$PAGE -dLastPage=$PAGE \
-dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode \
-sDEVICE=pdfwrite -sOutputFile=${FNAME%\.pdf}_$PAGE.pdf $FNAME
done
@tenomoto
tenomoto / searchword.vim
Created December 9, 2015 02:13
Count occurrence of a particular word in vim
" n prevents replace
" in line
:s/word//gn
" in file
:%s/word//gn
@tenomoto
tenomoto / splitwfm
Created January 22, 2016 02:01
Split JMA one-week ensemble using wgrib
#!/bin/bash
N=25 # number of ensembles
NFT0=9 # number of forecast time (including FT=0)
NFT=9
VNAME=""
while getopts ":v:n:" opt; do
case $opt in
v) VNAME=$OPTARG ;;
n) NFT=$OPTARG ;;
\?) echo 'usage:: splitwfm [-v VARNAME -n NFT] FNAME'
@tenomoto
tenomoto / legendre.cc
Created March 10, 2016 00:03
Legendre polynomials using GiNaC
#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
ex LegendrePoly(const symbol &x, int n)
{
ex PKer = pow(x * x - 1, n);
return normal(1 / (pow(2, n) * factorial(n)) * diff(PKer, x, n));
@tenomoto
tenomoto / grd2grb.f90
Created March 30, 2016 08:49
Replace values in ECMWF initial condition in GRIB format
program grd2grb
use grib_api
implicit none
character(len=*), parameter :: &
ifname = "ICMSHepc8INIT", gfname = "out.grd", ofname = "out.grb"
integer, parameter :: &
ug = 41, ntrunc = 21, nv = (ntrunc + 2) * (ntrunc + 1)
real*4, dimension(nv) :: sh
@tenomoto
tenomoto / read_ascii.h
Last active April 27, 2016 07:28
Read the whole content of a text file and return C++ std::vector
#include <iostream>
#include <fstream>
#include <vector>
template <typename T>
std::vector<T> read_ascii(std::string fname, bool verbose = false)
{
std::vector<T> data;
std::ifstream ifs (fname);
T buf;
if (ifs.is_open())