IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 8, 2006, 10:13:03 AM (20 years ago)
Author:
magnier
Message:

adding pmFPAfile handling functions for arguments, etc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/config/pmConfig.c

    r6773 r6819  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.7.4.9 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-04-04 22:14:58 $
     5 *  @version $Revision: 1.7.4.10 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-04-08 20:13:03 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1515#include <sys/types.h>
    1616#include <sys/stat.h>
     17#include <glob.h>
    1718#include "pslib.h"
    1819#include "pmConfig.h"
     
    4041    // Initialise
    4142    config->site = NULL;
    42     config->files = NULL;
    4343    config->camera = NULL;
    4444    config->recipes = NULL;
     
    4646    config->database = NULL;
    4747
     48    // the file structure is used to carry pmFPAfiles
     49    config->files = psMetadataAlloc ();
    4850    return config;
    4951}
     
    656658    return true;
    657659}
     660
     661// given the 'file' and 'list' words, find the arguments associated with these words
     662// and interpret them as lists of files.  return an array of the resulting filenames.
     663psArray *pmConfigFileSets (int *argc, char **argv, char *file, char *list)
     664{
     665
     666    int Narg;
     667
     668    // we load all input files onto a psArray, to be parsed later
     669    psArray *input = psArrayAlloc (16);
     670    input->n = 0;
     671
     672    // load the list of filenames the supplied file (may be a glob: "file*.fits")
     673    if ((Narg = psArgumentGet (*argc, argv, file))) {
     674        glob_t globList;
     675        psArgumentRemove (Narg, argc, argv);
     676        globList.gl_offs = 0;
     677        glob (argv[Narg], 0, NULL, &globList);
     678        for (int i = 0; i < globList.gl_pathc; i++) {
     679            char *filename = psStringCopy (globList.gl_pathv[i]);
     680            psArrayAdd (input, 16, filename);
     681            psFree (filename);
     682        }
     683        psArgumentRemove (Narg, argc, argv);
     684    }
     685
     686    // load the list from the supplied text file
     687    if ((Narg = psArgumentGet (*argc, argv, list))) {
     688        int nItems;
     689        char line[1024]; // XXX limits the list lines to 1024 chars
     690        char word[1024];
     691        char *filename;
     692
     693        psArgumentRemove (Narg, argc, argv);
     694        FILE *f = fopen (argv[Narg], "r");
     695        if (f == NULL) {
     696            psAbort ("psphot", "unable to open specified list file");
     697        }
     698        while (fgets (line, 1024, f) != NULL) {
     699            nItems = sscanf (line, "%s", word);
     700            switch (nItems) {
     701            case 0:
     702                break;
     703            case 1:
     704                filename = psStringCopy (word);
     705                psArrayAdd (input, 16, filename);
     706                psFree (filename);
     707                break;
     708            default:
     709                // rigid format, no comments allowed?
     710                psAbort ("pmConfig", "error parsing input list file");
     711                break;
     712            }
     713        }
     714        psArgumentRemove (Narg, argc, argv);
     715    }
     716
     717    return input;
     718}
     719
     720bool pmConfigFileSetsMD (psMetadata *metadata, int *argc, char **argv, char *name, char *file, char *list)
     721{
     722
     723    psArray *files = pmConfigFileSets (argc, argv, file, list);
     724    if (files->n == 0) {
     725        psFree (files);
     726        return false;
     727    }
     728
     729    psMetadataAddPtr (metadata, PS_LIST_TAIL, name,  PS_DATA_ARRAY, "", files);
     730    psFree (files);
     731    return true;
     732}
Note: See TracChangeset for help on using the changeset viewer.