/****************************************************************************/
/*                                                                          */
/*  FILE: cmd_image2fits.c                                                  */
/*                                                                          */
/*  PURPOSE:                                                                */
/*      Execute a client command to save the current image buffer(s) to     */
/*      FITS format image files.                                            */
/*                                                                          */
/*  HISTORY:                                                                */   
/*      June 1998 -- Chris Albertson Started work                           */
/*                                                                          */
/****************************************************************************/
/*                                                                          */
/*                  Copyright (C) 1998 Chris Albertson.                     */
/*                                                                          */
/*   This program is free software; you can redistribute it and/or          */
/*   modify it under the terms of the GNU General Public License as         */ 
/*   published by the Free Software Foundation; either version 2, or        */ 
/*   (at your option) any later version.                                    */
/****************************************************************************/


/* Used by RCS and ident */
char cmd_image2fits_rcsid[] = 
    "$Id: cmd_image2fits.c,v 1.2 1998/09/29 06:44:33 chris Exp $";


#include <stdio.h>
#include <string.h>
#include <errno.h>

#include "MLog.h"
#include "server_lib.h"
#include "commands.h"
#include "tasks.h"
#include "time_funct.h"
#include "buffer_mgr.h"


/****************************************************************************/
/*                                                                          */
/*  cmd_image2fits                                                          */
/*                                                                          */
/*  PURPOSE:                                                                */
/*      Execute the "cmd_image2fits" command.                               */
/*                                                                          */
/*  ARGUMENTS:                                                              */
/*      None.  A TASS convention is used, no user settable parameters       */
/*                                                                          */
/****************************************************************************/
int cmd_image2fits(int sd, char args[])
{ 
    int res;
    
     
    ml_printf(ML_DEBUG, ML_INFORMATION,
        "cmd_image2fits called\n");  
        
    /* Write out the image */
    if(-1 == IA2FITS())
    {
        /* ERROR */
        ml_print (ML_MANDATORY, ML_ERROR,
            "ERROR: cmd_image2fits failed.\n");
            
        res = sl_Send2Client(sd, 
            "Image not writtn to disk\n");
        if (res < 0)
        {
            /* error sending command.  Client died? */
            ml_printf(ML_MANDATORY, ML_ERROR,
                "ERROR: Send to client failed on socket %d\n", sd);
            ml_printf(ML_MANDATORY, ML_ERROR, 
                "       File: %s  Line: %d\n", __FILE__, __LINE__);
            return CMD_FAIL;
        }

        return CMD_FAIL;
    }

        
    return CMD_OK;
}
