|
| 1 | + |
| 2 | +function [ veg_opacity, N_tile, avg_period ] = read_vegopacity( fname, N_tile ); |
| 3 | + |
| 4 | +% Reader for climatological mwRTM vegopacity file (little-endian, Fortran sequential binary). |
| 5 | +% |
| 6 | +% vegopacity files are created with the script |
| 7 | +% GEOSldas_GridComp/GEOSldas_App/util/inputs/mwRTM_params/Create_vegopacity_8day_clim.m |
| 8 | +% |
| 9 | +% The format of the vegopacity file is compatible with MAPL_ReadForcing(). There are 96 Fortran |
| 10 | +% records for 48 pairs of header/vegopacity entries, stored in a temporal wrap-around manner: |
| 11 | +% |
| 12 | +% record 1: [FortranTag] header [FortranTag] % last record of year |
| 13 | +% record 2: [FortranTag] vegopacity [FortranTag] |
| 14 | +% record 3: [FortranTag] header [FortranTag] % first record of year |
| 15 | +% record 4: [FortranTag] vegopacity [FortranTag] |
| 16 | +% ... |
| 17 | +% record 93: [FortranTag] header [FortranTag] % last record of year |
| 18 | +% record 94: [FortranTag] vegopacity [FortranTag] |
| 19 | +% record 95: [FortranTag] header [FortranTag] % first record of year |
| 20 | +% record 96: [FortranTag] vegopacity [FortranTag] |
| 21 | +% |
| 22 | +% header: [FortranTag] Year Month Day Hour Minute Second ... % start of 8-day avg period (float) |
| 23 | +% Year Month Day Hour Minute Second ... % end of 8-day avg period (float) |
| 24 | +% N_data_vegopacity ... % number of tiles (float) |
| 25 | +% 1 ... (float) |
| 26 | +% [FortranTag] |
| 27 | +% |
| 28 | +% The [FortranTag] is an integer that indicates how many bytes of data are stored in the |
| 29 | +% corresponding Fortran sequential binary record. Integers and reals are stored in |
| 30 | +% simple (4-byte) precision. |
| 31 | +% Odd ("header") records: FortranTag = 14 * 4 |
| 32 | +% Even ("vegopactiy") records: FortranTag = N_tile * 4 |
| 33 | +% |
| 34 | +% N_tile is *required* as input because some vegopacity files that were interpolated to cube-sphere |
| 35 | +% have the wrong N_tile info in their header lines. |
| 36 | +% |
| 37 | +% - reichle, 29 Sep 2025 |
| 38 | +% |
| 39 | +% ------------------------------------------------------------------ |
| 40 | + |
| 41 | +MAPL_UNDEF = 1.e15; |
| 42 | + |
| 43 | +machfmt = 'l'; % little-endian, GEOSldas |
| 44 | + |
| 45 | +int_precision = 'int32'; % precision of fortran tag and integer data |
| 46 | +float_precision = 'float32'; % precision of real data |
| 47 | + |
| 48 | +disp(['read_vegopacity.m: reading from ', fname]) |
| 49 | + |
| 50 | +ifp = fopen( fname, 'r', machfmt ); |
| 51 | + |
| 52 | +N_head = 14; |
| 53 | +N_time = 48; |
| 54 | + |
| 55 | +for ii=1:N_time |
| 56 | + |
| 57 | + disp(['reading avg period ', num2str(ii)]) |
| 58 | + |
| 59 | + % odd records ("header") |
| 60 | + |
| 61 | + fortran_tag = fread( ifp, 1, int_precision ); if fortran_tag~=N_head*4, error('wrong fortran_tag A'), end |
| 62 | + |
| 63 | + tmp = fread( ifp, N_head, float_precision ); |
| 64 | + |
| 65 | + fortran_tag = fread( ifp, 1, int_precision ); if fortran_tag~=N_head*4, error('wrong fortran_tag B'), end |
| 66 | + |
| 67 | + % populate avg_period |
| 68 | + |
| 69 | + avg_period(ii,:) = tmp(1:12); |
| 70 | + |
| 71 | + % verify N_tile |
| 72 | + |
| 73 | + N_tile_tmp = tmp(13); |
| 74 | + |
| 75 | + if N_tile_tmp~=N_tile, disp(['WARNING: wrong N_tile in header lines: ', num2str(N_tile_tmp)]), end |
| 76 | + |
| 77 | + |
| 78 | + % even records ("vegopacity") |
| 79 | + |
| 80 | + fortran_tag = fread( ifp, 1, int_precision ); if fortran_tag~=N_tile*4, disp(['WARNING: wrong N_tile in vegopacity file ', num2str(fortran_tag/4)]), end |
| 81 | + |
| 82 | + tmp = fread( ifp, N_tile, float_precision ); |
| 83 | + |
| 84 | + fortran_tag = fread( ifp, 1, int_precision ); if fortran_tag~=N_tile*4, disp(['WARNING: wrong N_tile in vegopacity file ', num2str(fortran_tag/4)]), end |
| 85 | + |
| 86 | + % populate veg_opacity |
| 87 | + |
| 88 | + veg_opacity(ii,:) = tmp; |
| 89 | + |
| 90 | +end |
| 91 | + |
| 92 | +fclose(ifp); |
| 93 | + |
| 94 | +% change no-data-values to NaN |
| 95 | + |
| 96 | +veg_opacity( veg_opacity>MAPL_UNDEF*0.9999 ) = NaN; |
| 97 | + |
| 98 | + |
| 99 | +disp(['done reading ', fname]) |
| 100 | + |
| 101 | +% =========== EOF =========================================== |
| 102 | + |
0 commit comments