-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeEvalutionBaseData.cpp
5878 lines (4994 loc) · 154 KB
/
MakeEvalutionBaseData.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
#include "stdafx.h"
#include "MakeEvalutionBaseData.h"
#include "wavedataManager.h"
#include "mseed2Gascii.h"
#include <math.h>
#include <complex>
#include <xcomplex>
#include <iostream>
#include <fstream>
#include <direct.h>
//using namespace std;
// fftw 라이브러리 사용시 아래 코드 필요
#ifdef DEF_FFT_LIB
#include "../fftw-3.3.5-dll64/fftw3.h"
// 프로젝트 추가 종속성에 추가 항목 : ..\Lib\libfftw3-3.lib;..\Lib\libfftw3f-3.lib;..\Lib\libfftw3l-3.lib
#endif // DEF_FFT_LIB
CMakeEvalutionBaseData::CMakeEvalutionBaseData(void)
{
m_pMainDlgHwnd = NULL;
iniFunc = NULL;
logFunc = NULL;
//m_nListAEMaxWidth = 0;
m_strDitc = "";
m_nWarningLimit = 0;
m_nMinAvailChanCnt = 0;
m_sEventID = "";
m_sExecProcKind = "";
m_strAcc_Val = "";
m_strSp_Val = "";
m_strDis_Val = "";
m_strCav_Val = "";
m_strStm_Val = "";
m_strTot_Result = "";
}
CMakeEvalutionBaseData::~CMakeEvalutionBaseData(void)
{
if (GetStationCount() > 0)
{
for (int i = GetStationCount(); 0 <= i; --i)
{
Sta_t* pSta = (Sta_t*)m_aryStation.GetAt(i);
if (pSta == NULL) continue;
DelAllStationDetail(pSta);
delete pSta->pArySta_Detail;
delete pSta;
m_aryStation.RemoveAt(i);
}
}
if (GetThStationCount() > 0)
{
for (int i = GetThStationCount(); 0 <= i; --i)
{
ThSta_t* pThSta = (ThSta_t*)m_aryThStation.GetAt(i);
if (pThSta == NULL) continue;
DelAllThStationDetail(pThSta);
delete pThSta->pAryThSta_Detail;
delete pThSta;
m_aryThStation.RemoveAt(i);
}
}
}
int CMakeEvalutionBaseData::MakeBaseDataProc(char* sDitc, char* sEventID, char* sMseedPath, char* sNet, char* sSta)
{
int nRet = 0;
CString strLog = "";
char szOutFile[2048];
double dwSensitivity = 0;
double dwResponse = 0;
double dwCalib = 0;
strLog = "";
strLog.Format("Building Evalution Process Start!!");
WriteReportLog(strLog);
if( _access(sMseedPath, 0x00) != 0 )
{
strLog.Format("Access Failed MseedPath = '%s'", sMseedPath);
WriteReportLog(strLog);
#ifdef _DEBUG
TRACE("Access Failed MseedPath : %s\n", sMseedPath);
#endif // DEBUG
return nRet;
}
CString strLoc = "";
CString strLoc_FileNameOnly = "";
CString strOutFilePath = "";
CString strLoc_MCOUNTName = "";
char sSrcFileFullPath[1024];
Sta_t* pSta = NULL;
Sta_Detail_t* pStaDetail = NULL;
char sSenId[8];
char sChannelId[4];
char sObsSenName[12];
double dblSettlement = 0.0;
double dblCAV = 0.0;
int nResSpectrum = -1;
// 2019.04.19 개별 모듈화시 아래 주석 해제(StationInfo.txt 읽는 부분) START
//CString strStationInfoFileFullPath = "";
//strStationInfoFileFullPath.Format("%s\\%s", sMseedPath, STATIONINFO_TXT);
//int nReadRet = ReadStationInfo2Array(strStationInfoFileFullPath);
// 2019.04.19 개별 모듈화시 아래 주석 해제(StationInfo.txt 읽는 부분) END
// 2019.04.19 개별 모듈화시 아래 주석 해제(type{시설물구분코드}_thInfo.txt 읽는 부분) START
//CString strThresholdsInfoPath = "";
//strThresholdsInfoPath.Format("%s", sMseedPath);
//int nReadRet = ReadThresholdsInfo2Array(strThresholdsInfoPath, m_strDitc);
// 2019.04.19 개별 모듈화시 아래 주석 해제(type{시설물구분코드}_thInfo.txt 읽는 부분) END
double dblLowFreq = 0.0;
double dblHighFreq = 0.0;
// BandPass 필터링을 위한 시설물별 Low Freq, High Freq 값 설정
if( sDitc[0] == 'K' ) // 콘크리트댐
{
}
else if( sDitc[0] == 'D' ) // 필댐 및 저수지
{
//// 2019.06.10 속도를 사용하는 알고리즘 사용시 주석 해제
//dblLowFreq = 0.1;
//dblHighFreq = 50.0;
}
else if( sDitc[0] == 'S' || sDitc[0] == 'B' ) // 교량-사장교, 교량-현수교
{
dblLowFreq = 0.1;
dblHighFreq = 40.0;
}
strOutFilePath.Format("%s\\%s", sMseedPath, PATH_RESULT);
CreatePathDirectory(strOutFilePath);
char sOutFilePath[1024];
memset(sOutFilePath, 0x00, sizeof(sOutFilePath));
sprintf(sOutFilePath, "%s\\%s", sMseedPath, PATH_RESULT);
DeleteAllFile(sOutFilePath, sNet, sSta); // RESULT 파일 경로의 파일 전체 삭제
// file find
CFileFind finder;
BOOL bWorking = FALSE;
// 2019.03.29 MCOUNT 파일 생성 부분 추가
char sLoc[1024];
char sLoc_MCOUNT[1024];
char sLocFullPath[2048];
char sLoc_MCOUNTFullPath[2048];
CString cpFilePath = "";
cpFilePath.Format("%s\\%s_%s*%s", sMseedPath, sNet, sSta, DEF_MSEED_EXT);
bWorking = finder.FindFile(cpFilePath);
while( bWorking )
{
dblCAV = 0.0;
bWorking = finder.FindNextFile();
strLoc = finder.GetFileName();
strLoc_FileNameOnly = strLoc;//.Replace(".mseed", "");
strLoc_FileNameOnly.Replace(".mseed", "");
strLoc_MCOUNTName = strLoc;
strLoc_MCOUNTName.Replace(".mseed", "_MCOUNT.txt");
memset(sLoc, 0x00, sizeof(sLoc));
memset(sLocFullPath, 0x00, sizeof(sLocFullPath));
sprintf(sLoc, "%s", strLoc);
sprintf(sLocFullPath, "%s\\%s", sMseedPath, sLoc);
memset(sLoc_MCOUNT, 0x00, sizeof(sLoc_MCOUNT));
memset(sLoc_MCOUNTFullPath, 0x00, sizeof(sLoc_MCOUNTFullPath));
sprintf(sLoc_MCOUNT, "%s", strLoc_MCOUNTName);
sprintf(sLoc_MCOUNTFullPath, "%s\\%s", strOutFilePath, sLoc_MCOUNT);
memset(sSenId, 0x00, sizeof(sSenId));
memset(sChannelId, 0x00, sizeof(sChannelId));
sprintf(sSenId, "%s", strLoc.Mid(0, 6));
sprintf(sChannelId, "%s", strLoc.Mid(7, 3));
if(sChannelId[0] != 'H') continue;
if (GetStationCount() > 0)
{
BOOL bSetDataYN = FALSE;
for (int i = 0; i < GetStationCount(); i++)
{
if(bSetDataYN == TRUE)
{
break;
}
pSta = (Sta_t*)m_aryStation.GetAt(i);
if (pSta == NULL) continue;
if (strcmp(pSta->sSen_Id, sSenId) == 0 && pSta->bDataAvailability == true)
{
for (int j = 0; j < pSta->pArySta_Detail->GetCount(); j++)
{
pStaDetail = (Sta_Detail_t*)pSta->pArySta_Detail->GetAt(j);
if (pStaDetail == NULL) continue;
if (sChannelId[2] == 'Z')
{
dwResponse = (float)(atof(pStaDetail->sZresponse));
dwSensitivity = (float)(atof(pStaDetail->sZsensitivity));
bSetDataYN = TRUE;
}
else if (sChannelId[2] == 'N' || sChannelId[2] == 'Y')
{
dwResponse = (float)(atof(pStaDetail->sNresponse));
dwSensitivity = (float)(atof(pStaDetail->sNsensitivity));
bSetDataYN = TRUE;
}
else if (sChannelId[2] == 'E' || sChannelId[2] == 'X')
{
dwResponse = (float)(atof(pStaDetail->sEresponse));
dwSensitivity = (float)(atof(pStaDetail->sEsensitivity));
bSetDataYN = TRUE;
}
else
{
dwResponse = (float)(atof(pStaDetail->sZresponse));
dwSensitivity = (float)(atof(pStaDetail->sZsensitivity));
bSetDataYN = TRUE;
}
break;
}
}
}
if( bSetDataYN == FALSE )
{
strLog = "";
strLog.Format("sen = '%s', channel = '%s', dataChk = '%d'", sSenId, sChannelId, bSetDataYN);
WriteReportLog(strLog);
}
}
#ifdef _DEBUG
//if (sDitc[0] == 'S' || sDitc[0] == 'B')
//{
//}
//else if (sDitc[0] == 'K')
//{
//}
//else if (sDitc[0] == 'D')
//{
//}
//else
//{
// if (pSta == NULL || pStaDetail == NULL)
// {
// // 성분에 대한 값이 없음
// continue;
// }
//}
if( pSta == NULL || pStaDetail == NULL || (int)dwSensitivity == 0 || (int)dwResponse == 0 )
{
// 성분에 대한 값이 없음
continue;
}
#else
if( pSta == NULL || pStaDetail == NULL || (int)dwSensitivity == 0 || (int)dwResponse == 0 )
{
// 성분에 대한 값이 없음
continue;
}
#endif // DEBUG
dwCalib = (((dwSensitivity * 0.000001) / dwResponse) / 9.81) * 981;
#ifdef _DEBUG
//if( sDitc[0] == 'S' || sDitc[0] == 'B' ) // 특수교량 완도대교 데이터 테스트 보정치
//{
// dwCalib = 0.000234;
//}
//else if( sDitc[0] == 'K' ) // 콘크리트댐 테스트로 완도대교 데이터 사용을 위함
//{
// dwCalib = 0.000234;
//}
//else if( sDitc[0] == 'D' ) // 필댐 임시 테스트로 임의 Calibration 값 설정
//{
// //dwCalib = 0.000234;
//}
#endif // DEBUG
CMseed2Gascii mseed2Gascii;
if(mseed2Gascii.MakeMseed2Gascii(sLocFullPath, sLoc_MCOUNTFullPath, dwCalib) != 0)
{
strLog = "";
strLog.Format("Make Count Data Failed!! sen = '%s', channel = '%s'", sSenId, sChannelId);
WriteReportLog(strLog);
continue;
}
}
// MCOUNT 파일로 deTrend, cosineTapering, TogroundTSPModule(최대가속도, 최대지반속도, 변위 산출 - 1999 가네모리식 적용) 순차적으로 시행하여 데이터 산출
bWorking = FALSE;
cpFilePath = "";
strLoc = "";
strLoc_FileNameOnly = "";
cpFilePath.Format("%s\\%s_%s*%s", strOutFilePath, sNet, sSta, DEF_MSEED_COUNT);
bWorking = finder.FindFile(cpFilePath);
if( bWorking == 0 )
{
strLog = "";
strLog.Format("Not found MCOUNT file!!\n");
WriteReportLog(strLog);
return nRet;
}
#ifdef _DEBUG
TRACE("111 pSta->sSen_Id = '%s', dwResponse = '%lf', dwSensitivity = '%lf', dwCalib = '%lf'\n", pSta->sSen_Id, dwResponse, dwSensitivity, dwCalib);
#endif // DEBUG
while( bWorking )
{
dblCAV = 0.0;
bWorking = finder.FindNextFile();
strLoc = finder.GetFileName();
strLoc_FileNameOnly = strLoc;//.Replace(".mseed", "");
strLoc_FileNameOnly.Replace("_MCOUNT.txt", "");
memset(sSrcFileFullPath, 0x00, sizeof(sSrcFileFullPath));
sprintf(sSrcFileFullPath, "%s\\%s", strOutFilePath, strLoc);
//char sSenId[8];
//char sChannelId[4];
char sLocation[1024];
char sFileNameOnly[1024];
memset(sSenId, 0x00, sizeof(sSenId));
memset(sChannelId, 0x00, sizeof(sChannelId));
memset(sObsSenName, 0x00, sizeof(sObsSenName));
memset(sLocation, 0x00, sizeof(sLocation));
memset(sFileNameOnly, 0x00, sizeof(sFileNameOnly));
sprintf(sSenId, "%s", strLoc.Mid(0, 6));
sprintf(sChannelId, "%s", strLoc.Mid(7, 3));
sprintf(sObsSenName, "%s", strLoc.Mid(0, 10));
sprintf(sLocation, "%s", strLoc);
sprintf(sFileNameOnly, "%s", strLoc_FileNameOnly);
sprintf(szOutFile, "%s\\%s", strOutFilePath, sFileNameOnly);
if(sChannelId[0] != 'H') continue;
//FILE *wFile = NULL;
//wFile = fopen(szOutFile, "w" );
//if( wFile == NULL )
//{
// TRACE("ERROR fopen(%s)\n", szOutFile);
// continue;
//}
//if( _access(szOutFile, 0x00) != 0 )
//{
// TRACE("Error create count file[%s]\n", szOutFile);
// continue;
//}
Init_WaveDataPool();
char cChanID;
// 0123456789012345678901234
// GK_OSV_HCY_20161113215257
cChanID = CheckChannelID(sFileNameOnly[9]);
if( ReadChanData(sSrcFileFullPath, cChanID) != 1 )
//if( ReadMseedData2ChanStruct(sSrcFileFullPath, cChanID) != 1 )
{
strLog = "";
strLog.Format("Read Channel Data Error!! path = '%s', channel = '%s'", sSrcFileFullPath, cChanID);
WriteReportLog(strLog);
Distory_WaveDataPool();
remove(szOutFile);
return nRet;
}
//remove(szOutFile);
// StationInfo.txt 파일 읽는 부분(각 센서별 Calib 데이터)
pSta = NULL;
pStaDetail = NULL;
//strStationInfoFileFullPath = "";
//strStationInfoFileFullPath.Format("%s\\%s", sMseedPath, STATIONINFO_TXT);
//int nReadRet = ReadStationInfo2Array(strStationInfoFileFullPath);
if (GetStationCount() > 0)
{
BOOL bSetDataYN = FALSE;
for (int i = 0; i < GetStationCount(); i++)
{
if(bSetDataYN == TRUE)
{
break;
}
pSta = (Sta_t*)m_aryStation.GetAt(i);
if (pSta == NULL) continue;
if (strcmp(pSta->sSen_Id, sSenId) == 0 && pSta->bDataAvailability == true)
{
for (int j = 0; j < pSta->pArySta_Detail->GetCount(); j++)
{
pStaDetail = (Sta_Detail_t*)pSta->pArySta_Detail->GetAt(j);
if (pStaDetail == NULL) continue;
if (sChannelId[2] == 'Z')
{
dwResponse = (float)(atof(pStaDetail->sZresponse));
dwSensitivity = (float)(atof(pStaDetail->sZsensitivity));
bSetDataYN = TRUE;
}
else if (sChannelId[2] == 'N' || sChannelId[2] == 'Y')
{
dwResponse = (float)(atof(pStaDetail->sNresponse));
dwSensitivity = (float)(atof(pStaDetail->sNsensitivity));
bSetDataYN = TRUE;
}
else if (sChannelId[2] == 'E' || sChannelId[2] == 'X')
{
dwResponse = (float)(atof(pStaDetail->sEresponse));
dwSensitivity = (float)(atof(pStaDetail->sEsensitivity));
bSetDataYN = TRUE;
}
else
{
dwResponse = (float)(atof(pStaDetail->sZresponse));
dwSensitivity = (float)(atof(pStaDetail->sZsensitivity));
bSetDataYN = TRUE;
}
break;
}
}
}
}
#ifdef _DEBUG
TRACE("222 pSta->sSen_Id = '%s', sObsSenName = '%s', dwResponse = '%lf', dwSensitivity = '%lf', dwCalib = '%lf'\n", pSta->sSen_Id, sObsSenName, dwResponse, dwSensitivity, dwCalib);
#endif // DEBUG
#ifdef _DEBUG
//if (sDitc[0] == 'S' || sDitc[0] == 'B')
//{
//}
//else if (sDitc[0] == 'K')
//{
//}
//else if (sDitc[0] == 'D')
//{
//}
//else
//{
// if (pSta == NULL || pStaDetail == NULL)
// {
// // 성분에 대한 값이 없음
// continue;
// }
//}
if( pSta == NULL || pStaDetail == NULL || (int)dwSensitivity == 0 || (int)dwResponse == 0 )
{
// 성분에 대한 값이 없음
continue;
}
#else
if( pSta == NULL || pStaDetail == NULL || (int)dwSensitivity == 0 || (int)dwResponse == 0 )
{
// 성분에 대한 값이 없음
continue;
}
#endif // DEBUG
dwCalib = (((dwSensitivity * 0.000001) / dwResponse) / 9.81) * 981;
#ifdef _DEBUG
//if( sDitc[0] == 'S' || sDitc[0] == 'B' ) // 특수교량 완도대교 데이터 테스트 보정치
//{
// dwCalib = 0.000234;
//}
//else if( sDitc[0] == 'K' ) // 콘크리트댐 테스트로 완도대교 데이터 사용을 위함
//{
// dwCalib = 0.000234;
//}
//else if( sDitc[0] == 'D' ) // 필댐 임시 테스트로 임의 Calibration 값 설정
//{
// //dwCalib = 0.000234;
//}
#endif // DEBUG
int idataCount;
double* dwDataArray;
double* real_in;
#ifdef DEF_FFT_LIB
fftw_complex *out;
fftw_complex *out_freq;
fftw_complex *out_period;
// fftw_complex *real_in, *out;
fftw_plan rp;
#endif // DEF_FFT_LIB
double dwsamplelate = 100.0;
if( sFileNameOnly[7] == DEF_H_SAMPLE ) // 100 샘플 자료만 사용
{
dwsamplelate = 100.0;
}
else if( sFileNameOnly[7] == DEF_B_SAMPLE ) // 20 샘플 자료는 무시
{
//dwsamplelate = 20.0;
continue;
}
else
{
strLog = "";
strLog.Format("Error unknown data sample code!! filename = '%s'", sFileNameOnly);
WriteReportLog(strLog);
TRACE("Error unknown data sample code[%s]\n", sFileNameOnly);
Distory_WaveDataPool();
return nRet;
}
int i;
double dwfftVal;
double dwtmp1;
double dwtmp2;
double dwtmp3;
double dwfrequency;
idataCount = GetRealDataCount(cChanID);
#ifdef _DEBUG
//TRACE("GetRealDataCount[%c][%d]\n", cChanID, idataCount);
#endif // DEBUG
if( idataCount <= 100 )
{
strLog = "";
strLog.Format("Error data low count!! count = '%d'", idataCount);
WriteReportLog(strLog);
TRACE("Error data low count[%d]\n", idataCount);
Distory_WaveDataPool();
return nRet;
}
int* ipDataArray;
ipDataArray = (int*)malloc(sizeof(int) * idataCount);
// TRACE("GetCountData(%d)\n", idataCount);
GetCountData(cChanID, ipDataArray, idataCount);
dwDataArray = (double*)malloc(sizeof(double) * idataCount);
for( i=0; i<idataCount; i++ )
{
dwDataArray[i] = ipDataArray[i];
// TRACE("\t%d\n", ipDataArray[i]);
}
double* dwRKTimeArray;
dwRKTimeArray = (double*)malloc(sizeof(double) * idataCount);
GetRKtimeData(cChanID, dwRKTimeArray, idataCount);
#ifdef _DEBUG
//TRACE("dTrend(%d)\n", idataCount);
#endif // DEBUG
CFFT_Common::deTrend(dwDataArray, idataCount);
#ifdef _DEBUG
//TRACE("cosineTapering(%d)\n", idataCount);
#endif // DEBUG
double dblMaxPGA = 0.0;
double dblMaxPGV = 0.0;
double dblMaxDisp = 0.0;
CFFT_Common::cosineTapering(dwDataArray, idataCount);
for( i=0; i<idataCount; i++ )
{
ipDataArray[i] = (int)dwDataArray[i];
//ipDataArray[i] = dwDataArray[i];
//TRACE("\t[%d] %d\n", i, ipDataArray[i]);
}
UpdateRealData(cChanID, DEF_D_KIND_C, dwDataArray, idataCount, dblMaxPGA, dblMaxPGV, dblMaxDisp);
SampleStruct_t *data;
data = (SampleStruct_t*)malloc(sizeof(SampleStruct_t) * idataCount);
#ifdef _DEBUG
//TRACE("data copy for ToGroundTSPModule(%d)\n", idataCount);
#endif // DEBUG
for( i=0; i<idataCount; i++ )
{
data[i].raw = ipDataArray[i];
}
#ifdef _DEBUG
TRACE("ToGroundTSPModule(%d)\n", idataCount);
//dwCalib = 0.000315784;
#endif // DEBUG
CFFT_Common::ToGroundTSPModule(idataCount, dwCalib, data); // Acc, Vel, Disp 산출
#ifdef _DEBUG
//TRACE("ToGroundTSPModule(%d)\n", idataCount);
#endif // DEBUG
#ifdef _DEBUG // 2019.05.14 필댐,저수지 테스트를 위한 부분
if( TESTDATA )
{
CStdioFile file;
CString strBufferLine = "";
CString cpFillDemDataPath = "";
CString strLoc_FillDem = "";
CString strLoc_FillDem_FileNameOnly = "";
BOOL bWorking_FillDem = FALSE;
// 필댐 및 저수지 테스트용 경로
if (TEST_D)
{
cpFillDemDataPath.Format("%s", "D:\\Project\\댐.저수지 안전성평가시스템\\2019\\안전성평가로직\\필댐및저수지\\20190514\\기반지진데이터\\Tabas.txt");
}
// 콘크리트댐 테스트용 경로
else if (TEST_K)
{
cpFillDemDataPath.Format("%s", "D:\\Project\\댐.저수지 안전성평가시스템\\2019\\안전성평가로직\\콘크리트댐\\테스트용데이터\\CAVTestData.txt");
}
// 특수교량 테스트용 경로
{
cpFillDemDataPath.Format("%s", "D:\\Project\\댐.저수지 안전성평가시스템\\2019\\Source\\Elastic-Spectrum-compare-program_Win04\\ERspectrum\\bin\\Debug\\Test\\Elcentro-NS.dat");
}
int nDataCount = 0;
double* pAccData = NULL;
double* pVelData = NULL;
double* pDataArray = NULL;
if( file.Open(cpFillDemDataPath, CFile::modeRead) )
{
while(file.ReadString(strBufferLine))
{
strBufferLine.Replace("\r", "");
nDataCount++;
}
}
file.Close();
pAccData = (double*)malloc(sizeof(double) * nDataCount);
pVelData = (double*)malloc(sizeof(double) * nDataCount);
pDataArray = (double*)malloc(sizeof(double) * nDataCount);
int nIdx = 0;
if( file.Open(cpFillDemDataPath, CFile::modeRead) )
{
while(file.ReadString(strBufferLine))
{
strBufferLine.Replace("\r", "");
if( strBufferLine.GetAt(0) == 0x20 )
{
//strBufferLine.SetAt(0, _T(""));
}
BOOL bDataChk = FALSE;
for(int i = strBufferLine.GetLength(); i > 0; i--)
{
if(strBufferLine.GetAt(i) == 0x20 || strBufferLine.GetAt(i) == 0x00 || strBufferLine.GetAt(i) == 0x09)
{
if(bDataChk == FALSE) continue;
CString strAcc = strBufferLine.Mid(i + 1, strBufferLine.GetLength() - 1);
char* pAcc = new char[strAcc.GetLength() + 1];
memset(pAcc, 0x00, sizeof(pAcc));
sprintf(pAcc, "%s", strAcc);
pAcc[strAcc.GetLength()] = '\0';
//strncpy(pAcc, strAcc, strAcc.GetLength());
pAccData[nIdx] = atof(pAcc);// / 100.0;
if( pAcc )
{
delete pAcc;
pAcc = NULL;
}
#ifdef _DEBUG
//TRACE("AccData[%d] = '%lf'\n", nIdx, pAccData[nIdx]);
#endif // DEBUG
nIdx++;
break;
}
else
{
bDataChk = TRUE;
}
}
}
}
file.Close();
double dblFillMaxPGA = 0.0;
double dblFillMaxPGV = 0.0;
if (TEST_K) // 콘크리트댐 테스트
{
for(int j = 0; j < nDataCount; j++)
{
pDataArray[j] = pAccData[j];
}
CFFT_Common::deTrend(pDataArray, nDataCount);
for(int j = 0; j < nDataCount; j++)
{
if(j == 0) continue;
double dblA = fabs(pDataArray[j - 1]);
double dblB = fabs(pDataArray[j]);
if(pDataArray[j - 1] > 0 && pDataArray[j] > 0 || pDataArray[j - 1] < 0 && pDataArray[j] < 0)
{
dblCAV += ((dblA + dblB) * 0.01) / 2;
}
else if(pDataArray[j - 1] < 0 || pDataArray[j] < 0)
{
dblCAV += ((0.01 * (dblA / (dblA + dblB)) * dblA) / 2) + ((0.01 * (1 - (dblA / (dblA + dblB))) * dblB) / 2);
}
#ifdef _DEBUG
//TRACE("%lf\n", dblCAV);
#endif // DEBUG
}
}
if (TEST_D) // 필댐(저수지) 테스트
{
dblLowFreq = 0.1;
dblHighFreq = 50.0;
//BandPassFilter(pDataArray, dwsamplelate, nDataCount, dblLowFreq, dblHighFreq, 2, NULL);
CFFT_Common::deTrend(pDataArray, nDataCount);
GetRKtimeData(cChanID, dwRKTimeArray, nDataCount);
CFFT_Common::FourthRungeKutta(dwRKTimeArray, pDataArray, nDataCount); // 가속도 -> 속도 변환
//CFFT_Common::FourthRungeKutta(dwRKTimeArray, dwDataArray, idataCount); // 속도 -> 변위 변환
CFFT_Common::deTrend(pDataArray, nDataCount);
for(int j = 0; j < nDataCount; j++)
{
pVelData[j] = pDataArray[j];
}
for(int j = 0; j < nDataCount; j++)
{
if(j == 0)
{
dblFillMaxPGA = fabs(pAccData[j]);
}
else
{
if(fabs(pAccData[j]) > dblFillMaxPGA)
{
dblFillMaxPGA = fabs(pAccData[j]);
}
}
}
for(int j = 0; j < nDataCount; j++)
{
if(j == 0)
{
dblFillMaxPGV = fabs(pVelData[j]);
}
else
{
if(fabs(pVelData[j]) > dblFillMaxPGV)
{
dblFillMaxPGV = fabs(pVelData[j]);
}
}
}
//dblSettlement = (exp( (RESERVOIR_PGA_FACTOR_V1 * dblFillMaxPGA / 981) - RESERVOIR_MINUS_V1 )); // 필댐및저수지 손상지수 계산 알고리즘 1번식 (PGA 사용)
//dblSettlement = RESERVOIR_FACTOR * (dblFillMaxPGA / 981); // 2019.10.23 한양대 김정현 연구원 전달 식으로 변경
dblSettlement = RESERVOIR_FACTOR * (dblFillMaxPGA); // 2019.11.21 PGA값이 gal 단위일 경우 / 981 제외, g 일 경우 * 981 사용
//int nSettlement = (int)((exp( (RESERVOIR_PGA_FACTOR_V2 * dblFillMaxPGA) + (RESERVOIR_PGV_FACTOR_V2 * dblFillMaxPGV) - RESERVOIR_MINUS_V2)) * 1000); // 필댐및저수지 손상지수 계산 알고리즘 2번식 (PGA, PGV 사용)
//double dblSettlement = dblSettlement * 0.010;
//dblSettlement = CFFT_Common::Rounding(dblSettlement, 1);
#ifdef _DEBUG
TRACE("[%s] dblMaxPGA = '%lf', dblMaxPGV = '%lf', dblSettlement = '%.6lf'\n", __FUNCTION__, dblFillMaxPGA, dblFillMaxPGV, dblSettlement);
TRACE("[%s] Reservoir Settlement = '%.2lf'\n", __FUNCTION__, dblSettlement);
#endif // DEBUG
}
if (TEST_SB) // 특수교량 테스트
{
ThSta_t* pThSta = NULL;
ThSta_Detail_t* pThStaDetail = NULL;
for (int j = 0; j < m_aryThStation.GetCount(); j++)
{
pThSta = (ThSta_t*)m_aryThStation.GetAt(j);
if (pThSta == NULL) continue;
if (strstr(pThSta->sSen_Id, sObsSenName) == NULL) continue;
pThStaDetail = (ThSta_Detail_t*)pThSta->pAryThSta_Detail->GetAt(0);
if (pThStaDetail == NULL) continue;
break;
}
GroundAccType* earthq = new GroundAccType;
SpectrumType* spectrum = new SpectrumType;
double damping = 0.05;
double gravity = 1 * -1;
double s1 = 0.068;//0.154;
//double s1 = 67; // 2019.11.26 경상대 정영석 연구원 요청으로 변경
double alpha = 2.8;
if (pThStaDetail != NULL)
{
damping = atof(pThStaDetail->sDampingRatio);
gravity = atof(pThStaDetail->sGravity) * -1;
s1 = atof(pThStaDetail->sEffectivePGA);
alpha = atof(pThStaDetail->sCoefficient);
}
char disfile[1024];
char velfile[1024];
char accfile[1024];
char dsgfile[1024];
memset(disfile, 0x00, sizeof(disfile)); //cpFillDemDataPath
memset(velfile, 0x00, sizeof(velfile));
memset(accfile, 0x00, sizeof(accfile));
memset(dsgfile, 0x00, sizeof(dsgfile));
sprintf(disfile, "%s", cpFillDemDataPath);
sprintf(velfile, "%s", cpFillDemDataPath);
sprintf(accfile, "%s", cpFillDemDataPath);
sprintf(dsgfile, "%s", cpFillDemDataPath);
disfile[strlen(disfile) - 4] = '\0';
velfile[strlen(velfile) - 4] = '\0';
accfile[strlen(accfile) - 4] = '\0';
dsgfile[strlen(dsgfile) - 4] = '\0';
strcat(disfile, ".dis");
strcat(velfile, ".vel");
strcat(accfile, ".acc");
strcat(dsgfile, ".dsg");
earthq->gcount = nDataCount;
earthq->gtime = new double[earthq->gcount + 1];
earthq->acc = new double[earthq->gcount + 1];
spectrum->nperiod = 501;
spectrum->period = new double[spectrum->nperiod + 1];
spectrum->dispSpectrum = new double[spectrum->nperiod + 1];
spectrum->velSpectrum = new double[spectrum->nperiod + 1];
spectrum->accSpectrum = new double[spectrum->nperiod + 1];
spectrum->designSpectrum = new double[spectrum->nperiod + 1];
for(int j = 0; j < nDataCount; j++)
{
pDataArray[j] = pAccData[j];
}
GetRKtimeData(cChanID, dwRKTimeArray, nDataCount);
earthq->gtime[0] = 0;
earthq->acc[0] = 0;
for(int k = 0; k < nDataCount; k++)
{
earthq->gtime[k + 1] = dwRKTimeArray[k];
earthq->acc[k + 1] = pDataArray[k] * gravity;
}
earthq->dt = earthq->gtime[2] - earthq->gtime[1];
CFFT_Common::deTrend(earthq->acc, nDataCount + 1);
earthq->maxtime = earthq->gtime[earthq->gcount];
SpectrumCompute(earthq, damping, spectrum);
DesignSpectrum(s1, alpha, spectrum);
if (CompareSpectrum(spectrum))
#ifdef _DEBUG
TRACE("\n\t N.G \n");
#endif // DEBUG
else
#ifdef _DEBUG
TRACE("\n\t O.K \n");
#endif // DEBUG
spectrum->WriteSpectrum(disfile, spectrum, 1);
spectrum->WriteSpectrum(velfile, spectrum, 2);
spectrum->WriteSpectrum(accfile, spectrum, 3);
spectrum->WriteSpectrum(dsgfile, spectrum, 4);
if (earthq) delete earthq;
if (spectrum) delete spectrum;
}
if (pAccData) free(pAccData);
if (pVelData) free(pVelData);
if (pDataArray) free(pDataArray);
}
#endif // DEBUG
if( sDitc[0] == 'S' || sDitc[0] == 'B' ) // 교량-사장교, 교량-현수교는 별도 RungeKutta 알고리즘으로 변위 산출
//if (false)
{
if( sChannelId[0] == 'H' )
{
for( i=0; i<idataCount; i++ )
{
dwDataArray[i] = data[i].a;
}
UpdateRealData(cChanID, DEF_D_KIND_A, dwDataArray, idataCount, dblMaxPGA, dblMaxPGV, dblMaxDisp);
// 2019.08.09 가속도 응답 스펙트럼 분석을 위한 추가 START
char sObsId1[4];
char sObsId2[4];
memset(sObsId1, 0x00, sizeof(sObsId1));
memset(sObsId2, 0x00, sizeof(sObsId2));
strncpy(sObsId1, sObsSenName + 5, 3);
sObsId1[3] = '\0';
strncpy(sObsId2, sObsSenName + 9, 1);
sObsId2[1] = '\0';
ThSta_t* pThSta = NULL;
ThSta_Detail_t* pThStaDetail = NULL;
for (int j = 0; j < m_aryThStation.GetCount(); j++)
{
pThSta = (ThSta_t*)m_aryThStation.GetAt(j);
if (pThSta == NULL) continue;
if (strstr(pThSta->sSen_Id, sObsSenName) == NULL) continue;
pThStaDetail = (ThSta_Detail_t*)pThSta->pAryThSta_Detail->GetAt(0);
if (pThStaDetail == NULL) continue;
break;
}
// 가속도값 으로 분석하는 데이터만 대상으로 시행
if( (strstr(sObsId1, "B_H") != NULL && strstr(sObsId2, "X") != NULL) || (strstr(sObsId1, "B_H") != NULL && strstr(sObsId2, "Y") != NULL) || (strstr(sObsId1, "B_H") != NULL && strstr(sObsId2, "Z") != NULL) || // 주탑기초 (주탑 기초 상단면)
(strstr(sObsId1, "G_H") != NULL && strstr(sObsId2, "N") != NULL) || (strstr(sObsId1, "G_H") != NULL && strstr(sObsId2, "E") != NULL) || (strstr(sObsId1, "G_H") != NULL && strstr(sObsId2, "Z") != NULL) || // 자유장
(strstr(sObsId1, "R_H") != NULL && strstr(sObsId2, "X") != NULL) || (strstr(sObsId1, "R_H") != NULL && strstr(sObsId2, "Y") != NULL) || (strstr(sObsId1, "R_H") != NULL && strstr(sObsId2, "Z") != NULL) ) // 앵커리지(현수교) (앵커블록 상단)
{
GroundAccType* earthq = new GroundAccType;
SpectrumType* spectrum = new SpectrumType;
double damping = 0.05;
double gravity = 1 * -1;
double s1 = 0.0;
// 2019.11.26 경상대 정영석 연구원 요청으로 변경
if( strstr(sObsId2, "Z") != NULL )
{
s1 = 52.0;
}
else
{
s1 = 67.0;
}
double alpha = 2.8;