title: Why I am suddently getting invalid file identifier error in MATLAB?
body: <p>Code:</p>
  
  <pre><code>list_of_files=dir(fullfile('/home/username/Desktop/Old/MTP/tfcodev2p1/data/', '*.dat'));
  </code></pre>
  
  <p>There are 50 dat files in that folder. Weird thing is it was working perfectly alright till last night. Now I am suddenly getting this error. Error: </p>
  
  <pre><code>Error using fseek
  Invalid file identifier.  Use fopen to generate a
  valid file identifier.
  
  Error in getvar&gt;get_convar (line 162)
  fseek(f,8*mesh.n*(sim.nvars*t+VARS) , 'bof');
  
  Error in getvar (line 82)
    data=get_convar(fname,sim,mesh,VARS,t);
  
  Error in realn (line 34)
         D1=getvar(list_of_files(i).name,sim,mesh,'rhoi',sim.nsaves);
  </code></pre>
  
  <p>I am working on Ubuntu 12.04. I have tried putting my data in different folder but am still getting the same error.</p>
  
  <p>Here is the code.
  File realn.m:</p>
  
  <pre><code>list_of_files=dir(fullfile('/home/rishi/Desktop/Old/MTP/tfcodev2p1/data', '*.dat'));
  %simulation details
  %display(list_of_files.name);
  hold off;
  sim.tend=0.1;
  sim.gamma=5.0/3.0;
  sim.nsaves=1;
  sim.nvars=20;
  sim.dim=1;
  sim.mass_ratio=1.0;
  %mesh details
  mesh.nx=100; %number of cells in x-direction
  mesh.ny=1; %number of cells in y-direction
  mesh.maxx=1.0;
  mesh.maxy=0;
  mesh.n=mesh.nx*mesh.ny;
  mesh.x=linspace(0,mesh.maxx,mesh.nx);
  
  N=100;
  n=51;
  tau=0.0001;
  h=1/N;
  lambda=tau/h;
  mu=lambda/2;
  uf=zeros(n,1);
  uf1=zeros(n,1);
  uf2=zeros(n,1);
  phi=zeros(n,1);
  for i=1:n
      phi(i,1)=2*pi*i/N;    
  end
  for i=1:length(list_of_files)
     display(list_of_files(i).name)
         D1=getvar(list_of_files(i).name,sim,mesh,'rhoi',sim.nsaves);
         D2=getvar(list_of_files(i).name,sim,mesh,'rhoi',0);
     for j=1:N
         uf1(i,1)=uf1(i,1)+(D1(j)*exp(-1i*j*phi(i)));
         uf2(i,1)=uf2(i,1)+(D2(j)*exp(-1i*j*phi(i)));
     end
     uf1(i,1)=uf1(i,1)/100;
     uf2(i,1)=uf2(i,1)/100;
  end
  </code></pre>
  
  <p>getvar.m</p>
  
  <pre><code>function data=getvar(fname,sim,mesh,V,t)
   NVARS=36;
   VARS=0;
   //switch upper(V)
  
  
   if (VARS&lt;sim.nvars)
    data=get_convar(fname,sim,mesh,VARS,t);
   elseif(VARS&lt;NVARS)
    data=get_extravar(fname,sim,mesh,VARS,t);
   else
      display('WRONG Variable: Check function getvars()')
   end
  
  function data=get_extravar(fname,sim,mesh,VARS,t)
  
  switch VARS
      case {20}
          mxe=get_convar(fname,sim,mesh,6,t);
          data=-mxe/sim.mass_ratio;    
      case {21}
          mye=get_convar(fname,sim,mesh,7,t);
          data=-mye/sim.mass_ratio;            
      case {22}
          mze=get_convar(fname,sim,mesh,8,t);
          data=-mze/sim.mass_ratio;      
      case {23}
          mxi=get_convar(fname,sim,mesh,1,t);
          data=mxi; %assuume that m_i=1.0 
      case {24}
          myi=get_convar(fname,sim,mesh,2,t);
          data=myi; %assuume that m_i=1.0 
      case {25}
          mzi=get_convar(fname,sim,mesh,3,t);
          data=myi; %assuume that m_i=1.0 
      case {26}
          rhoe=get_convar(fname,sim,mesh,5,t);
          mxe=get_convar(fname,sim,mesh,6,t);
          data=mxe./rhoe;    
      case {27}
          rhoe=get_convar(fname,sim,mesh,5,t);
          mye=get_convar(fname,sim,mesh,7,t);
          data=mye./rhoe;
      case {28}
          rhoe=get_convar(fname,sim,mesh,5,t);
          mze=get_convar(fname,sim,mesh,8,t);
          data=mze./rhoe;
      case {29}
          rhoi=get_convar(fname,sim,mesh,0,t);
          mxi=get_convar(fname,sim,mesh,1,t);
          data=mxi./rhoi;
      case {30}
          rhoi=get_convar(fname,sim,mesh,0,t);
          myi=get_convar(fname,sim,mesh,2,t);
          data=myi./rhoi;
      case {31}
          rhoi=get_convar(fname,sim,mesh,0,t);
          mzi=get_convar(fname,sim,mesh,3,t);
          data=mzi./rhoi;     
      case {32}
          mxe=get_convar(fname,sim,mesh,6,t);
          mye=get_convar(fname,sim,mesh,7,t);
          mze=get_convar(fname,sim,mesh,8,t);
          data=sqrt(mxe.^2 + mye.^2 + mze.^2);
      case {33}
          mxi=get_convar(fname,sim,mesh,1,t);
          myi=get_convar(fname,sim,mesh,2,t);
          mzi=get_convar(fname,sim,mesh,3,t);
          data=sqrt(mxi.^2 + myi.^2 + mzi.^2);
      case {34}
          mze=get_convar(fname,sim,mesh,8,t);
          mzi=get_convar (fname,sim,mesh,3,t);
          data=abs(mzi-mze/sim.mass_ratio);   
     case {35}
         mxe=get_convar(fname,sim,mesh,6,t);
         mye=get_convar(fname,sim,mesh,7,t);
         mze=get_convar(fname,sim,mesh,8,t);
  
          mxi=get_convar (fname,sim,mesh,1,t);
          myi=get_convar (fname,sim,mesh,2,t);
          mzi=get_convar (fname,sim,mesh,3,t);
          data=abs(mxi + myi + mzi-(mxe+mye+mze)/sim.mass_ratio);        
  end
  
  function data=get_convar(fname,sim,mesh,VARS,t)
  f=fopen(fname,'r');
  if (VARS&lt;sim.nvars)
  fseek(f,8*mesh.n*(sim.nvars*t+VARS) , 'bof');
  if (sim.dim==1)
  data=fread(f,[mesh.nx],'float64');
  elseif(sim.dim==2)
      data=fread(f,[mesh.ny,mesh.nx],'float64');
  else
       error('Check Dimension');
  end
  else
      error('Variable is out of range Use function get_extravar')
  end
  data=data';
  fclose(f);
  </code></pre>