/****************************************************************************** * * cnv_swath.c * * Program outputs binary swath data in an output tabular ascii format * * LAST UPDATE: 14 April 1998 * * ARGUMENTS: * None. Prompts user for variables. * * FUNCTIONS CALLED: * allocdata Allocates space for one-scanline std_data structure * read_hdr Reads 1000-byte header * read_scan Reads one scanline into std_data * * ORIGINAL AUTHOR: * Don Anderson, CIRES/CDC, November 1997 * * NOTES: * (1) Assumes data are in standard CDC Climate Satellite Group data format, * including 1000 bytes of header information. * (2) Works with single OR dual-resolution dataset. * (3) When extracting data, scale and offset are applied as follows: * 1. First subtract the offset from the data ; * 2. Then divide the value by the scale factor. * (5) Don't forget to watch out for missing data values (== hdr.missing_val) * ******************************************************************************/ #include #include #include #include /** Define structures **/ struct describe_text { char text[40] ; /* Description of data field */ } ; struct std_hdr { char filename[80] ; /* Name of file */ char sensor[20] ; /* Name of sensor */ short fields ; /* Number of (lo-res) fields */ short pixperscan ; /* Pixels per (lo-res) scanline */ short hifields ; /* Number of hi-res fields */ short hipixperscan ; /* Number of hi-res pixels per scan */ short missing_val ; /* Value for missing data */ short *scale ; /* Scaling factor for each field */ short *offset ; /* Offset value for each field */ struct describe_text *description ; /* Description for each field */ } ; struct std_data { long *itime ; /* Time in seconds since 1-1-1970 */ float *lat ; /* Decimal degs latitude scaled by 100 */ float *lng ; /* Decimal degs longitude scaled by 100 */ float **fielddata ; /* Data, dimensions [fields][pixels] */ } ; /** Function prototypes **/ int allocdata ( struct std_data *, short, short ) ; int read_hdr ( FILE *, struct std_hdr * ) ; int read_scan ( FILE *, struct std_hdr, struct std_data *, struct std_data *, struct std_data * ) ; /** Main program **/ void main ( ) { int error_flag ; /* Error flag */ int fieldno ; /* Data field number */ int pixno ; /* Data pixel number */ char istr[10] ; /* Integer string */ int i ; /* Generic counter */ int j ; /* Generic counter */ FILE *infile ; /* Pointer to input file */ char infile_str[160] ; /* Name of input file */ int nscan ; /* Scan line counter */ int nfiles=0 ; /* number of input data files */ int res=0 ; /* Flag for high or low res output */ float mis_val ; /* Missing value */ FILE *outfile ; /* Pointer to output file */ char outfile_str[160] ; /* Name of output file */ int pix ; /* Pixel counter */ int nfield ; /* Number of the field to output */ char pstr[10] ; /* Pixel number string */ int returnval ; /* Value returned from function call */ int scanno ; /* Number of scans to print */ char date_str[9] ; /* Date string (MM-DD-YY) */ char time_str[9] ; /* Time string (HH:MM:SS) */ char format[10][20] ; /* Output format string */ struct std_hdr hdr ; /* Header data */ struct std_data datalo ; /* (Low-res) field data */ struct std_data datahiA ; /* High-res field data A-scan */ struct std_data datahiB ; /* High-res field data B-scan */ strcpy ( outfile_str, "junk.out" ) ; error_flag = 0 ; /** Get name of input file **/ printf ( "\n Enter the input file name: " ) ; gets ( infile_str ) ; if ( infile_str[0] == '\0' ) exit (1) ; while ( ( infile = fopen ( infile_str, "r" ) ) == NULL ) { printf (" Unable to open input file, please try again!\n") ; printf (" Please enter the input file name: ") ; gets ( infile_str ) ; } /** Specify the data field, scanlines, and pixels to retreive **/ printf ("\n Enter number of scanlines to print (default = all): "); gets ( istr ) ; scanno = atoi ( istr ) ; if ( scanno < 0 || istr[0] == '\0' ) scanno = 10000000 ; printf ("\n Enter an output ASCII datafile name (or return to echo results to screen):" ); gets ( outfile_str ) ; if ( outfile_str[0] == '\0' ) outfile = stdout ; else while ( ( outfile = fopen ( outfile_str, "w" ) ) == NULL ) { printf (" Unable to open output file, please try again! " ) ; printf (" Enter the output file name: " ) ; gets ( outfile_str ) ; } printf ("\n" ) ; /** Read and echo the header data **/ while ( ( returnval = read_hdr ( infile, &hdr ) ) == 0 ) { if ( returnval < 0 ) { fprintf ( stderr, " Error %d reading header -- exiting\n", returnval ) ; exit (1) ; } nfiles = nfiles + 1 ; printf ( "Datafile name: %s\n", hdr.filename ) ; printf ( "Sensor: %s\n\n", hdr.sensor ) ; if (hdr.hifields > 0) { printf ( "Missing value: %5d\n", hdr.missing_val ) ; printf ( "Number of low-resolution fields: %5d\n", hdr.fields ) ; printf ( "Number of pixels per low-res scan: %5d\n", hdr.pixperscan ) ; printf ( "Number of hi-resolution fields: %5d\n", hdr.hifields ) ; printf ( "Number of pixels per high-res scan: %5d\n\n", hdr.hipixperscan ) ; } else { printf ( "Missing value: %5d\n", hdr.missing_val ) ; printf ( "Number of fields: %5d\n", hdr.fields ) ; printf ( "Number of pixels per scan: %5d\n\n", hdr.pixperscan ) ; } if (hdr.hifields > 0 ) { printf ( " Field Res Scale Offset Description\n" ) ; printf ( " ----- --- ----- ------ -----------\n" ) ; } else { printf ( " Field Scale Offset Description\n" ) ; printf ( " ----- ----- ------ -----------\n" ) ; } for ( i=0; i < hdr.fields ; i++) { if ( hdr.hifields > 0 ) printf ( " %5d LOW %7d %5d %s\n", i+1, hdr.scale[i], hdr.offset[i], hdr.description[i] ) ; else printf ( " %5d %7d %5d %s\n", i+1, hdr.scale[i], hdr.offset[i], hdr.description[i] ) ; sprintf(format[i],"%%7.%1df",(int) log10(hdr.scale[i])); } for ( j=i; j < hdr.fields + hdr.hifields ; j++) { printf ( " %5d HIGH %7d %5d %s\n", j+1, hdr.scale[j], hdr.offset[j], hdr.description[j] ) ; sprintf(format[j],"%%7.%1df",(int) log10(hdr.scale[j])); } mis_val = ( float ) hdr.missing_val ; printf ("\n Enter the number of the field to output: "); gets ( istr ) ; nfield = atoi ( istr ) ; if (nfield > hdr.fields) res = 1; else res = 0; /** Allocate arrays to hold one scanline data **/ if ( nfiles == 1 ) { if ( allocdata ( &datalo, hdr.pixperscan, hdr.fields ) < 0 ) { error_flag = -1 ; goto outta_here ; } if ( allocdata ( &datahiA, hdr.hipixperscan, hdr.hifields ) < 0 ) { error_flag = -1 ; goto outta_here ; } if ( allocdata ( &datahiB, hdr.hipixperscan, hdr.hifields ) < 0 ) { error_flag = -1 ; goto outta_here ; } } /** Skip past 1000-byte header and read data into structures **/ nscan = 1 ; while ( returnval != 999 && nscan < scanno + 1 ) { returnval = read_scan ( infile, hdr, &datalo, &datahiA, &datahiB ) ; if ( returnval < 0 ) fprintf ( stderr, "Error %d invoking read_scan\n", returnval ) ; else if ( returnval == 999 ) { fprintf ( stderr, "All scanlines read\n" ) ; break ; } else { /****************************************************************************/ /**------------------------ Begin Data Output section ---------------------**/ /** **/ /** Notes: **/ /** **/ /** 1) Check for missing values! (== hdr.missing_val) **/ /** 2) Time values are stored for each pixel, however, they do not **/ /** change within a given scan line for any of the DMSP data. **/ /** 3) The high-resolution data applies only to the 85 GHz data from **/ /** SSM/I. **/ /****************************************************************************/ /** Output low-resolution data **/ if ( res == 0 ) { /** Output scan-line information **/ date ( date_str, time_str, datalo.itime[0], 70 ) ; /** Output data **/ for ( pix = 0 ; pix < hdr.pixperscan ; pix++ ) { fprintf(outfile," %6.2f %7.2f",datalo.lat[pix],datalo.lng[pix]); for ( fieldno = nfield-1 ; fieldno < nfield ; fieldno++ ) { if ( (int) datalo.fielddata[fieldno][pix] == hdr.missing_val ) fprintf ( outfile, "%7d", hdr.missing_val ) ; else if ( hdr.scale[fieldno] == 1 ) fprintf ( outfile, "%7d", (int) datalo.fielddata[fieldno][pix] ) ; else fprintf ( outfile, format[fieldno], datalo.fielddata[fieldno][pix] ) ; } fprintf ( outfile, "\n" ) ; } } /** Output high-resolution A-scan data **/ else { /** Output A scan information **/ date ( date_str, time_str, datahiA.itime[0], 70 ) ; /** Output data **/ for ( pix = 0 ; pix < hdr.hipixperscan ; pix++ ) { fprintf ( outfile, " %6.2f %7.2f", datahiA.lat[pix], datahiA.lng[pix] ) ; for ( fieldno = nfield-1 ; fieldno < nfield ; fieldno++ ) { if ( (int) datahiA.fielddata[fieldno][pix] == hdr.missing_val ) fprintf ( outfile, "%7d", hdr.missing_val ) ; else if ( hdr.scale[fieldno] == 1 ) fprintf ( outfile, "%7d", (int) datahiA.fielddata[fieldno][pix] ) ; else fprintf ( outfile, format[fieldno], datahiA.fielddata[fieldno][pix] ) ; } fprintf ( outfile, "\n" ) ; } /** Output high-resolution B-scan data **/ /** Output B scan information **/ date ( date_str, time_str, datahiB.itime[0], 70 ) ; for ( pix = 0 ; pix < hdr.hipixperscan ; pix++ ) { fprintf ( outfile, " %6.2f %7.2f", datahiB.lat[pix], datahiB.lng[pix] ) ; for ( fieldno = nfield-1 ; fieldno < nfield ; fieldno++ ) { if ( (int) datahiB.fielddata[fieldno][pix] == hdr.missing_val ) fprintf ( outfile, "%7d", hdr.missing_val ) ; else if ( hdr.scale[fieldno] == 1 ) fprintf ( outfile, "%7d", (int) datahiB.fielddata[fieldno][pix] ) ; else fprintf ( outfile, format[fieldno], datahiB.fielddata[fieldno][pix] ) ; } fprintf ( outfile, "\n" ) ; } } } nscan++ ; } } /****************************************************************************/ /**------------------------- End Data Output section ----------------------**/ /****************************************************************************/ /** Clean up and exit **/ outta_here : if ( infile != NULL ) fclose ( infile ) ; if ( outfile != NULL ) fclose ( outfile ) ; if ( error_flag < 0 ) printf ( "Error %d\n", error_flag ) ; return ; } /*------------------------ End of Main Program -----------------------------*/ /****************************************************************************** * * read_hdr * * Fills the passed std_hdr header structure with header data * read from the specified file. * * LAST UPDATE: 26 November 1997 * * ARGUMENTS: * * Name Type Description * ---- ---- ----------- * infile *FILE Opened input data file pointer * hdr *struct std_hdr Pointer to std_hdr structure * * ORIGINAL AUTHORS: * Don Anderson and Wesley Berg, CIRES/CDC, November 1997 * * RETURNS: 0 If successful * -1 If error allocating space * -2 If error returned from fread * * NOTES: * (1) The passed file descriptor ("infile") must be for a file which * has already been opened * (2) Binary read (fread) stops at the 1000th byte of the file * (end of header) * (3) Example of use: * To print the 0th field description from the calling routine, * printf ("Description of field 0 is %s\n", hdrstruct.description[0]); * ***************************************************************************/ int read_hdr ( FILE *infile, struct std_hdr *hdr ) { char buff[1000] ; /* Buffer for filler bytes */ int error_flag ; /* Error flag */ short fields ; /* Number of fields */ int i,n ; /* Generic counter */ error_flag = 0 ; if ((n=fread ( hdr->filename, 1, 80, infile )) != 80) { error_flag = -2 ; goto outta_here ; } fread ( hdr->sensor, 1, 20, infile ) ; fread ( &hdr->fields, 2, 1, infile ) ; fread ( &hdr->pixperscan, 2, 1, infile ) ; fread ( &hdr->hifields, 2, 1, infile ) ; fread ( &hdr->hipixperscan, 2, 1, infile ) ; fread ( &hdr->missing_val, 2, 1, infile ) ; fields = hdr->fields + hdr->hifields ; /** Allocate space for variable-length records **/ hdr->scale = ( short * ) malloc ( ( hdr->fields + hdr->hifields ) * sizeof ( short ) ) ; hdr->offset = ( short * ) malloc ( ( hdr->fields + hdr->hifields ) * sizeof ( short ) ) ; hdr->description = ( struct describe_text * ) malloc ( ( hdr->fields + hdr->hifields ) * sizeof ( struct describe_text ) ) ; if ( hdr->scale == NULL || hdr->offset == NULL || hdr->description == NULL ) { error_flag = -1 ; goto outta_here ; } for ( i = 0 ; i < ( hdr->fields + hdr->hifields ) ; i++ ) { fread ( &hdr->scale[i], 2, 1, infile ) ; fread ( &hdr->offset[i], 2, 1, infile ) ; fread ( &hdr->description[i], 40, 1, infile ) ; } /** Read past additional bytes to get to 1000 **/ if ( ! fread ( buff, 1000 - 110 - ( fields * 44 ), 1, infile ) ) error_flag = -2 ; outta_here : return ( error_flag ) ; } /****************************************************************************** * * read_scan * * Fills the passed structures with data read from the next scanline * (low res scan A and, if it exists, hi res scan A and B) of the specified * file. Memory must already be allocated for the passed structures * (use allocdata function). * * LAST UPDATE: 5 December 1997 * * ARGUMENTS: * * Name Type Description * ---- ---- ----------- * infile *FILE Opened input data file pointer * hdr std_hdr Filled std_hdr header info structure * structA *std_data Pointer to scanline A stuct of array data * structAhi *std_data Pointer to scanline A hi-res array * structBhi *std_data Pointer to scanline B hi-res array * * ORIGINAL AUTHORS: * Don Anderson, CIRES/CDC, November 1997 * * RETURNS: 0 If successful read of scanline * 999 If end-of-file scanline read * -1 If error allocating temporary array * -2 If error reading infile for low resolution data * -3 If error reading infile for high-resolution scanline A * -4 If error reading infile for high-resolution scanline B * -5 If the passed structA is null * * NOTES: * (1) The passed file descriptor ("infile") must be for a file that * has already been opened * (2) The passed std_hdr structure holding header information about the * opened file must already be populated with valid data (use read_hdr) * (3) Adequate memory must already be allocated for the arrays in the * passed data structures (use allocdata). Alternatively, structAhi * and structBhi may be declared NULL. * (4) This code handles either single-resolution data, or low-and-high * resolution data where hi-res is 2X resolution of lo-res (e.g., SSM/I). * Other multiples of nested resolution cannot be handled by this code. * (5) This code expects that the EOF file record has an itime value equal * to hdr.missing_val, whereupon this function returns the value 999. * (6) Assumes that lat and long values in data file scaled by 100. * * MODIFICATIONS: * Wes Berg 12/5/97 Add reclen increments to read past EOF * Don Anderson 12/5/97 Return data values as scaled & offset floats * ***************************************************************************/ #define LATSCALE 100.0 #define LONSCALE 100.0 int read_scan ( FILE *infile, struct std_hdr hdr, struct std_data *structA, struct std_data *structAhi, struct std_data *structBhi ) { int Abytes ; /* Length of A-scan data to read */ int Bbytes ; /* Length of B-scan data to read */ int Bflag ; /* Flag to expect B-scan data */ int error_flag ; /* Error flag */ short field ; /* Array field counter */ short fields ; /* Number of lo-res fields */ short hifields ; /* Number of hi-res fields */ int loc ; /* Array byte location */ int pix ; /* Pixel counter */ int reclen ; /* Total record length */ short *temparray ; /* Array for holding one scanline data */ short tlat ; /* Temporary latitude value holder */ short tlon ; /* Temporary longitude value holder */ long ttime ; /* Temporary itime value holder */ char buf[5000] ; /* Temporary buffer to read to EOR */ error_flag = 0 ; Bflag = 0 ; if ( ! structA ) { error_flag = -5 ; goto outta_here ; } if ( hdr.hifields > 0 && structAhi != NULL && structBhi != NULL ) Bflag = 1 ; /** Determine length of data records per pixel **/ Abytes = hdr.fields * sizeof ( short ) ; if ( ! Bflag ) Bbytes = 0 ; else { Abytes = ( hdr.fields + hdr.hifields ) * sizeof ( short ) ; Bbytes = hdr.hifields * sizeof ( short ) ; } reclen = ( Abytes + 8 ) * hdr.pixperscan + ( Bbytes + 8 ) * ( hdr.hipixperscan / 2 ) + ( Bbytes + 8 ) * hdr.hipixperscan ; temparray = ( short * ) malloc ( Abytes ) ; if ( temparray == NULL ) { error_flag = -1 ; goto outta_here ; } /** Case 1: single-resolution data only **/ if ( ! Bflag ) { for ( pix = 0 ; pix < hdr.pixperscan ; pix++ ) { fread ( &ttime, 4, 1, infile ) ; fread ( &tlat, 2, 1, infile ) ; fread ( &tlon, 2, 1, infile ) ; if ( ttime == hdr.missing_val ) { error_flag = 999 ; fread ( &buf, reclen - 8, 1, infile ) ; goto outta_here ; } structA->itime[pix] = ttime ; structA->lat[pix] = tlat / LATSCALE ; structA->lng[pix] = tlon / LONSCALE ; loc = 0 ; if ( ! fread ( temparray, Abytes, 1, infile ) ) { error_flag = -2 ; goto outta_here ; } field = 0 ; while ( field < hdr.fields ) { if ( temparray[loc] == hdr.missing_val ) structA->fielddata[field][pix] = (float) hdr.missing_val ; else structA->fielddata[field][pix] = (float) ( temparray[loc] - hdr.offset[field] ) / (float) hdr.scale[field] ; loc ++ ; field++ ; } } } /** Case 2: low- and high-resolution data together **/ if ( Bflag ) { /** Read scanline A **/ for ( pix = 0 ; pix < hdr.hipixperscan ; pix++ ) { fread ( &ttime, 4, 1, infile ) ; fread ( &tlat, 2, 1, infile ) ; fread ( &tlon, 2, 1, infile ) ; if ( ttime == hdr.missing_val ) { error_flag = 999 ; fread ( &buf, reclen - 8, 1, infile ) ; goto outta_here ; } /** Even scanline A locations **/ if ( pix % 2 == 0 ) { structA->itime[pix/2] = ttime ; structAhi->itime[pix] = ttime ; structA->lat[pix/2] = tlat / LATSCALE ; structAhi->lat[pix] = tlat / LATSCALE ; structA->lng[pix/2] = tlon / LONSCALE ; structAhi->lng[pix] = tlon / LONSCALE ; loc = 0 ; if ( ! fread ( temparray, Abytes, 1, infile ) ) { error_flag = -3 ; goto outta_here ; } /** Load lo-res data **/ field = 0 ; while ( field < hdr.fields ) { if ( temparray[loc] == hdr.missing_val ) structA->fielddata[field][pix/2] = (float) hdr.missing_val ; else structA->fielddata[field][pix/2] = (float) ( temparray[loc] - hdr.offset[field] ) / (float) hdr.scale[field] ; loc ++ ; field++ ; } /** Load hi-res data **/ if ( hdr.hifields > 0 ) { field = 0 ; while ( field < hdr.hifields ) { if ( temparray[loc] == hdr.missing_val ) structAhi->fielddata[field][pix] = (float) hdr.missing_val ; else structAhi->fielddata[field][pix] = (float) ( temparray[loc] - hdr.offset[field] ) / (float) hdr.scale[hdr.fields+field] ; loc ++ ; field++ ; } } } /** Odd scanline A locations **/ else { structAhi->itime[pix] = ttime ; structAhi->lat[pix] = tlat / LATSCALE ; structAhi->lng[pix] = tlon / LONSCALE ; if ( ! fread ( temparray, Bbytes, 1, infile ) ) { error_flag = -3 ; goto outta_here ; } /** Load hi-res data **/ loc = 0 ; if ( hdr.hifields > 0 ) { field = 0 ; while ( field < hdr.hifields ) { if ( temparray[loc] == hdr.missing_val ) structAhi->fielddata[field][pix] = (float) hdr.missing_val ; else structAhi->fielddata[field][pix] = (float) ( temparray[loc] - hdr.offset[field] ) / (float) hdr.scale[hdr.fields+field] ; loc ++ ; field++ ; } } } } /** End scan A read **/ /** Read scanline B **/ loc = 0 ; for ( pix = 0 ; pix < hdr.hipixperscan ; pix++ ) { fread ( &ttime, 4, 1, infile ) ; fread ( &tlat, 2, 1, infile ) ; fread ( &tlon, 2, 1, infile ) ; if ( ! fread ( temparray, Bbytes, 1, infile ) ) { error_flag = -4 ; goto outta_here ; } structBhi->itime[pix] = ttime ; structBhi->lat[pix] = tlat / LATSCALE ; structBhi->lng[pix] = tlon / LATSCALE ; loc = 0 ; if ( hdr.hifields > 0 ) { field = 0 ; while ( field < hdr.hifields ) { if ( temparray[loc] == hdr.missing_val ) structBhi->fielddata[field][pix] = (float) hdr.missing_val ; else structBhi->fielddata[field][pix] = (float) ( temparray[loc] - hdr.offset[field] ) / (float) hdr.scale[hdr.fields+field] ; loc ++ ; field ++ ; } } } /** End scan B read **/ } /** End hi-resolution case **/ outta_here : return ( error_flag ) ; } /**************************************************************************** * * allocdata * * Allocates necessary space for the passed structures to hold one scanline * of data. * * ARGUMENTS: * Name Type Description * ---- ---- ----------- * *data struct std_data Pointer to std_data structure to hold data * pixels short Pixels per scanline for these data * fields short Fields per pixel for these data * * RETURNS: * 0 if successful * -1 if suspect arguments passed * -2 if unable to allocate space * *****************************************************************************/ int allocdata ( struct std_data *data, short pixels, short fields ) { int error_flag = 0 ; int i ; /** Check for valid arguments **/ if ( ( pixels < 0 ) || ( pixels > 100000 ) || ( fields < 0 ) || ( fields > 100000 ) ) { error_flag = -1 ; goto bailout ; } /** Allocate space for time, lat and lon fields **/ data->itime = ( long * ) malloc ( pixels * sizeof ( long ) ) ; data->lat = ( float * ) malloc ( pixels * sizeof ( float ) ) ; data->lng = ( float * ) malloc ( pixels * sizeof ( float ) ) ; if ( data->itime == NULL || data->lat == NULL || data->lng == NULL ) { error_flag = -2 ; goto bailout ; } /** Allocate pointers to data fields **/ data->fielddata = ( float ** ) malloc ( fields * sizeof ( float * ) ) ; if ( data->fielddata == NULL ) { error_flag = -2 ; goto bailout ; } for ( i = 0 ; i < pixels ; i++ ) { data->fielddata[i] = ( float * ) malloc ( pixels * sizeof ( float ) ) ; if ( data->fielddata[i] == NULL ) { error_flag = -2 ; goto bailout ; } } bailout : return ( error_flag ) ; } /**************************************************************************** * * date * * Converts integer time in seconds from specified year into a date and time * string * * ARGUMENTS: * Name Type Description * ---- ---- ----------- * *date_str char Date string (MM-DD-YY) * *time_str char Time string (HH:MM:SS) * itime long integer time in seconds from base_year * base_year int Baseline year (i.e 70 -> time from 1970) * *****************************************************************************/ date (char *date_str, char *time_str, long itime, int base_year) { long itime2; int mon,day,yr,tday,i,ndays=365,ind; int hr,min,sec; static int julian[2][12] = { {1,32,60,91,121,152,182,213,244,274,305,335}, {1,32,61,92,122,153,183,214,245,275,306,336}}; yr = base_year ; itime2 = itime ; while ((itime2 - ndays*86400) > 0) { yr = yr + 1; itime2 = itime2 - ndays*86400; if (yr%4 == 0) ndays = 366; else ndays = 365; } if (yr%4 == 0) ind = 1; else ind = 0; mon = 12; tday = itime2/86400; for (i=1; i<=12; i++) { if (julian[ind][i-1] > tday+1) { mon = i-1; break; } } day = tday - julian[ind][mon-1] + 2; itime2 = itime2 - (julian[ind][mon-1]+day-2)*86400; hr = itime2/3600; itime2 = itime2 - hr*3600; min = itime2/60; itime2 = itime2 - min*60; sec = itime2; date_str[0] = '0' + (mon/10); date_str[1] = '0' + (mon%10); date_str[2] = '-'; date_str[3] = '0' + (day/10); date_str[4] = '0' + (day%10); date_str[5] = '-'; date_str[6] = '0' + (yr/10); date_str[7] = '0' + (yr%10); date_str[8] = '\0'; time_str[0] = '0' + (hr/10); time_str[1] = '0' + (hr%10); time_str[2] = ':'; time_str[3] = '0' + (min/10); time_str[4] = '0' + (min%10); time_str[5] = ':'; time_str[6] = '0' + (sec/10); time_str[7] = '0' + (sec%10); time_str[8] = '\0'; return(1); }