/* 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 #include "array.h" #include "fields.h" #include "rational.h" #include "number.h" #include "polynomial.h" #include "rcc.h" #include "rcc_mpfr.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 #define PP_NONCOMMUTING_MODE 11 // indices #define PP_INDEX_MODE 12 // factors or monomials #define PP_BRACKET_MODE 13 // labels #define PP_LABEL_MODE 14 // polynomial #define PP_POLYNOMIAL_MODE 15 // group #define PP_GROUP_MODE 16 // 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); } // set indices and length of init for RCC_mpfr int prepare_init_mpfr(int* indices, int length, RCC_mpfr* init){ int i; init_RCC_mpfr(init, length); for(i=0;i-DOFFSET){ mpfr_set_ui((*init).values[i],1,MPFR_RNDN); } else{ mpfr_set_zero((*init).values[i],1); } } return(0); }