Newer
Older
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
function s = save2json(varargin)
% read dynaload (csv or xls) file or netcdf
% and convert it to json format
%
% test=loadjson('test.json')
%
% test =
%
% DIMENSIONS: [1x1 struct]
% VARIABLES: [1x1 struct]
% ATTRIBUTES: [1x1 struct]
% QUALITY: [1x1 struct]
%
% test.ATTRIBUTES
%
% ans =
%
% TITLE: [1x1 struct]
% CYCLE_MESURE: [1x1 struct]
% PLATFORM_NAME: [1x1 struct]
% PROJECT_NAME: [1x1 struct]
% SHIP_CALL_SIGN: [1x1 struct]
% PI_NAME: [1x1 struct]
% ...
%
% getfield(test.ATTRIBUTES.PI_NAME, 'comment')
%
% ans =
%
% Name of principal investigator in charge of the TSG, ex: Delcroix
%
% fieldnames(test.ATTRIBUTES.PI_NAME)
%
% ans =
%
% 'key__'
% 'name'
% 'conventions'
% 'uicontrolType'
% 'string'
% 'value'
% 'length'
% 'height'
% 'line'
% 'horizontalAlignment'
% 'comment'
% init default value
% ------------------
s = [], filterIndex = 0; theArg = []; theFileName = '';
% test constructor argument
% ------------------------
switch nargin
% default constructor, try to open dynaload file descriptor
% ---------------------------------------------------------
case 0
[fileName, pathName, filterIndex] = uigetfile(...
{'*.csv','Ascii-file (*.csv)';...
'*.xls;*.xlsx','Excel-file (*.xls,*.xlsx)';...
'*.nc;*.ncd','NetCDF-file (*.nc,*.ncd)'}, 'Select file');
if ~any(fileName)
return
else
theFileName = fullfile(pathName, fileName);
end
% one arg, if it is a dynaload filename, open it, otherwise,
% create new dynamic propertiy
% ----------------------------------------------------------
case 1
if (isa(varargin{1}, 'char'))
% if file exist and is in the search path, return 2
% --------------------------------------------------
if exist(varargin{1}, 'file') == 2
theFileName = varargin{1};
else
% if file is in matlab path directories
% -------------------------------------
theFileName = which(varargin{1});
% if not, bad name, return an error
% ---------------------------------
if isempty( theFileName)
error('Wrong or bad file: %s', varargin{1});
end
end
end
end
% call read_xxx_file functions
% ----------------------------
switch filterIndex
case 0
% memory, do nothing
case {1,2}
% read csv file
% -------------
f = dynaload(theFileName);
case 3
% read netCDF file
% ----------------
f = netcdf_native(theFileName);
otherwise
error('Wrong filterIndex');
end
% loop over keys
% --------------
for i = keys(f)
for j = keys(f.(char(i)))
s.(char(i)).(char(j)) = f.(char(i)).(char(j))
end
end
% save jscon file
% ---------------
% slip filename into path, name & extension with .json
% ----------------------------------------------------
[path, name, ~] = fileparts(theFileName);
theFileName = strcat(path, filesep, name, '.json');
%theFileName = fullfile(pathName, theFileName);
savejson('', s, theFileName);