/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CONVTEST -- tests for convergence of non-linear routines.

            call as:

            converge=convtest(relb,relgrad,btol,gradtol);

            INPUTS
              relb -- relative change in the parameters; see RELVALS.
           relgrad -- relative gradient; see RELVALS.
              btol -- convergence tolerance for RELB.
           gradtol -- convergence tolerance for RELGRAD.
            OUTPUT
          converge -- if 1, convergence tests satisfied; otherwise 0.
NOTE: The code is clear and self-explanatory as to the nature of the test.
............................................................................*/
proc 1=convtest(relb,relgrad,btol,gradtol);
local converge;
             converge=0;
             if abs(relb) < btol;   @ Test this on every iteration. @
                if abs(relgrad) < gradtol;  @ Then test this.       @
                       converge=1;          @ CONVERGENCE!          @
                endif;
             endif;

retp(converge);
endp;
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
OPENFILE -- proc to open data file and return the file handle.

       f1=openfile(dataset,useivs);

       INPUTS
       dataset -- name of dataset; if null ("" or 0) will prompt for name.
        useivs -- if 1, will OPEN VARINDXI; if 0, then will not.
       OUTPUT
           f1 -- the file handle of the opened file.
............................................................................*/
proc openfile(dataset,useivs);
local kd, vn, f1;
  retryml:                        @ open file using name in variable DATASET @
  if useivs;  open f1=^dataset varindxi;
   else;      open f1=^dataset;
  endif;
 if f1==-1; format 8,8;
   print "Can't find data file: " dataset;
   print "Enter new name of data file or <enter> to quit: ";; dataset=cons;?;
   if dataset $/= ""; goto retryml; else; end; endif;
 endif;
call varput(dataset,"dataset");
retp(f1);
endp;
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SETFLAGS -- will convert a name into a number which equals its position in
            a character vector.  This is really just INDCV with an error
            message printed if the name does not exist in the vector.
............................................................................*/
proc setflags(flagname,optns);
local aflag;
   flagname=upper(flagname);
   optns=upper(optns);
   aflag=indcv(flagname,optns);
   if ismiss(aflag);
"ERROR: The option specified for the algorithm to be used does not exist.
The option must be" optns; end;
   endif;
retp(aflag);
endp;

.
