Skip to content

Commit

Permalink
Merge pull request #53 from jhamman/develop
Browse files Browse the repository at this point in the history
Fixes failing tests on Travis
Various warnings cleaned as well
  • Loading branch information
gutmann authored Mar 10, 2017
2 parents fd6b2d9 + 8f80e1d commit 1fcb993
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 76 deletions.
30 changes: 19 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
sudo: false
sudo: false # use container-based build
language: fortran
compiler:
- gfortran
os:
- linux
notifications:
email: false

compiler: gfortran-6
os: linux
env: TESTID='gard_linux'
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gfortran
- libnetcdf-dev
- liblapack-dev
- libnetcdf-dev
- gfortran-6
before_install:
- source ci/gard_install_utils
- gard_before_install
install:
- gard_install
script:
- sed -i "s|NCDF_PATH = /usr/local|NCDF_PATH = /usr|" src/makefile
- sed -i "s|LAPACK_PATH = /usr/local|LAPACK_PATH = /usr|" src/makefile
- make -C src -j4 test
- make -C src -j4
- gard_script
after_success:
- gard_after_success
after_failure:
- gard_after_failure
115 changes: 115 additions & 0 deletions ci/gard_install_utils
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/env bash

set -e
set -x

export CC=/usr/bin/gcc-6
export FC=/usr/bin/gfortran-6

if [ -z "$WORKDIR" ]; then
export WORKDIR=$HOME/workdir
mkdir -p $WORKDIR
fi

if [ -z "$INSTALLDIR" ]; then
export INSTALLDIR=$HOME/installdir
mkdir -p $INSTALLDIR
fi

function install_szip {
echo install_szip
cd $WORKDIR
wget --no-check-certificate -q http://www.hdfgroup.org/ftp/lib-external/szip/2.1/src/szip-2.1.tar.gz
tar -xzf szip-2.1.tar.gz
cd szip-2.1
./configure --prefix=$INSTALLDIR &> config.log
make &> make.log
make install
export CPPFLAGS="$CPPFLAGS -I${INSTALLDIR}/include"
export LDFLAGS="$LDFLAGS -L${INSTALLDIR}/lib"
}

function install_hdf5 {
echo install_hdf5
cd $WORKDIR
wget --no-check-certificate -q http://www.hdfgroup.org/ftp/HDF5/current/src/hdf5-1.10.0-patch1.tar.gz
tar -xzf hdf5-1.10.0-patch1.tar.gz
cd hdf5-1.10.0-patch1
./configure --prefix=$INSTALLDIR &> config.log
make &> make.log
make install
export LIBDIR=${INSTALLDIR}/lib
}

function install_netcdf_c {
echo install_netcdf_c
cd $WORKDIR
wget --no-check-certificate -q ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.4.1.tar.gz
tar -xzf netcdf-4.4.1.tar.gz
cd netcdf-4.4.1
./configure --prefix=$INSTALLDIR &> config.log
make &> make.log
make install
export LD_LIBRARY_PATH=${INSTALLDIR}/lib
}

function install_netcdf_fortran {
echo install_netcdf_fortran
cd $WORKDIR
wget --no-check-certificate -q ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-fortran-4.4.4.tar.gz
tar -xzf netcdf-fortran-4.4.4.tar.gz
cd netcdf-fortran-4.4.4
./configure --prefix=$INSTALLDIR &> config.log
make &> make.log
make install
}

function gard_before_install {
echo gard_before_install
# Install szip (used by hdf5)
install_szip
# Install HDF5
install_hdf5
# Install NetCDF-C
install_netcdf_c
# Install NetCDF fortran
install_netcdf_fortran
}

function gard_install {
echo gard_install
cd ${TRAVIS_BUILD_DIR}
sed -i "s|NCDF_PATH = /usr/local|NCDF_PATH = ${INSTALLDIR}|" src/makefile
sed -i "s|LAPACK_PATH = /usr/local|LAPACK_PATH = /usr|" src/makefile
make -C src clean; make -C src -j4 test
make -C src clean; make -C src -j4 MODE=debugslow
make -C src clean; make -C src -j4 MODE=debug
make -C src clean; make -C src -j4 MODE=debugompslow
make -C src clean; make -C src -j4 MODE=debugomp
make -C src clean; make -C src -j4 MODE=profile
make -C src clean; make -C src -j4 MODE=fast
make -C src clean; make -C src -j4
echo "GARD install succeeded"
}

function gard_script {
cd ./src
./gard --version
./gard -h
./test_calendar
# ./test_random
./test_regression
# ./test_config ../run/downscale_options.txt
cd ../
echo "GARD script succeeded"
}

function gard_after_success {
echo gard_after_success
echo "GARD build succeeded"
}

function gard_after_failure {
echo gard_after_failure
echo "GARD build failed"
}
2 changes: 2 additions & 0 deletions docs/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ GARD has the following dependencies:
1. LAPACK — Linear Algebra PACKage.
1. netCDF4 - Network Common Data Form.

*Note: GARD allocates memory to the stack. Users should set the "The maximum stack size." to "unlimited" prior to building/running GARD. `ulimit -s unlimited`*

## Building GARD

GARD is built using a standard `makefile`. From the command line, simply run the following command:
Expand Down
50 changes: 47 additions & 3 deletions src/config/configuration.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!>------------------------------------------------
!! Reads the configuration input file
!! Also looks for commandline arguments to for an config filename
!! Also looks for command line arguments to for an config filename
!!
!! @author
!! Ethan Gutmann ([email protected])
Expand All @@ -19,6 +19,7 @@ module config_mod
logical :: module_debug
public :: read_config
public :: read_files_list, read_data_type, get_options_file ! only need to be public for test_config
public :: print_model_init
contains

!>------------------------------------------------
Expand Down Expand Up @@ -762,6 +763,16 @@ function get_options_file() result(options_file)
! read the commandline argument
call get_command_argument(1,options_file, status=error)

if (trim(options_file) == '--version') then
write(*, *) 'GARD '//trim(kVERSION_STRING)
stop
elseif (trim(options_file) == '-h') then
call print_model_init()
stop
else
call print_model_init()
endif

! if there was an error, return the default filename
if (error>0) then
options_file = kDEFAULT_OPTIONS_FILENAME
Expand All @@ -772,8 +783,8 @@ function get_options_file() result(options_file)
stop "ERROR: options filename too long"
endif
else
! if not commandline options were given, assume a default filename
options_file = kDEFAULT_OPTIONS_FILENAME
call print_model_init()
stop
endif

! check to see if the expected filename even exists on disk
Expand All @@ -786,4 +797,37 @@ function get_options_file() result(options_file)
write(*,*) "Using options file = ", trim(options_file)
end function get_options_file

!>------------------------------------------------
!! Prints model configuration info before running
!!
!! Prints a welcome and version string as well.
!!------------------------------------------------
subroutine print_model_init()
implicit none

write(*,*) "Generalized Analog Regression Downscaling (GARD)"
write(*,*) "-----------------------------------------------------------"
write(*,*) "GARD Version : "//trim(kVERSION_STRING)
! TODO: Add compile time options
write(*,*) ""
write(*,*) " The Generalized Analog Regression Downscaling (GARD)"
write(*,*) " downscaling tool, version "//trim(kVERSION_STRING)//", Copyright (C) 2017 The"
write(*,*) " National Center for Atmospheric Research. GARD comes with"
write(*,*) " ABSOLUTELY NO WARRANTY. This is free software, you may "
write(*,*) " redistribute it under certain conditions; see LICENSE.txt"
write(*,*) " for details."
write(*,*) ""
write(*,*) " Online Documentation : http://gard.readthedocs.io"
write(*,*) " Report Bugs and Issues to : https://github.com/NCAR/GARD/issues"
write(*,*) ""
write(*,*) "-----------------------------------------------------------"
write(*,*) "Usage: gard [-h] [--version] options_file"
write(*,*) ""
write(*,*) "-h Help information for GARD"
write(*,*) "--version Print the version number"
write(*,*) "options_file Input options file name"
write(*,*) ""

end subroutine print_model_init

end module config_mod
7 changes: 3 additions & 4 deletions src/downscaling_stats/regression.f90
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function compute_regression(x, training_x, training_y, coefficients, y_test, err
if (size(weights)/=size(training_y_lp)) then
!$omp critical (print_lock)
write(*,*) "ERROR size of weights /= data"
write(*,*), shape(weights), shape(training_y_lp)
write(*,*) shape(weights), shape(training_y_lp)
!$omp end critical (print_lock)
endif
if (present(y_test)) then
Expand Down Expand Up @@ -207,8 +207,8 @@ subroutine weighted_least_squares(X, Y, B, W)
real, intent(inout), dimension(:,:) :: X
real, intent(inout), dimension(:) :: Y, W
real(8), intent(inout), dimension(:) :: B
real, dimension(:,:), allocatable :: X_weighted, W_full
real, dimension(:), allocatable :: Y_weighted, Bs, output_y
real, dimension(:,:), allocatable :: W_full
real, dimension(:), allocatable :: Bs, output_y

real, dimension(10000) :: WORK
integer :: i, n, m, nrhs, LDX, LDY, LDW, LWORK, INFO, p
Expand Down Expand Up @@ -281,7 +281,6 @@ subroutine logistic_regression(X, Y, B)
real, allocatable :: YN(:), XV(:,:)

integer :: nvars, ntimes, i, t, f, it
real :: d
integer :: info

! skip the logistic regression and force the result to be 1
Expand Down
9 changes: 5 additions & 4 deletions src/downscaling_stats/sampling.f90
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,18 @@ subroutine sample_distribution(output, mean_values, error_term, &

! if random number is greater than the non-exceedence probability, then we have exceeded it...
! rescale the uniform random number for the region of exceedence and convert to a normal random number
random_normal = get_normal_from_cdf((uniform(i) - (1 - exceedence_probability(i))) / (exceedence_probability(i)) )

random_normal = get_normal_from_cdf((uniform(i) - (1 - exceedence_probability(i))) &
/ (exceedence_probability(i)))

! ultimately this is the same equation as below for variables without an exceedence threshold
output(i) = mean_values(i) + error_term(i) * random_normal

! also check, if the random term has pushed the value below the threshold anyway, then just set to the threshold
if (output(i) < threshold_internal) then
output(i) = threshold_internal
endif
else
! if this value did not exceed the threshold, then just set it to the threshold.
! if this value did not exceed the threshold, then just set it to the threshold.
output(i) = threshold_internal
endif
else
Expand Down
4 changes: 2 additions & 2 deletions src/io/io_routines.f90
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ subroutine io_write2d(filename,varname,data_out)
! Close the file, freeing all resources.
call check( nf90_close(ncid) )
end subroutine io_write2d

subroutine io_write1d(filename,varname,data_out)
implicit none
! This is the name of the data file and variable we will read.
Expand Down Expand Up @@ -1218,7 +1218,7 @@ subroutine check(status,extra)
print *, trim(nf90_strerror(status))
if(present(extra)) then
! print any optionally provided context
write(*,*), trim(extra)
write(*,*) trim(extra)
endif
! STOP the program execute
stop "Stopped"
Expand Down
8 changes: 4 additions & 4 deletions src/io/output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ subroutine write_output(output, options)
implicit none
type(config), intent(in) :: options
type(results), intent(in) :: output

character(len=MAXFILELENGTH) :: filename
character(len=MAXFILELENGTH) :: dimnames(3)
real, dimension(:,:,:), allocatable :: output_data
Expand Down Expand Up @@ -145,9 +145,9 @@ subroutine memory_error(error, variable_name, dims)
character(len=*), intent(in) :: variable_name
integer, intent(in), dimension(:) :: dims

write(*,*), "Error allocating memory for variable: ", trim(variable_name)
write(*,*), " ERROR = ", error
write(*,*), " Dimensions = ", dims
write(*,*) "Error allocating memory for variable: ", trim(variable_name)
write(*,*) " ERROR = ", error
write(*,*) " Dimensions = ", dims

stop "MEMORY ALLOCATION ERROR"

Expand Down
38 changes: 1 addition & 37 deletions src/main/init.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,9 @@ module init_mod

implicit none
private
public :: model_init, print_model_init
public :: model_init
contains

!>------------------------------------------------
!! Prints model configuration info before running
!!
!! Prints a welcome and version string as well.
!! Only prints configuration info if debug == true
!!
!!------------------------------------------------
subroutine print_model_init()
implicit none

write(*,*) ""
write(*,*) " ====================================================== "
write(*,*) ""
write(*,*) " Downscaling Model "
write(*,*) " Version : "//trim(kVERSION_STRING)
write(*,*) ""
write(*,*) " Developed at NCAR: "
write(*,*) " The National Center for Atmospheric Research "
write(*,*) " NCAR is supported by the National Science Foundation "
write(*,*) " ------------------------------------------------------ "
write(*,*) " ------------------------------------------------------ "
write(*,*) ""
write(*,*) " WARNING WARNING WARNING WARNING WARNING WARNING "
write(*,*) ""
write(*,*) " This is pre-release not-even-beta code. "
write(*,*) ""
write(*,*) " WARNING WARNING WARNING WARNING WARNING WARNING "
write(*,*) ""
write(*,*) " ------------------------------------------------------ "
write(*,*) " ------------------------------------------------------ "
write(*,*) " ====================================================== "
write(*,*) ""

end subroutine print_model_init


!>------------------------------------------------
!! Initialize the model
!!
Expand Down
Loading

0 comments on commit 1fcb993

Please sign in to comment.