00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023
00024
00025
00026
00027 #include <cpl.h>
00028 #include <xsh_data_pre.h>
00029 #include <xsh_error.h>
00030 #include <xsh_msg.h>
00031 #include <xsh_data_instrument.h>
00032 #include <xsh_dfs.h>
00033 #include <xsh_pfits.h>
00034 #include <math.h>
00035 #include <string.h>
00036 #include <xsh_paf_save.h>
00037 #include <xsh_qc_handling.h>
00038 #include <tests.h>
00039
00040
00041
00042
00043 #define MODULE_ID "XSH_PAF_SAVE"
00044
00045
00050
00051
00052
00056
00057
00058 static void with_dots( char *to, const char *from, char *filename )
00059 {
00060 int k ;
00061
00062 k = sprintf( to, "grep --quiet '" ) ;
00063 to += k ;
00064
00065 if ( strncmp( from, "ESO ", 4 ) == 0 )
00066 from += 4 ;
00067
00068 for( ; *from != '\0' ; from++, to++ )
00069 if ( *from == ' ' ) *to = '.' ;
00070 else *to = *from ;
00071 *to++ = '\'' ;
00072 *to++ = ' ' ;
00073 *to = '\0' ;
00074 strcat( to, filename ) ;
00075 }
00076
00077 int main(void)
00078 {
00079 cpl_propertylist *qc = NULL;
00080 char * filename = NULL;
00081 qc_description *pqc ;
00082 int ret=0;
00083 xsh_instrument * iiinstrument = NULL;
00084
00085 TESTS_INIT(MODULE_ID);
00086
00087
00088 {
00089 const char * const rrrecipe = "xsh_mbias";
00090 const char * pro_catg = NULL ;
00091
00092
00093 iiinstrument = xsh_instrument_new() ;
00094 xsh_instrument_set_arm( iiinstrument, XSH_ARM_UVB ) ;
00095 xsh_instrument_set_mode( iiinstrument, XSH_MODE_UNDEFINED ) ;
00096 pro_catg = "MASTER_BIAS_UVB" ;
00097
00098 filename = xsh_stringcat_any(rrrecipe, XSH_PAF_SAVE_EXTENSION, NULL) ;
00099
00100 assure( xsh_paf_save(iiinstrument, rrrecipe,
00101 NULL,
00102 filename, pro_catg)
00103 == CPL_ERROR_NULL_INPUT, CPL_ERROR_ILLEGAL_OUTPUT,
00104 "Failed to fail on NULL input");
00105 xsh_error_reset();
00106
00107 qc = cpl_propertylist_new();
00108
00109
00110 pqc = NULL ;
00111 while ( (pqc = xsh_get_qc_desc_by_recipe( rrrecipe, pqc )) != NULL ) {
00112
00113 switch( pqc->kw_type ) {
00114 case CPL_TYPE_INT:
00115 cpl_propertylist_append_int (qc, pqc->kw_name, 0 ) ;
00116 break ;
00117 case CPL_TYPE_DOUBLE:
00118 cpl_propertylist_append_double(qc, pqc->kw_name, 1.0 ) ;
00119 break ;
00120 case CPL_TYPE_CHAR:
00121 cpl_propertylist_append_char(qc, pqc->kw_name, 'x' ) ;
00122 break ;
00123 case CPL_TYPE_FLOAT:
00124 cpl_propertylist_append_float(qc, pqc->kw_name, 0.1 ) ;
00125 break ;
00126 case CPL_TYPE_STRING:
00127 cpl_propertylist_append_string(qc, pqc->kw_name, "ABCDEF" ) ;
00128 break ;
00129 default:
00130 xsh_msg( "Other Types not handled" ) ;
00131 break ;
00132 }
00133 if ( pqc->kw_help != NULL )
00134 cpl_propertylist_set_comment (qc, pqc->kw_name, pqc->kw_help ) ;
00135 }
00136
00137 assure( xsh_paf_save(iiinstrument, rrrecipe,
00138 qc,
00139 filename, pro_catg)
00140 == CPL_ERROR_NONE, cpl_error_get_code(),
00141 "PAF file creation failed");
00142
00143 pqc = NULL ;
00144 while ( (pqc = xsh_get_qc_desc_by_recipe( rrrecipe, pqc )) != NULL ) {
00145 char cmd[128] ;
00146
00147 memset( cmd, 0, 128 ) ;
00148 with_dots( cmd, pqc->kw_name, filename ) ;
00149 assure( system( cmd ) == 0, CPL_ERROR_ILLEGAL_INPUT,
00150 "QC parameter '%s' NOT in PAF",
00151 pqc->kw_name ) ;
00152 }
00153 }
00154
00155 cleanup:
00156 xsh_instrument_free( &iiinstrument);
00157 xsh_free_propertylist(&qc);
00158 cpl_free(filename);
00159 TEST_END();
00160
00161 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00162 xsh_error_dump(CPL_MSG_ERROR);
00163 ret = 1;
00164 }
00165 return ret;
00166 }