Advertisement
Guest User

Untitled

a guest
Jan 17th, 2014
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <?php
  2. ini_set('memory_limit', '-1');
  3. ini_set('max_execution_time', 300);
  4. error_reporting(0);
  5.  
  6. // open the file
  7. $file = file_get_contents('glds00g.asc');
  8.  
  9. // put lines in an array
  10. $lines = explode("\n", $file);
  11.  
  12. // first few lines are irrelevant
  13. for($i=0;$i<6;$i++)
  14.     unset($lines[$i]);
  15.  
  16. $count =array();
  17.  
  18. // the catogories. So from 6000 to 8000 people per square km fit in catogory P for example.
  19. $cats = array(
  20.     '0'=>0,
  21.     '1'=>0.5,
  22.     '2'=>1,
  23.     '3'=>3,
  24.     '4'=>5,
  25.     '5'=>10,
  26.     '6'=>25,
  27.     '7'=>50,
  28.     '8'=>100,
  29.     '9'=>150,
  30.     'a'=>200,
  31.     'b'=>300,
  32.     'c'=>400,
  33.     'd'=>500,
  34.     'e'=>600,
  35.     'f'=>800,
  36.     'g'=>1000,
  37.     'h'=>1250,
  38.     'i'=>1500,
  39.     'j'=>1750,
  40.     'k'=>2000,
  41.     'l'=>2500,
  42.     'm'=>3000,
  43.     'n'=>4000,
  44.     'o'=>6000,
  45.     'p'=>8000,
  46.     'q'=>10000,
  47.     'r'=>25000,
  48.     's'=>50000,
  49.     't'=>10000000,
  50.     );
  51.  
  52. // find the catogory for a value
  53. function popcat($a)
  54. {
  55.     global $count;
  56.     global $cats;
  57.         foreach($cats as $key=>$cat)
  58.         {
  59.             if($a<$cat)
  60.             {
  61.                 return $key;
  62.                 break;
  63.             }
  64.         }
  65. }
  66.  
  67.  
  68. // run trough all lines and all values
  69. $line_content = array();
  70. foreach($lines as $key=> $line)
  71. {
  72.         $items = explode(' ',$line);
  73.  
  74.         foreach($items AS $item)
  75.             $line_content[$key] = $line_content[$key].popcat($item);
  76.         $line_content[$key] = substr($line_content[$key], 0, strlen($line_content[$key])-1).PHP_EOL;
  77.        
  78. }
  79.  
  80. // save the data
  81. $fp = fopen('compressed.log', 'w');
  82.  
  83.         fwrite($fp, implode('', $line_content));
  84.         fclose($fp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement