/*+++++++++++++++++++++++++
.IDENTifer  SCIA_LV2_WR_ASCII_SQADS
.PURPOSE    dump -- in ASCII Format -- the SQADS
.INPUT/OUTPUT
  call as   SCIA_LV2_WR_ASCII_SQADS( param, num_dsr, sqads );
     input:
            struct param_record param : struct holding user-defined settings
	    unsigned int num_dsr      : number of data sets
	    struct sqads2_scia *sqads : pointer to SQADS records
            
.RETURNS     Nothing, error status passed by global variable ``nadc_stat''
.COMMENTS    None
-------------------------*/
void SCIA_LV2_WR_ASCII_SQADS( struct param_record param, unsigned int num_dsr,
			      const struct sqads2_scia *sqads )
{
     register unsigned int nd, nr;

     char date_str[UTC_STRING_LENGTH];
     unsigned int  count[2];

     FILE *outfl = CRE_ASCII_File( param.outfile, "sqads" );

     if ( outfl == NULL || IS_ERR_STAT_FATAL )
	  NADC_RETURN_ERROR( NADC_ERR_FILE_CRE, param.outfile );
/*
 * write ASCII dump of SQADS record
 */
     nadc_write_header( outfl, 0, param.infile,  
			 "Summary of Quality Flags per State" );
     for ( nd = 0; nd < num_dsr; nd++ ) {
	  nr = 1;
	  (void) MJD_2_ASCII( sqads[nd].mjd.days, sqads[nd].mjd.secnd,
			      sqads[nd].mjd.musec, date_str );
	  nadc_write_text( outfl, nr++, "Date", date_str );
	  nadc_write_uchar( outfl, nr++, "MDS DSR attached", 
			     sqads[nd].flag_mds );
	  count[0] = NL2_SQADS_PQF_FLAGS;
	  nadc_write_arr_uchar( outfl, nr++, "summary of quality (PQF)", 
				 1, count, sqads[nd].flag_pqf );
     }
     (void) fclose( outfl );
}
/*+++++++++++++++++++++++++ Main Program or Function +++++++++++++++*/
void ENVI_WR_ASCII_MPH( struct param_record param, 
			const struct mph_envi *mph )
{
     register unsigned int  nr = 0;

     FILE *outfl = CRE_ASCII_File( param.outfile, "mph" );

     if ( outfl == NULL || IS_ERR_STAT_FATAL )
	  NADC_RETURN_ERROR( NADC_ERR_FILE_CRE, param.outfile );
/*
 * write ASCII dump of MPH record
 */
     nadc_write_header( outfl, nr, param.infile, "Main Product Header" );
     nadc_write_text( outfl, ++nr, "PRODUCT", mph->product );
     nadc_write_text( outfl, ++nr, "PROC_STAGE", mph->proc_stage );
     nadc_write_text( outfl, ++nr, "REF_DOC", mph->ref_doc );
     nr++;    /* spare_1 */
     nadc_write_text( outfl, ++nr, "ACQUISITION_STATION", mph->acquis );
     nadc_write_text( outfl, ++nr, "PROC_CENTER", mph->proc_center );
     nadc_write_text( outfl, ++nr, "PROC_TIME", mph->proc_time );
     nadc_write_text( outfl, ++nr, "SOFTWARE_VER", mph->soft_version );
     nr++;    /* spare_2 */
     nadc_write_text( outfl, ++nr, "SENSING_START", mph->sensing_start );
     nadc_write_text( outfl, ++nr, "SENSING_STOP", mph->sensing_stop );
     nr++;    /* spare_3 */
     nadc_write_text( outfl, ++nr, "PHASE", mph->phase );
     nadc_write_short( outfl, ++nr, "CYCLE", mph->cycle );
     nadc_write_int( outfl, ++nr, "REL_ORBIT", mph->rel_orbit );
     nadc_write_int( outfl, ++nr, "ABS_ORBIT", mph->abs_orbit );
     nadc_write_text( outfl, ++nr, "STATE_VECTOR_TIME", mph->state_vector );
     nadc_write_double( outfl, ++nr, "DELTA_UT1", 3, mph->delta_ut );
     nadc_write_double( outfl, ++nr, "X_POSITION", 3, mph->x_position );
     nadc_write_double( outfl, ++nr, "Y_POSITION", 3, mph->y_position );
     nadc_write_double( outfl, ++nr, "Z_POSITION", 3, mph->z_position );
     nadc_write_double( outfl, ++nr, "X_VELOCITY", 6, mph->x_velocity );
     nadc_write_double( outfl, ++nr, "Y_VELOCITY", 6, mph->y_velocity );
     nadc_write_double( outfl, ++nr, "Z_VELOCITY", 6, mph->z_velocity );
     nr++;    /* spare_4 */
     nadc_write_text( outfl, ++nr, "VECTOR_SOURCE", mph->vector_source );
     nadc_write_text( outfl, ++nr, "UTC_SBT_TIME", mph->utc_sbt_time );
     nadc_write_uint( outfl, ++nr, "SAT_BINARY_TIME", mph->sat_binary_time );
     nadc_write_uint( outfl, ++nr, "CLOCK_STEP", mph->clock_step );
     nr++;    /* spare_5 */
     nadc_write_text( outfl, ++nr, "LEAP_UTC", mph->leap_utc );
     nadc_write_short( outfl, ++nr, "LEAP_SIGN", mph->leap_sign );
     nadc_write_text( outfl, ++nr, "LEAP_ERR", mph->leap_err );
     nr++;    /* spare_6 */
     nadc_write_text( outfl, ++nr, "PRODUCT_ERR", mph->product_err );
     nadc_write_uint( outfl, ++nr, "TOT_SIZE", mph->tot_size );
     nadc_write_uint( outfl, ++nr, "SPH_SIZE", mph->sph_size );
     nadc_write_uint( outfl, ++nr, "NUM_DSD", mph->num_dsd );
     nadc_write_uint( outfl, ++nr, "DSD_SIZE", mph->dsd_size );
     nadc_write_uint( outfl, ++nr, "NUM_DATA_SETS", mph->num_data_sets );
     nr++;    /* spare_7 */
     (void) fclose( outfl );
}
/*+++++++++++++++++++++++++
.IDENTifer  SCIA_LV2_WR_ASCII_GEO
.PURPOSE    dump -- in ASCII Format -- the records
.INPUT/OUTPUT
  call as   SCIA_LV2_WR_ASCII_GEO( param, num_dsr, geo );
     input:
            struct param_record param : struct holding user-defined settings
	    unsigned int num_dsr      : number of data sets
	    struct geo_scia *geo      : pointer to Geolocation records
            
.RETURNS     Nothing, error status passed by global variable ``nadc_stat''
.COMMENTS    None
-------------------------*/
void SCIA_LV2_WR_ASCII_GEO( struct param_record param, unsigned int num_dsr,
			    const struct geo_scia *geo )
{
     register unsigned int nd, ni, nr, ny;

     char  date_str[UTC_STRING_LENGTH];
     double rbuff[2 * 4];
     unsigned int  count[2];

     FILE *outfl = CRE_ASCII_File( param.outfile, "geo" );

     if ( outfl == NULL || IS_ERR_STAT_FATAL )
	  NADC_RETURN_ERROR( NADC_ERR_FILE_CRE, param.outfile );
/*
 * write ASCII dump of GEO record
 */
     nadc_write_header( outfl, 0, param.infile,  
			 "Geolocation Data set(s)" );
     for ( nd = 0; nd < num_dsr; nd++ ) {
	  nr = 0;
	  (void) MJD_2_ASCII( geo[nd].mjd.days, geo[nd].mjd.secnd,
			      geo[nd].mjd.musec, date_str );
	  nadc_write_text( outfl, ++nr, "Date", date_str );
	  nadc_write_uchar( outfl, ++nr, "MDS DSR attached", 
			     geo[nd].flag_mds );
	  nadc_write_ushort( outfl, ++nr, "Integration time",
			      geo[nd].intg_time );
	  count[0] = 3;
	  nadc_write_arr_float( outfl, ++nr, "Solar zenith angles",
				 1, count, 5, geo[nd].sun_zen_ang );
	  nadc_write_arr_float( outfl, ++nr, "Line-of-Sight zenith angles",
				 1, count, 5, geo[nd].los_zen_ang );
	  nadc_write_arr_float( outfl, ++nr, "Relative Azimuth angles",
				 1, count, 5, geo[nd].rel_azi_ang );
	  nadc_write_float( outfl, ++nr, "Satellite geodetic height",
			     5, geo[nd].sat_h );
	  nadc_write_float( outfl, ++nr, "Earth radius",
			     5, geo[nd].earth_rad );
	  count[0] = 2;
	  count[1] = 4;
	  for ( ni = ny = 0; ny < count[1]; ny++ ) {
	       rbuff[ni++] = geo[nd].corner[ny].lat / 1e6;
	       rbuff[ni++] = geo[nd].corner[ny].lon / 1e6;
	  }
	  nadc_write_arr_double( outfl, ++nr, "Corner coordinates",
				 2, count, 6, rbuff );
	  
	  rbuff[0] = geo[nd].center.lat / 1e6;
	  rbuff[1] = geo[nd].center.lon / 1e6;
	  nadc_write_arr_double( outfl, ++nr, "Center coordinates",
				 1, count, 6, rbuff );
     }
     (void) fclose( outfl );
}
/*+++++++++++++++++++++++++
.IDENTifer  SCIA_LV2_WR_ASCII_STATE
.PURPOSE    dump -- in ASCII Format -- the STATE records
.INPUT/OUTPUT
  call as   SCIA_LV2_WR_ASCII_STATE( param, num_dsr, state );
     input:
            struct param_record param : struct holding user-defined settings
	    unsigned int num_dsr      : number of data sets
	    struct state2_scia *state : pointer to STATE records
            
.RETURNS     Nothing, error status passed by global variable ``nadc_stat''
.COMMENTS    None
-------------------------*/
void SCIA_LV2_WR_ASCII_STATE( struct param_record param, unsigned int num_dsr,
			      const struct state2_scia *state )
{
     register unsigned int nd, nr;

     char date_str[UTC_STRING_LENGTH];

     FILE *outfl = CRE_ASCII_File( param.outfile, "state" );

     if ( outfl == NULL || IS_ERR_STAT_FATAL )
	  NADC_RETURN_ERROR( NADC_ERR_FILE_CRE, param.outfile );
/*
 * write ASCII dump of STATE record
 */
     nadc_write_header( outfl, 0, param.infile, "States of the Product" );
     for ( nd = 0; nd < num_dsr; nd++ ) {
	  nr = 1;
	  (void) MJD_2_ASCII( state[nd].mjd.days, state[nd].mjd.secnd,
			      state[nd].mjd.musec, date_str );
	  nadc_write_text( outfl, nr, "MJD (Date Time)", date_str );
	  nadc_write_double( outfl, nr++, "MJD (Julian Day)", 16, 
			     (double) state[nd].mjd.days + 
			     ((state[nd].mjd.secnd + state[nd].mjd.musec / 1e6)
			      / (24. * 60 * 60)) );
	  nadc_write_uchar( outfl, nr++, "MDS DSR attached", 
			     state[nd].flag_mds );
	  nadc_write_ushort( outfl, nr++, "State ID", 
			      state[nd].state_id );
	  nadc_write_ushort( outfl, nr++, "Duration of scan phase", 
			      state[nd].duration );
	  nadc_write_ushort( outfl, nr++, "Longest integration time", 
			      state[nd].longest_intg_time );
	  nadc_write_ushort( outfl, nr++, "Shortest integration time", 
			      state[nd].shortest_intg_time );
	  nadc_write_ushort( outfl, nr++, "Number of Observations", 
			      state[nd].num_obs_state );
     }
     (void) fclose( outfl );
}
/*+++++++++++++++++++++++++ Main Program or Function +++++++++++++++*/
void SCIA_OL2_WR_ASCII_SPH( struct param_record param, 
			    const struct sph_sci_ol *sph )
{
     register unsigned int  nr = 0;

     FILE *outfl = CRE_ASCII_File( param.outfile, "sph" );

     if ( outfl == NULL || IS_ERR_STAT_FATAL )
	  NADC_RETURN_ERROR( NADC_ERR_FILE_CRE, param.outfile );
/*
 * write ASCII dump of SPH record
 */
     nadc_write_header( outfl, nr, param.infile, 
			 "Specific Product Header of Level 2 Product" );
     nadc_write_text( outfl, ++nr, "SPH_DESCRIPTOR", sph->descriptor );
     nadc_write_short( outfl, ++nr, "STRIPLINE_CONTINUITY_INDICATOR", 
		       sph->stripline );
     nadc_write_short( outfl, ++nr, "SLICE_POSITION", sph->slice_pos );
     nadc_write_ushort( outfl, ++nr, "NUM_SLICES", sph->no_slice );
     nadc_write_text( outfl, ++nr, "START_TIME", sph->start_time );
     nadc_write_text( outfl, ++nr, "STOP_TIME", sph->stop_time );
     nadc_write_double( outfl, ++nr, "START_LAT", 6, sph->start_lat );
     nadc_write_double( outfl, ++nr, "START_LON", 6, sph->start_lon );
     nadc_write_double( outfl, ++nr, "STOP_LAT", 6, sph->stop_lat );
     nadc_write_double( outfl, ++nr, "STOP_LON", 6, sph->stop_lon );
     if ( strlen( sph->decont ) == 0 )
	  nadc_write_text( outfl, ++nr, "DECONT", sph->decont );
     else
	  ++nr;    /* spare_1 */
     nadc_write_text( outfl, ++nr, "DB_SERVER_VER", sph->dbserver );
     nadc_write_text( outfl, ++nr, "FITTING_ERROR_SUM", sph->errorsum );
/*
 * Nadir
 */
     nadc_write_ushort( outfl, ++nr, "NO_OF_NADIR_FITTING_WINDOWS", 
			 sph->no_nadir_win );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_UV0", sph->nadir_win_uv0 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_UV1", sph->nadir_win_uv1 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_UV2", sph->nadir_win_uv2 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_UV3", sph->nadir_win_uv3 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_UV4", sph->nadir_win_uv4 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_UV5", sph->nadir_win_uv5 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_UV6", sph->nadir_win_uv6 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_UV7", sph->nadir_win_uv7 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_UV8", sph->nadir_win_uv8 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_UV9", sph->nadir_win_uv9 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_IR0", sph->nadir_win_ir0 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_IR1", sph->nadir_win_ir1 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_IR2", sph->nadir_win_ir2 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_IR3", sph->nadir_win_ir3 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_IR4", sph->nadir_win_ir4 );
     nadc_write_text( outfl, ++nr, "NAD_FIT_WINDOW_IR5", sph->nadir_win_ir5 );
/*
 * Limb
 */
     nadc_write_ushort( outfl, ++nr, "NO_OF_LIMB_FITTING_WINDOWS", 
			 sph->no_limb_win );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_PTH", sph->limb_win_pth );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_UV0", sph->limb_win_uv0 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_UV1", sph->limb_win_uv1 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_UV2", sph->limb_win_uv2 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_UV3", sph->limb_win_uv3 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_UV4", sph->limb_win_uv4 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_UV5", sph->limb_win_uv5 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_UV6", sph->limb_win_uv6 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_UV7", sph->limb_win_uv7 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_IR0", sph->limb_win_ir0 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_IR1", sph->limb_win_ir1 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_IR2", sph->limb_win_ir2 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_IR3", sph->limb_win_ir3 );
     nadc_write_text( outfl, ++nr, "LIM_FIT_WINDOW_IR4", sph->limb_win_ir4 );
/*
 * Occultation
 */
     nadc_write_ushort( outfl, ++nr, "NO_OF_OCCL_FITTING_WINDOWS", 
			 sph->no_occl_win );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_PTH", sph->occl_win_pth );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_UV0", sph->occl_win_uv0 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_UV1", sph->occl_win_uv1 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_UV2", sph->occl_win_uv2 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_UV3", sph->occl_win_uv3 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_UV4", sph->occl_win_uv4 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_UV5", sph->occl_win_uv5 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_UV6", sph->occl_win_uv6 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_UV7", sph->occl_win_uv7 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_IR0", sph->occl_win_ir0 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_IR1", sph->occl_win_ir1 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_IR2", sph->occl_win_ir2 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_IR3", sph->occl_win_ir3 );
     nadc_write_text( outfl, ++nr, "OCC_FIT_WINDOW_IR4", sph->occl_win_ir4 );
     (void) fclose( outfl );
}
/*+++++++++++++++++++++++++ Main Program or Function +++++++++++++++*/
void MERIS_WR_ASCII_SPH( struct param_record param, 
			 const struct sph_meris *sph )
{
     register unsigned int  nr = 0;

     FILE *outfl = CRE_ASCII_File( param.outfile, "sph" );

     if ( outfl == NULL || IS_ERR_STAT_FATAL )
	  NADC_RETURN_ERROR( NADC_ERR_FILE_CRE, param.outfile );
/*
 * write ASCII dump of SPH record
 */
     nadc_write_header( outfl, nr, param.infile, 
			 "Specific Product Header of Level 1b Product" );
     nadc_write_text( outfl, ++nr, "SPH_DESCRIPTOR", sph->descriptor );
     nadc_write_short( outfl, ++nr, "STRIPLINE_CONTINUITY_INDICATOR", 
		       sph->stripline );
     nadc_write_short( outfl, ++nr, "SLICE_POSITION", sph->slice_pos );
     nadc_write_ushort( outfl, ++nr, "NUM_SLICES", sph->num_slices );
     nadc_write_text( outfl, ++nr, "FIRST_LINE_TIME", sph->start_time );
     nadc_write_text( outfl, ++nr, "LAST_LINE_TIME", sph->stop_time );
     nadc_write_double( outfl, ++nr, "FIRST_FIRST_LAT", 
			6, sph->first_first_lat );
     nadc_write_double( outfl, ++nr, "FIRST_FIRST_LONG", 
			6, sph->first_first_lon );
     nadc_write_double( outfl, ++nr, "FIRST_MID_LAT", 6, sph->first_mid_lat );
     nadc_write_double( outfl, ++nr, "FIRST_MID_LONG", 6, sph->first_mid_lon );
     nadc_write_double( outfl, ++nr, "FIRST_LAST_LAT", 
			6, sph->first_last_lat );
     nadc_write_double( outfl, ++nr, "FIRST_LAST_LONG", 
			6, sph->first_last_lon );
     nadc_write_double( outfl, ++nr, "LAST_FIRST_LAT", 
			6, sph->last_first_lat );
     nadc_write_double( outfl, ++nr, "LAST_FIRST_LONG", 
			6, sph->last_first_lon );
     nadc_write_double( outfl, ++nr, "LAST_MID_LAT", 6, sph->last_mid_lat );
     nadc_write_double( outfl, ++nr, "LAST_MID_LONG", 6, sph->last_mid_lon );
     nadc_write_double( outfl, ++nr, "LAST_LAST_LAT", 6, sph->last_last_lat );
     nadc_write_double( outfl, ++nr, "LAST_LAST_LONG", 6, sph->last_last_lon );
     nr++;    /* spare_1 */
     nadc_write_bool( outfl, ++nr, "TRANS_ERR_FLAG", sph->trans_err );
     nadc_write_bool( outfl, ++nr, "FORMAT_ERR_FLAG", sph->format_err );
     nadc_write_bool( outfl, ++nr, "DATABASE_FLAG", sph->database );
     nadc_write_bool( outfl, ++nr, "COARSE_ERR_FLAG", sph->coarse_err );
     nadc_write_bool( outfl, ++nr, "ECMWF_TYPE", sph->ecmwf_type );
     nadc_write_ushort( outfl, ++nr, "NUM_TRANS_ERR", sph->num_trans_err );
     nadc_write_ushort( outfl, ++nr, "NUM_FORMAT_ERR", sph->num_format_err );
     nadc_write_float( outfl, ++nr, "TRANS_ERR_THRESH", 
		       6, sph->thres_trans_err );
     nadc_write_float( outfl, ++nr, "FORMAT_ERR_THRESH", 
		       6, sph->thres_format_err );
     nr++;    /* spare_2 */
     nadc_write_ushort( outfl, ++nr, "NUM_BANDS", sph->num_bands );
     nadc_write_text( outfl, ++nr, "BAND_WAVELEN", sph->band_wavelen );
     nadc_write_text( outfl, ++nr, "BANDWIDTH", sph->bandwidth );
     nadc_write_double( outfl, ++nr, "INST_FOV", 6, sph->inst_fov );
     nadc_write_bool( outfl, ++nr, "PROC_MODE", sph->proc_mode );
     nadc_write_bool( outfl, ++nr, "OFFSET_COMP", sph->offset_comp );
     nadc_write_double( outfl, ++nr, "LINE_TIME_INTERVAL", 
			6, sph->line_time_interval );
     nadc_write_ushort( outfl, ++nr, "LINE_LENGTH", sph->line_length );
     nadc_write_ushort( outfl, ++nr, "LINES_PER_TIE_PT", sph->lines_per_tie );
     nadc_write_ushort( outfl, ++nr, "SAMPLES_PER_TIE_PT", 
			sph->samples_per_tie );
     nadc_write_float( outfl, ++nr, "COLUMN_SPACING", 6, sph->column_spacing );
     nr++;    /* spare_3 */
     (void) fclose( outfl );
}
Exemple #7
0
/*+++++++++++++++++++++++++ Main Program or Function +++++++++++++++*/
void SCIA_LV2_WR_ASCII_SPH( struct param_record param, 
			    const struct sph2_scia *sph )
{
     register unsigned int  ni, nr = 0;

     char           cbuff[MX_SZ_CBUFF];
     unsigned short ubuff[8];
     unsigned int   ndim;
     unsigned int   dims[2];

     FILE *outfl = CRE_ASCII_File( param.outfile, "sph" );

     if ( outfl == NULL || IS_ERR_STAT_FATAL )
	  NADC_RETURN_ERROR( NADC_ERR_FILE_CRE, param.outfile );
/*
 * write ASCII dump of SPH record
 */
     nadc_write_header( outfl, nr, param.infile, 
			 "Specific Product Header of Level 2 Product" );
     nadc_write_text( outfl, ++nr, "SPH_DESCRIPTOR", sph->descriptor );
     nadc_write_short( outfl, ++nr, "STRIPLINE_CONTINUITY_INDICATOR", 
		       sph->stripline );
     nadc_write_short( outfl, ++nr, "SLICE_POSITION", sph->slice_pos );
     nadc_write_ushort( outfl, ++nr, "NUM_SLICES", sph->no_slice );
     nadc_write_text( outfl, ++nr, "START_TIME", sph->start_time );
     nadc_write_text( outfl, ++nr, "STOP_TIME", sph->stop_time );
     nadc_write_double( outfl, ++nr, "START_LAT", 6, sph->start_lat );
     nadc_write_double( outfl, ++nr, "START_LON", 6, sph->start_lon );
     nadc_write_double( outfl, ++nr, "STOP_LAT", 6, sph->stop_lat );
     nadc_write_double( outfl, ++nr, "STOP_LON", 6, sph->stop_lon );
     ++nr;    /* spare_1 */
     nadc_write_text( outfl, ++nr, "FITTING_ERROR_SUM", sph->fit_error );
     nadc_write_ushort( outfl, ++nr, "NO_OF_DOAS_FITTING_WIN", 
			 sph->no_doas_win );
     ndim = 2;
     for ( ni = 0; ni < sph->no_doas_win; ni++ ) {
	  (void) snprintf(cbuff, MX_SZ_CBUFF, "DOAS_FITTING_WINDOW_%02u", ni);
	  ubuff[0] = sph->doas_win[ni].wv_min;
	  ubuff[1] = sph->doas_win[ni].wv_max;
	  nadc_write_arr_ushort( outfl, ++nr, cbuff, 1, &ndim, ubuff );
     }
     nr += (MAX_DOAS_FITTING_WIN - sph->no_doas_win);
     nadc_write_ushort( outfl, ++nr, "NO_OF_BIAS_FITTING_WIN", 
			 sph->no_bias_win );
     for ( ni = 0; ni < sph->no_bias_win; ni++ ) {
	  (void) snprintf(cbuff, MX_SZ_CBUFF, "BIAS_FITTING_WINDOW_%02u", ni);
	  ubuff[0] = sph->bias_win[ni].wv_min;
	  ubuff[1] = sph->bias_win[ni].wv_max;
	  if ( sph->bias_win[ni].nr_micro == 0 )
	       nadc_write_arr_ushort( outfl, ++nr, cbuff, 1, &ndim, ubuff );
	  else {
	       register unsigned int nm, nb;

	       dims[0] = 2;
	       dims[1] = sph->bias_win[ni].nr_micro+1;
	       for ( nb = 2, nm = 0; nm < sph->bias_win[ni].nr_micro; nm++ ) {
		    ubuff[nb++] = sph->bias_win[ni].micro_min[nm];
		    ubuff[nb++] = sph->bias_win[ni].micro_max[nm];
	       }
	       nadc_write_arr_ushort( outfl, ++nr, cbuff, 2, dims, ubuff );
	  }
     }
     nadc_write_ushort( outfl, ++nr, "NO_OF_DOAS_MOL",  sph->no_doas_mol );
     for ( ni = 0; ni < MAX_DOAS_SPECIES; ni++ ) {
	  (void) snprintf( cbuff, MX_SZ_CBUFF, "DOAS_MOLECULE_%02u", ni );
          nadc_write_text( outfl, ++nr, cbuff, sph->doas_mol[ni] );
     }
     nadc_write_ushort( outfl, ++nr, "NO_OF_BIAS_MOL", sph->no_bias_mol );
     for ( ni = 0; ni < sph->no_bias_mol; ni++ ) {
	  (void) snprintf( cbuff, MX_SZ_CBUFF, "BIAS_MOLECULE_%02u", ni );
          nadc_write_text( outfl, ++nr, cbuff, sph->bias_mol[ni] );
     }
     (void) fclose( outfl );
}
/*+++++++++++++++++++++++++ Main Program or Function +++++++++++++++*/
void SCIA_LV1C_WR_ASCII_CALOPT( const struct param_record param,
				const struct cal_options *calopt )
{
     register unsigned int nr = 0;

     char date_str[UTC_STRING_LENGTH];

     unsigned int   count[1];

     FILE *outfl = CRE_ASCII_File( param.outfile, "calopt" );

     if ( outfl == NULL || IS_ERR_STAT_FATAL )
	  NADC_RETURN_ERROR( NADC_ERR_FILE_CRE, param.outfile );
/*
 * write ASCII dump of CAL_OPTIONS record
 */
     nadc_write_header( outfl, nr, param.infile, 
			 "Calibration Options GADS to SciaL1C" );
     nadc_write_text( outfl,++nr, "l1b_product_name", calopt->l1b_prod_name );
     if ( calopt->geo_filter != SCHAR_ZERO ) {
	  nadc_write_double( outfl, ++nr, "start_lat", 6, 
			     calopt->start_lat/1e6 );
	  nadc_write_double( outfl, ++nr, "start_lon", 6, 
			     calopt->start_lon/1e6 );
	  nadc_write_double( outfl, ++nr, "end_lat", 6, calopt->end_lat/1e6 );
	  nadc_write_double( outfl, ++nr, "end_lon", 6, calopt->end_lon/1e6 );
     } else
	  nr += 4;
     if ( calopt->time_filter != SCHAR_ZERO ) {
	  (void) MJD_2_ASCII( calopt->start_time.days, 
			      calopt->start_time.secnd,
                              calopt->start_time.musec, date_str );
          nadc_write_text( outfl, ++nr, "start_time", date_str );
	  (void) MJD_2_ASCII( calopt->stop_time.days, 
			      calopt->stop_time.secnd,
                              calopt->stop_time.musec, date_str );
          nadc_write_text( outfl, ++nr, "stop_time", date_str );

     } else
	  nr += 2;
     if ( calopt->category_filter != SCHAR_ZERO ) {
	  count[0] = 5;
          nadc_write_arr_ushort( outfl, ++nr, "category", 
                                  1, count, calopt->category );
     } else
	  nr += 1;
     if ( calopt->nadir_mds != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "nadir_mds_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "nadir_mds_flag", "FALSE" );
     if ( calopt->limb_mds != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "limb_mds_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "limb_mds_flag", "FALSE" );
     if ( calopt->occ_mds != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "occ_mds_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "occ_mds_flag", "FALSE" );
     if ( calopt->moni_mds != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "moni_mds_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "moni_mds_flag", "FALSE" );

     if ( calopt->pmd_mds != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "pmd_mds_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "pmd_mds_flag", "FALSE" );
     if ( calopt->frac_pol_mds != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "frac_pol_mds_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "frac_pol_mds_flag", "FALSE" );
     if ( calopt->slit_function != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "slit_function_gads_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "slit_function_gads_flag", "FALSE" );
     if ( calopt->sun_mean_ref != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "sun_mean_ref_gads_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "sun_mean_ref_gads_flag", "FALSE" );
     if ( calopt->leakage_current != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "leakage_current_gads_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "leakage_current_gads_flag", "FALSE");
     if ( calopt->spectral_cal != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "spectral_cal_gads_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "spectral_cal_gads_flag", "FALSE" );
     if ( calopt->pol_sens != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "pol_sens_gads_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "pol_sens_gads_flag", "FALSE" );
     if ( calopt->rad_sens != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "rad_sens_gads_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "rad_sens_gads_flag", "FALSE" );
     if ( calopt->ppg_etalon != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "ppg_etalon_gads_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "ppg_etalon_gads_flag", "FALSE" );
     nadc_write_ushort( outfl,++nr, "num_nadir_clusters", calopt->num_nadir );
     nadc_write_ushort( outfl,++nr, "num_limb_clusters", calopt->num_limb );
     nadc_write_ushort( outfl,++nr, "num_occ_clusters", calopt->num_occ );
     nadc_write_ushort( outfl,++nr, "num_moni_clusters", calopt->num_moni );
     count[0] = MAX_CLUSTER;
     nadc_write_arr_schar( outfl, ++nr, "nadir_cluster_flag", 
			    1, count, calopt->nadir_cluster );
     nadc_write_arr_schar( outfl, ++nr, "limb_cluster_flag", 
			    1, count, calopt->limb_cluster );
     nadc_write_arr_schar( outfl, ++nr, "occ_cluster_flag", 
			    1, count, calopt->occ_cluster );
     nadc_write_arr_schar( outfl, ++nr, "moni_cluster_flag", 
			    1, count, calopt->moni_cluster );
     if ( calopt->mem_effect_cal != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "mem_effect_cal_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "mem_effect_cal_flag", "FALSE" );
     if ( calopt->leakage_cal != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "leakage_cal_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "leakage_cal_flag", "FALSE" );
     if ( calopt->straylight_cal != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "straylight_cal_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "straylight_cal_flag", "FALSE" );
     if ( calopt->ppg_cal != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "ppg_cal_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "ppg_cal_flag", "FALSE" );
     if ( calopt->etalon_cal != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "etalon_cal_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "etalon_cal_flag", "FALSE" );
     if ( calopt->wave_cal != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "spectal_cal_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "spectral_cal_flag", "FALSE" );
     if ( calopt->polarisation_cal != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "polarisation_cal_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "polarisation_cal_flag", "FALSE" );
     if ( calopt->radiance_cal != SCHAR_ZERO )
	  nadc_write_text( outfl, ++nr, "radiance_cal_flag", "TRUE" );
     else
	  nadc_write_text( outfl, ++nr, "radiance_cal_flag", "FALSE" );

     (void) fclose( outfl );
}