ocssw  1.0
/disk01/web/ocssw/build/src/l2gen/l12_proto.h (r8084/r7820)
Go to the documentation of this file.
00001 #ifndef _L12_PROTO_H
00002 #define _L12_PROTO_H
00003 
00004 #ifdef __cplusplus
00005 extern "C" {
00006 #endif
00007 
00008 #include <stdint.h>
00009 #include <sys/types.h>
00010 #include <unistd.h>
00011 #include <stdio.h>
00012 #include <math.h>
00013 #include <stdlib.h>
00014 #include <libgen.h>
00015 #include <string.h>
00016 #include <ctype.h>
00017 #include <netcdf.h>
00018 
00019 #include "hdf.h"
00020 // #include "anc.h"
00021 #include "ancproto.h"
00022 #include "l12_parms.h"
00023 #include "l1_struc.h"
00024 #include "l1q_struc.h"
00025 #include "l2_struc.h"
00026 #include "target_struc.h"
00027 #include "vcal_struc.h"
00028 #include "filehandle.h"
00029 #include "filter.h"
00030 #include "l2_flags.h"
00031 #include "input_struc.h"
00032 #include "time_utils.h"
00033 #include "genutils.h"
00034 #include "aer_struc.h"
00035 #include "l2prod.h"
00036 #include "l2prod_struc.h"
00037 #include "hdf_utils.h"
00038 #include "alloc_2d.h"
00039 #include "xcal.h"
00040 #include "epr_api.h"
00041 #include "scene_meta.h"
00042 #include "l2_hdf_generic.h"
00043 #include "flags_iop.h"
00044 #include "table_io_wrapper.h"
00045 #include <clo.h>
00046 #include "navigation.h"
00047 #include "read_l3bin.h"
00048 
00049 #ifndef MAX
00050 #define MAX(A,B)    ((A) > (B) ? (A) : (B))  /* Greater of (A,B) */ 
00051 #endif
00052 
00053 #ifndef MIN
00054 #define MIN(A,B)    ((A) < (B) ? (A) : (B))  /* Lesser  of (A,B) */
00055 #endif
00056 
00057 
00058 void filehandle_init(filehandle *file);
00059 
00060 int32_t getFormat(filehandle *file);
00061 
00062 int  getl1rec  (filehandle *l1file, instr *input_str, int32_t recnum, 
00063                 l1str *l1rec);
00064 
00065 int  loadl1    (filehandle *l1file, instr *input_str, l1str *l1rec);
00066 
00067 int  openl1    (filehandle *l1file);
00068 int  readl1    (filehandle *l1file, int32_t recnum, l1str *l1rec);
00069 int  readl1_lonlat (filehandle *l1file, int32_t recnum, l1str *l1rec);
00070 int  writel1   (filehandle *l1file, int32_t recnum, l1str *l1rec);
00071 void closel1   (filehandle *l1file);
00072 
00073 int  openl1_read_hdf (filehandle *l1file);
00074 int  openl1_write_hdf (filehandle *l1file);
00075 int  writel1_hdf (filehandle *l1file, int32_t recnum, l1str *l1rec);
00076 void closel1_hdf (filehandle *l1file);
00077 
00078 int  openl2    (filehandle *l2file );
00079 int  writel2   (filehandle *l2file, int32_t recnum, l2str *l2rec);
00080 int  closel2   (filehandle *l2file );
00081 
00082 int  open_target  (filehandle *file );
00083 int  read_target  (filehandle *file, int32_t recnum, tgstr *tgrec);
00084 void close_target (void);
00085 
00086 int  open_aer  (filehandle *file );
00087 int  read_aer  (filehandle *file, int32_t recnum, aestr *aerec);
00088 void close_aer (filehandle *file );
00089 
00090 void init_l1( l1str *l1rec, int32_t npix );
00091 void init_l2( l2str *l2rec );
00092 
00093 void free_l1q(void);
00094 int32_t alloc_l1( int32_t npix, int32_t nbands, int32_t nbandsir, int32_t n_inprods, l1str *l1rec);
00095 void free_l1( l1str *l1rec );
00096 int32_t alloc_l2( int32_t npix, int32_t nbands, l2str *l2rec);
00097 void free_l2( l2str *l2rec );
00098 int32_t alloc_target( int32_t npix, int32_t nbands, tgstr *tgrec);
00099 int32_t alloc_aer( int32_t npix, int32_t nbands, aestr *aerec);
00100 
00101 l2prodstr *get_l2prod_index(char *name, int32 sensorID, int32 numBands, int32 numPixels,
00102                             int32 numScans, int32_t *wave);
00103 void write_product_XML_file(char* filename);
00104 
00105 int32 prodlist(int32 sensorID, int32 evalmask, char *inprod, char *defprod, char outprod[MAXPROD][32]);
00106 
00107 void cpl1l2  ( l1str *l1rec, l2str *l2rec);
00108 int  convl12 ( l1str *l1rec, l2str *l2rec, int32_t spix, int32_t epix, instr *input_str, aestr *aerec);
00109 int  convl21 ( l2str *l2rec, tgstr *tgrec, int32_t spix, int32_t epix, instr *input_str, float *Lt, vcstr *vrec);
00110 
00111 int32 l2_seawifs(filehandle *l1file, filehandle *l2file);
00112 int32 l1b_seawifs(filehandle *l1file, filehandle *ofile,
00113                   int32 sscan, int32 escan, int32 dscan,
00114                   int32 spixl, int32 epixl, int32 dpixl);
00115 int32 get_modis_calfile(int32 sd_id,char *file);
00116 
00117 int setanc  ( l1str *l1rec, instr *input_str );
00118 int setflags( instr *input_str, l1str *l1rec );
00119 void setflagbits( int level, l1str *l1rec, l2str *l2rec, int32_t ipix );
00120 void l1_mask_set(l1str *l1rec, int32_t ip);
00121 int modis_cloud_mask(l1str *l1rec, int32_t ip);
00122 int modis_cirrus_mask(l1str *l1rec, int32_t ip);
00123 void compute_alpha(float lon[], float lat[], float senz[], float sena[], double mnorm[3], 
00124                    int32 npix, float alpha[]);
00125 
00126 void cpl1rec(l1str *l1new, l1str *l1old);
00127 
00128 int b128_msk_init( char *landfile, int msknum );
00129 int b128_msk_get ( float lat, float lon, int msknum );
00130 
00131 int32_t rdsensorinfo(int32_t sensorID, int32_t evalmask, char *pname, void **pval);
00132 void lowercase(char *s);
00133 
00134 void atmocor1(l1str *l1rec, int32_t ip);
00135 int atmocor2(l2str *l2rec, aestr *aerec, int32_t ip);
00136 void whitecaps(int32_t sensorID, int32_t evalmask, int32_t nwave, float ws, float ws_max, float rhof[]);
00137 void rayleigh(int32_t sensorID, int32_t evalmask, int32_t nwave, int pol_opt,
00138               float solz, float senz, float phi, float taur[], 
00139               float Fo[], float pr, float ws,
00140               float Lr_i[], float Lr_q[], float Lr_u[]);
00141 int aerosol(l2str *l2rec, int32_t aer_opt_in, aestr *aerec, int32_t ip, 
00142             float wave[], int32_t nwave, int32_t nir_s_in, int32_t nir_l_in,
00143             float F0_in[], float La1_in[], float La2_out[], 
00144             float t_sol_out[], float t_sen_out[], float *eps, float taua_out[],
00145             int32_t *modmin, int32_t *modmax, float *modrat);
00146 void gaseous_transmittance(int gasmask, int32_t sensorID, int32_t evalmask, int32_t nwave, float mu0, float mu, 
00147             float ozone, float wv, float no2_tropo, float no2_strat, float no2_frac,
00148         float t_gas_sol[], float t_gas_sen[]);
00149 
00150 float ky_airmass(float theta);
00151 float pp_airmass(float theta);
00152 
00153 void get_rhown_nir(float Rrs[], float wave[], int32_t nir_s, int32_t nir_l, 
00154                    float aw[], float bbw[], float chl, float rhown[]);
00155 void get_rhown_eval(float Rrs[], float wave[], int32_t nir_s, int32_t nir_l,
00156                    int32_t nwave, float aw[], float bbw[], float chl,
00157                    float solz, float senz, float phi, float rhown[]);
00158 void get_rho_mumm(l2str *l2rec, int32_t ip, int32_t iw, float *rhom);
00159 void get_rhown_mumm(l2str *l2rec, int32_t ip, int32_t nir_s, int32_t nir_l, float rhown[]);
00160 void glint_rad(int32_t num_iter, int32_t nband, int32_t nir_s, int32_t nir_l, 
00161                float glint_coef, float air_mass, 
00162                float mu0, float F0[],float taur[], float  taua[], float La[], float TLg[]);
00163 
00164 float fresnel_coef(float mu, float n);
00165 float fresnel_sen(float senz,int return_tf);
00166 void  fresnel_sol(float wave[],int32_t nwave,float solz,float ws,float brdf[],int return_tf);
00167 void foqint_morel(float wave[],int32_t nwave,float solz,float senzp,
00168                   float phi,float chl,float brdf[]); 
00169 void qint_morel(float wave[],int32_t nwave,float solz,float chl,float Qn[]);
00170 void gothic_R(float wave[],int32_t nwave,float solz,float senz, float ws,float R[]); 
00171 int ocbrdf(l2str *l2rec,int32_t ip,int32_t brdf_opt,float wave[],int32_t nwave,
00172            float solz,float senz,float phi,float ws,float chl,float nLw[],float Fo[], float brdf[]);
00173 
00174 void nlw_outband(int32_t evalmask, int32_t sensorID, float wave[], int32_t nwave, float Lw[], float nLw[]);
00175 
00176 int l2gen_usage(char *prog);
00177 int msl12_input_defaults(filehandle *l1file, instr *input);
00178 void msl12_input_init(instr *input);
00179 int l2gen_init_options(clo_optionList_t* list, char* prog);
00180 int msl12_option_input(int argc, char *argv[], clo_optionList_t* list,
00181         char *progName, instr *input, filehandle *l1file);
00182 int msl12_input(int argc, char *argv[], char* progName, instr *input, filehandle *l1file);
00183 
00184 int l1subpix(filehandle *l1file, l1str *l1rec);
00185 
00186 float fresnel(float theta,float rel_index);
00187 int windex(float wave, float twave[], int ntwave);
00188 int invbindx(int band, int32_t *bindx, int nbands);
00189 void bindex_set(int32_t wave[], int nwave, int dwave);
00190 int windex_get(int32_t wave);
00191 int bindex_get(int32_t wave);
00192 
00193 float bin_climatology(char *l3file, int32_t day, float lon, float lat, char *prodname);
00194 
00195 float get_default_chl(l2str *l2rec, float Rrs[]);
00196 void  get_chl   (l2str *l2rec, int prodnum, float prod[]);
00197 void  get_las   (l2str *l2rec, l2prodstr *p, float prod[]);
00198 void  get_sma   (l2str *l2rec, int32_t prodID, float prod[]);
00199 void  get_tsm   (l2str *l2rec, int prodnum, float prod[]);
00200 void  get_poc   (l2str *l2rec, int prodnum, float prod[]);
00201 void  get_flh   (l2str *l2rec, float flh[]);
00202 void  get_fsat  (l2str *l2rec, float flh[]);
00203 void  get_fsat2 (l2str *l2rec, float flh[]);
00204 void  get_fqy   (l2str *l2rec, float fqy[]);
00205 void  get_fqy2  (l2str *l2rec, float fqy[]);
00206 void  get_ipar  (l2str *l2rec, float ipar[]);
00207 void  get_ipar2  (l2str *l2rec, float ipar[]);
00208 void  get_depth (l2str *l2rec, float depth[]);
00209 void  get_par   (l2str *l2rec, float par[]);
00210 void  get_bsi   (l2str *l2rec, float BSi[]);
00211 void  get_ssn   (l2str *l2rec, float ssn[]);
00212 void  get_angstrom (l2str *l2rec, int band, float angst[]);
00213 void  get_ms_epsilon(l2str *l2rec, float eps[]);
00214 void  get_es (l2str *l2rec, int band, float es[]);
00215 void  get_toa_refl (l2str *l2rec, int band, float rhot[]);
00216 void  get_dust_index (l2str *l2rec, float dust[]);
00217 void  get_ndvi (l2str *l2rec, float ndvi[]);
00218 void  get_evi (l2str *l2rec, float evi[]);
00219 void  get_smoke (l2str *l2rec, float smoke[]);
00220 void  get_Kd(l2str *l2rec, l2prodstr *p, float Kd[]);
00221 void  get_photic_depth(l2str *l2rec, l2prodstr *p, float Z[]);
00222 void  cdom_morel(l2str *l2rec, l2prodstr *p, float prod[]);
00223 void  get_soa(l2str *l2rec, int32_t prodID, float prod[]);
00224 int   run_soa_sma(l2str *l2rec, int32_t ip);
00225 void  vcal(l2str *l2rec, l2prodstr *p, float vcal[]);
00226 double *get_xcal(l1str *l1rec, int type, int bandnum);
00227 
00228 float aw_spectra (int32_t wl, int32_t width);
00229 float bbw_spectra(int32_t wl, int32_t width);
00230 void  get_aw_bbw(l2str *l2rec, float wave[], int nwave, float *aw, float *bbw);
00231 float seawater_nsw (float wave, float sst, float sss, float *dnswds); 
00232 float seawater_bb (float wave, float sst, float sss); 
00233 void seawater_set(l1str *l1rec);
00234 float seawater_get_n(int32_t ivar, int32_t ip, int32_t ib);
00235 float seawater_get_a(int32_t ivar, int32_t ip, int32_t ib);
00236 float seawater_get_bb(int32_t ivar, int32_t ip, int32_t ib);
00237 
00238 int   atmocor1_land(instr *input, l1str *l1rec, int32_t ip);
00239 void  radcor(l1str *l1rec, int32_t ip, int land);
00240 void  polcor(l1str *l1rec, int32_t ip);
00241 int   get_rhos(l1str *l1rec, int32_t ip);
00242 int8  *get_qual_sst (l2str *l2rec);
00243 int8  *get_qual_sst4(l2str *l2rec);
00244 int16 *get_flags_sst (l2str *l2rec);
00245 int16 *get_flags_sst4(l2str *l2rec);
00246 float *get_sst (l2str *l2rec);
00247 float *get_sst4(l2str *l2rec);
00248 float *get_bias_sst (l2str *l2rec);
00249 float *get_bias_sst4(l2str *l2rec);
00250 float *get_stdv_sst (l2str *l2rec);
00251 float *get_stdv_sst4(l2str *l2rec);
00252 void  radiance2bt(l1str *l1rec, int resolution);
00253 float get_sstref(char *file, float lon, float lat, int day);
00254 float get_sssref(char *file, float lon, float lat, int day);
00255 void  calcite ( l2str *l2rec, l2prodstr *p, float caco3[]);
00256 void  tindx_morel(l2str *l2rec, int32_t ip, float *tindx);
00257 void  tindx_shi  (l2str *l2rec, int32_t ip, float *tindx);
00258 float conv_rrs_to_555(float Rrs, float wave);
00259 
00260 float water_vapor(int ib, float wv, float airmass);
00261 int ice_mask_init(char *file, int year, int day, float threshold);
00262 char ice_mask(float lon, float lat);
00263 float ice_fraction(float lon, float lat);
00264 void get_ice_frac(l2str *l2rec, float ice[]);
00265 void get_tauc(l2str *l2rec, float tauc[]);
00266 void get_mgiop(l2str *l2rec, l2prodstr *p, float prod[]);
00267 void get_gsm(l2str *l2rec, l2prodstr *p, float prod[]);
00268 int16 *get_iter_gsm(l2str *l2rec);
00269 void iops_gsm(l2str *l2rec);
00270 void get_giop(l2str *l2rec, l2prodstr *p, float prod[]);
00271 int16 *get_iter_giop(l2str *l2rec);
00272 int16 *get_flags_giop(l2str *l2rec);
00273 void iops_giop(l2str *l2rec);
00274 void get_carder(l2str *l2rec, l2prodstr *p, float prod[]);
00275 int16 *get_flags_carder(l2str *l2rec);
00276 void iops_carder(l2str *l2rec);
00277 void chl_carder_empirical(l2str *l2rec,float prod[]);
00278 void get_pml(l2str *l2rec, l2prodstr *p, float prod[]);
00279 void iops_pml(l2str *l2rec);
00280 void get_qaa(l2str *l2rec, l2prodstr *p, float prod[]);
00281 unsigned char *get_flags_qaa(l2str *l2rec);
00282 void iops_qaa(l2str *l2rec);
00283 void get_niwa(l2str *l2rec, l2prodstr *p, float prod[]);
00284 void iops_niwa(l2str *l2rec);
00285 int16 *get_flags_niwa(l2str *l2rec);
00286 void iops_las(l2str *l2rec);
00287 int get_bbp_qaa(l2str *l2rec, int ip, float tab_wave[], float tab_bbp[], int tab_nwave);
00288 int get_bbp_las(l2str *l2rec, int ip, float tab_wave[], float tab_bbp[], int tab_nwave);
00289 float get_bbp_las_eta(l2str *l2rec, int ip);
00290 void get_iops(l2str *l2rec, int32_t iop_opt);
00291 void set_iop_flag(float32 wave[], int32 nwave, 
00292                   float32 a[], float32 aph[], float32 adg[], 
00293                   float32 bb[], float32 bbp[],int16 *flag);
00294 float aph_bricaud(float wave, float chl);
00295 float aph_ciotti(float wave, float sf);
00296 float get_aphstar(float wave, int dwave, int ftype, float proxy);
00297 float rrs_above_to_below(float Rrs); 
00298 void optical_class(l2str *l2rec, l2prodstr *p, float prod[]);
00299 float *get_class_ward_owmc(l2str *l2rec);
00300 float *get_class_k_owmc(l2str *l2rec);
00301 float *get_class_34k_w_owmc(l2str *l2rec);
00302 
00303 void  myprod1 (l2str *l2rec, float prod[]);
00304 void  myprod2 (l2str *l2rec, float prod[]);
00305 void  myprod3 (l2str *l2rec, float prod[]);
00306 void  myprod4 (l2str *l2rec, float prod[]);
00307 void  myprod5 (l2str *l2rec, float prod[]);
00308 void  myprod6 (l2str *l2rec, float prod[]);
00309 void  myprod7 (l2str *l2rec, float prod[]);
00310 void  myprod8 (l2str *l2rec, float prod[]);
00311 void  myprod9 (l2str *l2rec, float prod[]);
00312 void  myprod10(l2str *l2rec, float prod[]);
00313 
00314 int get_f0_neckel   (int32_t wl, int32_t width, float *f0);
00315 int get_f0_thuillier(int32_t wl, int32_t width, float *f0);
00316 int get_f0_thuillier_ext(int32_t wl, int32_t width, float *f0);
00317 
00318 float32 westernmost( float32 lon1, float32 lon2 );
00319 float32 easternmost( float32 lon1, float32 lon2 );
00320 
00321 /* Filter functions */
00322 
00323 void  fctl_init(fctlstr *fctl);
00324 int   fctl_set (fctlstr *fctl, int32_t npix, char *fname, 
00325                 int32_t band, int32_t nx, int32_t ny, int32_t minfill);
00326 void  filter(fctlstr *fctl, l1qstr *l1que, l1str *l1rec);
00327 int   rdfilter( char *file, fctlstr *fctl );
00328 void  fdilate (l1qstr *l1que,int32_t nx,int32_t ny,int flag,char kernel[],l1str *l1rec);
00329 void  fclean  (l1qstr *l1que,int32_t nx,int32_t ny,int flag,char kernel[],l1str *l1rec);
00330 void  fLTmean (l1qstr *l1que,int32_t nx,int32_t ny,int ib,int32_t minfill,char kernel[],l1str *l1rec);
00331 void  fLTRmean(l1qstr *l1que,int32_t nx,int32_t ny,int ib,int32_t minfill,char kernel[],l1str *l1rec);
00332 void  fLTmed  (l1qstr *l1que,int32_t nx,int32_t ny,int ib,int32_t minfill,char kernel[],l1str *l1rec);
00333 void  fLTRmed (l1qstr *l1que,int32_t nx,int32_t ny,int ib,int32_t minfill,char kernel[],l1str *l1rec);
00334 void  fEPSmean(l1qstr *l1que,int32_t nx,int32_t ny,int ib,int32_t minfill,char kernel[],l1str *l1rec);
00335 void  fEPSiqmean(l1qstr *l1que,int32_t nx,int32_t ny,int ib,int32_t minfill,char kernel[],l1str *l1rec);
00336 void  fLTRiqmean(l1qstr *l1que,int32_t nx,int32_t ny,int ib,int32_t minfill,char kernel[],l1str *l1rec);
00337 void  fLTrat(l1qstr *l1que,int32_t nx,int32_t ny,l1str *l1rec);
00338 
00339 /* viirs pixel conversion */
00340 void viirs_pxcvt_2uag( int, int *, int * );
00341 void viirs_pxcvt_2ag( int, int * );
00342 void viirs_pxcvt_agdel( int, int, int * );
00343 
00344 /* Fortran functions called from C */
00345 
00346 void   sunangs_( int *, int *, float *, float *, float *, float *, float * );
00347 int    getglint_(float *, float *, float *, float *, float *, float *);
00348 int    getglint_iqu_(float *, float *, float *, float *, float *, float *, float *, float *);
00349 double esdist_( int32_t *year, int32_t *day, int32_t *msec);
00350 int    get_dem_height_(
00351           char  *demfile,
00352               float *lon, 
00353               float *lat, 
00354               float *senz,
00355               float *sena,
00356               float *height,   
00357               int32_t  *status);
00358 
00359 void get_um_prod_(int32_t* idProd, int32_t* pix, float* val);
00360 void clear_um_prod_();
00361 int atmcor_soa_(
00362           int32_t  *sensorID,
00363               char  *sensorNm, 
00364               int32_t  *nwave, 
00365               float *wave, 
00366               int32_t  *scan, 
00367               int32_t  *pixel,
00368               float *solz, 
00369               float *senz, 
00370               float *raz,
00371               float *lat,
00372               float *lon,
00373               float *Lt,
00374               float *rho_r,
00375               float *Fo,
00376               float *Tau_r,
00377               float *aw, 
00378               float *bbw, 
00379               float *aphstar, 
00380               float *adg_s, 
00381               float *bbp_s, 
00382               float *Rs,
00383               float *Rw,
00384               float *wv,
00385               float *t_sen,
00386               float *t_sol,
00387               float *optTaua,
00388               float *optW0,
00389               float *optChl,
00390               float *optAcdm,
00391               float *pcentCDM,
00392               float *optBbp,
00393               float *optMr,
00394               float *optMi,
00395               float *optV,
00396               int32_t  *status);
00397 
00398 void get_fdiff(l2str *l2rec, float fdiff[]);
00399 
00400 void get_cdom_morel(l2str *l2rec, l2prodstr *p, float prod[]);
00401 
00402 void optical_water_type(l2str *l2rec, l2prodstr *p, void *vptr);
00403 
00404 VOIDP prodgen( l2prodstr *p, l2str *l2rec);
00405 
00406 void virtual_constellation(l2str *l2rec, l2prodstr *p, float prod[]);
00407 
00408 void get_swim(l2str *l2rec, l2prodstr *p, float prod[]);
00409 
00410 void elev_init(char* elevFilename, char* elevAuxFilename);
00411 short get_elev(float lat, float lon);
00412 
00413 int read_target_l3(filehandle *file, l1str *l1rec, int32_t nbands, tgstr *tgrec);
00414 
00415 #ifdef __cplusplus
00416 }
00417 #endif
00418 
00419 #endif
00420 
00421 
00422 
00423