Changeset 7676 for trunk/psModules/src/config/pmConfig.c
- Timestamp:
- Jun 23, 2006, 5:25:14 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfig.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfig.c
r7601 r7676 3 3 * @author PAP, IfA 4 4 * 5 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-06-2 1 03:05:53$5 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-06-24 03:25:14 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 35 35 } 36 36 37 pmConfig *pmConfigAlloc( void)37 pmConfig *pmConfigAlloc(int argc, char **argv) 38 38 { 39 39 pmConfig *config = psAlloc(sizeof(pmConfig)); … … 46 46 config->arguments = NULL; 47 47 config->database = NULL; 48 config->argc = argc; 49 config->argv = argv; 48 50 49 51 // the file structure is used to carry pmFPAfiles … … 166 168 *****************************************************************************/ 167 169 pmConfig *pmConfigRead( 168 int *argc,170 int argc, 169 171 char **argv) 170 172 { 171 PS_ASSERT_INT_POSITIVE( *argc, false);173 PS_ASSERT_INT_POSITIVE(argc, false); 172 174 PS_ASSERT_PTR_NON_NULL(argv, false); 173 175 174 pmConfig *config = pmConfigAlloc( ); // The configuration, containing site, camera and recipes176 pmConfig *config = pmConfigAlloc(argc, argv); // The configuration, containing site, camera and recipes 175 177 176 178 // … … 183 185 // First, try command line 184 186 // 185 psS32 argNum = psArgumentGet( *argc,argv, "-site");187 psS32 argNum = psArgumentGet(config->argc, config->argv, "-site"); 186 188 if (argNum != 0) { 187 189 // … … 190 192 // remove it as well. 191 193 // 192 psArgumentRemove(argNum, argc,argv);193 if (argNum >= *argc) {194 psArgumentRemove(argNum, &config->argc, config->argv); 195 if (argNum >= config->argc) { 194 196 psLogMsg(__func__, PS_LOG_WARN, 195 197 "-site command-line switch provided without the required filename --- ignored.\n"); 196 198 } else { 197 siteName = psStringCopy( argv[argNum]);198 psArgumentRemove(argNum, argc,argv);199 siteName = psStringCopy(config->argv[argNum]); 200 psArgumentRemove(argNum, &config->argc, config->argv); 199 201 } 200 202 } … … 250 252 // file is read and parsed into psMetadata struct "camera". 251 253 // 252 argNum = psArgumentGet( *argc,argv, "-camera");254 argNum = psArgumentGet(config->argc, config->argv, "-camera"); 253 255 if (argNum > 0) { 254 psArgumentRemove(argNum, argc,argv);255 if (argNum >= *argc) {256 psArgumentRemove(argNum, &config->argc, config->argv); 257 if (argNum >= config->argc) { 256 258 psLogMsg(__func__, PS_LOG_WARN, 257 259 "-camera command-line switch provided without the required camera or filename --- " 258 260 "ignored.\n"); 259 261 } else { 260 char *cameraFile = argv[argNum]; // The camera configuration file to read262 char *cameraFile = config->argv[argNum]; // The camera configuration file to read 261 263 262 264 // look for a symbolic camera name in the CAMERAS metadata … … 277 279 278 280 readConfig(&config->camera, cameraFile, "camera"); 279 psArgumentRemove(argNum, argc,argv);281 psArgumentRemove(argNum, &config->argc, config->argv); 280 282 } 281 283 } … … 328 330 329 331 330 argNum = psArgumentGet( *argc,argv, "-log");332 argNum = psArgumentGet(config->argc, config->argv, "-log"); 331 333 if (argNum > 0) { 332 psArgumentRemove(argNum, argc,argv);333 if (argNum >= *argc) {334 psArgumentRemove(argNum, &config->argc, config->argv); 335 if (argNum >= config->argc) { 334 336 psLogMsg(__func__, PS_LOG_WARN, 335 337 "-log command-line switch provided without the required log destination --- ignored.\n"); 336 338 } else { 337 if (!psLogSetDestination(psMessageDestination(argv[argNum]))) { 338 psLogMsg(__func__, PS_LOG_WARN, "Unable to set log destination to %s\n", argv[argNum]); 339 } 340 psArgumentRemove(argNum, argc, argv); 339 if (!psLogSetDestination(psMessageDestination(config->argv[argNum]))) { 340 psLogMsg(__func__, PS_LOG_WARN, "Unable to set log destination to %s\n", 341 config->argv[argNum]); 342 } 343 psArgumentRemove(argNum, &config->argc, config->argv); 341 344 } 342 345 } else { … … 351 354 // expanded in the future to do files, and perhaps even sockets. 352 355 if (!psLogSetDestination(psMessageDestination(logDest))) { 353 psLogMsg(__func__, PS_LOG_WARN, "Unable to set log destination to %s\n", argv[argNum]); 356 psLogMsg(__func__, PS_LOG_WARN, "Unable to set log destination to %s\n", 357 config->argv[argNum]); 354 358 } 355 359 } … … 384 388 // 385 389 psS32 saveLogLevel = psLogGetLevel(); 386 psArgumentVerbosity( argc,argv);390 psArgumentVerbosity(&config->argc, config->argv); 387 391 // XXX: substitute the string for the default log level for "2". 388 392 if (2 == psLogGetLevel()) { … … 498 502 psMetadata *pmConfigCameraFormatFromHeader( 499 503 pmConfig *config, // The configuration 500 const psMetadata *header // The FITS header504 const psMetadata *header // The FITS header 501 505 ) 502 506 { … … 599 603 } 600 604 601 bool pmConfigReadRecipes( 602 pmConfig *config 603 ) 605 606 // Read the recipe filenames 607 static bool recipeFileNames(psMetadata *target, // The target metadata into which to read the recipes 608 psMetadata *source, // The source configuration, from which to read the filenames 609 const char *sourceName // The name of the source, for error messages 610 ) 611 { 612 assert(target); 613 614 if (!source) { 615 psLogMsg(__func__, PS_LOG_WARN, "The %s has not been read --- cannot read recipes from this " 616 "location.\n", sourceName); 617 return false; 618 } 619 620 bool mdok = true; // Status of MD lookup 621 psMetadata *recipes = psMetadataLookupMD(&mdok, source, "RECIPES"); // The list of recipes 622 if (!mdok || !recipes) { 623 psLogMsg(__func__, PS_LOG_WARN, "RECIPES in the %s is not of type METADATA --- ignored\n", 624 sourceName); 625 return false; 626 } 627 628 // Copy the filenames to the target from the "RECIPES" in the source. 629 // We could use psMetadataCopy for this, but it's better to check that everything's of the correct type. 630 // If it's not of the correct type, we can tell the user which file it's in, so they can find it easier. 631 psMetadataIterator *recipesIter = psMetadataIteratorAlloc(recipes, PS_LIST_HEAD, NULL); // Iterator 632 psMetadataItem *fileItem = NULL; // MD item containing the filename, from recipe iteration 633 while ((fileItem = psMetadataGetAndIncrement(recipesIter))) { 634 if (fileItem->type != PS_DATA_STRING) { 635 psLogMsg(__func__, PS_LOG_WARN, "Recipe %s from %s is not of type STR --- ignored.\n", 636 fileItem->name, sourceName); 637 continue; 638 } 639 psMetadataAddItem(target, fileItem, PS_LIST_TAIL, PS_META_REPLACE); 640 } 641 psFree(recipesIter); 642 643 return true; 644 } 645 646 647 bool pmConfigReadRecipes(pmConfig *config 648 ) 604 649 { 605 650 PS_ASSERT_PTR_NON_NULL(config, false); 606 PS_ASSERT_PTR_NON_NULL(config->camera, false);607 651 608 652 if (!config->recipes) { … … 611 655 612 656 bool mdok = true; // Status of MD lookup 613 psMetadata *recipes = psMetadataLookupMD(&mdok, config->camera, "RECIPES"); // The list of recipes 614 if (! mdok || ! recipes) { 615 psLogMsg(__func__, PS_LOG_WARN, "RECIPES in the camera configuration file is not of type METADATA\n"); 616 return false; 617 } 618 // Go through the recipes and load each one 619 psMetadataIterator *recipesIter = psMetadataIteratorAlloc(recipes, PS_LIST_HEAD, NULL); // Iterator 657 658 // Read the recipe file names from the site configuration and camera configuration 659 recipeFileNames(config->recipes, config->site, "site configuration"); 660 recipeFileNames(config->recipes, config->camera, "camera configuration"); 661 662 // Go through the command-line arguments 663 int argNum; // Argument number for "-recipe" 664 while ((argNum = psArgumentGet(config->argc, config->argv, "-recipe")) > 0) { 665 psArgumentRemove(argNum, &config->argc, config->argv); 666 if (argNum + 1 >= config->argc) { 667 psLogMsg(__func__, PS_LOG_WARN, "-recipe command-line switch provided without the " 668 "required recipe and source --- ignored.\n"); 669 if (argNum == config->argc) { 670 // Remove the single last argument (we required two, they gave us one) 671 psArgumentRemove(argNum, &config->argc, config->argv); 672 } 673 continue; 674 } 675 676 const char *recipeName = psStringCopy(config->argv[argNum]); // Name of the recipe 677 psArgumentRemove(argNum, &config->argc, config->argv); 678 const char *recipeSource = psStringCopy(config->argv[argNum]); // Source of the recipe 679 psArgumentRemove(argNum, &config->argc, config->argv); 680 681 // Is the source a symbolic reference? 682 const char *recipeFile = psMetadataLookupStr(&mdok, config->recipes, recipeSource); 683 if (mdok && recipeFile && strlen(recipeFile) > 0) { 684 psString comment = psStringCopy("Recipe added from command line as symbolic link to "); 685 psStringAppend(&comment, "%s", recipeSource); 686 psMetadataAddStr(config->recipes, PS_LIST_TAIL, recipeName, PS_META_REPLACE, comment, recipeFile); 687 } else { 688 // Otherwise, treat the source as a filename 689 psMetadataAddStr(config->recipes, PS_LIST_TAIL, recipeName, PS_META_REPLACE, 690 "Recipe added from command line", recipeSource); 691 } 692 } 693 694 // Read the recipes 695 psMetadataIterator *recipesIter = psMetadataIteratorAlloc(config->recipes, PS_LIST_HEAD, NULL);// Iterator 620 696 psMetadataItem *recipesItem = NULL; // Item from iteration 621 697 while ((recipesItem = psMetadataGetAndIncrement(recipesIter))) { … … 625 701 continue; 626 702 } 627 628 703 psMetadata *recipe = NULL; // Recipe from file 629 704 if (readConfig(&recipe, recipesItem->data.V, "recipe")) { … … 705 780 // given the 'file' and 'list' words, find the arguments associated with these words 706 781 // and interpret them as lists of files. return an array of the resulting filenames. 707 psArray *pmConfigFileSets (int *argc, char **argv, char *file, char *list)708 { 709 PS_ASSERT_ PTR_NON_NULL(argc, NULL);710 PS_ASSERT_ INT_NONNEGATIVE(*argc, NULL);711 PS_ASSERT_PTR_NON_NULL( argv, NULL);782 psArray *pmConfigFileSets(pmConfig *config, char *file, char *list) 783 { 784 PS_ASSERT_INT_NONNEGATIVE(config->argc, NULL); 785 PS_ASSERT_PTR_NON_NULL(config, NULL); 786 PS_ASSERT_PTR_NON_NULL(config->argv, NULL); 712 787 PS_ASSERT_PTR_NON_NULL(file, NULL); 713 788 PS_ASSERT_INT_POSITIVE(strlen(file), NULL); … … 722 797 723 798 // load the list of filenames the supplied file (may be a glob: "file*.fits") 724 if ((Narg = psArgumentGet ( *argc,argv, file))) {799 if ((Narg = psArgumentGet (config->argc, config->argv, file))) { 725 800 glob_t globList; 726 psArgumentRemove (Narg, argc,argv);801 psArgumentRemove (Narg, &config->argc, config->argv); 727 802 globList.gl_offs = 0; 728 glob ( argv[Narg], 0, NULL, &globList);803 glob (config->argv[Narg], 0, NULL, &globList); 729 804 730 805 if (globList.gl_pathc == 0) { 731 psError(PS_ERR_IO, true, "No match for %s", argv[Narg]);806 psError(PS_ERR_IO, true, "No match for %s", config->argv[Narg]); 732 807 return input; 733 808 } … … 738 813 psFree (filename); 739 814 } 740 psArgumentRemove (Narg, argc,argv);815 psArgumentRemove (Narg, &config->argc, config->argv); 741 816 } 742 817 743 818 // load the list from the supplied text file 744 if ((Narg = psArgumentGet ( *argc,argv, list))) {819 if ((Narg = psArgumentGet (config->argc, config->argv, list))) { 745 820 int nItems; 746 821 char line[1024]; // XXX limits the list lines to 1024 chars … … 748 823 char *filename; 749 824 750 psArgumentRemove (Narg, argc,argv);751 FILE *f = fopen ( argv[Narg], "r");825 psArgumentRemove (Narg, &config->argc, config->argv); 826 FILE *f = fopen (config->argv[Narg], "r"); 752 827 if (f == NULL) { 753 828 psAbort ("psphot", "unable to open specified list file"); … … 769 844 } 770 845 } 771 psArgumentRemove (Narg, argc,argv);846 psArgumentRemove (Narg, &config->argc, config->argv); 772 847 } 773 848 … … 775 850 } 776 851 777 bool pmConfigFileSetsMD (psMetadata *metadata, int *argc, char **argv, char *name, char *file, char *list)852 bool pmConfigFileSetsMD (psMetadata *metadata, pmConfig *config, char *name, char *file, char *list) 778 853 { 779 854 PS_ASSERT_PTR_NON_NULL(metadata, false); 780 PS_ASSERT_PTR_NON_NULL( argc, false);781 PS_ASSERT_INT_NONNEGATIVE( *argc, NULL);782 PS_ASSERT_PTR_NON_NULL( argv, false);855 PS_ASSERT_PTR_NON_NULL(config, NULL); 856 PS_ASSERT_INT_NONNEGATIVE(config->argc, NULL); 857 PS_ASSERT_PTR_NON_NULL(config->argv, false); 783 858 PS_ASSERT_PTR_NON_NULL(name, false); 784 859 PS_ASSERT_INT_POSITIVE(strlen(name), NULL); … … 790 865 psErrorClear(); // pmConfigFileSets may or may not call psError, so 791 866 // if files->n == 0 we'll want to call psError(..., false, ...) 792 psArray *files = pmConfigFileSets (argc, argv, file, list);867 psArray *files = pmConfigFileSets(config, file, list); 793 868 if (files->n == 0) { 794 869 // psError(PS_ERR_IO, false, "pmConfigFileSets failed to find %s in the argument list", name);
Note:
See TracChangeset
for help on using the changeset viewer.
