Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gdat
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
Model registry
Operate
Environments
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
SPC
gdat
Commits
8066dd64
Commit
8066dd64
authored
4 months ago
by
Olivier Sauter
Browse files
Options
Downloads
Patches
Plain Diff
fix reading netcdf with units not defined (e.g. fi cdf), add shot as input
parent
b7fdd59a
No related branches found
No related tags found
1 merge request
!181
fix reading netcdf with units not defined (e.g. fi cdf), add shot as input
Checking pipeline status
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
matlab/CHDF/cdf2mat.m
+16
-2
16 additions, 2 deletions
matlab/CHDF/cdf2mat.m
with
16 additions
and
2 deletions
matlab/CHDF/cdf2mat.m
+
16
−
2
View file @
8066dd64
function
cdf2mat_out
=
cdf2mat
(
pfname
)
function
cdf2mat_out
=
cdf2mat
(
pfname
,
varargin
)
% cdf2mat_out = cdf2mat(pfname,varargin)
%
%
% reads all variables and coordinates from netcdf
% reads all variables and coordinates from netcdf
% some trials with netcdf, using 50725c01.cdf as test
% some trials with netcdf, using 50725c01.cdf as test
...
@@ -7,6 +8,9 @@ function cdf2mat_out = cdf2mat(pfname)
...
@@ -7,6 +8,9 @@ function cdf2mat_out = cdf2mat(pfname)
%
%
% Uses matlab netcdf.open, ncinfo, netcdf.inqVarIDs, netcd.getVar, etc
% Uses matlab netcdf.open, ncinfo, netcdf.inqVarIDs, netcd.getVar, etc
%
%
% varargin{1}: shot number to add (in particular when cdf file does not have it defined
% shot from file: allinfo=ncinfo(pfname);if ~isempty(allinfo.Attributes),top_attr_names = {allinfo.Attributes(:).Name};allinfo.Attributes(strmatch('shot',top_attr_names,'exact')).Value, else, disp('no Attributes'),end
%
%
%
if
~
exist
(
pfname
,
'file'
)
if
~
exist
(
pfname
,
'file'
)
...
@@ -33,6 +37,7 @@ if length(allvarnames) ~= length(allvarids)
...
@@ -33,6 +37,7 @@ if length(allvarnames) ~= length(allvarids)
end
end
[
varnames_sorted
,
~
]
=
sort
(
allvarnames
);
[
varnames_sorted
,
~
]
=
sort
(
allvarnames
);
cdf2mat_out
.
allvarnames_sorted
=
varnames_sorted
;
% to find a variable:
% to find a variable:
% strmatch('GFUN',allvarnames,'exact')
% strmatch('GFUN',allvarnames,'exact')
...
@@ -56,6 +61,8 @@ for i=1:length(coordnames_sorted)
...
@@ -56,6 +61,8 @@ for i=1:length(coordnames_sorted)
for
ij
=
1
:
length
(
fields_variables_to_copy
)
for
ij
=
1
:
length
(
fields_variables_to_copy
)
matcdf
.
coords
(
i
)
.
(
fields_variables_to_copy
{
ij
})
=
allinfo
.
Variables
(
matcdf
.
coords
(
i
)
.
index_allvarnames
)
.
(
fields_variables_to_copy
{
ij
});
matcdf
.
coords
(
i
)
.
(
fields_variables_to_copy
{
ij
})
=
allinfo
.
Variables
(
matcdf
.
coords
(
i
)
.
index_allvarnames
)
.
(
fields_variables_to_copy
{
ij
});
end
end
matcdf
.
coords
(
i
)
.
units
=
''
;
matcdf
.
coords
(
i
)
.
long_name
=
[
matcdf
.
coords
(
i
)
.
name
' empty'
];
for
jj
=
1
:
numel
(
allinfo
.
Variables
(
matcdf
.
coords
(
i
)
.
index_allvarnames
)
.
Attributes
)
for
jj
=
1
:
numel
(
allinfo
.
Variables
(
matcdf
.
coords
(
i
)
.
index_allvarnames
)
.
Attributes
)
if
strcmp
(
lower
(
allinfo
.
Variables
(
matcdf
.
coords
(
i
)
.
index_allvarnames
)
.
Attributes
(
jj
)
.
Name
),
'units'
)
if
strcmp
(
lower
(
allinfo
.
Variables
(
matcdf
.
coords
(
i
)
.
index_allvarnames
)
.
Attributes
(
jj
)
.
Name
),
'units'
)
matcdf
.
coords
(
i
)
.
units
=
strtrim
(
allinfo
.
Variables
(
matcdf
.
coords
(
i
)
.
index_allvarnames
)
.
Attributes
(
jj
)
.
Value
);
matcdf
.
coords
(
i
)
.
units
=
strtrim
(
allinfo
.
Variables
(
matcdf
.
coords
(
i
)
.
index_allvarnames
)
.
Attributes
(
jj
)
.
Value
);
...
@@ -80,6 +87,7 @@ for i=1:length(varnames_sorted)
...
@@ -80,6 +87,7 @@ for i=1:length(varnames_sorted)
matcdf
.
vars
(
i
)
.
name
=
varnames_sorted
{
i
};
matcdf
.
vars
(
i
)
.
name
=
varnames_sorted
{
i
};
matcdf
.
vars
(
i
)
.
index_allvarnames
=
strmatch
(
matcdf
.
vars
(
i
)
.
name
,
allvarnames
,
'exact'
);
matcdf
.
vars
(
i
)
.
index_allvarnames
=
strmatch
(
matcdf
.
vars
(
i
)
.
name
,
allvarnames
,
'exact'
);
matcdf
.
vars
(
i
)
.
varid
=
allvarids
(
matcdf
.
vars
(
i
)
.
index_allvarnames
);
matcdf
.
vars
(
i
)
.
varid
=
allvarids
(
matcdf
.
vars
(
i
)
.
index_allvarnames
);
% if i==strmatch('ZEFFC',varnames_sorted,'exact'), keyboard; end
if
~
isempty
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
if
~
isempty
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
if
strcmp
(
allinfo
.
Variables
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
.
Datatype
,
'single'
)
if
strcmp
(
allinfo
.
Variables
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
.
Datatype
,
'single'
)
matcdf
.
vars
(
i
)
.
data
=
netcdf
.
getVar
(
funnetcdf
,
matcdf
.
vars
(
i
)
.
varid
,
'double'
);
matcdf
.
vars
(
i
)
.
data
=
netcdf
.
getVar
(
funnetcdf
,
matcdf
.
vars
(
i
)
.
varid
,
'double'
);
...
@@ -89,6 +97,8 @@ for i=1:length(varnames_sorted)
...
@@ -89,6 +97,8 @@ for i=1:length(varnames_sorted)
for
ij
=
1
:
length
(
fields_variables_to_copy
)
for
ij
=
1
:
length
(
fields_variables_to_copy
)
matcdf
.
vars
(
i
)
.
(
fields_variables_to_copy
{
ij
})
=
allinfo
.
Variables
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
.
(
fields_variables_to_copy
{
ij
});
matcdf
.
vars
(
i
)
.
(
fields_variables_to_copy
{
ij
})
=
allinfo
.
Variables
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
.
(
fields_variables_to_copy
{
ij
});
end
end
matcdf
.
vars
(
i
)
.
units
=
''
;
matcdf
.
vars
(
i
)
.
long_name
=
[
matcdf
.
vars
(
i
)
.
name
' empty'
];
for
jj
=
1
:
numel
(
allinfo
.
Variables
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
.
Attributes
)
for
jj
=
1
:
numel
(
allinfo
.
Variables
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
.
Attributes
)
if
strcmp
(
lower
(
allinfo
.
Variables
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
.
Attributes
(
jj
)
.
Name
),
'units'
)
if
strcmp
(
lower
(
allinfo
.
Variables
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
.
Attributes
(
jj
)
.
Name
),
'units'
)
matcdf
.
vars
(
i
)
.
units
=
strtrim
(
allinfo
.
Variables
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
.
Attributes
(
jj
)
.
Value
);
matcdf
.
vars
(
i
)
.
units
=
strtrim
(
allinfo
.
Variables
(
matcdf
.
vars
(
i
)
.
index_allvarnames
)
.
Attributes
(
jj
)
.
Value
);
...
@@ -128,7 +138,11 @@ if ~isempty(allinfo.Attributes)
...
@@ -128,7 +138,11 @@ if ~isempty(allinfo.Attributes)
ij
=
strmatch
(
'shot'
,
top_attr_names
,
'exact'
);
ij
=
strmatch
(
'shot'
,
top_attr_names
,
'exact'
);
cdf2mat_out
.
shot
=
allinfo
.
Attributes
(
ij
)
.
Value
;
cdf2mat_out
.
shot
=
allinfo
.
Attributes
(
ij
)
.
Value
;
else
else
cdf2mat_out
.
shot
=
NaN
;
if
nargin
>
1
&&
isnumeric
(
varargin
{
1
})
cdf2mat_out
.
shot
=
varargin
{
1
};
else
cdf2mat_out
.
shot
=
NaN
;
end
end
end
cdf2mat_out
.
fname
=
pfname
;
cdf2mat_out
.
fname
=
pfname
;
[
a1
,
a2
,
a3
]
=
fileparts
(
pfname
);
[
a1
,
a2
,
a3
]
=
fileparts
(
pfname
);
...
...
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