From d5d5c15b7e582106b7394e492267bf4f16d4f47a Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Fri, 14 Apr 2023 15:01:52 -0400 Subject: binary io --- src/io.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c index cb14029..de52972 100644 --- a/src/io.c +++ b/src/io.c @@ -115,6 +115,60 @@ int read_u(_Complex double* u, int K1, int K2, FILE* file){ return 0; } +// write final entry to file in binary format +int write_u_bin(_Complex double* u, int K1, int K2, FILE* file){ + // do nothing if there is no file + if(file==NULL){ + return 0; + } + + fwrite(u, sizeof(_Complex double), (K1+1)*(2*K2+1), file); + + return 0; +} + +// read u from file in binary format +int read_u_bin(_Complex double* u, int K1, int K2, FILE* file){ + char c; + int ret; + + // do nothing if there is no file + if(file==NULL){ + return 0; + } + + // seek past initial comments + while(true){ + ret=fscanf(file, "%c", &c); + if (ret==1 && c=='#'){ + // find endline + while(true){ + ret=fscanf(file, "%c", &c); + // end of file + if (ret==0) { + // no data + return 0; + } + + if (c=='\n'){ + break; + } + } + } else { + if (ret==1){ + // backtrack + fseek(file, -sizeof(char), SEEK_CUR); + } + // past comments + break; + } + } + + fread(u, sizeof(_Complex double), (K1+1)*(2*K2+1), file); + + return 0; +} + // remove an entry from params string (inplace) int remove_entry( char* param_str, -- cgit v1.2.3-54-g00ecf