/* fnameio.c Library of routines to create file name from date and seqno Also image list and directory write routines */ /* Creation: 30-Mar-92 GCE Copied from libfnsel.c 14-Sep-1992 GCE Seperated list and IDR file functions 15-Sep-1992 GCE Consolidated file_name_sel routine */ #include #include #include #include #include "fnameio.h" /* Build next sequence string for saving files from sequence number and date */ char *file_name_sel (char *seq_fname) { static char mdstr[4], seqstr[8] = ""; FILE *seq_file = NULL; struct tm timeval; time_t timenow; int seqno = 0; /* Create string containing month and day */ time (&timenow); timeval = *localtime (&timenow); sprintf (mdstr, "%01X%02d", (timeval.tm_mon + 1), timeval.tm_mday); if (strlen (seqstr) == 0) { /* Just starting program - get last seqstr from file and close */ /* Open last sequence number file and rewind */ if (seq_fname) seq_file = fopen (seq_fname, "r"); if (seq_file) { rewind (seq_file); fgets (seqstr, 8, seq_file); fclose (seq_file); } } /* Get last seqno from seqstr if dates match */ if (strncmp (mdstr, seqstr, 3) == 0) sscanf (seqstr + 3, "%d", &seqno); /* increment seq number and build seqstr */ sprintf (seqstr, "%3s%04d", mdstr, ++seqno); /* put seqstr in sequence number file */ if (seq_fname) seq_file = fopen(seq_fname, "w+"); if (seq_file) { rewind (seq_file); fputs (seqstr, seq_file); fclose (seq_file); } /* return current sequence string */ return seqstr; } /* Write file name to list file */ /* Returns 0 on success, -1 on failure */ int listfile_write (char *listname, char *filename) { FILE *list_file; list_file = fopen (listname, "a"); if (!list_file) return -1; fprintf (list_file, "%s\n", filename); fclose (list_file); return 0; } /* Put image info in IDR (Image DiRectory) file */ /* Returns 0 on success, -1 on failure */ int idrfile_write (char *idrname, char *filename, char obs, int frames, int bitpix, int telpos[2], struct tm btim) { FILE *idr_file; idr_file = fopen (idrname, "a"); if (!idr_file) return -1; fprintf (idr_file, "%s %c %4d %2d %5d %5d %02d/%02d/%02d %02d:%02d:%02d\n", filename, obs, frames, bitpix, telpos[0], telpos[1], btim.tm_mon + 1, btim.tm_mday, btim.tm_year, btim.tm_hour, btim.tm_min, btim.tm_sec); fclose (idr_file); return 0; }