%[img head]=loadsir('green.sir'); % lambert
[img head]=loadsir('../../sir2cetb/queh-a-E2T04-10-10.sir'); % ease2

myfigure(1)
showsir(img,head)

%writesir('junk.sir',img,head)

%myfigure(2);
%[im h]=loadsir('junk.sir');
%showsir(im,h);

LLx=225;
LLy=200;
URx=325;
URy=320;
flg=1;
[imgout, headout]=sirsubregion(img, head, LLx, LLy, URx, URy, flg);

myfigure(3)
showsir(imgout,headout)

writesir('junk.sir',imgout,headout);

myfigure(4);
[im h]=loadsir('junk.sir');
showsir(im,h);

LLx=-30;
LLy=70;
LLy=60;
URx=-20;
URy=72;
URy=62;
[x, y] = latlon2pix1(LLx,LLy,head);
[lon,lat]=pix2latlon(x,y,head);
fprintf("%f %f  %f %f  %f %f\n",LLx,LLy,lon,lat,x,y);
[x, y] = latlon2pix1(URx,URy,head);
[lon,lat]=pix2latlon(x,y,head);
fprintf("%f %f  %f %f  %f %f\n",URx,URy,lon,lat,x,y);
flg=0;
[imgout, headout]=sirsubregion(img, head, LLx, LLy, URx, URy);

myfigure(5)
showsir(imgout,headout)

[x, y] = latlon2pix1(LLx,LLy,headout);
[lon,lat]=pix2latlon(x,y,headout);
fprintf("%f %f  %f %f  %f %f\n",LLx,LLy,lon,lat,x,y);
[x, y] = latlon2pix1(URx,URy,headout);
[lon,lat]=pix2latlon(x,y,headout);
fprintf("%f %f  %f %f  %f %f\n",URx,URy,lon,lat,x,y);

%[lon,lat]=pix2latlon(1,1,headout)
%[lon,lat]=pix2latlon(headout(1),headout(2),headout)

printsirhead(headout)

writesir('junk.sir',imgout,headout);

%viewsir('junk.sir');

[im h]=loadsir('junk.sir');
myfigure(6);
showsir(im,h);

