| 1 | /*
 | 
|---|
| 2 | Check if suivi is OK
 | 
|---|
| 3 | > chkfsv -e 1,99999,10 -m 1,99999,10 -p 2 -d 1001,11 s4l074l15R.suivi01
 | 
|---|
| 4 | > echo $status
 | 
|---|
| 5 | */
 | 
|---|
| 6 | #include "sopnamsp.h"
 | 
|---|
| 7 | #include "machdefs.h"
 | 
|---|
| 8 | #include <stdlib.h>
 | 
|---|
| 9 | #include <stdio.h>
 | 
|---|
| 10 | #include <string.h>
 | 
|---|
| 11 | #include <ctype.h>
 | 
|---|
| 12 | #include <math.h>
 | 
|---|
| 13 | #include <iostream>
 | 
|---|
| 14 | #include <typeinfo>
 | 
|---|
| 15 | #include <unistd.h>
 | 
|---|
| 16 | 
 | 
|---|
| 17 | #include "fsvcache.h"
 | 
|---|
| 18 | #include "fsvst.h"
 | 
|---|
| 19 | 
 | 
|---|
| 20 | void usage(void)
 | 
|---|
| 21 | {
 | 
|---|
| 22 |  printf("Usage: chkfsv NomSuivi\n");
 | 
|---|
| 23 |  printf("  -e n1,n2,inc : Traitement des etoiles n1 a n2 avec increment inc\n");
 | 
|---|
| 24 |  printf("  -m m1,m2,inc : Traitement des mesures m1 a m2 avec increment inc\n");
 | 
|---|
| 25 |  printf("  -p lp : print level\n");
 | 
|---|
| 26 |  printf("  -d et,mes : debug by full printing for star et and mesure mes\n");
 | 
|---|
| 27 |  printf("Warning: number go [1,n]\n");
 | 
|---|
| 28 | }
 | 
|---|
| 29 | 
 | 
|---|
| 30 | int main(int narg, char *arg[] )
 | 
|---|
| 31 | {
 | 
|---|
| 32 |  //---- Decodage des arguments
 | 
|---|
| 33 |  int lp=1, etdbg=-1, mesdbg=-1;
 | 
|---|
| 34 |  int numes1=1, numes2=9999999, incmes=1;
 | 
|---|
| 35 |  int numet1=1, numet2=9999999, incet=1;
 | 
|---|
| 36 |  if(narg<2)  {usage(); return 1;}
 | 
|---|
| 37 |  char c;
 | 
|---|
| 38 |  while((c = getopt(narg, arg, "he:m:p:d:")) != -1) {
 | 
|---|
| 39 |    switch (c) {
 | 
|---|
| 40 |    case 'e' :
 | 
|---|
| 41 |      sscanf(optarg,"%d,%d,%d",&numet1,&numet2,&incet);
 | 
|---|
| 42 |    case 'm' :
 | 
|---|
| 43 |      sscanf(optarg,"%d,%d,%d",&numes1,&numes2,&incmes);
 | 
|---|
| 44 |    case 'p' :
 | 
|---|
| 45 |      sscanf(optarg,"%d",&lp);
 | 
|---|
| 46 |      if(lp<0) lp=0;
 | 
|---|
| 47 |    case 'd' :
 | 
|---|
| 48 |      sscanf(optarg,"%d,%d",&etdbg,&mesdbg);
 | 
|---|
| 49 |    break;
 | 
|---|
| 50 |    case 'h' :
 | 
|---|
| 51 |    default:
 | 
|---|
| 52 |      usage();
 | 
|---|
| 53 |      return 1;
 | 
|---|
| 54 |    }
 | 
|---|
| 55 |  }
 | 
|---|
| 56 |  if(optind>=narg) {usage(); return 2;}
 | 
|---|
| 57 |  char svf[2048];
 | 
|---|
| 58 |  strcpy(svf,arg[optind]);
 | 
|---|
| 59 | 
 | 
|---|
| 60 |  int rc = 0;
 | 
|---|
| 61 | 
 | 
|---|
| 62 |  //---- Ouverture du fichier de suivi
 | 
|---|
| 63 |  SUIVIFIP *sfip = NULL;
 | 
|---|
| 64 |  if( (sfip=SuiviOpen(svf,SUOF_RO_MEM2)) == NULL ) {
 | 
|---|
| 65 |    cout<<"Error opening: "<<svf<<endl;
 | 
|---|
| 66 |    return(10);
 | 
|---|
| 67 |  }
 | 
|---|
| 68 |  if(lp>0) cout<<svf<<endl;
 | 
|---|
| 69 |  int nbstar = SuiviGetNbStars(sfip);
 | 
|---|
| 70 |  int nbmes = SuiviGetNbMesures(sfip);
 | 
|---|
| 71 |  if(lp>0) cout<<"nbstar = "<<nbstar<<" nbmes = "<<nbmes<<endl;
 | 
|---|
| 72 | 
 | 
|---|
| 73 |  if(incet<=0) incet = 1;
 | 
|---|
| 74 |  if(numes1<1) numes1 = 1;
 | 
|---|
| 75 |  if(numes2<1) numes2 = 1;
 | 
|---|
| 76 |  if(numes2>nbmes) numes2 = nbmes;
 | 
|---|
| 77 |  if(numes2<numes1) numes1 = numes2;
 | 
|---|
| 78 |  if(incmes<=0) incmes = 1;
 | 
|---|
| 79 |  if (numet1<1) numet1 = 1;
 | 
|---|
| 80 |  if (numet2<1) numet2 = 1;
 | 
|---|
| 81 |  if (numet2>nbstar) numet2 = nbstar;
 | 
|---|
| 82 |  if (numet2<numet1) numet1 = numet2;
 | 
|---|
| 83 |   
 | 
|---|
| 84 |  //----  Lecture GlobInfo
 | 
|---|
| 85 |  GLOBINFO glinf;
 | 
|---|
| 86 |  if(lp>0) cout<<"Reading GlobInfo"<<endl;
 | 
|---|
| 87 |  rc = SuiviReadGlobInfo(sfip, (char *)(&glinf));
 | 
|---|
| 88 |  if(rc!=0) {
 | 
|---|
| 89 |    cout<<"Error reading GlobInfo rc="<<rc<<endl;
 | 
|---|
| 90 |    return 11;
 | 
|---|
| 91 |  } 
 | 
|---|
| 92 |  if(lp>1) {cout<<"\n>>> GLOBINFO"<<endl; PrtGlobInfo(&glinf,99);}
 | 
|---|
| 93 |   
 | 
|---|
| 94 |  //---- Lecture TimeInfo
 | 
|---|
| 95 |  TIMEINFO tminf;
 | 
|---|
| 96 |  TIMEINFOU tminfu;
 | 
|---|
| 97 |  if(lp>0) cout<<"Reading TimeInfo from "<<numes1<<" to "<<numes2<<" with inc "<<incmes<<endl;
 | 
|---|
| 98 |  if(nbmes>0) for(int i=numes1;i<=numes2;i++) {
 | 
|---|
| 99 |    rc = SuiviReadTimeInfo(sfip,i,i,(char *)(&tminf));
 | 
|---|
| 100 |    if(rc!=0) {
 | 
|---|
| 101 |      cout<<"Error reading TimeInfo mes="<<i<<" rc="<<rc<<endl;
 | 
|---|
| 102 |      return 12;
 | 
|---|
| 103 |    }
 | 
|---|
| 104 |    if(mesdbg==i) {
 | 
|---|
| 105 |      cout<<"\n>>> TIMEINFO"<<endl; PrtTimeInfo(&tminf,i,99);
 | 
|---|
| 106 |      DecodeTim(&tminf,&tminfu);
 | 
|---|
| 107 |      cout<<"\n>>> TIMEINFOU"<<endl; PrtTimeInfoU(&tminfu,i,99);
 | 
|---|
| 108 |    }
 | 
|---|
| 109 |  }
 | 
|---|
| 110 |   
 | 
|---|
| 111 |  //---- Lecture StarInfo
 | 
|---|
| 112 |  STARINFO  star;
 | 
|---|
| 113 |  if(lp>0) cout<<"Reading StarInfo from "<<numet1<<" to "<<numet2<<" with inc "<<incet<<endl;
 | 
|---|
| 114 |  if(nbstar>0) for(int i=numet1;i<=numet2;i+=incet) {
 | 
|---|
| 115 |    rc = SuiviReadStarInfo(sfip,i,(char *)(&star));
 | 
|---|
| 116 |    if(rc!=0) {
 | 
|---|
| 117 |      cout<<"Error reading StarInfo star="<<i<<" rc="<<rc<<endl;
 | 
|---|
| 118 |      return 13;
 | 
|---|
| 119 |    }
 | 
|---|
| 120 |    if(etdbg==i) {cout<<"\n>>> STARINFO"<<endl; PrtStarInfo(&star,i,99);}
 | 
|---|
| 121 |  }
 | 
|---|
| 122 |   
 | 
|---|
| 123 |   //---- Lecture Mesures
 | 
|---|
| 124 |   MESURE mes;
 | 
|---|
| 125 |   MESUREU mesu;
 | 
|---|
| 126 |   if(lp>0) cout<<"Reading Mesures"<<endl;
 | 
|---|
| 127 |   if(nbstar>0) for(int i=numet1;i<=numet2;i+=incet) {
 | 
|---|
| 128 |     if(nbmes>0) for(int j=numes1;j<=numes2;j+=incmes) {
 | 
|---|
| 129 |       rc = SuiviReadMesures(sfip,i,j,j,(char *)(&mes));
 | 
|---|
| 130 |       if(rc!=0) {
 | 
|---|
| 131 |         cout<<"Error reading Mesures star="<<i<<" mes="<<j<<" rc="<<rc<<endl;
 | 
|---|
| 132 |         return 14;
 | 
|---|
| 133 |       }
 | 
|---|
| 134 |       if(etdbg==i && mesdbg==j) {
 | 
|---|
| 135 |         cout<<"\n>>> MESURE"<<endl; PrtMesure(&mes,j,99);
 | 
|---|
| 136 |         DecodeMes(&mes,&mesu);
 | 
|---|
| 137 |         cout<<"\n>>> MESUREU"<<endl; PrtMesureU(&mesu,j,99);
 | 
|---|
| 138 |         Calibre_F_E(&mesu,&tminfu);
 | 
|---|
| 139 |         cout<<"\n>>> MESUREU apres Calib"<<endl; PrtMesureU(&mesu,j,99);
 | 
|---|
| 140 |       }
 | 
|---|
| 141 |     }
 | 
|---|
| 142 |   }
 | 
|---|
| 143 |   
 | 
|---|
| 144 |   //---- Fermeture du fichier de Suivi
 | 
|---|
| 145 |   rc = SuiviClose(sfip);
 | 
|---|
| 146 |   if(rc!=0) {
 | 
|---|
| 147 |     cout<<"Error Closing Suivi file rc="<<rc<<endl;
 | 
|---|
| 148 |     return 15;
 | 
|---|
| 149 |   }
 | 
|---|
| 150 | 
 | 
|---|
| 151 |   return(rc);
 | 
|---|
| 152 | }
 | 
|---|