Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compressed state option for MITgcm_ocean NBLING #455

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
d67b475
Initial commit of the adaptive close_state_caching
Jun 6, 2022
874cf22
Comment out the close_state_cach = .false. in get_close_state_cached
Jun 6, 2022
0428283
Add do_output for the print statements
Jun 10, 2022
774b9cc
New I/O scheme with offline processing of large input state
Jul 8, 2022
5a8b812
Merge branch 'main' into netcdf-reduce
hkershaw-brown Aug 16, 2022
7d5867f
moved dart_nc_reduce one directory up to compile
hkershaw-brown Aug 16, 2022
d376f80
grid size is harded coded - change to small case
hkershaw-brown Aug 17, 2022
869d89d
using dart netcdf utilites and types modules
hkershaw-brown Aug 17, 2022
fbbb201
mirror of dart_nc_reduce. untested.
hkershaw-brown Aug 18, 2022
b14007d
ZC is double - check dart_nc_reduce
hkershaw-brown Aug 19, 2022
d9e2979
zc double dart_nc_expand
hkershaw-brown Aug 22, 2022
d197e63
netcdf and model_mod_check for comparision with main
hkershaw-brown Aug 22, 2022
e9273c8
Merge branch 'main' into netcdf-reduce
hkershaw-brown Aug 22, 2022
a409ff4
function for defining variables mit2dart
hkershaw-brown Aug 25, 2022
3d0c053
function for dart to mit. untested.
hkershaw-brown Aug 25, 2022
e007252
bug-fix: returns need to be inside if statement
hkershaw-brown Aug 26, 2022
fba76b4
bitwise mit_to_dart non-compressed with main, log and nolog
hkershaw-brown Aug 26, 2022
951235c
bitwise with main dart_to_mit, no compression
hkershaw-brown Aug 26, 2022
60c742c
size of compressed variables
hkershaw-brown Aug 26, 2022
8b556ba
partway through compressed write, I think separate writes for 2d vs
hkershaw-brown Aug 29, 2022
b239419
write compressed. untested. missing coord
hkershaw-brown Aug 29, 2022
1a7bf39
note on delX,Y - does delX,Y vary?
hkershaw-brown Aug 30, 2022
d4c3905
record indices for X,Y,Z
hkershaw-brown Aug 31, 2022
39568db
compressing out vals=0.0
hkershaw-brown Aug 31, 2022
329cd42
replace hardcoded 0.0_r8 with binary_fill variable
hkershaw-brown Aug 31, 2022
6fbbdf0
somthing funky with ETA
hkershaw-brown Sep 1, 2022
a7d60db
bug-fix: 2D ETA variable is th k=1 slice
hkershaw-brown Sep 1, 2022
0c2c781
revert assim_tools_mod to main
hkershaw-brown Sep 2, 2022
80e22dc
move initializing to fill outside read_compressed
hkershaw-brown Sep 2, 2022
0a30429
Merge branch 'main' into netcdf-reduce
hkershaw-brown Sep 16, 2022
3d1746f
bug fix: was not setting binary fill correctly for 2d
hkershaw-brown Sep 16, 2022
5709e68
Merge branch 'main' into netcdf-reduce
hkershaw-brown Sep 19, 2022
9951fd8
removed dart_nc_reduce/expand as these functions are now part of mit_…
hkershaw-brown Sep 19, 2022
720f763
revert mpas input.nml to main
hkershaw-brown Sep 19, 2022
b2b218d
remove whitespace only differences
hkershaw-brown Sep 19, 2022
1e7e186
get_state_meta data and get_val
hkershaw-brown Sep 19, 2022
25769ca
compressed lon,lat is r4. compressed depth r8
hkershaw-brown Sep 19, 2022
3e92f58
note on perturbing compressed vs non-compressed state
hkershaw-brown Sep 19, 2022
43e74ca
bug-fix: masked initialized to false for compresed and not compressed
hkershaw-brown Sep 23, 2022
e641695
style: switch tabs for spaces
hkershaw-brown Sep 23, 2022
32df048
2d and staggered variables are incorrect
hkershaw-brown Sep 23, 2022
12fa6c0
Merge branch 'main' into netcdf-reduce
hkershaw-brown Sep 23, 2022
8dcb481
fix: depth dimension first in compression so 2d index search is correct
hkershaw-brown Sep 30, 2022
03564a4
program to expand compressed netcdf to full X,Y,Z
hkershaw-brown Oct 3, 2022
63c19b5
recl2d and recl3d set in static_init_trans
hkershaw-brown Oct 7, 2022
d54cbfb
doc: compressed netcdf files
fnrliu Oct 7, 2022
e926fe0
Merge branch 'main' into netcdf-reduce
hkershaw-brown Oct 11, 2022
cd107d1
Option to output CHL for dart_to_mit
hkershaw-brown Oct 11, 2022
2c0b275
Merge branch 'main' into netcdf-reduce
hkershaw-brown Oct 21, 2022
5fe6781
Merge branch 'main' into netcdf-reduce
hkershaw-brown Nov 3, 2022
630b5a1
Merge branch 'main' into netcdf-reduce
hkershaw-brown Nov 9, 2022
d048a05
one place to set recl3d recl2d
hkershaw-brown Feb 9, 2023
134570b
Merge branch 'main' into netcdf-reduce
hkershaw-brown Feb 9, 2023
f0da199
Merge branch 'main' into netcdf-reduce
hkershaw-brown May 8, 2023
de015c6
Merge branch 'main' into netcdf-reduce
hkershaw-brown May 10, 2023
a2c0d26
Merge branch 'main' into netcdf-reduce
hkershaw-brown Jun 22, 2023
41b35e3
Merge branch 'main' into netcdf-reduce
hkershaw-brown Jun 27, 2023
92142d8
Merge branch 'main' into netcdf-reduce
hkershaw-brown Nov 7, 2023
e0dd62b
Merge branch 'main' into netcdf-reduce
hkershaw-brown Nov 9, 2023
e5ce225
Merge branch 'main' into netcdf-reduce
hkershaw-brown Dec 12, 2023
96770ad
Merge branch 'main' into netcdf-reduce
hkershaw-brown Jan 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,7 @@ function nc_create_file(filename, context)
character(len=*), parameter :: routine = 'nc_create_file'
integer :: ret, ncid, oldmode

ret = nf90_create(filename, NF90_CLOBBER, ncid)
ret = nf90_create(filename, ior(NF90_CLOBBER,NF90_64BIT_OFFSET), ncid)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helen you probably don't want to leave this in, see #287 for netcdf notes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need to leave this in if we want to be able to create DART files in the netCDF-4 format (with unlimited time dim), else it will throw the error message shown in #287.

But I'm not sure if including NF90_64BIT_OFFSET as an ior argument will cause DART files that are not in the netCDF-4 format to be created with incorrect formatting?

call nc_check(ret, routine, 'create '//trim(filename)//' read/write', context)

call add_fh_to_list(ncid, filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ subroutine check_meta_data( iloc )
kind_index=qty_index, &
kind_string=qty_string)

write(string1,'("index ",i11," is i,j,k",3(1x,i4)," and is in domain ",i2)') &
write(string1,'("index ",i11," is i,j,k",3(1x,i10)," and is in domain ",i2)') &
iloc, ix, iy, iz, dom_id
write(string2,'("is quantity ", I4,", ",A)') var_type, trim(qty_string)//' at location'
call write_location(0,loc,charstring=string3)
Expand Down Expand Up @@ -556,9 +556,12 @@ subroutine check_all_meta_data()
kind_string=qty_string)

! CLM has (potentially many) columns and needs i7 ish precision
write(string1,'(i11,1x,''i,j,k'',3(1x,i7),'' domain '',i2)') &
! write(string1,'(i11,1x,''i,j,k'',3(1x,i7),'' domain '',i2)') &
! iloc, ix, iy, iz, dom_id
! EL: integer to short for the new I/O method
! Change to long int to avoid problems
write(string1,'(i21,1x,''i,j,k'',3(1x,i21),'' domain '',i2)') &
iloc, ix, iy, iz, dom_id

call get_state_meta_data(iloc, loc, var_type)
metadata_qty_string = trim(get_name_for_quantity(var_type))

Expand Down
149 changes: 149 additions & 0 deletions models/MITgcm_ocean/expand_netcdf.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
! Uncompress a netcdf fil
program expand_netcdf

use netcdf_utilities_mod, only: nc_open_file_readonly, nc_get_dimension_size, &
nc_define_dimension, nc_create_file, &
nc_get_variable, nc_close_file, nc_put_variable, &
nc_define_real_variable, nc_end_define_mode, &
nc_add_attribute_to_variable

use types_mod, only : r4, MISSING_R4

use utilities_mod, only : initialize_utilities, finalize_utilities

use netcdf

implicit none

integer :: ncid, ncid_comp, dimid(1), dimlen, ret
integer :: Nx,Ny,Nz
integer :: nvars ! total number of variables in compressed file
integer :: id, n, c! loop variables
integer :: i,j,k, ncomp3d, ncomp2d
character(len=NF90_MAX_NAME) :: varname
real(r4), allocatable :: vals3d(:,:,:), vals2d(:,:), vals_comp(:)
integer, allocatable :: Xcomp_ind(:), Ycomp_ind(:), Zcomp_ind(:)

call initialize_utilities('expand_netcdf')

ncid_comp = nc_open_file_readonly('compressed.nc')
ncid = nc_create_file('expanded.nc')

! get the Nx,Ny,Nz
Nx = nc_get_dimension_size(ncid_comp, 'XC')
Ny = nc_get_dimension_size(ncid_comp, 'YC')
Nz = nc_get_dimension_size(ncid_comp, 'ZC')

! define Nx,Ny,Nz in the expanded file
call nc_define_dimension(ncid, 'X', Nx)
call nc_define_dimension(ncid, 'Y', Ny)
call nc_define_dimension(ncid, 'Z', Nz)

! get the compressed size
ncomp2d = nc_get_dimension_size(ncid_comp, 'comp2d')
ncomp3d = nc_get_dimension_size(ncid_comp, 'comp3d')

allocate(vals_comp(ncomp3d))
allocate(vals2d(Nx,Ny), vals3d(Nx,Ny,Nz))

! read in
allocate(Xcomp_ind(ncomp3d), Ycomp_ind(ncomp3d), Zcomp_ind(ncomp3d))
call nc_get_variable(ncid_comp, 'Ycomp_ind', Ycomp_ind)
call nc_get_variable(ncid_comp, 'Xcomp_ind', Xcomp_ind)
call nc_get_variable(ncid_comp, 'Zcomp_ind', Zcomp_ind)


! get the number of variables
ret = nf90_inquire(ncid_comp, nVariables=nvars)

! define variables
do id = 1, nvars
ret = nf90_inquire_variable(ncid_comp, id, varname, dimids=dimid)

! is a it a compressed state variable?
if (var_of_interest(varname)) then

! inquire dimention length (2d or 3d)
ret = nf90_inquire_dimension(ncid_comp, dimid(1), len=dimlen)

! define expanded variable
if (dimlen == ncomp3d) then
call nc_define_real_variable(ncid, varname, (/'X','Y','Z'/))
else
call nc_define_real_variable(ncid, varname, (/'X','Y'/))
endif

call nc_add_attribute_to_variable(ncid, varname, 'missing_value', MISSING_R4)

endif
enddo

call nc_end_define_mode(ncid)

! write variables
do id = 1, nvars
ret = nf90_inquire_variable(ncid_comp, id, varname, dimids=dimid)

! is a it a compressed state variable?
if (var_of_interest(varname)) then

! inquire dimention length (2d or 3d)
ret = nf90_inquire_dimension(ncid_comp, dimid(1), len=dimlen)

! read in compressed variable
if (dimlen == ncomp3d) then
call nc_get_variable(ncid_comp, varname, vals_comp)
vals3d = MISSING_R4
else
call nc_get_variable(ncid_comp, varname, vals_comp(1:ncomp2d))
vals2d = MISSING_R4
endif

! expand
c = 1
do n = 1, ncomp3d
i = Xcomp_ind(n)
j = Ycomp_ind(n)
k = Zcomp_ind(n)
if (k == 1 .and. dimlen == ncomp2d) then
vals2d(i,j) = vals_comp(c)
c = c + 1
else
vals3d(i,j,k) = vals_comp(n)
endif
enddo

! write expanded variable
if (dimlen == ncomp3d) then
call nc_put_variable(ncid, varname, vals3d)
else
call nc_put_variable(ncid, varname, vals2d)
endif

endif
enddo

call nc_close_file(ncid_comp)
call nc_close_file(ncid)

call finalize_utilities('expand_netcdf')

contains

! logical to ignore compression variables
function var_of_interest(varname)
character(len=*), intent(in) :: varname
logical :: var_of_interest

select case (varname)
case ('XGcomp', 'XCcomp', 'YGcomp', 'YCcomp', 'ZCcomp', 'Xcomp_ind', 'Ycomp_ind', 'Zcomp_ind')
var_of_interest = .false.
case ('XC', 'YC', 'ZC', 'XG', 'YG')
var_of_interest = .false.
case default
var_of_interest = .true.
end select

end function var_of_interest

end program expand_netcdf
Loading