diff --git a/Tests/read_overlap.py b/Tests/read_overlap.py new file mode 100755 index 0000000000000000000000000000000000000000..9c756497fc421cfa823b63f12f40440473610657 --- /dev/null +++ b/Tests/read_overlap.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import networkx as nx +import csv +import matplotlib.pyplot as plt + +G = nx.DiGraph() + +with open("edgelist_1.csv") as f: + reader = csv.reader(f, delimiter = " ", skipinitialspace = True) + + # Skip title lines: + next(reader) + next(reader) + + for row in reader: + k1, i1, k2, i2, weight = int(row[0]), int(row[1]), int(row[2]), \ + int(row[3]), float(row[4]) + G.add_edge((k1, i1), (k2, i2), weight = weight) + +plt.figure() +nx.draw(G, with_labels=True) +plt.show() diff --git a/Tests/test_successive_overlap.f b/Tests/test_successive_overlap.f index e30e359faaaadd482093ded193e73cc77bdd0a62..35dbbac6fdb9fda72bbd74aff91685110747e726 100644 --- a/Tests/test_successive_overlap.f +++ b/Tests/test_successive_overlap.f @@ -12,7 +12,7 @@ program test_successive_overlap implicit none - integer unit_graph, i + integer unit_edgelist, i type(snapshot) flow(2) TYPE(shpfileobject) hshp_extremum ! shapefile extremum_1 TYPE(shpfileobject) hshp_outermost ! shapefile outermost_contour_1 @@ -43,11 +43,19 @@ program test_successive_overlap CALL shpclose(hshp_max_speed) flow(2) = flow(1) - call new_unit(unit_graph) - open(unit_graph, file = "graph_1.txt", status = "replace", action = "write") - call successive_overlap(unit_graph, nlon, nlat, flow, j = 2, k = 2) - close(unit_graph) - print *, 'Created file "graph_1.txt".' + call new_unit(unit_edgelist) + open(unit_edgelist, file = "edgelist_1.csv", status = "replace", & + action = "write") + + ! Title lines: + write(unit_edgelist, fmt = "(1x, a)") '"predecessor date index" ' & + // '"predecessor eddy index" "successor date index" ' & + // '"successor eddy index"' + write(unit_edgelist, fmt = *) "k1 i1 k2 i2 weight" + + call successive_overlap(unit_edgelist, nlon, nlat, flow, j = 2, k = 2) + close(unit_edgelist) + print *, 'Created file "edgelist_1.csv".' do i = 1, 2 print *, "flow(", i, ")%list_vis%delta_in:", flow(i)%list_vis%delta_in diff --git a/successive_overlap.f b/successive_overlap.f index 78c1f44d5f31ff0170cb2608b3ffb4213d6991f3..5f3948eea1e62a4b8b01fbc407afb289f488491e 100644 --- a/successive_overlap.f +++ b/successive_overlap.f @@ -4,10 +4,10 @@ module successive_overlap_m contains - subroutine successive_overlap(unit_graph, nlon, nlat, flow, j, k) + subroutine successive_overlap(unit_edgelist, nlon, nlat, flow, j, k) ! Finds edges between flow(j - 1) and flow(j), corresponding to - ! dates k - 1 and k. Writes these edges to graph.txt. Updates + ! dates k - 1 and k. Writes these edges to unit_edgelist. Updates ! flow(j - 1)%list_vis%delta_out and flow(j)%list_vis%delta_in. use contour_531, only: polyline @@ -17,7 +17,7 @@ contains use spherical_polyline_area_m, only: spherical_polyline_area use weight_m, only: weight - integer, intent(in):: unit_graph ! logical unit for graph file + integer, intent(in):: unit_edgelist ! logical unit for edgelist file integer, intent(in):: nlon, nlat type(snapshot), intent(inout):: flow(:) ! (max_delta + 1) integer, intent(in):: j, k @@ -62,7 +62,7 @@ contains if (spherical_polygon_area(res_pol) >= 0.25 & * min(spherical_polyline_area(polyline_1), & spherical_polyline_area(polyline_2))) then - write(unit_graph, fmt = *) k - 1, i1, k, i2, & + write(unit_edgelist, fmt = *) k - 1, i1, k, i2, & weight(flow(j - 1)%list_vis(i1), & flow(j)%list_vis(i2)) flow(j - 1)%list_vis(i1)%delta_out = 1