From 9b67830e430bbad8d9faf19d555223a678648dc3 Mon Sep 17 00:00:00 2001 From: nqdu Date: Sun, 21 Apr 2024 12:49:30 -0400 Subject: [PATCH] fix bugs in fortranio --- coupling_specfem.py | 11 +++++------ transpose_fields.py | 20 +------------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/coupling_specfem.py b/coupling_specfem.py index 8314082..50eda3f 100644 --- a/coupling_specfem.py +++ b/coupling_specfem.py @@ -2,7 +2,6 @@ import numpy as np import os from scipy.io import FortranFile -import h5py from mpi4py import MPI from scipy.interpolate import interp1d import sys @@ -69,8 +68,8 @@ def get_field_proc(args): f = FortranFile(outbin,'w') if npts == 0: for i in range(nt1): - f.write_record(veloc_axi[i,...],'f4') - f.write_record(trac_axi[i,...],'f4') + f.write_record(veloc_axi[i,...]) + f.write_record(trac_axi[i,...]) f.close() return 0 @@ -87,7 +86,7 @@ def get_field_proc(args): # get rotation matrix from (xyz) to (enz) R = rotation_matrix(np.deg2rad(90-stla[ir]),np.deg2rad(stlo[ir])) tmp = R[:,1] * 1. - R[:,1] = -R[:,0] * 1. # \hat{e}_n is -\hat{\theta} + R[:,1] = -R[:,0] * 1. # \hat{n}_n is -\hat{\theta} R[:,0] = tmp * 1. R = R.T @@ -119,8 +118,8 @@ def get_field_proc(args): # write file for i in range(nt1): - f.write_record(veloc_axi[i,...],'f4') - f.write_record(trac_axi[i,...],'f4') + f.write_record(veloc_axi[i,...]) + f.write_record(trac_axi[i,...]) f.close() diff --git a/transpose_fields.py b/transpose_fields.py index 594b905..0e91adb 100644 --- a/transpose_fields.py +++ b/transpose_fields.py @@ -4,25 +4,7 @@ from tqdm import tqdm import sys import os - -def allocate_task(ntasks,nprocs,myrank): - - sub_n = ntasks // nprocs - num_larger_procs = ntasks - nprocs * sub_n - starid = 0; endid = 0 - if myrank < num_larger_procs : - sub_n = sub_n + 1 - startid = 0 + myrank * sub_n - elif sub_n > 0: - startid = 0 + num_larger_procs + myrank * sub_n - else: # // this process has only zero elements - startid = -1 - sub_n = 0 - - endid = startid + sub_n - 1 - - return startid,endid - +from utils import allocate_task def write_transpose_data(file_r:h5py.File,file_w:h5py.File, dataname:str,dsetstr:str,stride=1):