Skip to content

Commit 7a9ea50

Browse files
committed
New check_for_file() NCL routine
NCL 6.2.1 changed the output from the isfilepresent() routine - instead of returning true if the file exists, the file must also be of a format that is readable by addfile(). 6.2.1 also introduced the function fileexists() with the same behavior as the old isfilepresent(), so I created version_consistency.ncl which only contains check_for_file() -- if fileexists() exists, it is used to check for the file, otherwise isfilepresent() is used. It's a little clunky, but it's better than requiring NCL 6.2.1 or later to generate plots.
1 parent 2a6a4ab commit 7a9ea50

9 files changed

+40
-14
lines changed

reg_tests/Bryan-Lewis/plot_diff_coeffs.ncl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
22
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
33
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
44
load "../common/plot_settings.ncl"
5+
load "../common/version_consistency.ncl"
56

67
begin
78

@@ -18,14 +19,14 @@ begin
1819
count = 0
1920
do while ((.not.filefound).and.(count.lt.2))
2021

21-
if (isfilepresent(file_names(count)+".nc")) then
22+
if (check_for_file(file_names(count)+".nc")) then
2223
print((/"Reading netCDF data from "+file_names(count)/))
2324
f = addfile(file_names(count)+".nc", "r")
2425
filefound = True
2526
x = transpose(f->Tdiff)
2627
y = f->zw
2728
else
28-
if (fileexists(file_names(count)+".out")) then
29+
if (check_for_file(file_names(count)+".out")) then
2930
print((/"Reading ascii data from "+file_names(count)/))
3031
nml = asciiread("input.nl", -1, "integer")
3132
nlev = nml(0)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; The isfilepresent() routine is different in version 6.2.1 than it was in
2+
; previous versions - it now only returns true if the file exists AND the file
3+
; is of a valid type for addfile() [netCDF, HDF5, etc]. The new routine
4+
; fileexists() replaces the old functionality... but fileexists() doesn't exist
5+
; in older versions of NCL. So this library contains a wrapper to use
6+
; fileexists() if it is part of NCL and isfilepresent() if it is not.
7+
8+
undef("check_for_file")
9+
function check_for_file(filename)
10+
begin
11+
if (isfunc("fileexists")) then
12+
return(fileexists(filename))
13+
end if
14+
return(isfilepresent(filename))
15+
16+
end
17+
18+

reg_tests/double_diff/plot_diff_coeffs.ncl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
22
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
33
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
44
load "../common/plot_settings.ncl"
5+
load "../common/version_consistency.ncl"
56

67
; This script reads in output from the CVMix stand-alone driver using double
78
; diffusion mixing from Large, et al., 1992. This script takes the output from
@@ -20,7 +21,7 @@ begin
2021
nml = asciiread("input.nl", -1, "integer")
2122
nlev = 2*nml(0)
2223
yt = new((/2, nlev/), "double")
23-
if (isfilepresent("data.nc")) then
24+
if (check_for_file("data.nc")) then
2425
print((/"Reading netCDF data"/))
2526
f = addfile("data.nc", "r")
2627

@@ -29,7 +30,7 @@ begin
2930
yt(0,:) = f->Tdiff(0:nlev-1,0)
3031
yt(1,:) = f->Tdiff(0:nlev-1,1)
3132
else
32-
if (fileexists("data.out")) then
33+
if (check_for_file("data.out")) then
3334
print((/"Reading ascii data"/))
3435
x1 = new((/nlev /), "double")
3536
ys = new((/nlev /), "double")

reg_tests/kpp/plot_bulk_Rich.ncl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
22
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
33
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
44
load "../common/plot_settings.ncl"
5+
load "../common/version_consistency.ncl"
56

67
begin
78

@@ -12,7 +13,7 @@ begin
1213
; Create Color Table
1314
my_color_map = (/"White", "Black"/)
1415

15-
if (isfilepresent("test5.nc")) then
16+
if (check_for_file("test5.nc")) then
1617
print((/"Reading netCDF data"/))
1718
f = addfile("test5.nc", "r")
1819
zt = f->zt
@@ -21,7 +22,7 @@ begin
2122
Ri_bulk = f->BulkRichardson
2223
hd = -f@OBL_depth
2324
else
24-
if (fileexists("test5.out")) then
25+
if (check_for_file("test5.out")) then
2526
print((/"Reading ascii data"/))
2627
nlev = 10
2728
zt = new((/nlev/), "double")

reg_tests/kpp/plot_flux_profiles.ncl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
22
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
33
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
44
load "../common/plot_settings.ncl"
5+
load "../common/version_consistency.ncl"
56

67
begin
78

@@ -12,14 +13,14 @@ begin
1213
; Create Color Table
1314
my_color_map = (/"White", "Black"/)
1415

15-
if (isfilepresent("test3.nc")) then
16+
if (check_for_file("test3.nc")) then
1617
print((/"Reading netCDF data"/))
1718
f = addfile("test3.nc", "r")
1819
sigma = f->data(0,:)
1920
phi_m = f->data(1,:)
2021
phi_s = f->data(2,:)
2122
else
22-
if (fileexists("test3.out")) then
23+
if (check_for_file("test3.out")) then
2324
print((/"Reading ascii data"/))
2425
nlev = 220
2526
sigma = new((/nlev+1/), "double")

reg_tests/shear/plot_LMD_diff_coeffs.ncl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
22
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
33
load "../common/plot_settings.ncl"
4+
load "../common/version_consistency.ncl"
45

56
; This script reads in output from the CVMix stand-alone driver using the shear
67
; mixing technique from Large, et al., 1992. This script takes the output from
@@ -16,13 +17,13 @@ begin
1617
my_color_map = (/"White", "Black"/)
1718

1819
; Read data for LMD94 plot
19-
if (isfilepresent("data_LMD.nc")) then
20+
if (check_for_file("data_LMD.nc")) then
2021
print((/"Reading netCDF data"/))
2122
f = addfile("data_LMD.nc", "r")
2223
x = f->ShearRichardson
2324
y = f->Tdiff
2425
else
25-
if (fileexists("data_LMD.out")) then
26+
if (check_for_file("data_LMD.out")) then
2627
print((/"Reading ascii data"/))
2728
nml = asciiread("input.nl", -1, "integer")
2829
nlev = nml(0)

reg_tests/shear/plot_PP_diff_coeffs.ncl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
22
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
33
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
44
load "../common/plot_settings.ncl"
5+
load "../common/version_consistency.ncl"
56

67
; This script reads in output from the CVMix stand-alone driver using the shear
78
; mixing technique from Large, et al., 1992. This script takes the output from
@@ -17,13 +18,13 @@ begin
1718
my_color_map = (/"White", "Black"/)
1819

1920
; Read data for PP81 plot
20-
if (isfilepresent("data_PP2d.nc")) then
21+
if (check_for_file("data_PP2d.nc")) then
2122
print((/"Reading netCDF data"/))
2223
f = addfile("data_PP2d.nc", "r")
2324
x = f->ShearRichardson
2425
y = transpose(f->Mdiff)
2526
else
26-
if (fileexists("data_PP2d.out")) then
27+
if (check_for_file("data_PP2d.out")) then
2728
print((/"Reading ascii data"/))
2829
nml = asciiread("input.nl", -1, "integer")
2930
nlev = nml(0)

reg_tests/tidal-Simmons/plot_diff_coeffs.ncl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
22
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
33
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
44
load "../common/plot_settings.ncl"
5+
load "../common/version_consistency.ncl"
56

67
begin
78

@@ -13,7 +14,7 @@ begin
1314
my_color_map = (/"White", "Black"/)
1415

1516
in_file = "single_col.nc"
16-
if (isfilepresent(in_file)) then
17+
if (check_for_file(in_file)) then
1718
print((/"Reading netCDF data"/))
1819
f = addfile(in_file, "r")
1920
x = f->Tdiff

reg_tests/tidal-Simmons/plot_tidal_energy_map.ncl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
22
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
3+
load "../common/version_consistency.ncl"
34

45
begin
56

@@ -8,7 +9,7 @@ begin
89
; out_type = "X11"
910

1011
in_file = "../../inputdata/tidal_energy_gx1v6_20130512.nc"
11-
if (isfilepresent(in_file)) then
12+
if (check_for_file(in_file)) then
1213
print((/"Reading netCDF data"/))
1314
f = addfile(in_file, "r")
1415
tmplat = f->lat

0 commit comments

Comments
 (0)