annotate main/netcdf/inst/private/test_netcdf_low_level_interface.m @ 12711:a4de85b2e6a0 octave-forge

fix bug 47014 and make test code work in matlab
author abarth93
date Fri, 19 Feb 2016 13:45:14 +0000
parents bd0a4b380d35
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11992
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
1 %% Copyright (C) 2013 Alexander Barth
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
2 %%
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
3 %% This program is free software; you can redistribute it and/or modify
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
4 %% it under the terms of the GNU General Public License as published by
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
5 %% the Free Software Foundation; either version 2 of the License, or
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
6 %% (at your option) any later version.
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
7 %%
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
8 %% This program is distributed in the hope that it will be useful,
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
9 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
10 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
11 %% GNU General Public License for more details.
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
12 %%
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
13 %% You should have received a copy of the GNU General Public License
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
14 %% along with this program; If not, see <http://www.gnu.org/licenses/>.
6f80e9b5a5cb add copyright (2)
abarth93
parents: 11989
diff changeset
15
11988
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
16 function test_netcdf_low_level_interface
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
17
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
18 import_netcdf
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
19
12029
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
20 % 2 dimensions
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
21
11988
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
22 fname = [tempname '-octave-netcdf.nc'];
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
23
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
24 ncid = netcdf.create(fname,'NC_CLOBBER');
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
25 assert(strcmp(netcdf.inqFormat(ncid),'FORMAT_CLASSIC'));
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
26
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
27 n = 10;
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
28 m = 5;
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
29
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
30 dimid_lon = netcdf.defDim(ncid,'lon',m);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
31 dimid = netcdf.defDim(ncid,'time',n);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
32
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
33 varidd = netcdf.defVar(ncid,'double_var','double',[dimid_lon,dimid]);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
34
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
35 varid = netcdf.defVar(ncid,'byte_var','byte',[dimid]);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
36
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
37 varidf = netcdf.defVar(ncid,'float_var','float',[dimid]);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
38
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
39 varidi = netcdf.defVar(ncid,'int_var','int',[dimid]);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
40
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
41 varids = netcdf.defVar(ncid,'short_var','short',[dimid]);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
42 assert(varidd == netcdf.inqVarID(ncid,'double_var'))
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
43
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
44 [numdims, numvars, numglobalatts, unlimdimID] = netcdf.inq(ncid);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
45 assert(numvars == 5)
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
46
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
47 [varname,xtype,dimids,natts] = netcdf.inqVar(ncid,varidd);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
48 assert(strcmp(varname,'double_var'));
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
49
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
50 [dimname,len] = netcdf.inqDim(ncid,dimid);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
51 assert(len == n);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
52 assert(strcmp(dimname,'time'));
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
53
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
54
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
55 types = {'double','float','byte','short','int'};
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
56
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
57
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
58 for i=1:length(types)
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
59 vid{i} = netcdf.defVar(ncid,[types{i} '_variable'],types{i},[dimid_lon,dimid]);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
60 end
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
61
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
62
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
63 netcdf.endDef(ncid)
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
64
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
65
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
66 z = randn(m,n);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
67 netcdf.putVar(ncid,varidd,z);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
68
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
69 varf = randn(n,1);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
70 netcdf.putVar(ncid,varidf,varf);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
71
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
72 vari = floor(randn(n,1));
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
73 netcdf.putVar(ncid,varidi,vari);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
74
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
75 netcdf.putVar(ncid,varids,[1:n])
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
76
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
77 z2 = netcdf.getVar(ncid,varidd);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
78 assert(all(all(abs(z2 - z) < 1e-5)))
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
79
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
80 z2 = netcdf.getVar(ncid,varidd,[0 0]);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
81 assert(z2 == z(1,1))
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
82
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
83 z2 = netcdf.getVar(ncid,varidd,[2 2],[3 5]);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
84 assert(isequal(z2,z(3:5,3:7)))
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
85
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
86 z2 = netcdf.getVar(ncid,varidd,[2 2],[3 4],[1 2]);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
87 assert(isequal(z2,z(3:5,3:2:9)))
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
88
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
89
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
90 netcdf.putVar(ncid,varidd,[0 0],123.);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
91 z(1,1) = 123;
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
92 z2 = netcdf.getVar(ncid,varidd);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
93 assert(isequal(z,z2))
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
94
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
95 netcdf.putVar(ncid,varidd,[2 2],[3 3],ones(3,3));
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
96 z(3:5,3:5) = 1;
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
97 z2 = netcdf.getVar(ncid,varidd);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
98 assert(isequal(z,z2))
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
99
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
100
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
101 netcdf.putVar(ncid,varidd,[0 0],[3 5],[2 2],zeros(3,5));
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
102 z(1:2:5,1:2:9) = 0;
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
103 z2 = netcdf.getVar(ncid,varidd);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
104 assert(isequal(z,z2))
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
105
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
106
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
107 z2 = netcdf.getVar(ncid,varidf);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
108 assert(all(z2 - varf < 1e-5))
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
109
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
110
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
111 vari2 = netcdf.getVar(ncid,varidi);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
112 assert(all(vari2 == vari))
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
113
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
114
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
115 netcdf.close(ncid);
2f62d37d5abc restructure test (3)
abarth93
parents:
diff changeset
116 delete(fname);
12029
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
117
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
118 % test with different dimensions
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
119
12030
bd0a4b380d35 make test work for 1d vectors
abarth93
parents: 12029
diff changeset
120 for i = 1:5
12029
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
121 nc_test_ndims(i);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
122 end
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
123
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
124
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
125
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
126 function nc_test_ndims(ndims)
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
127 import_netcdf
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
128
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
129 fname = [tempname '-octave-netcdf.nc'];
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
130
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
131 ncid = netcdf.create(fname,'NC_CLOBBER');
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
132
12711
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
133 sz = ones(1,ndims);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
134 dimids = ones(1,ndims);
12029
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
135
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
136 for i = 1:ndims
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
137 sz(i) = 10+i;
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
138 dimids(i) = netcdf.defDim(ncid,sprintf('dim%g',i),sz(i));
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
139 end
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
140
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
141 varid = netcdf.defVar(ncid,'double_var','double',dimids);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
142
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
143 [varname,xtype,dimids,natts] = netcdf.inqVar(ncid,varid);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
144 assert(strcmp(varname,'double_var'));
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
145
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
146 for i = 1:ndims
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
147 [dimname,len] = netcdf.inqDim(ncid,dimids(i));
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
148 assert(len == sz(i));
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
149 assert(strcmp(dimname,sprintf('dim%g',i)));
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
150 end
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
151
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
152
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
153 netcdf.endDef(ncid)
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
154
12030
bd0a4b380d35 make test work for 1d vectors
abarth93
parents: 12029
diff changeset
155 if ndims == 1
bd0a4b380d35 make test work for 1d vectors
abarth93
parents: 12029
diff changeset
156 z = randn(sz,1);
bd0a4b380d35 make test work for 1d vectors
abarth93
parents: 12029
diff changeset
157 else
bd0a4b380d35 make test work for 1d vectors
abarth93
parents: 12029
diff changeset
158 z = randn(sz);
bd0a4b380d35 make test work for 1d vectors
abarth93
parents: 12029
diff changeset
159 end
bd0a4b380d35 make test work for 1d vectors
abarth93
parents: 12029
diff changeset
160
12029
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
161 netcdf.putVar(ncid,varid,z);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
162
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
163
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
164 z2 = netcdf.getVar(ncid,varid);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
165 assert(isequal(z,z2))
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
166
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
167 z2 = netcdf.getVar(ncid,varid,zeros(ndims,1));
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
168 assert(z2 == z(1))
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
169
12711
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
170 start = 2 * ones(1,ndims);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
171 count = 5 * ones(1,ndims);
12029
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
172 z2 = netcdf.getVar(ncid,varid,start,count);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
173 idx = scs(start,count);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
174 assert(isequal(z2,z(idx{:})))
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
175
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
176
12711
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
177 start = 2 * ones(1,ndims);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
178 count = 5 * ones(1,ndims);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
179 stride = 2 * ones(1,ndims);
12029
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
180 z2 = netcdf.getVar(ncid,varid,start,count,stride);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
181 idx = scs(start,count,stride);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
182 assert(isequal(z2,z(idx{:})))
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
183
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
184
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
185 % put with start
12711
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
186 start = zeros(1,ndims);
12029
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
187 netcdf.putVar(ncid,varid,start,123.);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
188 z(1) = 123;
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
189 z2 = netcdf.getVar(ncid,varid);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
190 assert(isequal(z,z2))
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
191
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
192
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
193 % put with start and count
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
194
12711
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
195 start = 2 * ones(1,ndims);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
196 count = 5 * ones(1,ndims);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
197 if ndims == 1
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
198 data = ones(count,1);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
199 else
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
200 data = ones(count);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
201 end
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
202 netcdf.putVar(ncid,varid,start,count,data);
12029
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
203 idx = scs(start,count);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
204 z(idx{:}) = 1;
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
205 z2 = netcdf.getVar(ncid,varid);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
206 assert(isequal(z,z2))
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
207
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
208 % put with start, count and stride
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
209
12711
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
210 start = 2 * ones(1,ndims);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
211 count = 5 * ones(1,ndims);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
212 stride = 2 * ones(1,ndims);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
213 if ndims == 1
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
214 data = zeros(count,1);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
215 else
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
216 data = zeros(count);
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
217 end
a4de85b2e6a0 fix bug 47014 and make test code work in matlab
abarth93
parents: 12030
diff changeset
218 netcdf.putVar(ncid,varid,start,count,stride,data);
12029
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
219 idx = scs(start,count,stride);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
220 z(idx{:}) = 0;
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
221 z2 = netcdf.getVar(ncid,varid);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
222 assert(isequal(z,z2))
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
223
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
224
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
225
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
226 netcdf.close(ncid);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
227 delete(fname);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
228
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
229 function idx = scs(start,count,stride)
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
230 idx = cell(length(start),1);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
231
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
232 if nargin == 2
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
233 stride = ones(length(start),1);
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
234 end
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
235
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
236 for i = 1:length(start)
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
237 idx{i} = start(i) + 1 + stride(i) * [0:count(i)-1];
21b530fbeee2 make size_t and ptrdiff_t convertion work with 32-bit compilers
abarth93
parents: 11992
diff changeset
238 end