; The calc_grid_size script is used to calculate the grid dimensions with the given ; two dimensional corner coordinates. The following arguments are inputs to the script ; ; ul_x - The upper left x axis coordinate of the grid ; ul_y - The upper left y axis coordinate of the grid ; lr_x - The lower right x axis coordinate of the grid ; lr_y - The lower right y axis coordinate of the grid ; x_offset - The x axis origin value of the grid ; y_offset - The y axis origin value of the grid ; res - The resolution of the grid cells ; out_file_name_str - The file name to which the calculated parameters will be written to ; ; The input coordinates are adjusted to align to a grid which is based on the resolution ; given to the script. With the adjusted corner coordinates the grid size is calculated. ; ; The output of this script is a file, and the file name is set the the variable ; out_file_name_str. The following parameters are written to the file: ; ADJ_UL_X - The adjusted upper left x coordinate ; ADJ_LR_X - The adjusted lower right x coordinate ; ADJ_UL_Y - The adjusted upper left y coordinate ; ADJ_LR_Y - The adjusted lower right y cooridnate ; COLS - The number of columns of the grid. In other words, the grid width based on the ; resolution size ; ROWS - The number of rows of the grid. In other words, the grid length based on the ; resolution size ; ; Author: Willem.Marais@ssec.wisc.edu ; Date: 09/14/2012 PRO CALC_GRID_SIZE, UL_X, UL_Y, LR_X, LR_Y, X_OFFSET, Y_OFFSET, RES, OUT_FILE_NAME_STR ; switch_coord_bl = 0 ; if ul_x GT lr_x then begin ; ; The UL and LR coordinates are switched. This probably means that the corner coordinates ; ; are over the anti-meridian. ; tmp_lr_x = lr_x ; tmp_lr_y = lr_y ; ; lr_x = ul_x ; lr_y = ul_y ; ; ul_x = tmp_lr_x ; ul_y = tmp_lr_y ; ; switch_coord_bl = 1 ; endif res = double (res) ul_x = double (ul_x) - double (x_offset) lr_x = double (lr_x) - double (x_offset) ul_y = double (ul_y) - double (y_offset) lr_y = double (lr_y) - double (y_offset) ; Snap the coordinates to the grid based on the resolution value ul_grid_x = ul_x / res ; Snap to the left lr_grid_x = lr_x / res ; Snap to the left lr_grid_y = lr_y / res ; Snap to the bottom ul_grid_y = ul_y / res ; Snap to the bottom ; The projected UL longitude value is snapped to the left of the ; 250m projection grid. If the UL longitude value is -180, the ; snapped projected UL longitude will be less than the projected ; value of -180. The following addition makes sure that the adjusted ; UL longitude value does not exceed the -180 degree limit. if ul_grid_x EQ 0 then $ ul_grid_x = ul_grid_x + 1.0 ; Caculate the grid size if lr_grid_x GT ul_grid_x then begin x_grid_size = round (lr_grid_x - ul_grid_x) endif else begin x_grid_size = round (ul_grid_x - lr_grid_x) endelse if ul_grid_y GT lr_grid_y then begin y_grid_size = round (ul_grid_y - lr_grid_y) endif else begin y_grid_size = round (lr_grid_y - ul_grid_y) endelse ; Caculate the adjusted coorner coordinates adj_ul_x = ul_grid_x * res + x_offset adj_lr_x = adj_ul_x + x_grid_size * res ;adj_lr_x = lr_grid_x * res + x_offset adj_ul_y = ul_grid_y * res + y_offset adj_lr_y = adj_ul_y - y_grid_size * res ;adj_lr_y = lr_grid_y * res + y_offset ; if switch_coord_bl GT 0 then begin ; tmp_adj_lr_x = adj_lr_x ; tmp_adj_lr_y = adj_lr_y ; ; adj_lr_x = adj_ul_x ; adj_lr_y = adj_ul_y ; ; adj_ul_x = tmp_adj_lr_x ; adj_ul_y = tmp_adj_lr_y ; endif openw, lun, out_file_name_str, /get_lun printf, lun, "ADJ_UL_X=", strcompress (string (long (adj_ul_x)), /remove_all) printf, lun, "ADJ_LR_X=", strcompress (string (long (adj_lr_x)), /remove_all) printf, lun, "ADJ_UL_Y=", strcompress (string (long (adj_ul_y)), /remove_all) printf, lun, "ADJ_LR_Y=", strcompress (string (long (adj_lr_y)), /remove_all) printf, lun, "COLS=", strcompress (string (long (x_grid_size)), /remove_all) printf, lun, "ROWS=", strcompress (string (long (y_grid_size)), /remove_all) free_lun, lun END