This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkpathtbl.cl
139 lines (127 loc) · 4.38 KB
/
mkpathtbl.cl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# MKPATHTBL 28SEP90 KMM
## MKPATHTBL convert mosaic path position to grid location relative to ll corner
procedure mkpathtbl (start_pos,end_pos,x_max,y_max,path_order,path_corner)
int start_pos {prompt="first path position"}
int end_pos {prompt="last path position"}
int x_max {prompt="grid dimension in x (== nxsub)"}
int y_max {prompt="grid dimension in y (== nysub)"}
string path_order {enum="row|column",prompt="path order: |row|column|"}
string path_corner {enum="lr|ll|ur|ul",prompt="start corner: |lr|ll|ur|ul|"}
bool sort_grid {no, prompt="Sort by grid location"}
bool format {no, prompt="Provide neat tabular output"}
begin
int nim,gridx,gridy,nxsub,nysub,ncol,pstart,pend
string corner,order,uniq,snim
file task,tmp1,tmp2
uniq = mktemp ("_Tmpt")
tmp1 = uniq // ".tm1"
tmp2 = uniq // ".tm2"
task = uniq // ".tsk"
pstart = start_pos
pend = end_pos
nxsub = x_max
nysub = y_max
order = path_order
corner = path_corner
# converting list order to grid position relative to ll corner
if (order == "row") {
if (corner == "ll") {
for (nim = pstart; nim <= pend; nim +=1) {
gridx = mod(nim-1,nxsub)+1
gridy = int((nim-1)/nxsub)+1
snim = "000" + nim
print (snim," ",gridx,gridy,>> tmp1)
}
}
else if (corner == "lr") {
for (nim = pstart; nim <= pend; nim +=1) {
gridx = nxsub-mod(nim-1,nxsub)
gridy = int((nim-1)/nxsub)+1
snim = "000" + nim
print (snim," ",gridx,gridy,>> tmp1)
}
}
else if (corner == "ul") {
for (nim = pstart; nim <= pend; nim +=1) {
gridx = mod(nim-1,nxsub)+1
gridy = nysub-int((nim-1)/nxsub)
snim = "000" + nim
print (snim," ",gridx,gridy,>> tmp1)
}
}
else {
for (nim = pstart; nim <= pend; nim +=1) {
gridx = nxsub-mod(nim-1,nxsub)
gridy = nysub-int((nim-1)/nxsub)
snim = "000" + nim
print (snim," ",gridx,gridy,>> tmp1)
}
}
}
else {
if (corner == "ll") {
for (nim = pstart; nim <= pend; nim +=1) {
gridx = int((nim-1)/nysub)+1
gridy = mod(nim-1,nysub)+1
snim = "000" + nim
print (snim," ",gridx,gridy,>> tmp1)
}
}
else if (corner == "lr") {
for (nim = pstart; nim <= pend; nim +=1) {
gridx = nxsub-int((nim-1)/nysub)
gridy = mod(nim-1,nysub)+1
snim = "000" + nim
print (snim," ",gridx,gridy,>> tmp1)
}
}
else if (corner == "ul") {
for (nim = pstart; nim <= pend; nim +=1) {
gridx = int((nim-1)/nysub)+1
gridy = nxsub-mod(nim-1,nysub)
snim = "000" + nim
print (snim," ",gridx,gridy,>> tmp1)
}
}
else {
for (nim = pstart; nim <= pend; nim +=1) {
gridx = nxsub-int((nim-1)/nysub)
gridy = nxsub-mod(nim-1,nysub)
snim = "000" + nim
print (snim," ",gridx,gridy,>> tmp1)
}
}
}
if (sort_grid)
# sort column == "x" ncol = 2
sort (tmp1,col=2,ignore+,num-,rev-)
# fancy formatter
if (format) {
print ('{printf("%03d %03d %03d\\n",$1,$2,$3)}',> task)
print("!awk -f ",task," ",tmp1) | cl
} else
type (tmp1)
# Finish up
delete (uniq//"*", verify=no)
end
# convert mosaic grid location relative to ll corner to path position
# if (order == "row") {
# if (corner == "ll")
# nim = nxsub*(ny-1) + nx
# else if (corner == "lr")
# nim = nxsub*ny + 1 - nx
# else if (corner == "ul")
# nim = nxsub*(nysub-ny) + nx
# else
# nim = nxsub*(nysub+1-ny) + 1 - nx
# }
# else {
# if (corner == "ll")
# nim = nysub*(nx-1) + ny
# else if (corner == "lr")
# nim = nysub*(nxsub-nx) +ny
# else if (corner == "ul")
# nim = nysub*nx + 1 - ny
# else
# nim = nysub*(nxsub+1-nx) + 1 - ny
# }