; ============================================================================
; Print the upper left and lower right coordinates of given binary geolocation files.
; The output will be printed to the standard output. It will be in the following format:
;
, ,
;
; Willem.Marais@ssec.wisc.edu
; Date: 09/14/2012
; ============================================================================
PRO BIN_GEO_UL_LR, LAT_BIN_FILE, LON_BIN_FILE, NR_COLS, NR_ROWS, OUTPUT_TEXT_FILE
; Get the latitude data
openr, lun, lat_bin_file, /get_lun
arr_lat = make_array (nr_cols, nr_rows, TYPE = 4)
readu, lun, arr_lat
free_lun, lun
; Get the longitude data
openr, lun, lon_bin_file, /get_lun
arr_lon = make_array (nr_cols, nr_rows, TYPE = 4)
readu, lun, arr_lon
free_lun, lun
lon_valid_index = where ((arr_lon LE 180.0) AND (arr_lon GE -180.0))
lat_valid_index = where ((arr_lat LE 90.0) AND (arr_lat GE -90.0))
ul_lon_flt = min (arr_lon [lon_valid_index])
lr_lon_flt = max (arr_lon [lon_valid_index])
ul_lat_flt = max (arr_lat [lat_valid_index])
lr_lat_flt = min (arr_lat [lat_valid_index])
; If ul_lon_flt > lr_lon_flt, the coordiantes are over the antimerdian line.
if ul_lon_flt > lr_lon_flt then begin
; Find all the negative longitude values and add 360 degrees to it
neg_lon_idx = where (arr_lon < 0)
arr_lon [neg_lon_idx] = arr_lon [neg_lon_idx] + 360
ul_lon_flt = min (arr_lon [lon_valid_index])
lr_lon_flt = max (arr_lon [lon_valid_index]) - 360
endif
openw, lun, output_text_file, /get_lun
printf, lun, "UL_LON=", strcompress (string (ul_lon_flt), /remove_all)
printf, lun, "UL_LAT=", strcompress (string (ul_lat_flt), /remove_all)
printf, lun, "LR_LON=", strcompress (string (lr_lon_flt), /remove_all)
printf, lun, "LR_LAT=", strcompress (string (lr_lat_flt), /remove_all)
free_lun, lun
END