Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse_file.c')
-rw-r--r--src/parse_file.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/parse_file.c b/src/parse_file.c
index 19b91c6..ae3a9af 100644
--- a/src/parse_file.c
+++ b/src/parse_file.c
@@ -18,12 +18,14 @@ limitations under the License.
#include <stdio.h>
#include <stdlib.h>
+#include <mpfr.h>
#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"
@@ -716,8 +718,8 @@ int parse_labels(Char_Array str_labels, Labels* labels){
}
-// read initial condition for numerical computation
-int parse_init_cd(Char_Array init_cd, RCC* init){
+// read initial condition for numerical computation (using either RCC or RCC_mpfr, as specified by mpfr_flag)
+int parse_init_cd(Char_Array init_cd, RCC* init, RCC_mpfr* init_mpfr, int mpfr_flag){
char* buffer=calloc(init_cd.length+1,sizeof(char));
char* buffer_ptr=buffer;
int index=0;
@@ -738,7 +740,12 @@ int parse_init_cd(Char_Array init_cd, RCC* init){
// new term
case ',':
// write init
- sscanf(buffer,"%Lf",(*init).values+intlist_find_err((*init).indices,(*init).length,index));
+ if(mpfr_flag==0){
+ sscanf(buffer,"%Lf",(*init).values+intlist_find_err((*init).indices,(*init).length,index));
+ }
+ else{
+ mpfr_strtofr((*init_mpfr).values[intlist_find_err((*init_mpfr).indices,(*init_mpfr).length,index)], buffer, &buffer_ptr, 10, MPFR_RNDN);
+ }
// reset buffer
buffer_ptr=buffer;
*buffer_ptr='\0';
@@ -782,7 +789,12 @@ int parse_init_cd(Char_Array init_cd, RCC* init){
}
// write init
- sscanf(buffer,"%Lf",(*init).values+unlist_find((*init).indices,(*init).length,index));
+ if(mpfr_flag==0){
+ sscanf(buffer,"%Lf",(*init).values+intlist_find_err((*init).indices,(*init).length,index));
+ }
+ else{
+ mpfr_strtofr((*init_mpfr).values[intlist_find_err((*init_mpfr).indices,(*init_mpfr).length,index)], buffer, &buffer_ptr, 10, MPFR_RNDN);
+ }
free(buffer);
return(0);
@@ -806,3 +818,20 @@ int prepare_init(int* indices, int length, RCC* init){
}
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<length;i++){
+ (*init).indices[i]=indices[i];
+ // set constants to 1
+ if(indices[i]<0 && indices[i]>-DOFFSET){
+ mpfr_set_ui((*init).values[i],1,MPFR_RNDN);
+ }
+ else{
+ mpfr_set_zero((*init).values[i],1);
+ }
+
+ }
+ return(0);
+}