source: Roms_tools/mexcdf/mexnc/tests/test_del_att.m @ 1

Last change on this file since 1 was 1, checked in by cholod, 13 years ago

import Roms_Agrif

File size: 5.3 KB
Line 
1function test_del_att ( ncfile )
2% TEST_DEL_ATT
3%
4% Test 1:  Delete an attribute.
5% Test 2:  Bad ncid.
6% Test 3:  Bad varid.
7% Test 4:  Empty name.
8% Test 5:  Bad name.
9% Test 6:  ncid = []
10% Test 7:  varid == []
11% Test 8:  attname == []
12% Test 9:  ncid is wrong datatype
13% Test 10:  varid is wrong datatype
14% Test 11:  attname is wrong datatype
15
16if nargin == 0
17        ncfile = 'foo.nc';
18end
19
20error_condition = 0;
21
22[ncid, status] = mexnc ( 'create', ncfile, nc_clobber_mode );
23if ( status ~= 0 )
24        ncerr = mexnc ( 'strerror', status );
25        err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
26        error ( err_msg );
27end
28
29
30[xdimid, status] = mexnc ( 'def_dim', ncid, 'x', 20 );
31if ( status ~= 0 )
32        ncerr = mexnc ( 'strerror', status );
33        err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
34        error ( err_msg );
35end
36
37[varid, status] = mexnc ( 'def_var', ncid, 'x', nc_double, 1, xdimid );
38if ( status ~= 0 )
39        ncerr = mexnc ( 'strerror', status );
40        err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
41        error ( err_msg );
42end
43
44input_data = 3.14159;
45status = mexnc ( 'put_att_double', ncid, varid, 'test_double', nc_double, 1, input_data );
46if ( status ~= 0 )
47        ncerr = mexnc ( 'strerror', status );
48        err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
49        error ( err_msg );
50end
51
52
53status = mexnc ( 'enddef', ncid  );
54if ( status ~= 0 )
55        ncerr = mexnc ( 'strerror', status );
56        err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
57        error ( err_msg );
58end
59
60
61status = mexnc ( 'sync', ncid  );
62if ( status ~= 0 )
63        ncerr = mexnc ( 'strerror', status );
64        err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
65        error ( err_msg );
66end
67
68status = mexnc ( 'redef', ncid  );
69if ( status ~= 0 )
70        ncerr = mexnc ( 'strerror', status );
71        err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
72        error ( err_msg );
73end
74
75
76
77%
78% Test 1
79testid = 'Test 1';
80status = mexnc ( 'del_att', ncid, varid, 'test_double' );
81if ( status < 0 )
82        ncerr = mexnc ( 'strerror', status );
83        err_msg = sprintf ( '%s:  %s:  ''%s''\n', mfilename, testid, ncerr );
84        error ( err_msg );
85end
86
87[attnum, status] = mexnc ( 'inq_attid', ncid, varid, 'test_double' );
88if ( status >= 0 )
89        err_msg = sprintf ( '%s:  attribute was not deleted', mfilename, ncerr );
90        error ( err_msg );
91end
92
93
94
95
96status = mexnc ( 'put_att_double', ncid, varid, 'to_be_deleted', nc_double, 1, input_data );
97if ( status < 0 )
98        ncerr = mexnc ( 'strerror', status );
99        err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
100        error ( err_msg );
101end
102
103
104
105
106% Test 2:  Bad ncid.
107testid = 'Test 2';
108status = mexnc ( 'del_att', -2000, varid, 'to_be_deleted' );
109if ( status == 0 )
110        ncerr = mexnc ( 'strerror', status );
111        err_msg = sprintf ( '%s:  %s:  ''%s''\n', mfilename, testid, ncerr );
112        error ( err_msg );
113end
114
115
116
117
118
119
120
121% Test 3:  Bad varid.
122testid = 'Test 3';
123status = mexnc ( 'del_att', ncid, -2000, 'to_be_deleted' );
124if ( status == 0 )
125        ncerr = mexnc ( 'strerror', status );
126        err_msg = sprintf ( '%s:  %s:  ''%s''\n', mfilename, testid, ncerr );
127        error ( err_msg );
128end
129
130
131
132
133
134% Test 4:  Empty name.
135testid = 'Test 4';
136try
137        status = mexnc ( 'del_att', ncid, varid, '' );
138        ncerr = mexnc ( 'strerror', status );
139        err_msg = sprintf ( '%s:  %s:  ''%s''\n', mfilename, testid, ncerr );
140        error ( err_msg );
141end
142
143
144
145
146
147% Test 5:  Bad name.
148testid = 'Test 5';
149status = mexnc ( 'del_att', ncid, varid, 'I know nothing' );
150if ( status == 0 )
151        ncerr = mexnc ( 'strerror', status );
152        err_msg = sprintf ( '%s:  %s:  ''%s''\n', mfilename, testid, ncerr );
153        error ( err_msg );
154end
155
156
157
158
159% Test 6:  ncid == []
160testid = 'Test 6';
161try
162        status = mexnc ( 'del_att', [], varid, 'I know less than nothing' );
163        err_msg = sprintf ( '%s:  %s:  succeeded where it should have failed\n', mfilename, testid, ncerr );
164        error ( err_msg );
165catch
166        ;
167end
168
169
170
171
172
173
174% Test 7:  varid == []
175testid = 'Test 7';
176try
177        status = mexnc ( 'del_att', ncid, [], 'I know less than nothing' );
178        err_msg = sprintf ( '%s:  %s:  succeeded where it should have failed\n', mfilename, testid, ncerr );
179        error ( err_msg );
180catch
181        ;
182end
183
184
185
186
187
188
189% Test 8:  Attribute name == []
190testid = 'Test 7';
191try
192        status = mexnc ( 'del_att', ncid, varid, [] );
193        err_msg = sprintf ( '%s:  %s:  succeeded where it should have failed\n', mfilename, testid, ncerr );
194        error ( err_msg );
195catch
196        ;
197end
198
199
200
201% Test 9:  ncid is wrong datatype
202testid = 'Test 9';
203try
204        status = mexnc ( 'del_att', 'ncid', varid, 'to_be_deleted' );
205        error_condition = 1;
206end
207if ( error_condition == 1 )
208        err_msg = sprintf ( '%s:  %s:  succeeded when it should have failed\n', mfilename, testid, ncerr );
209        error ( err_msg );
210end
211
212
213% Test 10:  varid is wrong datatype
214testid = 'Test 10';
215try
216        status = mexnc ( 'del_att', ncid, 'varid', 'to_be_deleted' );
217        error_condition = 1;
218end
219if ( error_condition == 1 )
220        err_msg = sprintf ( '%s:  %s:  succeeded when it should have failed\n', mfilename, testid, ncerr );
221        error ( err_msg );
222end
223
224
225% Test 11:  varid is wrong datatype
226testid = 'Test 11';
227try
228        status = mexnc ( 'del_att', ncid, varid, 5 );
229        error_condition = 1;
230end
231if ( error_condition == 1 )
232        err_msg = sprintf ( '%s:  %s:  succeeded when it should have failed\n', mfilename, testid, ncerr );
233        error ( err_msg );
234end
235
236
237
238
239
240
241
242
243
244
245
246fprintf ( 1, 'DEL_ATT succeeded.\n' );
247
248
249status = mexnc ( 'close', ncid );
250if ( status < 0 )
251        ncerr = mexnc ( 'strerror', status );
252        err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
253        error ( err_msg );
254end
255
256
257return
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
Note: See TracBrowser for help on using the repository browser.