2014年8月3日日曜日

スミソニアン天体物理観測所星表

ちょっとやってみたいことがあって、恒星カタログが欲しくなったのでスミソニアン天体物理観測所星表というデータを落としてみました
NASAのWebサイトからダウンロードでき、展開後のデータは約50MBです

このデータは固定長文字列で表現されていて、フォーマットはWebサイトに公開されています
が、あんまり扱いやすいデータではないと思います

とりあえず構造体と、文字列から構造体へ変換する関数、それとそれに必要となる関数を作ったので、最後に置いておきます


スミソニアン天体物理観測所(SAO)星表は1行204文字の文字列で表され、それぞれのデータは\nで区切られます
つまり1つのデータは205バイトです
現在のカタログには258997個の恒星が登録されていて、データファイルの大きさは正確に53094385バイトです

※約26万個の中には削除フラグが付いているものがいくつかあります


1行205バイトのデータには52種の値が格納されており、その値は整数だったり、浮動小数点だったり、文字だったり、文字列だったりします

とりあえず簡単に使えそうなデータは赤緯、赤経、視等級くらいでしょうか
ただこのカタログにはどこにどれくらいの明るさの星がある ということしかわからず、星座の星を探す場合は何らかの方法で星座とそれに使われている恒星、恒星からSAO番号を関連付ける必要があります


このデータをどのように加工すれば欲しい情報が手に入るか… まだ不明なところも多いですが、もうちょっと色々調べてみようと思います




/* 構造体 */
typedef struct {
    int     SAO;
    char    delFlag;
    int     RAh;
    int     RAm;
    float   RAs;
    float   pmRA;
    int     e_pmRA;
    char    RA2mf;
    float   RA2s;
    int     e_RA2s;
    float   EpRA2;
    char    DE;
    int     DEd;
    int     DEm;
    float   DEs;
    float   pmDE;
    int     e_pmDE;
    char    DE2mf;
    float   DE2s;
    int     e_DE2s;
    float   EpDE2;
    int     e_Pos;
    float   Pmag;
    float   Vmag;
    char    SpType    [3 + 1];
    int     r_Vmag;
    int     r_Num;
    int     r_Pmag;
    int     r_pmRA;
    int     r_SpType;
    int     Rem;
    int     a_Vmag;
    int     a_Pmag;
    int     r_Cat;
    int     CatNum;
    char    DM        [13 + 1];
    char    HD        [6 + 1];
    char    m_HD;
    char    GC        [5 + 1];
    float   RArad;
    float   DErad;
    int     RA2000h;
    int     RA2000m;
    float   RA2000s;
    float   pmRA2000;
    char    DE2000;
    int     DE2000d;
    int     DE2000m;
    float   DE2000s;
    float   pmDE2000;
    float   RA2000rad;
    float   DE2000rad;
#ifdef SAO_RAW_DATA
    char    RAW        [210];
#endif
} SAO_t;

/* 関数 */
const SAO_t *dec(const char *line) {
char str[20];
static SAO_t SAO;

strncopy(line +   0, str ,  6);
sscanf(str, "%d", &SAO.SAO);
strncopy(line +   6, str ,  1);
sscanf(str, "%c", &SAO.delFlag);
strncopy(line +   7, str ,  2);
sscanf(str, "%d", &SAO.RAh);
strncopy(line +   9, str ,  2);
sscanf(str, "%d", &SAO.RAm);
strncopy(line +  11, str ,  6);
sscanf(str, "%f", &SAO.RAs);
strncopy(line +  17, str ,  7);
sscanf(str, "%f", &SAO.pmRA);
strncopy(line +  24, str ,  2);
sscanf(str, "%d", &SAO.e_pmRA);
strncopy(line +  26, str ,  1);
sscanf(str, "%c", &SAO.RA2mf);
strncopy(line +  27, str ,  6);
sscanf(str, "%f", &SAO.RA2s);
strncopy(line +  33, str ,  2);
sscanf(str, "%d", &SAO.e_RA2s);
strncopy(line +  35, str ,  6);
sscanf(str, "%f", &SAO.EpRA2);
strncopy(line +  41, str ,  1);
sscanf(str, "%c", &SAO.DE);
strncopy(line +  42, str ,  2);
sscanf(str, "%d", &SAO.DEd);
strncopy(line +  44, str ,  2);
sscanf(str, "%d", &SAO.DEm);
strncopy(line +  46, str ,  5);
sscanf(str, "%f", &SAO.DEs);
strncopy(line +  51, str ,  6);
sscanf(str, "%f", &SAO.pmDE);
strncopy(line +  57, str ,  2);
sscanf(str, "%d", &SAO.e_pmDE);
strncopy(line +  59, str ,  1);
sscanf(str, "%c", &SAO.DE2mf);
strncopy(line +  60, str ,  5);
sscanf(str, "%f", &SAO.DE2s);
strncopy(line +  65, str ,  2);
sscanf(str, "%d", &SAO.e_DE2s);
strncopy(line +  67, str ,  6);
sscanf(str, "%f", &SAO.EpDE2);
strncopy(line +  73, str ,  3);
sscanf(str, "%d", &SAO.e_Pos);
strncopy(line +  76, str ,  4);
sscanf(str, "%f", &SAO.Pmag);
strncopy(line +  80, str ,  4);
sscanf(str, "%f", &SAO.Vmag);
strncopy(line +  84, str ,  3);
sscanf(str, "%[^\n]",  SAO.SpType);
strncopy(line +  87, str ,  2);
sscanf(str, "%d", &SAO.r_Vmag);
strncopy(line +  89, str ,  2);
sscanf(str, "%d", &SAO.r_Num);
strncopy(line +  91, str ,  1);
sscanf(str, "%d", &SAO.r_Pmag);
strncopy(line +  92, str ,  1);
sscanf(str, "%d", &SAO.r_pmRA);
strncopy(line +  93, str ,  1);
sscanf(str, "%d", &SAO.r_SpType);
strncopy(line +  94, str ,  1);
sscanf(str, "%d", &SAO.Rem);
strncopy(line +  95, str ,  1);
sscanf(str, "%d", &SAO.a_Vmag);
strncopy(line +  96, str ,  1);
sscanf(str, "%d", &SAO.a_Pmag);
strncopy(line +  97, str ,  2);
sscanf(str, "%d", &SAO.r_Cat);
strncopy(line +  99, str ,  5);
sscanf(str, "%d", &SAO.CatNum);
strncopy(line + 104, str , 13);
sscanf(str, "%[^\n]",  SAO.DM);
strncopy(line + 117, str ,  6);
sscanf(str, "%[^\n]",  SAO.HD);
strncopy(line + 123, str ,  1);
sscanf(str, "%c", &SAO.m_HD);
strncopy(line + 124, str ,  5);
sscanf(str, "%[^\n]",  SAO.GC);
strncopy(line + 129, str , 10);
sscanf(str, "%f", &SAO.RArad);
strncopy(line + 139, str , 11);
sscanf(str, "%f", &SAO.DErad);
strncopy(line + 150, str ,  2);
sscanf(str, "%d", &SAO.RA2000h);
strncopy(line + 152, str ,  2);
sscanf(str, "%d", &SAO.RA2000m);
strncopy(line + 154, str ,  6);
sscanf(str, "%f", &SAO.RA2000s);
strncopy(line + 160, str ,  7);
sscanf(str, "%f", &SAO.pmRA2000);
strncopy(line + 167, str ,  1);
sscanf(str, "%c", &SAO.DE2000);
strncopy(line + 168, str ,  2);
sscanf(str, "%d", &SAO.DE2000d);
strncopy(line + 170, str ,  2);
sscanf(str, "%d", &SAO.DE2000m);
strncopy(line + 172, str ,  5);
sscanf(str, "%f", &SAO.DE2000s);
strncopy(line + 177, str ,  6);
sscanf(str, "%f", &SAO.pmDE2000);
strncopy(line + 183, str , 10);
sscanf(str, "%f", &SAO.RA2000rad);
strncopy(line + 193, str , 11);
sscanf(str, "%f", &SAO.DE2000rad);

#ifdef SAO_RAW_DATA
memcpy(SAO.RAW, line, 204);
SAO.RAW[204] = '\0';
#endif

return(&SAO);
}

/* 文字列切り出し関数 */
const char *strncopy(const char *str1, char *str2, int n) {
const char *p1 = str1;
char *p2 = str2;
int i = 0;
for (i = 0; i < n; i++) {
*p2++ = *p1;
if (!*p1++) { break; }
}
for (; i < n; i++) {
*p2++ = '\0';
}
str2[n] = '\0';
return(str2);
}

0 件のコメント:

コメントを投稿