Skip to content

Commit 7eeabb1

Browse files
committed
improve performance of check subroutine
1 parent f9eb325 commit 7eeabb1

File tree

1 file changed

+35
-39
lines changed

1 file changed

+35
-39
lines changed

src/forcolormap.f90

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,78 +1230,74 @@ pure subroutine check(self,check_name, check_bounds, check_levels, check_extract
12301230
! Initialize status array
12311231
self%status = .true.
12321232

1233+
! Check name and levels and set them to default if not valid
12331234
if (present(check_name)) then
12341235
if (check_name) then
12351236

1236-
! Check if the colormap is valid
1237-
self%status(1) = .false.
1238-
do i = 1, cmap_info%get_ncolormaps()
1239-
if (self%name == trim(cmap_info%get_name(i))) then
1240-
self%status(1) = .true.
1241-
exit
1242-
end if
1243-
end do
1244-
1245-
! Fix the colormap if it is not valid
1246-
if (self%status(1) .eqv. .false.) self%name = "grayC"
1247-
1248-
! Find the number of levels of the colormap
1249-
do i = 1, cmap_info%get_ncolormaps()
1250-
if (self%name == trim(cmap_info%get_name(i))) then
1251-
levels = cmap_info%get_levels(i)
1252-
exit
1253-
end if
1254-
end do
1237+
i = cmap_info%find_index(self%name)
1238+
if (i == 0) then
1239+
self%status(1) = .false.
1240+
self%name = "grayC"
1241+
i = cmap_info%find_index(self%name)
1242+
else
1243+
self%status(1) = .true.
1244+
end if
1245+
1246+
levels = -1
1247+
if (i > 0) levels = cmap_info%get_levels(i)
12551248

1256-
! Check if the number of levels is valid
1257-
if (levels /= self%levels .or. self%levels < 1) then
1258-
if (self%levels /= -256) then
1259-
if (levels /= -1) then
1249+
select case (self%levels)
1250+
case (-256)
1251+
self%levels = 256
1252+
case default
1253+
if (levels /= -1) then
1254+
if (self%levels < 1) then
1255+
self%status(4) = .false.
1256+
self%levels = 256
1257+
end if
1258+
if (self%levels /= levels) then
12601259
self%status(3) = .false.
12611260
self%levels = levels
12621261
end if
12631262
else
1264-
self%levels = 256
1263+
if (self%levels < 1) then
1264+
self%status(4) = .false.
1265+
self%levels = 256
1266+
end if
12651267
end if
1266-
end if
1267-
1268-
! Fix the number of levels if it is not valid
1269-
if (self%status(3) .eqv. .false.) then
1270-
self%levels = levels
1271-
end if
1268+
end select
12721269

12731270
end if
12741271
end if
12751272

1273+
! Check zmin and zmax and fix them if necessary
12761274
if (present(check_bounds)) then
12771275
if (check_bounds) then
1278-
! Check validity of zmin and zmax
1279-
if (self%zmin > self%zmax) self%status(2) = .false.
1280-
1281-
! Fix zmin and zmax if they are not valid
1282-
if (self%status(2) .eqv. .false.) then
1276+
if (self%zmin > self%zmax) then
1277+
self%status(2) = .false.
12831278
temp = self%zmin
12841279
self%zmin = self%zmax
12851280
self%zmax = temp
12861281
end if
1287-
12881282
end if
12891283
end if
12901284

1285+
! Check levels and set to default if not valid
12911286
if (present(check_levels)) then
12921287
if (check_levels) then
1293-
! Check if the number of levels is valid
12941288
if (self%levels < 1) then
12951289
self%status(4) = .false.
12961290
self%levels = 256
12971291
end if
12981292
end if
12991293
end if
13001294

1301-
! Check validity of extractedLevels
1295+
! Check extracted levels, no fix possible, just set status
13021296
if (present(check_extract)) then
13031297
if (check_extract) then
1304-
if (extractedLevels <= 1 .or. extractedLevels > self%levels) then
1298+
if (.not. present(extractedLevels)) then
1299+
self%status(5) = .false.
1300+
else if (extractedLevels <= 1 .or. extractedLevels > self%levels) then
13051301
self%status(5) = .false.
13061302
else
13071303
self%status(5) = .true.

0 commit comments

Comments
 (0)