From f27b5c7b1183ea16fa691efa0842404bba5bc4f4 Mon Sep 17 00:00:00 2001 From: LarissaReames-NOAA Date: Fri, 20 Nov 2020 16:49:53 +0000 Subject: [PATCH] Updated logic for reading soil type from the geogrid file If the user provides a geogrid file and any of the calls in this process fail, the code will now fail on an error. Also, added a check to ensure input and geogrid grid sizes match. Addresses Issue #228 --- sorc/chgres_cube.fd/input_data.F90 | 58 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/sorc/chgres_cube.fd/input_data.F90 b/sorc/chgres_cube.fd/input_data.F90 index 13a0774ad..fe49b3b6d 100644 --- a/sorc/chgres_cube.fd/input_data.F90 +++ b/sorc/chgres_cube.fd/input_data.F90 @@ -4603,7 +4603,7 @@ subroutine read_input_sfc_grib2_file(localpet) character(len=50) :: method integer :: rc, varnum, iret, i, j,k - integer :: ncid2d, varid + integer :: ncid2d, varid, varsize integer, parameter :: icet_default = 265.0 logical :: exist, rap_latlon @@ -4875,40 +4875,42 @@ subroutine read_input_sfc_grib2_file(localpet) vname=":SOTYP:" rc = grb2_inq(the_file, inv_file, vname,slev, data2=dummy2d) !failed => rc = 0 - if (rc <= 0 .and. (trim(to_upper(external_model))=="HRRR" .or. rap_latlon)) then + if (rc <= 0 .and. (trim(to_upper(external_model))=="HRRR" .or. rap_latlon) .and. geo_file .ne. "NULL") then ! Some HRRR and RAP files don't have dominant soil type in the output, but the geogrid files ! do, so this gives users the option to provide the geogrid file and use input soil ! type print*, "OPEN GEOGRID FILE ", trim(geo_file) rc = nf90_open(geo_file,NF90_NOWRITE,ncid2d) ! failed => rc < 0 - if (rc == 0) then - print*, "INQUIRE ABOUT SOIL TYPE FROM GEOGRID FILE" - rc = nf90_inq_varid(ncid2d,"SCT_DOM",varid) - ! failed => rc < 0 - if (rc<0) print*, "ERROR FINDING SCT_DOM IN GEOGRID FILE" - if (rc == 0) then - print*, "READ SOIL TYPE FROM GEOGRID FILE " - rc = nf90_get_var(ncid2d,varid,dummy2d) - ! failed => rc < 0 - if (rc<0) print*, "ERROR READING SCT_DOM FROM FILE" - print*, "min max dummy2d = ", minval(dummy2d), maxval(dummy2d) - endif - print*, "INQUIRE ABOUT SOIL TYPE FRACTIONS FROM GEOGRID FILE" - rc = nf90_inq_varid(ncid2d,"SOILCTOP",varid) - ! failed => rc < 0 - if (rc<0) print*, "ERROR FINDING SOILCTOP IN GEOGRID FILE" - if (rc == 0) then - print*, "READ SOIL TYPE FRACTIONS FROM GEOGRID FILE " - rc = nf90_get_var(ncid2d,varid,dummy3d_stype) - ! failed => rc < 0 - if (rc<0) print*, "ERROR READING SCT_DOM FROM FILE" - print*, "min max dummy3d_stype = ", minval(dummy3d_stype), maxval(dummy3d_stype) - endif + if (rc /= nf90_noerr) call error_handler("READING GEOGRID FILE",rc) - print*, "CLOSE GEOGRID FILE " - iret = nf90_close(ncid2d) - endif + print*, "INQURE ABOUT DIM IDS" + rc = nf90_inq_dimid(ncid2d,"west_east",varid) + if (rc /= nf90_noerr) call error_handler("READING west_east DIMENSION FROM GEOGRID FILE",rc) + + rc = nf90_inquire_dimension(ncid2d,varid,len=varsize) + if (rc /= nf90_noerr) call error_handler("READING west_east DIMENSION SIZE",rc) + if (varsize .ne. i_input) call error_handler ("GEOGRID FILE GRID SIZE DIFFERS FROM INPUT DATA.", -1) + + print*, "INQUIRE ABOUT SOIL TYPE FROM GEOGRID FILE" + rc = nf90_inq_varid(ncid2d,"SCT_DOM",varid) + if (rc /= nf90_noerr) call error_handler("FINDING SCT_DOM IN GEOGRID FILE",rc) + + print*, "READ SOIL TYPE FROM GEOGRID FILE " + rc = nf90_get_var(ncid2d,varid,dummy2d) + if (rc /= nf90_noerr) call error_handler("READING SCT_DOM FROM FILE",rc) + + print*, "INQUIRE ABOUT SOIL TYPE FRACTIONS FROM GEOGRID FILE" + rc = nf90_inq_varid(ncid2d,"SOILCTOP",varid) + if (rc /= nf90_noerr) call error_handler("FINDING SOILCTOP IN GEOGRID FILE",rc) + + print*, "READ SOIL TYPE FRACTIONS FROM GEOGRID FILE " + rc = nf90_get_var(ncid2d,varid,dummy3d_stype) + if (rc /= nf90_noerr) call error_handler("READING SCT_DOM FROM FILE",rc) + + print*, "CLOSE GEOGRID FILE " + iret = nf90_close(ncid2d) + ! There's an issue with the geogrid file containing soil type water at land points. ! This correction replaces the soil type at these points with the soil type with