Skip to content

Commit

Permalink
Reads obs config, and successfully reads data for all inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
gutmann committed Jun 2, 2016
1 parent 6b26de5 commit e7b470d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 37 deletions.
5 changes: 5 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This code is designed to provide a simple statistical downscaling method relying
regressions and statistical transformations from various inputs (e.g. precipitation,
humidity, wind, PCA, etc.) to various outputs (e.g. precipitation, temperature, etc.)

##Useful commands
Use the following to generate a list of e.g. GEFS precipitation files for input.
ls -1 gefs/2010/*/apcp_sfc_*_mean.nc | sed 's/*//g;s/$/"/g;s/^/"/g'>gefs_pr_file.txt


##Requirements
T.B.D

Expand Down
72 changes: 35 additions & 37 deletions src/config/configuration.f90
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function read_config() result(options)

call read_base_options(options)

options%training = read_training_options( options%training_file, options%debug)
options%prediction = read_prediction_options( options%prediction_file, options%debug)
options%training = read_training_options( options%training_file, options%debug)
options%obs = read_obs_options( options%observation_file, options%debug)

end function read_config
Expand Down Expand Up @@ -90,13 +90,14 @@ function read_training_options(filename, debug) result(training_options)
integer :: nfiles, nvars, calendar_start_year
character(len=MAXSTRINGLENGTH) :: name, data_type, calendar
character(len=MAXVARLENGTH) :: lat_name, lon_name, time_name
character(len=MAXFILELENGTH), dimension(:), allocatable :: file_list
character(len=MAXVARLENGTH), dimension(:), allocatable :: var_names
character(len=MAXFILELENGTH), dimension(MAX_NUMBER_VARS) :: file_list
character(len=MAXVARLENGTH), dimension(MAX_NUMBER_VARS) :: var_names

! setup the namelist
namelist /training_parameters/ nfiles, nvars, name, data_type, &
lat_name, lon_name, time_name, &
file_list, var_names
file_list, var_names, &
calendar, calendar_start_year
!defaults :
nfiles = -1
nvars = -1
Expand Down Expand Up @@ -126,12 +127,13 @@ function read_training_options(filename, debug) result(training_options)
training_options%name = name
training_options%n_variables = nvars
training_options%nfiles = nfiles
! training_options%file_names(1,1)= "/d5/gefs/all/2010/20101127/spfh_2m_2010112700_mean.nc"
! training_options%var_names(1) = "SPFH_2maboveground"
do i=1,nvars
training_options%var_names(i) = var_names(i)
nfiles = read_files_list(file_list(i), training_options%file_names(:,i))
if (nfiles /= training_options%nfiles) stop "Error reading the correct number of training input files"
if (nfiles /= training_options%nfiles) then
write(*,*) nfiles, training_options%nfiles
stop "Error reading the correct number of training input files"
endif
end do
training_options%lat_name = lat_name
training_options%lon_name = lon_name
Expand All @@ -144,6 +146,7 @@ function read_training_options(filename, debug) result(training_options)

call check_training_options(training_options)


end function read_training_options

!>------------------------------------------------
Expand Down Expand Up @@ -180,19 +183,20 @@ function read_prediction_options(filename, debug) result(prediction_options)
logical, intent(in) :: debug
type(prediction_config) :: prediction_options

integer :: name_unit, i
integer :: name_unit, i, j

! namelist variables to be read
integer :: nfiles, nvars, calendar_start_year
character(len=MAXSTRINGLENGTH) :: name, data_type, calendar
character(len=MAXVARLENGTH) :: lat_name, lon_name, time_name
character(len=MAXFILELENGTH), dimension(:), allocatable :: file_list
character(len=MAXVARLENGTH), dimension(:), allocatable :: var_names
character(len=MAXFILELENGTH), dimension(MAX_NUMBER_VARS) :: file_list
character(len=MAXVARLENGTH), dimension(MAX_NUMBER_VARS) :: var_names

! setup the namelist
namelist /prediction_parameters/ nfiles, nvars, name, data_type, &
lat_name, lon_name, time_name, &
file_list, var_names
namelist /prediction_parameters/ nfiles, nvars, name, data_type, &
lat_name, lon_name, time_name, &
file_list, var_names, &
calendar, calendar_start_year
!defaults :
nfiles = -1
nvars = -1
Expand Down Expand Up @@ -222,11 +226,13 @@ function read_prediction_options(filename, debug) result(prediction_options)
prediction_options%name = name
prediction_options%n_variables = nvars
prediction_options%nfiles = nfiles
! prediction_options%file_names(1,1)= "/d4/gutmann/cmip/daily/ccsm/subset/hus_day_CCSM4_historical_r6i1p1_19750101-19791231.nc"
do i=1,nvars
prediction_options%var_names(i) = var_names(i)
nfiles = read_files_list(file_list(i), prediction_options%file_names(:,i))
if (nfiles/=prediction_options%nfiles) stop "Error reading the correct number of prediction input files"
if (nfiles/=prediction_options%nfiles) then
write(*,*) nfiles, prediction_options%nfiles
stop "Error reading the correct number of prediction input files"
endif
end do
prediction_options%lat_name = lat_name
prediction_options%lon_name = lon_name
Expand Down Expand Up @@ -280,13 +286,14 @@ function read_obs_options(filename, debug) result(obs_options)
integer :: nfiles, nvars, calendar_start_year
character(len=MAXSTRINGLENGTH) :: name, data_type, calendar
character(len=MAXVARLENGTH) :: lat_name, lon_name, time_name
character(len=MAXFILELENGTH), dimension(:), allocatable :: file_list
character(len=MAXVARLENGTH), dimension(:), allocatable :: var_names
character(len=MAXFILELENGTH), dimension(MAX_NUMBER_VARS) :: file_list
character(len=MAXVARLENGTH), dimension(MAX_NUMBER_VARS) :: var_names

! setup the namelist
namelist /obs_parameters/ nfiles, nvars, name, data_type, &
lat_name, lon_name, time_name, &
file_list, var_names
namelist /obs_parameters/ nfiles, nvars, name, data_type, &
lat_name, lon_name, time_name, &
file_list, var_names, &
calendar, calendar_start_year
!defaults :
nfiles = -1
nvars = -1
Expand Down Expand Up @@ -316,12 +323,13 @@ function read_obs_options(filename, debug) result(obs_options)
obs_options%name = name
obs_options%n_variables = nvars
obs_options%nfiles = nfiles
! obs_options%file_names(1,1)= "/d2/gutmann/usbr/stat_data/DAILY/obs/maurer.125/pr/nldas_met_update.obs.daily.pr.1980.nc"
! obs_options%var_names(1) = "pr"
do i=1,nvars
obs_options%var_names(i) = var_names(i)
nfiles = read_files_list(file_list(i), obs_options%file_names(:,i))
if (nfiles/=obs_options%nfiles) stop "Error reading the correct number of obs input files"
if (nfiles/=obs_options%nfiles) then
write(*,*) nfiles, obs_options%nfiles
stop "Error reading the correct number of obs input files"
endif
end do
obs_options%lat_name = lat_name
obs_options%lon_name = lon_name
Expand Down Expand Up @@ -379,8 +387,8 @@ function read_data_type(type_name) result(data_type)
case("obs")
data_type = kOBS_TYPE
case default
print*, "ERROR: unknown data type: "//trim(type_name)
print*, "Must be one of: GEFS, GCM, obs"
write(*,*) "ERROR: unknown data type: "//trim(type_name)
write(*,*) "Must be one of: GEFS, GCM, obs"
stop
end select

Expand Down Expand Up @@ -409,9 +417,9 @@ function read_files_list(filename, file_list) result(nfiles)
open(unit=io_newunit(file_unit), file=filename)
i=0
error=0
temporary_file = ""
do while (error==0)
read(file_unit, *, iostat=error) temporary_file

if (error==0) then
i=i+1

Expand All @@ -424,20 +432,10 @@ function read_files_list(filename, file_list) result(nfiles)
endif

enddo

close(file_unit)

nfiles = i
! print out a summary
write(*,*) "Files to be used:"
if (nfiles>10) then
write(*,*) " nfiles=", trim(str(nfiles)), ", too many to print."
write(*,*) " First file:", trim(forcing_files(1))
write(*,*) " Last file: ", trim(forcing_files(nfiles))
else
do i=1,nfiles
write(*,*) " ",trim(forcing_files(i))
enddo
endif

file_list(1:nfiles) = forcing_files(1:nfiles)

Expand Down
3 changes: 3 additions & 0 deletions src/main/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ program downscale
call model_init(options)

! read in the training atmospheric data (e.g. reanalysis or GEFS)
print*, "Reading training"
training_atm = read_atm(options%training)
! read in the training surface data (e.g. Maurer et al., Newman et al., Livneh et al., DAYMET )
print*, "Reading obs"
training_obs = read_obs(options%obs)

! read in the atmospheric predictor data (e.g. GCM or GEFS)
print*, "Reading predictor"
predictions = read_atm(options%prediction)

if (options%debug) then
Expand Down
1 change: 1 addition & 0 deletions src/objects/model_constants.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module model_constants
integer,public,parameter :: MAXFILELENGTH = 1024 ! maximum file name length
integer,public,parameter :: MAXVARLENGTH = 1024 ! maximum variable name length
integer,public,parameter :: MAXDIMLENGTH = 1024 ! maximum variable name length
integer,public,parameter :: MAX_NUMBER_VARS = 255 ! maximum number of permitted variables to process
integer,public,parameter :: MAX_NUMBER_FILES = 100000 ! maximum number of permitted input files
! 100000 = 1 file/day for ~274 years

Expand Down

0 comments on commit e7b470d

Please sign in to comment.