function [time,pitch,nb_harm,gain,ki,amp,phase,ceps] = loadHNM(fich, typeofread);

% loadHNM Charge un fichier d'analyse HNM. Le nom de fichier
%         doit etre specifie sans l'extension '_hnma'.
% Exemple : [time,pitch,nb_harm,gain,ki,amp,phase,ceps] = loadHNM('fich', 'typeofread');
% typeofread : float, double, ...

% Auteur : Olivier Cappe, 12/12/94 - 29/12/94
% changement : STYLIANOU Yannis (03/04/95)
% (c) TELECOM Paris, departement SIGNAL

% Nombre maximal d'harmoniques a priori (si il y en a plus, il
% semble que ca marche quand meme (feature MATLAB) !)
NB_HARM_MAX = 40;

if(nargin <2)
 typeofread = 'double';
end

fid = fopen([fich '_hnma.dsc'],'r');
DESC = fscanf(fid,'%d ',5);
fclose(fid);
fid = fopen([fich '_hnma.res'],'r');

% Declarations
time = zeros(DESC(2),1);
pitch = zeros(DESC(2),1);
nb_harm = zeros(DESC(2),1);
gain = zeros(DESC(2),1);
ki = zeros(DESC(2),(DESC(5)+1));
amp = zeros(DESC(2),NB_HARM_MAX+1);
phase = zeros(DESC(2),NB_HARM_MAX+1);
ceps = zeros(DESC(2),DESC(3));

% Lecture
for i = 1:DESC(2)
  time(i) = fread(fid,1,typeofread);
  pitch(i) = fread(fid,1,typeofread);
  nb_harm(i) = fread(fid,1,typeofread);
  gain(i) = fread(fid,1,typeofread);
  ki(i,:) = fread(fid,[1 (DESC(5)+1)],typeofread);
  amp(i,1:(nb_harm(i)+1)) = fread(fid,[1 (nb_harm(i)+1)],typeofread);
  phase(i,1:(nb_harm(i)+1)) = fread(fid,[1 (nb_harm(i)+1)],typeofread);
  ceps(i,:) = fread(fid,[1 (DESC(3))],typeofread);
end;
fclose(fid);

% On ne garde que la partie utile de amp et phase
n = max(nb_harm)+1;
phase = phase(:,1:n);
amp = amp(:,1:n);

