• Main Page
  • Data Structures
  • Files

main.c

Go to the documentation of this file.
00001 
00002 /*
00003  * This file is part of Titan2Reader
00004  *
00005  * Copyright (C) 2006, Sebastien Judenherc <sebastien.judenherc@agecodagis.com>
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  */
00023 
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <time.h>
00027 #include <ctype.h>
00028 #include <math.h>
00029 #include <errno.h>
00030 #include <unistd.h>
00031 #include <string.h>
00032 #include <sys/types.h>
00033 #include <sys/stat.h>
00034 #include <fcntl.h>
00035 #include <dirent.h>
00036 #include <signal.h>
00037 #include <unistd.h>
00038 #include <sys/time.h>
00039 #include <sys/resource.h>
00040 
00041 #ifdef RENICE
00042 #include <sys/time.h>     // to manage priority
00043 #include <sys/resource.h> // to manage priority
00044 #endif
00045 
00046 #include "common.h"
00047 
00048 #define FILE_MODE 0
00049 #define DAY_MODE 1
00050 #define DISK_MODE 2
00051 
00052 
00053 // global variables
00054 int privateDebug=0; 
00055 
00056 int forceNameOptions=-1; 
00057 
00058 int minSamplesPerFrame=1; 
00059 
00060 char currentTag[16];   
00061 char onlyTag[16];   
00062 
00063 char tdbName[128] = ""; 
00064 
00065 clock_t startClock; 
00066 
00067 struct HWConfigType HWConfig; 
00068 
00069 struct HWConfigType oldHWConfig; 
00070 
00071 unsigned char lastSync=0; 
00072 
00073 FILE * titan2File=NULL; 
00074 
00075 char * currentFile=NULL; 
00076 
00077 int64_t inputOffset=0; 
00078 
00079 int64_t totalFrameProcessed=0; 
00080 
00081 int64_t printTrigger=INIT_PRINT_TRIGGER; 
00082 
00083 int timeSegment=-1; 
00084 
00085 int timeList=0; 
00086 
00087 int preEvent=0xefffffff; 
00088 int postEvent=0xefffffff; 
00089 
00090 int syncWarn=1; 
00091 
00092 int eduseis=0; 
00093 
00094 int noWrite=0; 
00095 
00096 int test0=0; 
00097 
00098 int noInfo=0; 
00099 
00100 int doOffset=1; 
00101 
00102 int noTimeCorrection=0; 
00103 
00104 int VERBOSE=0; 
00105 
00106 char ARGV0[128]; 
00107 
00108 char **ARGV=NULL; 
00109 
00110 int ARGC; 
00111 
00112 int logInfo=0; 
00113 
00114 int inputMode; 
00115 
00116 int iFileInput=0; 
00117 
00118 char *baseDir=NULL; 
00119 
00120 int saveShift=0; 
00121 int64_t auxiliaryMask=0x00000000LL; 
00122 int64_t channelMask=0x00ffffffLL; 
00123 int64_t inputChannelMask=0x00ffffffLL; 
00124 char * streamList=NULL; 
00125 int extractTrig=0; 
00126 int extractTit=0; 
00127 int extractWav=0; 
00128 int extractGif=0; 
00129 int extractSegy=0; 
00130 int extractSeg2=0; 
00131 int extractSac=0; 
00132 int extractSis=0; 
00133 int extractAsc=0; 
00134 int extractBin=0; 
00135 int extractMSeed=0; 
00136 int extractingData=0; 
00137 int removeMean=0; 
00138 int dataExtracted=0; 
00139 int extracting=0; 
00140 int seeking=0; 
00141 int fastSeek=0; 
00142 int cutDtOnReset=1; 
00143 int pulseFilter=1; 
00144 int localCache=0; 
00145 int prependdaydir=0; 
00146 
00147 int timeWarning=0; 
00148 
00149 int overWrite=0; 
00150 
00151 int ignoreDiscontinuity=0; 
00152 
00153 int scanAll=0; 
00154 
00155 char forceName[128]=""; 
00156 
00157 int ndx2tl=0; 
00158 int ndx2cache=0; 
00159 
00160 struct Titan2TimeType currentTime = { 0, 0 }; 
00161 struct Titan2TimeType correctedTime = { 0, 0 }; 
00162 struct Titan2TimeType pulseTime = { 0, 0 }; 
00163 struct Titan2TimeType gpsExtTime = { 0, 0 }; 
00164 struct Titan2TimeType gpsIntTime = { 0, 0 }; 
00165 
00166 struct EventType event = { -12345.0, -12345.0, -12345.0, -1.0 };
00167 
00168 int channelNameNumber=0; 
00169 
00170 int seedBlockSizePowerOf2=3; 
00171 
00172 time_t beginWindow=-1;  
00173 time_t endWindow=-1;    
00174 int cmdLineWindow=0;  
00175 
00176 int noCache=0; 
00177 
00178 int64_t beginOfFile=-1; 
00179 int64_t endOfFile=-1; 
00180 int skipTime=-1; 
00181 
00182 int globalStationChange=0; 
00183 
00184 char manualStationName[64]=""; 
00185 
00186 time_t timeCounterSleepIfArm=0; 
00187 
00188 void howto(void)
00189 {
00190 #include "howto.c"
00191 }
00192 
00193 void usage(void)
00194 {
00195 #include "usage.c"
00196 }
00197 
00198 void logdoc(void)
00199 {
00200 #include "logdoc.c"
00201 }
00202 
00203 void tdbdoc(void)
00204 {
00205 #include "tdbdoc.c"
00206 }
00207 
00209 void SleepIfArm(void)
00210 {
00211         time_t now;
00212         time(&now);
00213         if (now!=timeCounterSleepIfArm)
00214         {
00215                 timeCounterSleepIfArm=now;
00216                 usleep(200*1000); // 200ms
00217         }
00218 }
00219 
00223 char * MyGetenv(char *s)
00224 {
00225         char *tmp;
00226         tmp=getenv(s);
00227         if (!tmp) { return(NULL); }
00228         if (strlen(tmp)==0) { return(NULL); }
00229         return(tmp);
00230 }
00233 void version(int rel)
00234 {
00235         if (rel)
00236         {
00237                 printf("%d.%d.%d",VERSION,MAJOR,MINOR);
00238 #ifdef SVER
00239                 printf("-%s",SVER);
00240 #endif
00241         }
00242         else
00243         {
00244                 printf(PROGRAMNAME" version %d.%d.%d",VERSION,MAJOR,MINOR);
00245 #ifdef SVER
00246                 printf(" %s\n",SVER);
00247 #else
00248                 printf("\n");
00249 #endif
00250         }
00251 }
00252 
00253 
00255 void copyright(void)
00256 {
00257         printf(PROGRAMNAME" is released under the GNU GENERAL PUBLIC LICENSE:\n");
00258         printf("This program is free software; you can redistribute it and/or\n");
00259         printf("modify it under the terms of the GNU General Public License\n");
00260         printf("as published by the Free Software Foundation; either version 2\n");
00261         printf("of the License, or (at your option) any later version.\n");
00262         printf("\n");
00263         printf("This program is distributed in the hope that it will be useful,\n");
00264         printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
00265         printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
00266         printf("GNU General Public License for more details.\n");
00267         printf("\n");
00268         printf("You should have received a copy of the GNU General Public License\n");
00269         printf("along with this program; if not, write to the Free Software\n");
00270         printf("Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n");
00271         printf("\n");
00272         printf("See file COPYING in the source tree.\n");
00273 }
00274 
00276 int PrintMessages(void)
00277 {
00278         if (VERBOSE)
00279         {
00280                 return(1);
00281         }
00282         if ((extractingData)&&(inputOffset!=0)&&(!seeking)) //&&(extractingData||saveShift))
00283         {
00284                 return(1);
00285         }
00286         return(0);
00287 }
00288 
00293 int ListToMask(char *ins, int64_t *newmask)
00294 {
00295         int64_t mask=0;
00296         int err=0;
00297         int i,count,len,next,nchar,last=0;
00298         char code=':';
00299         char *s;
00300         s=ins;
00301         // sanity check
00302         if (!s)
00303         {
00304                 return(err);
00305         }
00306         while (*s==' ')
00307         {
00308                 s++;
00309         }
00310         /* if s is '*' or 'all' set the mask to 0x00ffffff */
00311         if ((!strcasecmp(s,"*"))||(!strcasecmp(s,"all"))) {
00312                 mask=0x00ffffff;
00313                 goto end_ListToMask;
00314         }
00315 
00316         /* if s is 'none' set mask to 0 */
00317         if ((!strcasecmp(s,"none"))) {
00318                 mask=0;
00319                 goto end_ListToMask;
00320         }
00321 
00322         /* else interpret the string */
00323         len=strlen(s);
00324         i=0;
00325         while (i<len) {
00326                 count=sscanf(s+i,"%d%n",&next,&nchar);
00327 
00328                 /* check for syntax */
00329                 if ((!count)||(!isdigit(s[i]))) {
00330                         err=-1;
00331                         PrintError("channel list syntax error '%s'\n",s+i);
00332                         goto end_ListToMask;
00333                 }
00334 
00335                 /* check for channel out of bounds */
00336                 if ((next>(MAX_OSIRIS_CHANNEL-1))||(next<0)) {
00337                         err=-1;
00338                         PrintError("channel out of range\n");
00339                         goto end_ListToMask;
00340                 }
00341 
00342                 /* process separator: ',' or '-' */
00343                 switch (code) {
00344                         case ':' :
00345                         case ';' :
00346                         case ',' :
00347                                 mask|=(1LL<<next);
00348                                 break;
00349                         case '-' :
00350                                 for (; last <=next; last++) {
00351                                         mask|=(1LL<<last);
00352                                 }
00353                                 break;
00354                         default :
00355                                 err=-1;
00356                                 PrintError("channel list syntax error\n");
00357                                 goto end_ListToMask;
00358                 }
00359                 last=next;
00360                 i+=nchar+1;
00361                 code=s[i-1];
00362         }
00363 end_ListToMask:
00364         if (!err) {
00365                 *newmask=mask;
00366         }
00367         return(err);
00368 }
00369 
00374 static unsigned char ProcessFrame(const unsigned char *frame)
00375 {
00376         int addTitan=1;
00377 
00378 #ifdef RENICE
00379         SleepIfArm();
00380 #endif
00381 
00382         switch (frame[11]&0x7)
00383         {
00384                 // information frame
00385                 case INFO_FRAME: // 100
00386                         ProcessInfoFrame(frame);
00387                         break;
00388                 case MISC_FRAME: // 110
00389                         ProcessMiscFrame(frame);
00390                         break;
00391                 case OFFSET_FRAME: // 011
00392                         ProcessOffsetFrame(frame);
00393                         break;
00394                 case TIME_FRAME: // 101
00395                 case GPST_FRAME: // 010
00396                         ProcessTimeFrame(frame);
00397                         break;
00398                 case DAT0_FRAME: // 000
00399                 case DAT1_FRAME: // 001
00400                 case DAT2_FRAME: // 111
00401                         addTitan=channelMask&ProcessDataFrame(frame);
00402                         break;
00403                 default:
00404                         PrintWarning("unknown frame type %#0x\n",
00405                                         frame[11]&0x7);
00406                         return(frame[11]&0x7);
00407         }
00408         // the special action of segment extraction must be done here
00409         if (extractTit)
00410         {
00411                 if (addTitan)
00412                 {
00413                         if (InWindow())
00414                         {
00415                                 AddTitFrame(frame);
00416                         }
00417                 }
00418         }
00419         return(frame[11]&0x7);
00420 }
00421 
00423 int ParseEvent(char *evt)
00424 {
00425         char *s=evt;
00426         while (*s++)
00427         {
00428                 if (*s==',')
00429                 {
00430                         *s=0;
00431                         s++;
00432                         break;
00433                 }
00434         }
00435         if ((3!=sscanf(s,"%f,%f,%f",&event.lat,&event.lon,&event.dep))||
00436                         (str2time(evt,&event.OT)<=0))
00437         {
00438                 PrintError("could not read event parameters\n");
00439                 event.lat=-12345.0;
00440                 event.lon=-12345.0;
00441                 event.dep=-12345.0;
00442                 event.OT=-1.0;
00443         }
00444         else
00445         {
00446                 PrintLog("event:%.23s lat=%.3f lon=%.3f dep=%.0f\n",
00447                                 time2str(event.OT),
00448                                 event.lat,event.lon,event.dep);
00449         }
00450         return(0);
00451 }
00452 
00457 int ParseOptions(int argc, char **argv)
00458 {
00459         int i;
00460         int done,timesel;
00461         timesel=0;
00462         // if this is the second pass for the command line window
00463         if (cmdLineWindow==-1)
00464         {
00465                 // stop
00466                 beginWindow=endWindow=0;
00467                 return(0);
00468         }
00469         // test argc
00470         if (argc==1)
00471         {
00472                 version(1);
00473                 printf("\nTry `"PROGRAMNAME" --help' for more information.\n");
00474                 return(-1);
00475         }
00476         // set the program name
00477         if (strrchr(argv[0],'/'))
00478         {
00479                 strcpy(ARGV0,strrchr(argv[0],'/')+1);
00480         }
00481         else
00482         {
00483                 strcpy(ARGV0,argv[0]);
00484         }
00485         // export argv and argc
00486         ARGV=argv;
00487         ARGC=argc;
00488         inputMode=-1;
00489         // supposer onlyTag non défini
00490         onlyTag[0]=0;
00491         // pour chaque argument
00492         for (i=1; i<argc; i++)
00493         {
00494                 // si le premier caractère est '-', c'est une option
00495                 if (argv[i][0]=='-')
00496                 {
00497                         done=0;
00498 
00499                         // first process the titan1 special actions that
00500                         // do not need to actually read the input stream
00501                         // and exits after the work:
00502 
00503                         // read the size.siz file and cut the input
00504                         if (0==strcmp(argv[i]+1,"size"))
00505                         {
00506                                 done=1;
00507                                 if (i+1>=argc)
00508                                 {
00509                                         goto error_not_enough_arguments;
00510                                 }
00511                                 i++;
00512                                 ReadSize(argv[i]);
00513                         }
00514                         // read the index file and generate cache or
00515                         // event list
00516                         if (0==strncmp(argv[i]+1,"index",5))
00517                         {
00518                                 done=1;
00519                                 if (i+1>=argc)
00520                                 {
00521                                         goto error_not_enough_arguments;
00522                                 }
00523                                 i++;
00524                                 ReadIndex(argv[i]);
00525                         }
00526                         // read the datafile file and dump the usefull
00527                         // part
00528                         if (0==strcmp(argv[i]+1,"data"))
00529                         {
00530                                 done=1;
00531                                 if (i+1>=argc)
00532                                 {
00533                                         goto error_not_enough_arguments;
00534                                 }
00535                                 i++;
00536                                 CutDataFile(argv[i]);
00537                         }
00538                         // read the TriggerEvents file and dump in tl
00539                         // format
00540                         if (0==strcmp(argv[i]+1,"te"))
00541                         {
00542                                 done=1;
00543                                 if (i+1>=argc)
00544                                 {
00545                                         goto error_not_enough_arguments;
00546                                 }
00547                                 i++;
00548                                 DumpTriggerEvents(argv[i]);
00549                                 exit(0);
00550                         }
00551 #ifdef USE_GD
00552                         // plot the logs
00553                         if (0==strncmp(argv[i]+1,"plotlog",9))
00554                         {
00555                                 if (argc>i+1)
00556                                 {
00557                                         void ReadOIF(char *file);
00558                                         PrintError("reading %s\n",argv[i+1]);
00559                                         ReadOIF(argv[i+1]);
00560                                 }
00561                                 done=1;
00562                                 DoPlots();
00563                                 exit(0);
00564                         }
00565 #endif
00566 #ifdef OMNI
00567                         // filter the OPF input
00568                         if (0==strncmp(argv[i]+1,"opffiltermask",13))
00569                         {
00570                                 done=1;
00571                                 ProcessOPF(1,1);
00572                                 exit(0);
00573                         }
00574                         if (0==strncmp(argv[i]+1,"opffilter",9))
00575                         {
00576                                 done=1;
00577                                 ProcessOPF(0,1);
00578                                 exit(0);
00579                         }
00580                         if (0==strncmp(argv[i]+1,"opffilternocase",15))
00581                         {
00582                                 done=1;
00583                                 ProcessOPF(0,0);
00584                                 exit(0);
00585                         }
00586                         // omni mode
00587                         if (0==strncmp(argv[i]+1,"omni",4))
00588                         {
00589                                 if (ParseOmniOptions(argv[i]+5)!=0)
00590                                 {
00591                                         goto error_syntax_error;
00592                                 }
00593                                 done=1;
00594                                 if (i+1>=argc)
00595                                 {
00596                                         goto error_not_enough_arguments;
00597                                 }
00598                                 i++;
00599                                 ProcessOMNI(argv[i]);
00600                                 exit(0);
00601                         }
00602 #endif
00603                         // read the OIF and dump a HTML page
00604                         if (0==strncmp(argv[i]+1,"oif",3))
00605                         {
00606                                 if (ParseOifOptions(argv[i]+4)!=0)
00607                                 {
00608                                         goto error_syntax_error;
00609                                 }
00610                                 done=1;
00611                                 if (i+1>=argc)
00612                                 {
00613                                         goto error_not_enough_arguments;
00614                                 }
00615                                 i++;
00616                                 ProcessOIF(argv[i]);
00617                                 exit(0);
00618                         }
00619                         // filter the dt file
00620                         if (0==strcmp(argv[i]+1,"pulsefilter"))
00621                         {
00622                                 done=1;
00623                                 if (i+1>=argc)
00624                                 {
00625                                         goto error_not_enough_arguments;
00626                                 }
00627                                 i++;
00628                                 PulseFilter(argv[i],1.e-5);
00629                                 exit(0);
00630                         }
00631 
00632 
00633                         // external parameters: source location, gif title etc.
00634                         if (0==strcmp(argv[i]+1,"event"))
00635                         {
00636                                 done=1;
00637                                 if (i+1>=argc)
00638                                 {
00639                                         goto error_not_enough_arguments;
00640                                 }
00641                                 i++;
00642                                 ParseEvent(argv[i]);
00643                         }
00644                         // select tit segments
00645                         if (0==strcmp(argv[i]+1,"tit"))
00646                         {
00647                                 done=1;
00648                                 noCache=1;
00649                                 extractTit=1;
00650                         }
00651                         // debug
00652                         if (0==strcmp(argv[i]+1,"debug"))
00653                         {
00654                                 done=1;
00655                                 privateDebug=1;
00656                         }
00657                         // build a wav image
00658                         if (0==strcmp(argv[i]+1,"wav"))
00659                         {
00660                                 done=1;
00661                                 noCache=1;
00662                                 extractWav=1;
00663                         }
00664                         // build a trigger list
00665                         if (0==strncmp(argv[i]+1,"trig",4))
00666                         {
00667                                 if (ParseTriggerOptions(argv[i]+5)!=0)
00668                                 {
00669                                         goto error_syntax_error;
00670                                 }
00671                                 done=1;
00672                                 noCache=1;
00673                                 extractTrig=1;
00674                         }
00675                         // merge trigger, window detection
00676                         if (0==strncmp(argv[i]+1,"mergetrigger",12))
00677                         {
00678                                 if (MergeTriggers(argv[i]+13)!=0)
00679                                 {
00680                                         goto error_syntax_error;
00681                                 }
00682                                 exit(0);
00683                         }
00684 #ifdef USE_GD
00685                         // build a gif image
00686                         if (0==strncmp(argv[i]+1,"gif",3))
00687                         {
00688                                 if (ParseImageOptions(argv[i]+4)!=0)
00689                                 {
00690                                         goto error_syntax_error;
00691                                 }
00692                                 done=1;
00693                                 noCache=1;
00694                                 extractGif=1;
00695                         }
00696 #endif
00697                         // convert to mseed
00698                         if (0==strncmp(argv[i]+1,"mseed",5))
00699                         {
00700                                 if (ParseSeedOptions(argv[i]+6)!=0)
00701                                 {
00702                                         goto error_syntax_error;
00703                                 }
00704                                 done=1;
00705                                 noCache=1;
00706                                 extractMSeed=1;
00707                         }
00708                         // convert to asc
00709                         if (0==strcmp(argv[i]+1,"asc"))
00710                         {
00711                                 done=1;
00712                                 noCache=1;
00713                                 extractAsc=1;
00714                         }
00715                         // convert to bin
00716                         if (0==strcmp(argv[i]+1,"bin"))
00717                         {
00718                                 done=1;
00719                                 noCache=1;
00720                                 extractBin=1;
00721                         }
00722                         // convert to sac
00723                         if (0==strcmp(argv[i]+1,"sac"))
00724                         {
00725                                 done=1;
00726                                 noCache=1;
00727                                 extractSac=1;
00728                         }
00729                         // convert to sis
00730                         if (0==strcmp(argv[i]+1,"sis"))
00731                         {
00732                                 done=1;
00733                                 noCache=1;
00734                                 extractSis=1;
00735                         }
00736                         if (0==strcmp(argv[i]+1,"sis,rm"))
00737                         {
00738                                 done=1;
00739                                 noCache=1;
00740                                 extractSis=1;
00741                                 removeMean=1;
00742                         }
00743                         // convert to seg2
00744                         if (0==strcmp(argv[i]+1,"seg2"))
00745                         {
00746                                 done=1;
00747                                 noCache=1;
00748                                 extractSeg2=1;
00749                         }
00750                         // convert to segy
00751                         if (0==strcmp(argv[i]+1,"segy"))
00752                         {
00753                                 done=1;
00754                                 noCache=1;
00755                                 extractSegy=1;
00756                         }
00757                         // extract the time shift
00758                         if (0==strcmp(argv[i]+1,"time"))
00759                         {
00760                                 done=1;
00761                                 saveShift=1;
00762                         }
00763                         // daydir
00764                         if (0==strcmp(argv[i]+1,"daydir"))
00765                         {
00766                                 done=1;
00767                                 prependdaydir=1;
00768                         }
00769                         // ignore offset frames
00770                         if (0==strcmp(argv[i]+1,"nooffset"))
00771                         {
00772                                 done=1;
00773                                 doOffset=0;
00774                         }
00775                         // do not create info files
00776                         if (0==strcmp(argv[i]+1,"noinfo"))
00777                         {
00778                                 done=1;
00779                                 noInfo=1;
00780                         }
00781                         // do not correct from delta
00782                         if (0==strcmp(argv[i]+1,"tcorr"))
00783                         {
00784                                 done=1;
00785                                 noTimeCorrection=1;
00786                         }
00787                         // ignore discontinuities
00788                         if (0==strcmp(argv[i]+1,"nodisc"))
00789                         {
00790                                 done=1;
00791                                 ignoreDiscontinuity=1;
00792                         }
00793                         // file list
00794                         if (0==strcmp(argv[i]+1,"f"))
00795                         {
00796                                 done=1;
00797                                 if (i+1>=argc)
00798                                 {
00799                                         goto error_not_enough_arguments;
00800                                 }
00801                                 i++;
00802                                 if (inputMode!=-1)
00803                                 {
00804                                         goto error_too_many_sources;
00805                                 }
00806                                 inputMode=FILE_MODE;
00807                                 iFileInput=i;
00808                         }
00809                         // disk directory
00810                         if (0==strcmp(argv[i]+1,"disk"))
00811                         {
00812                                 done=1;
00813                                 if (i+1>=argc)
00814                                 {
00815                                         goto error_not_enough_arguments;
00816                                 }
00817                                 i++;
00818                                 if (inputMode!=-1)
00819                                 {
00820                                         goto error_too_many_sources;
00821                                 }
00822                                 inputMode=DISK_MODE;
00823                                 noCache=1;
00824                                 OpenDiskDir(argv[i]);
00825                         }
00826                         // day directory
00827                         if (0==strcmp(argv[i]+1,"day"))
00828                         {
00829                                 done=1;
00830                                 if (i+1>=argc)
00831                                 {
00832                                         goto error_not_enough_arguments;
00833                                 }
00834                                 i++;
00835                                 if (inputMode!=-1)
00836                                 {
00837                                         goto error_too_many_sources;
00838                                 }
00839                                 inputMode=DAY_MODE;
00840                                 noCache=1;
00841                                 OpenDayDir(argv[i]);
00842                         }
00843                         // skip
00844                         if (0==strcmp(argv[i]+1,"skip"))
00845                         {
00846                                 done=1;
00847                                 if (i+1>=argc)
00848                                 {
00849                                         goto error_not_enough_arguments;
00850                                 }
00851                                 i++;
00852                                 if (sscanf(argv[i],"%d",&skipTime)!=1)
00853                                 {
00854                                         goto error_syntax_error;
00855                                 }
00856                         }
00857                         // bof
00858                         if (0==strcmp(argv[i]+1,"bof"))
00859                         {
00860                                 done=1;
00861                                 if (i+1>=argc)
00862                                 {
00863                                         goto error_not_enough_arguments;
00864                                 }
00865                                 i++;
00866                                 if (sscanf(argv[i],"%Ld",&beginOfFile)!=1)
00867                                 {
00868                                         goto error_syntax_error;
00869                                 }
00870                         }
00871                         // eof
00872                         if (0==strcmp(argv[i]+1,"eof"))
00873                         {
00874                                 done=1;
00875                                 if (i+1>=argc)
00876                                 {
00877                                         goto error_not_enough_arguments;
00878                                 }
00879                                 i++;
00880                                 if (sscanf(argv[i],"%Ld",&endOfFile)!=1)
00881                                 {
00882                                         goto error_syntax_error;
00883                                 }
00884                         }
00885                         // misc:
00886                         if (0==strcmp(argv[i]+1,"howto"))
00887                         {
00888                                 done=1;
00889                                 howto();
00890                                 exit(0);
00891                         }
00892                         if (0==strcmp(argv[i]+1,"logdoc"))
00893                         {
00894                                 done=1;
00895                                 logdoc();
00896                                 exit(0);
00897                         }
00898                         if (0==strcmp(argv[i]+1,"tdbdoc"))
00899                         {
00900                                 done=1;
00901                                 tdbdoc();
00902                                 exit(0);
00903                         }
00904                         if ((0==strcmp(argv[i]+1,"-version"))||
00905                                         (0==strcmp(argv[i],"-version")))
00906                         {
00907                                 done=1;
00908                                 version(0);
00909                                 exit(0);
00910                         }
00911                         if (0==strcmp(argv[i]+1,"release"))
00912                         {
00913                                 done=1;
00914                                 version(1);
00915                                 exit(0);
00916                         }
00917                         if ((0==strcmp(argv[i]+1,"-help"))||
00918                                         (0==strcmp(argv[i],"-help")))
00919                         {
00920                                 done=1;
00921                                 usage();
00922                                 exit(0);
00923                         }
00924                         if ((0==strcmp(argv[i]+1,"-copy"))||
00925                                         (0==strcmp(argv[i],"-copy")))
00926                         {
00927                                 done=1;
00928                                 copyright();
00929                                 exit(0);
00930                         }
00931                         if (0==strcmp(argv[i]+1,"0"))
00932                         {
00933                                 done=1;
00934                                 noWrite=1;
00935                                 noInfo=1;
00936                                 noCache=1;
00937                                 extractSac=1;
00938                         }
00939                         if (0==strcmp(argv[i]+1,"nodata"))
00940                         {
00941                                 done=1;
00942                                 // avoid printing the message twice
00943                                 if (noWrite!=1)
00944                                 {
00945                                         PrintWarning("not writing data files\n");
00946                                 }
00947                                 noWrite=1;
00948                         }
00949                         if (0==strcmp(argv[i]+1,"q"))
00950                         {
00951                                 done=1;
00952                                 VERBOSE=-1;
00953                         }
00954                         if (0==strcmp(argv[i]+1,"v"))
00955                         {
00956                                 done=1;
00957                                 VERBOSE=1;
00958                         }
00959                         if (0==strcmp(argv[i]+1,"V"))
00960                         {
00961                                 done=1;
00962                                 VERBOSE=2;
00963                         }
00964                         // sismo des écoles
00965                         if (0==strcmp(argv[i]+1,"eduseis"))
00966                         {
00967                                 done=1;
00968                                 fileNameOptions|=EDU_FILE_NAME;
00969                         }
00970                         // name
00971                         if (0==strcmp(argv[i]+1,"n"))
00972                         {
00973                                 done=1;
00974                                 channelNameNumber=1;
00975                         }
00976                         // overwrite
00977                         if (0==strcmp(argv[i]+1,"o"))
00978                         {
00979                                 done=1;
00980                                 overWrite=1;
00981                         }
00982                         // force name options
00983                         if (0==strcmp(argv[i]+1,"nameoption"))
00984                         {
00985                                 done=1;
00986                                 if (i+1>=argc)
00987                                 {
00988                                         goto error_not_enough_arguments;
00989                                 }
00990                                 i++;
00991                                 sscanf(argv[i],"%d",&forceNameOptions);
00992                         }
00993                         // force name
00994                         if (0==strcmp(argv[i]+1,"O"))
00995                         {
00996                                 done=1;
00997                                 if (i+1>=argc)
00998                                 {
00999                                         goto error_not_enough_arguments;
01000                                 }
01001                                 i++;
01002                                 strncpy(forceName,argv[i],127);
01003                                 forceName[127]=0;
01004                                 overWrite=1;
01005                         }
01006                         // request for information log
01007                         if (0==strncmp(argv[i]+1,"log",3))
01008                         {
01009                                 done=1;
01010                                 logInfo=1;
01011                         }
01012                         // force the complete scan
01013                         if (0==strcmp(argv[i]+1,"scanall"))
01014                         {
01015                                 done=1;
01016                                 scanAll=1;
01017                         }
01018                         // no cache creation
01019                         if (0==strcmp(argv[i]+1,"nocache"))
01020                         {
01021                                 done=1;
01022                                 noCache=1;
01023                         }
01024                         // force the use of the local cache
01025                         if (0==strcmp(argv[i]+1,"localcache"))
01026                         {
01027                                 done=1;
01028                                 localCache=1;
01029                         }
01030                         // clear the cache
01031                         if (0==strcmp(argv[i]+1,"clearcache"))
01032                         {
01033                                 done=1;
01034                                 // clear the cache
01035                                 OpenCacheFileRead(NULL, -2);
01036                                 exit(0);
01037                         }
01038                         // cut dt on reset
01039                         if (0==strcmp(argv[i]+1,"onedt"))
01040                         {
01041                                 done=1;
01042                                 cutDtOnReset=0;
01043                         }
01044                         // pulsefilter
01045                         if (0==strcmp(argv[i]+1,"nopulsefilter"))
01046                         {
01047                                 done=1;
01048                                 cutDtOnReset=1;
01049                                 pulseFilter=0;
01050                         }
01051                         // stream list
01052                         if (0==strcmp(argv[i]+1,"stream"))
01053                         {
01054                                 if (inputChannelMask!=0x00ffffffLL)
01055                                 {
01056                                         goto error_select_both;
01057                                 }
01058                                 done=1;
01059                                 if (i+1>=argc)
01060                                 {
01061                                         goto error_not_enough_arguments;
01062                                 }
01063                                 i++;
01064                                 streamList=argv[i];
01065                         }
01066                         // auxiliary channels
01067                         if (0==strcmp(argv[i]+1,"aux"))
01068                         {
01069                                 auxiliaryMask=0xffff000000LL;
01070                                 done=1;
01071                         }
01072                         // channel list
01073                         if (0==strcmp(argv[i]+1,"chan"))
01074                         {
01075                                 if (streamList!=NULL)
01076                                 {
01077                                         goto error_select_both;
01078                                 }
01079                                 done=1;
01080                                 if (i+1>=argc)
01081                                 {
01082                                         goto error_not_enough_arguments;
01083                                 }
01084                                 i++;
01085                                 if (ListToMask(argv[i],&inputChannelMask)<0)
01086                                 {
01087                                         exit(0);
01088                                 }
01089                                 channelMask=inputChannelMask;
01090                         }
01091                         // select tag
01092                         if (0==strcmp(argv[i]+1,"tag"))
01093                         {
01094                                 done=1;
01095                                 if (i+1>=argc)
01096                                 {
01097                                         goto error_not_enough_arguments;
01098                                 }
01099                                 i++;
01100                                 strncpy(onlyTag,argv[i],8);
01101                                 onlyTag[8]=0;
01102                         }
01103                         // force station name
01104                         if (0==strcmp(argv[i]+1,"sta"))
01105                         {
01106                                 done=1;
01107                                 if (i+1>=argc)
01108                                 {
01109                                         goto error_not_enough_arguments;
01110                                 }
01111                                 i++;
01112                                 strncpy(manualStationName,argv[i],15);
01113                                 manualStationName[15]=0;
01114                         }
01115                         // use TDB
01116                         if (0==strcmp(argv[i]+1,"tdb"))
01117                         {
01118                                 done=1;
01119                                 if (i+1>=argc)
01120                                 {
01121                                         goto error_not_enough_arguments;
01122                                 }
01123                                 i++;
01124                                 strncpy(tdbName,argv[i],sizeof(tdbName)-1);
01125                                 tdbName[sizeof(tdbName)-1]=0;
01126                         }
01127                         // timesel: ts
01128                         if (0==strcmp(argv[i]+1,"ts"))
01129                         {
01130                                 timesel=1; // a time selection is required
01131                                 done=1;
01132                                 if (i+1>=argc)
01133                                 {
01134                                         goto error_not_enough_arguments;
01135                                 }
01136                                 i++;
01137                                 if (1!=sscanf(argv[i],"%d",&timeSegment))
01138                                 {
01139                                         goto error_syntax_error;
01140                                 }
01141                                 if (timeSegment<10)
01142                                 {
01143                                         PrintError("time segments must "
01144                                                         "be longer than "
01145                                                         "10 seconds\n");
01146                                         goto error_syntax_error;
01147                                 }
01148                                 cmdLineWindow=1;
01149                                 beginWindow=10;
01150                                 endWindow=1<<31;
01151                         }
01152                         // minSamplesPerFrame
01153