save_state to its own function
This commit is contained in:
@@ -149,10 +149,10 @@ int enstrophy(
|
||||
FILE* savefile,
|
||||
FILE* utfile,
|
||||
// for interrupt recovery
|
||||
char* cmd_string,
|
||||
char* params_string,
|
||||
char* savefile_string,
|
||||
char* utfile_string
|
||||
const char* cmd_string,
|
||||
const char* params_string,
|
||||
const char* savefile_string,
|
||||
const char* utfile_string
|
||||
){
|
||||
_Complex double* u;
|
||||
_Complex double* tmp1;
|
||||
@@ -248,57 +248,7 @@ int enstrophy(
|
||||
}
|
||||
|
||||
if(savefile!=NULL){
|
||||
fprintf(savefile,"# Continue computation with\n");
|
||||
|
||||
// command to resume
|
||||
fprintf(savefile,"#! ");
|
||||
fprintf(savefile, cmd_string);
|
||||
// params
|
||||
// allocate buffer for params
|
||||
if(params_string!=NULL) {
|
||||
char* params=calloc(sizeof(char), strlen(params_string)+1);
|
||||
strcpy(params, params_string);
|
||||
remove_entry(params, "starting_time");
|
||||
remove_entry(params, "init");
|
||||
if(algorithm>ALGORITHM_ADAPTIVE_THRESHOLD){
|
||||
remove_entry(params, "delta");
|
||||
}
|
||||
fprintf(savefile," -p \"%s;init=file:%s", params, savefile_string);
|
||||
free(params);
|
||||
// write delta if adaptive, and not writing binary
|
||||
if(algorithm>ALGORITHM_ADAPTIVE_THRESHOLD && (savefile==stderr || savefile==stdout)){
|
||||
fprintf(savefile,";delta=%.15e", step);
|
||||
}
|
||||
// write starting_time if not writing binary
|
||||
if(savefile==stderr || savefile==stdout){
|
||||
fprintf(savefile,";starting_time=%.15e", time);
|
||||
}
|
||||
fprintf(savefile,"\"");
|
||||
}
|
||||
|
||||
// utfile
|
||||
if(utfile!=NULL){
|
||||
fprintf(savefile," -u \"%s\"", utfile_string);
|
||||
}
|
||||
// threads
|
||||
if(nthreads!=1){
|
||||
fprintf(savefile," -t %d", nthreads);
|
||||
}
|
||||
|
||||
fprintf(savefile," enstrophy\n");
|
||||
|
||||
// save final u to savefile
|
||||
if(savefile==stderr || savefile==stdout){
|
||||
write_vec(u, K1, K2, savefile);
|
||||
} else {
|
||||
write_vec_bin(u, K1, K2, savefile);
|
||||
// last binary entry: starting time
|
||||
fwrite(&time, sizeof(double), 1, savefile);
|
||||
// extra binary data for adaptive algorithm
|
||||
if(algorithm>ALGORITHM_ADAPTIVE_THRESHOLD){
|
||||
fwrite(&step, sizeof(double), 1, savefile);
|
||||
}
|
||||
}
|
||||
save_state(u, savefile, K1, K2, cmd_string, params_string, savefile_string, utfile_string, utfile, COMMAND_ENSTROPHY, algorithm, step, time, nthreads);
|
||||
}
|
||||
|
||||
// save final u to utfile in txt format
|
||||
|
||||
Reference in New Issue
Block a user