/****************************************************************************/
/*                                                                          */
/*  FILE: cmd_fits2image.c                                                  */
/*                                                                          */
/*  PURPOSE:                                                                */
/*      Execute a client command to read a FITS file into the image         */
/*      buffer(s).  This is used for testing.                               */
/*                                                                          */
/*  HISTORY:                                                                */   
/*      Sept. 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_fits2image_rcsid[] = 
    "$Id: cmd_fits2image.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_fits2image                                                          */
/*                                                                          */
/*  PURPOSE:                                                                */
/*      Execute the "cmd_fits2image" command.                               */
/*                                                                          */
/*  ARGUMENTS:                                                              */
/*      One string.  This is the name of the FITS file                      */
/*                                                                          */
/****************************************************************************/
int cmd_fits2image(int sd, char args[])
{  
    int res;
    
    
    ml_printf(ML_DEBUG, ML_INFORMATION,
        "cmd_fits2image called\n");  
            
    /* Read in the file */
    if(-1 == FITS2IA())
    {
        /* ERROR */
        ml_print (ML_MANDATORY, ML_ERROR,
            "ERROR: cmd_fits2image failed.\n");
            
        res = sl_Send2Client(sd, 
            "File is not read.  Buffer remains empty\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;
}
