Newer
Older
function self = netcdf_native(varargin)
% file @netcdf_native/netcdf_native
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
arg = nargin;
if arg == 1 && isempty(varargin{1})
arg = 0;
end
theFile = ''; theDynaload = 'memory'; theMode = 'MEMORY';
switch arg
% with not arg, read netcdf file with uigetfile
% ---------------------------------------------
case 0
[theFileName, thePathName] = uigetfile(...
{'*.nc;*.cdf','NetCDF (*.nc,*.cdf)'}, 'Select file');
if any(theFileName)
theFile = fullfile(thePathName, theFileName);
theMode = 'NC_NOWRITE';
theDynaload = 'memory';
else
theFile = '';
end
% with one arg, read given netcdf filename
% ----------------------------------------
case 1
if( strcmp(varargin{1}, 'memory'))
theDynaload = 'memory';
theFile = 'memory';
theMode = 'MEMORY';
elseif( isa(varargin{1}, 'char'))
theFile = varargin{1};
if isempty(exist(theFile, 'file'))
error('netcdf: %s file don''t exist.\n', theFile );
end
[thePathName, theFileName, theFileExt] = fileparts(varargin{1});
switch theFileExt
case {'.nc', 'cdf'}
theMode = 'NC_NOWRITE';
% a revoir ...
theDynaload = 'memory';
case {'.csv', '.xls'}
theDynaload = varargin{1};
theMode = 'DYNALOAD';
otherwise
error('Wrong file type');
end
else
error('Wrong input argument');
end
% work on given netcdf filename with mode and dynaload dexcriptor
% file
% ---------------------------------------------------------------
case 2
% is the mode numeric.
if ischar(varargin{2})
% convert it in numeric value
switch (varargin{2})
case { 'NC_WRITE', 'NC_CLOBBER', 'NC_NOCLOBBER', 'NC_SHARE' };
theMode = varargin{2};
otherwise
error('Wrong mode to create netcdf file: %s', varargin{2});
end
else
% a modifier sur mode est numeric
theMode = varargin{2};
end
otherwise
error('Wrong number of input arguments');
end
d = dynaload( theDynaload );
self.file = theFile;
%self.dynaload = theDynaload;
self.mode = theMode;
self.nc_id = 0;
self.autonan = logical(1);
self.autoscale = logical(0);
% constants for netcdf data types
% -------------------------------
self.NC_BYTE = netcdf.getConstant('NC_BYTE'); % 1
self.NC_CHAR = netcdf.getConstant('NC_CHAR'); % 2
self.NC_SHORT = netcdf.getConstant('NC_SHORT'); % 3
self.NC_INT = netcdf.getConstant('NC_INT'); % 4
self.NC_LONG = netcdf.getConstant('NC_LONG'); % 4
self.NC_FLOAT = netcdf.getConstant('NC_FLOAT'); % 5
self.NC_DOUBLE = netcdf.getConstant('NC_DOUBLE'); % 6
self.NC_MEMORY = -1;
% constants for netcdf.open()
% ---------------------------
%self.NC_NOWRITE: Read-only access
self.NC_NOWRITE = netcdf.getConstant('NC_NOWRITE'); % 0
%self.NC_WRITE: Read-write access
self.NC_WRITE = netcdf.getConstant('NC_WRITE'); % 1
% constants for netcdf.create()
% -----------------------------
self.NC_CLOBBER = netcdf.getConstant('NC_CLOBBER'); % 0
%self.NC_NOCLOBBER: Prevent overwriting of existing file with the same name.
self.NC_NOCLOBBER = netcdf.getConstant('NC_NOCLOBBER'); % 4
%self.NC_SHARE: Allow synchronous file updates.
self.NC_SHARE = netcdf.getConstant('NC_SHARE'); % 2048
%self.NC_64BIT_OFFSET: Allow easier creation of files and variables which
% are larger than two gigabytes.
self.NC_64BIT_OFFSET = netcdf.getConstant('NC_64BIT_OFFSET'); % 512
self.NC_ERR = netcdf.getConstant('NC2_ERR'); % -1
self.NC_EBADDIM = netcdf.getConstant('NC_EBADDIM');
self.NC_EBADID = netcdf.getConstant('NC_EBADID');
self.NC_EBADNAME = netcdf.getConstant('NC_EBADNAME');
self.NC_EBADTYPE = netcdf.getConstant('NC_EBADTYPE');
self.NC_ECHAR = netcdf.getConstant('NC_ECHAR');
self.NC_EDIMSIZE = netcdf.getConstant('NC_EDIMSIZE');
self.NC_EEDGE = netcdf.getConstant('NC_EEDGE');
self.NC_EEXIST = netcdf.getConstant('NC_EEXIST');
self.NC_EGLOBAL = netcdf.getConstant('NC_EGLOBAL');
self.NC_EINDEFINE = netcdf.getConstant('NC_EINDEFINE');
self.NC_EINVAL = netcdf.getConstant('NC_EINVAL');
self.NC_EINVALCOORDS = netcdf.getConstant('NC_EINVALCOORDS');
self.NC_EMAXATTS = netcdf.getConstant('NC_EMAXATTS');
self.NC_EMAXDIMS = netcdf.getConstant('NC_EMAXDIMS');
self.NC_EMAXNAME = netcdf.getConstant('NC_EMAXNAME');
self.NC_EMAXVARS = netcdf.getConstant('NC_EMAXVARS');
self.NC_ENAMEINUSE = netcdf.getConstant('NC_ENAMEINUSE');
self.NC_ENFILE = netcdf.getConstant('NC_ENFILE');
self.NC_ENOMEM = netcdf.getConstant('NC_ENOMEM');
self.NC_ENORECVARS = netcdf.getConstant('NC_ENORECVARS');
self.NC_ENOTATT = netcdf.getConstant('NC_ENOTATT');
self.NC_ENOTINDEFINE = netcdf.getConstant('NC_ENOTINDEFINE');
self.NC_ENOTNC = netcdf.getConstant('NC_ENOTNC');
self.NC_ENOTVAR = netcdf.getConstant('NC_ENOTVAR');
self.NC_EPERM = netcdf.getConstant('NC_EPERM');
self.NC_ERANGE = netcdf.getConstant('NC_ERANGE');
self.NC_ESTRIDE = netcdf.getConstant('NC_ESTRIDE');
self.NC_ESTS = netcdf.getConstant('NC_ESTS');
self.NC_ETRUNC = netcdf.getConstant('NC_ETRUNC');
self.NC_EUNLIMIT = netcdf.getConstant('NC_EUNLIMIT');
self.NC_EUNLIMPOS = netcdf.getConstant('NC_EUNLIMPOS');
self.NC_EVARSIZE = netcdf.getConstant('NC_EVARSIZE');
self.NC_FATAL = netcdf.getConstant('NC_FATAL'); % 1
self.NC_FILL = netcdf.getConstant('NC_FILL'); % 0
self.NC_FILL_BYTE = netcdf.getConstant('NC_FILL_BYTE'); % -127
self.NC_FILL_CHAR = netcdf.getConstant('NC_FILL_CHAR'); % 0
self.NC_FILL_DOUBLE = netcdf.getConstant('NC_FILL_DOUBLE'); % 9.9692e+036
self.NC_FILL_FLOAT = netcdf.getConstant('NC_FILL_FLOAT'); % 9.9692e+036
self.NC_FILL_INT = netcdf.getConstant('NC_FILL_INT'); % -2.1475e+009
self.NC_FILL_SHORT = netcdf.getConstant('NC_FILL_SHORT'); % -32767
self.NC_FORMAT_64BIT = netcdf.getConstant('NC_FORMAT_64BIT'); % 2
self.NC_FORMAT_CLASSIC = netcdf.getConstant('NC_FORMAT_CLASSIC'); % 1
self.NC_GLOBAL = netcdf.getConstant('NC_GLOBAL'); % -1
self.NC_LOCK = netcdf.getConstant('NC_LOCK'); % 1024
self.NC_MAX_ATTRS = netcdf.getConstant('NC_MAX_ATTRS'); % 8192
self.NC_MAX_DIMS = netcdf.getConstant('NC_MAX_DIMS'); % 1024
self.NC_MAX_NAME = netcdf.getConstant('NC_MAX_NAME'); % 256
self.NC_MAX_VARS = netcdf.getConstant('NC_MAX_VARS'); % 8192
self.NC_MAX_VAR_DIMS = netcdf.getConstant('NC_MAX_VAR_DIMS'); % 1024
self.NC_NAT = netcdf.getConstant('NC_NAT'); % 0
self.NC_NOERR = netcdf.getConstant('NC_NOERR'); % 0
self.NC_NOFILL = netcdf.getConstant('NC_NOFILL'); % 256
self.NC_SIZEHINT_DEFAULT = netcdf.getConstant('NC_SIZEHINT_DEFAULT'); % 0
self.NC_UNLIMITED = netcdf.getConstant('NC_UNLIMITED'); % 0
self.NC_VERBOSE = netcdf.getConstant('NC_VERBOSE'); % 2
% bless class
% -----------
self = class(self, 'netcdf_native', d);
% call private function following mode state
% a revoir !!!!!!!!!!!!!!!
% ------------------------------------------
switch self.mode
case 'NC_NOWRITE' % NOWRITE mode
[self] = read(self, true);
case 'NC_WRITE' % READ/WRITE mode
self = put(self,'DIMENSIONS', hashtable);
self = put(self,'VARIABLES', hashtable);
self = put(self,'ATTRIBUTES', hashtable);
case 'NC_NOCLOBBER' % NOCLOBBER mode
case 'NC_CLOBBER' % NOCLOBBER mode
self = put(self,'DIMENSIONS', hashtable);
self = put(self,'VARIABLES', hashtable);
self = put(self,'ATTRIBUTES', hashtable);
% case self.NC_SHARE % SHARE mode
% % not implemeted
case 'NC_64BIT_OFFSET'
% %
case 'DYNALOAD'
% %
case 'MEMORY'
self = put(self,'DIMENSIONS', hashtable);
self = put(self,'VARIABLES', hashtable);
self = put(self,'ATTRIBUTES', hashtable);
otherwise
error('Wrong mode argument');
end