Changeset 13275 for trunk/ippScripts/scripts/ipp_serial_inject_mosaic.pl
- Timestamp:
- May 4, 2007, 4:52:03 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/ipp_serial_inject_mosaic.pl
r13018 r13275 5 5 6 6 use IPC::Cmd 0.36 qw( can_run run ); 7 use PS::IPP::Config ;7 use PS::IPP::Config qw( caturi ); 8 8 use Data::Dumper; 9 use File::Spec;10 9 11 10 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); … … 14 13 my ($camera, # Camera used 15 14 $telescope, # Telescope used 16 $workdir, # Working directory to append17 15 $dbname, # Database name 16 $workdir, # Working directory 17 $path, # Path to data 18 18 ); 19 19 GetOptions( 20 'camera|c=s' => \$camera,20 'camera|c=s' => \$camera, 21 21 'telescope|t=s' => \$telescope, 22 'workdir=s' => \$workdir, 23 'dbname=s' => \$dbname, 22 'workdir=s' => \$workdir, 23 'path=s' => \$path, 24 'dbname=s' => \$dbname, 24 25 ) or pod2usage( 2 ); 25 26 26 27 pod2usage( 27 -msg => "Required options: --camera --telescope --workdir -- dbname",28 -msg => "Required options: --camera --telescope --workdir --path --dbname", 28 29 -exitval => 3, 29 ) unless defined $camera and defined $telescope and defined $workdir and defined $dbname; 30 ) unless defined $camera 31 and defined $telescope 32 and defined $workdir 33 and defined $path 34 and defined $dbname; 30 35 31 36 my $ipprc = PS::IPP::Config->new(); # IPP configuration 32 my $workdir_abs = $ipprc->convert_filename_absolute( $workdir );33 37 34 38 # Look for programs we need … … 36 40 my $pxinject = can_run('pxinject') or (warn "Can't find pxinject" and $missing_tools = 1); 37 41 42 if (scalar @ARGV == 0) { 43 die "No exposures provided.\n"; 44 } 45 38 46 # Inject new data into the database 39 if (scalar @ARGV != 0) { 40 my @classes; # Names of the classes 41 my @files; # What to add to the filename for each class 42 my $imfiles; 43 my $add_dir; # Add directory name to get file name? 44 if ($camera eq "MEGACAM") { 45 for (my $i = 0; $i < 36; $i++) { 46 push @classes, sprintf("ccd%02d", $i); 47 push @files, sprintf(".ccd%02d", $i); 48 } 49 } elsif ($camera eq "MCSHORT") { 50 @classes = ( 'ccd12', 'ccd13', 'ccd14', 'ccd21', 'ccd22', 'ccd23' ); 51 @files = ( '.ccd12', '.ccd13', '.ccd14', '.ccd21', '.ccd22', '.ccd23' ); 52 53 } elsif ($camera eq "CTIO_MOSAIC2") { 54 @classes = (); 55 @files = (); 56 } elsif ($camera eq "TC3") { 57 @classes = ( 'CCID58-1-06b2', 'CCID45-1-14A', 'CCID45-1-11A', 'CCID45-1-22A', 58 'CCID45-1-04C', 'CCID45-1-13A', 'CCID45-1-05A', 'CCID45-1-19A' ); 59 @files = ( '00', '01', '10', '11', '20', '21', '30', '31' ); 60 $add_dir = 1; 61 } elsif ($camera eq "SIMMOSAIC") { 62 @classes = ( 'Chip00', 'Chip01', 'Chip10', 'Chip11' ); 63 @files = ( '.Chip00', '.Chip01', '.Chip10', '.Chip11' ); 64 } elsif ($camera eq "SIMTEST") { 65 @classes = (); 66 @files = (); 67 } else { 68 die "Unrecognised camera name: $camera.\n"; 47 my @classes; # Names of the classes 48 my @files; # What to add to the filename for each class 49 my $imfiles; 50 my $add_dir; # Add directory name to get file name? 51 if ($camera eq "MEGACAM") { 52 for (my $i = 0; $i < 36; $i++) { 53 push @classes, sprintf("ccd%02d", $i); 54 push @files, sprintf(".ccd%02d", $i); 55 } 56 } elsif ($camera eq "MCSHORT") { 57 @classes = ( 'ccd12', 'ccd13', 'ccd14', 'ccd21', 'ccd22', 'ccd23' ); 58 @files = ( '.ccd12', '.ccd13', '.ccd14', '.ccd21', '.ccd22', '.ccd23' ); 59 } elsif ($camera eq "CTIO_MOSAIC2") { 60 @classes = (); 61 @files = (); 62 } elsif ($camera eq "TC3") { 63 @classes = ( 'CCID58-1-06b2', 'CCID45-1-14A', 'CCID45-1-11A', 'CCID45-1-22A', 64 'CCID45-1-04C', 'CCID45-1-13A', 'CCID45-1-05A', 'CCID45-1-19A' ); 65 @files = ( '00', '01', '10', '11', '20', '21', '30', '31' ); 66 $add_dir = 1; 67 } elsif ($camera eq "SIMMOSAIC") { 68 @classes = ( 'Chip00', 'Chip01', 'Chip10', 'Chip11' ); 69 @files = ( '.Chip00', '.Chip01', '.Chip10', '.Chip11' ); 70 } elsif ($camera eq "SIMTEST") { 71 @classes = (); 72 @files = (); 73 } else { 74 die "Unrecognised camera name: $camera.\n"; 75 } 76 77 foreach my $exp ( @ARGV ) { 78 my $command = "$pxinject -newExp -exp_id $exp -inst $camera -telescope $telescope -workdir $workdir -dbname $dbname -imfiles " . (scalar @classes or 1) ; # Command to run 79 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 80 run( command => $command, verbose => 1 ); 81 die "Unable to inject $exp: $error_code\n" if not $success; 82 83 my @line = split(/\s+/, $$stdout_buf[0]); # The output line, containing the exposure tag 84 my $exp_tag = $line[2]; # The exposure tag 85 for (my $i = 0; $i < scalar @classes; $i++) { 86 my $class_id = $classes[$i]; 87 my $file_id = $files[$i]; 88 my $filename = $exp . $file_id . '.fits'; 89 $filename = caturi( $exp, $filename ) if defined $add_dir; 90 $filename = caturi( $path, $filename ); 91 92 die "Unable to find file $filename" unless -f $ipprc->file_resolve( $filename ); 93 94 $filename = $ipprc->convert_filename_relative( $filename ); 95 my $command = "$pxinject -newImfile -exp_tag $exp_tag -class chip -class_id $class_id -uri $filename -dbname $dbname"; # Command to run 96 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 97 run( command => $command, verbose => 1 ); 98 die "Unable to inject $exp $class_id: $error_code\n" if not $success; 69 99 } 70 100 71 foreach my $exp ( @ARGV ) { 72 my $command = "$pxinject -newExp -exp_id $exp -inst $camera -telescope $telescope -workdir $workdir -dbname $dbname -imfiles " . (scalar @classes or 1) ; # Command to run 101 if (scalar @classes == 0) { 102 my $filename = "$exp.fits"; 103 $filename = caturi( $exp, $filename ) if defined $add_dir; 104 $filename = caturi( $path, $filename ); 105 106 die "Unable to find file $filename" unless -f $ipprc->file_resolve( $filename ); 107 108 $filename = $ipprc->convert_filename_relative( $filename ); 109 my $command = "$pxinject -newImfile -exp_tag $exp_tag -class fpa -class_id fpa -dbname $dbname -uri $filename"; # Command to run 73 110 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 74 111 run( command => $command, verbose => 1 ); 75 die "Unable to inject $exp: $error_code\n" if not $success; 76 77 my @line = split(/\s+/, $$stdout_buf[0]); # The output line, containing the exposure tag 78 my $exp_tag = $line[2]; # The exposure tag 79 for (my $i = 0; $i < scalar @classes; $i++) { 80 my $class_id = $classes[$i]; 81 my $file_id = $files[$i]; 82 my $filename = "$exp$file_id.fits"; 83 $filename = File::Spec->catfile( $exp, $filename ) if defined $add_dir; 84 $filename = File::Spec->catfile( $workdir_abs, $filename); 85 $filename = $ipprc->convert_filename_relative( $filename ); 86 my $command = "$pxinject -newImfile -exp_tag $exp_tag -class chip -class_id $class_id -uri $filename -dbname $dbname"; # Command to run 87 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 88 run( command => $command, verbose => 1 ); 89 die "Unable to inject $exp $class_id: $error_code\n" if not $success; 90 } 112 die "Unable to inject $exp imfile: $error_code\n" if not $success; 113 } 91 114 92 if (scalar @classes == 0) {93 my $filename = "$exp.fits";94 $filename = File::Spec->catfile( $exp, $filename ) if defined $add_dir;95 $filename = File::Spec->catfile( $workdir_abs, $filename);96 $filename = $ipprc->convert_filename_relative( $filename );97 my $command = "$pxinject -newImfile -exp_tag $exp_tag -class fpa -class_id fpa -dbname $dbname -uri $filename"; # Command to run98 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =99 run( command => $command, verbose => 1 );100 die "Unable to inject $exp imfile: $error_code\n" if not $success;101 }102 103 }104 115 } 105 116 106 117 END { 107 118 my $status = $?; 108 system("sync") == 0109 or die "failed to execute sync: $!" ;110 $? = $status;119 system("sync") == 0 120 or die "failed to execute sync: $!" ; 121 $? = $status; 111 122 } 112 123
Note:
See TracChangeset
for help on using the changeset viewer.
