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
10d4bb70
Commit
10d4bb70
authored
17 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
just write datagui code to read XML trajectory files, need to be modified and update
parent
c24468af
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tsg_io/readTsgDataXML.m
+131
-4
131 additions, 4 deletions
tsg_io/readTsgDataXML.m
with
131 additions
and
4 deletions
tsg_io/readTsgDataXML.m
+
131
−
4
View file @
10d4bb70
...
@@ -16,13 +16,136 @@ function [error] = readTsgDataXML( hTsgGUI, filename)
...
@@ -16,13 +16,136 @@ function [error] = readTsgDataXML( hTsgGUI, filename)
% Caution : replace the fill-value with NaN
% Caution : replace the fill-value with NaN
% $Id$
% $Id$
% Get the data from the application GUI
% -------------------------------------
tsg
=
getappdata
(
hTsgGUI
,
'tsg_data'
);
% Display read file info on console
% ---------------------------------
fprintf
(
'\nREAD_XML_FILE\n'
);
tic
;
% Open the file
% Open the file
% -------------
% -------------
fid
=
fopen
(
filename
,
'r'
);
fd
=
fopen
(
file
(
self
),
'rt'
);
if
(
fd
==
-
1
)
warndlg
(
msg_error
,
'XML error dialog'
);
sprintf
(
'...cannot locate %s\n'
,
filename
);
error
=
-
1
;
return
;
end
fprintf
(
'...reading %s : '
,
filename
);
h
=
hashtable
;
%% parse le fichier XML
tree
=
xml_parseany
(
fileread
(
file
(
self
)
)
);
%data = tree.DATA{1}.CONTENT;
% decode l'entete, a completer
%tsg.CYCLE_MESURE = tree.ENTETE{1}.CYCLE_MESURE{1}.LIBELLE{1}.CONTENT;
tsg
.
DATA_ACQUISITION
=
tree
.
ENTETE
{
1
}
.
CYCLE_MESURE
{
1
}
.
INSTITUT
{
1
}
.
CONTENT
;
tsg
.
PLATFORME
=
tree
.
ENTETE
{
1
}
.
PLATEFORME
{
1
}
.
LIBELLE
{
1
}
.
CONTENT
;
tsg
.
TSG_TYPE
=
tree
.
ENTETE
{
1
}
.
INSTRUMENT
{
1
}
.
ATTRIBUTE
.
TYPE
;
fclose
(
fd
);
%% deuxieme lecture des donnees dans le fichier apres la balise <DATA>
% on lit la deuxieme ligne contenant les entetes des colonnes
fd
=
fopen
(
file
(
self
),
'rt'
);
while
~
feof
(
fd
)
line
=
fgetl
(
fd
);
[
tok
match
]
=
regexp
(
line
,
'<(\w+)>'
,
'tokens'
);
if
isempty
(
match
),
continue
,
end
if
strmatch
(
tok
{
1
},
'DATA'
),
break
,
end
end
% lit la ligne contenant les entetes des colonnes
header
=
fgetl
(
fd
);
%disp( ['Entete: ', header] );
variables
=
strread
(
header
,
'%s'
);
columns
=
length
(
variables
);
% cree l'equivalent d'une table de hashage des codes Roscop (GF3)
% valides -> colonne associe
for
i
=
1
:
columns
if
(
~
strcmp
(
variables
(
i
),
'N/A'
)
&&
~
strcmp
(
variables
(
i
),
'YEAR'
)
)
h
=
put
(
h
,
variables
{
i
},
i
);
elseif
(
strcmp
(
variables
(
i
),
'YEAR'
)
)
col_year
=
i
;
end
end
cles
=
keys
(
h
);
val
=
values
(
h
);
[
A
,
count
]
=
fscanf
(
fd
,
'%g'
,
[
columns
,
inf
]
);
%
nb
=
count
/
columns
;
disp
(
[
num2str
(
nb
),
' records'
]
);
%
% on inverse la matrice
A
=
A
'
;
% test si filtre median necessaire
root
=
get
(
0
,
'UserData'
);
prompt
=
{
'Enter median filter size:'
};
dlg_title
=
'Input for median filter'
;
num_lines
=
1
;
size
=
inputdlg
(
prompt
,
dlg_title
,
num_lines
,{
num2str
(
root
.
medianSize
)});
% si l'utilisateur sort par cancel, pas de filtre mais on ne sauvegarde pas
% la structure root
if
(
isempty
(
size
))
root
.
medianSize
=
0
;
else
root
.
medianSize
=
str2num
(
size
{
1
});
set
(
0
,
'UserData'
,
root
);
end
% gere les dates
year
=
A
(:,
col_year
);
year_base
=
year
(
1
);
% met la date au format YYYYMMDDHHmmss
ref_date
=
[
num2str
(
year_base
)
'0101000000'
];
%% attributs globaux (data_0d)
assignin
(
'base'
,
'CYCLE_MESURE'
,
tsg
.
CYCLE_MESURE
);
assignin
(
'base'
,
'INSTITUT'
,
tsg
.
CYCLE_MESURE
);
assignin
(
'base'
,
'INSTITUT'
,
tsg
.
PLATFORME
);
assignin
(
'base'
,
'INSTRUMENT'
,
tsg
.
TSG_TYPE
);
%% variables 1 dimension (data_1d)
assignin
(
'base'
,
'REFERENCE_DATE_TIME'
,
tsg
.
REFERENCE_DATE_TIME
);
for
i
=
1
:
length
(
cles
)
data
=
A
(:,
val
{
i
});
data
(
find
(
data
>
1e35
)
)
=
NaN
;
switch
cles
{
i
}
case
'DAYD'
% pre-allocation
%days = ones(nb,1);
%for k=1: nb % DAYD
% days(k) = to_day(year_base,to_date(year(k), data(k), 'n'));
%end
days
=
to_day
(
year_base
,
to_date
(
year
,
data
,
'n'
));
if
(
root
.
medianSize
>
0
)
% filtre median
days
=
medianf
(
days
,
root
.
medianSize
);
% affichage de la taille apres
fprintf
(
'...find %d records after median filter'
,
length
(
days
)
);
end
% cas de thermo antea
self
=
set
(
self
,
'data_1d'
,
cles
{
i
},
days
);
assignin
(
'base'
,
cles
{
i
},
days
);
case
{
'LATX'
,
'LONX'
}
if
(
root
.
medianSize
>
0
);
data
=
medianf
(
data
,
root
.
medianSize
);
end
% cas de thermo antea
self
=
set
(
self
,
'data_1d'
,
cles
{
i
},
data
);
assignin
(
'base'
,
cles
{
i
},
data
);
otherwise
if
(
root
.
medianSize
>
0
);
data
=
medianf
(
data
,
root
.
medianSize
);
end
% cas de thermo antea
self
=
set
(
self
,
'data_2d'
,
cles
{
i
},
data
);
assignin
(
'base'
,
cles
{
i
},
data
);
end
end
error
=
-
1
;
if
fid
~=
-
1
disp
(
'Read XML file, not yet implemeted ...'
);
% % Read the file
% % Read the file
% % -------------
% % -------------
% tsgData = fscanf(fid, '%d/%d/%d %d:%d:%d %f %f %f %f %d %f %f', ...
% tsgData = fscanf(fid, '%d/%d/%d %d:%d:%d %f %f %f %f %d %f %f', ...
...
@@ -57,6 +180,10 @@ if fid ~= -1
...
@@ -57,6 +180,10 @@ if fid ~= -1
% --------------
% --------------
fclose
(
fid
);
fclose
(
fid
);
% Display time to read file on console
% ------------------------------------
t
=
toc
;
fprintf
(
'...done (%6.2f sec).\n\n'
,
t
);
% Everything is not OK
% Everything is not OK
% -------------
% -------------
error
=
-
1
;
error
=
-
1
;
...
...
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