/* A lexical scanner generated by flex */

/* Scanner skeleton version:
 * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $
 */

#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5

#include <stdio.h>


/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
#ifdef c_plusplus
#ifndef __cplusplus
#define __cplusplus
#endif
#endif


#ifdef __cplusplus

#include <stdlib.h>
#include <unistd.h>

/* Use prototypes in function declarations. */
#define YY_USE_PROTOS

/* The "const" storage-class-modifier is valid. */
#define YY_USE_CONST

#else	/* ! __cplusplus */

#if __STDC__

#define YY_USE_PROTOS
#define YY_USE_CONST

#endif	/* __STDC__ */
#endif	/* ! __cplusplus */

#ifdef __TURBOC__
 #pragma warn -rch
 #pragma warn -use
#include <io.h>
#include <stdlib.h>
#define YY_USE_CONST
#define YY_USE_PROTOS
#endif

#ifdef YY_USE_CONST
#define yyconst const
#else
#define yyconst
#endif


#ifdef YY_USE_PROTOS
#define YY_PROTO(proto) proto
#else
#define YY_PROTO(proto) ()
#endif

/* Returned upon end-of-file. */
#define YY_NULL 0

/* Promotes a possibly negative, possibly signed char to an unsigned
 * integer for use as an array index.  If the signed char is negative,
 * we want to instead treat it as an 8-bit unsigned char, hence the
 * double cast.
 */
#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)

/* Enter a start condition.  This macro really ought to take a parameter,
 * but we do it the disgusting crufty way forced on us by the ()-less
 * definition of BEGIN.
 */
#define BEGIN yy_start = 1 + 2 *

/* Translate the current start state into a value that can be later handed
 * to BEGIN to return to the state.  The YYSTATE alias is for lex
 * compatibility.
 */
#define YY_START ((yy_start - 1) / 2)
#define YYSTATE YY_START

/* Action number for EOF rule of a given start state. */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)

/* Special action meaning "start processing a new file". */
#define YY_NEW_FILE yyrestart( yyin )

#define YY_END_OF_BUFFER_CHAR 0

/* Size of default input buffer. */
#define YY_BUF_SIZE 16384

typedef struct yy_buffer_state *YY_BUFFER_STATE;

extern int yyleng;
extern FILE *yyin, *yyout;

#define EOB_ACT_CONTINUE_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2

/* The funky do-while in the following #define is used to turn the definition
 * int a single C statement (which needs a semi-colon terminator).  This
 * avoids problems with code like:
 *
 * 	if ( condition_holds )
 *		yyless( 5 );
 *	else
 *		do_something_else();
 *
 * Prior to using the do-while the compiler would get upset at the
 * "else" because it interpreted the "if" statement as being all
 * done when it reached the ';' after the yyless() call.
 */

/* Return all but the first 'n' matched characters back to the input stream. */

#define yyless(n) \
	do \
		{ \
		/* Undo effects of setting up yytext. */ \
		*yy_cp = yy_hold_char; \
		YY_RESTORE_YY_MORE_OFFSET \
		yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
		YY_DO_BEFORE_ACTION; /* set up yytext again */ \
		} \
	while ( 0 )

#define unput(c) yyunput( c, yytext_ptr )

/* The following is because we cannot portably get our hands on size_t
 * (without autoconf's help, which isn't available because we want
 * flex-generated scanners to compile on their own).
 */
typedef unsigned int yy_size_t;


struct yy_buffer_state
	{
	FILE *yy_input_file;

	char *yy_ch_buf;		/* input buffer */
	char *yy_buf_pos;		/* current position in input buffer */

	/* Size of input buffer in bytes, not including room for EOB
	 * characters.
	 */
	yy_size_t yy_buf_size;

	/* Number of characters read into yy_ch_buf, not including EOB
	 * characters.
	 */
	int yy_n_chars;

	/* Whether we "own" the buffer - i.e., we know we created it,
	 * and can realloc() it to grow it, and should free() it to
	 * delete it.
	 */
	int yy_is_our_buffer;

	/* Whether this is an "interactive" input source; if so, and
	 * if we're using stdio for input, then we want to use getc()
	 * instead of fread(), to make sure we stop fetching input after
	 * each newline.
	 */
	int yy_is_interactive;

	/* Whether we're considered to be at the beginning of a line.
	 * If so, '^' rules will be active on the next match, otherwise
	 * not.
	 */
	int yy_at_bol;

	/* Whether to try to fill the input buffer when we reach the
	 * end of it.
	 */
	int yy_fill_buffer;

	int yy_buffer_status;
#define YY_BUFFER_NEW 0
#define YY_BUFFER_NORMAL 1
	/* When an EOF's been seen but there's still some text to process
	 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
	 * shouldn't try reading from the input source any more.  We might
	 * still have a bunch of tokens to match, though, because of
	 * possible backing-up.
	 *
	 * When we actually see the EOF, we change the status to "new"
	 * (via yyrestart()), so that the user can continue scanning by
	 * just pointing yyin at a new input file.
	 */
#define YY_BUFFER_EOF_PENDING 2
	};

static YY_BUFFER_STATE yy_current_buffer = 0;

/* We provide macros for accessing buffer states in case in the
 * future we want to put the buffer states in a more general
 * "scanner state".
 */
#define YY_CURRENT_BUFFER yy_current_buffer


/* yy_hold_char holds the character lost when yytext is formed. */
static char yy_hold_char;

static int yy_n_chars;		/* number of characters read into yy_ch_buf */


int yyleng;

/* Points to current character in buffer. */
static char *yy_c_buf_p = (char *) 0;
static int yy_init = 1;		/* whether we need to initialize */
static int yy_start = 0;	/* start state number */

/* Flag which is used to allow yywrap()'s to do buffer switches
 * instead of setting up a fresh yyin.  A bit of a hack ...
 */
static int yy_did_buffer_switch_on_eof;

void yyrestart YY_PROTO(( FILE *input_file ));

void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
void yy_load_buffer_state YY_PROTO(( void ));
YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )

YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));

static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
static void yy_flex_free YY_PROTO(( void * ));

#define yy_new_buffer yy_create_buffer

#define yy_set_interactive(is_interactive) \
	{ \
	if ( ! yy_current_buffer ) \
		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
	yy_current_buffer->yy_is_interactive = is_interactive; \
	}

#define yy_set_bol(at_bol) \
	{ \
	if ( ! yy_current_buffer ) \
		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
	yy_current_buffer->yy_at_bol = at_bol; \
	}

#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)

typedef unsigned char YY_CHAR;
FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
typedef int yy_state_type;
extern char *yytext;
#define yytext_ptr yytext

static yy_state_type yy_get_previous_state YY_PROTO(( void ));
static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
static int yy_get_next_buffer YY_PROTO(( void ));
static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));

/* Done after the current pattern has been matched and before the
 * corresponding action - sets up yytext.
 */
#define YY_DO_BEFORE_ACTION \
	yytext_ptr = yy_bp; \
	yyleng = (int) (yy_cp - yy_bp); \
	yy_hold_char = *yy_cp; \
	*yy_cp = '\0'; \
	yy_c_buf_p = yy_cp;

#define YY_NUM_RULES 39
#define YY_END_OF_BUFFER 40
static yyconst short int yy_accept[174] =
    {   0,
        0,    0,    0,    0,   40,    4,    1,   37,   37,    4,
        1,   37,   39,   38,    4,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    4,    3,    0,
        0,    2,    0,   38,   36,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,   20,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,   21,    0,

        0,    0,    0,   19,    0,   32,    0,    0,    0,    0,
        0,    0,    0,    0,    0,   26,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,   30,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    6,    5,   13,   12,
       11,   18,   27,    0,    0,    0,   23,    8,    7,   15,
       14,    0,   10,    9,   17,   16,    0,    0,   35,   25,
       31,    0,   24,    0,    0,    0,    0,   28,   29,   33,
       34,   22,    0
    } ;

static yyconst int yy_ec[256] =
    {   0,
        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    2,    1,    1,    4,    1,    5,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    6,    6,    6,
        6,    6,    6,    6,    6,    6,    6,    1,    1,    1,
        1,    1,    1,    1,    7,    8,    9,   10,   11,   12,
        6,   13,   14,   15,    6,   16,   17,   18,   19,   20,
        6,   21,   22,   23,   24,   25,    6,    6,   26,    6,
        1,    1,    1,    1,    6,    1,    6,    6,    6,    6,

        6,    6,    6,    6,    6,    6,    6,    6,    6,    6,
        6,    6,    6,    6,    6,    6,    6,    6,    6,    6,
        6,    6,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,

        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1
    } ;

static yyconst int yy_meta[27] =
    {   0,
        1,    1,    2,    2,    3,    4,    4,    4,    4,    4,
        4,    4,    4,    4,    4,    4,    4,    4,    4,    4,
        4,    4,    4,    4,    4,    4
    } ;

static yyconst short int yy_base[180] =
    {   0,
        0,    4,  285,  284,  286,    0,  289,  289,    4,   29,
      289,  282,  281,  289,    0,  278,   29,   30,   46,   31,
       32,   64,   36,   33,   86,   34,   35,   40,  289,  279,
      278,  289,  277,  289,  289,   48,   52,   53,   40,   55,
       73,   77,   78,   57,   74,   60,   84,   93,   82,   89,
       56,   98,   99,   92,  103,  106,  109,  110,  111,  274,
      113,  115,  114,  116,  117,  118,  121,  122,  126,  139,
      124,  133,  140,  273,  136,  125,  144,  145,  272,  147,
      271,  148,  149,  152,  289,  159,  165,  154,  156,  270,
      155,  161,  170,  173,  175,  176,  177,  189,  289,  269,

      190,  193,  192,  289,  194,  289,  196,  198,  204,  268,
      267,  266,  265,  264,  263,  289,  262,  205,  207,  209,
      261,  260,  259,  258,  257,  178,  289,  256,  255,  243,
      242,  211,  212,  229,  228,  227,  289,  289,  289,  289,
      289,  289,  289,  213,  224,  216,  289,  289,  289,  289,
      289,  214,  289,  289,  289,  289,  217,  218,  289,  289,
      289,  220,  289,  181,  179,  153,   61,  289,  289,  289,
      289,  289,  289,  237,  241,  245,  249,  253,  255
    } ;

static yyconst short int yy_def[180] =
    {   0,
      174,  174,  175,  175,  173,  176,  173,  173,  173,  176,
      173,  177,  178,  173,  176,  179,  179,  179,  179,  179,
      179,  179,  179,  179,  179,  179,  179,  176,  173,  177,
      177,  173,  178,  173,  173,  179,  179,  179,  179,  179,
      179,  179,  179,  179,  179,  179,  179,  179,  179,  179,
      179,  179,  179,  179,  179,  179,  179,  179,  179,  179,
      179,  179,  179,  179,  179,  179,  179,  179,  179,  179,
      179,  179,  179,  179,  179,  179,  179,  179,  179,  179,
      179,  179,  179,  179,  173,  179,  179,  179,  179,  179,
      179,  179,  179,  179,  179,  179,  179,  179,  173,  179,

      179,  179,  179,  173,  179,  173,  179,  179,  179,  179,
      179,  179,  179,  179,  179,  173,  179,  179,  179,  179,
      179,  179,  179,  179,  179,  179,  173,  179,  179,  179,
      179,  179,  179,  179,  179,  179,  173,  173,  173,  173,
      173,  173,  173,  179,  179,  179,  173,  173,  173,  173,
      173,  179,  173,  173,  173,  173,  179,  179,  173,  173,
      173,  179,  173,  179,  179,  179,  179,  173,  173,  173,
      173,  173,    0,  173,  173,  173,  173,  173,  173
    } ;

static yyconst short int yy_nxt[316] =
    {   0,
      173,  173,    7,    8,    9,   10,   11,   12,    9,   16,
       17,   18,   19,   20,   16,   16,   21,   22,   16,   16,
       23,   16,   16,   24,   16,   25,   26,   16,   27,   16,
       28,   29,   30,   35,   35,   35,   35,   35,   35,   35,
       35,   28,   29,   30,   35,   55,   41,   42,   37,   36,
       35,   48,   35,   49,   50,   54,   35,   35,   56,   35,
       35,   35,   38,   59,   35,  172,   39,   40,   35,   75,
       69,   58,   60,   43,   57,   66,   44,   35,   35,   61,
       45,   35,   35,   63,   65,   46,   35,   67,   35,   47,
       35,   62,   68,   35,   70,   64,   35,   35,   51,   71,

       73,   52,   35,   35,   76,   78,   74,   35,   53,   79,
       35,   72,   81,   35,   35,   35,   77,   35,   35,   35,
       35,   35,   35,   80,   84,   35,   35,   83,   35,   35,
       35,   82,   87,   89,   94,   86,   88,   35,   92,   93,
       35,   91,   90,   35,   35,   95,   96,  101,   35,   35,
       97,   35,   35,   35,   98,  100,   35,  171,   35,   35,
       35,  102,  114,   35,  115,   35,  107,  103,  105,   35,
      110,  108,  111,  109,   35,  117,  112,   35,  113,   35,
       35,   35,   35,  170,  118,  169,  152,  122,  124,  123,
      125,  120,  119,   35,   35,  121,   35,   35,   35,  126,

       35,  128,   35,  129,  130,  132,  131,  133,   35,   35,
      135,   35,  134,   35,  136,   35,   35,   35,   35,  145,
       35,   35,   35,  162,  168,  164,  146,  144,  163,  157,
      158,  161,  160,  159,  166,  167,  165,    6,    6,    6,
        6,   13,   13,   13,   13,   15,  156,  155,   15,   31,
       31,   31,   31,   33,   33,   33,   33,   16,   16,  154,
      153,  151,  150,  149,  148,  147,  143,  142,  141,  140,
      139,  138,  137,  127,  116,  106,  104,   99,   85,   34,
       32,   32,   35,   34,   32,  173,   14,   14,    5,  173,
      173,  173,  173,  173,  173,  173,  173,  173,  173,  173,

      173,  173,  173,  173,  173,  173,  173,  173,  173,  173,
      173,  173,  173,  173,  173
    } ;

static yyconst short int yy_chk[316] =
    {   0,
        0,    0,    1,    1,    1,    2,    2,    2,    2,    9,
        9,    9,    9,    9,    9,    9,    9,    9,    9,    9,
        9,    9,    9,    9,    9,    9,    9,    9,    9,    9,
       10,   10,   10,   17,   18,   20,   21,   24,   26,   27,
       23,   28,   28,   28,   39,   27,   20,   21,   18,   17,
       19,   23,   36,   24,   24,   26,   37,   38,   36,   40,
       51,   44,   19,   39,   46,  167,   19,   19,   22,   51,
       46,   38,   40,   22,   37,   44,   22,   41,   45,   41,
       22,   42,   43,   42,   43,   22,   49,   45,   47,   22,
       25,   41,   45,   50,   47,   42,   54,   48,   25,   48,

       49,   25,   52,   53,   52,   53,   50,   55,   25,   54,
       56,   48,   56,   57,   58,   59,   52,   61,   63,   62,
       64,   65,   66,   55,   59,   67,   68,   58,   71,   76,
       69,   57,   62,   64,   69,   61,   63,   72,   67,   68,
       75,   66,   65,   70,   73,   70,   71,   76,   77,   78,
       72,   80,   82,   83,   73,   75,   84,  166,   88,   91,
       89,   77,   88,   86,   89,   92,   82,   78,   80,   87,
       86,   83,   86,   84,   93,   91,   87,   94,   87,   95,
       96,   97,  126,  165,   92,  164,  126,   96,   97,   96,
       97,   94,   93,   98,  101,   95,  103,  102,  105,   98,

      107,  101,  108,  101,  102,  103,  102,  105,  109,  118,
      108,  119,  107,  120,  109,  132,  133,  144,  152,  119,
      146,  157,  158,  144,  162,  146,  120,  118,  145,  132,
      133,  136,  135,  134,  157,  158,  152,  174,  174,  174,
      174,  175,  175,  175,  175,  176,  131,  130,  176,  177,
      177,  177,  177,  178,  178,  178,  178,  179,  179,  129,
      128,  125,  124,  123,  122,  121,  117,  115,  114,  113,
      112,  111,  110,  100,   90,   81,   79,   74,   60,   33,
       31,   30,   16,   13,   12,    5,    4,    3,  173,  173,
      173,  173,  173,  173,  173,  173,  173,  173,  173,  173,

      173,  173,  173,  173,  173,  173,  173,  173,  173,  173,
      173,  173,  173,  173,  173
    } ;

static yy_state_type yy_last_accepting_state;
static char *yy_last_accepting_cpos;

/* The intent behind this definition is that it'll catch
 * any uses of REJECT which flex missed.
 */
#define REJECT reject_used_but_not_detected
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
#line 1 "scan_sbe.l"
#define INITIAL 0
/*----------------------------------------------------------------------------
 * 
 * scan_sbe.l -- 
 * 
 * Author          : Jaccard Pierre
 * Created On      : 2000/01/25 14:22:03
 * Last Modified By: Jaccard Pierre
 * Last Modified On: 2000/12/15 12:50:26
 * Directory       : /mnt/local/data/jaccard/codas/2000-11-21/codas3/gfi/src/apps/ctd/
 * ------------------------------------------------------------------------ * 
 * VERSION CONTROL: 
 * 
 *   $Author$
 *   $Date$
 *   $Id$
 *   $Name$
 *   $Revision$
 *   $State$
 *   $Log$
 * 
 *--------------------------------------------------------------------------*/
/**
 * Scan SBE CTD header files and generate standard header files. This
 * programme uses a lexical scanner to determine header fields and their
 * meanings. Configuration for the lexical scanner must be provided in file
 * "scan_sbe.lex",in the working directory. See separate documentation for
 * more information. 
 **/
/* ------------------------------------------------------------------
   Definition section 
   ------------------------------------------------------------------ */
/* The next block will be copied verbatim into the source */
#line 37 "scan_sbe.l"

#define HAVE_VFSCANF 1
#define VERSION "Version: $Revision$ $Date$"
#define PRGM    "scan_sbe"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <ctype.h>
#include <math.h>
#include <stdarg.h>
#include <dirent.h>

 
#define LINE_LENGTH   120                        /* Length of a line  */
#define FIELD_LENGTH   20                        /* Length of a field */
#define EOH           "*END*"                    /* End of header     */
#define HEADER_SUFFIX "hdr"                      /* Header suffix     */
#define DEFAULT_LEX   "scan_sbe.lex"             /* Name of lex-file  */
  
/* Strings with characetrs to exclude from strings */
#define EXCLUDE_FROM_STRING_0 (char*)NULL
#define EXCLUDE_FROM_STRING_1 "§!\"#%&/()=?`|+@£${[]}´^~*'_-:.;,<>"
  
#define BADSHORT     32767                     
#define BADINT       32767                     
#define BADFLOAT     1.0E38                     
#define ADJ_BADFLOAT 1.0E37        /* Adjustment for comparisons with 
                                      bad floats */
 
/* The following defines the codes used in this application. This registered
   in the list code_names will be used for reporting errors  */
#define NO_CODE                0
#define UNKNOWN_CODE           1
#define UNKNOWN_KEYWORD_CODE   2
#define UNKNOWN_RULE_CODE      3
#define UNKNOWN_NAME_CODE      4
#define UNDEFINED_VALUE_CODE   5
#define INVALID_VALUE_CODE     6
/* */
#define OPEN_CODE             10
#define CLOSE_CODE            11
#define READ_CODE             12
#define WRITE_CODE            13
#define SEEK_CODE             14
#define RENAME_CODE           15
/* */
#define STRING_CODE           20
#define INT_CODE              21
#define FLOAT_CODE            22
#define SHORT_CODE            23
#define CHAR_CODE             24
/* */
#define OPTION_CODE           50
#define ARGUMENT_CODE         51
/* */
#define HEADER_OFFSET_CODE   100
#define LATITUDE_CODE        101
#define LONGITUDE_CODE       102
#define DATE_TIME_CODE       103
#define STATION_CODE         104
#define SHIP_CODE            105
#define CRUISE_CODE          106
#define PROJECT_CODE         107
#define AREA_CODE            108
#define BOTTOM_CODE          109
#define VERSION_CODE         110
#define TSN_CODE             111
#define CSN_CODE             112
#define PSN_CODE             113

/* List of the required header fields in the output file */
#define HEADER_FIELDS        LATITUDE_CODE, \
                             LONGITUDE_CODE, \
                             DATE_TIME_CODE, \
                             STATION_CODE, \
                             SHIP_CODE, \
                             CRUISE_CODE, \
                             PROJECT_CODE, \
                             AREA_CODE, \
                             BOTTOM_CODE, \
                             VERSION_CODE, \
                             TSN_CODE, \
                             CSN_CODE, \
                             PSN_CODE
  
/* Used to store a list with codes and their associated names */
 typedef struct
 {
   char *name;
   short code;
 } CODE_NAME_LIST_TYPE;

 typedef struct 
 {
   short degree, minute, second;
 } I_POSITION_TYPE;
 
 typedef struct
 {
   float degree, minute, second;
 } F_POSITION_TYPE;
 
 typedef struct
 {
   char tsn[FIELD_LENGTH], csn[FIELD_LENGTH], psn[FIELD_LENGTH], 
     version[FIELD_LENGTH];
 } SN_TYPE;
 
 typedef struct
 {
   char cruise[FIELD_LENGTH], ship[FIELD_LENGTH], project[FIELD_LENGTH], 
     area[FIELD_LENGTH], station[FIELD_LENGTH];
   int  bottom;
 } MISC_TYPE;
    
 typedef struct
 {
   short year, month, day, hour, minute, second;
 } YMDHMS_TIME_TYPE;
 
 /* Header structure */
 typedef struct 
 {
   I_POSITION_TYPE   ilat, ilon;
   F_POSITION_TYPE   flat, flon;
   YMDHMS_TIME_TYPE  time;
   SN_TYPE           sn;
   MISC_TYPE         misc;
   char              hlat, hlon;
 } HDR_TYPE; 
   
 /* Option structure */
 typedef struct {
   HDR_TYPE *hdr;
   char suffix[FIELD_LENGTH];
 } OPT_TYPE;

 /* Required for opening the input for the lexical analyzer */
 extern FILE *yyin;
    
 /* Global Variables */
 int IERR = 0;             /* Error status     */
 int VERBOSE = 0;          /* Verbose mode     */
 int INTERACTIVE = 0;      /* Interactive mode */

 /* File Variables */
 static HDR_TYPE hdr;              /* Header structure                */
 static FILE *fp_hdr;              /* Pointer to header file          */
 static int lexstat;               /* Current lext status             */
 static int line_num;              /* Current line number in header   */
 static long fpos;                 /* Start of current header field   */
  
  /* Code names. This list is used for reporting warnings and errors. */
  static CODE_NAME_LIST_TYPE code_names[]=
  {
    {"NO CODE"        , NO_CODE},
    {"UNKNOWN CODE"   , UNKNOWN_CODE},
    {"UNKNOWN KEYWORD", UNKNOWN_KEYWORD_CODE},
    {"UNKNOWN RULE"   , UNKNOWN_RULE_CODE},
    {"UNKNOWN NAME"   , UNKNOWN_NAME_CODE},
    {"UNDEFINED VALUE", UNDEFINED_VALUE_CODE},
    {"INVALID VALUE"  , INVALID_VALUE_CODE},
    {"STRING"         , STRING_CODE},
    {"CHAR"           , CHAR_CODE},
    {"INTEGER"        , INT_CODE},
    {"SHORT"          , SHORT_CODE},
    {"FLOAT"          , FLOAT_CODE},
    {"OPTION"         , OPTION_CODE},
    {"ARGUMENT"       , ARGUMENT_CODE},
    {"OPEN"           , OPEN_CODE},
    {"CLOSE"          , CLOSE_CODE},
    {"WRITE"          , WRITE_CODE},
    {"READ"           , READ_CODE},
    {"RENAME"         , RENAME_CODE},
    {"LATITUDE"       , LATITUDE_CODE},
    {"LONGITUDE"      , LONGITUDE_CODE},
    {"DATE TIME"      , DATE_TIME_CODE},
    {"STATION"        , STATION_CODE},
    {"SHIP"           , SHIP_CODE},
    {"CRUISE"         , CRUISE_CODE},
    {"AREA"           , AREA_CODE},
    {"PROJECT"        , PROJECT_CODE},
    {"BOTTOM"         , BOTTOM_CODE},
    {"VERSION"        , VERSION_CODE},
    {"T SENSOR"       , TSN_CODE},
    {"C SENSOR"       , CSN_CODE},
    {"P SENSOR"       , PSN_CODE},
    {(char*) NULL, 0}
  };

  /* Correspondance between month names and their associated number */
  static CODE_NAME_LIST_TYPE month_name_list[]=
  {
    {"Jan",  1},
    {"Feb",  2},
    {"Mar",  3},
    {"Apr",  4},
    {"May",  5},
    {"Jun",  6},
    {"Jul",  7},
    {"Aug",  8},
    {"Sep",  9},
    {"Oct", 10},
    {"Nov", 11},
    {"Dec", 12},
    {(char*)NULL, 0}
  };

  static CODE_NAME_LIST_TYPE scanf_format_list[]=
    {
      {"%hd", SHORT_CODE },
      {"%d" , INT_CODE   },
      {"%c" , CHAR_CODE  },
      {"%f" , FLOAT_CODE },
      {"%s" , STRING_CODE},
      {(char*)NULL, 0}
    };

  /* Required fields in the output file. The list must be terminated with an
     EOF */
  static int field_list[] = { HEADER_FIELDS, EOF };

static int err(int test, int code, char *fmt, ...);
static int warn(int test, int code, char *fmt, ...);
static int get_code_number(int *code, char *name, CODE_NAME_LIST_TYPE *list);
static int read_keyword(int code, char *str, char *fmt, ...);

/* Definition of keywords for the lexical file */
/* Latitude */
/* Longitude */
/* Sensor serial numbers */
/* Date and Time */
/* Ship, Cruise, ... */
/* Start conditions */
#define SKIP 1


/* Macros after this point can all be overridden by user definitions in
 * section 1.
 */

#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
extern "C" int yywrap YY_PROTO(( void ));
#else
extern int yywrap YY_PROTO(( void ));
#endif
#endif

#ifndef YY_NO_UNPUT
static void yyunput YY_PROTO(( int c, char *buf_ptr ));
#endif

#ifndef yytext_ptr
static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
#endif

#ifdef YY_NEED_STRLEN
static int yy_flex_strlen YY_PROTO(( yyconst char * ));
#endif

#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput YY_PROTO(( void ));
#else
static int input YY_PROTO(( void ));
#endif
#endif

#if YY_STACK_USED
static int yy_start_stack_ptr = 0;
static int yy_start_stack_depth = 0;
static int *yy_start_stack = 0;
#ifndef YY_NO_PUSH_STATE
static void yy_push_state YY_PROTO(( int new_state ));
#endif
#ifndef YY_NO_POP_STATE
static void yy_pop_state YY_PROTO(( void ));
#endif
#ifndef YY_NO_TOP_STATE
static int yy_top_state YY_PROTO(( void ));
#endif

#else
#define YY_NO_PUSH_STATE 1
#define YY_NO_POP_STATE 1
#define YY_NO_TOP_STATE 1
#endif

#ifdef YY_MALLOC_DECL
YY_MALLOC_DECL
#else
#if __STDC__
#ifndef __cplusplus
#include <stdlib.h>
#endif
#else
/* Just try to get by without declaring the routines.  This will fail
 * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
 * or sizeof(void*) != sizeof(int).
 */
#endif
#endif

/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
#define YY_READ_BUF_SIZE 8192
#endif

/* Copy whatever the last rule matched to the standard output. */

#ifndef ECHO
/* This used to be an fputs(), but since the string might contain NUL's,
 * we now use fwrite().
 */
#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
#endif

/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
 * is returned in "result".
 */
#ifndef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
	if ( yy_current_buffer->yy_is_interactive ) \
		{ \
		int c = '*', n; \
		for ( n = 0; n < max_size && \
			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
			buf[n] = (char) c; \
		if ( c == '\n' ) \
			buf[n++] = (char) c; \
		if ( c == EOF && ferror( yyin ) ) \
			YY_FATAL_ERROR( "input in flex scanner failed" ); \
		result = n; \
		} \
	else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
		  && ferror( yyin ) ) \
		YY_FATAL_ERROR( "input in flex scanner failed" );
#endif

/* No semi-colon after return; correct usage is to write "yyterminate();" -
 * we don't want an extra ';' after the "return" because that will cause
 * some compilers to complain about unreachable statements.
 */
#ifndef yyterminate
#define yyterminate() return YY_NULL
#endif

/* Number of entries by which start-condition stack grows. */
#ifndef YY_START_STACK_INCR
#define YY_START_STACK_INCR 25
#endif

/* Report a fatal error. */
#ifndef YY_FATAL_ERROR
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
#endif

/* Default declaration of generated scanner - a define so the user can
 * easily add parameters.
 */
#ifndef YY_DECL
#define YY_DECL int yylex YY_PROTO(( void ))
#endif

/* Code executed at the beginning of each rule, after yytext and yyleng
 * have been set up.
 */
#ifndef YY_USER_ACTION
#define YY_USER_ACTION
#endif

/* Code executed at the end of each rule. */
#ifndef YY_BREAK
#define YY_BREAK break;
#endif

#define YY_RULE_SETUP \
	if ( yyleng > 0 ) \
		yy_current_buffer->yy_at_bol = \
				(yytext[yyleng - 1] == '\n'); \
	YY_USER_ACTION

YY_DECL
	{
	register yy_state_type yy_current_state;
	register char *yy_cp, *yy_bp;
	register int yy_act;

#line 321 "scan_sbe.l"



   char cbuff[LINE_LENGTH];
   int  ibuff;



	if ( yy_init )
		{
		yy_init = 0;

#ifdef YY_USER_INIT
		YY_USER_INIT;
#endif

		if ( ! yy_start )
			yy_start = 1;	/* first start state */

		if ( ! yyin )
			yyin = stdin;

		if ( ! yyout )
			yyout = stdout;

		if ( ! yy_current_buffer )
			yy_current_buffer =
				yy_create_buffer( yyin, YY_BUF_SIZE );

		yy_load_buffer_state();
		}

	while ( 1 )		/* loops until end-of-file is reached */
		{
		yy_cp = yy_c_buf_p;

		/* Support of yytext. */
		*yy_cp = yy_hold_char;

		/* yy_bp points to the position in yy_ch_buf of the start of
		 * the current run.
		 */
		yy_bp = yy_cp;

		yy_current_state = yy_start;
		yy_current_state += YY_AT_BOL();
yy_match:
		do
			{
			register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
			if ( yy_accept[yy_current_state] )
				{
				yy_last_accepting_state = yy_current_state;
				yy_last_accepting_cpos = yy_cp;
				}
			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
				{
				yy_current_state = (int) yy_def[yy_current_state];
				if ( yy_current_state >= 174 )
					yy_c = yy_meta[(unsigned int) yy_c];
				}
			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
			++yy_cp;
			}
		while ( yy_base[yy_current_state] != 289 );

yy_find_action:
		yy_act = yy_accept[yy_current_state];
		if ( yy_act == 0 )
			{ /* have to back up */
			yy_cp = yy_last_accepting_cpos;
			yy_current_state = yy_last_accepting_state;
			yy_act = yy_accept[yy_current_state];
			}

		YY_DO_BEFORE_ACTION;


do_action:	/* This label is used only to access EOF actions. */


		switch ( yy_act )
	{ /* beginning of action switch */
			case 0: /* must back up */
			/* undo the effects of YY_DO_BEFORE_ACTION */
			*yy_cp = yy_hold_char;
			yy_cp = yy_last_accepting_cpos;
			yy_current_state = yy_last_accepting_state;
			goto yy_find_action;

case 1:
YY_RULE_SETUP
#line 328 "scan_sbe.l"
{ if(lexstat){
                      return(lexstat);
                    }
                  } 
	YY_BREAK
case 2:
YY_RULE_SETUP
#line 333 "scan_sbe.l"
{ /* Ignored */
                  }
	YY_BREAK
case 3:
YY_RULE_SETUP
#line 336 "scan_sbe.l"
{ /* Ignored */
                  }
	YY_BREAK
case 4:
YY_RULE_SETUP
#line 339 "scan_sbe.l"
{ /* Try to read string from input file */
                    if(err( read_keyword(STRING_CODE, yytext, yytext), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
/* LATITUDE */ 
case 5:
YY_RULE_SETUP
#line 349 "scan_sbe.l"
{ 
                    if(err( read_keyword(LATITUDE_CODE, yytext, 
                                         "%hd", &(hdr.ilat.degree)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 6:
YY_RULE_SETUP
#line 358 "scan_sbe.l"
{ 
                    if(err( read_keyword(LATITUDE_CODE, yytext, 
                                         "%f", &(hdr.flat.degree)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 7:
YY_RULE_SETUP
#line 367 "scan_sbe.l"
{ 
                    if(err( read_keyword(LATITUDE_CODE, yytext, 
                                         "%hd", &(hdr.ilat.minute)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 8:
YY_RULE_SETUP
#line 376 "scan_sbe.l"
{ 
                    if(err( read_keyword(LATITUDE_CODE, yytext, 
                                         "%f", &(hdr.flat.minute)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 9:
YY_RULE_SETUP
#line 385 "scan_sbe.l"
{ 
                    if(err( read_keyword(LATITUDE_CODE, yytext, 
                                         "%hd", &(hdr.ilat.second)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 10:
YY_RULE_SETUP
#line 394 "scan_sbe.l"
{ 
                    if(err( read_keyword(LATITUDE_CODE, yytext, 
                                         "%f", &(hdr.flat.second)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 11:
YY_RULE_SETUP
#line 403 "scan_sbe.l"
{ 
                    if(err( read_keyword(LATITUDE_CODE, yytext, 
                                         "%c", &(hdr.hlat)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
/* LONGITUDE */ 
case 12:
YY_RULE_SETUP
#line 414 "scan_sbe.l"
{ 
                    if(err( read_keyword(LONGITUDE_CODE, yytext, 
                                         "%hd", &(hdr.ilon.degree)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 13:
YY_RULE_SETUP
#line 423 "scan_sbe.l"
{ 
                    if(err( read_keyword(LONGITUDE_CODE, yytext, 
                                         "%f", &(hdr.flon.degree)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 14:
YY_RULE_SETUP
#line 432 "scan_sbe.l"
{ 
                    if(err( read_keyword(LONGITUDE_CODE, yytext, 
                                         "%hd", &(hdr.ilon.minute)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 15:
YY_RULE_SETUP
#line 441 "scan_sbe.l"
{ 
                    if(err( read_keyword(LONGITUDE_CODE, yytext, 
                                         "%f", &(hdr.flon.minute)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 16:
YY_RULE_SETUP
#line 450 "scan_sbe.l"
{ 
                    if(err( read_keyword(LONGITUDE_CODE, yytext, 
                                         "%hd", &(hdr.ilon.second)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 17:
YY_RULE_SETUP
#line 459 "scan_sbe.l"
{ 
                    if(err( read_keyword(LONGITUDE_CODE, yytext, 
                                         "%f", &(hdr.flon.second)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 18:
YY_RULE_SETUP
#line 468 "scan_sbe.l"
{ 
                    if(err( read_keyword(LONGITUDE_CODE, yytext, 
                                         "%c", &(hdr.hlon)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
/* SERIAL NUMBERS */
case 19:
YY_RULE_SETUP
#line 479 "scan_sbe.l"
{ 
                    if(err( read_keyword(TSN_CODE, yytext, 
                                         "%F", &(hdr.sn.tsn)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 20:
YY_RULE_SETUP
#line 488 "scan_sbe.l"
{ 
                    if(err( read_keyword(CSN_CODE, yytext, 
                                         "%F", &(hdr.sn.csn)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 21:
YY_RULE_SETUP
#line 497 "scan_sbe.l"
{ 
                    if(err( read_keyword(PSN_CODE, yytext, 
                                         "%F", &(hdr.sn.psn)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 22:
YY_RULE_SETUP
#line 506 "scan_sbe.l"
{ 
                    if(err( read_keyword(VERSION_CODE, yytext, 
                                         "%F", &(hdr.sn.version)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
/* DATE and TIME */
case 23:
YY_RULE_SETUP
#line 517 "scan_sbe.l"
{ 
                    if(err( read_keyword(DATE_TIME_CODE, yytext, 
                                         "%hd", &(hdr.time.year)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 24:
YY_RULE_SETUP
#line 526 "scan_sbe.l"
{ 
                    if(err( read_keyword(DATE_TIME_CODE, yytext, 
                                         "%hd", &(hdr.time.month)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 25:
YY_RULE_SETUP
#line 535 "scan_sbe.l"
{ 
                    strcpy(cbuff, "");
                    if(err( read_keyword(DATE_TIME_CODE, yytext, 
                                         "%s", &cbuff), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                    else{
                      if(err(get_code_number(&ibuff, cbuff, month_name_list),
                             INVALID_VALUE_CODE, 
                             "Getting code for month %s\n", cbuff))
                        return(IERR);
                      hdr.time.month = (short) ibuff;
                      if(err(IERR, DATE_TIME_CODE, 
                             "Converting month \"cbuff\"\n"))
                        return(IERR);
                    }
                  }
	YY_BREAK
case 26:
YY_RULE_SETUP
#line 555 "scan_sbe.l"
{ 
                    if(err( read_keyword(DATE_TIME_CODE, yytext, 
                                         "%hd", &(hdr.time.day)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 27:
YY_RULE_SETUP
#line 564 "scan_sbe.l"
{ 
                    if(err( read_keyword(DATE_TIME_CODE, yytext, 
                                         "%hd", &(hdr.time.hour)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 28:
YY_RULE_SETUP
#line 573 "scan_sbe.l"
{ 
                    if(err( read_keyword(DATE_TIME_CODE, yytext, 
                                         "%hd", &(hdr.time.minute)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
case 29:
YY_RULE_SETUP
#line 582 "scan_sbe.l"
{ 
                    if(err( read_keyword(DATE_TIME_CODE, yytext, 
                                         "%hd", &(hdr.time.second)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;
                  }
	YY_BREAK
/* SHIP, CRUISE, ... */
case 30:
YY_RULE_SETUP
#line 593 "scan_sbe.l"
{ 
                    if(err( read_keyword(SHIP_CODE, yytext, 
                                         "%F", &(hdr.misc.ship)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;                      
                  }
	YY_BREAK
case 31:
YY_RULE_SETUP
#line 602 "scan_sbe.l"
{ 
                    if(err( read_keyword(CRUISE_CODE, yytext, 
                                         "%F", &(hdr.misc.cruise)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;                      
                  }
	YY_BREAK
case 32:
YY_RULE_SETUP
#line 611 "scan_sbe.l"
{ 
                    if(err( read_keyword(AREA_CODE, yytext, 
                                         "%F", &(hdr.misc.area)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;                      
                  }
	YY_BREAK
case 33:
YY_RULE_SETUP
#line 620 "scan_sbe.l"
{ 
                    if(err( read_keyword(PROJECT_CODE, yytext, 
                                         "%F", &(hdr.misc.project)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;                      
                  }
	YY_BREAK
case 34:
YY_RULE_SETUP
#line 629 "scan_sbe.l"
{ 
                    if(err( read_keyword(STATION_CODE, yytext, 
                                         "%s", &(hdr.misc.station)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;                      
                  }
	YY_BREAK
case 35:
YY_RULE_SETUP
#line 638 "scan_sbe.l"
{ 
                    if(err( read_keyword(BOTTOM_CODE, yytext, 
                                         "%d", &(hdr.misc.bottom)), 
                            READ_CODE, 
                            "Reading \"%s\" from header file\n", yytext))
                      return(IERR);
                    if(lexstat == NO_CODE)
                      BEGIN SKIP;                      
                  }
	YY_BREAK
case 36:
YY_RULE_SETUP
#line 649 "scan_sbe.l"
{ /* This is an unknown keyword */
                    err(1, UNKNOWN_KEYWORD_CODE, 
                        "Unknown keyword: %s\n", yytext);
                    return(IERR);
                  }
	YY_BREAK
case 37:
YY_RULE_SETUP
#line 655 "scan_sbe.l"
{ 
                    err(1, UNKNOWN_RULE_CODE,
                        "Don't know how to handle lexical input \"%s\"\n",
                        yytext);
                    return(IERR);
                  }
	YY_BREAK
case 38:
YY_RULE_SETUP
#line 662 "scan_sbe.l"
{ BEGIN INITIAL; }
	YY_BREAK
case 39:
YY_RULE_SETUP
#line 664 "scan_sbe.l"
ECHO;
	YY_BREAK
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(SKIP):
	yyterminate();

	case YY_END_OF_BUFFER:
		{
		/* Amount of text matched not including the EOB char. */
		int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;

		/* Undo the effects of YY_DO_BEFORE_ACTION. */
		*yy_cp = yy_hold_char;
		YY_RESTORE_YY_MORE_OFFSET

		if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
			{
			/* We're scanning a new file or input source.  It's
			 * possible that this happened because the user
			 * just pointed yyin at a new source and called
			 * yylex().  If so, then we have to assure
			 * consistency between yy_current_buffer and our
			 * globals.  Here is the right place to do so, because
			 * this is the first action (other than possibly a
			 * back-up) that will match for the new input source.
			 */
			yy_n_chars = yy_current_buffer->yy_n_chars;
			yy_current_buffer->yy_input_file = yyin;
			yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
			}

		/* Note that here we test for yy_c_buf_p "<=" to the position
		 * of the first EOB in the buffer, since yy_c_buf_p will
		 * already have been incremented past the NUL character
		 * (since all states make transitions on EOB to the
		 * end-of-buffer state).  Contrast this with the test
		 * in input().
		 */
		if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
			{ /* This was really a NUL. */
			yy_state_type yy_next_state;

			yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;

			yy_current_state = yy_get_previous_state();

			/* Okay, we're now positioned to make the NUL
			 * transition.  We couldn't have
			 * yy_get_previous_state() go ahead and do it
			 * for us because it doesn't know how to deal
			 * with the possibility of jamming (and we don't
			 * want to build jamming into it because then it
			 * will run more slowly).
			 */

			yy_next_state = yy_try_NUL_trans( yy_current_state );

			yy_bp = yytext_ptr + YY_MORE_ADJ;

			if ( yy_next_state )
				{
				/* Consume the NUL. */
				yy_cp = ++yy_c_buf_p;
				yy_current_state = yy_next_state;
				goto yy_match;
				}

			else
				{
				yy_cp = yy_c_buf_p;
				goto yy_find_action;
				}
			}

		else switch ( yy_get_next_buffer() )
			{
			case EOB_ACT_END_OF_FILE:
				{
				yy_did_buffer_switch_on_eof = 0;

				if ( yywrap() )
					{
					/* Note: because we've taken care in
					 * yy_get_next_buffer() to have set up
					 * yytext, we can now set up
					 * yy_c_buf_p so that if some total
					 * hoser (like flex itself) wants to
					 * call the scanner after we return the
					 * YY_NULL, it'll still work - another
					 * YY_NULL will get returned.
					 */
					yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;

					yy_act = YY_STATE_EOF(YY_START);
					goto do_action;
					}

				else
					{
					if ( ! yy_did_buffer_switch_on_eof )
						YY_NEW_FILE;
					}
				break;
				}

			case EOB_ACT_CONTINUE_SCAN:
				yy_c_buf_p =
					yytext_ptr + yy_amount_of_matched_text;

				yy_current_state = yy_get_previous_state();

				yy_cp = yy_c_buf_p;
				yy_bp = yytext_ptr + YY_MORE_ADJ;
				goto yy_match;

			case EOB_ACT_LAST_MATCH:
				yy_c_buf_p =
				&yy_current_buffer->yy_ch_buf[yy_n_chars];

				yy_current_state = yy_get_previous_state();

				yy_cp = yy_c_buf_p;
				yy_bp = yytext_ptr + YY_MORE_ADJ;
				goto yy_find_action;
			}
		break;
		}

	default:
		YY_FATAL_ERROR(
			"fatal flex scanner internal error--no action found" );
	} /* end of action switch */
		} /* end of scanning one token */
	} /* end of yylex */


/* yy_get_next_buffer - try to read in a new buffer
 *
 * Returns a code representing an action:
 *	EOB_ACT_LAST_MATCH -
 *	EOB_ACT_CONTINUE_SCAN - continue scanning from current position
 *	EOB_ACT_END_OF_FILE - end of file
 */

static int yy_get_next_buffer()
	{
	register char *dest = yy_current_buffer->yy_ch_buf;
	register char *source = yytext_ptr;
	register int number_to_move, i;
	int ret_val;

	if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
		YY_FATAL_ERROR(
		"fatal flex scanner internal error--end of buffer missed" );

	if ( yy_current_buffer->yy_fill_buffer == 0 )
		{ /* Don't try to fill the buffer, so this is an EOF. */
		if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
			{
			/* We matched a single character, the EOB, so
			 * treat this as a final EOF.
			 */
			return EOB_ACT_END_OF_FILE;
			}

		else
			{
			/* We matched some text prior to the EOB, first
			 * process it.
			 */
			return EOB_ACT_LAST_MATCH;
			}
		}

	/* Try to read more data. */

	/* First move last chars to start of buffer. */
	number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;

	for ( i = 0; i < number_to_move; ++i )
		*(dest++) = *(source++);

	if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
		/* don't do the read, it's not guaranteed to return an EOF,
		 * just force an EOF
		 */
		yy_current_buffer->yy_n_chars = yy_n_chars = 0;

	else
		{
		int num_to_read =
			yy_current_buffer->yy_buf_size - number_to_move - 1;

		while ( num_to_read <= 0 )
			{ /* Not enough room in the buffer - grow it. */
#ifdef YY_USES_REJECT
			YY_FATAL_ERROR(
"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
#else

			/* just a shorter name for the current buffer */
			YY_BUFFER_STATE b = yy_current_buffer;

			int yy_c_buf_p_offset =
				(int) (yy_c_buf_p - b->yy_ch_buf);

			if ( b->yy_is_our_buffer )
				{
				int new_size = b->yy_buf_size * 2;

				if ( new_size <= 0 )
					b->yy_buf_size += b->yy_buf_size / 8;
				else
					b->yy_buf_size *= 2;

				b->yy_ch_buf = (char *)
					/* Include room in for 2 EOB chars. */
					yy_flex_realloc( (void *) b->yy_ch_buf,
							 b->yy_buf_size + 2 );
				}
			else
				/* Can't grow it, we don't own it. */
				b->yy_ch_buf = 0;

			if ( ! b->yy_ch_buf )
				YY_FATAL_ERROR(
				"fatal error - scanner input buffer overflow" );

			yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];

			num_to_read = yy_current_buffer->yy_buf_size -
						number_to_move - 1;
#endif
			}

		if ( num_to_read > YY_READ_BUF_SIZE )
			num_to_read = YY_READ_BUF_SIZE;

		/* Read in more data. */
		YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
			yy_n_chars, num_to_read );

		yy_current_buffer->yy_n_chars = yy_n_chars;
		}

	if ( yy_n_chars == 0 )
		{
		if ( number_to_move == YY_MORE_ADJ )
			{
			ret_val = EOB_ACT_END_OF_FILE;
			yyrestart( yyin );
			}

		else
			{
			ret_val = EOB_ACT_LAST_MATCH;
			yy_current_buffer->yy_buffer_status =
				YY_BUFFER_EOF_PENDING;
			}
		}

	else
		ret_val = EOB_ACT_CONTINUE_SCAN;

	yy_n_chars += number_to_move;
	yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
	yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;

	yytext_ptr = &yy_current_buffer->yy_ch_buf[0];

	return ret_val;
	}


/* yy_get_previous_state - get the state just before the EOB char was reached */

static yy_state_type yy_get_previous_state()
	{
	register yy_state_type yy_current_state;
	register char *yy_cp;

	yy_current_state = yy_start;
	yy_current_state += YY_AT_BOL();

	for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
		{
		register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
		if ( yy_accept[yy_current_state] )
			{
			yy_last_accepting_state = yy_current_state;
			yy_last_accepting_cpos = yy_cp;
			}
		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
			{
			yy_current_state = (int) yy_def[yy_current_state];
			if ( yy_current_state >= 174 )
				yy_c = yy_meta[(unsigned int) yy_c];
			}
		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
		}

	return yy_current_state;
	}


/* yy_try_NUL_trans - try to make a transition on the NUL character
 *
 * synopsis
 *	next_state = yy_try_NUL_trans( current_state );
 */

#ifdef YY_USE_PROTOS
static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
#else
static yy_state_type yy_try_NUL_trans( yy_current_state )
yy_state_type yy_current_state;
#endif
	{
	register int yy_is_jam;
	register char *yy_cp = yy_c_buf_p;

	register YY_CHAR yy_c = 1;
	if ( yy_accept[yy_current_state] )
		{
		yy_last_accepting_state = yy_current_state;
		yy_last_accepting_cpos = yy_cp;
		}
	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
		{
		yy_current_state = (int) yy_def[yy_current_state];
		if ( yy_current_state >= 174 )
			yy_c = yy_meta[(unsigned int) yy_c];
		}
	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
	yy_is_jam = (yy_current_state == 173);

	return yy_is_jam ? 0 : yy_current_state;
	}


#ifndef YY_NO_UNPUT
#ifdef YY_USE_PROTOS
static void yyunput( int c, register char *yy_bp )
#else
static void yyunput( c, yy_bp )
int c;
register char *yy_bp;
#endif
	{
	register char *yy_cp = yy_c_buf_p;

	/* undo effects of setting up yytext */
	*yy_cp = yy_hold_char;

	if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
		{ /* need to shift things up to make room */
		/* +2 for EOB chars. */
		register int number_to_move = yy_n_chars + 2;
		register char *dest = &yy_current_buffer->yy_ch_buf[
					yy_current_buffer->yy_buf_size + 2];
		register char *source =
				&yy_current_buffer->yy_ch_buf[number_to_move];

		while ( source > yy_current_buffer->yy_ch_buf )
			*--dest = *--source;

		yy_cp += (int) (dest - source);
		yy_bp += (int) (dest - source);
		yy_current_buffer->yy_n_chars =
			yy_n_chars = yy_current_buffer->yy_buf_size;

		if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
			YY_FATAL_ERROR( "flex scanner push-back overflow" );
		}

	*--yy_cp = (char) c;


	yytext_ptr = yy_bp;
	yy_hold_char = *yy_cp;
	yy_c_buf_p = yy_cp;
	}
#endif	/* ifndef YY_NO_UNPUT */


#ifdef __cplusplus
static int yyinput()
#else
static int input()
#endif
	{
	int c;

	*yy_c_buf_p = yy_hold_char;

	if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
		{
		/* yy_c_buf_p now points to the character we want to return.
		 * If this occurs *before* the EOB characters, then it's a
		 * valid NUL; if not, then we've hit the end of the buffer.
		 */
		if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
			/* This was really a NUL. */
			*yy_c_buf_p = '\0';

		else
			{ /* need more input */
			int offset = yy_c_buf_p - yytext_ptr;
			++yy_c_buf_p;

			switch ( yy_get_next_buffer() )
				{
				case EOB_ACT_LAST_MATCH:
					/* This happens because yy_g_n_b()
					 * sees that we've accumulated a
					 * token and flags that we need to
					 * try matching the token before
					 * proceeding.  But for input(),
					 * there's no matching to consider.
					 * So convert the EOB_ACT_LAST_MATCH
					 * to EOB_ACT_END_OF_FILE.
					 */

					/* Reset buffer status. */
					yyrestart( yyin );

					/* fall through */

				case EOB_ACT_END_OF_FILE:
					{
					if ( yywrap() )
						return EOF;

					if ( ! yy_did_buffer_switch_on_eof )
						YY_NEW_FILE;
#ifdef __cplusplus
					return yyinput();
#else
					return input();
#endif
					}

				case EOB_ACT_CONTINUE_SCAN:
					yy_c_buf_p = yytext_ptr + offset;
					break;
				}
			}
		}

	c = *(unsigned char *) yy_c_buf_p;	/* cast for 8-bit char's */
	*yy_c_buf_p = '\0';	/* preserve yytext */
	yy_hold_char = *++yy_c_buf_p;

	yy_current_buffer->yy_at_bol = (c == '\n');

	return c;
	}


#ifdef YY_USE_PROTOS
void yyrestart( FILE *input_file )
#else
void yyrestart( input_file )
FILE *input_file;
#endif
	{
	if ( ! yy_current_buffer )
		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );

	yy_init_buffer( yy_current_buffer, input_file );
	yy_load_buffer_state();
	}


#ifdef YY_USE_PROTOS
void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
#else
void yy_switch_to_buffer( new_buffer )
YY_BUFFER_STATE new_buffer;
#endif
	{
	if ( yy_current_buffer == new_buffer )
		return;

	if ( yy_current_buffer )
		{
		/* Flush out information for old buffer. */
		*yy_c_buf_p = yy_hold_char;
		yy_current_buffer->yy_buf_pos = yy_c_buf_p;
		yy_current_buffer->yy_n_chars = yy_n_chars;
		}

	yy_current_buffer = new_buffer;
	yy_load_buffer_state();

	/* We don't actually know whether we did this switch during
	 * EOF (yywrap()) processing, but the only time this flag
	 * is looked at is after yywrap() is called, so it's safe
	 * to go ahead and always set it.
	 */
	yy_did_buffer_switch_on_eof = 1;
	}


#ifdef YY_USE_PROTOS
void yy_load_buffer_state( void )
#else
void yy_load_buffer_state()
#endif
	{
	yy_n_chars = yy_current_buffer->yy_n_chars;
	yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
	yyin = yy_current_buffer->yy_input_file;
	yy_hold_char = *yy_c_buf_p;
	}


#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
#else
YY_BUFFER_STATE yy_create_buffer( file, size )
FILE *file;
int size;
#endif
	{
	YY_BUFFER_STATE b;

	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
	if ( ! b )
		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );

	b->yy_buf_size = size;

	/* yy_ch_buf has to be 2 characters longer than the size given because
	 * we need to put in 2 end-of-buffer characters.
	 */
	b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
	if ( ! b->yy_ch_buf )
		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );

	b->yy_is_our_buffer = 1;

	yy_init_buffer( b, file );

	return b;
	}


#ifdef YY_USE_PROTOS
void yy_delete_buffer( YY_BUFFER_STATE b )
#else
void yy_delete_buffer( b )
YY_BUFFER_STATE b;
#endif
	{
	if ( ! b )
		return;

	if ( b == yy_current_buffer )
		yy_current_buffer = (YY_BUFFER_STATE) 0;

	if ( b->yy_is_our_buffer )
		yy_flex_free( (void *) b->yy_ch_buf );

	yy_flex_free( (void *) b );
	}


#ifndef YY_ALWAYS_INTERACTIVE
#ifndef YY_NEVER_INTERACTIVE
extern int isatty YY_PROTO(( int ));
#endif
#endif

#ifdef YY_USE_PROTOS
void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
#else
void yy_init_buffer( b, file )
YY_BUFFER_STATE b;
FILE *file;
#endif


	{
	yy_flush_buffer( b );

	b->yy_input_file = file;
	b->yy_fill_buffer = 1;

#if YY_ALWAYS_INTERACTIVE
	b->yy_is_interactive = 1;
#else
#if YY_NEVER_INTERACTIVE
	b->yy_is_interactive = 0;
#else
	b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
#endif
#endif
	}


#ifdef YY_USE_PROTOS
void yy_flush_buffer( YY_BUFFER_STATE b )
#else
void yy_flush_buffer( b )
YY_BUFFER_STATE b;
#endif

	{
	if ( ! b )
		return;

	b->yy_n_chars = 0;

	/* We always need two end-of-buffer characters.  The first causes
	 * a transition to the end-of-buffer state.  The second causes
	 * a jam in that state.
	 */
	b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
	b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;

	b->yy_buf_pos = &b->yy_ch_buf[0];

	b->yy_at_bol = 1;
	b->yy_buffer_status = YY_BUFFER_NEW;

	if ( b == yy_current_buffer )
		yy_load_buffer_state();
	}


#ifndef YY_NO_SCAN_BUFFER
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
#else
YY_BUFFER_STATE yy_scan_buffer( base, size )
char *base;
yy_size_t size;
#endif
	{
	YY_BUFFER_STATE b;

	if ( size < 2 ||
	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
	     base[size-1] != YY_END_OF_BUFFER_CHAR )
		/* They forgot to leave room for the EOB's. */
		return 0;

	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
	if ( ! b )
		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );

	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
	b->yy_buf_pos = b->yy_ch_buf = base;
	b->yy_is_our_buffer = 0;
	b->yy_input_file = 0;
	b->yy_n_chars = b->yy_buf_size;
	b->yy_is_interactive = 0;
	b->yy_at_bol = 1;
	b->yy_fill_buffer = 0;
	b->yy_buffer_status = YY_BUFFER_NEW;

	yy_switch_to_buffer( b );

	return b;
	}
#endif


#ifndef YY_NO_SCAN_STRING
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
#else
YY_BUFFER_STATE yy_scan_string( yy_str )
yyconst char *yy_str;
#endif
	{
	int len;
	for ( len = 0; yy_str[len]; ++len )
		;

	return yy_scan_bytes( yy_str, len );
	}
#endif


#ifndef YY_NO_SCAN_BYTES
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
#else
YY_BUFFER_STATE yy_scan_bytes( bytes, len )
yyconst char *bytes;
int len;
#endif
	{
	YY_BUFFER_STATE b;
	char *buf;
	yy_size_t n;
	int i;

	/* Get memory for full buffer, including space for trailing EOB's. */
	n = len + 2;
	buf = (char *) yy_flex_alloc( n );
	if ( ! buf )
		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );

	for ( i = 0; i < len; ++i )
		buf[i] = bytes[i];

	buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;

	b = yy_scan_buffer( buf, n );
	if ( ! b )
		YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );

	/* It's okay to grow etc. this buffer, and we should throw it
	 * away when we're done.
	 */
	b->yy_is_our_buffer = 1;

	return b;
	}
#endif


#ifndef YY_NO_PUSH_STATE
#ifdef YY_USE_PROTOS
static void yy_push_state( int new_state )
#else
static void yy_push_state( new_state )
int new_state;
#endif
	{
	if ( yy_start_stack_ptr >= yy_start_stack_depth )
		{
		yy_size_t new_size;

		yy_start_stack_depth += YY_START_STACK_INCR;
		new_size = yy_start_stack_depth * sizeof( int );

		if ( ! yy_start_stack )
			yy_start_stack = (int *) yy_flex_alloc( new_size );

		else
			yy_start_stack = (int *) yy_flex_realloc(
					(void *) yy_start_stack, new_size );

		if ( ! yy_start_stack )
			YY_FATAL_ERROR(
			"out of memory expanding start-condition stack" );
		}

	yy_start_stack[yy_start_stack_ptr++] = YY_START;

	BEGIN(new_state);
	}
#endif


#ifndef YY_NO_POP_STATE
static void yy_pop_state()
	{
	if ( --yy_start_stack_ptr < 0 )
		YY_FATAL_ERROR( "start-condition stack underflow" );

	BEGIN(yy_start_stack[yy_start_stack_ptr]);
	}
#endif


#ifndef YY_NO_TOP_STATE
static int yy_top_state()
	{
	return yy_start_stack[yy_start_stack_ptr - 1];
	}
#endif

#ifndef YY_EXIT_FAILURE
#define YY_EXIT_FAILURE 2
#endif

#ifdef YY_USE_PROTOS
static void yy_fatal_error( yyconst char msg[] )
#else
static void yy_fatal_error( msg )
char msg[];
#endif
	{
	(void) fprintf( stderr, "%s\n", msg );
	exit( YY_EXIT_FAILURE );
	}



/* Redefine yyless() so it works in section 3 code. */

#undef yyless
#define yyless(n) \
	do \
		{ \
		/* Undo effects of setting up yytext. */ \
		yytext[yyleng] = yy_hold_char; \
		yy_c_buf_p = yytext + n; \
		yy_hold_char = *yy_c_buf_p; \
		*yy_c_buf_p = '\0'; \
		yyleng = n; \
		} \
	while ( 0 )


/* Internal utility routines. */

#ifndef yytext_ptr
#ifdef YY_USE_PROTOS
static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
#else
static void yy_flex_strncpy( s1, s2, n )
char *s1;
yyconst char *s2;
int n;
#endif
	{
	register int i;
	for ( i = 0; i < n; ++i )
		s1[i] = s2[i];
	}
#endif

#ifdef YY_NEED_STRLEN
#ifdef YY_USE_PROTOS
static int yy_flex_strlen( yyconst char *s )
#else
static int yy_flex_strlen( s )
yyconst char *s;
#endif
	{
	register int n;
	for ( n = 0; s[n]; ++n )
		;

	return n;
	}
#endif


#ifdef YY_USE_PROTOS
static void *yy_flex_alloc( yy_size_t size )
#else
static void *yy_flex_alloc( size )
yy_size_t size;
#endif
	{
	return (void *) malloc( size );
	}

#ifdef YY_USE_PROTOS
static void *yy_flex_realloc( void *ptr, yy_size_t size )
#else
static void *yy_flex_realloc( ptr, size )
void *ptr;
yy_size_t size;
#endif
	{
	/* The cast to (char *) in the following accommodates both
	 * implementations that use char* generic pointers, and those
	 * that use void* generic pointers.  It works with the latter
	 * because both ANSI C and C++ allow castless assignment from
	 * any pointer type to void*, and deal with argument conversions
	 * as though doing an assignment.
	 */
	return (void *) realloc( (char *) ptr, size );
	}

#ifdef YY_USE_PROTOS
static void yy_flex_free( void *ptr )
#else
static void yy_flex_free( ptr )
void *ptr;
#endif
	{
	free( ptr );
	}

#if YY_MAIN
int main()
	{
	yylex();
	return 0;
	}
#endif
#line 664 "scan_sbe.l"


/* ------------------------------------------------------------------
   Action section 
   ------------------------------------------------------------------ */

/* ------------------------------------------------------------------
  get_code_name - Get the name of a given code

  RETURNS: the given code, or UNKNOWN_CODE if no name is associated to
           the given list.

  WARNINGS: 
     - if no name is associated to the given list.

  ERRORS: none
  ------------------------------------------------------------------ */
static int get_code_name(/* Sting for holding the name */
                         char *name, 
                         /* Code value */
                         int code, 
                         /* Pointer to list with codes and associated names */
                         CODE_NAME_LIST_TYPE *list)
{
  
  CODE_NAME_LIST_TYPE *p;
  
  p = list; 
  while((p->name != (char*)NULL) && (p->code != code)) p++;
  if(warn((p->name == (char*)NULL), UNKNOWN_CODE, 
          "No name associated to code %-d\n", code)){        
    code = get_code_name(name, UNKNOWN_CODE, code_names); 
    return(code);
  }
  strcpy(name, p->name);
  return(code);
}
  
/* ------------------------------------------------------------------
   get_code_number - Get the number of the given name

   RETURNS: EOF if no code can be found

   WARNINGS: none 
      
   ERRORS: none
   ------------------------------------------------------------------ */
static int get_code_number(int *code, char *name, CODE_NAME_LIST_TYPE *list){
  
  CODE_NAME_LIST_TYPE *p;
  
  p = list;
  while((p->name != (char*)NULL) && strcmp(p->name, name) != 0) p++;
  if(p->name == (char*)NULL)
    return(EOF);
  *code = p->code;
  return(0);
}

/* ------------------------------------------------------------------
   warn - Write a warning message to stderr

   This function uses the list "code_names" for printing the name of
   the given code.
   
   Set the format string to (char *)NULL to avoid a message.

   RETURNS: Zero if the test does not evaluate to true, or the given code, or
            UNKNOWN_CODE if no name is associated to it.

   WARNINGS: none

   ERRORS: none
   ------------------------------------------------------------------ */
static int warn(/* Test to evaluate. If true, a warning message is 
                   generated.*/
                   int test, 
                   /* Code for the warning message */
                   int code, 
                   /* Format string for warning message */
                   char *fmt, 
                   /* Arguments assiciated to the format string */
                   ...)
{
  
  char name[LINE_LENGTH];
  va_list ap;
  
  if(test){
    if(fmt){
      code = get_code_name(name, code, code_names);
      fprintf(stderr, "\n!!! WARNING %-d: %s\n", code, name);
      va_start(ap, fmt);
      vfprintf(stderr, fmt, ap);
      va_end(ap);
      fflush(stderr);
    }
    return(code);
  }
  return(0);
}

/* ------------------------------------------------------------------
   err - Output an error message and set IERR

   This function uses the list "code_names" for printing the name of
   the given code. The error code is defined by the result of the test, or by
   the given code if non-zero. Global variable IERR is set to this value.
   
   Set the format string to (char *)NULL to avoid a message.

   RETURNS: Zero if the test does not evaluate to true, or the given code, or
            UNKNOWN_CODE if no name is associated to it.

   WARNINGS: none

   ERRORS: none
   ------------------------------------------------------------------ */
static int err(/* Test to evaluate. An error is reported if it evaluates to
                  true */
               int test, 
               /* Code value corresponding to the error */
               int code, 
               /* Format string for the message */
               char *fmt, 
               /* Arguments associated to the format string */
               ...)
{
  
  char name[LINE_LENGTH];
  va_list ap;
  
  if(test){
    if(!code) code = test;
    if(fmt){
      code = get_code_name(name, code, code_names);
      fprintf(stderr, "\n!!! ERROR %-d: %s\n", code, name);
      va_start(ap, fmt);
      vfprintf(stderr, fmt, ap);
      va_end(ap);
      fflush(stderr);
    }
    IERR = code;
    return(code);
  }
  return(0);
}
 
/* ------------------------------------------------------------------
   strtrim - Trim leading and trailing spaces
   
   RETURNS: Zero
   
   WARNINGS: none

   ERRORS: none
   ------------------------------------------------------------------ */
int strtrim(char *s)
{

  int i, j, i0, i1;

  i0 = 0;
  i1 = strlen(s);

  /* Reamove leading spaces */
  i = i0;
  while((i < i1) && isspace(s[i])) i++;
  i0 = i;
  
  /* Remove trailing spaces */
  i = i1-1;
  while((i > i0) && isspace(s[i])) i--;
  i1 = i;

  /* Create copy of trimmed string */
  j = 0;
  for(i=i0; i<=i1; i++)
    s[j++] = s[i];
  s[j] = '\0';
  
  return(0);
}
     
/* ------------------------------------------------------------------
   read_keyword - Read the value associated to a keyword

   This function is used for reading the different fields in the header file.
   It is called by the lexical analyzer.

   This function uses file pointer to header file "fp_hdr". If successful,
   variable "lexstat" is set to the given code, or NO_CODE if failure.
   Currently, only one value can be read.

   Strings with code STRING_CODE are treated differently. The format string
   must contain the whole string to macth. A substring of the same length (but
   less than LINE_LENGTH) is read from the file and compared to the given
   format. This code is used to determine if the current header line
   corresponds to the given field name.

   A special format string is %F, for reading a field content as a string
   containing white spaces. A substring of length FIELD_LENGTH, but not
   extending the current line is read and returned in the given argument.

   RETURNS: error code IERR

   WARNINGS: none

   ERRORS: 
      - SEEK_CODE if it cannot seek back in the input file
   ------------------------------------------------------------------ */
static int read_keyword(/* Code correspinding to data to be read */
                        int code, 
                        /* Current buffer of data from the lexical analyzer.
                           This is the same as yytext */
                        char *str, 
                        /* Format string for reading the data */
                        char *fmt, 
                        /* Arguments associated to the format string */
                        ...)
{
  
  va_list ap;
  char cbuff[LINE_LENGTH], *c;
  long cpos;
  int n;
  
#if (HAVE_VFSCANF != 1)
  CODE_NAME_LIST_TYPE *p;
  char  last_c;
  char  *cptr;
  int   *iptr;
  float *fptr;
#endif

  /* Try to read header file according to the format */    
  if(VERBOSE)
    fprintf(stderr, "Now trying: %s ... ", str); 
  if(code == STRING_CODE){
    fgets(cbuff, strlen(fmt)+1, fp_hdr);
    n = strcmp(cbuff, fmt) ? 0 : 1;
  }
  else if(strcmp(fmt, "%F") == 0){
    n = 0;
    cpos = ftell(fp_hdr);
    if(fgets(cbuff, FIELD_LENGTH, fp_hdr)){
      /* Trim spaces */
      strtrim(cbuff);
      /* Copy string into argument */
      va_start(ap, fmt);
      c = (char *) va_arg(ap, char *);
      strcpy(c, cbuff);
      va_end(ap);
      n = 1;
    }
  }
  else{
#if (HAVE_VFSCANF == 1)    
    va_start(ap, fmt);
    n = vfscanf(fp_hdr, fmt, ap);
    va_end(ap);
#else
    /*
     * Get code for format
     */
    p = scanf_format_list;
    while((p->code != 0) && (strcmp(p->name, fmt) != 0))
      p++;
    if(p->code == 0)
      return( err(READ_CODE, code, 
                  "\n!!!ERROR: no code associated to format string \"%s\"\n",
                  fmt));
    /*
     * We've got a code for this format
     */
    va_start(ap, fmt);
    switch(p->code)
    {
      case INT_CODE:
        iptr = (int *) va_arg(ap, int *);
        n = fscanf(fp_hdr, "%d", iptr);
        break;
      case SHORT_CODE:
        iptr = (int *) va_arg(ap, int *);
        n = fscanf(fp_hdr, "%hd", (short *) iptr);
        break;
      case FLOAT_CODE:
        fptr = (float *) va_arg(ap, float *);
        n = fscanf(fp_hdr, "%f", fptr);
        break;
      case CHAR_CODE:
        cptr = (char *) va_arg(ap, char *);
        n = fscanf(fp_hdr, "%c", cptr);
        break;
      case STRING_CODE:
        cptr = (char *) va_arg(ap, char *);
        n = fscanf(fp_hdr, "%s", cptr);
        break;
      default:
        err(1, READ_CODE, "Reading input format \"%s\"\n", fmt);
        n = 0;
        break;
    }
    va_end(ap);
#endif /* HAVE_VFSCANF */
  
  }
  
  /* Success */
  if(n == 1){
    lexstat = code;
    if(VERBOSE)
      fprintf(stderr, "success\n");
    return(0);
  }
  
  /* Failure */
  if(VERBOSE)
    fprintf(stderr, "failure\n");
  get_code_name(cbuff, code, code_names);
  if(err( fseek(fp_hdr, fpos, SEEK_SET), SEEK_CODE,
          "Seeking header file at line %-d:\n%s%-d\n%s%s\n%s%s\n", line_num,
          "   current code     : ", cbuff,
          "   current lex input: ", str)) 
    return(IERR);
  lexstat = NO_CODE;
  return(0);
}

/* ------------------------------------------------------------------
   init_header - Initialize the header structure

   All data are set to their associated bad values, except for strings which
   are set to the empty string. On request, the structure can be initialized
   with coded default values.
   
   RETURNS: 0

   WARNINGS: none

   ERRORS: none
   ------------------------------------------------------------------ */
int init_header(/* Pointer to header structure */
                HDR_TYPE *hdr, 
                /* If default values should be initialized */
                int def)
{

  static int header_fields[] = { HEADER_FIELDS, EOF };
  int i;

  /* */
  hdr->ilat.degree = BADSHORT;
  hdr->ilat.minute = BADSHORT;
  hdr->ilat.second = BADSHORT;
  /* */
  hdr->ilon.degree = BADSHORT;
  hdr->ilon.minute = BADSHORT;
  hdr->ilon.second = BADSHORT;
  /* */
  hdr->flat.degree = BADFLOAT;
  hdr->flat.minute = BADFLOAT;
  hdr->flat.second = BADFLOAT;
  /* */
  hdr->flon.degree = BADFLOAT;
  hdr->flon.minute = BADFLOAT;
  hdr->flon.second = BADFLOAT;
  /* */
  hdr->time.year   = BADSHORT;
  hdr->time.month  = BADSHORT;
  hdr->time.day    = BADSHORT;
  hdr->time.hour   = BADSHORT;
  hdr->time.minute = BADSHORT;
  hdr->time.second = BADSHORT;
  /* */
  hdr->hlat = hdr->hlon = '\0';
  /* */
  hdr->sn.tsn[0] = hdr->sn.csn[0] = hdr->sn.psn[0] = 
    hdr->sn.version[0] = '\0';
  /* */
  hdr->misc.ship[0] = hdr->misc.project[0] = hdr->misc.area[0] = 
    hdr->misc.cruise[0] = hdr->misc.station[0] = '\0';
  /* */
  hdr->misc.bottom = BADINT;

  if(def){
    strcpy(hdr->sn.tsn,       "UNKNOWN"); 
    strcpy(hdr->sn.csn,       "UNKNOWN"); 
    strcpy(hdr->sn.psn,       "UNKNOWN"); 
    strcpy(hdr->sn.version,   "UNKNOWN");
    strcpy(hdr->misc.area,    "UNKNOWN"); 
  }

  /*
   * Initialize the list of required header fields
   */
  i = 0;
  while(header_fields[i] != EOF){
    field_list[i] = header_fields[i];
    i++;
  }

  return(0);
}
     
/* ------------------------------------------------------------------
   check_string - Check a string

   Checks if the string is defined. On demand, special characters can be
   removed and all characters set to upper case.

   The length of the string must not exceed LINE_LENGTH.

   RETURNS:
      - Zero on success
      - UNDEFINED_VALUE_CODE if the string is empty
      
   WARNINGS: none

   ERRORS: none
   ------------------------------------------------------------------ */
int check_string(/* String to check */
                 char *str,
                 /* String of characters to be removed. Set it to NULL if all
                    characters should be kept */
                 char *excl,
                 /* If characters should be set to upper case */
                 int uc)
{

  
  char cbuff[LINE_LENGTH];
  int  i, j, k;

  /* Check if the string is defined */
  if(!strlen(str))
    return(UNDEFINED_VALUE_CODE);

  /* Trim string */
  strtrim(str);

  /* Remove all special characters */
  if(excl){
    for(i=0; i<strlen(excl); i++){
      strcpy(cbuff, str);
      k = 0;
      for(j=0; j<strlen(cbuff); j++){
        if(cbuff[j] != excl[i])
          str[k++] = cbuff[j];
      }
      str[k] = '\0';
    }
  }
   
  /* Set characters to upper case */
  if(uc){
    for(i=0; i<strlen(str); i++)
      str[i] = toupper(str[i]);
  }

  /* Check if the string is still defined */
  if(!strlen(str))
    return(UNDEFINED_VALUE_CODE);

  return(0);
}
  
/* ------------------------------------------------------------------
   check_ival - Check integer value

   Checks if the given value is not bad, or within a certain range (inclusive
   the lower boundary, exclusive the upper).
   
   RETURNS: Zero if successful, UNDEFINED_VALUE_CODE for bad data, or
            INVALID_VALUE_CODE if not within the given range.
            
   WARNINGS: none

   ERRORS: none
   ------------------------------------------------------------------ */
int check_ival(/* Value to check */
               int value, 
               /* Minimal value allowed */
               int min, 
               /* Maximal value allowed */
               int max)
{

  if(value == BADINT) 
    return(UNDEFINED_VALUE_CODE);  
  if((value < min) || (value >= max))
    return(INVALID_VALUE_CODE);
  return(0);
}

/* ------------------------------------------------------------------
   check_fval - Check float value

   Checks if the given value is not bad, or within a certain range (inclusive
   the lower boundary, exclusive the upper).

   RETURNS: Zero if successful, UNDEFINED_VALUE_CODE for bad data, or
            INVALID_VALUE_CODE if not within the given range.
            
   WARNINGS: none

   ERRORS: none
   ------------------------------------------------------------------ */
int check_fval(/* Value to check */
               float value, 
               /* Minimal value allowed */
               float min, 
               /* Maximal value alloed */
               float max)
{
  
  if(value > ADJ_BADFLOAT)
    return(UNDEFINED_VALUE_CODE);
  if((value < min) || (value >= max))
    return(INVALID_VALUE_CODE);
  return(0);
}

/* ------------------------------------------------------------------
   check_position_field - Check the value of a position field

   Check and determine the value of the given position field (i.e. degree,
   minute or second). It first tries to read the field from the integer
   holder. If successful, it looks if a decimal value is available in the
   float holder, in which case this must be less than one (i.e. only the
   decimal part). If no integer value is available, it tries to get the value
   from the float holder.

   The final value is checked according to the given range. See functions
   check_ival() and check_fval() for more information.

   On output, the integer or float holder is updated with the value, the other 
   one being set to bad.

   RETURNS: 
      - UNDEFINED_VALUE_CODE if both holders are set to bad
      - INVALID_VALUE_CODE if no valid data is found, or too much data is
        available
      - INT_CODE if successful and the position field is an integer
      - FLOAT_CODE if successful and the position field is a float

   WARNINGS: none
   
   ERRORS: none

   2000/12/14 PJ
              Modified so that if one has an integer *AND* a float value,
              the float value is divided by hundred. and added to the integer
              value. This allows reading of floats with comma as decimal
              point. 
   ------------------------------------------------------------------ */
int check_position_field(/* Pointer to integer holder */
                         short *ival, 
                         /* Pointer to float holder */
                         float *fval, 
                         /* Minimal allowed value */
                         float min, 
                         /* Maximal allowed value */
                         float max)
{
 
  float fpos = BADFLOAT;
  short ipos = BADSHORT;
  int code;
 
  /* Check if an integer value is defined */
  if(*ival != BADSHORT){
    /* A decimal value is allowed, but only the decimals */
    if(*fval < ADJ_BADFLOAT){
      if(*fval < 1.0){
        /* 2000/12/14 PJ
         *
         * fpos = (float) (ipos) + fpos;
         */
        fpos = (float) (ipos) + fpos/100.0;
        code = FLOAT_CODE;
      }
      else
        code = INVALID_VALUE_CODE;
    }
    else{
      ipos = *ival;
      code = INT_CODE;
    }
  }
  /* Check for a defined float value */
  else if(*fval < ADJ_BADFLOAT){
    fpos = *fval;
    code = FLOAT_CODE;
  }
  else
    code = UNDEFINED_VALUE_CODE;

  /* Check the value and updates the holder */
  switch(code)
    {
    case INT_CODE:
      if(check_ival((int)ipos, floor(min), ceil(max)))
        code = INVALID_VALUE_CODE;
      else{
        *ival = ipos;
        *fval = BADFLOAT;
      }
      break;
    case FLOAT_CODE:
      if(check_fval(fpos, min, max))
        code = INVALID_VALUE_CODE;
      else{
        *ival = BADSHORT;
        *fval = fpos;
      }
      break;
    default:
      break;
    }

  return(code);
}
      
/* ------------------------------------------------------------------
   check_position - Check a position

   Check and determine position value from the integer and float holders.
   Individual fields are processed by function check_position_field() (i.e.
   degree, minute and second). If a parent field is found to be a float, its
   children are ignored. For example, minute and second are ignored if degree
   are decimal and second is ignored if minute is decimal.

   The calculated position is checked against a given range by functions
   check_ival() and check_fval().

   On output, both holders are updated with the given position. Hemisphere
   sign is not checked.
   

   RETURNS: 
      - Zero on success
      - UNDEFINED_VALUE_CODE if a required position field is not defined
      - INVALID_VALUE_CODE 
           - if a required field does not contain valid data
           - if the processed position is not valid
      - UNKNOWN_CODE if function check_position_field() does not return
        an expected value. This should not happen.

    WARNINGS: if a default value from the command line should be used.

    ERRORS: lots of them if position cannot be processed correctly.
   ------------------------------------------------------------------ */
int check_position(/* Code associated to position structure */
                   int code, 
                   /* Pointer to structure of integer holders */
                   I_POSITION_TYPE *ipos, 
                   /* Pointer to structure of float holders */
                   F_POSITION_TYPE *fpos,
                   /* Minimal value allowed */
                   float min, 
                   /* Maximal value allowed */
                   float max)
{
  
  char  cbuff[LINE_LENGTH];
  float pos;
  int   status;

  /* Check degree */
  status = check_position_field(&(ipos->degree), &(fpos->degree), min, max);
  switch(status)
    {
    case UNDEFINED_VALUE_CODE:
      err(1, code, "Undefined value for degree\n");
      return(status);
      break;
    case INVALID_VALUE_CODE:
      err(1, code, "Invalid value for degree\n%s%-d\n%s%12.6f\n",
          "   i-degree: ", ipos->degree,
          "   f-degree: ", fpos->degree);
      return(status);
      break;
    case INT_CODE:
      pos = (float) ipos->degree;
      break;
    case FLOAT_CODE:
      pos = fpos->degree;
      break;
    default:
      get_code_name(cbuff, status, code_names);
      err(1, code, 
          "Invalid value status for degree:\n%s%-d\n%s%s\n",
          "   value: ", status,
          "   name : ", cbuff);
      return(UNKNOWN_CODE);
    }
 
  /* Check for minutes */
  if(status == INT_CODE){
    status = check_position_field(&(ipos->minute), &(fpos->minute), 0.0, 60.0);
    switch(status)
      {
      case UNDEFINED_VALUE_CODE:
        err(1, code, "Undefined value for minute\n");
        return(status);
        break;
      case INVALID_VALUE_CODE:
        err(1, code, "Invalid value for minute\n%s%-d\n%s%12.6f\n",
            "   i-degree: ", ipos->minute,
            "   f-degree: ", fpos->minute);
        return(status);
        break;
      case INT_CODE:
        pos += ((float) ipos->minute)/60.0;
        break;
      case FLOAT_CODE:
        pos += fpos->minute/60.0;
        break;
      default:
        get_code_name(cbuff, status, code_names);
        err(1, code, 
            "Invalid value status for minute\n%s%-d\n%s%s\n",
            "   value: ", status,
            "   name : ", cbuff);
        return(UNKNOWN_CODE);
      }
  }
  
  /* Check for seconds */
  if(status == INT_CODE){
    status = check_position_field(&(ipos->second), &(fpos->second), 0.0, 60.0);
    switch(status)
      {
      case UNDEFINED_VALUE_CODE:
        err(1, code, "Undefined value for second\n");
        return(status);
        break;
      case INVALID_VALUE_CODE:
        err(1, code, "Invalid value for second\n%s%-d\n%s%12.6f\n",
            "   i-degree: ", ipos->second,
            "   f-degree: ", fpos->second);
        return(status);
        break;
      case INT_CODE:
        pos += ((float) ipos->second)/3600.0;
        break;
      case FLOAT_CODE:
        pos += fpos->second/3600.0;
        break;
      default:
        get_code_name(cbuff, status, code_names);
        err(1, code, 
            "Invalid value status for second:\n%s%-d\n%s%s\n",
            "   value: ", status,
            "   name : ", cbuff);
        return(UNKNOWN_CODE);
      }
  }

  /* Check position value */
  if(err( check_fval(pos, min, max), code, 
          "Invalid position: %12.6f\n", pos))
    return(INVALID_VALUE_CODE);
  
  /* Update the holders */
  fpos->degree = pos;
  ipos->degree = (short)fpos->degree;
  fpos->minute = (fpos->degree - (float)ipos->degree) * 60.0;
  ipos->minute = (short)fpos->minute;
  fpos->second = (fpos->minute - (float)ipos->minute) * 60.0;
  ipos->second = (short)fpos->second;
    
  return(0);
}
        
/* ------------------------------------------------------------------
   check_header - Check values from the header

   Check and process values from the elements in the header structure. If
   given values are undefined or invalid, it will try to take those from the
   default structure.

   Hemisphere are checked and set to upper case.

   RETURNS: Zero if sucessfull, or an error code if the given value is
            undefined or invalid.

   WARNINGS: whenever a default value has to be used.

   ERRORS: lots of them if something goes wrong.
   ------------------------------------------------------------------ */
int check_header(/* Code corresponding to the elements that should be
                    processed */
                 int code, 
                 /* Pointer to the header structure */
                 HDR_TYPE *hdr,
                 /* Pointer to default values */
                 HDR_TYPE *def)
{

  char cbuff[LINE_LENGTH];
  char hemi;
  YMDHMS_TIME_TYPE *t;
  MISC_TYPE        *m;
  SN_TYPE          *sn;
  
  /* Initializations */
  t  = &(hdr->time);
  m  = &(hdr->misc);
  sn = &(hdr->sn);
  get_code_name(cbuff, code, code_names);

  switch(code)
    {
    case LATITUDE_CODE:
      IERR = check_position(code, &(hdr->ilat), &(hdr->flat), 0.0, 90.0);
      if(err( IERR, IERR, "Processing %s\n", cbuff))
        return(IERR);
      /* Check the hemisphere */
      hemi = hdr->hlat;
      hemi = toupper(hemi);
      if((hemi != 'N') && (hemi != 'S')){
        hemi = def->hlat;
        hemi = toupper(hemi);
        warn(1, code, "%s%c\n%s%c\n",
             "   Invalid hemisphere   : ", hdr->hlat,
             "   Using default instead: ", hemi);
      }
      if(err( (hemi != 'N') && (hemi != 'S'), code,
              "Invalid hemisphere %c\n", hemi))
        return(INVALID_VALUE_CODE);
      hdr->hlat = hemi;
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %02hd %7.4f %c\n", cbuff,
                hdr->ilat.degree, hdr->flat.minute, hdr->hlat);
      }
      break;
    case LONGITUDE_CODE:
      IERR = check_position(code, &(hdr->ilon), &(hdr->flon), 0.0, 360.0);
      if(err( IERR, 0, "Processing %s\n", cbuff))
        return(IERR);
      /* Check the hemisphere */
      hemi = hdr->hlon;
      hemi = toupper(hemi);
      if((hemi != 'W') && (hemi != 'E')){
        hemi = def->hlon;
        hemi = toupper(hemi);      
        warn(1, code, "%s%c\n%s%c\n",
             "   Invalid hemisphere   : ", hdr->hlon,
             "   Using default instead: ", hemi);
      }
      if(err( (hemi != 'W') && (hemi != 'E'), code,
              "Invalid hemisphere %c\n", hemi))
        return(INVALID_VALUE_CODE);
      hdr->hlon = hemi;
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %03hd %7.4f %c\n", cbuff,
                hdr->ilon.degree, hdr->flon.minute, hdr->hlon);
      }
      break;
    case DATE_TIME_CODE:
      /* Check year */
      if(t->year == BADSHORT){
        t->year = def->time.year;
        warn(1, code, "Using default value for year: %-d\n", t->year);
      }
      if(t->year < 1900) t->year += 1900;
      if(t->year < 1970) t->year += 100;
      if( err( check_ival((int)t->year, 1970, (int)BADSHORT), 0,
               "Checking value for year: %-d\n", t->year))
        return(IERR);      
      /* Check month */
      if( err( check_ival((int)t->month, 1, 13), 0,
               "Checking value for month: %-d\n", t->month))
        return(IERR);
      /* Check day */
      if( err( check_ival((int)t->day, 1, 32), 0,
               "Checking value for day: %-d\n", t->day))
        return(IERR);
      /* Check hour */
      if( err( check_ival((int)t->hour, 0, 24), 0,
               "Checking value for hour: %-d\n", t->hour))
        return(IERR);
      /* Check minute */
      if( err( check_ival((int)t->minute, 0, 60), 0,
               "Checking value for minute: %-d\n", t->minute))
        return(IERR);
      /* Check second */
      if( check_ival((int)t->second, 0, 60) )
        t->second = 0;
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %04hd/%02hd/%02hd %02hd:%02hd:%02hd\n",
                cbuff, t->year, t->month, t->day, 
                t->hour, t->minute, t->second);
      }
      break;
    case BOTTOM_CODE:
      if( err( check_ival(m->bottom, 0, 10000), 0,
               "Checking value for %s: %-d\n", cbuff, m->bottom))
        return(IERR);
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %-d\n", cbuff, m->bottom);
      }
      break;
    case SHIP_CODE:
      if(check_string(m->ship, EXCLUDE_FROM_STRING_1, 1)){
        strcpy(m->ship, def->misc.ship);
        warn(1, code, "Undefined string. Using default instead\n");
      }
      if( err( check_string(m->ship, EXCLUDE_FROM_STRING_1, 1),
               0, "Checking value for %s\n", cbuff))
        return(IERR);
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %s\n", cbuff, m->ship);
      }
      break;
    case CRUISE_CODE:
      if(check_string(m->cruise, EXCLUDE_FROM_STRING_1, 1)){
        strcpy(m->cruise, def->misc.cruise);
        warn(1, code, "Undefined string. Using default instead\n");
      }
      if( err( check_string(m->cruise, EXCLUDE_FROM_STRING_1, 1),
               0, "Checking value for %s\n", cbuff))
        return(IERR);
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %s\n", cbuff, m->cruise);
      }
      break;
      break;
    case STATION_CODE:
      if(check_string(m->station, EXCLUDE_FROM_STRING_1, 1)){
        strcpy(m->station, def->misc.station);
        warn(1, code, "Undefined string. Using default instead\n");
      }
      if( err( check_string(m->station, EXCLUDE_FROM_STRING_1, 1),
               0, "Checking value for %s\n", cbuff))
        return(IERR);
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %s\n", cbuff, m->station);
      }
      break;
      break;
    case AREA_CODE:
      if(check_string(m->area, EXCLUDE_FROM_STRING_1, 1)){
        strcpy(m->area, def->misc.area);
        warn(1, code, "Undefined string. Using default instead\n");
      }
      if( err( check_string(m->area, EXCLUDE_FROM_STRING_1, 1),
               0, "Checking value for %s\n", cbuff))
        return(IERR);
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %s\n", cbuff, m->area);
      }
      break;
      break;
    case PROJECT_CODE:
      if(check_string(m->project, EXCLUDE_FROM_STRING_1, 1)){
        strcpy(m->project, def->misc.project);
        warn(1, code, "Undefined string. Using default instead\n");
      }
      if( err( check_string(m->project, EXCLUDE_FROM_STRING_1, 1),
               0, "Checking value for %s\n", cbuff))
        return(IERR);
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %s\n", cbuff, m->project);
      }
      break;
      break;
    case TSN_CODE:
      if(check_string(sn->tsn, EXCLUDE_FROM_STRING_0, 1)){
        strcpy(sn->tsn, def->sn.tsn);
        warn(1, code, "Undefined string. Using default instead\n");
      }
      if( err( check_string(sn->tsn, EXCLUDE_FROM_STRING_0, 1),
               0, "Checking value for %s\n", cbuff))
        return(IERR);
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %s\n", cbuff, sn->tsn);
      }
      break;
      break;
    case CSN_CODE:
      if(check_string(sn->csn, EXCLUDE_FROM_STRING_0, 1)){
        strcpy(sn->csn, def->sn.csn);
        warn(1, code, "Undefined string. Using default instead\n");
      }
      if( err( check_string(sn->csn, EXCLUDE_FROM_STRING_0, 1),
               0, "Checking value for %s\n", cbuff))
        return(IERR);
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %s\n", cbuff, sn->csn);
      }
      break;
    case PSN_CODE:
      if(check_string(sn->psn, EXCLUDE_FROM_STRING_0, 1)){
        strcpy(sn->psn, def->sn.psn);
        warn(1, code, "Undefined string. Using default instead\n");
      }
      if( err( check_string(sn->psn, EXCLUDE_FROM_STRING_0, 1),
               0, "Checking value for %s\n", cbuff))
        return(IERR);
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: %s\n", cbuff, sn->psn);
      }
      break;
    case VERSION_CODE:
      if(check_string(sn->version, EXCLUDE_FROM_STRING_0, 1)){
        strcpy(sn->version, def->sn.version);
        warn(1, code, "Undefined string. Using default instead\n");
      }
      if( err( check_string(sn->version, EXCLUDE_FROM_STRING_0, 1),
               0, "Checking value for %s\n", cbuff))
        return(IERR);
      if(VERBOSE){
        fprintf(stderr, "   Checked %s: [%s]\n", cbuff, sn->version);
      }
      break;
    case NO_CODE:
      return(0);
      break;
    default:
      err(1, code, "Invalid code\n");
      return(IERR);
    }

  return(0);
}

/* ------------------------------------------------------------------
   write_header - Write the new header

   Write to the output file the header line corresponding to the given code.
   If this is NO_CODE, the current header line is considered as unrequired and 
   is copied as is from the input to the output file. In this case, string
   line must contain the input header line. If the code is UNKNOWN_CODE, the
   function looks through the list of required header lines for those which
   have not been written yet and append them to the end of the output file.
   This is usefull for inserting header lines which are not present in the
   input file.

   On output, the list of required header lines is updated.

   RETURNS: Zero on success or an error code.

   WARNINGS: none

   ERRORS: if an error is raised
   ------------------------------------------------------------------ */
int write_header(/* Pointer to output file */
                 FILE *fp, 
                 /* Code of current header item */
                 int code, 
                 /* Pointer to header structure */
                 HDR_TYPE *hdr, 
                 /* Pointer to current header line */
                 char *line, 
                 /* Pointer to default header values */
                 HDR_TYPE *def)
{

  char cbuff[LINE_LENGTH];
  int i;

  if(code == UNKNOWN_CODE){
    /* Loop through missing lines */
    i = 0;
    while( field_list[i] != EOF ){
      /* Check for missing field */
      if(field_list[i]){
        code = field_list[i];
        get_code_name(cbuff, code, code_names);
        if(VERBOSE)
          fprintf(stderr, "Appending data for %s\n", cbuff); 
        if(err( check_header(code, hdr, def), IERR,
                "Checking field for %s\n", cbuff))
          return(IERR);
        if(err( write_header(fp, code, hdr, (char*)NULL, def), IERR,
                "Writing field for %s\n", cbuff))
          return(IERR);
      }
      i++;
    }
    /* Write the end of header */
    if(VERBOSE)
      fprintf(stderr, "Adding end of header: %s\n", EOH);
    fprintf(fp, "%s\n", EOH);
    return(0);
  }

  i = code - HEADER_OFFSET_CODE - 1;
  switch(code)
    {
    case LATITUDE_CODE:
      fprintf(fp, "* Latitude = %02hd %06.4f %c\n", 
              hdr->ilat.degree, hdr->flat.minute, hdr->hlat);
      field_list[i] = 0;
      break;
    case LONGITUDE_CODE:
      fprintf(fp, "* Longitude = %03hd %06.4f %c\n", 
              hdr->ilon.degree, hdr->flon.minute, hdr->hlon);
      field_list[i] = 0;
      break;
    case DATE_TIME_CODE:
      fprintf(fp, "* Time = %04hd/%02hd/%02hd %02hd:%02hd:%02hd\n",
              hdr->time.year, hdr->time.month, hdr->time.day,
              hdr->time.hour, hdr->time.minute, hdr->time.second);
      field_list[i] = 0;
      break;
    case BOTTOM_CODE:
      fprintf(fp, "* Depth = %-d\n", hdr->misc.bottom);
      field_list[i] = 0;
      break;
    case SHIP_CODE:
      fprintf(fp, "* Ship = %s\n", hdr->misc.ship);
      field_list[i] = 0;
      break;
    case CRUISE_CODE:
      fprintf(fp, "* Cruise = %s\n", hdr->misc.cruise);
      field_list[i] = 0;
      break;
    case STATION_CODE:
      fprintf(fp, "* Station = %s\n", hdr->misc.station);
      field_list[i] = 0;
      break;
    case AREA_CODE:
      fprintf(fp, "* Area = %s\n", hdr->misc.area);
      field_list[i] = 0;
      break;
    case PROJECT_CODE:
      fprintf(fp, "* Project = %s\n", hdr->misc.project);
      field_list[i] = 0;
      break;
    case TSN_CODE:
      fprintf(fp, "* Temperature SN = %s\n", hdr->sn.tsn);
      field_list[i] = 0;
      break;
    case CSN_CODE:
      fprintf(fp, "* Conductivity SN = %s\n", hdr->sn.csn);
      field_list[i] = 0;
      break;
    case PSN_CODE:
      fprintf(fp, "* Pressure SN = %s\n", hdr->sn.psn);
      field_list[i] = 0;
      break;
    case VERSION_CODE:
      fprintf(fp, "* SBE Software Version = %s\n", hdr->sn.version);
      field_list[i] = 0;
      break;
    case NO_CODE:
      if(line)
        fprintf(fp, "%s", line);
      break;
    }
  return(0);
}

/* ------------------------------------------------------------------
   print_usage - Print usage information
   
   RETURNS: Zero
   ------------------------------------------------------------------ */
int print_usage(void)
{

  fprintf(stderr, "

   %s - %s

   USAGE name [options]

   OPTIONS:
      -C <CSN>
      -E
      -N
      -P <PSN>
      -S
      -T <TSN>
      -V
      -W
      -a <area>
      -c <cruise>
      -h
      -i 
      -p <project>
      -s <ship>
      -y <year>

", PRGM, VERSION);

  return(0);
}

/* ------------------------------------------------------------------
   parse_options - Parse command line options

   RETURNS: The number of arguments parsed as options. If it fails, the
            function exists abnormally.

   WARNINGS: none

   ERRORS: If the option code is not recognized.
   ------------------------------------------------------------------ */
int parse_options(int argc, char **argv, OPT_TYPE *opt)
{

  extern char *optarg;
  extern int  optind;

  int c, long_index=0;

  char short_opts[]="C:P:T:EWNSZ:a:dc:p:s:y:hvi";
  enum OPT_CODE 
    {
      OPT_COND    = 'C',
      OPT_TEMP    = 'T',
      OPT_PRESS   = 'P',
      OPT_EAST    = 'E',
      OPT_WEST    = 'W',
      OPT_NORTH   = 'N',
      OPT_SOUTH   = 'S',
      OPT_SUFFIX  = 'Z',
      OPT_AREA    = 'a',
      OPT_CRUISE  = 'c',
      OPT_DISPLAY = 'd',
      OPT_SHIP    = 's',
      OPT_PROJECT = 'p',
      OPT_YEAR    = 'y',
      OPT_HELP    = 'h',
      OPT_VERBOSE = 'v'
    };
  struct option long_opts[]=
    {
      {"conductivity-sensor", required_argument, 0, OPT_COND    },
      {"pressure-sensor"    , required_argument, 0, OPT_PRESS   },
      {"temperature-sensor" , required_argument, 0, OPT_TEMP    },
      {"east-longitude"     , no_argument      , 0, OPT_EAST    },
      {"west-longitude"     , no_argument      , 0, OPT_WEST    },
      {"north-latitude"     , no_argument      , 0, OPT_NORTH   },
      {"south-latitude"     , no_argument      , 0, OPT_SOUTH   },
      {"header-suffix"      , required_argument, 0, OPT_SUFFIX  },
      {"area-name"          , required_argument, 0, OPT_AREA    },
      {"cruise-name"        , required_argument, 0, OPT_CRUISE  },
      {"project-name"       , required_argument, 0, OPT_PROJECT },
      {"ship-name"          , required_argument, 0, OPT_SHIP    },
      {"year-base"          , required_argument, 0, OPT_YEAR    },
      {"no-display"         , required_argument, 0, OPT_DISPLAY },
      {"help"               , no_argument      , 0, OPT_HELP    },
      {"Help"               , no_argument      , 0, OPT_HELP    },
      {"HELP"               , no_argument      , 0, OPT_HELP    },
      {"verbose"            , no_argument      , 0, OPT_VERBOSE },
      {"Verbose"            , no_argument      , 0, OPT_VERBOSE },
      {"VERBOSE"            , no_argument      , 0, OPT_VERBOSE },
    };

  HDR_TYPE *hdr;

  /*
   * Initializations
   */
  hdr = opt->hdr;

  /*
   * Loop through options
   */
  while(1){
    
    c = getopt_long(argc, argv, short_opts, long_opts, &long_index);
    if(c == -1)
      break;

    switch(c){
      
      case OPT_HELP:
        print_usage();
        exit(EXIT_FAILURE);
        break;
      case OPT_VERBOSE:
        VERBOSE = 1;
        break;
      case OPT_COND:
        strcpy(hdr->sn.csn, optarg);
        break;
      case OPT_PRESS:
        strcpy(hdr->sn.psn, optarg);
        break;
      case OPT_TEMP:
        strcpy(hdr->sn.tsn, optarg);
        break;
      case OPT_EAST:
        hdr->hlon = 'E';
        break;
      case OPT_NORTH:
        hdr->hlat = 'N';
        break;
      case OPT_WEST:
        hdr->hlon = 'W';
        break;
      case OPT_SOUTH:
        hdr->hlat = 'S';
        break;
      case OPT_SUFFIX:
        strcpy(opt->suffix, optarg);
        break;
      case OPT_AREA:
        strcpy(hdr->misc.area, optarg);
        break;
      case OPT_CRUISE:
        strcpy(hdr->misc.cruise, optarg);
        break;
      case OPT_SHIP:
        strcpy(hdr->misc.ship, optarg);
        break;
      case OPT_PROJECT:
        strcpy(hdr->misc.project, optarg);
        break;
      case OPT_YEAR:
        hdr->time.year = (short) atoi(optarg);
        break;
      case OPT_DISPLAY:
        if(getenv("DISPLAY"))
          unsetenv("DISPLAY");
        break;
      default:
        print_usage();
        exit(EXIT_FAILURE);
        break;
    }
  }

  return(optind);
}

/* ------------------------------------------------------------------
   MAIN
   ------------------------------------------------------------------ */

int main(int argc, char **argv){
  
  OPT_TYPE opts;                /* Structure for options         */
  HDR_TYPE def_hdr;             /* Header structure for defaults */
  char idir[LINE_LENGTH];       /* Input directory               */
  char gname[LINE_LENGTH];      /* Generic header file name      */
  char dir_sep = '/';           /* Directory separator           */
  struct dirent *dentry;        /* Directory entry               */
  DIR *dp_dir;                  /* Pointer to input directory    */
  int iarg;                     /* Number of options on cmd line */
  char fhdr[LINE_LENGTH];       /* Name of header file           */
  char fout[LINE_LENGTH];       /* Name of final output file     */
  FILE *fp_out;                 /* File pointer to output file   */
  char cbuff[LINE_LENGTH];      /* Temporary buffer              */
  char line[LINE_LENGTH];       /* Line buffer from header       */

  int i;

  /* These are temporary */
  char flex[]=DEFAULT_LEX;
  char lexstr[LINE_LENGTH];

  /* Initializations */
  opts.hdr = &(def_hdr);
  strcpy(opts.suffix, HEADER_SUFFIX);
  init_header(&def_hdr, 1);     /* With default values */
  
  /* Options and default values */
  iarg = parse_options(argc, argv, &opts);

  /* Loop through directory entries */
  while(iarg < argc){
    /* Initializations */
    yyin = fp_hdr = fp_out = fp_hdr = NULL;
    strcpy(cbuff, argv[iarg++]);
    /* Get directory separator and generic header file name */
    i = strlen(cbuff);
    while((i >= 0) && (cbuff[i] != '/') && (cbuff[i] != '\\')) i--;
    /* A directory path is required for detrmining the directory separator */
    if(i < 0){
      fprintf(stderr, "\nName of input files must contain directory path\n");
      exit(-1);
    }
    /* Save directory separator, input directory and generic name */
    dir_sep = cbuff[i];
    strncpy(idir, cbuff, i+1);
    idir[i+1] = '\0';
    strcpy(gname, cbuff+i+1);
    /* Open directory */
    if(err( (dp_dir = opendir(idir)) == NULL, OPEN_CODE, 
            "Opening input directory: %s\n", idir))
      goto on_error;
    /* Loop through directory entries */
    while((dentry = readdir(dp_dir)) != NULL){
      /* Check if the file starts with the same generic name, and ends with
         the correct suffix */
      i = strlen(dentry->d_name);
      while((i > 0) && (dentry->d_name[i] != '.')) i--;
      if(i <= 0)
        continue;
      strcpy(cbuff, dentry->d_name + (i+1));
      if((strstr(dentry->d_name, gname) != dentry->d_name) ||
         (strcmp(cbuff, opts.suffix) != 0))
        continue;
      /* Build name for output file */
      strcpy(fout, dentry->d_name);
      /* Build full input name */
      strcpy(fhdr, idir);
      strcat(fhdr, dentry->d_name);
      fprintf(stderr, "HEADER FILE: %s\n", fhdr);
      
      /* --- PROCESS HEADER FILE --- */

      /* Initializations */
      init_header(&hdr, 0);
      line_num = 0;
        
      /* Open input/output files */
      if(err((fp_hdr = fopen(fhdr, "r")) == NULL, OPEN_CODE, 
             "Opening header file \"%s\"\n", fhdr))
        goto on_error;
      if(err((yyin = fopen(flex, "r")) == NULL, OPEN_CODE, 
             "Opening lexical definitionfile \"%s\"\n", flex))
        goto on_error;
      if(err((fp_out = fopen(fout, "w")) == NULL, OPEN_CODE, 
             "Opening output file \"%s\"\n", fout))
        goto on_error;
      
      /* Loop through header file */
      while(!IERR && !feof(fp_hdr)){
        /* Keep start of line */
        fpos = ftell(fp_hdr);
        /* Check for end of header */
        if(err( (fscanf(fp_hdr, "%s", cbuff) != 1), READ_CODE, 
                "Reading file \"%s\" for end of header\n", fhdr))
          goto on_error;
        if(!strcmp(cbuff, EOH)){
          if(VERBOSE)
            fprintf(stderr, "Reached the end of the header: %s\n", EOH);
          break;
        }
        /* Position back to start of line */
        fseek(fp_hdr, fpos, SEEK_SET);
        /* Update line number */
        line_num++ ;
        /* Verbose */
        if(VERBOSE){
          if(err( fgets(cbuff, LINE_LENGTH, fp_hdr) == NULL, READ_CODE,
                  "Current header line at line %-d\n", line_num))
            goto on_error;
          fprintf(stderr, "Now processing header line %-d:\n  %s", 
                  line_num, cbuff);
          fseek(fp_hdr, fpos, SEEK_SET);
        } 
        /* Initialize lexical file */
        rewind(yyin);
        /* Parse header file */
        yylex();
        if(err(IERR, IERR, "Parsing header file with lexical analyzer\n"))
          goto on_error;
        if(VERBOSE){
          get_code_name(cbuff, lexstat, code_names);
          fprintf(stderr, "Returned code from lexical analyzer: %-d %s\n",
                  lexstat, cbuff);
        }
        /* Update name of lex status */
        get_code_name(lexstr, lexstat, code_names);
        /* Process data */
        if( err( check_header(lexstat, &hdr, &def_hdr), IERR,
                 "Checking header data for %s\n", lexstr))
          goto on_error;
        /* Move back to beginning of line.This is necessary as the %F fomat can
           read up to end (including it) of the line */    
        fseek(fp_hdr, fpos, SEEK_SET);
        /* Read up to next input header line */
        if( err( fgets(line, LINE_LENGTH, fp_hdr) == NULL, READ_CODE,
                 "Seeking forward header file at line %-d\n", line_num))
          goto on_error;    
        /* Write output */
        if( err( write_header(fp_out, lexstat, &hdr, line, &def_hdr), IERR, 
                 "Writing header data for %s\n", lexstr))
          goto on_error;
        /* Reset lexical status */
        lexstat = NO_CODE;
      }
      
      /* Write rest of header */
      if( err( write_header(fp_out, UNKNOWN_CODE, &hdr, (char*)NULL, &def_hdr), 
               IERR, "Writing end of header or missing lines\n"))
        goto on_error;
            
      /* Close input/output files */
      fclose(fp_hdr);
      fclose(yyin);
      fclose(fp_out);
      fp_hdr = yyin = fp_out = NULL;
            
    } /* Loop through directory entries      */
  }   /* Loop through command line arguments */

 on_error:

  if(fp_hdr) fclose(fp_hdr);
  if(yyin)   fclose(yyin);
  if(fp_out) fclose(fp_out);

  err(IERR, IERR, "!!! Abnormal termination of %s !!!\n", argv[0]);
  fflush(stderr);

  return(IERR);

}
            













