Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('memory_limit', '-1');
- ini_set('max_execution_time', 300);
- error_reporting(0);
- // open the file
- $file = file_get_contents('glds00g.asc');
- // put lines in an array
- $lines = explode("\n", $file);
- // first few lines are irrelevant
- for($i=0;$i<6;$i++)
- unset($lines[$i]);
- $count =array();
- // the catogories. So from 6000 to 8000 people per square km fit in catogory P for example.
- $cats = array(
- '0'=>0,
- '1'=>0.5,
- '2'=>1,
- '3'=>3,
- '4'=>5,
- '5'=>10,
- '6'=>25,
- '7'=>50,
- '8'=>100,
- '9'=>150,
- 'a'=>200,
- 'b'=>300,
- 'c'=>400,
- 'd'=>500,
- 'e'=>600,
- 'f'=>800,
- 'g'=>1000,
- 'h'=>1250,
- 'i'=>1500,
- 'j'=>1750,
- 'k'=>2000,
- 'l'=>2500,
- 'm'=>3000,
- 'n'=>4000,
- 'o'=>6000,
- 'p'=>8000,
- 'q'=>10000,
- 'r'=>25000,
- 's'=>50000,
- 't'=>10000000,
- );
- // find the catogory for a value
- function popcat($a)
- {
- global $count;
- global $cats;
- foreach($cats as $key=>$cat)
- {
- if($a<$cat)
- {
- return $key;
- break;
- }
- }
- }
- // run trough all lines and all values
- $line_content = array();
- foreach($lines as $key=> $line)
- {
- $items = explode(' ',$line);
- foreach($items AS $item)
- $line_content[$key] = $line_content[$key].popcat($item);
- $line_content[$key] = substr($line_content[$key], 0, strlen($line_content[$key])-1).PHP_EOL;
- }
- // save the data
- $fp = fopen('compressed.log', 'w');
- fwrite($fp, implode('', $line_content));
- fclose($fp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement