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
cda02b61
Commit
cda02b61
authored
17 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
renomme le fichier
parent
22ed3831
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_util/writeTSGDataNetCDF.m
+147
-0
147 additions, 0 deletions
tsg_util/writeTSGDataNetCDF.m
with
147 additions
and
0 deletions
tsg_util/writeTSGDataNetCDF.m
0 → 100644
+
147
−
0
View file @
cda02b61
function
[
error
]
=
tsg_writeTSGDataNetCDF
(
hTsgGUI
,
filename
)
% Function to write TSG data in NetCDF file.
%
% Input
% -----
% hTsgGUI ............ Handel to the main user interface
% filename ........... Data filename
%
% Output
% ------
% error ............. 1 : OK
% ............. -1 : an error occured
%
% The data are store using setappdata - Variable name : 'tsg_data'
%
% Caution : replace the fill-value with NaN
% $Id$
% Open the file
% -------------
nc
=
netcdf
(
filename
,
'clobber'
);
if
isempty
(
nc
)
msg_error
=
[
'TSG_GOSUD file_lecture : Open file error : '
filename
];
warndlg
(
msg_error
,
'NetCDF write dialog'
);
error
=
-
1
;
return
;
end
% Initialize loading NetCDF file waitbar
% --------------------------------------
wb
=
waitbar
(
0
,
'Initializing NetCDF file. Please wait...'
);
% We cannot change title property to 'none' (default set as 'tex') inside
% waitbar function (line 81), see
% http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/115725
% -----------------------------------------------------------------------
hchild
=
get
(
wb
,
'children'
);
htitle
=
get
(
hchild
,
'title'
);
set
(
htitle
,
'Interpreter'
,
'None'
);
% Get the data from the application GUI
% -------------------------------------
tsg
=
getappdata
(
hTsgGUI
,
'tsg_data'
);
% Get global attributes list from class tsg_nc with file 'tsg_ncattr.csv'
% -----------------------------------------------------------------------
nca
=
tsg_nc
(
'tsg_ncattr.csv'
);
nca_keys
=
keys
(
nca
);
% Get GF3 variables list codes from class tsg_nc with file 'tsg_ncvar.csv'
% -----------------------------------------------------------------------
ncv
=
tsg_nc
(
'tsg_ncvar.csv'
);
ncv_keys
=
keys
(
ncv
);
ncv_fieldNames
=
get_fieldnames
(
ncv
);
% Create NetCDF file:
% -------------------
% Variable dimensions
% -------------------
nc
(
'DAYD'
)
=
numel
(
tsg
.
DAYD
);
% number of TSG measurements
nc
(
'DAYD_WS'
)
=
numel
(
tsg
.
DAYD_WS
);
% number of water samples
nc
(
'DAYD_EXT'
)
=
numel
(
tsg
.
DAYD_EXT
);
% number of external SSPS or SSTP comparison
nc
(
'NCOEF_CAL'
)
=
5
;
% number of calibration coefficients
nc
(
'NCOEF_LIN'
)
=
2
;
% number of linearisation coefficients
% Fixed dimensions
% ----------------
nc
(
'STRING256'
)
=
256
;
nc
(
'STRING14'
)
=
14
;
nc
(
'STRING4'
)
=
4
;
nc
(
'N1'
)
=
1
;
% display filename after 'Interpreter','None' initialization to prevent
% display console warning
% ---------------------------------------------------------------------
waitbar
(
1
/
50
,
wb
,[
'Writing file: '
filename
' Please wait...'
]);
% Create NetCDF global attributes
% -------------------------------
for
i
=
1
:
numel
(
nca_keys
)
nc
.
(
nca_keys
{
i
})
=
tsg
.
(
nca_keys
{
i
});
end
% Create NetCDF variables and attributes
% ---------------------------------------------------
for
i
=
1
:
numel
(
ncv_keys
)
for
j
=
1
:
numel
(
ncv_fieldNames
)
fn
=
ncv_fieldNames
{
j
};
% define dimension
if
strcmp
(
fn
,
'dimension'
)
nc
{
ncv_keys
{
i
}}
=
ncfloat
(
get
(
ncv
,
ncv_keys
{
i
},
fn
));
% define variable atributes
elseif
~
isempty
(
get
(
ncv
,
ncv_keys
{
i
},
fn
))
if
ischar
(
get
(
ncv
,
ncv_keys
{
i
},
fn
))
nc
{
ncv_keys
{
i
}}
.
(
fn
)
=
ncchar
(
get
(
ncv
,
ncv_keys
{
i
},
fn
));
else
nc
{
ncv_keys
{
i
}}
.
(
fn
)
=
ncfloat
(
get
(
ncv
,
ncv_keys
{
i
},
fn
));
end
end
end
end
% Create data to NetCDF file:
% ---------------------------
% Write global attributes
% -----------------------
for
i
=
1
:
numel
(
nca_keys
)
nc
.
(
nca_keys
{
i
})
=
tsg
.
(
nca_keys
{
i
});
end
% Convert Matlab julian days (datenum) to 1950 reference
% ------------------------------------------------------
d
=
strmatch
(
'DAYD'
,
ncv_keys
);
for
i
=
1
:
numel
(
d
)
tsg
.
(
ncv_keys
{
d
(
i
)})
=
datenumToJulian
(
tsg
.
(
ncv_keys
{
d
(
i
)}));
end
% Write measurements (variables)
% -------------------------------
for
i
=
1
:
numel
(
ncv_keys
)
% display waitbar
waitbar
(
i
/
numel
(
ncv_keys
),
wb
,
[
'writing '
ncv_keys
{
i
}
' variable'
]);
% DATE as two dimension
if
strmatch
(
'DATE'
,
ncv_keys
(
i
))
nc
{
ncv_keys
{
i
}}(:,:)
=
tsg
.
(
ncv_keys
{
i
});
else
% other one dimension
nc
{
ncv_keys
{
i
}}(:)
=
tsg
.
(
ncv_keys
{
i
});
end
end
% Close waitbar
% -------------
close
(
wb
)
% Close NetCDF file
% -----------------
endef
(
nc
)
close
(
nc
)
% Everything OK
% -------------
error
=
1
;
end
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