Changeset 342 in Sophya for trunk/Poubelle/archTOI.old/archeopsfile.cc
- Timestamp:
- Aug 2, 1999, 3:45:52 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Poubelle/archTOI.old/archeopsfile.cc
r315 r342 38 38 39 39 SSTHandler sstHandler; 40 GPSParser gpsParser; 40 41 }; 41 42 … … 211 212 else if (!llastBolo) { 212 213 llastBolo = new block_type_bolo; 214 } 215 if (llastBolo) { 213 216 memcpy(llastBolo, lastBolo, sizeof(block_type_bolo)); 214 217 } … … 286 289 fn = x.fn; 287 290 f = fopen(fn.c_str(), "rb"); 291 292 rawMJD = x.rawMJD; 293 startMJD = x.startMJD; 294 utcOffset = x.utcOffset; 288 295 } 289 296 … … 300 307 //curBlock = oldFile.curBlock; 301 308 //peekBlock = oldFile.peekBlock; 302 peekPos = 0;309 if (peekPos>0) peekPos = 0; 303 310 setUTCOffset(oldFile.utcOffset); 304 311 } … … 306 313 307 314 def_nom_block 315 316 def_long_block 308 317 309 318 bool ArcheopsFile::nextBlock() { … … 316 325 317 326 memcpy(curBlock, peekBlock, sizeof(block_type_modele)); 318 319 if (peekPos+12 > fLen) return false; 320 fseek(f,peekPos,SEEK_SET); 321 size_t read = fread(peekBlock,1,sizeof(block_type_modele),f); 322 swapEntete(peekBlock); 323 if (read < longueur_block(peekBlock)) return false; 324 swapContent(peekBlock); 325 if (verifie_block(peekBlock) != block_correct) { 326 printf("block invalide\n"); throw ArchExc("invalid block"); 327 } 328 peekPos += longueur_block(peekBlock); 327 curPos = peekPos; 328 329 while (true) { 330 if (peekPos+12 > fLen) return false; // fin de fichier 331 fseek(f,peekPos,SEEK_SET); // aller en peekPos 332 size_t read = fread(peekBlock,1,sizeof(block_type_modele),f); 333 swapEntete(peekBlock); 334 if (read < longueur_block(peekBlock) || 335 type_block(peekBlock) < 0 || type_block(peekBlock) > 19 || 336 longueur_block(peekBlock) != long_block[type_block(peekBlock)]) { 337 cout << "block de type/longueur invalide" << endl; 338 memset(peekBlock, 0, sizeof(block_type_modele)); // don't keep trash... 339 peekPos = searchNextBlock(peekPos); 340 if (peekPos<0) return false; 341 continue; 342 } 343 swapContent(peekBlock); 344 if (verifie_block(peekBlock) != block_correct) { 345 cout << "block invalide " << numero_block(peekBlock); 346 if (!fixBlock(peekBlock)) { 347 cout << " -- skipped" << endl; 348 peekPos += longueur_block(peekBlock); // la longueur doit etre ok... 349 continue; 350 } else { 351 cout << " -- fixed" << endl; 352 break; 353 } 354 } 355 break; // tout semble bon pour ce bloc... 356 } 357 358 peekPos += longueur_block(peekBlock); // on suppose que longueur OK... 329 359 if (curPos < 0) { 330 360 curPos = 0; return true; 331 361 } 332 curPos += longueur_block(curBlock); 333 curRawKind = curKind = type_block(curBlock); 334 //printf("block %d : %s \n",numero_block(&curBlock),nom_block[curKind]); 335 postProcessBlock(); 336 saveCurBlock(); 362 if (curBlock->debut != 0) { 363 curRawKind = curKind = type_block(curBlock); 364 postProcessBlock(); 365 saveCurBlock(); 366 } else { 367 curRawKind = curKind = -1; 368 } 337 369 return true; 338 370 } … … 346 378 } 347 379 380 bool ArcheopsFile::fixBlock(block_type_modele* blk) { 381 return false; 382 } 383 384 348 385 int ArcheopsFile::blockKind() { 349 386 return curKind; … … 363 400 double p,f1,f2,f3; 364 401 int pp; 402 if (!lastReglage()) return -1; 365 403 pp=lastReglage()->reglage.horloge.periode; 366 404 p=pp/5.; … … 374 412 375 413 int ArcheopsFile::nEchBlock() { // Nb d'echantillons dans un bloc 376 return lastParam()->param.n_per_block*2 .;414 return lastParam()->param.n_per_block*2; 377 415 } 378 416 … … 448 486 } 449 487 488 void ArcheopsFile::forceBlock(block_type_modele* blk) { 489 blockSet->setBloc(*blk); 490 } 491 492 #define place_paquet(i,j) ((i/8) * 24 + j*8 + (i%8) ) 493 450 494 void ArcheopsFile::postProcessBlock() { 451 495 switch (curKind) { … … 454 498 block_type_bolo blk2; 455 499 block_type_bolo_comprime* blk = (block_type_bolo_comprime*) &blockSet->curBlock; 500 #if version_num <= 25 456 501 for(int j=0;j<nb_bolo_util;j++) 457 { 458 decompress_7_2(blk->data_bolo[j],blk2.data_bolo[j],nb_per_block*2); 502 { 503 decompress_7_2((int4*)blk->data_bolo[j],blk2.data_bolo[j],nb_per_block*2); 504 } 505 #else 506 block_type_param* param = lastParam(); 507 int jc=0;for(int j=0;j<nb_max_bolo;j++) // jc = bolo_comprime // j=bolo normal 508 { 509 if( (param->param.bolo[j].bolo_code_util==bolo_normal_transmis) && (jc<nb_bolo_util) ) 510 { 511 decompress_7_2((int4 *)blk->data_bolo[jc],blk2.data_bolo[j],nb_per_block*2); 512 jc++; 513 } 514 else { 515 memset(blk2.data_bolo[j], 0, nb_per_block*2*sizeof(int4)); 459 516 } 517 } 518 519 #endif 460 520 valide_block((block_type_modele*)&blk2,block_bolo,numero_block(blk)); 461 521 memcpy(&blockSet->curBlock,&blk2,sizeof(blk2)); … … 464 524 } 465 525 case block_sst_comprime: { // $CHECK$ TBD 526 blockSet->setRawBloc(blockSet->curBlock); 527 block_type_sst blk2; 528 block_type_sst_comprime* blk = (block_type_sst_comprime*) &blockSet->curBlock; 529 for (int j=0; j<18; j++) 530 for (int i=0; i<nb_per_block*2; i++) 531 blk2.sst[i][j] = 0; 532 533 int jc=0; 534 for( int j=0;j<48;j++) { 535 if ((j!=0) && (j!=4)) 536 { 537 unsigned int4 sst_vrai[nb_per_block*2]; 538 decompress_4_1((int4*)blk->sst[jc],(int4*)sst_vrai,nb_per_block*2); 539 for (int k=0;k<nb_per_block*2;k++) { 540 unsigned int4 a,b0,b1,b2; 541 b2 = sst_vrai[k] & 0xf; 542 b1 = (sst_vrai[k] >> 4) & 0xf; 543 b0 = (sst_vrai[k] >> 8) & 0xf; 544 a=place_paquet(j,0); 545 blk2.sst[k][a/8] |= (b0 << (a%8)*4); 546 a=place_paquet(j,1); 547 blk2.sst[k][a/8] |= (b1 << (a%8)*4); 548 a=place_paquet(j,2); 549 blk2.sst[k][a/8] |= (b2 << (a%8)*4); 550 } 551 jc++; 552 } 553 } 554 valide_block((block_type_modele*)&blk2,block_sst,numero_block(blk)); 555 memcpy(&blockSet->curBlock,&blk2,sizeof(blk2)); 556 curKind = block_sst; 557 blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock); 558 break; 466 559 } 467 560 case block_sst : { 468 561 blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock); 562 } 563 case block_gps : { 564 blockSet->gpsParser.ProcessBlock((block_type_gps*)&blockSet->curBlock); 469 565 } 470 566 } … … 519 615 #endif 520 616 617 #ifdef SWAP 521 618 void ArcheopsFile::swapEntete(block_type_modele* blk) { 522 #ifdef SWAP523 619 bswap4(&(blk->debut)); 524 620 bswap4(&(blk->code1)); 525 621 bswap4(&(blk->code2)); 526 622 long lg = longueur_block(blk); 527 bswap4(((char*)blk) + lg - 4); 623 if (lg < taille_maxi_block_archeops) 624 bswap4(((char*)blk) + lg - 4); 625 } 626 #else 627 void ArcheopsFile::swapEntete(block_type_modele* ) { 628 } 528 629 #endif 529 } 530 630 631 #ifdef SWAP 531 632 void ArcheopsFile::swapContent(block_type_modele* blk) { 532 #ifdef SWAP533 633 int typ = type_block(blk); 534 634 … … 550 650 for (int i=0; i<nb_max_bolo; i++) 551 651 for (int j=0; j<8; j++) 552 bswap4(&b->param.bolo[i].bolo_nom[4*j]); 553 }554 555 } 652 #if version_num<=25 653 bswap4(&b->param.bolo[i].bolo_nom[4*j]); 654 #else 655 bswap4(&b->param.nom_coef[i].bolo_nom[4*j]); 556 656 #endif 557 } 558 657 } 658 659 } 660 } 661 #else 662 void ArcheopsFile::swapContent(block_type_modele* ) { 663 } 664 #endif 665 666 long ArcheopsFile::searchNextBlock(long pos) { 667 static char* buffer = 0; 668 static int4 debswp = debut_block_mesure; 669 static int4 longmax = taille_maxi_block_archeops*20; 670 if (!buffer) { 671 buffer = new char[longmax]; 672 #ifdef SWAP 673 bswap4(&debswp); 674 #endif 675 } 676 fseek(f,pos,SEEK_SET); 677 size_t read = fread(buffer,1,taille_maxi_block_archeops*2,f); 678 //if (read<taille_maxi_block_archeops*2) return -1; 679 for (int i=4; i<read; i+=4) { 680 if (*(int4*)(buffer+i) == debswp) { 681 cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl; 682 return pos+i; 683 } 684 } 685 cout << "cannot find block start" << endl; 686 return -1; 687 } 688 559 689 560 690 … … 562 692 static int mlen[] = {31,28,31,30,31,30,31,31,30,31,30,31}; 563 693 694 double ArcheopsFile::decodeMJD(string const& dateString) { 695 //99_04_29-15h36m22 ou 99_05_10 696 short y,m,d,hh,mm,ss; 697 char const* p = dateString.c_str(); 698 char const* p2 = dateString.c_str() + dateString.length(); 699 y = atoi(p); p+=3; if (p>p2) return -1; 700 m = atoi(p); p+=3; if (p>p2) return -1; 701 d = atoi(p); p+=3; 702 if (p<p2) { 703 hh = atoi(p); p+=3; if (p>p2) return -1; 704 mm = atoi(p); p+=3; if (p>p2) return -1; 705 ss = atoi(p); 706 } else { 707 hh=mm=ss=0; 708 } 709 710 if (y<50) y += 100; 711 // 1. depuis 0/1/97 minuit 712 double mjd = (int) (365.25 * (y-97)); 713 for (int i=0; i<m-1; i++) 714 mjd += mlen[i]; 715 if (y%4 == 0 && m > 2) mjd++; 716 mjd += d; 717 mjd += hh/24. + mm/24./60. + ss/24./60./60; 718 719 mjd += 448.5; // 0/1/97 minuit 720 721 return mjd; 722 } 723 564 724 void ArcheopsFile::computeMJD(string const& fname) { 565 // h99_04_29-15h36m22566 short y,m,d,hh,mm,ss;725 //telemetrie : h99_04_29-15h36m22 726 //enregistreur : ARKxxxxxx.dat, et MJD = samedi 17 juillet, 21h -> 1377.4 567 727 char const* p = fname.c_str(); 568 728 char const* p2 = p + fname.length()-1; … … 570 730 if (*p2 == ':' || *p2 == '/') p2++; 571 731 if (*p2 == 'h') p2++; 572 y = atoi(p2); p2+=3; 573 m = atoi(p2); p2+=3; 574 d = atoi(p2); p2+=3; 575 hh = atoi(p2); p2+=3; 576 mm = atoi(p2); p2+=3; 577 ss = atoi(p2); 578 579 if (y<50) y += 100; 580 // 1. depuis 0/1/97 minuit 581 rawMJD = (int) (365.25 * (y-97)); 582 for (int i=0; i<m-1; i++) 583 rawMJD += mlen[i]; 584 if (y%4 == 0 && m > 2) rawMJD++; 585 rawMJD += d; 586 rawMJD += hh/24. + mm/24./60. + ss/24./60./60; 587 588 rawMJD += 448.5; // 0/1/97 minuit 732 if (!strncmp(p2, "ARK",3)) { 733 rawMJD = 1377.4; 734 } else { 735 rawMJD = decodeMJD(p2); 736 } 589 737 startMJD = rawMJD - utcOffset/24.; 590 738 } … … 610 758 611 759 760 int ArcheopsFile::getGyroBlockNum() { 761 if (!lastGyro()) return -1; 762 return numero_block(lastGyro()); 763 } 764 765 612 766 // GPS 613 767 // $GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z, … … 621 775 double ArcheopsFile::getGPSUTC() { // en secondes depuis minuit UTC jour courant 622 776 if (!lastGPS()) return -9.e99; 623 char* p = lastGPS()->gps; 624 if (strncmp(p, "$GPGGA,", 7)) return -9.e99; 625 p += 7; 777 return blockSet->gpsParser.getUTC(); 778 /* char* p = lastGPS()->gps; 779 //if (strncmp(p, "$GPGGA,", 7)) return -9.e99; 780 //p += 7; 781 if (*p != '$') return -9.e99; 782 p += 1; 626 783 double t; 627 784 sscanf(p, "%lg", &t); 628 785 int h = int(t/10000); t -= h*10000; 629 786 int m = int(t/100); t -= m*100; 630 return h*3600. + m*60. + t; 787 return h*3600. + m*60. + t;*/ 631 788 } 632 789 633 790 double ArcheopsFile::getGPSMJD() { // modified julian day du dernier bloc GPS, JD - 2450000 634 double t = getGPSUTC()/86400. ;791 double t = getGPSUTC()/86400. - 0.5; 635 792 if (t<0) return t; 636 793 if (t > (startMJD - int(startMJD))) { … … 643 800 double ArcheopsFile::getGPSLat() { // degres, + = NORD 644 801 if (!lastGPS()) return -9.e99; 645 char* p = lastGPS()->gps; 646 if (strncmp(p, "$GPGGA,", 7)) return -9.e99; 802 return blockSet->gpsParser.getLatitude(); 803 /*char* p = lastGPS()->gps; 804 //if (strncmp(p, "$GPGGA,", 7)) return -9.e99; 805 if (*p!='$') return -9.e99; 647 806 char* fence = p+80; 648 p += 7;807 p += 1; 649 808 while (*p != ',' && p<fence) p++; 650 809 if (*p != ',') return -9.e99; … … 658 817 p++; 659 818 if (*p == 'S') t = -t; 660 return t; 661 } 819 return t;*/ 820 } 821 662 822 663 823 double ArcheopsFile::getGPSLong() { // degres, + = EST 664 824 if (!lastGPS()) return -9.e99; 665 char* p = lastGPS()->gps; 666 if (strncmp(p, "$GPGGA,", 7)) return -9.e99; 825 return blockSet->gpsParser.getLongitude(); 826 /*char* p = lastGPS()->gps; 827 //if (strncmp(p, "$GPGGA,", 7)) return -9.e99; 828 if (*p!='$') return -9.e99; 667 829 char* fence = p+80; 668 p += 7;830 p += 1; 669 831 for (int i=0; i<3; i++) { 670 832 while (*p != ',' && p<fence) p++; … … 680 842 p++; 681 843 if (*p == 'W') t = -t; 682 return t; 683 } 684 844 return t;*/ 845 } 846 847 double ArcheopsFile::getGPSAlt() { // meters from sea level 848 if (!lastGPS()) return -9.e99; 849 return blockSet->gpsParser.getAltitude(); 850 /*char* p = lastGPS()->gps; 851 //if (strncmp(p, "$GPGGA,", 7)) return -9.e99; 852 if (*p!='$') return -9.e99; 853 char* fence = p+80; 854 p += 1; 855 for (int i=0; i<8; i++) { 856 while (*p != ',' && p<fence) p++; 857 if (*p != ',') return -9.e99; 858 p++; 859 } 860 double t; 861 sscanf(p, "%lg", &t); 862 return t;*/ 863 } 864 865 bool ArcheopsFile::hasGPSTime() { 866 if (!lastGPS()) return false; 867 return blockSet->gpsParser.hasGPSTime(); 868 } 869 870 bool ArcheopsFile::hasGPSPos() { 871 if (!lastGPS()) return false; 872 return blockSet->gpsParser.hasPosition(); 873 } 874 875 bool ArcheopsFile::hasGPSAlt() { 876 if (!lastGPS()) return false; 877 return blockSet->gpsParser.hasAltitude(); 878 } 685 879 686 880 687 881 // Bolo 882 #define val_DS(j,i) (blk->data_bolo[j][i]&0x1fffff) 883 688 884 689 885 long ArcheopsFile::getRawBolo(int ibolo, int imesure) { // donnee brute, avec seulement soustraction offset 690 886 int nb_coups,aa; 691 887 block_type_bolo* blk = imesure >= 0 ? lastBolo() : llastBolo(); 888 //cout << "raw " << imesure << " "; 692 889 if (imesure < 0) imesure += nEchBlock(); 693 890 if (!blk) return 0; … … 699 896 700 897 int s = imesure % 2 ? 1 : -1; 701 702 return s*(((blk->data_bolo[ibolo][imesure]-aa)<<1)/nb_coups); 898 899 //cout << s*(((val_DS(ibolo,imesure)-aa)<<1)/nb_coups) << "\n"; 900 901 return s*(((val_DS(ibolo,imesure)-aa)<<1)/nb_coups); 703 902 } 704 903 … … 706 905 707 906 double ArcheopsFile::getMuVBolo(int ibolo, int imesure) { // microvolts, filtre avec filtre carre 708 double y = (getRawBolo(ibolo, imesure-1) -getRawBolo(ibolo, imesure))/2.;709 if (imesure%2) y=-y;907 double y = (getRawBolo(ibolo, imesure-1) + getRawBolo(ibolo, imesure))/2.; 908 //if (imesure%2) y=-y; 710 909 block_type_reglage* reglage = lastReglage(); 711 return ((1e5*y)/(65536.*gain_ampli(reglage->reglage.bolo[ibolo]))); 910 block_type_param* param = lastParam(); 911 //cout << "muv " << imesure << " " << y << "\n"; 912 return bol_micro_volt(y,(double)param->param.bolo[ibolo].bolo_gain*gain_ampli(reglage->reglage.bolo[ibolo])); 913 //return ((1e5*y)/(65536.*gain_ampli(reglage->reglage.bolo[ibolo]))); 712 914 } 713 915 … … 719 921 } 720 922 721 722 923 long ArcheopsFile::getSSTSignal(int idiode, int imesure) { 723 924 return blockSet->sstHandler.getSignal(imesure, idiode); 724 925 } 926 927 long ArcheopsFile::getSSTRawSignal(int idiode, int imesure) { 928 return blockSet->sstHandler.getRawSignal(imesure, idiode); 929 } 930 931 double ArcheopsFile::getSSTStarZ(int istar, int imesure) { 932 return blockSet->sstHandler.getStarZ(imesure, istar); 933 } 934 935 double ArcheopsFile::getSSTStarF(int istar, int imesure) { 936 return blockSet->sstHandler.getStarF(imesure, istar); 937 } 938 939 long ArcheopsFile::getGyro(int igyro, int imesure) { 940 if (igyro<0 || igyro>2) return 0; 941 if (imesure<0 || imesure>= nb_per_block*2) return 0; 942 block_type_gyro* blk = lastGyro() ; 943 if (!blk) return 0; 944 #if version_num<=25 945 return blk->gyros[igyro][imesure]; 946 #else 947 return blk->gyro[igyro][imesure]; 948 #endif 949 } 950 951 952 725 953 // $CHECK$ TBD 726 954
Note:
See TracChangeset
for help on using the changeset viewer.