# Test script to problem with rasterread function

# When a 300x300px GEOtif exported from QGIS is read and displayed
#   the plotted image is incorrect
# It is rotated counterclockwise by 20-30 degrees from the
#   actual OS map orientation and looks as if it has been
#   clipped (not accurately checked)
# Test file is "FernhurstDTM1mSU8828.tif" - 353kB FP32


# MAIN ROUTINE

iniDir="c:/users/anthony/documents/qgis/hampshire/test/*.tif"
lidar=read_tif(iniDir);  # 'double' returned, 'single' read
see(lidar);
key=kbhit(); # Wait for key and then exit
close


function tif=read_tif(iniDir)  #Read double from Geotif (from QGIS)
  [fn,fpath,idx]=uigetfile("*.tif","ReadTif",iniDir);
  fullfn=strcat(fpath,fn);
  [data0,inf]=rasterread(fullfn);
  data=getfield(data0,"data"); # Double FP64 raw lidar output
  whos data  # Gives 300x300 double(8bytes)
  tif=mat2gray(data,[min(min(data)),max(max(data))]); #0...1 FP
endfunction

function see(img) # Display image
  figure("name","Monitor","position",[680,30,650,650]);
  axes("position",[0.05,0.05,0.90,0.90]);
  imshow(img)  # Raw data
  set (gcf, 'WindowButtonDownFcn', @btn_down); # Pixel data
endfunction


