Logo Search packages:      
Sourcecode: qfits version File versions  Download package

int qfits_query ( const char *  filename,
int  what 
)

Query a FITS file offset from the cache.

Parameters:
filename Name of the file to examine.
what What should be queried (see below).
Returns:
an integer offset, or -1 if an error occurred.
This function queries the cache for FITS offset information. If the requested file name has never been seen before, it is completely parsed to extract all offset informations, which are then stored in the cache. The next query will get the informations from the cache, avoiding a complete re-parsing of the file. This is especially useful for large FITS files with lots of extensions, because querying the extensions is an expensive operation.

This operation has side-effects: the cache is an automatically allocated structure in memory, that can only grow. Every request on a new FITS file will make it grow. The structure is pretty light-weight in memory, but nonetheless this is an issue for daemon-type programs which must run over long periods. The solution is to clean the cache using qfits_cache_purge() at regular intervals. This is left to the user of this library.

To request information about a FITS file, you must pass an integer built from the following symbols:

  • QFITS_QUERY_N_EXT
  • QFITS_QUERY_HDR_START
  • QFITS_QUERY_DAT_START
  • QFITS_QUERY_HDR_SIZE
  • QFITS_QUERY_DAT_SIZE

Querying the number of extensions present in a file is done simply with:

  next = qfits_query(filename, QFITS_QUERY_N_EXT);

Querying the offset to the i-th extension header is done with:

  off = qfits_query(filename, QFITS_QUERY_HDR_START | i);

i.e. you must OR (|) the extension number with the QFITS_QUERY_HDR_START symbol. Requesting offsets to extension data is done in the same way:

  off = qfits_query(filename, QFITS_QUERY_DAT_START | i);

Notice that extension 0 is the main header and main data part of the FITS file.

Definition at line 229 of file qfits_cache.c.

Referenced by qfits_get_datinfo(), qfits_get_hdrinfo(), and qfits_query_n_ext().

{
    int    rank ;
    int    which ;
    int    answer ;

    qdebug(
        printf("qfits: cache req %s\n", filename);
    );
    if ((rank=qfits_is_cached(filename))==-1) {
        rank = qfits_cache_add(filename);
    }
    if (rank==-1) {
        qdebug(
            printf("qfits: error adding %s to cache\n", filename);
        );
        return -1 ;
    }

    /* See what was requested */
    answer=-1 ;
    if (what & QFITS_QUERY_N_EXT) {
        answer = qfits_cache[rank].exts ;
        qdebug(
            printf("qfits: query n_exts\n");
            printf("qfits: -> %d\n", answer);
        );
    } else if (what & QFITS_QUERY_HDR_START) {
        which = what & (~QFITS_QUERY_HDR_START);
        if (which>=0 && which<=qfits_cache[rank].exts) {
            answer = qfits_cache[rank].ohdr[which] * FITS_BLOCK_SIZE ;
        }
        qdebug(
            printf("qfits: query offset to header %d\n", which);
            printf("qfits: -> %d (%d bytes)\n", answer/2880, answer);
        );
    } else if (what & QFITS_QUERY_DAT_START) {
        which = what & (~QFITS_QUERY_DAT_START);
        if (which>=0 && which<=qfits_cache[rank].exts) {
            answer = qfits_cache[rank].data[which] * FITS_BLOCK_SIZE ;
        }
        qdebug(
            printf("qfits: query offset to data %d\n", which);
            printf("qfits: -> %d (%d bytes)\n", answer/2880, answer);
        );
    } else if (what & QFITS_QUERY_HDR_SIZE) {
        which = what & (~QFITS_QUERY_HDR_SIZE);
        if (which>=0 && which<=qfits_cache[rank].exts) {
            answer = qfits_cache[rank].shdr[which] * FITS_BLOCK_SIZE ;
        }
        qdebug(
            printf("qfits: query sizeof header %d\n", which);
            printf("qfits: -> %d (%d bytes)\n", answer/2880, answer);
        );
    } else if (what & QFITS_QUERY_DAT_SIZE) {
        which = what & (~QFITS_QUERY_DAT_SIZE);
        if (which>=0 && which<=qfits_cache[rank].exts) {
            answer = qfits_cache[rank].dsiz[which] * FITS_BLOCK_SIZE ;
        }
        qdebug(
            printf("qfits: query sizeof data %d\n", which);
            printf("qfits: -> %d (%d bytes)\n", answer/2880, answer);
        );
    }
    return answer ;
}


Generated by  Doxygen 1.6.0   Back to index