Zhang-Suen thinning algorithm: Difference between revisions

(→‎{{header|Fortran}}: After much head-scratching...)
Line 917:
 
=={{header|Fortran}}==
With F90 came standardisation of a variety of array manipulation facilities. Since the image array is to be inspected as a whole then adjusted rather than adjusted step-by-step as it is inspected, the first thought was to employ the special facility of the FOR ALL statement, which is that in an expression such as <codelang Fortarn>FOR ALL (i = 2:n - 1) A(i) = (A(i - 1) + A(i) + A(I + 1))/3</codelang> all right-hand-side expressions will be evaluated with the original values of the array, while in the less special array assignment <codelang Fortran>A(2:N - 1) = (A(1:N - 2) + A(2:N - 1) + A(3:N))/3</codelang>, as in the case of the equivalent DO-loop, the processing will be with a mixture of old and new values as the loop proceeds. So, something like <lang Fortran> FOR ALL (I = 2:N - 1, J = 2:M - 1)
 
So, that suggests something like <lang Fortran> FOR ALL (I = 2:N - 1, J = 2:M - 1)
WHERE(DOT(I,J) .NE. 0) DOT(I,J) = ADJUST(DOT,I,J)</lang>
This requires function ADJUST to be a "pure" function, and they are not supposed to perpetrate side effects, such as one reporting that any adjustment was made. Nor is it clear that array DOT must be presented as a parameter either as the entire array or as element DOT(i,j), or if not, that it can be global to function ADJUST - which would also be an impurity - and for that matter, variables I and J could be global also...
 
Instead, thought turned to more closely following the task specification, which involves producing a list of elements to be adjusted after an inspection pass. Given that array DOT is two-dimensional, it would be nice if an element could be indexed via an expression such as <code>DOT(INDEX)</code> where INDEX was an array of two elements with INDEX(1) = i, and INDEX(2) = j, so as to access DOT(i,j) If this were possible, then obviously one could hope that array INDEX could be extended so as to store the multiple elements of a list of such locations to access, with a view to <code>DOT(INDEX(1:n)) = 0</code> adjusting the image.
 
Alas, such a syntax form is not accommodated. However, F90 also introduced the ability to define and use compound data types, such as the type PLACE as used below. It is not possible to define a type of a special, recognised form, such as say "SUBSCRIPT LIST" that can be used as dreamt of above, so the components are just ordinary variables. EvenTwo so,ordinary theyarrays cancould be placedused, inone anfor arrayeach assignmentof statementthe two subscripts, suchor asa compound type could be devised in a hint towards self-documentation. Thus, <lang Fortran> DOT(WHACK(1:WHACKCOUNT).I,WHACK(1:WHACKCOUNT).J) = 0</lang>
But it doesn't work...
 
1,220

edits