I finally got it right by taking help from another forum after so many days. Here is the code
function read_grid
IM=241;
JM=131;
fid = fopen('grid.txt','r');
for J=1:JM
for I=1:IM
buffer = fscanf(fid,[repmat('%f',1,7) '/n']);
X(I,J)=buffer(1);
Y(I,J)=buffer(2);
XIX(I,J)=buffer(3);
XIY(I,J)=buffer(4);
ETAX(I,J)=buffer(5);
ETAY(I,J)=buffer(6);
JJ(I,J)=buffer(7);
end
end
fclose(fid);
end