#! perl -sw use strict; use constant BaseX => 0; use constant BaseY => 196_000; use constant MapX => 16_000; use constant MapXN => 17; use constant MapY => 14_000; use constant MapYN => 12; use constant GridX => 3_200; use constant GridY => 2_800; use constant SubX => 1066+ 2/3; use constant SubY => 933+ 1/3; while () { print,next if /^\s*$/ or /^#/; my ($thing, $x, $y)= split','; $y = BaseY-$y; #! invert Y my $mapX = int($x/MapX); my $mapY = int($y/MapY); my $map = $mapY*MapXN + $mapX + 1; my $gridX = int( ($x - $mapX*MapX)/GridX ); my $gridY = int( ($y - $mapY*MapY)/GridY ); my $grid = $gridY*5 + $gridX + 1; my $subX = int( ($x - ($mapX*MapX + $gridX*GridX) )/SubX ); my $subY = int( ($y - ($mapY*MapY + $gridY*GridY) )/SubY ); my $sub = $subY*3 + $subX + 1; print "$thing => Map:$map Grid:$grid Subgrid:$sub\n"; } __DATA__ # Test data, points just inside the topleft, topright, bottomleft and bottomright # of each supplied subgrid. # 062, 25, 6, 030933, 112933, 032000, 113866 Left Top 062:25:6, 030934, 113866 Left Bot 062:25:6, 030934, 112934 Right Top 062:25:6, 031999, 113866 Right Bot 062:25:6, 031999, 112934 # 062, 25, 7, 028800, 112000, 029866, 112933 Left Top 062:25:7, 028801, 112932 Left Bot 062:25:7, 028801, 112001 Right Top 062:25:7, 029865, 112932 Right Bot 062:25:7, 029865, 112001 # 062, 25, 8, 029866, 112000, 030933, 112933 Left Top 062:25:8, 029867, 112932 Left Bot 062:25:8, 029867, 112001 Right Top 062:25:8, 030932, 112932 Right Bot 062:25:8, 030932, 112001 # 062, 25, 9, 030933, 112000, 032000, 112933 Left Top 062:25:9, 030934, 112932 Left Bot 062:25:9, 030934, 112001 Right Top 062:25:9, 031999, 112932 Right Bot 062:25:9, 031999, 112001 #063, 01, 1, 032000, 125066, 033066, 125999 Left Top 063:01:1, 032001, 125998 Left Bot 063:01:1, 032001, 125067 Right Top 063:01:1, 033065, 125998 Right Bot 063:01:1, 033065, 125067 # 063, 01, 2, 033066, 125066, 034133, 125999 Left Top 063:01:1, 033067, 125998 Left Bot 063:01:1, 033067, 125067 Right Top 063:01:1, 034132, 125998 Right Bot 063:01:1, 034132, 125067 # 044, 15, 2, 061866, 133466, 062933, 134399 Left Top 044:15:2, 061867, 134398 Left Bot 044:15:2, 061867, 133467 Right Top 044:15:2, 062932, 134398 Right Bot 044:15:2, 062932, 133467 # 107, 14, 4, 105600, 090533, 106666, 091466 Left Top 107:14:4, 105601, 091465 Left Bot 107:14:4, 105601, 090534 Right Top 107:14:4, 106665, 091465 Right Bot 107:14:4, 106665, 090534