ocssw  1.0
/disk01/web/ocssw/build/src/viirs_sim_sdr/rhos_to_lt.c (r8102/r5074)
Go to the documentation of this file.
00001 #include "viirs_sim_sdr.h"
00002 #include "l12_parms.h"
00003 /*#include "l12_proto.h"  - Again, if we get the make more like ocssw 
00004    and maybe also need to move formally to that area */
00005 
00006 int rhos_to_lt( int rhos_opt, float **rhos, in_rec_struc *in_rec, int idet, 
00007   sdr_info_struc *sdr_info )
00008 /*-----------------------------------------------------------------------------
00009     Program:   rhos_to_lt
00010 
00011     Description:  convert the reflectance into Lt value and replace
00012       the Lt conditionally for a line in a scan of lines
00013 
00014     Arguments:
00015         Type      Name         I/O   Description
00016         ----      ----         ---   -----------
00017         int       rhos_opt      I    reflectance use option: 0 - replace 
00018                                      where Lt from ocean color is missing
00019                                      1 - replace everywhere
00020         float **  rhos          I    a scan's worth of reflectance
00021         in_rec_struc *  in_rec  I/O  input record structure with input values
00022                                      of atmospheric values and output of 
00023                                      final lt for simulated scan
00024         int       idet          I    line in scan to process
00025         sdr_info_struc * sdr_info I  general SDR information
00026 
00027     Modification history:
00028 
00029     W. Robinson, SAIC  18 Nov 2009  Original development
00030     W. Robinson, SAIC  12 Apr 2011  for a reflectance that is missing -999.
00031                 or just < 0., set the bnd_q = 2
00032 
00033 ----------------------------------------------------------------------------*/
00034   {
00035   int ipx, npix, ibnd, repl, loc;
00036   float lt[N_VNIR_BND], solz, senz, mu, mu0;
00037   float tg_sol, tg_sen, t_sol, t_sen, t_h2o, t_o2, lr, refl;
00038  /*  positions of parameter fields in the l2 record, see rd_sim_init */
00039   int loc_tg_sol = N_VNIR_BND * 2, loc_tg_sen = N_VNIR_BND * 3; 
00040   int loc_t_sol = N_VNIR_BND * 4, loc_t_sen = N_VNIR_BND * 5;
00041   int loc_t_h2o = N_VNIR_BND * 6, loc_t_o2 = N_VNIR_BND * 7;
00042   int loc_lr = N_VNIR_BND;
00043 
00044   npix = in_rec->npix;
00045  /*
00046   *  get lt from rhos for all pixels and lines in the scan
00047   */
00048   for( ipx = 0; ipx < npix; ipx++ )
00049     {
00050     loc = ipx + idet * npix;
00051     solz = *( in_rec->solz + loc );
00052     senz = *( in_rec->senz + loc );
00053     mu0 = cos( solz / RADEG );
00054     mu = cos( senz / RADEG );
00055   
00056    /*
00057     *  derive the Lt for each band
00058     */
00059     for( ibnd = 0; ibnd < N_VNIR_BND; ibnd++ )
00060       {
00061       refl = *( *rhos + ipx + ( idet + ibnd * in_rec->ndet_scan ) * npix );
00062       if( refl < 0. )
00063         lt[ibnd] = -999.;
00064       else
00065         {
00066         t_h2o = *( in_rec->l2_str.l2_data + ( loc_t_h2o + ibnd ) * npix + ipx );
00067         lr = *( in_rec->l2_str.l2_data + ( loc_lr + ibnd ) * npix + ipx );
00068         t_sen = *( in_rec->l2_str.l2_data + ( loc_t_sen + ibnd ) * npix + ipx );
00069         t_sol = *( in_rec->l2_str.l2_data + ( loc_t_sol + ibnd ) * npix + ipx );
00070         t_o2 = *( in_rec->l2_str.l2_data + ( loc_t_o2 + ibnd ) * npix + ipx );
00071         tg_sen = *( in_rec->l2_str.l2_data + 
00072           ( loc_tg_sen + ibnd ) * npix + ipx );
00073         tg_sol = *( in_rec->l2_str.l2_data + 
00074           ( loc_tg_sol + ibnd ) * npix + ipx );
00075         
00076         lt[ibnd] = tg_sol * tg_sen * 
00077            ( refl * in_rec->f0[ibnd] * mu0 * t_sol * t_sen * t_o2 /PI + 
00078            RAD_CGS_2_MKS *lr );
00079         }
00080       }
00081    /*
00082     *  examine all the ocean lt and decide on replacing it with the lt(rhos)
00083     *  Options are to replace if Lt < 0 or a bad value (rhos_opt=0)
00084     *  or replace al points (rhos_opt=1)
00085     */
00086     if( rhos_opt == 1 )
00087       repl = 1;
00088     else
00089       {
00090       repl = 0;
00091       for( ibnd = 0; ibnd < N_VNIR_BND; ibnd++ )
00092         {
00093         if( ( *( in_rec->bnd_lt[ibnd] + loc ) < 0. ) ||
00094             ( *( in_rec->bnd_q[ibnd] + loc ) == 2 ) )
00095           {
00096           repl = 1;
00097           break;
00098           }
00099         }
00100      /*
00101       *  now, assume all reflectance is good and fill
00102       */
00103       if( repl == 1 )
00104         for( ibnd = 0; ibnd < N_VNIR_BND; ibnd++ )
00105           {
00106           if( lt[ibnd] < -0.5 )
00107             {
00108             *( in_rec->bnd_lt[ibnd] + loc ) = 0.;
00109             *( in_rec->bnd_q[ibnd] + loc ) = 2;
00110             }
00111           else
00112             {
00113             *( in_rec->bnd_lt[ibnd] + loc ) = lt[ibnd];
00114             *( in_rec->bnd_q[ibnd] + loc ) = 0;
00115             }
00116           }
00117       }
00118     }
00119   return 0;
00120   }