Skip to content

Commit 5141cd6

Browse files
committed
Added the fileIngest to contributions subdirectory
1 parent 9197597 commit 5141cd6

23 files changed

+9605
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/test
2+
/fileIngester
3+
/test.c
4+
/log_tester
5+
/Makefile.in
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright 2011 University Corporation for Atmospheric Research
2+
#
3+
# This file is part of the Unidata LDM package. See the file COPYRIGHT in the
4+
# top-level source-directory of the package for copying and redistribution
5+
# conditions.
6+
#
7+
## Process this file with automake(1) to produce file Makefile.in
8+
9+
################################################################################
10+
11+
LDMHOME = @LDMHOME@
12+
LDMSRC = $(top_srcdir)
13+
14+
CLEANFILES = $(BUILT_SOURCES)
15+
16+
AM_CPPFLAGS = \
17+
-DLDM_SUPPORT \
18+
-I$(top_srcdir) \
19+
-I$(top_srcdir)/noaaport \
20+
-I$(top_srcdir)/protocol -I$(top_builddir)/protocol \
21+
-I$(top_srcdir)/protocol2 \
22+
-I$(top_srcdir)/pq \
23+
-I$(top_srcdir)/ulog \
24+
-I$(top_srcdir)/log \
25+
-I$(top_srcdir)/misc \
26+
-I$(top_builddir)/registry -I$(top_srcdir)/registry
27+
28+
bin_PROGRAMS = fileIngester
29+
30+
COMMON_SOURCES = \
31+
stdclib.c stdclib.h \
32+
goesr_lib.c goesr_lib.h \
33+
mlogger.c mlogger.h \
34+
datelib.c datelib.h \
35+
ldmProductQueue.c ldmProductQueue.h
36+
37+
fileIngester_SOURCES = fileIngester.c $(COMMON_SOURCES)
38+
39+
LDADD = $(top_builddir)/lib/libldm.la
40+
41+
TAGS_FILES = \
42+
*.c *.h
43+
44+
.c.i:
45+
$(COMPILE) -E $< >$@
46+
47+
.hin.h:
48+
./extractDecls $*.hin $*.c >$@.tmp
49+
mv -f $@.tmp $@
50+
51+
#installcheck-local:
52+
# pqcreate -c -s 2m /tmp/readnoaaport-test.pq
53+
# $(DESTDIR)$(bindir)/readnoaaport -l- -q /tmp/readnoaaport-test.pq \
54+
# $(srcdir)/nwstgdump.data
55+
# rm /tmp/readnoaaport-test.pq
56+
57+
#check-local: check-readnoaaport
58+
#check-readnoaaport: readnoaaport
59+
# pqcreate -c -s 2m /tmp/readnoaaport-test.pq
60+
# ./readnoaaport -nl- -q /tmp/readnoaaport-test.pq \
61+
# $(srcdir)/nwstgdump.data
62+
# rm /tmp/readnoaaport-test.pq
63+
64+
#root-ni-ck:
65+
# ./noaaportIngester -b 3 -q /tmp/noaaportIngester-test.pq \
66+
# <$(srcdir)/nwstgdump.data
67+
68+
#valgrind: valgrind-readnoaaport
69+
70+
#valgrind-readnoaaport: readnoaaport
71+
# pqcreate -c -s 2m /tmp/readnoaaport-test.pq
72+
# $(LIBTOOL) --mode=execute valgrind --leak-check=yes \
73+
# readnoaaport -l- -q /tmp/readnoaaport-test.pq nwstgdump.data
74+
# rm /tmp/readnoaaport-test.pq
75+
76+
#root-ni-vg:
77+
# $(LIBTOOL) --mode=execute valgrind --leak-check=yes \
78+
# noaaportIngester -n -q /tmp/noaaportIngester-test.pq \
79+
# <$(srcdir)/nwstgdump.data
80+
81+
#debug-readnoaaport: readnoaaport
82+
# pqcreate -c -s 2m /tmp/readnoaaport-test.pq
83+
# echo 'handle SIGCONT pass noprint nostop' >/tmp/readnoaaport.gdb
84+
# echo 'b 617' >>/tmp/readnoaaport.gdb
85+
# echo 'run -l- -q /tmp/readnoaaport-test.pq nwstgdump.data' \
86+
# >>/tmp/readnoaaport.gdb
87+
# $(LIBTOOL) --mode=execute gdb -x /tmp/readnoaaport.gdb readnoaaport
88+
# rm /tmp/readnoaaport-test.pq /tmp/readnoaaport.gdb
89+
90+
#root-ni-db:
91+
# $(LIBTOOL) --mode=execute gdb -x /tmp/noaaportIngester.gdb \
92+
# noaaportIngester
93+
94+
#.PHONY:
95+
# install-html \
96+
# root-ni-ck \
97+
# root-ni-db \
98+
# root-ni-vg
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
COPTS = -g -Wall
3+
4+
BUILT_HEADERS = datelib.h goesr_lib.h mlogger.h stdclib.h
5+
BUILT_PROGS = fileIngester test read_acq_pipe log_tester
6+
INGEST_OBJS = fileIngester.o stdclib.o goesr_lib.o mlogger.o
7+
8+
all :: fileIngester test log_tester read_acq_pipe
9+
10+
clean ::
11+
rm -f $(INGEST_OBJS) $(BUILT_PROGS) read_acq_pipe.o log_tester.o
12+
13+
%.h : %.hin %.c extractDecls
14+
./extractDecls $*.hin $*.c > $@
15+
16+
%.o : %.c
17+
cc $(COPTS) -o $@ -c $<
18+
19+
goesr_lib.o : stdclib.h mlogger.h goesr_lib.h
20+
stdclib.o : stdclib.h
21+
fileIngester.o : stdclib.h mlogger.h goesr_lib.h
22+
log_tester.o : stdclib.h mlogger.h
23+
24+
fileIngester : $(INGEST_OBJS)
25+
cc -g -lrt -o $@ $^
26+
27+
read_acq_pipe : read_acq_pipe.o stdclib.o
28+
cc -g -lrt -o $@ $^
29+
30+
acq_ftp_send : $(INGEST_OBJS)
31+
cc -g -lrt -o $@ $^
32+
33+
test : test.o
34+
cc -g -o $@ $^
35+
36+
log_tester : log_tester.o mlogger.o stdclib.o
37+
cc -g -lrt -o $@ $^
38+

contributions/fileIngest/datelib.c

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/* ------------------------------------------------------------------------------
2+
*
3+
* File Name:
4+
* datelib.c
5+
*
6+
* Description:
7+
* This file contains functions for manipulating dates and times.
8+
*
9+
* Functions defined:
10+
* format_date_string
11+
*
12+
* Author:
13+
* Brian Rapp Jun 19, 2012
14+
*
15+
* Modification History:
16+
* Modified by Date
17+
* Description
18+
*
19+
------------------------------------------------------------------------------ */
20+
21+
#ifndef _XOPEN_SOURCE
22+
#define _XOPEN_SOURCE
23+
#endif
24+
#include <time.h>
25+
#include <stdio.h>
26+
#include <stdlib.h>
27+
#include <string.h>
28+
#include <unistd.h>
29+
#include <ctype.h>
30+
#include <libgen.h>
31+
32+
#include "datelib.h"
33+
34+
/* ------------------------------------------------------------------------------
35+
36+
Function Name
37+
formatDateString
38+
Synopsis
39+
Creates custom-formatted date strings.
40+
41+
Prototype
42+
int formatDateString (char *in_format, char *out_format, long adjustment,
43+
char *in_date, char *out_date)
44+
45+
Arguments
46+
47+
Name: in_format
48+
Type: char *
49+
Access: read only
50+
51+
Character string containing the format specification for the input time.
52+
See the man page for strftime for details. This is only used when an
53+
absolute input date is provided.
54+
55+
Name: out_format
56+
Type: char *
57+
Access: read only
58+
59+
Character string containing the Format specification for the output time.
60+
See the man page for strftime for details. This argument is required.
61+
62+
Name: adjustment
63+
Type: long
64+
Access: read only
65+
66+
A long integer containing an adjustment (in seconds) to be applied to
67+
the input time. Negative values adjust the time prior to the input
68+
time. Positive values adjust the time after the input time. A value of
69+
zero indicates no adjustment is to be made to the input time.
70+
71+
Name: in_date
72+
Type: char *
73+
Access: read only
74+
75+
Character string containing the input time. Can be an absolute time in
76+
any format supported by the strftime function, or one of the following
77+
relative times:
78+
79+
NOW Current date and time
80+
TODAY Today at midnight
81+
YESTERDAY Yesterday at midnight
82+
TOMORROW Tomorrow at midnight
83+
84+
Name: out_date
85+
Type: char *
86+
Access: write only
87+
88+
A character string that is large enough to hold the output date provided
89+
in the out_format argument. The string must be allocated by the caller.
90+
91+
Name: max_out_size
92+
Type: int
93+
Access: read only
94+
95+
An integer containing the maximum size for out_date. This value must
96+
include the trailing nul character.
97+
98+
Description
99+
This function creates a formatted date string optionally adjusted by
100+
a specified amount. The output format defaults to "YYYY-MM-DD HH:MM:SS",
101+
but can be fully specified with the 'out_format' argument. See the
102+
man page for strftime for more information on formatting.
103+
104+
An input time string is required, which can either be an absolute time
105+
of the form "YYYY-MM-DD HH:MM:SS" or one of the relative time strings
106+
"NOW", "YESTERDAY", "TODAY", or "TOMORROW".
107+
108+
Another optional parameter provides the
109+
ability to adjust the time string by the specified number of seconds.
110+
111+
Return Values
112+
The number of characters placed in out_date, not including the terminating
113+
nul terminator, provided the string, including the terminating nul byte,
114+
fits. Otherwise, it returns 0, and the contents of the array is undefined.
115+
116+
------------------------------------------------------------------------------ */
117+
118+
int formatDateString (const char *in_format, const char *out_format, long adjustment,
119+
char *in_date, char *out_date, int max_out_size) {
120+
121+
struct tm *tp;
122+
struct tm ts;
123+
time_t the_time;
124+
char *res;
125+
size_t stat;
126+
time_t time_adjust = 0;
127+
char new_out_format[MAX_DATE_FORMAT_LEN+1];
128+
129+
if ((out_format == NULL) || (strlen (out_format) == 0)) {
130+
strcpy (new_out_format, DEFAULT_OUT_FORMAT);
131+
} else {
132+
strncpy (new_out_format, out_format, MAX_DATE_FORMAT_LEN);
133+
}
134+
135+
if (!strcmp (in_date, RELT_NOW)) {
136+
time (&the_time);
137+
} else {
138+
if (!strcmp (in_date, RELT_TODAY)) {
139+
time (&the_time);
140+
tp = localtime (&the_time);
141+
tp->tm_hour = tp->tm_min = tp->tm_sec = 0;
142+
the_time = mktime (tp);
143+
} else {
144+
if (!strcmp (in_date, RELT_YESTERDAY)) {
145+
time (&the_time);
146+
tp = localtime (&the_time);
147+
tp->tm_hour = tp->tm_min = tp->tm_sec = 0;
148+
the_time = mktime (tp);
149+
the_time -= 86400;
150+
} else {
151+
if (!strcmp (in_date, RELT_TOMORROW)) {
152+
time (&the_time);
153+
tp = localtime (&the_time);
154+
tp->tm_hour = tp->tm_min = tp->tm_sec = 0;
155+
the_time = mktime (tp);
156+
the_time += 86400;
157+
} else {
158+
memset (&ts, 0, sizeof (struct tm));
159+
res = strptime (in_date, in_format, &ts); /* Convert time string to broken-down time -- dst may be wrong */
160+
if ((res == 0) || (*res != 0)) {
161+
return 0;
162+
}
163+
164+
/* Convert broken-down time back to calendar time so we have a proper value for tm_isdst */
165+
the_time = mktime (&ts); /* Convert broken-down time to calendar time */
166+
localtime_r (&the_time, &ts); /* Convert calendar time back to broken-down time -- dst will be set properly here */
167+
168+
res = strptime (in_date, in_format, &ts);
169+
170+
if ((ts.tm_year == 0) || (ts.tm_mday == 0)) {
171+
return 0;
172+
}
173+
the_time = mktime (&ts);
174+
}
175+
}
176+
}
177+
}
178+
179+
the_time += time_adjust;
180+
memset (&ts, 0, sizeof (struct tm));
181+
tp = localtime_r (&the_time, &ts); /* This will set tm_isdst properly for the given time */
182+
stat = strftime (out_date, max_out_size, new_out_format, &ts);
183+
184+
return stat;
185+
186+
}

0 commit comments

Comments
 (0)