@@ -182,20 +182,6 @@ submodule (stdlib_linalg) stdlib_linalg_schur
182182 overwrite_a_ = .false._lk
183183 endif
184184
185- !> SORTING: no sorting options are currently supported
186- sort = gees_sort_eigs(.false.)
187- sdim = 0_ilp
188-
189- if (sort/=GEES_NOT) then
190-
191- allocate(bwork(n),source=.false.)
192-
193- else
194-
195- bwork => bwork_dummy
196-
197- end if
198-
199185 !> Schur vectors
200186 jobvs = gees_vectors(present(z))
201187 if (present(z)) then
@@ -207,7 +193,8 @@ submodule (stdlib_linalg) stdlib_linalg_schur
207193 if (ldvs<n .or. nvs/=n) then
208194 err0 = linalg_state_type(this, LINALG_VALUE_ERROR, 'Schur vectors size=',[ldvs,nvs], &
209195 'should be n=',n)
210- goto 1
196+ call linalg_error_handling(err0, err)
197+ return
211198 end if
212199
213200 else
@@ -226,10 +213,29 @@ submodule (stdlib_linalg) stdlib_linalg_schur
226213
227214 ! Query optimal workspace
228215 call get_schur_${ri}$_workspace(a,lwork,err0)
229- if (err0%error()) goto 1
230- allocate(work(lwork))
231216
232- end if
217+ if (err0%error()) then
218+ call linalg_error_handling(err0, err)
219+ return
220+ else
221+ allocate(work(lwork))
222+ end if
223+
224+ end if
225+
226+ !> SORTING: no sorting options are currently supported
227+ sort = gees_sort_eigs(.false.)
228+ sdim = 0_ilp
229+
230+ if (sort/=GEES_NOT) then
231+
232+ allocate(bwork(n),source=.false.)
233+
234+ else
235+
236+ bwork => bwork_dummy
237+
238+ end if
233239
234240 !> User or self-allocated eigenvalue storage
235241 if (present(eigvals)) then
@@ -262,25 +268,30 @@ submodule (stdlib_linalg) stdlib_linalg_schur
262268 #:endif
263269
264270 if (lde<n) then
265- err0 = linalg_state_type(this, LINALG_VALUE_ERROR, 'Insufficient eigenvalue array size=',lde, &
266- 'should be >=',n)
267- goto 2
271+
272+ err0 = linalg_state_type(this, LINALG_VALUE_ERROR, &
273+ 'Insufficient eigenvalue array size=',lde, &
274+ 'should be >=',n)
275+
276+ else
277+
278+ ! Compute Schur decomposition
279+ call gees(jobvs,sort,eig_select,nt,t,mt,sdim,eigs,#{if rt.startswith('r')}#eigi,#{endif}# &
280+ vs,ldvs,work,lwork,#{if rt.startswith('c')}#rwork,#{endif}#bwork,info)
281+ call handle_gees_info(info,m,n,m,err0)
282+
283+
268284 end if
269285
270- ! Compute Schur decomposition
271- call gees(jobvs,sort,eig_select,nt,t,mt,sdim,eigs,#{if rt.startswith('r')}#eigi,#{endif}# &
272- vs,ldvs,work,lwork,#{if rt.startswith('c')}#rwork,#{endif}#bwork,info)
273- call handle_gees_info(info,m,n,m,err0)
274-
275- 2 eigenvalue_output: if (local_eigs) then
286+ eigenvalue_output: if (local_eigs) then
276287 #:if rt.startswith('r')
277288 ! Build complex eigenvalues
278289 if (present(eigvals)) eigvals = cmplx(eigs,eigi,kind=${rk}$)
279290 #:endif
280291 if (.not.overwrite_a_) deallocate(eigs#{if rt.startswith('r')}#,eigi#{endif}#)
281292 endif eigenvalue_output
282293 if (.not.present(storage)) deallocate(work)
283- 1 if (sort/=GEES_NOT) deallocate(bwork)
294+ if (sort/=GEES_NOT) deallocate(bwork)
284295 call linalg_error_handling(err0,err)
285296
286297 contains
0 commit comments