#include #include #include /* This program is used to convert a sp3-c file into an older-style sp3-a file (which has <= 60 cols of data on each line). Author: Steve Hilla, NGS/NOAA Date: 28 July 2005 0211.26, SH , Creation of program SP3ASP3C.C 0507.28, SH , use sp3asp3c.c to create sp3csp3a.c 0512.28, SH , compiled for use on the PC */ FILE *in, *out; int main( int argc, char * argv[]) { char buff[256]; int i,l; int endOfFile = 0; printf("\nProgram SP3cSP3a converts a sp3-c file into an older sp3-a\n"); printf("file. It truncates any standard deviations or flags in\n"); printf("columns 61 through 80. It assumes the sp3-c file contains\n"); printf("only GPS satellite data. It omits any EP and EV records.\n\n"); /* check the # arguments on the command line */ if( argc < 3 ) { printf("\n You must give two arguments: \n"); printf(" example: sp3csp3a sp3cfile.sp3 sp3afile.sp3 \n"); return (-1); } /* open both files */ if( ( in = fopen(argv[1],"r") ) == NULL ) { printf(" ERROR opening the input sp3c file: %s\n",argv[1]); return(-1); } if( ( out = fopen(argv[2],"w") ) == NULL ) { printf(" ERROR opening the output sp3a file: %s\n",argv[2]); return(-1); } /* read the first line */ fgets(buff, 85, in); if(buff[0] == '#' && buff[1] == 'c' ) { buff[1] = 'a'; fprintf(out,"%s",buff); } else { printf("Error reading line 1 of file %s, version symbol is not #c !\n%s\n\n", argv[1],buff); return(-1); } /* read and echo the second line */ fgets(buff, 85, in); fprintf(out,"%s",buff); /* read and modify lines 3 thru 4 */ for( l = 3; l < 5; l++ ) { fgets(buff, 85, in); for( i = 9; i < 60; i += 3) { if( buff[i] == ' ' && buff[i+1] == ' ' && buff[i+2] == '0' ) { // do nothing } else { if( buff[i] != 'G' ) { printf("Error reading lines 3 thru 4, invalid Satellite ID, not G !\n%s\n\n", buff); return(-1); }; buff[i] = ' '; if( buff[i+1] == '0' ) buff[i+1] = ' '; /* change G03 into __3 */ } } fprintf(out,"%s",buff); } /* read and echo lines 5 thru 12 */ for( l = 5; l < 13; l++ ) { fgets(buff, 85, in); fprintf(out,"%s",buff); } /* read lines 13 thru 15 */ for( l = 13; l < 16; l++ ) { fgets(buff, 85, in); } fprintf(out, "%%c c cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc\n"); /* In the sp3a format, this line should be all c's */ fprintf(out, "%%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc\n"); fprintf(out, "%%f 0.0000000 0.000000000 0.00000000000 0.000000000000000\n"); /* In the sp3a format, these should all be zeroes */ /* read and echo lines 16 thru 23 */ for( l = 16; l < 24; l++ ) { fgets(buff, 85, in); fprintf(out,"%s",buff); } /* read and modify all of the Position and Clock Records (and Velocity and Clock Rate-of-Change Records) Omit any EP or EV records records -- these will NOT go into the sp3a file */ while( !endOfFile ) { if( fgets(buff, 85, in) == NULL ) { printf("Error reading file %s. Previous line was:\n%s\n\n", argv[1],buff); printf("Check that this file ends with an EOF line.\n\n"); endOfFile = 1; fclose(in); fclose(out); return(-1); } if( buff[0] == 'P' && buff[1] == 'G' ) { buff[1] = ' '; if( buff[2] == '0') buff[2] = ' '; /* change PG03 into P__3 */ fprintf(out,"%.60s\n",buff); /* truncate to 60 columns */ } else if( buff[0] == 'V' && buff[1] == 'G' ) { buff[1] = ' '; if( buff[2] == '0') buff[2] = ' '; /* change VG03 into V__3 */ fprintf(out,"%.60s\n",buff); /* truncate to 60 columns */ } else if( buff[0] == 'E' && buff[1] == 'P' ) { // do nothing, do NOT write these types of sp3c records to the sp3a file } else if( buff[0] == 'E' && buff[1] == 'V' ) { // do nothing, do NOT write these types of sp3c records to the sp3a file } else if( buff[0] == 'E' && buff[1] == 'O' && buff[2] == 'F' ) { endOfFile = 1; fprintf(out,"%s",buff); } else { fprintf(out,"%s",buff); /* print out all time tag lines without changes */ } } fclose(in); fclose(out); printf("\n\nNormal Termination for Program SP3cSP3a.\n\n"); printf("\n\nCheck that only P (and optional V) records exist in the output sp3a file.\n\n"); return(0); } /* end of main */