From: Alan W. I. <ai...@us...> - 2007-02-26 00:52:17
|
Update of /cvsroot/plplot/plplot/bindings/ada In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3757/bindings/ada Added Files: CMakeLists.txt plplot.adb plplot.ads plplotthin.adb plplotthin.ads Log Message: Initial commit of an Ada example and Ada binding (donated by Jerry Bauck under the LGPL) to PLplot. Initial commit of rudimentary CMake build system support (supplied by AWI) for the Ada example and Ada binding. --- NEW FILE: plplot.adb --- with PLplotThin, Ada.Text_IO, Ada.Numerics.Long_Elementary_Functions, Ada.Strings.Unbounded, Ada.Unchecked_Conversion, Ada.Strings.Maps, Ada.Command_Line, System, System.Address_To_Access_Conversions, Interfaces.C.Pointers, Interfaces.C; use PLplotThin, Ada.Text_IO, Ada.Numerics.Long_Elementary_Functions, Ada.Strings.Unbounded, Interfaces.C; [...2783 lines suppressed...] -- before beginning normal plotting but AFTER any optional pre-initialization. -- The following lines are some examples of how the entire initialzation -- can be done here if the user wants to do so, and is willing to uncomment -- these lines and/or add new lines. -- plscompression should be called before plinit when it is needed. -- There should be a list of devices which use compression, and plscompression -- called conditioned on the current device being in that list. -- Optionally call plsetopt (Set_Command_Line_Option) before Initialize_Plotter. -- Parse_Command_Line_Arguments(1); -- Set_File_Family_Parameters(False); -- Default off; other args are don't-cares here. -- Set_Orientation(Landscape); -- Optional; before Initialize_Plotter if used. -- Initialize_Plotter; null; end PLplot; --- NEW FILE: plplot.ads --- with PLplotThin, System, Interfaces.C.Pointers, Ada.Strings.Unbounded, Ada.Strings.Maps; use PLplotThin, Ada.Strings.Unbounded; -- COMMENT THIS LINE IF YOUR COMPILER DOES NOT INCLUDE THESE -- DEFINITIONS, FOR EXAMPLE, IF IT IS NOT ADA 2005 WITH ANNEX G.3 COMPLIANCE. --with Ada.Numerics.Long_Real_Arrays; use Ada.Numerics.Long_Real_Arrays; package PLplot is -------------------------------------------------------------------------------- -- Types and constants for thick binding -- -------------------------------------------------------------------------------- [...1450 lines suppressed...] -- Does linear interpolation from singly dimensioned coord arrays. -- pltr1 procedure Plot_Transformation_1 (x_Grid, y_Grid : Long_Float; x_World, y_World : out Long_Float; Data_Pointer : PLpointer); -- Does linear interpolation from doubly dimensioned coord arrays -- (column dominant, as per normal C 2d arrays). -- pltr2 procedure Plot_Transformation_2 (x_Grid, y_Grid : Long_Float; x_World, y_World : out Long_Float; Data_Pointer : PLpointer); end PLplot; --- NEW FILE: CMakeLists.txt --- # bindings/ada/CMakeLists.txt ### Process this file with cmake to produce Makefile ### # Copyright (C) 2007 Alan W. Irwin # # This file is part of PLplot. # # PLplot is free software; you can redistribute it and/or modify # it under the terms of the GNU Library General Public License as published # by the Free Software Foundation; version 2 of the License. # # PLplot is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU Library General Public License # along with PLplot; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA if(ENABLE_ada) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libplplotada${LIB_TAG}.so COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplot.adb ${CMAKE_CURRENT_BINARY_DIR}/plplot.adb COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplot.ads ${CMAKE_CURRENT_BINARY_DIR}/plplot.ads COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplotthin.adb ${CMAKE_CURRENT_BINARY_DIR}/plplotthin.adb COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplotthin.ads ${CMAKE_CURRENT_BINARY_DIR}/plplotthin.ads COMMAND ${GNATMAKE_EXECUTABLE} -c -fPIC plplot.adb COMMAND gcc -fPIC -shared ${CMAKE_CURRENT_BINARY_DIR}/plplot.o ${CMAKE_CURRENT_BINARY_DIR}/plplotthin.o -Wl,-soname,libplplotada${LIB_TAG}.so.${plplotada_SOVERSION} -Wl,-rpath,${CMAKE_BINARY_DIR}/src -o libplplotada${LIB_TAG}.so.${plplotada_VERSION} -L${GNAT_DIR} -lgnat -L${CMAKE_BINARY_DIR}/src -lplplot${LIB_TAG} COMMAND ${CMAKE_COMMAND} -E cmake_symlink_library libplplotada${LIB_TAG}.so.${plplotada_VERSION} libplplotada${LIB_TAG}.so.${plplotada_SOVERSION} libplplotada${LIB_TAG}.so # COMMAND # rm -f # ${CMAKE_CURRENT_BINARY_DIR}/plplot.o # ${CMAKE_CURRENT_BINARY_DIR}/plplotthin.o DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/plplot.adb ${CMAKE_CURRENT_SOURCE_DIR}/plplotthin.adb WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) add_custom_target(plplotada${LIB_TAG} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libplplotada${LIB_TAG}.so ) # set(plplotthinada{LIB_TAG}_LIB_SRCS # ${CMAKE_CURRENT_BINARY_DIR}/plplotthin.o # ) # add_library(plplotthinada${LIB_TAG} ${plplotthinada${LIB_TAG}_LIB_SRCS}) # target_link_libraries(plplotthinada${LIB_TAG} plplot${LIB_TAG}) # get_target_property(LIB_INSTALL_RPATH plplot${LIB_TAG} INSTALL_RPATH) # set_target_properties(plplotthinada${LIB_TAG} # PROPERTIES # SOVERSION ${plplotthinada_SOVERSION} # VERSION ${plplotthinada_VERSION} # INSTALL_RPATH "${LIB_INSTALL_RPATH}" # INSTALL_NAME_DIR "${LIB_DIR}" # ) # install(TARGETS plplotthinada${LIB_TAG} # ARCHIVE DESTINATION ${LIB_DIR} # LIBRARY DESTINATION ${LIB_DIR} # RUNTIME DESTINATION ${BIN_DIR} # ) endif(ENABLE_ada) --- NEW FILE: plplotthin.ads --- -- Copyright (C) 1992 Maurice J. LeBrun, Geoff Furnish, Tony Richardson. -- Copyright (C) 2004 Alan W. Irwin -- Copyright (C) 2004 Rafael Laboissiere -- Copyright (C) 2004 Andrew Ross -- This file is part of PLplot. -- PLplot is free software; you can redistribute it and/or modify -- it under the terms of the GNU Library General Public License as published -- by the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- PLplot is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU Library General Public License for more details. -- You should have received a copy of the GNU Library General Public License -- along with PLplot; if not, write to the Free Software [...1569 lines suppressed...] -- Identity transformation. procedure pltr0(x, y : PLFLT; tx, ty : out PLFLT; pltr_data : PLpointer); pragma Import(Ada, pltr0, "pltr0"); -- fix this; why need "Ada" convention? -- Does linear interpolation from singly dimensioned coord arrays. procedure pltr1(x, y : PLFLT; tx, ty : out PLFLT; pltr_data : PLpointer); pragma Import(Ada, pltr1, "pltr1"); -- fix this; why need "Ada" convention? -- Does linear interpolation from doubly dimensioned coord arrays -- (column dominant, as per normal C 2d arrays). procedure pltr2(x, y : PLFLT; tx, ty : out PLFLT; pltr_data : PLpointer); pragma Import(C, pltr2, "pltr2"); end PLplotThin; --- NEW FILE: plplotthin.adb --- with Ada.Text_IO; use Ada.Text_IO; package body PLplotThin is -- Find minimum in a 1D array. function Vector_Min(x : Real_Vector) return Long_Float is Result : Long_Float; begin Result := x(x'First); for i in x'First+1..x'Last loop Result := Long_Float'min(Result, x(i)); end loop; return Result; end Vector_Min; -- Find minimum and its location in a 1D array. procedure Vector_Min(x : Real_Vector; The_Minimum : out Long_Float; Location_Of_Min : out Integer) is begin The_Minimum := x(x'First); Location_Of_Min := x'First; for i in x'First+1..x'Last loop if x(i) < x(i - 1) then -- Finds the first of repeated mins. The_Minimum := x(i); Location_Of_Min := i; end if; end loop; end Vector_Min; -- Find maximum in a 1D array. function Vector_Max(x : Real_Vector) return Long_Float is Result : Long_Float; begin Result := x(x'First); for i in x'First+1..x'Last loop Result := Long_Float'max(Result, x(i)); end loop; return Result; end Vector_Max; -- Find maximum and its location in a 1D array. procedure Vector_Max(x : Real_Vector; The_Maximum : out Long_Float; Location_Of_Max : out Integer) is begin The_Maximum := x(x'First); Location_Of_Max := x'First; for i in x'First+1..x'Last loop if x(i) > x(i - 1) then -- Finds the first of repeated maxes. The_Maximum := x(i); Location_Of_Max := i; end if; end loop; end Vector_Max; -- Find minimum in a 2D array. function Matrix_Min(x : Real_Matrix) return Long_Float is Result : Long_Float := Long_Float'large; begin for j in x'First(2)..x'Last(2) loop for i in x'First(1)..x'Last(1) loop Result := Long_Float'Min(Result, x(i, j)); end loop; end loop; return Result; end Matrix_Min; -- Find maximum in a 2D array. function Matrix_Max(x : Real_Matrix) return Long_Float is Result : Long_Float := Long_Float'small; begin for j in x'First(2)..x'Last(2) loop for i in x'First(1)..x'Last(1) loop Result := Long_Float'Max(Result, x(i, j)); end loop; end loop; return Result; end Matrix_Max; -------------------------------------------------------------------------------- -- Utility for passing matrices to C -- -------------------------------------------------------------------------------- -- Take a Real_Matrix as defined in Ada.Numerics.Generic_Real_Arrays -- and its instances and produce a 1D array of access variables to the -- element located at the first column of each row. This is then suitable -- for passing to an external C subroutine which expects a "2D array" in the -- form of an array of pointers to "1D arrays" which in turn are pointers to -- the first element of each row in C-land. This currently uses the GNAT -- attribute Unrestricted_Access which makes it non-portable but allows the -- accessing of the matrix elements without aliasing them, which is useful -- because the Ada 2005 vector and matrix types are non-aliased. -- For more about the Unrestricted_Access attribute, see Implementation -- Defined Attributes in the GNAT Reference Manual. -- TO-DO: Write a function which accepts x(Index, Index_Of_First_Column) -- as an argument and returns a "proper" access variable using the method -- discussed in "Ada as a Second Language," Second Edition, by Norman H. -- Cohen, Section 19.3, for portability. This should remove GNAT dependence. function Matrix_To_Pointers(x : Real_Matrix) return Long_Float_Pointer_Array is Index_Of_First_Column : Integer := x'First(2); x_As_Pointers : Long_Float_Pointer_Array (x'range(1)); begin for Index in x'range(1) loop x_As_Pointers(Index) := x(Index, Index_Of_First_Column)'Unrestricted_Access; end loop; return x_As_Pointers; end Matrix_To_Pointers; end PLplotThin; |