00001
00002 #include <cstdlib>
00003 #include <cassert>
00004 #include <cstdio>
00005
00006 #include "EEname2Index.h"
00007
00008
00009 void EEindexRange(int secID,int &ix1, int &ix2){
00010
00011 assert(secID>=0);
00012 assert(secID<=12);
00013 ix1=(secID-1)*1000;
00014 ix2=ix1+999;
00015 }
00016
00017
00018
00019
00020 void EEindex2Name(int ix,char *name){
00021 assert(ix>=0);
00022 assert(ix<EEindexMax);
00023
00024 int sec=1+ix/1000;
00025 assert(sec>0 && sec<=12);
00026
00027 int jx=ix%1000;
00028
00029 int key=jx/100;
00030
00031 char ckey=' ';
00032
00033 switch(key) {
00034 case 0: ckey='T';break;
00035 case 1: ckey='P';break;
00036 case 2: ckey='Q';break;
00037 case 3: ckey='R';break;
00038 case 4:
00039 case 5:
00040 case 6: ckey='U';break;
00041 case 7:
00042 case 8:
00043 case 9: ckey='V';break;
00044 default:
00045 printf("EEindex2Name() Logical Error1: invalid index=%d\n",ix);
00046 exit(-1);
00047 }
00048
00049
00050
00051 switch(ckey) {
00052 case 'T':
00053 case 'P':
00054 case 'Q':
00055 case 'R': {
00056 jx=jx%100 -1;
00057 int sub ='A'+jx/12;
00058 assert(sub>='A' && sub<='E');
00059 int eta=1+jx%12;
00060 assert(eta>0 && eta <=12);
00061 sprintf(name,"%2.2d%c%c%2.2d",sec,ckey,sub,eta);
00062 break;}
00063
00064 case 'V': jx-=300;
00065 case 'U': {
00066 int strip=jx-400;
00067 assert(strip>0 && strip<=288);
00068 sprintf(name,"%2.2d%c%3.3d",sec,ckey,strip);
00069 break;}
00070
00071 default:
00072 printf("EEindex2Name() Logical Error2: invalid index=%d\n",ix);
00073 exit(-1);
00074 }
00075
00076
00077 }
00078
00079
00080
00081
00082 int EEname2Index(const char *name){
00083
00084 int index=-1;
00085
00086 int sec=atoi(name);
00087 assert(sec>0 && sec<=12);
00088
00089 index=(sec-1)*1000;
00090
00091 if(sec<10 && name[0]!='0') name--;
00092 char key=name[2];
00093
00094 switch(key) {
00095 case 'R': index+=100;
00096 case 'Q': index+=100;
00097 case 'P': index+=100;
00098 case 'T': {
00099 int sub =name[3];
00100 assert(sub>='A' && sub<='E');
00101 int eta=atoi(name+4);
00102 assert(eta>0 && eta <=12);
00103 index+=(sub-'A')*12 +eta;
00104 } break;
00105 case 'V': index+=300;
00106 case 'U': {index+=400;
00107 int strip=atoi(name+3);
00108 assert(strip>0 && strip<=288);
00109 index+=strip;
00110 } break;
00111
00112 default:
00113 printf("EEname2Index('%s') Logical Error3: invalid index=%d\n",name,index);
00114 exit(-1);
00115 }
00116
00117
00118
00119 assert(index>=0);
00120 assert(index<EEindexMax);
00121
00122 return index;
00123
00124 }