>> Rodney Roberts IS & Education Professional Homepage >> Programming Tutorials And Downloads
![]() ![]()
Science makes it known,
|
D Windows program calling
Numerical Recipes: The Art of Scientific Computing1
This is a Windows version of
D Programming Language, Silverfrost Fortran 95, and Numerical Recipes
(which was a
IMOMENT(...), IMODE(...), CRANK(...), GEOMEAN(...), and HARMONICMEAN(...)]; entire source code unavailable for download from this site; Older Numerical Recipes book editions available from the publisher with the original FORTRAN source code; sttstcs.dll - sttstcs.for dynamic link library; sttstcs.lib - sttstcs.dll import library; Up to 300 data points are inputted in a grid of 30 rows and 10 columns, using an HWND array (HWND[300] hEditDataPt) of edit text boxes. The Number of Points edit box controls how many data points edit boxes are enabled for user input. In the case WM_COMMAND: section, used if (HIWORD(wParam)==EN_KILLFOCUS) and a for loop to search for an element of const uint[300] IDC_EDIT_DP equal LOWORD(wParam), indicating the user entered a value for one of the data points.6 An extern (...) {...} declaration with a linkage attribute is needed since IMDIAN1(...), IMOMENT(...), IMODE(...), CRANK(...), GEOMEAN(...)7, and HARMONICMEAN(...)7 are defined in another object file; it does not need a D interface (.di) file. FORTRAN converts the identifiers in its symbol table to upper case, therefore the subroutine names must be in upper case. // sttstcs.dll subroutine declarations extern (Pascal) { void* IMDIAN1(ref short, ref short, ref short, ref short[300]); void* IMOMENT(ref short, ref float, ref float, ref float, ref float, ref float, ref float, ref short, ref short[300]); void* IMODE(ref short, ref short, ref short, ref short, ref short, ref short[300]); void* CRANK(ref short, ref float, ref short[300], ref short[300], ref short); float GEOMEAN (ref short, ref short[300]); float HARMONICMEAN (ref short, ref short[300]); }extern (Pascal) {...} is the only extern declaration that produced a clean compile, requiring the parameters be passed to the external sttstcs.dll subprograms in reverse order as defined in the FORTRAN subroutines declarations. The subroutine calls require a try {} catch {} block in the windows program.8 try // Sort data, determine Median value { IMDIAN1(iErr,iMed,NumVal,idata); } catch (Throwable e) { MessageBoxA(hWnd, "IMDIAN1 Throw Error", "Statistical Analysis", MB_ICONERROR); PostQuitMessage(0); break; } When the user clicks on File, Calculate, the subprograms IMDIAN1(...), IMOMENT(...), IMODE(...), CRANK(...), GEOMEAN(...), and HARMONICMEAN(...) are called and calculate Average, Median, displayed by winstat. The data points are redisplayed in sorted order - IMDIAN1(...) calls internal subroutine ISORT(...) to sort the data point array.
1. Press, William H., Brian P. Flannery, Saul A Teukolsky, and William T. Vetterling (1986). Numerical Recipes: The Art of Scientific Computing. New York:Press Syndicate of the University of Cambridge. 2. Thanks to Simpledisplay.d for the clipboard code; module hedtio procedure hEditPopUpMenu (...) uses the Win32 API procedures CreatePopupMenu(), AppendMenuA(...), TrackPopupMenu(...), and DestroyMenu (...) for the short cut menu processing; the clipboard operations consist of Win32 API calls to OpenClipboard(hWnd), IsClipboardFormatAvailable(CF_TEXT), GetClipboardData (...), GlobalAlloc (GMEM_MOVEABLE, ...), GlobalLock(...), EmptyClipboard( ), SetClipboardData (CF_TEXT, ...), and GlobalUnlock(...). This is a rudimentary implementation of Win32 API clipboard operations designed for an application using an array of child window edit controls containing numeric data (hence the need for Delete Element and Insert Element options in the pop-up menu, hEditPopUpMenu (...) verifying the clipboard data is numeric). "commented out" prior to revising. This way, it is easy to revert back to a previous state. Current issue is partially selecting an edit control array element, extracting a subset of its data, and pasting to another edit control - SELECT ALL does not work again until use mouse to select all text. Time permitting, will continue researching D documentation and Win32 Developer's References for solution. 3. Only try this method to avoid making changes to the D module. As an alternative, write a D procedure declared extern (C) which calls the desired D procedure; the Pascal procedure then calls the D "wrapper" procedure. See cPopUpMenu (...) for an example. 4. For additional information on *.di files, see D .dll Calling FORTRAN .dll. 5. Additional information on writing D DLLs can be found at Win32 DLLs in D. 6. EN_KILLFOCUS does not get set until after the user clicks (or TABs) out of the field. 7. Recently added. These come from FORTRAN For Scientists & Engineers, 2nd Edition, 1995 8. Considered eliminating the try {} catch {} block by appending nothrow to each subprogram declaration. However, a misbehaving subroutine was generating floating point errors and was caught upon exit by the try {} catch {} block. In a computationally intense application, it may be advantageous to declare a subprogram nothrow, eliminating the overhead of try {} catch {} processing. |
Any and all © copyrights, ® ™ trademarks, or other intellectual
property (IP) mentioned here are the property of their respective owners.
Feel free to use any of the above in your project (without violating any intellectual property rights); please give credit (same idea as Copyleft). Page best viewed with Mozilla FireFox 3.6.13 (or higher) and Google Chrome Version 40.0.2214.94 (or higher) - Internet Explorer may not display or link correctly. |
Web hosting provided by | ||||
![]() |
, | ![]() |
, & |
![]() |