!*************************************************************************
!*                                                                       *
!*     Initialization of parameters for nonsmooth optimization based     *
!*     clusterwise linear regression software (last modified 15.07.2016) *
!*                                                                       *
!*************************************************************************
!*
!*     Modules included:
!*
!*     initclr          ! Initialization of parameters for regerssion.
!*     initlmbm         ! Initialization of LMBM -solver.
!*

MODULE initclr  ! Initialization of parameters for clusterwise linear regression codes.

    USE r_precision, ONLY : prec  ! Precision for reals.
    IMPLICIT NONE

    ! Names of input and output files:
    CHARACTER(LEN=80), SAVE :: &
        !infile   = 'Carbonneau/acorn.txt', & !1 Name of dataset file.
        !infile   = 'Carbonneau/brinks.txt', & !2 Name of dataset file.
        !infile   = 'Carbonneau/carfuel.txt', & !3 Name of dataset file.
        !infile   = 'Carbonneau/CEOsalaries.txt', & !4 Name of dataset file.
        !infile   = 'Carbonneau/checkoff.txt', & !5 Name of dataset file.
        !infile   = 'Carbonneau/cheesetaste.txt', & !6 Name of dataset file.
        !infile   = 'Carbonneau/crimerate.txt', & !7 Name of dataset file.
        !infile   = 'Carbonneau/diabetes.txt', & !8 Name of dataset file.
        !infile   = 'Carbonneau/electricity.txt', & !9 Name of dataset file.
        !infile   = 'Carbonneau/enrollment.txt', & !10 Name of dataset file.
        !infile   = 'Carbonneau/extroversionCar.txt', & !11 Name of dataset file.
        !infile   = 'Carbonneau/HousePrices.txt', & !12 Name of dataset file.
        !infile   = 'Carbonneau/MercuryBass.txt', & !13 Name of dataset file.
        !infile   = 'Carbonneau/Mortality.txt', & !14 Name of dataset file.
        !infile   = 'Carbonneau/NuclearPlant.txt', & !15 Name of dataset file.
        !infile   = 'Carbonneau/PolishingTime.txt', & !16 Name of dataset file.
        !infile   = 'Carbonneau/PublicExpenditure.txt', & !17 Name of dataset file.
        !infile   = 'Carbonneau/SmokingCancer.txt', & !18 Name of dataset file.
        !infile   = 'Carbonneau/Temperatures.txt', & !19 Name of dataset file.
        !infile   = 'Carbonneau/Votes.txt', & !20 Name of dataset file.
        !
        !infile   = 'DataSets/RealData/ConcreteCompressiveStrength.txt', & !1 iso 1030   &   8(9) Name of dataset file
        !infile   = 'DataSets/RealData/airfoil_self_noise.txt', & !2 iso 1503   &   5(6) Name of dataset file
        !infile   = 'DataSets/RealData/winequality-red.txt', & !3 iso 1599   &   11(12) Name of dataset file
        !infile   = 'DataSets/RealData/winequality-white.txt', & !4 iso 4898   &   11(12) Name of dataset file
        !infile   = 'DataSets/RealData/CombinedPowerPlant.txt', & !5 iso 9568   &   4(5) Name of dataset file
        !infile   = 'DataSets/RealData/ProteinTertiary.txt', & !6 iso 45730  &   9(10) output=1 Name of dataset file
        !infile   = 'OnlineNewsPopularity.txt', & !7 iso 39797  &   58(59) Name of dataset file
        !infile   = 'DataSets/RealData/ticdata2000.txt', & !8 iso 9000  &   86 Name of dataset file
        infile   = 'DataSets/RealData/BlogData_train.txt', & !9 iso 52397  &   281  Name of dataset file
        !
        outfile1 = 'lmbm_hp_blog82.txt', &   ! Result file with hyperplanes.
        outfile2 = 'lmbm_pred.txt', &   ! Result file with predictions.
        outfile3 = 'lmbm_train.txt'     ! Result file with training test.


    ! Input integer parameters. Give values here.
    INTEGER, PARAMETER :: &
        !nft  = 128, &            ! Number of features in data, from user. 1
        nclust = 10, &             ! Maximum number of clusters, from user.
        !nft  = 8+1, &                !1 iso Number of features in data, from user.
        !nrecord = 1030, &             ! Number of records in data, from user.
        !nft  = 5+1, &                !2 iso Number of features in data, from user.
        !nrecord = 1503, &             ! Number of records in data, from user.
        !nft  = 11+1, &                !3 iso Number of features in data, from user.
        !nrecord = 1599, &             ! Number of records in data, from user.
        !nft  = 11+1, &                !4 iso Number of features in data, from user.
        !nrecord = 4898, &             ! Number of records in data, from user.
        !nft  = 4+1, &                !5 iso Number of features in data, from user.
        !nrecord = 9568, &             ! Number of records in data, from user.
        !nft  = 9+1, &                !6 iso Number of features in data, from user.
        !nrecord = 45730, &             ! Number of records in data, from user.
        !nft  = 58+1, &                !7 iso Number of features in data, from user.
        !nrecord = 39644, &             ! Number of records in data, from user.
        !nft  = 86, &                !8 iso Number of features in data, from user.
        !nrecord = 5822, &             ! Number of records in data, from user.
        nft  = 281, &                !9 iso Number of features in data, from user.
        nrecord = 52397, &             ! Number of records in data, from user.
        !
        !nft  = 4, &                !1 Number of features in data, from user. acorn
        !nrecord = 39, &             ! Number of records in data, from user.
        !nft  = 5, &                 !2 Number of features in data, from user.
        !nrecord = 47, &             ! Number of records in data, from user.
        !nft  = 2, &                 !3 Number of features in data, from user.
        !nrecord = 82, &             ! Number of records in data, from user.
        !nft  = 2, &                 !4 Number of features in data, from user.
        !nrecord = 59, &             ! Number of records in data, from user.
        !nft  = 5, &                 !5 Number of features in data, from user.
        !nrecord = 56, &             ! Number of records in data, from user.
        !nft  = 4, &                 !6 Number of features in data, from user.
        !nrecord = 30, &             ! Number of records in data, from user.
        !nft  = 6, &                 !7 Number of features in data, from user.
        !nrecord = 47, &             ! Number of records in data, from user.
        !nft  = 3, &                 !8 Number of features in data, from user.
        !nrecord = 43, &             ! Number of records in data, from user.
        !nft  = 4, &                 !9 Number of features in data, from user.
        !nrecord = 50, &             ! Number of records in data, from user.
        !nft  = 5, &                 !10 Number of features in data, from user.
        !nrecord = 29, &             ! Number of records in data, from user.
        !nft  = 4, &                 !11 Number of features in data, from user.
        !nrecord = 40, &             ! Number of records in data, from user.
        !nft  = 2, &                 !12 Number of features in data, from user.
        !nrecord = 40, &             ! Number of records in data, from user.
        !nft  = 5, &                 !13 Number of features in data, from user.
        !nrecord = 53, &             ! Number of records in data, from user.
        !nft  = 4, &                 !14 Number of features in data, from user.
        !nrecord = 58, &             ! Number of records in data, from user.
        !nft  = 4, &                 !15 Number of features in data, from user.
        !nrecord = 32, &             ! Number of records in data, from user.
        !nft  = 3, &                 !16 Number of features in data, from user.
        !nrecord = 59, &             ! Number of records in data, from user.
        !nft  = 5, &                 !17 Number of features in data, from user.
        !nrecord = 48, &             ! Number of records in data, from user.
        !nft  = 2, &                 !18 Number of features in data, from user.
        !nrecord = 44, &             ! Number of records in data, from user.
        !nft  = 3, &                 !19 Number of features in data, from user.
        !nrecord = 56, &             ! Number of records in data, from user.
        !nft  = 2, &                 !20 Number of features in data, from user.
        !nrecord = 50, &             ! Number of records in data, from user.
        !noutcom =1, &          ! Number of the output column, from user.
        noutcom =nft, &          ! Number of the output column, from user.
        itest = 1, &             ! Choose:
                                 !   1: if you do not use test set,
                                 !   2: if you use one training set and one test set,
                                 !   3: if you use cross-validation.
        ntrain = nrecord, &      ! Number of points in training set. Choose:
                                 !   ntrain = nrecord, if itest = 1.
        nfoldmax = 1, &          ! Number of cross validations. Choose:
                                 !   nfoldmax = 1, if itest = 1 or itest = 2.
        iscale = 1, &            ! Choose:
                                 !   1: if scaling is used,
                                 !   2: if no scaling is used.

        !
        maxdim   = nclust*nft, & ! Maximum number of variables in optimization.
        maxinit  = 10000*maxdim    ! Maximum number of candidate points of data set,
                                 !   maxinit >> maxdim. Mistä tämä oikeasti nykyään riippuu? Pitää ehkä ottaa recordit mukaan


    ! Input real parameters. Give values here.
    ! If parameter value <= 0.0 the default value of the parameter will be used.
    !    REAL(KIND=prec), SAVE :: &   !

    REAL, SAVE :: &
        tlimit    = 70000.0      ! Maximum CPU-time in seconds, from user.



    ! Other Real parameters.
    REAL(KIND=prec), SAVE :: & !
        a(nrecord,nft), &        ! Data matrix, from input file, give the name of the file above.
        a4(nrecord,nft), &       ! Auxiliary data matrix.
        gamma1, &                ! Parameter affecting the size of the set of starting point,
        gamma2, &                ! Parameter affecting the size of the set of starting point,
        gamma3, &                ! Parameter affecting the size of the set of starting point,
        gamma4, &                ! Parameter affecting the size of the set of starting point,
        gam1, &                  ! Multiplier for gamma1
        gam2, &                  ! Multiplier for gamma2
        gam3, &                  ! Multiplier for gamma3
        gam4, &                  ! Multiplier for gamma4
        dminim(nrecord), &       !
        clin(nft), &
        dlin(nft), &
        toler


    ! Other integer parameters.
    INTEGER, SAVE :: & !
            !        mf, &                    ! Number of used features:
                                 !   mf = nft, when no classes,
        nrecord1, &              ! Number of instances used in computions.
        nrecord2, &              ! Number of instances used in computions.
        nupdate, &               ! Number of updates.
        naux2, &                 ! Number of first problem evaluations.
        naux, &                  ! Number of auxiliary function evaluations.
        nfit, &                  ! Number of function evaluations.
        nc, &                    ! Current number of clusters, loops from 1 to nclust
        ns, &                    ! Switch for auxiliary and real clustering problem.
        nlist(nrecord), &        !
        nlisttrain(nrecord), &   !
        nl, &                    !
        m, &                     ! Number of variables in optimization:
                                 !   m = mf    if ns = 1,
                                 !   m = mf*nc if ns = 2.
        !        nk(nclust,nrecord), &    !
        nel1, &                   !
        nob1(nrecord), &
        nob(nclust,nrecord), &
        nel(nclust)
!        ncand, &                 ! Number of canditate points.
!        lcand(nrecord)           !


CONTAINS


    SUBROUTINE init_clrpar()    ! User supplied subroutine for further initialization of parameters (when needed).
                                ! May be left empty.
        IMPLICIT NONE

    END SUBROUTINE init_clrpar

    ! korjattu regressio-ongelmille
    SUBROUTINE def_clrpar()    ! Default values for parameters.

        USE param, ONLY : zero,one  ! Parameters.

        IMPLICIT NONE

        gam1 = one
        gam2 = one
        gam3 = one
        gam4 = one

        IF (nrecord <  200) THEN
            gamma1 = 0.00_prec       ! gamma1 in [0,1], smaller value -> more data points
            gamma2 = 20.0_prec   ! gamma2 in [1, infty) -> smaller value less minimizers are chosen
            gamma3 = 20.0_prec   ! gamma3 in [1, infty) -> smaller value less minimizers are chosen
            gamma4 = 0.10_prec
            !gamma1 = zero       ! 4 gamma1 in [0,1], smaller value -> more data points
            !gamma2 = 20.0_prec   ! gamma2 in [1, infty) -> smaller value less minimizers are chosen
            !gamma3 = 20.0_prec   ! gamma3 in [1, infty) -> smaller value less minimizers are chosen
            !gamma4 = 0.10_prec
            !gamma1 = zero       ! 3 gamma1 in [0,1], smaller value -> more data points
            !gamma2 = 20.0_prec   ! gamma2 in [1, infty) -> smaller value less minimizers are chosen
            !gamma3 = 20.0_prec   ! gamma3 in [1, infty) -> smaller value less minimizers are chosen
            !gamma4 = 0.10_prec
           ! gamma1 = 0.1        ! 5 gamma1 in [0,1], smaller value -> more data points
           ! gamma2 = 10.0_prec   ! gamma2 in [1, infty) -> smaller value less minimizers are chosen
           ! gamma3 = 2.50_prec   ! gamma3 in [1, infty) -> smaller value less minimizers are chosen
           ! gamma4 = 0.30_prec
            !gamma1 = zero        ! 2 gamma1 in [0,1], smaller value -> more data points
            !gamma2 = 2.0_prec   ! gamma2 in [1, infty) -> smaller value less minimizers are chosen
            !gamma3 = 2.0_prec   ! gamma3 in [1, infty) -> smaller value less minimizers are chosen
            !gamma4 = 0.5_prec
            !gamma1 = zero        ! 1 gamma1 in [0,1], smaller value -> more data points
            !gamma2 = 20.0_prec   ! gamma2 in [1, infty) -> smaller value less minimizers are chosen
            !gamma3 = 20.0_prec   ! gamma3 in [1, infty) -> smaller value less minimizers are chosen
            !gamma4 = 0.2_prec

        ELSE IF (nrecord < 1000) THEN !
            gamma1 = 0.50_prec
            gamma2 = 2.5_prec
            gamma3 = 2.25_prec
            gamma4 = 0.50_prec

        ELSE IF (nrecord < 4000) THEN
            gamma1=0.6_prec ! 1 2 3 tehtävälle
            gamma2=2.50_prec
            gamma3=1.250_prec
            gamma4=1.0_prec

        ELSE IF (nrecord < 15000) THEN ! 4,5
            gamma1=0.95_prec !tämä 4 ja 5 tehtävälle
            gamma2=2.0_prec
            gamma3=1.150_prec
            gamma4=1.0_prec

        ELSE IF (nrecord < 50000) THEN ! nämä 6 tehtävässä
            gamma1=0.9750_prec ! 64
            gamma2=2.0_prec    !
            gamma3=1.050_prec  !
            gamma4=1.0_prec    !
            !gamma3=1.010_prec  ! news2. Tulokset samoja kuin tuolla ylempänä, joten nekin parametrit käy
                                ! vain tol2 modifiointi ei toleria kummassakaan yllä tosin 6 kai ei vaikuta

            !gamma1=0.980_prec ! nämä nykyisessä 6 tehtävässä output=last
            !gamma2=10.0_prec
            !gamma3=1.050_prec ! tämä 64
            !gamma4=1.0_prec
            !gamma1=0.9750_prec ! Adilin parametrit
            !gamma2=1.05_prec
            !gamma3=1.0250_prec
            !gamma3=1.020_prec ! testaa vielä tämä paremmalla lopetuksella
            !gamma3=1.05_prec !
            !gamma4=1.0_prec
            !gamma1=0.96_prec !
            !gamma2=2.0_prec
            !gamma3=1.10_prec
            !gamma4=1.0_prec
            !gamma1=0.9950_prec ! nämä oli 2
            !gamma2=1.025_prec
            !gamma3=1.010_prec
            !gamma4=1.0_prec


        ELSE ! nämä blog2
            !gamma1=0.995_prec
            !gamma2=1.025_prec
            !gamma3=1.01_prec
            !gamma4=1.0_prec
            !gamma1=0.997_prec !3
            !gamma2=1.02_prec
            !gamma3=1.01_prec
            !gamma4=1.0_prec
            !gamma1=0.999_prec !5 pistä tämä vielä viikonloppuna muutoin 3 paras
            !gamma2=1.005_prec
            !gamma3=1.01_prec
            !gamma3=1.005_prec !6
            !gamma4=1.0_prec
            !gamma1=0.995_prec !7 pistä tämä vielä viikonloppuna muutoin 3 paras
            !gamma2=1.01_prec
            !gamma3=1.01_prec
            !gamma4=1.0_prec
            gamma1=0.99_prec !8 pistä tämä vielä viikonloppuna muutoin 3 paras
            gamma2=1.01_prec ! katso tänne parhaat muihin
            gamma3=1.01_prec
            gamma4=1.0_prec
            !gamma1=0.997_prec !9 pistä tämä vielä viikonloppuna muutoin 3 paras
            !gamma2=1.01_prec ! katso tänne parhaat muihin
            !gamma3=1.01_prec
            !gamma4=1.0_prec
            !gamma1=0.998_prec !10 pistä tämä vielä viikonloppuna muutoin 3 paras
            !gamma2=1.015_prec ! katso tänne parhaat muihin
            !gamma3=1.015_prec
            !gamma4=1.0_prec
            !gamma1=0.999_prec !11 pistä tämä vielä viikonloppuna muutoin 3 paras
            !gamma2=1.001_prec ! katso tänne parhaat muihin
            !gamma3=1.025_prec
            !gamma4=1.0_prec
            !gamma1=0.999_prec !12 pistä tämä vielä viikonloppuna muutoin 3 paras
            !gamma2=1.001_prec ! katso tänne parhaat muihin
            !gamma3=1.05_prec
            !gamma4=1.0_prec
            !gamma1=0.995_prec !13 pistä tämä vielä viikonloppuna muutoin 3 paras
            !gamma2=1.001_prec ! katso tänne parhaat muihin
            !gamma3=1.05_prec
            !gamma4=1.0_prec

            !DGM:llä huomattavasti vähemmän ns=3 ja ns=1 kutsuja katso mitä voit tehdä

        END IF

        RETURN

    END SUBROUTINE def_clrpar

END MODULE initclr


MODULE initlmbm  ! Initialization of parameters for LMBM.

    USE r_precision, ONLY : prec   ! Precision for reals.
    USE param, ONLY : zero, one    ! Parameters.
    USE initclr, ONLY : maxdim   ! Maximum dimension of x.

    IMPLICIT NONE

    ! Parameters
    INTEGER, PARAMETER :: &
        na      = 2, &             ! Maximum bundle dimension, na >= 2.
        mcu     = 15, &             ! Maximum number of stored corrections, mcu >=1.
        mcinit  = 7, &             ! Initial maximum number of stored corrections, mcu >= mcinit >= 3.
                                   ! If mcinit <= 0, the default value mcinit = 3 will be used.
                                   ! However, the value mcinit = 7 is recommented.
        inma    = 3, &             ! Selection of line search method:
                                   !   inma = 0, Armijo line search,
                                   !   inma = 1, nonmonotone Armijo line search.
                                   !   inma = 2, weak Wolfe line search.
                                   !   inma = 3, nonmonotone  weak Wolfe line search.
        !mnma    = 10, &            ! Maximum number of function values used in nonmonotone line search.
        mnma    = 10, &            ! Maximum number of function values used in nonmonotone line search.
        maxnin  = 20               ! Maximum number of interpolations, maxnin >= 0.
        !maxnin  = 20               ! Maximum number of interpolations, maxnin >= 0.
                                   ! The value maxnin = 2-20 is recommented with inma=0,
                                   ! maxnin >= 20 with inma=1 and 3, and maxnin =200 with inma=2.
                                   ! For example:
                                   !   inma = 0, maxin = 20.
                                   !   inma = 1, mnma = 20, maxin = 30.
                                   !   inma = 2, maxnin = 200.
                                   !   inma = 3, mnma=10, maxnin = 20.


    ! Real parameters (if parameter value <= 0.0 the default value of the parameter will be used).
    REAL(KIND=prec), SAVE :: &
        tolb    = zero, &         ! Tolerance for the function value (default = -large).
        tolf    = zero, &         ! Tolerance for change of function values (default = 1.0E-8).
        tolf2   = -1.0_prec, &    ! Second tolerance for change of function values.
                                  !   - If tolf2 < 0 the the parameter and the corresponding termination
                                  !   criterion will be ignored (recommended with inma=1,3).
                                  !   - If tolf2 = 0 the default value 1.0E+4 will be used.
        tolg    = 1.0E-5_prec, &  ! Tolerance for the termination criterion (default = 1.0E-5).
        tolg2   = 1.0E-3_prec, &  ! Tolerance for the second termination criterion (default = 1.0E-3).
        eta     = 1.0E-3_prec, &  ! Distance measure parameter, eta > 0.
                                  !   - If eta < 0  the default value 0.0001 will be used.
        epsl    = 0.22E+00, &     ! Line search parameter, 0 < epsl < 0.25 (default = 0.24).
                                  ! use small value with inma=2 and larger value with inma=3
        xmax    = 1000.0_prec     ! Maximum stepsize, 1 < XMAX (default = 1000).

    ! Integer parameters (if value <= 0 the default value of the parameter will be used).
    INTEGER, SAVE :: &
        n       = maxdim,  &      ! Number of variables.
        mit     = 5000, &         ! Maximun number of iterations.
        mfe     = 5000, &         ! Maximun number of function evaluations.
        mtesf   = 20, &           ! Maximum number of iterations with changes of
                                  ! function values smaller than tolf (default = 20).
        iprint  = 0, &            ! Printout specification:
                                  !    -1  - No printout.
                                  !     0  - Only the error messages.
                                  !     1  - The final values of the objective function
                                  !          (default used if iprint < -1).
                                  !     2  - The final values of the objective function and the
                                  !          most serious warning messages.
                                  !     3  - The whole final solution.
                                  !     4  - At each iteration values of the objective function.
                                  !     5  - At each iteration the whole solution
        iscale  = 0               ! Selection of the scaling with LMBM:
                                  !     0  - Scaling at every iteration with STU/UTU (default).
                                  !     1  - Scaling at every iteration with STS/STU.
                                  !     2  - Interval scaling with STU/UTU.
                                  !     3  - Interval scaling with STS/STU.
                                  !     4  - Preliminary scaling with STU/UTU.
                                  !     5  - Preliminary scaling with STS/STU.
                                  !     6  - No scaling.


    REAL(KIND=prec), DIMENSION(maxdim), SAVE :: x  ! Vector of variables


CONTAINS

    SUBROUTINE defaults()  ! Default values for parameters.

        USE param, ONLY: small, large, zero, one, half
        IMPLICIT NONE

        IF (iprint < -1) iprint  = 1               ! Printout specification.
        IF (mit   <= 0) mit      = 5000            ! Maximum number of iterations.
        IF (mfe   <= 0) mfe      = n*mit           ! Maximum number of function evaluations.
        IF (tolf  <= zero) tolf  = 1.0E-08_prec    ! Tolerance for change of function values.
        IF (tolf2 == zero) tolf2 = 1.0E+04_prec    ! Second tolerance for change of function values.
        IF (tolb  == zero) tolb  = -large + small  ! Tolerance for the function value.
        IF (tolg  <= zero) tolg  = 1.0E-05_prec    ! Tolerance for the termination criterion.
        IF (tolg2  <= zero) tolg  = 1.0E-03_prec   ! Tolerance for the second termination criterion.
        IF (xmax  <= zero) xmax  = 1000.0_prec     ! Maximum stepsize.
        IF (eta   <  zero) eta   = 1.0E-03_prec    ! Distance measure parameter
        IF (epsl  <= zero) epsl  = 0.22_prec       ! Line search parameter,
        IF (mtesf <= 0) mtesf    = 20              ! Maximum number of iterations with changes
                                                   ! of function values smaller than tolf.
        IF (iscale > 6 .OR. iscale < 0) iscale = 0 ! Selection of the scaling.


    END SUBROUTINE defaults

    SUBROUTINE init_lmbmpar()  ! User supplied subroutine for further initialization of parameters
                               ! (when needed) for LMBM. May be left empty.

        USE initclr, ONLY : ns,nc,nrecord
        IMPLICIT NONE

        ! For big data sets use larger values
        IF (nrecord < 500) THEN ! small data sets

            IF (ns == 3) THEN !
                mit=5000
                tolg2= 1.0E-12
                tolg=1.0E-7
            ELSE IF (ns == 1) THEN
                mit=5000
                tolg2= 1.0E-12
                tolg = 1.0E-5
            ELSE
                mit=5000
                tolg2 = 1.0E-8
                tolg = 1.0E-5
            END IF

        ELSE IF (nrecord < 4000) THEN ! medium data sets
            IF (ns == 3) THEN !
                mit=5000
                tolg2= 1.0E-12
                tolg=1.0E-7
            ELSE IF (ns == 1) THEN
                mit=5000
                tolg2 = 1.0E-6
                tolg = 1.0E-5 !
            ELSE
                mit=5000
                tolg2 = 1.0E-6
                tolg = 1.0E-5 !
            END IF

        ELSE IF (nrecord < 50000) THEN ! large datasets oikeasti täällä 50000
           IF (ns == 3) THEN !
                mit=5000
                tolg2= 1.0E-12 !32
                tolg=1.0E-7
            ELSE IF (ns == 1) THEN
                mit=5000
                tolg2 = 1.0E-5 !64
                tolg = 1.0E-6 !
            ELSE
                mit=5000
                tolg2 = 1.0E+1
                tolg = 1.0E-5 !
            END IF

        ELSE ! very large datasets
           IF (ns == 3) THEN !
                mit=5000
                tolg2= 1.0E-8 !32
                tolg=1.0E-7
            ELSE IF (ns == 1) THEN
                mit=5000
                tolg2 = 1.0E-3 !32
                tolg = 1.0E-6 !
            ELSE
                mit=5000
                tolg2 = 1.0E+2
                tolg = 1.0E-4 !
            END IF

        END IF


    END SUBROUTINE init_lmbmpar

END MODULE initlmbm



