/* Thu Dec 16 13:17:58 EST 1993 /plas5/h1/ksg/src/test readxxx.c */ /* Tues Jan 18 1994 gsg jr. changed time to seconde & corrected leap year */ /* Sun Jan 23 1994 gsg jr. corrected for sedr size & varying record size */ /* Mon Oct 23 1995 gsg jr. array of output buffers added. allows backspacing & insert */ /* Fri Jan 14 2000 cw/laf. corrected for two-digit year bug. If the year plus 1900 still less than 1970, we add 100 to the year. */ #include #include #include #include #define MAX_FILES 100 #define MAX_NUM_BUF 4 static int isleep=1; static char *buf[ MAX_FILES]; /* pointer to buffers*/ static char *fn[ MAX_FILES] = { "ft00", "ft01", "ft02", "ft03", "ft04", "ft05", "ft06", "ft07", "ft08", "ft09", "ft10", "ft11", "ft12", "ft13", "ft14", "ft15", "ft16", "ft17", "ft18", "ft19", "ft20", "ft21", "ft22", "ft23", "ft24", "ft25", "ft26", "ft27", "ft28", "ft29", "ft30", "ft31", "ft32", "ft33", "ft34", "ft35", "ft36", "ft37", "ft38", "ft39", "ft40", "ft41", "ft42", "ft43", "ft44", "ft45", "ft46", "ft47", "ft48", "ft49", "ft50", "ft51", "ft52", "ft53", "ft54", "ft55", "ft56", "ft57", "ft58", "ft59", "ft60", "ft61", "ft62", "ft63", "ft64", "ft65", "ft66", "ft67", "ft68", "ft69", "ft70", "ft71", "ft72", "ft73", "ft74", "ft75", "ft76", "ft77", "ft78", "ft79", "ft80", "ft81", "ft82", "ft83", "ft84", "ft85", "ft86", "ft87", "ft88", "ft89", "ft90", "ft91", "ft92", "ft93", "ft94", "ft95", "ft96", "ft97", "ft98", "ft99", }; static int rec_size[ MAX_FILES]; /* number of bytes in this record */ #define NUM_TYPES 8 static char *types[ NUM_TYPES]= { "unknown", "ha", "spl", "vgr", "sum", "edr", "sedr", "shortsedr" }; static int type=0; static int size_type[ NUM_TYPES]= { 30000, 1000, 1000, 600, 2400, 2000, 1512, 316 }; static char *pt_type; static char name_type[]="TYPE"; static int irecords=0; /* counter of number of records read */ static int il=4; /* length of unit name */ static int rb[13]; /* bats count & error flags */ static int sc=-1; /* space craft if known */ /* not implimented yet */ extern struct comtype { int mod16; int mod60; int linecnt; int itlmod; }; extern struct comtype spclk_; static int mod16, mod60, linecnt, itlmod; /* Spacecraft clock */ static int mit_data_type, mit_data_mode; /* mit data type & transmission mode */ static int gsfc_data_type, gsfc_data_mode; /* gsfc data type & transmission mode */ static char *gsfc_data_type_array_ch[] = { " ", " LFM", " HFM", " M", " E1", " L", " E2", " ENG", "HDR1", "HDR3", " ", " ", " "}; static int gsfc_data_type_array[] = { 00, -3, 22, 2, 3, 1, 4, -1, 9, 10, 11, 1111, 1212}; static char *gsfc_data_mode_array_ch[]= { "GS-3", "CR-1", "CR-2", "CR-3", "CR-4", "CR5A", "CR6A", "CR6B", "CR-7", "CR5B", " ", " ", " "}; static int gsfc_data_mode_array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; static int iy, id, ih, im, is, ims; static int ly; static int it1a[3], it2a[3]; static double tt1a[MAX_FILES], tt2a[MAX_FILES]; static char *pt_type_name; static char str[128], *pt_str; static int iunitn; char* typexxx(); void dtotime_(); static double time_bad=((((1970-1990)*365.0)*24.0)*60.0)*60.0; /* time to return if bad/no data */ void readxxx_( iunit, time, ieof) int *iunit; /* unit number, used as index into arrays */ double *time; /* time of this record's data" */ int *ieof; /* 0 for normar read */ { int i; /* indicies */ int rcount; /* max number of bytes to be read */ int num_eof; /* number of consecutive eof. two mark eod */ int ivar; int irecid, isc; int iloop; char *pt_file; unsigned char *pt_char; unsigned short *pt_short; int *pt_int; int ncur; int idata_len; if ( *iunit < 0 ) goto ttt; /* just want time from preset */ mod16 = 0; mod60 = 0; linecnt = 0; itlmod = -10; if ( type <= 0 ) { /* does environmental variable "TYPE" have type? */ pt_type = getenv( name_type ); if ( pt_type != NULL ) { for ( i=0 ; i < NUM_TYPES ; i++ ) { if ( ! strcmp( pt_type, types[i]) ) { type = i; break; } } } } if ( buf[ *iunit] == NULL ) { /* is buffer allocated? */ pt_file = getenv( fn[ *iunit] ); if ( pt_file == NULL ) { /* no file specified */ *ieof = 1; return; } dtotime_( pt_file); ly = (it1a[0] - 1969)/4; tt1a[*iunit] = (((( it1a[0] - 1990)*365.0e+0 + ly + it1a[1])*24.0e+0 + it1a[2])*60)*60.0; ly = (it2a[0] - 1969)/4; tt2a[*iunit] = (((( it2a[0] - 1990)*365.0e+0 + ly + it2a[1])*24.0e+0 + it2a[2])*60)*60.0; buf[ *iunit] = malloc( size_type[ type] ); if ( buf[ *iunit] == NULL ) { fprintf( stderr, " unable to allocate for unit %d \n", *iunit); exit( 2); } } rcount = size_type[ type]; num_eof = 0; rb[0] = 1; /* an number < 80 to start loop but accept electron mission tapes */ iloop = 0; type_test: while ( ! ((rb[0] > 80) || (rb[0] == 28 ) || (rb[0] == 32 ) ) ) { /* we qre not going to deal with labels and other short records */ iloop++; /* sleep ( isleep); */ iunitn = *iunit; treadbat_( fn[ *iunit], buf[ *iunit], &rcount, il); twait_( fn[ *iunit], rb, il); /* pt_str = &str[0]; pt_str = getenv( fn[ *iunit]); fprintf( stderr,"iunit %d, %s \n %s\n", iunit, fn[ *iunit], pt_str); */ if ( rb[0] <= 0 ) { num_eof++; *ieof = 1; } else { *ieof = 0; } if ( num_eof >= 2 ) break; /* end of data */ } rec_size[ *iunit] = rb[0]; pt_char = ( unsigned char *) buf[ *iunit]; pt_short = ( unsigned short * ) buf[ *iunit]; pt_int = ( int * ) buf[ *iunit]; /* to compute time, we must know type */ if ( type <= 0 ) { /* if we do not know it yet, let try to figure it out */ pt_type_name = typexxx( buf[ *iunit]); if ( type < 0 ) { /* could not be sure, test the next record */ pt_str = &str[0]; pt_str = getenv( fn[ *iunit]); fprintf( stderr,"type %d, %s \n %s\n", type, fn[ *iunit], pt_str); if ( iloop < 3 ) { goto type_test; } else { *ieof=1; return; } } buf[ *iunit] = realloc( buf[ *iunit], size_type[ type]); } switch ( type ) /* calculate time according to type of data */ { case 1: /* we have an hourly average or spectral */ iy = *(pt_int + 7); id = *(pt_int + 8); ih = *(pt_int + 9); ih = ( ( ih < 0 ) ? -ih : ih) % 25; /* ih = mod( iabs( ih, 25) */ im = is = ims = 0; break; case 2: /* we have a spectral dataset */ iy = *(pt_short + 4); id = *(pt_short + 5); ih = *(pt_short + 6); im = *(pt_short + 7); is = *(pt_short + 8); ims = *(pt_short + 9); itlmod = *(pt_short + 12); break; case 3: /* we have a vgr dataset */ iy = *(pt_char + 0) + 1900; /*added by cw-laf */ if(iy < 1970) { iy = iy + 100; } id = *(pt_char + 1); ih = *(pt_char + 2); im = *(pt_char + 3); is = *(pt_char + 4); ims = *(pt_char + 5); if ( ih >= 100 ) { ih -= 100; id += 256; } if ( ih >= 25 ) { ih -= 25; } ims *= 4; itlmod = *(pt_char + 10); ncur = *(pt_char + 9); idata_len = 12 + ncur*4; if ( itlmod == 1 || itlmod == 2 ) idata_len += 48; if ( idata_len < rec_size[ *iunit] ) { /* we have sc clock */ mod16 = *(pt_short + idata_len/2 ); mod60 = *(pt_char + idata_len + 2); linecnt = *(pt_char + idata_len + 3) << 8; } else { mod16 = -1; mod60 = -1; linecnt = -1; } break; case 4: /* summary */ /* we must convert to ebdic */ /* we should also check word 11 time type */ iy = *(pt_short + 6); if ( iy < 1900 ) { /* always true */ iy = iy + 1900; } /*added by cw-laf */ if (iy < 1970) { iy = iy + 100; } id = *(pt_short + 7); ih = *(pt_short + 8); im = *(pt_short + 9); is = *(pt_short + 10); ims = *(pt_short + 11); mod16 = *(pt_short + 24); mod60 = *(pt_short + 25); linecnt = *(pt_short + 26); gsfc_data_type = *(pt_short + 32); gsfc_data_mode = *(pt_short + 33); if ( gsfc_data_type > 0 && gsfc_data_type < 12 ) { mit_data_type = gsfc_data_type_array[ gsfc_data_type]; } else { mit_data_type = -10; } if ( gsfc_data_mode > 0 && gsfc_data_mode < 12 ) { mit_data_mode = gsfc_data_mode_array[ gsfc_data_mode]; } else { mit_data_mode = -10; } itlmod = mit_data_type; break; case 5: /* edr */ ivar = *(pt_char + 3); isc = ivar % 16; irecid = ivar / 16; if ( irecid == 11 || irecid == 15 ) { /* eng or decom record */ iy = id = ih = im = is = ims = 0; *time = time_bad; itlmod = -1; return; } else { /* science record */ iy = *(pt_char + 30); ih = *(pt_short + 12); is = *(pt_short + 13); ims = *(pt_short + 14); /*iy = ( iy < 1900 ) ? 1900 + iy : iy;*/ if (iy < 1900) { iy = iy + 1900; } /*added by cw-laf */ if (iy < 1970){ iy = iy + 100; } id = ih/24; ih = ih - id*24; im = is/60; is = is - im*60; itlmod = 2; } mod16 = *(pt_short + 16); mod60 = *(pt_char + 34); linecnt = *(pt_char + 35); linecnt = linecnt << 8 + *(pt_char + 36); mit_data_type = 13; mit_data_mode = -10; break; case 6: /* sedr */ if ( rb[0] == 180 ) { /* header no time */ iy = id = ih = im = is = ims = 0; } else { iy = *(pt_int + 0); id = *(pt_int + 1); ih = *(pt_int + 2); im = *(pt_int + 3); is = *(pt_int + 4); ims = *(pt_int + 5); } itlmod = -5; break; case 7: /* short sedr */ iy = *(pt_int + 62); /* using pointing blocks */ id = *(pt_int + 63); ih = *(pt_int + 64); im = *(pt_int + 65); is = *(pt_int + 66); ims = *(pt_int + 67); iy = *(pt_int + 0); /* using nav blocks */ id = *(pt_int + 1); ih = *(pt_int + 2); im = *(pt_int + 3); is = *(pt_int + 4); ims = *(pt_int + 5); itlmod = -5; break; default: fprintf( stderr,"wrong type of data %d\n", type); exit(4); } ttt: ; /* label for returning time only */ if ( *iunit == -2 ) { /* return earlyest acceptable time in file */ if ( it1a[0] == 0 ) return; iy = it1a[0]; id = it1a[1]; ih = it1a[2]; im = is = ims = 0; } else if ( *iunit == -3 ) { /* return latest acceptable time in file */ if ( it2a[0] == 0 ) return; iy = it2a[0]; id = it2a[1]; ih = it2a[2]; im = is = ims = 0; } else if ( *iunit == -9 ) { /* store time to return for invalid data */ time_bad = *time; } ly = (iy - 1969)/4; *time = (((( iy - 1990)*365.0e+0 + ly + id)*24.0e+0 + ih)*60 + im)*60.0 + is + ims/1.0e+3; /* *time = ( iy - 1970)*10000.e+0 + iy*100.e+0 + ih + im/100. + is/10000. */ if ( rb[0] <= 0 ) *ieof = 1; else *ieof = 0; if ( (*iunit >= 0) && ( *ieof == 0) ) { if ( *time < tt1a[*iunit] || *time > tt2a[*iunit]) { rb[0] = 80; /* treat an out of time record as a label */ goto type_test; } } spclk_.itlmod = itlmod; spclk_.mod16 = mod16; spclk_.mod60 = mod60; spclk_.linecnt = linecnt; return; } void timexx_( iunit, iyy, idd, ihh, imm, iss, imss, imod16, imod60, ilinc, iitlmod) int *iunit; int *iyy; int *idd; int *ihh; int *imm; int *iss; int *imss; int *imod16; int *imod60; int *ilinc; int *iitlmod; { /* if iunit > 0 read time, if iunit < 0 set time */ if ( *iunit > 0 ) { iy = *iyy; id = *idd; ih = *ihh; im = *imm; is = *iss ; ims = *imss; mod16 = *imod16; mod60 = *imod60; linecnt = *ilinc; itlmod = *iitlmod; } else if ( *iunit < 0) { *iyy = iy; *idd = id; *ihh = ih; *imm = im; *iss = is ; *imss = ims; *imod16 = mod16; *imod60 = mod60; *ilinc = linecnt; *iitlmod = itlmod; } } void timexxx_( iunit, iyy, idd, ihh, imm, iss, imss) int *iunit; int *iyy; int *idd; int *ihh; int *imm; int *iss; int *imss; { /* if iunit > 0 read time, if iunit < 0 set time */ if ( *iunit > 0 ) { iy = *iyy; id = *idd; ih = *ihh; im = *imm; is = *iss ; ims = *imss; } else if ( *iunit < 0) { *iyy = iy; *idd = id; *ihh = ih; *imm = im; *iss = is ; *imss = ims; } } static int ounit=10; static int num_in=0; /* number of records put into i/o buffer */ static int num_out=0; /* number 0f records written out of buffer */ static char *pt_buf; /* pointer it an output buffer */ static char **pt_bufa; /* array of pointers to output buffers */ static int *pt_size; /* pointer to current size of record */ static int *sizea; /* size array */ static int num_buf=0; /* size of buffer */ void writexxx_( iunit) int *iunit; /* unit number, used as index into arrays */ { int i; /* indicies */ int n; /* index into buffer array */ int rcount; /* max number of bytes to be read */ int rb[13]; /* bats count& error flags */ int rc; rcount = rec_size[ *iunit]; if ( *iunit <= 0 ) { teom_( fn[ ounit], il); } else { if ( num_buf == 0 ) { num_buf = MAX_NUM_BUF; sizea = ( int * ) malloc( MAX_NUM_BUF*sizeof( int)); if ( sizea == NULL ) { fprintf( stderr,"unable to allocate sizea\n"); exit(1); } pt_bufa = ( char ** ) malloc( MAX_NUM_BUF*sizeof( pt_buf)); if ( pt_bufa == NULL ) { fprintf( stderr,"unable to allocate pt_bufa\n"); exit(1); } for ( i=0 ; i < num_buf ; i++ ) { *( pt_bufa + i ) = malloc( size_type[ type] ); if ( *( pt_bufa + i ) == NULL ) { fprintf( stderr, "unable to allocate buffer number %d \n", i); exit(1); } sizea[ i] = 0; } } n = num_out % num_buf; pt_buf = pt_bufa[ n]; rc = sizea[ n]; if ( num_in - num_out == num_buf ) /* buffer array full */ { /* twritebat_( fn[ ounit], buf[ *iunit], &rcount, il); */ twritebat_( fn[ ounit], pt_buf, &rc, il); num_out++; } n = num_in % num_buf; sizea[ n] = rec_size[ *iunit]; pt_buf = pt_bufa[ n]; pt_bufa[ n] = buf[ *iunit]; buf[ *iunit] = pt_buf; num_in++; } twait_( fn[ ounit], rb, il); } void bsxxx_() { num_in--; if ( num_in < num_out ) { fprintf( stderr," back spaced too many times\n"); exit(1); } } void insertxxx_( iunit) int *iunit; /* unit number, used as index into arrays */ { int n, n1; int rc; if ( num_in > num_out + num_buf ) { fprintf( stderr,"error on insett %d %d\n", num_in, num_out); exit(1); } while ( num_in >= num_out + num_buf ) { n = num_out % num_buf; pt_buf = pt_bufa[ n]; rc = sizea[ n]; twritebat_( fn[ ounit], pt_buf, &rc, il); num_out++; } n = num_in % num_buf; num_in++; n1 = num_in % num_buf; sizea[ n1] = sizea[ n]; *pt_bufa[ n1] = *pt_bufa[ n]; sizea[ n] = rec_size[ *iunit]; pt_bufa[ n] = buf[ *iunit]; buf[ *iunit] = pt_buf; } void closexxx_() { int i, n; int rc; for ( i=num_out ; i < num_in ; i++ ) { n = i % num_buf; pt_buf = pt_bufa[ n]; rc = sizea[ n]; twritebat_( fn[ ounit], pt_buf, &rc, il); twait_( fn[ ounit], rb, il); } twait_( fn[ ounit], rb, il); } char* typexxx( buf) char *buf; { unsigned char *pt_char; short *pt_short; int *pt_int; pt_char = ( unsigned char *) buf; pt_short = ( short * ) buf; pt_int = ( int * ) buf; /* first check for sumary */ if ( *(pt_char + 8) == 0xc6 && *(pt_char + 9) == 0xd3 && *(pt_char + 10 ) == 0xe3 ) /* ebdic for flt */ { #ifdef NOT if ( ! ( *(pt_char + 40) == 0xe2 && *(pt_char + 41) == 0xc3 && *(pt_char + 42 ) == 0xc5 && *(pt_char + 43) == 0xe3 ) ) /* scet */ { /* reject not scet */ fprintf( stderr," not SCET sumary tape \n"); exit(3); } #endif type = 4; /* summary */ /* we must convert to ebdic */ /* we shoul also check word 11 time type */ } else if ( rb[0] == 180 && *(pt_char + 0) == 'V' && *(pt_char + 1) == 'G' && *(pt_char + 2) == 'R' && *(pt_char + 3) == ' ' && *(pt_char + 4) == 'S' && *(pt_char + 5) == 'E' && *(pt_char + 6) == 'D' && *(pt_char + 7) == 'R' ) { /* first two words are "VGR SEDR", so we have a header block */ type = 6; } else if ( rb[0] == 180 && *(pt_char + 0) == 0xe5 && *(pt_char + 1) == 0xc7 && *(pt_char + 2) == 0xd9 && *(pt_char + 3) == 0x40 && *(pt_char + 4) == 0xe2 && *(pt_char + 5) == 0xc5 && *(pt_char + 6) == 0xc4 && *(pt_char + 7) == 0xd9 ) { /* first two words are "VGR SEDR", so we have a header block */ type = 6; } else if ( rb[0] % 504 == 0 && ( *(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 ) { /* we have a sedr data block */ type = 6; } else if ( *pt_int == ((rb[0]/4) - 1) ) { /* we have an hourly average or spectral */ if ( *(pt_char + 24) == 'V' && *(pt_char + 25) == 'O' && *(pt_char + 26 ) == 'Y' && ( *(pt_char + 27 ) == '1' || ( *(pt_char + 27 ) == '2')) ) { /* we have a ha dataset */ type = 1; } else if ( *(pt_int + 1) == 0 ) /* shour be sc id but it is not */ /* have to check on length, remember both long & short */ { /* we have a spectral dataset */ type = 2; } else { /* does not agree with either a spectral or vgr format */ fprintf( stderr," unable to identify data type not a ha or spl tape \n"); type=-10; /* exit(3); */ return '\0'; } } else if ( *(pt_char + 0 ) >= 77 && *(pt_char + 0 ) <= 123 && *(pt_char + 10 ) <= 4 && *(pt_char + 11 ) <= 3 ) /* check year , itlmod & jclk */ { /* we have a vgr dataset */ if ( (*(pt_char + 9) + 15)*4 == rb[0] ) /* check length */ { type = 3; } else if ( (*(pt_char + 9) + 16)*4 == rb[0] ) /* ans array may be one long */ { type = 3; } else if ( (*(pt_char + 9) + 3)*4 == rb[0] ) /* electron do not have ans */ { type = 3; } else if ( (*(pt_char + 9) + 4)*4 == rb[0] ) /* electron do not have ans */ { type = 3; } else { /* do not know what it is */ fprintf( stderr,"wrong length for vgr tape\n"); exit(3); } } else if ( *(pt_char + 0 ) == 0xd4 && *(pt_char + 0 ) == 0xd4 &&*(pt_char + 0 ) == 0xd4 ) { /* we have an edr */ type = 5; } else if ( rb[0] == 180 ) { /* guess that we have a sedr header record. read next to check */ type = -6; return '\0'; } else if ( ( rb[0] == 316 ) && ( *(pt_int + 0 ) >= 1977 ) && ( *(pt_int + 0 ) <= 2030 ) && /* nav block */ ( *(pt_int + 62) >= 1977 ) && (:q! *(pt_int + 62) <= 2030 ) && /* pointing block */ ( *(pt_int + 1 ) >= 1 ) && ( *(pt_int + 1 ) <= 366 ) && /* nav block */ ( *(pt_int + 63) >= 1 ) && ( *(pt_int + 63) <= 366 ) && /* pointing block */ ( *(pt_int + 2 ) >= 0 ) && ( *(pt_int + 2 ) <= 23 ) && /* nav block */ ( *(pt_int + 64) >= 0 ) && ( *(pt_int + 64) <= 23 ) && /* pointing block */ ( *(pt_int + 3 ) >= 0 ) && ( *(pt_int + 3 ) <= 59 ) && /* nav block */ ( *(pt_int + 65) >= 0 ) && ( *(pt_int + 65) <= 59 ) && /* pointing block */ ( *(pt_int + 4 ) >= 0 ) && ( *(pt_int + 4 ) <= 59 ) && /* nav block */ ( *(pt_int + 66) >= 0 ) && ( *(pt_int + 66) <= 59 ) && /* pointing block */ ( *(pt_int + 5 ) >= 0 ) && ( *(pt_int + 5 ) <= 999 ) && /* nav block */ ( *(pt_int + 67) >= 0 ) && ( *(pt_int + 67) <= 999 ) ) /* pointing block */ { /* looks like a short sedr */ type = 7; } else { /* do not know what it is */ fprintf( stderr," unable to identify data type \n"); pt_str = &str[0]; pt_str = getenv( fn[ iunitn]); fprintf( stderr,"iunit %d, %s \n %s\n", &iunitn, fn[ iunitn], pt_str); type = -11; /* exit(3); */ return '\0'; } spclk_.itlmod = itlmod; spclk_.mod16 = mod16; spclk_.mod60 = mod60; spclk_.linecnt = linecnt; return types[ type]; } void print_type_( iunit) int *iunit; { void readxxx_(); double time; int ieof; readxxx_( iunit, &time, &ieof); fprintf( stdout,"%s\n", types[ type]); } void typexxx_( typ, il) char* typ; int il; { int i; for ( i=0 ; *(types[ type] + i) != 0 ; typ++, i++ ) *(typ) = *(types[ type] + i); for ( ; i < 8 ; typ++, i++ ) *(typ) = ' '; } /* get first & last time from file name */ void dtotime_( fn) char *fn; { char *pt_ch1, *pt_ch2; char ch[16]; char cc; int *i1, *i2; int ii; int len; len = strlen( fn) - 10; it1a[0] = it1a[1] = it1a[2] = 0; it2a[0] = it2a[1] = it2a[2] = 0; for ( pt_ch1 = fn + len ; pt_ch1 > fn ; pt_ch1-- ) { if ( *pt_ch1 == '_' ) { /* found last _, now get last time */ ch[1] = *(pt_ch1 + 1); ch[2] = *(pt_ch1 + 2); ch[3] = *(pt_ch1 + 3); ch[4] = *(pt_ch1 + 4); ch[5] = 0; ch[6] = *(pt_ch1 + 6); ch[7] = *(pt_ch1 + 7); ch[8] = *(pt_ch1 + 8); ch[9] = 0; ch[10] = *(pt_ch1 + 10); ch[11] = *(pt_ch1 + 11); ch[12] = 0; it2a[0] = atoi( &ch[1] ); it2a[1] = atoi( &ch[6] ); it2a[2] = atoi( &ch[10]) + 1; break; } } pt_ch2 = pt_ch1; for ( pt_ch1-- ; pt_ch1 > fn ; pt_ch1-- ) { if ( *pt_ch1 == '_' ) { /* found first _, now get first time */ ch[1] = *(pt_ch1 + 1); ch[2] = *(pt_ch1 + 2); ch[3] = *(pt_ch1 + 3); ch[4] = *(pt_ch1 + 4); ch[5] = 0; ch[6] = *(pt_ch1 + 6); ch[7] = *(pt_ch1 + 7); ch[8] = *(pt_ch1 + 8); ch[9] = 0; ch[10] = *(pt_ch1 + 10); ch[11] = *(pt_ch1 + 11); ch[12] = 0; it1a[0] = atoi( &ch[1] ); it1a[1] = atoi( &ch[6] ); it1a[2] = atoi( &ch[10]); break; } } if (( it1a[0] < 1970 || it1a[0] > 2030 ) || ( it2a[0] < 1970 || it2a[0] > 2030 ) || ( it1a[1] < 0 || it1a[1] > 366 ) || ( it2a[1] < 0 || it2a[1] > 366 ) || ( it1a[2] < 0 || it1a[2] > 24 ) || ( it2a[2] < 0 || it2a[2] > 24 )) { it1a[0] = it1a[1] = it1a[2] = 0; it2a[0] = it2a[1] = it2a[2] = 0; it1a[0] = 1970; it2a[0] = 2030; } if ( (pt_ch2 - pt_ch1) != 12 ) { it1a[0] = it1a[1] = it1a[2] = 0; it2a[0] = it2a[1] = it2a[2] = 0; it1a[0] = 1970; it2a[0] = 2030; } }