Skip to content

Commit d2db495

Browse files
committed
CD: Fortran bugfix for malloc error w/ old MAS files
- instead of deallocate, use nullify to clear pointer assignment to the input python B data when adding a phi point and updating the B data in mapfl - add option in testing routine dipole_field to emulate dropping a point
1 parent 628d179 commit d2db495

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/mapfl/mapfl.f

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ module ident
4848
c
4949
c
5050
character(*), parameter :: cname='MAPFL'
51-
character(*), parameter :: cvers='2.1.0'
52-
character(*), parameter :: cdate='04/16/2024'
51+
character(*), parameter :: cvers='2.1.0_mapflpy'
52+
character(*), parameter :: cdate='02/09/2026'
5353
c
5454
end module
5555
c#######################################################################
@@ -1546,8 +1546,8 @@ subroutine set_btype (b)
15461546
f(:,:,n3+1)=b%r%f(:,:,1)
15471547
z(1:n3)=b%r%scales(3)%f(:)
15481548
z(n3+1)=b%r%scales(3)%f(1)+twopi
1549-
deallocate (b%r%f)
1550-
deallocate (b%r%scales(3)%f)
1549+
nullify (b%r%f)
1550+
nullify (b%r%scales(3)%f)
15511551
b%r%dims(3)=n3+1
15521552
b%r%f=>f
15531553
b%r%scales(3)%f=>z
@@ -1561,8 +1561,8 @@ subroutine set_btype (b)
15611561
f(:,:,n3+1)=b%t%f(:,:,1)
15621562
z(1:n3)=b%t%scales(3)%f(:)
15631563
z(n3+1)=b%t%scales(3)%f(1)+twopi
1564-
deallocate (b%t%f)
1565-
deallocate (b%t%scales(3)%f)
1564+
nullify (b%t%f)
1565+
nullify (b%t%scales(3)%f)
15661566
b%t%dims(3)=n3+1
15671567
b%t%f=>f
15681568
b%t%scales(3)%f=>z
@@ -1576,8 +1576,8 @@ subroutine set_btype (b)
15761576
f(:,:,n3+1)=b%p%f(:,:,1)
15771577
z(1:n3)=b%p%scales(3)%f(:)
15781578
z(n3+1)=b%p%scales(3)%f(1)+twopi
1579-
deallocate (b%p%f)
1580-
deallocate (b%p%scales(3)%f)
1579+
nullify (b%p%f)
1580+
nullify (b%p%scales(3)%f)
15811581
b%p%dims(3)=n3+1
15821582
b%p%f=>f
15831583
b%p%scales(3)%f=>z

tests/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def dipole_field(lon: float = 180.,
3030
r1: float = 10.0,
3131
r_resolution: int = 71,
3232
t_resolution: int = 91,
33-
p_resolution: int = 181
33+
p_resolution: int = 181,
34+
remove_phi_point: bool = False,
3435
) -> Tuple[NDArray[float], NDArray[float], NDArray[float], NDArray[float], NDArray[float], NDArray[float]]:
3536
"""Generate a 3D dipole field in spherical coordinates.
3637
@@ -54,6 +55,8 @@ def dipole_field(lon: float = 180.,
5455
number of theta points. Default is 91.
5556
p_resolution: int
5657
number of phi points. Default is 181.
58+
remove_phi_point: bool
59+
Option to delete the last phi point to emulate an "old" MAS file
5760
5861
Returns
5962
-------
@@ -107,6 +110,12 @@ def dipole_field(lon: float = 180.,
107110

108111
br, bt, bp = cvtosv(bx, by, bz, t3d, p3d)
109112

113+
if remove_phi_point:
114+
br = br[:-1,:,:]
115+
bt = bt[:-1,:,:]
116+
bp = bp[:-1,:,:]
117+
p = p[:-1]
118+
110119
return br, bt, bp, r, t, p
111120

112121

0 commit comments

Comments
 (0)