コード例 #1
0
ファイル: mvc_model.cpp プロジェクト: vadz/lmi.new
void MvcModel::Transmogrify()
{
    typedef NamesType::const_iterator ntci;
    for(ntci i = Names().begin(); i != Names().end(); ++i)
        {
        DoEnforceCircumscription(*i);
        DoEnforceProscription   (*i);
        }
    DoTransmogrify();
}
コード例 #2
0
void THierarchicalStorage::ReadValues(TStrings * Strings,
  bool MaintainKeys)
{
  std::unique_ptr<TStrings> Names(new TStringList());
  try__finally
  {
    GetValueNames(Names.get());
    for (intptr_t Index = 0; Index < Names->GetCount(); ++Index)
    {
      if (MaintainKeys)
      {
        Strings->Add(FORMAT(L"%s=%s", Names->GetString(Index).c_str(),
          ReadString(Names->GetString(Index), L"").c_str()));
      }
      else
      {
        Strings->Add(ReadString(Names->GetString(Index), L""));
      }
    }
  }
  __finally
  {
/*
    delete Names;
*/
  };
}
コード例 #3
0
ファイル: ArpConfigureFile.cpp プロジェクト: dtbinh/Sequitur
status_t ArpConfigureFile::ApplySettings(const BMessage* from)
{
    if( from == 0 ) return B_BAD_VALUE;

    const ArpVectorI<ArpConfigurableI*>& configs = Configs();
    const ArpVectorI<BString>& names = Names();

    status_t err = B_OK;

    for( size_t i=0; err == B_OK && i<configs.size(); i++ ) {
        if( configs[i] ) {
            if( i < names.size() && names[i] != "" ) {
                BMessage msg;
                err = from->FindMessage(names[i].String(), &msg);
                if( err == B_OK ) {
                    err = configs[i]->PutConfiguration(&msg);
                }
            } else {
                err = configs[i]->PutConfiguration(from);
            }
        }
    }

    return err;
}
コード例 #4
0
ファイル: ArpConfigureFile.cpp プロジェクト: dtbinh/Sequitur
status_t ArpConfigureFile::MakeSettings(BMessage* in) const
{
    if( in == 0 ) return B_BAD_VALUE;

    const ArpVectorI<ArpConfigurableI*>& configs = Configs();
    const ArpVectorI<BString>& names = Names();

    status_t err = B_OK;

    for( size_t i=0; err == B_OK && i<configs.size(); i++ ) {
        if( configs[i] ) {
            if( i < names.size() && names[i] != "" ) {
                BMessage msg;
                err = configs[i]->GetConfiguration(&msg);
                if( err == B_OK ) {
                    err = in->AddMessage(names[i].String(), &msg);
                }
            } else {
                err = configs[i]->GetConfiguration(in);
            }
        }
    }

    return err;
}
コード例 #5
0
string
HinduLunisolarCalendarService::Respond( CalendarService::Action action,
                                        string calendarName,
                                        CalendarService::Format format )
{
    CGIInput & cgiInput = CGIInput::Instance();
    string versionName = cgiInput[ "version" ];
    HinduLunisolarCalendar::EVersion version = HinduLunisolarCalendar::Modern;
    for ( int i = 0; i < HinduLunisolarCalendar::NumVersions; ++i )
        if ( s_versionNames[ i ] == versionName )
        {
            version = HinduLunisolarCalendar::EVersion( i );
            break;
        }
    HinduLunisolarCalendar::SetVersion( version );

    switch ( action )
    {
    case CalendarService::AvailableOptions:
        return AvailableOptions( calendarName, format );
    case CalendarService::Names:
        return Names( calendarName, format );
    case CalendarService::DateToJD:
        return DateToJD( calendarName, format );
    case CalendarService::JDToDate:
        return JDToDate( calendarName, format );
    case CalendarService::MonthData:
        return MonthData( calendarName, format );
    default:
        throw Exception( "Unexpected action for "
                         + calendarName + " calendar." );
    }
}
コード例 #6
0
bool TRegistryStorage::Copy(TRegistryStorage * Storage)
{
  TRegistry * Registry = Storage->FRegistry;
  bool Result = true;
  std::unique_ptr<TStrings> Names(new TStringList());
  try__finally
  {
    rde::vector<uint8_t> Buffer(1024);
    Registry->GetValueNames(Names.get());
    intptr_t Index = 0;
    while ((Index < Names->GetCount()) && Result)
    {
      UnicodeString Name = MungeStr(Names->GetString(Index), GetForceAnsi());
      DWORD Size = static_cast<DWORD>(Buffer.size());
      DWORD Type;
      int RegResult = 0;
      do
      {
        RegResult = ::RegQueryValueEx(Registry->GetCurrentKey(), Name.c_str(), nullptr,
          &Type, &Buffer[0], &Size);
        if (RegResult == ERROR_MORE_DATA)
        {
          Buffer.resize(Size);
        }
      }
      while (RegResult == ERROR_MORE_DATA);

      Result = (RegResult == ERROR_SUCCESS);
      if (Result)
      {
        RegResult = ::RegSetValueEx(FRegistry->GetCurrentKey(), Name.c_str(), 0, Type,
          &Buffer[0], Size);
        Result = (RegResult == ERROR_SUCCESS);
      }

      ++Index;
    }
  }
  __finally
  {
/*
    delete Names;
*/
  };
  return Result;
}
コード例 #7
0
void THierarchicalStorage::ClearValues()
{
  std::unique_ptr<TStrings> Names(new TStringList());
  try__finally
  {
    GetValueNames(Names.get());
    for (intptr_t Index = 0; Index < Names->GetCount(); ++Index)
    {
      DeleteValue(Names->GetString(Index));
    }
  }
  __finally
  {
/*
    delete Names;
*/
  };
}
コード例 #8
0
std::string
DMYWCalendarService< C, W, O >::Respond( CalendarService::Action action,
                                         std::string calendarName,
                                         CalendarService::Format format )
{
    O::Set( );
    switch ( action )
    {
    case CalendarService::AvailableOptions:
        return AvailableOptions( calendarName, format );
    case CalendarService::Names:
        return Names( calendarName, format );
    case CalendarService::DateToJD:
        return DateToJD( calendarName, format );
    case CalendarService::JDToDate:
        return JDToDate( calendarName, format );
    case CalendarService::MonthData:
        return MonthData( calendarName, format );
    default:
        throw Exception( "Unexpected action for "
                         + calendarName + " calendar." );
    }
}
コード例 #9
0
ファイル: Configuration.cpp プロジェクト: elfmz/far2l
void TConfiguration::CopyData(THierarchicalStorage * Source,
  THierarchicalStorage * Target)
{
  std::unique_ptr<TStrings > Names(new TStringList());
  try__finally
  {
    if (Source->OpenSubKey(GetConfigurationSubKey(), false))
    {
      if (Target->OpenSubKey(GetConfigurationSubKey(), true))
      {
        if (Source->OpenSubKey("CDCache", false))
        {
          if (Target->OpenSubKey("CDCache", true))
          {
            Names->Clear();
            Source->GetValueNames(Names.get());

            for (intptr_t Index = 0; Index < Names->GetCount(); ++Index)
            {
              Target->WriteBinaryData(Names->GetString(Index),
                Source->ReadBinaryData(Names->GetString(Index)));
            }

            Target->CloseSubKey();
          }
          Source->CloseSubKey();
        }

        if (Source->OpenSubKey("Banners", false))
        {
          if (Target->OpenSubKey("Banners", true))
          {
            Names->Clear();
            Source->GetValueNames(Names.get());

            for (intptr_t Index = 0; Index < Names->GetCount(); ++Index)
            {
              Target->WriteString(Names->GetString(Index),
                Source->ReadString(Names->GetString(Index), L""));
            }

            Target->CloseSubKey();
          }
          Source->CloseSubKey();
        }

        Target->CloseSubKey();
      }
      Source->CloseSubKey();
    }

    if (Source->OpenSubKey(GetSshHostKeysSubKey(), false))
    {
      if (Target->OpenSubKey(GetSshHostKeysSubKey(), true))
      {
        Names->Clear();
        Source->GetValueNames(Names.get());

        for (intptr_t Index = 0; Index < Names->GetCount(); ++Index)
        {
          Target->WriteStringRaw(Names->GetString(Index),
            Source->ReadStringRaw(Names->GetString(Index), L""));
        }

        Target->CloseSubKey();
      }
      Source->CloseSubKey();
    }
  }
  __finally
  {
//    delete Names;
  };
}
コード例 #10
0
int
main(int argc, char **argv)
{
    int done;
    char units[16], fname[80];
    int optc;

    while ( (optc = bu_getopt( argc, argv, "tsmnc" )) != -1)
    {
	switch ( optc )	/* Set joint type and cable option */
	{
	    case 't':
		torus = 1;
		break;
	    case 's':
		sphere = 1;
		break;
	    case 'm':
		mitre = 1;
		break;
	    case 'n':
		nothing = 1;
		break;
	    case 'c':
		cable = 1;
		break;
	    case '?':
		fprintf( stderr, "Illegal option %c\n", optc );
		Usage();
		return 1;
		break;

	}
    }

    if ( (torus + sphere + mitre + nothing) > 1 ) /* Too many joint options */
    {
	Usage();
	fprintf( stderr, "Options t, s, m, n are mutually exclusive\n" );
	return 1;
    }
    else if ( (torus + sphere + mitre + nothing) == 0 ) {
	torus = 1;		/* default */
    }

    if ( (argc - bu_optind) != 2 ) {
	Usage();
	return 1;
    }

    bu_strlcpy( name, argv[bu_optind++], sizeof(name) ); /* Base name for objects */

    fdout = wdb_fopen( argv[bu_optind] );
    if ( fdout == NULL )
    {
	fprintf( stderr, "Cannot open %s\n", argv[bu_optind] );
	perror( "Pipe" );
	Usage();
	return 1;
    }

    MAT_IDN(identity);	/* Identity matrix for all objects */
    pi = atan2( 0.0, -1.0 );	/* PI */

    printf( "FLUID & PIPING V%d.%d 10 Mar 89\n\n", VERSION, RELEASE );
    printf( "append %s to your target description using 'concat' in mged\n", argv[bu_optind] );

    k = 0.0;
    while ( k == 0.0 )
    {
	printf( "UNITS? (ft, in, m, cm, default is millimeters) ");
	bu_fgets(units, sizeof(units), stdin);
	switch (units[0])
	{

	    case '\0':
		k = 1.0;
		break;

	    case 'f':
		k = 12*25.4;
		break;

	    case 'i':
		k=25.4;
		break;

	    case 'm':
		if ( units[1] == '\0') k=1000.0;
		else k=1.0;
		break;

	    case 'c':
		k=10.0;
		break;

	    default:
		k=0.0;
		printf( "\n\t%s is not a legal choice for units\n", units );
		printf( "\tTry again\n" );
		break;
	}
    }

    done = 0;
    while ( !done )
    {
	if ( !cable ) {
	    printf( "radius and wall thickness: ");
	    if (scanf("%lf %lf", &radius, &wall) == EOF )
		return 1;
	    if (radius > wall)
		done = 1;
	    else
	    {
		printf( " *** bad input!\n\n");
		printf( "\tradius must be larger than wall thickness\n" );
		printf( "\tTry again\n" );
	    }
	}
	else {
	    printf( "radius: ");
	    if ( scanf("%lf", &radius ) == EOF )
		return 1;
	    done=1;
	}
    }
    radius=k*radius;
    wall=k*wall;

    Readpoints();	/* Read data points */

    Names();	/* Construct names for all solids */

    Normals();	/* Calculate normals and other vectors */

    Adjust();       /* Adjust points to allow for elbows */

/*	Generate Title */

    bu_strlcpy(fname, name, sizeof(fname));

    if ( !cable )
	bu_strlcat(fname, " pipe and fluid", sizeof(fname));
    else
	bu_strlcat(fname, " cable", sizeof(fname));

/*	Create ident record	*/

    mk_id(fdout, fname);

    Pipes();	/* Construct the piping */

    Elbows();	/* Construct the elbow sections */

    Groups();	/* Make some groups */

    return 0;
}
コード例 #11
0
InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(
    const ASTPtr & query_ptr_,
    const Context & context_,
    const Names & required_result_column_names,
    QueryProcessingStage::Enum to_stage_,
    size_t subquery_depth_,
    bool only_analyze,
    bool modify_inplace)
    : query_ptr(query_ptr_),
    context(context_),
    to_stage(to_stage_),
    subquery_depth(subquery_depth_)
{
    const ASTSelectWithUnionQuery & ast = typeid_cast<const ASTSelectWithUnionQuery &>(*query_ptr);

    size_t num_selects = ast.list_of_selects->children.size();

    if (!num_selects)
        throw Exception("Logical error: no children in ASTSelectWithUnionQuery", ErrorCodes::LOGICAL_ERROR);

    /// Initialize interpreters for each SELECT query.
    /// Note that we pass 'required_result_column_names' to first SELECT.
    /// And for the rest, we pass names at the corresponding positions of 'required_result_column_names' in the result of first SELECT,
    ///  because names could be different.

    nested_interpreters.reserve(num_selects);

    std::vector<Names> required_result_column_names_for_other_selects(num_selects);
    if (!required_result_column_names.empty() && num_selects > 1)
    {
        /// Result header if there are no filtering by 'required_result_column_names'.
        /// We use it to determine positions of 'required_result_column_names' in SELECT clause.

        Block full_result_header = InterpreterSelectQuery(
            ast.list_of_selects->children.at(0), context, Names(), to_stage, subquery_depth, true).getSampleBlock();

        std::vector<size_t> positions_of_required_result_columns(required_result_column_names.size());
        for (size_t required_result_num = 0, size = required_result_column_names.size(); required_result_num < size; ++required_result_num)
            positions_of_required_result_columns[required_result_num] = full_result_header.getPositionByName(required_result_column_names[required_result_num]);

        for (size_t query_num = 1; query_num < num_selects; ++query_num)
        {
            Block full_result_header_for_current_select = InterpreterSelectQuery(
                ast.list_of_selects->children.at(query_num), context, Names(), to_stage, subquery_depth, true).getSampleBlock();

            if (full_result_header_for_current_select.columns() != full_result_header.columns())
                throw Exception("Different number of columns in UNION ALL elements:\n"
                    + full_result_header.dumpNames()
                    + "\nand\n"
                    + full_result_header_for_current_select.dumpNames() + "\n",
                    ErrorCodes::UNION_ALL_RESULT_STRUCTURES_MISMATCH);

            required_result_column_names_for_other_selects[query_num].reserve(required_result_column_names.size());
            for (const auto & pos : positions_of_required_result_columns)
                required_result_column_names_for_other_selects[query_num].push_back(full_result_header_for_current_select.getByPosition(pos).name);
        }
    }

    for (size_t query_num = 0; query_num < num_selects; ++query_num)
    {
        const Names & current_required_result_column_names
            = query_num == 0 ? required_result_column_names : required_result_column_names_for_other_selects[query_num];

        nested_interpreters.emplace_back(std::make_unique<InterpreterSelectQuery>(
            ast.list_of_selects->children.at(query_num),
            context,
            current_required_result_column_names,
            to_stage,
            subquery_depth,
            only_analyze,
            modify_inplace));
    }

    /// Determine structure of the result.

    if (num_selects == 1)
    {
        result_header = nested_interpreters.front()->getSampleBlock();
    }
    else
    {
        Blocks headers(num_selects);
        for (size_t query_num = 0; query_num < num_selects; ++query_num)
            headers[query_num] = nested_interpreters[query_num]->getSampleBlock();

        result_header = headers.front();
        size_t num_columns = result_header.columns();

        for (size_t query_num = 1; query_num < num_selects; ++query_num)
            if (headers[query_num].columns() != num_columns)
                throw Exception("Different number of columns in UNION ALL elements:\n"
                    + result_header.dumpNames()
                    + "\nand\n"
                    + headers[query_num].dumpNames() + "\n",
                    ErrorCodes::UNION_ALL_RESULT_STRUCTURES_MISMATCH);

        for (size_t column_num = 0; column_num < num_columns; ++column_num)
        {
            ColumnWithTypeAndName & result_elem = result_header.getByPosition(column_num);

            /// Determine common type.

            DataTypes types(num_selects);
            for (size_t query_num = 0; query_num < num_selects; ++query_num)
                types[query_num] = headers[query_num].getByPosition(column_num).type;

            result_elem.type = getLeastSupertype(types);

            /// If there are different constness or different values of constants, the result must be non-constant.

            if (result_elem.column->isColumnConst())
            {
                bool need_materialize = false;
                for (size_t query_num = 1; query_num < num_selects; ++query_num)
                {
                    const ColumnWithTypeAndName & source_elem = headers[query_num].getByPosition(column_num);

                    if (!source_elem.column->isColumnConst()
                        || (static_cast<const ColumnConst &>(*result_elem.column).getField()
                            != static_cast<const ColumnConst &>(*source_elem.column).getField()))
                    {
                        need_materialize = true;
                        break;
                    }
                }

                if (need_materialize)
                    result_elem.column = result_elem.type->createColumn();
            }

            /// BTW, result column names are from first SELECT.
        }
    }
}
コード例 #12
0
NS_IMETHODIMP
HTMLPropertiesCollection::GetNames(nsIDOMDOMStringList** aResult)
{
  NS_ADDREF(*aResult = Names());
  return NS_OK;
}
コード例 #13
0
ファイル: output.cpp プロジェクト: RelativePrime/usgs
bool PutMetadata(Output_t *ds_output, int nband, Input_meta_t *meta, Param_t *param,
                 Lut_t *lut, Geo_bounds_t* bounds)
/* 
!C******************************************************************************

!Description: 'PutMetadata' writes metadata to the output file.
 
!Input Parameters:
 ds_output           'output' data structure; the following fields are input:
                   open
 geoloc         'geoloc' data structure; the following fields are input:
                   (none)
 input          'input' data structure;  the following fields are input:
                   (none)

!Output Parameters:
 ds_output           'output' data structure; the following fields are modified:
                   (none)
 (returns)      status:
                  'true' = okay
		  'false' = error return

!Team Unique Header:

 ! Design Notes:
   1. ds_output routine is currently a 'stub' and will be implemented later.
   2. An error status is returned when:
       a. the file is not open for access.
   3. Error messages are handled with the 'RETURN_ERROR' macro.
   4. 'OutputFile' must be called before ds_output routine is called.

!END****************************************************************************
*/
{
  Myhdf_attr_t attr;
  char date[MAX_DATE_LEN + 1];
/*double dval[1];     */
  double dval[NBAND_REFL_MAX];
  char *string
     , short_name[250]
     , local_granule_id[250]
     , production_date[MAX_DATE_LEN + 1]
     , pge_ver[100]
     , process_ver[100]
     , long_name[250]
    ;
  int ib;
  const char *qa_band_names[NUM_QA_BAND] = {"fill_QA", "DDV_QA", "cloud_QA",
    "cloud_shadow_QA", "snow_QA", "land_water_QA", "adjacent_cloud_QA"};
  char *QA_on[NBAND_SR_EXTRA] = {"N/A", "fill", "dark dense vegetation",
    "cloud", "cloud shadow", "snow", "water", "adjacent cloud", "N/A", "N/A",
    "N/A"};
  char *QA_off[NBAND_SR_EXTRA] = {"N/A", "not fill", "clear", "clear",
    "clear", "clear", "land", "clear", "N/A", "N/A", "N/A"};
  char* units_b;
  char*  message;
  char lndsr_QAMAP[1000];

  /* Check the parameters */

  if (!ds_output->open)
    RETURN_ERROR("file not open", "PutMetadata", false);

  if (nband < 1  ||  nband > NBAND_REFL_MAX)
    RETURN_ERROR("invalid number of bands", "PutMetadata", false);

  /* Write the metadata */

  attr.id = -1;

  if (meta->provider != PROVIDER_NULL) {
    string = Provider_string[meta->provider].string;
    attr.type = DFNT_CHAR8;
    attr.nval = strlen(string);
    attr.name = OUTPUT_PROVIDER;
    if (!PutAttrString(ds_output->sds_file_id, &attr, string))
      RETURN_ERROR("writing attribute (data provider)", "PutMetadata", false);
  }

  if (meta->sat != SAT_NULL) {
    string = Sat_string[meta->sat].string;
    attr.type = DFNT_CHAR8;
    attr.nval = strlen(string);
    attr.name = OUTPUT_SAT;
    if (!PutAttrString(ds_output->sds_file_id, &attr, string))
      RETURN_ERROR("writing attribute (satellite)", "PutMetadata", false);
  }

  if (meta->inst != INST_NULL) {
    string = Inst_string[meta->inst].string;
    attr.type = DFNT_CHAR8;
    attr.nval = strlen(string);
    attr.name = OUTPUT_INST;
    if (!PutAttrString(ds_output->sds_file_id, &attr, string))
      RETURN_ERROR("writing attribute (instrument)", "PutMetadata", false);
  }

  if (!FormatDate(&meta->acq_date, DATE_FORMAT_DATEA_TIME, date))
    RETURN_ERROR("formating acquisition date", "PutMetadata", false);
  attr.type = DFNT_CHAR8;
  attr.nval = strlen(date);
  attr.name = OUTPUT_ACQ_DATE;
  if (!PutAttrString(ds_output->sds_file_id, &attr, date))
    RETURN_ERROR("writing attribute (acquisition date)", "PutMetadata", false);

  if (!FormatDate(&meta->prod_date, DATE_FORMAT_DATEA_TIME, date))
    RETURN_ERROR("formating production date", "PutMetadata", false);
  attr.type = DFNT_CHAR8;
  attr.nval = strlen(date);
  attr.name = OUTPUT_L1_PROD_DATE;
  if (!PutAttrString(ds_output->sds_file_id, &attr, date))
    RETURN_ERROR("writing attribute (production date)", "PutMetadata", false);

  attr.type = DFNT_FLOAT32;
  attr.nval = 1;
  attr.name = OUTPUT_SUN_ZEN;
  dval[0] = (double)meta->sun_zen * DEG;
  if (!PutAttrDouble(ds_output->sds_file_id, &attr, dval))
    RETURN_ERROR("writing attribute (solar zenith)", "PutMetadata", false);

  attr.type = DFNT_FLOAT32;
  attr.nval = 1;
  attr.name = OUTPUT_SUN_AZ;
  dval[0] = (double)meta->sun_az * DEG;
  if (!PutAttrDouble(ds_output->sds_file_id, &attr, dval))
    RETURN_ERROR("writing attribute (solar azimuth)", "PutMetadata", false);

  if (meta->wrs_sys != WRS_NULL) {

    string = Wrs_string[meta->wrs_sys].string;
    attr.type = DFNT_CHAR8;
    attr.nval = strlen(string);
    attr.name = OUTPUT_WRS_SYS;
    if (!PutAttrString(ds_output->sds_file_id, &attr, string))
      RETURN_ERROR("writing attribute (WRS system)", "PutMetadata", false);

    attr.type = DFNT_INT16;
    attr.nval = 1;
    attr.name = OUTPUT_WRS_PATH;
    dval[0] = (double)meta->ipath;
    if (!PutAttrDouble(ds_output->sds_file_id, &attr, dval))
      RETURN_ERROR("writing attribute (WRS path)", "PutMetadata", false);

    attr.type = DFNT_INT16;
    attr.nval = 1;
    attr.name = OUTPUT_WRS_ROW;
    dval[0] = (double)meta->irow;
    if (!PutAttrDouble(ds_output->sds_file_id, &attr, dval))
      RETURN_ERROR("writing attribute (WRS row)", "PutMetadata", false);
  }

  attr.type = DFNT_INT8;
  attr.nval = 1;
  attr.name = OUTPUT_NBAND;
  dval[0] = (double)nband;
  if (!PutAttrDouble(ds_output->sds_file_id, &attr, dval))
    RETURN_ERROR("writing attribute (number of bands)", "PutMetadata", false);

  attr.type = DFNT_INT8;
  attr.nval = nband;
  attr.name = OUTPUT_BANDS;
  for (ib = 0; ib < nband; ib++)
    dval[ib] = (double)meta->iband[ib];
  if (!PutAttrDouble(ds_output->sds_file_id, &attr, dval))
    RETURN_ERROR("writing attribute (band numbers)", "PutMetadata", false);

  /* Get the short name, local granule id and production date/time */
  
  if (!Names(meta->sat, meta->inst, "SR", &meta->acq_date, 
             meta->wrs_sys, meta->ipath, meta->irow, 
	     short_name, local_granule_id, production_date))
    RETURN_ERROR("creating the short name and local granule id", 
                 "PutMetadata", false);

  attr.type = DFNT_CHAR8;
  attr.nval = strlen(short_name);
  attr.name = OUTPUT_SHORT_NAME;
  if (!PutAttrString(ds_output->sds_file_id, &attr, short_name))
    RETURN_ERROR("writing attribute (short name)", "PutMetadata", false);

  attr.type = DFNT_CHAR8;
  attr.nval = strlen(local_granule_id);
  attr.name = OUTPUT_LOCAL_GRAN_ID;
  if (!PutAttrString(ds_output->sds_file_id, &attr, local_granule_id))
    RETURN_ERROR("writing attribute (local granule id)", "PutMetadata", false);

  attr.type = DFNT_CHAR8;
  attr.nval = strlen(production_date);
  attr.name = OUTPUT_PROD_DATE;
  if (!PutAttrString(ds_output->sds_file_id, &attr, production_date))
    RETURN_ERROR("writing attribute (production date)", "PutMetadata", false);

  if (sprintf(pge_ver, "%s", param->PGEVersion) < 0)
    RETURN_ERROR("creating PGEVersion","PutMetadata", false);
  attr.type = DFNT_CHAR8;
  attr.nval = strlen(pge_ver);
  attr.name = OUTPUT_PGEVERSION;
  if (!PutAttrString(ds_output->sds_file_id, &attr, pge_ver))
    RETURN_ERROR("writing attribute (PGE Version)", "PutMetadata", false);

  if (sprintf(process_ver, "%s", param->ProcessVersion) < 0)
    RETURN_ERROR("creating ProcessVersion","PutMetadata", false);
  attr.type = DFNT_CHAR8;
  attr.nval = strlen(process_ver);
  attr.name = OUTPUT_PROCESSVERSION;
  if (!PutAttrString(ds_output->sds_file_id, &attr, process_ver))
    RETURN_ERROR("writing attribute (Process Version)", "PutMetadata", false);

  attr.type = DFNT_FLOAT64;
  attr.nval = 1;
  attr.name = OUTPUT_WEST_BOUND;
  dval[0] = bounds->min_lon * DEG;
  if (!PutAttrDouble(ds_output->sds_file_id, &attr, dval))
    RETURN_ERROR("writing attribute (West Bounding Coords)", "PutMetadata", false);

  attr.type = DFNT_FLOAT64;
  attr.nval = 1;
  attr.name = OUTPUT_EAST_BOUND;
  dval[0] = bounds->max_lon * DEG;
  if (!PutAttrDouble(ds_output->sds_file_id, &attr, dval))
    RETURN_ERROR("writing attribute (East Bounding Coords)", "PutMetadata", false);

  attr.type = DFNT_FLOAT64;
  attr.nval = 1;
  attr.name = OUTPUT_NORTH_BOUND;
  dval[0] = bounds->max_lat * DEG;
  if (!PutAttrDouble(ds_output->sds_file_id, &attr, dval))
    RETURN_ERROR("writing attribute (North Bounding Coords)", "PutMetadata", false);

  attr.type = DFNT_FLOAT64;
  attr.nval = 1;
  attr.name = OUTPUT_SOUTH_BOUND;
  dval[0] = bounds->min_lat * DEG;
  if (!PutAttrDouble(ds_output->sds_file_id, &attr, dval))
    RETURN_ERROR("writing attribute (South Bounding Coords)", "PutMetadata", false);

  /* now write out the per sds attributes */

/*for (ib = 0; ib < NBAND_REFL_MAX; ib++) {     */
/*  for (ib = 0; ib < NBAND_SR_MAX; ib++) { EV 9/7/2009 */
  for (ib = 0; ib < NBAND_SR_MAX-3; ib++) {
//printf ("DEBUG: SDS metadata for band %d\n", ib);

  sprintf(long_name, lut->long_name_prefix, meta->iband[ib]); 
  if (ib >= NBAND_REFL_MAX){sprintf(long_name,"%s", DupString(qa_band_names[ib - NBAND_REFL_MAX])); }
//printf ("DEBUG: long name: %s\n", long_name);
  attr.type = DFNT_CHAR8;
  attr.nval = strlen(long_name);
  attr.name = OUTPUT_LONG_NAME;
  if (!PutAttrString(ds_output->sds_sr[ib].id, &attr, long_name))
    RETURN_ERROR("writing attribute (long name)", "PutMetadata", false);

  attr.type = DFNT_CHAR8;
  if (ib <= nband) {  /* reflective bands and atmos_opacity */
    attr.nval = strlen(lut->units);
    attr.name = OUTPUT_UNITS;
    if (!PutAttrString(ds_output->sds_sr[ib].id, &attr, lut->units))
      RETURN_ERROR("writing attribute (units ref)", "PutMetadata", false);
  } else {  /* QA bands */
    units_b=DupString("quality/feature classification");
    attr.nval = strlen(units_b);
    attr.name = OUTPUT_UNITS;
    if (!PutAttrString(ds_output->sds_sr[ib].id, &attr, units_b))
      RETURN_ERROR("writing attribute (units ref)", "PutMetadata", false);  
  }
  attr.type = DFNT_INT16;
  attr.nval = 2;
  attr.name = OUTPUT_VALID_RANGE;
  dval[0] = (double)lut->min_valid_sr;
  dval[1] = (double)lut->max_valid_sr;
  if(ib >= nband+FILL && ib <= nband+ADJ_CLOUD) { /* QA bands */
     dval[0] = (double)(0);
     dval[1] = (double)(255);
  }
  if (!PutAttrDouble(ds_output->sds_sr[ib].id, &attr, dval))
    RETURN_ERROR("writing attribute (valid range ref)","PutMetadata",false);

  if (ib <= nband) {  /* reflective bands and atmos_opacity */
    attr.type = DFNT_INT16;
    attr.nval = 1;
    attr.name = OUTPUT_FILL_VALUE;
    dval[0] = (double)lut->output_fill;
    if (!PutAttrDouble(ds_output->sds_sr[ib].id, &attr, dval))
      RETURN_ERROR("writing attribute (valid range ref)","PutMetadata",false);

    attr.type = DFNT_INT16;
    attr.nval = 1;
    attr.name = OUTPUT_SATU_VALUE;
    dval[0] = (double)lut->out_satu;
	if (ib != nband+ATMOS_OPACITY) /* doesn't apply for atmos opacity */
      if (!PutAttrDouble(ds_output->sds_sr[ib].id, &attr, dval))
        RETURN_ERROR("writing attribute (saturate value ref)","PutMetadata",false);

    attr.type = DFNT_FLOAT64;
    attr.nval = 1;
    attr.name = OUTPUT_SCALE_FACTOR;
    dval[0] = (double)lut->scale_factor;
    if (ib == nband+ATMOS_OPACITY)
      dval[0] = (double) 0.001;
    if (!PutAttrDouble(ds_output->sds_sr[ib].id, &attr, dval))
      RETURN_ERROR("writing attribute (scale factor ref)", "PutMetadata", false);
  
    if (ib != nband+ATMOS_OPACITY) { /* don't apply for atmos opacity */
      attr.type = DFNT_FLOAT64;
      attr.nval = 1;
      attr.name = OUTPUT_ADD_OFFSET;
      dval[0] = (double)lut->add_offset;
      if (!PutAttrDouble(ds_output->sds_sr[ib].id, &attr, dval))
        RETURN_ERROR("writing attribute (add offset ref)", "PutMetadata", false);
  
      attr.type = DFNT_FLOAT64;
      attr.nval = 1;
      attr.name = OUTPUT_SCALE_FACTOR_ERR;
      dval[0] = (double)lut->scale_factor_err;
      if (!PutAttrDouble(ds_output->sds_sr[ib].id, &attr, dval))
        RETURN_ERROR("writing attribute (scale factor err ref)", "PutMetadata", false);
  
      attr.type = DFNT_FLOAT64;
      attr.nval = 1;
      attr.name = OUTPUT_ADD_OFFSET_ERR;
      dval[0] = (double)lut->add_offset_err;
      if (!PutAttrDouble(ds_output->sds_sr[ib].id, &attr, dval))
        RETURN_ERROR("writing attribute (add offset err ref)", "PutMetadata", false);
  
      attr.type = DFNT_FLOAT32;
      attr.nval = 1;
      attr.name = OUTPUT_CALIBRATED_NT;
      dval[0] = (double)lut->calibrated_nt;
      if (!PutAttrDouble(ds_output->sds_sr[ib].id, &attr, dval))
        RETURN_ERROR("writing attribute (calibrated nt ref)","PutMetadata",false);
    } /* end if not atmos opacity */
  } /* end if no QA bands */

  if (ib >= nband+FILL && ib <= nband+ADJ_CLOUD) {
//printf ("DEBUG: Writing lndsr_QAMAP for band %d\n", ib);
    attr.type = DFNT_CHAR8;
    sprintf (lndsr_QAMAP,
      "\n\tQA pixel values are either off or on:\n"
      "\tValue  Description\n"
      "\t0\t%s\n"
      "\t255\t%s", QA_off[ib-nband], QA_on[ib-nband]);
    message=DupString(lndsr_QAMAP);
//printf ("DEBUG: %s\n", lndsr_QAMAP);
    attr.nval = strlen(message);
    attr.name = "QA index";
    if (!PutAttrString(ds_output->sds_sr[ib].id, &attr, message))
      RETURN_ERROR("writing attribute (QA index)", "PutMetadata", false);
   }
  }  /* end for ib */

  return true;
}