| misc.c (3568c3e82964a3def751ac86e46777809ee904c5) | misc.c (38690fecfcf11bfdf51c3082dadeac248fcdcecf) |
|---|---|
| 1// Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 2// All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3// 4// SPDX-License-Identifier: BSD-2-Clause 5// 6// This file is part of CEED: http://github.com/ceed 7 8/// @file --- 327 unchanged lines hidden (view full) --- 336 PetscCall(PhastaDatFileOpen(comm, path, char_array_len, dims, &fp)); 337 *nrows = dims[0]; 338 PetscCall(PetscFClose(comm, fp)); 339 PetscFunctionReturn(PETSC_SUCCESS); 340} 341 342PetscErrorCode PhastaDatFileReadToArrayReal(MPI_Comm comm, const char path[PETSC_MAX_PATH_LEN], PetscReal array[]) { 343 PetscInt dims[2]; | 1// Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 2// All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3// 4// SPDX-License-Identifier: BSD-2-Clause 5// 6// This file is part of CEED: http://github.com/ceed 7 8/// @file --- 327 unchanged lines hidden (view full) --- 336 PetscCall(PhastaDatFileOpen(comm, path, char_array_len, dims, &fp)); 337 *nrows = dims[0]; 338 PetscCall(PetscFClose(comm, fp)); 339 PetscFunctionReturn(PETSC_SUCCESS); 340} 341 342PetscErrorCode PhastaDatFileReadToArrayReal(MPI_Comm comm, const char path[PETSC_MAX_PATH_LEN], PetscReal array[]) { 343 PetscInt dims[2]; |
| 344 int ndims; | |
| 345 FILE *fp; 346 const PetscInt char_array_len = 512; 347 char line[char_array_len]; | 344 FILE *fp; 345 const PetscInt char_array_len = 512; 346 char line[char_array_len]; |
| 348 char **row_array; | |
| 349 350 PetscFunctionBeginUser; 351 PetscCall(PhastaDatFileOpen(comm, path, char_array_len, dims, &fp)); 352 353 for (PetscInt i = 0; i < dims[0]; i++) { | 347 348 PetscFunctionBeginUser; 349 PetscCall(PhastaDatFileOpen(comm, path, char_array_len, dims, &fp)); 350 351 for (PetscInt i = 0; i < dims[0]; i++) { |
| 352 int ndims; 353 char **row_array; 354 |
|
| 354 PetscCall(PetscSynchronizedFGets(comm, fp, char_array_len, line)); 355 PetscCall(PetscStrToArray(line, ' ', &ndims, &row_array)); 356 PetscCheck(ndims == dims[1], comm, PETSC_ERR_FILE_UNEXPECTED, 357 "Line %" PetscInt_FMT " of %s does not contain enough columns (%d instead of %" PetscInt_FMT ")", i, path, ndims, dims[1]); 358 | 355 PetscCall(PetscSynchronizedFGets(comm, fp, char_array_len, line)); 356 PetscCall(PetscStrToArray(line, ' ', &ndims, &row_array)); 357 PetscCheck(ndims == dims[1], comm, PETSC_ERR_FILE_UNEXPECTED, 358 "Line %" PetscInt_FMT " of %s does not contain enough columns (%d instead of %" PetscInt_FMT ")", i, path, ndims, dims[1]); 359 |
| 359 for (PetscInt j = 0; j < dims[1]; j++) { 360 array[i * dims[1] + j] = (PetscReal)atof(row_array[j]); 361 } | 360 for (PetscInt j = 0; j < dims[1]; j++) array[i * dims[1] + j] = (PetscReal)atof(row_array[j]); 361 PetscCall(PetscStrToArrayDestroy(ndims, row_array)); |
| 362 } 363 364 PetscCall(PetscFClose(comm, fp)); 365 PetscFunctionReturn(PETSC_SUCCESS); 366} 367 368// Print information about the given simulation run 369PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData problem, TS ts) { --- 196 unchanged lines hidden --- | 362 } 363 364 PetscCall(PetscFClose(comm, fp)); 365 PetscFunctionReturn(PETSC_SUCCESS); 366} 367 368// Print information about the given simulation run 369PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData problem, TS ts) { --- 196 unchanged lines hidden --- |