From 95fd4c5b08cc5259217306f8ceeadacaae85b43c Mon Sep 17 00:00:00 2001 From: Jacques Grelet <jacques.grelet@ird.fr> Date: Tue, 15 Jan 2008 11:43:37 +0000 Subject: [PATCH] =?UTF-8?q?Code=20simplifi=C3=A9=20dans=20readTsgDataNetCD?= =?UTF-8?q?F=20(structure=20tsg=20remplie=20dynamiquement=20a=20la=20lectu?= =?UTF-8?q?re).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tsg_io/readTsgDataNetCDF.m | 176 ++++++++++--------------------------- 1 file changed, 47 insertions(+), 129 deletions(-) diff --git a/tsg_io/readTsgDataNetCDF.m b/tsg_io/readTsgDataNetCDF.m index 83cdabd..4df8f6c 100644 --- a/tsg_io/readTsgDataNetCDF.m +++ b/tsg_io/readTsgDataNetCDF.m @@ -15,6 +15,10 @@ function [error] = readTsgDataNetCDF( hTsgGUI, filename) % % $Id$ +% clear all variables in base workspace +% ------------------------------------- +%clear all; + % Get the data from the application GUI % ------------------------------------- tsg = getappdata( hTsgGUI, 'tsg_data'); @@ -43,137 +47,51 @@ fprintf('...reading %s : ', filename); tsg.file.name = filename; tsg.file.type = 'NETCDF'; -% Read global attributes: meta data -% ---------------------------------- -tsg.PLATFORM_NAME = nc.PLATFORM_NAME(:); -tsg.SHIP_CALL_SIGN = nc.SHIP_CALL_SIGN(:); -tsg.SHIP_MMSI = nc.SHIP_MMSI(:); -tsg.TSG_TYPE = nc.TSG_TYPE(:); -tsg.TSG_NUMBER = nc.TSG_NUMBER(:); -tsg.TINT_TYPE = nc.TINT_TYPE(:); -tsg.TINT_NUMBER = nc.TINT_NUMBER(:); -tsg.DATA_TYPE = nc.DATA_TYPE(:); -tsg.DATA_MODE = nc.DATA_MODE(:); -tsg.SAMPLING_PERIOD = nc.SAMPLING_PERIOD(:); -tsg.PROCESSING_STATUS = nc.PROCESSING_STATUS(:); -tsg.DATE_START = nc.DATE_START(:); -tsg.DATE_END = nc.DATE_END(:); -tsg.SOUTH_LATX = nc.SOUTH_LATX(:); -tsg.NORTH_LATX = nc.NORTH_LATX(:); -tsg.WEST_LONX = nc.WEST_LONX(:); -tsg.EAST_LONX = nc.EAST_LONX(:); -tsg.FORMAT_VERSION = nc.FORMAT_VERSION(:); -tsg.DATE_CREATION = nc.DATE_CREATION(:); -tsg.DATE_UPDATE = nc.DATE_UPDATE(:); -tsg.DATA_RESTRICTIONS = nc.DATA_RESTRICTIONS(:); -tsg.CITATION = nc.CITATION(:); -tsg.COMMENT = nc.COMMENT(:); -tsg.PROJECT_NAME = nc.PROJECT_NAME(:); -tsg.PI_NAME = nc.PI_NAME(:); -tsg.DATA_CENTRE = nc.DATA_CENTRE(:); -tsg.DATA_ACQUISITION = nc.DATA_ACQUISITION(:); -tsg.PROCESSING_CENTRE = nc.PROCESSING_CENTRE(:); -tsg.PROCESSING_STATE = nc.PROCESSING_STATE(:); - -% read variables describing TSG installation -% ------------------------------------------ - -tsg.SSJT_DEPH = nc{'SSJT_DEPH'}(:); -tsg.SSJT_DEPH_MIN = nc{'SSJT_DEPH_MIN'}(:); -tsg.SSJT_DEPH_MAX = nc{'SSJT_DEPH_MAX'}(:); -tsg.CNDC_CALCOEF = nc{'CNDC_CALCOEF'}(:); -tsg.CNDC_LINCOEF = nc{'CNDC_LINCOEF'}(:); -tsg.SSJT_CALCOEF = nc{'SSJT_CALCOEF'}(:); -tsg.SSJT_LINCOEF = nc{'SSJT_LINCOEF'}(:); - -% read variables describing Temperature sensor at intake (TINT) installation -% -------------------------------------------------------------------------- - -tsg.SSTP_DEPH = nc{'SSTP_DEPH'}(:); -tsg.SSTP_DEPH_MIN = nc{'SSTP_DEPH_MIN'}(:); -tsg.SSTP_DEPH_MAX = nc{'SSTP_DEPH_MAX'}(:); -tsg.SSTP_CALCOEF = nc{'SSTP_CALCOEF'}(:); -tsg.SSTP_LINCOEF = nc{'SSTP_LINCOEF'}(:); - -% Coordinates -%------------ - -tsg.DATE = nc{'DATE'}(:,:); -tsg.DAYD = nc{'DAYD'}(:); -tsg.LATX = nc{'LATX'}(:); -tsg.LONX = nc{'LONX'}(:); -tsg.POSITION_QC = nc{'POSITION_QC'}(:); -tsg.SPDC = nc{'SPDC'}(:); -tsg.REFERENCE_DATE_TIME = nc{'REFERENCE_DATE_TIME'}(:); - -% Convert julian day with origin 1950 to Matlab datenum in memory -% --------------------------------------------------------------- -tsg.DAYD = julianToDatenum( tsg.DAYD ); - -% Variables holding data from the main TSG -% data series 1 -%----------------------------------------- - -% measured variables -%----------------------------------------- -%if isempty(tsg.PRES) - tsg.PRES = nc{'PRES'}(:); -%end - -%if isempty(tsg.SSJT) - tsg.SSJT = nc{'SSJT'}(:); - tsg.SSJT_STD = nc{'SSJT_STD'}(:); - tsg.SSJT_STD_CAL = nc{'TEMP_STD_CAL'}(:); -%end - -%if isempty(tsg.CNDC) - tsg.CNDC = nc{'CNDC'}(:); - tsg.CNDC_STD = nc{'CNDC_STD'}(:); - tsg.CNDC_CAL = nc{'CNDC_CAL'}(:); -%end - -% intake temperature variable -%----------------------------------------- -tsg.SSTP = nc{'SSTP'}(:); -tsg.SSTP_QC = nc{'SSTP_QC'}(:); -tsg.SSTP_CAL = nc{'SSTP_CAL'}(:); -tsg.SSTP_ADJUSTED = nc{'SSTP_ADJUSTED'}(:); -tsg.SSTP_ADJUSTED_ERROR = nc{'SSTP_ADJUSTED_ERROR'}(:); -tsg.SSTP_ADJUSTED_QC = nc{'SSTP_ADJUSTED_QC'}(:); -tsg.SSTP_ADJUSTED_HIST = nc{'HIST_SSTP_ADJUSTED'}(:); - -% derived variables -%----------------------------------------- -tsg.SSPS = nc{'SSPS'}(:); -tsg.SSPS_QC = nc{'SSPS_QC'}(:); -tsg.SSPS_CAL = nc{'SSPS_CAL'}(:); -tsg.SSPS_ADJUSTED = nc{'SSPS_ADJUSTED'}(:); -tsg.SSPS_ADJUSTED_ERROR = nc{'SSPS_ADJUSTED_ERROR'}(:); -tsg.SSPS_ADJUSTED_QC = nc{'SSPS_ADJUSTED_QC'}(:); -tsg.SSPS_ADJUSTED_HIST = nc{'HIST_SSPS_ADJUSTED'}(:); - -% data series 2 -%----------------------------------------- - -% water samples -%----------------------------------------- -tsg.DATE_WS = nc{'DATE_WS'}(:,:); -tsg.DAYD_WS = julianToDatenum(nc{'DAYD_WS'}(:)); -tsg.LATX_WS = nc{'LATX_WS'}(:); -tsg.LONX_WS = nc{'LONX_WS'}(:); -tsg.SSPS_WS = nc{'SSPS_WS'}(:); -tsg.SSPS_WS_QC = nc{'SSPS_WS_QC'}(:); -tsg.SSPS_WS_ANALDATE = nc{'SSPS_WS_ANALDATE'}(:,:); -tsg.SSPS_WS_BOTTLE = nc{'SSPS_WS_BOTTLE'}(:,:); - -v=var(nc); -for i=1:length(v) - assignin('base',char(ncnames(v{i})),nc{char(ncnames(v{i}))}(:)); + +% get global attributes: meta data +% -------------------------------- +global_att = att(nc); + +for i=1:length(global_att) + + % extract name and value from netcdf globals attributes + % ----------------------------------------------------- + attribute = name(global_att{i}); + value = global_att{i}(:); + + % assign globals attributes in base workspace + % ------------------------------------------- + assignin('base', attribute, value); + + % populate tsg structure with globals attributes + % ---------------------------------------------- + tsg.(attribute) = value; end -a=att(nc); -for i=1:length(a) - assignin('base',char(ncnames(a{i})),nc{char(ncnames(a{i}))}(:)); +% get variables describing TSG installation +% ----------------------------------------- +variables = var(nc); + +for i=1:length(variables) + + % extract name and value from netcdf variables + % -------------------------------------------- + variable = name(variables{i}); + value = variables{i}(:); + + % assign netcdf variables in base workspace + % ----------------------------------------- + assignin('base', variable, value); + + % populate tsg structure with netcdf variables + % -------------------------------------------- + tsg.(variable) = value; + + % transforme julian days variables to Matlab datenum + % -------------------------------------------------- + if strmatch('DAYD', variable) + tsg.(variable) = julianToDatenum(tsg.(variable)); + end end % Save the data in the application GUI -- GitLab