| 1 | #include <stdlib.h> | 
|---|
| 2 | #include <stdio.h> | 
|---|
| 3 | #include <string.h> | 
|---|
| 4 | #include <ctype.h> | 
|---|
| 5 |  | 
|---|
| 6 | #include "strutil.h" | 
|---|
| 7 | #include "nomfits.h" | 
|---|
| 8 |  | 
|---|
| 9 | /*  RZ + CMV  07/94, modifs EROS II CMV 27/11/96  */ | 
|---|
| 10 |  | 
|---|
| 11 | /* | 
|---|
| 12 | ++ | 
|---|
| 13 | Module        Codage des noms de fichiers Eros 1 et 2 (C) | 
|---|
| 14 | Lib   LibsUtil | 
|---|
| 15 | include       nomfits.h | 
|---|
| 16 |  | 
|---|
| 17 | Pour coder et decoder les noms de fichiers Fits Eros 1 et 2. | 
|---|
| 18 | -- | 
|---|
| 19 | */ | 
|---|
| 20 |  | 
|---|
| 21 | /* Nouvelle-Fonction */ | 
|---|
| 22 | /* | 
|---|
| 23 | ++ | 
|---|
| 24 | int CodeFitsName(char const* nom) | 
|---|
| 25 | Decodage d'un `nom' de fichier pour fournir un entier code (Rc). | 
|---|
| 26 | | Rc :   C A MM JJ NNN  pour EROS I | 
|---|
| 27 | |      1 C A MM JJ NNN  pour EROS II | 
|---|
| 28 | |     (Une lettre = un chiffre decimal) | 
|---|
| 29 | | C Couleur : 1 = Rouge, 2= Bleu, 0 Sinon (cas EROS I) | 
|---|
| 30 | |   Camera  : 1 = Rouge, 2= Bleu, 0 Sinon (cas EROS II) | 
|---|
| 31 | | A  Annee  (Ex 1994 -> 4) | 
|---|
| 32 | | MM Mois   (01 a 12)   JJ  Jour (01 a 31) | 
|---|
| 33 | | NNN Numero de sequence en decimal (jusqu'a 999) | 
|---|
| 34 | | Remarque: Marche pour un nom EROS I ou EROS II | 
|---|
| 35 | -- | 
|---|
| 36 | */ | 
|---|
| 37 | int CodeFitsName(char const* nom) | 
|---|
| 38 | { | 
|---|
| 39 | int c,a,jj,mm,nn,l,rc; | 
|---|
| 40 | int ieros,ic,ia,im,ij,in; | 
|---|
| 41 | char name[30],s[6]; | 
|---|
| 42 |  | 
|---|
| 43 | strncpy(name,nom,28);  name[29] = '\0'; | 
|---|
| 44 | strip(name,'B',' '); | 
|---|
| 45 | if ( (l=posc(name,'.')) >= 0)  name[l] = '\0'; | 
|---|
| 46 | l = strlen(name); | 
|---|
| 47 | if (l < 8) {  /* type de nom inconnu */ | 
|---|
| 48 | return(0); | 
|---|
| 49 | } else if (l < 15 ) { /* c'est un nom EROS I */ | 
|---|
| 50 | ieros = 1; | 
|---|
| 51 | ic = 1; ia = 2; im = 3; ij = 4; in = 6; | 
|---|
| 52 | } else {              /* c'est un nom EROS II */ | 
|---|
| 53 | ieros = 2; | 
|---|
| 54 | ic = 5; ia = 10; im = 11; ij = 12; in = 14; | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | /* codage de la couleur/camera */ | 
|---|
| 58 | if( ieros == 1 ) { | 
|---|
| 59 | if(name[ic] == 'r')        c = 1; | 
|---|
| 60 | else if(name[ic] == 'b') c = 2; | 
|---|
| 61 | else                   c = 0; | 
|---|
| 62 | } else { | 
|---|
| 63 | c = (int)name[ic] - (int)'0'; c += 10; | 
|---|
| 64 | } | 
|---|
| 65 | rc = c*100000000; | 
|---|
| 66 |  | 
|---|
| 67 | /* codage de l'annee */ | 
|---|
| 68 | s[0] = name[ia];  s[1] = '\0'; | 
|---|
| 69 | a = atoi(s); | 
|---|
| 70 | rc += a*10000000; | 
|---|
| 71 |  | 
|---|
| 72 | /* codage du mois */ | 
|---|
| 73 | mm = (int)name[im]-(int)'a'+1; | 
|---|
| 74 | rc += mm*100000; | 
|---|
| 75 |  | 
|---|
| 76 | /* codage du jour */ | 
|---|
| 77 | s[0] = name[ij];  s[1] = name[ij+1];  s[2] = '\0'; | 
|---|
| 78 | jj = atoi(s); | 
|---|
| 79 | rc += jj*1000; | 
|---|
| 80 |  | 
|---|
| 81 | if( ieros == 1 ) { | 
|---|
| 82 | nn = strtol(name+in,NULL,16); | 
|---|
| 83 | } else { | 
|---|
| 84 | strncpy(s,&name[in],3); /* pas plus de 999 */ | 
|---|
| 85 | nn = atoi(s); | 
|---|
| 86 | } | 
|---|
| 87 | rc += nn; | 
|---|
| 88 |  | 
|---|
| 89 | return(rc); | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | /* Nouvelle-Fonction */ | 
|---|
| 93 | /* | 
|---|
| 94 | ++ | 
|---|
| 95 | char * DecodeNumPhoto(int num, char* nom) | 
|---|
| 96 | Fonction inverse de CodeFitsName(). Retourne | 
|---|
| 97 | le `nom' de fichier Fits Eros correspondant a l'entier `num'. | 
|---|
| 98 | -- | 
|---|
| 99 | */ | 
|---|
| 100 | char * DecodeNumPhoto(int num, char* nom) | 
|---|
| 101 | { | 
|---|
| 102 | int f,a,m,j,n; | 
|---|
| 103 | char cm,cf[3]; | 
|---|
| 104 | cf[0] = '-'; cf[1] = 'r'; cf[2] = 'b'; | 
|---|
| 105 |  | 
|---|
| 106 | n = num%1000; | 
|---|
| 107 | num = (num-n)/1000;  j = num%100; | 
|---|
| 108 | num = (num-j)/100;  m = num%100; | 
|---|
| 109 | if ((m<1) || (m > 12) )  cm = '-'; | 
|---|
| 110 | else  cm = 'a'+(m-1); | 
|---|
| 111 | num = (num-m)/100;  a = num%10; | 
|---|
| 112 | num = (num-a)/10;   f = num; | 
|---|
| 113 | if( f >= 10 ) {  /* c'est un nom EROS II */ | 
|---|
| 114 | f -= 10; | 
|---|
| 115 | sprintf(nom,"@%1d%1d%c%02d%d",f,a,cm,j,n); | 
|---|
| 116 | } else {        /* c'est un nom EROS I  */ | 
|---|
| 117 | if ((f>2) || (f<0))  f = 0; | 
|---|
| 118 | sprintf(nom,"@%c%1d%c%02d%02x",cf[f],a,cm,j,n); | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | return(nom); | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | /* Nouvelle-Fonction */ | 
|---|
| 125 | int CodeFilterName(char const* filtre) | 
|---|
| 126 | /*  Renvoie 1 pour filtre rouge , 2 Bleu, 0 sinon */ | 
|---|
| 127 | { | 
|---|
| 128 | char name[25]; | 
|---|
| 129 |  | 
|---|
| 130 | strncpy(name,filtre,20);  name[20] = '\0'; | 
|---|
| 131 | strip(name,'B',' '); | 
|---|
| 132 | if (tolower(name[0]) == 'r')  return(1); | 
|---|
| 133 | if (tolower(name[0]) == 'b')  return(2); | 
|---|
| 134 | return(0); | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | /* Nouvelle-Fonction */ | 
|---|
| 138 | /* | 
|---|
| 139 | ++ | 
|---|
| 140 | int CodeFilterName2(char const* nom,int* champ,int* coul,int* ccd) | 
|---|
| 141 | Decortique un nom de fichier EROS II et le code dans 3 entiers. | 
|---|
| 142 | | champ = conversion decimale du champ ex: cg601 -> 20909665 | 
|---|
| 143 | | coul  = codage numero de camera (D) + numero de filtre (Z) | 
|---|
| 144 | |       = nfilt*10 + ncam,  ex: camera 1 filtre z -> 35*10+1 = 351 | 
|---|
| 145 | |       recup rapide du num de camera: coul%10 | 
|---|
| 146 | | ccd   = codage du mumero de sous image (Z) et de CCD (D) | 
|---|
| 147 | |       = nssima*10 + nccd, ex: ssima=t ccd 7 -> 29*10+7 = 297 | 
|---|
| 148 | |       recup rapide du num de ccd: ccd%10 | 
|---|
| 149 | | Rc = 0 si OK, -1 sinon | 
|---|
| 150 | -- | 
|---|
| 151 | */ | 
|---|
| 152 | int CodeFilterName2(char const* nom,int* champ,int* coul,int* ccd) | 
|---|
| 153 | { | 
|---|
| 154 | int i1,i2,l; | 
|---|
| 155 | char name[30],s[6]; | 
|---|
| 156 | *champ = *coul = *ccd = 0; | 
|---|
| 157 |  | 
|---|
| 158 | strncpy(name,nom,28);  name[29] = '\0'; | 
|---|
| 159 | strip(name,'B',' '); | 
|---|
| 160 | if ( (l=posc(name,'.')) >= 0)  name[l] = '\0'; | 
|---|
| 161 | l = strlen(name); | 
|---|
| 162 | if (l < 15 ) return(-1); /* c'est pas un nom EROS II */ | 
|---|
| 163 |  | 
|---|
| 164 | strncpy(s,name,5); s[5]='\0'; | 
|---|
| 165 | *champ = strtol(s,NULL,36); | 
|---|
| 166 |  | 
|---|
| 167 | strncpy(s,&name[8],1); s[1]='\0'; | 
|---|
| 168 | i1 = strtol(s,NULL,36); | 
|---|
| 169 | i2 = (int)name[5] - (int)'0'; | 
|---|
| 170 | *coul = i1*10 + i2; | 
|---|
| 171 |  | 
|---|
| 172 | strncpy(s,&name[7],1); s[1]='\0'; | 
|---|
| 173 | i1 = strtol(s,NULL,36); | 
|---|
| 174 | i2 = (int)name[6] - (int)'0'; | 
|---|
| 175 | *ccd = i1*10 + i2; | 
|---|
| 176 |  | 
|---|
| 177 | return(0); | 
|---|
| 178 | } | 
|---|