function y = open(filename)
%asumir informacion de entrada
%bands numero de bandas
%lines numero de lineas
%columns numero de columnas
%format image format
%psize pixel size
%b2u vector de largo n con los numeros de bandas n a usarse para el analisis
%Si desea observar distintas bandas solo tiene que modificar los valores
%de este vector
%y= hyperimg(bands,lines,columns,format,psize,b2u)
%filename=imgin;
bands=220;
lines=145;
columns=145;
pixelsize=9;
b2u=[17 27 50];

fid = fopen(filename,'r','s');

switch(pixelsize)   %Arreglo de casos para las precisiones de imagen a usarse
case 1         % psize es la precision, nb es el numero de bytes por dato
   psize = ('char'); 
   nb = 1;
case 2
   psize = ('schar');
   nb = 1;
case 3
   psize = ('uchar');
   nb = 1;
case 4
   psize = ('int8');
   nb = 1;
case 5
	psize = ('int16');
   nb = 2;
case 6
      psize = ('int32');
   nb = 4;
case 7
   psize = ('int64');
   nb = 8;
case 8
   psize = ('uint8');
   nb = 1;
case 9
   psize = ('uint16');
   nb = 2;
case 10
   psize = ('uint32');
   nb = 4;
case 11
   psize = ('uint64');
   nb = 8;
case 12
   psize = ('float32');
   nb = 4;
case 13
   psize = ('float64');
   nb = 8;
case 14
   psize = ('double');
   nb = 8;
end   
   

%BIS or BIP format
%el vector a leer contiene pixel1 todas las bandas, pixel2 todas las bandas ...
newcolumns = lines*columns;
[i newlines] = size(b2u);

%busca primera banda de bands to use
b=b2u-1;
c = b*nb;
d=bands-1;

im_bis=zeros(newlines, newcolumns);

for n = 1:newlines,
   fseek(fid,c(1,n),'bof');
   for m=1:(newcolumns-1),
      im_bis(n,m) = fread(fid,1,psize);
      %ftell(fid);
      fseek(fid,(d*nb),'cof');
   end
	im_bis(n,newcolumns) = fread(fid,1,psize);
end

fclose(fid);

%y = im_bis;
for i = 1:newlines,
	img1(:,:,i) = reshape(im_bis(i,:), [columns lines])';%hypercube image with selected bands
end

val = max(max(max(img1)));

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 figure						%Prueba Spot
 for x=1:3  					%Image spot
 picture(:,:,x)= (img1(:,:,x)/val);
 end
 image(picture)
 %imshow(picture,'notruesize')
 clear picture
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

y = img1;
