Пример #1
0
void InitSumTrl (char *input, char *output) {

    extern int status;
    IRAFPointer    tpin;
    int n;

    char *trl_in;     /* trailer filename for input */
    char trl_out[CHAR_LINE_LENGTH+1];     /* output trailer filename */
    char in_name[CHAR_FNAME_LENGTH+1];
    char out_name[CHAR_FNAME_LENGTH+1];

    int trl_len;

    char *isuffix[] = {"_crj", "_flt"};
    char *osuffix[] = {"_sfl", "_sfl"};
    char *trlsuffix[] = {"", ""};
    int nsuffix = 2;

    int MkOutName (char *, char **, char **, int, char *, int);
    int MkNewExtn (char *, char *);
    void WhichError (int);

    trl_in = realloc (NULL, (CHAR_LINE_LENGTH));
    trl_len = CHAR_LINE_LENGTH;

    if (trl_in == NULL) {
        trlerror ("Out of memory: Couldn't allocate for CRJ_TMP trailer file.");
         status = OUT_OF_MEMORY;
        trl_len = 0;
     }
    /* Initialize TRL filenames */
    trl_in[0] = '\0';
    trl_out[0] = '\0';

    /* open the input file template */
    tpin = c_imtopen (input);

     for (n = 0; n < c_imtlen(tpin); ++n) {
        c_imtgetim (tpin, in_name, CHAR_FNAME_LENGTH);
        out_name[0] = '\0';


        /* Start by stripping off suffix from input/output filenames */
        if (MkOutName (in_name, isuffix, trlsuffix, nsuffix, out_name, CHAR_LINE_LENGTH)) {
            WhichError (status);
            sprintf (MsgText, "Couldn't create trailer filename for %s", in_name);
            trlerror (MsgText);
            continue;
        }

        /* Now, convert trailer filename extensions from '.fits' to '.trl' */
        if (MkNewExtn (out_name, TRL_EXTN) ) {
            sprintf(MsgText, "Error with input trailer filename %s", out_name);
            trlerror (MsgText);
            WhichError (status);
        }

        if ( (strlen(out_name) + strlen(trl_in) + 1) >= trl_len) {
            /*
                Add 1 to out_name to account for comma to be appended.
                WJH  4 June 2002
            */
            trl_len += strlen(out_name) + 1;
            trl_in = realloc (trl_in, trl_len);
        }

        /* Append each filename to create list of input trailer files */
        strcat(trl_in, out_name);

        /* But don't put a comma after the last filename */
        if (n < (c_imtlen(tpin)-1)) strcat (trl_in, ",");

    }

    if (MkOutName (output, osuffix, trlsuffix, nsuffix, trl_out, CHAR_LINE_LENGTH)) {
        WhichError (status);
        sprintf (MsgText, "Couldn't create trailer filename for %s", output);
        trlerror (MsgText);
    }

    /* Now, convert trailer filename extensions from '.fits' to '.trl' */
    if (MkNewExtn (trl_out, TRL_EXTN) ) {
        sprintf(MsgText, "Error with input trailer filename %s", trl_out);
        trlerror (MsgText);
        WhichError (status);
    }
    /* Sets up temp trailer file for output and copies input
        trailer file into it.
    */
    InitTrlFile (trl_in, trl_out);

    /* Deallocate memory */
    free(trl_in);
    c_imtclose (tpin);
}
Пример #2
0
int initCTETrl (char *input, char *output) {

    extern int status;

    char trl_in[SZ_LINE+1];     /* trailer filename for input */
    char trl_out[SZ_LINE+1];    /* output trailer filename */
    int exist;


    int MkName (char *, char *, char *, char *, char *, int);
    int TrlExists (char *);
    void SetTrlOverwriteMode (int);

    /* Initialize internal variables */
    trl_in[0] = '\0';
    trl_out[0] = '\0';
    exist = EXISTS_UNKNOWN;

	/* Input and output suffixes. */
	char *isuffix[] = {"_raw"};
	char *osuffix[] = {"_rac_tmp"};
	char *trlsuffix[] = {""};

	int nsuffix = 1;


	/* Start by stripping off suffix from input/output filenames */
	if (MkOutName (input, isuffix, trlsuffix, nsuffix, trl_in, SZ_LINE)) {
	    WhichError (status);
	    sprintf (MsgText, "Couldn't determine trailer filename for %s",
		     input);
	    trlmessage (MsgText);
	}
	if (MkOutName (output, osuffix, trlsuffix, nsuffix, trl_out, SZ_LINE)) {
	    WhichError (status);
	    sprintf (MsgText, "Couldn't create trailer filename for %s",
		     output);
	    trlmessage (MsgText);
	}

	/* NOW, CONVERT TRAILER FILENAME EXTENSIONS FROM '.FITS' TO '.TRL' */
    
	if (MkNewExtn (trl_in, TRL_EXTN) ) {
	    sprintf (MsgText, "Error with input trailer filename %s", trl_in);
	    trlerror (MsgText);
	    WhichError (status);
	}
	if (MkNewExtn (trl_out, TRL_EXTN) ) {
	    sprintf (MsgText, "Error with output trailer filename %s", trl_out);
	    trlerror (MsgText);
	    WhichError (status);
	}
    
 	/* If we are working with a RAW file, then see if a TRL file 
	   needs to be overwritten after the generic conversion comments.  */
	if (strstr(input, isuffix[0]) != NULL) {
	    /* Test whether the output file already exists */
	    exist = TrlExists(trl_out);            
	    if (exist == EXISTS_YES) {
		/* The output file exists, so we want to add to them 
		** the new trailer comments.  */
		    SetTrlOverwriteMode (NO);	
	    }
	}
   
    /* Sets up temp trailer file for output and copies input
     ** trailer file into it.  */
    InitTrlFile (trl_in, trl_out);
    
    return(status);
}