Stand With Ukraine

Thursday, July 28, 2011

Bash: kill processes with a given name pattern

As we know the kill command in linux permits to kill a process using its id. kill -9 tries to kill your process even harder. But what if I have many similar processes? We can use the cut function that I recently saw here as shown below:

What it does is: searches the list of processes for lines containing bootstrap.py, then extracts the process id from each line and kills the process.

Saturday, July 23, 2011

C++: Allocating 2D array using new

This link explains how to allocate 2d arrays with variable dimensions:
the link. I find that it is a very useful and clear explanation.

Thursday, July 21, 2011

NCO

NCO is a very powerfull tool for editing netcdf files. In this post I will be writing some useful commands.

1. Delete a dimension of size 1 (the dimension name is level):
ncwa -a level directions_qc_amno.nc directions_qc_amno1.nc

2. Copy data from one to the other netcdf file, if possible recognize common dimensions:
ncks file1.nc file2.nc

3. Rename a dimension
ncrename -d rlat,latitude directions_qc_amno.nc

4. permute dimensions(make longitude first and the latitude second):
ncpdq -a longitude,latitude infocell.nc infocell.nc 

5. Rename the variable lat to latitude:
ncrename -v lat,latitude infocell.nc

6. Take difference of variable x in 2 files:
ncbo -v x --op_typ='-' infocell.nc infocell_1.nc infocell_diff.nc

7. Operation on variables in a file. Here the values of the variable are changed and the attributes added.
ncap -O -s "air=(air-512.81)/0.01" filename.nc temp.nc
ncap -O -s "air=short(air);air@add_offset=512.81;air@scale_factor=0.01" temp.nc filename.nc
taken from http://jisao.washington.edu/data/nco/
8. Concantenating netcdf files along the record dimension.
ncrcat runoff_file_name_pattern total_runoff_af.nc

9. Subsetting by index and by coordinate values:
ncks -d lon,0,4 -d lat,2,9,2 in.nc out.nc
ncks -d lon,10.,20. -d lat,80.,90. in.nc out.nc


Used data from: