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
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';
% ...
%

jacques.grelet_ird.fr
committed
%% 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

jacques.grelet_ird.fr
committed
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';
filterIndex = -1;
else
self.file = fullfile(path, file);

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed
case 1
if strcmp(varargin{1}, 'memory')
self.file = 'memory';
filterIndex = -1;
elseif( isa(varargin{1}, 'char'))

jacques.grelet_ird.fr
committed
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

jacques.grelet_ird.fr
committed
otherwise
error('Wrong number of input arguments');

jacques.grelet_ird.fr
committed
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