Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Summa Actors
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Numerical_Simulations_Lab
Actors
Summa Actors
Commits
e91091ee
Commit
e91091ee
authored
2 years ago
by
Kyle
Browse files
Options
Downloads
Patches
Plain Diff
added better error messaging
parent
a8ead8c4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
build/source/engine/ffile_info.f90
+100
-83
100 additions, 83 deletions
build/source/engine/ffile_info.f90
with
100 additions
and
83 deletions
build/source/engine/ffile_info.f90
+
100
−
83
View file @
e91091ee
...
@@ -106,11 +106,20 @@ subroutine ffile_info(indxGRU,forcFileInfo,numFiles,err,message)
...
@@ -106,11 +106,20 @@ subroutine ffile_info(indxGRU,forcFileInfo,numFiles,err,message)
! open file
! open file
call
file_open
(
trim
(
infile
),
unt
,
err
,
cmessage
)
call
file_open
(
trim
(
infile
),
unt
,
err
,
cmessage
)
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
trim
(
cmessage
);
return
;
end
if
if
(
err
/
=
0
)
then
message
=
trim
(
message
)//
trim
(
cmessage
)
print
*
,
message
return
end
if
! get a list of character strings from non-comment lines
! get a list of character strings from non-comment lines
call
get_vlines
(
unt
,
dataLines
,
err
,
cmessage
)
call
get_vlines
(
unt
,
dataLines
,
err
,
cmessage
)
if
(
err
/
=
0
)
then
;
err
=
20
;
message
=
trim
(
message
)//
trim
(
cmessage
);
return
;
end
if
if
(
err
/
=
0
)
then
err
=
20
message
=
trim
(
message
)//
trim
(
cmessage
)
print
*
,
message
return
end
if
nFile
=
size
(
dataLines
)
nFile
=
size
(
dataLines
)
! Get the number of forcing files needed
! Get the number of forcing files needed
...
@@ -207,14 +216,19 @@ subroutine ffile_info(indxGRU,forcFileInfo,numFiles,err,message)
...
@@ -207,14 +216,19 @@ subroutine ffile_info(indxGRU,forcFileInfo,numFiles,err,message)
! check if file exists
! check if file exists
inquire
(
file
=
trim
(
infile
),
exist
=
xist
)
inquire
(
file
=
trim
(
infile
),
exist
=
xist
)
if
(
.not.
xist
)
then
if
(
.not.
xist
)
then
message
=
trim
(
message
)//
"FileNotFound[file='"
//
trim
(
infile
)//
"']"
message
=
trim
(
message
)//
"FileNotFound[file='"
//
trim
(
infile
)//
"']"
err
=
10
;
return
print
*
,
message
err
=
10
;
return
end
if
end
if
! open file
! open file
mode
=
nf90_NoWrite
mode
=
nf90_NoWrite
call
nc_file_open
(
trim
(
infile
),
mode
,
ncid
,
err
,
cmessage
)
call
nc_file_open
(
trim
(
infile
),
mode
,
ncid
,
err
,
cmessage
)
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
trim
(
cmessage
);
return
;
end
if
if
(
err
/
=
0
)
then
message
=
trim
(
message
)//
trim
(
cmessage
)
print
*
,
message
return
end
if
! how many variables are there?
! how many variables are there?
err
=
nf90_inquire
(
ncid
,
nvariables
=
nVar
)
err
=
nf90_inquire
(
ncid
,
nvariables
=
nVar
)
...
@@ -228,8 +242,9 @@ subroutine ffile_info(indxGRU,forcFileInfo,numFiles,err,message)
...
@@ -228,8 +242,9 @@ subroutine ffile_info(indxGRU,forcFileInfo,numFiles,err,message)
! allocate space
! allocate space
allocate
(
forcFileInfo
%
ffile_list
(
iFile
)
%
var_ix
(
nVar
),
stat
=
err
)
allocate
(
forcFileInfo
%
ffile_list
(
iFile
)
%
var_ix
(
nVar
),
stat
=
err
)
if
(
err
/
=
0
)
then
if
(
err
/
=
0
)
then
message
=
trim
(
message
)//
'problem allocating space for structure element'
message
=
trim
(
message
)//
'problem allocating space for structure element'
err
=
20
;
return
print
*
,
message
err
=
20
;
return
endif
endif
! initialize data structure
! initialize data structure
...
@@ -246,90 +261,92 @@ subroutine ffile_info(indxGRU,forcFileInfo,numFiles,err,message)
...
@@ -246,90 +261,92 @@ subroutine ffile_info(indxGRU,forcFileInfo,numFiles,err,message)
! loop through all variables in netcdf file, check to see if everything needed to run the model exists and data_step is correct
! loop through all variables in netcdf file, check to see if everything needed to run the model exists and data_step is correct
do
iNC
=
1
,
nVar
do
iNC
=
1
,
nVar
! inquire about current variable name, type, number of dimensions
! inquire about current variable name, type, number of dimensions
err
=
nf90_inquire_variable
(
ncid
,
iNC
,
name
=
varName
)
err
=
nf90_inquire_variable
(
ncid
,
iNC
,
name
=
varName
)
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
'problem inquiring variable: '
//
trim
(
varName
);
return
;
end
if
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
'problem inquiring variable: '
//
trim
(
varName
);
return
;
end
if
! process variable
! process variable
select
case
(
trim
(
varName
))
select
case
(
trim
(
varName
))
! if variable is in the forcing vector
! if variable is in the forcing vector
case
(
'time'
,
'pptrate'
,
'SWRadAtm'
,
'LWRadAtm'
,
'airtemp'
,
'windspd'
,
'airpres'
,
'spechum'
)
case
(
'time'
,
'pptrate'
,
'SWRadAtm'
,
'LWRadAtm'
,
'airtemp'
,
'windspd'
,
'airpres'
,
'spechum'
)
! get variable index
! get variable index
ivar
=
get_ixforce
(
trim
(
varname
))
ivar
=
get_ixforce
(
trim
(
varname
))
if
(
ivar
<
0
)
then
;
err
=
40
;
message
=
trim
(
message
)//
"variableNotFound[var="
//
trim
(
varname
)//
"]"
;
return
;
end
if
if
(
ivar
<
0
)
then
;
err
=
40
;
message
=
trim
(
message
)//
"variableNotFound[var="
//
trim
(
varname
)//
"]"
;
return
;
end
if
if
(
ivar
>
size
(
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
))
then
;
err
=
35
;
message
=
trim
(
message
)//
"indexOutOfRange[var="
//
trim
(
varname
)//
"]"
;
return
;
end
if
if
(
ivar
>
size
(
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
))
then
;
err
=
35
;
message
=
trim
(
message
)//
"indexOutOfRange[var="
//
trim
(
varname
)//
"]"
;
return
;
end
if
! put netcdf file variable index in the forcing file metadata structure
! put netcdf file variable index in the forcing file metadata structure
err
=
nf90_inq_varid
(
ncid
,
trim
(
varName
),
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
(
ivar
))
err
=
nf90_inq_varid
(
ncid
,
trim
(
varName
),
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
(
ivar
))
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
"problem inquiring forcing variable[var="
//
trim
(
varName
)//
"]"
;
return
;
end
if
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
"problem inquiring forcing variable[var="
//
trim
(
varName
)//
"]"
;
return
;
end
if
! put variable index of the forcing structure in the metadata structure
! put variable index of the forcing structure in the metadata structure
if
(
trim
(
varName
)/
=
'time'
)
then
if
(
trim
(
varName
)/
=
'time'
)
then
forcFileInfo
%
ffile_list
(
iFile
)
%
var_ix
(
iNC
)
=
ivar
forcFileInfo
%
ffile_list
(
iFile
)
%
var_ix
(
iNC
)
=
ivar
forcFileInfo
%
ffile_list
(
iFile
)
%
varName
(
ivar
)
=
trim
(
varName
)
forcFileInfo
%
ffile_list
(
iFile
)
%
varName
(
ivar
)
=
trim
(
varName
)
! get first time from file, place into forcFileInfo
! get first time from file, place into forcFileInfo
else
else
err
=
nf90_get_var
(
ncid
,
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
(
ivar
),
forcFileInfo
%
ffile_list
(
iFile
)
%
firstJulDay
,
start
=
(/
1
/))
err
=
nf90_get_var
(
ncid
,
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
(
ivar
),
forcFileInfo
%
ffile_list
(
iFile
)
%
firstJulDay
,
start
=
(/
1
/))
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
'problem reading first Julian day'
;
return
;
end
if
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
'problem reading first Julian day'
;
return
;
end
if
end
if
! if the variable name is time
end
if
! if the variable name is time
! data step
! data step
case
(
'data_step'
)
case
(
'data_step'
)
! read data_step from netcdf file
! read data_step from netcdf file
err
=
nf90_inq_varid
(
ncid
,
"data_step"
,
varId
);
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
'cannot find data_step'
;
return
;
end
if
err
=
nf90_inq_varid
(
ncid
,
"data_step"
,
varId
);
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
'cannot find data_step'
;
return
;
end
if
err
=
nf90_get_var
(
ncid
,
varid
,
dataStep_iFile
);
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
'cannot read data_step'
;
return
;
end
if
err
=
nf90_get_var
(
ncid
,
varid
,
dataStep_iFile
);
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
'cannot read data_step'
;
return
;
end
if
! check data_step is the same for all forcing files
! check data_step is the same for all forcing files
if
(
iFile
==
1
)
then
if
(
iFile
==
1
)
then
data_step
=
dataStep_iFile
data_step
=
dataStep_iFile
else
else
if
(
abs
(
dataStep_iFile
-
data_step
)
>
epsilon
(
dataStep_iFile
))
then
if
(
abs
(
dataStep_iFile
-
data_step
)
>
epsilon
(
dataStep_iFile
))
then
write
(
message
,
'(a,i0,a)'
)
trim
(
message
)//
'data step for forcing file '
,
iFile
,
'differs from the datastep of the first forcing file'
write
(
message
,
'(a,i0,a)'
)
trim
(
message
)//
'data step for forcing file '
,
iFile
,
'differs from the datastep of the first forcing file'
err
=
20
;
return
err
=
20
;
return
end
if
end
if
end
if
end
if
! HRU id -- required
! HRU id -- required
case
(
'hruId'
)
case
(
'hruId'
)
! check to see if hruId exists as a variable, this is a required variable
! check to see if hruId exists as a variable, this is a required variable
err
=
nf90_inq_varid
(
ncid
,
trim
(
varname
),
varId
)
err
=
nf90_inq_varid
(
ncid
,
trim
(
varname
),
varId
)
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
'hruID variable not present'
;
return
;
endif
if
(
err
/
=
0
)
then
;
message
=
trim
(
message
)//
'hruID variable not present'
;
return
;
endif
! check that the hruId is what we expect
! check that the hruId is what we expect
! NOTE: we enforce that the HRU order in the forcing files is the same as in the zLocalAttributes files (too slow otherwise)
! NOTE: we enforce that the HRU order in the forcing files is the same as in the zLocalAttributes files (too slow otherwise)
! do iGRU=1,nGRU
do
localHRU_ix
=
1
,
gru_struc
(
indxGRU
)
%
hruCount
do
localHRU_ix
=
1
,
gru_struc
(
indxGRU
)
%
hruCount
! check the HRU is what we expect
! check the HRU is what we expect
err
=
nf90_get_var
(
ncid
,
varId
,
ncHruId
,
start
=
(/
gru_struc
(
indxGRU
)
%
hruInfo
(
localHRU_ix
)
%
hru_nc
/),
count
=
(/
1
/))
err
=
nf90_get_var
(
ncid
,
varId
,
ncHruId
,
start
=
(/
gru_struc
(
indxGRU
)
%
hruInfo
(
localHRU_ix
)
%
hru_nc
/),
count
=
(/
1
/))
if
(
gru_struc
(
indxGRU
)
%
hruInfo
(
localHRU_ix
)
%
hru_id
/
=
ncHruId
(
1
))
then
if
(
gru_struc
(
indxGRU
)
%
hruInfo
(
localHRU_ix
)
%
hru_id
/
=
ncHruId
(
1
))
then
write
(
message
,
'(a,i0,a,i0,a,i0,a,a)'
)
trim
(
message
)//
'hruId for global HRU: '
,
gru_struc
(
indxGRU
)
%
hruInfo
(
localHRU_ix
)
%
hru_nc
,
' - '
,
&
write
(
message
,
'(a,i0,a,i0,a,i0,a,a)'
)
trim
(
message
)//
'hruId for global HRU: '
,
gru_struc
(
indxGRU
)
%
hruInfo
(
localHRU_ix
)
%
hru_nc
,
' - '
,
&
ncHruId
(
1
),
' differs from the expected: '
,
gru_struc
(
indxGRU
)
%
hruInfo
(
localHRU_ix
)
%
hru_id
,
' in file '
,
trim
(
infile
)
ncHruId
(
1
),
' differs from the expected: '
,
gru_struc
(
indxGRU
)
%
hruInfo
(
localHRU_ix
)
%
hru_id
,
' in file '
,
trim
(
infile
)
write
(
message
,
'(a)'
)
trim
(
message
)//
' order of hruId in forcing file needs to match order in zLocalAttributes.nc'
write
(
message
,
'(a)'
)
trim
(
message
)//
' order of hruId in forcing file needs to match order in zLocalAttributes.nc'
err
=
40
;
return
err
=
40
;
return
endif
endif
end
do
end
do
! end do
! OK to have additional variables in the forcing file that are not used
case
default
;
cycle
! OK to have additional variables in the forcing file that are not used
end
select
! select variable name
case
default
;
cycle
end
select
! select variable name
end
do
! (end of netcdf file variable loop)
end
do
! (end of netcdf file variable loop)
! check to see if any forcing variables are missed
! check to see if any forcing variables are missed
if
(
any
(
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
(:)
==
integerMissing
))
then
if
(
any
(
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
(:)
==
integerMissing
))
then
do
iVar
=
1
,
size
(
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
)
do
iVar
=
1
,
size
(
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
)
if
(
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
(
iVar
)
==
integerMissing
)
then
;
err
=
40
;
message
=
trim
(
message
)//
"variable missing [var='"
//
trim
(
forcFileInfo
%
ffile_list
(
iFile
)
%
varname
(
iVar
))//
"']"
;
return
;
end
if
if
(
forcFileInfo
%
ffile_list
(
iFile
)
%
data_id
(
iVar
)
==
integerMissing
)
then
;
err
=
40
;
message
=
trim
(
message
)//
"variable missing [var='"
//
trim
(
forcFileInfo
%
ffile_list
(
iFile
)
%
varname
(
iVar
))//
"']"
;
return
;
end
if
end
do
end
do
end
if
end
if
! close file
! close file
err
=
nf90_close
(
ncid
)
err
=
nf90_close
(
ncid
)
if
(
err
/
=
nf90_noerr
)
then
;
message
=
trim
(
message
)//
'trouble closing file '
//
trim
(
infile
);
return
;
endif
if
(
err
/
=
nf90_noerr
)
then
message
=
trim
(
message
)//
'trouble closing file '
//
trim
(
infile
)
print
*
,
message
return
endif
end
do
! (loop through files)
end
do
! (loop through files)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment