|
| 1 | +#!/usr/bin/env perl |
| 2 | +#======================================================================= |
| 3 | +# name - setup_gaas_obs |
| 4 | +# purpose - organize GAAS observation data into subdirectories expected |
| 5 | +# by the reading program |
| 6 | +# |
| 7 | +# runtime parameter |
| 8 | +# => $workdir: directory location of modis data |
| 9 | +# |
| 10 | +# runtime flags (choose at least one) |
| 11 | +# => $avhrr: organize avhrr patmosx data into subdirectories |
| 12 | +# => $modis: organize modis Level2 HDF data into subdirectories |
| 13 | +#======================================================================= |
| 14 | +use strict; |
| 15 | +use warnings; |
| 16 | + |
| 17 | +# global variables |
| 18 | +#----------------- |
| 19 | +my ($workdir, $modis, $viirs, $avhrr, %flags, $verbose); |
| 20 | + |
| 21 | +# main program |
| 22 | +#------------- |
| 23 | +{ |
| 24 | + use File::Basename ("basename"); |
| 25 | + use File::Copy ("move"); |
| 26 | + use File::Path ("mkpath"); |
| 27 | + |
| 28 | + my ($file, $base, $adflg); |
| 29 | + my ($label, $Adate, $time, $version); |
| 30 | + my ($type, $jdoy, $subdir); |
| 31 | + my ($year, $month, $day); |
| 32 | + |
| 33 | + init(); |
| 34 | + if ($modis) { |
| 35 | + foreach $file (<$workdir/M?D04_L2.*.*.hdf>) { |
| 36 | + $base = basename $file; |
| 37 | + ($label, $Adate, $time, $version) = split /[\.]/, $base; |
| 38 | + |
| 39 | + $type = substr($label, 0, 5); |
| 40 | + $year = substr($Adate, 1, 4); |
| 41 | + $jdoy = substr($Adate, 5, 3); |
| 42 | + |
| 43 | + $subdir = "$workdir/$version/$type/$year/$jdoy"; |
| 44 | + unless (-d $subdir) { |
| 45 | + mkpath($subdir, \%flags) or die "Error making dir: $subdir;"; |
| 46 | + system("touch $subdir/.no_archiving"); |
| 47 | + } |
| 48 | + print "mv $file $subdir\n" if $verbose; |
| 49 | + move($file, $subdir); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + if ($avhrr) { |
| 54 | + foreach $file (<$workdir/patmosx_v05r02.*.npz>) { |
| 55 | + $base = basename $file; |
| 56 | + ($label, $adflg, $Adate) = split /[\.]/, $base; |
| 57 | + |
| 58 | + $year = substr($Adate, 0, 4); |
| 59 | + $month = substr($Adate, 4, 2); |
| 60 | + $day = substr($Adate, 6, 2); |
| 61 | + |
| 62 | + $subdir = "$workdir/Y$year/M$month/D$day"; |
| 63 | + unless (-d $subdir) { |
| 64 | + mkpath($subdir, \%flags) or die "Error making dir: $subdir;"; |
| 65 | + system("touch $subdir/.no_archiving"); |
| 66 | + } |
| 67 | + print "mv $file $subdir\n" if $verbose; |
| 68 | + move($file, $subdir); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + if ($viirs) { |
| 73 | + foreach $file (<$workdir/VN20AERD?_L2_VIIRS_NOAA20.*.*.nc>) { |
| 74 | + $base = basename $file; |
| 75 | + ($label, $Adate, $time, $version) = split /[\.]/, $base; |
| 76 | + |
| 77 | + $type = substr($label, 0, 9); |
| 78 | + $year = substr($Adate, 1, 4); |
| 79 | + $jdoy = substr($Adate, 5, 3); |
| 80 | + |
| 81 | + $subdir = "$workdir/${type}/$version/$year/$jdoy"; |
| 82 | + unless (-d $subdir) { |
| 83 | + mkpath($subdir, \%flags) or die "Error making dir: $subdir;"; |
| 84 | + system("touch $subdir/.no_archiving"); |
| 85 | + } |
| 86 | + print "mv $file $subdir\n" if $verbose; |
| 87 | + move($file, $subdir); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +#======================================================================= |
| 93 | +# name - init |
| 94 | +# purpose - get input parameters and flags |
| 95 | +#======================================================================= |
| 96 | +sub init { |
| 97 | + use Getopt::Long; |
| 98 | + |
| 99 | + GetOptions( "v" => \$verbose, |
| 100 | + "viirs" => \$viirs, |
| 101 | + "modis" => \$modis, |
| 102 | + "avhrr" => \$avhrr ); |
| 103 | + $workdir = shift @ARGV; |
| 104 | + |
| 105 | + $flags{"verbose"} = 1 if $verbose; |
| 106 | +} |
0 commit comments