Beispiel #1
0
void FITSTab::saveFile()
{
    int err_status;
    char err_text[FLEN_STATUS];

    KUrl backupCurrent = currentURL;
    QString currentDir = Options::fitsDir();

    if (currentURL.path().contains("/tmp/"))
        currentURL.clear();

    // If no changes made, return.
    if( mDirty == false && !currentURL.isEmpty())
        return;

    if (currentURL.isEmpty())
    {
        currentURL = KFileDialog::getSaveUrl( currentDir, "*.fits |Flexible Image Transport System");
        // if user presses cancel
        if (currentURL.isEmpty())
        {
            currentURL = backupCurrent;
            return;
        }

        if (currentURL.path().contains('.') == 0)
            currentURL.setPath(currentURL.path() + ".fits");

        if (QFile::exists(currentURL.path()))
        {
            int r = KMessageBox::warningContinueCancel(0,
                        i18n( "A file named \"%1\" already exists. "
                              "Overwrite it?", currentURL.fileName() ),
                        i18n( "Overwrite File?" ),
                        KGuiItem(i18n( "&Overwrite" )) );
            if(r==KMessageBox::Cancel) return;
        }
    }

    if ( currentURL.isValid() )
    {
        if ( (err_status = saveFITS('!' + currentURL.path())) < 0)
        {
            fits_get_errstatus(err_status, err_text);
            // Use KMessageBox or something here
            KMessageBox::error(0, i18n("FITS file save error: %1",
                                       QString::fromUtf8(err_text)), i18n("FITS Save"));
            return;
        }

        //statusBar()->changeItem(i18n("File saved."), 3);

        emit newStatus(i18n("File saved."), FITS_MESSAGE);
        modifyFITSState();
    } else
    {
        QString message = i18n( "Invalid URL: %1", currentURL.url() );
        KMessageBox::sorry( 0, message, i18n( "Invalid URL" ) );
    }
}
Beispiel #2
0
int main (int argc, char **argv)
{
  struct CCDdev device = {"/dev/ccda"};
  struct CCDexp exposure = {&device};
  unsigned short *pixelRow, *end;
  int overage;
  unsigned avgPixel = 0;
  char *outFn;
  FILE *outFile;

  const static struct option options[] = {
    {"autoexpose", 2, NULL, 'a'},
    {"binning", 1, NULL, 'b'},
    {"bin", 1, NULL, 'b'},
    {"offset", 1, NULL, 'o'},
    {"origin", 1, NULL, 'o'},
    {"size", 1, NULL, 's'},
    {"dark", 0, NULL, 'D'},
//    {"depth", 1, NULL, 'd'},
    {"nowipe", 0, NULL, 'w'},
    {"noclear", 0, NULL, 'c'},
    {"noaccumulation", 0, NULL, 'A'},
    {"tdi", 0, NULL, 't'},
    {"TDI", 0, NULL, 't'},
    {"tiff", 2, NULL, 'T'},
    {"TIFF", 2, NULL, 'T'},
    {"FITS", 0, NULL, 'F'},
    {"fits", 0, NULL, 'F'},
    {"JPEG", 0, NULL, 'J'},
    {"jpeg", 0, NULL, 'J'},
    {"camera", 1, NULL, 'n'},
    {"debug", 2, NULL, 'S'},
    {"help", 0, NULL, 'h'},
    {NULL}
  };

  progName = basename (argv[0]);
  if (write (progressFD, "", 0)) progressFD=fileno(stdout);
  for (;;) {
    int optc = getopt_long_only (argc, argv, "", options, 0);
    switch(optc) {
      case -1:
        goto gotAllOpts;
      case 'a':  //auto exposure
        exposureSecs = 5*60;  //default to 5 minute max exposure time
        if (optarg) {
          char *terminator = optarg;
          if (*optarg != ',') terminator=parseDuration (optarg, &exposureSecs);
          switch (*terminator) {
            case ',':
              switch(*(terminator=parseInt (terminator+1, &maxAutoSignal))) {
                case ',':
                  if (*parseInt(terminator+1, &adcBias))
                    syntaxErr("Junk text after min A/D counts!");
                case '\0':
                  break;
                default:
                  syntaxErr("Junk text after autoexposure max A/D count target!");
              }
            case '\0':
              break;
            default:
              syntaxErr ("Junk text after autoexposure max duration!");
          }
          if (exposureSecs < 0.002)
            syntaxErr ("autoexposure limit must be > 2ms");
        }
        exposureSecs = -exposureSecs;
        break;
      case 'b':  //XY binning
        parseXYoptArg (&binX, &binY);
        if (!validBin(binX) || !validBin(binY))
          syntaxErr ("Binning factors must be between 1 and 4!");
        break;
      case 'o':  //origin offset
        parseXYoptArg (&offsetX, &offsetY);
        if (offsetX < 0 || offsetY < 0)
          syntaxErr ("Negative origin offset specified!");
        break;
      case 's':  //image size
        parseXYoptArg (&sizeX, &sizeY);
        if (sizeX < 0 || sizeY < 0)
          syntaxErr ("Negative image size specified!");
        break;
      case 'd':  //depth
        if (*parseInt (optarg, &CCDdepth))
          syntaxErr ("invalid text after depth option");
        if (CCDdepth <= 0)
          syntaxErr ("Negative # of depth bits specified");
        break;
      case 'S':  //display debuging status info
        debug = optarg ? atoi(optarg) : 1;
        break;
      case 'w':  //suppress CCD wipe
        exposure.flags |= CCD_EXP_FLAGS_NOWIPE_FRAME;
        break;
      case 'c':  //suppress image clear
        exposure.flags |= CCD_EXP_FLAGS_NOCLEAR_FRAME;
        break;
      case 't':  //time delay integration
        exposure.flags |= CCD_EXP_FLAGS_TDI;
        break;
      case 'A':  //no binning accumulation
        exposure.flags |= CCD_EXP_FLAGS_NOBIN_ACCUM;
        break;
      case 'D':  //dard frame
        exposure.flags |= CCD_EXP_FLAGS_NOOPEN_SHUTTER;
        break;
      case 'n':  //camera device file
        device.filename[NAME_STRING_LENGTH]='\0';
        strncpy (device.filename, optarg, NAME_STRING_LENGTH-1);
        break;
      case 'T':  //generate TIFF file
        assignType(TIFFfile);
        if (optarg && toupper(*optarg)=='D')
          setenv ("TIFF_COMPRESSION", "32946", 1);
        break;
      case 'F': //generate FITS file
        assignType(FITSfile);
        break;
      case 'J': //generate JPEG file
        assignType(JPEGfile);
        break;
      case 'h':
        usage();
        return 0;
      default:
        syntaxErr("invalid option: %s", argv[optind]);
    }
  }
gotAllOpts: //on to arguments (exposure time and output file name)
  if (exposureSecs == 0.0) {
    if (!argv[optind])
      syntaxErr ("Missing Exposure Time");
    if (*parseDuration (argv[optind], &exposureSecs))
      syntaxErr ("Junk text after exposure duration");
    if (exposureSecs < 0.001)
      syntaxErr ("Exposure duration must be >= 0.001 seconds");
    ++optind;
  }
  if (!CCDconnect (&device)) {
    fprintf (stderr, "Cannot open camera device: %s\n", device.filename);
    return 1;
  }
  printf ("%s: %dx%d pixel %d-bit CCD camera\n",
    device.camera, device.width, device.height, device.depth);

  outFn = argv[optind];
  if (outFn) {
    char *lastDot;
    outFile = fopen (outFn, "w");
    if (!outFile) {
      perror(outFn);
      return errno;
    }
    if (outputFileType == unspecifiedFile) {
      lastDot = strrchr (outFn, '.');
      if (lastDot) switch (toupper(lastDot[1])) {
        case 'J': outputFileType = JPEGfile;
          break;
        case 'T': outputFileType = TIFFfile;
          break;
        case 'F': outputFileType = FITSfile;
          break;
      }
    }
  }else  //trying to write image to stdout
    syntaxErr ("Missing output image filename!");

  exposure.width = sizeX ? sizeX : device.width;
  exposure.height = sizeY ? sizeY : device.height;
  exposure.xoffset = offsetX;
  exposure.yoffset = offsetY;
  overage = device.width - exposure.width - offsetX;
  if (overage < 0)
    exposure.width += overage;
  overage = device.height - exposure.height - offsetY;
  if (overage < 0)
    exposure.height += overage;
  exposure.xbin = binX;
  exposure.ybin = binY;
  exposure.dacBits = CCDdepth ? CCDdepth : device.dacBits;

  if (exposure.dacBits < 8 || exposure.dacBits > 16)
    syntaxErr ("Pixel depth of %d bits is not currently supported!\n", exposure.dacBits);

  if (exposureSecs < 0.0) {
    exposureSecs = -exposureSecs;
    if (debug) printf(
      "Calibrating <= %g second exposure between %d and %d A/D counts...\n",
                exposureSecs, maxAutoSignal, adcBias);
    exposure.msec = exposureSecs * 1000.0 + 0.5;
    if (optimizeExposure (&exposure)) {
      fprintf (stderr, "Autoexposure calibration failed!\n");
      return 6;
    }
  }else
    exposure.msec = exposureSecs * 1000.0 + 0.5;

  exposureSecs = (double)exposure.msec / 1000.0;
  printf ("Exposing %dx%d pixel %d-bit image for %g seconds\n",
    exposure.width/binX, exposure.height/binY, exposure.dacBits, exposureSecs);

  expose (&exposure);

  /*  Write out the image in the specified format */
  switch (outputFileType) {
    case unspecifiedFile:
      outputFileType = TIFFfile;  //default to TIFF
    case TIFFfile:
      {
        TIFF *tif = TIFFFdOpen (fileno(outFile), outFn, "w");
        if (!tif || saveTIFF (tif, &exposure)) imageWrtFailed();
        TIFFClose(tif);
      }
      break;

    case FITSfile:
      if (saveFITS (fileno(outFile), &exposure)) imageWrtFailed();
      break;

    default:
      syntaxErr("Unsupported image file type:  %s",fileTypeName[outputFileType]);
  }
  printf ("%s: %s Upload Complete\n", outFn, fileTypeName[outputFileType]);
  return 0;
}