Skip to content
Snippets Groups Projects
Commit 53c886d4 authored by leprob001's avatar leprob001
Browse files

Added first version of ARGO netCDF trajectory file export.

parent 84b58f5b
No related branches found
No related tags found
No related merge requests found
313 314
\ No newline at end of file \ No newline at end of file
function [] = saveArgoTrajectoryFile(~, ~)
%SAVERFC Saves the argo trajectory netcdf file to disk.
% Detailed explanation goes here
global artoaWorkspace artoaConfig artoaDataInput;
%% Get selected trajectory
trajectoryIndex = artoaWorkspace.trajectoryOutput.tableGeneratedTracksSelectedRow;
trajectory = artoaWorkspace.trajectoryOutput.trajectories{trajectoryIndex};
%% Ask for filename
folder = artoa.data.getMember(artoaConfig, {'directory', 'argotraj'}, pwd());
filter = artoa.data.getMember(artoaConfig, {'filemask', 'argotraj'}, '*.nc');
[filename, pathname] = uiputfile(fullfile(folder, filter));
if filename == 0
return;
end
filepath = fullfile(pathname, filename);
artoa.save.argo_trajectory(filepath, artoaDataInput.rfb, trajectory);
end
...@@ -22,6 +22,7 @@ callbacks.loadSoundsourceFile = @artoa.controller.file.loadSoundSourceFile; ...@@ -22,6 +22,7 @@ callbacks.loadSoundsourceFile = @artoa.controller.file.loadSoundSourceFile;
callbacks.saveRfc = @artoa.controller.file.saveRfc; callbacks.saveRfc = @artoa.controller.file.saveRfc;
callbacks.saveInterim = @artoa.controller.file.saveInterim; callbacks.saveInterim = @artoa.controller.file.saveInterim;
callbacks.saveOptimumTables = @artoa.controller.file.saveOptimumTables; callbacks.saveOptimumTables = @artoa.controller.file.saveOptimumTables;
callbacks.saveArgoTrajectory = @artoa.controller.file.saveArgoTrajectoryFile;
callbacks.saveTrajectoryToProfile = @artoa.controller.file.trajectory2profile.open; callbacks.saveTrajectoryToProfile = @artoa.controller.file.trajectory2profile.open;
callbacks.loadArtoaIni = @artoa.controller.file.reloadArtoaIni; callbacks.loadArtoaIni = @artoa.controller.file.reloadArtoaIni;
callbacks.reloadSoundsourceFile = @artoa.controller.file.reloadSoundSourceFile; callbacks.reloadSoundsourceFile = @artoa.controller.file.reloadSoundSourceFile;
......
...@@ -13,6 +13,7 @@ availableCallbacks = { ... ...@@ -13,6 +13,7 @@ availableCallbacks = { ...
'loadSoundsourceFile', ... 'loadSoundsourceFile', ...
'saveRfc', ... 'saveRfc', ...
'saveInterim', ... 'saveInterim', ...
'saveArgoTrajectory', ...
'saveOptimumTables', ... 'saveOptimumTables', ...
'saveTrajectoryToProfile', ... 'saveTrajectoryToProfile', ...
'loadArtoaIni', ... 'loadArtoaIni', ...
...@@ -133,6 +134,12 @@ uimenu( ... ...@@ -133,6 +134,12 @@ uimenu( ...
'Callback', pCallbacks.saveInterim ... 'Callback', pCallbacks.saveInterim ...
); );
uimenu( ...
artoaGui.main.menus.fileSave, ...
'Label', 'ARGO trajectory file', ...
'Callback', pCallbacks.saveArgoTrajectory ...
);
uimenu( ... uimenu( ...
artoaGui.main.menus.fileSave, ... artoaGui.main.menus.fileSave, ...
'Label', 'Optimum tables', ... 'Label', 'Optimum tables', ...
......
function [outputArg1,outputArg2] = argo_trajectory(p_filepath, p_rfb, p_trajectory)
%ARGO_TRAJECTORY Summary of this function goes here
% Detailed explanation goes here
%% Prepare required variables
%% Remove file if exists
if exist(p_filepath, 'file')
delete(p_filepath);
end
%% Create netCDF file
ncid = netcdf.create(p_filepath, 'CLOBBER');
%% Define dimensions
DIM_DATE_TIME = netcdf.defDim(ncid, 'DATE_TIME', 14);
DIM_STRING2 = netcdf.defDim(ncid, 'STRING2', 2);
DIM_STRING4 = netcdf.defDim(ncid, 'STRING4', 4);
DIM_STRING8 = netcdf.defDim(ncid, 'STRING8', 8);
DIM_STRING16 = netcdf.defDim(ncid, 'STRING16', 16);
DIM_STRING32 = netcdf.defDim(ncid, 'STRING32', 32);
DIM_STRING64 = netcdf.defDim(ncid, 'STRING64', 64);
DIM_N_PARAM = netcdf.defDim(ncid, 'N_PARAM', 2);
%DIM_N_MEASUREMENT = netcdf.defDim(ncid, 'N_MEASUREMENT', netcdf.getConstant('NC_UNLIMITED'));
DIM_N_MEASUREMENT = netcdf.defDim(ncid, 'N_MEASUREMENT', length(p_trajectory.date));
DIM_N_CYCLE = netcdf.defDim(ncid, 'N_CYCLE', 1); % TODO: needs to be determined if it is correct!
DIM_N_HISTORY = netcdf.defDim(ncid, 'N_HISTORY', 1);
%% Define variables for general trajectory file information
ID_DATA_TYPE = netcdf.defVar(ncid, 'DATA_TYPE', 'NC_CHAR', DIM_STRING16);
netcdf.putAtt(ncid, ID_DATA_TYPE, 'long_name', 'Data type');
netcdf.putAtt(ncid, ID_DATA_TYPE, 'conventions', 'Argo reference table 1');
netcdf.putAtt(ncid, ID_DATA_TYPE, '_FillValue', ' ');
ID_FORMAT_VERSION = netcdf.defVar(ncid, 'FORMAT_VERSION', 'NC_CHAR', DIM_STRING4);
netcdf.putAtt(ncid, ID_FORMAT_VERSION, 'long_name', 'File format version');
netcdf.putAtt(ncid, ID_FORMAT_VERSION, '_FillValue', ' ');
ID_HANDBOOK_VERSION = netcdf.defVar(ncid, 'HANDBOOK_VERSION', 'NC_CHAR', DIM_STRING16);
netcdf.putAtt(ncid, ID_HANDBOOK_VERSION, 'long_name', 'Data handbook version');
netcdf.putAtt(ncid, ID_HANDBOOK_VERSION, '_FillValue', ' ');
ID_REFERENCE_DATE_TIME = netcdf.defVar(ncid, 'REFERENCE_DATE_TIME', 'NC_CHAR', DIM_DATE_TIME);
netcdf.putAtt(ncid, ID_REFERENCE_DATE_TIME, 'long_name', 'Date of reference for Julian days');
netcdf.putAtt(ncid, ID_REFERENCE_DATE_TIME, 'conventions', 'YYYYMMDDHHMISS');
netcdf.putAtt(ncid, ID_REFERENCE_DATE_TIME, '_FillValue', ' ');
ID_DATE_CREATION = netcdf.defVar(ncid, 'DATE_CREATION', 'NC_CHAR', DIM_DATE_TIME);
netcdf.putAtt(ncid, ID_DATE_CREATION, 'long_name', 'Date of file creation');
netcdf.putAtt(ncid, ID_DATE_CREATION, 'conventions', 'YYYYMMDDHHMISS');
netcdf.putAtt(ncid, ID_DATE_CREATION, '_FillValue', ' ');
ID_DATE_UPDATE = netcdf.defVar(ncid, 'DATE_UPDATE', 'NC_CHAR', DIM_DATE_TIME);
netcdf.putAtt(ncid, ID_DATE_UPDATE, 'long_name', 'Date of update of this file');
netcdf.putAtt(ncid, ID_DATE_UPDATE, 'conventions', 'YYYYMMDDHHMISS');
netcdf.putAtt(ncid, ID_DATE_UPDATE, '_FillValue', ' ');
%% Define variables for general information about the float
ID_PLATFORM_NUMBER = netcdf.defVar(ncid, 'PLATFORM_NUMBER', 'NC_CHAR', DIM_STRING8);
netcdf.putAtt(ncid, ID_PLATFORM_NUMBER, 'long_name', 'Float unique identifier');
netcdf.putAtt(ncid, ID_PLATFORM_NUMBER, 'conventions', 'WMO float identifier : A9IIIII');
netcdf.putAtt(ncid, ID_PLATFORM_NUMBER, '_FillValue', ' ');
ID_PROJECT_NAME = netcdf.defVar(ncid, 'PROJECT_NAME', 'NC_CHAR', DIM_STRING64);
netcdf.putAtt(ncid, ID_PROJECT_NAME, 'long_name', 'Name of the project');
netcdf.putAtt(ncid, ID_PROJECT_NAME, '_FillValue', ' ');
ID_PI_NAME = netcdf.defVar(ncid, 'PI_NAME', 'NC_CHAR', DIM_STRING64);
netcdf.putAtt(ncid, ID_PI_NAME, 'long_name', 'Name of the principal investigator');
netcdf.putAtt(ncid, ID_PI_NAME, '_FillValue', ' ');
ID_TRAJECTORY_PARAMETERS = netcdf.defVar(ncid, 'TRAJECTORY_PARAMETERS', 'NC_CHAR', [DIM_N_PARAM, DIM_STRING16]);
netcdf.putAtt(ncid, ID_TRAJECTORY_PARAMETERS, 'long_name', 'List of available parameters for the station');
netcdf.putAtt(ncid, ID_TRAJECTORY_PARAMETERS, 'conventions', 'Argo reference table 3');
netcdf.putAtt(ncid, ID_TRAJECTORY_PARAMETERS, '_FillValue', ' ');
ID_DATA_CENTRE = netcdf.defVar(ncid, 'DATA_CENTRE', 'NC_CHAR', DIM_STRING2);
netcdf.putAtt(ncid, ID_DATA_CENTRE, 'long_name', 'Data centre in charge of float data processing');
netcdf.putAtt(ncid, ID_DATA_CENTRE, 'conventions', 'Argo reference table 4');
netcdf.putAtt(ncid, ID_DATA_CENTRE, '_FillValue', ' ');
ID_DATA_STATE_INDICATOR = netcdf.defVar(ncid, 'DATA_STATE_INDICATOR', 'NC_CHAR', DIM_STRING4);
netcdf.putAtt(ncid, ID_DATA_STATE_INDICATOR, 'long_name', 'Degree of processing the data have passed through');
netcdf.putAtt(ncid, ID_DATA_STATE_INDICATOR, 'conventions', 'Argo reference table 6');
netcdf.putAtt(ncid, ID_DATA_STATE_INDICATOR, '_FillValue', ' ');
ID_PLATFORM_TYPE = netcdf.defVar(ncid, 'PLATFORM_TYPE', 'NC_CHAR', DIM_STRING32);
netcdf.putAtt(ncid, ID_PLATFORM_TYPE, 'long_name', 'Type of float');
netcdf.putAtt(ncid, ID_PLATFORM_TYPE, 'conventions', 'Argo reference table 23');
netcdf.putAtt(ncid, ID_PLATFORM_TYPE, '_FillValue', ' ');
ID_FLOAT_SERIAL_NO = netcdf.defVar(ncid, 'FLOAT_SERIAL_NO', 'NC_CHAR', DIM_STRING32);
netcdf.putAtt(ncid, ID_FLOAT_SERIAL_NO, 'long_name', 'Serial number of the float');
netcdf.putAtt(ncid, ID_FLOAT_SERIAL_NO, '_FillValue', ' ');
ID_FIRMWARE_VERSION = netcdf.defVar(ncid, 'FIRMWARE_VERSION', 'NC_CHAR', DIM_STRING64);
netcdf.putAtt(ncid, ID_FIRMWARE_VERSION, 'long_name', 'Instrument firmware version');
netcdf.putAtt(ncid, ID_FIRMWARE_VERSION, '_FillValue', ' ');
ID_WMO_INST_TYPE = netcdf.defVar(ncid, 'WMO_INST_TYPE', 'NC_CHAR', DIM_STRING4);
netcdf.putAtt(ncid, ID_WMO_INST_TYPE, 'long_name', 'Coded instrument type');
netcdf.putAtt(ncid, ID_WMO_INST_TYPE, 'conventions', 'Argo reference table 8');
netcdf.putAtt(ncid, ID_WMO_INST_TYPE, '_FillValue', ' ');
ID_POSITIONING_SYSTEM = netcdf.defVar(ncid, 'POSITIONING_SYSTEM', 'NC_CHAR', DIM_STRING8);
netcdf.putAtt(ncid, ID_POSITIONING_SYSTEM, 'long_name', 'Positioning system');
netcdf.putAtt(ncid, ID_POSITIONING_SYSTEM, '_FillValue', ' ');
%% Create global attributes
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'title', 'Argo trajectory file');
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'institution', '');
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'source', 'Argo float');
% prepare datetime
dt = string(datetime('now', 'Format', 'yyyy-MM-dd HH:mm:ss', 'TimeZone', 'Z'));
dt = strsplit(dt, ' ');
dt = strjoin(dt, 'T');
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'history', dt + 'Z creation');
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'references', 'http://www.argodatamgt.org/Documentation');
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'comment', '');
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'user_manual_version', '3.2');
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'Conventions', 'Argo-3.1 CF-1.6');
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'featureType', 'trajectory');
%% Define trajectory variables
ID_JULD = netcdf.defVar(ncid, 'JULD', 'NC_DOUBLE', DIM_N_MEASUREMENT);
netcdf.putAtt(ncid, ID_JULD, 'long_name', 'Julian day (UTC) of each measurement relative to REFERENCE_DATE_TIME');
netcdf.putAtt(ncid, ID_JULD, 'standard_name', 'time');
netcdf.putAtt(ncid, ID_JULD, 'units', 'days since 1950-01-01 00:00:00 UTC');
netcdf.putAtt(ncid, ID_JULD, 'conventions', 'Relative julian days with decimal part (as parts of day)');
netcdf.putAtt(ncid, ID_JULD, 'resolution', 'X');
netcdf.putAtt(ncid, ID_JULD, '_FillValue', 999999);
netcdf.putAtt(ncid, ID_JULD, 'axis', 'T');
ID_LATITUDE = netcdf.defVar(ncid, 'LATITUDE', 'NC_DOUBLE', DIM_N_MEASUREMENT);
netcdf.putAtt(ncid, ID_LATITUDE, 'long_name', 'Latitude of each location');
netcdf.putAtt(ncid, ID_LATITUDE, 'standard_name', 'latitude');
netcdf.putAtt(ncid, ID_LATITUDE, 'units', 'degree_north');
netcdf.putAtt(ncid, ID_LATITUDE, '_FillValue', 99999);
netcdf.putAtt(ncid, ID_LATITUDE, 'valid_min', -90);
netcdf.putAtt(ncid, ID_LATITUDE, 'valid_max', 90);
netcdf.putAtt(ncid, ID_LATITUDE, 'axis', 'Y');
ID_LONGITUDE = netcdf.defVar(ncid, 'LONGITUDE', 'NC_DOUBLE', DIM_N_MEASUREMENT);
netcdf.putAtt(ncid, ID_LONGITUDE, 'long_name', 'Longitude of each location');
netcdf.putAtt(ncid, ID_LONGITUDE, 'standard_name', 'longitude');
netcdf.putAtt(ncid, ID_LONGITUDE, 'units', 'degree_east');
netcdf.putAtt(ncid, ID_LONGITUDE, '_FillValue', 99999);
netcdf.putAtt(ncid, ID_LONGITUDE, 'valid_min', -180);
netcdf.putAtt(ncid, ID_LONGITUDE, 'valid_max', 180);
netcdf.putAtt(ncid, ID_LONGITUDE, 'axis', 'X');
ID_PRES = netcdf.defVar(ncid, 'PRES', 'NC_DOUBLE', DIM_N_MEASUREMENT);
netcdf.putAtt(ncid, ID_PRES, 'long_name', 'Sea water pressure, equals 0 at sea-level');
netcdf.putAtt(ncid, ID_PRES, 'standard_name', 'sea_water_pressure');
netcdf.putAtt(ncid, ID_PRES, 'units', 'decibar');
netcdf.putAtt(ncid, ID_PRES, 'valid_min', '0.f');
netcdf.putAtt(ncid, ID_PRES, 'valid_max', '12000.f');
ID_TEMP = netcdf.defVar(ncid, 'TEMP', 'NC_DOUBLE', DIM_N_MEASUREMENT);
netcdf.putAtt(ncid, ID_TEMP, 'long_name', 'Sea temperature in-situ ITS-90 scale');
netcdf.putAtt(ncid, ID_TEMP, 'standard_name', 'sea_water_temperature');
netcdf.putAtt(ncid, ID_TEMP, 'units', 'degree_Celsius');
netcdf.putAtt(ncid, ID_TEMP, 'valid_min', '-2.5f');
netcdf.putAtt(ncid, ID_TEMP, 'valid_max', '40.f');
%
% ID_PSAL = netcdf.defVar(ncid, 'PSAL', 'NC_CHAR', DIM_N_MEASUREMENT);
% netcdf.putAtt(ncid, ID_PSAL, 'long_name', 'Practical salinity');
% netcdf.putAtt(ncid, ID_PSAL, 'standard_name', 'sea_water_salinity');
% netcdf.putAtt(ncid, ID_PSAL, 'units', 'psu');
% netcdf.putAtt(ncid, ID_PSAL, 'valid_min', '2.f');
% netcdf.putAtt(ncid, ID_PSAL, 'valid_max', '41.f');
% ID_JULD_STATUS = netcdf.defVar(ncid, 'JULD_STATUS', 'NC_CHAR', DIM_N_MEASUREMENT);
% netcdf.putAtt(ncid, ID_JULD_STATUS, 'long_name', 'Status of the date and time');
% netcdf.putAtt(ncid, ID_JULD_STATUS, 'conventions', 'Argo reference table 19');
% netcdf.putAtt(ncid, ID_JULD_STATUS, '_FillValue', ' ');
%
% ID_JULD_QC = netcdf.defVar(ncid, 'JULD_QC', 'NC_CHAR', DIM_N_MEASUREMENT);
% netcdf.putAtt(ncid, ID_JULD_QC, 'long_name', 'Quality on date and time');
% netcdf.putAtt(ncid, ID_JULD_QC, 'conventions', 'Argo reference table 2');
% netcdf.putAtt(ncid, ID_JULD_QC, '_FillValue', ' ');
%
%
% ID_JULD_ADJUSTED = netcdf.defVar(ncid, 'JULD_ADJUSTED', 'NC_CHAR', DIM_N_MEASUREMENT);
% netcdf.putAtt(ncid, ID_JULD_ADJUSTED, 'long_name', 'Adjusted julian day (UTC) of each measurement relative to REFERENCE_DAT_TIME');
% netcdf.putAtt(ncid, ID_JULD_ADJUSTED, 'standard_name', 'time');
% netcdf.putAtt(ncid, ID_JULD_ADJUSTED, 'units', 'days since 1950-01-01 00:00:00 UTC');
% netcdf.putAtt(ncid, ID_JULD_ADJUSTED, 'conventions', 'Relative julian days with decimal part (as parts of day)');
% netcdf.putAtt(ncid, ID_JULD_ADJUSTED, 'resultion', 'X');
% netcdf.putAtt(ncid, ID_JULD_ADJUSTED, '_FillValue', 999999);
% netcdf.putAtt(ncid, ID_JULD, 'axis', 'T');
%% End defintions
netcdf.endDef(ncid);
%% Fill variables for general trajectory file information
netcdf.putVar(ncid, ID_DATA_TYPE, pad('Argo trajectory', 16, 'right', ' '));
netcdf.putVar(ncid, ID_FORMAT_VERSION, pad('3.1', 4, 'right', ' '));
netcdf.putVar(ncid, ID_HANDBOOK_VERSION, pad('3.3', 16, 'right', ' '));
netcdf.putVar(ncid, ID_REFERENCE_DATE_TIME, pad('', 14, 'right', ' ')); % TODO:
netcdf.putVar(ncid, ID_DATE_CREATION, string(datetime('now', 'Format', 'yyyyMMddHHmmss', 'TimeZone', 'Z')));
netcdf.putVar(ncid, ID_DATE_UPDATE, string(datetime('now', 'Format', 'yyyyMMddHHmmss', 'TimeZone', 'Z')));
%% Fill variables for general float information
netcdf.putVar(ncid, ID_PLATFORM_NUMBER, pad('', 8, 'right', ' ')); % TODO:
netcdf.putVar(ncid, ID_PROJECT_NAME, pad(p_rfb.FLOAT.projectname, 64, 'right', ' '));
netcdf.putVar(ncid, ID_PI_NAME, pad('', 64, 'right', ' ')); % TODO:
%netcdf.putVar(ncid, ID_TRAJECTORY_PARAMETERS, [pad('PRES', 16, 'right', ' '); pad('TEMP', 16, 'right', ' '); pad('PSAL', 16, 'right', ' ')]);
netcdf.putVar(ncid, ID_TRAJECTORY_PARAMETERS, [pad('PRES', 16, 'right', ' '); pad('TEMP', 16, 'right', ' ')]);
netcdf.putVar(ncid, ID_DATA_CENTRE, ' '); % TODO:
netcdf.putVar(ncid, ID_DATA_STATE_INDICATOR, pad('', 4, 'right', ' ')); % TODO:
netcdf.putVar(ncid, ID_PLATFORM_TYPE, pad(p_rfb.FLOAT.type, 32, 'right', ' '));
netcdf.putVar(ncid, ID_FLOAT_SERIAL_NO, pad(string(p_rfb.FLOAT.floatname), 32, 'right', ' '));
netcdf.putVar(ncid, ID_FIRMWARE_VERSION, pad('', 64, 'right', ' ')); % TODO:
netcdf.putVar(ncid, ID_WMO_INST_TYPE, pad('', 4, 'right', ' ')); % TODO:
netcdf.putVar(ncid, ID_POSITIONING_SYSTEM, pad('', 8, 'right', ' ')); % TODO:
%% Fill dataset
netcdf.putVar(ncid, ID_JULD, p_trajectory.date);
netcdf.putVar(ncid, ID_LONGITUDE, p_trajectory.longitude);
netcdf.putVar(ncid, ID_LATITUDE, p_trajectory.latitude);
netcdf.putVar(ncid, ID_PRES, p_trajectory.pressure);
netcdf.putVar(ncid, ID_TEMP, p_trajectory.temperature);
%% Close file
netcdf.close(ncid);
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment