WeixiangYan/CodeTransOcean huggingface dataset:
Task: Shoelace formula for polygonal area







Python: >>> def area_by_shoelace(x, y):
    "Assumes x,y points go around the polygon in one direction"
    return abs( sum(i * j for i, j in zip(x,             y[1:] + y[:1]))
               -sum(i * j for i, j in zip(x[1:] + x[:1], y            ))) / 2

>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*points)
>>> area_by_shoelace(x, y)
30.0
>>>





Ada: with Ada.Text_IO;

procedure Shoelace_Formula_For_Polygonal_Area
is
   type Point is record
      x, y : Float;
   end record;
   
   type Polygon is array (Positive range <>) of Point;
   
   function Shoelace(input : in Polygon) return Float
   is
      sum_1 : Float := 0.0;
      sum_2 : Float := 0.0;
      tmp : constant Polygon := input & input(input'First);
   begin
      for I in tmp'First .. tmp'Last - 1 loop
         sum_1 := sum_1 + tmp(I).x * tmp(I+1).y;
         sum_2 := sum_2 + tmp(I+1).x * tmp(I).y;
      end loop;
      return abs(sum_1 - sum_2) / 2.0;
   end Shoelace;
   
   my_polygon : constant Polygon :=
     ((3.0, 4.0),
      (5.0, 11.0),
      (12.0, 8.0),
      (9.0, 5.0),
      (5.0, 6.0));
begin
   Ada.Text_IO.Put_Line(Shoelace(my_polygon)'Img);
end Shoelace_Formula_For_Polygonal_Area;
Task: Shoelace formula for polygonal area








VB: Option Base 1
Public Enum axes
    u = 1
    v
End Enum
Private Function shoelace(s As Collection) As Double
    Dim t As Double
    If s.Count > 2 Then
        s.Add s(1)
        For i = 1 To s.Count - 1
            t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
        Next i
    End If
    shoelace = Abs(t) / 2
End Function
 
Public Sub polygonal_area()
    Dim task() As Variant
    task = [{3,4;5,11;12,8;9,5;5,6}]
    Dim tcol As New Collection
    For i = 1 To UBound(task)
        tcol.Add Array(task(i, u), task(i, v))
    Next i
    Debug.Print shoelace(tcol)
End Sub




Ada: with Ada.Text_IO;

procedure Shoelace_Formula_For_Polygonal_Area
is
   type Point is record
      x, y : Float;
   end record;
   
   type Polygon is array (Positive range <>) of Point;
   
   function Shoelace(input : in Polygon) return Float
   is
      sum_1 : Float := 0.0;
      sum_2 : Float := 0.0;
      tmp : constant Polygon := input & input(input'First);
   begin
      for I in tmp'First .. tmp'Last - 1 loop
         sum_1 := sum_1 + tmp(I).x * tmp(I+1).y;
         sum_2 := sum_2 + tmp(I+1).x * tmp(I).y;
      end loop;
      return abs(sum_1 - sum_2) / 2.0;
   end Shoelace;
   
   my_polygon : constant Polygon :=
     ((3.0, 4.0),
      (5.0, 11.0),
      (12.0, 8.0),
      (9.0, 5.0),
      (5.0, 6.0));
begin
   Ada.Text_IO.Put_Line(Shoelace(my_polygon)'Img);
end Shoelace_Formula_For_Polygonal_Area;
Task: Shoelace formula for polygonal area

C: #include<stdlib.h>
#include<stdio.h>
#include<math.h>

typedef struct{
	double x,y;
}point;

double shoelace(char* inputFile){
	int i,numPoints;
	double leftSum = 0,rightSum = 0;
	
	point* pointSet;
	FILE* fp = fopen(inputFile,"r");
	
	fscanf(fp,"%d",&numPoints);
	
	pointSet = (point*)malloc((numPoints + 1)*sizeof(point));
	
	for(i=0;i<numPoints;i++){
		fscanf(fp,"%lf %lf",&pointSet[i].x,&pointSet[i].y);
	}
	
	fclose(fp);
	
	pointSet[numPoints] = pointSet[0];
	
	for(i=0;i<numPoints;i++){
		leftSum += pointSet[i].x*pointSet[i+1].y;
		rightSum += pointSet[i+1].x*pointSet[i].y;
	}
	
	free(pointSet);
	
	return 0.5*fabs(leftSum - rightSum);
}

int main(int argC,char* argV[])
{
	if(argC==1)
		printf("\nUsage : %s <full path of polygon vertices file>",argV[0]);
	
	else
		printf("The polygon area is %lf square units.",shoelace(argV[1]));
	
	return 0;
}
Task: Shoelace formula for polygonal area



C#: using System;
using System.Collections.Generic;

namespace ShoelaceFormula {
    using Point = Tuple<double, double>;

    class Program {
        static double ShoelaceArea(List<Point> v) {
            int n = v.Count;
            double a = 0.0;
            for (int i = 0; i < n - 1; i++) {
                a += v[i].Item1 * v[i + 1].Item2 - v[i + 1].Item1 * v[i].Item2;
            }
            return Math.Abs(a + v[n - 1].Item1 * v[0].Item2 - v[0].Item1 * v[n - 1].Item2) / 2.0;
        }

        static void Main(string[] args) {
            List<Point> v = new List<Point>() {
                new Point(3,4),
                new Point(5,11),
                new Point(12,8),
                new Point(9,5),
                new Point(5,6),
            };
            double area = ShoelaceArea(v);
            Console.WriteLine("Given a polygon with vertices [{0}],", string.Join(", ", v));
            Console.WriteLine("its area is {0}.", area);
        }
    }
}
Task: Shoelace formula for polygonal area


C++: #include <iostream>
#include <tuple>
#include <vector>

using namespace std;

double shoelace(vector<pair<double, double>> points) {
	double leftSum = 0.0;
	double rightSum = 0.0;

	for (int i = 0; i < points.size(); ++i) {
		int j = (i + 1) % points.size();
		leftSum  += points[i].first * points[j].second;
		rightSum += points[j].first * points[i].second;
	}

	return 0.5 * abs(leftSum - rightSum);
}

void main() {
	vector<pair<double, double>> points = {
		make_pair( 3,  4),
		make_pair( 5, 11),
		make_pair(12,  8),
		make_pair( 9,  5),
		make_pair( 5,  6),
	};

	auto ans = shoelace(points);
	cout << ans << endl;
}
Task: Shoelace formula for polygonal area





Java: import java.util.List;

public class ShoelaceFormula {
    private static class Point {
        int x, y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return String.format("(%d, %d)", x, y);
        }
    }

    private static double shoelaceArea(List<Point> v) {
        int n = v.size();
        double a = 0.0;
        for (int i = 0; i < n - 1; i++) {
            a += v.get(i).x * v.get(i + 1).y - v.get(i + 1).x * v.get(i).y;
        }
        return Math.abs(a + v.get(n - 1).x * v.get(0).y - v.get(0).x * v.get(n - 1).y) / 2.0;
    }

    public static void main(String[] args) {
        List<Point> v = List.of(
            new Point(3, 4),
            new Point(5, 11),
            new Point(12, 8),
            new Point(9, 5),
            new Point(5, 6)
        );
        double area = shoelaceArea(v);
        System.out.printf("Given a polygon with vertices %s,%n", v);
        System.out.printf("its area is %f,%n", area);
    }
}
Task: Shoelace formula for polygonal area







Python: >>> def area_by_shoelace(x, y):
    "Assumes x,y points go around the polygon in one direction"
    return abs( sum(i * j for i, j in zip(x,             y[1:] + y[:1]))
               -sum(i * j for i, j in zip(x[1:] + x[:1], y            ))) / 2

>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*points)
>>> area_by_shoelace(x, y)
30.0
>>>
Task: Shoelace formula for polygonal area








VB: Option Base 1
Public Enum axes
    u = 1
    v
End Enum
Private Function shoelace(s As Collection) As Double
    Dim t As Double
    If s.Count > 2 Then
        s.Add s(1)
        For i = 1 To s.Count - 1
            t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
        Next i
    End If
    shoelace = Abs(t) / 2
End Function
 
Public Sub polygonal_area()
    Dim task() As Variant
    task = [{3,4;5,11;12,8;9,5;5,6}]
    Dim tcol As New Collection
    For i = 1 To UBound(task)
        tcol.Add Array(task(i, u), task(i, v))
    Next i
    Debug.Print shoelace(tcol)
End Sub
Task: Shoelace formula for polygonal area




Go: package main

import "fmt"

type point struct{ x, y float64 }

func shoelace(pts []point) float64 {
    sum := 0.
    p0 := pts[len(pts)-1]
    for _, p1 := range pts {
        sum += p0.y*p1.x - p0.x*p1.y
        p0 = p1
    }
    return sum / 2
}

func main() {
    fmt.Println(shoelace([]point{{3, 4}, {5, 11}, {12, 8}, {9, 5}, {5, 6}}))
}
Task: Shoelace formula for polygonal area



C#: using System;
using System.Collections.Generic;

namespace ShoelaceFormula {
    using Point = Tuple<double, double>;

    class Program {
        static double ShoelaceArea(List<Point> v) {
            int n = v.Count;
            double a = 0.0;
            for (int i = 0; i < n - 1; i++) {
                a += v[i].Item1 * v[i + 1].Item2 - v[i + 1].Item1 * v[i].Item2;
            }
            return Math.Abs(a + v[n - 1].Item1 * v[0].Item2 - v[0].Item1 * v[n - 1].Item2) / 2.0;
        }

        static void Main(string[] args) {
            List<Point> v = new List<Point>() {
                new Point(3,4),
                new Point(5,11),
                new Point(12,8),
                new Point(9,5),
                new Point(5,6),
            };
            double area = ShoelaceArea(v);
            Console.WriteLine("Given a polygon with vertices [{0}],", string.Join(", ", v));
            Console.WriteLine("its area is {0}.", area);
        }
    }
}








Fortran:       DOUBLE PRECISION FUNCTION AREA(N,P)	
C   Uses the mid-point rule for integration. Consider the line joining (x1,y1) to (x2,y2)
C The area under that line (down to the x-axis) is the y-span midpoint (y1 + y2)/2 times the width (x2 - x1)
C This is the trapezoidal rule for a single interval, and follows from simple geometry.
C Now consider a sequence of such points heading in the +x direction: each successive interval's area is positive.
C Follow with a sequence of points heading in the -x direction, back to the first point: their areas are all negative.
C The resulting sum is the area below the +x sequence and above the -x sequence: the area of the polygon.
C   The point sequence can wobble as it wishes and can meet the other side, but it must not cross itself
c as would be done in a figure 8 drawn with a crossover instead of a meeting.
C   A clockwise traversal (as for an island) gives a positive area; use anti-clockwise for a lake.
       INTEGER N		
       DOUBLE COMPLEX P(N)	
       DOUBLE COMPLEX PP,PC	
       DOUBLE COMPLEX W		
       DOUBLE PRECISION A	
       INTEGER I		
        IF (N.LT.3) STOP "Area: at least three points are needed
        W = (P(1) + P(N/3) + P(2*N/3))/3	
        W = SUM(P(1:N) - W)/N + W	
        A = 0			
        PC = P(N) - W		
        DO I = 1,N		
          PP = PC			
          PC = P(I) - W			
          A = (DIMAG(PC) + DIMAG(PP))*(DBLE(PC) - DBLE(PP)) + A	
        END DO			
        AREA = A/2		
      END FUNCTION AREA		

      DOUBLE PRECISION FUNCTION AREASL(N,P)	
       INTEGER N		
       DOUBLE COMPLEX P(N)	
       DOUBLE PRECISION A	
        A = SUM(DBLE(P(1:N - 1)*DIMAG(P(2:N)))) + DBLE(P(N))*DIMAG(P(1))
     1    - SUM(DBLE(P(2:N)*DIMAG(P(1:N - 1)))) - DBLE(P(1))*DIMAG(P(N))
        AREASL = A/2		
      END FUNCTION AREASL	

      INTEGER ENUFF
      DOUBLE PRECISION AREA,AREASL	
      DOUBLE PRECISION A1,A2		
      PARAMETER (ENUFF = 5)		
      DOUBLE COMPLEX POINT(ENUFF)	
      DATA POINT/(3D0,4D0),(5D0,11D0),(12D0,8D0),(9D0,5D0),(5D0,6D0)/	

      WRITE (6,*) POINT
      A1 = AREA(5,POINT)
      A2 = AREASL(5,POINT)
      WRITE (6,*) "A=",A1,A2
      END
Task: Shoelace formula for polygonal area


C++: #include <iostream>
#include <tuple>
#include <vector>

using namespace std;

double shoelace(vector<pair<double, double>> points) {
	double leftSum = 0.0;
	double rightSum = 0.0;

	for (int i = 0; i < points.size(); ++i) {
		int j = (i + 1) % points.size();
		leftSum  += points[i].first * points[j].second;
		rightSum += points[j].first * points[i].second;
	}

	return 0.5 * abs(leftSum - rightSum);
}

void main() {
	vector<pair<double, double>> points = {
		make_pair( 3,  4),
		make_pair( 5, 11),
		make_pair(12,  8),
		make_pair( 9,  5),
		make_pair( 5,  6),
	};

	auto ans = shoelace(points);
	cout << ans << endl;
}









Fortran:       DOUBLE PRECISION FUNCTION AREA(N,P)	
C   Uses the mid-point rule for integration. Consider the line joining (x1,y1) to (x2,y2)
C The area under that line (down to the x-axis) is the y-span midpoint (y1 + y2)/2 times the width (x2 - x1)
C This is the trapezoidal rule for a single interval, and follows from simple geometry.
C Now consider a sequence of such points heading in the +x direction: each successive interval's area is positive.
C Follow with a sequence of points heading in the -x direction, back to the first point: their areas are all negative.
C The resulting sum is the area below the +x sequence and above the -x sequence: the area of the polygon.
C   The point sequence can wobble as it wishes and can meet the other side, but it must not cross itself
c as would be done in a figure 8 drawn with a crossover instead of a meeting.
C   A clockwise traversal (as for an island) gives a positive area; use anti-clockwise for a lake.
       INTEGER N		
       DOUBLE COMPLEX P(N)	
       DOUBLE COMPLEX PP,PC	
       DOUBLE COMPLEX W		
       DOUBLE PRECISION A	
       INTEGER I		
        IF (N.LT.3) STOP "Area: at least three points are needed
        W = (P(1) + P(N/3) + P(2*N/3))/3	
        W = SUM(P(1:N) - W)/N + W	
        A = 0			
        PC = P(N) - W		
        DO I = 1,N		
          PP = PC			
          PC = P(I) - W			
          A = (DIMAG(PC) + DIMAG(PP))*(DBLE(PC) - DBLE(PP)) + A	
        END DO			
        AREA = A/2		
      END FUNCTION AREA		

      DOUBLE PRECISION FUNCTION AREASL(N,P)	
       INTEGER N		
       DOUBLE COMPLEX P(N)	
       DOUBLE PRECISION A	
        A = SUM(DBLE(P(1:N - 1)*DIMAG(P(2:N)))) + DBLE(P(N))*DIMAG(P(1))
     1    - SUM(DBLE(P(2:N)*DIMAG(P(1:N - 1)))) - DBLE(P(1))*DIMAG(P(N))
        AREASL = A/2		
      END FUNCTION AREASL	

      INTEGER ENUFF
      DOUBLE PRECISION AREA,AREASL	
      DOUBLE PRECISION A1,A2		
      PARAMETER (ENUFF = 5)		
      DOUBLE COMPLEX POINT(ENUFF)	
      DATA POINT/(3D0,4D0),(5D0,11D0),(12D0,8D0),(9D0,5D0),(5D0,6D0)/	

      WRITE (6,*) POINT
      A1 = AREA(5,POINT)
      A2 = AREASL(5,POINT)
      WRITE (6,*) "A=",A1,A2
      END
Task: Shoelace formula for polygonal area

C: #include<stdlib.h>
#include<stdio.h>
#include<math.h>

typedef struct{
	double x,y;
}point;

double shoelace(char* inputFile){
	int i,numPoints;
	double leftSum = 0,rightSum = 0;
	
	point* pointSet;
	FILE* fp = fopen(inputFile,"r");
	
	fscanf(fp,"%d",&numPoints);
	
	pointSet = (point*)malloc((numPoints + 1)*sizeof(point));
	
	for(i=0;i<numPoints;i++){
		fscanf(fp,"%lf %lf",&pointSet[i].x,&pointSet[i].y);
	}
	
	fclose(fp);
	
	pointSet[numPoints] = pointSet[0];
	
	for(i=0;i<numPoints;i++){
		leftSum += pointSet[i].x*pointSet[i+1].y;
		rightSum += pointSet[i+1].x*pointSet[i].y;
	}
	
	free(pointSet);
	
	return 0.5*fabs(leftSum - rightSum);
}

int main(int argC,char* argV[])
{
	if(argC==1)
		printf("\nUsage : %s <full path of polygon vertices file>",argV[0]);
	
	else
		printf("The polygon area is %lf square units.",shoelace(argV[1]));
	
	return 0;
}










Fortran:       DOUBLE PRECISION FUNCTION AREA(N,P)	
C   Uses the mid-point rule for integration. Consider the line joining (x1,y1) to (x2,y2)
C The area under that line (down to the x-axis) is the y-span midpoint (y1 + y2)/2 times the width (x2 - x1)
C This is the trapezoidal rule for a single interval, and follows from simple geometry.
C Now consider a sequence of such points heading in the +x direction: each successive interval's area is positive.
C Follow with a sequence of points heading in the -x direction, back to the first point: their areas are all negative.
C The resulting sum is the area below the +x sequence and above the -x sequence: the area of the polygon.
C   The point sequence can wobble as it wishes and can meet the other side, but it must not cross itself
c as would be done in a figure 8 drawn with a crossover instead of a meeting.
C   A clockwise traversal (as for an island) gives a positive area; use anti-clockwise for a lake.
       INTEGER N		
       DOUBLE COMPLEX P(N)	
       DOUBLE COMPLEX PP,PC	
       DOUBLE COMPLEX W		
       DOUBLE PRECISION A	
       INTEGER I		
        IF (N.LT.3) STOP "Area: at least three points are needed
        W = (P(1) + P(N/3) + P(2*N/3))/3	
        W = SUM(P(1:N) - W)/N + W	
        A = 0			
        PC = P(N) - W		
        DO I = 1,N		
          PP = PC			
          PC = P(I) - W			
          A = (DIMAG(PC) + DIMAG(PP))*(DBLE(PC) - DBLE(PP)) + A	
        END DO			
        AREA = A/2		
      END FUNCTION AREA		

      DOUBLE PRECISION FUNCTION AREASL(N,P)	
       INTEGER N		
       DOUBLE COMPLEX P(N)	
       DOUBLE PRECISION A	
        A = SUM(DBLE(P(1:N - 1)*DIMAG(P(2:N)))) + DBLE(P(N))*DIMAG(P(1))
     1    - SUM(DBLE(P(2:N)*DIMAG(P(1:N - 1)))) - DBLE(P(1))*DIMAG(P(N))
        AREASL = A/2		
      END FUNCTION AREASL	

      INTEGER ENUFF
      DOUBLE PRECISION AREA,AREASL	
      DOUBLE PRECISION A1,A2		
      PARAMETER (ENUFF = 5)		
      DOUBLE COMPLEX POINT(ENUFF)	
      DATA POINT/(3D0,4D0),(5D0,11D0),(12D0,8D0),(9D0,5D0),(5D0,6D0)/	

      WRITE (6,*) POINT
      A1 = AREA(5,POINT)
      A2 = AREASL(5,POINT)
      WRITE (6,*) "A=",A1,A2
      END
Task: Shoelace formula for polygonal area







Python: >>> def area_by_shoelace(x, y):
    "Assumes x,y points go around the polygon in one direction"
    return abs( sum(i * j for i, j in zip(x,             y[1:] + y[:1]))
               -sum(i * j for i, j in zip(x[1:] + x[:1], y            ))) / 2

>>> points = [(3,4), (5,11), (12,8), (9,5), (5,6)]
>>> x, y = zip(*points)
>>> area_by_shoelace(x, y)
30.0
>>>




Fortran:       DOUBLE PRECISION FUNCTION AREA(N,P)	
C   Uses the mid-point rule for integration. Consider the line joining (x1,y1) to (x2,y2)
C The area under that line (down to the x-axis) is the y-span midpoint (y1 + y2)/2 times the width (x2 - x1)
C This is the trapezoidal rule for a single interval, and follows from simple geometry.
C Now consider a sequence of such points heading in the +x direction: each successive interval's area is positive.
C Follow with a sequence of points heading in the -x direction, back to the first point: their areas are all negative.
C The resulting sum is the area below the +x sequence and above the -x sequence: the area of the polygon.
C   The point sequence can wobble as it wishes and can meet the other side, but it must not cross itself
c as would be done in a figure 8 drawn with a crossover instead of a meeting.
C   A clockwise traversal (as for an island) gives a positive area; use anti-clockwise for a lake.
       INTEGER N		
       DOUBLE COMPLEX P(N)	
       DOUBLE COMPLEX PP,PC	
       DOUBLE COMPLEX W		
       DOUBLE PRECISION A	
       INTEGER I		
        IF (N.LT.3) STOP "Area: at least three points are needed
        W = (P(1) + P(N/3) + P(2*N/3))/3	
        W = SUM(P(1:N) - W)/N + W	
        A = 0			
        PC = P(N) - W		
        DO I = 1,N		
          PP = PC			
          PC = P(I) - W			
          A = (DIMAG(PC) + DIMAG(PP))*(DBLE(PC) - DBLE(PP)) + A	
        END DO			
        AREA = A/2		
      END FUNCTION AREA		

      DOUBLE PRECISION FUNCTION AREASL(N,P)	
       INTEGER N		
       DOUBLE COMPLEX P(N)	
       DOUBLE PRECISION A	
        A = SUM(DBLE(P(1:N - 1)*DIMAG(P(2:N)))) + DBLE(P(N))*DIMAG(P(1))
     1    - SUM(DBLE(P(2:N)*DIMAG(P(1:N - 1)))) - DBLE(P(1))*DIMAG(P(N))
        AREASL = A/2		
      END FUNCTION AREASL	

      INTEGER ENUFF
      DOUBLE PRECISION AREA,AREASL	
      DOUBLE PRECISION A1,A2		
      PARAMETER (ENUFF = 5)		
      DOUBLE COMPLEX POINT(ENUFF)	
      DATA POINT/(3D0,4D0),(5D0,11D0),(12D0,8D0),(9D0,5D0),(5D0,6D0)/	

      WRITE (6,*) POINT
      A1 = AREA(5,POINT)
      A2 = AREASL(5,POINT)
      WRITE (6,*) "A=",A1,A2
      END
Task: Shoelace formula for polygonal area








VB: Option Base 1
Public Enum axes
    u = 1
    v
End Enum
Private Function shoelace(s As Collection) As Double
    Dim t As Double
    If s.Count > 2 Then
        s.Add s(1)
        For i = 1 To s.Count - 1
            t = t + s(i)(u) * s(i + 1)(v) - s(i + 1)(u) * s(i)(v)
        Next i
    End If
    shoelace = Abs(t) / 2
End Function
 
Public Sub polygonal_area()
    Dim task() As Variant
    task = [{3,4;5,11;12,8;9,5;5,6}]
    Dim tcol As New Collection
    For i = 1 To UBound(task)
        tcol.Add Array(task(i, u), task(i, v))
    Next i
    Debug.Print shoelace(tcol)
End Sub



Fortran:       DOUBLE PRECISION FUNCTION AREA(N,P)	
C   Uses the mid-point rule for integration. Consider the line joining (x1,y1) to (x2,y2)
C The area under that line (down to the x-axis) is the y-span midpoint (y1 + y2)/2 times the width (x2 - x1)
C This is the trapezoidal rule for a single interval, and follows from simple geometry.
C Now consider a sequence of such points heading in the +x direction: each successive interval's area is positive.
C Follow with a sequence of points heading in the -x direction, back to the first point: their areas are all negative.
C The resulting sum is the area below the +x sequence and above the -x sequence: the area of the polygon.
C   The point sequence can wobble as it wishes and can meet the other side, but it must not cross itself
c as would be done in a figure 8 drawn with a crossover instead of a meeting.
C   A clockwise traversal (as for an island) gives a positive area; use anti-clockwise for a lake.
       INTEGER N		
       DOUBLE COMPLEX P(N)	
       DOUBLE COMPLEX PP,PC	
       DOUBLE COMPLEX W		
       DOUBLE PRECISION A	
       INTEGER I		
        IF (N.LT.3) STOP "Area: at least three points are needed
        W = (P(1) + P(N/3) + P(2*N/3))/3	
        W = SUM(P(1:N) - W)/N + W	
        A = 0			
        PC = P(N) - W		
        DO I = 1,N		
          PP = PC			
          PC = P(I) - W			
          A = (DIMAG(PC) + DIMAG(PP))*(DBLE(PC) - DBLE(PP)) + A	
        END DO			
        AREA = A/2		
      END FUNCTION AREA		

      DOUBLE PRECISION FUNCTION AREASL(N,P)	
       INTEGER N		
       DOUBLE COMPLEX P(N)	
       DOUBLE PRECISION A	
        A = SUM(DBLE(P(1:N - 1)*DIMAG(P(2:N)))) + DBLE(P(N))*DIMAG(P(1))
     1    - SUM(DBLE(P(2:N)*DIMAG(P(1:N - 1)))) - DBLE(P(1))*DIMAG(P(N))
        AREASL = A/2		
      END FUNCTION AREASL	

      INTEGER ENUFF
      DOUBLE PRECISION AREA,AREASL	
      DOUBLE PRECISION A1,A2		
      PARAMETER (ENUFF = 5)		
      DOUBLE COMPLEX POINT(ENUFF)	
      DATA POINT/(3D0,4D0),(5D0,11D0),(12D0,8D0),(9D0,5D0),(5D0,6D0)/	

      WRITE (6,*) POINT
      A1 = AREA(5,POINT)
      A2 = AREASL(5,POINT)
      WRITE (6,*) "A=",A1,A2
      END