Ox Developer's Manual

Ox Developer's Manual

Developer's manual for OxTM 9 Jurgen A Doornik OxMetrics 9 www.oxlang.org www.doornik.com www.timberlake.co.uk www.timberlake-analytics.com OxTM 9 Developer's manual Copyright ©2018-2021 Jurgen A Doornik First published 1998 Revised in 2012,2018,2021 All rights reserved. No part of this work, which is copyrighted, may be reproduced or used in any form or by any means { graphic, electronic, or mechanical, including photocopy, record taping, or information storage and retrieval systems { without the written consent of the Publisher, except in accordance with the provisions of the Copyright Designs and Patents Act 1988. Whilst the Publisher has taken all reasonable care in the preparation of this book, the Publisher makes no representation, express or implied, with regard to the accuracy of the information contained in this book and cannot accept any legal responsability or liability for any errors or omissions from the book, or from the software, or the consequences thereof. Trademark notice All Companies and products referred to in this manual are either trademarks or registered trademarks of their associated Companies. Contents Front matter iii Contents v List of Program Listings viii D1 Introduction 1 D2 Modelbase and OxPack 3 D2.1 Introduction . .3 D2.2 Examples . .6 D2.3 OxPack functions that can be called from Ox . .6 OxPackBufferOff, OxPackBufferOn ..............6 OxPackDialog ...........................6 OxPackGetData .......................... 13 OxPackReadProfile... ..................... 14 OxPackSendMenuChoice ..................... 14 OxPackSetMarker ......................... 15 OxPackSpecialDialog ...................... 15 OxPackStore ............................ 21 OxPackWriteProfile... ..................... 21 D2.4 Modelbase virtual functions for OxPack . 22 Modelbase::DoEstimateDlg .................. 23 Modelbase::DoFormulateDlg .................. 24 Modelbase::DoOption ...................... 24 Modelbase::DoOptionsDlg ................... 24 Modelbase::DoSettingsDlg .................. 25 Modelbase::ForceYlag ..................... 25 Modelbase::GetModelSettings ................ 25 Modelbase::LoadOptions .................... 25 Modelbase::ReceiveData .................... 26 Modelbase::ReceiveMenuChoice ................ 26 Modelbase::ReceiveModel ................... 26 v vi CONTENTS Modelbase::SaveOptions .................... 26 Modelbase::SendFunctions .................. 27 Modelbase::SendMenu ...................... 27 Modelbase::SendSpecials ................... 28 Modelbase::SendVarStatus .................. 28 Modelbase::SetModelSettings ................ 29 D2.5 Adding support for a Batch language . 30 Modelbase::Batch ........................ 30 Modelbase::BatchCommands .................. 31 Modelbase::BatchMethod .................... 31 Modelbase::GetBatchEstimate ................ 31 Modelbase::GetBatchModelSettings ............. 31 D2.6 Adding support for Help . 32 D3 The ox/dev folder 33 D4 Ox Foreign Language Interface 35 D4.1 Calling C code from Ox . 35 D4.1.1 Calling the Dynamic Link Library . 36 D4.1.2 Compiling threes.c ................... 37 D4.1.2.1 Windows: Microsoft Visual C++ . 38 D4.1.2.2 Linux: gcc . 38 D4.1.2.3 macOS: clang . 38 D4.1.2.4 Windows: MinGW (gcc) . 39 D4.1.2.5 Name decoration . 39 D4.2 Calling FORTRAN code from Ox . 40 D4.3 Calling C/C++ code from Ox: returning values in arguments . 41 D4.4 Calling Ox functions from C . 44 D4.5 C macros and functions to access an OxVALUE; using arrays . 47 D5 Who is in charge? 48 D5.1 Introduction . 48 D5.2 Using Ox as a mathematical and statistical library . 48 D5.2.1 Using Ox as a library from C/C++ . 48 D5.2.2 Using Ox as a library from Java . 48 D5.2.3 Using Ox as a library from C# . 51 D5.3 Creating and using Ox objects . 54 D5.3.1 Creating and using Ox objects from Java . 55 D5.4 Adding a user-friendly interface . 58 D5.4.1 Using Java and the NetBeans IDE . 59 D5.4.2 Using Visual C++ and MFC . 60 CONTENTS vii D6 Ox Exported Functions 65 D6.1 Introduction . 65 D6.2 Ox function summary . 66 D6.3 Macros to access OxVALUEs .................... 83 D6.4 Ox-OxMetrics function summary . 85 D6.5 Ox exported mathematics functions . 87 D6.5.1 MATRIX and VECTOR types . 87 D6.5.2 Exported matrix functions . 88 D6.5.3 Matrix function reference . 92 Subject Index 117 Listings Adding C/C++ functions to Ox: threes.c ................ 35 Using the threes DLL from Ox code: threes.ox ............. 36 Adding C functions to Ox: fnInvert from the standard library . 41 Adding C functions to Ox: fnDecldl from the standard library . 42 Calling Ox functions from C: part of callback.c ............ 44 Calling Ox functions from C: callback.ox ............... 45 Using Ox as a library from Java: HelloOx.java ............. 48 Using Ox as a library from C#: Form1.cs ................. 51 Creating an Ox class object: class test.ox ............... 54 Creating an Ox class object: CallObject.java ............. 55 Writing a C++ wrapper: part of RanApp.java .............. 59 Writing a C++ wrapper: part of RanApp.cpp ............... 60 Writing a C++ wrapper: part of RanAppDlg.c .............. 62 Writing a C++ wrapper: ranapp.ox .................... 63 viii Chapter D1 Introduction There are several possible reasons why it can be useful to interface Ox with another language, e.g. • to access a library that is already available, possibly using a C layer in between; • to implement a small section of code that would be more efficiently executed in another language; • embed Ox functionality in another system, such as Excel; • to provide a user interface for existing code. An easy way to create an interface for an Ox program is using OxPack and the Ox- Metrics front-end. This only requires coding in Ox, and is documented first in Chap- ter D2. Ox is an open system to which you can add functions written in other languages. It is also possible to control Ox from another programming environment such as Visual C++. The interface to the Ox dynamic link library is based on the C language. Most, if not all, other languages provide a mechanism to interface in a manner similar to the C language. For example, under Windows, the Ox interface is very similar to interfacing with the Windows API. Extending Ox requires an understanding of the innards of Ox, a decent knowledge of C, as well as the right tools. In addition, extending Ox is simpler on some platforms than others. Thus, it is unavoidable that writing Ox extensions is somewhat more com- plex than writing plain Ox code. However, there could be reasons for extending Ox, e.g. when you need the speed of raw C or FORTRAN code, or to add a user-friendly interface in Java, say. Another case is to write a wrapper to use a function from another library. When you port some Ox code to C for reasons of speed, make sure that the function takes up a significant part of the time it takes to run the program and that it actually will be a faster in C than in Ox! This chapter gives many examples that could provide a start for your coding effort. When you write your own C functions to link to Ox, memory management inside the C code is your responsibility. So care is required: any errors can bring down the Ox program, or, worse, lead to erroneous outcomes. The main platforms for Ox are Windows, Linux and macOS, and the foreign lan- 1 2 Chapter D1 Introduction guage interface is available on each platform. A dynamic link library has the .so ex- tension under Linux and macOS, while under Windows it is .dll. Chapter D6 documents the C functions available to interface with Ox. This includes the C mathematical functions exported by the Ox DLL: any program could use Ox as a function library by making direct calls to the Ox DLL. Note that from Ox 9 onwards, the default version is 64 bit. Chapter D2 Modelbase and OxPack D2.1 Introduction OxPack allows for interactive use of a Modelbase-derived class in cooperation with OxMetrics. This can be achieved solely by adding Ox code – no special Windows programming is required (currently it only works under Windows, but Linux and Mac are on the horizon). In particular, it is possible to create dialogs, and define menu entries. The following three captures show the OxPack menus, after estimating a model with the Arfima package: 3 4 Chapter D2 Modelbase and OxPack Before a package can be used, it must be added using the Package menu. This menu is also used to choose a package to run. The items on the Model and Test menu are determined by the package. The menus are configured from the package through the SendMenu function. • Model/Formulate This brings up the Model Formulation dialog: The Arfima package uses OxPackSpecialDialog to show the OP FORMULATE di- alog. Modelbase uses SendVarStatus() in the package to determine the type of variables available to build the model, and SendSpecials() to add special vari- ables in the dialog (here they are: Constant, Trend and Seasonal, CSeasonal). • Model/Model Settings The model settings determine the remaining model specification, here: D2.1 Introduction 5 When the user selects Model Settings on the model menu (or automatically after successful formulation), OxPack calls ReceiveMenuChoice("OP SETTINGS"). • Model/Estimate When the user clicks on Estimate, OxPack first calls ReceiveData() and ReceiveModel(), to allow the package to extract the data and model formulation using the "OxPackGetData" function. (The package implements this function call as a string to avoid a link error when using the package directly from Ox.) Next, the Estimate function is called. • Model/Options Options refer to settings which may be less frequently changed. When OxPack calls ReceiveMenuChoice("OP OPTIONS"), the default Modelbase implementa- tion allows for the maximization options to be set. • Test menu The menu entries are determined from the return value of SendMenu("Test"). The package can again use dialogs to allow the user to choose options. 6 Chapter D2 Modelbase and OxPack D2.2 Examples The following sample code is in ox/samples/oxpack: • OxPackDlg Provides an example of all dialogs that can be used in the OxPack application. • BprobitEx Provides an example of a Modelbased package that implements an estimation pro- cedure (Probit), and a test menu.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    123 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us