Пример #1
0
int insert_cat(CAT * cat, CELL value, int num_cells)
{
    CAT *temp_cat;

    for (;;) {
        if (value > cat->cat_val) {
            if (cat->nxt == NULL) {
                cat->nxt = new_cat(value, num_cells);
                cat = cat->nxt;
                cat->nxt = NULL;
                return 0;
            }
            else
                cat = cat->nxt;
        }
        else if (value == cat->cat_val) {
            cat->num_cat = cat->num_cat + num_cells;
            return 0;
        }
        else {
            temp_cat = new_cat(cat->cat_val, cat->num_cat);
            temp_cat->nxt = cat->nxt;
            cat->cat_val = value;
            cat->num_cat = num_cells;
            cat->nxt = temp_cat;
            return 0;
        }
    }

    return 0;
}
void MXPImporter::loadCategories( QTextStream &stream, Recipe &recipe )
{
	//====================categories====================//
	stream.skipWhiteSpace();
	QString current = stream.readLine().trimmed();
	if ( current.mid( 0, current.indexOf( ":" ) ).simplified().toLower() == "categories" ) {
		QString tmp_str = current.mid( current.indexOf( ":" ) + 1, current.length() ).trimmed();

		while ( current.trimmed() != "Amount  Measure       Ingredient -- Preparation Method" && !stream.atEnd() ) {
			if ( !tmp_str.isEmpty() ) {
				const QStringList categories = tmp_str.split( QRegExp("\t|  "), QString::SkipEmptyParts );
				for ( QStringList::const_iterator it = categories.constBegin(); it != categories.constEnd(); ++it ) {
					Element new_cat( ( *it ).trimmed() );
					recipe.categoryList.append( new_cat );

					kDebug()<<"Found category: "<<new_cat.name;
				}
			}

			current = stream.readLine();
			tmp_str = current;
		}
		//else
		//	kDebug()<<"No categories found.";
	}
	else {
		addWarningMsg(i18n( "While loading recipe \"%1\" "
			"the field \"Categories:\" is either missing or could not be detected.", recipe.title ) );

		//the ingredient loaded will expect the last thing to have been read to be this header line
		while ( current.trimmed() != "Amount  Measure       Ingredient -- Preparation Method" && !stream.atEnd() )
			current = stream.readLine();
	}
}
Пример #3
0
/*
initialize check-image.
*/
checkstruct	*initcheck(char *filename, checkenum check_type, int next)

  {
   catstruct	*fitscat;
   checkstruct	*check;

  QCALLOC(check, checkstruct, 1);

  strcpy(check->filename, filename);
  check->type = check_type;

  if (next>1)
/*-- Create a "pure" primary HDU */
    {
    fitscat = new_cat(1);
    init_cat(fitscat);
    strcpy(fitscat->filename, filename);
    fitsadd(fitscat->tab->headbuf, "NEXTEND ", "Number of extensions");
    fitswrite(fitscat->tab->headbuf, "NEXTEND ", &next, H_INT, T_LONG);
    if (open_cat(fitscat, WRITE_ONLY) != RETURN_OK)
      error(EXIT_FAILURE,"*Error*: cannot open for writing ", filename);
    save_tab(fitscat, fitscat->tab);
    check->file = fitscat->file;
    fitscat->file = NULL;
    free_cat(&fitscat, 1);
    }
  else
    if (!(check->file = fopen(check->filename, "wb")))
      error(EXIT_FAILURE, "*Error*: Cannot open for output ", check->filename);

  return check;
  }
void MXPImporter::loadInstructions( QTextStream &stream, Recipe &recipe )
{
	//==========================instructions ( along with other optional fields... mxp format doesn't define end of ingredients and start of other fields )==============//
	stream.skipWhiteSpace();
	QString current = stream.readLine().trimmed();
	while ( !current.contains( "- - - -" ) && !stream.atEnd() ) {
		if ( current.trimmed() == "Source:" ) {
			Element new_author( getNextQuotedString( stream ) );
			recipe.authorList.append( new_author );
			//kDebug()<<"Found source: "<<new_author.name<<" (adding as author)";
		}
		else if ( current.trimmed() == "Description:" ) {
			QString description = getNextQuotedString( stream );
			//kDebug()<<"Found description: "<<m_description<<" (adding to end of instructions)";
			recipe.instructions += "\n\nDescription: " + description;
		}
		else if ( current.trimmed() == "S(Internet Address):" ) {
			QString internet = getNextQuotedString( stream );
			//kDebug()<<"Found internet address: "<<m_internet<<" (adding to end of instructions)";
			recipe.instructions += "\n\nInternet address: " + internet;
		}
		else if ( current.trimmed() == "Yield:" ) {
			recipe.yield.setAmount(getNextQuotedString( stream ).trimmed().toInt());
			recipe.yield.setType(i18n("servings"));
			//kDebug()<<"Found yield: "<<recipe.yield.amount<<" (adding as servings)";
		}
		else if ( current.trimmed() == "T(Cook Time):" ) {
			( void ) getNextQuotedString( stream ); //this would be prep time, but we don't use prep time at the moment
			//kDebug()<<"Found cook time: "<<m_prep_time<<" (adding as prep time)";
		}
		else if ( current.trimmed() == "Cuisine:" ) {
			Element new_cat( getNextQuotedString( stream ) );
			recipe.categoryList.append( new_cat );
			//kDebug()<<"Found cuisine (adding as category): "<<new_cat.name;
		}
		else
			recipe.instructions += current + '\n';

		current = stream.readLine().trimmed();
	}
	recipe.instructions = recipe.instructions.trimmed();
	//kDebug()<<"Found instructions: "<<m_instructions;
}
Пример #5
0
/****** read_cats **************************************************************
PROTO	read_cats(char **filenames, int ncat)
PURPOSE	``Read'' several FITS catalogs.
INPUT	A pointer to pointers of char,
	The number of catalogs.
OUTPUT	catstruct pointer.
NOTES	-.
AUTHOR	E. Bertin (IAP & Leiden observatory)
VERSION	25/04/97
 ***/
catstruct	*read_cats(char **filenames, int ncat)

  {
   catstruct	*cat, *ccat;
   int		i;

  if (!(cat = new_cat(ncat)))
    error (EXIT_FAILURE, "Not enough memory to read ", "catalogs");

  for (i=ncat, ccat = cat; i--; ccat++, filenames++)
    {
    strcpy(ccat->filename, *filenames);
    if (open_cat(ccat, READ_ONLY) != RETURN_OK)
      error (EXIT_FAILURE, "Cannot open ", *filenames);
    if (map_cat(ccat) != RETURN_OK)
      error (EXIT_FAILURE, "Cannot map ", *filenames);
    close_cat(ccat);
    }

  return cat;
  }
Пример #6
0
/****** read_cat ***************************************************************
PROTO	catstruct read_cat(char *filename)
PURPOSE	``Read'' a FITS catalog with name filename.
INPUT	Filename,
OUTPUT	catstruct pointer.
NOTES	Returns NULL if no file with name \<filename\> is found.
AUTHOR	E. Bertin (IAP & Leiden observatory)
VERSION	07/05/2002
 ***/
catstruct	*read_cat(char *filename)

  {
   catstruct *cat;

  if (!(cat = new_cat(1)))
    error (EXIT_FAILURE, "Not enough memory to read ", filename);

  strcpy(cat->filename, filename);
  if (open_cat(cat, READ_ONLY) != RETURN_OK)
    {
    free_cat(&cat, 1);
    return NULL;
    }

  if (map_cat(cat) != RETURN_OK)
    {
    free_cat(&cat, 1);
    return NULL;
    }

  return cat;
  }
Пример #7
0
/****** check_write ********************************************************
PROTO	void	check_write(fieldstruct *field, char *checkname,
		checkenum checktype, int ext, int next, int cubeflag)
PURPOSE	Write a FITS image for check.
INPUT	Pointer to the field,
	Pointer to the set,
	Check-image filename,
	Check-image type,
	Extension number,
	Number of extensions,
	Datacube flag.
OUTPUT  -.
NOTES   Check-image is written as a datacube if cubeflag!=0.
AUTHOR  E. Bertin (IAP)
VERSION 21/09/2015
 ***/
void	check_write(fieldstruct *field, setstruct *set, char *checkname,
		checkenum checktype, int ext, int next, int cubeflag)
  {
   psfstruct		*psf;
   catstruct		*cat;
   tabstruct		*tab;
   samplestruct		**gridsample,
			*sample,*osample;
   char			filename[MAXCHAR], str[82],
			*head, *pstr,*pstr2;
   static double	dpos[POLY_MAXDIM], *dpost;
   double		dstep,dstart, dval1,dval2, scalefac, dstepx,dstepy;
   float		*pix,*pix0, *vig,*vig0, *fpix,*fpixsym,
			val;
   int			i,g,j,l,x,y, w,h,n, npc,nt, nw,nh,np, npos,npos2,
			step,step2, ipos, inpos, ival1,ival2, npix;

/* Create the new cat (well it is not a "cat", but simply a FITS table */
  if (!ext)
    {
    cat = new_cat(1);
    init_cat(cat);
    strcpy(cat->filename, checkname);
    if (!(pstr = strrchr(cat->filename, '.')))
      pstr = cat->filename+strlen(cat->filename);
    strcpy(filename, field->rcatname);
    if (!(pstr2 = strrchr(filename, '.')))
      pstr2 = filename+strlen(filename);
    *pstr2 = '\0';
    sprintf(pstr, "_%s.fits", filename);
    if (open_cat(cat, WRITE_ONLY) != RETURN_OK)
      error(EXIT_FAILURE, "*Error*: cannot open for writing ", cat->filename);
    if (next>1)
      {
      addkeywordto_head(cat->tab, "NEXTEND ", "Number of extensions");
      fitswrite(cat->tab->headbuf, "NEXTEND", &next, H_INT, T_LONG);
      save_tab(cat, cat->tab);
      }
    field->ccat[checktype] = cat;
    }
  else
    cat = field->ccat[checktype];

  sprintf(str, "chip%02d", ext+1);

  psf = field->psf[ext];
  tab = new_tab(str);
  head = tab->headbuf;
  tab->bitpix =  BP_FLOAT;
  tab->bytepix = t_size[T_FLOAT];

  switch(checktype)
    {
    case PSF_BASIS:
/*----  View basis vectors as small vignets */
      if (cubeflag)
        {
        tab->naxis = 3;
        QREALLOC(tab->naxisn, int, tab->naxis);
        tab->naxisn[0] = psf->size[0];
        tab->naxisn[1] = psf->size[1];
        tab->naxisn[2] = psf->nbasis;
        npix = tab->naxisn[0]*tab->naxisn[1]*tab->naxisn[2];
        tab->tabsize = tab->bytepix*npix;
        QCALLOC(pix0, float, tab->tabsize);
        tab->bodybuf = (char *)pix0; 
        pix = pix0;
        fpix = psf->basis;
        for (i=npix; i--;)
          *(pix++) = *(fpix++);
        }
      else
        {
        nw = (int)sqrt((double)psf->nbasis);
        nw = ((nw-1)/10+1)*10;
        nh = (psf->nbasis-1)/nw + 1;
        w = psf->size[0];
        h = psf->dim>1? psf->size[1] : 1;
        tab->naxisn[0] = nw*w;
        tab->naxisn[1] = nh*h;
        step = (nw-1)*w;
        tab->tabsize = tab->bytepix*tab->naxisn[0]*tab->naxisn[1];
        QCALLOC(pix0, float, tab->tabsize);
        tab->bodybuf = (char *)pix0; 
        fpix = psf->basis;
        for (n=0; n<psf->nbasis; n++)
          {
          pix = pix0 + ((n%nw) + (n/nw)*nw*h)*w;
          for (y=h; y--; pix += step)
            for (x=w; x--;)
              *(pix++) = *(fpix++);
          }
        }
      break;
    case PSF_CHI:
/*---- sqrt(chi2) map in PSF pixel-space 
      nw = 1;
      nh = 1;
      w = psf->size[0];
      h = psf->size[1];
      tab->naxisn[0] = nw*w;
      tab->naxisn[1] = nh*h;
      tab->tabsize = tab->bytepix*tab->naxisn[0]*tab->naxisn[1];
      QCALLOC(pix0, float, tab->tabsize);
      tab->bodybuf = (char *)pix0; 
      pix = pix0;
      fpix = psf->resi;
      for (i=w*h; i--;)
        *(pix++) = *(fpix++);
      break;
*/
      if (cubeflag)
        {
        tab->naxis = 3;
        QREALLOC(tab->naxisn, int, tab->naxis);
        tab->naxisn[0] = set->vigsize[0];
        tab->naxisn[1] = set->vigsize[1];
        tab->naxisn[2] = set->ngood? set->ngood : 1;
        npix = tab->naxisn[0]*tab->naxisn[1];
        tab->tabsize = tab->bytepix*npix*tab->naxisn[2];
        QCALLOC(pix0, float, tab->tabsize);
        tab->bodybuf = (char *)pix0; 
        pix = pix0;
        sample = set->sample;
        for (n=set->nsample; n--; sample++)
          {
          if (sample->badflag)
            continue;
          fpix = sample->vigchi;
          for (i=npix; i--;)
            *(pix++) = *(fpix++);
          }
        }
      else
        {
Пример #8
0
void NYCGenericImporter::importNYCGeneric( QTextStream &stream )
{
	kapp->processEvents(); //don't want the user to think its frozen... especially for files with thousands of recipes

	QString current;

	stream.skipWhiteSpace();

	//title
	while ( !( current = stream.readLine() ).isEmpty() && !stream.atEnd() )
		m_recipe.title = current;

	//categories
	while ( !( current = stream.readLine() ).isEmpty() && !stream.atEnd() ) {
		if ( current[ 0 ].isNumber() ) {
			loadIngredientLine( current );
			break;
		} //oops, this is really an ingredient line (there was no category line)

		QStringList categories = current.split( ',', QString::SkipEmptyParts );

		if ( categories.count() > 0 && categories[ 0 ].toUpper() == "none" )  //there are no categories
			break;

		for ( QStringList::const_iterator it = categories.constBegin(); it != categories.constEnd(); ++it ) {
			Element new_cat( QString( *it ).trimmed() );
			kDebug() << "Found category: " << new_cat.name ;
			m_recipe.categoryList.append( new_cat );
		}
	}

	//ingredients
	while ( !( current = stream.readLine() ).isEmpty() && !stream.atEnd() )
		loadIngredientLine( current );

	//everything else is the instructions with optional "contributor", "prep time" and "yield"
	bool found_next;
	while ( !( found_next = ( current = stream.readLine() ).startsWith( "@@@@@" ) ) && !stream.atEnd() ) {
		if ( current.startsWith( "Contributor:" ) ) {
			Element new_author( current.mid( current.indexOf( ':' ) + 1, current.length() ).trimmed() );
			kDebug() << "Found author: " << new_author.name ;
			m_recipe.authorList.append( new_author );
		}
		else if ( current.startsWith( "Preparation Time:" ) ) {
			m_recipe.prepTime = QTime::fromString( current.mid( current.indexOf( ':' ), current.length() ) );
		}
		else if ( current.startsWith( "Yield:" ) ) {
			int colon_index = current.indexOf( ':' );
			int amount_type_sep_index = current.indexOf(" ",colon_index+1);

			m_recipe.yield.setAmount(current.mid( colon_index+2, amount_type_sep_index-colon_index ).toDouble());
			m_recipe.yield.setType(current.mid( amount_type_sep_index+3, current.length() ));
		}
		else if ( current.startsWith( "NYC Nutrition Analysis (per serving or yield unit):" ) ) {
			//m_recipe.instructions += current + '\n';
		}
		else if ( current.startsWith( "NYC Nutrilink:" ) ) {
			//m_recipe.instructions += current + '\n';
		}
		else if ( !current.trimmed().isEmpty() && !current.startsWith("** Exported from Now You're Cooking!") ) {
			m_recipe.instructions += current + '\n';
		}
	}

	m_recipe.instructions = m_recipe.instructions.trimmed();
	putDataInRecipe();

	if ( found_next )
		importNYCGeneric( stream );
}
void AISUpdate::parseCategory(const LLSD& category_map)
{
	LLUUID category_id = category_map["category_id"].asUUID();

	// Check descendent count first, as it may be needed
	// to populate newly created categories
	if (category_map.has("_embedded"))
	{
		parseDescendentCount(category_id, category_map["_embedded"]);
	}

	LLPointer<LLViewerInventoryCategory> new_cat(new LLViewerInventoryCategory(category_id));
	LLViewerInventoryCategory *curr_cat = gInventory.getCategory(category_id);
	if (curr_cat)
	{
		// Default to current values where not provided.
		new_cat->copyViewerCategory(curr_cat);
	}
	BOOL rv = new_cat->unpackMessage(category_map);
	// *NOTE: unpackMessage does not unpack version or descendent count.
	//if (category_map.has("version"))
	//{
	//	mCatVersionsUpdated[category_id] = category_map["version"].asInteger();
	//}
	if (rv)
	{
		if (curr_cat)
		{
			mCategoriesUpdated[category_id] = new_cat;
			// This statement is here to cause a new entry with 0
			// delta to be created if it does not already exist;
			// otherwise has no effect.
			mCatDescendentDeltas[new_cat->getParentUUID()];
			// Capture update for the category itself as well.
			mCatDescendentDeltas[category_id];
		}
		else
		{
			// Set version/descendents for newly created categories.
			if (category_map.has("version"))
			{
				S32 version = category_map["version"].asInteger();
				LL_DEBUGS("Inventory") << "Setting version to " << version
									   << " for new category " << category_id << LL_ENDL;
				new_cat->setVersion(version);
			}
			uuid_int_map_t::const_iterator lookup_it = mCatDescendentsKnown.find(category_id);
			if (mCatDescendentsKnown.end() != lookup_it)
			{
				S32 descendent_count = lookup_it->second;
				LL_DEBUGS("Inventory") << "Setting descendents count to " << descendent_count 
									   << " for new category " << category_id << LL_ENDL;
				new_cat->setDescendentCount(descendent_count);
			}
			mCategoriesCreated[category_id] = new_cat;
			mCatDescendentDeltas[new_cat->getParentUUID()]++;
		}
	}
	else
	{
		// *TODO: Wow, harsh.  Should we just complain and get out?
		LL_ERRS() << "unpack failed" << LL_ENDL;
	}

	// Check for more embedded content.
	if (category_map.has("_embedded"))
	{
		parseEmbedded(category_map["_embedded"]);
	}
}