IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 2, 2008, 5:53:22 PM (18 years ago)
Author:
Paul Price
Message:

Fixing compilation error.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/magic_tree.pl

    r17671 r18410  
    3030use Pod::Usage qw( pod2usage );
    3131
    32 use constant MAX_FIELDS => 4;   # Maximum number of fields to be in a node
     32use constant MAX_FIELDS => 4;   # Maximum number of fields to be in a node
    3333
    3434# Parse the command-line arguments
    3535my ($magic_id, $tess_id, $camera, $ra0, $dec0, $dbname, $outroot, $save_temps, $verbose, $no_update, $no_op);
    3636GetOptions(
    37            'magic_id=s'    => \$magic_id,   # Magic identifier
    38            'tess_id=s'     => \$tess_id,    # Tessellation identifier
    39            'camera=s'      => \$camera,     # Camera name
    40            'ra=f'          => \$ra0,        # Boresight right ascension, radians
    41            'dec=f'         => \$dec0,       # Boresight declination, radians
    42            'dbname=s'      => \$dbname,     # Database name
    43            'outroot=s'     => \$outroot,    # Output root name
    44            'save-temps'    => \$save_temps, # Save temporary files?
    45            'verbose'       => \$verbose,    # Print stuff?
    46            'no-update'     => \$no_update,  # Don't update the database?
    47            'no-op'         => \$no_op,      # Don't do any operations?
    48            ) or pod2usage( 2 );
     37           'magic_id=s'    => \$magic_id,   # Magic identifier
     38           'tess_id=s'     => \$tess_id,    # Tessellation identifier
     39           'camera=s'      => \$camera,     # Camera name
     40           'ra=f'          => \$ra0,        # Boresight right ascension, radians
     41           'dec=f'         => \$dec0,       # Boresight declination, radians
     42           'dbname=s'      => \$dbname,     # Database name
     43           'outroot=s'     => \$outroot,    # Output root name
     44           'save-temps'    => \$save_temps, # Save temporary files?
     45           'verbose'       => \$verbose,    # Print stuff?
     46           'no-update'     => \$no_update,  # Don't update the database?
     47           'no-op'         => \$no_op,      # Don't do any operations?
     48           ) or pod2usage( 2 );
    4949
    5050pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    5151pod2usage( -msg => "Required options: --magic_id --camera --outroot",
    52            -exitval => 3) unless
     52           -exitval => 3) unless
    5353    defined $magic_id and
    5454    defined $tess_id and
     
    6565my $magictool = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1);
    6666my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    67 if ($missing_tools) { 
     67if ($missing_tools) {
    6868    warn("Can't find required tools.");
    69     exit($PS_EXIT_CONFIG_ERROR); 
    70 }
    71 
    72 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     69    exit($PS_EXIT_CONFIG_ERROR);
     70}
     71
     72my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    7373
    7474### Get a list of skycells
    75 my @skycells;                   # List of skycells
     75my @skycells;                   # List of skycells
    7676{
    7777    my $command = "$magictool -inputskyfile -magic_id $magic_id"; # Command to run
    7878    $command .= " -dbname $dbname" if defined $dbname;
    7979    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    80         run(command => $command, verbose => $verbose);
     80        run(command => $command, verbose => $verbose);
    8181    unless ($success) {
    82         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    83         &my_die("Unable to perform magictool -inputfile: $error_code", $magic_id, $error_code);
     82        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     83        &my_die("Unable to perform magictool -inputfile: $error_code", $magic_id, $error_code);
    8484    }
    8585
    8686    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    87         &my_die("Unable to parse metadata config doc", $magic_id, $PS_EXIT_PROG_ERROR);
     87        &my_die("Unable to parse metadata config doc", $magic_id, $PS_EXIT_PROG_ERROR);
    8888
    8989    my $inputs = parse_md_list($metadata) or
    90         &my_die("Unable to parse metadata list", $magic_id, $PS_EXIT_PROG_ERROR);
     90        &my_die("Unable to parse metadata list", $magic_id, $PS_EXIT_PROG_ERROR);
    9191
    9292    foreach my $input ( @$inputs ) {
    93         push @skycells, $input->{skycell_id};
     93        push @skycells, $input->{skycell_id};
    9494    }
    9595}
     
    9999foreach my $skycell_id ( @skycells ) {
    100100    my $skyfile = $ipprc->filename("SKYCELL.TEMPLATE", $outroot, $skycell_id );
    101     $ipprc->skycell_file($tess_id, $skycell_id, $skyFile, $verbose) or &my_die("Unable to generate skycells $skycell_id", $magic_id, $PS_EXIT_PROG_ERROR);
     101    $ipprc->skycell_file($tess_id, $skycell_id, $skyfile, $verbose) or &my_die("Unable to generate skycells $skycell_id", $magic_id, $PS_EXIT_PROG_ERROR);
    102102    my $skyfileResolved = $ipprc->file_resolve( $skyfile );
    103103    my ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $skyfileResolved );
    104104    &my_die("Unable to read skycell header: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
    105    
     105
    106106    # Get the useful header keywords
    107107    my $naxis1 = $$header{'NAXIS1'} or &my_die("Can't find NAXIS1", $magic_id, $PS_EXIT_SYS_ERROR);
     
    123123
    124124    &my_die("Unexpected projection: $ctype1 and $ctype2.", $magic_id, $PS_EXIT_SYS_ERROR) unless
    125         $ctype1 =~ /^\'RA---TAN\s*\'$/ and $ctype2 =~ /^\'DEC--TAN\s*\'$/;
     125        $ctype1 =~ /^\'RA---TAN\s*\'$/ and $ctype2 =~ /^\'DEC--TAN\s*\'$/;
    126126    &my_die("Can't determine size of skycell ($naxis1,$naxis2)", $magic_id, $PS_EXIT_SYS_ERROR) unless
    127         $naxis1 > 0 and $naxis2 > 0;
     127        $naxis1 > 0 and $naxis2 > 0;
    128128    &my_die("Can't determine scale of skycell ($cdelt1,$cdelt2)", $magic_id, $PS_EXIT_SYS_ERROR) if
    129         not defined $cdelt1 or $cdelt1 == 0 or not defined $cdelt2 or $cdelt2 == 0;
     129        not defined $cdelt1 or $cdelt1 == 0 or not defined $cdelt2 or $cdelt2 == 0;
    130130    &my_die("We don't know how to handle rotations ($crota1,$crota2)", $magic_id, $PS_EXIT_SYS_ERROR)
    131         if defined $crota1 or defined $crota2;
     131        if defined $crota1 or defined $crota2;
    132132
    133133    # Relative coordinates of centre of the field
     
    140140    $xi *= $cdelt1;
    141141    $eta *= $cdelt2;
    142    
     142
    143143    # Coordinates on rotated celestial sphere
    144144    my $phi = atan2($eta,$xi) + pi/2;
    145145    my $theta = atan(180 / pi / sqrt($xi**2 + $eta**2));
    146    
     146
    147147    # Coordinates on celestial sphere
    148148    $crval1 = deg2rad($crval1);
    149149    $crval2 = deg2rad($crval2);
    150150    my $ra = $crval1 + atan2(cos($theta) * sin($phi),
    151                              sin($theta) * cos($crval2) + cos($theta) * sin($crval2) * cos($phi));
     151                             sin($theta) * cos($crval2) + cos($theta) * sin($crval2) * cos($phi));
    152152    my $dec = asin(sin($theta) * sin($crval2) - cos($theta) * cos($crval2) * cos($phi));
    153153
    154154    # Rotate to boresight
    155     my $phi_new = atan2(cos($dec) * sin($ra - $ra0), 
    156                         sin($dec) * cos($dec0) + cos($dec) * sin($dec0) * cos($ra - $ra0));
     155    my $phi_new = atan2(cos($dec) * sin($ra - $ra0),
     156                        sin($dec) * cos($dec0) + cos($dec) * sin($dec0) * cos($ra - $ra0));
    157157    my $theta_new = asin(sin($dec) * sin($dec0) - cos($dec) * cos($dec0) * cos($ra - $ra0));
    158158
     
    163163
    164164    my $field = { id => $skycell_id,
    165                   xi => $xi_new,
    166                   eta => $eta_new,
    167               };
     165                  xi => $xi_new,
     166                  eta => $eta_new,
     167              };
    168168
    169169    push @fields, $field;
     
    171171
    172172### Subdivide list of positions into kd-tree
    173 my $root = {                    # Root node of tree
    174     contents => \@fields,       # Contents of node
    175     position => 'root',         # Position in tree
    176     children => {},             # Children of node
     173my $root = {                    # Root node of tree
     174    contents => \@fields,       # Contents of node
     175    position => 'root',         # Position in tree
     176    children => {},             # Children of node
    177177};
    178178my @tasks = ( $root );
     
    197197    # Add the processed file to the database
    198198    unless ($no_update) {
    199         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    200             run(command => $command, verbose => $verbose);
    201         unless ($success) {
    202             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    203             warn("Unable to perform magictool -inputtree: $error_code");
    204             exit($error_code);
    205         }
     199        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     200            run(command => $command, verbose => $verbose);
     201        unless ($success) {
     202            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     203            warn("Unable to perform magictool -inputtree: $error_code");
     204            exit($error_code);
     205        }
    206206    } else {
    207         print "Skipping command: $command\n";
     207        print "Skipping command: $command\n";
    208208    }
    209209}
     
    213213sub my_die
    214214{
    215     my $msg = shift;            # Warning message on die
    216     my $magic_id = shift;       # Magic identifier
    217     my $exit_code = shift;      # Exit code to add
     215    my $msg = shift;            # Warning message on die
     216    my $magic_id = shift;       # Magic identifier
     217    my $exit_code = shift;      # Exit code to add
    218218
    219219    carp($msg);
    220220    if (defined $magic_id and not $no_update) {
    221         my $command = "$magictool -inputtree";
    222         $command .= " -magic_id $magic_id";
    223         $command .= " -code $exit_code";
    224         $command .= " -dbname $dbname" if defined $dbname;
    225         system($command);
     221        my $command = "$magictool -inputtree";
     222        $command .= " -magic_id $magic_id";
     223        $command .= " -code $exit_code";
     224        $command .= " -dbname $dbname" if defined $dbname;
     225        system($command);
    226226    }
    227227    exit $exit_code;
     
    231231sub divide_list
    232232{
    233     my $list = shift;           # List to divide
    234     my $index = shift;          # Name of index for sorting
     233    my $list = shift;           # List to divide
     234    my $index = shift;          # Name of index for sorting
    235235
    236236    my @sorted = sort { $$a{$index} <=> $$b{$index} } @$list; # Sorted list
     
    244244sub new_node
    245245{
    246     my $parent = shift;         # The parent node
    247     my $contents = shift;       # Contents of the new node
    248     my $position = shift;       # Position description
    249     my $tasks = shift;          # Tasks to do
     246    my $parent = shift;         # The parent node
     247    my $contents = shift;       # Contents of the new node
     248    my $position = shift;       # Position description
     249    my $tasks = shift;          # Tasks to do
    250250
    251251    my $node = {
    252         contents => $contents,
    253         position => $parent->{position} . '_' . $position,
    254         children => {},
     252        contents => $contents,
     253        position => $parent->{position} . '_' . $position,
     254        children => {},
    255255    };
    256256
     
    265265sub divide_node
    266266{
    267     my $node = shift;           # Node to divide
    268     my $tasks = shift;          # Tasks to do
     267    my $node = shift;           # Node to divide
     268    my $tasks = shift;          # Tasks to do
    269269
    270270    my $position = $node->{position};
     
    275275
    276276    if (scalar @$lower > 4) {
    277         my ($ll, $lr) = divide_list($lower, 'eta');
    278         new_node($node, $ll, 'll', $tasks);
    279         new_node($node, $lr, 'lr', $tasks);
     277        my ($ll, $lr) = divide_list($lower, 'eta');
     278        new_node($node, $ll, 'll', $tasks);
     279        new_node($node, $lr, 'lr', $tasks);
    280280    } else {
    281         new_node($node, $lower, 'L', $tasks);
     281        new_node($node, $lower, 'L', $tasks);
    282282    }
    283283
    284284    if (scalar @$upper > 4) {
    285         my ($ul, $ur) = divide_list($upper, 'eta');
    286         new_node($node, $ul, 'ul', $tasks);
    287         new_node($node, $ur, 'ur', $tasks);
     285        my ($ul, $ur) = divide_list($upper, 'eta');
     286        new_node($node, $ul, 'ul', $tasks);
     287        new_node($node, $ur, 'ur', $tasks);
    288288    } else {
    289         new_node($node, $upper, 'U', $tasks);
     289        new_node($node, $upper, 'U', $tasks);
    290290    }
    291291
     
    298298sub print_node
    299299{
    300     my $node = shift;           # Node to print
     300    my $node = shift;           # Node to print
    301301
    302302    my $position = $node->{position}; # Position of node
     
    305305
    306306    if (defined $node->{contents}) {
    307         foreach my $field ( @{$node->{contents}} ) {
    308             my $skycell_id = $field->{id};      # Skycell name
    309             $output .= "$position\t\tSTR\t$skycell_id\n";
    310             $output .= "$skycell_id\t\tSTR\tNULL\t\# $field->{xi},$field->{eta}\n";
    311         }
     307        foreach my $field ( @{$node->{contents}} ) {
     308            my $skycell_id = $field->{id};      # Skycell name
     309            $output .= "$position\t\tSTR\t$skycell_id\n";
     310            $output .= "$skycell_id\t\tSTR\tNULL\t\# $field->{xi},$field->{eta}\n";
     311        }
    312312    } else {
    313         foreach my $div ( keys %{$node->{children}} ) {
    314             $output .= "$position\t\tSTR\t${position}_$div\n";
    315             $output .= print_node($node->{children}->{$div});
    316         }
     313        foreach my $div ( keys %{$node->{children}} ) {
     314            $output .= "$position\t\tSTR\t${position}_$div\n";
     315            $output .= print_node($node->{children}->{$div});
     316        }
    317317    }
    318318
Note: See TracChangeset for help on using the changeset viewer.