Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / TBBT / trace_init / ns_loc2gmt.pl
1 #!/usr/bin/perl\r
2 #\r
3 # Copyright (c) 2002-2003\r
4 #      The President and Fellows of Harvard College.\r
5 #\r
6 # Redistribution and use in source and binary forms, with or without\r
7 # modification, are permitted provided that the following conditions\r
8 # are met:\r
9 # 1. Redistributions of source code must retain the above copyright\r
10 #    notice, this list of conditions and the following disclaimer.\r
11 # 2. Redistributions in binary form must reproduce the above copyright\r
12 #    notice, this list of conditions and the following disclaimer in the\r
13 #    documentation and/or other materials provided with the distribution.\r
14 # 3. Neither the name of the University nor the names of its contributors\r
15 #    may be used to endorse or promote products derived from this software\r
16 #    without specific prior written permission.\r
17 #\r
18 # THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND\r
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
21 # ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE\r
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
28 # SUCH DAMAGE.\r
29 #\r
30 # $Id: ns_loc2gmt,v 1.6 2003/07/28 14:27:16 ellard Exp $\r
31 #\r
32 # A helper application used by ns_quickview to convert from local time\r
33 # to GMT.  nfsdump records time as localtime, but gnuplot only know\r
34 # how to deal with dates expressed as Greenwich Mean Time (which it\r
35 # then displays using the local time, for some reason).\r
36 #\r
37 # This is a fragile tool -- it must be run in the same time zone in\r
38 # which the data was collected via nfsdump, or else it will not do the\r
39 # proper conversion.  Improvements welcomed!\r
40 #\r
41 # The 'C' (count) and 'L' (latency) records use the second column for\r
42 # dates, expressed as seconds.microseconds in localtime.  The seconds\r
43 # portion is the only part of the data modified by this program. \r
44 # Comment lines are passed through unaltered.\r
45 #\r
46 # There is no error checking.  Garbage in, garbage out.\r
47 #\r
48 # Note - we're throwing the microseconds away.\r
49 \r
50 \r
51 use Getopt::Std;\r
52 require 'timelocal.pl';\r
53 \r
54 $Usage =<< ".";\r
55 \r
56 Usage: $0 [options] [table1.ns [table2.ns ... ]]\r
57 \r
58 If no table files are specified, then the input is read from stdin.\r
59 \r
60 Command line options:\r
61 \r
62 -h              Print usage message and exit.\r
63 \r
64 -d secs         Time offset, in seconds, to subtract from each time\r
65                 in the input tables.  Note that all times are rounded\r
66                 down to the nearest second.\r
67 \r
68 IMPORTANT NOTE:  this must be run in the same time zone in which the\r
69 data was collected via nfsdump, or else it will not do the proper\r
70 conversion unless the -d option is used.\r
71 \r
72 .\r
73 \r
74 $Options = "d:";\r
75 if (! getopts ($Options)) {\r
76         print STDERR "$0: Incorrect usage.\n";\r
77         print STDERR $Usage;\r
78         exit (1);\r
79 }\r
80 if (defined $opt_h) {\r
81         print $Usage;\r
82         exit (0);\r
83 }\r
84 \r
85 $TimeOffset = 0;\r
86 if (defined $opt_d) {\r
87         $TimeOffset = int ($opt_d);\r
88 }\r
89 \r
90 while ($line = <>) {\r
91         if ($line =~ /^#/) {\r
92                 print $line;\r
93                 next;\r
94         }\r
95 \r
96         @arr = split (' ', $line);\r
97 \r
98         ($secs, $usec) = split (/\./, $arr[1]);\r
99         $secs -= $TimeOffset;\r
100 \r
101         $arr[1] = &timegm (localtime ($secs));\r
102 \r
103         print join (' ', @arr);\r
104         print "\n";\r
105 }\r
106 \r
107 exit (0);\r
108 \r