/* * This program converts a list of ASCII star catalogs into a C header * file, ready to be included with the appropriate data structure * declarations and associated methods (see irstd.[ch]). * * The format for each catalog is: * col 1: Name * col 2: RA (2000) hrs min sec * col 3: DEC (2000) deg ' "" * col 4: spectral type. A table for correspondance with temperature * will be provided separately. Non 'standard' spectral types can just * be disabled. In some cases the spectral type is not provided (--). * col 5: J * col 6: H * col 7: K * col 8: Ks * col 9: L * col 10: M */ #include #include #include #include #include #include #include #include #define STRINGSZ 50 #define LINESZ 512 #define HEADERFILENAME "irlist.h" #define WEBPAGENAME "html/index.html" #define NMAXCATALOG 50 char * get_basename(const char *filename) { char *p ; p = strrchr (filename, '/'); return p ? p + 1 : (char *) filename; } int is_catalog_file(char * filename) { FILE * cat ; char line[10]; int ret ; DIR * dir ; if (filename==NULL) return 0 ; if ((dir=opendir(filename))!=NULL) { closedir(dir); return 0 ; } ret=0 ; if ((cat=fopen(filename, "r"))!=NULL) { fread(line, sizeof(char), 10, cat); fclose(cat); if (!strncmp(line, "# CATALOG", 9)) { ret=1; } } return ret ; } void generate_header_file(char ** catalogs, int ncat) { FILE * header_file ; int i ; int lineno ; char line[LINESZ+1] ; FILE * tab ; char star_name [STRINGSZ], star_ra_1 [STRINGSZ], star_ra_2 [STRINGSZ], star_ra_3 [STRINGSZ], star_dec_1 [STRINGSZ], star_dec_2 [STRINGSZ], star_dec_3 [STRINGSZ], star_sptype [STRINGSZ], star_J [STRINGSZ], star_H [STRINGSZ], star_K [STRINGSZ], star_Ks [STRINGSZ], star_L [STRINGSZ], star_M [STRINGSZ] ; int scanned ; double ra, dec ; header_file = fopen(HEADERFILENAME, "w"); if (header_file==NULL) { printf("cannot create %s: aborting\n", HEADERFILENAME); return ; } /* Print out header */ fprintf(header_file, "\n" "\n" "#ifndef _IRLIST_H_\n" "#define _IRLIST_H_\n" "\n"); /* Print out catalog information */ fprintf(header_file, "\n" "static const char * irstd_catalogs[] = {\n", ncat ); for (i=0 ; i\n" "Infrared standard star catalog\n" "\n" "

\n" "List of all catalogs:\n" "

\n" "
    \n"); for (i=0 ; i%s\n", get_basename(catalogs[i]), get_basename(catalogs[i])); } fprintf(wpage, "
\n" "\n" "\n"); fclose(wpage); for (i=0 ; i\n" "Catalog: %s\n" "\n", get_basename(catalogs[i])); fprintf(wpage, "

Catalog: %s

\n", get_basename(catalogs[i])); fprintf(wpage, "

\n" "\n" ); fprintf(wpage, "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n"); lineno = 0 ; while (fgets(line, LINESZ, tab)!=NULL) { if (line[0]=='#') continue; line[LINESZ] = (char)0; lineno++ ; scanned = sscanf(line, "%s | %s %s %s | %s %s %s | %s | %s | %s | %s | %s | %s | %s", star_name, star_ra_1, star_ra_2, star_ra_3, star_dec_1, star_dec_2, star_dec_3, star_sptype, star_J, star_H, star_K, star_Ks, star_L, star_M); if (scanned != 14) { printf("syntax error file %s line %d\n", catalogs[i], lineno); } else { if (!strcmp(star_J, "99")) { strcpy(star_J, "--"); } if (!strcmp(star_H, "99")) { strcpy(star_H, "--"); } if (!strcmp(star_K, "99")) { strcpy(star_K, "--"); } if (!strcmp(star_Ks, "99")) { strcpy(star_Ks, "--"); } if (!strcmp(star_L, "99")) { strcpy(star_L, "--"); } if (!strcmp(star_M, "99")) { strcpy(star_M, "--"); } fprintf(wpage, "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n", star_name, star_ra_1, star_ra_2, star_ra_3, star_dec_1, star_dec_2, star_dec_3, star_sptype, star_J, star_H, star_K, star_Ks, star_L, star_M); } } fclose(tab); fprintf(wpage, "
NameRADecSpTypeJHKKsLM
%s%s:%s:%s%s:%s:%s%s%s%s%s%s%s%s
\n" "

\n" "\n"); /* Output tail */ fprintf(wpage, "\n" "\n"); fclose(wpage); } return ; } int main(int argc, char *argv[]) { char ** catalogs ; int ncat ; int nstars ; int i, j ; int web_page ; if (argc<2) { printf("usage: %s \n", argv[0]); return 1 ; } /* Identify catalogs in command-line arguments */ web_page = 0 ; ncat = 0 ; for (i=1 ; i