Rename read_u/write_u to read_vec/write_vec

This commit is contained in:
Ian Jauslin 2023-04-24 12:12:20 -04:00
parent 23e61c143a
commit 2b1b66f8f1
4 changed files with 35 additions and 35 deletions

View File

@ -89,7 +89,7 @@ int init_file_txt (
int K2, int K2,
FILE* initfile FILE* initfile
){ ){
read_u(u0, K1, K2, initfile); read_vec(u0, K1, K2, initfile);
return 0; return 0;
} }
// binary input // binary input
@ -99,6 +99,6 @@ int init_file_bin (
int K2, int K2,
FILE* initfile FILE* initfile
){ ){
read_u_bin(u0, K1, K2, initfile); read_vec_bin(u0, K1, K2, initfile);
return 0; return 0;
} }

View File

@ -4,8 +4,8 @@
#include "io.h" #include "io.h"
#include "navier-stokes.h" #include "navier-stokes.h"
// write final entry to file // write complex vector indexed by k1,k2 to file
int write_u(_Complex double* u, int K1, int K2, FILE* file){ int write_vec(_Complex double* vec, int K1, int K2, FILE* file){
int kx,ky; int kx,ky;
// do nothing if there is no file // do nothing if there is no file
@ -15,15 +15,27 @@ int write_u(_Complex double* u, int K1, int K2, FILE* file){
for(kx=0;kx<=K1;kx++){ for(kx=0;kx<=K1;kx++){
for (ky=-K2;ky<=K2;ky++){ for (ky=-K2;ky<=K2;ky++){
fprintf(file,"% 3d % 3d % .15e % .15e\n",kx,ky,__real__ u[klookup_sym(kx,ky,K2)],__imag__ u[klookup_sym(kx,ky,K2)]); fprintf(file,"% 3d % 3d % .15e % .15e\n",kx,ky,__real__ vec[klookup_sym(kx,ky,K2)],__imag__ vec[klookup_sym(kx,ky,K2)]);
} }
} }
return 0; return 0;
} }
// read u from file // write complex vector indexed by k1,k2 to file in binary format
int read_u(_Complex double* u, int K1, int K2, FILE* file){ int write_vec_bin(_Complex double* vec, int K1, int K2, FILE* file){
// do nothing if there is no file
if(file==NULL){
return 0;
}
fwrite(vec, sizeof(_Complex double), (K1+1)*(2*K2+1), file);
return 0;
}
// read complex vector indexed by k1,k2 from file
int read_vec(_Complex double* out, int K1, int K2, FILE* file){
int kx,ky; int kx,ky;
double r,i; double r,i;
char* line; char* line;
@ -37,7 +49,7 @@ int read_u(_Complex double* u, int K1, int K2, FILE* file){
// error if there is no file (this should not happen) // error if there is no file (this should not happen)
if (file==NULL){ if (file==NULL){
fprintf(stderr,"error reading u from file (this is a bug!)\n"); fprintf(stderr,"error reading input from file (this is a bug, contact Ian at ian.jauslin@rutgers.edu!)\n");
return -1; return -1;
} }
@ -74,8 +86,8 @@ int read_u(_Complex double* u, int K1, int K2, FILE* file){
fprintf(stderr, "warning: reading line %d: kx should be >=0, skipping\n", counter); fprintf(stderr, "warning: reading line %d: kx should be >=0, skipping\n", counter);
} }
else{ else{
// set u // set output
u[klookup_sym(kx, ky, K2)]=r+i*I; out[klookup_sym(kx, ky, K2)]=r+i*I;
} }
} }
} }
@ -115,20 +127,8 @@ int read_u(_Complex double* u, int K1, int K2, FILE* file){
return 0; return 0;
} }
// write final entry to file in binary format // read complex vector indexed by k1,k2 from file in binary format
int write_u_bin(_Complex double* u, int K1, int K2, FILE* file){ int read_vec_bin(_Complex double* out, 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; char c;
int ret; int ret;
@ -164,7 +164,7 @@ int read_u_bin(_Complex double* u, int K1, int K2, FILE* file){
} }
} }
fread(u, sizeof(_Complex double), (K1+1)*(2*K2+1), file); fread(out, sizeof(_Complex double), (K1+1)*(2*K2+1), file);
return 0; return 0;
} }

View File

@ -3,13 +3,13 @@
#include <stdio.h> #include <stdio.h>
// write u to file // write complex vector indexed by k1,k2 to file
int write_u(_Complex double* u, int K1, int K2, FILE* file); int write_vec(_Complex double* u, int K1, int K2, FILE* file);
int write_u_bin(_Complex double* u, int K1, int K2, FILE* file); int write_vec_bin(_Complex double* u, int K1, int K2, FILE* file);
// read u from file // read complex vector indexed by k1,k2 from file
int read_u(_Complex double* u, int K1, int K2, FILE* file); int read_vec(_Complex double* u, int K1, int K2, FILE* file);
int read_u_bin(_Complex double* u, int K1, int K2, FILE* file); int read_vec_bin(_Complex double* u, int K1, int K2, FILE* file);
// remove an entry from params string (inplace) // remove an entry from params string (inplace)
int remove_entry(char* param_str, char* entry); int remove_entry(char* param_str, char* entry);

View File

@ -71,7 +71,7 @@ int uk(
} }
// save final entry to savefile // save final entry to savefile
write_u_bin(u, K1, K2, savefile); write_vec_bin(u, K1, K2, savefile);
ns_free_tmps(u, tmp1, tmp2, tmp3, fft1, fft2, ifft); ns_free_tmps(u, tmp1, tmp2, tmp3, fft1, fft2, ifft);
return(0); return(0);
@ -188,9 +188,9 @@ int eea(
// save final entry to savefile // save final entry to savefile
if(savefile==stderr || savefile==stdout){ if(savefile==stderr || savefile==stdout){
write_u(u, K1, K2, savefile); write_vec(u, K1, K2, savefile);
} else { } else {
write_u_bin(u, K1, K2, savefile); write_vec_bin(u, K1, K2, savefile);
} }
ns_free_tmps(u, tmp1, tmp2, tmp3, fft1, fft2, ifft); ns_free_tmps(u, tmp1, tmp2, tmp3, fft1, fft2, ifft);
@ -233,7 +233,7 @@ int quiet(
} }
// save final entry to savefile // save final entry to savefile
write_u(u, K1, K2, savefile); write_vec(u, K1, K2, savefile);
ns_free_tmps(u, tmp1, tmp2, tmp3, fft1, fft2, ifft); ns_free_tmps(u, tmp1, tmp2, tmp3, fft1, fft2, ifft);
return(0); return(0);