-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·3812 lines (2915 loc) · 160 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
* *
* *
* *
* *
* *
* *
***************************************************************************/
//tsmp -ascii -tc -abst 0 -dateformat ISO -start_date 2009-07-02T14:49:48 -stop_date 2009-07-02T14:49:50 053C44XA.ats
// tsmp -ascii -tc -abst 0 -dateformat ISO -isostart 2009-07-02T14:49:48 -isostop 2009-07-02T14:49:50 053C44XA.ats
//
/*! \mainpage TSMP - Time Series Manipulation
*
* \section intro_sec Introduction
*
* A command line driven data maipulation program
*
* \section install_sec Installation
/.configure
make
*
* \subsection step1 Step 1: FFTW
*
* etc...
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <QCoreApplication>
#include <iostream>
#include <fstream>
#include <sstream>
#include <ctime>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <valarray>
#include <cctype> // try to find out wheter your machine is
// little (INTEL) or big endian (motorola, hp)
using namespace std;
#include "tsheader.h"
#include "atsheader80.h"
#include "fubheader.h"
#include "mtxcal.h"
#include "fgs01cal.h"
#include "fgs02cal.h"
#include "ltscal.h"
#include "efp05cal.h"
#include "emimt24header.h"
#include "emisyscal.h"
#include "emi_bfcal.h"
#include "adu06cal.h"
#include "adu07cal.h"
#include "mfs07cal.h"
#include "plaincal.h"
#include "tsdata.h"
#include "eDateTime.h"
#include "my_valarray.h"
#include "string_utils.h"
#include "atmfile.h" // atm class for mapros
#include "spectra.h" // my spectral classes
#include "coherency.h"
#include "mtstd.h" // ... maybe in the future....
#include "date_utils.h"
#ifdef myMySQL
#include "mysql_simple_vector.h"
#include </usr/include/mysql++/mysql++.h>
#include <atsfilename>
using namespace mysqlpp;
#endif
#ifdef myGSL
#include <errno.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_rng.h>
#endif
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
if (argc < 2 ) {
cerr << "\nProgVer " << "1.01 Qt" << endl;
// do some checks for the console message
#if SIZEOF_LONG == 4
cerr << "size of long is ok (32 bit)" << endl;
#endif
#if SIZEOF_LONG == 8
cerr << "size of is NOT OK (64 bit instead of 32) " << endl;
cerr << "atsview will not run" << endl;
#endif
#if SIZEOF_DOUBLE == 8
cerr << "size of double is ok and 8 bytes" << endl;
#endif
#if SIZEOF_DOUBLE == 10
cerr << "size of double is PERHAPS NOT OK! and 10 bytes" << endl;
#endif
#if SIZEOF_DOUBLE == 12
cerr << "size of double is PERHAPS NOT! OK and 12 bytes" << endl;
#endif
#if SIZEOF_DOUBLE == 16
cerr << "size of double is PERHAPS NOT! OK and 16 bytes" << endl;
#endif
#ifdef __CYGWIN__
cerr << "using CYGWIN " << endl;
#endif
#ifdef __MINGW32__
cerr << "using MINGW32 " << endl;
#endif
#ifdef __WIN32__
cerr << "using WIN32 environment" << endl;
#endif
#if SIZEOF_LONG > 4
cerr << "size of is NOT OK (64 bit? instead of 32) " << endl;
cerr << "program will not be able to read the 32 bit values from ats file" << endl;
cerr << "using int as type" << endl;
return EXIT_FAILURE;
#endif
#if SIZEOF_DOUBLE > 8
cerr << "size of double is not ok greater than 8 bytes" << endl;
#endif
/***************************************************************************
* *
* display command line options *
* *
* *
* *
* *
***************************************************************************/
cerr << "\nusage: " << argv[0] << " arguments infile\n";
cerr << "\nex.: " << argv[0] << " -start 4096 -use 1024 001C02XB.ats";
cerr << "\nselects file 001C02XB.ats, skips first 4096 values(0...4095) and writes 1024 to disk\n";
cerr << "\nex.: " << argv[0] << " 0 all 001C02XB.ats dumps the complete file\n";
//cerr << " -all reads the complete file\n";
cerr << " -chan reads a channel from multi channle file; -chan 0 2 4 reads the according channels\n";
cerr << " -run nn provides a new run number; e.g. for conversion of time series or other output\n";
cerr << " -add 5.2 adds 5.2 mV to atsfile \n";
cerr << " -add mean removes the mean of the time series\n";
cerr << " -mul 2.5 multiplies atsfiles with given value; can be used together with -corr -wrh or in ascii output without changing the ats file\n";
cerr << " if you use -mul -1 you will change the polarity of the electrical / magnetical field\n";
cerr << " -mul mean devides the time series by its mean\n";
cerr << " use -corr -wrh -time_s 13 to make changes permanent in the atsfile\n";
cerr << " -gensign generates artificial signal (undocumented yet)\n";
cerr << " -gen_rand" << endl;
cerr << " -gen_sin freq freq .. freq" <<endl;
cerr << " [-with_rectpulse start stop dvalue] " << endl;
cerr << " -gen_rand_gsl mix1 ... mix5; e.g. 1 2 11.31 22.61 1 for coil or 1 2 0.0014142136 0.0028284272 1 for a fluxgate" << endl;
cerr << " -cut_int use this for reading 32bit integer; use -start -use/-stop -run xx -cut_int for shortening the timeseries without any processing" << endl;
cerr << " -nodata atsfile will not be converted into ascii, data section is not read\n";
cerr << " -ascii writes ascii data of time series and converted timeseries (especially from despike, destep, stddev)" << endl;
cerr << " which will write their results into ascii files but ALSO posibbly to atm files" << endl;
cerr << " -ts2mysql [truncate, truncate_first] will write time series into sql data base ... TESTING VERSION " << endl;
cerr << " -ncal indicates wether this is the first call of tsmp or not; needed for truncate options and online processing" << endl;
cerr << " -ascii -back -wl .. etc. writes the timeseries data after FFT application and NOT the raw data\n";
cerr << " -nspw data section is read in but not written to disk; useful if you calculate spectra and do not need conversion\n";
cerr << " -start 4096 skips the first 4096 samples of the atsfile\n";
cerr << " -slice 2 use second slice if available, the start sample 4 if the start sample of 2. slice in this case\n";
cerr << " -isostart 2009-12-24T16:34:00.5 try to start reading at this time\n";
cerr << " -use 16384 reads 16384 samples after given start point\n";
cerr << " -stop 20000 reads from start to stop defined samples from the atsfile\n";
cerr << " -isostop 2009-12-24T18:34:01.5 try to stop reading at this time\n";
cerr << " -last 1024 reads the last 1024 points from the data file\n";
cerr << " -samples 3000 -corr -wrh set samples inside header (better do not do this)\n";
cerr << " -wl 2048 uses 2048 point for the FFT; activates spectra calculations automatically\n";
cerr << " -wl 1 will use all given points for the fft window\n";
cerr << " this can only be used together with -back in order to get inverted time series\n";
cerr << " the spectra itself is zero padded and is not a \"true\" spectrum";
cerr << " -rect use a rectangular fft window instead of Hanning (default)\n";
cerr << " -trf auto enable automatically reading of the transfer function of the used sensor as specified in the header\n";
cerr << " in the log file you find Sensor Type; if MFS05 the program tries to read mfs05.trf and so on\n";
cerr << " sensor cal file name \"SENSOR.CAL\" in the header is a template and not a valid entry\n";
cerr << " otherwise the sensor cal file name will be read\n";
cerr << " -trf theo uses the built in transfer functions of the spectra module\n";
cerr << " -trf hw05on uses a measured transfer function with chopper on of the spectra module\n";
cerr << " -trf hw05off uses a measured transfer function with chopper off of the spectra module\n";
cerr << " -trf hw05auto uses a measured transfer function with chopper auto of the spectra module\n";
cerr << " -trf test.trf reads the specified file with 3 columns; 1. frequency, 2. amplitude, 3. phase in degree (not radians)\n";
cerr << " -trf1 a.trf -trf2 b.trf reads both file in the two files only mode (like with atsadd for example)\n";
cerr << " -dump_trf writes a control file for sensor, system and other calibration to disk\n";
cerr << " -latlon 52 09 12.4 N 9 45 22.6 E -corr -wrh corrects the latitude and longitude\n";
cerr << " -elev 56 -corr -wrh corrects the elevation with +56 centimeters\n";
cerr << " -lsbval [-corr -wrh] sets a new LSB \n";
cerr << " -fliplsbval [-corr -wrh] multiplies the lsb by -1 = change of polarity of the channel\n";
cerr << " -adbser 34 -corr -wrh sets the ADB board serial number to 34\n";
cerr << " -aduser 14 -corr -wrh sets the ADU serial number to 14\n";
cerr << " -sensser 114 -corr -wrh sets the Sensor serial number to 114\n";
cerr << " -samplefreq 2 -corr -wrh set the sampling frequency to 2 Hz inside the atsheader\n";
cerr << " -datetime 12346 -corr -wrh set the absolute UNIX time stamp of the header\n";
cerr << " -time_s seconds shifts the start time in secons\n";
cerr << " -gmtoff 3600 -corr -wrh corrects the UTC (former GMT) offset to your local time with +3600 s\n";
cerr << " -utctogps offset between UTC and GPS clock (2015 = 16 secs)\n";
cerr << " -sensorcal MFS07.trf -corr -wrh changes the sensor cal file name in the header; use the DOS 8.3 format\n";
cerr << " -systemcal mylogger.trf -corr -wrh changes a possible calibration file for the datalogger\n";
cerr << " -sensor_type EFP05 -corr -wrh changes the sensor name in the header; max. 6 char\n";
cerr << " -system_name ADU06, MMS03e (-corr -wrh) sets the system name \n";
cerr << " -channel_type EX -corr -wrh changes the channel type in the header; atsview makes use of this information\n";
cerr << " -corr activates the header correction mode \n";
cerr << " -wrh writes the correction permant to the file; with -corr you can simulate the the corrections\n";
cerr << " -diplen 100 -corr -wrh changes dipole length to 100 metersn";
cerr << " -resis 1000 -corr -wrh changes the contact resistivity to 1000 ohm/m\n";
cerr << " -angle 90 -corr -wrh changes the angle to 90 degress\n";
cerr << " -spos x1 y1 z1 x2 y2 z2 -corr -wrh changes the coordinates of the sensor position\n";
cerr << " -spos 100 n n 0 n n -corr -wrh changes the coordinates of x1 and x2 only\n";
cerr << " -mrd 9 changes the reference meridian to 9 deg East\n";
cerr << " -tc activates the time column in the ascii output; if activated you get a 2 columne file with time and values\n";
cerr << " -abst nn -tc activates the absolute time (UNIX format, secs. since 1970) in your time column\n";
cerr << " nn shifts this time; use -abst -1000000 for example to lower the numbers in your time column\n";
cerr << " when you simply want to display almost parallel time series and the absolute date is not needed in the time column\n";
cerr << " -atsadd adds the given atsfile into the last given new atsfile\n";
cerr << " -atssub s.o.\n";
cerr << " -atsmul .. \n";
cerr << " -atsdiv .. \n";
cerr << " -spwadd nn adds a value to the spectral output file\n";
cerr << " -swpmul nn multiplies value to the spectral output file\n";
cerr << " -median nn returns a median spectra if nn = 0 and uses +-10% of all value AROUND the median if -median 10\n";
cerr << " -median_coh nn returns median processing for coherencies; use small values like 0.1\n";
cerr << " -rda sample_freq column year month day hour min sec" << endl;
cerr << " example : -rda 512 1 2000 12 24 9 15 0" << endl;
cerr << " for a file recorded at Christmas 2000 at breakfast time 9:15 " << endl;
cerr << " your 024C01XC.dat will be converted in 024C01XC.ats " << endl;
cerr << " hence that MAPROS et al using the filename!! to determine sample frequency, run number, E/H channel" << endl;
cerr << " -atsoutfile output filename for ascii conversion to ats" << endl;
cerr << " -merge merges all outputfiles in one ascii file" << endl;
cerr << " can not be used with parameters which expect an output filename like atsadd and so on or -nodata" << endl;
cerr << " -out_dir /wrk/mt/ directs the output to this directory; useful if data is on a CDROM " << endl;
cerr << " -s_scale [f, sqr(f), sqrt(f), 1/f, 1/sqr(f), 1/sqrt(f)] scales the foward fft; -scale f means spectra is divided by f!" << endl;
cerr << " -back [scale_f || scale_f2] enables an inverse FFT [devide by f || devide by f square]" << endl;
cerr << " -fil 32 [-raster -1] or -fil 2, 4, 8, 25 decimates the timeseries with given factor" << endl;
cerr << " -filw 32 [-raster -1] or -filw 2, 4, 8, 25 decimates the timeseries with given factor and writes new atsfile" << endl;
cerr << " -nmtx violates the metronix name convention and appends 32x or 4x and so on for the filtred bands" << endl;
cerr << " -nosystrf disables the automatic calibration of ADB boards for HF or calibration in general" << endl;
cerr << " -fn2 {1,2, -1, -2} " << endl;
cerr << " -ll 5 -ul 20 cuts the first 5 (low) and last 20 (high) points of the spectal output" << endl;
cerr << " -destep int step_len double step_height int relaxation double step_skewness; refer to manual" << endl;
cerr << " tries to fix jumps in the eletrical field caused by poor connections; try 40 0.2 1 0.8 for example" << endl;
cerr << " -despike shoulder_length spike_height relaxation skewness; refer to manual" << endl;
cerr << " tries to extenuate spike caused by electric fences etc.; try 10 0.1 6 1.2 for example" << endl;
cerr << " -dstw or -dspw will destroy your data (overwrite) together with the destep or despike option" << endl;
cerr << " use here -nspw for avoiding ascii output and -tc to plot ascii and spike/step indices together" << endl;
cerr << " -cat new_run_number <file1.ats> <file2.ats> concatenates 2 atsfiles to a third with increased run number" << endl;
cerr << " -stddev min_fac max_fac ovr; ovr overlapping of windows in pts; try together with atm and mapros" << endl;
cerr << " -atm new | merge | cat | use ; [-run nn] new creates or overwrites an existing atm file; merge puts an existing together" << endl;
cerr << " fil expects a file .atm.cat with an existing selection done by -cat option of this program\n";
cerr << " -utm calculates UTM cooridates; togther -mrd n a certain meridian can be forced\n";
cerr << " -gk calculates Gauss Krueger cooridates; togther -mrd n a certain meridian can be forced\n";
cerr << " -sync automatically forces all files to use the same start time; can be important for remote referencing\n";
cerr << " -sync2 .. same as above; stop time also synchronised\n";
cerr << " -synctime 1002384003 forces all file to start at given .putdatetime(), UNIX time format required\n";
cerr << " -detrend removes a trend of the time series\n";
cerr << " -wtrend removes a trend for each given window (option -wl) and if -rect is given\n";
cerr << " -dateformat ISO -tc -abst nn ; write ISO8601 for XMGRACE as x-axis; tick x-axis format inside xmgrace\n";
cerr << " -overwrite overwrites existing atsfile " << endl;
cerr << " -resample new_sample_freq new sampling frequency " << endl;
cerr << " -raster nn set start times of filtred band to nn second raster\n";
cerr << " -calib xx generates a some calibration data, phase multiplied with xx\n";
cerr << " -ccf cstartx cstarty cshifts tohether -wl; refer to manual" << endl;
cerr << " -pipe pipes result to std out " << endl;
cerr << " -lin_conv filter_length frequencies - try a linear convolution; try lin_conv 1024 16.666 50 150" << endl;
cerr << " -sst n sub stacks in time dommian; -sst 4 -wl 1024 calculates 4 sub stacks of 1024 points in time domain\n";
cerr << " -noscale_e turns off scaling for E-Field into mv/km\n";
cerr << " -wbin [float] writes data as binary; output is double (8 byte); if float use 4 byte\n";
cerr << " -write_trf writes all interpolated transfer functions to disk - avoid to use with -wl 1 (very big file sizes!)\n";
cerr << " -ovr ovoerlapping in points\n";
cerr << " -nogrid turns off automatic adjustment of start time to a grid time\n";
cerr << " -mt for magnetotellurics\n";
cerr << " -coh for calulating coherencies - best use with sync2 option!\n";
// cerr << " -conv2ats \n";
cerr << " -prz 0.2 gives a parzen radius of 0.2; shoulb be 0.05 ... 0.1, 0.2 ... 0.5\n";
cerr << " -firfil 471 300 800 0 filters a band pass \n";
cerr << " example for 4096Hz and 8193 coeff: 8193 0 1000 0 is low pass, 8193 100 4096 0 is high pass, 8193 100 1000 0 is bandpass, 8193 70 40 0 is notch / bandstop\n";
cerr << " -online " << endl;
cerr << " -db_database tsmp connects to MySQL database tsmp" << endl;
cerr << " -db_host localhost connects to MySQL on the computer where tsmp is running" << endl;
cerr << " -db_password secret connects to MySQL with password \"secret\"" << endl;
cerr << " -db_user berni connects to MySQL database as user berni" << endl;
cerr << " -extra_scale divides by [f, sqr(f), sqrt(f) , 1/f, 1/sqr(f), 1/sqrt(f)] " << endl;
cerr << " -xmul -xadd : multiply or add a complex to the complex raw spectra; give TWO!! nums at command line!!" << endl;
cerr << " -flist default.lst (give filename) use only frequencies from this file for spectra" << endl;
cerr << " -ascii_sst write sub stacked time slices" << endl;
cerr << " -set_xmlheader try to set a new xml filename for filtered files (not enabled yet)" << endl;
cerr << " Version 14 August 2016, sclice version / 64bit possibly" << endl;
cerr << "\n\n";
return EXIT_FAILURE;
}
// above we gave the info; here I must stop!
// set ctime function to expect a int which represents GMT or UTC without summer time
std:char myenv[80]="TZ=GMT0GMT";
if (!putenv(myenv))
tzset();
else
cerr << "no environment free; times will be interpreted wrong" << endl;
/***************************************************************************
* *
* declare all variables *
* *
* *
* *
* *
***************************************************************************/
stringstream convert_num;
unsigned int nargs, nfiles, nspw = 0;
unsigned int l, nm = 0, i, j, loops = 1, reduction = 0;
// vaiables for setting addition, subtraction, multiplication, division, concatenate,
// correction, time cols, no ascii output and filename two active
unsigned int lc_filter_len = 0;
size_t fir_order = 0; /*! order (length) of the FIR filter*/
double cutlow = 0; /*! cut off frequency low*/
double cuthigh = DBL_MAX; /*! cut off frequency high*/
// read ascii file
unsigned int asc_col = 0; // which columne of file - starting with 0
unsigned short int chan_no = 0; // channel number
// command line option control
bool deselect_samples = false;
bool select_samples = false;
int corr = 0; /*! header correction on/off*/
int write_header = 0; /*! header correction writen to header -> permanent changes */
int raster = 0; /*! sync time series to a given raster - e.g. lowest sampling period*/
int nogrid = 0; /*! if nogrid == 1 filter regardless of start time */
int dump_trf = 0; /*! writes ascii transfer functions to disk which have been applied to the spectra*/
int gensign = 0, rda = 0; /*! genrate signal, read ascii */
double gen_rand = DBL_MAX; /*! generate standard random singnal and scale */
int gen_sin = 0; /*! generate sinus frequencies */
int gen_rect = 0; /*! generate rectangulars */
int gen_rand_gsl = 0; /*! take gsl random generator */
unsigned int ascii_sst = 0; /*! wite sub stacked time slices */
unsigned int ascii_sst_count = 0; /*! wite sub stacked time slices */
unsigned int destep = 0, dstw = 0; /*! activate destep and destep with over-write*/
unsigned int cut_int = 0; /*! cut integers directly from ats file */
unsigned int despike = 0, dspw = 0; /*! activate despike and despike with over-write*/
unsigned int rmtrend = 0; /*! use a global detrend (e.g. fluxgate data)*/
unsigned int wdetrend = 0; /*! use a local detrend, e.g. for each window together with -rect*/
unsigned int back = 0; /*! backwards FFT*/
unsigned int calc_median = 0; /*! activate median processing for FFT*/
unsigned int median_coh = 0; /*! and coherency*/
unsigned int lin_conv = 0; /*! activate linear convolution*/
unsigned int mc = 0; /*! *.ats files will be merged into ONE .dat file*/
unsigned int site = 0; /*! read a complete ats set according to a site or 5 channel GOE file*/
unsigned int conv = 0; /*! convert GOE file into ats files*/
unsigned int calc_utm = 0; /*! calculate UTM coordinates (use refmed!)*/
unsigned int calc_gk = 0; /*! calculate Gauss Krueger must use meridian*/
unsigned int last_century = 0; /*! assume year 2000+ for goe files*/
unsigned int allchan = 0; /*! total number of channels used*/
unsigned int sync = 0; /*! read all files and start at the same absolute time*/
unsigned int sync2 = 0; /*! same for stop times if required*/
unsigned int overwrite = 0; /*! allow atsview to overwrite existing data*/
unsigned int do_ccf = 0; /*! compute cross correlation (slow)*/
unsigned int resample = 0; /*! if sampling freq is > 1 Hz (e.g 64Hz) and you want 25 Hz*/
unsigned int noscale_e = 0; /*! otherwise E-Field set to mv/km (divided by dipole length)*/
unsigned int usefloat = 0; /*! try to use float as binary output instead of double*/
unsigned int wbin = 0; /*! write all channels subsequently a1 b1 c1 a2 b2 c2 ...*/
unsigned int write_trf = 0; /*! writes all transferfunctions to disk*/
unsigned int mt = 0; /*! magnetotellurics*/
unsigned int coh = 0; /*! coherency between two channels */
unsigned int write_atm = 0; /*! we can only write the atm file in total so -all must have been used */
unsigned int firfil = 0; /*! applies a finite response filter (lp, hp, bad pass band stop) to time series*/
size_t firfil_reduct = 0; /*! possible reduction with this fir filter */
unsigned int use_flist = 0; /*! write only these frequencies */
int set_xmlheader = 0; /*! try to write a new xml header name after filtering */
long int UTCGPSOffset = 0; /*! offset between UTC and GPS - mostly never used */
size_t start_rectpulse = 0; /*! start sample of rect pulse (together with gensign) */
size_t stop_rectpulse = 0; /*! stop sample of rect pulse (together with gensign) */
double rectpulse_val = 0.; /*! rect pulse value (together with gensign) */
string flist_name; /*! read frequenvies for spectra output */
valarray<double> flist;
int invfft_zeropadding = 0; /*! prepare for full inversion - e.g. to get real ts data from coils */
vector<long int> sync_dates_start, sync_dates_stop; /*! contains the absolute start, stop time data*/
vector<size_t> vstart, vsamples, vtotalsmpls; /*! contains the individual start/used/total samples for sync option*/
unsigned long int synctime = 0; /*! for given synctime; together with -sync*/
vector<double> gensign_params; /*! list of frequencies for sinus generator */
vector<double> noise_mix; /*! mix levers of noise for mt noise; e.g 4 numbers are required */
vector<string> extra_scale; /*! strings with extra scales for the forward fft .. like f or sqrt(f) etc */
vector<unsigned int> chan(0,1);
string run ="", /*! read run number from command line*/
dateformat, /*! can be set to ISO 8601*/
ascii_outget_type; /*! types are data, spikes, step, stddev*/
// file handling
int fn2 = 0;
int last_file_is_result = 0; /*! if output results into a NEW ats file*/
unsigned int do_atm = 0; /*! 0 no, 1 create /overwrite; 2 merge; 3 merge from a file .atm.cat*/
vector<bool> newselect; /*! IO vector for atm files*/
// values for changing header entries
// general: where we have to SET a variable we use INT_MAX NOT to do it
// where we have to add, multiply or CHANGE we use 0 (ZERO) not to do it.
// position
int log = INT_MAX; /*! readable coodinates, grad */
int lom = INT_MAX;
int lag = INT_MAX;
int lam = INT_MAX;
double las = DBL_MAX;
double los = DBL_MAX;
string LatH = "x";
string LonH = "x";
int ref_med = INT_MAX; /*! INT_MAX means: don't want to change*/
// time
long time_sec = LONG_MAX; /*! shift ascii file output with nn seconds;*/
double iso_sec = DBL_MAX; /*! shift ISO date - possible duble values!*/
long datetime = LONG_MAX; /*! set absolute time of header */
size_t samples = LONG_MAX; /* will be used for changing samples inside header */
// also used to shift header .putdatetime() entry
// most common for the 13s problem
long gmt_offset = LONG_MAX; /*! seconds from GMT; Berlin = 3600s at winter time*/
double d_start = DBL_MAX, d_stop = DBL_MAX; /*! correction time for start and stop*/
unsigned relative_time = 1; /*! do NOT use the long date in ascii time series output*/
long time_offset = 0; /*! together with -abst you can remove leading 10+e9*/
// seconds and so on; abst sets relative_time to 0
double parzen = 0.; /*! parzen radius */
double SampleFreq = DBL_MAX;
double rsmpl_freq = DBL_MAX; /*! new sampling frequency from resample option*/
double elevation = DBL_MAX; /*! new elevation in meter */
double lsbval = DBL_MAX; /*! new lsb value */
bool fliplsbval = false; /*! multiply LSB with -1 */
tm read_t; /*! for using time functions in main*/
time_t ats_time = LONG_MAX; /*! for using time functions in main and read ascii*/
// E-field
double angle = DBL_MAX, diplen = DBL_MAX; /*! DBL_MAX means: don't want to change*/
double eprobe_res = DBL_MAX, dcoffset = DBL_MAX;
valarray<double> senspos(DBL_MAX, 6);
// x1, y1, z1, x2, y2, z2; senspos[i] = DBL_MAX means no changes
// ADU specific
string SerNoADU; /*! that is the system_id */
string SerNoADB; /*! that is the board_id */
string SensorNo; /*! that is the sensor id */
string achxmlheader; /*! info for haeder */
string comments; /*! comments */
string meas_type; /*! MT, AMT, CSAMT, CSEMM etc. */
string atsoutfile; /*! ats filename used for conversion from ascii to ats */
// used for changing header entries
string channel_type, sensor_type; /*! Hx, Hy, Hz, Ex, Ey; MFS06, FGS01 etc.*/
string system_name; /*! want to change the system name ADU06, MMS03e */
// string are empty and shoud stay so except you want
// change header entries
// output
int nodata = 0, ascii = 0; /*! no data section, no ascii output*/
int ts2mysql = 0; /*! write time series to mysql db*/
int ncall = 0; /*! counter for external calls - eg. fro truncate options */
int truncate = 0; /*! truncate corresponding tables*/
int tc = 0; /*! time column in ascii output on/off*/
int nspc = 0; /*! supress all spectr calculation */
// database handling
string db_database = "tsdata"; /*! database name */
string db_host = "localhost"; /*! database host; eg. localhost */
string db_user = "tsdata"; /*! database login */
string db_password = "tsmptsdata"; /*! database password */
// data handling
size_t start = 0, stop = 0, used_samples = 0, last_samples = 0, slice = 0;
QString isostart;
QString isostop;
eDateTime edate;
eDateTime start_date;
eDateTime stop_date;
// data functions (also for activating the function if value is not 0
int atsadd = 0, atssub = 0, atsmul = 0, atsdiv = 0, atscat = 0; /*! adding ... ats files TOGETHER*/
int spectra_add = 0, spectra_sub = 0, spectra_mul = 0, spectra_div = 0; //!< adding spectra together
double add
= 0, mul = 0; /*! adding a number to the data vector*/
// transfer functions
unsigned int auto_trf = 0, theo_trf = 0, hw_trf = 0;
double calib = 0;
string sensorcalfile; /*! leave empty*/
string systemcalfile; /*! leave empty*/
// filtering
string nmtx, bandstr; /*! nmtx will violate the mtx naming convention*/
// banstring will attach a 4 or 32
unsigned int write_ats = 0; /*! write filtred values to disk*/
int filter_length = 0; /*! filter length will cause time offset after filtering*/
// data handling and FFT
unsigned int hanning = 1; /*! hanning window is defaultb instead of recangular*/
unsigned int no_dc_fft = 1; /*! skip the dc-part of FFT; do not use with FFT-BACK*/
unsigned int nosystrf = 0; /*! 0 = activate internal transfer function for ADU-06*/
int inverse_trf = 0; /*! instead of dividing multiply with transfer function */
unsigned int wl = 0; /*! window length of FFT; also used for activating FFT section*/
unsigned int ul = 0, ll = 0; /*! upper limit lower limit of ascii ouput of FFT*/
/*! ll, ul 20 = skip the first, last 20 points from output*/
unsigned int sst = 0; /*! sub stacks in time domain*/
unsigned int scale_f = 0; /*! scale spectra by /f before backwards time series conversion*/
size_t ccf_startx = 0, ccf_starty = 0; /*! starting points for cross correlation*/
size_t ccf_shifts = 0; /*! how many ccf's will be calculted */
double range = 0, range_coh = 0; /*! ranges around median*/
double spwadd = 0, spwmul = 1; /*! adding and multiplying spectral OUTPUT files (not the data itself!)*/
complex<double> xadd = complex<double>(0,0);
complex<double> xmul = complex<double>(0,0);
// spwadd -90 subtracts 90 degrees for expample from phase
// spwmul 180./M_PI makes rad to grad if phase was selected
// hence that this applies to all spectra files....
// time series processing, destep, despike, std. dev. proc
size_t ovr = 0; /*! overlay of windows for std deviation */
unsigned int step_len = 0, shoulder_len = 0, relaxation = 0, do_stddev = 0;
string new_run_number;
double step_skewness = 0, step_height = 0, spike_height = 0, spike_skewness = 0,
min_stddev = DBL_MAX, max_stddev = DBL_MAX;
double max_min = DBL_MAX; /*! used for max min analysis */
size_t max_min_length; /*! length of segment to test */
valarray<double> vx, vy, vz, ccfxy;
string fname, f2name, temp_str, out_dir, my_dir;
string trf_file, trf_file1, trf_file2;
vector<double> lc_target_f;
/***************************************************************************
* *
* *
* scan comand line options *
* *
* *
* *
***************************************************************************/
l = 1;
while (argc > 1 && (l < unsigned(argc)) && *argv[l] == '-') {
if (!strcmp(argv[l], "-all")) {
used_samples = UINT_MAX;
} else if (!strcmp(argv[l], "-overwrite")) {
overwrite = 1;
} else if (!strcmp(argv[l], "-chan")) {
chan.resize(0);
++l;
// isdigit
while (!strstr(argv[l], "-") && !strstr(argv[l], ".")) {
chan.push_back(atoi(argv[l]));
++l;
}
--l;
} else if (!strcmp(argv[l], "-conv")) {
conv++;
} else if (!strcmp(argv[l], "-max_min")) {
max_min = atof(argv[++l]);
max_min_length = atoi(argv[++l]);
} else if (!strcmp(argv[l], "-run")) {
run = argv[++l];
// } else if (!strcmp(argv[l], "-mt")) {
// mt = 1;
// } else if (!strcmp(argv[l], "-last_century")) {
// last_century = 1;
} else if (!strcmp(argv[l], "-raster")) {
raster = atoi(argv[++l]);
} else if (!strcmp(argv[l], "-nogrid")) {
nogrid = 1;
} else if (!strcmp(argv[l], "-calib")) {
calib = atof(argv[++l]);
} else if (!strcmp(argv[l], "-cut_int")) {
cut_int = 1;
noscale_e = 1;
} else if (!strcmp(argv[l], "-select")) {
select_samples = true;
} else if (!strcmp(argv[l], "-deselect")) {
deselect_samples = true;
// } else if (!strcmp(argv[l], "-prz")) {
// parzen = atof(argv[++l]);
} else if (!strcmp(argv[l], "-nspc")) {
nspc = 1;
} else if (!strcmp(argv[l], "-firfil")) {
firfil = 1;
fir_order = atoi(argv[++l]);
cutlow = atof(argv[++l]);
cuthigh = atof(argv[++l]);
firfil_reduct = (unsigned) atoi(argv[++l]);
} else if (!strcmp(argv[l], "-sync")) {
sync = 1;
} else if (!strcmp(argv[l], "-sync2")) {
sync = 2;
sync2 = 1;
} else if (!strcmp(argv[l], "-synctime")) {
sync = 1;
synctime = atol(argv[++l]);
} else if (!strcmp(argv[l], "-add")) {
if (!strcmp(argv[++l], "mean"))
add = DBL_MAX;
else
add = atof(argv[l]);
} else if (!strcmp(argv[l], "-mul")) {
if (!strcmp(argv[++l], "mean"))
mul = DBL_MAX;
else
mul = atof(argv[l]);
} else if (!strcmp(argv[l], "-time_s")) {
time_sec = atol(argv[++l]);
} else if (!strcmp(argv[l], "-iso_s")) {
iso_sec = atof(argv[++l]);
} else if (!strcmp(argv[l], "-spwadd")) {
spwadd = atof(argv[++l]);
} else if (!strcmp(argv[l], "-spwmul")) {
spwmul = atof(argv[++l]);
} else if (!strcmp(argv[l], "-utm")) {
calc_utm = 1;
// } else if (!strcmp(argv[l], "-gk")) {
// calc_gk = 1;
} else if (!strcmp(argv[l], "-ascii_sst")) {
ascii_sst = 1;
} else if (!strcmp(argv[l], "-gensign")) {
gensign = 1;
} else if (!strcmp(argv[l], "-gen_rand")) {
gen_rand = atof(argv[++l]);
} else if (!strcmp(argv[l], "-s_scale")) {
l++;
while ( (l < unsigned(argc)) && (*argv[l] != '-') && !strstr(argv[l], ".ats") ) {
cout << "getting " << argv[l] << endl;
extra_scale.push_back(argv[l++]);
}
l--;
} else if (!strcmp(argv[l], "-gen_rand_gsl")) {
gen_rand_gsl = 1;
l++;
while ( (l < unsigned(argc)) && (*argv[l] != '-') && !strstr(argv[l], ".ats") ) {
cout << "getting " << argv[l] << endl;
noise_mix.push_back(atof(argv[l++]));
// Ex Ey Hx Hy Hz
}
l--;
} else if (!strcmp(argv[l], "-gen_sin")) {
gen_sin = 1;
l++;
while ( (l < unsigned(argc)) && (*argv[l] != '-') && !strstr(argv[l], ".ats") ) {
cout << "getting " << argv[l] << endl;
gensign_params.push_back(atof(argv[l++]));
}
l--;
} else if (!strcmp(argv[l], "-gen_rect")) {
gen_rect = 1;
l++;
while ( (l < unsigned(argc)) && (*argv[l] != '-') && !strstr(argv[l], ".ats") ) {
cout << "getting " << argv[l] << endl;
gensign_params.push_back(atof(argv[l++]));
}
l--;
} else if (!strcmp(argv[l], "-with_rectpulse")) {
start_rectpulse = atoi(argv[++l]);
stop_rectpulse = atoi(argv[++l]);
rectpulse_val = atof(argv[++l]);
} else if (!strcmp(argv[l], "-rect")) {
hanning = 0;
} else if (!strcmp(argv[l], "-nodata")) {
nodata = 1;
// data section of ats is not read
} else if (!strcmp(argv[l], "-ascii")) {
ascii = 1; // data section is written but most ascii output supressed
// data section of ats is not read
} else if (!strcmp(argv[l], "-ts2mysql")) {
ts2mysql = 1;
if (!strcmp(argv[l+1], "truncate")) {
truncate = 1; // clean tables
++l;
}
if (!strcmp(argv[l+1], "truncate_first")) {
truncate = 2; // clean tables
++l;
}
// solution for PHP and using select drop down boxes -> ts2mysql must have a pre-set value
if (!strcmp(argv[l+1], "off")) {
ts2mysql = 0;
++l;
}
if (!strcmp(argv[l+1], "on")) {
ts2mysql = 1;
++l;
}
} else if ((!strcmp(argv[l], "-ncall"))) {
ncall = atoi(argv[++l]);
} else if ((!strcmp(argv[l], "-utctogps"))) {
UTCGPSOffset = atoi(argv[++l]);
} else if ((!strcmp(argv[l], "-lsbval"))) {
lsbval = atof(argv[++l]);
} else if ((!strcmp(argv[l], "-set_xmlheader"))) {
set_xmlheader = 1;
++l;
} else if ((!strcmp(argv[l], "-fliplsbval"))) {
fliplsbval = true;
} else if (!strcmp(argv[l], "-nspw")) {
nspw = 1; // if spectra calculation is activated
// data section is read but not written
// to disk
} else if (!strcmp(argv[l], "-back")) {
back = 1;
++l; // backward FFT
if (!strcmp(argv[l], "scale_f"))
scale_f = 1; // scale back spectra by /f before conversion
else if (!strcmp(argv[l], "scale_f2"))
scale_f = 2; // scale back spectra by /(f*f) before conversion
else
--l;
// } else if (strstr(argv[l], "evaluated iso_s")) {
// start = atoi(argv[++l]);
}
else if (strstr(argv[l], "-start")) {
start = atoi(argv[++l]);
}
else if (strstr(argv[l], "-slice")) {
slice = atoi(argv[++l]);
} else if (!strcmp(argv[l], "-use")) {
used_samples = atoi(argv[++l]);
} else if (!strcmp(argv[l], "-last")) {
last_samples = atoi(argv[++l]);
} else if (!strcmp(argv[l], "-stop")) {
stop = unsigned(atoi(argv[++l]));
stop++; // because of C notation!
}
else if (strstr(argv[l], "-isostart")) {
isostart = argv[++l];
start_date.set_ISOTime(isostart);
}
else if (strstr(argv[l], "-isostop")) {
isostop = argv[++l];
stop_date.set_ISOTime(isostop);
}
else if (!strcmp(argv[l], "-wtrend")) {
wdetrend = 1;
} else if (!strcmp(argv[l], "-wl")) {
wl = unsigned(atoi(argv[++l]));
} else if (!strcmp(argv[l], "-ovr")) {
ovr = unsigned(atoi(argv[++l]));
} else if (!strcmp(argv[l], "-trf")) { // use strcmp because strstr returns true if argv was trf1
if (!strcmp(argv[l+1], "auto")) {
auto_trf = 1; // automatic detection from atsheader, read from file
++l;
} else if (!strcmp(argv[l+1], "theo")) {
theo_trf = 1; // automatic detection from atsheader,
++l; // theoretical cal functio is used
} else if (!strcmp(argv[l+1], "hw")) {
hw_trf = 1; // use cal function of MFS-05 No. 143
++l; // or
} else
trf_file = argv[++l];
//cerr << trf_file << "!!" << endl;
// } else if (!strcmp(argv[l], "-trf1")) {
// trf_file1 = argv[++l];
// auto_trf = 0;
// } else if (!strcmp(argv[l], "-trf2")) {
// trf_file2 = argv[++l];
// auto_trf = 0;
} else if (!strcmp(argv[l], "-dump_trf")) {
dump_trf = 1;
} else if (!strcmp(argv[l], "-out_dir")) {
out_dir = argv[++l];
} else if (!strcmp(argv[l], "-latlon")) {
lag = atoi(argv[++l]);
lam = atoi(argv[++l]);
las = atof(argv[++l]);
LatH = argv[++l];
log = atoi(argv[++l]);
lom = atoi(argv[++l]);
los = atoi(argv[++l]);
LonH = argv[++l];
} else if (!strcmp(argv[l], "-mrd")) {
ref_med = atoi(argv[++l]);
} else if (!strcmp(argv[l], "-elev")) {
elevation = atof(argv[++l]);
} else if (!strcmp(argv[l], "-datetime")) {
datetime = atoi(argv[++l]);
} else if (!strcmp(argv[l], "-samples")) {
samples = atoi(argv[++l]);
} else if (!strcmp(argv[l], "-gmtoff")) {
gmt_offset = atoi(argv[++l]);
} else if (!strcmp(argv[l], "-angle")) {
angle = atof(argv[++l]);
} else if (!strcmp(argv[l], "-diplen")) {
diplen = atof(argv[++l]);
} else if (!strcmp(argv[l], "-resis")) {
eprobe_res = atof(argv[++l]);
} else if (!strcmp(argv[l], "-dcoffset")) {
dcoffset = atof(argv[++l]);
}
// use this for spectra
else if (!strcmp(argv[l], "-median")) {
calc_median = 1;
range = atof(argv[++l]);
} else if (!strcmp(argv[l], "-median_coh")) {
median_coh = 1;
range_coh = atof(argv[++l]);
} else if (!strcmp(argv[l], "-sensorcal")) {
sensorcalfile = argv[++l];
if (sensorcalfile.size() > 12) {
cerr << "\nsorry, inside ats file format only 12 chars (8.3) are allowed for cal file name\n";
return EXIT_FAILURE;
}
} else if (!strcmp(argv[l], "-systemcal")) {
systemcalfile = argv[++l];
if (systemcalfile.size() > 12) {
cerr << "\nsorry, inside ats file format only 12 chars (8.3) are allowed for cal file name\n";
return EXIT_FAILURE;
}
} else if (!strcmp(argv[l], "-sensor_type")) {
sensor_type = argv[++l];
if (sensor_type.size() > 6) {
cerr << "\nsorry, inside ats file format only 6 chars are allowed for Sensor type\n";
return EXIT_FAILURE;
}
} else if (!strcmp(argv[l], "-channel_type")) {
channel_type = argv[++l];
if (channel_type.size() > 2) {
cerr << "\nsorry, inside ats file format only 2 chars are allowed for ChannelType (Hx, ..Ey)\n";
return EXIT_FAILURE;
}
} else if (!strcmp(argv[l], "-system_name")) {
system_name = argv[++l];
} else if (!strcmp(argv[l], "-channelno")) {
chan_no = (unsigned short) (atoi(argv[++l]));
} else if (!strcmp(argv[l], "-adbser")) {
SerNoADB = argv[++l];
} else if (!strcmp(argv[l], "-aduser")) {
SerNoADU = argv[++l];
} else if (!strcmp(argv[l], "-sensser")) {
SensorNo = argv[++l];
} else if (!strcmp(argv[l], "-samplefreq")) {
SampleFreq = atof(argv[++l]);
} else if (!strcmp(argv[l], "-corr")) {
corr = 1; // correct header
} else if (!strcmp(argv[l], "-wrh")) {
write_header = 1; // correct header permanently
} else if (!strcmp(argv[l], "-tc")) {
tc = 1; // write time and values in file
} else if (!strcmp(argv[l], "-ccf")) { // cross correlation
ccf_startx = abs(atoi(argv[++l]));
ccf_starty = abs(atoi(argv[++l]));
ccf_shifts = abs(atoi(argv[++l]));
do_ccf = 1;
} else if (!strcmp(argv[l], "-lin_conv")) {
lin_conv = 1;
lc_filter_len = (unsigned int) atoi(argv[++l]);
l++;
while ( (l < unsigned(argc)) && (*argv[l] != '-') && !strstr(argv[l], ".ats") ) {
lc_target_f.push_back(atof(argv[l++]));
}
l--;
} else if (!strcmp(argv[l], "-merge")) {
mc = 1;
last_file_is_result++;
} else if (!strcmp(argv[l], "-atsadd")) {
atsadd = 1;
last_file_is_result++;
} else if (!strcmp(argv[l], "-atssub")) {
atssub = 1;
last_file_is_result++;
} else if (!strcmp(argv[l], "-atsmul")) {
atsmul = 1;
last_file_is_result++;
} else if (!strcmp(argv[l], "-atsdiv")) {
atsdiv = 1;
last_file_is_result++;
} else if (!strcmp(argv[l], "-spectra_add")) {
spectra_add = 1;
} else if (!strcmp(argv[l], "-spectra_sub")) {
spectra_sub = 1;
} else if (!strcmp(argv[l], "-spectra_mul")) {
spectra_mul = 1;
} else if (!strcmp(argv[l], "-spectra_div")) {
spectra_div = 1;
} else if (!strcmp(argv[l], "-spos")) {
for ( i = 0; i < senspos.size(); i++) {
if (!strstr(argv[++l], "n"))
senspos[i] = atof(argv[l]);
}
}
// reads NOT in C notation that means first col is 1 !!!!
else if (!strcmp(argv[l], "-rda")) {
rda = 1;
SampleFreq = atof(argv[++l]);
asc_col = atoi(argv[++l]);
read_t.tm_year = atoi(argv[++l]) - 1900;
read_t.tm_mon = atoi(argv[++l]) - 1;
read_t.tm_mday = atoi(argv[++l]);
read_t.tm_hour = atoi(argv[++l]);