From: André L. A. <st...@us...> - 2004-06-08 15:22:30
|
Update of /cvsroot/uts/uts/src/cam/camfits.st7 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23662 Modified Files: Makefile.am main.cpp Added Files: getindex.c getindex.h Log Message: Continues image names in camfits.st7: increments bfname-####.fits. Also some error handling. --- NEW FILE: getindex.h --- #ifndef GETINDEX_H #ifdef __cplusplus extern "C" { #endif int getindex(char *bfname); #ifdef __cplusplus } #endif #define GETINDEX_H #endif Index: main.cpp =================================================================== RCS file: /cvsroot/uts/uts/src/cam/camfits.st7/main.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** main.cpp 18 Mar 2004 19:30:19 -0000 1.1 --- main.cpp 8 Jun 2004 15:22:20 -0000 1.2 *************** *** 16,20 **** #include "fitsio.h" #include "csbigcam.h" ! using namespace std; --- 16,21 ---- #include "fitsio.h" #include "csbigcam.h" ! #include "getindex.h" ! using namespace std; *************** *** 29,33 **** char *exec_name; // Name of executable file static char *conffname; // configuration file ! static char *imagefname; // image file static double exptime; // seconds static int interval; // seconds --- 30,35 ---- char *exec_name; // Name of executable file static char *conffname; // configuration file ! static char *bfname; // image base file name ! static char imagefname[256]; // image file name static double exptime; // seconds static int interval; // seconds *************** *** 53,56 **** --- 55,59 ---- { CSBIGCam *cam; + PAR_ERROR err; unsigned short *data; *************** *** 72,95 **** printf("left: %d\n", left); printf("width: %d\n", width); ! printf("Image: %s\n", imagefname); printf("Config: %s\n", conffname); - // allocate image buffer - data = (unsigned short*)calloc(width*height, sizeof(unsigned short)); - if (data == NULL) { - printf("Error malloc\'ing! o_O\n"); - exit(1); - } - - // start talking to camera cam = new CSBIGCam(device); printf("Establishing link... "); fflush(stdout); ! cam->EstablishLink(); printf("OK.\nCamera type: %s\n", (cam->GetCameraTypeString()).c_str()); // set up camera cam->SetActiveCCD(ccd); --- 75,103 ---- printf("left: %d\n", left); printf("width: %d\n", width); ! printf("Output: %s\n", bfname); printf("Config: %s\n", conffname); // start talking to camera cam = new CSBIGCam(device); printf("Establishing link... "); fflush(stdout); ! err = cam->EstablishLink(); ! if (err != CE_NO_ERROR) { ! printf("Error linking to camera.\n"); ! delete cam; ! exit(1); ! } printf("OK.\nCamera type: %s\n", (cam->GetCameraTypeString()).c_str()); + // allocate image buffer + data = (unsigned short*)calloc(width*height, sizeof(unsigned short)); + if (data == NULL) { + printf("Error malloc\'ing! :-/\n"); + delete cam; + exit(1); + } + // set up camera cam->SetActiveCCD(ccd); *************** *** 122,129 **** // start taking images int i; printf("Taking %d images of %'.2f sec., with %d sec. interval.\n", nexp, exptime, interval); ! for (i = 1; i <= nexp; i++){ int fitstatus; long int naxes[2]; --- 130,141 ---- // start taking images int i; + int index; + + // find last image + index = getindex(bfname) + 1; printf("Taking %d images of %'.2f sec., with %d sec. interval.\n", nexp, exptime, interval); ! for (i = 0; i < nexp; i++){ int fitstatus; long int naxes[2]; *************** *** 134,143 **** naxes[1] = height; fits_create_file(&fptr, imagefname, &fitstatus); fits_create_img(fptr, SHORT_IMG, 2, naxes, &fitstatus); fits_write_date(fptr, &fitstatus); // expose ! printf("\nImage #%d: %'.2f seconds exposure... ", i, exptime); fflush(stdout); cam->StartExposure(SC_OPEN_SHUTTER); --- 146,162 ---- naxes[1] = height; + // create file name + sprintf(imagefname,"%s-%04d.fits", bfname, index + i); fits_create_file(&fptr, imagefname, &fitstatus); fits_create_img(fptr, SHORT_IMG, 2, naxes, &fitstatus); + + // fill the header + fits_update_key(fptr, TDOUBLE, "EXPTIME", &exptime, + "Exposure Time (secs.)", &fitstatus); fits_write_date(fptr, &fitstatus); // expose ! printf("\nFile: %s\n", imagefname); ! printf("Starting a %'.2f seconds exposure... ", exptime); fflush(stdout); cam->StartExposure(SC_OPEN_SHUTTER); *************** *** 197,204 **** // naxes[0], naxes[1], data, &fitstatus); - // fill the header - fits_update_key(fptr, TDOUBLE, "EXPTIME", &exptime, - "Exposure Time (secs.)", &fitstatus); - fits_close_file(fptr, &fitstatus); --- 216,219 ---- *************** *** 351,356 **** exec_name = argv[0]; conffname = NULL; ! imagefname = NULL; ! filter = 0; device = DEV_USB; ccd = CCD_IMAGING; --- 366,371 ---- exec_name = argv[0]; conffname = NULL; ! bfname = "img"; ! filter = 0; // keep the same device = DEV_USB; ccd = CCD_IMAGING; *************** *** 431,436 **** case 'o': ! /* image file name */ ! imagefname = optarg; break; --- 446,452 ---- case 'o': ! /* base image file name */ ! //imagefname = optarg; ! bfname = optarg; break; --- NEW FILE: getindex.c --- #include <stdio.h> #include <dirent.h> #include <fnmatch.h> static int matchfits(const struct dirent *d); static char *bfn; static char pattern[256]; // returns last index of bfname-####.fits int getindex(char *bfname) { struct dirent **namelist; int nd; char scanfmt[256]; char *lastent; int lastindex; int i; bfn = bfname; snprintf(pattern, 255, "%s-[0-9][0-9][0-9][0-9].fits", bfn); //find files that match pattern, see matchfits() below nd = scandir(".", &namelist, matchfits, alphasort); if (nd == 0) // no file with this base name return 0; // extract index from filename snprintf(scanfmt, 255, "%s-%%d.fits", bfname); lastent = namelist[nd-1]->d_name; sscanf(lastent, scanfmt, &lastindex); /* TODO: must somehow free the space allocated by scandir() for (i = 0; i < nd; i++) { free(namelist[i]->d_name); } free(namelist); */ return lastindex; } int matchfits(const struct dirent *d) { return !fnmatch(pattern, d->d_name, 0); } Index: Makefile.am =================================================================== RCS file: /cvsroot/uts/uts/src/cam/camfits.st7/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile.am 6 Apr 2004 20:34:05 -0000 1.4 --- Makefile.am 8 Jun 2004 15:22:20 -0000 1.5 *************** *** 1,5 **** bin_PROGRAMS = camfits.st7 ! camfits_st7_SOURCES = csbigimg.h csbigimg.cpp csbigcam.h csbigcam.cpp main.cpp camfits_st7_LDADD = -lm -lcfitsio -lsbigudrv --- 1,5 ---- bin_PROGRAMS = camfits.st7 ! camfits_st7_SOURCES = getindex.h getindex.c csbigimg.h csbigimg.cpp csbigcam.h csbigcam.cpp main.cpp camfits_st7_LDADD = -lm -lcfitsio -lsbigudrv |