00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <sys/types.h>
00023 #include <sys/stat.h>
00024 #include <unistd.h>
00025 #include <fcntl.h>
00026 #include <sys/mman.h>
00027
00028 #define TESTIO(a) { \
00029 if((a)<0){ \
00030 perror(""); \
00031 exit(-1); \
00032 } \
00033 }
00034
00035 typedef double REAL8;
00036 typedef float REAL4;
00037
00038 typedef struct {
00039 REAL8 key;
00040 int gps;
00041 int nsec;
00042 REAL8 timebase;
00043 int bin_start;
00044 int nbins;
00045 } HEADER;
00046
00047 int main(int argc, char *argv[])
00048 {
00049 int fd;
00050 unsigned char *p;
00051 REAL4 *data;
00052 struct stat buf;
00053 HEADER *header;
00054 long i;
00055
00056 if(argc<2){
00057 fprintf(stderr,"Usage: %s filename\n", argv[0]);
00058 exit(-1);
00059 }
00060
00061 TESTIO(fd=open(argv[1], O_RDWR));
00062 TESTIO(fstat(fd, &buf));
00063 p=mmap(NULL, buf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
00064 TESTIO(p==NULL?-1:0);
00065 close(fd);
00066
00067 header=p;
00068 data=p+sizeof(*header);
00069
00070 fprintf(stderr,"key=%g\n", header->key);
00071 fprintf(stderr,"gps=%d\n", header->gps);
00072 fprintf(stderr,"nsec=%d\n", header->nsec);
00073 fprintf(stderr,"timebase=%g\n", header->timebase);
00074 fprintf(stderr,"bin_start=%d\n", header->nsec);
00075 fprintf(stderr,"nbins=%d\n", header->nbins);
00076
00077
00078
00079 if(header->key!=1.0){
00080 fprintf(stderr,"file %s has unknown key\n", argv[1]);
00081 exit(-3);
00082 }
00083
00084 if(header->timebase >0) {
00085 fprintf(stderr,"file %s is correct - leaving alone\n", argv[1]);
00086 exit(-2);
00087 }
00088 fprintf(stderr,"Adjusting file %s\n", argv[1]);
00089
00090 header->timebase=-header->timebase;
00091 return 0;
00092 (volatile)header->key=1.5;
00093 for(i=0;i<header->nbins*2;i++)
00094 data[i]=data[i]*(header->nbins*1.0)/(0.5*1800.0*16384.0);
00095 (volatile)header->key=1.0;
00096 return 0;
00097 }