/***************************************************************************** *File: pds2fits.c *Programmers: Anne Raugh * Dorian Winterfeld *Institution: PDS/Small Bodies Node * University of Maryland *Date: Feb 20, 1995 *Last revision: *Abstract: Main function for the PDS to FITS translator. * * Modification History * * 19 Jan 1996, acr: Added failure print statement after check for * successful opening of PDSDD file. * *****************************************************************************/ #include #include #include #include "pds_util.h" #include "fits_obj.h" #include "pds.h" #include "pdserror.h" #include "pds_tbl.h" #include "fits_hdr.h" #include "defaults.h" /* Global Variables */ FILE *FITS_file; /* Pointer to FITS file */ FILE *PDS_file; /* Pointer to PDS file */ FILE *table_file; /* Pointer to user translation table */ FILE *PDSDD; /* Pointer to PDS Data Dictionary file */ FILE *index_file; /* Pointer to PDSDD index file */ FILE *trans_out; /* output file for translation table */ FILE *log_file; /* output file for unmatched FITS keywords */ FILE *reserved_file; /* list of reserved FITS keywords */ /********************************************************************* *Function: main *Abstract: Main driver routine for the fits to pds translator *Description: Reads in command line arguments. OPEN all input files. * Read in translation table. Setup FITS header. Read in * PDS file and build FITS objects. Write objects to * ITS header. Close all files. ***********************************************************************/ void main(int argc, char *argv[]) { table *ttable,*ltable; /* translation tables pointers*/ FITS_object *main_object; /* FITS main object pointer */ char FITS_filename[50]; /* FITS file name */ char PDS_filename[50]; /* PDS file name */ char table_filename[50]; /* User defined translation table */ char reserved_filename[50];/* name of reserved keyword file */ char table[50]; /* holds table name */ char log_filename[50]; /* holds error log file name */ char *dd_path = NULL; /* holds path to PDSDD */ char pds_dd2[200]; /* full path to PDSDD */ char pds_idx2[200]; /* full path to PDSDD index */ char pds_dd[15]; /* PDSDD name */ char *name; char pds_idx[15]; /* PDSDD index name */ char *std_path = NULL; /* path to Standard Translation Table*/ char keyword[100]; /* FITS keyword from reserved list*/ int status; /* error status */ int done = FALSE; /* used when reading in the reserved */ list_type *reserved_list; /* list of reserved FITS keywords */ /* default filename for reserved keyword list */ strcpy(reserved_filename,RES_KEYS); /* parse command line arguments */ status = parse_arguments(argc,argv,PDS_filename,table_filename, FITS_filename,reserved_filename,&dd_path, &std_path); if (status <= 0){ print_error(status); exit(1); } /* Open the FITS header file */ PDS_file = fopen(PDS_filename,"r"); if ( !PDS_file ){ print_error(PDS_ERROR); exit(1); } /* Open User defined translation table */ table_file = fopen(table_filename,"r"); if ( !table_file ){ print_error(TBL_ERROR); fclose( FITS_file ); exit(1); } /* Create FITS header file */ FITS_file = fopen(FITS_filename,"w+"); if (!PDS_file) { print_error(FITS_ERROR); fclose( PDS_file ); fclose( table_file ); exit(1); } /* build path and open PDSDD */ strcpy(pds_dd,"pdsdd.full"); if (dd_path == NULL) make_path(PDSDD_PATH,pds_dd,pds_dd2); else make_path(dd_path,pds_dd,pds_dd2); PDSDD = fopen(pds_dd2,"r"); if (!PDSDD) { printf("Cannot open PDSDD!\n"); fclose( FITS_file ); fclose( table_file ); fclose( PDS_file ); exit(1); } /* build path for PDS Data Dictionary Index */ strcpy(pds_idx,"pdsdd.idx"); if (dd_path == NULL) make_path(PDSDD_PATH,pds_idx,pds_idx2); else make_path(dd_path,pds_idx,pds_idx2); index_file = fopen(pds_idx2,"r"); if (!index_file) { print_error(INDEX_ERROR); fclose( FITS_file ); fclose( table_file ); fclose( PDS_file ); fclose( PDSDD ); exit(1); } /* Open log file for unmatched FITS keywords and error messages */ name = strtok(PDS_filename,"."); strcpy(log_filename,name); strcat(log_filename,".log"); log_file = fopen(log_filename,"w"); if (!log_file) { print_error(LOG_ERROR); fclose( FITS_file ); fclose( table_file ); fclose( PDS_file ); fclose( PDSDD ); fclose( index_file ); fclose( trans_out ); exit(1); } print_header(log_filename); /* open reserved keyword list file */ reserved_file = fopen(reserved_filename,"r"); if ( !reserved_file ){ print_error(RES_ERROR); close_files(); exit(1); } /* read in reserved keyword list */ reserved_list = list_create(); while(fgets(keyword,100,reserved_file)&&(done == FALSE)) { while ((keyword[0] == '#') || (keyword[0] == ' ')) if (!fgets(keyword,100,reserved_file)) done = TRUE; insert(reserved_list,keyword); } /* initialise translation table */ if ((ttable = init_table(ttable)) == NULL){ print_error(MALLOC_ERROR); close_files(); exit(1); } /* initialize literal table */ if ((ltable = init_table(ltable)) == NULL){ print_error(MALLOC_ERROR); close_files(); exit(1); } /* read in translation table */ printf("\nReading in translation table.\n"); fprintf(log_file,"\nReading in translation table.\n"); status = read_table(ltable,ttable,std_path,reserved_list); if (status < 1 ){ print_error(status); close_files(); exit(1); } else if (status > 1 ){ print_error(status); } /* setup FITS header */ printf("\nSetting up PDS label data structures.\n"); fprintf(log_file,"\nSetting up PDS label data structures.\n"); status = setup_FITS_object(ttable,&main_object); if (status < 1){ print_error(status); close_files(); exit(1); } else if (status > 1){ print_error(status); } /* read in PDS file and build FITS object */ printf("\nReading in PDS label file.\n"); fprintf(log_file,"\nReading in PDS label file.\n"); fprintf(log_file,"Unmatched PDS keywords (if any):\n"); status = read_PDS_file(main_object,ttable,ltable); if (status < 1 ) { print_error(status); close_files(); exit(1); } else if (status > 1){ print_error(status); } /* write to FITS output file */ printf("\nWriting FITS header.\n"); fprintf(log_file,"\nWriting FITS header.\n"); status = write_FITS_header(main_object); if (status < 1){ print_error(status); close_files(); exit(1); } else if (status > 1) print_error(status); close_files(); exit(1); } /* end fits2pds */