%open file
fid=fopen(fname);

%header
line = fgetl(fid);
while not(strcmp(line(1), '*'))
    fprintf([line(1:end), '\n'])
    line = fgetl(fid);
end
fprintf([line(1:end), '\n'])
line = fgetl(fid);
fprintf([line(1:end), '\n'])
fprintf('\n \n')

%read profiles
iperf=0;
while 1
iperf=iperf+1;
%sub-header
   for iline=1:4
      line=fgetl(fid);
   end
   if line==-1; break;end;
%read name of profile
   x= sscanf(line,'%s',1);
   ux=sscanf(line,'%s',2);
   line=fgetl(fid);
   y= sscanf(line,'%s',1);
   uy=sscanf(line,'%s',2);
   line=fgetl(fid);
   z= sscanf(line,'%s',1);
   uz=sscanf(line,'%s',2);
   if(not(strcmp(uz(3), '['))) uz=z;end;

   line=fgets(fid);
%read number of times and positions
   nx=fscanf(fid,'%d');
   line=fgets(fid);
   ny=fscanf(fid,'%d');
   line=fgets(fid);
   if isempty(nx); break;end;
%read profiles
   rperf=fscanf(fid,'%e',[1,nx]);
   time=fscanf(fid,'%e',1);
   perf=fscanf(fid,'%e',[1,nx]);


   xx(iperf)={x};
   rperfx(iperf,:)=rperf(:);
   zx(iperf)={z};
   perfx(iperf,:)=perf(:);
%plot
   figure
   plot(rperf,perf,'o') 
   xlabel(ux)
   ylabel(uz)
%read footer
   line=fgets(fid);
   line = fgetl(fid);
   while not(strcmp(line(1), '*'))
      line = fgetl(fid);
   end
   line = fgetl(fid);

end

%close file
fclose(fid);

switch iperf-1
   case 1
       profiles=struct(xx{1},rperfx(1,:),zx{1},perfx(1,:));
   case 2
       profiles=struct(xx{1},rperfx(1,:),zx{1},perfx(1,:),...
	              xx{2},rperfx(2,:),zx{2},perfx(2,:));
   case 3
       profiles=struct(xx{1},rperfx(1,:),zx{1},perfx(1,:),...
                      xx{2},rperfx(2,:),zx{2},perfx(2,:),...
		      xx{3},rperfx(3,:),zx{3},perfx(3,:));
   case 4
       profiles=struct(xx{1},rperfx(1,:),zx{1},perfx(1,:),...
                      xx{2},rperfx(2,:),zx{2},perfx(2,:),...
                      xx{3},rperfx(3,:),zx{3},perfx(3,:),...
                      xx{4},rperfx(4,:),zx{3},perfx(4,:));
   case 5
       profiles=struct(xx{1},rperfx(1,:),zx{1},perfx(1,:),...
                      xx{2},rperfx(2,:),zx{2},perfx(2,:),...
                      xx{3},rperfx(3,:),zx{3},perfx(3,:),...
                      xx{4},rperfx(4,:),zx{4},perfx(4,:),...
                      xx{5},rperfx(5,:),zx{5},perfx(5,:));
   case 6
       profiles=struct(xx{1},rperfx(1,:),zx{1},perfx(1,:),...
                      xx{2},rperfx(2,:),zx{2},perfx(2,:),...
                      xx{3},rperfx(3,:),zx{3},perfx(3,:),...
                      xx{4},rperfx(4,:),zx{4},perfx(4,:),...
                      xx{5},rperfx(5,:),zx{5},perfx(5,:),...
                      xx{6},rperfx(6,:),zx{6},perfx(6,:));
   case 7
       profiles=struct(xx{1},rperfx(1,:),zx{1},perfx(1,:),...
                      xx{2},rperfx(2,:),zx{2},perfx(2,:),...
                      xx{3},rperfx(3,:),zx{3},perfx(3,:),...
                      xx{4},rperfx(4,:),zx{4},perfx(4,:),...
                      xx{5},rperfx(5,:),zx{5},perfx(5,:),...
                      xx{6},rperfx(6,:),zx{6},perfx(6,:),...
                      xx{7},rperfx(7,:),zx{7},perfx(7,:));
   case 8
       profiles=struct(xx{1},rperfx(1,:),zx{1},perfx(1,:),...
                      xx{2},rperfx(2,:),zx{2},perfx(2,:),...
                      xx{3},rperfx(3,:),zx{3},perfx(3,:),...
                      xx{4},rperfx(4,:),zx{4},perfx(4,:),...
                      xx{5},rperfx(5,:),zx{5},perfx(5,:),...
                      xx{6},rperfx(6,:),zx{6},perfx(6,:),...
                      xx{7},rperfx(7,:),zx{7},perfx(7,:),...
                      xx{8},rperfx(8,:),zx{8},perfx(8,:));
   case 9
       profiles=struct(xx{1},rperfx(1,:),zx{1},perfx(1,:),...
                      xx{2},rperfx(2,:),zx{2},perfx(2,:),...
                      xx{3},rperfx(3,:),zx{3},perfx(3,:),...
                      xx{4},rperfx(4,:),zx{4},perfx(4,:),...
                      xx{5},rperfx(5,:),zx{5},perfx(5,:),...
                      xx{6},rperfx(6,:),zx{6},perfx(6,:),...
                      xx{7},rperfx(7,:),zx{7},perfx(7,:),...
                      xx{8},rperfx(8,:),zx{8},perfx(8,:),...
                      xx{9},rperfx(9,:),zx{9},perfx(9,:));
   case 10
       profiles=struct(xx{1},rperfx(1,:),zx{1},perfx(1,:),...
                      xx{2},rperfx(2,:),zx{2},perfx(2,:),...
                      xx{3},rperfx(3,:),zx{3},perfx(3,:),...
                      xx{4},rperfx(4,:),zx{4},perfx(4,:),...
                      xx{5},rperfx(5,:),zx{5},perfx(5,:),...
                      xx{6},rperfx(6,:),zx{6},perfx(6,:),...
                      xx{7},rperfx(7,:),zx{7},perfx(7,:),...
                      xx{8},rperfx(8,:),zx{8},perfx(8,:),...
                      xx{9},rperfx(9,:),zx{9},perfx(9,:),...
                      xx{10},rperfx(10,:),zx{10},perfx(10,:));
end
