adjust_geo.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Vladimir Dergachev
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
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 /* Modify file here : */
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 }

Generated on Sat Jul 19 03:13:54 2008 for LAL by  doxygen 1.5.2