|
HowDoesRFortranWork
Explains how RFortran Works
How the RDCOM Module was createdThe module 'rdcom' in the file RFortran_COMInterface_IVF.f90 was created by pointing the 'Fortran Module Wizard' in Compaq to the file StatConnectorSrv.exe which was located in the installation directory of the rdcom server found here. The code generated respectively by the Intel and Compaq wizards is slightly different and as a result a tweak has been made to the IStatConnector_SetSymbol function so that it avoids a serious complication when using the Intel compiler. The reason for this module is to make sure that Fortran correctly passes information to the COM server - i.e. the module is a 'wrapper'. It is the lowest level module in the Fortran code. Many additional routines created by the Module Wizard were removed as they are not used. RDCOM and RCOMThere are two separate implementations in RFortran, one is referred to as RCOM and the other RDCOM, confusing, but it is not our terminology.
Rput and RgetAnother module, called RFortran_Rput_Rget, has been written on top of the rdcom wrapper module. The purpose of the RFortran_base module is to provide convenience for accessing R so the the user only needs to use the functions Rput(), Rget() and does not have to bother with details on how to pass different types of data. This module overloads the Rput and Rget functions so that a large variety of data types and shapes can be passed into R. There is a fair degree of complication in passing data into R, because it uses objects called 'variants' to pass any type of data. This is useful as it allows one interface to handle any type of data, but it means that the user has to package the data into the variant before passing it and then unpack it after retrieving data from R ... which is precisely what this module does. Support for Complex(4) complex(8) data types and array sizes above 3D is planned for the future. Please contact us if you require these features. Overhead penaltiesBecause data must be packed into variant objects, there are overhead penalties, a speed penalty and a memory penalty. The memory penalty of an Rput routine causes 2 additional copies of the array:
Bstrings and SafearraysThere is a complication in that Fortran strings and arrays are not conformable to the COM standard for strings and arrays, so functions have to be used to convert strings into Bstrings and arrays into safearrays before they are then packed into the variant object and passed over to R. The functions for Bstrings and safearrays (as well as variants) are located in the built-in modules dfcom/dfwinty (Compaq) ifcom/ifwinty (Intel) ... which is the reason why RFortran is restricted to these compilers. If you would like to know more about these features, then there is an excellent library of information on the web provided by a company called Canaima. Global VariablesThe R object and the variant data type used for passing are made global in the RFortran_base module, this means that only one copy of the R server can be used at any one time. If you have a need for multiple copies of R servers, please indicate this to us and we will address it. | |