Skip to content

Commit fa232ef

Browse files
committed
added matlab reader for catchment.def file; fixed name of tile coord field "pfaf_index" in read_tile_file.m
1 parent ddeabca commit fa232ef

File tree

2 files changed

+58
-13
lines changed

2 files changed

+58
-13
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function [tile_coord ] = read_catchmentdef( fname )
2+
3+
% read (land) tile properties from "catchment.def" file (EASEv2 and cube-sphere)
4+
%
5+
% reichle, 24 Jan 2025
6+
%
7+
% -------------------------------------------------------------
8+
9+
% read file
10+
11+
disp(['reading from ', fname])
12+
13+
ifp = fopen( fname, 'r' );
14+
15+
% read header line
16+
17+
tmpdata = fscanf( ifp, '%f', 1 );
18+
19+
tile_coord.N_tile = tmpdata(1);
20+
21+
% read rest of data
22+
23+
tmpdata = fscanf( ifp, '%f' );
24+
25+
fclose(ifp);
26+
27+
disp('done reading "catchment.def" file')
28+
29+
% --------------------------------------------------
30+
31+
% process data
32+
33+
tmpdata = reshape(tmpdata, [7, tile_coord.N_tile])';
34+
35+
tile_coord.tile_id = tmpdata(:,1);
36+
tile_coord.pfaf_index = tmpdata(:,2);
37+
38+
tile_coord.min_lon = tmpdata(:,3);
39+
tile_coord.max_lon = tmpdata(:,4);
40+
tile_coord.min_lat = tmpdata(:,5);
41+
tile_coord.max_lat = tmpdata(:,6);
42+
43+
tile_coord.elev = tmpdata(:,7);
44+
45+
% ========== EOF ===================================================
46+

GEOSldas_App/util/shared/matlab/read_tile_file.m

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181

8282
% rename some fields
8383

84-
if strcmp(this_varname,'pfaf_index' ), this_varname = 'pfaf'; end
8584
if strcmp(this_varname,'i_indg1' ), this_varname = 'i_indg'; end
8685
if strcmp(this_varname,'j_indg1' ), this_varname = 'j_indg'; end
8786
if strcmp(this_varname,'frac_cell1' ), this_varname = 'frac_cell'; end
@@ -346,7 +345,7 @@
346345
tile_coord.elev = tmpNaN; % elevation of tile
347346

348347
tile_coord.area = tmpNaN; % area of "atm" grid cell
349-
tile_coord.pfaf = tmpNaN; % index of (hydrological) Pfafstetter catchment
348+
tile_coord.pfaf_index = tmpNaN; % index of (hydrological) Pfafstetter catchment
350349
tile_coord.frac_pfaf = tmpNaN; % area fraction of Pfafstetter catchment
351350

352351
if ~isEASE
@@ -372,14 +371,14 @@
372371
if isEASE
373372

374373
col_area = NaN;
375-
col_pfaf = 2; % land tiles only
376-
col_frac_pfaf = NaN; % land tiles only
374+
col_pfafindex = 2; % land tiles only
375+
col_fracpfaf = NaN; % land tiles only
377376

378377
else
379378

380379
col_area = 2;
381-
col_pfaf = 9; % land tiles only
382-
col_frac_pfaf = 11;
380+
col_pfafindex = 9; % land tiles only
381+
col_fracpfaf = 11;
383382

384383
end
385384

@@ -390,7 +389,7 @@
390389

391390
end
392391

393-
tile_coord.pfaf( ind_NOTocean) = tmpdata(ind_NOTocean, col_pfaf);
392+
tile_coord.pfaf_index( ind_NOTocean) = tmpdata(ind_NOTocean, col_pfafindex);
394393

395394
% -------------------------------------------------
396395
%
@@ -401,14 +400,14 @@
401400
%
402401
% non-EASE grid tile file:
403402
%
404-
% column 9: i_indg2 [for ocean tiles] *OR* pfaf [for non-ocean tiles]
403+
% column 9: i_indg2 [for ocean tiles] *OR* pfaf_index [for non-ocean tiles]
405404
% column 10: j_indg2
406-
% column 11: frac_cell2 [for ocean tiles] *OR* frac_pfaf [for non-ocean tiles]
405+
% column 11: frac_cell2 [for ocean tiles] *OR* frac_pfaf [for non-ocean tiles]
407406
% column 12: dummy_index2
408407

409408
if ~isEASE
410409

411-
tile_coord.frac_pfaf( ind_NOTocean) = tmpdata(ind_NOTocean, col_frac_pfaf);
410+
tile_coord.frac_pfaf( ind_NOTocean) = tmpdata(ind_NOTocean, col_fracpfaf);
412411

413412
tile_coord.i_indg2( ind_ocean) = tmpdata(ind_ocean, 9);
414413
tile_coord.j_indg2( ind_ocean) = tmpdata(ind_ocean, 10);
@@ -430,11 +429,11 @@
430429

431430
end
432431

433-
if ( any(tile_coord.tile_id(ind_land) - tctmp.tile_id) | ...
434-
any(tile_coord.pfaf( ind_land) - tctmp.pfaf ) ...
432+
if ( any(tile_coord.tile_id( ind_land) - tctmp.tile_id ) | ...
433+
any(tile_coord.pfaf_index(ind_land) - tctmp.pfaf_index) ...
435434
)
436435

437-
error('mismatch between tile file and catchment.def file: tile_id or pfaf')
436+
error('mismatch between tile file and catchment.def file: tile_id or pfaf_index')
438437

439438
end
440439

0 commit comments

Comments
 (0)