From aa0f3ae2988d372b190b9bde2e75a6d17e744e93 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Sun, 14 Jun 2015 00:52:45 +0000 Subject: Initial commit --- src/parse_file.c | 796 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 796 insertions(+) create mode 100644 src/parse_file.c (limited to 'src/parse_file.c') diff --git a/src/parse_file.c b/src/parse_file.c new file mode 100644 index 0000000..6054372 --- /dev/null +++ b/src/parse_file.c @@ -0,0 +1,796 @@ +/* +Copyright 2015 Ian Jauslin + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include "parse_file.h" + +#include +#include +#include "array.h" +#include "fields.h" +#include "rational.h" +#include "number.h" +#include "polynomial.h" +#include "rcc.h" +#include "definitions.cpp" +#include "istring.h" +#include "tools.h" +#include "idtable.h" + + +// parsing modes +#define PP_NULL_MODE 0 +// when reading a factor +#define PP_FACTOR_MODE 1 +// reading a monomial +#define PP_MONOMIAL_MODE 2 +// reading a numerator and denominator +#define PP_NUMBER_MODE 3 +// types of fields +#define PP_FIELD_MODE 6 +#define PP_PARAMETER_MODE 7 +#define PP_EXTERNAL_MODE 8 +#define PP_INTERNAL_MODE 9 +#define PP_FERMIONS_MODE 10 +// indices +#define PP_INDEX_MODE 11 +// factors or monomials +#define PP_BRACKET_MODE 12 +// labels +#define PP_LABEL_MODE 13 +// polynomial +#define PP_POLYNOMIAL_MODE 14 +// group +#define PP_GROUP_MODE 15 + + +// parse fields list +int parse_input_fields(Char_Array str_fields, Fields_Table* fields){ + // buffer + char* buffer=calloc(str_fields.length+1,sizeof(char)); + char* buffer_ptr=buffer; + int i,j; + int mode; + int comment=0; + + // allocate memory + init_Fields_Table(fields); + + // loop over input + mode=PP_NULL_MODE; + for(j=0;j0){ + str_to_Polynomial(buffer, &polynomial); + symbols_append_noinit(index, polynomial, &((*fields).symbols)); + } + + // simplify + for(i=0;i<(*fields).symbols.length;i++){ + polynomial_simplify((*fields).symbols.expr+i, *fields); + } + + free(buffer); + return(0); +} + +// parse groups of independent fields +int parse_input_groups(Char_Array str_groups, Groups* groups){ + // buffer + char* buffer=calloc(str_groups.length+1,sizeof(char)); + char* buffer_ptr=buffer; + int index; + int j; + Int_Array group; + int mode; + int comment=0; + + // alloc + init_Groups(groups, GROUP_SIZE); + + // loop over input + mode=PP_NULL_MODE; + for(j=0;j=0 && index2>=0){ + free_Polynomial((*propagator).matrix[index1][index2]); + str_to_Polynomial(buffer,(*propagator).matrix[index1]+index2); + buffer_ptr=buffer; + *buffer_ptr='\0'; + mode=PP_INDEX_MODE; + } + break; + + // comment + case '#': + comment=1; + break; + + default: + buffer_ptr=str_addchar(buffer_ptr,str_propagator.str[j]); + break; + } + } + } + + // last step + if(mode==PP_POLYNOMIAL_MODE){ + free_Polynomial((*propagator).matrix[index1][index2]); + str_to_Polynomial(buffer,(*propagator).matrix[index1]+index2); + } + + free(buffer); + return(0); +} + + +// parse input polynomial +int parse_input_polynomial(Char_Array str_polynomial, Polynomial* output, Fields_Table fields){ + int j; + // buffer + char* buffer=calloc(str_polynomial.length+1,sizeof(char)); + char* buffer_ptr=buffer; + Polynomial tmp_poly; + + // allocate memory + init_Polynomial(output,POLY_SIZE); + + for(j=0;j-DOFFSET){ + (*init).values[i]=1.; + } + else{ + (*init).values[i]=0.; + } + + } + return(0); +} -- cgit v1.2.3-70-g09d2