ocssw  1.0
/disk01/web/ocssw/build/src/viirs_sim_sdr/fin_sdr.c (r9883/r5304)
Go to the documentation of this file.
00001 #include "viirs_sim_sdr.h"
00002 
00003 int fin_sdr( ctl_struc *ctl, in_rec_struc *in_rec, out_rec_struc *out_rec )
00004 /*-----------------------------------------------------------------------------
00005     Program:   fin_sdr
00006 
00007     Description:  finish up on the simulation processing: close input
00008       and output dataset IDs
00009 
00010     Arguments:
00011         Type      Name         I/O   Description
00012         ----      ----         ---   -----------
00013         ctl_struc * ctl         I    processing controls
00014         in_rec_struc * in_rec   I    input record controls
00015         out_rec_struc * out_rec   I/O  output record controls
00016 
00017     Modification history:
00018 
00019     W. Robinson, SAIC  21 Oct 2008  Original development
00020 
00021 ----------------------------------------------------------------------------*/
00022   {
00023   int iid, jid, isdr, ibnd;
00024  /*
00025   *  Input dataset controls
00026   *  geolocation
00027   */
00028   for( iid = 0; iid < 6; iid++ )
00029     {
00030     if( h5io_close( &( in_rec->geo_dat_id[ iid ] ) ) != 0 ) 
00031       {
00032       printf( "%s: Unable to close input geoloc dataset # %d\n", 
00033         __FILE__, iid );
00034       return 1;
00035       }
00036     }
00037 
00038   if( h5io_close( &( in_rec->geo_fid ) ) != 0 )
00039     {
00040     printf( "%s: Unable to close input geoloc file\n", __FILE__ );
00041     return 1;
00042     }
00043  /*
00044   *  compute the granule latitude, longitude limits
00045   *  this could be placed in the dataset, if needed, in the future
00046   */
00047   printf( "latitude limits, S: %f, N: %f\n", in_rec->ll_lims[0], 
00048     in_rec->ll_lims[1] );
00049   printf( "(-) longitude limits, W: %f, E: %f\n", in_rec->ll_lims[2],
00050     in_rec->ll_lims[3] );
00051   printf( "(+) longitude limits, W: %f, E: %f\n", in_rec->ll_lims[4],
00052     in_rec->ll_lims[5] );
00053   /* w_lim = -180.;
00054   e_lim = 180.;
00055    we'll have to make some kind of actual W, E limits */
00056  /*
00057   *  Output dataset controls
00058   *  geolocation and then band data ids
00059   */
00060   for( iid = 0; iid < 6; iid++ )
00061     {
00062     if( h5io_close( &( out_rec->geo_dat_id[ iid ] ) ) != 0 )
00063       {
00064       printf( "%s: Unable to close output geoloc dataset id # %d\n", 
00065         __FILE__, iid );
00066       return 1;
00067       }
00068     }
00069   for( isdr = 0; isdr < out_rec->nbnd; isdr++ )
00070     {
00071     for( iid = 0; iid < 2; iid++ )
00072       {
00073       if( h5io_close( &( out_rec->bnd_dat_id[iid][isdr] ) ) != 0 )
00074         {
00075         printf( "%s: Unable to close output band file # %d, dataset # %d\n",
00076           __FILE__, isdr, iid );
00077         return 1;
00078         }
00079       }
00080    /*
00081     *  QF1_VIIRSMBANDSDR dataset id close
00082     */
00083     if( h5io_close( &( out_rec->qual1_m_id[isdr] ) ) != 0 )
00084       {
00085       printf( 
00086         "%s, %d: Failed closing output QF1_VIIRSMBANDSDR dataset file # %d\n",
00087         __FILE__, __LINE__, isdr );
00088       return 1;
00089       }
00090     }
00091  /*  open groups  */
00092   for( isdr = 0; isdr < out_rec->nbnd + 1; isdr++ )
00093     {
00094     for( iid = 0; iid < 2; iid++ )
00095       {
00096       jid = 1 - iid;
00097       if( h5io_close( &( out_rec->sdr_dat_gid[ jid ][isdr] ) ) != 0 )
00098         {
00099         printf( "%s: Unable to close output sdr group id # %d, sdr # %d\n", 
00100           __FILE__, jid, isdr );
00101         return 1;
00102         }
00103       }
00104     }
00105  /* open files  */
00106   for( isdr = 0; isdr < out_rec->nbnd + 1; isdr++ )
00107     {
00108     if( h5io_close( &( out_rec->sdr_fid[isdr] ) ) != 0 )
00109       {
00110       printf( "%s: Unable to close output sdr file for sdr# %d\n", 
00111         __FILE__, isdr );
00112       return 1;
00113       }
00114     }
00115  /* close the L2 file if used */
00116   if( ctl->l2_use == 1 )
00117     if( closeL2( &in_rec->l2_str, 0 ) != 0 )
00118       {
00119       printf( "%s: Unable to close input L2 file: %s\n",
00120         __FILE__, in_rec->l2_str.filename );
00121       return 1;
00122       }
00123  /*
00124   *  free data storage, note that the in_rec->lat of NULL signals frees 
00125   *  in scan_cvt
00126   */
00127   free( in_rec->lat );
00128   in_rec->lat = NULL;
00129   if( scan_cvt( in_rec, out_rec ) != 0 )
00130     return 1;
00131   free( in_rec->lon );
00132   free( in_rec->sena );
00133   free( in_rec->senz );
00134   free( in_rec->sola );
00135   free( in_rec->solz );
00136   for( ibnd = 0; ibnd < out_rec->nbnd; ibnd++ )
00137     {
00138     free( in_rec->bnd_lt[ibnd] );
00139     free( in_rec->bnd_q[ibnd] );
00140     free( out_rec->qual1_m[ibnd] );
00141     free( in_rec->gain_bit[ibnd] );
00142     free( in_rec->dn_sat[ibnd] );
00143     if( ctl->count_cal_opt != 0 )
00144       {
00145       free( in_rec->dn[ibnd] );
00146       }
00147     }
00148  /*
00149   *  clean up for artifact use
00150   *  free the electronic crosstalk internal storage
00151   */
00152   if( ctl->ext_opt != 0 )
00153     if( viirs_ext( ctl, in_rec ) != 0 )
00154       return 1;
00155  /*  for the noise and stray light generation  */
00156   if( ctl->noise_mode == 1 )
00157     viirs_noise( ctl, in_rec, 1 );
00158   if( ctl->stray_opt == 1 )
00159     viirs_straylt( ctl, in_rec, 1 );
00160 
00161   return 0;
00162   }