use strict;
use warnings;
use Panotools::Script;

die "usage $0 0 2-4 8 [..] infile.pto outfile.pto"
    unless (scalar @ARGV > 2);

my $path_out = pop @ARGV;
my $path_in = pop @ARGV;

my $pto_in = new Panotools::Script;
$pto_in->Read ($path_in);

my @images;
for my $item (@ARGV)
    push (@images, $item) if ($item =~ /^[0-9]+$/);
    push (@images, ($1 .. $2)) if ($item =~ /^([0-9]+)-([0-9]+)$/);

my $pto_out = $pto_in->Subset (@images)
    or die "invalid image specification";

$pto_out->Write ($path_out);


=head1 NAME

ptosplit - extracts a subset pto project

=head1 Synopsis

  ptosplit 0 2-4 8 [..] infile.pto outfile.pto


Extracts just the specified images from a .pto project and writes a new
project containing just these images, related control points and
optimisation settings.

Images can be requested in any order, but they will be returned in the same
order as the 'parent' project.  Note image numbers start at 0.

Ranges can be used, '2-5' is the same as '2 3 4 5'.

=head1 Calling syntax

  ptosplit <number> <number ...>  <pto-file> <pto-file>

(input and output can be the same file)

=head1 License

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

=head1 See Also


=head1 Author

Bruno Postle, E<lt>bruno (at) postle.netE<gt>