11992
|
1 %% Copyright (C) 2013 Alexander Barth |
|
2 %% |
|
3 %% This program is free software; you can redistribute it and/or modify |
|
4 %% it under the terms of the GNU General Public License as published by |
|
5 %% the Free Software Foundation; either version 2 of the License, or |
|
6 %% (at your option) any later version. |
|
7 %% |
|
8 %% This program is distributed in the hope that it will be useful, |
|
9 %% but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 %% GNU General Public License for more details. |
|
12 %% |
|
13 %% You should have received a copy of the GNU General Public License |
|
14 %% along with this program; If not, see <http://www.gnu.org/licenses/>. |
|
15 |
11988
|
16 |
|
17 fname = [tempname '-octave-netcdf.nc']; |
|
18 |
|
19 |
|
20 nccreate(fname,'temp','Dimensions',{'lon',10,'lat',20}); |
|
21 nccreate(fname,'salt','Dimensions',{'lon',10,'lat',20}); |
|
22 nccreate(fname,'u','Dimensions',{'lon','lat'}); |
|
23 u = randn(10,20); |
|
24 ncwrite(fname,'u',u); |
|
25 |
|
26 u2 = ncread(fname,'u'); |
|
27 assert(isequalwithequalnans(u,u2)); |
|
28 |
|
29 u2 = ncread(fname,'u',[10 5],[inf inf],[1 1]); |
|
30 assert(isequalwithequalnans(u(10:end,5:end),u2)); |
|
31 |
|
32 ncwriteatt(fname,'temp','units','degree Celsius'); |
|
33 assert(strcmp(ncreadatt(fname,'temp','units'),'degree Celsius')); |
|
34 |
|
35 ncwriteatt(fname,'temp','range',[0 10]); |
|
36 assert(isequal(ncreadatt(fname,'temp','range'),[0 10])); |
|
37 |
|
38 ncwriteatt(fname,'temp','float_range',single([0 10])); |
|
39 assert(isequal(ncreadatt(fname,'temp','float_range'),[0 10])); |
|
40 |
|
41 ncwriteatt(fname,'temp','int_range',int32([0 10])); |
|
42 assert(isequal(ncreadatt(fname,'temp','int_range'),[0 10])); |
|
43 |
|
44 info = ncinfo(fname); |
|
45 assert(length(info.Variables) == 3) |
|
46 assert(strcmp(info.Variables(1).Name,'temp')); |
|
47 assert(isequal(info.Variables(1).Size,[10 20])); |
|
48 delete(fname); |
|
49 |
|
50 |
|
51 nccreate(fname,'temp','Dimensions',{'lon',10,'lat',20},'Format','64bit'); |
|
52 delete(fname); |
|
53 |
|
54 nccreate(fname,'temp','Dimensions',{'lon',10,'lat',20},'Format','classic'); |
|
55 info = ncinfo(fname); |
|
56 assert(strcmp(info.Format,'classic')); |
|
57 |
|
58 delete(fname); |
|
59 |
|
60 % netcdf4 |
|
61 |
|
62 nccreate(fname,'temp','Dimensions',{'lon',10,'lat',20},'Format','netcdf4'); |
|
63 ncwriteatt(fname,'temp','uint_range',uint32([0 10])); |
|
64 assert(isequal(ncreadatt(fname,'temp','uint_range'),[0 10])); |
|
65 |
|
66 info = ncinfo(fname); |
|
67 assert(strcmp(info.Format,'netcdf4')); |
|
68 delete(fname) |
|
69 |
|
70 % scalar variable |
|
71 nccreate(fname,'temp','Format','netcdf4','Datatype','double'); |
|
72 ncwrite(fname,'temp',123); |
|
73 assert(ncread(fname,'temp') == 123) |
|
74 delete(fname) |
|
75 |
|
76 |
|
77 % test unlimited dimension with nccreate |
|
78 fname = [tempname '-octave-netcdf.nc']; |
|
79 nccreate(fname,'temp','Dimensions',{'lon',10,'lat',inf}); |
|
80 %system(['ncdump -h ' fname]) |
|
81 |
|
82 info = ncinfo(fname); |
|
83 assert(~info.Dimensions(1).Unlimited) |
|
84 assert(info.Dimensions(2).Unlimited) |
|
85 |
|
86 delete(fname) |
|
87 |