Newer
Older
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
function [error] = readTsgDataSDF( hMainFig, filename )
% readAsciiTsg( hMainFig, filename )
% Function to read TSG data in SDF format
% (standard ORE-SSS format until 2005)
%
% 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 code value
% -------------------------
NO_CONTROL = tsg.qc.hash.NO_CONTROL.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);
% SDF format has no header
% Columns are:
% ? call_sign cyc_mes yyyymmddHHMM 100*latx 100*lonx 100*ssjt 1000*ssps
% ---------------------------------------------------------------------
format = '%s %s %s %s %d %d %d %d %d';
% Read the data in a cell
% -----------------------
cellData = textscan( fid, format );
% Check the file is for a single ship/trip
% ----------------------------------------
nrecords=length(cellData{8});
call_sign=char(cellData{2}(1));
cycle_mesure=char(cellData{3}(1));
if ~isempty(find(call_sign(ones(1,nrecords),:)~=char(cellData{2})))...
| ~isempty(find(cycle_mesure(ones(1,nrecords),:)~=char(cellData{3})))
msg_error = ['TSG_GOSUD file_lecture : Open file error : ' filename];
warndlg( msg_error, 'SDF error dialog');
sprintf('...file %s contains data from several ships/trips\n', filename);
error = -1;
return;
end
% Fill TSG attributes and variables
% ---------------------------------
tsg.SHIP_CALL_SIGN = call_sign;
tsg.CYCLE_MESURE = cycle_mesure;
tsg.report.tsgfile = filename;
sec='00';
tsg.DATE = cat(2,char(cellData{4}),sec(ones(1,nrecords),:));
tsg.DAYD = datenum(tsg.DATE,'yyyymmddHHMMSS');
tsg.LATX = double(cellData{5})/100;
tsg.LONX = double(cellData{6})/100;
tsg.SSJT = double(cellData{7})/100;
tsg.SSPS = double(cellData{8})/1000;
% Fill external data variables
% ----------------------------
ext=find(cellData{9}~=0);
if ~isempty(ext)
next=length(ext);
tsg.DATE_EXT = tsg.DATE(ext,:);
tsg.DAYD_EXT = tsg.DAYD(ext,:);
tsg.LATX_EXT = tsg.LATX(ext,:);
tsg.LONX_EXT = tsg.LONX(ext,:);
tsg.SSPS_EXT = double(cellData{9}(ext,:))/1000;
tsg.SSTP_EXT = NaN * ones(next,1);
tsg.SSPS_EXT_QC = int8(NO_CONTROL) * int8(ones(next,1));
tsg.SSTP_EXT_QC = int8(NO_CONTROL) * int8(ones(next,1));
type='WS ';
tsg.SSPS_EXT_TYPE = type(ones(1,next),:);
type='UNKN';
tsg.SSTP_EXT_TYPE = type(ones(1,next),:);
date_anal = '19500101000000';
tsg.SSPS_EXT_ANALDATE = date_anal( ones(1,next), :);
nbottle = '0 ';
tsg.SSPS_EXT_BOTTLE = nbottle( ones(1,next), :);
end
% populate tsg.file structure
% ---------------------------
[tsg.file.pathstr, tsg.file.name, tsg.file.ext, tsg.file.versn] = ...
fileparts(filename);
% Perform some automatic tests
% -----------------------------
automaticQC( hMainFig );
tsg.file.type = 'SDF';
% 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