Newer
Older
gael.alory_legos.obs-mip.fr
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function [error] = readTsgDataNuka( hMainFig, filename )
% readTsgDataNuka( hMainFig, filename )
% Function to read TSG data from Nuka Arctica
% in Gilles Reverdin ASCII format (*.transmit*)
%
% Input
% -----
% hMainFig ........... Handle to the main user interface
% filename ........... Data filename
%
% Output
% ------
% error .............. 1: OK - -1 : an error occured
%
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');
% Get the fieldnames of tsg structure
% -----------------------------------
tsgNames = fieldnames(tsg);
nbFieldNames = length( tsgNames );
% Get NO_CONTROL, GOOD, PROBABLY_GOOD codes
% -----------------------------------------
NO_CONTROL = tsg.qc.hash.NO_CONTROL.code;
GOOD = tsg.qc.hash.GOOD.code;
PROBABLY_GOOD = tsg.qc.hash.PROBABLY_GOOD.code;
% Display read file info on console
% ---------------------------------
fprintf('\nREAD_ASCII_FILE\n'); tic;
% Open the file
% -------------
fid = fopen( filename, 'rt' );
% Check file
% -----------
if fid == -1
msg_error = ['TSG_GOSUD file_lecture : Open file error : ' filename];
warndlg( msg_error, 'ASCII error dialog');
sprintf('...cannot locate %s\n', filename);
error = -1;
return;
end
% Display more info about read file on console
% --------------------------------------------
fprintf('...reading %s : ', filename);
% .transmit format has no header
% Columns are:
% ? ship_name yyyy mm dd HHMM latx lonx ssjt ssps (sstp sstp_qc)
% ---------------------------------------------------------------------
theFormat = '%d %s %f %f %f %4c %f %f %f %f %f %d';
gael.alory_legos.obs-mip.fr
committed
% Read the data in a cell
% -----------------------
cellData = textscan( fid, theFormat );
gael.alory_legos.obs-mip.fr
committed
% Check the file is for NUKA ship
% -----------------------------------
nrecords=length(cellData{1});
ship_name=char(cellData{2}(1));
if ~isempty(find(ship_name(ones(1,nrecords),:)~=char(cellData{2})))
% | ~strcmp(ship_name,'NUKA')
gael.alory_legos.obs-mip.fr
committed
msg_error = ['TSG_GOSUD file_lecture : Open file error : ', filename,...
'...file contains data from several ships'];
gael.alory_legos.obs-mip.fr
committed
warndlg( msg_error, '.transmit* error dialog');
error = -1;
return;
end
% Fill TSG attributes
% --------------------
tsg.PLATFORM_NAME='nuka arctica';
tsg.SHIP_CALL_SIGN = 'OXYH2';
%tsg.CYCLE_MESURE = cycle_mesure;
tsg.report.tsgfile = filename;
% Fill hour and minute vectors accounting for blanks in HHMM char array
% ---------------------------------------------------------------------
hh=zeros(nrecords,1);
mm=zeros(nrecords,1);
blank=cellData{6}==' ';
% HHMM and HH M case
hh=str2num(cellData{6}(:,1:2));
mm=str2num(cellData{6}(:,3:4));
% H M and HMM case
HMM=find(blank(:,4));
if ~isempty(HMM)
hh(HMM)=str2num(cellData{6}(HMM,1:1));
mm(HMM)=str2num(cellData{6}(HMM,2:4));
end
% Fill other TSG variables
% ---------------------------------

jacques.grelet_ird.fr
committed
tsg.DATE = datestr([cellData{3} cellData{4} cellData{5} hh mm zeros(nrecords,1)],...
tsg.preference.date_format_variable);
tsg.DAYD = datenum(tsg.DATE, tsg.preference.date_format_variable);
gael.alory_legos.obs-mip.fr
committed
tsg.LATX = cellData{7};
tsg.LONX = cellData{8};
tsg.SSPS = cellData{10};
% by default, SSPS flagged GOOD as data have been corrected by G. Reverdin
% ------------------------------------------------------------------------
tsg.SSPS_QC=GOOD*ones(nrecords,1,'int32');
% check if there is data from external temperature sensor
% -------------------------------------------------------
if ~isempty(find(isfinite(cellData{11})))
tsg.SSJT = cellData{11};
tsg.SSTP = cellData{9};
% SSTP flagged GOOD if measured
% and PROBABLY_GOOD if estimated from SSJT
%-----------------------------------------
tsg.SSTP_QC = (1-cellData{12})*GOOD + cellData{12}*PROBABLY_GOOD;
else
tsg.SSJT = cellData{9};
end
% populate tsg.file structure
% ---------------------------
[tsg.file.pathstr, tsg.file.name, tsg.file.ext] = ...
gael.alory_legos.obs-mip.fr
committed
fileparts(filename);
% Perform some automatic tests
% -----------------------------
automaticQC( hMainFig );
tsg.file.type = 'ASCII';
% Save the data in the application GUI
% ------------------------------------
setappdata( hMainFig, 'tsg_data', tsg );
% Close the file
% --------------
fclose( fid );
% Display time to read file on console
% ------------------------------------
t = toc; fprintf('...done (%6.2f sec).\n\n',t);
% Everything OK
% -------------
error = 1;
end