function ncmovie_general(nc_file,nc_file_dir,out_dir,x0,x1,y0,y1)

format compact

dfile = [nc_file_dir '/' nc_file '.nc'];
if (~exist(dfile,'file'))
  error(['File ' dfile ' does not exist!']);
  return
end

if(~exist(out_dir,'dir'))
  eval(['! mkdir -p ' out_dir]);
end

ncfile = netcdf(dfile,'nowrite');
%ni = ncfile{'ni'};
%ni10 = ni/10;
%nj = ncfile{'nj'};
%xx = ncfile{'x'}; if(isempty(xx)) xx = ncfile{'xx'}; end; x = xx(:);
%yy = ncfile{'y'}; if(isempty(yy)) yy = ncfile{'yy'}; end; y = yy(:);
rho = ncfile{'rho'};

nsize = size(rho);

nfram = nsize(1);   %% nr. of frames
typestr='jpg';      %% movie is JPG-files
namestr=[nc_file];    %% base name of .jpg or .gif files       
nam=namestr;

%minrho = min(min(rho(nfram,:,:)));
%maxrho = max(max(rho(nfram,:,:)));

%cbord=[minrho maxrho];
%ccont=linspace(minrho,maxrho,30);
%pos2 = [ 0 0 1 1];

%%  
%%  LOOP OVER FRAMES, INCLUDING FRAME 1
%%  
for kfram=1:nfram
%  if kfram==1
    %%
    %%   Preparing the figure window. This should not be changed
    %%
    h = figure;
%    set(gcf,'pos',[ 10 10 600 300] );   %  WINDOW SIZE  is 400 x 400
    set(gcf,'pos',[ 10 10 900 300] );   %  WINDOW SIZE  is 400 x 400
    set(gcf,'menu','none','numbertitle','off','name','NEWMOVIE') ;
    set(gcf,'menu','none');
    %set(gcf,'color','white');
    %%
    %%  This makes gray colormap can be changed
    %%
%  end
  %%
  %%
  %%    HERE COMES YOUR CODE FOR PRODUCING EACH OF THE FRAMES
  %%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

% draw one frame
  kfram
%  malujdens(dfile,kfram,x0,x1,y0,y1);
  malujener(dfile,kfram,9.72e9,1.35e11,x0,x1,y0,y1);
  title([num2str(kfram) ' ns']); 
  drawnow;
  pause(0.2);
  
%  % get one frame values
%  rhof = rho(kfram,:,:);
% 
%  pcolor(x,y,rhof);
%%  caxis([minp maxp]);
%  shading flat;
%  hold on;
%  contour(x,y,rhof,15,'k');
%  hold off;
%  set(gca,'XTickLabel',{' '},'YTickLabel',{' '});
%  axes('Units','normalized','Position',pos2,'XTickLabel',{' '});
%  pcolor(x,y,rhof);
%  shading flat;
%  caxis(cbord);
%  hold on;
%  contour(x,y,rhof,ccont,'k');
%  hold off;
%  set(gca,'XTickLabel',{' '},'YTickLabel',{' '});
%  drawnow;
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 %%
 %%    END OF THE DRAWING CODE IS HERE
 %%
 %% 
 %%    THE FOLLOWING PART PICKS THE FRAMES AND MAKES GIF IMAGES
 %%
 %%    IN PRINCIPLE, MATLAB CAN DO THIS, BUT THAT NEEDS 
 %%    A WELL TUNED MATLAB (The author never met one)
 %%
 
 % xwd  is  an  X  Window System window dumping utility.
 if typestr=='gif'
    eval( [ '!xwd -silent -name "NEWMOVIE " | xwdtopnm |  ppmtogif > ' ...
    out_dir '/' nam '_' num2str(kfram) '.gif' ] ) 
 end
 if typestr=='jpg'
    eval( [ '!xwd -silent -name "NEWMOVIE " | xwdtopnm |  cjpeg > ' ...
    out_dir '/' nam '_' num2str(kfram) '.jpg' ] ) 
 end 
 %%
 %%
 %%
 close(h);
end % over all the FRAMES
%%
%%
%%
%%   The following lines handle the production of the HTML
%%   YOU SHOULD NOT CHANGE MUCH HERE 
%%   UNLES YOU KNOW WHAT YOU ARE DOING
%%   
%%   
% get dimensions of the window
windim=get(gcf,'pos');

% print size of the window
windim(3),windim(4)

% delete all previously created temporary files
eval( [ '! rm -f tmp.txt tmp2.txt ' out_dir '/' nam '.html '  ]);

% Put PART1.txt into the output html file
eval([ '! cat ./matlabmovies/PART1.txt > ' ...
       out_dir '/' nam '.html ' ]);

% create a new temporary file 
fid=fopen('tmp.txt','w');

% description of the animation

line1=[ 'image_name = "'  nam '_' '";' ]; 
if typestr=='gif'
  line2=[ 'image_type = "gif";']; 
end
if typestr=='jpg'
  line2=[ 'image_type = "jpg";']; 
end    
line3=[ 'first_image = 1;' ]; 
line4=[ 'last_image  = ' num2str(nfram) '; ' ];
%line5=[ 'animation_height = ' num2str(windim(4)) '; '];             
%line6=[ 'animation_width = '  num2str(windim(3)) '; '];          
line5=[ 'animation_height = ' num2str(300) '; '];             
line6=[ 'animation_width = '  num2str(900) '; '];          

% put the description in the file

fprintf(fid,'%s%c%c', line1,setstr(10),setstr(13));
fprintf(fid,'%s%c%c', line2,setstr(10),setstr(13));
fprintf(fid,'%s%c%c', line3,setstr(10),setstr(13));
fprintf(fid,'%s%c%c', line4,setstr(10),setstr(13));
fprintf(fid,'%s%c%c', line5,setstr(10),setstr(13));
fprintf(fid,'%s%c%c', line6,setstr(10),setstr(13));

% close  the file
fclose(fid);

% append contents of the temporary file to the output html file
eval([ '! cat tmp.txt >> ' out_dir '/'  nam '.html ' ]);
  
% append PART2.TXT to the html file
eval([ '! cat ./matlabmovies/PART2.txt >> '  ...
       out_dir '/'  nam '.html ' ]);
 
% html code for the picture
lineL=[ '   document.write(" <P><IMG NAME=\"animation\" SRC=\"' ...
	nam '_' '1.gif\"HEIGHT=",animation_height, " WIDTH=", ' ...
	'animation_width, "\" >");' ];
% put html into a file
fid=fopen('tmp2.txt','w');
fprintf(fid,'%s%c%c', lineL,setstr(10),setstr(13)); 
fclose(fid);

% append tmp2.txt to the output html file
eval([ '! cat tmp2.txt >> ' out_dir '/' nam '.html ' ]);

% append PART3.txt to the output file 
eval([ '! cat ./matlabmovies/PART3.txt >> ' ...
       out_dir '/' nam '.html ' ]);  

% remove temporary files and close figure win.
eval('! rm tmp.txt tmp2.txt');
close(h);

