help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Writing netcdf file using a function


From: Lester Anderson
Subject: Writing netcdf file using a function
Date: Fri, 26 Feb 2016 16:42:56 +0000

Hello,

Quick query. I have a short program that calls one function but I
would like to write the processed grid data out.

I have tried nccreate and ncwrite, but not too sure where these need to apply:

clear
data = ncread("Gz_1VD.grd","z");
lon = ncread("Gz_1VD.grd","longitude");
lat = ncread("Gz_1VD.grd","latitude");
data=rot90(data,1); % for some reason this is needed for use of GMT grids!
data=flipud(data); % for some reason this is needed for use of GMT grids!
azi=45
elev=50
order=1
gradients(data,azi,elev,order);


where the function does this:

function dr=gradients(data,azi,elev,order)

% Directional derivative

azi=azi*pi/180; elev=elev*pi/180;
[dy,dx]=gradient(data);
dt1=-dy*sin(azi)-dx*cos(azi);

% Sunshading

cAzi=cos(azi); sAzi=sin(azi); tElev=tan(elev);
top=(1.0-dx.*cAzi.*tElev-dy.*sAzi.*tElev);
bottom=sqrt(1.0+dx.*dx+dy.*dy)+sqrt(1.0+tElev.*tElev);
sun=top./bottom;

% Derivative ratio

dt2=-dy*sin(azi+pi/2)-dx*cos(azi+pi/2);
dr=atan2(dt1,abs(dt2).^order);

figure(1);
md=mean(data(:)); sd=std(data(:));
subplot(1,2,1); imagesc(data,[md-2*sd md+2*sd]); axis equal; axis
tight; axis off; axis xy;
title('Data'); colormap(gray(256));

sd=std(dt1(:));
subplot(1,2,2); imagesc(dt1,[-2*sd 2*sd]); axis equal; axis tight;
axis off; axis xy;
title('Directional Derivative'); colormap(gray(256));

figure(2);
subplot(1,2,1); imagesc(sun); axis equal; axis tight; axis off; axis xy;
title('Sunshaded'); colormap(gray(256)); brighten(-0.5);

subplot(1,2,2); imagesc(dr); axis equal; axis tight; axis off; axis xy;
title('Derivative Ratio'); colormap(gray(256));

The variable I want to write out to a netcdf grid is dr. Tested the
ncreate/ncwrite in the function itself and nothing happened.

Thanks for any pointers; sure it is something very simple!
Lester



reply via email to

[Prev in Thread] Current Thread [Next in Thread]