arc.to.gridatb.pl 926 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env perl
  2. if($#ARGV != 1 || $ARGV[0] =~ m/^-*help$/){
  3. print "Usage: arc.to.gridatb arc_file gridatb_file\n";
  4. exit;
  5. }
  6. open IN, $ARGV[0] or die;
  7. $head = 0;
  8. while(<IN>){
  9. if(m/^ncols[ \t]+([0-9.]+)[ \t]*$/i){
  10. $ncols = $1;
  11. $head |= 0x1;
  12. }elsif(m/^nrows[ \t]+([0-9.]+)[ \t]*$/i){
  13. $nrows = $1;
  14. $head |= 0x2;
  15. }elsif(m/^xllcorner[ \t]+([0-9.]+)[ \t]*$/i){
  16. $xllcorner = $1;
  17. $head |= 0x4;
  18. }elsif(m/^yllcorner[ \t]+([0-9.]+)[ \t]*$/i){
  19. $yllcorner = $1;
  20. $head |= 0x8;
  21. }elsif(m/^cellsize[ \t]+([0-9.]+)[ \t]*$/i){
  22. $cellsize = $1;
  23. $head |= 0x10;
  24. }elsif(m/^nodata_value[ \t]+([0-9.]+)[ \t]*$/i){
  25. $nodata_value = $1;
  26. $head |= 0x20;
  27. }else{
  28. die;
  29. }
  30. if($head == 0x3f){
  31. last;
  32. }
  33. }
  34. open OUT, ">$ARGV[1]" or die;
  35. print OUT <<EOT
  36. arc.to.gridatb $ARGV[0] $ARGV[1]
  37. $ncols $nrows $cellsize
  38. EOT
  39. ;
  40. while(<IN>){
  41. s/(?=^|[ \t]*)$nodata_value(\.0*)?(?=([ \t]*|$))/9999.00/g;
  42. print OUT;
  43. }
  44. close IN;
  45. close OUT;