Date: Thu, 16 Jan 1997 9:53:32 -0500 (EST) From: "SANDY KRAMER, Code 692, NASA GSFC, 301-286-4957" To: z1sbk@lepvgr.GSFC.NASA.GOV Message-Id: <970116095332.204004b1@LEPVOY.GSFC.NASA.GOV> Subject: SEDR_REBLCK.C Date: Mon, 12 Apr 93 09:54:48 EDT From: George S. Gordon Jr. To: XRTPM@lepvax.gsfc.nasa.gov Subject: Re: SEDR reblocking Content-Type: X-sun-attachment ---------- X-Sun-Data-Type: text X-Sun-Data-Description: text X-Sun-Data-Name: text X-Sun-Content-Lines: 14 It is probably easiest to get my EDR's from fuzzpeach, As I reformat them immedeately. I have the some reblocking programs for summary, but a look at your's would be helpfull, as they might be better than mine which are sort of a hack. my conv_sedr.c follows after the line of '*' gsg jr. ************************************************************** ---------- X-Sun-Data-Type: c-file X-Sun-Data-Description: c-file X-Sun-Data-Name: conv_sedr.c X-Sun-Content-Lines: 376 #include /* modified to allow only 1 pointing block for each nav block */ /* modified to try to recover from being lost */ #define MAX_SKIP 99 #define MIN_SKIP 3 static int break_num[20]; static int skip_num[ MAX_SKIP + 1 ]; static int in=0; static int out=1; static unsigned char buf[20000]; static unsigned char *pt_buf; static int scid=-3; static int nb=1; static int nbyte_st=126; static int nbyte=126; static int size_header=180; static int size_data_w=126; static int size_data=504; static int count_rec=0; static int count_byte=0; static int count_byte_read=0; static int nbb; static int lcheck=0; static int iny,ind,inh,inm,ins; /* time of current nav */ static int ipy,ipd,iph,ipm,ips; /* time of current pointing */ static int iNy,iNd,iNh,iNm,iNs; /* time of last nav */ static int iPy,iPd,iPh,iPm,iPs; /* time of last pointing */ /* read a sedr with no inter record gaps, and put in bat format */ /* does not work for saturn encounter & manuver tapes */ /* */ main() { int which_read; int num_pb; int nbo, nboo, nbooo; int *pt_int; int num_skip; int num_skip_o; int lheader; int found; int *pt_int_end; int i; num_skip_o = num_skip = 0; iny = -1; /* flag for starting time */ while ( nb > 0 ) { /* loop till end of data */ which_read = 11; if ( num_skip > MAX_SKIP ) break; num_pb = 0; nbooo = nboo = nbo = -1; lheader = 0; which_read = 1; nb = fread( buf, sizeof( char), size_header, stdin); count_byte_read += nb; if ( nb <= 0 ) break; if ( nb != size_header ) { /* read error */ fprintf( stderr,"read error after REC %d, BYTE %d, 0x%x\nnb %d, size_header %d, bytes read %d, 0x%x\n", count_rec, count_byte, count_byte, nb, size_header, count_byte_read, count_byte_read); break_num[1]++; break; } /* check type of block */ if ( buf[0] == 0xe5 && buf[1] == 0xc7 && buf[2] == 0xd9 && buf[3] == 0x40 && buf[4] == 0xe2 && buf[5] == 0xc5 && buf[6] == 0xc4 && buf[7] == 0xd9 ) { /* first two words are "VGR SEDR", so we have a header block */ scid = *( (int *) &buf[8]); if ( scid != 0 && scid != 1 ) { fprintf( stderr, "After block %d, byte count %d, 0x%x\n", count_rec, count_byte, count_byte); fprintf( stderr,"wrong scid %d\n", scid); fprintf( stderr," last good time was NAV %d %d %d %d %d POINT %d %d %d %d %d\n", iNy,iNd, iNh, iNm, iNs, iPy, iPd, iPh, iPm, iPs); exit( 1); } if ( ! ( buf[12] == 0xe2 && ( buf[13] == 0xd7 && buf[14] == 0xd3 ) || (( buf[13] == 0xd4 && buf[14] == 0xc1 )))) { /* failed tape identifier */ fprintf( stderr, "After block %d, byte count %d, 0x%x\n", count_rec, count_byte, count_byte); fprintf( stderr,"wrong tape identifier\n"); fprintf( stderr," last good time was NAV %d %d %d %d %d POINT %d %d %d %d %d\n", iNy,iNd, iNh, iNm, iNs, iPy, iPd, iPh, iPm, iPs); exit(4); } lheader = 1; } else { /* should be a nav block */ pt_int = ( int * ) &buf[0]; /* check time */ nbooo = nboo; nboo = nbo; nbo = nb; which_read = 2; nbb = fread( &buf[nb], sizeof( char), size_data - nb, stdin); /* read in enough for short nav */ count_byte_read += nbb; if ( nbb <= 0 ) break; if ( nbb != size_data - nb ) { /* read error */ fprintf( stderr,"read error %d %d\ncount_rec %d, count_byte %d, 0x%x, %d bytes read, %d bytes expected\nbytes read %d, 0x%x\n", count_rec, count_byte, count_byte, nbb,size_data - nb, count_byte_read, count_byte_read); break_num[2]++; break; } nb += nbb; if ( ( *(pt_int + 0) == 0 && *(pt_int + 1) == 0 && *(pt_int + 2) == 0 && *(pt_int + 3) == 0 && *(pt_int + 4) == 0 ) || (( (*(pt_int + 0) > 30000) || (*(pt_int + 0) < -30000)) && ((*(pt_int + 1) > 30000) || (*(pt_int + 1) < -30000)) &&((*(pt_int + 2) > 30000) || (*(pt_int + 2) < -30000)) &&((*(pt_int + 3) > 30000) || (*(pt_int + 3) < -30000)) &&((*(pt_int + 4) > 30000 ) || (*(pt_int + 4) < -30000)) ) ) { /* skip zero records or out of position record */ /* check if we want to search for time */ found = 0; if ( num_skip > MIN_SKIP ) { pt_int_end = (( int * ) &buf[ size_data]) - 6; while ( pt_int < pt_int_end ) { /* look for time block */ if (( *(pt_int + 0) < 2030) && *(pt_int + 0) >= 1977 && ( *(pt_int + 1) < 367) && *(pt_int + 1) >= 0 && ( *(pt_int + 2) < 24) && *(pt_int + 2) >= 0 && ( *(pt_int + 3) < 60) && *(pt_int + 3) >= 0 && ( *(pt_int + 4) < 60) && *(pt_int + 4) >= 0 && ( *(pt_int + 5) < 1000) && *(pt_int + 5) >= 0 ) found = 1; if ( found == 1 ) break; } if ( found == 1 ) { /* found pounting block so move it to beginning of buffer & fill buffer */ nb = &buf[size_data] - ( unsigned char *) pt_int; bcopy( (char *) pt_int, &buf[0], nb); pt_int = ( int * ) &buf[0]; /* check time, already done */ iny = *(pt_int + 0); ind = *(pt_int + 1); inh = *(pt_int + 2); inm = *(pt_int + 3); ins = *(pt_int + 4); nbooo = nboo; nboo = nbo; nbo = nb; which_read = 3; nbb = fread( &buf[nb], sizeof( char), size_data - nb, stdin); /* read in enough for short nav */ nb += nbb; fprintf( stderr,"OUT of ORDER time sequence at times %d %d %d %d ; %d %d %d %d %d\n", iNy, iNd, iNh, iNm, iNs, iny, ind, inh, inm, ins); } } } else { found = 1; } if ( found == 0 ) { /* fprintf( stderr,"skipping %d bytes after rec %d, byte %d, 0x%x\n", nb, count_rec, count_byte, count_byte); fprintf( stderr, "time NAV %d %d %d %d %d\n", iny, ind, inh, inm, ins); */ num_skip++; break_num[11]++; continue; } else { /* not a zero block, so a Nav block */ pt_int = ( int * ) &buf[0]; /* check time */ iNy = iny; iNd = ind; iNh = inh; iNm = inm; iNs = ins; iny = *(pt_int + 0); ind = *(pt_int + 1); inh = *(pt_int + 2); inm = *(pt_int + 3); ins = *(pt_int + 4); if ( iNy == -1 ) { fprintf( stderr,"starting time NAV %d %d %d %d %d \n", iny,ind, inh, inm, ins); } nbooo = nboo; nboo = nbo; nbo = nb; which_read = 4; nbb = fread( &buf[nb], sizeof( char), 2*size_data - nb, stdin); /* read in enough for short nav plus pointing */ count_byte_read += nbb; if ( nbb <= 0 ) break; if ( nbb != 2*size_data - nb ) { /* read error */ fprintf( stderr,"read error %d %d\ncount_rec %d, count_byte %d, 0x%x, %d bytes read, %d bytes expected\nbytes read %d, 0x%x\n", count_rec, count_byte, count_byte, nbb, 2*size_data - nb, count_byte_read, count_byte_read); break_num[3]++; break; } nb += nbb; } if ( ( iny < 1977 || iny > 2030 ) || ( ind < 0 || ind > 366 ) || ( inh >= 24 || inh < 0 ) || ( inm < 0 || inm >= 60 ) || ( ins < 0 || ins >= 60 )) { /* failed time test on nav block */ fprintf( stderr,"\nbad nav time %d %d %d %d %d, at block %d, byte %d, 0x%x, bytes read %d, 0x%x\n", iny, ind, inh, inm, ins, count_rec, count_byte, count_byte, count_byte_read, count_byte_read); fprintf( stderr," last good time was NAV %d %d %d %d %d POINT %d %d %d %d %d\n", iNy,iNd, iNh, iNm, iNs, iPy, iPd, iPh, iPm, iPs); fprintf( stderr,"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", *(pt_int + 0), *(pt_int + 1), *(pt_int + 2), *(pt_int + 3), *(pt_int + 4), *(pt_int + 5), *(pt_int + 6), *(pt_int + 7)); if ( ( num_skip + num_skip_o > 0 || ( ( iny < 1977 || iny > 2030 ) || ( ind < 0 || ind > 400 ) || ( inh >= 40 || inh < 0 ) || ( inm < 0 || inm >= 66 ) || ( ins < 0 || ins >= 66 )) ) ) { /* slightly out of time, just skip, or just after skip */ num_pb = 0; num_skip++; break_num[12]++; continue; } else { exit( 11); } } if ( *(pt_int + 6) > -30000 && *(pt_int + 6) < 30000 || *(pt_int + 7) > -30000 && *(pt_int + 7) < 30000 ) { /* not a nav block */ fprintf( stderr, "After block %d, byte count %d, 0x%x, bytes read %d, 0x%x\n", count_rec, count_byte, count_byte, count_byte_read, count_byte_read); fprintf( stderr," bad data in place of nav block\n"); fprintf( stderr," last good time was NAV %d %d %d %d %d POINT %d %d %d %d %d\n", iNy,iNd, iNh, iNm, iNs, iPy, iPd, iPh, iPm, iPs); pt_int = ( int * ) &buf[0]; fprintf( stderr,"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", *(pt_int + 0), *(pt_int + 1), *(pt_int + 2), *(pt_int + 3), *(pt_int + 4), *(pt_int + 5), *(pt_int + 6), *(pt_int + 7)); num_pb = 0; num_skip++; break_num[13]++; continue; /* exit(5); */ } if ( buf[ (size_data_w+6)*4] == 0x00 || buf[ (size_data_w+7)*4] == 0x00 || buf[ (size_data_w+0)*4] == 0x00 || buf[ (size_data_w+1)*4] == 0x00 ||buf[ (size_data_w+2)*4] == 0x00 || buf[ (size_data_w+3)*4] == 0x00 || buf[ (size_data_w+4)*4] == 0x00 ||buf[ (size_data_w+5)*4] == 0x00 ) { /* short nav block */ pt_int = ( int * ) &buf[ size_data]; /* check time */ } else { nbooo = nboo; nboo = nbo; nbo = nb; which_read = 5; nbb = fread( &buf[nb], sizeof( char), 3*size_data - nb, stdin); /* read in rest of data for long nav plus pointing */ count_byte_read += nbb; if ( nbb <= 0 ) break; if ( nbb != 3*size_data - nb ) { /* read error */ fprintf( stderr,"read error %d %d\ncount_rec %d, count_byte %d, 0x%x, %d bytes read, %d bytes expected\nbytes read %d, 0x%x\n", count_rec, count_byte, count_byte, nb, 3*size_data - nb , count_byte_read, count_byte_read ); break_num[4]++; break; } nb += nbb; if ( buf[ (2*size_data_w+6)*4] == 0x00 && buf[ (2*size_data_w+7)*4] == 0x00 && buf[ (2*size_data_w+0)*4] == 0x00 && buf[ (2*size_data_w+1)*4] == 0x00 && buf[ (2*size_data_w+2)*4] == 0x00 && buf[ (2*size_data_w+3)*4] == 0x00 && buf[ (2*size_data_w+4)*4] == 0x00 && buf[ (2*size_data_w+5)*4] == 0x00 ) { /* long nav block */ pt_int = ( int * ) &buf[ 2*size_data]; /* check time */ } } /* check for pointing blocks */ while ( num_pb == 0 || *( ( int * ) &buf[ nb - size_data + 400]) == 1 ) { nbooo = nboo; nboo = nbo; nbo = nb; num_pb++; if ( num_pb > 1 ) { which_read = 6; nbb = fread( &buf[nb], sizeof( char), size_data, stdin); /* read in next pointing block */ count_byte_read += nbb; if ( nbb <= 0 ) break; if ( nbb != size_data ) { /* read error */ fprintf( stderr,"read error %d %d\ncount_rec %d, count_byte %d, 0x%x, %d bytes read, %d bytes expected\nbytes read %d, 0x%x\n", count_rec, count_byte, count_byte, nb, size_data, count_byte_read, count_byte_read); break_num[5]++; break; } pt_int = ( int * ) &buf[nb]; nb += nbb; if ( nbb < size_data ) { nbooo = nboo; nboo = nbo; nbo = nb; which_read = 7; nbb = fread( &buf[nb], sizeof( char), size_data - nbb, stdin); /* */ count_byte_read += nbb; if ( nbb <= 0 ) break; nb += nbb; fprintf( stderr, "After block %d, byte count %d, 0x%x\n", count_rec, count_byte, count_byte); fprintf( stderr," WRONG SIZE READ \n"); fprintf( stderr," last good time was NAV %d %d %d %d %d POINT %d %d %d %d %d\n", iNy,iNd, iNh, iNm, iNs, iPy, iPd, iPh, iPm, iPs); } } pt_int = ( int * ) &buf[ nb - size_data ]; /* check time */ /* fprintf( stderr," extra pointing block after block %d, %d, 0x%x, num_pb %d, nb 0x%x, 0x%x, 0x%x\n", count_rec, count_byte, count_byte, num_pb, nb, nbo, nboo); fprintf( stderr," last good time was NAV %d %d %d %d %d POINT %d %d %d %d %d\n", iNy,iNd, iNh, iNm, iNs, iPy, iPd, iPh, iPm, iPs); fprintf( stderr," this time NAV %d %d %d %d %d POINT %d %d %d %d %d\n", iny,ind, inh, inm, ins, ipy, ipd, iph, ipm, ips); */ if ( ( *(pt_int + 0) < 1977 || *(pt_int + 0) > 2030 ) || ( *(pt_int + 1) < 0 || *(pt_int + 1) > 366 ) || ( *(pt_int + 2) >= 24 || *(pt_int + 2) < 0 ) || ( *(pt_int + 3) < 0 || *(pt_int + 3) >= 60 ) || ( *(pt_int + 4) < 0 || *(pt_int + 4) >= 60 )) { /* failed time test on pointing block */ if ( *(pt_int + 0) == 0 && *(pt_int + 1) == 0 && *(pt_int + 2) == 0 && *(pt_int + 3) == 0 && *(pt_int + 4) == 0 ) { /* assume a blank block & skip */ nb -= size_data; num_pb--; fprintf( stderr, "zero block num_pb %d, count_byte_read %d, 0x%x\n", num_pb, count_byte_read, count_byte_read); break_num[6]++; break; } fprintf( stderr," bad pointing time %d %d %d %d %d, at block %d, byte %d, 0x%x, num_pb %d, nb, %d, nbo %d, nboo %d, nbooo %d, nbb %d, bytes read %d, 0x%x\n", *(pt_int + 0), *(pt_int + 1), *(pt_int + 2), *(pt_int + 3), *(pt_int + 4), count_rec, count_b yte, count_byte, num_pb, nb, nbo, nboo, nbooo, nbb, count_byte_read, count_byte_read ); fprintf( stderr," last good time was NAV %d %d %d %d %d POINT %d %d %d %d %d\n", iNy,iNd, iNh, iNm, iNs, iPy, iPd, iPh, iPm, iPs); fprintf( stderr,"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", *(pt_int + 0), *(pt_int + 1), *(pt_int + 2), *(pt_int + 3), *(pt_int + 4), *(pt_int + 5), *(pt_int + 6), *(pt_int + 7)); pt_int += 8; fprintf( stderr,"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", *(pt_int + 0), *(pt_int + 1), *(pt_int + 2), *(pt_int + 3), *(pt_int + 4), *(pt_int + 5), *(pt_int + 6), *(pt_int + 7)); pt_int += 8; fprintf( stderr,"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", *(pt_int + 0), *(pt_int + 1), *(pt_int + 2), *(pt_int + 3), *(pt_int + 4), *(pt_int + 5), *(pt_int + 6), *(pt_int + 7)); nb -= size_data; num_pb--; break_num[7]++; break; /* exit( 13); */ } if ( ( *(pt_int + 6) < 3000 && *(pt_int + 6) > 3000 ) || ( *(pt_int + 7) < 3000 && *(pt_int + 7) > 3000 ) ) { /* not really a nav block */ fprintf( stderr," not a nav block 0x%x, 0x%x\n", *(pt_int + 6), *(pt_int + 7)); exit( 14); } pt_int = ( int * ) &buf[ nb - size_data ]; /* check time */ iPy = ipy; iPd = ipd; iPh = iph; iPm = ipm; iPs = ips; ipy = *(pt_int + 0); ipd = *(pt_int + 1); iph = *(pt_int + 2); ipm = *(pt_int + 3); ips = *(pt_int + 4); } which_read += 1000; } which_read = -which_read; if ( num_pb <= 0 && lheader == 0 ) { /* skipped zero record */ num_skip++; break_num[14]++; continue; } count_rec++; if ( num_pb > 1 ) { /* a hack to keep the number of pointing blocks to 1 */ nb -= (num_pb - 1)*size_data; buf[nb - size_data*num_pb + 400] = 0; /* mark for no following pointing blocks */ } count_byte += nb; if ( nb > 0 ) { nbyte = fwrite( &nb, sizeof( char), 4, stdout); nbyte = fwrite( buf, sizeof( char), nb, stdout); nbyte = fwrite( &nb, sizeof( char), 4, stdout); skip_num[num_skip]++; if ( num_skip > MIN_SKIP ) { fprintf( stderr, "%d records skiped. %d\n navigation times %d %d %d %d %d to %d %d %d %d %d\n Pointing times %d %d %d %d %d to %d %d %d %d %d\n", num_skip, num_skip_o, iNy, iNd, iNh, iNm, iNs, iny, ind, inh, inm, ins,iPy, iPd, iPh, iPm, iPs, ipy, ipd, iph, ipm, ips); } num_skip_o = num_skip; num_skip = 0; } nbyte = nb; } fprintf( stderr,"\n ending with nb %d, nbo %d, nboo %d, nbooo %d, nbb %d, which_read %d\n", nb, nbo, nboo, nbooo, nbb, which_read); fprintf( stderr,"conv_sedr ended with %d blocks, and %d bytes, %d bytes read\n", count_rec, count_byte, count_byte_read); fprintf( stderr,"ending time NAV %d %d %d %d %d POINT %d %d %d %d %d\n", iny,ind, inh, inm, ins, ipy, ipd, iph, ipm, ips); fprintf( stderr,"\n"); for ( i=0 ; i < 20 ; i++ ) fprintf( stderr," %d",break_num[i]); fprintf( stderr,"\n\nSKIP HISTRORY\n"); for ( i=0 ; i <= MAX_SKIP ; i++ ) { if ( skip_num[i] > 0 ) fprintf( stderr,"%d recorde skipped %d times\n", i, skip_num[i]); } nb = 0; nbyte = fwrite( &nb, sizeof( char), 4, stdout); nbyte = fwrite( &nb, sizeof( char), 4, stdout); nbyte = fwrite( &nb, sizeof( char), 4, stdout); nbyte = fwrite( &nb, sizeof( char), 4, stdout); }