# include # include # include # include # include /* defines HST I/O functions */ # include "calnic.h" /* defines NICMOS data structures */ # include "calnica.h" /* defines CALNICA data structures */ /* N_HISTORY: This file contains routines for saving history info and ** writing it to an image header. These are the functions: ** ** savHist: save a history record in the structure ** ** putHist: write all history records to output image; call clr_hist ** ** clrHist: free memory and reset nhist to zero ** ** Revision history: ** H.Bushouse Sept. 1995 Build 1 ** H.Bushouse 13-Mar-1998 Fixed bug in savHist to increase length of ** malloc to "length+1" (Version 3.1.2) */ # define MAX_HISTORY 25 /* Size of array of history records */ int nhist = 0; /* current number of history records */ char *phist[MAX_HISTORY]; /* array of pointers to history records */ /* Save a string so we can write it as history at the appropriate time */ int savHist (char *history) { char *p; /* temp */ int length; /* length of history record */ if (nhist+1 > MAX_HISTORY) { sprintf (MsgText, "too many history records"); n_error (MsgText); return (status = 1); } /* Note that nhist is the number of records, so it's one indexed */ nhist++; length = strlen (history); if ((p = (char *)malloc (length+1)) == NULL) { sprintf (MsgText, "savHist: can't allocate memory"); n_error (MsgText); return (status = 1); } strcpy (p, history); phist[nhist-1] = p; return (status); } /* Write all history records to the image header */ int putHist (Hdr *prihdr) { int i; void clrHist(); /* nhist is the number of records, not the index */ for (i=0; i < nhist; i++) { addHistoryKw (prihdr, phist[i]); if (hstio_err()) return (status = 1); } clrHist(); return (status = 0); } /* Free memory and reset the number of history records */ void clrHist () { int i; /* nhist is the number of records, not the index */ for (i=0; i < nhist; i++) free (phist[i]); nhist = 0; return; }