ocssw  1.0
/disk01/web/ocssw/build/src/l1agen_czcs/cz_clean.c (r8106/r3)
Go to the documentation of this file.
00001 #include "l1czcs.h"
00002 
00003 int cz_clean( gattr_struc *gattr, l1_data_struc *l1_data )
00004 /*******************************************************************
00005 
00006    cz_clean
00007 
00008    purpose: clean up the czcs data for the following
00009      - bad time in the lines (solution - remove lines)
00010 
00011    Returns type: int - 0 no problems, else no good lines left in file
00012 
00013    Parameters: (in calling order)
00014       Type              Name            I/O     Description
00015       ----              ----            ---     -----------
00016       gattr_struc *     gattr           I/O     structure with final 
00017                                                 attributes
00018       l1_data_struc *   l1_data         I/O     arrays data counts, lat, lons
00019 
00020    Modification history:
00021       Programmer        Date            Description of change
00022       ----------        ----            ---------------------
00023       W. Robinson       23-Sep-2004     Original development, 
00024       W. Robinson, SAIC 19 Dec 2005     add the pos_err array to this
00025 
00026 *******************************************************************/
00027   {
00028   int i, linout = 0, nlin, npix, nctl_pix, msec, icompr, j, ncompr;
00029 
00030  /*
00031   *  loop through the scan lines, any bad lines are compressed out
00032   *  and the # scan lines is adjusted accordingly
00033   */
00034   nlin = gattr->scan_lines;
00035   npix = gattr->pix_per_scan;
00036   nctl_pix = gattr->n_ctl_pt;
00037   icompr = 0;
00038 
00039   for( i = 0; i < nlin; i++ )
00040     {
00041    /*
00042     *  currently, the only check is on the msec in each line
00043     */
00044     msec = *( l1_data->msec + i );
00045    /*
00046     *  if a bad msec found, don't incriment the output line and note that 
00047     *  compression must be done
00048     */
00049     if( ( msec < 0 ) || ( msec > 86399999 ) )
00050       {
00051       icompr = 1;
00052       }
00053     else
00054       {
00055      /*
00056       *  once the compress switch is on, copy lines to proper place
00057       */
00058       if( icompr == 1 ) 
00059         {
00060         for( j = 0; j < 6; j++ )
00061           memcpy( l1_data->counts[j] + npix * linout, 
00062                   l1_data->counts[j] + npix * i, npix );
00063         *( l1_data->msec + linout ) = *( l1_data->msec + i );
00064         memcpy( l1_data->ctl_pt_lat + nctl_pix * linout,
00065                 l1_data->ctl_pt_lat + nctl_pix * i, 
00066                 nctl_pix * sizeof( float ) );
00067         memcpy( l1_data->ctl_pt_lon + nctl_pix * linout,
00068                 l1_data->ctl_pt_lon + nctl_pix * i, 
00069                 nctl_pix * sizeof( float ) );
00070        /*  note that ctl_pt_cols, ctl_pt_rows don't need change  */
00071         *( l1_data->tilt + linout ) = *( l1_data->tilt + i );
00072         *( l1_data->slat + linout ) = *( l1_data->slat + i );
00073         *( l1_data->slon + linout ) = *( l1_data->slon + i );
00074         *( l1_data->clat + linout ) = *( l1_data->clat + i );
00075         *( l1_data->clon + linout ) = *( l1_data->clon + i );
00076         *( l1_data->elat + linout ) = *( l1_data->elat + i );
00077         *( l1_data->elon + linout ) = *( l1_data->elon + i );
00078         memcpy( l1_data->cal_sum + 5 * linout, 
00079                 l1_data->cal_sum + 5 * i, 5 * sizeof( unsigned char ) );
00080         memcpy( l1_data->cal_scan + 6 * linout, 
00081                 l1_data->cal_scan + 6 * i, 6 * sizeof( unsigned char ) );
00082         memcpy( l1_data->orb_vec + 3 * linout, 
00083                 l1_data->orb_vec + 3 * i, 3 * sizeof( float ) );
00084         memcpy( l1_data->att_ang + 3 * linout,
00085                 l1_data->att_ang + 3 * i, 3 * sizeof( float ) );
00086         *( l1_data->pos_err + linout ) = *( l1_data->pos_err + i );
00087         memcpy( l1_data->slope + 6 * linout,
00088                 l1_data->slope + 6 * i, 6 * sizeof( float ) );
00089         memcpy( l1_data->intercept + 6 * linout,
00090                 l1_data->intercept + 6 * i, 6 * sizeof( float ) );
00091         *( l1_data->gain + linout ) = *( l1_data->gain + i );
00092 #ifdef GEOM_CAL
00093         memcpy( l1_data->sen_zen + npix * linout,
00094                 l1_data->sen_zen + npix * i, npix * sizeof( float ) );
00095         memcpy( l1_data->sen_az + npix * linout,
00096                 l1_data->sen_az + npix * i, npix * sizeof( float ) );
00097         memcpy( l1_data->sol_zen + npix * linout,
00098                 l1_data->sol_zen + npix * i, npix * sizeof( float ) );
00099         memcpy( l1_data->sol_az + npix * linout,
00100                 l1_data->sol_az + npix * i, npix * sizeof( float ) );
00101         memcpy( l1_data->all_lat + npix * linout,
00102                 l1_data->all_lat + npix * i, npix * sizeof( float ) );
00103         memcpy( l1_data->all_lon + npix * linout,
00104                 l1_data->all_lon + npix * i, npix * sizeof( float ) );
00105         memcpy( l1_data->Lt_443 + npix * linout,
00106                 l1_data->Lt_443 + npix * i, npix * sizeof( float ) );
00107         memcpy( l1_data->Lt_520 + npix * linout,
00108                 l1_data->Lt_520 + npix * i, npix * sizeof( float ) );
00109         memcpy( l1_data->Lt_550 + npix * linout,
00110                 l1_data->Lt_550 + npix * i, npix * sizeof( float ) );
00111         memcpy( l1_data->Lt_670 + npix * linout,
00112                 l1_data->Lt_670 + npix * i, npix * sizeof( float ) );
00113         memcpy( l1_data->Lt_750 + npix * linout,
00114                 l1_data->Lt_750 + npix * i, npix * sizeof( float ) );
00115         memcpy( l1_data->Lt_11500 + npix * linout,
00116                 l1_data->Lt_11500 + npix * i, npix * sizeof( float ) );
00117 #endif
00118         }
00119       linout++;
00120       }
00121     }
00122  /*
00123   *  re-set the # lines and # control lines
00124   */
00125   gattr->scan_lines = linout;
00126   gattr->n_ctl_lin = linout;
00127  /*
00128   *  and end
00129   */
00130   if( icompr != 0 )
00131     {
00132     ncompr = nlin - linout;
00133     printf( "cz_clean: %d bad lines (of %d) were compressed out of the L1 file\n",
00134       ncompr, nlin );
00135     }
00136   if( linout == 0 )
00137     {
00138     printf( "cz_clean: No good lines were found in the file\n" );
00139     return -1;
00140     }
00141   else
00142     return 0;  
00143   }