Skip to content

Commit

Permalink
Added scaling to cubedenstats.f90 to prevent FP overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
will-henney committed Nov 18, 2010
1 parent 5820b1b commit 2e817f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -17,3 +17,5 @@
/phabrebin
/rotatetest
/turbstats
/cubeextras
/cubet
11 changes: 11 additions & 0 deletions cubedenstats.f90
Expand Up @@ -79,6 +79,8 @@ program cubedenstats
dmean_tot = sum(d)/real(nx*ny*nz, dp)
d2mean_tot = sum(d*d)/real(nx*ny*nz, dp)

d = d / dmean_tot ! rescale density to prevent overflow

! version 2: weight by the ion fraction
dmean_m = sum(d*wm)/sum(wm)
dmean_n = sum(d*wn)/sum(wn)
Expand All @@ -92,6 +94,15 @@ program cubedenstats
! mean of density-cubed - only for ionized gas
d3mean_i = sum(d*d*d*wi, mask=m)/sum(wi, mask=m)

! put scaling back in
dmean_m = dmean_m * dmean_tot
dmean_n = dmean_n * dmean_tot
dmean_i = dmean_i * dmean_tot
d2mean_m = d2mean_m * dmean_tot * dmean_tot
d2mean_n = d2mean_n * dmean_tot * dmean_tot
d2mean_i = d2mean_i * dmean_tot * dmean_tot
d3mean_i = d3mean_i * dmean_tot * dmean_tot * dmean_tot

if (mod(it,10)==0) print *, 'Done timestep: ', it

write(1, '(i4.4,"'//TAB//'",9(es11.3,"'//TAB//'")))') it, &
Expand Down

0 comments on commit 2e817f9

Please sign in to comment.