#!/bin/bash # compute the toal precipitation (L+S) # usage: # getTotalPrec.sh RainFile SnowFile # assuming the variable name for rain : pr # snow : prsn #copyright @ http://scriptdemo.blogspot.com ncVarNameRain="pr" ncVarNameSnow="prsn" if [ $# -eq 2 ]; then RainFile=$1; SnowFile=$2 else sed -n '3,6p' getTotalPrec.sh exit fi [ ! -e ${RainFile} ] && echo "${RainFile} does not exist!" && exit [ ! -e ${SnowFile} ] && echo "${SnowFile} does not exist!" && exit oriP="ori_${RainFile}" cp ${RainFile} ${oriP} eval "ncks -A -v ${ncVarNameSnow} ${SnowFile} ${oriP}" eval "ncap2 -s 'prtot=${ncVarNameRain}+${ncVarNameSnow}' ${oriP} new${oriP}" ncks -v prtot new${oriP} total_${oriP} && rm -f new${oriP} eval "ncrename -v prtot,${ncVarNameRain} total_${oriP} && rm -f ${oriP}" |
Monday, August 15, 2011
[Bash] manipulate variables from different netcdf files using nco
Friday, July 8, 2011
[VBA] List folders using VBS
#copyright @ http://scriptdemo.blogspot.com parentFolder="C:\" Dim fso, folderOBJ, subF set fso=CreateObject("Scripting.FileSystemObject") if fso.folderexists(parentFolder) then set folderOBJ=fso.GetFolder(parentFolder) For Each subF in folderOBJ.SubFolders 'WScript.Echo subF.Name msgbox("Found " & subF.Name) Next else msgbox(parentFolder & " dose not exist") end if |
Sunday, June 26, 2011
[Matlab] create a faked colorbar in matlab
function newhcb=plotcolorbar(hcbar,cmap) % create a colorbar using true color (fill function) to replace the existing one created by matlab itself % Usage: newHandle=plotcolorbar(h,cmap) % copyright @ http://scriptdemo.blogspot.com if nargin==0 hcbar=findobj('tag','Colorbar'); if isempty(hcbar) disp('No colorbar obj found!!!'); return; end cmap=colormap; elseif nargin==1 if ishandle(hcbar) cmap=colormap; else cmap=hcbar; hcbar=findobj('tag','Colorbar'); if isempty(hcbar) disp('No colorbar obj found!!!'); return; end end end oriNPlot=get(gcf,'NextPlot'); set(gcf,'NextPlot','add'); oriH=gca; oriPos=get(oriH,'position'); cbarpos=get(hcbar,'position'); cbarxlim=get(hcbar,'xlim'); cbarxtick=get(hcbar,'xtick'); cbarxticklabel=get(hcbar,'xticklabel'); cbarylim=get(hcbar,'ylim'); cbarytick=get(hcbar,'ytick'); cbaryticklabel=get(hcbar,'yticklabel'); newHcbar=axes('Position',cbarpos,'tag','newColorbar'); NC=size(cmap,1); if isempty(cbarxtick) %vertical yy=linspace(cbarylim(1),cbarylim(2),NC+1); yy=[yy(1:NC); yy(1:NC); yy(2:NC+1); yy(2:NC+1); yy(1:NC)]; xx=[cbarxlim(1) cbarxlim(2) cbarxlim(2) cbarxlim(1) cbarxlim(1)]; xx=xx'*ones(1,NC); else %horizontal xx=linspace(cbarxlim(1),cbarxlim(2),NC+1); xx=[xx(1:NC); xx(1:NC); xx(2:NC+1); xx(2:NC+1); xx(1:NC)]; yy=[cbarylim(1) cbarylim(2) cbarylim(2) cbarylim(1) cbarylim(1)]; yy=yy'*ones(1,NC); end for jj=1:NC hf=fill(xx(:,jj),yy(:,jj),cmap(jj,:)); set(hf,'linestyle','none'); hold on; end set(newHcbar,'YAxisLocation',get(hcbar,'YAxisLocation'), ... 'XAxisLocation',get(hcbar,'XAxisLocation'), ... 'YScale',get(hcbar,'YScale'), 'XScale',get(hcbar,'XScale'), ... 'TickDir',get(hcbar,'TickDir'), ... 'xlim',cbarxlim,'ylim',cbarylim, ... 'xtick',cbarxtick,'ytick',cbarytick, ... 'xticklabel',cbarxticklabel,'yticklabel',cbaryticklabel,... 'fontweight',get(hcbar,'fontweight'), 'fontsize',get(hcbar,'fontsize'),'linewidth',get(hcbar,'linewidth'), ... 'XDir',get(hcbar,'XDir'),'YDir',get(hcbar,'YDir'), 'XColor',get(hcbar,'XColor'),'YColor',get(hcbar,'YColor')); set(gcf,'NextPlot',oriNPlot); set(gcf,'CurrentAxes',oriH); colorbar off; set(oriH,'position',oriPos) if nargout>0, newhcb = newHcbar; end |
Subscribe to:
Posts (Atom)