Newer
Older

jacques.grelet_ird.fr
committed
1
2
3
4
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
function self = dynaload(varargin)
%
% file @dynaload/dynaload
%
% Class used to load complex object descriptor from Excel xls or ASCII csv
% files
% Usually Excel file is used during development under Windows, and csv file is
% create and use in production.
%
% >> nc = dynaload('tsgqc_netcdf.xls');
% >> nc
% dynaload
%
% file: ..\MATLAB\toolbox\@dynaload\tsgqc_netcdf.csv
%
% DIMENSIONS 8 [hashtable]
% VARIABLES 60 [hashtable]
% ATTRIBUTES 31 [hashtable]
% QUALITY 10 [hashtable]
%
% >> s = nc.VARIABLES.SSTP
%
% s =
% code__: 'SSTP'
% dimension__: {'DAYD'}
% type__: 'float'
% long_name: 'SEA SURFACE TEMPERATURE'
% standard_name: 'surface temperature'
% units: 'degrees Celsius'
% conventions: ''
% valid_min: -1.5000
% valid_max: 38
% format: '%6.3lf'
% FillValue_: 99999
% epic_code: []
% axis: ''
% resolution: 1.0000e-003
% comment: [1x99 char]
% missing_value: []
%
% % get value :
% >> nc.VARIABLES.SSTP.long_name
% ans = SEA SURFACE TEMPERATURE
%
% % change value :
% >> nc.VARIABLES.SSTP.long_name = 'NEW SEA SURFACE TEMPERATURE'
%
% % convert Excel file to csv :
% >> write(nc, '+/@dynaload/tsgqc_netcdf.csv');
%
% >> type +/@dynaload/tsgqc_netcdf.csv
%
% tsgqc_netcdf.csv
%
% $DIMENSIONS$
% #;code;value;#
% #;char;integer;#
% #;PROFILE;120;#
% ...
% %
% $VARIABLES$
% #;code;dimension;nctype;long_name;standard_name;units;conventions;valid_min;valid_max;format;FillValue_;epic_code;axis;resolution;comment;missing_value;#
% #;char;cell;char;char;char;char;char;double;double;char;double;double;char;double;char;double;#
% #;REFERENCE_DATE_TIME;'STRING14';char;REFERENCE DATE TIME FOR JULIAN DAYS;reference date time;;yyyymmddhhmmss;;;;;;;;Reference date for julian days origin;;#
% ...
%
% An instance of dynaload can be create in memory:
%
% m = dynaload('memory');
% m.DIMENSIONS = hashtable;
% m.VARIABLES = hashtable;
% m.DIMENSIONS.STRING4 = 4;
% m.VARIABLES.TEMP.data = [20.0 21.2 23.5];
% m.VARIABLES.TEMP.nctype = 'float';
% m.VARIABLES.TEMP.dimension = {'DAYD'};
% m.VARIABLES.TEMP.long_name ='Temperature';
% m.VARIABLES.TEMP.FillValue = '99999';
% ...
%
% $Id: dynaload.m 400 2009-03-14 17:32:55Z jgrelet $
%% COPYRIGHT & LICENSE
% Copyright 2009 - IRD US191, all rights reserved.
%
% This file is part of Matlab package.
%
% tsgqc package is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% tsgqc package is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
%% Class definition
% -------------------
% test constructor argument
% -------------------------
switch nargin
case 0 % can't create default object
[file, path, filterIndex] = uigetfile(...
{'*.csv','Ascii-file (*.csv)';...
'*.xls','Excel-file (*.xls)'}, 'Select file');
if ~any(file)
self.file = 'memory';
return
end
self.file = fullfile(path, file);
case 1
if strcmp(varargin{1}, 'memory')
self.file = 'memory';
return
end
if( isa(varargin{1}, 'char'))
file = which(varargin{1});
if isempty( file)
file = varargin{1};
end
[path, name, ext] = fileparts(file);
switch ext
case '.csv'
filterIndex = 1;
case '.xls'
filterIndex = 2;
otherwise
error('Wrong file type');
end
self.file = file;
else
error('Wrong input argument');
end
otherwise
error('Wrong number of input arguments');
end
% init class properties
% ----------------------
self.line = 0;
self.fid = 0;
% bless class
% -----------
self = class(self, 'dynaload', hashtable);
% call read_xxx_file functions
% ----------------------------
switch filterIndex
case 1
[self] = read_csv_file(self);
case 2
[self] = read_xls_file(self);
otherwise
end