From 3f382f3dcf233565e12fbf70196cc3abc97f5fa5 Mon Sep 17 00:00:00 2001 From: Damian Rouson Date: Mon, 28 Oct 2024 21:15:24 -0700 Subject: [PATCH] fix(train-cloud-micro): inquire about network file This commit replaces an `open` statement with an `inquire` statatement to prevent a crash when mistakenly attempting to reopen an already open file. --- demo/app/train-cloud-microphysics.F90 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/demo/app/train-cloud-microphysics.F90 b/demo/app/train-cloud-microphysics.F90 index ee19bda9d..3ad745ae6 100644 --- a/demo/app/train-cloud-microphysics.F90 +++ b/demo/app/train-cloud-microphysics.F90 @@ -261,10 +261,14 @@ subroutine read_train_write(training_configuration, args, plot_file) ), & network_file => args%base_name // "_network.json" & ) - open(newunit=network_unit, file=network_file, form='formatted', status='old', iostat=io_status, action='read') - + check_for_network_file: & + block + logical preexisting_network_file + + inquire(file=network_file, exist=preexisting_network_file) + read_or_initialize_network: & - if (io_status==0) then + if (preexisting_network_file) then print *,"Reading network from file " // network_file trainable_network = trainable_network_t(neural_network_t(file_t(string_t(network_file)))) close(network_unit) @@ -303,6 +307,8 @@ subroutine read_train_write(training_configuration, args, plot_file) end if read_or_initialize_network + end block check_for_network_file + print *, "Conditionally sampling for a flat distribution of output values" flatten_histogram: &