Re: [fpc-pascal] FORTRAN from FreePascal

2017-11-13 Thread brian
On 11/13/2017 10:20 AM, Adriaan van Os wrote:
> brian wrote:
>> Anyone with any past experience here? It seems I have two choices, to
>> try to call the FORTRAN subroutines from FreePascal or to port the
>> FORTRAN code to Pascal, I'm looking for advice...
> 
> It is no problem calling FORTRAN from either C or FreePascal (or at
> least not on UNIX-like platforms like Mac OS X, havn't tried for
> Windows). The LAPACK package  for
> example (also installed in the Mac system software) is written in
> Fortran. Some key points:
> 
> 1. Lapack Fortran arrays are column-major (where column elements are
> contiguous in memory)
> 2. Lapack Fortran arrays are 1-base indexed
> 3. Lapack Fortran parameters are always passed by reference, even if
> they are value parameters
> 
> So, for example, DGETRF
> 
>   =
>   SUBROUTINE DGETRF( M, N, A, LDA, IPIV, INFO )
> *
> *  -- LAPACK computational routine (version 3.X) --
> *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
> *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG
> Ltd..--
> * November 2011
> *
> * .. Scalar Arguments ..
>   INTEGER    INFO, LDA, M, N
> * ..
> * .. Array Arguments ..
>   INTEGER    IPIV( * )
>   DOUBLE PRECISION   A( LDA, * )
> * ..
> 
> 
>  function dgetrf_
>    ( constref theNumRows  : LapackInt;
>  constref theNumColumns   : LapackInt;
>   theMatrixPtr    : LapackArrayOfDoublePtr;
>  constref theLeadingDimension : LapackInt;
>   thePivotIndicesPtr  : LapackArrayOfIntPtr;
>   var theInfo : LapackInt): LapackResult;
> cdecl; external;
> 
> where (it's just an example)
> 
>     LapackInt = Int32;
>     LapackLongBool    = Int32;
>     LapackResult  = Int32;
>     LapackDouble  = double;
>     LapackArrayOfIntPtr   = ^Int32;
>     LapackArrayOfLongBoolPtr  = ^Int32;
>     LapackArrayOfDoublePtr    = ^double;
> 
> The "constref" for value parameters makes sure they are passed by
> reference, which is what Fortram requires.
> 

Thanks, Adriaan, that's exactly what I needed. :)  I'm going to be
writing for a Debian platform (I should have mentioned that, the
original code is from a Unix minicomputer) so there hopefully
shouldn't be a problem. If I can just chunk up some of the FORTRAN
code and re-use the calculation routines (which I don't understand
anyway, the statistics are at a level that's over my head) then it
will make life a lot easier.


Brian.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] AggPas / PTCGraph dynamic memory allocation

2017-11-13 Thread James Richters
>> ClockBuffer_With_Time:=ClockBuffer_original;
>
>That seems fine.
>
>> AggClockbuffer^:=ClockBuffer_With_Time^+3*Sizeof(Longint);   //Set 
>> AggClockBuffer to be 3 Longints past ClockBuffer_with_time
>
>This seems wrong. Try changing that to the following:
>
> AggClockbuffer := ClockBuffer_With_Time + (3*Sizeof(Longint));

Now I have a new issue...  It's just failing with either return code 253 or 255 
 but no runtime error.. I put in some writeln's to see where the problem is.  
Here below my test program.  It executes the Writeln('5'); but not the 
Writeln('6') in between is 
 aggclock^.Text(2 ,19,FormatDateTime('hh:nn:ssam/pm',Now));  I moved 
this line up to where the aggclock^fillcolor commands are, and it fails up 
there too...

Any ideas?



{$mode objfpc}{$H+}

uses
  shlobj,
  ptcgraph,
  ptccrt,
  sysutils,
  agg_pixfmt_rgb_packed,
  agg_2D;

const
  RGB_WIDTH =2;
  Clock_W = 120;
  Clock_h = 40;

Var
   address1,address2  : longint;
   Newtime,Oldtime: Double;
   Bufsize: Longint;
   gd,gm  : smallint;
   aggClock   : Agg2D_ptr;
   Font2use,FontPath  : Array[0..MaxPathLen] of Char;
   clockbuffer_Original   : ^Byte;
   clockbuffer_with_time  : ^Byte;
   Aggclockbuffer : ^Byte;

Begin
   gd:=d16Bit;
   gm:=m800x600;
   ptcgraph.Initgraph(gd,gm,'');
   SHGetSpecialFolderPath(0,FontPath,CSIDL_FONTS,false);
   font2use:=FontPath+'\Lucon.ttf';
   bufSize:=ImageSize((GetMaxX-4)-Clock_W, 4 , GetMaxX-4, 4+Clock_H);
   GetMem(ClockBuffer_Original, bufSize);   { Allocate memory on heap }
   GetImage((GetMaxX-4)-Clock_W+1,  4, GetMaxX-4,  4+Clock_H-1, 
ClockBuffer_original^);
   ClockBuffer_With_Time:=ClockBuffer_original;
   Writeln('1');
   Putimage((GetMaxX-4)-Clock_W,  4, Clockbuffer_With_Time^, normalPut);
   Writeln('1.5');
   AggClockbuffer := ClockBuffer_With_Time + (3*Sizeof(Longint));
   Writeln('2');
   New(aggClock , Construct(@pixfmt_rgb565));
   aggClock^.attach(@AggClockbuffer,Clock_W, Clock_H, -Clock_W * RGB_WIDTH);
   aggclock^.Font(font2use ,12 );
   aggclock^.LineColor($FF ,$FF ,$00 );
   aggclock^.FillColor($FF ,$FF ,$60 );
   Writeln('3');

Repeat
   Newtime:=now;
   If Trunc(Newtime*346600)<>Trunc(Oldtime*345600) Then  //update every 1/4 
second
  Begin
 OldTime:=NewTime;
 Writeln('4');
 ClockBuffer_With_Time:=ClockBuffer_original;
 Writeln('5');
 aggclock^.Text(2 ,19,FormatDateTime('hh:nn:ssam/pm',Now));
 Writeln('6');
 Putimage((GetMaxX-4)-Clock_W,  4, Clockbuffer_With_Time^, normalPut);
 Writeln('7');
  End;
until KeyPressed;
End.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] FORTRAN from FreePascal

2017-11-13 Thread Adriaan van Os

brian wrote:

Anyone with any past experience here? It seems I have two choices, to
try to call the FORTRAN subroutines from FreePascal or to port the
FORTRAN code to Pascal, I'm looking for advice...


It is no problem calling FORTRAN from either C or FreePascal (or at least not on UNIX-like 
platforms like Mac OS X, havn't tried for Windows). The LAPACK package 
 for example (also installed in the Mac system software) is written 
in Fortran. Some key points:


1. Lapack Fortran arrays are column-major (where column elements are contiguous 
in memory)
2. Lapack Fortran arrays are 1-base indexed
3. Lapack Fortran parameters are always passed by reference, even if they are 
value parameters

So, for example, DGETRF

  =
  SUBROUTINE DGETRF( M, N, A, LDA, IPIV, INFO )
*
*  -- LAPACK computational routine (version 3.X) --
*  -- LAPACK is a software package provided by Univ. of Tennessee,--
*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
  INTEGERINFO, LDA, M, N
* ..
* .. Array Arguments ..
  INTEGERIPIV( * )
  DOUBLE PRECISION   A( LDA, * )
* ..


 function dgetrf_
   ( constref theNumRows  : LapackInt;
 constref theNumColumns   : LapackInt;
  theMatrixPtr: LapackArrayOfDoublePtr;
 constref theLeadingDimension : LapackInt;
  thePivotIndicesPtr  : LapackArrayOfIntPtr;
  var theInfo : LapackInt): LapackResult; cdecl; 
external;

where (it's just an example)

LapackInt = Int32;
LapackLongBool= Int32;
LapackResult  = Int32;
LapackDouble  = double;
LapackArrayOfIntPtr   = ^Int32;
LapackArrayOfLongBoolPtr  = ^Int32;
LapackArrayOfDoublePtr= ^double;

The "constref" for value parameters makes sure they are passed by reference, which is what Fortram 
requires.


Etcetera.

Regards,

Adriaan van Os




___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] FORTRAN from FreePascal

2017-11-13 Thread Mark Morgan Lloyd

On 13/11/17 13:30, brian wrote:

I need to try to put a user-friendly GUI and some graphical outputonto an old 
command-line FORTRAN number cruncher, and have beenprovided with around 130 KB 
of FORTRAN source code. A quick scan ofdocumentation seems to suggest that this 
is possible using gfortranand the C calling conventions (if someone knows 
differently, pleasesay so right now!) :)
My knowledge of FORTRAN-77 is sound, if rather rusty, but I knowalmost nothing 
about C programming, having been brought up as achemist before I was dragged 
across to programming (I learned toprogram on Algol-60, BASIC and FORTRAN-IV, 
yes, that long ago ): ).
Anyone with any past experience here? It seems I have two choices, totry to 
call the FORTRAN subroutines from FreePascal or to port theFORTRAN code to 
Pascal, I'm looking for advice...


If the FORTRAN can be called from C as distinct from being able to call 
C subroutines, then I'd have thought that you'd be able to replace the 
main part of the program (that reads the data cards or whatever) with 
something written in Pascal. That would potentially allow you to put 
together a UI using Lazarus etc.


Granted that various companies have long had translators from FORTRAN to 
ALGOL (particularly in the case of B who I don't think had a native 
compiler) or other languages, but I'd have thought that a full 
translation would be best avoided if possible.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] FORTRAN from FreePascal

2017-11-13 Thread brian
I need to try to put a user-friendly GUI and some graphical output
onto an old command-line FORTRAN number cruncher, and have been
provided with around 130 KB of FORTRAN source code. A quick scan of
documentation seems to suggest that this is possible using gfortran
and the C calling conventions (if someone knows differently, please
say so right now!) :)

My knowledge of FORTRAN-77 is sound, if rather rusty, but I know
almost nothing about C programming, having been brought up as a
chemist before I was dragged across to programming (I learned to
program on Algol-60, BASIC and FORTRAN-IV, yes, that long ago ): ).

Anyone with any past experience here? It seems I have two choices, to
try to call the FORTRAN subroutines from FreePascal or to port the
FORTRAN code to Pascal, I'm looking for advice...

Thanks,

Brian.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal