Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TSG QC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
US191
TSG QC
Commits
d153144e
Commit
d153144e
authored
12 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
add xls, csv or netcdf conversion to json format
parent
50aabfa6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tsg_tools/save2json.m
+138
-0
138 additions, 0 deletions
tsg_tools/save2json.m
with
138 additions
and
0 deletions
tsg_tools/save2json.m
0 → 100644
+
138
−
0
View file @
d153144e
function
s
=
save2json
(
varargin
)
%
read
dynaload
(
csv
or
xls
)
file
or
netcdf
%
and
convert
it
to
json
format
%
%
test
=
loadjson
(
'
test
.
json
'
)
%
%
test
=
%
%
DIMENSIONS
:
[
1
x1
struct
]
%
VARIABLES
:
[
1
x1
struct
]
%
ATTRIBUTES
:
[
1
x1
struct
]
%
QUALITY
:
[
1
x1
struct
]
%
%
test
.
ATTRIBUTES
%
%
ans
=
%
%
TITLE
:
[
1
x1
struct
]
%
CYCLE
_
MESURE
:
[
1
x1
struct
]
%
PLATFORM
_
NAME
:
[
1
x1
struct
]
%
PROJECT
_
NAME
:
[
1
x1
struct
]
%
SHIP
_
CALL
_
SIGN
:
[
1
x1
struct
]
%
PI
_
NAME
:
[
1
x1
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);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment