function [dev] = emso2ml(file, fid)

if nargin < 2
   fid = -1;
end

root = 0;
if fid < 0
   fid = fopen(file, 'rt');
   if fid < 0 , error('Erro na abertura do arquivo.');end
   
   dev.name = str2mat(fscanf(fid, '%s /n'));	// process name
   n=fscanf(fid,'%d',1);		// time length
   dev.time = fscanf(fid, '%g', [n,1]);
   root = 1;
end

if ~ root
   dev.name = str2mat(fscanf(fid, '%s /n')); //device name
end

nv=fscanf(fid,'%d',1);	//number of variables
for i=1:nv
   name = str2mat(fscanf(fid, '%s /n'));
   ndim = fscanf(fid,'%d',1);	// number of dimension
   dim = fscanf(fid,'%d',[1,ndim]);
   nd = prod(dim);
   values = [];
   for j=1:nd
      ntime = fscanf(fid,'%d',1);		// time length
      values = [values, fscanf(fid,'%g',[ntime,1])];
   end
   dim = [ntime, dim(end:-1:1)];
   eval( [ 'dev.' name ' = reshape(values, dim);' ] );
end

ndev = fscanf(fid,'%d',1);	//number of base-devices
for i=1:ndev
   sub = emso2ml(file, fid);
   eval( [ 'dev.' sub.name ' = sub;' ] );
end

ndev = fscanf(fid,'%d',1);	//number of sub-devices
for i=1:ndev
   sub = emso2ml(file, fid);
   eval( [ 'dev.' sub.name ' = sub;' ] );
end

endfunction
