[fpc-pascal] DLL and SO with Free Pascal

Jilani Khaldi jilani.khaldi1 at virgilio.it
Sun Apr 9 13:56:47 CEST 2006


Hi All,
excuse me if I have included the code, but I really need help.
I have:
1) spa.c (coded in ANSI C) which compiled with mingw produces "spa.dll", 
and compiled with gcc produces a "libspa.so" under Linux.
2) myDelphi.dpr (a delphi project) uses "spa.dll" and works fine.
3) myFpc.pp (a FP project under windows) uses "spa.dll" and works fine.
4) myC.c (a C project under Linux) uses "libspa.so" and works fine.
5) myFpc.pp (a FP project under Linux -- same code as 3)  uses 
"libspa.so" gives many troubles.

This is the C header file:

#ifndef __solar_position_algorithm_header
#define __solar_position_algorithm_header
//enumeration for function codes to select desired final outputs from SPA
enum {
    SPA_ZA,           //calculate zenith and azimuth
    SPA_ZA_INC,       //calculate zenith, azimuth, and incidence
    SPA_ZA_RTS,       //calculate zenith, azimuth, and sun 
rise/transit/set values
    SPA_ALL,          //calculate all SPA output values
};

typedef struct
{
    //----------------------INPUT VALUES------------------------

    int year;            // 4-digit year,    valid range: -2000 to 6000, 
error code: 1
    int month;           // 2-digit month,         valid range: 1 to 12, 
error code: 2
    int day;             // 2-digit day,           valid range: 1 to 31, 
error code: 3
    int hour;            // Observer local hour,   valid range: 0 to 24, 
error code: 4
    int minute;          // Observer local minute, valid range: 0 to 59, 
error code: 5
    int second;          // Observer local second, valid range: 0 to 59, 
error code: 6

    float delta_t;       // Difference between earth rotation time and 
terrestrial time
                         //     (from observation)
                         // valid range: -8000 to 8000 seconds, error 
code: 7

    float timezone;      // Observer time zone (negative west of Greenwich)
                         // valid range: -12   to   12 hours,   error 
code: 8

    float longitude;     // Observer longitude (negative west of Greenwich)
                         // valid range: -180  to  180 degrees, error 
code: 9

    float latitude;      // Observer latitude (negative south of equator)
                         // valid range: -90   to   90 degrees, error 
code: 10

    float elevation;     // Observer elevation [meters]
                         // valid range: -6500000 or higher meters,    
error code: 11

    float pressure;      // Annual average local pressure [millibars]
                         // valid range:    0 to 5000 millibars,       
error code: 12

    float temperature;   // Annual average local temperature [degrees 
Celsius]
                         // valid range: -273 to 6000 degrees Celsius, 
error code; 13

    float slope;         // Surface slope (measured from the horizontal 
plane)
                         // valid range: -360 to 360 degrees, error code: 14

    float azm_rotation;  // Surface azimuth rotation (measured from 
south to projection of
                         //     surface normal on horizontal plane, 
negative west)
                         // valid range: -360 to 360 degrees, error code: 15

    float atmos_refract; // Atmospheric refraction at sunrise and sunset 
(0.5667 deg is typical)
                         // valid range: -10  to  10 degrees, error code: 16

    int function;        // Switch to choose functions for desired 
output (from enumeration)

    //-----------------Intermediate OUTPUT VALUES--------------------

    double jd;          //Julian day
    double jc;          //Julian century

    double jde;         //Julian ephemeris day
    double jce;         //Julian ephemeris century
    double jme;         //Julian ephemeris millennium

    double l;           //earth heliocentric longitude [degrees]
    double b;           //earth heliocentric latitude [degrees]
    double r;           //earth radius vector [Astronomical Units, AU]

    double theta;       //geocentric longitude [degrees]
    double beta;        //geocentric latitude [degrees]

    double x0;          //mean elongation (moon-sun) [degrees]
    double x1;          //mean anomaly (sun) [degrees]
    double x2;          //mean anomaly (moon) [degrees]
    double x3;          //argument latitude (moon) [degrees]
    double x4;          //ascending longitude (moon) [degrees]

    double del_psi;     //nutation longitude [degrees]
    double del_epsilon; //nutation obliquity [degrees]
    double epsilon0;    //ecliptic mean obliquity [arc seconds]
    double epsilon;     //ecliptic true obliquity  [degrees]

    double del_tau;     //aberration correction [degrees]
    double lamda;       //apparent sun longitude [degrees]
    double nu0;         //Greenwich mean sidereal time [degrees]
    double nu;          //Greenwich sidereal time [degrees]

    double alpha;       //geocentric sun right ascension [degrees]
    double delta;       //geocentric sun declination [degrees]

    double h;           //observer hour angle [degrees]
    double xi;          //sun equatorial horizontal parallax [degrees]
    double del_alpha;   //sun right ascension parallax [degrees]
    double delta_prime; //topocentric sun declination [degrees]
    double alpha_prime; //topocentric sun right ascension [degrees]
    double h_prime;     //topocentric local hour angle [degrees]

    double e0;          //topocentric elevation angle (uncorrected) 
[degrees]
    double del_e;       //atmospheric refraction correction [degrees]
    double e;           //topocentric elevation angle (corrected) [degrees]

    double eot;         //equation of time [minutes]
    double srha;        //sunrise hour angle [degrees]
    double ssha;        //sunset hour angle [degrees]
    double sta;         //sun transit altitude [degrees]

    //---------------------Final OUTPUT VALUES------------------------

    double zenith;      //topocentric zenith angle [degrees]
    double azimuth180;  //topocentric azimuth angle (westward from 
south) [-180 to 180 degrees]
    double azimuth;     //topocentric azimuth angle (eastward from 
north) [   0 to 360 degrees]
    double incidence;   //surface incidence angle [degrees]

    double suntransit;  //local sun transit time (or solar noon) 
[fractional hour]
    double sunrise;     //local sunrise time (+/- 30 seconds) 
[fractional hour]
    double sunset;      //local sunset time (+/- 30 seconds) [fractional 
hour]

} spa_data;

//Calculate SPA output values (in structure) based on input values 
passed in structure
int spa_calculate(spa_data *spa);
#endif

and this is the Pascal unit;
unit spaUnit;

interface
uses
  SysUtils;

type
//enumeration for function codes to select desired final outputs from SPA
  enum =(
    SPA_ZA,           //calculate zenith and azimuth
    SPA_ZA_INC,       //calculate zenith, azimuth, and incidence
    SPA_ZA_RTS,       //calculate zenith, azimuth, and sun 
rise/transit/set values
    SPA_ALL          //calculate all SPA output values
);

PSpaData = ^SpaData;
SpaData = record
    //----------------------INPUT VALUES------------------------

    year: integer;            // 4-digit year,    valid range: -2000 to 
6000, error code: 1
    month: integer;           // 2-digit month,         valid range: 1 
to 12, error code: 2
    day: integer;             // 2-digit day,           valid range: 1 
to 31, error code: 3
    hour: integer;            // Observer local hour,   valid range: 0 
to 24, error code: 4
    minute: integer;          // Observer local minute, valid range: 0 
to 59, error code: 5
    second: integer;          // Observer local second, valid range: 0 
to 59, error code: 6

    delta_t: single;       // Difference between earth rotation time and 
terrestrial time
                         //     (from observation)
                         // valid range: -8000 to 8000 seconds, error 
code: 7

    timezone: single;      // Observer time zone (negative west of 
Greenwich)
                         // valid range: -12   to   12 hours,   error 
code: 8

    longitude: single;     // Observer longitude (negative west of 
Greenwich)
                         // valid range: -180  to  180 degrees, error 
code: 9

    latitude: single;      // Observer latitude (negative south of equator)
                         // valid range: -90   to   90 degrees, error 
code: 10

    elevation: single;     // Observer elevation [meters]
                         // valid range: -6500000 or higher meters,    
error code: 11

    pressure: single;      // Annual average local pressure [millibars]
                         // valid range:    0 to 5000 millibars,       
error code: 12

    temperature: single;   // Annual average local temperature [degrees 
Celsius]
                         // valid range: -273 to 6000 degrees Celsius, 
error code; 13

    slope: single;         // Surface slope (measured from the 
horizontal plane)
                         // valid range: -360 to 360 degrees, error code: 14

    azm_rotation: single;  // Surface azimuth rotation (measured from 
south to projection of
                         //     surface normal on horizontal plane, 
negative west)
                         // valid range: -360 to 360 degrees, error code: 15

    atmos_refract: single; // Atmospheric refraction at sunrise and 
sunset (0.5667 deg is typical)
                         // valid range: -10  to  10 degrees, error code: 16

    AFunction: integer;        // Switch to choose functions for desired 
output (from enumeration)

    //-----------------Intermediate OUTPUT VALUES--------------------

    jd: double;          //Julian day
    jc: double;          //Julian century

    jde: double;         //Julian ephemeris day
    jce: double;         //Julian ephemeris century
    jme: double;         //Julian ephemeris millennium

    l: double;           //earth heliocentric longitude [degrees]
    b: double;           //earth heliocentric latitude [degrees]
    r: double;           //earth radius vector [Astronomical Units, AU]

    theta: double;       //geocentric longitude [degrees]
    beta: double;        //geocentric latitude [degrees]

    x0: double;          //mean elongation (moon-sun) [degrees]
    x1: double;          //mean anomaly (sun) [degrees]
    x2: double;          //mean anomaly (moon) [degrees]
    x3: double;          //argument latitude (moon) [degrees]
    x4: double;          //ascending longitude (moon) [degrees]

    del_psi: double;     //nutation longitude [degrees]
    del_epsilon: double; //nutation obliquity [degrees]
    epsilon0: double;    //ecliptic mean obliquity [arc seconds]
    epsilon: double;     //ecliptic true obliquity  [degrees]

    del_tau: double;     //aberration correction [degrees]
    lamda: double;       //apparent sun longitude [degrees]
    nu0: double;         //Greenwich mean sidereal time [degrees]
    nu: double;          //Greenwich sidereal time [degrees]

    alpha: double;       //geocentric sun right ascension [degrees]
    delta: double;       //geocentric sun declination [degrees]

    h: double;           //observer hour angle [degrees]
    xi: double;          //sun equatorial horizontal parallax [degrees]
    del_alpha: double;   //sun right ascension parallax [degrees]
    delta_prime: double; //topocentric sun declination [degrees]
    alpha_prime: double; //topocentric sun right ascension [degrees]
    h_prime: double;     //topocentric local hour angle [degrees]

    e0: double;          //topocentric elevation angle (uncorrected) 
[degrees]
    del_e: double;       //atmospheric refraction correction [degrees]
    e: double;           //topocentric elevation angle (corrected) [degrees]

    eot: double;         //equation of time [minutes]
    srha: double;        //sunrise hour angle [degrees]
    ssha: double;        //sunset hour angle [degrees]
    sta: double;         //sun transit altitude [degrees]

    //---------------------Final OUTPUT VALUES------------------------

    zenith: double;      //topocentric zenith angle [degrees]
    azimuth180: double;  //topocentric azimuth angle (westward from 
south) [-180 to 180 degrees]
    azimuth: double;     //topocentric azimuth angle (eastward from 
north) [   0 to 360 degrees]
    incidence: double;   //surface incidence angle [degrees]

    suntransit: double;  //local sun transit time (or solar noon) 
[fractional hour]
    sunrise: double;     //local sunrise time (+/- 30 seconds) 
[fractional hour]
    sunset: double;      //local sunset time (+/- 30 seconds) 
[fractional hour]
end;

const
  spaDLL = 'spa.dll';

//Calculate SPA output values (in structure) based on input values 
passed in structure
function spa_calculate(PRec: PSpaData): integer; cdecl; external spaDLL;

implementation

end.

--
Jilani KHALDI
http://jkhaldi.oltrelinux.com




More information about the fpc-pascal mailing list