
|
 |
 |
|
 |

IMSL Products: CNL Tips
1. CNL - Calling C libraries from FORTRAN
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version: All
PROBLEM DESCRIPTION
A user wants to call the C Numerical Libraries from FORTRAN.
SOLUTION
There is no easy way to do this and there are many reasons for NOT trying it.
1) It is very difficult to do. It is much easier to call FORTRAN from C.
2) If the user has access to the FORTRAN libraries, they provide more
coverage than the C libraries. 3) Because of the
complexity of the problems that can arise from trying to call C routines from
FORTRAN, there are no technical documents available. If the user insists on
trying, he must pass every C argument by reference.
2. CNL - Random number from a general discrete distribution
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version: All
PROBLEM DESCRIPTION
There is no comparable routine in the C libraries that will perform what
RNGDA does (random numbers from a general discrete distribution).
SOLUTION
The user can, however, obtain a random number from a general discrete
distribution by using the values that you are passing through the parameters
NMASS and PROBS. You have to assign intervals of probability where the first
interval is 0 to PROBS(1), the second interval is PROBS(1) to
PROBS(1)+PROBS(2), the third interval is PROBS(1)+PROBS(2) to
PROBS(2)+PROBS(3), and so on up to PROBS(n-1)+PROBS(n). Then just generate a
uniform random number using the C routine random_uniform and select the
interval that it falls in. Return the index of the interval it falls into.
This will provide the random discrete deviates
3. CNL - how to represent the FORTRAN "complex" variable type in C.
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: FNL, CNL
Architecture/OS version: All
PROBLEM DESCRIPTION
Complex, and double complex data types are not defined in C, but they are
defined in FORTRAN.
SOLUTION
Complex, and double complex data types are not defined in C.
However, they are frequently used in the IMSL Libraries. To get around this
problem, an equivalent structure can easily be defined as follows :
/* type definition of ( single ) complex data type */
typedef struct
{float r, i;} complex;
/* type definition of ( double ) complex data type */
typedef struct
{double r, i;} double_complex;
4. CNL - normality_test (Shapiro_Wilk W test) is limited to 2000 samples
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version: All
PROBLEM DESCRIPTION
In the routine normality_test, the Shapiro_Wilk W test is limited to 2000
samples.
SOLUTION
The code is from 1982. A newer algorithm exists that might take care of this
limitation, but has not yet been implemented. See Royston (1992), Journal of
Statistical Computations and Simulations, #2, pg 117 and #42 pg 79.
Alternatively, use the Lilliefors Test. It is not as powerful as the
Shapiro-Wilk W Test, but there is no limit on the number of input samples.
5. CNL - Creating a man page for compiling and linking instructions
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: F90/CNL
Architecture/OS version: unix
PROBLEM DESCRIPTION
Is there any online documentation containing the compilation and linking
instructions for F90 and CNL?
SOLUTION
This is not contained in the online documentation supplied with PDF files
since this is usually platform dependent. It is supplied in the README files.
It is possible to add the README files to the man pages under Unix using the
following instructions:
Here is a method for creating a man page from our README file:
The man pages are usually located in either /usr/share/man or /usr/man or you
may have defined a separate directory for customized man pages on your
system. It depends on how your system is set up and may depend on the
environment variable MANPATH.
Let's say for example that you want to create a man page called imslfnl for
help on how to compile and link to the FORTRAN libraries. The easiest way to
do this is to copy the README file into /usr/share/man/man1:
cp $CTT_DIR/notes/f90/README /usr/share/man/man1/imslf90
Likewise, if you want to create a man page from the CNL README file, called
imslcnl:
cp $CTT_DIR/notes/cnl/README /usr/share/man/man1/imslcnl
Then to use it you would enter either "man imslf90" or "man imslcnl".
Obviously you can call it whatever you want. If you have a separate directory
on your system for customized man pages, you would probably want to copy into
that directory instead of /usr/share/man. You can consult a Unix manual or
"man man" for additional information on this.
6. CNL - VC++ examples not working with single precision
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version: Windows 95/NT
PROBLEM DESCRIPTION
The CNL example programs are not giving the correct results under Visual C ++,
Windows NT or 95, with single precision.
SOLUTION
The compiler switch -DANSI is required. Check to be certain that this
switch is on.
7. CNL - Unresolved dependencies, rename.h
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version: All
PROBLEM DESCRIPTION
Getting 2 unresolved dependencies, rename.h and renames.h
SOLUTION
These are references to include files for PV-WAVE advantage. If the user is
complaining about this, all they need to do is create a blank dummy include
file, rename.h.
8. CNL - Results from regression differ between Win NT and HP
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version: Windows NT
PROBLEM DESCRIPTION
The results of certain data run through the imsls_d_regression function
differ between Win NT and HP. Specifically, with the test data, the Win NT
platform gave a RANK_DEFICIENT error message whereas the same data run on the
HP gave a solution.
SOLUTION
Try regression_stepwise as a possible workaround.
9. CNL - Computing Null space of a matrix using the SVD routine.
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version: All
PROBLEM DESCRIPTION
User wants to compute the 'base of the null space' as done in Numerical
recipes.
SOLUTION
the value is equal to (n-rank).
10. CNL - documentation of nonlin_least_squares optional arguments
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 4.0
Architecture/OS version: Any
PROBLEM DESCRIPTION
The documentation of nonlin_least_squares optional arguments XSCALE,
GRAD_TOL, and STEP_TOL needs enhancement.
SOLUTION
The XSCALE argument can affect the stepsize. The documentation should
state that the expressions shown under GRAD_TOL and STEP_TOL must be
greater than these tolerances.
11. CNL - debug assertion failure on free
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0 (and earlier versions)
Architecture/OS version: Windows / Microsoft Visual C++
PROBLEM DESCRIPTION
The error message "debug assertion failure" occurs when trying to delete or
free memory allocated within one of our C functions, such as with
Imsls_d_regression for IMSLS_REGRESSION_INFO, using CNL on Windows with
Microsoft VC++.
SOLUTION
There are two possible solutions to this problem.
1. Use compiler switch /MD
Since these functions are using malloc to allocate space, free should be used
to deallocate the space. This error can occur when linking with the CNL dll
library, cmath.lib or cstat.lib, and a run-time library other than
Multithreaded DLL, or /MD, is used in the compiler settings. Memory
allocation must be freed by the same run-time library that performed the
allocation. CNL was built with the Multithreaded DLL run-time library,
so this library must also be used to free space allocated within CNL.
If using the visual studio, set this under Project / Settings. Select the
C/C++ tab. Select Category "Code Generation". Under "use run-time library",
select "Multithreaded DLL".
If compiling from the DOS prompt, use the environment variable LINK_CNL:
cl program.c %link_cnl%
2. Build an intermediate dll
When linking to the Debug Multithreaded DLL version of the Microsoft Visual C
runtime libraries, the user must use the DLL version of CNL in order for it to
compile and link properly. However, when the user does, they will get Debug
Assertion errors when trying to use free( ) on memory that has been allocated
using malloc( ) for use in CNL functions. The CNL DLL is linked against the
release Microsoft C runtime DLL. The program subsequently fails when it calls
free( ), because the debug version of free( ) is what gets linked in when
linking against the debug version of the C run time libs.
As a workaround, the user can build a separate DLL that links to the release
version of the C runtime. The user should call it something like FREE_CNL.DLL
for example. Inside that new DLL, only one function is needed that accepts a
pointer as its only argument. This new DLL is linked into the executable at
compile and link time along with any other libraries, including the CNL DLL.
The function would be similar to this:
void free_CNL_release(void* p)
{
free(p);
}
But since it will be linked to the release version of the runtimes, it will
call the release version of free, which is the same version as the one we call.
This will get around the issue of calling the incorrect version of free( ) in
his own code (which is the one in the debug version of the C run time). Avoid
using IMSL_free( ) or CNL_free( ) for the function name, as they might be names
that we choose if we decide to implement this functionality in a future version
of CNL.
12. CNL - VC++ / linking to MFC application / unresolved external __imp__xxx
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version: Windows
PROBLEM DESCRIPTION
When linking an MFC application with the CNL static libraries under Visual
C++ 6.0, you get an unresolved external symbol on __imp__function.
SOLUTION
This error message is documented in the VC++ help under LNK2001. It says:
When compiling with the /MD option, a reference to "func" in your source
becomes a reference "__imp__func" in the object since all the run-time is now
held within a DLL. If you try to link with the static libraries LIBC.LIB or
LIBCMT.LIB, you will get an unresolved external on __imp__func. If you try to
link with MSVCxx.LIB when compiling without the /MD option you will not
always get an unresolved external, but you will likely have other problems.
Solution: Check the project settings. If the General tab, Microsoft Foundation
Classes is set to "Use MFC in a Shared DLL", try changing it to "Use MFC in a
Static Library". Otherwise, link with the dynamic (dll) libraries.
13. CNL - passing C++ class member to C function
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version: Windows 95 or NT, Visual C++
PROBLEM DESCRIPTION
Is there any way to pass a C++ class member function to a C function,
such as zeros_fcn?
SOLUTION
This can be done by creating a "wrapper" c function which calls the
member function and then passing that to the CNL function.
For example:
#include
float fcn(float x);
class ftest
{
public:
float func(float x);
};
float ftest::func(float x)
{
float result;
result = x * x * x - 3.0 * x * x + 3.0 * x - 1.0;
return result;
}
ftest fobj;
main()
{
float *x;
/* Solve fcn(x)=0 for x */
x = imsl_f_zeros_fcn (fcn, 0);
/* Print x */
imsl_f_write_matrix ("x", 1, 1, x, 0);
}
float fcn(float x)
{
return fobj.func(x);
}
14. CNL 4.0 / F90 4.01 - Bessel bugs: bessel_Jx and CBJS/DCBJS
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: F90 4.01
CNL 4.0
Architecture/OS version: all
PROBLEM DESCRIPTION
The CNL routine bessel_Jx and the FNL routine CBJS/DCBJS give
incorrect results for complex numbers with modulus > 25.
A change request has been submitted.
SOLUTION
The CNL routine bessel_Jx produces incorrect results for
complex numbers (z=x+yi) where |z| = sqrt(x*x + y*y) > 25.
Note: |z| = modulus of z, where z is a complex number.
There in no workaround in CNL for this error.
The F90 routine DCBJS exhibits the same error described above.
DCBJNS appears to produce correct results and can be
used as a workaround when Bessel functions of integer
order are sufficient.
This code shows the error in DCBJS and shows how to use
DCBJNS as a workaround for Bessel functions of order 0.
This example uses complex numbers with imaginary part
equal to zero to clearly illustrate the bug in DCBJS.
double precision xnu,x
double precision real_1,imag_1,real_2,imag_2
double complex output1,output2,z
integer n
xnu=0.0d0
n=1
write(*,3)
write(*,2)"|z| dcbjs output dcbjns output "
write(*,2)" real imag real imag"
do x=24d0,26d0,0.5d0
z=dcmplx(x,0.0d0)
call dcbjs(xnu,z,n,output1)
real_1=dreal(output1)
imag_1=dimag(output1)
call dcbjns(z,n,output2)
real_2=dreal(output2)
imag_2=dimag(output2)
write(*,1)cdabs(z),real_1,imag_1,real_2,imag_2
enddo
write(*,3)
1 format(5x,f6.1,4(f12.6))
2 format(6x,a51)
3 format(//)
stop
end
Output:
|z| dcbjs output dcbjns output
real imag real imag
24.0 -.056230 .000000 -.056230 .000000
24.5 .023697 .000000 .023697 .000000
25.0 .096267 .000000 .096267 .000000
25.5 .000000 .064860 .144062 .000000
26.0 .000000 -.012045 .155999 .000000
Note: The output shown above from DCBJS is wrong when |z| > 25.
The output from DCBJNS is correct.
A change rquest has been filed.
15. CNL 3.0 - imsl_f_lin_sol_gen_min_residual example not working
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0
Architecture/OS version: all
PROBLEM DESCRIPTION
Example 1 routine from CNL routine, imsl_f_lin_sol_gen_min_residual,
is returning error messages that state that there is an error with
argument number 7 and argument number 8.
SOLUTION
The error is not being generated correctly. It really is a
documentation problem with the matrix multiplication routine in the
user function. There is a 1 parameter missing. It should be:
imsl_f_mat_mul_rect_coordinate ("A*x",
IMSL_A_MATRIX, n, n, nz, a,
IMSL_X_VECTOR, n, p,
IMSL_RETURN_USER_VECTOR, z,
0);
An extra "n" has been added as the fourth coordinate.
This has been corrected in CNL 4.0 documentation.
16. CNL - How to call CNL from Visual Basic
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 2.0
Architecture/OS version: Windows NT/95
PROBLEM DESCRIPTION
Errors occur when trying to call CNL from Visual Basic 5.0,
especially "Bad DLL calling convention".
SOLUTION
An intermediate library must be used to accept the calls from
Visual Basic 5.0 and to make the proper calls to the CNL libraries.
The problem is the data types between VB5 and CNL (and most other C
libraries) are incompatible. The solution is to build an intermediate
C library that can be called from VB5. The intermediate library moves
the data into "safe" arrays that can be safely passed to CNL routines.
The same is true when the data is passed back. A ZIP file, VB5_IMSL.ZIP,
contains both an example VB5 program and an intermediate C library to
translate the calls to CNL. Source code for both is also included.
The user should unzip the file the files into the same path, D:\VB5_IMSL,
that was used during the compilation. Otherwise, hard-coded values will
have to be changed. Contact Technical Support to obtain a copy of this file.
The Visual Basic compiler is not a supported platform, but we can provide
tips for doing this. The ZIP file contains a full working example of
how to call CNL 2.0 from Visual Basic 5.0. Make sure you have added the
MSFLEXGRID to your project. Basically, you have to write an intermediate
DLL in C that translates the call from Visual Basic to our CNL library.
It also accepts the results and sends them back to the Visual Basic
calling program. To use the program, just run it in the VB5 environment,
click on "Upload data" to load the raw data and click "Perform Regression"
to make the call the CNL routine and get the results. The ZIP file
contains the Visual Basic source code and the C source code for the
intermediate DLL that is written in C. There is also a small
readme.txt file that you should read.
This is a very simple example that loads a small data set from a
text file into a grid, performs a linear regression and then dumps
the results into 2 other grids. This program shows how to set up
the intermediate DLL.
There are two points to be aware of concerning this program.
There is very little if any error checking. We know what the results
should be and we know the data is good. Error checking is not
the point of this example program. Also, we have not passed any
optional arguments to the intermediate IMSL.DLL. You will need to
figure out some mechanism for passing optional arguments from VB5
to the intermediate DLL and then onto CNL.
17. CNL 3.0 - Bug in IMSLS_X_INDICES option in regression routine
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0
Architecture/OS version:
PROBLEM DESCRIPTION
Example 3 in the regression documentation illustrates the problem.
The example code compiles but the executable produces a segmentation fault.
SOLUTION
The code will work if it is rewritten without using the IMSLS_X_INDICES option.
Fixed in CNL 4.0.
18. CNL - Write CNL output to MFC MessageBox
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version: Windows NT/95 and Visual C++
PROBLEM DESCRIPTION
This sample program writes CNL output to a MessageBox.
The example also shows how to create a more general MessageBox.
SOLUTION
Create a console application with MSDEV. Include cmath.lib.
Use default compiler switches.
#include
#include
#include
void main(void)
{
char *message_text;
char *caption_text;
int a[]={1,2,3,4,5}; /* sample data*/
char *b; /* pointer to output from write_matrix */
imsl_i_write_matrix("Sample Data\n",1,5,(int *)a,
IMSL_RETURN_STRING,&b,
IMSL_NO_COL_LABELS,
0);
printf("\n\n%s\n\n",b);
caption_text="IMSL Data";
MessageBox(NULL,b,caption_text,MB_OK);
caption_text="Message Caption";
message_text="This is an OK message.";
MessageBox(NULL,message_text,caption_text,MB_OK);
/* Other MessageBox types include: MB_ICONSTOP, MB_ICONINFORMATION */
}
19. CNL 4.0 - MSVC++ DLLs and LIB files needed
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 4.0
Architecture/OS version: Windows NT / 95
PROBLEM DESCRIPTION
What MSVC++ DLLs and LIB files are needed for the CNL library?
SOLUTION
Customer should look in our Makefile in the examples directory.
It refers to NTWIN32.MAK which may in turn refer to WIN32.MAK.
Inside WIN32.MAK near the bottom are the 6 base MS libs that are
needed by our product.
20. CNL - use of active parameter in min_con_nonlin
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version: all
PROBLEM DESCRIPTION
How is the active parameter in the user supplied function of
min_con_nonlin used?
SOLUTION
The active parameter of the user supplied function, fcn, is
used to determine which constraints the function needs to have
evaluated each time it is called. The function may not need to
have all constraints evaluated for each call, so using this
parameter could save computation time in some cases. When
active[n] is true or equal to 1, function fcn needs to have
constraint n evaluated.
Active[0] to active[meq] show whether or not the equality
constraints need to be evaluated, and active[meq+1] to active[m]
show whether or not the inequality constraints need to be evaluated.
Also, see example 1 for an example of how this parameter is used
inside the function.
21. CNL - Nonlin_least_squares routine with weighting
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL
Architecture/OS version:
PROBLEM DESCRIPTION
Is there a nonlin_least_squares routine that has weighting?
SOLUTION
Following is a method which can be used to implement weights using
the nonlin_least_squares routine.
The technique is to multiply the evaluating function by a vector of weights.
For example, if you look at example number 1 in the documentation, in the
user-supplied function fcn, you will see the evaluating function, fcn:
f[i] = exp ( x[0] * t[i] ) - y[i]. Create a weight vector (you can use w[] for
example) of m size. Then in the user-supplied function, fcn, change the
evaluating function to: f[i] = ( exp ( x[0] * t[i] ) - y[i] ) * w[i].
If you set each value in the weight vector to 1.0 then obviously the weights
will have no effect.
The greater you make a weight, then the greater the difference will be between
that point and the evaluating curve. This will cause the routine to work to
minimize that error more so than the others.
22. CNL - path environment variable not setting up correctly
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 2.0 or 2.5
Architecture/OS version: PC / Windows 98
PROBLEM DESCRIPTION
Noticed when doing testing on Windows 98:
compilers - Microsoft Visual C++ 5.0 or Digital Visual Fortran 5.0
When the batch file (to set the environment variables) of either of the two
above compilers is run before CNLENV.BAT, an error message
-Too many parameters -
results. At this point the IMSL environment variables INCLUDE and LIB are
set correctly, however PATH is not. The correct directory path is NOT
added to the PATH variable.
When the CNLENV.BAT file is executed before the compiler's .BAT files, all
three environment variables are set correctly. The problem only occurs if
the compiler's .BAT is executed first.
The problem occurs when the bat files are executed either manually or if they
are called in the AUTOEXEC.BAT file to be executed at setup.
SOLUTION
There are two possible workarounds to this problem:
1. Always execute CNLENV.BAT before executing the compiler's .BAT files.
If the .BAT files are entered into the AUTOEXEC.BAT file, make sure to
CALL CNLENV.BAT first.
2. Edit the CNLENV.BAT. Change the SET PATH statement to read the following:
SET PATH="%IMSLNT_CNL%\BIN";"%PATH%"
Notice the addition of the " (double quotes) surrounding the entire statement
before and after the ; (semicolon).
When using this solution, the directory to the PATH environment variable will
be set correctly no matter which .BAT file is executed first.
23. CNL 2.5 - quadratic_prog constraints
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 2.5
Architecture/OS version: all
PROBLEM DESCRIPTION
Function quadratic_prog is inconsistent in determining whether the
constraints passed to it are valid.
SOLUTION
An assumption is made by both quadratic_prog and its Fortran equivalent, QPROG,
that the constraints passed to it are valid. There is no code in this routine
that specifically checks for the validity of the constraints. Quadratic_prog
should not be used for determining the validity of the constraints.
A change request has been filed to clarify this point in the documentation.
24. CNL 2.5 - random_normal returns terminal error
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 2.5
Architecture/OS version:
PROBLEM DESCRIPTION
Function imsl_f_random_normal is returning the following terminal error:
TERMINAL Error from imsls_f_random_normal. The argument to the function
*** must be greater than 0.0 and less than 1.0. "p" =1.000000e+000.
SOLUTION
The error message is actually coming from normal_inverse_cdf, which is
called by random_normal. The error occurs when the input value to
normal_inverse_cdf is 1.0 or very close to 1.0. The input values
to normal_inverse_cdf are in turn being computed by random_uniform,
and it is possible for this routine to return a value of 1.0. This
is documented in the description of random_uniform.
Use imsl_d_random_normal as a workaround. A change request has been filed.
25. CNL 2.5 - error messages when compiling documentation examples in VC++
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 2.5
Architecture/OS version: PC / Windows 95 or NT
PROBLEM DESCRIPTION
When using some example problems from the documentation, the following
error message occurs in Visual C++ Developer Studio:
+++ TERMINAL Error from imsls_(routine name). Illegal optional argument.
+++ 1071644672 on argument number 3.
The argument number is always the ", 0" at the end of the argument list.
Some other error messages occured, however the above error message is
the most frequent.
This occurs when the user tries to compile and link WITHOUT using the
-DANSI compiler option. The -DANSI compiler option must be used to
obtain the correct output.
SOLUTION
The -DANSI compiler option must be used to obtain the correct output.
Follow these steps to include this option within the Developer Studio environment:
1. Open the Project Setting dialog box by selecting "Settings..." from
the Build pull-down menu.
2. Click on the "C/C++" tab.
3. In the Project Options box, add /DANSI to the end of the list.
4. Click "OK"
26. CNL 2.5 - passing zero constraints to min_con_gen_lin
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 2.5
Architecture/OS version:
PROBLEM DESCRIPTION
The following error message is returned from min_con_gen_lin
when ncon, number of contraints, is zero.
TERMINAL Error from imsl_f_min_con_gen_lin. The number of rows must be
greater than zero. "nra" = 0
SOLUTION
There is a check for ncon greater than zero within min_con_gen_lin
and this message is output if ncon=0. If there are no contraints
other than simple bounds, generate one dummy constraint from the
simple bound as a workaround to this restriction. A change request has
been filed to have the reason for this restriction evaluated and possibly
remove it in a future release.
27. CNL 2.5 - random_binomial produces incorrect results when n*p > 10
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 2.5
Architecture/OS version: all
PROBLEM DESCRIPTION
Random_binomial produces incorrect results when n*p > 10. The following
example demonstrates the problem:
#include
#include
void main()
{
int n_random = 100;
int n = 200;
float p = 0.5;
int *ir;
imsls_random_seed_set(123457);
ir = imsls_f_random_binomial(n_random, n, p, 0);
imsls_i_write_matrix("Binomial (20, 0.5) random deviates:",
1, n_random, ir, IMSLS_NO_COL_LABELS, 0);
}
The routine only produces random numbers related to the first half of
the bell curve. It produces numbers up to the median (n*p) and not
over the median. In this case it produces numbers related to the
first half of the bell curve which are 87 to 100 with 100 being the
median. This routine should produce random numbers for both halves
of the bell curve which would include numbers over the median (100).
The following Fortran example, using RNBIN, produces the correct results:
INTEGER NR
PARAMETER (NR=100)
C
INTEGER IR(NR), ISEED, N, NOUT
REAL P
EXTERNAL RNBIN, RNSET, UMACH
C
CALL UMACH (2, NOUT)
N = 200
P = 0.5
ISEED = 123457
CALL RNSET (ISEED)
CALL RNBIN (NR, N, P, IR)
WRITE (NOUT,99999) IR
99999 FORMAT (' Binomial (20, 0.5) random deviates: ', 5I4)
END
SOLUTION
A change request has been filed.
28. CNL - Data Fitting using Legendre Polynomials
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0
Architecture/OS version: n/a
PROBLEM DESCRIPTION
Write a data fitting routine using Legendre Polynomials to evauate the fit.
SOLUTION
This is an example of Fitting Data using Legendre Polynomials.
Everywhere (5 places) that it says USER SUPPLIES, the user needs to supply data
or an argument. For test data, the example uses cos(x) + some noise on an
evenly spaced interval. The user will supply his own data, exactly "m" number of
points. The user must also supply the degree of the polynomials to use as well
as a vector (x_grid) that contains the points at which the fit is to be evaluated.
As shown in the example, evenly spaced data may be used along the original
interval [a,b] for the output grid (x_grid[]). The user should pay close attention
to the degree polynomial that he chooses for his particular data.
Also, this is an example with hard-coded test data and no error checking. The
typical user will likely get data from an external file or live link and will
need to use variables where the example uses #defines. This may mean changes
would need to be made in the way memory is allocated for the arrays. These are
C language issues that the user should easily be able to work through. The user
should also supply his own error checking.
Please contact Technical Support (support@houston.vni.com) for a FAX that outlines
the algorithm used for this code.
//Program written in C to fit data with Legendre Polynomials using CNL
#include
#include
#include
#include
// constants from user's data, would normally be read from input file
#define m 50 // number of input data points USER SUPPLIES
#define N 6 // degree of Legendre polynomials to use USER SUPPLIES
#define num_pts 100 // number of fitted output points on [a,b] USER SUPPLIES
main() {
int i, j, k;
float a, b, *c;
float *stat_result;
float alpha, beta, interval;
float lambda[N+1], gamma[N+2];
float t[m], fdata[m];
float x_translated_grid[num_pts];
float x[m], Z[N+3], p[m][N+1];
float x_grid[num_pts], sdata[num_pts];
float *ran_num;
/* t, fdata are the user's original data points. These will usually
be read in from file, but the test values are hard-coded for this
example. */
/* generate [m] evenly spaced t[] values. User's original data does
not have to be evenly-spaced. Also generate some fdata values with
some noise using an IMSL routine. USER SUPPLIES */
for (i = 0; i < m; i++) {
t[i] = (float) i;
ran_num = imsl_f_random_normal(1,0); // generate some noise
fdata[i] = cos(t[i]/4.0f) + *ran_num * 0.1f;
}
/* get the min and max values of t using imsl stat code, user can use
some other method */
stat_result = imsls_f_simple_statistics(m, 1, t, 0);
a = stat_result[5]; // minimum value of t
b = stat_result[6]; // maximum value of t
/* convert t on the interval [a,b] to x on the interval [-1,1] */
alpha = 2.0f / (b - a);
beta = (b + a) / (b - a);
for (i = 0; i < m; i++) {
x[i] = (alpha * t[i]) - beta;
}
/* x_grid is the vector of points that the user wants to evaluate the
fit through. Choose [num_pts] output grid locations. The user needs
to supply these in the x_grid[] vector and can use any points on the
interval [a,b]. For this example we have just used evenly spaced
points on the interval [a,b] USER SUPPLIES */
interval = (b - a) / (num_pts - 1);
for (i = 0; i < num_pts; i++) {
x_grid[i] = (float) i * interval;
}
/* convert the output grid points on interval [a,b] to the interval [-1,1] */
for (i = 0; i < num_pts; i++) {
x_translated_grid[i] = (x_grid[i] * alpha) - beta;
}
/* contruct p */
for (i = 0; i < m; i++) {
p[i][0] = 1.0f;
p[i][1] = x[i];
}
for (j = 1; j < N; j++) {
for (i = 0; i < m; i++) {
p[i][j+1] = (((2.0f*j)+1.0f)/(j+1.0f))*x[i]*
(p[i][j])-(j/(j+1.0f))*(p[i][j-1]);
}
}
/* solve for c using a linear least squares routine */
c = imsl_f_lin_least_squares_gen (m, N+1, p, fdata, 0);
/* evaluate the series */
for (j = 0; j < num_pts; j++) {
Z[N+2] = 0;
Z[N+1] = 0;
gamma[N+1] = N / (N + 1.0f);
for (k = N; k > -1; k--) {
lambda[k] = ((2.0f * k) + 1.0f) / (k + 1.0f);
gamma[k] = k / (k + 1.0f);
Z[k] = c[k] + (lambda[k] * x_translated_grid[j] * Z[k+1]) -
(gamma[k+1] * Z[k+2]);
}
sdata[j] = Z[0];
}
/*********************** OUTPUT **********************/
/* output orginal data points, (t[], fdata[]) */
printf("\n\nOriginal Points\n");
for (i = 0; i < m; i++) {
printf ("%2.4f, %2.4f\n", t[i], fdata[i]);
}
/* output fitted data points, (x_grid[], sdata[]) */
printf("\n\nFitted Data Points\n");
for (i = 0; i < num_pts; i++) {
printf ("%2.4f, %2.4f\n", x_grid[i], sdata[i]);
}
}
29. CNL - freeing memory from lin_sol_posdef_coordinate
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0 or 3.01
Architecture/OS version: n/a
PROBLEM DESCRIPTION
How do you free the memory allocated to optional argument IMSL_RETURN_NUMERIC_FACTOR
of function lin_sol_posdef_coordinate?
SOLUTION
This code shows an example of how this memory can be freed:
#include
#include
main()
{
Imsl_d_sparse_elem a[] = {0, 0, 10.0,
1, 1, 20.0,
2, 0, 1.0,
2, 2, 30.0,
3, 2, 4.0,
3, 3, 40.0,
4, 0, 2.0,
4, 1, 3.0,
4, 3, 5.0,
4, 4, 50.0};
double b[] = {55.0, 83.0, 103.0, 97.0, 82.0};
Imsl_d_numeric_factor num_factor;
int n = 5,i;
int nz = 10, *k;
double *x, *y;
x = imsl_d_lin_sol_posdef_coordinate (n, nz, a, b,
IMSL_NUMERIC_FACTOR_ONLY, IMSL_RETURN_NUMERIC_FACTOR, &num_factor, 0);
y=*num_factor.diag;
free(y);
y=*num_factor.alnz;
free(y);
k=*num_factor.nzsub;
free(k);
k=*num_factor.xnzsub;
free(k);
k=*num_factor.xlnz;
free(k);
k=*num_factor.perm;
free(k);
}
30. CNL - out of environment space on Windows 95
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0/4.0/5.0
Architecture/OS version: Windows 95/98/ME
PROBLEM DESCRIPTION
When cnlenv.bat is executed on a Windows 95/98/ME machine, this message appears:
out of environment space
SOLUTION
This message indicates that you do not have enough environment space to set
the variables defined in the cnlenv.bat batch file.
On Windows 95 or 98, you can increase this space by inserting the following line
in the config.sys file and then rebooting:
SHELL=C:\COMMAND.COM C:\ /P /E:4096
This assumes that C: is your system drive. It will increase the environment space
to 4096, which is usually adequate.
The above command does not work on Windows ME. From the Microsoft web site:
http://support.microsoft.com/support/kb/articles/Q261/8/
25.ASP?LN=EN-US&SD=gn&FR=0&qry=environment&rnk=7&src=DHCS_MSPSS_gn_SRCH&SPR=WINME
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Windows Millennium Edition
--------------------------------------------------------------------------------
SYMPTOMS
When you start a batch file or use a command prompt, you may receive the following
error message:
Out of environment space
CAUSE
The default space for environment variables is 256 bytes by default. More
environment variables are being set than can fit in 256 bytes.
RESOLUTION
To work around this issue, use one of the following methods:
Method 1
Right-click the MS-DOS Prompt shortcut, and then click Properties.
Click the Memory tab.
In the Initial Environment box, set the initial environment size you want
(from 256 to 4,096 bytes, in 256-byte increments).
Click OK.
Method 2
Edit the Autoexec.bat file to include any environment variables that you
need to set, and then reboot the computer. The changes are incorporated
into the registry and the environment variable size is increased.
MORE INFORMATION
Windows Millennium Edition ignores Config.sys statements to increase the
environment variable size.
For a list of command-line options, type command.com /?.
-----------------------------------------------------------------
For Windows ME systems only, to get the CNL environment variables registered with system,
the following steps must be taken:
1) Open CNLENV.BAT in a text editor and copy all of the environment variables that
CNL sets
2) Open the autoexec.bat file and paste those environment variable set commands into
the file.
3) Save the autoexec.bat file.
4) Click START / RUN and type in msconfig and click OK.
5) It should read the environment variables into the system registry. You should see
this message:
"When you start the System Configuration Utility (Msconfig), you see the following
information dialog: Environment Variables were found in the legacy files Autoexec.bat
and/or Config.sys and the variables were moved to the Windows Registry."
6) Exit the msconfig utility and reboot your system.
7) Open up a DOS command window and type set to see if the environment variables are set.
8) Open up the autoexec.bat file to make sure that the environment variable set commands
are still there.
31. CNL 3.0 - adding env file to system startup on Windows 95
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0 or F90 3.0
Architecture/OS version: Windows 95 or 98
PROBLEM DESCRIPTION
Environment variables required for CNL or F90 are not defined on Windows 95.
SOLUTION
For CNL, cnlenv.bat must be executed to define the required environment variables.
For F90, f90env.bat must be executed. If these batch files are executed at system
startup, the environment variables will be already defined.
To execute cnlenv.bat at system startup, add this line to autoexec.bat:
call c:\imslnt\cnl\cnlenv.bat
To execute f90env.bat at system startup, add this line to autoexec.bat:
call c:\imslnt\f90\f90env.bat
Note that this assumes the default installation directory of c:\imslnt. If either of
these products were installed in a directory other than the default, the directory
names must be changed accordingly.
32. CNL 3.0 - device name in IMSLSERRPATH logical is ignored
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0
Architecture/OS version: Dec Alpha / OpenVMS
PROBLEM DESCRIPTION
For CNL 3.0 on alpha openvms systems, the device name in logical IMSLSERRPATH
is ignored when locating the error file imsls_e.bin.
SOLUTION
The device name is being dropped when parsing the logical IMSLSERRPATH for the
location of the Stat library error file, imsls_e.bin. The file will only be found
when it is on the same device as the default device.
Workaround is to set the default device to the same device as specified in
IMSLSERRPATH before running the program. A change request has been filed.
33. CNL 3.01 - duplicate symbol from static link
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.01
Architecture/OS version: unix
PROBLEM DESCRIPTION
A program which calls functions from both the math and stat libraries produces
"duplicate symbol" messages when linked with the static library. The errors do not
appear when it is linked with the shared library.
SOLUTION
This problem only occurs when calling both math and stat functions in the same
program and linking to the static library. Link to the shared library as a
workaround. A change request has been filed.
34. CNL - imsl_d_regression returns a NULL pointer when a warning error occurs
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0
Architecture/OS version: any
PROBLEM DESCRIPTION
In a C program, a customer is calling imsl_d_regression from CNL on Windows 95. During
runtime, the following message appears :
IMSL_WARNING_IMMEDIATE imsl_d_regression
dfe=0.000000E+000 statistical inference is not possible, more observations are needed
The function returns a NULL pointer. In the documentation, this message is not explained.
Normally, even if there is a warning message, the function should compute the results.
But with imsl_d_regression, the result is a NULL pointer. When the program uses
imsls_d_regression instead of imsl_d_regression, the same WARNING is output, but the
correct result is returned with the stat routine while the math routine only returns a
NULL pointer.
SOLUTION
The C/math version of regression had a logic error when the error conditions were checked.
Use the stat version of regression (imsls_d_regression). This problem has been fixed for
the next release of CNL.
35. CNL 3.0 - invalid license file syntax
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0
Architecture/OS version: Solaris
PROBLEM DESCRIPTION
A program calling a stat routine from CNL 3.0 on Solaris produces the following errors:
client: Invalid license file syntax (-2,134)
or
CSTAT does not exist as a licensed product in the license file
SOLUTION
A workaround to this problem is to use a softkey for CSTAT 3.01 instead of CSTAT 3.0.
36. CNL 3.0 - numerical difficulty message from lin_prog
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.01
Architecture/OS version: any
PROBLEM DESCRIPTION
What does this error message mean? It may be output by lin_prog in CNL or DLPRS in
the Fortran library.
Numerical difficulty occurred. Using double precision may help.
SOLUTION
This message indicates that the problem has moved to a vertex that is poorly
conditioned. If single precision is being used, changing to double precision may help.
37. CNL - error when using IMSLS_RETURN_USER with routine random_normal
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0
Architecture/OS version: any
PROBLEM DESCRIPTION
When using the optional argument IMSLS_RETURN_USER, the computed answers should be stored
in the user-provided array a, and the pointer returned by the function is set to point
to the user-provided array a.
When using the optional argument IMSLS_RETURN_USER with the routine random_normal,
the pointer returned by the function is NOT set properly. It does NOT get set to
the user-provided array a, as it should. The below sample illustrates.
#include "imsls.h"
#include
#include
void main()
{
int N = 5;
double *Y;
Y = (double *)calloc(N,sizeof(double));
Y = imsls_d_random_normal(N,IMSLS_RETURN_USER, Y, 0);
// at this point Y points to 0x0000000
printf("%s:\n%8.4f%8.4f%8.4f%8.4f%8.4f\n",
"Standard normal random deviates",
Y[0], Y[1], Y[2], Y[3], Y[4]);
}
This routine will crash. If you change the name of the pointer returned by the function
to any other name such as:
r = imsls_d_random_normal(N,IMSLS_RETURN_USER, Y, 0);
The routine will not crash and compute correctly, however, the answer must be retrieved
through Y and not r. The return from the function r does not point to valid information.
SOLUTION
Either use a different variable name for the pointer returned by the function as opposed
to the variable name for the user-provided array used with IMSLS_RETURN_USER or do not
use the optional argument IMSLS_RETURN_USER at all. If this optional argument is not
used, the answer can be retrieved from the pointer returned by the function.
38. CNL - examples for categorical_glm
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: N/A
PROBLEM DESCRIPTION
This is the code for categorical_glm documentation examples:
SOLUTION
/* Example 1 categorical_glm */
#include
main ()
{
static float x[8][3] = { 1.69, 6, 59,
1.724, 13, 60,
1.755, 18, 62,
1.784, 28, 56,
1.811, 52, 63,
1.836, 53, 59,
1.861, 61, 62,
1.883, 60, 60};
float *coef_statistics, *last_step;
int n_obs=8, n_class=0, n_continuous=1;
int n_coef, model=3, ipar=2, i;
char *fmt = "%12.4f";
static char *clabels[] = {"", "coefficients", "s.e", "z", "p"};
n_coef = imsls_f_categorical_glm (n_obs, n_class, n_continuous,
model, &x[0][0],
IMSLS_X_COL_DIST_PARAMETER, ipar,
IMSLS_COEF_STAT, &coef_statistics,
IMSLS_LAST_STEP, &last_step, 0);
imsls_f_write_matrix ("Coefficient statistics", n_coef, 4, coef_statistics,
IMSLS_WRITE_FORMAT, fmt, IMSLS_NO_ROW_LABELS, IMSLS_COL_LABELS, clabels,0);
imsls_f_write_matrix ("parameter update", 1, n_coef, last_step,
IMSLS_WRITE_FORMAT, fmt, 0);
}
/* Example 2 categorical_glm */
#include
main ()
{
int nobs = 4;
int n_class = 2;
int n_cont = 0;
int model = 0;
float x[16] = {
4, 1259, 0, 0,
1, 2082, 0, 1,
7, 1417, 1, 0,
9, 1647, 1, 1
};
int iclass[2] = {2, 3};
int icont[1] = {-1};
int n_coef;
float *coef;
float *case_analysis, *cov, *means, *ls;
float crit, *cv ;
int *obs_status, *ncv, k, ksum, n_rows_missing;
char *clabels[5] = {"", "coefficient", "std error", "z-statistic", "p-value"};
char *fmt = "%10.6W";
n_coef = imsls_f_categorical_glm(nobs, n_class, n_cont, model, x,
IMSLS_COEF_STAT, &coef,
IMSLS_X_COL_VARIABLES, iclass, icont, 0,
IMSLS_X_COL_DIST_PARAMETER, 1,
0);
imsls_f_write_matrix("Coefficient Statistics", n_coef, 4, coef,
IMSLS_COL_LABELS, clabels, IMSLS_ROW_NUMBER_ZERO,
IMSLS_WRITE_FORMAT, fmt, 0);
}
39. CNL - core dump on Red Hat Linux 6.1
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0
Architecture/OS version: Red Hat Linux 6.1
PROBLEM DESCRIPTION
The example programs core dump on Red Hat Linux 6.1, when compiled with the
gnu C 2.9.1.66.
$ $CC $CFLAGS -o cmath cmath.c $LINK_CNL
$ $CC $CFLAGS -o cstat cstat.c $LINK_CNL
$ ./cmath
Library version: IMSL C/Math/Library Version 3.0
Customer number: 999999
Segmentation fault (core dumped)
$ ./cstat
Library version: IMSL C/Stat/Library Version 3.0
Customer number: 999999
Segmentation fault (core dumped)
SOLUTION
The supported platform for CNL 3.0 on linux is Red Hat 5.2 and gnu C 2.7.2.3.
There are differences in the libc.so.6 made from glibc 2.1.1 on Red Hat 6.1 ,
as opposed to RedHat 5.2, which still uses a glibc 2.0.7-based libc.so.6.
Contact your sales representative to obtain CNL for Red Hat 6.1.
40. CNL 3.0 - version function does not return license number on Windows
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.0
Architecture/OS version: Windows NT/95
PROBLEM DESCRIPTION
On Windows NT, function imsl_version always returns "000000" for the license number.
SOLUTION
The license number should be retrieved from file cnl.ini. This file contains
the following line:
SerialNumber=xxxxxx
where xxxxxx is the license number. The version function is incorrectly using
the environment variable IMSL_CNL to locate the cnl.ini file. This variable is
not defined. It should be using IMSLNT_CNL, which is defined by cnlenv.bat.
A workaround is to define the environment variable IMSL_CNL. Set it to the same
value as IMSLNT_CNL. A change request has been filed.
41. CNL 4.0 - spline_lsq_constrained
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 4.0
Architecture/OS version: Windows NT/95
PROBLEM DESCRIPTION
The single precision version of spline_lsq_constrained behaves unpredictably
on the Windows platform.
SOLUTION
Use the double precision version as a workaround.
A change request has been filed.
42. CNL 4.0 - cannot read distribution file from CNL 4.0 CD
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CTT 3.0
Architecture/OS version: Solaris 7
PROBLEM DESCRIPTION
During installation from CNL 4.0 CD, part number 8201, on Solaris 7, the message
"reading softkey unlock file" is displayed and after that, the error message
"Cannot read distribution file, I/O error" occurs, and the process is ended.
SOLUTION
This problem has been determined to be unique to Solaris 7. It does not occur on
Solaris 8 or 2.6. We have referred the problem to Sun for further investigation.
Workarounds are to install the product from another system running Solaris 8 or 2.6, or
to download the product from the VNI ftp site.
43. CNL 4.0 - incorrect p value from normal_one_sample
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CTT 4.0
Architecture/OS version: n/a
PROBLEM DESCRIPTION
Normal_one_sample is returning a p value greater than one for some problems.
SOLUTION
There is an error in the computation of p_value, as returned in the optional
argument IMSLS_T_TEST. A change request has been filed.
44. CNL 4.0 - mount command for CTT 3.0 CD on Digital Unix 4.0E
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 4.0 or F90 4.01 on CTT 3.0 CD
Architecture/OS version: Digital Unix 4.0E or earlier 4.0
PROBLEM DESCRIPTION
When using a version of Digital UNIX 4.0 PRIOR to 4.0F, the mount command listed
in the CTT 3.0 CD installation guide will not work.
SOLUTION
Use the mount command in the CTT 2.1 CD installation guide. The command is:
mount -r -t cdfs -o noversion device/cdrom
45. CNL 3.01 - incorrect softkey code
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 3.01 or F90 4.01
Architecture/OS version: Solaris
PROBLEM DESCRIPTION
Using CNL 3.01 with cwave or F90 4.01 with cwavefor produces error message
"incorrect softkey code" at first call to IMSL routine.
SOLUTION
There is a conflict in the license handler when both products are used in one
application. Try linking to the static version of the IMSL library as a
workaround, or for CNL, try using CNL 4.0. It may be necessary to add a switch to ignore
multiply defined symbols during the link step. On Solaris this switch is "-z muldefs".
A change request has been filed.
46. CNL 4.0 - compatibility with SuSE linux
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 4.0
Architecture/OS version: SuSE Linux
PROBLEM DESCRIPTION
Is CNL 4.0, for Red Hat linux and gcc compiler, compatible with SuSE linux?
SOLUTION
Yes. The product has been tested successfully on i486-SUSE-linux version 2.95.2
with gcc version 2.95.2 19991024 release. The installation procedure differs
from that on Red Hat in that the installer must login as root to mount the CD.
47. CNL 4.0 - segmentation violation from sort_data
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 4.0
Architecture/OS version: any
PROBLEM DESCRIPTION
Sort_data returns the following message on Windows:
*** TERMINAL Error from imsls_d_sort_data. Segmentation violation. This can
*** be caused by:
*** (1) A missing argument or a missing parameter after an optional
*** argument.
*** (2) An incorrectly set pointer. If the procedure expects a
*** pointer to be set on input, and it is not set, then the
*** procedure will attempt to reference a random location in memory.
*** This can cause this error.
*** TERMINAL Errror from imsls_d_sort_data. Major violation occurred.
SOLUTION
The error occurs in a program which uses the IMSLS_TABLE optional argument.
Behavior may vary depending on platform, including hanging or output of the
following message:
*** FATAL Error IMSLS_MAXTAB_ERROR from imsls_d_sort_data.
A Change Request has been filed.
48. CNL - environment variable conflict with WAVE
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: any
PROBLEM DESCRIPTION
The setup scripts for both CNL 5.0 and Wave 7.01 set environment variables
IMSLERRPATH and IMSLSERRPATH, used to locate error message files. This
creates a conflict if a customer is using both products in the same
window and has sourced both setup files.
SOLUTION
The customer will have to source wvsetup prior to using Wave and source
cttsetup.csh prior to using CNL. These environment variable definitions
must remain separate because the two products do not use the same error
message files.
49. CNL - adding cnlenv.bat to autoexec.bat
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: Windows 98
PROBLEM DESCRIPTION
What is the command to add cnlenv.bat to autoexec.bat on Windows 98 or
Windows ME for CNL 5.0?
SOLUTION
Add this line to the autoexec.bat file:
CALL C:\PROGRA~1\VNI\CNL50\cnlenv.bat
where PROGRA~1 is the DOS equivalent name to "Program Files". Check the directory
names under C:\ in a DOS window to find the name that is equivalent to
"Program Files" on your system.
For example:
dir c:
50. CNL - use of input array for output U and V in lin_svd_gen
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: any
PROBLEM DESCRIPTION
The lin_svd_gen documentation states that input array a can be used to
return either U or V, but this results in an incorrect result for U or V.
SOLUTION
This does not work as documented. Use a separate array for both U and V.
A Change Request has been filed.
51. CNL - setting up license file for demo softkeys
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: Windows
PROBLEM DESCRIPTION
What is required for CNL 5.0 on Windows to set up licensing for a demo or campus softkey?
SOLUTION
Create a file named license.dat in the license subdirectory. This file should
contain the FEATURE lines for CMATH and CSTAT. For example:
FEATURE CMATH VNI 5.000 25-jun-2001 0 FC0A4990CB6B1360B543 "" DEMO
FEATURE CSTAT VNI 5.000 25-jun-2001 0 1C7A79A08C36A5149B8B "" DEMO
These lines will be found on the softkey notification form that was sent to you
with the software or that was sent to you by our license administrator.
Eexecute the batch file cnlenv.bat, found in the Cnl50 subdirectory, to define the
environment variable LM_LICENSE_FILE. This environment variable defines the location
of the license.dat file and must be set prior to executing any application that
uses CNL 5.0.
On Windows NT or 2000, if you chose to have the environment variables updated
during the installation, this environment variable will already be defined.
On Windows 98, you can add cnlenv.bat to the autoexec.bat file to have the
CNL environment variables defined when the system is booted.
52. CNL - zeros_sys_eqn Jacobian is transposed
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: any
PROBLEM DESCRIPTION
In zeros_sys_eqn the fjac argument to optional parameter IMSL_JACOBIAN is
incorrectly documented, and it is transposed from what should be documented.
SOLUTION
The documentation for derivative reads dfi/dxi. It should read dfi/dxj, but it
is treated internally as dfj/dxi. The workaround is to transpose fjac before
returning it from jacobian. This problem will be corrected in the next release.
53. CNL - terminal error from lin_sol_posdef_coordinate
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: any
PROBLEM DESCRIPTION
In lin_sol_posdef_coordinate, when optional argument IMSL_SUPPLY_SYMBOLIC_FACTOR
is used with IMSL_SOLVE_ONLY, the following terminal error occurs :
*** TERMINAL Error from imsl_f_lin_sol_posdef_coordinate. Segmentation
*** violation. This can be caused by:
*** (1) A missing argument or a missing parameter after an optional
*** argument.
*** (2) An incorrectly set pointer. If the procedure expects a
*** pointer to be set on input, and it is not set, then the
*** procedure will attempt to reference a random location in memory.
*** This can cause this error.
*** TERMINAL Error from imsl_f_lin_sol_posdef_coordinate. Major violation
*** occurred.
SOLUTION
The routine does not work as documented with argument IMSL_SUPPLY_SYMBOLIC_FACTOR.
A CR has been filed.
54. CNL - example of calling CNL from Fortran
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: Windows
PROBLEM DESCRIPTION
How would a CNL function be called from Fortran, using Visual C++ and
Compaq Fortran on Windows?
SOLUTION
This example shows one way to call CNL function lin_sol_gen from Fortran using
an intermediate C function to interface between the Fortran subroutine call and
the CNL function with one optional argument.
Fortran code: lsg.f
integer n
real x(3), a(3,3), b(3)
data a/1.0, 3.0, 3.0,
* 1.0, 3.0, 4.0,
* 1.0, 4.0, 3.0/
data b/1.0, 4.0, -1.0/
n=3
c call Fortran interface to CNL function imsl_f_lin_sol_gen */
call imsl_fi_lin_sol_gen (n, a, b, x)
write (*,*) 'solution =', x
end
C interface function: lsgi.c
#include
/* Fortran interface to lin_sol_gen */
void __stdcall IMSL_FI_LIN_SOL_GEN (int *n, float a[], float b[], float x[])
{
int m;
m = *n;
imsl_f_lin_sol_gen (m, a, b, IMSL_RETURN_USER, x, 0);
}
To build using Visual C++ and Compaq Fortran:
cl -c -DANSI lsgi.c
df lsg.f lsgi.obj cmath.lib
-------------------------------------
This example shows another method of calling CNL from Fortran using INTERFACE
statements. This example also demonstrates how to call a CNL function, min_con_gen_lin,
which requires a user supplied function as an argument. Note that the user supplied
function is written in Fortran.
Fortran code lconfg.f90:
! Interface for intermediate C objective function
INTERFACE TO SUBROUTINE c_fcn [C,ALIAS:'_c_fcn'](N, X, F)
INTEGER N[VALUE]
REAL X[REFERENCE], F[REFERENCE]
END
! Interface for intermediate C gradient function
INTERFACE TO SUBROUTINE c_grad [C,ALIAS:'_c_grad'](N, X, g)
INTEGER N[VALUE]
REAL X[REFERENCE], G[REFERENCE]
END
! Interface to C/Math routine imsl_f_min_con_gen_lin().
INTERFACE TO SUBROUTINE imsl_f_min_con_gen_lin &
[C,ALIAS:'_imsl_f_min_con_gen_lin']&
(c_fcn,NVAR,NCON,NEQ,A,B,XLB,XUB,&
IOP_XGUESS, XGUESS, &
IOP_RETURN_USER, SOLUTION, &
IOP_MAXFCN, MAXFCN, &
IOP_TOL, TOLERANCE, &
IOP_GRAD, c_grad,&
ZERO)
! Required args.
EXTERNAL c_fcn
INTEGER NVAR[VALUE]
INTEGER NCON[VALUE]
INTEGER NEQ[VALUE]
INTEGER A[VALUE]
INTEGER B[VALUE]
INTEGER XLB[VALUE]
INTEGER XUB[VALUE]
! Optional args
INTEGER IOP_XGUESS[VALUE]
INTEGER XGUESS[VALUE]
INTEGER IOP_RETURN_USER[VALUE]
INTEGER SOLUTION[VALUE]
INTEGER IOP_MAXFCN[VALUE]
INTEGER MAXFCN[VALUE]
! *** Need REAL*8 for IMSL_TOLERANCE since imsl_f_min_con_gen_lin
! *** pulls a double off the stack for this optional argument.
INTEGER IOP_TOL[VALUE]
REAL*8 TOLERANCE[VALUE]
INTEGER IOP_GRAD[VALUE]
EXTERNAL c_grad
INTEGER ZERO[VALUE]
END ! Interface for imsl_f_min_con_gen_lin
! Use parameters to set C/Math enums for optionalarguments
INTEGER IMSL_TOLERANCE, IMSL_XGUESS, IMSL_GRADIENT, &
IMSL_MAX_FCN, IMSL_RETURN_USER
PARAMETER (IMSL_TOLERANCE = 10053, &
IMSL_XGUESS = 10100, &
IMSL_GRADIENT = 10250, &
IMSL_MAX_FCN = 10103, &
IMSL_RETURN_USER = 10260)
! Declaration of variables
INTEGER NCON, NEQ, NVAR
PARAMETER (NCON=2, NEQ=0, NVAR=3)
!
INTEGER MAXFCN
REAL A(NCON*NVAR), ACC, ALAMDA(NVAR), B(NCON), &
SOL(NVAR), XGUESS(NVAR), XLB(NVAR), XUB(NVAR)
! ***
! *** NOTE, We have to re-arrange 2D data into C storage, i.e, row-major.
! ***
! DATA A/-1.0, 1.0, -2.0, 2.0, -2.0, 2.0/
DATA A/-1.0, -2.0, -2.0, 1.0, 2.0, 2.0/
DATA B/0.0, 72.0/
DATA XLB/3*0.0/, XUB/20.0, 11.0, 42.0/, XGUESS/3*10.0/
DATA ACC/0.0/, MAXFCN/400/
! Use LOC() to pass address of arrays.
CALL imsl_f_min_con_gen_lin(c_fcn, NVAR, NCON, NEQ,&
LOC(A), LOC(B), LOC(XLB), LOC(XUB), &
IMSL_XGUESS, LOC(XGUESS), &
IMSL_RETURN_USER, LOC(SOL), &
IMSL_MAX_FCN, MAXFCN, &
IMSL_TOLERANCE, ACC, &
IMSL_GRADIENT, c_grad, &
0)
WRITE(*,*) "Expected Solution: ", 20.0, 11.0, 15.0
WRITE(*,*) "Computed Solution: ", SOL
END
! Subroutines F_FCN & F_GRAD will be called by the C functions that are
! passed to imsl_f_min_con_gen_lin. We use intermediate C functions
! since Fortran expects arguments passed by reference, but CNL does
! not supply all arguments by reference.
SUBROUTINE F_FCN (N, X, F)
INTEGER N
REAL X(*), F
F = -X(1)*X(2)*X(3)
RETURN
END
!
SUBROUTINE F_GRAD (N, X, G)
INTEGER N
REAL X(*), G(*)
G(1) = -X(2)*X(3)
G(2) = -X(1)*X(3)
G(3) = -X(1)*X(2)
RETURN
END
-------------------------------------------------------------------------------
C code fcn_interface.c:
extern void __stdcall F_FCN();
extern void __stdcall F_GRAD();
void c_fcn(int n, float *x, float *f)
{
F_FCN(&n, x, f);
}
void c_grad(int n, float *x, float *g)
{
F_GRAD(&n, x, g);
}
-------------------------------------------------------------------------------
To build using Visual C++ and Compaq Fortran:
cl -c -DANSI fcn_interface.c
df lconfg.f90 fac_interface.obj cmath.lib
Execute it:
lconfg
Expected Solution: 20.00000 11.00000 15.00000
Computed Solution: 20.00000 11.00000 15.00000
55. CNL - error from nonlinear_optimization with IMSLS_ACC argument
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version:
PROBLEM DESCRIPTION
When the optional argument IMSLS_ACC is used with nonlinear_optimization, the
following terminal error occurs:
*** TERMINAL Error from imsls_f_nonlinear_optimization. Segmentation
*** violation. This can be caused by:
*** (1) A missing argument or a missing parameter after an optional
*** argument.
*** (2) An incorrectly set pointer. If the procedure expects a
*** pointer to be set on input, and it is not set, then the
*** procedure will attempt to reference a random location in memory.
*** This can cause this error.
*** TERMINAL Error from imsls_f_nonlinear_optimization. Major violation
*** occurred.
SOLUTION
When the optional argument IMSLS_ACC is supplied, nonlinear_optimization is
incorrectly setting a flag to also expect optional argument IMSLS_THETA_GUESS.
A Change Request has been filed.
As a workaround, supply IMSLS_THETA_GUESS with theta_guess[]=0, which would be
the equivalent of the default.
56. CNL - error from shared library on Red Hat Linux 7.1
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: Red Hat 7.1
PROBLEM DESCRIPTION
A program linked to CNL 5.0 on Red Hat Linux 7.1 with gnu c 2.96 gives the
following error at execution time:
error while loading shared libraries: libimslcmath.so : undefined symbol : stat
SOLUTION
The supported platform for this product is Red Hat 6.1 and gnu c 2.91.66.
This problem occurs with the shared library only. Link to the static library as
a workaround.
57. CNL - determinant of a real general matrix
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: any
PROBLEM DESCRIPTION
Is there a function in CNL to compute the determinant of a real general matrix?
SOLUTION
CNL does not have a function for computing the determinant but the determinant
can be computed from the LU factorization. The method for computing determinant
is given in the description of Fortran routine LFDRG. It is the product of
det L and det U, where det U is the product of the diagonal elements of the
U factor and det L is (-1)^k where k is the number of pivoting interchanges.
lin_sol_gen can be used to obtain the LU factorization. Using Example 2 of
lin_sol_gen to demonstrate:
det U = 1. * 1. * 1. (U is the upper triangular part of factor
with diagonal 1., 1., 1.)
det L = -1. ( There is one pivot interchange in pvt (-1)^1)
#include
main()
{
int n = 3, i, pvt[3];
float factor[9];
float x[3];
float detL, detU, detA;
float a[] = {1.0, 3.0, 3.0,
1.0, 3.0, 4.0,
1.0, 4.0, 3.0};
float b[] = {1.0, 4.0, -1.0};
/* Solve trans(A)*x = b for x */
imsl_f_lin_sol_gen (n, a, b,
IMSL_TRANSPOSE,
IMSL_RETURN_USER, x,
IMSL_FACTOR_USER, pvt, factor,
0);
/* Print x */
imsl_f_write_matrix ("Solution, x, of trans(A)x = b", 1, n, x, 0);
/* Print factors and pivot sequence */
imsl_f_write_matrix ("LU factors of A", n, n, factor, 0);
imsl_i_write_matrix ("Pivot sequence", 1, n, pvt, 0);
detL = 1.;
detU = 1.;
for (i=0; i
58. CNL - error from covariances optional argument FREQUENCIES
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: any
PROBLEM DESCRIPTION
On Windows the following terminal error occurs when attempting to use the
FREQUENCIES optional argument to covariances:
*** TERMINAL Error from imsls_f_covariances. Segmentation violation. This
*** can be caused by:
*** (1) A missing argument or a missing parameter after an optional
*** argument.
*** (2) An incorrectly set pointer. If the procedure expects a
*** pointer to be set on input, and it is not set, then the
*** procedure will attempt to reference a random location in memory.
*** This can cause this error.
*** TERMINAL Error from imsls_f_covariances. Major violation occurred.
SOLUTION
A change request has been filed for this problem. A workaround is to use both
the FREQUENCIES and WEIGHTS optional arguments. The problem only occurs when
FREQUENCIES is used by itself.
59. CNL - anova_nested example for unequal subgroups
-
PRODUCT/PLATFORM INFORMATION
Product/Version #: CNL 5.0
Architecture/OS version: any
PROBLEM DESCRIPTION
This is an example using anova_nested with unequal numbers in the subgroups.
SOLUTION
This is a 3 factor nested random model with unequal numbers in the
subgroups as follows:
nl[0] = 6 levels
nl[1] = 2 groups for level 1
nl[2] = 2 groups for level 2
nl[3] = 1 group for level 3
nl[4] = 9 groups for level 4
nl[5] = 1 group for level 5
nl[6] = 10 groups for level 6
nl[7] = 2 responses for group 1 level 1
nl[8] = 2 responses for group 2 level 1
nl[9] = 2 responses for group 1 level 2
nl[10] = 1 response for group 2 level 2
etc.
A B C
1 1 23.0 19.0
2 31.0 37.0
2 1 33.0 29.0
2 29.0
3 1 36.0 29.0 33.0
4 1 11.0 21.0
2 23.0 18.0
3 33.0
4 23.0
5 26.0
6 39.0
7 20.0
8 24.0
9 36.0
5 1 25.0 33.0
6 1 28.0 31.0
2 25.0 42.0
3 32.0 36.0
4 41.0
5 35.0
6 16.0
7 30.0
8 40.0
9 32.0
10 44.0
#include
#include
void main()
{
float *aov, *ems, *vc, *ymeans;
float y[36] = {23.0, 19.0, 31.0, 37.0, 33.0, 29.0, 29.0,
36.0, 29.0, 33.0, 11.0, 21.0, 23.0, 18.0, 33.0, 23.0,
26.0, 39.0, 20.0, 24.0, 36.0,
25.0, 33.0, 28.0, 31.0, 25.0, 42.0, 32.0, 36.0,
41.0, 35.0, 16.0, 30.0, 40.0,
32.0, 44.0};
int nl[32] = {6, 2, 2, 1, 9, 1, 10, 2, 2, 2, 1, 3,
2, 2, 1, 1, 1, 1, 1, 1,
1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1};
char *aov_labels[] = {
"degrees of freedom for model",
"degrees of freedom for error",
"total (corrected) degrees of freedom",
"sum of squares for model",
"sum of squares for error",
"total (corrected) sum of squares",
"model mean square",
"error mean square",
"F-statistic",
"p-value",
"R-squared (in percent)",
"adjusted R-squared (in percent)",
"est. standard deviation of within error",
"overall mean of y",
"coefficient of variation (in percent)"};
char *ems_labels[] = {
"Effect A and Error",
"Effect A and Effect B",
"Effect A and Effect A",
"Effect B and Error",
"Effect B and Effect B",
"Error and Error"};
char *means_labels[] = {
"Grand mean",
" A means 1",
" A means 2",
" A means 3",
" A means 4",
" A means 5",
" A means 6",
"AB means 1 1",
"AB means 1 2",
"AB means 2 1",
"AB means 2 2",
"AB means 3 1",
"AB means 4 1",
"AB means 4 2",
"AB means 4 3",
"AB means 4 4",
"AB means 4 5",
"AB means 4 6",
"AB means 4 7",
"AB means 4 8",
"AB means 4 9",
"AB means 5 1",
"AB means 6 1",
"AB means 6 2",
"AB means 6 3",
"AB means 6 4",
"AB means 6 5",
"AB means 6 6",
"AB means 6 7",
"AB means 6 8",
"AB means 6 9",
"AB means 6 10"
};
char *components_labels[] = {
"degrees of freedom for A",
"sum of squares for A",
"mean square of A",
"F-statistic for A",
"p-value for A",
"Estimate of A",
"Percent Variation Explained by A",
"95% Confidence Interval Lower Limit for A",
"95% Confidence Interval Upper Limit for A",
"degrees of freedom for B",
"sum of squares for B",
"mean square of B",
"F-statistic for B",
"p-value for B",
"Estimate of B",
"Percent Variation Explained by B",
"95% Confidence Interval Lower Limit for B",
"95% Confidence Interval Upper Limit for B",
"degrees of freedom for Error",
"sum of squares for Error",
"mean square of Error",
"F-statistic for Error",
"p-value for Error",
"Estimate of Error",
"Percent Explained by Error",
"95% Confidence Interval Lower Limit for Error",
"95% Confidence Interval Upper Limit for Error"};
imsls_f_anova_nested (3, 0, nl, y,
IMSLS_ANOVA_TABLE, &aov,
IMSLS_EMS, &ems,
IMSLS_VARIANCE_COMPONENTS, &vc,
IMSLS_Y_MEANS, &ymeans,
0);
imsls_f_write_matrix("***AnalysisofVariance ***",15,1,aov,
IMSLS_ROW_LABELS, aov_labels,
IMSLS_WRITE_FORMAT, "%10.5f",
0);
imsls_f_write_matrix("***ExpectedMeanSquare Coefficients ***",
6, 1, ems,
IMSLS_ROW_LABELS, ems_labels,
IMSLS_WRITE_FORMAT, "%6.2f",
0);
imsls_f_write_matrix("* * * Means ***",32,1,ymeans,
IMSLS_ROW_LABELS, means_labels,
IMSLS_WRITE_FORMAT, "%6.2f",
0);
imsls_f_write_matrix("* * Analysis of Variance / Variance Components * *",
27, 1, vc,
IMSLS_ROW_LABELS, components_labels,
IMSLS_WRITE_FORMAT, "%10.5f",
0);
}
-----------------------Results-------------------------------------------
***AnalysisofVariance ***
degrees of freedom for model 24.00000
degrees of freedom for error 11.00000
total (corrected) degrees of freedom 35.00000
sum of squares for model 1810.80591
sum of squares for error 310.16626
total (corrected) sum of squares 2120.97217
model mean square 75.45025
er
| |