Go to the documentation of this file.
64 #define NAME "pdsinfo"
70 #define PRI_HDR_SIZE 6
72 #define MODIS_HDR_SIZE 12
74 #define MODIS_REF_DATE 2436205.0
76 #define DATA_SIZE 100000
137 void caldat(
int *minute,
int *hour,
int *
day,
int *month,
int *
year,
146 int main(
int argc,
char *argv[]) {
156 unsigned char *buf_data;
162 long int firstday = 1.E6, firstms = 1.E6, firstmics = 1.E6;
164 long int lastday = 0, lastms = 0, lastmics = 0;
166 long int prevday = 0, prevms = 0;
168 int second, minute, hour,
day, month,
year;
178 long int missingsecs = 0;
182 int lastdays, lastmicrosec, lastsrc;
183 unsigned long int lastmillisec;
185 long int daypkts1 = 0, daypkts2 = 0;
187 long int nightpkts1 = 0, nightpkts2 = 0;
189 long int engpkts1 = 0, engpkts2 = 0;
195 fprintf(
stderr,
"%s V%d.%d ("__DATE__
")\n",
200 fprintf(
stderr,
"USAGE: %s <input>\n", argv[0]);
205 if (!(buf_data = malloc(
sizeof (
unsigned char) *
DATA_SIZE))) {
206 fprintf(
stderr,
"not enough memory\n");
211 if (!(fin = fopen(argv[1],
"rb"))) {
212 fprintf(
stderr,
"can't open input file (%s)\n", argv[1]);
225 "error 1 reading input file (%s): "
226 "file might be corrupted\n",
239 "unsupported packet version (%d): "
240 "file might be corrupted, trying to resyncronise\n",
244 if (fread(buf_data, hdr.
pkt_length + 1, 1, fin) != 1) {
246 "error 2 reading input file (%s): "
247 "file might be corrupted\n",
255 "unknown error (%d) while decoding primary header\n",
261 if (apidinfo !=
NULL) {
268 fprintf(
stderr,
"can't allocate memory\n");
279 fprintf(
stderr,
"can't allocate memory\n");
301 fprintf(
stderr,
"duplicated packet!!!\n");
313 "buffer overflow (%d), "
314 "please contact developer\n",
318 if (fread(buf_data, hdr.
pkt_length + 1, 1, fin) != 1) {
320 "error 3 reading input file (%s): "
321 "file might be corrupted\n",
328 if ((hdr.
apid >= 64) && (hdr.
apid <= 127)) {
334 fprintf(
stderr,
"duplicated MODIS packet: %d/%d %ld/%ld %d/%d %d/%d\n",
340 lastdays = mhdr.
days;
357 if (mhdr.
days < firstday) {
358 firstday = mhdr.
days;
362 if (mhdr.
days == firstday) {
364 firstday = mhdr.
days;
370 firstday = mhdr.
days;
378 if (mhdr.
days > lastday) {
383 if (mhdr.
days == lastday) {
404 (mhdr.
days - prevday) * 86400000;
405 missingsecs += diffms / 1000;
411 if (mhdr.
src1 == 0) {
444 if (apidinfo ==
NULL) {
445 fprintf(
stderr,
"no valid packets found\n");
450 for (apidinfo = apidlist;
452 apidinfo = apidinfo->
next) {
453 printf(
"APID %d: count %ld invalid %ld missing %ld\n",
463 hour = firstms / (1000
L * 60
L * 60
L);
464 ms = firstms - hour * 1000
L * 60
L * 60
L;
465 minute = ms / (1000
L * 60
L);
466 ms = ms - minute * 1000
L * 60
L;
468 ms = ms - second * 1000
L;
469 printf(
"first packet: %04d/%02d/%02d %02d:%02d:%d.%03ld%03ld\n",
470 year, month,
day, hour, minute, second, ms, firstmics);
473 hour = lastms / (1000
L * 60
L * 60
L);
474 ms = lastms - hour * 1000
L * 60
L * 60
L;
475 minute = ms / (1000
L * 60
L);
476 ms = ms - minute * 1000
L * 60
L;
478 ms = ms - second * 1000
L;
479 printf(
"last packet: %04d/%02d/%02d %02d:%02d:%d.%03ld%03ld\n",
480 year, month,
day, hour, minute, second, ms, lastmics);
483 printf(
"missing seconds: %ld\n", missingsecs);
486 printf(
"day packets: %ld/%ld\n", daypkts1, daypkts2);
489 printf(
"night packets: %ld/%ld\n", nightpkts1, nightpkts2);
492 printf(
"engineering packets: %ld/%ld\n", engpkts1, engpkts2);
540 hdr->
version = (buf[0] & 0xE0) >> 5;
547 hdr->
type = (buf[0] & 0x10) >> 4;
553 hdr->
apid = (((
int) (buf[0] & 0x07)) << 8) + buf[1];
559 hdr->
pkt_count = (((
int) (buf[2] & 0x3F)) << 8) + buf[3];
584 if (!(ai = malloc(
sizeof (
struct apid_info))))
634 if ((*list)->apid > ai->
apid) {
646 if (
p->next->apid > ai->
apid) {
732 (((
int) buf[0]) << 8) +
737 (((
unsigned long int) buf[2]) << 24) +
738 (((
unsigned long int) buf[3]) << 16) +
739 (((
unsigned long int) buf[4]) << 8) +
740 (((
unsigned long int) buf[5]));
744 (((
int) buf[6]) << 8) +
748 hdr->
ql = (buf[8] & 0x80) >> 7;
751 hdr->
pkt_type = (buf[8] & 0x70) >> 4;
760 hdr->
src1 = (buf[9] & 0x80) >> 7;
764 (((
int) buf[9] & 0x7F) << 4) +
765 (((
int) buf[10] & 0xF0) >> 4);
769 (((
int) buf[10] & 0x0F) << 6) +
770 (((
int) buf[11] & 0xFC) >> 2);
780 (((
int) buf[len - 2] & 0x0F) << 8) +
781 (((
int) buf[len - 1]));
805 long ja, jalpha,
jb, jc,
jd, je;
808 ljul = (long) floor(jul);
810 *hour = (
int) (floor(jul * 24.0));
811 jul -= (
double) *hour / 24.0;
812 *minute = (
int) (floor(jul * 1440.0));
814 if (ljul >= 2299161) {
815 jalpha = (long) (((
float) (ljul - 1867216) - 0.25) / 36524.25);
816 ja = ljul + 1 + jalpha - (long) (0.25 * jalpha);
820 jc = (long) (6680.0 + ((
float) (
jb - 2439870) - 122.1) / 365.25);
821 jd = (long) (365 * jc + (0.25 * jc));
822 je = (long) ((
jb -
jd) / 30.6001);
823 *
day =
jb -
jd - (long) (30.6001 * je);
854 for (
i = 0;
i < n;
i++) {
857 (((
unsigned long) buf[(
int) (1.5 *
i)]) << 4) +
858 (((
unsigned long) buf[(
int) (1.5 *
i) + 1] & 0xF0) >> 4);
872 (((
unsigned long) buf[(
int) (1.5 * (
i - 1)) + 1] & 0x0F) << 8) +
873 (((
unsigned long) buf[(
int) (1.5 * (
i - 1)) + 2]));
unsigned long int millisec
list(APPEND LIBS ${PGSTK_LIBRARIES}) add_executable(atteph_info_modis atteph_info_modis.c) target_link_libraries(atteph_info_modis $
int DecodePriHdr(unsigned char *buf, struct pri_hdr *hdr)
void caldat(int *minute, int *hour, int *day, int *month, int *year, double jul)
struct apid_info * FindAPIDInfo(struct apid_info *list, int apid)
void FreeAPIDInfoList(struct apid_info *list)
int ReadPriHdr(FILE *f, unsigned char *buf)
struct apid_info * AllocAPIDInfo(int apid)
int CalcChecksum12(unsigned char *buf, int n)
a context in which it is NOT documented to do so subscript error
double precision function f(R1)
int main(int argc, char *argv[])
void AddAPIDInfo(struct apid_info **list, struct apid_info *ai)
int DecodeMODISHdr(unsigned char *buf, int len, struct modis_hdr *hdr)
integer, parameter double