diff --git a/CMakeLists.txt b/CMakeLists.txt index facecba..b462925 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ list(APPEND SUBLIST "MOSAIC") list(APPEND SUBLIST "PM") list(APPEND SUBLIST "RADMON") list(APPEND SUBLIST "REF2TTEN") +list(APPEND SUBLIST "RRFS_BUCKET") list(APPEND SUBLIST "RTMA_MINMAXTRH") list(APPEND SUBLIST "UPDATE_BC") list(APPEND SUBLIST "UPDATE_GVF") diff --git a/bufrsnd.fd/rrfs_bufr.fd/makefile b/bufrsnd.fd/rrfs_bufr.fd/makefile deleted file mode 100755 index 8886157..0000000 --- a/bufrsnd.fd/rrfs_bufr.fd/makefile +++ /dev/null @@ -1,105 +0,0 @@ -################################################################################ -# -# Makefile for WRFBUFR code -# -# Use: -# make - build the executable -# make clean - start with a clean slate -# -# The following macros will be of interest: -# -# CMD - name of the executable -# FC - name of Fortran compiler -# CPP - name of CPP -# ARCH - architecture -# CPPFLAGS - CPP flags -# OPTS - compiler code optimizations -# TRAPS - runtime traps for floating point exceptions -# DEBUG - -g -# -################################################################################# -# -# Define the name of the executable -# -CMD = rrfs_bufr.x -# -# CPP, Compiler, and Linker Options -# - -FC = ${COMP_MP} - -CPP = /lib/cpp -P -ARCH = -CPPFLAGS = -OPTS = -O -fp-model precise -convert big_endian -assume noold_ldout_format -FREE = -FR -TRAPS = -DEBUG = -g -traceback -fpe0 -ftrapuv -check all - - -# -# Assemble Options -# -FFLAGS = $(OPTS) $(TRAPS) -I$(NETCDF_INCLUDES) -FFLAGST = $(OPTS) $(FREE) $(TRAPS) -I$(NETCDF_INCLUDES) - -FFLAGS_DEBUG = $(OPTS) $(TRAPS) $(DEBUG) -I$(NETCDF_INCLUDES) -FFLAGST_DEBUG = $(OPTS) $(FREE) $(TRAPS) $(DEBUG) -I$(NETCDF_INCLUDES) - -LDFLAGS = -LIBS = \ - $(W3EMC_LIB4) $(W3NCO_LIB4) $(BACIO_LIB4) \ - -L$(NETCDF_LIBRARIES) -lnetcdf -lnetcdff -# -# -# free-format object files -# -OBJST= PARA_RANGE.o - -OBJST_DEBUG= PARA_RANGE.o -# -# -# fixed-format object files -# -# -OBJS= VRBLS2D_mod.o VRBLS3D_mod.o MASKS_mod.o SOIL_mod.o \ -WRFBUFR.o \ -PROF_FV3SAR_NET.o iw3jdn.o w3fs26.o w3movdat.o w3reddat.o - -OBJS_DEBUG= VRBLS2D_mod.o VRBLS3D_mod.o MASKS_mod.o SOIL_mod.o \ -WRFBUFR.o \ -PROF_FV3SAR_NET.o iw3jdn.o w3fs26.o w3movdat.o w3reddat.o - -# -# Includes -# -INCLUDES= parmsoil -# - -DEPS= $(INCLUDES) - -.SUFFIXES: .F .f .o - -.F.f: - $(CPP) $(CPPFLAGS) $< > $*.f - -$(CMD): $(OBJST) $(OBJS) - $(FC) $(LDFLAGS) -o $@ $(OBJST) $(OBJS) $(LIBS) - -debug: $(OBJST_DEBUG) $(OBJS_DEBUG) - $(FC) $(LDFLAGS) -o rrfs_bufr.x $(OBJST_DEBUG) $(OBJS_DEBUG) $(LIBS) - -$(OBJS):: $(DEPS) - $(FC) -c $(FFLAGS) $(@:.o=.f) - -$(OBJS_DEBUG):: $(DEPS) - $(FC) -c $(FFLAGS_DEBUG) $(@:.o=.f) - -$(OBJST):: $(DEPS) - $(FC) -c $(FFLAGST) $(@:.o=.f90) - -$(OBJST_DEBUG):: $(DEPS) - $(FC) -c $(FFLAGST_DEBUG) $(@:.o=.f90) - -clean: - /bin/rm -f *.lst *.o *.mod diff --git a/bufrsnd.fd/rrfs_bufr.fd/makefile_debug_try_fails b/bufrsnd.fd/rrfs_bufr.fd/makefile_debug_try_fails deleted file mode 100755 index a076504..0000000 --- a/bufrsnd.fd/rrfs_bufr.fd/makefile_debug_try_fails +++ /dev/null @@ -1,120 +0,0 @@ -################################################################################ -# -# Makefile for WRFBUFR code -# -# Use: -# make - build the executable -# make clean - start with a clean slate -# -# The following macros will be of interest: -# -# CMD - name of the executable -# FC - name of Fortran compiler -# CPP - name of CPP -# ARCH - architecture -# CPPFLAGS - CPP flags -# OPTS - compiler code optimizations -# TRAPS - runtime traps for floating point exceptions -# DEBUG - -g -# -################################################################################# -# -# Define the name of the executable -# -CMD = hireswfv3_bufr.x -# -# CPP, Compiler, and Linker Options -# - -FC = ${COMP_MP} - -CPP = /lib/cpp -P -ARCH = -CPPFLAGS = -OPTS = -O -fp-model precise -convert big_endian -assume noold_ldout_format -FREE = -FR -TRAPS = -DEBUG = -g -traceback -fpe0 -ftrapuv -check all - -WRFLIB = ./wrflibs/libwrflib.a \ - ./wrflibs/pack_utils.o \ - ./wrflibs/libfftpack.a \ - ./wrflibs/libio_grib1.a \ - ./wrflibs/libio_grib_share.a \ - ./wrflibs/libwrfio_int.a \ - ./wrflibs/libwrfio_nf.a \ - ./wrflibs/libesmf_time.a \ - ./wrflibs/librsl_lite.a - -# -# Assemble Options -# -FFLAGS = $(OPTS) $(TRAPS) $(WRFFLAGS) -I$(NEMSIO_INC) -I$(NETCDF_INC) -FFLAGST = $(OPTS) $(FREE) $(TRAPS) $(WRFFLAGS) -I$(NEMSIO_INC) -I$(NETCDF_INC) - -FFLAGS_DEBUG = $(OPTS) $(TRAPS) $(DEBUG) $(WRFFLAGS) -I$(NEMSIO_INC) -I$(NETCDF_INC) -FFLAGST_DEBUG = $(OPTS) $(FREE) $(TRAPS) $(DEBUG) $(WRFFLAGS) -I$(NEMSIO_INC) -I$(NETCDF_INC) - -LDFLAGS = -LIBS = $(WRFLIB) \ - $(NEMSIO_LIB) \ - $(W3EMC_LIB4) $(W3NCO_LIB4) $(BACIO_LIB4) \ - -L$(NETCDF_LIB) -lnetcdf -lnetcdff -# -# -# free-format object files -# -OBJST= module_internal_header_util.o getIVariableB.o getIVariable.o getVariableB.o getVariable.o \ - kinds_mod.o count_recs_wrf_binary_file.o inventory_wrf_binary_file.o \ - next_buf.o retrieve_index.o GETNEMSANDPLACE.o PARA_RANGE.o - -OBJST_DEBUG= module_internal_header_util.o getIVariableB.o getIVariable.o getVariableB.o getVariable.o \ - kinds_mod.o count_recs_wrf_binary_file.o inventory_wrf_binary_file.o \ - next_buf.o retrieve_index.o GETNEMSANDPLACE.o PARA_RANGE.o -# -# fixed-format object files -# -# -OBJS= VRBLS2D_mod.o VRBLS3D_mod.o MASKS_mod.o SOIL_mod.o \ -WRFBUFR.o PROF_EM.o PROF_NMM.o PROF_NMM_NET.o PROF_EM_NET.o PROF_NMMB_SERIAL.o \ -PROF_FV3SAR_NET.o iw3jdn.o w3fs26.o w3movdat.o w3reddat.o gdswiz.o gdswiz01.o \ -gdswiz03.o gdswiz05.o - -OBJS_DEBUG= VRBLS2D_mod.o VRBLS3D_mod.o MASKS_mod.o SOIL_mod.o \ -WRFBUFR.o PROF_EM.o PROF_NMM.o PROF_NMM_NET.o PROF_EM_NET.o PROF_NMMB_SERIAL.o \ -PROF_FV3SAR_NET.o iw3jdn.o w3fs26.o w3movdat.o w3reddat.o gdswiz.o gdswiz01.o \ -gdswiz03.o gdswiz05.o - -# -# Includes -# -INCLUDES= parmsoil -# - -DEPS= $(INCLUDES) - -.SUFFIXES: .F .f .o - -.F.f: - $(CPP) $(CPPFLAGS) $< > $*.f - -$(CMD): $(OBJST) $(OBJS) - $(FC) $(LDFLAGS) -o $@ $(OBJST) $(OBJS) $(LIBS) - -debug: $(OBJST_DEBUG) $(OBJS_DEBUG) - $(FC) $(LDFLAGS) -o hireswfv3_bufr.x $(OBJST_DEBUG) $(OBJS_DEBUG) $(LIBS) - -# $(OBJS): $(DEPS) -# $(FC) -c $(FFLAGS) $(@:.o=.f) - -$(OBJS_DEBUG): $(DEPS) - $(FC) -c $(FFLAGS_DEBUG) $(@:.o=.f) - -# $(OBJST): $(DEPS) -# $(FC) -c $(FFLAGST) $(@:.o=.f90) - -$(OBJST_DEBUG): $(DEPS) - $(FC) -c $(FFLAGST_DEBUG) $(@:.o=.f90) - -clean: - /bin/rm -f *.lst *.o *.mod diff --git a/bufrsnd.fd/rrfs_sndp.fd/makefile b/bufrsnd.fd/rrfs_sndp.fd/makefile deleted file mode 100755 index ea86f93..0000000 --- a/bufrsnd.fd/rrfs_sndp.fd/makefile +++ /dev/null @@ -1,51 +0,0 @@ -SHELL=/bin/sh -# -SRCS= BFRHDR.f BFRIZE.f CALHEL.f CALWXT.f SMIX.f SNDPST.f \ - SNDPST_FV3S.f VAP.f \ - WETBLB.f CALVIS.f CALWXT_RAMER.f CALWXT_EXPLICIT.f \ - CALWXT_REVISED.f CALWXT_BOURG.f CALWXT_DOMINANT.f - -OBJS= BFRHDR.o BFRIZE.o CALHEL.o CALWXT.o SMIX.o SNDPST.o \ - SNDPST_FV3S.o VAP.o \ - WETBLB.o CALVIS.o CALWXT_RAMER.o CALWXT_EXPLICIT.o \ - CALWXT_REVISED.o CALWXT_BOURG.o CALWXT_DOMINANT.o - -OBJS_DEBUG= BFRHDR.o BFRIZE.o CALHEL.o CALWXT.o SMIX.o SNDPST.o \ - SNDPST_FV3S.o VAP.o \ - WETBLB.o CALVIS.o CALWXT_RAMER.o CALWXT_EXPLICIT.o \ - CALWXT_REVISED.o CALWXT_BOURG.o CALWXT_DOMINANT.o - -# Tunable parameters -# -# FC Name of the fortran compiling system to use -# LDFLAGS Flags to the loader -# LIBS List of libraries -# CMD Name of the executable -# PROFLIB Library needed for profiling -# -#FC = ${COMP} -convert big_endian - -FC = ${COMPILER} -convert big_endian -DEBUG = -g -traceback -ftrapuv -check all -fp-stack-check -LDFLAGS = -CMD = rrfs_sndp.x -LIBS = ${BUFR_LIB4} - -# Lines from here on down should not need to be changed. They are the -# actual rules which make uses to build a.out. -# -all: $(CMD) - -$(CMD):: $(OBJS) - $(FC) $(LDFLAGS) -o $(@) $(OBJS) $(LIBS) - -debug:: $(OBJS_DEBUG) - $(FC) $(DEBUG) $(LDFLAGS) -o hireswfv3_sndp.x $(OBJS_DEBUG) $(LIBS) - -OBJS_DEBUG:: - $(FC) ${INC} -c $(DEBUG) $(@:.o=.f) -OBJS:: - $(FC) ${INC} -c $(@:.o=.f) - -clean: - @rm *.o diff --git a/bufrsnd.fd/rrfs_stnmlist.fd/makefile b/bufrsnd.fd/rrfs_stnmlist.fd/makefile deleted file mode 100755 index 0969ace..0000000 --- a/bufrsnd.fd/rrfs_stnmlist.fd/makefile +++ /dev/null @@ -1,61 +0,0 @@ -SHELL=/bin/sh -# -# This makefile was produced by /usr/bin/fmgen at 11:24:59 AM on 09/25/96 -# If it is invoked by the command line -# make -f makefile -# it will compile the fortran modules indicated by SRCS into the object -# modules indicated by OBJS and produce an executable named a.out. -# -# If it is invoked by the command line -# make -f makefile a.out.prof -# it will compile the fortran modules indicated by SRCS into the object -# modules indicated by OBJS and produce an executable which profiles -# named a.out.prof. -# -# To remove all the objects but leave the executables use the command line -# make -f makefile clean -# -# The parameters SRCS and OBJS should not need to be changed. If, however, -# you need to add a new module add the name of the source module to the -# SRCS parameter and add the name of the resulting object file to the OBJS -# parameter. The new modules are not limited to fortran, but may be C, YACC, -# LEX, or CAL. An explicit rule will need to be added for PASCAL modules. -# -SRCS= stnmlist.f - -OBJS= stnmlist.o -OBJS_DEBUG= stnmlist.o - -# Tunable parameters -# -# FC Name of the fortran compiling system to use -# LDFLAGS Flags to the loader -# LIBS List of libraries -# CMD Name of the executable -# PROFLIB Library needed for profiling -# -#FC = ${COMP} -FC = ${COMPILER} -FC_DEBUG = ${COMPILER} -g -traceback -ftrapuv -check all -fp-stack-check -LDFLAGS = -LIBS = ${W3NCO_LIB4} ${W3EMC_LIB4} ${BUFR_LIB4} - -CMD = rrfs_stnmlist.x -PROFLIB = - - -# Lines from here on down should not need to be changed. They are the -# actual rules which make uses to build a.out. -# -all: $(CMD) - -$(CMD):: $(OBJS) - $(FC) $(LDFLAGS) -o $(@) $(OBJS) $(LIBS) -debug:: $(OBJS_DEBUG) - $(FC_DEBUG) $(LDFLAGS) -o hireswfv3_stnmlist.x $(OBJS) $(LIBS) -$(OBJS_DEBUG): - $(FC_DEBUG) -c $(@:.o=.f) - - -clean: - -rm -f $(OBJS) diff --git a/bufrsnd.fd/rrfs_stnmlist.fd/makefile.orig b/bufrsnd.fd/rrfs_stnmlist.fd/makefile.orig deleted file mode 100755 index ab9b329..0000000 --- a/bufrsnd.fd/rrfs_stnmlist.fd/makefile.orig +++ /dev/null @@ -1,58 +0,0 @@ -SHELL=/bin/sh -# -# This makefile was produced by /usr/bin/fmgen at 11:24:59 AM on 09/25/96 -# If it is invoked by the command line -# make -f makefile -# it will compile the fortran modules indicated by SRCS into the object -# modules indicated by OBJS and produce an executable named a.out. -# -# If it is invoked by the command line -# make -f makefile a.out.prof -# it will compile the fortran modules indicated by SRCS into the object -# modules indicated by OBJS and produce an executable which profiles -# named a.out.prof. -# -# To remove all the objects but leave the executables use the command line -# make -f makefile clean -# -# The parameters SRCS and OBJS should not need to be changed. If, however, -# you need to add a new module add the name of the source module to the -# SRCS parameter and add the name of the resulting object file to the OBJS -# parameter. The new modules are not limited to fortran, but may be C, YACC, -# LEX, or CAL. An explicit rule will need to be added for PASCAL modules. -# -SRCS= stnmlist.f - -OBJS= stnmlist.o - -# Tunable parameters -# -# FC Name of the fortran compiling system to use -# LDFLAGS Flags to the loader -# LIBS List of libraries -# CMD Name of the executable -# PROFLIB Library needed for profiling -# -FC = ${COMP} -LDFLAGS = -LIBS = ${W3NCO_LIB4} ${W3EMC_LIB4} ${BUFR_LIB4} - -CMD = ../../exec/hiresw_stnmlist -PROFLIB = - -# To perform the default compilation, use the first line -# To compile with flowtracing turned on, use the second line -# To compile giving profile additonal information, use the third line -# WARNING: SIMULTANEOUSLY PROFILING AND FLOWTRACING IS NOT RECOMMENDED -FFLAGS = -O - -# Lines from here on down should not need to be changed. They are the -# actual rules which make uses to build a.out. -# -all: $(CMD) - -$(CMD): $(OBJS) - $(FC) $(LDFLAGS) -o $(@) $(OBJS) $(LIBS) - -clean: - -rm -f $(OBJS) diff --git a/rrfs_bucket.fd/CMakeLists.txt b/rrfs_bucket.fd/CMakeLists.txt new file mode 100644 index 0000000..00e2601 --- /dev/null +++ b/rrfs_bucket.fd/CMakeLists.txt @@ -0,0 +1,19 @@ +list(APPEND src_bucket + bucket_diff.f) + +add_executable(rrfs_bucket.exe ${src_bucket}) +target_link_libraries(rrfs_bucket.exe PRIVATE ${PROJECT_NAME}::ncio + PRIVATE w3emc::w3emc_4 + PRIVATE w3nco::w3nco_4 + PRIVATE g2tmpl::g2tmpl + PRIVATE g2::g2_4 + PRIVATE bacio::bacio_4 + PRIVATE MPI::MPI_Fortran + PRIVATE MPI::MPI_C) + +install( + TARGETS rrfs_bucket.exe + EXPORT ${PROJECT_NAME}Exports + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/rrfs_bucket.fd/bucket_diff.f b/rrfs_bucket.fd/bucket_diff.f new file mode 100755 index 0000000..e8805b9 --- /dev/null +++ b/rrfs_bucket.fd/bucket_diff.f @@ -0,0 +1,338 @@ + program wrfbucket + +! Program will read in the total accumulated precipitation from +! a series of WRFPRS files, and compute simple differences to +! get precip buckets with a duration equal to the interval between +! output times. + + USE GRIB_MOD + + real, allocatable :: pdiff(:,:) + + integer :: ihrs1, ihrs2, reset_flag + integer :: imin1, imin2 + character(len=2), dimension(2):: hrs,min + + character(len=255):: file1,file2,testout + character(len=150):: dirname + character(len=150):: filename + character(len=10):: cycname,dom + character(len=1):: reflag + + read(5,FMT='(A)') dirname + read(5,FMT='(A)') filename + read(5,FMT='(A)') hrs(1) + read(5,FMT='(A)') min(1) + read(5,FMT='(A)') hrs(2) + read(5,FMT='(A)') min(2) + read(5,FMT='(I1)') reset_flag + read(5,*) IM, JM + read(5,FMT='(A)') dom + + allocate(pdiff(im,jm)) + + n=index(dirname,' ')-1 + m=index(filename,' ')-1 + k=index(dom,' ')-1 + + I=2 + + if (min(1) .eq. '00') then + file1= dirname(1:n)//'/'//filename(1:m)// + + HRS(I-1)//'.'//dom(1:k)//'.grib2' + else + file1= dirname(1:n)//'/'//filename(1:m)// + + HRS(I-1)//'-'//MIN(I-1)//'-00.'//dom(1:k)//'.grib2' + endif + + if (min(2) .eq. '00') then + file2= dirname(1:n)//'/'//filename(1:m)//HRS(I)//'.'// + + dom(1:k)//'.grib2' + else + file2= dirname(1:n)//'/'//filename(1:m)// + + HRS(I)//'-'//MIN(I)//'-00.'//dom(1:k)//'.grib2' + endif + + read(HRS(I-1), '(I2)' ) ihrs1 + read(HRS(I) , '(I2)' ) ihrs2 + read(MIN(I-1), '(I2)' ) imin1 + read(MIN(I) , '(I2)' ) imin2 + + imin1=(ihrs1-1)*60+imin1 + imin2=(ihrs2-1)*60+imin2 + + interv=15 + + if (interv .eq. 15) then + testout= dirname(1:n)//'/PCP15MIN_'//dom(1:k)//'_'// + + HRS(I)//MIN(I)//'.grib2' + endif + + mm=index(file1,' ')-1 + nn=index(file2,' ')-1 + mmm=index(testout,' ')-1 + + write(0,*) 'file1: ', file1(1:mm) + write(0,*) 'file2: ', file2(1:nn) + write(0,*) 'testout: ', testout(1:mmm) + + write(0,*) 'call calc_pdiff with reset_flag: ', reset_flag + write(0,*) 'ihrs1, imin1: ', ihrs1, imin1 + + call calc_pdiff(file1(1:mm),file2(1:nn),TESTOUT(1:mmm), + & pdiff,reset_flag,ihrs1,imin1,interv,IM,JM) + + END + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + SUBROUTINE CALC_PDIFF(FNAME1,FNAME2,TESTOUT,DPRECIP, + & reset_flag,ihrs1,imin1,interv,IM,JM) + USE GRIB_MOD + USE pdstemplates + character(*):: FNAME1,FNAME2,testout + integer:: JPDS(200),JGDS(200), reset_flag,lencheck + integer :: ihrs1,imin1,interv + integer:: KPDS1(200),KGDS(200),KPDS2(200),KPDS(200),KGDS2(200) + logical:: BITMAP(IM*JM),FIRST + +C grib2 + INTEGER :: LUGB,LUGI,J,JDISC,JPDTN,JGDTN + INTEGER,DIMENSION(:) :: JIDS(200),JPDT(200),JGDT(200) + INTEGER,DIMENSION(:) :: PDS_RAIN_HOLD(200) + INTEGER,DIMENSION(:) :: PDS_RAIN_HOLD_EARLY(200) + LOGICAL :: UNPACK + INTEGER :: K,IRET + TYPE(GRIBFIELD) :: GFLD +C grib2 + real:: p_later(IM*JM),p_earlier(IM*JM),dprecip(im*jm) + real:: sno_later(IM*JM),sno_earlier(IM*JM),snoprecip(im*jm) + real:: frzr_later(IM*JM),frzr_earlier(IM*JM),frzrprecip(im*jm) + + call baopenr(11,fname1,ierr1) + call baopenr(12,fname2,ierr2) + call baopenw(13,testout,ierr3) + +! write(0,*) 'baopened ', fname1,fname2,testout + + if ( (ierr1+ierr2+ierr3) .ne. 0) then + write(0,*) 'bad baopen!!! ', ierr1 + write(0,*) 'bad baopen!!! ', ierr2 + write(0,*) 'bad baopen!!! ', ierr3 + STOP 9 + endif + + p_earlier=0. + + JIDS=-9999 + JPDTN=-1 + JPDT=-9999 + JGDTN=-1 + JGDT=-9999 + UNPACK=.true. + + allocate(gfld%fld(im*jm)) + allocate(gfld%idsect(200)) + allocate(gfld%igdtmpl(200)) + allocate(gfld%ipdtmpl(200)) + allocate(gfld%idrtmpl(200)) + allocate(gfld%bmap(im*jm)) + +C USAGE: CALL GETGB2(LUGB,LUGI,J,JDISC,JIDS,JPDTN,JPDT,JGDTN,JGDT, +C & UNPACK,K,GFLD,IRET) + + J=0 + JIDS=-9999 + JPDTN=8 + JPDT=-9999 + JPDT(2)=8 + JGDTN=-1 + JGDT=-9999 + UNPACK=.true. + + call getgb2(11,0,J,0,JIDS,JPDTN,JPDT,JGDTN,JGDT, + & UNPACK,K,GFLD,IRET) + + if (IRET .eq. 0) then + p_earlier=gfld%fld + do K=1,gfld%ipdtlen + PDS_RAIN_HOLD_EARLY(K)=gfld%ipdtmpl(K) + enddo + write(0,*) 'maxval(p_earlier): ', maxval(p_earlier) + + JIDS=-9999 + JPDTN=8 + JPDT=-9999 + JPDT(2)=29 + JGDTN=-1 + JGDT=-9999 + UNPACK=.true. + + call getgb2(11,0,J,0,JIDS,JPDTN,JPDT,JGDTN,JGDT, + & UNPACK,K,GFLD,IRET) + + if (IRET .eq. 0) then + sno_earlier=gfld%fld + endif + + JIDS=-9999 + JPDTN=8 + JPDT=-9999 + JPDT(2)=225 + JGDTN=-1 + JGDT=-9999 + UNPACK=.true. + + call getgb2(11,0,J,0,JIDS,JPDTN,JPDT,JGDTN,JGDT, + & UNPACK,K,GFLD,IRET) + + if (IRET .eq. 0) then + frzr_earlier=gfld%fld + endif + + else + + write(0,*) 'did not find record in earlier file ', reset_flag + + endif + +! --------------------------------- + + J=0 + + JIDS=-9999 + JPDTN=8 + JPDT=-9999 + JPDT(2)=8 + JGDTN=-1 + JGDT=-9999 + UNPACK=.true. + + call getgb2(12,0,0,0,JIDS,JPDTN,JPDT,JGDTN,JGDT, + & UNPACK,K,GFLD,IRET1) + + write(0,*) 'K: ', K + + if (IRET1 .eq. 0) then + p_later=gfld%fld + write(0,*) 'maxval(p_later): ', maxval(p_later) + do K=1,gfld%ipdtlen + PDS_RAIN_HOLD(K)=gfld%ipdtmpl(K) + enddo + else + write(0,*) 'bad getgb later ', IRET1 + STOP 999 + endif + +! -------SNOW -------------------------- + + J=0 + + JIDS=-9999 + JPDTN=8 + JPDT=-9999 + JPDT(2)=29 + JGDTN=-1 + JGDT=-9999 + UNPACK=.true. + + call getgb2(12,0,0,0,JIDS,JPDTN,JPDT,JGDTN,JGDT, + & UNPACK,K,GFLD,IRET1) + + write(0,*) 'K: ', K + + if (IRET1 .eq. 0) then + sno_later=gfld%fld + write(0,*) 'maxval(sno_later): ', maxval(sno_later) + else + write(0,*) 'bad getgb later asnow ', IRET1 + STOP 999 + endif + +! -------FRZR -------------------------- + + J=0 + + JIDS=-9999 + JPDTN=8 + JPDT=-9999 + JPDT(2)=225 + JGDTN=-1 + JGDT=-9999 + UNPACK=.true. + + call getgb2(12,0,0,0,JIDS,JPDTN,JPDT,JGDTN,JGDT, + & UNPACK,K,GFLD,IRET1) + + if (IRET1 .eq. 0) then + frzr_later=gfld%fld + write(0,*) 'maxval(frzr_later): ', maxval(frzr_later) + else + write(0,*) 'bad getgb later frzr ', IRET1 + STOP 999 + endif + + if (reset_flag .eq. 1) then + write(0,*) 'just later value' + do NPT=1,IM*JM + dprecip(NPT)=p_later(NPT) + snoprecip(NPT)=sno_later(NPT) + frzrprecip(NPT)=frzr_later(NPT) + enddo + else + do NPT=1,IM*JM + dprecip(NPT)=p_later(NPT)-p_earlier(NPT) + snoprecip(NPT)=sno_later(NPT)-sno_earlier(NPT) + frzrprecip(NPT)=frzr_later(NPT)-frzr_earlier(NPT) + enddo + endif + +!! force decimal scaling +! KPDS2(22)=4 +!! force decimal scaling + + write(0,*) 'define gfld%fld with dprecip' + + gfld%ipdtmpl(1:gfld%ipdtlen)=PDS_RAIN_HOLD_EARLY(1:gfld%ipdtlen) + + write(0,*) 'gfld%ipdtmpl(8): ', gfld%ipdtmpl(8) + gfld%ipdtmpl(9)=imin1 + + do J=16,21 + gfld%ipdtmpl(J)=PDS_RAIN_HOLD(J) + enddo + + gfld%ipdtmpl(22)=1 + gfld%ipdtmpl(27)=interv + + write(0,*) 'interval specified in 27: ', interv + +! gfld%ipdtmpl(28)=1 + + gfld%ipdtmpl(2)=8 + gfld%fld=dprecip + +! do J=1,29 +! write(0,*) 'at write J,gfld%ipdtmpl(J): ', J,gfld%ipdtmpl(J) +! enddo + + call putgb2(13,GFLD,IRET) + write(0,*) 'IRET from putgb2 for dprecip', IRET + + gfld%ipdtmpl(2)=29 + gfld%fld=snoprecip + call putgb2(13,GFLD,IRET) + write(0,*) 'IRET from putgb2 for snoprecip', IRET + + gfld%ipdtmpl(2)=225 + gfld%fld=frzrprecip + call putgb2(13,GFLD,IRET) + write(0,*) 'IRET from putgb2 for frzrprecip', IRET + +! ------------------------------------------- + + call baclose(13,IRET) + + write(0,*) 'extremes of precip: ', maxval(dprecip) + + end subroutine calc_pdiff