Skip to content

Commit

Permalink
fix bugs in fortranio
Browse files Browse the repository at this point in the history
  • Loading branch information
nqdu committed Apr 21, 2024
1 parent bfc428f commit 9b67830
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
11 changes: 5 additions & 6 deletions coupling_specfem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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()

Expand Down
20 changes: 1 addition & 19 deletions transpose_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 9b67830

Please sign in to comment.