I’ve had some fun looking at what data you can get via the National Rail Open Data scheme, and was really impressed by the ActiveMQ implementation they’ve got for Real Time Train Movement Messages!
The messages National Rail send allow you to plot trains to stations, or even along route, but the message only contains station IDs or train IDs – which is kinda boring. I like to visualise the data, on a map for example.
To get the station name and location for a particular train message one has to access an entirely different database, from another provider. Along comes ATOC with their CIF files, which look very scary compared to ActiveMQ.
To cut a long story as short as I can, the CIF files contain a lot of information (400MB+ files), using string length and new lines to split up the data. You can sign up to download the files on the ATOC website, and the specification for the files is available here.
Why the blog post? Well, I needed a way to parse these files to populate a Mongo database and wanted to promote the PHP CIF parser I’ve started work on: https://github.com/rb-cohen/php-cif-parser
Warning: Declaration of Social_Walker_Comment::start_lvl(&$output, $depth, $args) should be compatible with Walker_Comment::start_lvl(&$output, $depth = 0, $args = Array) in /home/customer/www/arronwoods.com/public_html/blog/wp-content/plugins/social/lib/social/walker/comment.php on line 18
Warning: Declaration of Social_Walker_Comment::end_lvl(&$output, $depth, $args) should be compatible with Walker_Comment::end_lvl(&$output, $depth = 0, $args = Array) in /home/customer/www/arronwoods.com/public_html/blog/wp-content/plugins/social/lib/social/walker/comment.php on line 42
Hi Arron.
I am trying to use your php cif parser, but I don’t think it is working properly.
When i view the examples, I just get a long list of letters.
How do i see the actual information in the CIF file?
And I also tried using a MCa file from ATOC (it is a CIF file) but it died saying about an identify “BS”
Any help on this?
Hi Paul,
I don’t think I made the usage clear enough, sorry about that. The parser takes a callback, which in the examples is a very simple function which just echos out the identity.
If on line 5 of examples/stations.php you changed the callback to something more verbose, you may get a better idea of what is going on:
$callback = function($record){ var_dump($record); }
In your application, you could replace this callback with your actual code, or a hook in to your actual code.
The missing identity error is because the new CIF file has a line starting “BS”, so you must register a record tokenizer to handle lines starting “BS”, like this:
$bsTokenizer = new \Cif\Parser\Tokenizer\StringLength();
$bsTokenizer->addFields(array('identity' => 2, 'example' => 5));
$parser->addRecordTokenizer("BS", $bsTokenizer);
If this hasn’t helped, feel free to email me over the code and the CIF file so far and I’ll try to see whats going wrong.
Thanks for getting in touch,
Arron
Appreciate it for this post, I am a big fan of this site would like to continue updated.