diff -r 93f374d090c4 src/sys/examples/tutorials/ex79.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sys/examples/tutorials/ex79.c Mon Jul 30 15:35:58 2012 -0500 @@ -0,0 +1,19 @@ +static char help[] = "Example for PetscOptionInsertFile_YAML\n"; +#include + +int main(int argc,char **argv) +{ + PetscErrorCode ierr; + char filename[PETSC_MAX_PATH_LEN]; + PetscBool flg; + + PetscInitialize(&argc,&argv,(char *)0,help); + ierr = PetscOptionsGetString(PETSC_NULL,"-f",filename,sizeof filename,&flg); + if (flg) { + ierr = PetscOptionsInsertFile_YAML(PETSC_COMM_WORLD,filename,PETSC_TRUE);CHKERRQ(ierr); + } + ierr = PetscOptionsView(PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); + ierr = PetscFinalize(); + return(0); +} + diff -r 93f374d090c4 src/sys/examples/tutorials/ex79f90.F90 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sys/examples/tutorials/ex79f90.F90 Mon Jul 30 15:35:58 2012 -0500 @@ -0,0 +1,19 @@ + program ex79f90 +#include "finclude/petscdef.h" + use petsc + implicit none + + PetscErrorCode :: ierr + Character(len=256) :: filename + PetscBool :: flg + + Call PetscInitialize(PETSC_NULL_CHARACTER,ierr) + call PetscOptionsGetString(PETSC_NULL_CHARACTER,"-f",filename,flg,ierr) + if (flg) then + call PetscOptionsInsertFile_YAML(PETSC_COMM_WORLD,filename,PETSC_TRUE,ierr); + end if + call PetscOptionsView(PETSC_VIEWER_STDOUT_WORLD,ierr) + Call PetscFinalize(ierr) + end program ex79f90 + + diff -r 93f374d090c4 src/sys/examples/tutorials/makefile --- a/src/sys/examples/tutorials/makefile Sat Jul 28 11:35:56 2012 -0500 +++ b/src/sys/examples/tutorials/makefile Mon Jul 30 15:35:58 2012 -0500 @@ -61,6 +61,15 @@ ex7: ex7.o chkopts ex8f90: ex8f90.o chkopts -${FLINKER} -o ex8f90 ex8f90.o ${PETSC_SYS_LIB} ${RM} ex8f90.o + +ex79: ex79.o chkopts + -${CLINKER} -o ex79 ex79.o ${PETSC_SYS_LIB} + ${RM} -f ex79.o + +ex79f90: ex79f90.o chkopts + -${FLINKER} -o ex79f90 ex79f90.o ${PETSC_SYS_LIB} + ${RM} -f ex79f90.o + # # ------------------------------------------------------------------------ # @@ -112,6 +121,12 @@ runex5f90: else echo ${PWD} ; echo "Possible problem with with ex5f90_1, diffs above \n========================================="; fi; \ ${RM} -f ex5f90_1.tmp +runex79: + -@${MPIEXEC} -n 1 ./ex79 -f petsc.yaml > ex79_1.tmp 5>&1; \ + if (${DIFF} output/ex79_1.out ex79_1.tmp) then true; \ + else echo ${PWD} ; echo "Possible problem with with ex5_1, diffs above \n========================================="; fi; \ + ${RM} -f ex79_1.tmp + runex6: -@${MPIEXEC} -n 1 ./ex6 diff -r 93f374d090c4 src/sys/examples/tutorials/output/ex79_1.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sys/examples/tutorials/output/ex79_1.out Mon Jul 30 15:35:58 2012 -0500 @@ -0,0 +1,47 @@ +#PETSc Option Table entries: +-a0img_url /finex/html/img/ +-a0title Finex +-a1img_url /finex/html/img/ +-a1title Finex +-blabla 1 +-cs0001_force 0. +-cs0010_force 0. +-cs0010_hookeslaw 1,2,3,4,5,6 +-cs0020_force 0. +-f petsc.yaml +-oula oulala +-prefix ../TestMeshes/SquareNG-tri3 +-temp_KSP_monitor +-temp_KSP_type cg +-temp_snes_type ksponly +-verbose 1 +-vs0010_temp 0. +-vs0010_tempBC 1 +-vs0020_temp 1. +-vs0020_tempBC 1 +-vs0030_temp 1. +-vs0030_tempBC 1 +#End of PETSc Option Table entries +WARNING! There are options you set that were not used! +WARNING! could be spelling mistake, etc! +Option left: name:-a0img_url value: /finex/html/img/ +Option left: name:-a0title value: Finex +Option left: name:-a1img_url value: /finex/html/img/ +Option left: name:-a1title value: Finex +Option left: name:-blabla value: 1 +Option left: name:-cs0001_force value: 0. +Option left: name:-cs0010_force value: 0. +Option left: name:-cs0010_hookeslaw value: 1,2,3,4,5,6 +Option left: name:-cs0020_force value: 0. +Option left: name:-oula value: oulala +Option left: name:-prefix value: ../TestMeshes/SquareNG-tri3 +Option left: name:-temp_KSP_monitor no value +Option left: name:-temp_KSP_type value: cg +Option left: name:-temp_snes_type value: ksponly +Option left: name:-verbose value: 1 +Option left: name:-vs0010_temp value: 0. +Option left: name:-vs0010_tempBC value: 1 +Option left: name:-vs0020_temp value: 1. +Option left: name:-vs0020_tempBC value: 1 +Option left: name:-vs0030_temp value: 1. +Option left: name:-vs0030_tempBC value: 1 diff -r 93f374d090c4 src/sys/examples/tutorials/petsc.yaml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sys/examples/tutorials/petsc.yaml Mon Jul 30 15:35:58 2012 -0500 @@ -0,0 +1,39 @@ +oula: oulala +blabla: 1 +prefix: ../TestMeshes/SquareNG-tri3 +verbose: 1 +a1title : Finex 2011 +a1img_url : /finex/html/img/ + +vs0010: &clamped {tempBC: 1, temp: 0. } + +a0title : Finex 2011 +a0img_url : /finex/html/img/ + +vs0020: + tempBC: 1 + temp: 1. +#vs0040: *clamped +cs0001: + force: 0. +cs0010: + force: 0. + hookeslaw: 1,2,3,4,5,6 +cs0020: + force: 0. + #hookeslaw: + # - 1 + # - 2 + # - 3 + # - 4 + # - 5 + # - 6 +temp: + snes: + type: ksponly + KSP: + type: cg + monitor: +vs0030: + tempBC: 1 + temp: 1. diff -r 93f374d090c4 src/sys/yaml/ftn-custom/makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sys/yaml/ftn-custom/makefile Mon Jul 30 15:35:58 2012 -0500 @@ -0,0 +1,16 @@ + +#requiresdefine 'PETSC_HAVE_FORTRAN' +ALL: lib +CFLAGS = +FFLAGS = +SOURCEC = zyamlimplsf.c +OBJSC = ${SOURCEC:.c=.o} +SOURCEF = +SOURCEH = +DIRS = +LIBBASE = libpetscsys +LOCDIR = src/sys/yaml/ftn-custom/ + +include ${PETSC_DIR}/conf/variables +include ${PETSC_DIR}/conf/rules +include ${PETSC_DIR}/conf/test diff -r 93f374d090c4 src/sys/yaml/ftn-custom/zyamlimplsf.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sys/yaml/ftn-custom/zyamlimplsf.c Mon Jul 30 15:35:58 2012 -0500 @@ -0,0 +1,26 @@ +/* + This file contains Fortran stubs for Options routines. + These are not generated automatically since they require passing strings + between Fortran and C. +*/ + +#include + +#ifdef PETSC_HAVE_FORTRAN_CAPS +#define petscoptionsinsertfile_yaml_ PETSCOPTIONSINSERTFILE_YAML +#elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE) +#define petscoptionsinsertfile_yaml_ petscoptionsinsertfile_yaml +#endif + +EXTERN_C_BEGIN + +void PETSC_STDCALL petscoptionsinsertfile_yaml_(MPI_Fint *comm,CHAR file PETSC_MIXED_LEN(len),PetscBool *require,PetscErrorCode *ierr PETSC_END_LEN(len)) +{ + char *c1; + + FIXCHAR(file,len,c1); + *ierr = PetscOptionsInsertFile_YAML(MPI_Comm_f2c(*comm),c1,*require); + FREECHAR(file,c1); +} + +EXTERN_C_END diff -r 93f374d090c4 src/sys/yaml/makefile --- a/src/sys/yaml/makefile Sat Jul 28 11:35:56 2012 -0500 +++ b/src/sys/yaml/makefile Mon Jul 30 15:35:58 2012 -0500 @@ -2,7 +2,7 @@ #requirespackage 'PETSC_HAVE_YAML' ALL: lib -SOURCEH = yamlimpls.h +SOURCEH = SOURCEC = yamlimpls.c OBJSC = yamlimpls.o DIRS = diff -r 93f374d090c4 src/sys/yaml/yamlimpls.c --- a/src/sys/yaml/yamlimpls.c Sat Jul 28 11:35:56 2012 -0500 +++ b/src/sys/yaml/yamlimpls.c Mon Jul 30 15:35:58 2012 -0500 @@ -1,780 +1,131 @@ -#include "yamlimpls.h" +#include /*I "petscsys.h" I*/ +#include -void options_list_delete(options_list_t *options_list) { - int i, j; +enum storage_flags {VAR,VAL,SEQ}; /* "Store as" switch */ - for(i=0; i<(*options_list).count; i++) - { - for(j=0; j<(*options_list).options[i].arguments.count; j++) { - if((*options_list).options[i].arguments.args[j]) { - free((*options_list).options[i].arguments.args[j]); +#undef __FUNCT__ +#define __FUNCT__ "PetscParseLayerYAML" +PetscErrorCode PetscParseLayerYAML(yaml_parser_t *parser,int *lvl) +{ + yaml_event_t event; + int storage = VAR; /* mapping cannot start with VAL definition w/o VAR key */ + char key[PETSC_MAX_PATH_LEN],option[PETSC_MAX_PATH_LEN],prefix[PETSC_MAX_PATH_LEN]; + PetscBool down = PETSC_FALSE; + PetscErrorCode ierr; + + PetscFunctionBegin; + ierr = PetscSNPrintf(option,PETSC_MAX_PATH_LEN,"%s"," ");CHKERRQ(ierr); + while (1) { + yaml_parser_parse(parser,&event); + /* Parse value either as a new leaf in the mapping */ + /* or as a leaf value (one of them, in case it's a sequence) */ + if (event.type == YAML_SCALAR_EVENT) { + if (storage) { + ierr = PetscSNPrintf(option,PETSC_MAX_PATH_LEN,"-%s %s",key,(char *)event.data.scalar.value);CHKERRQ(ierr); + ierr = PetscOptionsInsertString(option);CHKERRQ(ierr); + } else { + ierr = PetscStrncpy(key,(char *)event.data.scalar.value,event.data.scalar.length+1);CHKERRQ(ierr); } - } - if((*options_list).options[i].arguments.args) { - free((*options_list).options[i].arguments.args); - } - if((*options_list).options[i].name) { - free((*options_list).options[i].name); - } - if((*options_list).options[i].group) { - free((*options_list).options[i].group); - } - } - if((*options_list).options) { - free((*options_list).options); - } -} - -int options_list_populate_yaml(char *str, options_list_t *options_list) { - yaml_parser_t parser; - yaml_event_t event, *events=0; - int i, j, k, ii; /* generic counters */ - int alias_count, events_length, sequence_stack, mapping_stack, mapping_end_index;; /* named counters */ - alias_list_t list; - grouping_stack_t grouping_stack; - const int MAX_NESTED_GROUPS = 10; - /* This can be edited later as needed, this is for memory allocation purposes for the grouping_stack */ - - /* Initialize objects and check for errors. */ - if (!yaml_parser_initialize(&parser)) { - fprintf(stderr, "Failed to initialize parser. (%s:%d)\n", __FILE__, __LINE__-1); - return 0; - } - yaml_parser_set_input_string(&parser, (unsigned char*) str, strlen(str)); - - /* Counting things for memory allocation purposes */ - if(!yaml_parser_parse(&parser, &event)) { - fprintf(stderr, "Parser error. (%s:%d)", __FILE__, __LINE__-1); - return 0; - } - i=0; - while(event.type != YAML_STREAM_END_EVENT) { - if(event.type == YAML_DOCUMENT_START_EVENT) { - yaml_event_delete(&event); - if(!yaml_parser_parse(&parser, &event)) { - fprintf(stderr, "Parser error. (%s:%d)", __FILE__, __LINE__-1); - return 0; + storage ^= VAL; /* Flip VAR/VAL switch for the next event */ + } else if (event.type == YAML_SEQUENCE_START_EVENT) { + /* Sequence - all the following scalars will be appended to the last_leaf */ + storage = SEQ; + SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP ,"Sequences not supported"); + } else if (event.type == YAML_SEQUENCE_END_EVENT) { + storage = VAR; + } else if (event.type == YAML_MAPPING_START_EVENT) { + ierr = PetscSNPrintf(prefix,PETSC_MAX_PATH_LEN,"%s_",key);CHKERRQ(ierr); + if (*lvl > 0) { + ierr = PetscOptionsPrefixPush(prefix);CHKERRQ(ierr); } - if(event.type == YAML_MAPPING_START_EVENT) { - yaml_event_delete(&event); - if(!yaml_parser_parse(&parser, &event)) { - fprintf(stderr, "Parser error. (%s:%d)", __FILE__, __LINE__-1); - return 0; - } - if(event.type == YAML_SCALAR_EVENT) { - if(strcmp((char*) event.data.scalar.value, "Options") == 0 - || strcmp((char*) event.data.scalar.value, "options") == 0) { - i=3;alias_count=0; - while(event.type != YAML_DOCUMENT_END_EVENT) { - yaml_event_delete(&event); - if(!yaml_parser_parse(&parser, &event)) { - fprintf(stderr, "Parser error. (%s:%d)", __FILE__, __LINE__-1); - return 0; - } - i++; - } - } - } + (*lvl)++; + ierr = PetscParseLayerYAML(parser,lvl);CHKERRQ(ierr); + (*lvl)--; + if (*lvl > 0) { + ierr = PetscOptionsPrefixPop();CHKERRQ(ierr); } - } - yaml_event_delete(&event); - if(!yaml_parser_parse(&parser, &event)) { - fprintf(stderr, "Parser error. (%s:%d)", __FILE__, __LINE__-1); - return 0; - } - } - yaml_event_delete(&event); - yaml_parser_delete(&parser); - - /* Populating the alias list. */ - if(!alias_list_populate_yaml(str, &list)) { - fprintf(stderr, "error alias_list_populate_yaml (%s:%d)", __FILE__, __LINE__-1); - return 0; - } - - /* Allocating memory based on counts from above */ - events = (yaml_event_t*) calloc((i+1)*4, sizeof(yaml_event_t)); - /* Multiplied by four because I am not counting the alias events this needs to be worked on later */ - /* We could overallocate by a lot and realloc once we get the actual number of events in the array later */ - - /* Time to load the events to an array so I can better play with them */ - yaml_parser_initialize(&parser); - yaml_parser_set_input_string(&parser, (unsigned char*) str, strlen(str)); - if(!yaml_parser_parse(&parser, &event)) { - fprintf(stderr, "Parser error. (%s:%d)\n", __FILE__, __LINE__-1); - return 0; - } - while(event.type != YAML_STREAM_END_EVENT) { - i=0;j=0;sequence_stack=0; - if(event.type == YAML_DOCUMENT_START_EVENT) { - if(!yaml_event_initialize(&events[i], &event)) { - fprintf(stderr, "error yaml_event_initialize (%s:%d)\n",__FILE__,__LINE__-1); - return 0; - } - yaml_event_delete(&event); - if(!yaml_parser_parse(&parser, &event)) { - fprintf(stderr, "Parser error. (%s:%d)", __FILE__, __LINE__-1); - return 0; - } - i++; - if(event.type == YAML_MAPPING_START_EVENT) { - if(!yaml_event_initialize(&events[i], &event)) { - fprintf(stderr, "error, yamL_event_initialize (%s:%d)\n", __FILE__, __LINE__); - return 0; - } - yaml_event_delete(&event); - if(!yaml_parser_parse(&parser, &event)) { - fprintf(stderr, "Parser error. (%s:%d)\n", __FILE__, __LINE__-1); - return 0; - } - i++; - if(event.type == YAML_SCALAR_EVENT) { - if(!yaml_event_initialize(&events[i], &event)) { - fprintf(stderr, "error yaml_event_initialize (%s:%d)\n", __FILE__, __LINE__-1); - return 0; - } - i++; - if(strcmp((char*) event.data.scalar.value, "options") == 0 - || strcmp((char*) event.data.scalar.value, "Options") == 0) { - yaml_event_delete(&event); - if(!yaml_parser_parse(&parser, &event)) { - fprintf(stderr, "Parser error. (%s:%d)\n", __FILE__, __LINE__-1); - return 0; - } - while(event.type != YAML_DOCUMENT_END_EVENT) { - switch(event.type) { - case YAML_ALIAS_EVENT: - /* Copy all of the alias event info from the alias list */ - for(j=0; j=0; i--) { - yaml_event_delete(&events[i]); - } - } - } else { - for(i--; i>=0; i--) { - yaml_event_delete(&events[i]); - } - } - } else { - for(i--; i>=0; i--) { - yaml_event_delete(&events[i]); - } - } - } - yaml_event_delete(&event); - if(!yaml_parser_parse(&parser, &event)) { - fprintf(stderr, "Parser error. (%s:%d)", __FILE__, __LINE__-1); - return 0; - } - } - yaml_event_delete(&event); - yaml_parser_delete(&parser); - alias_list_delete(&list); - - /* Making sure the last block of code ran properly and my config file was written properly */ - if(events[0].type != YAML_DOCUMENT_START_EVENT - || events[1].type != YAML_MAPPING_START_EVENT - || events[2].type != YAML_SCALAR_EVENT - ||(strcmp((char*) events[2].data.scalar.value, "options") != 0 - && strcmp((char*) events[2].data.scalar.value, "Options") != 0) - || events[3].type != YAML_SEQUENCE_START_EVENT) { - fprintf(stderr, "Events did not load properly. (%s:%d)\n", __FILE__, __LINE__); - return 0; - } - for(i=0; i -#include - -/* The option structure */ -typedef struct option_s { - /* The option name */ - char *name; - /* The group the option is in. Defaults to default */ - char *group; - struct { - /* The array of strings containing the arguments */ - char **args; - /* The number of arguments in the list */ - int count; - } arguments; -} option_t; - -/* The options_list structure */ -typedef struct options_list_s { - /* The array containing the options */ - option_t *options; - /* The length of the options list */ - int count; -} options_list_t; - -/** - * This is a generic function to call on the proper function to populate an options list. - * - * The application is responsible for freeing any buffers associated with the produced - * options_list object using the options_list_delete function. - * - * @param[in] filename A string containing the filename - * @param[out] options_list An empty options_list_t object. - * - * returns 1 if the function succeeded, 0 on error. - */ -int -options_list_populate(char *filename, options_list_t *options_list); - -/** - * Reads a YAML file from a string and produces an options_list. - * - * The application is responsible for freeing any buffers assiciated with the produced - * options_list object using the options_list_delete function. - * - * @param[in] str A string containing the YAML file. - * @param[out] options_list An empty options_list object. - * - * returns 1 if the function succeeded, 0 on error. - */ -int -options_list_populate_yaml(char *str, options_list_t *options_list); - -/** - * Destroy an options_list - * - * @param[in,out] options_list An options_list object. - */ -void -options_list_delete(options_list_t *options_list); - -/** - * Reads data from a file and copies it to a string. - * - * The application is responsible for freeing the str buffer. - * - * @param[in] filename The name of the file to be read to string. - * @param[out] str The address of a NULL char* object. - * - * returns 1 on success, 0 on error. - */ -PetscErrorCode -file_to_string(char *filename, char **str); - -/* The grouping_stack_group structure */ -typedef struct grouping_stack_group_s { - /* The name of the group */ - char *name; - /* The event index the group starts at */ - int start; - /* The event index the group ends at */ - int end; -} grouping_stack_group_t; - -/* The grouping_stack structure */ -typedef struct grouping_stack_s { - /* The array of groups in the stack */ - grouping_stack_group_t *groups; - /* The number of elements in the string array */ - int count; -} grouping_stack_t; - -/* The alias_key_value structure */ -typedef struct alias_key_value_s { - /* The string containing the alias name */ - char *alias; - /* The YAML event corresponding with the name */ - yaml_event_t event; -} alias_key_value_t; - -/* The alias_list structure */ -typedef struct alias_list_s { - /* The length of the list */ - int count; - /* The list itself */ - alias_key_value_t *list; -} alias_list_t; - -/** - * Generic copy constructor for a YAML event. - * - * @param[out] out An uninitialized yaml_event_t object. - * @param[in] in The yaml_event_t object to copy. - * - * returns 1 if the function succeeded, 0 on error. - */ -int -yaml_event_initialize(yaml_event_t *out, yaml_event_t *in); - -/** - * Populates a list of alias information from parsing a yaml file. - * This is only called on by the options_list_populate_yaml function. - * - * The application is responsible for freeing any buffers associated - * with the alias_list_t object by use of the alias_list_delete() function. - * - * @param[in] str A string containing the YAML document to be read. - * @param[out] list An empty alias_list_t object. - * - * returns 1 on success. - */ -int -alias_list_populate_yaml(char *str, alias_list_t *list); - -/** - * Destroy an alias_list_t object. - * - * @param[in,out] list An alias_list_t object. - */ -void -alias_list_delete(alias_list_t *list);