]> Pileus Git - ~andy/rsl/blob - examples/kwaj_subtract_one_day.c
RSL v1.41
[~andy/rsl] / examples / kwaj_subtract_one_day.c
1 #include <stdlib.h>
2 #include "rsl.h"
3
4 /**********************************************************************/
5 /*                                                                    */
6 /*                           usage                                    */
7 /*                                                                    */
8 /**********************************************************************/
9 void usage(char **argv)
10 {
11   fprintf(stderr, "Usage: %s in out.uf\n", argv[0]);
12   fprintf(stderr, "\n");
13   fprintf(stderr, "Subtract one day from all time fields in all headers,\n");
14   fprintf(stderr, "all the way down to the ray.  Output to uf.\n");
15   return;
16 }
17
18 /**********************************************************************/
19 /*                                                                    */
20 /*                        subtract_one_day_ray                        */
21 /*                                                                    */
22 /**********************************************************************/
23 #include<time.h>
24 void    *subtract_one_day(int month, int day, int year,
25                                                   int *m, int *d, int *y)
26 {
27   /* Connocialize and subtract. */
28   struct tm *t;
29   time_t the_time;
30
31   t = (struct tm *)calloc(1, sizeof(struct tm));
32   t->tm_mon  = month-1;   /* 0 - 11 */
33   t->tm_mday = day-1;       /* 1 - 31 */  /* And, subtract one day. */
34   t->tm_year = year-1900; /* since 1900 */
35   the_time = mktime(t);
36   t = localtime(&the_time);
37   *m = t->tm_mon+1;
38   *d = t->tm_mday;
39   *y = t->tm_year+1900;
40   return;
41 }
42
43 /**********************************************************************/
44 /*                                                                    */
45 /*                        subtract_one_day_ray                        */
46 /*                                                                    */
47 /**********************************************************************/
48 Ray    *subtract_one_day_ray(Ray *x)
49 {
50   if (x == NULL) return x;
51   subtract_one_day(x->h.month, x->h.day, x->h.year,
52                                    &x->h.month, &x->h.day, &x->h.year);
53   return x;
54 }
55 /**********************************************************************/
56 /*                                                                    */
57 /*                        subtract_one_day_sweep                      */
58 /*                                                                    */
59 /**********************************************************************/
60 Sweep  *subtract_one_day_sweep(Sweep *x)
61 {
62   int i;
63
64   if (x == NULL) return x;
65   for(i=0; i<x->h.nrays; i++)
66         x->ray[i] = subtract_one_day_ray(x->ray[i]);
67   return x;
68 }
69 /**********************************************************************/
70 /*                                                                    */
71 /*                        subtract_one_day_volume                     */
72 /*                                                                    */
73 /**********************************************************************/
74 Volume *subtract_one_day_volume(Volume *x)
75 {
76   int i;
77
78   if (x == NULL) return x;
79   for(i=0; i<x->h.nsweeps; i++)
80         x->sweep[i] = subtract_one_day_sweep(x->sweep[i]);
81   return x;
82 }
83 /**********************************************************************/
84 /*                                                                    */
85 /*                        subtract_one_day_radar                      */
86 /*                                                                    */
87 /**********************************************************************/
88 Radar  *subtract_one_day_radar(Radar *x)
89 {
90   int i;
91
92   if (x == NULL) return x;
93   for(i=0; i<x->h.nvolumes; i++)
94         x->v[i] = subtract_one_day_volume(x->v[i]);
95   return x;
96 }
97   
98
99
100 /**********************************************************************/
101 /*                                                                    */
102 /*                             m a i n                                */
103 /*                                                                    */
104 /**********************************************************************/
105 int main(int argc, char **argv)
106 {
107
108   Radar *radar;
109
110   if (argc != 3) {
111         usage(argv);
112         exit(-1);
113   }
114
115   radar = RSL_anyformat_to_radar(argv[1]);
116   radar = subtract_one_day_radar(radar);
117   subtract_one_day(radar->h.month, radar->h.day, radar->h.year,
118                                    &radar->h.month, &radar->h.day, &radar->h.year);
119   RSL_radar_to_uf_gzip(radar, argv[2]);
120
121   exit(0);
122 }