Skip to content

Spectral bin microphysics option crashes due to file not closed #2271

@csmill

Description

@csmill

Describe the bug
When trying to run WRF with the HUJI-fast spectral bin microphysics option (mp_physics=30), wrf.exe fails shortly after starting. It gives the error: module_mp_FAST_SBM_INIT: error opening hujisbm_DATA on unit,model stop. However, I have already downloaded the required files into the WRF/run folder, and they should be available. A similar issue was mentioned in a forum post (https://forum.mmm.ucar.edu/threads/huji-sbm.18560/) but no solution was given there.

Running in GDB revealed that the problem occurred after the second time the capacity33.asc file was read in, but the first time had no issues. It seems the file is opened successfully once but apparently never closed. Therefore, subsequent reads fail because the file was still open.

There are two files with this error in the module_mp_fast_sbm.F file, both of which can be fixed easily as far as I can tell. I was able to get the model to run without crashing by adding CLOSE() statements as follows:

(lines 5443-5448)

OPEN(UNIT=hujisbm_unit1,FILE=trim(input_dir)//"/BLKD_SDC.dat",FORM="FORMATTED",STATUS="OLD",ERR=2070)
DO kr=1,NKR
    READ(hujisbm_unit1,*) bin_mass(kr),tab_colum(kr),tab_dendr(kr),tab_snow(kr)
    bin_log(kr) = log10(bin_mass(kr))
ENDDO
CLOSE(hujisbm_unit1)

and

(lines 5498-5502)

OPEN(UNIT=hujisbm_unit1,FILE=trim(input_dir)//"/capacity33.asc",FORM="FORMATTED",STATUS="OLD",ERR=2070)
!OPEN(UNIT=hujisbm_unit1,FILE=trim(input_dir)//"/capacity43.asc",FORM="FORMATTED",STATUS="OLD",ERR=2070)
 	900	FORMAT(6E13.5)
READ(hujisbm_unit1,900) RLEC,RIEC,RSEC,RGEC,RHEC
CLOSE(hujisbm_unit1)

To Reproduce
Steps to reproduce the behavior:

  1. Use compiler and version: GNU Fortran (GCC) 13.3.1 20240611 (Red Hat 13.3.1-2)
  2. System: Rocky Linux release 8.10
  3. WRF version: WRF v4.7.1
  4. Use namelist options: see below for copy of my namelist.input
  5. Output is: module_mp_FAST_SBM_INIT: error opening hujisbm_DATA on unit,model stop

Expected behavior
The model should run without crashing.

Namelist

 &time_control
 run_days                            = 0,
 run_hours                           = 12,
 run_minutes                         = 0,
 run_seconds                         = 0,
 start_year                          = 2025, 2025, 2025,
 start_month                         = 11, 11, 11,
 start_day                           = 15, 15, 15,
 start_hour                          = 00, 00, 00,
 end_year                            = 2025, 2025, 2025,
 end_month                           = 11, 11, 11,
 end_day                             = 15, 15, 15,
 end_hour                            = 12, 12, 12,
 interval_seconds                    = 3600
 input_from_file                     = .true., .true., .true.,
 history_interval                    = 10, 10, 10,
 frames_per_outfile                  = 1, 1, 1,
 restart                             = .false.,
 restart_interval                    = 7200,
 io_form_history                     = 2
 io_form_restart                     = 2
 io_form_input                       = 2
 io_form_boundary                    = 2
 iofields_filename                   = "my_iofields", "my_iofields", "my_iofields"
 /

 &domains
 time_step                           = 54,
 time_step_fract_num                 = 0,
 time_step_fract_den                 = 1,
 max_dom                             = 3,
 e_we                                = 151, 151, 151,
 e_sn                                = 151, 151, 151,
 e_vert                              = 72, 72, 72,
 dzbot                               = 10.
 dzstretch_s                         = 1.11
 dzstretch_u                         = 1.10
 p_top_requested                     = 5000,
 num_metgrid_levels                  = 34,
 num_metgrid_soil_levels             = 4,
 dx                                  = 9000, 3000, 1000,
 dy                                  = 9000, 3000, 1000,
 grid_id                             = 1, 2, 3,
 parent_id                           = 1, 1, 2,
 i_parent_start                      = 1, 50, 50,
 j_parent_start                      = 1, 50, 50,
 parent_grid_ratio                   = 1, 3, 3,
 parent_time_step_ratio              = 1, 3, 3,
 feedback                            = 1,
 smooth_option                       = 0
 wif_input_opt                       = 0
 /

 &physics
 mp_physics                          = 30, 30, 30,
 cu_physics                          = 1, 1, 1,
 ra_lw_physics                       = 1, 1, 1,
 ra_sw_physics                       = 1, 1, 1,
 bl_pbl_physics                      = 1, 1, 1,
 sf_sfclay_physics                   = 1, 1, 1,
 sf_surface_physics                  = 2, 2, 2,
 radt                                = 1, 1, 1,
 bldt                                = 0, 0, 0,
 cudt                                = 0, 0, 0,
 icloud                              = 1,
 num_land_cat                        = 21,
 sf_urban_physics                    = 0, 0, 0,
 grav_settling                       = 2, 2, 2,
 fractional_seaice                   = 1,
 /

 &fdda
 /

 &dynamics
 hybrid_opt                          = 2,
 w_damping                           = 0,
 diff_opt                            = 2, 2, 2,
 km_opt                              = 4, 4, 4,
 diff_6th_opt                        = 0, 0, 0,
 diff_6th_factor                     = 0.12, 0.12, 0.12,
 base_temp                           = 290.
 damp_opt                            = 3,
 zdamp                               = 5000., 5000., 5000.,
 dampcoef                            = 0.2, 0.2, 0.2,
 khdif                               = 0, 0, 0,
 kvdif                               = 0, 0, 0,
 non_hydrostatic                     = .true., .true., .true.,
 moist_adv_opt                       = 1, 1, 1,
 scalar_adv_opt                      = 1, 1, 1,
 gwd_opt                             = 1, 0, 0,
 /

 &bdy_control
 spec_bdy_width                      = 5,
 specified                           = .true.
 /

 &grib2
 /

 &namelist_quilt
 nio_tasks_per_group = 0,
 nio_groups = 1,
 /

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions