comparison extra/ncArray/inst/ncarray_example_file.m @ 12682:e97980ace11d octave-forge

add example of using ncArray
author abarth93
date Mon, 24 Aug 2015 08:51:53 +0000
parents extra/ncArray/inst/private/ncarray_example_file.m@34b88e26cfd2
children
comparison
equal deleted inserted replaced
12681:0c936bf960f6 12682:e97980ace11d
1 % create an example NetCDF file with the name filename and given data
2
3 function ncarray_example_file(filename,data)
4
5 dtype = 'double';
6 sz = size(data);
7
8 % Variables
9 nccreate(filename,'lon','Format','classic','Datatype',dtype,...
10 'Dimensions',{'x',sz(1), 'y',sz(2)});
11 ncwriteatt(filename,'lon','long_name','Longitude')
12 ncwriteatt(filename,'lon','units','degrees_east')
13
14 nccreate(filename,'lat','Datatype',dtype,'Dimensions',{'x',sz(1), 'y',sz(2)});
15 ncwriteatt(filename,'lat','long_name','Latitude')
16 ncwriteatt(filename,'lat','units','degrees_north')
17
18 nccreate(filename,'time','Datatype',dtype,'Dimensions',{'time',1});
19 ncwriteatt(filename,'time','long_name','Time')
20 ncwriteatt(filename,'time','units','days since 1858-11-17 00:00:00 GMT')
21
22 nccreate(filename,'SST','Datatype',dtype,'Dimensions',...
23 {'x',sz(1), 'y',sz(2), 'time',1});
24 ncwriteatt(filename,'SST','missing_value',single(9999))
25 ncwriteatt(filename,'SST','_FillValue',single(9999))
26 ncwriteatt(filename,'SST','units','degC')
27 ncwriteatt(filename,'SST','long_name','Sea Surface Temperature')
28 ncwriteatt(filename,'SST','coordinates','lat lon')
29
30 ncwrite(filename,'SST',data);
31
32 % Copyright (C) 2012,2013,2015 Alexander Barth <barth.alexander@gmail.com>
33 %
34 % This program is free software; you can redistribute it and/or modify
35 % it under the terms of the GNU General Public License as published by
36 % the Free Software Foundation; either version 2 of the License, or
37 % (at your option) any later version.
38 %
39 % This program is distributed in the hope that it will be useful,
40 % but WITHOUT ANY WARRANTY; without even the implied warranty of
41 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 % GNU General Public License for more details.
43 %
44 % You should have received a copy of the GNU General Public License
45 % along with this program; If not, see <http://www.gnu.org/licenses/>.
46