From 2fce5d3cc47480a7768ba3b8ce32dcd066a1178c Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 21 Nov 2024 11:20:49 -0500 Subject: [PATCH 001/124] updated ice.csv, init_mod.f90, and ocnicepost.F90 for new grib generator --- parm/ocnicepost/ice.csv | 23 ++++++++-------- src/ocnicepost.fd/init_mod.F90 | 47 ++++++++++++++++++++++++-------- src/ocnicepost.fd/ocnicepost.F90 | 43 +++++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 27 deletions(-) diff --git a/parm/ocnicepost/ice.csv b/parm/ocnicepost/ice.csv index c42ff4dc..29b2ddad 100644 --- a/parm/ocnicepost/ice.csv +++ b/parm/ocnicepost/ice.csv @@ -1,12 +1,11 @@ -! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair - 'hi_h', 2 , 'Ct', 'bilinear', '', '' - 'hs_h', 2 , 'Ct', 'bilinear', '', '' - 'aice_h', 2 , 'Ct', 'bilinear', '', '' - 'Tsfc_h', 2 , 'Ct', 'bilinear', '', '' - 'uvel_h', 2 , 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y' - 'vvel_h', 2 , 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x' - 'frzmlt_h', 2 , 'Ct', 'conserve', '', '' - 'albsni_h', 2 , 'Ct', 'bilinear', '', '' -'mlt_onset_h', 2 , 'Ct', 'bilinear', '', '' -'frz_onset_h', 2 , 'Ct', 'bilinear', '', '' - 'sst_h', 2 , 'Ct', 'bilinear', '', '' +! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,g1,g2,g3,g4,gc5,gc6,gc7,gc8 + 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,1,0,255,0,0,2,1 + 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,1,0,255,0,0,2,16 + 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,1,0,255,0,0,2,0 + 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,1,0,255,0,0,2,8 + 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,1,0,255,0,0,2,4 + 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,1,0,255,0,0,2,5 + 'frzmlt_h',2, 'Ct', 'conserve', '', '',,,,,,,,,,, + 'albsni_h',2, 'Ct', 'bilinear', '', '', 'ALBDOICE', 'Albedo', 'Numeric',10,1,0,255,0,0,2,14 +'mlt_onset_h',2, 'Ct', 'bilinear', '', '',,,,,,,,,,, +'frz_onset_h',2, 'Ct', 'bilinear', '', '',,,,,,,,,,, diff --git a/src/ocnicepost.fd/init_mod.F90 b/src/ocnicepost.fd/init_mod.F90 index 2949a088..a13de592 100644 --- a/src/ocnicepost.fd/init_mod.F90 +++ b/src/ocnicepost.fd/init_mod.F90 @@ -7,15 +7,27 @@ module init_mod real, parameter :: maxvars = 50 !< The maximum number of fields expected in a source file type :: vardefs - character(len= 20) :: var_name !< A variable's variable name - character(len=120) :: long_name !< A variable's long name - character(len= 20) :: units !< A variable's unit - character(len= 20) :: var_remapmethod !< A variable's mapping method - integer :: var_dimen !< A variable's dimensionality - character(len= 4) :: var_grid !< A variable's input grid location; all output locations are on cell centers - character(len= 20) :: var_pair !< A variable's pair - character(len= 4) :: var_pair_grid !< A pair variable grid - real :: var_fillvalue !< A variable's fillvalue + character(len= 20) :: var_name !< A variable's variable name + ! character(len=120) :: long_name !< A variable's long name + ! character(len= 20) :: units !< A variable's unit + character(len= 20) :: var_remapmethod !< A variable's mapping method + integer :: var_dimen !< A variable's dimensionality + character(len= 4) :: var_grid !< A variable's input grid location; all output locations are on cell centers + character(len= 20) :: var_pair !< A variable's pair + character(len= 4) :: var_pair_grid !< A pair variable grid + real :: var_fillvalue !< A variable's fillvalue + character(len= 20) :: var_name_gb2 !< A variable's grib2 variable name + character(len=120) :: long_name !< A variable's discription + character(len= 20) :: units !< A variable's unit + !!!may need to add a fillvalue for grib2 file + integer ::var_g1 !< Variables' grib2 coefficients g1-g8 + integer ::var_g2 + integer ::var_g3 + integer ::var_g4 + integer ::var_g5 + integer ::var_g6 + integer ::var_g7 + integer ::var_g8 end type vardefs type(vardefs) :: outvars(maxvars) !< An empty structure filled by reading a csv file describing the fields @@ -120,8 +132,8 @@ subroutine readcsv(nvalid) character(len= 40) :: fname character(len=100) :: chead - character(len= 20) :: c1,c3,c4,c5,c6 - integer :: i2 + character(len= 20) :: c1,c3,c4,c5,c6,c7,c8,c9 + integer :: i2,i10,i11,i12,i13,i14,i15,i16,i17 integer :: nn,n,ierr,iounit ! -------------------------------------------------------- @@ -138,7 +150,7 @@ subroutine readcsv(nvalid) read(iounit,*)chead nn=0 do n = 1,maxvars - read(iounit,*,iostat=ierr)c1,i2,c3,c4,c5,c6 + read(iounit,*,iostat=ierr)c1,i2,c3,c4,c5,c6,c7,c8,c9,i10,i11,i12,i13,i14,i15,i16,i17 if (ierr .ne. 0) exit if (len_trim(c1) > 0) then nn = nn+1 @@ -148,6 +160,17 @@ subroutine readcsv(nvalid) outvars(nn)%var_remapmethod = trim(c4) outvars(nn)%var_pair = trim(c5) outvars(nn)%var_pair_grid = trim(c6) + outvars(nn)%var_name_gb2 = trim(c7) + outvars(nn)%var_discription = trim(c8) + outvars(nn)%var_unit = trim(c9) + outvars(nn)%var_g1 = trim(i10) + outvars(nn)%var_g2 = trim(i11) + outvars(nn)%var_g3 = trim(i12) + outvars(nn)%var_g4 = trim(i13) + outvars(nn)%var_g5 = trim(i14) + outvars(nn)%var_g6 = trim(i15) + outvars(nn)%var_g7 = trim(i16) + outvars(nn)%var_g8 = trim(i17) end if end do close(iounit) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 975219ac..0e33dd2b 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -27,16 +27,18 @@ program ocnicepost use netcdf use init_mod , only : nxt, nyt, nlevs, nxr, nyr, outvars, readnml, readcsv use init_mod , only : wgtsdir, ftype, fsrc, fdst, input_file, cosvar, sinvar, angvar - use init_mod , only : do_ocnpost, debug, logunit + use init_mod , only : do_ocnpost, debug, logunit, grib2 + use init_mod , only : vardefs use arrays_mod , only : b2d, c2d, b3d, rgb2d, rgc2d, rgb3d, dstlon, dstlat, setup_packing use arrays_mod , only : nbilin2d, nbilin3d, nconsd2d, bilin2d, bilin3d, consd2d use masking_mod, only : mask2d, mask3d, rgmask2d, rgmask3d, remap_masks use utils_mod , only : getfield, packarrays, remap, dumpnc, nf90_err + implicit none character(len=120) :: wgtsfile - character(len=120) :: fout + character(len=120) :: fout, gout ! dimensions, units and variables from source file used in creation of ! output netcdf @@ -49,6 +51,11 @@ program ocnicepost real, allocatable, dimension(:,:) :: out2d !< 2D destination grid output array real, allocatable, dimension(:,:,:) :: out3d !< 3D destination grid output array + ! arrays for output grib2 + real, allocatable, dimension(:,:) :: grib2d !< 2D destination grib2 concat array + type(vardefs), allocatable, dimension(:) :: g2d !< concatinated variable metadata for 2D source fields remap + + real(kind=8) :: timestamp character(len= 40) :: timeunit, timecal character(len= 20) :: vname, vunit @@ -357,6 +364,7 @@ program ocnicepost call nf90_err(nf90_put_var(ncid, varid, out2d), 'put variable: '//vname) end do end if + if (allocated(rgb3d)) then do n = 1,nbilin3d out3d(:,:,:) = reshape(rgb3d(:,:,n), (/nxr,nyr,nlevs/)) @@ -369,6 +377,35 @@ program ocnicepost call nf90_err(nf90_close(ncid), 'close: '// trim(fout)) write(logunit,'(a)')trim(fout)//' done' + + if(grib2) then + gout = trim(ftype)//'.'//trim(fdst)//'.gb2' + if (debug) write(logunit, '(a)')'GRIB2 2D output file: '//trim(gout) + + if (allocated(rgb2d) .and. allocated(rgc2d)) then + grib2d(:, 1:nconsd2d) = rgc2d + grib2d(:, nconsd2d+1:nconsd2d+nbinin2d) = rgb2d + g2d(:, 1:nconsd2d) = c2d + g2d(:, nconsd2d+1:nconsd2d+nbinin2d) = b2d + else if (allocated(rgb2d)) then + grib2d(:, 1:nconsd2d) = rgc2d + g2d(:, 1:nconsd2d) = c2d + else if (allocated(rgc2d)) then + grib2d(:, 1:nbinin2d) = rgb2d + g2d(:, 1:nbinin2d) = b2d + end if + ! write 2D grib2 file + call write_grib2_2d(gout, g2d, dims=(/nxr,nyr/), nconsd2d+nbinin2d, grib2d) + + if (allocated(rgb3d)) then + gout = trim(ftype)//'.'//trim(fdst)//'_3D.gb2' + ! write 3D grib2 file + call write_grib2_3d(gout, b3d, dims=(/nxr,nyr,nlevs/),nbilin3d,rgb3d) + if (debug) write(logunit, '(a)')'GRIB2 3D output file: '//trim(gout) + end if + + end if + stop -end program ocnicepost +end program ocnicepost \ No newline at end of file From ce9825b56e37097a29a428cea489bd3580272203 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 21 Nov 2024 14:15:57 -0500 Subject: [PATCH 002/124] initial writing of grib2 capablities --- src/ocnicepost.fd/utils_mod.F90 | 200 ++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 590eec09..88f52215 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -578,6 +578,206 @@ subroutine dumpnc1d(fname, vname, dims, field) end subroutine dumpnc1d + + subroutine write_grib2_2d(fname, vars, dims, nflds, field) + + ! This subroutine will work if we have a template with all variables included + + implicit none + + character(len=*), intent(in) :: fname, fsrc ! Output GRIB2 file name and source nc file + character(len=*), intent(in) :: vname ! Variable name (metadata for identification) + integer, intent(in) :: dims(2) ! Dimensions of the field (nx, ny) + integer, intent(in) :: nflds + real, intent(in) :: field(dims(1)*dims(2),nflds) ! 2D data array + + ! GRIB2 specific variables + integer :: lunout ! Logical unit number for the GRIB2 file + integer :: ierr ! Error handling status + integer :: npt ! Total number of grid points + integer :: fortime + + ! real, allocatable :: field_1d(:) ! Flattened field data for GRIB2 compatibility + integer(4) :: max_bytes, lengrib + integer :: count, iseek ! iseek no of bytes to skip + integer, parameter :: msk1=32000 !max no. od bytes to search + + + ! GRIB2 metadata arrays + integer :: listsec0(2), listsec1(13) + integer :: igdtnum, ipdtnum, idrtnum + integer :: igdtlen, ipdtlen, idrtlen + integer, allocatable :: jgdt(:), jpdt(:), idrtmpl(:) + integer(4) :: igds(5) + integer :: numcoord, ibmap, currlen + real(4) :: coordlist + + ! Character buffer for GRIB2 message + character(1), allocatable :: cgrib(:) + + + npt = dims(1) * dims(2) + ! allocate(field_1d(npt)) + ! field_1d = reshape(field, (/npt/)) ! Flatten 2D field to 1D for GRIB2 format + + ! Allocate character buffer for GRIB2 message + max_bytes = npt * 4 ! Estimated max bytes + ! allocate(cgrib(max_bytes)) + + + icount=0 + iseek=0 + + ! Use getlun90 to get a logical unit and baopenw to open the file + call getlun90(lunout, 1) + call baopenw(lunout, trim(fname), ierr) + if (ierr /= 0) then + print *, 'Error opening template file ', trim(fname) + return + end if + + call skgb(lunout,iseek,msk1,lskip,lgrib) ! lgrib is the number of bytes in message and lskip is the no of + if (lgrib==0) exit ! end loop at EOF or problem + if (lgrib>currlen) then + if (allocated(cgrib)) deallocate(cgrib) + allocate(cgrib(lgrib),stat=ierr) + currlen=lgrib + endif + + call baread(ifl1,lskip,lgrib,lengrib,cgrib) + if (lgrib/=lengrib) then + print *,' degrib2: IO Error.' + call errexit(9) + endif + + iseek=lskip+lgrib + icount=icount+1 + PRINT * + PRINT *,'GRIB MESSAGE ',icount,' starts at',lskip+1 + PRINT * + + + call gb_info(cgrib,lengrib,listsec0,listsec1,& + nflds,numlocal,maxlocal,ierr) + if (ierr/=0) then + write(6,*) ' ERROR querying GRIB2 message = ',ierr + stop 10 + endif + + print *,' SECTION 0: ',(listsec0(j),j=1,3) + print *,' SECTION 1: ',(listsec1(j),j=1,13) + + + call retrieve_time(fsrc, time_str, fortime, ref_time_array) + + + + + + + ! Initialize GRIB2 message sections + listsec0(1) = 10 ! Discipline - GRIB Master Table Number (Code Table 0.0) + listsec0(2) = 2 ! GRIB Edition Number (currently 2) + + listsec1(1) = 7 ! Originating Centre (Common Code Table C-1) + listsec1(2) = 4 ! Originating Sub-centre (local table) + listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) + listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) + listsec1(6) = ref_time(1) ! Reference Time - Year -4digits + listsec1(7) = ref_time(2) ! Reference Time - Month + listsec1(8) = ref_time(3) ! Reference Time - Day + listsec1(9) = ref_time(4) ! Reference Time - Hour + listsec1(10) = ref_time(5) ! Reference Time - Minute + listsec1(11) = ref_time(6) ! Reference Time - Second + listsec1(12) = 0 ! Production status of data (Code Table 1.3) + listsec1(13) = 1 ! Type of processed data (Code Table 1.4) + + + + + + + do n=1,nflds + + + + ! Initialize GRIB2 message + call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) + if (ierr /= 0) then + print *, 'GRIB2 message', ierr + return + end if + + call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) + if (ierr /= 0) then + print *, 'GRIB2 message', ierr + return + end if + + + + + + + + end subroutine write_grib2_2d + + + + + + + + subroutine retrieve_time(fsrc, time_str, forecast_hour, ref_time_array) + use netcdf + implicit none + + character(len=*), intent(in) :: fsrc ! tripolar NetCDF file name + + character(len=10), intent(out) :: time_str ! Date in YYYYMMDDHH format + integer, intent(out) :: forecast_hour ! Forecast hour as an integer + integer, dimension(6), intent(out) :: ref_time_array ! Array for GRIB2 reference time: [year, month, day, hour, minute, second] + + integer :: ncid, time_varid, T1_varid, T2_varid, ierr + character(len=30) :: units_str ! Units attribute string for time + double precision :: T1, T2 ! Scalars to hold start and end time data + + integer :: ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec + integer :: year, month, day, hour + double precision :: hours_offset + + call nf90_err(nf90_open(trim(ncfile), nf90_nowrite, ncid), 'opening '//fsrc) + call nf90_err(nf90_inq_varid(ncid, 'time', time_varid), 'get variable ID: time') + call nf90_err(nf90_get_var(ncid, time_varid, forecast_hour), 'get variable time') + call nf90_err(nf90_get_att(ncid, time_varid, 'units', units_str), 'get attribute: units') + + ! Assuming format "hours since YYYY-MM-DD HH:MM:SS" + read(units_str(13:30), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & + ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec + + ! Set up ref_time_array for GRIB2 Section 1 + ref_time_array(1) = ref_year + ref_time_array(2) = ref_month + ref_time_array(3) = ref_day + ref_time_array(4) = ref_hour + ref_time_array(5) = ref_min + ref_time_array(6) = ref_sec + + call nf90_err(nf90_inq_varid(ncid, 'average_T1', T1_varid), 'get variable ID: average_T1')) + call nf90_err(nf90_get_var(ncid, T1_varid, T1), 'get variable: average_T1') + call nf90_err(nf90_inq_varid(ncid, 'average_T2', T2_varid), 'get variable ID: average_T2')) + call nf90_err(nf90_get_var(ncid, T2_varid, T2), 'get variable: average_T2') + call nf90_err(nf90_close(ncid), 'close: '//fsrc) + +! forecast_string = int(T2 - T1) +! Format the datetime in YYYYMMDDHH format + write(time_str, '(I4.4,I2.2,I2.2,I2.2)') ref_year, ref_month, ref_day, ref_hour + + + end subroutine retrieve_time + + + !---------------------------------------------------------- ! handle netcdf errors !---------------------------------------------------------- From 805974532eb4cd1db7e3eaeb5f99eb5c09155d9a Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 26 Nov 2024 13:31:55 -0500 Subject: [PATCH 003/124] updates for implimmenting grib2 writer --- parm/ocnicepost/ice.csv | 20 +-- src/ocnicepost.fd/utils_mod.F90 | 275 +++++++++++++++++++++++++++----- 2 files changed, 246 insertions(+), 49 deletions(-) diff --git a/parm/ocnicepost/ice.csv b/parm/ocnicepost/ice.csv index 29b2ddad..ee933ae2 100644 --- a/parm/ocnicepost/ice.csv +++ b/parm/ocnicepost/ice.csv @@ -1,11 +1,11 @@ ! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,g1,g2,g3,g4,gc5,gc6,gc7,gc8 - 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,1,0,255,0,0,2,1 - 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,1,0,255,0,0,2,16 - 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,1,0,255,0,0,2,0 - 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,1,0,255,0,0,2,8 - 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,1,0,255,0,0,2,4 - 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,1,0,255,0,0,2,5 - 'frzmlt_h',2, 'Ct', 'conserve', '', '',,,,,,,,,,, - 'albsni_h',2, 'Ct', 'bilinear', '', '', 'ALBDOICE', 'Albedo', 'Numeric',10,1,0,255,0,0,2,14 -'mlt_onset_h',2, 'Ct', 'bilinear', '', '',,,,,,,,,,, -'frz_onset_h',2, 'Ct', 'bilinear', '', '',,,,,,,,,,, + 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,32,0,255,0,0,2,1 + 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,32,0,255,0,0,2,16 + 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,32,0,255,0,0,2,0 + 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,32,0,255,0,0,2,8 + 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,32,0,255,0,0,2,4 + 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,32,0,255,0,0,2,5 + 'frzmlt_h',2, 'Ct', 'conserve', '', '', 'FRZMLTPOT', 'freeze/melt potential', 'W m-2',10,32,0,255,0,0,2,27 + 'albsni_h',2, 'Ct', 'bilinear', '', '', 'ALBDOICE', 'Albedo', 'Numeric',10,32,0,255,0,0,2,14 +'mlt_onset_h',2, 'Ct', 'bilinear', '', '', 'MLTDATE', 'melt onset date', 'Numeric',10,32,0,255,0,0,2,28 +'frz_onset_h',2, 'Ct', 'bilinear', '', '', 'FRZDATE', 'freeze onset date', 'Numeric',10,32,0,255,0,0,2,29 diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 88f52215..53771444 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -1,7 +1,9 @@ module utils_mod use netcdf - use init_mod, only : debug, logunit, vardefs, fsrc + use init_mod, only : debug, logunit, vardefs, fsrc, input_file + use grib_mod + implicit none @@ -579,30 +581,47 @@ subroutine dumpnc1d(fname, vname, dims, field) end subroutine dumpnc1d - subroutine write_grib2_2d(fname, vars, dims, nflds, field) + + !----------------------------------------------------------------------------------- + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Write Grib2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!This subroutine write Grib2 file modified messages!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !----------------------------------------------------------------------------------- + + subroutine write_grib2_2d(fname, g2d, dims, nflds, field) ! This subroutine will work if we have a template with all variables included implicit none - character(len=*), intent(in) :: fname, fsrc ! Output GRIB2 file name and source nc file - character(len=*), intent(in) :: vname ! Variable name (metadata for identification) + character(len=*), intent(in) :: fname ! Output GRIB2 file name and source nc file + type(vardefs), intent(in) :: g2d integer, intent(in) :: dims(2) ! Dimensions of the field (nx, ny) integer, intent(in) :: nflds real, intent(in) :: field(dims(1)*dims(2),nflds) ! 2D data array - + + integer, dimension(6), intent(out) :: ref_time ! Array for GRIB2 reference time: [year, month, day, hour, minute, second] + ! GRIB2 specific variables + type(gribfield) :: gfld integer :: lunout ! Logical unit number for the GRIB2 file integer :: ierr ! Error handling status integer :: npt ! Total number of grid points integer :: fortime + integer :: dij - ! real, allocatable :: field_1d(:) ! Flattened field data for GRIB2 compatibility integer(4) :: max_bytes, lengrib integer :: count, iseek ! iseek no of bytes to skip integer, parameter :: msk1=32000 !max no. od bytes to search - + type(gribfield) :: gfld + integer :: lunout,iseek,icount,lskip,lgrib,lengrib,ierr + integer :: nflds,numlocal,maxlocal + CHARACTER(len=1),allocatable,dimension(:) :: cgrib + integer, parameter :: msk1=32000 + logical :: unpack,expand + + ! GRIB2 metadata arrays integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum @@ -644,7 +663,7 @@ subroutine write_grib2_2d(fname, vars, dims, nflds, field) currlen=lgrib endif - call baread(ifl1,lskip,lgrib,lengrib,cgrib) + call baread(lunout,lskip,lgrib,lengrib,cgrib) if (lgrib/=lengrib) then print *,' degrib2: IO Error.' call errexit(9) @@ -659,29 +678,36 @@ subroutine write_grib2_2d(fname, vars, dims, nflds, field) call gb_info(cgrib,lengrib,listsec0,listsec1,& nflds,numlocal,maxlocal,ierr) - if (ierr/=0) then + if (ierr/=0) then write(6,*) ' ERROR querying GRIB2 message = ',ierr - stop 10 - endif + stop 10 + endif - print *,' SECTION 0: ',(listsec0(j),j=1,3) - print *,' SECTION 1: ',(listsec1(j),j=1,13) + print *,' SECTION 0: ',(listsec0(j),j=1,3) + print *,' SECTION 1: ',(listsec1(j),j=1,13) - call retrieve_time(fsrc, time_str, fortime, ref_time_array) + unpack=.false. + expand=0 + ! get template info + call gf_getfld(cgrib,lengrib,0,unpack,expand,gfld,ierr) + if (ierr/=0) then + write(6,*) ' ERROR extracting field = ',ierr + cycle + endif + call retrieve_time(time_str, fortime, ref_time) - - - ! Initialize GRIB2 message sections - listsec0(1) = 10 ! Discipline - GRIB Master Table Number (Code Table 0.0) + ! Initialize GRIB2 message sections + listsec0(1) = g2d(10,1) ! Discipline - GRIB Master Table Number (Code Table 0.0) listsec0(2) = 2 ! GRIB Edition Number (currently 2) listsec1(1) = 7 ! Originating Centre (Common Code Table C-1) - listsec1(2) = 4 ! Originating Sub-centre (local table) - listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) + listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 +! listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0) + listsec1(4) = 0 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) listsec1(6) = ref_time(1) ! Reference Time - Year -4digits listsec1(7) = ref_time(2) ! Reference Time - Month @@ -693,13 +719,51 @@ subroutine write_grib2_2d(fname, vars, dims, nflds, field) listsec1(13) = 1 ! Type of processed data (Code Table 1.4) + ! set grid res + if (nxt == 1440 .and. nyt == 1080) dij= = 250000 ! 1/4deg tripole + if (nxt == 720 .and. nyt == 576) dij= = 500000 ! 1/2deg tripole + if (nxt == 360 .and. nyt == 320) dij= = 1000000 ! 1deg tripole + if (nxt == 72 .and. nyt == 35) dij= = 5000000 ! 5deg tripole + lon0=0 + lon1=360000000-dij + lat0=-90000000 + lat1=90000000 + ! Populate the jgdt array for Template 3.0 + jgdt(1) = dims(2) ! Number of latitude points + jgdt(2) = dims(1) ! Number of longitude points + jgdt(3) = lat0 ! Latitude of first grid point (microdegrees) + jgdt(4) = lon0 ! Longitude of first grid point (microdegrees) + jgdt(5) = 0 ! Resolution and component flags + jgdt(6) = lat1 ! Latitude of last grid point (microdegrees) + jgdt(7) = lon1 ! Longitude of last grid point (microdegrees) + jgdt(8) = dij ! Grid increment in longitude direction (microdegrees) + jgdt(9) = dij ! Grid increment in latitude direction (microdegrees) + jgdt(10) = 0 ! Scanning mode (0 for default) +! ! Remaining values are reserved or unused for Template 3.0 + jgdt(11:19) = 0 + + + igdtnum=0 + ! Define igds GRIB2 - SECTION 3 + igds(1) = 0 ! Source of grid definition + igds(2) = npt ! Number of grid points + igds(3) = 0 ! Number of octets for each additional grid points definition + igds(4) = 0 ! Interpretation of list for optional points definition + igds(5) = igdtnum ! GRIB2 - CODE TABLE 3.1 - do n=1,nflds + igdtlen=size(jgdt) + print *,' igdtnum: ',(igdtnum) + print *,' jgdt: ',(jgdt) + + + do n=1,nflds + + listsec0(1) = g2d(10,n) ! Discipline - GRIB Master Table Number (Code Table 0.0) ! Initialize GRIB2 message call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) @@ -707,36 +771,170 @@ subroutine write_grib2_2d(fname, vars, dims, nflds, field) print *, 'GRIB2 message', ierr return end if - + call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) if (ierr /= 0) then print *, 'GRIB2 message', ierr return end if +! modifiy parametr https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp4-0.shtml + jpdt=-9999 + ipdtnum=0 + + + jpdt(1)=g2d(10,n) ! cat number + jpdt(2)=g2d(11,n) ! parm number + jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) + jpdt(4)=0 ! +! jpdt(5)=0 ! see Code ON388 Table A - need to be modified + jpdt(6)=1 ! unit (Hour=1) + jpdt(7)=fortime ! forecast hour + jpdt(8)=g2b(,n) ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer, ) + jpdt(9)=0 ! level value + jpdt(10)=255 + jpdt(12)=0 ! + jpdt(13)=0 + jpdt(14)=0 + jpdt(15)=0 + ! if(gfld%ipdtlen>=16) jpdt(16)=gfld%ipdtmpl(16) ! spatial statistical processing + print*,'jpdtn,jpdt= ',jpdtn,jpdt(1:15) + ipdtlen=size(jpdt) + + numcoord=0 + coordlist=0. !needed for hybrid vertical coordinate + ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + + + ! Assign example values + idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + + ! Populate idrtmpl for Template 5.0 + idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) + idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) + idrtmpl(3) = 0 ! Decimal scale factor (scale by 10^D) + idrtmpl(4) = 16 ! Number of bits for each packed value + idrtmpl(5) = 0 ! Type of original field values (0 = floating point) + ! Reserved fields for Template 5.0 + idrtmpl(6:11) = 0 ! Reserved for future use + + idrtlen=size(idrtmpl) + + + call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & + idrtnum, idrtmpl, idrtlen, field(:,nflds), npt, ibmap, ierr) + if (ierr /= 0) then + print *, 'Error adding field to GRIB2 message', ierr + return + end if + + end do + + call gribend(cgrib,max_bytes,lengrib,ierr) + print*,'gribend status=',ierr + print*,'length of the final GRIB2 message in octets =',lengrib + call wryte(lunout, lengrib, cgrib) + + deallocate(cgrib) + return + end subroutine write_grib2_2d + !--------------------------------------------------------------------------------- + !!!!!!!!!!!!!!!!!!!!!!!!!!!!Read Grib2 Template File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!This subroutine read a template grib2 file field!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !--------------------------------------------------------------------------------- - end subroutine write_grib2_2d + subroutine read_gtemp(gfld) + + ! This subroutine read a template grib2 file field + + implicit none + + type(gribfield) :: gfld + integer :: lunout,iseek,icount,lskip,lgrib,lengrib,ierr +! integer :: nflds,numlocal,maxlocal + CHARACTER(len=1),allocatable,dimension(:) :: cgrib + integer, parameter :: msk1=32000 + logical :: unpack,expand + + icount=0 + iseek=0 + + ! Use getlun90 to get a logical unit and baopenw to open the file + call getlun90(lunout, 1) + call baopenr(lunout, trim(input_file), ierr) + if (ierr /= 0) then + print *, 'Error opening template file ', trim(input_file) + return + end if + call skgb(lunout,iseek,msk1,lskip,lgrib) ! lgrib is the number of bytes in message and lskip is the no of + if (lgrib==0) exit ! end loop at EOF or problem + if (lgrib>currlen) then + if (allocated(cgrib)) deallocate(cgrib) + allocate(cgrib(lgrib),stat=ierr) + currlen=lgrib + endif + call baread(lunout,lskip,lgrib,lengrib,cgrib) + if (lgrib/=lengrib) then + print *,' degrib2: IO Error.' + call errexit(9) + endif + iseek=lskip+lgrib + icount=icount+1 + PRINT * + PRINT *,'GRIB MESSAGE ',icount,' starts at',lskip+1 + PRINT * +! call gb_info(cgrib,lengrib,listsec0,listsec1,& +! nflds,numlocal,maxlocal,ierr) +! if (ierr/=0) then +! write(6,*) ' ERROR querying GRIB2 message = ',ierr +! stop 10 +! endif +! print *,' SECTION 0: ',(listsec0(j),j=1,3) +! print *,' SECTION 1: ',(listsec1(j),j=1,13) + + + unpack=.false. + expand=.true. + ! get template info + call gf_getfld(cgrib,lengrib,0,unpack,expand,gfld,ierr) + if (ierr/=0) then + write(6,*) ' ERROR extracting field = ',ierr + cycle + endif + + return + + end subroutine read_gtemp + + + + + !-------------------------------------------------------------------------------------- + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!Retrieve Time From Input File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !-------------------------------------------------------------------------------------- + + subroutine retrieve_time(forecast_hour, ref_time) - subroutine retrieve_time(fsrc, time_str, forecast_hour, ref_time_array) use netcdf implicit none - character(len=*), intent(in) :: fsrc ! tripolar NetCDF file name - - character(len=10), intent(out) :: time_str ! Date in YYYYMMDDHH format +! character(len=10), intent(out) :: time_str ! Date in YYYYMMDDHH format integer, intent(out) :: forecast_hour ! Forecast hour as an integer - integer, dimension(6), intent(out) :: ref_time_array ! Array for GRIB2 reference time: [year, month, day, hour, minute, second] + integer, dimension(6), intent(out) :: ref_time ! Array for GRIB2 reference time: [year, month, day, hour, minute, second] integer :: ncid, time_varid, T1_varid, T2_varid, ierr character(len=30) :: units_str ! Units attribute string for time @@ -746,7 +944,7 @@ subroutine retrieve_time(fsrc, time_str, forecast_hour, ref_time_array) integer :: year, month, day, hour double precision :: hours_offset - call nf90_err(nf90_open(trim(ncfile), nf90_nowrite, ncid), 'opening '//fsrc) + call nf90_err(nf90_open(trim(input_file), nf90_nowrite, ncid), 'opening '//input_file) call nf90_err(nf90_inq_varid(ncid, 'time', time_varid), 'get variable ID: time') call nf90_err(nf90_get_var(ncid, time_varid, forecast_hour), 'get variable time') call nf90_err(nf90_get_att(ncid, time_varid, 'units', units_str), 'get attribute: units') @@ -755,24 +953,23 @@ subroutine retrieve_time(fsrc, time_str, forecast_hour, ref_time_array) read(units_str(13:30), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec - ! Set up ref_time_array for GRIB2 Section 1 - ref_time_array(1) = ref_year - ref_time_array(2) = ref_month - ref_time_array(3) = ref_day - ref_time_array(4) = ref_hour - ref_time_array(5) = ref_min - ref_time_array(6) = ref_sec + ! Set up ref_time for GRIB2 Section 1 + ref_time(1) = ref_year + ref_time(2) = ref_month + ref_time(3) = ref_day + ref_time(4) = ref_hour + ref_time(5) = ref_min + ref_time(6) = ref_sec call nf90_err(nf90_inq_varid(ncid, 'average_T1', T1_varid), 'get variable ID: average_T1')) call nf90_err(nf90_get_var(ncid, T1_varid, T1), 'get variable: average_T1') call nf90_err(nf90_inq_varid(ncid, 'average_T2', T2_varid), 'get variable ID: average_T2')) call nf90_err(nf90_get_var(ncid, T2_varid, T2), 'get variable: average_T2') - call nf90_err(nf90_close(ncid), 'close: '//fsrc) + call nf90_err(nf90_close(ncid), 'close: '//input_file) ! forecast_string = int(T2 - T1) ! Format the datetime in YYYYMMDDHH format - write(time_str, '(I4.4,I2.2,I2.2,I2.2)') ref_year, ref_month, ref_day, ref_hour - +! write(time_str, '(I4.4,I2.2,I2.2,I2.2)') ref_year, ref_month, ref_day, ref_hour end subroutine retrieve_time From fa44befcbe392353bd97db7adc8a627739ba61dc Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 4 Dec 2024 13:04:18 -0500 Subject: [PATCH 004/124] adding grib2 2D writing capabilities to ocnicepost --- parm/ocnicepost/ice.csv | 20 +- parm/ocnicepost/ice_mx025_to_0p25.nml | 1 + parm/ocnicepost/ocnicepost.nml.jinja2 | 1 + src/ocnicepost.fd/init_mod.F90 | 19 +- src/ocnicepost.fd/ocnicepost.F90 | 5 +- src/ocnicepost.fd/utils_mod.F90 | 329 ++++++++------------------ 6 files changed, 119 insertions(+), 256 deletions(-) diff --git a/parm/ocnicepost/ice.csv b/parm/ocnicepost/ice.csv index ee933ae2..99c16ad4 100644 --- a/parm/ocnicepost/ice.csv +++ b/parm/ocnicepost/ice.csv @@ -1,11 +1,11 @@ ! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,g1,g2,g3,g4,gc5,gc6,gc7,gc8 - 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,32,0,255,0,0,2,1 - 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,32,0,255,0,0,2,16 - 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,32,0,255,0,0,2,0 - 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,32,0,255,0,0,2,8 - 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,32,0,255,0,0,2,4 - 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,32,0,255,0,0,2,5 - 'frzmlt_h',2, 'Ct', 'conserve', '', '', 'FRZMLTPOT', 'freeze/melt potential', 'W m-2',10,32,0,255,0,0,2,27 - 'albsni_h',2, 'Ct', 'bilinear', '', '', 'ALBDOICE', 'Albedo', 'Numeric',10,32,0,255,0,0,2,14 -'mlt_onset_h',2, 'Ct', 'bilinear', '', '', 'MLTDATE', 'melt onset date', 'Numeric',10,32,0,255,0,0,2,28 -'frz_onset_h',2, 'Ct', 'bilinear', '', '', 'FRZDATE', 'freeze onset date', 'Numeric',10,32,0,255,0,0,2,29 + 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,32,0,0,2,1,101,0 + 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,32,0,0,2,16,101,0 + 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,32,0,0,2,0,101,0 + 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,32,0,0,2,8,101,0 + 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,32,0,0,2,4,101,0 + 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,32,0,0,2,5,101,0 + 'frzmlt_h',2, 'Ct', 'conserve', '', '', 'FRZMLTPOT', 'freeze/melt potential', 'W m-2',10,32,0,0,2,27,101,0 + 'albsni_h',2, 'Ct', 'bilinear', '', '', 'ALBDOICE', 'Albedo', 'Numeric',10,32,0,0,2,14,101,0 +'mlt_onset_h',2, 'Ct', 'bilinear', '', '', 'MLTDATE', 'melt onset date', 'Numeric',10,32,0,0,2,28,101,0 +'frz_onset_h',2, 'Ct', 'bilinear', '', '', 'FRZDATE', 'freeze onset date', 'Numeric',10,32,0,0,2,29,101,0 diff --git a/parm/ocnicepost/ice_mx025_to_0p25.nml b/parm/ocnicepost/ice_mx025_to_0p25.nml index 89a7d016..e8cd3d99 100644 --- a/parm/ocnicepost/ice_mx025_to_0p25.nml +++ b/parm/ocnicepost/ice_mx025_to_0p25.nml @@ -7,5 +7,6 @@ maskvar='tmask' sinvar='' cosvar='' angvar='ANGLET' +grib2=.true. debug=.false. / diff --git a/parm/ocnicepost/ocnicepost.nml.jinja2 b/parm/ocnicepost/ocnicepost.nml.jinja2 index 4cc6c596..8dd1e8bf 100644 --- a/parm/ocnicepost/ocnicepost.nml.jinja2 +++ b/parm/ocnicepost/ocnicepost.nml.jinja2 @@ -7,5 +7,6 @@ sinvar = "{{ sinvar }}", cosvar = "{{ cosvar }}", angvar = "{{ angvar }}", + grib2 = {{ grib2 | default('.true.') }} debug = {{ debug | default('.false.') }} / diff --git a/src/ocnicepost.fd/init_mod.F90 b/src/ocnicepost.fd/init_mod.F90 index a13de592..b89bbbf7 100644 --- a/src/ocnicepost.fd/init_mod.F90 +++ b/src/ocnicepost.fd/init_mod.F90 @@ -20,14 +20,14 @@ module init_mod character(len=120) :: long_name !< A variable's discription character(len= 20) :: units !< A variable's unit !!!may need to add a fillvalue for grib2 file - integer ::var_g1 !< Variables' grib2 coefficients g1-g8 - integer ::var_g2 - integer ::var_g3 - integer ::var_g4 - integer ::var_g5 - integer ::var_g6 - integer ::var_g7 - integer ::var_g8 + integer ::var_g1 !< Variables' grib2 coefficients g1-Dissipline + integer ::var_g2 !< Variables' grib2 coefficients g2-Master Tables Version Number + integer ::var_g3 !< Variables' grib2 coefficients g3-Section 1 originating center, used for local tables + integer ::var_g4 !< Variables' grib2 coefficients g4-Section 1 Local Tables Version Number + integer ::var_g5 !< Variables' grib2 coefficients g5-Section 4 Template 4.0 Parameter category + integer ::var_g6 !< Variables' grib2 coefficients g6-Section 4 Template 4.0 Parameter number + integer ::var_g7 !< Variables' grib2 coefficients g7-Level ID + integer ::var_g8 !< Variables' grib2 coefficients g8- end type vardefs type(vardefs) :: outvars(maxvars) !< An empty structure filled by reading a csv file describing the fields @@ -52,6 +52,7 @@ module init_mod integer :: nyr !< The y-dimension of the destination rectilinear grid integer :: logunit !< The log unit + logical :: grib2 !< If true, write grib2 message logical :: debug !< If true, print debug messages and intermediate files logical :: do_ocnpost !< If true, the source file is ocean, otherwise ice @@ -65,7 +66,7 @@ subroutine readnml integer :: srcdims(2), dstdims(2) namelist /ocnicepost_nml/ ftype, srcdims, wgtsdir, dstdims, maskvar, sinvar, cosvar, & - angvar, debug + angvar, grib2, debug ! -------------------------------------------------------- ! read the name list diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 0e33dd2b..9de4d052 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -394,13 +394,12 @@ program ocnicepost grib2d(:, 1:nbinin2d) = rgb2d g2d(:, 1:nbinin2d) = b2d end if - ! write 2D grib2 file + call write_grib2_2d(gout, g2d, dims=(/nxr,nyr/), nconsd2d+nbinin2d, grib2d) if (allocated(rgb3d)) then gout = trim(ftype)//'.'//trim(fdst)//'_3D.gb2' - ! write 3D grib2 file - call write_grib2_3d(gout, b3d, dims=(/nxr,nyr,nlevs/),nbilin3d,rgb3d) + call write_grib2_3d(gout, b3d, dims=(/nxr,nyr,nlevs/), nbilin3d, rgb3d) if (debug) write(logunit, '(a)')'GRIB2 3D output file: '//trim(gout) end if diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 53771444..6193212d 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -589,38 +589,22 @@ end subroutine dumpnc1d !----------------------------------------------------------------------------------- subroutine write_grib2_2d(fname, g2d, dims, nflds, field) - - ! This subroutine will work if we have a template with all variables included implicit none - character(len=*), intent(in) :: fname ! Output GRIB2 file name and source nc file + character(len=*), intent(in) :: fname type(vardefs), intent(in) :: g2d - integer, intent(in) :: dims(2) ! Dimensions of the field (nx, ny) + integer, intent(in) :: dims(2) integer, intent(in) :: nflds - real, intent(in) :: field(dims(1)*dims(2),nflds) ! 2D data array - - integer, dimension(6), intent(out) :: ref_time ! Array for GRIB2 reference time: [year, month, day, hour, minute, second] + real, intent(in) :: field(dims(1)*dims(2),nflds) - ! GRIB2 specific variables - type(gribfield) :: gfld - integer :: lunout ! Logical unit number for the GRIB2 file - integer :: ierr ! Error handling status - integer :: npt ! Total number of grid points - integer :: fortime - integer :: dij - + ! internal variables integer(4) :: max_bytes, lengrib - integer :: count, iseek ! iseek no of bytes to skip - integer, parameter :: msk1=32000 !max no. od bytes to search - - type(gribfield) :: gfld - integer :: lunout,iseek,icount,lskip,lgrib,lengrib,ierr - integer :: nflds,numlocal,maxlocal + integer, dimension(6), intent(out) :: ref_time + integer :: lunout, ierr, + integer :: nflds, fortime, dij, npt + integer :: numlocal, maxlocal CHARACTER(len=1),allocatable,dimension(:) :: cgrib - integer, parameter :: msk1=32000 - logical :: unpack,expand - ! GRIB2 metadata arrays integer :: listsec0(2), listsec1(13) @@ -628,124 +612,67 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) integer :: igdtlen, ipdtlen, idrtlen integer, allocatable :: jgdt(:), jpdt(:), idrtmpl(:) integer(4) :: igds(5) - integer :: numcoord, ibmap, currlen + integer :: numcoord, ibmap real(4) :: coordlist - - ! Character buffer for GRIB2 message - character(1), allocatable :: cgrib(:) - - + npt = dims(1) * dims(2) - ! allocate(field_1d(npt)) - ! field_1d = reshape(field, (/npt/)) ! Flatten 2D field to 1D for GRIB2 format - ! Allocate character buffer for GRIB2 message max_bytes = npt * 4 ! Estimated max bytes - ! allocate(cgrib(max_bytes)) - - icount=0 - iseek=0 - ! Use getlun90 to get a logical unit and baopenw to open the file call getlun90(lunout, 1) call baopenw(lunout, trim(fname), ierr) if (ierr /= 0) then - print *, 'Error opening template file ', trim(fname) + print *, 'Error opening grib2 file ', trim(fname) return end if - - call skgb(lunout,iseek,msk1,lskip,lgrib) ! lgrib is the number of bytes in message and lskip is the no of - if (lgrib==0) exit ! end loop at EOF or problem - if (lgrib>currlen) then - if (allocated(cgrib)) deallocate(cgrib) - allocate(cgrib(lgrib),stat=ierr) - currlen=lgrib - endif - - call baread(lunout,lskip,lgrib,lengrib,cgrib) - if (lgrib/=lengrib) then - print *,' degrib2: IO Error.' - call errexit(9) - endif - iseek=lskip+lgrib - icount=icount+1 - PRINT * - PRINT *,'GRIB MESSAGE ',icount,' starts at',lskip+1 - PRINT * - - - call gb_info(cgrib,lengrib,listsec0,listsec1,& - nflds,numlocal,maxlocal,ierr) - if (ierr/=0) then - write(6,*) ' ERROR querying GRIB2 message = ',ierr - stop 10 - endif - - print *,' SECTION 0: ',(listsec0(j),j=1,3) - print *,' SECTION 1: ',(listsec1(j),j=1,13) - - - unpack=.false. - expand=0 - ! get template info - call gf_getfld(cgrib,lengrib,0,unpack,expand,gfld,ierr) - if (ierr/=0) then - write(6,*) ' ERROR extracting field = ',ierr - cycle - endif - - - call retrieve_time(time_str, fortime, ref_time) - + call retrieve_time( fortime , ref_time ) ! Initialize GRIB2 message sections - listsec0(1) = g2d(10,1) ! Discipline - GRIB Master Table Number (Code Table 0.0) - listsec0(2) = 2 ! GRIB Edition Number (currently 2) + listsec0(1) = g2d(1)%var_g1 ! Discipline - GRIB Master Table Number (Code Table 0.0) + listsec0(2) = 2 ! GRIB Edition Number (currently 2) - listsec1(1) = 7 ! Originating Centre (Common Code Table C-1) - listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 -! listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0) - listsec1(4) = 0 ! GRIB Local Tables Version Number (Code Table 1.1) - listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) - listsec1(6) = ref_time(1) ! Reference Time - Year -4digits - listsec1(7) = ref_time(2) ! Reference Time - Month - listsec1(8) = ref_time(3) ! Reference Time - Day - listsec1(9) = ref_time(4) ! Reference Time - Hour - listsec1(10) = ref_time(5) ! Reference Time - Minute - listsec1(11) = ref_time(6) ! Reference Time - Second - listsec1(12) = 0 ! Production status of data (Code Table 1.3) - listsec1(13) = 1 ! Type of processed data (Code Table 1.4) - + listsec1(1) = 7 ! Originating Centre (Common Code Table C-1) + listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 + listsec1(3) = 0 ! GRIB Master Tables Version Number (Code Table 1.0) +! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) + listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) + listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) + listsec1(6) = ref_time(1) ! Reference Time - Year -4digits + listsec1(7) = ref_time(2) ! Reference Time - Month + listsec1(8) = ref_time(3) ! Reference Time - Day + listsec1(9) = ref_time(4) ! Reference Time - Hour + listsec1(10) = ref_time(5) ! Reference Time - Minute + listsec1(11) = ref_time(6) ! Reference Time - Second + listsec1(12) = 0 ! Production status of data (Code Table 1.3) + listsec1(13) = 1 ! Type of processed data (Code Table 1.4) ! set grid res - if (nxt == 1440 .and. nyt == 1080) dij= = 250000 ! 1/4deg tripole - if (nxt == 720 .and. nyt == 576) dij= = 500000 ! 1/2deg tripole - if (nxt == 360 .and. nyt == 320) dij= = 1000000 ! 1deg tripole - if (nxt == 72 .and. nyt == 35) dij= = 5000000 ! 5deg tripole + if (dims(1) == 1440 .and. dims(2) == 721) dij= 250000 ! 1/4deg rectilinear + if (dims(1) == 720 .and. dims(2) == 361) dij= 500000 ! 1/2deg rectilinear + if (dims(1) == 360 .and. dims(2) == 181) dij= 1000000 ! 1deg rectilinear + if (dims(1) == 72 .and. dims(2) == 36) dij= 5000000 ! 5deg rectilinear - - lon0=0 - lon1=360000000-dij - lat0=-90000000 - lat1=90000000 + lon0 = 0 + lon1 = 360000000 - dij + lat0 = -90000000 + lat1 = 90000000 ! Populate the jgdt array for Template 3.0 - jgdt(1) = dims(2) ! Number of latitude points - jgdt(2) = dims(1) ! Number of longitude points + jgdt(1) = dims(2) ! Number of latitude points + jgdt(2) = dims(1) ! Number of longitude points jgdt(3) = lat0 ! Latitude of first grid point (microdegrees) jgdt(4) = lon0 ! Longitude of first grid point (microdegrees) - jgdt(5) = 0 ! Resolution and component flags - jgdt(6) = lat1 ! Latitude of last grid point (microdegrees) - jgdt(7) = lon1 ! Longitude of last grid point (microdegrees) - jgdt(8) = dij ! Grid increment in longitude direction (microdegrees) - jgdt(9) = dij ! Grid increment in latitude direction (microdegrees) - jgdt(10) = 0 ! Scanning mode (0 for default) + jgdt(5) = 0 ! Resolution and component flags + jgdt(6) = lat1 ! Latitude of last grid point (microdegrees) + jgdt(7) = lon1 ! Longitude of last grid point (microdegrees) + jgdt(8) = dij ! Grid increment in longitude direction (microdegrees) + jgdt(9) = dij ! Grid increment in latitude direction (microdegrees) + jgdt(10) = 0 ! Scanning mode (0 for default) ! ! Remaining values are reserved or unused for Template 3.0 jgdt(11:19) = 0 - igdtnum=0 ! Define igds GRIB2 - SECTION 3 igds(1) = 0 ! Source of grid definition @@ -754,73 +681,67 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) igds(4) = 0 ! Interpretation of list for optional points definition igds(5) = igdtnum ! GRIB2 - CODE TABLE 3.1 - igdtlen=size(jgdt) print *,' igdtnum: ',(igdtnum) print *,' jgdt: ',(jgdt) + ! Initialize GRIB2 message + call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) + if (ierr /= 0) then + print *, 'Error initializing GRIB2 message', ierr + return + end if do n=1,nflds - listsec0(1) = g2d(10,n) ! Discipline - GRIB Master Table Number (Code Table 0.0) - - ! Initialize GRIB2 message - call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) - if (ierr /= 0) then - print *, 'GRIB2 message', ierr - return - end if - call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) if (ierr /= 0) then - print *, 'GRIB2 message', ierr + print *, 'Error adding grid to GRIB2 message', ierr return end if -! modifiy parametr https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp4-0.shtml +! Create Section 4 parametrs jpdt=-9999 ipdtnum=0 - - jpdt(1)=g2d(10,n) ! cat number - jpdt(2)=g2d(11,n) ! parm number - jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) - jpdt(4)=0 ! -! jpdt(5)=0 ! see Code ON388 Table A - need to be modified - jpdt(6)=1 ! unit (Hour=1) - jpdt(7)=fortime ! forecast hour - jpdt(8)=g2b(,n) ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer, ) - jpdt(9)=0 ! level value + jpdt(1)=g2d(n)%var_g5 ! cat number + jpdt(2)=g2d(n)%var_g6 ! parm number + jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) + jpdt(4)=0 ! +! jpdt(5)=0 ! + jpdt(6)=1 ! unit (Hour=1) + jpdt(7)=fortime ! forecast hour + jpdt(8)=g2b(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) + jpdt(9)=0 ! level value jpdt(10)=255 - jpdt(12)=0 ! + jpdt(12)=0 ! jpdt(13)=0 jpdt(14)=0 jpdt(15)=0 - ! if(gfld%ipdtlen>=16) jpdt(16)=gfld%ipdtmpl(16) ! spatial statistical processing - print*,'jpdtn,jpdt= ',jpdtn,jpdt(1:15) + + print*,'ipdtnum,jpdt= ',ipdtnum,jpdt(1:15) + ipdtlen=size(jpdt) numcoord=0 - coordlist=0. !needed for hybrid vertical coordinate - ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + coordlist=0. ! needed for hybrid vertical coordinate + ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap - - ! Assign example values + ! Assign Template 5 idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) ! Populate idrtmpl for Template 5.0 - idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) + idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 0 ! Decimal scale factor (scale by 10^D) - idrtmpl(4) = 16 ! Number of bits for each packed value + idrtmpl(3) = 0 ! Decimal scale factor (scale by 10^D) + idrtmpl(4) = 16 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) ! Reserved fields for Template 5.0 - idrtmpl(6:11) = 0 ! Reserved for future use + idrtmpl(6:11) = 0 ! Reserved for future use idrtlen=size(idrtmpl) - call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,nflds), npt, ibmap, ierr) if (ierr /= 0) then @@ -836,91 +757,13 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) call wryte(lunout, lengrib, cgrib) deallocate(cgrib) - return + return end subroutine write_grib2_2d - !--------------------------------------------------------------------------------- - !!!!!!!!!!!!!!!!!!!!!!!!!!!!Read Grib2 Template File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !!!!!!!!!!!!!!This subroutine read a template grib2 file field!!!!!!!!!!!!!!!!!!!! - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !--------------------------------------------------------------------------------- - - subroutine read_gtemp(gfld) - - ! This subroutine read a template grib2 file field - - implicit none - - type(gribfield) :: gfld - integer :: lunout,iseek,icount,lskip,lgrib,lengrib,ierr -! integer :: nflds,numlocal,maxlocal - CHARACTER(len=1),allocatable,dimension(:) :: cgrib - integer, parameter :: msk1=32000 - logical :: unpack,expand - - icount=0 - iseek=0 - - ! Use getlun90 to get a logical unit and baopenw to open the file - call getlun90(lunout, 1) - call baopenr(lunout, trim(input_file), ierr) - if (ierr /= 0) then - print *, 'Error opening template file ', trim(input_file) - return - end if - - call skgb(lunout,iseek,msk1,lskip,lgrib) ! lgrib is the number of bytes in message and lskip is the no of - if (lgrib==0) exit ! end loop at EOF or problem - if (lgrib>currlen) then - if (allocated(cgrib)) deallocate(cgrib) - allocate(cgrib(lgrib),stat=ierr) - currlen=lgrib - endif - - call baread(lunout,lskip,lgrib,lengrib,cgrib) - if (lgrib/=lengrib) then - print *,' degrib2: IO Error.' - call errexit(9) - endif - - iseek=lskip+lgrib - icount=icount+1 - PRINT * - PRINT *,'GRIB MESSAGE ',icount,' starts at',lskip+1 - PRINT * - - -! call gb_info(cgrib,lengrib,listsec0,listsec1,& -! nflds,numlocal,maxlocal,ierr) -! if (ierr/=0) then -! write(6,*) ' ERROR querying GRIB2 message = ',ierr -! stop 10 -! endif - -! print *,' SECTION 0: ',(listsec0(j),j=1,3) -! print *,' SECTION 1: ',(listsec1(j),j=1,13) - - - unpack=.false. - expand=.true. - ! get template info - call gf_getfld(cgrib,lengrib,0,unpack,expand,gfld,ierr) - if (ierr/=0) then - write(6,*) ' ERROR extracting field = ',ierr - cycle - endif - - return - - end subroutine read_gtemp - - - - !-------------------------------------------------------------------------------------- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!Retrieve Time From Input File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -929,14 +772,13 @@ end subroutine read_gtemp subroutine retrieve_time(forecast_hour, ref_time) - use netcdf implicit none ! character(len=10), intent(out) :: time_str ! Date in YYYYMMDDHH format - integer, intent(out) :: forecast_hour ! Forecast hour as an integer - integer, dimension(6), intent(out) :: ref_time ! Array for GRIB2 reference time: [year, month, day, hour, minute, second] + integer, intent(out) :: forecast_hour ! Forecast hour as an integer + integer, dimension(6), intent(out) :: ref_time ! Array for GRIB2 reference time: [year, month, day, hour, minute, second] - integer :: ncid, time_varid, T1_varid, T2_varid, ierr + integer :: ncid, time_varid, T1_varid, T2_varid character(len=30) :: units_str ! Units attribute string for time double precision :: T1, T2 ! Scalars to hold start and end time data @@ -992,3 +834,22 @@ subroutine nf90_err(ierr, string) end if end subroutine nf90_err end module utils_mod + + + !-------------------------------------------------------------------------------------- + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!handle grib2 errors!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !-------------------------------------------------------------------------------------- +subroutine grib_err(ierr, msg) + implicit none + integer, intent(in) :: ierr + character(len=*), intent(in) :: msg + + if (ierr /= 0) then + open(unit=20, file="grib_errors.log", status="unknown", action="write") + write(20, *) "GRIB2 Error:", trim(msg), "Error code:", ierr + close(20) + stop + end if +end subroutine grib_err From 788826fab6e180f41beaee541b98d7ec653fb032 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 5 Dec 2024 10:27:02 -0500 Subject: [PATCH 005/124] adding grib2 2D writing capabilities to ocnicepost-fixed some issues --- src/ocnicepost.fd/utils_mod.F90 | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 6193212d..d28f55f8 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -4,7 +4,6 @@ module utils_mod use init_mod, only : debug, logunit, vardefs, fsrc, input_file use grib_mod - implicit none private @@ -41,6 +40,7 @@ module utils_mod public packarrays public remap public dumpnc + public write_grib2_2d public nf90_err contains @@ -600,10 +600,9 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) ! internal variables integer(4) :: max_bytes, lengrib - integer, dimension(6), intent(out) :: ref_time - integer :: lunout, ierr, + integer(6) :: ref_time + integer :: lunout, ierr integer :: nflds, fortime, dij, npt - integer :: numlocal, maxlocal CHARACTER(len=1),allocatable,dimension(:) :: cgrib ! GRIB2 metadata arrays @@ -686,7 +685,6 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) print *,' igdtnum: ',(igdtnum) print *,' jgdt: ',(jgdt) - ! Initialize GRIB2 message call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) if (ierr /= 0) then print *, 'Error initializing GRIB2 message', ierr @@ -702,7 +700,6 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) end if ! Create Section 4 parametrs - jpdt=-9999 ipdtnum=0 jpdt(1)=g2d(n)%var_g5 ! cat number @@ -774,13 +771,12 @@ subroutine retrieve_time(forecast_hour, ref_time) implicit none -! character(len=10), intent(out) :: time_str ! Date in YYYYMMDDHH format integer, intent(out) :: forecast_hour ! Forecast hour as an integer integer, dimension(6), intent(out) :: ref_time ! Array for GRIB2 reference time: [year, month, day, hour, minute, second] integer :: ncid, time_varid, T1_varid, T2_varid - character(len=30) :: units_str ! Units attribute string for time - double precision :: T1, T2 ! Scalars to hold start and end time data + character(len=30) :: units_str + double precision :: T1, T2 integer :: ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec integer :: year, month, day, hour @@ -791,11 +787,9 @@ subroutine retrieve_time(forecast_hour, ref_time) call nf90_err(nf90_get_var(ncid, time_varid, forecast_hour), 'get variable time') call nf90_err(nf90_get_att(ncid, time_varid, 'units', units_str), 'get attribute: units') - ! Assuming format "hours since YYYY-MM-DD HH:MM:SS" read(units_str(13:30), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec - ! Set up ref_time for GRIB2 Section 1 ref_time(1) = ref_year ref_time(2) = ref_month ref_time(3) = ref_day @@ -809,9 +803,6 @@ subroutine retrieve_time(forecast_hour, ref_time) call nf90_err(nf90_get_var(ncid, T2_varid, T2), 'get variable: average_T2') call nf90_err(nf90_close(ncid), 'close: '//input_file) -! forecast_string = int(T2 - T1) -! Format the datetime in YYYYMMDDHH format -! write(time_str, '(I4.4,I2.2,I2.2,I2.2)') ref_year, ref_month, ref_day, ref_hour end subroutine retrieve_time From 7d8b0a518867823ab951f6295d7dbc496ea791ef Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 5 Dec 2024 12:26:05 -0500 Subject: [PATCH 006/124] adding grib2 2D writing capabilities to ocnicepost-fixed issues --- src/ocnicepost.fd/init_mod.F90 | 18 +++++++++--------- src/ocnicepost.fd/utils_mod.F90 | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/ocnicepost.fd/init_mod.F90 b/src/ocnicepost.fd/init_mod.F90 index b89bbbf7..da90a5cd 100644 --- a/src/ocnicepost.fd/init_mod.F90 +++ b/src/ocnicepost.fd/init_mod.F90 @@ -7,18 +7,18 @@ module init_mod real, parameter :: maxvars = 50 !< The maximum number of fields expected in a source file type :: vardefs - character(len= 20) :: var_name !< A variable's variable name - ! character(len=120) :: long_name !< A variable's long name - ! character(len= 20) :: units !< A variable's unit + character(len= 20) :: var_name !< A variable's variable name character(len= 20) :: var_remapmethod !< A variable's mapping method + character(len=120) :: long_name !< A variable's long name + character(len= 20) :: units !< A variable's unit integer :: var_dimen !< A variable's dimensionality character(len= 4) :: var_grid !< A variable's input grid location; all output locations are on cell centers character(len= 20) :: var_pair !< A variable's pair character(len= 4) :: var_pair_grid !< A pair variable grid real :: var_fillvalue !< A variable's fillvalue - character(len= 20) :: var_name_gb2 !< A variable's grib2 variable name - character(len=120) :: long_name !< A variable's discription - character(len= 20) :: units !< A variable's unit + character(len= 20) :: name_gb2 !< A variable's grib2 variable name + character(len=120) :: discription_gb2 !< A variable's discription + character(len= 20) :: unit_gb2 !< A variable's unit !!!may need to add a fillvalue for grib2 file integer ::var_g1 !< Variables' grib2 coefficients g1-Dissipline integer ::var_g2 !< Variables' grib2 coefficients g2-Master Tables Version Number @@ -161,9 +161,9 @@ subroutine readcsv(nvalid) outvars(nn)%var_remapmethod = trim(c4) outvars(nn)%var_pair = trim(c5) outvars(nn)%var_pair_grid = trim(c6) - outvars(nn)%var_name_gb2 = trim(c7) - outvars(nn)%var_discription = trim(c8) - outvars(nn)%var_unit = trim(c9) + outvars(nn)%name_gb2 = trim(c7) + outvars(nn)%discription_gb2 = trim(c8) + outvars(nn)%unit_gb2 = trim(c9) outvars(nn)%var_g1 = trim(i10) outvars(nn)%var_g2 = trim(i11) outvars(nn)%var_g3 = trim(i12) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index d28f55f8..384d3a2b 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -803,7 +803,6 @@ subroutine retrieve_time(forecast_hour, ref_time) call nf90_err(nf90_get_var(ncid, T2_varid, T2), 'get variable: average_T2') call nf90_err(nf90_close(ncid), 'close: '//input_file) - end subroutine retrieve_time From 3f1cd1c69c5e27a820dac48105c0db72eab29ff0 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 5 Dec 2024 13:25:20 -0500 Subject: [PATCH 007/124] adding grib2 2D writing capabilities to ocnicepost-fixed issues --- src/ocnicepost.fd/utils_mod.F90 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 384d3a2b..ab5af982 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -593,16 +593,15 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) implicit none character(len=*), intent(in) :: fname - type(vardefs), intent(in) :: g2d integer, intent(in) :: dims(2) integer, intent(in) :: nflds real, intent(in) :: field(dims(1)*dims(2),nflds) ! internal variables integer(4) :: max_bytes, lengrib - integer(6) :: ref_time + integer :: ref_time(6) integer :: lunout, ierr - integer :: nflds, fortime, dij, npt + integer :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib ! GRIB2 metadata arrays @@ -613,6 +612,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist + integer :: n, lon0, lon1, lat0, lat1 npt = dims(1) * dims(2) @@ -797,9 +797,9 @@ subroutine retrieve_time(forecast_hour, ref_time) ref_time(5) = ref_min ref_time(6) = ref_sec - call nf90_err(nf90_inq_varid(ncid, 'average_T1', T1_varid), 'get variable ID: average_T1')) + call nf90_err(nf90_inq_varid(ncid, 'average_T1', T1_varid), 'get variable ID: average_T1') call nf90_err(nf90_get_var(ncid, T1_varid, T1), 'get variable: average_T1') - call nf90_err(nf90_inq_varid(ncid, 'average_T2', T2_varid), 'get variable ID: average_T2')) + call nf90_err(nf90_inq_varid(ncid, 'average_T2', T2_varid), 'get variable ID: average_T2') call nf90_err(nf90_get_var(ncid, T2_varid, T2), 'get variable: average_T2') call nf90_err(nf90_close(ncid), 'close: '//input_file) From 73ccd1d091192be871fd30036dd352e79d9cc113 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 5 Dec 2024 13:33:13 -0500 Subject: [PATCH 008/124] adding grib2 2D writing capabilities to ocnicepost-fixed more issues --- src/ocnicepost.fd/init_mod.F90 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ocnicepost.fd/init_mod.F90 b/src/ocnicepost.fd/init_mod.F90 index da90a5cd..3aa8824c 100644 --- a/src/ocnicepost.fd/init_mod.F90 +++ b/src/ocnicepost.fd/init_mod.F90 @@ -164,14 +164,14 @@ subroutine readcsv(nvalid) outvars(nn)%name_gb2 = trim(c7) outvars(nn)%discription_gb2 = trim(c8) outvars(nn)%unit_gb2 = trim(c9) - outvars(nn)%var_g1 = trim(i10) - outvars(nn)%var_g2 = trim(i11) - outvars(nn)%var_g3 = trim(i12) - outvars(nn)%var_g4 = trim(i13) - outvars(nn)%var_g5 = trim(i14) - outvars(nn)%var_g6 = trim(i15) - outvars(nn)%var_g7 = trim(i16) - outvars(nn)%var_g8 = trim(i17) + outvars(nn)%var_g1 = i10 + outvars(nn)%var_g2 = i11 + outvars(nn)%var_g3 = i12 + outvars(nn)%var_g4 = i13 + outvars(nn)%var_g5 = i14 + outvars(nn)%var_g6 = i15 + outvars(nn)%var_g7 = i16 + outvars(nn)%var_g8 = i17 end if end do close(iounit) From 51e58b6f476ab898c8667c3caef606e852935089 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 6 Dec 2024 10:07:11 -0500 Subject: [PATCH 009/124] adding grib2 2D writing capabilities to ocnicepost-fixed one more issue --- src/ocnicepost.fd/utils_mod.F90 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index ab5af982..ee5361a1 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -2,7 +2,6 @@ module utils_mod use netcdf use init_mod, only : debug, logunit, vardefs, fsrc, input_file - use grib_mod implicit none From 86972f3a574b9f956c29aef56a79fcd7cf4b5790 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 6 Dec 2024 10:19:37 -0500 Subject: [PATCH 010/124] adding grib2 2D writing capabilities to ocnicepost-fixed typo --- src/ocnicepost.fd/utils_mod.F90 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index ee5361a1..798d230a 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -591,8 +591,9 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) implicit none - character(len=*), intent(in) :: fname - integer, intent(in) :: dims(2) + character(len=*), intent(in) :: fname + type(vardefs), allocatable, dimension(:) :: g2d + integer, intent(in) :: dims(2) integer, intent(in) :: nflds real, intent(in) :: field(dims(1)*dims(2),nflds) @@ -708,7 +709,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) ! jpdt(5)=0 ! jpdt(6)=1 ! unit (Hour=1) jpdt(7)=fortime ! forecast hour - jpdt(8)=g2b(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) + jpdt(8)=g2d(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) jpdt(9)=0 ! level value jpdt(10)=255 jpdt(12)=0 ! From 069eaf5873ae07c42ac359962ab39c7fbfa5ba33 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 6 Dec 2024 10:30:07 -0500 Subject: [PATCH 011/124] adding grib2 2D writing capabilities to ocnicepost-fixed issues --- src/ocnicepost.fd/ocnicepost.F90 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 9de4d052..09e6a486 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -383,16 +383,16 @@ program ocnicepost if (debug) write(logunit, '(a)')'GRIB2 2D output file: '//trim(gout) if (allocated(rgb2d) .and. allocated(rgc2d)) then - grib2d(:, 1:nconsd2d) = rgc2d - grib2d(:, nconsd2d+1:nconsd2d+nbinin2d) = rgb2d - g2d(:, 1:nconsd2d) = c2d - g2d(:, nconsd2d+1:nconsd2d+nbinin2d) = b2d + grib2d(1:nconsd2d) = rgc2d + grib2d(nconsd2d+1:nconsd2d+nbinin2d) = rgb2d + g2d(1:nconsd2d) = c2d + g2d(nconsd2d+1:nconsd2d+nbinin2d) = b2d else if (allocated(rgb2d)) then - grib2d(:, 1:nconsd2d) = rgc2d - g2d(:, 1:nconsd2d) = c2d + grib2d(1:nconsd2d) = rgc2d + g2d(1:nconsd2d) = c2d else if (allocated(rgc2d)) then - grib2d(:, 1:nbinin2d) = rgb2d - g2d(:, 1:nbinin2d) = b2d + grib2d(1:nbinin2d) = rgb2d + g2d(1:nbinin2d) = b2d end if call write_grib2_2d(gout, g2d, dims=(/nxr,nyr/), nconsd2d+nbinin2d, grib2d) From 0f75119121ca55efc9ca34334aff9b802c928165 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 6 Dec 2024 10:39:56 -0500 Subject: [PATCH 012/124] adding grib2 2D writing capabilities to ocnicepost-fixed issues --- src/ocnicepost.fd/ocnicepost.F90 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 09e6a486..a01cc77d 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -383,25 +383,25 @@ program ocnicepost if (debug) write(logunit, '(a)')'GRIB2 2D output file: '//trim(gout) if (allocated(rgb2d) .and. allocated(rgc2d)) then - grib2d(1:nconsd2d) = rgc2d - grib2d(nconsd2d+1:nconsd2d+nbinin2d) = rgb2d + grib2d(:, 1:nconsd2d) = rgc2d + grib2d(:, nconsd2d+1:nconsd2d+nbilin2d) = rgb2d g2d(1:nconsd2d) = c2d - g2d(nconsd2d+1:nconsd2d+nbinin2d) = b2d + g2d(nconsd2d+1:nconsd2d+nbilin2d) = b2d else if (allocated(rgb2d)) then - grib2d(1:nconsd2d) = rgc2d + grib2d(:, 1:nconsd2d) = rgc2d g2d(1:nconsd2d) = c2d else if (allocated(rgc2d)) then - grib2d(1:nbinin2d) = rgb2d - g2d(1:nbinin2d) = b2d + grib2d(:, 1:nbilin2d) = rgb2d + g2d(1:nbilin2d) = b2d end if - call write_grib2_2d(gout, g2d, dims=(/nxr,nyr/), nconsd2d+nbinin2d, grib2d) + call write_grib2_2d(gout, g2d, (/nxr,nyr/), nconsd2d+nbilin2d, grib2d) - if (allocated(rgb3d)) then - gout = trim(ftype)//'.'//trim(fdst)//'_3D.gb2' - call write_grib2_3d(gout, b3d, dims=(/nxr,nyr,nlevs/), nbilin3d, rgb3d) - if (debug) write(logunit, '(a)')'GRIB2 3D output file: '//trim(gout) - end if +! if (allocated(rgb3d)) then +! gout = trim(ftype)//'.'//trim(fdst)//'_3D.gb2' +! call write_grib2_3d(gout, b3d, (/nxr,nyr,nlevs/), nbilin3d, rgb3d) +! if (debug) write(logunit, '(a)')'GRIB2 3D output file: '//trim(gout) +! end if end if From 1d8010454c43f5c00cca55ae185253f2e39d00b2 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 6 Dec 2024 11:07:59 -0500 Subject: [PATCH 013/124] adding grib2 2D writing capabilities to ocnicepost-fixed issues --- src/ocnicepost.fd/CMakeLists.txt | 3 ++- src/ocnicepost.fd/ocnicepost.F90 | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/CMakeLists.txt b/src/ocnicepost.fd/CMakeLists.txt index 529454fa..ff7140ab 100644 --- a/src/ocnicepost.fd/CMakeLists.txt +++ b/src/ocnicepost.fd/CMakeLists.txt @@ -8,6 +8,7 @@ list(APPEND fortran_src set(exe_name ocnicepost.x) add_executable(${exe_name} ${fortran_src}) -target_link_libraries(${exe_name} PRIVATE NetCDF::NetCDF_Fortran) +target_link_libraries(${exe_name} PRIVATE NetCDF::NetCDF_Fortran + g2::g2_d) install(TARGETS ${exe_name} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index a01cc77d..9fa29483 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -32,7 +32,7 @@ program ocnicepost use arrays_mod , only : b2d, c2d, b3d, rgb2d, rgc2d, rgb3d, dstlon, dstlat, setup_packing use arrays_mod , only : nbilin2d, nbilin3d, nconsd2d, bilin2d, bilin3d, consd2d use masking_mod, only : mask2d, mask3d, rgmask2d, rgmask3d, remap_masks - use utils_mod , only : getfield, packarrays, remap, dumpnc, nf90_err + use utils_mod , only : getfield, packarrays, remap, dumpnc, nf90_err, write_grib2_2d implicit none From 5331042269f1b9cc1fecf87416bad47545a65d23 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 6 Dec 2024 11:19:40 -0500 Subject: [PATCH 014/124] adding grib2 2D writing capabilities to ocnicepost-fixed issues --- src/ocnicepost.fd/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/CMakeLists.txt b/src/ocnicepost.fd/CMakeLists.txt index ff7140ab..0d9d3e94 100644 --- a/src/ocnicepost.fd/CMakeLists.txt +++ b/src/ocnicepost.fd/CMakeLists.txt @@ -9,6 +9,7 @@ list(APPEND fortran_src set(exe_name ocnicepost.x) add_executable(${exe_name} ${fortran_src}) target_link_libraries(${exe_name} PRIVATE NetCDF::NetCDF_Fortran - g2::g2_d) + g2::g2_d + bacio::bacio_4) install(TARGETS ${exe_name} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) From f301fc940d8719a12e21a8ee4ae241148577ab44 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 6 Dec 2024 12:00:30 -0500 Subject: [PATCH 015/124] adding grib2 2D writing capabilities to ocnicepost-fixed issues --- src/ocnicepost.fd/ocnicepost.F90 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 9fa29483..58ed3413 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -402,7 +402,6 @@ program ocnicepost ! call write_grib2_3d(gout, b3d, (/nxr,nyr,nlevs/), nbilin3d, rgb3d) ! if (debug) write(logunit, '(a)')'GRIB2 3D output file: '//trim(gout) ! end if - end if stop From 6352c7c5cfed261717a46c9e4461ce472f53fd9f Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 6 Dec 2024 12:13:02 -0500 Subject: [PATCH 016/124] adding grib2 2D writing capabilities to ocnicepost-fixed issues --- src/ocnicepost.fd/utils_mod.F90 | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 798d230a..d7101b82 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -618,8 +618,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) max_bytes = npt * 4 ! Estimated max bytes - ! Use getlun90 to get a logical unit and baopenw to open the file - call getlun90(lunout, 1) + call getlun(lunout) call baopenw(lunout, trim(fname), ierr) if (ierr /= 0) then print *, 'Error opening grib2 file ', trim(fname) @@ -759,6 +758,27 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) end subroutine write_grib2_2d +!-------------------------------------------------------------------------------------- + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!To get a lun used for bacio!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !-------------------------------------------------------------------------------------- + subroutine getlun(lun) + integer, intent(out) :: lun + logical :: is_open + lun = 50 + do + inquire(unit=lun, opened=is_open) + if (.not. is_open) then + return + else + lun = lun + 1 + end if + end do + end subroutine getlun + + + !-------------------------------------------------------------------------------------- From 9144c52455154953ebfae5435856dd9db6370fa7 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Mon, 9 Dec 2024 11:13:08 -0500 Subject: [PATCH 017/124] implimmenting 2d grib2 writer-fixed issues --- src/ocnicepost.fd/ocnicepost.F90 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 58ed3413..4acc61a8 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -383,10 +383,10 @@ program ocnicepost if (debug) write(logunit, '(a)')'GRIB2 2D output file: '//trim(gout) if (allocated(rgb2d) .and. allocated(rgc2d)) then - grib2d(:, 1:nconsd2d) = rgc2d - grib2d(:, nconsd2d+1:nconsd2d+nbilin2d) = rgb2d - g2d(1:nconsd2d) = c2d - g2d(nconsd2d+1:nconsd2d+nbilin2d) = b2d + grib2d(:, 1:nbilin2d) = rgb2d + grib2d(:, nbilin2d+1:nconsd2d+nbilin2d) = rgc2d + g2d(1:nbilin2d) = b2d + g2d(nbilin2d+1:nconsd2d+nbilin2d) = c2d else if (allocated(rgb2d)) then grib2d(:, 1:nconsd2d) = rgc2d g2d(1:nconsd2d) = c2d From 39089fee64eb80e375a1520770a6e8416bd1e877 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Mon, 9 Dec 2024 11:56:09 -0500 Subject: [PATCH 018/124] implimmenting 2d grib2 writer-fixed issues --- src/ocnicepost.fd/ocnicepost.F90 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 4acc61a8..01b06b07 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -383,14 +383,20 @@ program ocnicepost if (debug) write(logunit, '(a)')'GRIB2 2D output file: '//trim(gout) if (allocated(rgb2d) .and. allocated(rgc2d)) then + allocate(grib2d(nxr*nyr,nconsd2d+nbilin2d)) + allocate(g2d(1:nconsd2d+nbilin2d)) grib2d(:, 1:nbilin2d) = rgb2d grib2d(:, nbilin2d+1:nconsd2d+nbilin2d) = rgc2d g2d(1:nbilin2d) = b2d g2d(nbilin2d+1:nconsd2d+nbilin2d) = c2d else if (allocated(rgb2d)) then + allocate(grib2d(nxr*nyr,nconsd2d)) + allocate(g2d(1:nconsd2d)) grib2d(:, 1:nconsd2d) = rgc2d g2d(1:nconsd2d) = c2d else if (allocated(rgc2d)) then + allocate(grib2d(nxr*nyr,nbilin2d)) + allocate(g2d(1:nbilin2d)) grib2d(:, 1:nbilin2d) = rgb2d g2d(1:nbilin2d) = b2d end if From 730924bef490d382e2cda2701c6e0528ca610337 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 10 Dec 2024 09:08:48 -0500 Subject: [PATCH 019/124] modified time string for ice model temporarly --- src/ocnicepost.fd/utils_mod.F90 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index d7101b82..8273ca0f 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -807,8 +807,10 @@ subroutine retrieve_time(forecast_hour, ref_time) call nf90_err(nf90_get_var(ncid, time_varid, forecast_hour), 'get variable time') call nf90_err(nf90_get_att(ncid, time_varid, 'units', units_str), 'get attribute: units') - read(units_str(13:30), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & + + read(units_str(12:29), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & ! (12:29) for testing ice model - (13:30) for testing ocean model ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec + ref_time(1) = ref_year ref_time(2) = ref_month @@ -817,11 +819,11 @@ subroutine retrieve_time(forecast_hour, ref_time) ref_time(5) = ref_min ref_time(6) = ref_sec - call nf90_err(nf90_inq_varid(ncid, 'average_T1', T1_varid), 'get variable ID: average_T1') - call nf90_err(nf90_get_var(ncid, T1_varid, T1), 'get variable: average_T1') - call nf90_err(nf90_inq_varid(ncid, 'average_T2', T2_varid), 'get variable ID: average_T2') - call nf90_err(nf90_get_var(ncid, T2_varid, T2), 'get variable: average_T2') - call nf90_err(nf90_close(ncid), 'close: '//input_file) +! call nf90_err(nf90_inq_varid(ncid, 'average_T1', T1_varid), 'get variable ID: average_T1') +! call nf90_err(nf90_get_var(ncid, T1_varid, T1), 'get variable: average_T1') +! call nf90_err(nf90_inq_varid(ncid, 'average_T2', T2_varid), 'get variable ID: average_T2') +! call nf90_err(nf90_get_var(ncid, T2_varid, T2), 'get variable: average_T2') +! call nf90_err(nf90_close(ncid), 'close: '//input_file) end subroutine retrieve_time From b0eda67ae055d229d7ed9a8b30fa5d3bbef5bf59 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 10 Dec 2024 09:33:59 -0500 Subject: [PATCH 020/124] fixed unit for wrting in log file --- src/ocnicepost.fd/utils_mod.F90 | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 8273ca0f..75209c99 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -621,7 +621,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) call getlun(lunout) call baopenw(lunout, trim(fname), ierr) if (ierr /= 0) then - print *, 'Error opening grib2 file ', trim(fname) + write(logunit, '(A, I5)') 'Error opening grib2 file ', trim(fname) return end if @@ -681,12 +681,12 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) igdtlen=size(jgdt) - print *,' igdtnum: ',(igdtnum) - print *,' jgdt: ',(jgdt) + write(logunit, '(A, I5)') 'igdtnum: ', igdtnum + write(logunit, '(A, I5)')' jgdt: ',(jgdt) call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) if (ierr /= 0) then - print *, 'Error initializing GRIB2 message', ierr + write(logunit, '(A, I5)') 'Error initializing GRIB2 message', ierr return end if @@ -694,7 +694,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) if (ierr /= 0) then - print *, 'Error adding grid to GRIB2 message', ierr + write(logunit, '(A, I5)') 'Error adding grid to GRIB2 message', ierr return end if @@ -716,7 +716,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) jpdt(14)=0 jpdt(15)=0 - print*,'ipdtnum,jpdt= ',ipdtnum,jpdt(1:15) + write(logunit, '(A, I5, A, 15I5)') 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) + ipdtlen=size(jpdt) @@ -741,15 +742,15 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,nflds), npt, ibmap, ierr) if (ierr /= 0) then - print *, 'Error adding field to GRIB2 message', ierr + write(logunit, '(A, I5)') 'Error adding field to GRIB2 message', ierr return end if end do call gribend(cgrib,max_bytes,lengrib,ierr) - print*,'gribend status=',ierr - print*,'length of the final GRIB2 message in octets =',lengrib + write(logunit, '(A, I5)') 'gribend status=',ierr + write(logunit, '(A, I5)') 'length of the final GRIB2 message in octets =',lengrib call wryte(lunout, lengrib, cgrib) deallocate(cgrib) From 057ab9ffa287e4baeac048ad9452b8a7cb3bf7fb Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 10 Dec 2024 10:20:29 -0500 Subject: [PATCH 021/124] fixed wrting in log file --- src/ocnicepost.fd/utils_mod.F90 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 75209c99..6f65d39f 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -682,7 +682,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) igdtlen=size(jgdt) write(logunit, '(A, I5)') 'igdtnum: ', igdtnum - write(logunit, '(A, I5)')' jgdt: ',(jgdt) + write(logunit, '(A, I5)') 'jgdt: ', jgdt call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) if (ierr /= 0) then @@ -860,9 +860,8 @@ subroutine grib_err(ierr, msg) character(len=*), intent(in) :: msg if (ierr /= 0) then - open(unit=20, file="grib_errors.log", status="unknown", action="write") - write(20, *) "GRIB2 Error:", trim(msg), "Error code:", ierr - close(20) - stop + write(0, *) "GRIB2 Error:", trim(msg), "Error code:", ierr + !stop ierr + stop 99 end if end subroutine grib_err From 26da8cc53caa03e5b7e96d2c3c449bf512c83300 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 10 Dec 2024 10:27:44 -0500 Subject: [PATCH 022/124] fixed wrting in log file --- src/ocnicepost.fd/utils_mod.F90 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 6f65d39f..b9ff3bab 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -621,7 +621,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) call getlun(lunout) call baopenw(lunout, trim(fname), ierr) if (ierr /= 0) then - write(logunit, '(A, I5)') 'Error opening grib2 file ', trim(fname) + write(logunit, *) 'Error opening grib2 file ', trim(fname) return end if @@ -681,12 +681,12 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) igdtlen=size(jgdt) - write(logunit, '(A, I5)') 'igdtnum: ', igdtnum - write(logunit, '(A, I5)') 'jgdt: ', jgdt + write(logunit, *) 'igdtnum: ', igdtnum + write(logunit, *) 'jgdt: ', jgdt call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) if (ierr /= 0) then - write(logunit, '(A, I5)') 'Error initializing GRIB2 message', ierr + write(logunit, *) 'Error initializing GRIB2 message', ierr return end if @@ -694,7 +694,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) if (ierr /= 0) then - write(logunit, '(A, I5)') 'Error adding grid to GRIB2 message', ierr + write(logunit, *) 'Error adding grid to GRIB2 message', ierr return end if @@ -716,7 +716,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) jpdt(14)=0 jpdt(15)=0 - write(logunit, '(A, I5, A, 15I5)') 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) + write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) ipdtlen=size(jpdt) @@ -742,15 +742,15 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,nflds), npt, ibmap, ierr) if (ierr /= 0) then - write(logunit, '(A, I5)') 'Error adding field to GRIB2 message', ierr + write(logunit, *) 'Error adding field to GRIB2 message', ierr return end if end do call gribend(cgrib,max_bytes,lengrib,ierr) - write(logunit, '(A, I5)') 'gribend status=',ierr - write(logunit, '(A, I5)') 'length of the final GRIB2 message in octets =',lengrib + write(logunit, *) 'gribend status=',ierr + write(logunit, *) 'length of the final GRIB2 message in octets =',lengrib call wryte(lunout, lengrib, cgrib) deallocate(cgrib) From bebf1a2e0e0f2ff4aabcb70f33ddb732b71901cc Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 10 Dec 2024 11:06:31 -0500 Subject: [PATCH 023/124] fixed allocation issues --- src/ocnicepost.fd/utils_mod.F90 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index b9ff3bab..d4d16d6b 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -608,11 +608,13 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer, allocatable :: jgdt(:), jpdt(:), idrtmpl(:) + integer :: jgdt(19), jpdt(15), idrtmpl(11) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist integer :: n, lon0, lon1, lat0, lat1 + + npt = dims(1) * dims(2) @@ -718,7 +720,6 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) - ipdtlen=size(jpdt) numcoord=0 From 728bb0c97031370d9d864bbbf1924b95cd536e6a Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 10 Dec 2024 11:29:20 -0500 Subject: [PATCH 024/124] fixed allocation issues --- src/ocnicepost.fd/utils_mod.F90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index d4d16d6b..0648b4a2 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -620,6 +620,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) max_bytes = npt * 4 ! Estimated max bytes + allocate(cgrib(max_bytes)) + call getlun(lunout) call baopenw(lunout, trim(fname), ierr) if (ierr /= 0) then From 7ff1c009b97113595b28656c66946cf1f9a11029 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 10 Dec 2024 11:51:43 -0500 Subject: [PATCH 025/124] fixed allocation issues --- src/ocnicepost.fd/utils_mod.F90 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 0648b4a2..227faf2b 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -620,7 +620,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) max_bytes = npt * 4 ! Estimated max bytes - allocate(cgrib(max_bytes)) + allocate(cgrib(max_bytes)) ! allocate cgrib + call getlun(lunout) call baopenw(lunout, trim(fname), ierr) @@ -688,7 +689,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'igdtnum: ', igdtnum write(logunit, *) 'jgdt: ', jgdt - call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) + call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) if (ierr /= 0) then write(logunit, *) 'Error initializing GRIB2 message', ierr return From 23a5be5f6ed8bef5af5688d0f1b3bc94a2ae00f4 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 10 Dec 2024 12:38:56 -0500 Subject: [PATCH 026/124] add stuff for debugging --- src/ocnicepost.fd/utils_mod.F90 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 227faf2b..40999897 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -620,7 +620,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) max_bytes = npt * 4 ! Estimated max bytes - allocate(cgrib(max_bytes)) ! allocate cgrib + allocate(cgrib(max_bytes)) ! allocate call getlun(lunout) @@ -662,7 +662,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) lat0 = -90000000 lat1 = 90000000 - ! Populate the jgdt array for Template 3.0 + ! Populate the jgdt array for Template 3.0 jgdt(1) = dims(2) ! Number of latitude points jgdt(2) = dims(1) ! Number of longitude points jgdt(3) = lat0 ! Latitude of first grid point (microdegrees) @@ -686,8 +686,11 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) igdtlen=size(jgdt) - write(logunit, *) 'igdtnum: ', igdtnum + write(logunit, *) 'igdtnum, igdtlen: ', igdtnum, igdtlen write(logunit, *) 'jgdt: ', jgdt + write(logunit, *) 'igds: ', igds + write(logunit, *) 'cgrib: ', cgrib + write(logunit, *) 'max_bytes: ', max_bytes call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) if (ierr /= 0) then @@ -697,7 +700,10 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) do n=1,nflds - call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) + write(logunit, *) 'n, nflds, npt: ', n, nflds, npt + write(logunit, *) 'max_bytes: ', max_bytes + + call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) ! (there is an error here ) if (ierr /= 0) then write(logunit, *) 'Error adding grid to GRIB2 message', ierr return From 567dd87d9b5bab8c31666a237f34cbbe5b18b714 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 10 Dec 2024 13:29:36 -0500 Subject: [PATCH 027/124] add stuff for debugging --- src/ocnicepost.fd/utils_mod.F90 | 52 ++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 40999897..3339c1ca 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -662,19 +662,41 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) lat0 = -90000000 lat1 = 90000000 - ! Populate the jgdt array for Template 3.0 - jgdt(1) = dims(2) ! Number of latitude points - jgdt(2) = dims(1) ! Number of longitude points - jgdt(3) = lat0 ! Latitude of first grid point (microdegrees) - jgdt(4) = lon0 ! Longitude of first grid point (microdegrees) - jgdt(5) = 0 ! Resolution and component flags - jgdt(6) = lat1 ! Latitude of last grid point (microdegrees) - jgdt(7) = lon1 ! Longitude of last grid point (microdegrees) - jgdt(8) = dij ! Grid increment in longitude direction (microdegrees) - jgdt(9) = dij ! Grid increment in latitude direction (microdegrees) - jgdt(10) = 0 ! Scanning mode (0 for default) + ! Populate the jgdt array for Template 3.0 (this seems to be wrong) +! jgdt(1) = dims(2) ! Number of latitude points +! jgdt(2) = dims(1) ! Number of longitude points +! jgdt(3) = lat0 ! Latitude of first grid point (microdegrees) +! jgdt(4) = lon0 ! Longitude of first grid point (microdegrees) +! jgdt(5) = 0 ! Resolution and component flags +! jgdt(6) = lat1 ! Latitude of last grid point (microdegrees) +! jgdt(7) = lon1 ! Longitude of last grid point (microdegrees) +! jgdt(8) = dij ! Grid increment in longitude direction (microdegrees) +! jgdt(9) = dij ! Grid increment in latitude direction (microdegrees) +! jgdt(10) = 0 ! Scanning mode (0 for default) ! ! Remaining values are reserved or unused for Template 3.0 - jgdt(11:19) = 0 +! jgdt(11:19) = 0 + + + ! Populate the jgdt array for Template 3.0 () + jgdt(1) = 6 + jgdt(2) = 0 + jgdt(3) = 0 + jgdt(4) = 0 + jgdt(5) = 0 + jgdt(6) = 0 + jgdt(7) = 0 + jgdt(8) = dims(1) + jgdt(9) = dims(1) + jgdt(10) = 0 + jgdt(11) = 0 + jgdt(12) = lat0 + jgdt(13) = lon0 + jgdt(14) = 14 + jgdt(15) = lat1 + jgdt(16) = lon1 + jgdt(17) = dij + jgdt(18) = dij + jgdt(19) = 0 igdtnum=0 ! Define igds GRIB2 - SECTION 3 @@ -689,7 +711,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'igdtnum, igdtlen: ', igdtnum, igdtlen write(logunit, *) 'jgdt: ', jgdt write(logunit, *) 'igds: ', igds - write(logunit, *) 'cgrib: ', cgrib + write(logunit, *) 'igds: ', dij +! write(logunit, *) 'cgrib: ', cgrib write(logunit, *) 'max_bytes: ', max_bytes call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) @@ -703,7 +726,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'n, nflds, npt: ', n, nflds, npt write(logunit, *) 'max_bytes: ', max_bytes - call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) ! (there is an error here ) +! call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) ! (there is an error here ) + call addgrid(cgrib, max_bytes, igds, jgdt, 100, ierr) ! (there is an error here ) if (ierr /= 0) then write(logunit, *) 'Error adding grid to GRIB2 message', ierr return From a6208cd361ea0a12a7c4788b78245c4430d484de Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 10 Dec 2024 13:43:49 -0500 Subject: [PATCH 028/124] add stuff for debugging --- src/ocnicepost.fd/utils_mod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 3339c1ca..b6d3acf0 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -686,12 +686,12 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) jgdt(6) = 0 jgdt(7) = 0 jgdt(8) = dims(1) - jgdt(9) = dims(1) + jgdt(9) = dims(2) jgdt(10) = 0 jgdt(11) = 0 jgdt(12) = lat0 jgdt(13) = lon0 - jgdt(14) = 14 + jgdt(14) = 48 jgdt(15) = lat1 jgdt(16) = lon1 jgdt(17) = dij @@ -711,7 +711,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'igdtnum, igdtlen: ', igdtnum, igdtlen write(logunit, *) 'jgdt: ', jgdt write(logunit, *) 'igds: ', igds - write(logunit, *) 'igds: ', dij + write(logunit, *) 'dij: ', dij ! write(logunit, *) 'cgrib: ', cgrib write(logunit, *) 'max_bytes: ', max_bytes From 038f8e9f166e6d4d4597c8133b1cf4fa910a0fe4 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 10 Dec 2024 15:30:52 -0500 Subject: [PATCH 029/124] add stuff for debugging --- src/ocnicepost.fd/utils_mod.F90 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index b6d3acf0..e17b20b0 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -688,7 +688,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) jgdt(8) = dims(1) jgdt(9) = dims(2) jgdt(10) = 0 - jgdt(11) = 0 + jgdt(11) = -1 !0 jgdt(12) = lat0 jgdt(13) = lon0 jgdt(14) = 48 @@ -696,7 +696,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) jgdt(16) = lon1 jgdt(17) = dij jgdt(18) = dij - jgdt(19) = 0 + jgdt(19) = 64 !0 igdtnum=0 ! Define igds GRIB2 - SECTION 3 @@ -726,8 +726,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'n, nflds, npt: ', n, nflds, npt write(logunit, *) 'max_bytes: ', max_bytes -! call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) ! (there is an error here ) - call addgrid(cgrib, max_bytes, igds, jgdt, 100, ierr) ! (there is an error here ) +! call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) ! (there is an error here ) maybe the problem is from max byte should ask + call addgrid(cgrib, max_bytes, igds, jgdt, 30, ierr) ! (there is an error here ) if (ierr /= 0) then write(logunit, *) 'Error adding grid to GRIB2 message', ierr return From 75f5585fb1dcd773ea512ce45f9d71cc9e36973b Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 11 Dec 2024 10:03:38 -0500 Subject: [PATCH 030/124] add some command, changed grid parameters for debugging --- src/ocnicepost.fd/utils_mod.F90 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index e17b20b0..05f38f28 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -662,7 +662,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) lat0 = -90000000 lat1 = 90000000 - ! Populate the jgdt array for Template 3.0 (this seems to be wrong) + ! Populate the jgdt array for Template 3.0 (this seems to be wrong format) ! jgdt(1) = dims(2) ! Number of latitude points ! jgdt(2) = dims(1) ! Number of longitude points ! jgdt(3) = lat0 ! Latitude of first grid point (microdegrees) @@ -677,7 +677,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) ! jgdt(11:19) = 0 - ! Populate the jgdt array for Template 3.0 () + ! Populate the jgdt array for Template 3.0 (changed parameters to current grib2 files) jgdt(1) = 6 jgdt(2) = 0 jgdt(3) = 0 @@ -708,12 +708,17 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) igdtlen=size(jgdt) + !!!!these are for debuging (remove after done) + write(logunit, *) 'listsec, listsec1: ', listsec0, listsec1 write(logunit, *) 'igdtnum, igdtlen: ', igdtnum, igdtlen write(logunit, *) 'jgdt: ', jgdt write(logunit, *) 'igds: ', igds write(logunit, *) 'dij: ', dij -! write(logunit, *) 'cgrib: ', cgrib write(logunit, *) 'max_bytes: ', max_bytes + write(logunit, *) 'forcast time: ', fortime + write(logunit, *) 'refference time: ', ref_time + + call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) if (ierr /= 0) then @@ -843,9 +848,9 @@ subroutine retrieve_time(forecast_hour, ref_time) call nf90_err(nf90_get_att(ncid, time_varid, 'units', units_str), 'get attribute: units') - read(units_str(12:29), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & ! (12:29) for testing ice model - (13:30) for testing ocean model + read(units_str(12:29), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & ! (12:29) for testing ice model (need to be changed request sent) - (13:30) is final and for testing the ocean model ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec - + forecast_hour=24*forecast_hour ! just for testing ice model (remove it once ice time unit fixed) ref_time(1) = ref_year ref_time(2) = ref_month From fb3b239469102a6365b5e74b3c101daf2e844b30 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 11 Dec 2024 10:33:31 -0500 Subject: [PATCH 031/124] add some command, changed grid parameters for debugging --- src/ocnicepost.fd/utils_mod.F90 | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 05f38f28..72efa2b0 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -640,7 +640,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 listsec1(3) = 0 ! GRIB Master Tables Version Number (Code Table 1.0) ! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) - listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) + listsec1(4) = 0 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) listsec1(6) = ref_time(1) ! Reference Time - Year -4digits listsec1(7) = ref_time(2) ! Reference Time - Month @@ -688,15 +688,15 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) jgdt(8) = dims(1) jgdt(9) = dims(2) jgdt(10) = 0 - jgdt(11) = -1 !0 + jgdt(11) = 0 !-1 jgdt(12) = lat0 jgdt(13) = lon0 - jgdt(14) = 48 + jgdt(14) = 48 !0 jgdt(15) = lat1 jgdt(16) = lon1 jgdt(17) = dij jgdt(18) = dij - jgdt(19) = 64 !0 + jgdt(19) = 0 !64 igdtnum=0 ! Define igds GRIB2 - SECTION 3 @@ -709,7 +709,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) igdtlen=size(jgdt) !!!!these are for debuging (remove after done) - write(logunit, *) 'listsec, listsec1: ', listsec0, listsec1 + write(logunit, *) 'listsec0, listsec1: ', listsec0, listsec1 write(logunit, *) 'igdtnum, igdtlen: ', igdtnum, igdtlen write(logunit, *) 'jgdt: ', jgdt write(logunit, *) 'igds: ', igds @@ -729,10 +729,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) do n=1,nflds write(logunit, *) 'n, nflds, npt: ', n, nflds, npt - write(logunit, *) 'max_bytes: ', max_bytes -! call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) ! (there is an error here ) maybe the problem is from max byte should ask - call addgrid(cgrib, max_bytes, igds, jgdt, 30, ierr) ! (there is an error here ) + call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) ! there is an error here if (ierr /= 0) then write(logunit, *) 'Error adding grid to GRIB2 message', ierr return From c121a064a7add8402c17bc359d450fee302feea3 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 11 Dec 2024 10:35:10 -0500 Subject: [PATCH 032/124] increased cgrib and changed grid parameters for debugging --- src/ocnicepost.fd/utils_mod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 72efa2b0..8b2f87dc 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -620,8 +620,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) max_bytes = npt * 4 ! Estimated max bytes - allocate(cgrib(max_bytes)) ! allocate - +! allocate(cgrib(max_bytes)) ! allocate + allocate(cgrib(max_bytes*4)) ! allocate call getlun(lunout) call baopenw(lunout, trim(fname), ierr) @@ -730,7 +730,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'n, nflds, npt: ', n, nflds, npt - call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) ! there is an error here + call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) ! there is an internal error here if (ierr /= 0) then write(logunit, *) 'Error adding grid to GRIB2 message', ierr return From 8435a5829819cbb5d73f990f706099e10a377dca Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 11 Dec 2024 11:23:48 -0500 Subject: [PATCH 033/124] changed add grib format to add dummy variables --- src/ocnicepost.fd/utils_mod.F90 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 8b2f87dc..8e7c3597 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -614,6 +614,9 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) real(4) :: coordlist integer :: n, lon0, lon1, lat0, lat1 + idefnum = 0 + ideflist=0 !Used if igds(3) .ne. 0. Dummy array otherwise + npt = dims(1) * dims(2) @@ -730,7 +733,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'n, nflds, npt: ', n, nflds, npt - call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ierr) ! there is an internal error here + call addgrid(cgrib, max_bytes, igds, jgdt, 100, ideflist, idefnum ierr) ! there is an internal error here if (ierr /= 0) then write(logunit, *) 'Error adding grid to GRIB2 message', ierr return From 1afae32ba23edb803f17e664222cef3a82afc63b Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 11 Dec 2024 11:27:55 -0500 Subject: [PATCH 034/124] changed add grib format to add dummy variables --- src/ocnicepost.fd/utils_mod.F90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 8e7c3597..537d671c 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -614,6 +614,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) real(4) :: coordlist integer :: n, lon0, lon1, lat0, lat1 + integer :: ideflist,idefnum + idefnum = 0 ideflist=0 !Used if igds(3) .ne. 0. Dummy array otherwise From 756fe13a89c4def6b2b2f2ca097e7c90350eb4df Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 11 Dec 2024 11:34:37 -0500 Subject: [PATCH 035/124] changed add grib format to add dummy variables --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 537d671c..efb0d22e 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -735,7 +735,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'n, nflds, npt: ', n, nflds, npt - call addgrid(cgrib, max_bytes, igds, jgdt, 100, ideflist, idefnum ierr) ! there is an internal error here + call addgrid(cgrib, max_bytes, igds, jgdt, 100, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then write(logunit, *) 'Error adding grid to GRIB2 message', ierr return From 0cb1e9693c355093e401caebb6d7318fe8eed3fe Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 11 Dec 2024 12:19:30 -0500 Subject: [PATCH 036/124] changed addfield added bmp --- src/ocnicepost.fd/utils_mod.F90 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index efb0d22e..96744f6c 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -615,6 +615,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) integer :: n, lon0, lon1, lat0, lat1 integer :: ideflist,idefnum + logical :: bmp(dims(1)*dims(2)) idefnum = 0 ideflist=0 !Used if igds(3) .ne. 0. Dummy array otherwise @@ -625,8 +626,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) max_bytes = npt * 4 ! Estimated max bytes -! allocate(cgrib(max_bytes)) ! allocate - allocate(cgrib(max_bytes*4)) ! allocate + allocate(cgrib(max_bytes)) ! allocate call getlun(lunout) call baopenw(lunout, trim(fname), ierr) @@ -645,7 +645,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 listsec1(3) = 0 ! GRIB Master Tables Version Number (Code Table 1.0) ! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) - listsec1(4) = 0 ! GRIB Local Tables Version Number (Code Table 1.1) + listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) listsec1(6) = ref_time(1) ! Reference Time - Year -4digits listsec1(7) = ref_time(2) ! Reference Time - Month @@ -748,7 +748,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) jpdt(2)=g2d(n)%var_g6 ! parm number jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) jpdt(4)=0 ! -! jpdt(5)=0 ! + jpdt(5)=0 ! jpdt(6)=1 ! unit (Hour=1) jpdt(7)=fortime ! forecast hour jpdt(8)=g2d(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) @@ -766,6 +766,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + bmp=.true. ! Assign Template 5 idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) @@ -773,7 +774,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) ! Populate idrtmpl for Template 5.0 idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 0 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 16 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) ! Reserved fields for Template 5.0 @@ -782,7 +783,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) idrtlen=size(idrtmpl) call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & - idrtnum, idrtmpl, idrtlen, field(:,nflds), npt, ibmap, ierr) + idrtnum, idrtmpl, 100, field(:,n), npt, ibmap,bmp, ierr) if (ierr /= 0) then write(logunit, *) 'Error adding field to GRIB2 message', ierr return From d568391309616ec441d502250e4802ffaaa463e9 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 11 Dec 2024 12:21:30 -0500 Subject: [PATCH 037/124] changed addfield added bmp --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 96744f6c..32b4356a 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -783,7 +783,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) idrtlen=size(idrtmpl) call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & - idrtnum, idrtmpl, 100, field(:,n), npt, ibmap,bmp, ierr) + idrtnum, idrtmpl, 100, field(:,n), npt, ibmap, bmp, ierr) if (ierr /= 0) then write(logunit, *) 'Error adding field to GRIB2 message', ierr return From 04ee9f782606cee067f147f90990fa3f70403827 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 11 Dec 2024 15:33:25 -0500 Subject: [PATCH 038/124] changed section 5 parameters --- src/ocnicepost.fd/utils_mod.F90 | 34 +++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 32b4356a..20246352 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -613,15 +613,15 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) integer :: numcoord, ibmap real(4) :: coordlist integer :: n, lon0, lon1, lat0, lat1 - + integer :: ideflist,idefnum logical :: bmp(dims(1)*dims(2)) - + integer :: bsf, nbits + real :: ref_val,Range + idefnum = 0 ideflist=0 !Used if igds(3) .ne. 0. Dummy array otherwise - - npt = dims(1) * dims(2) max_bytes = npt * 4 ! Estimated max bytes @@ -770,15 +770,29 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) ! Assign Template 5 idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + + ref_val=minval(field(:,n)) + range=maxval(field(:,n))-ref_val + if (range > 0.0) then + bsf = ceiling(log2(range / 2.0**31)) + else + bsf = 0 + end if + if (range > 0.0) then + nbits = ceiling(log2(range * 2.0**(-bsf))) + else + nbits = 0 + end if + ! Populate idrtmpl for Template 5.0 - idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) - idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) - idrtmpl(4) = 16 ! Number of bits for each packed value - idrtmpl(5) = 0 ! Type of original field values (0 = floating point) + idrtmpl(1) = ref_val ! Reference value (scaled value of the minimum data point) + idrtmpl(2) = bsf ! Binary scale factor (scale by 2^E) + idrtmpl(3) = 0 ! Decimal scale factor (scale by 10^D) + idrtmpl(4) = nbits ! Number of bits for each packed value + idrtmpl(5) = 0 ! Type of original field values (0 = floating point) ! Reserved fields for Template 5.0 - idrtmpl(6:11) = 0 ! Reserved for future use + idrtmpl(6:11) = 0 ! Reserved for future use idrtlen=size(idrtmpl) From 521cbaa30f0b3b4890c6f4c615e1ee6b890a540f Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 11 Dec 2024 15:38:18 -0500 Subject: [PATCH 039/124] removed section 5 parameters --- src/ocnicepost.fd/utils_mod.F90 | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 20246352..340c4119 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -618,7 +618,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) logical :: bmp(dims(1)*dims(2)) integer :: bsf, nbits real :: ref_val,Range - + idefnum = 0 ideflist=0 !Used if igds(3) .ne. 0. Dummy array otherwise @@ -771,25 +771,14 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) ! Assign Template 5 idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) - ref_val=minval(field(:,n)) - range=maxval(field(:,n))-ref_val - if (range > 0.0) then - bsf = ceiling(log2(range / 2.0**31)) - else - bsf = 0 - end if - if (range > 0.0) then - nbits = ceiling(log2(range * 2.0**(-bsf))) - else - nbits = 0 - end if + ! Populate idrtmpl for Template 5.0 - idrtmpl(1) = ref_val ! Reference value (scaled value of the minimum data point) - idrtmpl(2) = bsf ! Binary scale factor (scale by 2^E) + idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) + idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) idrtmpl(3) = 0 ! Decimal scale factor (scale by 10^D) - idrtmpl(4) = nbits ! Number of bits for each packed value + idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) ! Reserved fields for Template 5.0 idrtmpl(6:11) = 0 ! Reserved for future use From afb8c51d818cb2d1f20eae9a9869ebf66cb45cea Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 11 Dec 2024 15:53:58 -0500 Subject: [PATCH 040/124] changed section 5 parameters --- src/ocnicepost.fd/utils_mod.F90 | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 340c4119..9b6d6eaf 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -771,14 +771,11 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) ! Assign Template 5 idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) - - - ! Populate idrtmpl for Template 5.0 - idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) - idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 0 ! Decimal scale factor (scale by 10^D) - idrtmpl(4) = 0 ! Number of bits for each packed value + idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) + idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) + idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) + idrtmpl(4) = 16 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) ! Reserved fields for Template 5.0 idrtmpl(6:11) = 0 ! Reserved for future use From dd2f19d477b6faef0e4da457e14f2aa22f4bee12 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 12 Dec 2024 10:41:55 -0500 Subject: [PATCH 041/124] changed parameters fpor section 5 --- src/ocnicepost.fd/utils_mod.F90 | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 9b6d6eaf..21ef9c54 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -613,14 +613,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) integer :: numcoord, ibmap real(4) :: coordlist integer :: n, lon0, lon1, lat0, lat1 - - integer :: ideflist,idefnum logical :: bmp(dims(1)*dims(2)) - integer :: bsf, nbits - real :: ref_val,Range - - idefnum = 0 - ideflist=0 !Used if igds(3) .ne. 0. Dummy array otherwise npt = dims(1) * dims(2) @@ -667,21 +660,6 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) lat0 = -90000000 lat1 = 90000000 - ! Populate the jgdt array for Template 3.0 (this seems to be wrong format) -! jgdt(1) = dims(2) ! Number of latitude points -! jgdt(2) = dims(1) ! Number of longitude points -! jgdt(3) = lat0 ! Latitude of first grid point (microdegrees) -! jgdt(4) = lon0 ! Longitude of first grid point (microdegrees) -! jgdt(5) = 0 ! Resolution and component flags -! jgdt(6) = lat1 ! Latitude of last grid point (microdegrees) -! jgdt(7) = lon1 ! Longitude of last grid point (microdegrees) -! jgdt(8) = dij ! Grid increment in longitude direction (microdegrees) -! jgdt(9) = dij ! Grid increment in latitude direction (microdegrees) -! jgdt(10) = 0 ! Scanning mode (0 for default) -! ! Remaining values are reserved or unused for Template 3.0 -! jgdt(11:19) = 0 - - ! Populate the jgdt array for Template 3.0 (changed parameters to current grib2 files) jgdt(1) = 6 jgdt(2) = 0 @@ -723,8 +701,6 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'forcast time: ', fortime write(logunit, *) 'refference time: ', ref_time - - call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) if (ierr /= 0) then write(logunit, *) 'Error initializing GRIB2 message', ierr @@ -735,7 +711,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'n, nflds, npt: ', n, nflds, npt - call addgrid(cgrib, max_bytes, igds, jgdt, 100, ideflist, idefnum, ierr) ! there is an internal error here + call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then write(logunit, *) 'Error adding grid to GRIB2 message', ierr return @@ -775,7 +751,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) - idrtmpl(4) = 16 ! Number of bits for each packed value + idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) ! Reserved fields for Template 5.0 idrtmpl(6:11) = 0 ! Reserved for future use @@ -783,7 +759,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) idrtlen=size(idrtmpl) call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & - idrtnum, idrtmpl, 100, field(:,n), npt, ibmap, bmp, ierr) + idrtnum, idrtmpl, idrtlen, field(:,n), npt, ibmap, bmp, ierr) if (ierr /= 0) then write(logunit, *) 'Error adding field to GRIB2 message', ierr return From 5254b306ec74ff1c8269eaae0dd25638d0a2b186 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 12 Dec 2024 10:42:55 -0500 Subject: [PATCH 042/124] changed parameters for section 5 --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 21ef9c54..af5d05df 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -750,7 +750,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) ! Populate idrtmpl for Template 5.0 idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) ! Reserved fields for Template 5.0 From 23a2fb9b95334deadf94186983cf24dff6548178 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 12 Dec 2024 10:56:19 -0500 Subject: [PATCH 043/124] changed parameters for section 5 --- src/ocnicepost.fd/utils_mod.F90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index af5d05df..97f11f93 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -613,6 +613,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) integer :: numcoord, ibmap real(4) :: coordlist integer :: n, lon0, lon1, lat0, lat1 + integer :: ideflist, idefnum logical :: bmp(dims(1)*dims(2)) npt = dims(1) * dims(2) @@ -707,6 +708,9 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) return end if + ideflist=0 + idefnum=0 + do n=1,nflds write(logunit, *) 'n, nflds, npt: ', n, nflds, npt From cb51a11815bc77a75da46e1ccee497e71aef9217 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 12 Dec 2024 11:48:31 -0500 Subject: [PATCH 044/124] changed parameters for sections --- src/ocnicepost.fd/utils_mod.F90 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 97f11f93..2382227a 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -40,6 +40,7 @@ module utils_mod public remap public dumpnc public write_grib2_2d + public write_grib2_3d public nf90_err contains @@ -637,8 +638,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) listsec1(1) = 7 ! Originating Centre (Common Code Table C-1) listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 - listsec1(3) = 0 ! GRIB Master Tables Version Number (Code Table 1.0) -! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) +! listsec1(3) = 2 ! GRIB Master Tables Version Number (Code Table 1.0) + listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) listsec1(6) = ref_time(1) ! Reference Time - Year -4digits @@ -802,9 +803,6 @@ subroutine getlun(lun) end subroutine getlun - - - !-------------------------------------------------------------------------------------- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!Retrieve Time From Input File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! From 381d586f2c71d6b00cbe5855393bf0e3efaeeb71 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 12 Dec 2024 12:13:55 -0500 Subject: [PATCH 045/124] changed parameters for sections --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 2382227a..d150c139 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -40,7 +40,7 @@ module utils_mod public remap public dumpnc public write_grib2_2d - public write_grib2_3d +! public write_grib2_3d public nf90_err contains From df6781672e9969e531b4410ebf4ed52b51ce6d0d Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 12 Dec 2024 12:28:32 -0500 Subject: [PATCH 046/124] changed parameters for section1 --- parm/ocnicepost/ice.csv | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/parm/ocnicepost/ice.csv b/parm/ocnicepost/ice.csv index 99c16ad4..2f0aa621 100644 --- a/parm/ocnicepost/ice.csv +++ b/parm/ocnicepost/ice.csv @@ -1,11 +1,11 @@ ! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,g1,g2,g3,g4,gc5,gc6,gc7,gc8 - 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,32,0,0,2,1,101,0 - 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,32,0,0,2,16,101,0 - 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,32,0,0,2,0,101,0 - 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,32,0,0,2,8,101,0 - 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,32,0,0,2,4,101,0 - 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,32,0,0,2,5,101,0 - 'frzmlt_h',2, 'Ct', 'conserve', '', '', 'FRZMLTPOT', 'freeze/melt potential', 'W m-2',10,32,0,0,2,27,101,0 - 'albsni_h',2, 'Ct', 'bilinear', '', '', 'ALBDOICE', 'Albedo', 'Numeric',10,32,0,0,2,14,101,0 -'mlt_onset_h',2, 'Ct', 'bilinear', '', '', 'MLTDATE', 'melt onset date', 'Numeric',10,32,0,0,2,28,101,0 -'frz_onset_h',2, 'Ct', 'bilinear', '', '', 'FRZDATE', 'freeze onset date', 'Numeric',10,32,0,0,2,29,101,0 + 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,2,0,0,2,1,101,0 + 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,2,0,0,2,16,101,0 + 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,2,0,0,2,0,101,0 + 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,2,0,0,2,8,101,0 + 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,2,0,0,2,4,101,0 + 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,2,0,0,2,5,101,0 + 'frzmlt_h',2, 'Ct', 'conserve', '', '', 'FRZMLTPOT', 'freeze/melt potential', 'W m-2',10,2,0,0,2,27,101,0 + 'albsni_h',2, 'Ct', 'bilinear', '', '', 'ALBDOICE', 'Albedo', 'Numeric',10,2,0,0,2,14,101,0 +'mlt_onset_h',2, 'Ct', 'bilinear', '', '', 'MLTDATE', 'melt onset date', 'Numeric',10,2,0,0,2,28,101,0 +'frz_onset_h',2, 'Ct', 'bilinear', '', '', 'FRZDATE', 'freeze onset date', 'Numeric',10,2,0,0,2,29,101,0 From 3ff6e0593f8b9060ce62914655e09e6e653c1fa5 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 12 Dec 2024 12:44:11 -0500 Subject: [PATCH 047/124] changed parameters for section1 --- src/ocnicepost.fd/utils_mod.F90 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index d150c139..97f11f93 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -40,7 +40,6 @@ module utils_mod public remap public dumpnc public write_grib2_2d -! public write_grib2_3d public nf90_err contains @@ -638,8 +637,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) listsec1(1) = 7 ! Originating Centre (Common Code Table C-1) listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 -! listsec1(3) = 2 ! GRIB Master Tables Version Number (Code Table 1.0) - listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) + listsec1(3) = 0 ! GRIB Master Tables Version Number (Code Table 1.0) +! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) listsec1(6) = ref_time(1) ! Reference Time - Year -4digits @@ -803,6 +802,9 @@ subroutine getlun(lun) end subroutine getlun + + + !-------------------------------------------------------------------------------------- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!Retrieve Time From Input File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! From 8ffb919e84fc89fc0ca6556c9796fe71a621edf0 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 13 Dec 2024 10:33:48 -0500 Subject: [PATCH 048/124] changed parameters for sections --- src/ocnicepost.fd/utils_mod.F90 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 97f11f93..39bc5d2b 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -608,7 +608,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(11) + integer :: jgdt(19), jpdt(15), idrtmpl(5) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist @@ -636,7 +636,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) listsec0(2) = 2 ! GRIB Edition Number (currently 2) listsec1(1) = 7 ! Originating Centre (Common Code Table C-1) - listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 + listsec1(2) = 0 ! Originating Sub-centre (local table) EMC=4 listsec1(3) = 0 ! GRIB Master Tables Version Number (Code Table 1.0) ! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) @@ -749,7 +749,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) bmp=.true. ! Assign Template 5 - idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + idrtnum = 40 ! Template 5.0 (Grid Point Data - Simple Packing) ! Populate idrtmpl for Template 5.0 idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) @@ -758,7 +758,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) ! Reserved fields for Template 5.0 - idrtmpl(6:11) = 0 ! Reserved for future use +! idrtmpl(6:11) = 0 ! Reserved for future use idrtlen=size(idrtmpl) From 5b400f44ebce557c523e14c90865f353ae14a989 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 13 Dec 2024 11:05:38 -0500 Subject: [PATCH 049/124] changed parameters for sections --- src/ocnicepost.fd/utils_mod.F90 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 39bc5d2b..0ba6183b 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -636,10 +636,10 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) listsec0(2) = 2 ! GRIB Edition Number (currently 2) listsec1(1) = 7 ! Originating Centre (Common Code Table C-1) - listsec1(2) = 0 ! Originating Sub-centre (local table) EMC=4 - listsec1(3) = 0 ! GRIB Master Tables Version Number (Code Table 1.0) + listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 + listsec1(3) = 33 ! GRIB Master Tables Version Number (Code Table 1.0) ! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) - listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) + listsec1(4) = 0 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) listsec1(6) = ref_time(1) ! Reference Time - Year -4digits listsec1(7) = ref_time(2) ! Reference Time - Month @@ -713,6 +713,14 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) do n=1,nflds + listsec0(1) = g2d(n)%var_g1 + + call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) + if (ierr /= 0) then + write(logunit, *) 'Error initializing GRIB2 message', ierr + return + end if + write(logunit, *) 'n, nflds, npt: ', n, nflds, npt call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here @@ -749,7 +757,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) bmp=.true. ! Assign Template 5 - idrtnum = 40 ! Template 5.0 (Grid Point Data - Simple Packing) + idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) ! Populate idrtmpl for Template 5.0 idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) From ba3d7f60f606af083ea50b4d7e5be7647abec759 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 13 Dec 2024 12:01:31 -0500 Subject: [PATCH 050/124] changed parameters for sections --- src/ocnicepost.fd/utils_mod.F90 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 0ba6183b..8926d7e0 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -713,6 +713,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) do n=1,nflds + allocate(cgrib(max_bytes)) ! allocate + listsec0(1) = g2d(n)%var_g1 call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) @@ -777,14 +779,20 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) return end if + + call gribend(cgrib,max_bytes,lengrib,ierr) + write(logunit, *) 'gribend status=',ierr + write(logunit, *) 'length of the final GRIB2 message in octets =',lengrib + call wryte(lunout, lengrib, cgrib) + + deallocate(cgrib) + end do - call gribend(cgrib,max_bytes,lengrib,ierr) - write(logunit, *) 'gribend status=',ierr - write(logunit, *) 'length of the final GRIB2 message in octets =',lengrib - call wryte(lunout, lengrib, cgrib) + baclose(lunout, ierr) deallocate(cgrib) + return end subroutine write_grib2_2d From 7fa9ec8b5c8d4983e04e5d078025eb2b44a47c7a Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 13 Dec 2024 12:09:37 -0500 Subject: [PATCH 051/124] changed parameters for sections-modified the code fix issues --- src/ocnicepost.fd/utils_mod.F90 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 8926d7e0..8c184744 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -702,11 +702,11 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) write(logunit, *) 'forcast time: ', fortime write(logunit, *) 'refference time: ', ref_time - call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) - if (ierr /= 0) then - write(logunit, *) 'Error initializing GRIB2 message', ierr - return - end if +! call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) +! if (ierr /= 0) then +! write(logunit, *) 'Error initializing GRIB2 message', ierr +! return +! end if ideflist=0 idefnum=0 @@ -787,13 +787,13 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) deallocate(cgrib) - end do + end do - baclose(lunout, ierr) + call baclose(lunout, ierr) - deallocate(cgrib) - - return + deallocate(cgrib) + + return end subroutine write_grib2_2d From a2e35e3b7c746640cc5a40c534a385af0b76acfe Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 13 Dec 2024 12:20:04 -0500 Subject: [PATCH 052/124] changed parameters for sections-modified the code fix issues --- src/ocnicepost.fd/utils_mod.F90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 8c184744..80da4aee 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -620,8 +620,6 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) max_bytes = npt * 4 ! Estimated max bytes - allocate(cgrib(max_bytes)) ! allocate - call getlun(lunout) call baopenw(lunout, trim(fname), ierr) if (ierr /= 0) then From e2a198768d5afba48cbf328ed3a35b5546eeca42 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 13 Dec 2024 12:27:38 -0500 Subject: [PATCH 053/124] changed parameters for sections-modified the code fix issues --- src/ocnicepost.fd/utils_mod.F90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 80da4aee..f52096af 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -788,8 +788,6 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) end do call baclose(lunout, ierr) - - deallocate(cgrib) return From 79ce23ca809b26e0635538996906b5c85ab34d33 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 13 Dec 2024 12:59:26 -0500 Subject: [PATCH 054/124] changed parameters for section1 for missing parammeters --- src/ocnicepost.fd/utils_mod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index f52096af..1d08506e 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -634,10 +634,10 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) listsec0(2) = 2 ! GRIB Edition Number (currently 2) listsec1(1) = 7 ! Originating Centre (Common Code Table C-1) - listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 - listsec1(3) = 33 ! GRIB Master Tables Version Number (Code Table 1.0) + listsec1(2) = 3 ! Originating Sub-centre (local table) EMC=4 + listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0) ! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) - listsec1(4) = 0 ! GRIB Local Tables Version Number (Code Table 1.1) + listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) listsec1(6) = ref_time(1) ! Reference Time - Year -4digits listsec1(7) = ref_time(2) ! Reference Time - Month From 8e39da195a194822a2c2fc540b58c251676f852e Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 13 Dec 2024 13:39:21 -0500 Subject: [PATCH 055/124] changed parameters for section1 for missing parammeters --- src/ocnicepost.fd/utils_mod.F90 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 1d08506e..735095a5 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -634,8 +634,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) listsec0(2) = 2 ! GRIB Edition Number (currently 2) listsec1(1) = 7 ! Originating Centre (Common Code Table C-1) - listsec1(2) = 3 ! Originating Sub-centre (local table) EMC=4 - listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0) + listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 + listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 ! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) @@ -735,8 +735,8 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) jpdt(1)=g2d(n)%var_g5 ! cat number jpdt(2)=g2d(n)%var_g6 ! parm number jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) - jpdt(4)=0 ! - jpdt(5)=0 ! + jpdt(4)=1 ! 1: Forecast initialized from an earlier analysis + jpdt(5)=0 ! Code ON388 Table A- no ice /ocean GFS jpdt(6)=1 ! unit (Hour=1) jpdt(7)=fortime ! forecast hour jpdt(8)=g2d(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) @@ -757,7 +757,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) bmp=.true. ! Assign Template 5 - idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + idrtnum = 2 ! Template 5.0 (Grid Point Data - Simple Packing) ! Populate idrtmpl for Template 5.0 idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) From b1ec97e99f0713272fb687352cc19eb6b9b8dfcc Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 13 Dec 2024 13:54:35 -0500 Subject: [PATCH 056/124] changed parameters for section1 for missing parammeters --- src/ocnicepost.fd/utils_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 735095a5..c3f82881 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -608,7 +608,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(5) + integer :: jgdt(19), jpdt(15), idrtmpl(16) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist @@ -766,7 +766,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) ! Reserved fields for Template 5.0 -! idrtmpl(6:11) = 0 ! Reserved for future use + idrtmpl(6:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) From 01af797b12fdda56a3f81b56c953ce0629bd1c01 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 17 Dec 2024 11:49:54 -0500 Subject: [PATCH 057/124] added 3D and Ocean writer capabilities - modified codes/tables --- .vscode/settings.json | 3 + parm/ocnicepost/ice.csv | 20 +- parm/ocnicepost/ocean.csv | 46 ++--- src/ocnicepost.fd/ocnicepost.F90 | 10 +- src/ocnicepost.fd/utils_mod.F90 | 330 +++++++++++++++++++++++++------ 5 files changed, 307 insertions(+), 102 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..63e4335f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "fortran.fortls.disabled": true +} \ No newline at end of file diff --git a/parm/ocnicepost/ice.csv b/parm/ocnicepost/ice.csv index 2f0aa621..a5835b53 100644 --- a/parm/ocnicepost/ice.csv +++ b/parm/ocnicepost/ice.csv @@ -1,11 +1,11 @@ ! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,g1,g2,g3,g4,gc5,gc6,gc7,gc8 - 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,2,0,0,2,1,101,0 - 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,2,0,0,2,16,101,0 - 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,2,0,0,2,0,101,0 - 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,2,0,0,2,8,101,0 - 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,2,0,0,2,4,101,0 - 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,2,0,0,2,5,101,0 - 'frzmlt_h',2, 'Ct', 'conserve', '', '', 'FRZMLTPOT', 'freeze/melt potential', 'W m-2',10,2,0,0,2,27,101,0 - 'albsni_h',2, 'Ct', 'bilinear', '', '', 'ALBDOICE', 'Albedo', 'Numeric',10,2,0,0,2,14,101,0 -'mlt_onset_h',2, 'Ct', 'bilinear', '', '', 'MLTDATE', 'melt onset date', 'Numeric',10,2,0,0,2,28,101,0 -'frz_onset_h',2, 'Ct', 'bilinear', '', '', 'FRZDATE', 'freeze onset date', 'Numeric',10,2,0,0,2,29,101,0 + 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,2,0,0,2,1,1,0 + 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,2,0,0,2,16,1,0 + 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,2,0,0,2,0,1,0 + 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,2,0,0,2,8,1,0 + 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,2,0,0,2,4,1,0 + 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,2,0,0,2,5,1,0 + 'frzmlt_h',2, 'Ct', 'conserve', '', '', 'FRZMLTPOT', 'freeze/melt potential', 'W m-2',10,2,0,0,2,27,1,0 + 'albsni_h',2, 'Ct', 'bilinear', '', '', 'ALBDOICE', 'Albedo', 'Numeric',10,2,0,0,2,14,1,0 +'mlt_onset_h',2, 'Ct', 'bilinear', '', '', 'MLTDATE', 'melt onset date', 'Numeric',10,2,0,0,2,28,1,0 +'frz_onset_h',2, 'Ct', 'bilinear', '', '', 'FRZDATE', 'freeze onset date', 'Numeric',10,2,0,0,2,29,1,0 diff --git a/parm/ocnicepost/ocean.csv b/parm/ocnicepost/ocean.csv index 1d853e98..0d1333e4 100644 --- a/parm/ocnicepost/ocean.csv +++ b/parm/ocnicepost/ocean.csv @@ -1,26 +1,20 @@ -! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair - 'SSH', 2 ,'Ct' , 'bilinear' , '', '' - 'SST', 2 ,'Ct' , 'bilinear' , '', '' - 'SSS', 2 ,'Ct' , 'bilinear' , '', '' - 'speed', 2 ,'Ct' , 'bilinear' , '', '' - 'ePBL', 2 ,'Ct' , 'bilinear' , '', '' - 'MLD_003', 2 ,'Ct' , 'bilinear' , '', '' - 'MLD_0125', 2 ,'Ct' , 'bilinear' , '', '' - 'latent', 2 ,'Ct' , 'conserve' , '', '' - 'sensible', 2 ,'Ct' , 'conserve' , '', '' - 'SW', 2 ,'Ct' , 'conserve' , '', '' - 'LW', 2 ,'Ct' , 'conserve' , '', '' - 'evap', 2 ,'Ct' , 'conserve' , '', '' - 'lprec', 2 ,'Ct' , 'conserve' , '', '' - 'fprec', 2 ,'Ct' , 'conserve' , '', '' -'LwLatSens', 2 ,'Ct' , 'conserve' , '', '' - 'Heat_PmE', 2 ,'Ct' , 'conserve' , '', '' - 'SSU', 2 ,'Cu' , 'bilinear' , 'SSV' , 'Cv' - 'SSV', 2 ,'Cv' , 'bilinear' , 'SSU' , 'Cu' - 'taux', 2 ,'Cu' , 'conserve' , 'tauy' , 'Cv' - 'tauy', 2 ,'Cv' , 'conserve' , 'taux' , 'Cu' - 'temp', 3 ,'Ct' , 'bilinear' , '', '' - 'tob', 2 ,'Ct' , 'bilinear' , '', '' - 'so', 3 ,'Ct' , 'bilinear' , '', '' - 'uo', 3 ,'Cu' , 'bilinear' , 'vo' , 'Cv' - 'vo', 3 ,'Cv' , 'bilinear' , 'uo' , 'Cu' +! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,g1,g2,g3,g4,gc5,gc6,gc7,gc8 + 'SSH',2,'Ct' , 'bilinear' , '', '','SSHG','Sea Surface Height Relative to Geoid','m',10,0,7,1,3,195,101,0 + 'SST',2,'Ct' , 'bilinear' , '', '','WTMP','Water Temperature','K',10,1,0,0,3,0,101,0 + 'SSS',2,'Ct' , 'bilinear' , '', '','SALINITY','Salinity','psu',10,0,7,1,3,21,101,0 + 'speed',2,'Ct' , 'bilinear' , '', '','SPC','Current Speed','m/s',10,1,0,0,1,1,101,0 + 'MLD_003',2,'Ct' , 'bilinear' , '', '','WDEPTH','Water Depth','m',10,1,0,0,4,14,101,0 + 'latent',2,'Ct' , 'conserve' , '', '','LHTFL','Latent Heat Net Flux','W/m^2',0,1,0,0,0,10,101,0 + 'sensible',2,'Ct' , 'conserve' , '', '','SHTFL','Sensible Heat Net Flux','W/m^2',0,1,0,0,0,11,101,0 + 'SW',2,'Ct' , 'conserve' , '', '','NSWRF','Net Short Wave Radiation Flux','W/m^2',0,1,0,0,4,9,101,0 + 'LW',2,'Ct' , 'conserve' , '', '','NLWRF','Net Long-Wave Radiation Flux','W/m^2',0,1,0,0,5,5,101,0 +'LwLatSens',2,'Ct' , 'conserve' , '', '','THFLX','Total Downward Heat Flux at Surface','W/m^2',0,0,7,1,0,197,101,0 + 'Heat_PmE',2,'Ct' , 'conserve' , '', '','DWHFLUX','Downward Heat Flux','W/m^2',10,1,0,0,3,4,101,0 + 'SSU',2,'Cu' , 'bilinear' , 'SSV' , 'Cv','UOGRD','U-Component of Current','m/s',10,1,0,0,1,2,101,0 + 'SSV',2,'Cv' , 'bilinear' , 'SSU' , 'Cu','VOGRD','V-Component of Current','m/s',10,1,0,0,1,3,101,0 + 'taux',2,'Cu' , 'conserve' , 'tauy' , 'Cv','XCOMPSS','x-component Surface Stress','N/m^2',10,1,0,0,3,7,101,0 + 'tauy',2,'Cv' , 'conserve' , 'taux' , 'Cu','YCOMPSS','y-component Surface Stress','N/m^2',10,1,0,0,3,7,101,0 + 'temp',3,'Ct' , 'bilinear' , '', '','WTMP','Water Temperature','K',10,1,0,0,3,0,168,0 + 'so',3,'Ct' , 'bilinear' , '', '','SALIN','3-D Salinity','psu',10,0,7,1,4,193,168,0 + 'uo',3,'Cu' , 'bilinear' , 'vo' , 'Cv','UOGRD','U-Component of Current','m/s',10,1,0,0,1,2,168,0 + 'vo',3,'Cv' , 'bilinear' , 'uo' , 'Cu','VOGRD','V-Component of Current','m/s',10,1,0,0,1,3,168,0 diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 01b06b07..7d9720b9 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -403,11 +403,11 @@ program ocnicepost call write_grib2_2d(gout, g2d, (/nxr,nyr/), nconsd2d+nbilin2d, grib2d) -! if (allocated(rgb3d)) then -! gout = trim(ftype)//'.'//trim(fdst)//'_3D.gb2' -! call write_grib2_3d(gout, b3d, (/nxr,nyr,nlevs/), nbilin3d, rgb3d) -! if (debug) write(logunit, '(a)')'GRIB2 3D output file: '//trim(gout) -! end if + if (allocated(rgb3d)) then + gout = trim(ftype)//'.'//trim(fdst)//'_3D.gb2' + call write_grib2_3d(gout, b3d, (/nxr,nyr,nlevs/), nbilin3d, rgb3d) + if (debug) write(logunit, '(a)')'GRIB2 3D output file: '//trim(gout) + end if end if stop diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index c3f82881..3326d1dd 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -40,6 +40,7 @@ module utils_mod public remap public dumpnc public write_grib2_2d + public write_grib2_3d public nf90_err contains @@ -582,7 +583,7 @@ end subroutine dumpnc1d !----------------------------------------------------------------------------------- - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Write Grib2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Write Grib2 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!This subroutine write Grib2 file modified messages!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !----------------------------------------------------------------------------------- @@ -623,7 +624,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) call getlun(lunout) call baopenw(lunout, trim(fname), ierr) if (ierr /= 0) then - write(logunit, *) 'Error opening grib2 file ', trim(fname) + write(0, *) 'Error opening grib2 file ', trim(fname) return end if @@ -633,7 +634,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) listsec0(1) = g2d(1)%var_g1 ! Discipline - GRIB Master Table Number (Code Table 0.0) listsec0(2) = 2 ! GRIB Edition Number (currently 2) - listsec1(1) = 7 ! Originating Centre (Common Code Table C-1) + listsec1(1) = g2d(1)%var_g3 ! Originating Centre (Common Code Table C-1) listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 ! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) @@ -690,34 +691,29 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) igdtlen=size(jgdt) - !!!!these are for debuging (remove after done) - write(logunit, *) 'listsec0, listsec1: ', listsec0, listsec1 - write(logunit, *) 'igdtnum, igdtlen: ', igdtnum, igdtlen - write(logunit, *) 'jgdt: ', jgdt - write(logunit, *) 'igds: ', igds - write(logunit, *) 'dij: ', dij - write(logunit, *) 'max_bytes: ', max_bytes - write(logunit, *) 'forcast time: ', fortime - write(logunit, *) 'refference time: ', ref_time - -! call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) -! if (ierr /= 0) then -! write(logunit, *) 'Error initializing GRIB2 message', ierr -! return -! end if + if (debug) then + write(logunit, *) 'listsec0, listsec1: ', listsec0, listsec1 + write(logunit, *) 'igdtnum, igdtlen: ', igdtnum, igdtlen + write(logunit, *) 'jgdt: ', jgdt + write(logunit, *) 'igds: ', igds + write(logunit, *) 'dij: ', dij + write(logunit, *) 'max_bytes: ', max_bytes + write(logunit, *) 'forcast time: ', fortime + write(logunit, *) 'refference time: ', ref_time + end if ideflist=0 idefnum=0 do n=1,nflds - allocate(cgrib(max_bytes)) ! allocate + allocate(cgrib(max_bytes)) listsec0(1) = g2d(n)%var_g1 call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) if (ierr /= 0) then - write(logunit, *) 'Error initializing GRIB2 message', ierr + write(0, *) 'Error initializing GRIB2 message', ierr return end if @@ -725,7 +721,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then - write(logunit, *) 'Error adding grid to GRIB2 message', ierr + write(0, *) 'Error adding grid to GRIB2 message', ierr return end if @@ -737,7 +733,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) jpdt(4)=1 ! 1: Forecast initialized from an earlier analysis jpdt(5)=0 ! Code ON388 Table A- no ice /ocean GFS - jpdt(6)=1 ! unit (Hour=1) + jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 jpdt(7)=fortime ! forecast hour jpdt(8)=g2d(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) jpdt(9)=0 ! level value @@ -747,7 +743,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) jpdt(14)=0 jpdt(15)=0 - write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) + if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) ipdtlen=size(jpdt) @@ -757,27 +753,27 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) bmp=.true. ! Assign Template 5 - idrtnum = 2 ! Template 5.0 (Grid Point Data - Simple Packing) + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) +! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) - ! Populate idrtmpl for Template 5.0 + ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) - ! Reserved fields for Template 5.0 - idrtmpl(6:16) = 0 ! Reserved for future use + ! Reserved fields + idrtmpl(6:16) = 0 ! Reserved for future use (for complex) idrtlen=size(idrtmpl) call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,n), npt, ibmap, bmp, ierr) if (ierr /= 0) then - write(logunit, *) 'Error adding field to GRIB2 message', ierr + write(0, *) 'Error adding field to GRIB2 message', ierr return end if - call gribend(cgrib,max_bytes,lengrib,ierr) write(logunit, *) 'gribend status=',ierr write(logunit, *) 'length of the final GRIB2 message in octets =',lengrib @@ -794,6 +790,247 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) end subroutine write_grib2_2d + + !----------------------------------------------------------------------------------- + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Write Grib2 3D!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!This subroutine write Grib2 file modified messages!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !----------------------------------------------------------------------------------- + + subroutine write_grib2_3d(fname, b3d, dims, nflds, field) + + implicit none + + character(len=*), intent(in) :: fname + type(vardefs), allocatable, dimension(:) :: b3d + integer, intent(in) :: dims(3) + integer, intent(in) :: nflds + real, intent(in) :: field( dims(1) * dims(2) , dims(3) , nflds ) + + ! internal variables + integer(4) :: max_bytes, lengrib + integer :: ref_time(6) + integer :: lunout, ierr + integer :: fortime, dij, npt + CHARACTER(len=1),allocatable,dimension(:) :: cgrib + + ! GRIB2 metadata arrays + integer :: listsec0(2), listsec1(13) + integer :: igdtnum, ipdtnum, idrtnum + integer :: igdtlen, ipdtlen, idrtlen + integer :: jgdt(19), jpdt(15), idrtmpl(16) + integer(4) :: igds(5) + integer :: numcoord, ibmap + real(4) :: coordlist + integer :: ideflist, idefnum + logical :: bmp( dims(1) * dims(2) ) + + integer :: n, lon0, lon1, lat0, lat1, nlay, lyr + real, dimension(40) :: dep1 + real, dimension(28) :: dep2 + real, dimension(:), allocatable :: dep + + npt = dims(1) * dims(2) + + max_bytes = npt * 4 + + call getlun(lunout) + call baopenw(lunout, trim(fname), ierr) + if (ierr /= 0) then + write(0, *) 'Error opening grib2 file ', trim(fname) + return + end if + + call retrieve_time( fortime , ref_time ) + + ! Initialize GRIB2 message sections + listsec0(1) = g2d(1)%var_g1 ! Discipline - GRIB Master Table Number (Code Table 0.0) + listsec0(2) = 2 ! GRIB Edition Number (currently 2) + + listsec1(1) = g2d(1)%var_g3 ! Originating Centre (Common Code Table C-1) + listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 + listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 +! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) + listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) + listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) + listsec1(6) = ref_time(1) ! Reference Time - Year -4digits + listsec1(7) = ref_time(2) ! Reference Time - Month + listsec1(8) = ref_time(3) ! Reference Time - Day + listsec1(9) = ref_time(4) ! Reference Time - Hour + listsec1(10) = ref_time(5) ! Reference Time - Minute + listsec1(11) = ref_time(6) ! Reference Time - Second + listsec1(12) = 0 ! Production status of data (Code Table 1.3) + listsec1(13) = 1 ! Type of processed data (Code Table 1.4) + + dep1=(5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155,& + 165, 175, 185, 195, 205, 215, 226, 241, 267, 309, 374, 467, 594, 757, 960,& + 1204, 1490, 1817, 2184, 2587, 3024, 3489, 3977, 4481) + + dep2=(5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155,& + 165, 175, 185, 195, 205, 215, 226, 241, 267, 309, 374, 467) + + if (dims(1) == 1440 .and. dims(2) == 721) then ! 1/4deg rectilinear + dij = 250000 + nlay = 40 + dep = dep1 + end if + + if (dims(1) == 720 .and. dims(2) == 361) then ! 1/2deg rectilinear + dij = 500000 + nlay = 40 + dep = dep1 + end if + + if (dims(1) == 360 .and. dims(2) == 181) then ! 1deg rectilinear + dij = 1000000 + nlay = 40 + dep = dep1 + end if + + if (dims(1) == 72 .and. dims(2) == 36 ) then ! 5deg rectilinear + dij = 5000000 + nlay = 25 + dep = dep2 + end if + + lon0 = 0 + lon1 = 360000000 - dij + lat0 = -90000000 + lat1 = 90000000 + + ! Populate the jgdt array for Template 3.0 (changed parameters to current grib2 files) + jgdt(1) = 6 + jgdt(2) = 0 + jgdt(3) = 0 + jgdt(4) = 0 + jgdt(5) = 0 + jgdt(6) = 0 + jgdt(7) = 0 + jgdt(8) = dims(1) + jgdt(9) = dims(2) + jgdt(10) = 0 + jgdt(11) = 0 !-1 + jgdt(12) = lat0 + jgdt(13) = lon0 + jgdt(14) = 48 !0 + jgdt(15) = lat1 + jgdt(16) = lon1 + jgdt(17) = dij + jgdt(18) = dij + jgdt(19) = 0 !64 + + igdtnum=0 + ! Define igds GRIB2 - SECTION 3 + igds(1) = 0 ! Source of grid definition + igds(2) = npt ! Number of grid points + igds(3) = 0 ! Number of octets for each additional grid points definition + igds(4) = 0 ! Interpretation of list for optional points definition + igds(5) = igdtnum ! GRIB2 - CODE TABLE 3.1 + + igdtlen=size(jgdt) + + if (debug) then + write(logunit, *) 'listsec0, listsec1: ', listsec0, listsec1 + write(logunit, *) 'igdtnum, igdtlen: ', igdtnum, igdtlen + write(logunit, *) 'jgdt: ', jgdt + write(logunit, *) 'igds: ', igds + write(logunit, *) 'dij: ', dij + write(logunit, *) 'max_bytes: ', max_bytes + write(logunit, *) 'forcast time: ', fortime + write(logunit, *) 'refference time: ', ref_time + end if + + ideflist=0 + idefnum=0 + + do lyr=1,nlay + + do n=1,nflds + + allocate(cgrib(max_bytes)) + + listsec0(1) = g2d(n)%var_g1 + + call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) + if (ierr /= 0) then + write(0, *) 'Error initializing GRIB2 message', ierr + return + end if + + if (debug) write(logunit, *) 'n, nflds, npt, lay: ', n, nflds, npt, lyr + + call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here + if (ierr /= 0) then + write(0, *) 'Error adding grid to GRIB2 message', ierr + return + end if + +! Create Section 4 parametrs + ipdtnum=0 + + jpdt(1)=g2d(n)%var_g5 ! cat number + jpdt(2)=g2d(n)%var_g6 ! parm number + jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) + jpdt(4)=1 ! 1: Forecast initialized from an earlier analysis + jpdt(5)=0 ! Code ON388 Table A- no ice /ocean GFS + jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 + jpdt(7)=fortime ! forecast hour + jpdt(8)=g2d(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) + jpdt(9)=dep(lyr) ! level value + jpdt(10)=255 + jpdt(12)=0 + jpdt(13)=0 + jpdt(14)=0 + jpdt(15)=0 + + if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) + + ipdtlen=size(jpdt) + + numcoord=0 + coordlist=0. ! needed for hybrid vertical coordinate + ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + bmp=.true. + + ! Assign Template 5 + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) +! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + + ! Populate idrtmpl + idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) + idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) + idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) + idrtmpl(4) = 0 ! Number of bits for each packed value + idrtmpl(5) = 0 ! Type of original field values (0 = floating point) + ! Reserved fields + idrtmpl(6:16) = 0 ! Reserved for future use (for complex) + + idrtlen=size(idrtmpl) + + call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & + idrtnum, idrtmpl, idrtlen, field(:,lyr,n), npt, ibmap, bmp, ierr) + if (ierr /= 0) then + write(0, *) 'Error adding field to GRIB2 message', ierr + return + end if + + call gribend(cgrib, max_bytes, lengrib, ierr) + write(logunit, *) 'gribend status=', ierr + write(logunit, *) 'length of the final GRIB2 message in octets =', lengrib + call wryte(lunout, lengrib, cgrib) + + deallocate(cgrib) + + end do + end do + + call baclose(lunout, ierr) + + return + +end subroutine write_grib2_3d + + !-------------------------------------------------------------------------------------- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!To get a lun used for bacio!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -814,9 +1051,6 @@ subroutine getlun(lun) end subroutine getlun - - - !-------------------------------------------------------------------------------------- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!Retrieve Time From Input File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -837,16 +1071,15 @@ subroutine retrieve_time(forecast_hour, ref_time) integer :: ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec integer :: year, month, day, hour double precision :: hours_offset - + call nf90_err(nf90_open(trim(input_file), nf90_nowrite, ncid), 'opening '//input_file) call nf90_err(nf90_inq_varid(ncid, 'time', time_varid), 'get variable ID: time') call nf90_err(nf90_get_var(ncid, time_varid, forecast_hour), 'get variable time') call nf90_err(nf90_get_att(ncid, time_varid, 'units', units_str), 'get attribute: units') - - read(units_str(12:29), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & ! (12:29) for testing ice model (need to be changed request sent) - (13:30) is final and for testing the ocean model + read(units_str(13:30), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & ! (12:29) for testing ice model (need to be changed request sent) - (13:30) is final and for testing the ocean model ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec - forecast_hour=24*forecast_hour ! just for testing ice model (remove it once ice time unit fixed) +! forecast_hour=24*forecast_hour ! just for testing ice model (remove it once ice time unit fixed) ref_time(1) = ref_year ref_time(2) = ref_month @@ -855,16 +1088,9 @@ subroutine retrieve_time(forecast_hour, ref_time) ref_time(5) = ref_min ref_time(6) = ref_sec -! call nf90_err(nf90_inq_varid(ncid, 'average_T1', T1_varid), 'get variable ID: average_T1') -! call nf90_err(nf90_get_var(ncid, T1_varid, T1), 'get variable: average_T1') -! call nf90_err(nf90_inq_varid(ncid, 'average_T2', T2_varid), 'get variable ID: average_T2') -! call nf90_err(nf90_get_var(ncid, T2_varid, T2), 'get variable: average_T2') -! call nf90_err(nf90_close(ncid), 'close: '//input_file) - end subroutine retrieve_time - !---------------------------------------------------------- ! handle netcdf errors !---------------------------------------------------------- @@ -882,21 +1108,3 @@ subroutine nf90_err(ierr, string) end if end subroutine nf90_err end module utils_mod - - - !-------------------------------------------------------------------------------------- - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!handle grib2 errors!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !-------------------------------------------------------------------------------------- -subroutine grib_err(ierr, msg) - implicit none - integer, intent(in) :: ierr - character(len=*), intent(in) :: msg - - if (ierr /= 0) then - write(0, *) "GRIB2 Error:", trim(msg), "Error code:", ierr - !stop ierr - stop 99 - end if -end subroutine grib_err From 17a1f16eac482ec597c328c67fb40712f23830ee Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 17 Dec 2024 12:04:40 -0500 Subject: [PATCH 058/124] added 3D and Ocean writer capabilities - modified codes/tables-changed varnames --- src/ocnicepost.fd/utils_mod.F90 | 45 +++++++++++++++++---------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 3326d1dd..e40f936c 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -588,12 +588,12 @@ end subroutine dumpnc1d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !----------------------------------------------------------------------------------- - subroutine write_grib2_2d(fname, g2d, dims, nflds, field) + subroutine write_grib2_2d(fname, gcf, dims, nflds, field) implicit none character(len=*), intent(in) :: fname - type(vardefs), allocatable, dimension(:) :: g2d + type(vardefs), allocatable, dimension(:) :: gcf integer, intent(in) :: dims(2) integer, intent(in) :: nflds real, intent(in) :: field(dims(1)*dims(2),nflds) @@ -631,13 +631,13 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) call retrieve_time( fortime , ref_time ) ! Initialize GRIB2 message sections - listsec0(1) = g2d(1)%var_g1 ! Discipline - GRIB Master Table Number (Code Table 0.0) + listsec0(1) = gcf(1)%var_g1 ! Discipline - GRIB Master Table Number (Code Table 0.0) listsec0(2) = 2 ! GRIB Edition Number (currently 2) - listsec1(1) = g2d(1)%var_g3 ! Originating Centre (Common Code Table C-1) + listsec1(1) = gcf(1)%var_g3 ! Originating Centre (Common Code Table C-1) listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 -! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) +! listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) listsec1(6) = ref_time(1) ! Reference Time - Year -4digits @@ -709,7 +709,7 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) allocate(cgrib(max_bytes)) - listsec0(1) = g2d(n)%var_g1 + listsec0(1) = gcf(n)%var_g1 call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) if (ierr /= 0) then @@ -728,14 +728,14 @@ subroutine write_grib2_2d(fname, g2d, dims, nflds, field) ! Create Section 4 parametrs ipdtnum=0 - jpdt(1)=g2d(n)%var_g5 ! cat number - jpdt(2)=g2d(n)%var_g6 ! parm number + jpdt(1)=gcf(n)%var_g5 ! cat number + jpdt(2)=gcf(n)%var_g6 ! parm number jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) jpdt(4)=1 ! 1: Forecast initialized from an earlier analysis jpdt(5)=0 ! Code ON388 Table A- no ice /ocean GFS jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 jpdt(7)=fortime ! forecast hour - jpdt(8)=g2d(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) + jpdt(8)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) jpdt(9)=0 ! level value jpdt(10)=255 jpdt(12)=0 ! @@ -797,12 +797,12 @@ end subroutine write_grib2_2d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !----------------------------------------------------------------------------------- - subroutine write_grib2_3d(fname, b3d, dims, nflds, field) + subroutine write_grib2_3d(fname, gcf, dims, nflds, field) implicit none character(len=*), intent(in) :: fname - type(vardefs), allocatable, dimension(:) :: b3d + type(vardefs), allocatable, dimension(:) :: gcf integer, intent(in) :: dims(3) integer, intent(in) :: nflds real, intent(in) :: field( dims(1) * dims(2) , dims(3) , nflds ) @@ -844,13 +844,13 @@ subroutine write_grib2_3d(fname, b3d, dims, nflds, field) call retrieve_time( fortime , ref_time ) ! Initialize GRIB2 message sections - listsec0(1) = g2d(1)%var_g1 ! Discipline - GRIB Master Table Number (Code Table 0.0) + listsec0(1) = gcf(1)%var_g1 ! Discipline - GRIB Master Table Number (Code Table 0.0) listsec0(2) = 2 ! GRIB Edition Number (currently 2) - listsec1(1) = g2d(1)%var_g3 ! Originating Centre (Common Code Table C-1) + listsec1(1) = gcf(1)%var_g3 ! Originating Centre (Common Code Table C-1) listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 -! listsec1(3) = g2d(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) +! listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) listsec1(6) = ref_time(1) ! Reference Time - Year -4digits @@ -862,12 +862,12 @@ subroutine write_grib2_3d(fname, b3d, dims, nflds, field) listsec1(12) = 0 ! Production status of data (Code Table 1.3) listsec1(13) = 1 ! Type of processed data (Code Table 1.4) - dep1=(5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155,& + dep1=(/ 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155,& 165, 175, 185, 195, 205, 215, 226, 241, 267, 309, 374, 467, 594, 757, 960,& - 1204, 1490, 1817, 2184, 2587, 3024, 3489, 3977, 4481) + 1204, 1490, 1817, 2184, 2587, 3024, 3489, 3977, 4481 /) - dep2=(5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155,& - 165, 175, 185, 195, 205, 215, 226, 241, 267, 309, 374, 467) + dep2=(/ 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155,& + 165, 175, 185, 195, 205, 215, 226, 241, 267, 309, 374, 467 /) if (dims(1) == 1440 .and. dims(2) == 721) then ! 1/4deg rectilinear dij = 250000 @@ -949,7 +949,7 @@ subroutine write_grib2_3d(fname, b3d, dims, nflds, field) allocate(cgrib(max_bytes)) - listsec0(1) = g2d(n)%var_g1 + listsec0(1) = gcf(n)%var_g1 call gribcreate(cgrib, max_bytes, listsec0, listsec1, ierr) if (ierr /= 0) then @@ -968,14 +968,14 @@ subroutine write_grib2_3d(fname, b3d, dims, nflds, field) ! Create Section 4 parametrs ipdtnum=0 - jpdt(1)=g2d(n)%var_g5 ! cat number - jpdt(2)=g2d(n)%var_g6 ! parm number + jpdt(1)=gcf(n)%var_g5 ! cat number + jpdt(2)=gcf(n)%var_g6 ! parm number jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) jpdt(4)=1 ! 1: Forecast initialized from an earlier analysis jpdt(5)=0 ! Code ON388 Table A- no ice /ocean GFS jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 jpdt(7)=fortime ! forecast hour - jpdt(8)=g2d(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) + jpdt(8)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) jpdt(9)=dep(lyr) ! level value jpdt(10)=255 jpdt(12)=0 @@ -1107,4 +1107,5 @@ subroutine nf90_err(ierr, string) stop 99 end if end subroutine nf90_err + end module utils_mod From 524542db4b885a5ab46f34894e45c742a5756201 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 17 Dec 2024 12:12:56 -0500 Subject: [PATCH 059/124] added 3D and Ocean writer capabilities - modified codes/tables-changed varnames --- parm/ocnicepost/ocean_mx025_to_0p25.nml | 1 + src/ocnicepost.fd/ocnicepost.F90 | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/parm/ocnicepost/ocean_mx025_to_0p25.nml b/parm/ocnicepost/ocean_mx025_to_0p25.nml index 0b800724..567bcd80 100644 --- a/parm/ocnicepost/ocean_mx025_to_0p25.nml +++ b/parm/ocnicepost/ocean_mx025_to_0p25.nml @@ -7,5 +7,6 @@ maskvar='temp' sinvar='sin_rot' cosvar='cos_rot' angvar='' +grib2=.true. debug=.false. / diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 7d9720b9..3ced0aea 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -32,7 +32,7 @@ program ocnicepost use arrays_mod , only : b2d, c2d, b3d, rgb2d, rgc2d, rgb3d, dstlon, dstlat, setup_packing use arrays_mod , only : nbilin2d, nbilin3d, nconsd2d, bilin2d, bilin3d, consd2d use masking_mod, only : mask2d, mask3d, rgmask2d, rgmask3d, remap_masks - use utils_mod , only : getfield, packarrays, remap, dumpnc, nf90_err, write_grib2_2d + use utils_mod , only : getfield, packarrays, remap, dumpnc, nf90_err, write_grib2_2d, write_grib2_3d implicit none From cf498c8ff9884c4b8782e2252b3580dad889d324 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 17 Dec 2024 12:41:36 -0500 Subject: [PATCH 060/124] added 3D and Ocean writer capabilities - modified codes/tables-changed varnames --- src/ocnicepost.fd/ocnicepost.F90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 3ced0aea..d08b046d 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -34,7 +34,6 @@ program ocnicepost use masking_mod, only : mask2d, mask3d, rgmask2d, rgmask3d, remap_masks use utils_mod , only : getfield, packarrays, remap, dumpnc, nf90_err, write_grib2_2d, write_grib2_3d - implicit none character(len=120) :: wgtsfile @@ -55,7 +54,6 @@ program ocnicepost real, allocatable, dimension(:,:) :: grib2d !< 2D destination grib2 concat array type(vardefs), allocatable, dimension(:) :: g2d !< concatinated variable metadata for 2D source fields remap - real(kind=8) :: timestamp character(len= 40) :: timeunit, timecal character(len= 20) :: vname, vunit From a242c5f66fbc10473683f455f7024efad6d78fa1 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 7 Jan 2025 15:32:20 -0500 Subject: [PATCH 061/124] fixed/changed some parameterizations --- parm/ocnicepost/ocean.csv | 8 ++--- src/ocnicepost.fd/utils_mod.F90 | 52 +++++++++++++++++---------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/parm/ocnicepost/ocean.csv b/parm/ocnicepost/ocean.csv index 0d1333e4..934a65c1 100644 --- a/parm/ocnicepost/ocean.csv +++ b/parm/ocnicepost/ocean.csv @@ -14,7 +14,7 @@ 'SSV',2,'Cv' , 'bilinear' , 'SSU' , 'Cu','VOGRD','V-Component of Current','m/s',10,1,0,0,1,3,101,0 'taux',2,'Cu' , 'conserve' , 'tauy' , 'Cv','XCOMPSS','x-component Surface Stress','N/m^2',10,1,0,0,3,7,101,0 'tauy',2,'Cv' , 'conserve' , 'taux' , 'Cu','YCOMPSS','y-component Surface Stress','N/m^2',10,1,0,0,3,7,101,0 - 'temp',3,'Ct' , 'bilinear' , '', '','WTMP','Water Temperature','K',10,1,0,0,3,0,168,0 - 'so',3,'Ct' , 'bilinear' , '', '','SALIN','3-D Salinity','psu',10,0,7,1,4,193,168,0 - 'uo',3,'Cu' , 'bilinear' , 'vo' , 'Cv','UOGRD','U-Component of Current','m/s',10,1,0,0,1,2,168,0 - 'vo',3,'Cv' , 'bilinear' , 'uo' , 'Cu','VOGRD','V-Component of Current','m/s',10,1,0,0,1,3,168,0 + 'temp',3,'Ct' , 'bilinear' , '', '','WTMP','Water Temperature','K',10,1,0,0,3,0,160,0 + 'so',3,'Ct' , 'bilinear' , '', '','SALIN','3-D Salinity','psu',10,0,7,1,4,193,160,0 + 'uo',3,'Cu' , 'bilinear' , 'vo' , 'Cv','UOGRD','U-Component of Current','m/s',10,1,0,0,1,2,160,0 + 'vo',3,'Cv' , 'bilinear' , 'uo' , 'Cu','VOGRD','V-Component of Current','m/s',10,1,0,0,1,3,160,0 diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index e40f936c..3333ffab 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -671,7 +671,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) jgdt(8) = dims(1) jgdt(9) = dims(2) jgdt(10) = 0 - jgdt(11) = 0 !-1 + jgdt(11) = -1 jgdt(12) = lat0 jgdt(13) = lon0 jgdt(14) = 48 !0 @@ -728,19 +728,20 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) ! Create Section 4 parametrs ipdtnum=0 - jpdt(1)=gcf(n)%var_g5 ! cat number - jpdt(2)=gcf(n)%var_g6 ! parm number - jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) - jpdt(4)=1 ! 1: Forecast initialized from an earlier analysis - jpdt(5)=0 ! Code ON388 Table A- no ice /ocean GFS - jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(7)=fortime ! forecast hour - jpdt(8)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) - jpdt(9)=0 ! level value - jpdt(10)=255 - jpdt(12)=0 ! - jpdt(13)=0 - jpdt(14)=0 + jpdt(1)=gcf(n)%var_g1 ! Dissipline + jpdt(2)=gcf(n)%var_g5 ! parm number catagory + jpdt(3)=gcf(n)%var_g6 ! parm number + jpdt(4)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) + jpdt(5)=0 ! 1: Forecast initialized from an earlier analysis + jpdt(6)=96 ! Code ON388 Table A- GFS + jpdt(7)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 + jpdt(8)=fortime ! forecast hour + jpdt(9)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level, 168 Ocean Model Layer,...) + jpdt(10)=0 ! scale factor + jpdt(11)=0 ! scale value + jpdt(12)=255 + jpdt(13)=0 + jpdt(14)=0 jpdt(15)=0 if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) @@ -968,17 +969,18 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) ! Create Section 4 parametrs ipdtnum=0 - jpdt(1)=gcf(n)%var_g5 ! cat number - jpdt(2)=gcf(n)%var_g6 ! parm number - jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) - jpdt(4)=1 ! 1: Forecast initialized from an earlier analysis - jpdt(5)=0 ! Code ON388 Table A- no ice /ocean GFS - jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(7)=fortime ! forecast hour - jpdt(8)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 168-Ocean Model Layer,...) - jpdt(9)=dep(lyr) ! level value - jpdt(10)=255 - jpdt(12)=0 + jpdt(1)=gcf(n)%var_g1 ! cat number + jpdt(2)=gcf(n)%var_g5 ! parm number catagory + jpdt(3)=gcf(n)%var_g6 ! parm number + jpdt(4)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) + jpdt(5)=0 ! 1: Forecast initialized from an earlier analysis + jpdt(6)=96 ! Code ON388 Table A- GFS + jpdt(7)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 + jpdt(8)=fortime ! forecast hour + jpdt(9)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) + jpdt(10)=0 ! scale factor + jpdt(11)=dep(lyr) ! scale value + jpdt(12)=255 jpdt(13)=0 jpdt(14)=0 jpdt(15)=0 From b31ccbb5f37e07eb38ab73ff6f01b4ff1a5db9d8 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 8 Jan 2025 10:25:36 -0500 Subject: [PATCH 062/124] fixed/changed some parameterizations --- parm/ocnicepost/ice.csv | 20 ++++++++++---------- parm/ocnicepost/ocean.csv | 30 +++++++++++++++--------------- src/ocnicepost.fd/utils_mod.F90 | 24 +++++++++++------------- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/parm/ocnicepost/ice.csv b/parm/ocnicepost/ice.csv index a5835b53..fc1cf238 100644 --- a/parm/ocnicepost/ice.csv +++ b/parm/ocnicepost/ice.csv @@ -1,11 +1,11 @@ ! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,g1,g2,g3,g4,gc5,gc6,gc7,gc8 - 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,2,0,0,2,1,1,0 - 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,2,0,0,2,16,1,0 - 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,2,0,0,2,0,1,0 - 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,2,0,0,2,8,1,0 - 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,2,0,0,2,4,1,0 - 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,2,0,0,2,5,1,0 - 'frzmlt_h',2, 'Ct', 'conserve', '', '', 'FRZMLTPOT', 'freeze/melt potential', 'W m-2',10,2,0,0,2,27,1,0 - 'albsni_h',2, 'Ct', 'bilinear', '', '', 'ALBDOICE', 'Albedo', 'Numeric',10,2,0,0,2,14,1,0 -'mlt_onset_h',2, 'Ct', 'bilinear', '', '', 'MLTDATE', 'melt onset date', 'Numeric',10,2,0,0,2,28,1,0 -'frz_onset_h',2, 'Ct', 'bilinear', '', '', 'FRZDATE', 'freeze onset date', 'Numeric',10,2,0,0,2,29,1,0 + 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,2,7,0,2,1,1,0 + 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,2,7,0,2,16,1,0 + 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,2,7,0,2,0,1,0 + 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,2,7,0,2,8,1,0 + 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,2,7,0,2,4,1,0 + 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,2,7,0,2,5,1,0 + 'frzmlt_h',2, 'Ct', 'conserve', '', '', 'FRZMLTPOT', 'freeze/melt potential', 'W m-2',10,2,7,0,2,27,1,0 + 'albsni_h',2, 'Ct', 'bilinear', '', '', 'ALBDOICE', 'Albedo', 'Numeric',10,2,7,0,2,14,1,0 +'mlt_onset_h',2, 'Ct', 'bilinear', '', '', 'MLTDATE', 'melt onset date', 'Numeric',10,2,7,0,2,28,1,0 +'frz_onset_h',2, 'Ct', 'bilinear', '', '', 'FRZDATE', 'freeze onset date', 'Numeric',10,2,7,0,2,29,1,0 diff --git a/parm/ocnicepost/ocean.csv b/parm/ocnicepost/ocean.csv index 934a65c1..430842c4 100644 --- a/parm/ocnicepost/ocean.csv +++ b/parm/ocnicepost/ocean.csv @@ -1,20 +1,20 @@ ! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,g1,g2,g3,g4,gc5,gc6,gc7,gc8 'SSH',2,'Ct' , 'bilinear' , '', '','SSHG','Sea Surface Height Relative to Geoid','m',10,0,7,1,3,195,101,0 - 'SST',2,'Ct' , 'bilinear' , '', '','WTMP','Water Temperature','K',10,1,0,0,3,0,101,0 + 'SST',2,'Ct' , 'bilinear' , '', '','WTMP','Water Temperature','K',10,1,7,0,3,0,101,0 'SSS',2,'Ct' , 'bilinear' , '', '','SALINITY','Salinity','psu',10,0,7,1,3,21,101,0 - 'speed',2,'Ct' , 'bilinear' , '', '','SPC','Current Speed','m/s',10,1,0,0,1,1,101,0 - 'MLD_003',2,'Ct' , 'bilinear' , '', '','WDEPTH','Water Depth','m',10,1,0,0,4,14,101,0 - 'latent',2,'Ct' , 'conserve' , '', '','LHTFL','Latent Heat Net Flux','W/m^2',0,1,0,0,0,10,101,0 - 'sensible',2,'Ct' , 'conserve' , '', '','SHTFL','Sensible Heat Net Flux','W/m^2',0,1,0,0,0,11,101,0 - 'SW',2,'Ct' , 'conserve' , '', '','NSWRF','Net Short Wave Radiation Flux','W/m^2',0,1,0,0,4,9,101,0 - 'LW',2,'Ct' , 'conserve' , '', '','NLWRF','Net Long-Wave Radiation Flux','W/m^2',0,1,0,0,5,5,101,0 + 'speed',2,'Ct' , 'bilinear' , '', '','SPC','Current Speed','m/s',10,1,7,0,1,1,101,0 + 'MLD_003',2,'Ct' , 'bilinear' , '', '','WDEPTH','Water Depth','m',10,1,7,0,4,14,101,0 + 'latent',2,'Ct' , 'conserve' , '', '','LHTFL','Latent Heat Net Flux','W/m^2',0,1,7,0,0,10,101,0 + 'sensible',2,'Ct' , 'conserve' , '', '','SHTFL','Sensible Heat Net Flux','W/m^2',0,1,7,0,0,11,101,0 + 'SW',2,'Ct' , 'conserve' , '', '','NSWRF','Net Short Wave Radiation Flux','W/m^2',0,1,7,0,4,9,101,0 + 'LW',2,'Ct' , 'conserve' , '', '','NLWRF','Net Long-Wave Radiation Flux','W/m^2',0,1,7,0,5,5,101,0 'LwLatSens',2,'Ct' , 'conserve' , '', '','THFLX','Total Downward Heat Flux at Surface','W/m^2',0,0,7,1,0,197,101,0 - 'Heat_PmE',2,'Ct' , 'conserve' , '', '','DWHFLUX','Downward Heat Flux','W/m^2',10,1,0,0,3,4,101,0 - 'SSU',2,'Cu' , 'bilinear' , 'SSV' , 'Cv','UOGRD','U-Component of Current','m/s',10,1,0,0,1,2,101,0 - 'SSV',2,'Cv' , 'bilinear' , 'SSU' , 'Cu','VOGRD','V-Component of Current','m/s',10,1,0,0,1,3,101,0 - 'taux',2,'Cu' , 'conserve' , 'tauy' , 'Cv','XCOMPSS','x-component Surface Stress','N/m^2',10,1,0,0,3,7,101,0 - 'tauy',2,'Cv' , 'conserve' , 'taux' , 'Cu','YCOMPSS','y-component Surface Stress','N/m^2',10,1,0,0,3,7,101,0 - 'temp',3,'Ct' , 'bilinear' , '', '','WTMP','Water Temperature','K',10,1,0,0,3,0,160,0 + 'Heat_PmE',2,'Ct' , 'conserve' , '', '','DWHFLUX','Downward Heat Flux','W/m^2',10,1,7,0,3,4,101,0 + 'SSU',2,'Cu' , 'bilinear' , 'SSV' , 'Cv','UOGRD','U-Component of Current','m/s',10,1,7,0,1,2,101,0 + 'SSV',2,'Cv' , 'bilinear' , 'SSU' , 'Cu','VOGRD','V-Component of Current','m/s',10,1,7,0,1,3,101,0 + 'taux',2,'Cu' , 'conserve' , 'tauy' , 'Cv','XCOMPSS','x-component Surface Stress','N/m^2',10,1,7,0,3,7,101,0 + 'tauy',2,'Cv' , 'conserve' , 'taux' , 'Cu','YCOMPSS','y-component Surface Stress','N/m^2',10,1,7,0,3,7,101,0 + 'temp',3,'Ct' , 'bilinear' , '', '','WTMP','Water Temperature','K',10,1,7,0,3,0,160,0 'so',3,'Ct' , 'bilinear' , '', '','SALIN','3-D Salinity','psu',10,0,7,1,4,193,160,0 - 'uo',3,'Cu' , 'bilinear' , 'vo' , 'Cv','UOGRD','U-Component of Current','m/s',10,1,0,0,1,2,160,0 - 'vo',3,'Cv' , 'bilinear' , 'uo' , 'Cu','VOGRD','V-Component of Current','m/s',10,1,0,0,1,3,160,0 + 'uo',3,'Cu' , 'bilinear' , 'vo' , 'Cv','UOGRD','U-Component of Current','m/s',10,1,7,0,1,2,160,0 + 'vo',3,'Cv' , 'bilinear' , 'uo' , 'Cu','VOGRD','V-Component of Current','m/s',10,1,7,0,1,3,160,0 diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 3333ffab..451a845f 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -635,7 +635,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) listsec0(2) = 2 ! GRIB Edition Number (currently 2) listsec1(1) = gcf(1)%var_g3 ! Originating Centre (Common Code Table C-1) - listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 + listsec1(2) = 0 ! Originating Sub-centre (local table) EMC=4 listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 ! listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) @@ -753,18 +753,17 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. - ! Assign Template 5 - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) -! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + ! Assign Template 5 + idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) - ! Populate idrtmpl + ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) - ! Reserved fields - idrtmpl(6:16) = 0 ! Reserved for future use (for complex) + ! Reserved fields + ! idrtmpl(6:16) = 0 ! Reserved for future use (for complex) idrtlen=size(idrtmpl) @@ -849,8 +848,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) listsec0(2) = 2 ! GRIB Edition Number (currently 2) listsec1(1) = gcf(1)%var_g3 ! Originating Centre (Common Code Table C-1) - listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 - listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 + listsec1(2) = 0 ! Originating Sub-centre (local table) EMC=4 + listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 ! listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) @@ -910,7 +909,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) jgdt(8) = dims(1) jgdt(9) = dims(2) jgdt(10) = 0 - jgdt(11) = 0 !-1 + jgdt(11) = -1 jgdt(12) = lat0 jgdt(13) = lon0 jgdt(14) = 48 !0 @@ -995,8 +994,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) bmp=.true. ! Assign Template 5 - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) -! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) @@ -1005,7 +1003,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) ! Reserved fields - idrtmpl(6:16) = 0 ! Reserved for future use (for complex) +! idrtmpl(6:16) = 0 ! Reserved for future use (for complex) idrtlen=size(idrtmpl) From a5e8dbc480c47ffcb8672fd65c3673c1f179e418 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 8 Jan 2025 10:54:03 -0500 Subject: [PATCH 063/124] fixed/changed some parameterizations --- src/ocnicepost.fd/utils_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 451a845f..1d3aac3c 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -609,7 +609,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(16) + integer :: jgdt(19), jpdt(15), idrtmpl(5) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist @@ -818,7 +818,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(16) + integer :: jgdt(19), jpdt(15), idrtmpl(5) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist From c3caabdd9b48896ee1495c3b44ba269af13a5f74 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 8 Jan 2025 11:28:15 -0500 Subject: [PATCH 064/124] fixed/changed some parameterizations --- src/ocnicepost.fd/utils_mod.F90 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 1d3aac3c..0aed1500 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -609,7 +609,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(5) + integer :: jgdt(19), jpdt(15), idrtmpl(6) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist @@ -762,6 +762,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) + idrtmpl(6) = 0 ! ! Reserved fields ! idrtmpl(6:16) = 0 ! Reserved for future use (for complex) @@ -818,7 +819,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(5) + integer :: jgdt(19), jpdt(15), idrtmpl(6) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist @@ -1002,6 +1003,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) + idrtmpl(6) = 0 ! ! Reserved fields ! idrtmpl(6:16) = 0 ! Reserved for future use (for complex) From 924f2c75447d0fd3935c2c4871faea11f4179827 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 8 Jan 2025 11:42:55 -0500 Subject: [PATCH 065/124] reverse some changes --- src/ocnicepost.fd/utils_mod.F90 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 0aed1500..d12a6405 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -609,7 +609,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(6) + integer :: jgdt(19), jpdt(15), idrtmpl(16) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist @@ -635,7 +635,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) listsec0(2) = 2 ! GRIB Edition Number (currently 2) listsec1(1) = gcf(1)%var_g3 ! Originating Centre (Common Code Table C-1) - listsec1(2) = 0 ! Originating Sub-centre (local table) EMC=4 + listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 ! listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) @@ -753,18 +753,18 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. - ! Assign Template 5 - idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + ! Assign Template 5 + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) +! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) - ! Populate idrtmpl + ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) - idrtmpl(6) = 0 ! - ! Reserved fields - ! idrtmpl(6:16) = 0 ! Reserved for future use (for complex) + ! Reserved fields + idrtmpl(6:16) = 0 ! Reserved for future use (for complex) idrtlen=size(idrtmpl) @@ -819,7 +819,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(6) + integer :: jgdt(19), jpdt(15), idrtmpl(16) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist @@ -850,7 +850,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) listsec1(1) = gcf(1)%var_g3 ! Originating Centre (Common Code Table C-1) listsec1(2) = 0 ! Originating Sub-centre (local table) EMC=4 - listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 + listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 ! listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) @@ -910,7 +910,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) jgdt(8) = dims(1) jgdt(9) = dims(2) jgdt(10) = 0 - jgdt(11) = -1 + jgdt(11) = -1 !-1 jgdt(12) = lat0 jgdt(13) = lon0 jgdt(14) = 48 !0 @@ -995,7 +995,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) bmp=.true. ! Assign Template 5 - idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) +! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) @@ -1003,9 +1004,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! Number of bits for each packed value idrtmpl(5) = 0 ! Type of original field values (0 = floating point) - idrtmpl(6) = 0 ! ! Reserved fields -! idrtmpl(6:16) = 0 ! Reserved for future use (for complex) + idrtmpl(6:16) = 0 ! Reserved for future use (for complex) idrtlen=size(idrtmpl) From 9f981aa31efaaaa2071f371f2f5fa2322957adcc Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 8 Jan 2025 12:11:26 -0500 Subject: [PATCH 066/124] change to simple packing 40 --- src/ocnicepost.fd/utils_mod.F90 | 35 ++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index d12a6405..463215a6 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -635,7 +635,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) listsec0(2) = 2 ! GRIB Edition Number (currently 2) listsec1(1) = gcf(1)%var_g3 ! Originating Centre (Common Code Table C-1) - listsec1(2) = 4 ! Originating Sub-centre (local table) EMC=4 + listsec1(2) = 0 ! Originating Sub-centre (local table) EMC=4 listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 ! listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) @@ -679,7 +679,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) jgdt(16) = lon1 jgdt(17) = dij jgdt(18) = dij - jgdt(19) = 0 !64 + jgdt(19) = 0 igdtnum=0 ! Define igds GRIB2 - SECTION 3 @@ -753,18 +753,20 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. - ! Assign Template 5 - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) -! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) - ! Populate idrtmpl + ! Assign Template 5 +! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) + + idrtmpl=0 + ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) - idrtmpl(4) = 0 ! Number of bits for each packed value - idrtmpl(5) = 0 ! Type of original field values (0 = floating point) - ! Reserved fields - idrtmpl(6:16) = 0 ! Reserved for future use (for complex) + idrtmpl(4) = 0 ! + idrtmpl(5) = 0 ! + ! Reserved fields + ! idrtmpl(6:16) = 0 ! Reserved for future use (for complex) idrtlen=size(idrtmpl) @@ -910,7 +912,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) jgdt(8) = dims(1) jgdt(9) = dims(2) jgdt(10) = 0 - jgdt(11) = -1 !-1 + jgdt(11) = -1 jgdt(12) = lat0 jgdt(13) = lon0 jgdt(14) = 48 !0 @@ -995,17 +997,18 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) bmp=.true. ! Assign Template 5 - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) -! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) +! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) + idrtmpl=0 ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) - idrtmpl(4) = 0 ! Number of bits for each packed value - idrtmpl(5) = 0 ! Type of original field values (0 = floating point) + idrtmpl(4) = 0 ! + idrtmpl(5) = 0 ! ! Reserved fields - idrtmpl(6:16) = 0 ! Reserved for future use (for complex) +! idrtmpl(6:16) = 0 ! Reserved for future use (for complex) idrtlen=size(idrtmpl) From 66b7615a11880cb0daaf3275c81bc4d098a47e55 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 9 Jan 2025 11:53:42 -0500 Subject: [PATCH 067/124] chaneged parameters --- src/ocnicepost.fd/utils_mod.F90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 463215a6..de108bc7 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -997,8 +997,9 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) bmp=.true. ! Assign Template 5 + idrtnum = 0 ! Template 5.40 (Grid Point Data - Simple Packing) ! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) - idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) +! idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) idrtmpl=0 ! Populate idrtmpl From bc8f59f4ffbb18a6964b7b8ba67b057fdb2e67cf Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 9 Jan 2025 13:33:18 -0500 Subject: [PATCH 068/124] chaneged parameters --- src/ocnicepost.fd/utils_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index de108bc7..dffd772b 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -997,8 +997,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) bmp=.true. ! Assign Template 5 - idrtnum = 0 ! Template 5.40 (Grid Point Data - Simple Packing) -! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) +! idrtnum = 0 ! Template 5.40 (Grid Point Data - Simple Packing) + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) ! idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) idrtmpl=0 From 54977b6cd833e71b56f501b1cdb7f02eb21cbf40 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 9 Jan 2025 14:22:17 -0500 Subject: [PATCH 069/124] chaneged parameters --- src/ocnicepost.fd/utils_mod.F90 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index dffd772b..5834b9f7 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -755,9 +755,10 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) ! Assign Template 5 -! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) - idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) - +! idrtnum = 0 ! Template 5.40 (Grid Point Data - Simple Packing) + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + ! idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) + idrtmpl=0 ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) @@ -766,7 +767,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! ! Reserved fields - ! idrtmpl(6:16) = 0 ! Reserved for future use (for complex) + ! idrtmpl(6:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) @@ -1009,7 +1010,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! ! Reserved fields -! idrtmpl(6:16) = 0 ! Reserved for future use (for complex) +! idrtmpl(6:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) From 7a8bfe54307ffb9e062960f1e0f5855aca8b2499 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 9 Jan 2025 14:47:09 -0500 Subject: [PATCH 070/124] chaneged parameters --- src/ocnicepost.fd/utils_mod.F90 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 5834b9f7..7ce3bd54 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -754,9 +754,9 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) bmp=.true. - ! Assign Template 5 -! idrtnum = 0 ! Template 5.40 (Grid Point Data - Simple Packing) - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + ! Assign Template 5 + idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + ! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) ! idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) idrtmpl=0 @@ -767,7 +767,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! ! Reserved fields - ! idrtmpl(6:16) = 0 ! Reserved for future use + ! idrtmpl(6:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) @@ -998,8 +998,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) bmp=.true. ! Assign Template 5 -! idrtnum = 0 ! Template 5.40 (Grid Point Data - Simple Packing) - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) +! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) ! idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) idrtmpl=0 From ebf130daf5b7fc2e0f7fc3e8024f58621e7291d6 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 9 Jan 2025 15:01:50 -0500 Subject: [PATCH 071/124] chaneged parameters --- src/ocnicepost.fd/utils_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 7ce3bd54..3b055e17 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -609,7 +609,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(16) + integer :: jgdt(19), jpdt(15), idrtmpl(5) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist @@ -822,7 +822,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(16) + integer :: jgdt(19), jpdt(15), idrtmpl(5) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist From 2cff6257ab22269361ee1997423007a30ce61274 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 9 Jan 2025 16:13:59 -0500 Subject: [PATCH 072/124] chaneged parameters --- src/ocnicepost.fd/utils_mod.F90 | 53 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 3b055e17..8861d52e 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -609,7 +609,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(5) + integer :: jgdt(19), jpdt(15), idrtmpl(15) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist @@ -728,21 +728,21 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) ! Create Section 4 parametrs ipdtnum=0 - jpdt(1)=gcf(n)%var_g1 ! Dissipline - jpdt(2)=gcf(n)%var_g5 ! parm number catagory - jpdt(3)=gcf(n)%var_g6 ! parm number - jpdt(4)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) - jpdt(5)=0 ! 1: Forecast initialized from an earlier analysis - jpdt(6)=96 ! Code ON388 Table A- GFS - jpdt(7)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(8)=fortime ! forecast hour - jpdt(9)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level, 168 Ocean Model Layer,...) - jpdt(10)=0 ! scale factor - jpdt(11)=0 ! scale value - jpdt(12)=255 + + jpdt(1)=gcf(n)%var_g5 ! parm number catagory + jpdt(2)=gcf(n)%var_g6 ! parm number + jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) + jpdt(4)=0 ! 1: Forecast initialized from an earlier analysis + jpdt(5)=96 ! Code ON388 Table A- GFS + jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 + jpdt(7)=fortime ! forecast hour + jpdt(8)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level, 168 Ocean Model Layer,...) + jpdt(9)=0 ! scale factor + jpdt(10)=0 ! scale value + jpdt(11)=255 + jpdt(12)=0 jpdt(13)=0 jpdt(14)=0 - jpdt(15)=0 if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) @@ -972,18 +972,19 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) ! Create Section 4 parametrs ipdtnum=0 - jpdt(1)=gcf(n)%var_g1 ! cat number - jpdt(2)=gcf(n)%var_g5 ! parm number catagory - jpdt(3)=gcf(n)%var_g6 ! parm number - jpdt(4)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) - jpdt(5)=0 ! 1: Forecast initialized from an earlier analysis - jpdt(6)=96 ! Code ON388 Table A- GFS - jpdt(7)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(8)=fortime ! forecast hour - jpdt(9)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) - jpdt(10)=0 ! scale factor - jpdt(11)=dep(lyr) ! scale value - jpdt(12)=255 + + jpdt(1)=gcf(n)%var_g5 ! parm number catagory + jpdt(2)=gcf(n)%var_g6 ! parm number + jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) + jpdt(4)=0 ! 1: Forecast initialized from an earlier analysis + jpdt(5)=96 ! Code ON388 Table A- GFS + jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 + jpdt(7)=fortime ! forecast hour + jpdt(8)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) + jpdt(9)=0 ! scale factor + jpdt(10)=dep(lyr) ! scale value + jpdt(11)=255 + jpdt(12)=0 jpdt(13)=0 jpdt(14)=0 jpdt(15)=0 From 09cb35ea042c89ac4ec236f208fd5f03bbaf9600 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 9 Jan 2025 16:30:17 -0500 Subject: [PATCH 073/124] chaneged parameters --- src/ocnicepost.fd/utils_mod.F90 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 8861d52e..0d135367 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -609,7 +609,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(15) + integer :: jgdt(19), jpdt(15), idrtmpl(16) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist @@ -755,9 +755,9 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) ! Assign Template 5 - idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) +! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) ! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) - ! idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) + idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) idrtmpl=0 ! Populate idrtmpl @@ -822,7 +822,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) integer :: listsec0(2), listsec1(13) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(5) + integer :: jgdt(19), jpdt(15), idrtmpl(16) integer(4) :: igds(5) integer :: numcoord, ibmap real(4) :: coordlist @@ -999,9 +999,9 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) bmp=.true. ! Assign Template 5 - idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) +! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) ! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) -! idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) + idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) idrtmpl=0 ! Populate idrtmpl From 269313c048f40c455bf3dafe74fbba4d09e21878 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 15 Jan 2025 11:35:58 -0500 Subject: [PATCH 074/124] chaneged parameters --- parm/ocnicepost/ice.csv | 2 +- parm/ocnicepost/ocean.csv | 2 +- src/ocnicepost.fd/utils_mod.F90 | 12 +++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/parm/ocnicepost/ice.csv b/parm/ocnicepost/ice.csv index fc1cf238..c06c65fe 100644 --- a/parm/ocnicepost/ice.csv +++ b/parm/ocnicepost/ice.csv @@ -1,4 +1,4 @@ -! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,g1,g2,g3,g4,gc5,gc6,gc7,gc8 +! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,gc1,gc2,gc3,gc4,gc5,gc6,gc7,gc8 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,2,7,0,2,1,1,0 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,2,7,0,2,16,1,0 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,2,7,0,2,0,1,0 diff --git a/parm/ocnicepost/ocean.csv b/parm/ocnicepost/ocean.csv index 430842c4..725c6897 100644 --- a/parm/ocnicepost/ocean.csv +++ b/parm/ocnicepost/ocean.csv @@ -1,4 +1,4 @@ -! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,g1,g2,g3,g4,gc5,gc6,gc7,gc8 +! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,gc1,gc2,gc3,gc4,gc5,gc6,gc7,gc8 'SSH',2,'Ct' , 'bilinear' , '', '','SSHG','Sea Surface Height Relative to Geoid','m',10,0,7,1,3,195,101,0 'SST',2,'Ct' , 'bilinear' , '', '','WTMP','Water Temperature','K',10,1,7,0,3,0,101,0 'SSS',2,'Ct' , 'bilinear' , '', '','SALINITY','Salinity','psu',10,0,7,1,3,21,101,0 diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 0d135367..11db74ef 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -756,16 +756,15 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) ! Assign Template 5 ! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) - ! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) - idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl=0 ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! - idrtmpl(5) = 0 ! + idrtmpl(5) = 0 ! ! Reserved fields ! idrtmpl(6:16) = 0 ! Reserved for future use @@ -1000,14 +999,13 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) ! Assign Template 5 ! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) -! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) - idrtnum = 40 ! Template 5.40 (Grid Point Data - Simple Packing Jpegg) + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl=0 ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! ! Reserved fields From 1ae438fb923d0e69d6d281ee31949c7006af7929 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 15 Jan 2025 14:16:31 -0500 Subject: [PATCH 075/124] chaneged parameters --- src/ocnicepost.fd/utils_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 11db74ef..2d2e725c 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -679,7 +679,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) jgdt(16) = lon1 jgdt(17) = dij jgdt(18) = dij - jgdt(19) = 0 + jgdt(19) = 1 igdtnum=0 ! Define igds GRIB2 - SECTION 3 @@ -920,7 +920,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) jgdt(16) = lon1 jgdt(17) = dij jgdt(18) = dij - jgdt(19) = 0 !64 + jgdt(19) = 1 !64 igdtnum=0 ! Define igds GRIB2 - SECTION 3 From bd1a68ee387b5b9c2a71aeb50c9b235fbc95e4ee Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 15 Jan 2025 14:34:04 -0500 Subject: [PATCH 076/124] chaneged parameters --- src/ocnicepost.fd/utils_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 2d2e725c..78842f5d 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -679,7 +679,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) jgdt(16) = lon1 jgdt(17) = dij jgdt(18) = dij - jgdt(19) = 1 + jgdt(19) = 010 igdtnum=0 ! Define igds GRIB2 - SECTION 3 @@ -920,7 +920,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) jgdt(16) = lon1 jgdt(17) = dij jgdt(18) = dij - jgdt(19) = 1 !64 + jgdt(19) = 010 !64 igdtnum=0 ! Define igds GRIB2 - SECTION 3 From 93c2bf170ba0e1490006cfde776887be1ba8850c Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 15 Jan 2025 14:41:38 -0500 Subject: [PATCH 077/124] chaneged parameters --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 78842f5d..1a1625dd 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -1005,7 +1005,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! ! Reserved fields From 2ba3b1daccb3b6e96a3a97ce2413c88f2d91ce86 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 15 Jan 2025 16:33:39 -0500 Subject: [PATCH 078/124] chaneged parameters --- src/ocnicepost.fd/utils_mod.F90 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 1a1625dd..a73d07f2 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -674,12 +674,12 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) jgdt(11) = -1 jgdt(12) = lat0 jgdt(13) = lon0 - jgdt(14) = 48 !0 + jgdt(14) = 24 !0 jgdt(15) = lat1 jgdt(16) = lon1 jgdt(17) = dij jgdt(18) = dij - jgdt(19) = 010 + jgdt(19) = 64 igdtnum=0 ! Define igds GRIB2 - SECTION 3 @@ -901,26 +901,26 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) lat0 = -90000000 lat1 = 90000000 - ! Populate the jgdt array for Template 3.0 (changed parameters to current grib2 files) - jgdt(1) = 6 - jgdt(2) = 0 - jgdt(3) = 0 - jgdt(4) = 0 - jgdt(5) = 0 - jgdt(6) = 0 - jgdt(7) = 0 - jgdt(8) = dims(1) - jgdt(9) = dims(2) + ! Populate the jgdt array for Template 3.0 (changed parameters to current grib2 files) + jgdt(1) = 6 + jgdt(2) = 0 + jgdt(3) = 0 + jgdt(4) = 0 + jgdt(5) = 0 + jgdt(6) = 0 + jgdt(7) = 0 + jgdt(8) = dims(1) + jgdt(9) = dims(2) jgdt(10) = 0 jgdt(11) = -1 jgdt(12) = lat0 jgdt(13) = lon0 - jgdt(14) = 48 !0 + jgdt(14) = 24 jgdt(15) = lat1 jgdt(16) = lon1 jgdt(17) = dij jgdt(18) = dij - jgdt(19) = 010 !64 + jgdt(19) = 64 igdtnum=0 ! Define igds GRIB2 - SECTION 3 From b42c2b13a4f8c167d0dd8e83783f5c8729f74d33 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 28 Jan 2025 10:41:04 -0500 Subject: [PATCH 079/124] some changed on utils mod --- src/ocnicepost.fd/utils_mod.F90 | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index a73d07f2..c1ae86f4 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -1,7 +1,7 @@ module utils_mod use netcdf - use init_mod, only : debug, logunit, vardefs, fsrc, input_file + use init_mod, only : debug, logunit, vardefs, fsrc, input_file, ftype implicit none @@ -636,8 +636,8 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) listsec1(1) = gcf(1)%var_g3 ! Originating Centre (Common Code Table C-1) listsec1(2) = 0 ! Originating Sub-centre (local table) EMC=4 - listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 -! listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) +! listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 + listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) listsec1(6) = ref_time(1) ! Reference Time - Year -4digits @@ -671,10 +671,10 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) jgdt(8) = dims(1) jgdt(9) = dims(2) jgdt(10) = 0 - jgdt(11) = -1 + jgdt(11) = 1000000 jgdt(12) = lat0 jgdt(13) = lon0 - jgdt(14) = 24 !0 + jgdt(14) = 48 !0 jgdt(15) = lat1 jgdt(16) = lon1 jgdt(17) = dij @@ -737,7 +737,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 jpdt(7)=fortime ! forecast hour jpdt(8)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level, 168 Ocean Model Layer,...) - jpdt(9)=0 ! scale factor + jpdt(9)=0 ! scale factor jpdt(10)=0 ! scale value jpdt(11)=255 jpdt(12)=0 @@ -762,7 +762,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! ! Reserved fields @@ -852,8 +852,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) listsec1(1) = gcf(1)%var_g3 ! Originating Centre (Common Code Table C-1) listsec1(2) = 0 ! Originating Sub-centre (local table) EMC=4 - listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 -! listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) +! listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 + listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) listsec1(6) = ref_time(1) ! Reference Time - Year -4digits @@ -912,10 +912,10 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) jgdt(8) = dims(1) jgdt(9) = dims(2) jgdt(10) = 0 - jgdt(11) = -1 + jgdt(11) = 1000000 jgdt(12) = lat0 jgdt(13) = lon0 - jgdt(14) = 24 + jgdt(14) = 48 jgdt(15) = lat1 jgdt(16) = lon1 jgdt(17) = dij @@ -1083,9 +1083,14 @@ subroutine retrieve_time(forecast_hour, ref_time) call nf90_err(nf90_get_var(ncid, time_varid, forecast_hour), 'get variable time') call nf90_err(nf90_get_att(ncid, time_varid, 'units', units_str), 'get attribute: units') - read(units_str(13:30), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & ! (12:29) for testing ice model (need to be changed request sent) - (13:30) is final and for testing the ocean model + if (trim(ftype) == 'ocean') then + read(units_str(13:30), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec -! forecast_hour=24*forecast_hour ! just for testing ice model (remove it once ice time unit fixed) + else + read(units_str(12:29), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & ! remove it once ice time unit changed + ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec + forecast_hour=24*forecast_hour ! remove it once ice time unit changed) + ref_time(1) = ref_year ref_time(2) = ref_month From 7fe32a1b4a20057cdfe52eca9ab99ea12084dc90 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 28 Jan 2025 11:31:27 -0500 Subject: [PATCH 080/124] some changed on utils mod --- src/ocnicepost.fd/utils_mod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index c1ae86f4..f33e7a40 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -717,7 +717,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) return end if - write(logunit, *) 'n, nflds, npt: ', n, nflds, npt + write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, , gcf(n)%discription_gb2 call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then @@ -960,7 +960,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) return end if - if (debug) write(logunit, *) 'n, nflds, npt, lay: ', n, nflds, npt, lyr + if (debug) write(logunit, *) 'n, nflds, npt, lay: ', n, nflds, npt, lyr, gcf(n)%discription_gb2 call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then @@ -1090,7 +1090,7 @@ subroutine retrieve_time(forecast_hour, ref_time) read(units_str(12:29), '(I4,1X,I2,1X,I2,1X,I2,1X,I2,1X,I2)') & ! remove it once ice time unit changed ref_year, ref_month, ref_day, ref_hour, ref_min, ref_sec forecast_hour=24*forecast_hour ! remove it once ice time unit changed) - + end if ref_time(1) = ref_year ref_time(2) = ref_month From 1b6e85efbedeb0151c6a3294e8c95ec16ec13810 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 28 Jan 2025 11:34:36 -0500 Subject: [PATCH 081/124] some changed on utils mod --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index f33e7a40..cc7fb2a5 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -717,7 +717,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) return end if - write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, , gcf(n)%discription_gb2 + write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%discription_gb2 call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then From 49d50b5b0a0d198946e6e41f2a6c642438e0e76d Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Tue, 28 Jan 2025 13:22:52 -0500 Subject: [PATCH 082/124] some changes --- parm/ocnicepost/ocean.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parm/ocnicepost/ocean.csv b/parm/ocnicepost/ocean.csv index 725c6897..e54ff2b5 100644 --- a/parm/ocnicepost/ocean.csv +++ b/parm/ocnicepost/ocean.csv @@ -1,7 +1,7 @@ ! variable name, dimension, grid location, remapping method, vector pair, grid location of vector pair,gb2 varname,discription,unit,gc1,gc2,gc3,gc4,gc5,gc6,gc7,gc8 'SSH',2,'Ct' , 'bilinear' , '', '','SSHG','Sea Surface Height Relative to Geoid','m',10,0,7,1,3,195,101,0 'SST',2,'Ct' , 'bilinear' , '', '','WTMP','Water Temperature','K',10,1,7,0,3,0,101,0 - 'SSS',2,'Ct' , 'bilinear' , '', '','SALINITY','Salinity','psu',10,0,7,1,3,21,101,0 + 'SSS',2,'Ct' , 'bilinear' , '', '',SALIN','Salinity','psu',10,0,7,1,4,193,101,0 'speed',2,'Ct' , 'bilinear' , '', '','SPC','Current Speed','m/s',10,1,7,0,1,1,101,0 'MLD_003',2,'Ct' , 'bilinear' , '', '','WDEPTH','Water Depth','m',10,1,7,0,4,14,101,0 'latent',2,'Ct' , 'conserve' , '', '','LHTFL','Latent Heat Net Flux','W/m^2',0,1,7,0,0,10,101,0 From b597bc392b32f0dd59198d2f65abbda5ac321880 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 29 Jan 2025 10:41:26 -0500 Subject: [PATCH 083/124] modifying the code for adding mask --- src/ocnicepost.fd/masking_mod.F90 | 2 +- src/ocnicepost.fd/utils_mod.F90 | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/ocnicepost.fd/masking_mod.F90 b/src/ocnicepost.fd/masking_mod.F90 index 3613d6f5..5a58e2b3 100644 --- a/src/ocnicepost.fd/masking_mod.F90 +++ b/src/ocnicepost.fd/masking_mod.F90 @@ -27,7 +27,7 @@ subroutine remap_masks(vfill) ! local variables integer :: rc, ncid, varid, n character(len=240) :: wgtsfile - real :: minlat = -78.63 + real :: minlat = -78.00 ! This is masking Antarctica which is not in the weighting function real, allocatable, dimension(:) :: out1d diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index cc7fb2a5..5f77d1d7 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -2,6 +2,7 @@ module utils_mod use netcdf use init_mod, only : debug, logunit, vardefs, fsrc, input_file, ftype + use masking_mod, only : rgmask2d, rgmask3d implicit none @@ -717,7 +718,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) return end if - write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%discription_gb2 + write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%discription_gb2, gcf(n)%var_fillvalue call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then @@ -750,8 +751,10 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate - ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap - bmp=.true. + + + ibmap = 0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + bmp = (rgmask2d == 1) ! Assign Template 5 @@ -770,6 +773,9 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) idrtlen=size(idrtmpl) + where ( field(:,n) == gcf(n)%var_fillvalue ) field(:,n) = -9999.0 + + call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,n), npt, ibmap, bmp, ierr) if (ierr /= 0) then @@ -960,7 +966,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) return end if - if (debug) write(logunit, *) 'n, nflds, npt, lay: ', n, nflds, npt, lyr, gcf(n)%discription_gb2 + if (debug) write(logunit, *) 'n, nflds, npt, lay: ', n, nflds, npt, lyr, gcf(n)%discription_gb2, gcf(n)%var_fillvalue call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then @@ -994,8 +1000,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate - ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap - bmp=.true. + ibmap=0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + bmp = (rgmask3d(:,lyr) == 1) ! Assign Template 5 ! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) @@ -1013,6 +1019,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) idrtlen=size(idrtmpl) + where ( field(:,lyr,n) == gcf(n)%var_fillvalue ) field(:,n) = -9999.0 + call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,lyr,n), npt, ibmap, bmp, ierr) if (ierr /= 0) then From b79810222ae23a2e60a76d9ddb31acb2d838d7ff Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Wed, 29 Jan 2025 13:26:31 -0500 Subject: [PATCH 084/124] modifying the code for ype of writing --- src/ocnicepost.fd/masking_mod.F90 | 2 +- src/ocnicepost.fd/utils_mod.F90 | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ocnicepost.fd/masking_mod.F90 b/src/ocnicepost.fd/masking_mod.F90 index 5a58e2b3..24c8df39 100644 --- a/src/ocnicepost.fd/masking_mod.F90 +++ b/src/ocnicepost.fd/masking_mod.F90 @@ -27,7 +27,7 @@ subroutine remap_masks(vfill) ! local variables integer :: rc, ncid, varid, n character(len=240) :: wgtsfile - real :: minlat = -78.00 ! This is masking Antarctica which is not in the weighting function + real :: minlat = -78.00 ! This is masking Antarctica which is not in the weighting file real, allocatable, dimension(:) :: out1d diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 5f77d1d7..57f64409 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -758,8 +758,8 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) ! Assign Template 5 -! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) +! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl=0 ! Populate idrtmpl @@ -775,6 +775,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) where ( field(:,n) == gcf(n)%var_fillvalue ) field(:,n) = -9999.0 + write(logunit, *) 'bmp: ', bmp call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,n), npt, ibmap, bmp, ierr) @@ -1004,14 +1005,14 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) bmp = (rgmask3d(:,lyr) == 1) ! Assign Template 5 -! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) +! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl=0 ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! ! Reserved fields @@ -1021,6 +1022,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) where ( field(:,lyr,n) == gcf(n)%var_fillvalue ) field(:,n) = -9999.0 + write(logunit, *) 'bmp: ', bmp + call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,lyr,n), npt, ibmap, bmp, ierr) if (ierr /= 0) then From bf25160f9cbd5870c8b7032e89b0cbf218fe778a Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 30 Jan 2025 10:16:59 -0500 Subject: [PATCH 085/124] debuging --- src/ocnicepost.fd/utils_mod.F90 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 57f64409..5dc4d7ab 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -618,6 +618,10 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) integer :: ideflist, idefnum logical :: bmp(dims(1)*dims(2)) + real :: max_val, min_val, mean_val + + + npt = dims(1) * dims(2) max_bytes = npt * 4 ! Estimated max bytes @@ -720,6 +724,13 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%discription_gb2, gcf(n)%var_fillvalue + ! Compute max, min, and mean + max_val = maxval(field(:,n)) + min_val = minval(field(:,n)) + mean_val = sum(field(:,n)) / size(field(:,n)) + + write(logunit, *) 'Variable_Name, max, min, mean: ', gcf(n)%var_name, max_val, min_val, mean_val + call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then write(0, *) 'Error adding grid to GRIB2 message', ierr From 68920b57a60042d6f06cb5e9a72c2db0bd13d74c Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 30 Jan 2025 11:06:04 -0500 Subject: [PATCH 086/124] modifying Cmake --- src/ocnicepost.fd/CMakeLists.txt | 4 ++-- src/ocnicepost.fd/utils_mod.F90 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ocnicepost.fd/CMakeLists.txt b/src/ocnicepost.fd/CMakeLists.txt index 0d9d3e94..0d97e314 100644 --- a/src/ocnicepost.fd/CMakeLists.txt +++ b/src/ocnicepost.fd/CMakeLists.txt @@ -1,9 +1,9 @@ list(APPEND fortran_src + init_mod.F90 arrays_mod.F90 - init_mod.F90 masking_mod.F90 - ocnicepost.F90 utils_mod.F90 + ocnicepost.F90 ) set(exe_name ocnicepost.x) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 5dc4d7ab..7a7b19f0 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -729,7 +729,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) min_val = minval(field(:,n)) mean_val = sum(field(:,n)) / size(field(:,n)) - write(logunit, *) 'Variable_Name, max, min, mean: ', gcf(n)%var_name, max_val, min_val, mean_val + write(logunit, *) 'Variable_name, max, min, mean: ', gcf(n)%var_name, max_val, min_val, mean_val call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then From 4e0d43c3689c2372c1e11de38a757cfeb9643a1a Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 30 Jan 2025 13:54:11 -0500 Subject: [PATCH 087/124] some changes in cmake, maskinga for debugging --- src/ocnicepost.fd/CMakeLists.txt | 5 ++-- src/ocnicepost.fd/masking_mod.F90 | 4 ++-- src/ocnicepost.fd/utils_mod.F90 | 40 ++++++++++++++++--------------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/ocnicepost.fd/CMakeLists.txt b/src/ocnicepost.fd/CMakeLists.txt index 0d97e314..c5d213a5 100644 --- a/src/ocnicepost.fd/CMakeLists.txt +++ b/src/ocnicepost.fd/CMakeLists.txt @@ -1,9 +1,10 @@ list(APPEND fortran_src - init_mod.F90 + init_mod.F90 arrays_mod.F90 - masking_mod.F90 utils_mod.F90 + masking_mod.F90 ocnicepost.F90 + ) set(exe_name ocnicepost.x) diff --git a/src/ocnicepost.fd/masking_mod.F90 b/src/ocnicepost.fd/masking_mod.F90 index 24c8df39..dc103287 100644 --- a/src/ocnicepost.fd/masking_mod.F90 +++ b/src/ocnicepost.fd/masking_mod.F90 @@ -80,7 +80,7 @@ subroutine remap_masks(vfill) if (debug) then write(logunit,'(a,2g14.4)')'mask min/max on destination grid ',minval(rgmask3d),maxval(rgmask3d) - call dumpnc(trim(ftype)//'.'//trim(fdst)//'.rgmask3d.nc', 'rgmask3d', dims=(/nxr,nyr,nlevs/), & + call dumpnc(trim(ftype)//'.'//trim(fdst)//'.rgmask3d.nc', 'rgmask3d', dims=(/nxr*nyr,nlevs/), & field=rgmask3d) end if else @@ -93,7 +93,7 @@ subroutine remap_masks(vfill) if (debug) then write(logunit,'(a,2g14.4)')'mask min/max on destination grid ',minval(rgmask2d),maxval(rgmask2d) - call dumpnc(trim(ftype)//'.'//trim(fdst)//'.rgmask2d.nc', 'rgmask2d', dims=(/nxr,nyr/), & + call dumpnc(trim(ftype)//'.'//trim(fdst)//'.rgmask2d.nc', 'rgmask2d', dims=(/nxr*nyr/), & field=rgmask2d) end if end if diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 7a7b19f0..0ee8ebf9 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -2,7 +2,7 @@ module utils_mod use netcdf use init_mod, only : debug, logunit, vardefs, fsrc, input_file, ftype - use masking_mod, only : rgmask2d, rgmask3d + implicit none @@ -589,15 +589,16 @@ end subroutine dumpnc1d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !----------------------------------------------------------------------------------- - subroutine write_grib2_2d(fname, gcf, dims, nflds, field) + subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) implicit none character(len=*), intent(in) :: fname - type(vardefs), allocatable, dimension(:) :: gcf + type(vardefs), intent(in) :: gcf(:) integer, intent(in) :: dims(2) integer, intent(in) :: nflds real, intent(in) :: field(dims(1)*dims(2),nflds) + real, intent(in) :: rgmask2d(dims(1) * dims(2)) ! internal variables integer(4) :: max_bytes, lengrib @@ -620,8 +621,6 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) real :: max_val, min_val, mean_val - - npt = dims(1) * dims(2) max_bytes = npt * 4 ! Estimated max bytes @@ -722,7 +721,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) return end if - write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%discription_gb2, gcf(n)%var_fillvalue + write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%var_name, gcf(n) ! Compute max, min, and mean max_val = maxval(field(:,n)) @@ -747,14 +746,16 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) jpdt(4)=0 ! 1: Forecast initialized from an earlier analysis jpdt(5)=96 ! Code ON388 Table A- GFS jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(7)=fortime ! forecast hour - jpdt(8)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level, 168 Ocean Model Layer,...) - jpdt(9)=0 ! scale factor - jpdt(10)=0 ! scale value - jpdt(11)=255 - jpdt(12)=0 - jpdt(13)=0 + jpdt(7)=0 ! + jpdt(8)=0 ! + jpdt(9)=fortime ! forecast hour + jpdt(10)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level, 168 Ocean Model Layer,...) + jpdt(11)=0 ! scale factor + jpdt(12)=0 ! scale value + jpdt(13)=255 jpdt(14)=0 + jpdt(15)=0 + jpdt(16)=0 if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) @@ -769,8 +770,8 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field) ! Assign Template 5 - idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) -! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) +! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl=0 ! Populate idrtmpl @@ -818,15 +819,16 @@ end subroutine write_grib2_2d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !----------------------------------------------------------------------------------- - subroutine write_grib2_3d(fname, gcf, dims, nflds, field) + subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) implicit none character(len=*), intent(in) :: fname - type(vardefs), allocatable, dimension(:) :: gcf + type(vardefs), intent(in) :: gcf(:) integer, intent(in) :: dims(3) integer, intent(in) :: nflds real, intent(in) :: field( dims(1) * dims(2) , dims(3) , nflds ) + real, intent(in) :: rgmask3d(dims(1) * dims(2) , dims(3)) ! internal variables integer(4) :: max_bytes, lengrib @@ -1016,8 +1018,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field) bmp = (rgmask3d(:,lyr) == 1) ! Assign Template 5 - idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) -! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) +! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl=0 ! Populate idrtmpl From a01aff428fc4a41b6950cfe8e2fe581fcb8af359 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 30 Jan 2025 14:06:18 -0500 Subject: [PATCH 088/124] fixed issues --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 0ee8ebf9..bb31ad12 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -1033,7 +1033,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) idrtlen=size(idrtmpl) - where ( field(:,lyr,n) == gcf(n)%var_fillvalue ) field(:,n) = -9999.0 + where ( field(:,lyr,n) == gcf(n)%var_fillvalue ) field(:,lyr,n) = -9999.0 write(logunit, *) 'bmp: ', bmp From 80d65af9ac62006f34b3740afefcc170e0315e97 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 30 Jan 2025 14:09:20 -0500 Subject: [PATCH 089/124] fixed issues --- src/ocnicepost.fd/utils_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index bb31ad12..977fbe3e 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -597,7 +597,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) type(vardefs), intent(in) :: gcf(:) integer, intent(in) :: dims(2) integer, intent(in) :: nflds - real, intent(in) :: field(dims(1)*dims(2),nflds) + real, intent(inout) :: field(dims(1)*dims(2),nflds) real, intent(in) :: rgmask2d(dims(1) * dims(2)) ! internal variables @@ -827,7 +827,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) type(vardefs), intent(in) :: gcf(:) integer, intent(in) :: dims(3) integer, intent(in) :: nflds - real, intent(in) :: field( dims(1) * dims(2) , dims(3) , nflds ) + real, intent(inout) :: field( dims(1) * dims(2) , dims(3) , nflds ) real, intent(in) :: rgmask3d(dims(1) * dims(2) , dims(3)) ! internal variables From 68a50ac9ba73af4bc20a7157daf5810ddb2d38a9 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 30 Jan 2025 14:13:00 -0500 Subject: [PATCH 090/124] fixed issues --- src/ocnicepost.fd/ocnicepost.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index d08b046d..d3ba6166 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -399,11 +399,11 @@ program ocnicepost g2d(1:nbilin2d) = b2d end if - call write_grib2_2d(gout, g2d, (/nxr,nyr/), nconsd2d+nbilin2d, grib2d) + call write_grib2_2d(gout, g2d, (/nxr,nyr/), nconsd2d+nbilin2d, grib2d, rgmask2d) if (allocated(rgb3d)) then gout = trim(ftype)//'.'//trim(fdst)//'_3D.gb2' - call write_grib2_3d(gout, b3d, (/nxr,nyr,nlevs/), nbilin3d, rgb3d) + call write_grib2_3d(gout, b3d, (/nxr,nyr,nlevs/), nbilin3d, rgb3d, rgmask3d) if (debug) write(logunit, '(a)')'GRIB2 3D output file: '//trim(gout) end if end if From 0da73256f3bbb6412ea8f289fd3a57bfbaea86d5 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 30 Jan 2025 15:04:32 -0500 Subject: [PATCH 091/124] fixed issues --- src/ocnicepost.fd/utils_mod.F90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 977fbe3e..c6d7c29e 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -723,6 +723,8 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%var_name, gcf(n) + write(logunit,*) 'size_bmp ,size_rgmask2d', size(bmp), size(rgmask2d) + ! Compute max, min, and mean max_val = maxval(field(:,n)) min_val = minval(field(:,n)) From bd86a58f2e236dbd441c9e9dbd62512bce20fc64 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 30 Jan 2025 15:17:50 -0500 Subject: [PATCH 092/124] fixed issues --- src/ocnicepost.fd/utils_mod.F90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index c6d7c29e..8bff10d3 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -768,6 +768,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) ibmap = 0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + bmp=.false. bmp = (rgmask2d == 1) @@ -1017,6 +1018,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate ibmap=0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + bmp=.false. bmp = (rgmask3d(:,lyr) == 1) ! Assign Template 5 From cd9a29845d529d461474e85d98333022328b2feb Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 30 Jan 2025 15:39:01 -0500 Subject: [PATCH 093/124] fixed issues --- src/ocnicepost.fd/utils_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 8bff10d3..453297e0 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -769,7 +769,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) ibmap = 0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.false. - bmp = (rgmask2d == 1) + where (rgmask2d == 1) bmp=.true. ! Assign Template 5 @@ -1019,7 +1019,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) coordlist=0. ! needed for hybrid vertical coordinate ibmap=0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.false. - bmp = (rgmask3d(:,lyr) == 1) + where (rgmask3d(:,lyr) == 1) bmp=.true. ! Assign Template 5 ! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) From 1b8190eae32f83b2557695f0e3221aab85df73e5 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Thu, 30 Jan 2025 16:25:44 -0500 Subject: [PATCH 094/124] debugging to implimment masking --- src/ocnicepost.fd/utils_mod.F90 | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 453297e0..ef6276a7 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -759,7 +759,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) jpdt(15)=0 jpdt(16)=0 - if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) + if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:16) ipdtlen=size(jpdt) @@ -768,9 +768,9 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) ibmap = 0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap - bmp=.false. - where (rgmask2d == 1) bmp=.true. - + bmp=.true. +! where (rgmask2d == 1) bmp=.true. +! bmp=.true. ! Assign Template 5 ! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) @@ -780,7 +780,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! ! Reserved fields @@ -788,7 +788,12 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) idrtlen=size(idrtmpl) - where ( field(:,n) == gcf(n)%var_fillvalue ) field(:,n) = -9999.0 + + if (gcf(n)%var_name .eq. 'WTMP') field(:,n) = field(:,n) + 273.15 + + where ( field(:,n) < -9999 ) field(:,n) = -9999.0 + + where (field(:,n) .eq. -9999.0) bmp= .false. write(logunit, *) 'bmp: ', bmp @@ -1001,6 +1006,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) jpdt(4)=0 ! 1: Forecast initialized from an earlier analysis jpdt(5)=96 ! Code ON388 Table A- GFS jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 + jpdt(7)=0 ! forecast hour + jpdt(8)=0 ! jpdt(7)=fortime ! forecast hour jpdt(8)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) jpdt(9)=0 ! scale factor @@ -1010,6 +1017,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) jpdt(13)=0 jpdt(14)=0 jpdt(15)=0 + jpdt(16)=0 if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) @@ -1018,8 +1026,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate ibmap=0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap - bmp=.false. - where (rgmask3d(:,lyr) == 1) bmp=.true. + bmp=.true. ! Assign Template 5 ! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) @@ -1037,7 +1044,9 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) idrtlen=size(idrtmpl) - where ( field(:,lyr,n) == gcf(n)%var_fillvalue ) field(:,lyr,n) = -9999.0 + where ( field(:,lyr,n) < -9999 ) field(:,lyr,n) = -9999.0 + + where (field(:,lyr,n) .eq. -9999.0) bmp= .false. write(logunit, *) 'bmp: ', bmp From 65850d5a047e6705720d4f45a18c3268b2850e39 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 10:45:22 -0500 Subject: [PATCH 095/124] changed some parammeters fixed issues, debuging --- src/ocnicepost.fd/ocnicepost.F90 | 72 ++++++++++++++------------ src/ocnicepost.fd/utils_mod.F90 | 87 +++++++++++++++++--------------- 2 files changed, 84 insertions(+), 75 deletions(-) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index d3ba6166..eab3e3f7 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -137,6 +137,8 @@ program ocnicepost call remap_masks(vfill) + + ! -------------------------------------------------------- ! create packed arrays for mapping and remap packed arrays ! to the destination grid @@ -255,6 +257,43 @@ program ocnicepost sqrt(rgb2d(:,idx2)**2 + rgb2d(:,idx3)**2) end if +!-------------------------------------------------------- +! Write the grib2 files +!-------------------------------------------------------- + + if(grib2) then + gout = trim(ftype)//'.'//trim(fdst)//'.gb2' + if (debug) write(logunit, '(a)')'GRIB2 2D output file: '//trim(gout) + + if (allocated(rgb2d) .and. allocated(rgc2d)) then + allocate(grib2d(nxr*nyr,nconsd2d+nbilin2d)); grib2d=0.0 + allocate(g2d(1:nconsd2d+nbilin2d)); g2d=0.0 + grib2d(:, 1:nbilin2d) = rgb2d + grib2d(:, nbilin2d+1:nconsd2d+nbilin2d) = rgc2d + g2d(1:nbilin2d) = b2d + g2d(nbilin2d+1:nconsd2d+nbilin2d) = c2d + else if (allocated(rgb2d)) then + allocate(grib2d(nxr*nyr,nconsd2d)); grib2d=0.0 + allocate(g2d(1:nconsd2d)); g2d=0.0 + grib2d(:, 1:nconsd2d) = rgc2d + g2d(1:nconsd2d) = c2d + else if (allocated(rgc2d)) then + allocate(grib2d(nxr*nyr,nbilin2d)); grib2d=0.0 + allocate(g2d(1:nbilin2d)); g2d=0.0 + grib2d(:, 1:nbilin2d) = rgb2d + g2d(1:nbilin2d) = b2d + end if + + call write_grib2_2d(gout, g2d, (/nxr,nyr/), nconsd2d+nbilin2d, grib2d, rgmask2d, vfill) + + if (allocated(rgb3d)) then + gout = trim(ftype)//'.'//trim(fdst)//'_3D.gb2' + call write_grib2_3d(gout, b3d, (/nxr,nyr,nlevs/), nbilin3d, rgb3d, rgmask3d, vfill) + if (debug) write(logunit, '(a)')'GRIB2 3D output file: '//trim(gout) + end if + end if + + ! -------------------------------------------------------- ! write the mapped fields ! -------------------------------------------------------- @@ -375,39 +414,6 @@ program ocnicepost call nf90_err(nf90_close(ncid), 'close: '// trim(fout)) write(logunit,'(a)')trim(fout)//' done' - - if(grib2) then - gout = trim(ftype)//'.'//trim(fdst)//'.gb2' - if (debug) write(logunit, '(a)')'GRIB2 2D output file: '//trim(gout) - - if (allocated(rgb2d) .and. allocated(rgc2d)) then - allocate(grib2d(nxr*nyr,nconsd2d+nbilin2d)) - allocate(g2d(1:nconsd2d+nbilin2d)) - grib2d(:, 1:nbilin2d) = rgb2d - grib2d(:, nbilin2d+1:nconsd2d+nbilin2d) = rgc2d - g2d(1:nbilin2d) = b2d - g2d(nbilin2d+1:nconsd2d+nbilin2d) = c2d - else if (allocated(rgb2d)) then - allocate(grib2d(nxr*nyr,nconsd2d)) - allocate(g2d(1:nconsd2d)) - grib2d(:, 1:nconsd2d) = rgc2d - g2d(1:nconsd2d) = c2d - else if (allocated(rgc2d)) then - allocate(grib2d(nxr*nyr,nbilin2d)) - allocate(g2d(1:nbilin2d)) - grib2d(:, 1:nbilin2d) = rgb2d - g2d(1:nbilin2d) = b2d - end if - - call write_grib2_2d(gout, g2d, (/nxr,nyr/), nconsd2d+nbilin2d, grib2d, rgmask2d) - - if (allocated(rgb3d)) then - gout = trim(ftype)//'.'//trim(fdst)//'_3D.gb2' - call write_grib2_3d(gout, b3d, (/nxr,nyr,nlevs/), nbilin3d, rgb3d, rgmask3d) - if (debug) write(logunit, '(a)')'GRIB2 3D output file: '//trim(gout) - end if - end if - stop end program ocnicepost \ No newline at end of file diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index ef6276a7..05d010d5 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -2,6 +2,7 @@ module utils_mod use netcdf use init_mod, only : debug, logunit, vardefs, fsrc, input_file, ftype + use ieee_arithmetic implicit none @@ -589,7 +590,7 @@ end subroutine dumpnc1d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !----------------------------------------------------------------------------------- - subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) + subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) implicit none @@ -599,6 +600,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) integer, intent(in) :: nflds real, intent(inout) :: field(dims(1)*dims(2),nflds) real, intent(in) :: rgmask2d(dims(1) * dims(2)) + real, intent(in) :: vfill ! internal variables integer(4) :: max_bytes, lengrib @@ -721,16 +723,16 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) return end if - write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%var_name, gcf(n) - - write(logunit,*) 'size_bmp ,size_rgmask2d', size(bmp), size(rgmask2d) - ! Compute max, min, and mean - max_val = maxval(field(:,n)) - min_val = minval(field(:,n)) - mean_val = sum(field(:,n)) / size(field(:,n)) + max_val = maxval(field(:,n).ne.vfill) + min_val = minval(field(:,n).ne.vfill) + mean_val = sum(field(:,n).ne.vfill) / size(field(:,n).ne.vfill) - write(logunit, *) 'Variable_name, max, min, mean: ', gcf(n)%var_name, max_val, min_val, mean_val +! if (debug) then + write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%var_name, gcf(n) + write(logunit,*) 'size_bmp ,size_rgmask2d', size(bmp), size(rgmask2d) + write(logunit, *) 'Variable_name, max, min, mean: ', gcf(n)%var_name, max_val, min_val, mean_val +! end if call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then @@ -745,16 +747,18 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) jpdt(1)=gcf(n)%var_g5 ! parm number catagory jpdt(2)=gcf(n)%var_g6 ! parm number jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) - jpdt(4)=0 ! 1: Forecast initialized from an earlier analysis + jpdt(4)=0 ! jpdt(5)=96 ! Code ON388 Table A- GFS - jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(7)=0 ! - jpdt(8)=0 ! - jpdt(9)=fortime ! forecast hour - jpdt(10)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level, 168 Ocean Model Layer,...) - jpdt(11)=0 ! scale factor - jpdt(12)=0 ! scale value - jpdt(13)=255 + jpdt(6)=0 ! + jpdt(7)=0 ! forecast hour + jpdt(8)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 + jpdt(7)=fortime ! forecast hour + jpdt(8)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) + jpdt(9)=0 ! + jpdt(10)=0 ! + jpdt(11)=255 + jpdt(12)=0 + jpdt(13)=0 jpdt(14)=0 jpdt(15)=0 jpdt(16)=0 @@ -769,8 +773,13 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) ibmap = 0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. -! where (rgmask2d == 1) bmp=.true. -! bmp=.true. + + if (gcf(n)%var_name .eq. 'WTMP') field(:,n) = field(:,n) + 273.15 + + where ( field(:,n) .eq. vfill ) field(:,n) = -9999.0 + where (field(:,n) .eq. -9999.0) bmp(:)= .false. + + write(logunit, *) 'bmp: ', bmp ! Assign Template 5 ! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) @@ -780,7 +789,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! ! Reserved fields @@ -789,14 +798,6 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d) idrtlen=size(idrtmpl) - if (gcf(n)%var_name .eq. 'WTMP') field(:,n) = field(:,n) + 273.15 - - where ( field(:,n) < -9999 ) field(:,n) = -9999.0 - - where (field(:,n) .eq. -9999.0) bmp= .false. - - write(logunit, *) 'bmp: ', bmp - call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,n), npt, ibmap, bmp, ierr) if (ierr /= 0) then @@ -827,7 +828,7 @@ end subroutine write_grib2_2d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !----------------------------------------------------------------------------------- - subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) + subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) implicit none @@ -837,6 +838,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) integer, intent(in) :: nflds real, intent(inout) :: field( dims(1) * dims(2) , dims(3) , nflds ) real, intent(in) :: rgmask3d(dims(1) * dims(2) , dims(3)) + real, intent(in) :: vfill ! internal variables integer(4) :: max_bytes, lengrib @@ -1003,14 +1005,14 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) jpdt(1)=gcf(n)%var_g5 ! parm number catagory jpdt(2)=gcf(n)%var_g6 ! parm number jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) - jpdt(4)=0 ! 1: Forecast initialized from an earlier analysis - jpdt(5)=96 ! Code ON388 Table A- GFS - jpdt(6)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(7)=0 ! forecast hour - jpdt(8)=0 ! + jpdt(4)=0 ! + jpdt(5)=96 ! Code ON388 Table A- GFS + jpdt(6)=0 ! + jpdt(7)=0 ! forecast hour + jpdt(8)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 jpdt(7)=fortime ! forecast hour - jpdt(8)=gcf(n)%var_g8 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) - jpdt(9)=0 ! scale factor + jpdt(8)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) + jpdt(9)=0 ! scale factor jpdt(10)=dep(lyr) ! scale value jpdt(11)=255 jpdt(12)=0 @@ -1028,6 +1030,11 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) ibmap=0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. + if (gcf(n)%var_name .eq. 'WTMP') field(:,lyr,n) = field(:,lyr,n) + 273.15 + + where ( field(:,lyr,n) .eq. vfill ) field(:,lyr,n) = -9999.0 + where (field(:,lyr,n) .eq. -9999.0) bmp(:)= .false. + ! Assign Template 5 ! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) @@ -1036,7 +1043,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! ! Reserved fields @@ -1044,10 +1051,6 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d) idrtlen=size(idrtmpl) - where ( field(:,lyr,n) < -9999 ) field(:,lyr,n) = -9999.0 - - where (field(:,lyr,n) .eq. -9999.0) bmp= .false. - write(logunit, *) 'bmp: ', bmp call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & From 118dbc4cd60aab530c8aa23f991498f2e9b904ee Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 11:05:47 -0500 Subject: [PATCH 096/124] fixed issues --- src/ocnicepost.fd/utils_mod.F90 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 05d010d5..e32188a0 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -724,9 +724,9 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) end if ! Compute max, min, and mean - max_val = maxval(field(:,n).ne.vfill) - min_val = minval(field(:,n).ne.vfill) - mean_val = sum(field(:,n).ne.vfill) / size(field(:,n).ne.vfill) + max_val = maxval(field(:,n), mask = field(:,n) .ne. vfill) + min_val = minval(field(:,n), mask = field(:,n) .ne. vfill) + mean_val = sum(field(:,n), mask = field(:,n) .ne. vfill) / count(field(:,n) .ne. vfill) ! if (debug) then write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%var_name, gcf(n) @@ -750,7 +750,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) jpdt(4)=0 ! jpdt(5)=96 ! Code ON388 Table A- GFS jpdt(6)=0 ! - jpdt(7)=0 ! forecast hour + jpdt(7)=0 ! jpdt(8)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 jpdt(7)=fortime ! forecast hour jpdt(8)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) @@ -774,7 +774,9 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) ibmap = 0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. - if (gcf(n)%var_name .eq. 'WTMP') field(:,n) = field(:,n) + 273.15 + if (gcf(n)%var_name .eq. 'WTMP') then + where ( field(:,n) .ne. vfill ) field(:,n) = field(:,n) + 273.15 + endif where ( field(:,n) .eq. vfill ) field(:,n) = -9999.0 where (field(:,n) .eq. -9999.0) bmp(:)= .false. @@ -1021,7 +1023,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) jpdt(15)=0 jpdt(16)=0 - if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) + if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:16) ipdtlen=size(jpdt) @@ -1030,10 +1032,13 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) ibmap=0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. - if (gcf(n)%var_name .eq. 'WTMP') field(:,lyr,n) = field(:,lyr,n) + 273.15 + if (gcf(n)%var_name .eq. 'WTMP') then + where ( field(:,lyr,n) .ne. vfill ) field(:,lyr,n) = field(:,lyr,n) + 273.15 + endif where ( field(:,lyr,n) .eq. vfill ) field(:,lyr,n) = -9999.0 - where (field(:,lyr,n) .eq. -9999.0) bmp(:)= .false. + + where ( field(:,lyr,n) .eq. -9999.0 ) bmp(:)= .false. ! Assign Template 5 ! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) From f5baace44bb8befd29315341e6e5cf8bfb8db9ba Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 11:15:57 -0500 Subject: [PATCH 097/124] fixed issues --- src/ocnicepost.fd/ocnicepost.F90 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index eab3e3f7..74306282 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -266,20 +266,20 @@ program ocnicepost if (debug) write(logunit, '(a)')'GRIB2 2D output file: '//trim(gout) if (allocated(rgb2d) .and. allocated(rgc2d)) then - allocate(grib2d(nxr*nyr,nconsd2d+nbilin2d)); grib2d=0.0 - allocate(g2d(1:nconsd2d+nbilin2d)); g2d=0.0 + allocate(grib2d(nxr*nyr,nconsd2d+nbilin2d), source=0.0) + allocate(g2d(1:nconsd2d+nbilin2d), source=0.0) grib2d(:, 1:nbilin2d) = rgb2d grib2d(:, nbilin2d+1:nconsd2d+nbilin2d) = rgc2d g2d(1:nbilin2d) = b2d g2d(nbilin2d+1:nconsd2d+nbilin2d) = c2d else if (allocated(rgb2d)) then - allocate(grib2d(nxr*nyr,nconsd2d)); grib2d=0.0 - allocate(g2d(1:nconsd2d)); g2d=0.0 + allocate(grib2d(nxr*nyr,nconsd2d), source=0.0) + allocate(g2d(1:nconsd2d), source=0.0) grib2d(:, 1:nconsd2d) = rgc2d g2d(1:nconsd2d) = c2d else if (allocated(rgc2d)) then - allocate(grib2d(nxr*nyr,nbilin2d)); grib2d=0.0 - allocate(g2d(1:nbilin2d)); g2d=0.0 + allocate(grib2d(nxr*nyr,nbilin2d), source=0.0) + allocate(g2d(1:nbilin2d), source=0.0) grib2d(:, 1:nbilin2d) = rgb2d g2d(1:nbilin2d) = b2d end if From ad679626e98c3e081b7e2461fe34d9969e2725c7 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 11:34:55 -0500 Subject: [PATCH 098/124] fixed issues --- src/ocnicepost.fd/ocnicepost.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 74306282..5c428bc8 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -267,19 +267,19 @@ program ocnicepost if (allocated(rgb2d) .and. allocated(rgc2d)) then allocate(grib2d(nxr*nyr,nconsd2d+nbilin2d), source=0.0) - allocate(g2d(1:nconsd2d+nbilin2d), source=0.0) + allocate(g2d(1:nconsd2d+nbilin2d)) grib2d(:, 1:nbilin2d) = rgb2d grib2d(:, nbilin2d+1:nconsd2d+nbilin2d) = rgc2d g2d(1:nbilin2d) = b2d g2d(nbilin2d+1:nconsd2d+nbilin2d) = c2d else if (allocated(rgb2d)) then allocate(grib2d(nxr*nyr,nconsd2d), source=0.0) - allocate(g2d(1:nconsd2d), source=0.0) + allocate(g2d(1:nconsd2d)) grib2d(:, 1:nconsd2d) = rgc2d g2d(1:nconsd2d) = c2d else if (allocated(rgc2d)) then allocate(grib2d(nxr*nyr,nbilin2d), source=0.0) - allocate(g2d(1:nbilin2d), source=0.0) + allocate(g2d(1:nbilin2d)) grib2d(:, 1:nbilin2d) = rgb2d g2d(1:nbilin2d) = b2d end if From 8c49fd4900665ea8d28f0e4b44aac7f1c16c143a Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 12:41:50 -0500 Subject: [PATCH 099/124] changed to simple packing --- src/ocnicepost.fd/utils_mod.F90 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index e32188a0..71f3301b 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -779,13 +779,13 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) endif where ( field(:,n) .eq. vfill ) field(:,n) = -9999.0 - where (field(:,n) .eq. -9999.0) bmp(:)= .false. + where (field(:,n) .eq. -9999.0) bmp(:) = .false. write(logunit, *) 'bmp: ', bmp ! Assign Template 5 -! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) +! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl=0 ! Populate idrtmpl @@ -1010,7 +1010,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) jpdt(4)=0 ! jpdt(5)=96 ! Code ON388 Table A- GFS jpdt(6)=0 ! - jpdt(7)=0 ! forecast hour + jpdt(7)=0 ! jpdt(8)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 jpdt(7)=fortime ! forecast hour jpdt(8)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) @@ -1041,8 +1041,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) where ( field(:,lyr,n) .eq. -9999.0 ) bmp(:)= .false. ! Assign Template 5 -! idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) +! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl=0 ! Populate idrtmpl From 1aa285f53ece3d68bcd17c40a0a55af8c6439678 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 12:59:44 -0500 Subject: [PATCH 100/124] trying to fix an issue --- src/ocnicepost.fd/utils_mod.F90 | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 71f3301b..a970bdf5 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -779,23 +779,25 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) endif where ( field(:,n) .eq. vfill ) field(:,n) = -9999.0 - where (field(:,n) .eq. -9999.0) bmp(:) = .false. + where (field(:,n) .eq. -9999.0) bmp(:)= .false. write(logunit, *) 'bmp: ', bmp - ! Assign Template 5 - idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) -! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) - + ! Create Section 5 parametrs + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + idrtmpl=0 ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! - idrtmpl(5) = 0 ! + idrtmpl(5) = 0 ! + idrtmpl(6) = 0 ! + idrtmpl(7) = 1 ! + idrtmpl(8) =-9999.0 ! Reserved fields - ! idrtmpl(6:16) = 0 ! Reserved for future use + ! idrtmpl(6:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) @@ -1041,8 +1043,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) where ( field(:,lyr,n) .eq. -9999.0 ) bmp(:)= .false. ! Assign Template 5 - idrtnum = 0 ! Template 5.0 (Grid Point Data - Simple Packing) -! idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl=0 ! Populate idrtmpl @@ -1051,6 +1053,9 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! + idrtmpl(6) = 0 ! + idrtmpl(7) = 1 ! + idrtmpl(8) =-9999.0 ! Reserved fields ! idrtmpl(6:16) = 0 ! Reserved for future use From 645be638f6ca0a0a6dfbf15a95c3c986c74ccb26 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 13:09:55 -0500 Subject: [PATCH 101/124] trying to fix an issue --- src/ocnicepost.fd/utils_mod.F90 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index a970bdf5..e1f20325 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -771,17 +771,17 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) coordlist=0. ! needed for hybrid vertical coordinate - ibmap = 0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + ibmap = 255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. if (gcf(n)%var_name .eq. 'WTMP') then where ( field(:,n) .ne. vfill ) field(:,n) = field(:,n) + 273.15 endif - where ( field(:,n) .eq. vfill ) field(:,n) = -9999.0 - where (field(:,n) .eq. -9999.0) bmp(:)= .false. +! where ( field(:,n) .eq. vfill ) field(:,n) = -9999.0 +! where (field(:,n) .eq. -9999.0) bmp(:)= .false. - write(logunit, *) 'bmp: ', bmp +! write(logunit, *) 'bmp: ', bmp ! Create Section 5 parametrs idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) @@ -795,12 +795,14 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) idrtmpl(5) = 0 ! idrtmpl(6) = 0 ! idrtmpl(7) = 1 ! - idrtmpl(8) =-9999.0 + idrtmpl(8) =vfill ! Reserved fields ! idrtmpl(6:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) + write(logunit, *) 'idrtmpl: ', idrtmpl + call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,n), npt, ibmap, bmp, ierr) From 4b4a98bc19eba2cf0e81975b169cad4a206991f9 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 13:19:59 -0500 Subject: [PATCH 102/124] trying to fix an issue --- src/ocnicepost.fd/utils_mod.F90 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index e1f20325..4238f808 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -797,7 +797,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) idrtmpl(7) = 1 ! idrtmpl(8) =vfill ! Reserved fields - ! idrtmpl(6:16) = 0 ! Reserved for future use + idrtmpl(9:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) @@ -1033,16 +1033,16 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate - ibmap=0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. if (gcf(n)%var_name .eq. 'WTMP') then where ( field(:,lyr,n) .ne. vfill ) field(:,lyr,n) = field(:,lyr,n) + 273.15 endif - where ( field(:,lyr,n) .eq. vfill ) field(:,lyr,n) = -9999.0 +! where ( field(:,lyr,n) .eq. vfill ) field(:,lyr,n) = -9999.0 - where ( field(:,lyr,n) .eq. -9999.0 ) bmp(:)= .false. +! where ( field(:,lyr,n) .eq. -9999.0 ) bmp(:)= .false. ! Assign Template 5 @@ -1059,7 +1059,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) idrtmpl(7) = 1 ! idrtmpl(8) =-9999.0 ! Reserved fields -! idrtmpl(6:16) = 0 ! Reserved for future use + idrtmpl(9:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) From 4933471996d49514044ad5c38d9aa0c5cc4ad209 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 13:39:32 -0500 Subject: [PATCH 103/124] trying to fix an issue --- src/ocnicepost.fd/utils_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 4238f808..4e54e4fd 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -732,6 +732,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%var_name, gcf(n) write(logunit,*) 'size_bmp ,size_rgmask2d', size(bmp), size(rgmask2d) write(logunit, *) 'Variable_name, max, min, mean: ', gcf(n)%var_name, max_val, min_val, mean_val + write(logunit, *) 'forcast time: ', fortime ! end if call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here @@ -752,7 +753,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) jpdt(6)=0 ! jpdt(7)=0 ! jpdt(8)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(7)=fortime ! forecast hour + jpdt(7)=fortime ! forecast time jpdt(8)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) jpdt(9)=0 ! jpdt(10)=0 ! @@ -1063,7 +1064,6 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) idrtlen=size(idrtmpl) - write(logunit, *) 'bmp: ', bmp call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,lyr,n), npt, ibmap, bmp, ierr) From 54d680b232a3525c6731c8d1dbf0b64b2d6c4ae9 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 14:09:20 -0500 Subject: [PATCH 104/124] Finalize the codes --- src/ocnicepost.fd/utils_mod.F90 | 38 +++++++++++++++------------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 4e54e4fd..00d3715e 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -626,6 +626,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) npt = dims(1) * dims(2) max_bytes = npt * 4 ! Estimated max bytes + bmp=.true. call getlun(lunout) call baopenw(lunout, trim(fname), ierr) @@ -728,12 +729,11 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) min_val = minval(field(:,n), mask = field(:,n) .ne. vfill) mean_val = sum(field(:,n), mask = field(:,n) .ne. vfill) / count(field(:,n) .ne. vfill) -! if (debug) then - write(logunit, *) 'n, nflds, npt: ', n, nflds, npt, gcf(n)%var_name, gcf(n) + if (debug) then + write(logunit, *) 'var_name, n: ', gcf(n)%var_name, n write(logunit,*) 'size_bmp ,size_rgmask2d', size(bmp), size(rgmask2d) write(logunit, *) 'Variable_name, max, min, mean: ', gcf(n)%var_name, max_val, min_val, mean_val - write(logunit, *) 'forcast time: ', fortime -! end if + end if call addgrid(cgrib, max_bytes, igds, jgdt, igdtlen, ideflist, idefnum, ierr) ! there is an internal error here if (ierr /= 0) then @@ -744,7 +744,6 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) ! Create Section 4 parametrs ipdtnum=0 - jpdt(1)=gcf(n)%var_g5 ! parm number catagory jpdt(2)=gcf(n)%var_g6 ! parm number jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) @@ -771,7 +770,6 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate - ibmap = 255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. @@ -782,12 +780,10 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) ! where ( field(:,n) .eq. vfill ) field(:,n) = -9999.0 ! where (field(:,n) .eq. -9999.0) bmp(:)= .false. -! write(logunit, *) 'bmp: ', bmp - ! Create Section 5 parametrs idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) - idrtmpl=0 + idrtmpl(:)=0 ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) @@ -795,14 +791,14 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! idrtmpl(6) = 0 ! - idrtmpl(7) = 1 ! - idrtmpl(8) =vfill +! idrtmpl(7) = 1 ! +! idrtmpl(8) =vfill ! Reserved fields idrtmpl(9:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) - write(logunit, *) 'idrtmpl: ', idrtmpl + if (debug) write(logunit, *) 'idrtmpl: ', idrtmpl call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & @@ -812,9 +808,9 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) return end if - call gribend(cgrib,max_bytes,lengrib,ierr) - write(logunit, *) 'gribend status=',ierr - write(logunit, *) 'length of the final GRIB2 message in octets =',lengrib + call gribend(cgrib, max_bytes, lengrib, ierr) + if (debug) write(logunit, *) 'gribend status=', ierr + if (debug) write(logunit, *) 'length of the final GRIB2 message in octets =', lengrib call wryte(lunout, lengrib, cgrib) deallocate(cgrib) @@ -873,6 +869,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) npt = dims(1) * dims(2) max_bytes = npt * 4 + bmp=.true. call getlun(lunout) call baopenw(lunout, trim(fname), ierr) @@ -1042,14 +1039,13 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) endif ! where ( field(:,lyr,n) .eq. vfill ) field(:,lyr,n) = -9999.0 - ! where ( field(:,lyr,n) .eq. -9999.0 ) bmp(:)= .false. ! Assign Template 5 idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) - idrtmpl=0 + idrtmpl(:)=0 ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) @@ -1057,8 +1053,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! idrtmpl(6) = 0 ! - idrtmpl(7) = 1 ! - idrtmpl(8) =-9999.0 +! idrtmpl(7) = 1 ! +! idrtmpl(8) =-9999.0 ! Reserved fields idrtmpl(9:16) = 0 ! Reserved for future use @@ -1073,8 +1069,8 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) end if call gribend(cgrib, max_bytes, lengrib, ierr) - write(logunit, *) 'gribend status=', ierr - write(logunit, *) 'length of the final GRIB2 message in octets =', lengrib + if (debug) write(logunit, *) 'gribend status=', ierr + if (debug) write(logunit, *) 'length of the final GRIB2 message in octets =', lengrib call wryte(lunout, lengrib, cgrib) deallocate(cgrib) From 5367c19321877bf66be9b994193aa08ed57b089e Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 14:56:43 -0500 Subject: [PATCH 105/124] Finalize the codes --- src/ocnicepost.fd/utils_mod.F90 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 00d3715e..36c43a08 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -1031,15 +1031,14 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate - ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + ibmap=0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. if (gcf(n)%var_name .eq. 'WTMP') then where ( field(:,lyr,n) .ne. vfill ) field(:,lyr,n) = field(:,lyr,n) + 273.15 endif -! where ( field(:,lyr,n) .eq. vfill ) field(:,lyr,n) = -9999.0 -! where ( field(:,lyr,n) .eq. -9999.0 ) bmp(:)= .false. + where ( field(:,lyr,n) .eq. vfill ) bmp(:)= .false. ! Assign Template 5 @@ -1053,8 +1052,6 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! idrtmpl(6) = 0 ! -! idrtmpl(7) = 1 ! -! idrtmpl(8) =-9999.0 ! Reserved fields idrtmpl(9:16) = 0 ! Reserved for future use From 536bf2796eec5228cfb57a78f001fb5b49091237 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Fri, 31 Jan 2025 15:00:08 -0500 Subject: [PATCH 106/124] Finalize the codes --- src/ocnicepost.fd/utils_mod.F90 | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 36c43a08..0facbf50 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -770,15 +770,14 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate - ibmap = 255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + ibmap = 0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. if (gcf(n)%var_name .eq. 'WTMP') then where ( field(:,n) .ne. vfill ) field(:,n) = field(:,n) + 273.15 endif -! where ( field(:,n) .eq. vfill ) field(:,n) = -9999.0 -! where (field(:,n) .eq. -9999.0) bmp(:)= .false. + where ( field(:,n) .eq. vfill ) bmp(:)= .false. ! Create Section 5 parametrs idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) @@ -791,10 +790,8 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! idrtmpl(6) = 0 ! -! idrtmpl(7) = 1 ! -! idrtmpl(8) =vfill ! Reserved fields - idrtmpl(9:16) = 0 ! Reserved for future use + idrtmpl(7:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) @@ -886,7 +883,6 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) listsec1(1) = gcf(1)%var_g3 ! Originating Centre (Common Code Table C-1) listsec1(2) = 0 ! Originating Sub-centre (local table) EMC=4 -! listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) @@ -1053,7 +1049,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) idrtmpl(5) = 0 ! idrtmpl(6) = 0 ! ! Reserved fields - idrtmpl(9:16) = 0 ! Reserved for future use + idrtmpl(7:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) From bd28fb31c75b7381e65159ce7938c0d846e08f61 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Mon, 3 Feb 2025 13:14:42 -0500 Subject: [PATCH 107/124] debug --- src/ocnicepost.fd/utils_mod.F90 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 0facbf50..99e36ae0 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -603,7 +603,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) real, intent(in) :: vfill ! internal variables - integer(4) :: max_bytes, lengrib + integer :: max_bytes, lengrib integer :: ref_time(6) integer :: lunout, ierr integer :: fortime, dij, npt @@ -614,9 +614,9 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen integer :: jgdt(19), jpdt(15), idrtmpl(16) - integer(4) :: igds(5) + integer :: igds(5) integer :: numcoord, ibmap - real(4) :: coordlist + real :: coordlist integer :: n, lon0, lon1, lat0, lat1 integer :: ideflist, idefnum logical :: bmp(dims(1)*dims(2)) @@ -841,7 +841,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) real, intent(in) :: vfill ! internal variables - integer(4) :: max_bytes, lengrib + integer :: max_bytes, lengrib integer :: ref_time(6) integer :: lunout, ierr integer :: fortime, dij, npt @@ -852,9 +852,9 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) integer :: igdtnum, ipdtnum, idrtnum integer :: igdtlen, ipdtlen, idrtlen integer :: jgdt(19), jpdt(15), idrtmpl(16) - integer(4) :: igds(5) + integer :: igds(5) integer :: numcoord, ibmap - real(4) :: coordlist + real :: coordlist integer :: ideflist, idefnum logical :: bmp( dims(1) * dims(2) ) From a8c9ead49d8a068e7969d084b53ff57954263a79 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Mon, 10 Feb 2025 11:43:19 -0500 Subject: [PATCH 108/124] added a tmp field --- src/ocnicepost.fd/utils_mod.F90 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 99e36ae0..29576489 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -608,6 +608,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) integer :: lunout, ierr integer :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib + real :: tmpfld(size(field(:,1)) ! GRIB2 metadata arrays integer :: listsec0(2), listsec1(13) @@ -797,9 +798,11 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) if (debug) write(logunit, *) 'idrtmpl: ', idrtmpl + tmpfld=0 + tmpfld =field(:,n) call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & - idrtnum, idrtmpl, idrtlen, field(:,n), npt, ibmap, bmp, ierr) + idrtnum, idrtmpl, idrtlen, tmpfld, npt, ibmap, bmp, ierr) if (ierr /= 0) then write(0, *) 'Error adding field to GRIB2 message', ierr return @@ -1027,18 +1030,18 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate - ibmap=0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. if (gcf(n)%var_name .eq. 'WTMP') then where ( field(:,lyr,n) .ne. vfill ) field(:,lyr,n) = field(:,lyr,n) + 273.15 endif - where ( field(:,lyr,n) .eq. vfill ) bmp(:)= .false. +! where ( field(:,lyr,n) .eq. vfill ) bmp(:)= .false. ! Assign Template 5 - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 0 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl(:)=0 ! Populate idrtmpl @@ -1056,7 +1059,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, field(:,lyr,n), npt, ibmap, bmp, ierr) - if (ierr /= 0) then + if (ierr /=- 0) then write(0, *) 'Error adding field to GRIB2 message', ierr return end if From 82b38320e1b6b74292495ed0ab3ebe6513484750 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Mon, 10 Feb 2025 12:48:10 -0500 Subject: [PATCH 109/124] some change to debug the issue of large negative numbers --- src/ocnicepost.fd/utils_mod.F90 | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 29576489..83b90fdf 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -596,30 +596,30 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) character(len=*), intent(in) :: fname type(vardefs), intent(in) :: gcf(:) - integer, intent(in) :: dims(2) - integer, intent(in) :: nflds - real, intent(inout) :: field(dims(1)*dims(2),nflds) - real, intent(in) :: rgmask2d(dims(1) * dims(2)) - real, intent(in) :: vfill + integer(4), intent(in) :: dims(2) + integer(4), intent(in) :: nflds + real(4), intent(inout) :: field(dims(1)*dims(2),nflds) + real(4), intent(in) :: rgmask2d(dims(1) * dims(2)) + real(4), intent(in) :: vfill ! internal variables - integer :: max_bytes, lengrib - integer :: ref_time(6) - integer :: lunout, ierr - integer :: fortime, dij, npt + integer(4) :: max_bytes, lengrib + integer(4) :: ref_time(6) + integer(4) :: lunout, ierr + integer(4) :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib - real :: tmpfld(size(field(:,1)) + real(4) :: tmpfld(size(field(:,1))) ! GRIB2 metadata arrays - integer :: listsec0(2), listsec1(13) - integer :: igdtnum, ipdtnum, idrtnum - integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(16) - integer :: igds(5) - integer :: numcoord, ibmap + integer(4) :: listsec0(2), listsec1(13) + integer(4) :: igdtnum, ipdtnum, idrtnum + integer(4) :: igdtlen, ipdtlen, idrtlen + integer(4) :: jgdt(19), jpdt(15), idrtmpl(16) + integer(4) :: igds(5) + integer(4) :: numcoord, ibmap real :: coordlist - integer :: n, lon0, lon1, lat0, lat1 - integer :: ideflist, idefnum + integer(4) :: n, lon0, lon1, lat0, lat1 + integer(4) :: ideflist, idefnum logical :: bmp(dims(1)*dims(2)) real :: max_val, min_val, mean_val @@ -771,17 +771,17 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate - ibmap = 0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + ibmap = 255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. if (gcf(n)%var_name .eq. 'WTMP') then where ( field(:,n) .ne. vfill ) field(:,n) = field(:,n) + 273.15 endif - where ( field(:,n) .eq. vfill ) bmp(:)= .false. + where ( field(:,n) .eq. vfill ) field(:,n)= 999.0 ! Create Section 5 parametrs - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 0 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl(:)=0 ! Populate idrtmpl From 8081588e71adcc2d212d93fddef979995f79b1b6 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Mon, 10 Feb 2025 14:11:33 -0500 Subject: [PATCH 110/124] fixed typos on section 4 --- src/ocnicepost.fd/utils_mod.F90 | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 83b90fdf..6481d4df 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -753,16 +753,14 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) jpdt(6)=0 ! jpdt(7)=0 ! jpdt(8)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(7)=fortime ! forecast time - jpdt(8)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) - jpdt(9)=0 ! - jpdt(10)=0 ! - jpdt(11)=255 - jpdt(12)=0 + jpdt(9)=fortime ! forecast time + jpdt(10)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) + jpdt(11)=0 ! + jpdt(12)=0 ! jpdt(13)=0 jpdt(14)=0 jpdt(15)=0 - jpdt(16)=0 + if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:16) @@ -1013,16 +1011,13 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) jpdt(6)=0 ! jpdt(7)=0 ! jpdt(8)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(7)=fortime ! forecast hour - jpdt(8)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) - jpdt(9)=0 ! scale factor - jpdt(10)=dep(lyr) ! scale value - jpdt(11)=255 - jpdt(12)=0 - jpdt(13)=0 + jpdt(9)=fortime ! forecast hour + jpdt(10)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) + jpdt(11)=0 ! scale factor + jpdt(12)=dep(lyr) ! scale value + jpdt(13)=255 jpdt(14)=0 jpdt(15)=0 - jpdt(16)=0 if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:16) From 76ffd30107e094a5c2ba31bd16f717bce2edc33f Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Mon, 10 Feb 2025 15:17:40 -0500 Subject: [PATCH 111/124] changed section 5 values --- src/ocnicepost.fd/utils_mod.F90 | 37 +++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 6481d4df..42739202 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -679,7 +679,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) jgdt(8) = dims(1) jgdt(9) = dims(2) jgdt(10) = 0 - jgdt(11) = 1000000 + jgdt(11) = -1 jgdt(12) = lat0 jgdt(13) = lon0 jgdt(14) = 48 !0 @@ -776,17 +776,17 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) where ( field(:,n) .ne. vfill ) field(:,n) = field(:,n) + 273.15 endif - where ( field(:,n) .eq. vfill ) field(:,n)= 999.0 + where ( field(:,n) .eq. vfill ) field(:,n)= -9999.0 ! Create Section 5 parametrs idrtnum = 0 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl(:)=0 ! Populate idrtmpl - idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) - idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) - idrtmpl(4) = 0 ! + idrtmpl(1) = min_val ! Reference value (scaled value of the minimum data point) + idrtmpl(2) = 100 ! Binary scale factor (scale by 2^E) + idrtmpl(3) = 0 ! Decimal scale factor (scale by 10^D) + idrtmpl(4) = 32 ! idrtmpl(5) = 0 ! idrtmpl(6) = 0 ! ! Reserved fields @@ -943,7 +943,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) jgdt(8) = dims(1) jgdt(9) = dims(2) jgdt(10) = 0 - jgdt(11) = 1000000 + jgdt(11) = -1 jgdt(12) = lat0 jgdt(13) = lon0 jgdt(14) = 48 @@ -1003,28 +1003,29 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) ipdtnum=0 - jpdt(1)=gcf(n)%var_g5 ! parm number catagory - jpdt(2)=gcf(n)%var_g6 ! parm number - jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) - jpdt(4)=0 ! - jpdt(5)=96 ! Code ON388 Table A- GFS - jpdt(6)=0 ! - jpdt(7)=0 ! - jpdt(8)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(9)=fortime ! forecast hour + jpdt(1)=gcf(n)%var_g5 ! parm number catagory + jpdt(2)=gcf(n)%var_g6 ! parm number + jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) + jpdt(4)=0 ! + jpdt(5)=96 ! Code ON388 Table A- GFS + jpdt(6)=0 ! + jpdt(7)=0 ! + jpdt(8)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 + jpdt(9)=fortime ! forecast hour jpdt(10)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) jpdt(11)=0 ! scale factor - jpdt(12)=dep(lyr) ! scale value + jpdt(12)=dep(lyr) ! scale value jpdt(13)=255 jpdt(14)=0 jpdt(15)=0 - if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:16) + if (debug) write(logunit, *) 'ipdtnum=', ipdtnum, ', jpdt= ', jpdt(1:15) ipdtlen=size(jpdt) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate + ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. From ef6347d05f01e6bd359697bfeea9d327c58d6c7c Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Mon, 10 Feb 2025 15:53:29 -0500 Subject: [PATCH 112/124] changed section 5 values --- src/ocnicepost.fd/utils_mod.F90 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 42739202..5d8c0d99 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -779,14 +779,14 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) where ( field(:,n) .eq. vfill ) field(:,n)= -9999.0 ! Create Section 5 parametrs - idrtnum = 0 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl(:)=0 ! Populate idrtmpl - idrtmpl(1) = min_val ! Reference value (scaled value of the minimum data point) - idrtmpl(2) = 100 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 0 ! Decimal scale factor (scale by 10^D) - idrtmpl(4) = 32 ! + idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) + idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) + idrtmpl(3) = -3 ! Decimal scale factor (scale by 10^D) + idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! idrtmpl(6) = 0 ! ! Reserved fields From d23cf8835afc664bd783c3a72d3d001291f07710 Mon Sep 17 00:00:00 2001 From: Amin Ilia <1621812366113305@mil> Date: Mon, 10 Feb 2025 16:04:24 -0500 Subject: [PATCH 113/124] changed section 5 values --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 5d8c0d99..45687c2c 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -785,7 +785,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = -3 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! idrtmpl(6) = 0 ! From 67c3d52eec884f562d430a20018e9b7cbfb457f2 Mon Sep 17 00:00:00 2001 From: AminIlia-NOAA Date: Thu, 13 Feb 2025 10:11:52 -0500 Subject: [PATCH 114/124] finalized the grib2 writer code --- src/ocnicepost.fd/utils_mod.F90 | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 45687c2c..b6a34546 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -594,8 +594,8 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) implicit none - character(len=*), intent(in) :: fname - type(vardefs), intent(in) :: gcf(:) + character(len=*), intent(in) :: fname + type(vardefs), intent(in) :: gcf(:) integer(4), intent(in) :: dims(2) integer(4), intent(in) :: nflds real(4), intent(inout) :: field(dims(1)*dims(2),nflds) @@ -608,8 +608,8 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) integer(4) :: lunout, ierr integer(4) :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib - real(4) :: tmpfld(size(field(:,1))) - + real(4) :: tmpfld(size(field,1)) +k ! GRIB2 metadata arrays integer(4) :: listsec0(2), listsec1(13) integer(4) :: igdtnum, ipdtnum, idrtnum @@ -622,7 +622,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) integer(4) :: ideflist, idefnum logical :: bmp(dims(1)*dims(2)) - real :: max_val, min_val, mean_val + real :: max_val, min_val, mean_val, count_val npt = dims(1) * dims(2) @@ -772,14 +772,14 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) ibmap = 255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. - if (gcf(n)%var_name .eq. 'WTMP') then + if (trim(gcf(n)%name_gb2) .eq. 'WTMP') then where ( field(:,n) .ne. vfill ) field(:,n) = field(:,n) + 273.15 endif - where ( field(:,n) .eq. vfill ) field(:,n)= -9999.0 + where ( field(:,n) .eq. vfill ) field(:,n)= 9999.0 ! Create Section 5 parametrs - idrtnum = 2 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 0 ! Template 5.2 (Grid Point Data - complex Packing) idrtmpl(:)=0 ! Populate idrtmpl @@ -799,6 +799,9 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) tmpfld=0 tmpfld =field(:,n) + + write(logunit, *) 'Variable_name, max, min, mean, count: ', gcf(n)%var_name, max_val, min_val, mean_val, count_val + call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, tmpfld, npt, ibmap, bmp, ierr) if (ierr /= 0) then @@ -847,6 +850,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) integer :: lunout, ierr integer :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib + real(4) :: tmpfld(size(field,1), size(field,2)) ! GRIB2 metadata arrays integer :: listsec0(2), listsec1(13) @@ -1029,12 +1033,10 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. - if (gcf(n)%var_name .eq. 'WTMP') then + if (trim(gcf(n)%name_gb2) .eq. 'WTMP') then where ( field(:,lyr,n) .ne. vfill ) field(:,lyr,n) = field(:,lyr,n) + 273.15 endif -! where ( field(:,lyr,n) .eq. vfill ) bmp(:)= .false. - ! Assign Template 5 idrtnum = 0 ! Template 5.2 (Grid Point Data - complex Packing) @@ -1052,9 +1054,12 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) idrtlen=size(idrtmpl) + tmpfld=0 + tmpfld =field(:,lyr,n) + call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & - idrtnum, idrtmpl, idrtlen, field(:,lyr,n), npt, ibmap, bmp, ierr) + idrtnum, idrtmpl, idrtlen, tmpfld, npt, ibmap, bmp, ierr) if (ierr /=- 0) then write(0, *) 'Error adding field to GRIB2 message', ierr return From 5f4858189b596085bfa04720614d7dfb61a8d4e6 Mon Sep 17 00:00:00 2001 From: Amin Ilia Date: Thu, 13 Feb 2025 10:18:22 -0500 Subject: [PATCH 115/124] Update utils_mod.F90 finalized --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index b6a34546..400f777b 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -609,7 +609,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) integer(4) :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib real(4) :: tmpfld(size(field,1)) -k + ! GRIB2 metadata arrays integer(4) :: listsec0(2), listsec1(13) integer(4) :: igdtnum, ipdtnum, idrtnum From d8e14141fa24fc60044741c713827d728d1c66b0 Mon Sep 17 00:00:00 2001 From: AminIlia-NOAA Date: Thu, 13 Feb 2025 10:29:34 -0500 Subject: [PATCH 116/124] fixed some issue in write_grib2_3d --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index b6a34546..400f777b 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -609,7 +609,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) integer(4) :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib real(4) :: tmpfld(size(field,1)) -k + ! GRIB2 metadata arrays integer(4) :: listsec0(2), listsec1(13) integer(4) :: igdtnum, ipdtnum, idrtnum From c778b79a1275c4692a22a35a1da76967e8ded2aa Mon Sep 17 00:00:00 2001 From: AminIlia-NOAA Date: Thu, 13 Feb 2025 10:33:49 -0500 Subject: [PATCH 117/124] fixed an issue in write_grib2_3d --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 400f777b..b510ee73 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -850,7 +850,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) integer :: lunout, ierr integer :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib - real(4) :: tmpfld(size(field,1), size(field,2)) + real(4) :: tmpfld(size(field,1)) ! GRIB2 metadata arrays integer :: listsec0(2), listsec1(13) From 408074eb8b99b0cb199bf4144093570396982a23 Mon Sep 17 00:00:00 2001 From: Amin Ilia Date: Thu, 13 Feb 2025 10:36:10 -0500 Subject: [PATCH 118/124] Update utils_mod.F90 fixed issue in write_grib2_3d --- src/ocnicepost.fd/utils_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 400f777b..b510ee73 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -850,7 +850,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) integer :: lunout, ierr integer :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib - real(4) :: tmpfld(size(field,1), size(field,2)) + real(4) :: tmpfld(size(field,1)) ! GRIB2 metadata arrays integer :: listsec0(2), listsec1(13) From 89dcdd8f65deebaceac280e85e2c4c8a9bf93352 Mon Sep 17 00:00:00 2001 From: AminIlia-NOAA Date: Fri, 14 Feb 2025 11:25:14 -0500 Subject: [PATCH 119/124] changed stack version --- modulefiles/gfsutils_hera.intel.lua | 6 +++--- src/ocnicepost.fd/utils_mod.F90 | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modulefiles/gfsutils_hera.intel.lua b/modulefiles/gfsutils_hera.intel.lua index c4c56935..d0d1c39f 100644 --- a/modulefiles/gfsutils_hera.intel.lua +++ b/modulefiles/gfsutils_hera.intel.lua @@ -2,11 +2,11 @@ help([[ Build environment for GFS utilities on Hera ]]) -prepend_path("MODULEPATH", "/scratch1/NCEPDEV/nems/role.epic/spack-stack/spack-stack-1.6.0/envs/gsi-addon-dev-rocky8/install/modulefiles/Core") +prepend_path("MODULEPATH", "/scratch1/NCEPDEV/nems/role.epic/spack-stack/spack-stack-1.7.0/envs/gsi-addon-intel/install/modulefiles/Core") local stack_intel_ver=os.getenv("stack_intel_ver") or "2021.5.0" -local stack_impi_ver=os.getenv("stack_impi_ver") or "2021.5.1" -local cmake_ver=os.getenv("cmake_ver") or "3.23.1" +local stack_impi_ver=os.getenv("stack_impi_ver") or "2021.5.0" +local cmake_ver=os.getenv("cmake_ver") or "3.28.1" load(pathJoin("stack-intel", stack_intel_ver)) load(pathJoin("stack-intel-oneapi-mpi", stack_impi_ver)) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index b510ee73..7dc7f571 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -867,7 +867,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) real, dimension(40) :: dep1 real, dimension(28) :: dep2 real, dimension(:), allocatable :: dep - + npt = dims(1) * dims(2) max_bytes = npt * 4 From 6129e4e8a4e37779138bb98b387e6ceffbda2ea6 Mon Sep 17 00:00:00 2001 From: AminIlia-NOAA Date: Thu, 20 Feb 2025 13:53:35 -0500 Subject: [PATCH 120/124] Some changes for real float data type --- modulefiles/gfsutils_hera.intel.lua | 6 +++--- src/ocnicepost.fd/ocnicepost.F90 | 4 ++-- src/ocnicepost.fd/utils_mod.F90 | 31 +++++++++++++---------------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/modulefiles/gfsutils_hera.intel.lua b/modulefiles/gfsutils_hera.intel.lua index d0d1c39f..c4c56935 100644 --- a/modulefiles/gfsutils_hera.intel.lua +++ b/modulefiles/gfsutils_hera.intel.lua @@ -2,11 +2,11 @@ help([[ Build environment for GFS utilities on Hera ]]) -prepend_path("MODULEPATH", "/scratch1/NCEPDEV/nems/role.epic/spack-stack/spack-stack-1.7.0/envs/gsi-addon-intel/install/modulefiles/Core") +prepend_path("MODULEPATH", "/scratch1/NCEPDEV/nems/role.epic/spack-stack/spack-stack-1.6.0/envs/gsi-addon-dev-rocky8/install/modulefiles/Core") local stack_intel_ver=os.getenv("stack_intel_ver") or "2021.5.0" -local stack_impi_ver=os.getenv("stack_impi_ver") or "2021.5.0" -local cmake_ver=os.getenv("cmake_ver") or "3.28.1" +local stack_impi_ver=os.getenv("stack_impi_ver") or "2021.5.1" +local cmake_ver=os.getenv("cmake_ver") or "3.23.1" load(pathJoin("stack-intel", stack_intel_ver)) load(pathJoin("stack-intel-oneapi-mpi", stack_impi_ver)) diff --git a/src/ocnicepost.fd/ocnicepost.F90 b/src/ocnicepost.fd/ocnicepost.F90 index 5c428bc8..c15c60cb 100644 --- a/src/ocnicepost.fd/ocnicepost.F90 +++ b/src/ocnicepost.fd/ocnicepost.F90 @@ -284,11 +284,11 @@ program ocnicepost g2d(1:nbilin2d) = b2d end if - call write_grib2_2d(gout, g2d, (/nxr,nyr/), nconsd2d+nbilin2d, grib2d, rgmask2d, vfill) + call write_grib2_2d(gout, g2d, (/nxr,nyr/), nconsd2d+nbilin2d, grib2d, vfill) if (allocated(rgb3d)) then gout = trim(ftype)//'.'//trim(fdst)//'_3D.gb2' - call write_grib2_3d(gout, b3d, (/nxr,nyr,nlevs/), nbilin3d, rgb3d, rgmask3d, vfill) + call write_grib2_3d(gout, b3d, (/nxr,nyr,nlevs/), nbilin3d, rgb3d, vfill) if (debug) write(logunit, '(a)')'GRIB2 3D output file: '//trim(gout) end if end if diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index 7dc7f571..d83106fe 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -2,7 +2,7 @@ module utils_mod use netcdf use init_mod, only : debug, logunit, vardefs, fsrc, input_file, ftype - use ieee_arithmetic + implicit none @@ -590,7 +590,7 @@ end subroutine dumpnc1d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !----------------------------------------------------------------------------------- - subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) + subroutine write_grib2_2d(fname, gcf, dims, nflds, field, vfill) implicit none @@ -599,7 +599,6 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) integer(4), intent(in) :: dims(2) integer(4), intent(in) :: nflds real(4), intent(inout) :: field(dims(1)*dims(2),nflds) - real(4), intent(in) :: rgmask2d(dims(1) * dims(2)) real(4), intent(in) :: vfill ! internal variables @@ -608,7 +607,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) integer(4) :: lunout, ierr integer(4) :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib - real(4) :: tmpfld(size(field,1)) + real(8) :: tmpfld(size(field,1)) ! GRIB2 metadata arrays integer(4) :: listsec0(2), listsec1(13) @@ -617,10 +616,10 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) integer(4) :: jgdt(19), jpdt(15), idrtmpl(16) integer(4) :: igds(5) integer(4) :: numcoord, ibmap - real :: coordlist + real(4) :: coordlist integer(4) :: n, lon0, lon1, lat0, lat1 integer(4) :: ideflist, idefnum - logical :: bmp(dims(1)*dims(2)) + logical*1 :: bmp(dims(1)*dims(2)) real :: max_val, min_val, mean_val, count_val @@ -668,7 +667,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) lat0 = -90000000 lat1 = 90000000 - ! Populate the jgdt array for Template 3.0 (changed parameters to current grib2 files) + ! Populate the jgdt array for Template 3.0 jgdt(1) = 6 jgdt(2) = 0 jgdt(3) = 0 @@ -797,7 +796,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, rgmask2d, vfill) if (debug) write(logunit, *) 'idrtmpl: ', idrtmpl tmpfld=0 - tmpfld =field(:,n) + tmpfld=real(field(:,n), 8) write(logunit, *) 'Variable_name, max, min, mean, count: ', gcf(n)%var_name, max_val, min_val, mean_val, count_val @@ -832,7 +831,7 @@ end subroutine write_grib2_2d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !----------------------------------------------------------------------------------- - subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) + subroutine write_grib2_3d(fname, gcf, dims, nflds, field, vfill) implicit none @@ -841,7 +840,6 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) integer, intent(in) :: dims(3) integer, intent(in) :: nflds real, intent(inout) :: field( dims(1) * dims(2) , dims(3) , nflds ) - real, intent(in) :: rgmask3d(dims(1) * dims(2) , dims(3)) real, intent(in) :: vfill ! internal variables @@ -850,7 +848,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) integer :: lunout, ierr integer :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib - real(4) :: tmpfld(size(field,1)) + real(8) :: tmpfld(size(field,1)) ! GRIB2 metadata arrays integer :: listsec0(2), listsec1(13) @@ -861,12 +859,12 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) integer :: numcoord, ibmap real :: coordlist integer :: ideflist, idefnum - logical :: bmp( dims(1) * dims(2) ) + logical*1 :: bmp( dims(1) * dims(2) ) integer :: n, lon0, lon1, lat0, lat1, nlay, lyr - real, dimension(40) :: dep1 - real, dimension(28) :: dep2 - real, dimension(:), allocatable :: dep + integer, dimension(40) :: dep1 + integer, dimension(28) :: dep2 + integer, dimension(:), allocatable :: dep npt = dims(1) * dims(2) @@ -1055,8 +1053,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, rgmask3d, vfill) idrtlen=size(idrtmpl) tmpfld=0 - tmpfld =field(:,lyr,n) - + tmpfld=real(field(:,lyr,n), 8) call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, tmpfld, npt, ibmap, bmp, ierr) From 776d147a84177fd1ae7d341ae0e909af17d4e199 Mon Sep 17 00:00:00 2001 From: AminIlia-NOAA Date: Thu, 20 Feb 2025 14:49:26 -0500 Subject: [PATCH 121/124] test --- src/ocnicepost.fd/masking_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocnicepost.fd/masking_mod.F90 b/src/ocnicepost.fd/masking_mod.F90 index dc103287..b3ac9c99 100644 --- a/src/ocnicepost.fd/masking_mod.F90 +++ b/src/ocnicepost.fd/masking_mod.F90 @@ -27,7 +27,7 @@ subroutine remap_masks(vfill) ! local variables integer :: rc, ncid, varid, n character(len=240) :: wgtsfile - real :: minlat = -78.00 ! This is masking Antarctica which is not in the weighting file + real :: minlat = -78.00 ! This is masking Antarctica which is not masked in the weighting file real, allocatable, dimension(:) :: out1d From e53ab1e2b9da5fccfdf2e6147c70cf7653c75e40 Mon Sep 17 00:00:00 2001 From: AminIlia-NOAA Date: Thu, 20 Feb 2025 15:17:05 -0500 Subject: [PATCH 122/124] variables types have been changed --- src/ocnicepost.fd/utils_mod.F90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index d83106fe..ee0d4f72 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -730,8 +730,6 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, vfill) mean_val = sum(field(:,n), mask = field(:,n) .ne. vfill) / count(field(:,n) .ne. vfill) if (debug) then - write(logunit, *) 'var_name, n: ', gcf(n)%var_name, n - write(logunit,*) 'size_bmp ,size_rgmask2d', size(bmp), size(rgmask2d) write(logunit, *) 'Variable_name, max, min, mean: ', gcf(n)%var_name, max_val, min_val, mean_val end if From 2e3fa29139356724ede4806f8b79fdf0f5543b6e Mon Sep 17 00:00:00 2001 From: AminIlia-NOAA Date: Mon, 24 Feb 2025 10:58:43 -0500 Subject: [PATCH 123/124] added bitmap --- src/ocnicepost.fd/utils_mod.F90 | 81 +++++++++++++++++---------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index ee0d4f72..e88a1e4d 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -621,7 +621,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, vfill) integer(4) :: ideflist, idefnum logical*1 :: bmp(dims(1)*dims(2)) - real :: max_val, min_val, mean_val, count_val + real(4):: max_val, min_val, mean_val, count_val npt = dims(1) * dims(2) @@ -681,7 +681,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, vfill) jgdt(11) = -1 jgdt(12) = lat0 jgdt(13) = lon0 - jgdt(14) = 48 !0 + jgdt(14) = 48 jgdt(15) = lat1 jgdt(16) = lon1 jgdt(17) = dij @@ -742,18 +742,18 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, vfill) ! Create Section 4 parametrs ipdtnum=0 - jpdt(1)=gcf(n)%var_g5 ! parm number catagory - jpdt(2)=gcf(n)%var_g6 ! parm number - jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) - jpdt(4)=0 ! - jpdt(5)=96 ! Code ON388 Table A- GFS - jpdt(6)=0 ! - jpdt(7)=0 ! - jpdt(8)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 - jpdt(9)=fortime ! forecast time + jpdt(1)=gcf(n)%var_g5 ! parm number catagory + jpdt(2)=gcf(n)%var_g6 ! parm number + jpdt(3)=2 ! (0-analysis, 1-initialazation, 2-forecast, .. GRIB2 - CODE TABLE 4.3 ) + jpdt(4)=0 ! + jpdt(5)=96 ! Code ON388 Table A- GFS + jpdt(6)=0 ! + jpdt(7)=0 ! + jpdt(8)=1 ! unit (Hour=1) 6hour=11 (ask later) Table 4.4 + jpdt(9)=fortime ! forecast time jpdt(10)=gcf(n)%var_g7 ! level ID (1-Ground or Water Surface, 101 mean sea level, 160 depth bellow mean sea level , 168-Ocean Model Layer,...) jpdt(11)=0 ! - jpdt(12)=0 ! + jpdt(12)=0 ! jpdt(13)=0 jpdt(14)=0 jpdt(15)=0 @@ -766,14 +766,14 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, vfill) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate - ibmap = 255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + ibmap = 0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. if (trim(gcf(n)%name_gb2) .eq. 'WTMP') then where ( field(:,n) .ne. vfill ) field(:,n) = field(:,n) + 273.15 endif - where ( field(:,n) .eq. vfill ) field(:,n)= 9999.0 + where ( field(:,n) .eq. vfill ) bmp(:)= .false. ! Create Section 5 parametrs idrtnum = 0 ! Template 5.2 (Grid Point Data - complex Packing) @@ -782,9 +782,9 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, vfill) ! Populate idrtmpl idrtmpl(1) = 0 ! Reference value (scaled value of the minimum data point) idrtmpl(2) = 0 ! Binary scale factor (scale by 2^E) - idrtmpl(3) = 2 ! Decimal scale factor (scale by 10^D) + idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! - idrtmpl(5) = 0 ! + idrtmpl(5) = 0 ! idrtmpl(6) = 0 ! ! Reserved fields idrtmpl(7:16) = 0 ! Reserved for future use @@ -833,36 +833,36 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, vfill) implicit none - character(len=*), intent(in) :: fname - type(vardefs), intent(in) :: gcf(:) - integer, intent(in) :: dims(3) - integer, intent(in) :: nflds - real, intent(inout) :: field( dims(1) * dims(2) , dims(3) , nflds ) - real, intent(in) :: vfill + character(len=*), intent(in) :: fname + type(vardefs), intent(in) :: gcf(:) + integer(4), intent(in) :: dims(3) + integer(4), intent(in) :: nflds + real(4), intent(inout) :: field( dims(1) * dims(2) , dims(3) , nflds ) + real(4), intent(in) :: vfill ! internal variables - integer :: max_bytes, lengrib - integer :: ref_time(6) - integer :: lunout, ierr - integer :: fortime, dij, npt + integer(4) :: max_bytes, lengrib + integer(4) :: ref_time(6) + integer(4) :: lunout, ierr + integer(4) :: fortime, dij, npt CHARACTER(len=1),allocatable,dimension(:) :: cgrib real(8) :: tmpfld(size(field,1)) ! GRIB2 metadata arrays - integer :: listsec0(2), listsec1(13) - integer :: igdtnum, ipdtnum, idrtnum - integer :: igdtlen, ipdtlen, idrtlen - integer :: jgdt(19), jpdt(15), idrtmpl(16) - integer :: igds(5) - integer :: numcoord, ibmap - real :: coordlist - integer :: ideflist, idefnum + integer(4) :: listsec0(2), listsec1(13) + integer(4) :: igdtnum, ipdtnum, idrtnum + integer(4) :: igdtlen, ipdtlen, idrtlen + integer(4) :: jgdt(19), jpdt(15), idrtmpl(16) + integer(4) :: igds(5) + integer(4) :: numcoord, ibmap + real(4):: coordlist + integer(4) :: ideflist, idefnum logical*1 :: bmp( dims(1) * dims(2) ) - integer :: n, lon0, lon1, lat0, lat1, nlay, lyr - integer, dimension(40) :: dep1 - integer, dimension(28) :: dep2 - integer, dimension(:), allocatable :: dep + integer(4) :: n, lon0, lon1, lat0, lat1, nlay, lyr + integer(4), dimension(40) :: dep1 + integer(4), dimension(28) :: dep2 + integer(4), dimension(:), allocatable :: dep npt = dims(1) * dims(2) @@ -1026,13 +1026,15 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, vfill) numcoord=0 coordlist=0. ! needed for hybrid vertical coordinate - ibmap=255 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap + ibmap=0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. if (trim(gcf(n)%name_gb2) .eq. 'WTMP') then where ( field(:,lyr,n) .ne. vfill ) field(:,lyr,n) = field(:,lyr,n) + 273.15 endif + where ( field(:,lyr,n) .eq. vfill ) bmp(:)= .false. + ! Assign Template 5 idrtnum = 0 ! Template 5.2 (Grid Point Data - complex Packing) @@ -1055,6 +1057,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, vfill) call addfield(cgrib, max_bytes, ipdtnum, jpdt, ipdtlen, coordlist, numcoord, & idrtnum, idrtmpl, idrtlen, tmpfld, npt, ibmap, bmp, ierr) + if (ierr /=- 0) then write(0, *) 'Error adding field to GRIB2 message', ierr return From 6d61a3f636514e349a894cec8e456558f3236f32 Mon Sep 17 00:00:00 2001 From: AminIlia-NOAA Date: Tue, 25 Feb 2025 13:17:33 -0500 Subject: [PATCH 124/124] added tob and removed ICETMP --- parm/ocnicepost/ice.csv | 1 - parm/ocnicepost/ocean.csv | 1 + src/ocnicepost.fd/utils_mod.F90 | 19 +++++++++---------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/parm/ocnicepost/ice.csv b/parm/ocnicepost/ice.csv index c06c65fe..5f946538 100644 --- a/parm/ocnicepost/ice.csv +++ b/parm/ocnicepost/ice.csv @@ -2,7 +2,6 @@ 'hi_h',2, 'Ct', 'bilinear', '', '', 'ICETK', 'Ice Thickness', 'm',10,2,7,0,2,1,1,0 'hs_h',2, 'Ct', 'bilinear', '', '', 'SNVOLSI', 'Snow Volume Over Sea Ice per Unit Area', 'm3m-2',10,2,7,0,2,16,1,0 'aice_h',2, 'Ct', 'bilinear', '', '', 'ICEC', 'Ice Cover', 'Proportion',10,2,7,0,2,0,1,0 - 'Tsfc_h',2, 'Ct', 'bilinear', '', '', 'ICETMP', 'Ice Temperature', 'K',10,2,7,0,2,8,1,0 'uvel_h',2, 'Bu_x', 'bilinear', 'vvel_h', 'Bu_y', 'UICE', 'U-Component of Ice Drift', 'm/s',10,2,7,0,2,4,1,0 'vvel_h',2, 'Bu_y', 'bilinear', 'uvel_h', 'Bu_x', 'VICE', 'V-Component of Ice Drift', 'm/s',10,2,7,0,2,5,1,0 'frzmlt_h',2, 'Ct', 'conserve', '', '', 'FRZMLTPOT', 'freeze/melt potential', 'W m-2',10,2,7,0,2,27,1,0 diff --git a/parm/ocnicepost/ocean.csv b/parm/ocnicepost/ocean.csv index e54ff2b5..257e49d0 100644 --- a/parm/ocnicepost/ocean.csv +++ b/parm/ocnicepost/ocean.csv @@ -14,6 +14,7 @@ 'SSV',2,'Cv' , 'bilinear' , 'SSU' , 'Cu','VOGRD','V-Component of Current','m/s',10,1,7,0,1,3,101,0 'taux',2,'Cu' , 'conserve' , 'tauy' , 'Cv','XCOMPSS','x-component Surface Stress','N/m^2',10,1,7,0,3,7,101,0 'tauy',2,'Cv' , 'conserve' , 'taux' , 'Cu','YCOMPSS','y-component Surface Stress','N/m^2',10,1,7,0,3,7,101,0 + 'tob', 2,'Ct' , 'bilinear' , '', '','WTMP','Ocean Bottom Water Temperature','K',10,1,7,0,3,0,9,0 'temp',3,'Ct' , 'bilinear' , '', '','WTMP','Water Temperature','K',10,1,7,0,3,0,160,0 'so',3,'Ct' , 'bilinear' , '', '','SALIN','3-D Salinity','psu',10,0,7,1,4,193,160,0 'uo',3,'Cu' , 'bilinear' , 'vo' , 'Cv','UOGRD','U-Component of Current','m/s',10,1,7,0,1,2,160,0 diff --git a/src/ocnicepost.fd/utils_mod.F90 b/src/ocnicepost.fd/utils_mod.F90 index e88a1e4d..f5fa62bf 100644 --- a/src/ocnicepost.fd/utils_mod.F90 +++ b/src/ocnicepost.fd/utils_mod.F90 @@ -643,7 +643,6 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, vfill) listsec1(1) = gcf(1)%var_g3 ! Originating Centre (Common Code Table C-1) listsec1(2) = 0 ! Originating Sub-centre (local table) EMC=4 -! listsec1(3) = 32 ! GRIB Master Tables Version Number (Code Table 1.0)-last one currently 32 listsec1(3) = gcf(1)%var_g2 ! GRIB Master Tables Version Number (Code Table 1.0) listsec1(4) = 1 ! GRIB Local Tables Version Number (Code Table 1.1) listsec1(5) = 1 ! Significance of Reference Time (Code Table 1.2) @@ -739,7 +738,7 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, vfill) return end if -! Create Section 4 parametrs + ! Create Section 4 parametrs ipdtnum=0 jpdt(1)=gcf(n)%var_g5 ! parm number catagory @@ -775,8 +774,8 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, vfill) where ( field(:,n) .eq. vfill ) bmp(:)= .false. - ! Create Section 5 parametrs - idrtnum = 0 ! Template 5.2 (Grid Point Data - complex Packing) + ! Create Section 5 parametrs + idrtnum = 0 ! Template 5.0 (Grid Point Data - simple Packing) idrtmpl(:)=0 ! Populate idrtmpl @@ -785,9 +784,9 @@ subroutine write_grib2_2d(fname, gcf, dims, nflds, field, vfill) idrtmpl(3) = 3 ! Decimal scale factor (scale by 10^D) idrtmpl(4) = 0 ! idrtmpl(5) = 0 ! - idrtmpl(6) = 0 ! + idrtmpl(6) = 0 ! ! Reserved fields - idrtmpl(7:16) = 0 ! Reserved for future use + idrtmpl(7:16) = 0 ! Reserved for future use idrtlen=size(idrtmpl) @@ -932,7 +931,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, vfill) lat0 = -90000000 lat1 = 90000000 - ! Populate the jgdt array for Template 3.0 (changed parameters to current grib2 files) + ! Populate the jgdt array for Template 3.0 (changed parameters to current grib2 files) jgdt(1) = 6 jgdt(2) = 0 jgdt(3) = 0 @@ -999,7 +998,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, vfill) return end if -! Create Section 4 parametrs + ! Create Section 4 parametrs ipdtnum=0 @@ -1029,7 +1028,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, vfill) ibmap=0 ! Bitmap indicator ( see Code Table 6.0 ) -255 no bitmap bmp=.true. - if (trim(gcf(n)%name_gb2) .eq. 'WTMP') then + if (trim(gcf(n)%name_gb2) .eq. 'WTMP' ) then where ( field(:,lyr,n) .ne. vfill ) field(:,lyr,n) = field(:,lyr,n) + 273.15 endif @@ -1037,7 +1036,7 @@ subroutine write_grib2_3d(fname, gcf, dims, nflds, field, vfill) ! Assign Template 5 - idrtnum = 0 ! Template 5.2 (Grid Point Data - complex Packing) + idrtnum = 0 ! Template 5.0 (Grid Point Data - simple Packing) idrtmpl(:)=0 ! Populate idrtmpl