Example #1
0
        // Write APNGAsm object to spec file.
        // Return true if write succeeded.
        bool XMLSpecWriterImpl::write(const std::string& filePath, const std::string& imagePathPrefix) const
        {
          boost::property_tree::ptree root;

          // Write apngasm fields.
          // root.put("animation.<xmlattr>.name", _pApngasm->name());
          root.put("animation.<xmlattr>.loops", _pApngasm->getLoops());
          root.put("animation.<xmlattr>.skip_first", _pApngasm->isSkipFirst());

          {
            boost::property_tree::ptree child;
            std::vector<APNGFrame>& frames = const_cast<std::vector<APNGFrame>&>(_pApngasm->getFrames()); // gununu...
            const int count = frames.size();
            for(int i = 0;  i < count;  ++i)
            {
              const std::string file = _pListener->onCreatePngPath(imagePathPrefix, i);
              
              std::ostringstream delay;
              delay << frames[i].delayNum() << "/" << frames[i].delayDen();

              boost::property_tree::ptree& frame = root.add("animation.frame", "");
              frame.put("<xmlattr>.src", file);
              frame.put("<xmlattr>.delay", delay.str());
            }
          }

          write_xml(filePath, root);
          return true;
        }
Example #2
0
static void write_xml(const PTree & p, std::ostream & out, std::string indent)
{
	for (PTree::const_iterator i = p.begin(), e = p.end(); i != e; ++i)
	{
		if (i->second.size() == 0)
		{
			out << indent << "<" << i->first << ">" << i->second.value() << "</" << i->first << ">\n";
			write_xml(i->second, out, indent+"\t");
		}
		else
		{
			out << indent << "<" << i->first << ">\n";
			write_xml(i->second, out, indent+"\t");
			out << indent << "</" << i->first << ">\n";
		}
	}
}
void xml_writer::xml_write_string_data(const std::string child, const std::string data, int idata) {
	boost::property_tree::ptree pt;
	auto& rt = pt.put(this->root, u8"");
	auto& children = rt.add(child, u8"");
	this->write_text_in_node(children, u8"test1", data);
	this->write_int_in_node(children, u8"test2", idata);
	write_xml(this->filepath, pt);
}
Example #4
0
int IndexState::write_index(const char *path,
                            int data_bytes,
                            Asset *asset,
                            int64_t length_source)
{

    FILE *file;
    if(!(file = fopen(path, "wb")))
    {
// failed to create it
        printf(_("IndexState::write_index Couldn't write index file %s to disk.\n"),
               path);
    }
    else
    {
        FileXML xml;
// Pad index start position
        fwrite((char*)&(index_start), sizeof(int64_t), 1, file);

        index_status = INDEX_READY;

// Write asset encoding information in index file.
// This also calls back into index_state to write it.
        if(asset)
        {
            asset->write(&xml,
                         1,
                         "");
        }
        else
        {
// Must write index_state directly.
            write_xml(&xml);
        }

        xml.write_to_file(file);
        index_start = ftell(file);
        fseek(file, 0, SEEK_SET);
// Write index start
        fwrite((char*)&(index_start), sizeof(int64_t), 1, file);
        fseek(file, index_start, SEEK_SET);

// Write index data
        fwrite(index_buffer,
               data_bytes,
               1,
               file);
        fclose(file);
    }

// Force reread of header
    index_status = INDEX_NOTTESTED;
    index_end = length_source;
    old_index_end = 0;
    index_start = 0;
    return 0;
}
void ExternalConnector::sendHandShake()
{
    boost::property_tree::ptree a_tree;
    a_tree.put("command", "handshake");
    a_tree.put("params.version", "0");
    std::ostringstream buffer;
    write_xml(buffer, a_tree);
    sendMessage(buffer.str());
}
Example #6
0
void
pcl::gpu::people::PersonAttribs::writePersonXMLConfig (std::ostream& os)
{
  boost::property_tree::ptree pt;
  pt.add("version", static_cast<int>(XML_VERSION));
//  boost::property_tree::ptree& node = pt.add("person", "");
//  node.put("name", name_);
  pt.add("person.name", name_);

  write_xml(os,pt);
}
void ExternalConnector::sendPortList(const QList<QString>& list)
{
    boost::property_tree::ptree a_tree;
    a_tree.put("command", "ports");
    boost::property_tree::ptree& portlist = a_tree.add_child("params.ports", boost::property_tree::ptree{});
    for (QString a_port : list)
    {
        portlist.add("port", a_port.toStdString());
    }
    std::ostringstream buffer;
    write_xml(buffer, a_tree);
    sendMessage(buffer.str());
}
Example #8
0
    std::string RewardXML::toXml() const {
        std::ostringstream oss;
        boost::property_tree::ptree xml;

        add_rewards(xml);

        write_xml(oss, xml);

        std::string xml_str = oss.str();
        xml_str.erase(std::remove(xml_str.begin(), xml_str.end(), '\n'), xml_str.end());

        return xml_str;
    }
    void ImageStackDirectoryDatasource::writeMetaDataFile(std::string metaDataFileName, const std::vector<float>& tiltAngles, const std::vector<std::string>& filenames, const ScannerGeometry* baseScannerGeometry, const VolumeProperties& volumeProperties)
    {
        if(tiltAngles.size() != filenames.size())
        {
            throw Exception("Filename count does not match tilt angle count!");
        }
        boost::property_tree::ptree propertyTree;

        writeMicroscopeMetaData(propertyTree, metaDataFileName, baseScannerGeometry, volumeProperties);
        writeProjectionMetaData(propertyTree, metaDataFileName, tiltAngles, filenames);

        boost::property_tree::xml_writer_settings<char> w(' ', 4);

        if(boost::filesystem::exists(metaDataFileName))
            boost::filesystem::remove(metaDataFileName);

        write_xml(metaDataFileName, propertyTree, std::locale(), w);
    }
Example #10
0
        void TF_Datasource::writeMetaDataFile(std::string metaDataFileName, std::vector<ScannerGeometry*> projectionProperties, const std::vector<std::string>& filenames, ScannerGeometry* baseScannerGeometry, const VolumeProperties& volumeProperties)
        {
            if(projectionProperties.size() != filenames.size())
            {
                throw Exception("Number of filenames does not match number of properties!");
            }
            ptree propertyTree;

            writeMicroscopeMetaData(propertyTree, metaDataFileName, baseScannerGeometry, volumeProperties);
            writeProjectionMetaData(propertyTree, metaDataFileName, projectionProperties, filenames);

            boost::property_tree::xml_writer_settings<char> w(' ', 4);

            if(boost::filesystem::exists(metaDataFileName))
                boost::filesystem::remove(metaDataFileName);

            write_xml(metaDataFileName, propertyTree, std::locale(), w);
        }
Example #11
0
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ){
	read_xml(CONFIG_FILE_NAME, gConfig);
	ChangeWindowMode(gConfig.get("WindowMode",true));
	SetMainWindowText( PJTITLE );
	if( DxLib_Init() == -1 ){
		 return -1;	// エラーが起きたら直ちに終了
	}
	LPCSTR font_path = "img\\font.ttf"; // 読み込むフォントファイルのパス
	AddFontResourceEx(font_path, FR_PRIVATE, NULL);
	ChangeFont("Neuropol",DX_CHARSET_DEFAULT);
	ChangeFontType( DX_FONTTYPE_ANTIALIASING_EDGE );
	shotButton = gConfig.get("Pad.Shot",PAD_INPUT_1);
	subButton = gConfig.get("Pad.Sub",PAD_INPUT_2);
	SetJoypadInputToKeyInput(DX_INPUT_PAD1, shotButton, gConfig.get("Key.Shot", KEY_INPUT_Z), -1, -1, -1 ) ;
	SetJoypadInputToKeyInput(DX_INPUT_PAD1, subButton, gConfig.get("Key.Sub", KEY_INPUT_X), -1, -1, -1 ) ;

	gGameManager.Set(&GameManager::Init);
	for(;;){ //メインループ
		//SetDrawScreen(DX_SCREEN_BACK);
		SetDrawScreen(gDrawScr);
		ClearDrawScreen();
		if(ProcessMessage()==-1 || GameMain()==1){break;} //ゲーム本体を実行
		SetDrawScreen( DX_SCREEN_BACK ) ; //裏スクリーンに描画対象を移す
		SetDrawBlendMode(DX_BLENDMODE_ALPHA,255);
		DrawGraph(0,0,gDrawScr,FALSE); //実際に描画
		SetDrawBlendMode(DX_BLENDMODE_NOBLEND,0);

		//FPS描画
		{
			int NowFPS = gFPS.Get();
			int Col = (int)(255 * NowFPS / gFPS.GetDefaultFPS());
			DrawFormatString(SCR_WIDTH-80,SCR_HEIGHT-20,GetColor(255,Col,Col),"%02dFPS",NowFPS);
		}
		ScreenFlip();
		CaptureScreen();
		gFPS.Fix();
	}

	DxLib_End() ;		// DXライブラリ使用の終了処理
	write_xml(CONFIG_FILE_NAME,gConfig);

	return 0 ;		// ソフトの終了
}
Example #12
0
bool
pcl::io::LZFImageWriter::writeParameter (const double &parameter,
                                         const std::string &tag,
                                         const std::string &filename)
{
  boost::property_tree::ptree pt;
  try
  {
    boost::property_tree::xml_parser::read_xml (filename, pt, boost::property_tree::xml_parser::trim_whitespace);
  }
  catch (std::exception& e)
  {}

  boost::property_tree::xml_writer_settings<char> settings ('\t', 1);
  pt.put (tag, parameter);
  write_xml (filename, pt, std::locale (), settings);

  return (true);
}
Example #13
0
bool
pcl::io::LZFRGB24ImageWriter::writeParameters (const pcl::io::CameraParameters &parameters,
                                              const std::string &filename)
{
  boost::property_tree::ptree pt;
  try
  {
    boost::property_tree::xml_parser::read_xml (filename, pt, boost::property_tree::xml_parser::trim_whitespace);
  }
  catch (std::exception& e)
  {}

  boost::property_tree::xml_writer_settings<char> settings ('\t', 1);
  pt.put ("rgb.focal_length_x", parameters.focal_length_x);
  pt.put ("rgb.focal_length_y", parameters.focal_length_y);
  pt.put ("rgb.principal_point_x", parameters.principal_point_x);
  pt.put ("rgb.principal_point_y", parameters.principal_point_y);
  write_xml (filename, pt, std::locale (), settings);

  return (true);
}
Example #14
0
int main(int argc, char *argv[])
{
	struct options options;
	INT8 tinj, jitter;
	gsl_rng *rng;
	ProcessTable *process_table_head = NULL, *process;
	ProcessParamsTable *process_params_table_head = NULL;
	SearchSummaryTable *search_summary_table_head = NULL, *search_summary;
	TimeSlide *time_slide_table_head = NULL;
	SimBurst *sim_burst_table_head = NULL;
	SimBurst **sim_burst = &sim_burst_table_head;


	/*
	 * Initialize debug handler
	 */


	lal_errhandler = LAL_ERR_EXIT;


	/*
	 * Process table
	 */


	process_table_head = process = XLALCreateProcessTableRow();
	if(XLALPopulateProcessTable(process, PROGRAM_NAME, lalAppsVCSIdentId, lalAppsVCSIdentStatus, lalAppsVCSIdentDate, 0))
		exit(1);
	XLALGPSTimeNow(&process->start_time);


	/*
	 * Command line and process params table.
	 */


	options = parse_command_line(&argc, &argv, process, &process_params_table_head);
	if(options.user_tag)
		snprintf(process->comment, sizeof(process->comment), "%s", options.user_tag);


	/*
	 * Search summary table
	 */


	search_summary_table_head = search_summary = XLALCreateSearchSummaryTableRow(process);
	if(options.user_tag)
		snprintf(search_summary->comment, sizeof(search_summary->comment), "%s", options.user_tag);
	search_summary->nnodes = 1;
	search_summary->out_start_time = *XLALINT8NSToGPS(&search_summary->in_start_time, options.gps_start_time);
	search_summary->out_end_time = *XLALINT8NSToGPS(&search_summary->in_end_time, options.gps_end_time);


	/*
	 * Initialize random number generator
	 */


	rng = gsl_rng_alloc(gsl_rng_mt19937);
	if(options.seed)
		gsl_rng_set(rng, options.seed);


	/*
	 * Main loop
	 */


	for(tinj = options.gps_start_time; tinj <= options.gps_end_time; tinj += options.time_step * 1e9) {
		/*
		 * Progress bar.
		 */

		XLALPrintInfo("%s: ", argv[0]);
		XLALPrintProgressBar((tinj - options.gps_start_time) / (double) (options.gps_end_time - options.gps_start_time));
		XLALPrintInfo(" complete\n");

		/*
		 * Create an injection
		 */

		switch(options.population) {
		case POPULATION_TARGETED:
			*sim_burst = random_directed_btlwnb(options.ra, options.dec, gsl_ran_flat(rng, 0, LAL_TWOPI), options.minf, options.maxf, options.minbandwidth, options.maxbandwidth, options.minduration, options.maxduration, options.minEoverr2, options.maxEoverr2, rng);
			break;

		case POPULATION_ALL_SKY_SINEGAUSSIAN:
			*sim_burst = random_all_sky_sineGaussian(options.minf, options.maxf, options.q, options.minhrss, options.maxhrss, rng);
			break;

		case POPULATION_ALL_SKY_BTLWNB:
			*sim_burst = random_all_sky_btlwnb(options.minf, options.maxf, options.minbandwidth, options.maxbandwidth, options.minduration, options.maxduration, options.minEoverr2, options.maxEoverr2, rng);
			break;

		case POPULATION_STRING_CUSP:
			*sim_burst = random_string_cusp(options.minf, options.maxf, options.minA, options.maxA, rng);
			break;

		default:
			/* shouldn't get here, command line parsing code
			 * should prevent it */
			XLALPrintError("internal error\n");
			exit(1);
		}

		if(!*sim_burst) {
			XLALPrintError("can't make injection\n");
			exit(1);
		}

		/*
		 * Peak time at geocentre in GPS seconds
		 */

		/* Add "jitter" to the injection if user requests it */
		if(options.jitter > 0) {
			jitter = gsl_ran_flat(rng, -options.jitter/2, options.jitter/2)*1e9;
		} else {
			jitter = 0;
		}

		XLALINT8NSToGPS(&(*sim_burst)->time_geocent_gps, tinj + jitter);

		/*
		 * Peak time at geocentre in GMST radians
		 */

		(*sim_burst)->time_geocent_gmst = XLALGreenwichMeanSiderealTime(&(*sim_burst)->time_geocent_gps);

		/*
		 * Move to next injection
		 */

		sim_burst = &(*sim_burst)->next;
	}

	XLALPrintInfo("%s: ", argv[0]);
	XLALPrintProgressBar(1.0);
	XLALPrintInfo(" complete\n");

	/* load time slide document and merge our table rows with its */

	if(load_tisl_file_and_merge(options.time_slide_file, &process_table_head, &process_params_table_head, &time_slide_table_head, &search_summary_table_head, &sim_burst_table_head))
		exit(1);
	if(set_instruments(process, time_slide_table_head))
		exit(1);
	snprintf(search_summary->ifos, sizeof(search_summary->ifos), "%s", process->ifos);

	/* output */

	XLALGPSTimeNow(&process->end_time);
	search_summary->nevents = XLALSimBurstAssignIDs(sim_burst_table_head, process->process_id, time_slide_table_head->time_slide_id, 0);
	write_xml(options.output, process_table_head, process_params_table_head, search_summary_table_head, time_slide_table_head, sim_burst_table_head);

	/* done */

	gsl_rng_free(rng);
	XLALDestroyProcessTable(process_table_head);
	XLALDestroyProcessParamsTable(process_params_table_head);
	XLALDestroyTimeSlideTable(time_slide_table_head);
	XLALDestroySearchSummaryTable(search_summary_table_head);
	XLALDestroySimBurstTable(sim_burst_table_head);
	exit(0);
}
Example #15
0
void	makeit(void)

  {
   wcsstruct		*wcs;
   fieldstruct		**fields,
			*field;
   psfstruct		**cpsf,
			*psf;
   setstruct		*set, *set2;
   contextstruct	*context, *fullcontext;
   struct tm		*tm;
   char			str[MAXCHAR];
   char			**incatnames,
			*pstr;
   float		**psfbasiss,
			*psfsteps, *psfbasis, *basis,
			psfstep, step;
   int			c,i,p, ncat, ext, next, nmed, nbasis;

/* Install error logging */
  error_installfunc(write_error);

  incatnames = prefs.incat_name;
  ncat = prefs.ncat;

/* Processing start date and time */
  thetime = time(NULL);
  tm = localtime(&thetime);
  sprintf(prefs.sdate_start,"%04d-%02d-%02d",
	tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
  sprintf(prefs.stime_start,"%02d:%02d:%02d",
	tm->tm_hour, tm->tm_min, tm->tm_sec);

  NFPRINTF(OUTPUT, "");
  QPRINTF(OUTPUT,
	"----- %s %s started on %s at %s with %d thread%s\n\n",
		BANNER,
		MYVERSION,
		prefs.sdate_start,
		prefs.stime_start,
		prefs.nthreads,
		prefs.nthreads>1? "s":"");


/* End here if no filename has been provided */
  if (!ncat)
    {
/*-- Processing end date and time */
    thetime2 = time(NULL);
    tm = localtime(&thetime2);
    sprintf(prefs.sdate_end,"%04d-%02d-%02d",
	tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
    sprintf(prefs.stime_end,"%02d:%02d:%02d",
	tm->tm_hour, tm->tm_min, tm->tm_sec);
    prefs.time_diff = difftime(thetime2, thetime);

/*-- Write XML */
    if (prefs.xml_flag)
      {
      init_xml(0);
      write_xml(prefs.xml_name);
      end_xml();
      }
    return;
    }

/* Create an array of PSFs (one PSF for each extension) */
  QMALLOC(fields, fieldstruct *, ncat);

  NFPRINTF(OUTPUT, "");
  QPRINTF(OUTPUT, "----- %d input catalogues:\n", ncat);
  for (c=0; c<ncat; c++)
    {
    fields[c] = field_init(incatnames[c]);
    QPRINTF(OUTPUT, "%-20.20s:  \"%-16.16s\"  %3d extension%s %7d detection%s\n",
        fields[c]->rcatname, fields[c]->ident,
        fields[c]->next, fields[c]->next>1 ? "s":"",
        fields[c]->ndet, fields[c]->ndet>1 ? "s":"");
    }
  QPRINTF(OUTPUT, "\n");

  if (prefs.xml_flag)
    init_xml(ncat);  
  
  makeit_body(fields, &context, &fullcontext, 1);
  next = fields[0]->next;

/* Write XML */
  if (prefs.xml_flag)
    {
    NFPRINTF(OUTPUT, "Writing XML file...");
    write_xml(prefs.xml_name);
    end_xml();
    }

/* Save result */
  for (c=0; c<ncat; c++)
    {
    sprintf(str, "Saving PSF model and metadata for %s...",
	fields[c]->rtcatname);
    NFPRINTF(OUTPUT, str);
/*-- Create a file name with a "PSF" extension */
    if (*prefs.psf_dir)
      {
      if ((pstr = strrchr(incatnames[c], '/')))
        pstr++;
      else
        pstr = incatnames[c];
      sprintf(str, "%s/%s", prefs.psf_dir, pstr);
      }
    else
      strcpy(str, incatnames[c]);
    if (!(pstr = strrchr(str, '.')))
      pstr = str+strlen(str);
    sprintf(pstr, "%s", prefs.psf_suffix);
    field_psfsave(fields[c], str);
/* Create homogenisation kernels */
    if (prefs.homobasis_type != HOMOBASIS_NONE)
      {
      for (ext=0; ext<next; ext++)
        {
        if (next>1)
          sprintf(str, "Computing homogenisation kernel for %s[%d/%d]...",
		fields[c]->rtcatname, ext+1, next);
        else
          sprintf(str, "Computing homogenisation kernel for %s...",
		fields[c]->rtcatname);
        NFPRINTF(OUTPUT, str);
        if (*prefs.homokernel_dir)
          {
          if ((pstr = strrchr(incatnames[c], '/')))
            pstr++;
          else
            pstr = incatnames[c];
          sprintf(str, "%s/%s", prefs.homokernel_dir, pstr);
          }
        else
          strcpy(str, incatnames[c]);
        if (!(pstr = strrchr(str, '.')))
          pstr = str+strlen(str);
        sprintf(pstr, "%s", prefs.homokernel_suffix);
        psf_homo(fields[c]->psf[ext], str, prefs.homopsf_params,
		prefs.homobasis_number, prefs.homobasis_scale, ext, next);
        }
      }
#ifdef HAVE_PLPLOT
/* Plot diagnostic maps for all catalogs */
    cplot_ellipticity(fields[c]);
    cplot_fwhm(fields[c]);
    cplot_moffatresi(fields[c]);
    cplot_asymresi(fields[c]);
    cplot_counts(fields[c]);
    cplot_countfrac(fields[c]);
    cplot_modchi2(fields[c]);
    cplot_modresi(fields[c]);
#endif

/*-- Update XML */
    if (prefs.xml_flag)
      update_xml(fields[c]);
    }

/* Processing end date and time */
  thetime2 = time(NULL);
  tm = localtime(&thetime2);
  sprintf(prefs.sdate_end,"%04d-%02d-%02d",
	tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
  sprintf(prefs.stime_end,"%02d:%02d:%02d",
	tm->tm_hour, tm->tm_min, tm->tm_sec);
  prefs.time_diff = difftime(thetime2, thetime);

/* Free memory */
  for (c=0; c<ncat; c++)
    field_end(fields[c]);
  free(fields);

  if (context->npc)
    context_end(fullcontext);   
  context_end(context);   

  return;
  }
int message_parsing(int server_socket,int *exit_num,MYSQL mysql_conn)
{
    char command[5][10]= {"ll","exit","vim","open","close"};
    xmlChar *xmlbuf;
    char *buffer=(char *)malloc(256*sizeof(char));
    memset(buffer,'\0',256);
    int response_type=-1; //响应类型
    xmlDocPtr doc;
    xmlNodePtr curNode;      //定义结点指针(你需要它为了在各个结点间移动)

    if((xmlbuf=recv_xml(server_socket))!=NULL)
    {
        /*  if(modify_num==1)
         *  *                   {
         *  *                                    printf("接收%s成功!\n",xmlbuf);
         **                                                     }*/
//        doc=xmlchar_to_doc(xmlbuf);
 
		doc = xmlReadMemory(xmlbuf,strlen(xmlbuf)+1,NULL,"utf-8",XML_PARSE_RECOVER    );

     //   doc = xmlParseMemory(xmlbuf,strlen(xmlbuf)+1);
        free(xmlbuf);
        curNode = xmlDocGetRootElement(doc); //确定文档根元素

        if(NULL == curNode)
        {
            xmlFreeDoc(doc);
            return -1;
        }
        if(xmlStrcmp(curNode->name, (const xmlChar *)"message")==0)
            response_type=0;

        if(xmlStrcmp(curNode->name, (const xmlChar *)"command")==0)
            response_type=1;
    }

    if(response_type==0)
    {
        int local_socket;

        if(xmlHasProp(curNode,(xmlChar *)"local_socket"))  //判断结点curNode是否具有属性attribute
        {
            xmlChar *local_socket_tmp;
            local_socket_tmp= xmlGetProp(curNode, "local_socket"); //获取属性值
            int i=0;

            while(local_socket_tmp[i]!='\0')
            {
                local_socket=local_socket*10+local_socket_tmp[i]-'0';
                i++;
            }

            xmlFree(local_socket_tmp); //释放内存
        }

        xmlSetProp(curNode,(const xmlChar *)"local_socket", (xmlChar *)"no");
        int buffersize;
        xmlDocDumpFormatMemory(doc, &xmlbuf, &buffersize, 1);
        int num=0;
        char *ptr=xmlbuf;

        while(*ptr)
        {
            if(*ptr=='<')
                num++;

            if(num==2)
                break;

            ptr++;
        }

        ptr[strlen(ptr)-1]='\0';
        fd_set wtfds;
        struct timeval timeout= {3,0}; //select等待3秒,3秒轮询,要非阻塞就置
        FD_ZERO(&wtfds); //每次循环都要清空集合,否则不能检测描述符变化
        FD_SET(local_socket,&wtfds); //添加描述符
        select(local_socket+1,NULL,&wtfds,NULL,&timeout); //select使用

        if(FD_ISSET(local_socket,&wtfds)) //测试文件是否可写
        {
            if(write_xml(ptr,local_socket)==0)
            {
                if(modify_num==1)
                {
                    printf("发送%s成功!\n",xmlbuf);
                }

                xmlFree(xmlbuf);
            }

            else
            {
                if(modify_num==1)
                {
                    printf("发送%s失败!\n",xmlbuf);
                }

                xmlFree(xmlbuf);
            }
        }
    }

    if(response_type==1)
    {
        xmlChar *key;
        key = xmlNodeListGetString(doc,curNode->xmlChildrenNode, 1); //获取文本结点的>文本,需用其子结点
        sprintf(buffer,"%s",key);
        xmlFree(key);
        char *jid=(char *)malloc(50*sizeof(char));
        memset(jid,'\0',50);
        char *buffer_tmp=(char *)malloc(256*sizeof(char));
        memset(buffer_tmp,'\0',256);
        int i=0;

        while(buffer[i]!=' '&&buffer[i]!='\0')
        {
            buffer_tmp[i]=buffer[i];
            i++;
        }

        buffer_tmp[i]='\0';
        int j=0;

        while(buffer[i]!='\0')
        {
            if(buffer[i]==' ')
            {
                i++;
                continue;
            }

            jid[j]=buffer[i];
            i++;
            j++;
        }

        jid[j]='\0';
        int num=-1;

        for(int i=0; i<5; i++)
            if(strcmp(buffer_tmp,command[i])==0)
            {
                num=i;
                break;
            }

        free(buffer_tmp);

        switch(num)
        {
            case 0:
                client_ll(server_socket,mysql_conn);
                break;

            case 1:
                *exit_num=1;
                break;

            case 3:
                if(remote_login(server_socket,jid,mysql_conn)==-1)
                    return -1;

                break;

            case 4:
                break;

            default:
                memset(buffer,'\0',256);
                sprintf(buffer,"%s","命令不存在!");
                xmlChar *xmlbuf_head="<message>";
                xmlChar *xmlbuf_tail="</message>";
                xmlChar *xmlbuf;
                xmlbuf=xmlchar_construct(xmlbuf_head,buffer,xmlbuf_tail);

                if(send_xml(xmlbuf,server_socket)==0)
                {
                    if(modify_num==1)
                    {
                        printf("发送%s成功!\n",xmlbuf);
                    }

                    xmlFree(xmlbuf);
                }

                else
                {
                    if(modify_num==1)
                    {
                        printf("发送%s失败!\n",xmlbuf);
                    }

                    xmlFree(xmlbuf);
                    return -1;
                }
        }

        free(jid);
    }

    free(buffer);
    xmlFreeDoc(doc);
    return 0;
}
Example #17
0
void write_xml(const PTree & p, std::ostream & out)
{
	write_xml(p, out, std::string());
}
Example #18
0
int main (int argc, char* argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd("Postp-process results of the LIE approach",
                       ' ', "0.1");
    TCLAP::ValueArg<std::string> arg_out_pvd("o", "output-file",
                                          "the name of the new PVD file", true,
                                          "", "path");
    cmd.add(arg_out_pvd);
    TCLAP::ValueArg<std::string> arg_in_pvd("i", "input-file",
                                         "the original PVD file name", true,
                                         "", "path");
    cmd.add(arg_in_pvd);

    cmd.parse(argc, argv);

    auto const in_pvd_filename = arg_in_pvd.getValue();
    auto const in_pvd_file_dir = BaseLib::extractPath(in_pvd_filename);
    auto const out_pvd_filename = arg_out_pvd.getValue();
    auto const out_pvd_file_dir = BaseLib::extractPath(out_pvd_filename);
    INFO("start reading the PVD file %s", in_pvd_filename.c_str());
    boost::property_tree::ptree pt;
    read_xml(arg_in_pvd.getValue(), pt,  boost::property_tree::xml_parser::trim_whitespace);

    for (auto& dataset : pt.get_child("VTKFile.Collection"))
    {
        if (dataset.first != "DataSet")
            continue;

        // read VTU with simulation results
        auto const org_vtu_filename = dataset.second.get<std::string>("<xmlattr>.file");
        INFO("processing %s...", (in_pvd_file_dir + org_vtu_filename).c_str());

        std::unique_ptr<MeshLib::Mesh const> mesh(
            MeshLib::IO::readMeshFromFile(in_pvd_file_dir + org_vtu_filename));

        // post-process
        std::vector<MeshLib::Element*> vec_matrix_elements;
        std::vector<int> vec_fracture_mat_IDs;
        std::vector<std::vector<MeshLib::Element*>> vec_fracture_elements;
        std::vector<std::vector<MeshLib::Element*>> vec_fracture_matrix_elements;
        std::vector<std::vector<MeshLib::Node*>> vec_fracture_nodes;
        ProcessLib::LIE::getFractureMatrixDataInMesh(
            *mesh, vec_matrix_elements, vec_fracture_mat_IDs, vec_fracture_elements,
            vec_fracture_matrix_elements, vec_fracture_nodes);

        ProcessLib::LIE::PostProcessTool post(
            *mesh, vec_fracture_nodes, vec_fracture_matrix_elements);

        // create a new VTU file and update XML
        auto const dest_vtu_filename = "post_" + org_vtu_filename;
        INFO("create %s", (out_pvd_file_dir + dest_vtu_filename).c_str());
        MeshLib::IO::writeMeshToFile(post.getOutputMesh(), out_pvd_file_dir + dest_vtu_filename);

        dataset.second.put("<xmlattr>.file", dest_vtu_filename);
    }

    // save into the new PVD file
    INFO("save into the new PVD file %s", out_pvd_filename.c_str());
    boost::property_tree::xml_writer_settings<std::string> settings('\t', 1);
    write_xml(arg_out_pvd.getValue(), pt, std::locale(), settings);

    return EXIT_SUCCESS;
}
Example #19
0
void SpectraSet::save_as(std::string file_name) {
  boost::unique_lock<boost::mutex> lock(mutex_);
  write_xml(file_name);
}
Example #20
0
File: xml.cpp Project: spolitov/lib
void write_xml(const boost::filesystem::wpath & path, const boost::property_tree::wptree & inp)
{
    boost::filesystem::ofstream out(path);
    write_xml(out, inp);
}
Example #21
0
File: xml.cpp Project: spolitov/lib
void write_xml(const std::wstring & path, const boost::property_tree::wptree & inp)
{
    write_xml(boost::filesystem::wpath(path), inp);
}
Example #22
0
void SpectraSet::save() {
  boost::unique_lock<boost::mutex> lock(mutex_);
  if (/*changed_ && */(identity_ != "New project"))
    write_xml(identity_);
}
Example #23
0
void SceneImporter::save(const std::string& filename)
{
//	Write property tree to XML file
	write_xml(filename, pt);
}
Example #24
0
File: xml.cpp Project: spolitov/lib
void write_xml(const wchar_t * path, const boost::property_tree::wptree & inp)
{
    write_xml(boost::filesystem::wpath(path), inp);
}
int main(int argc, char *argv[])
{
	int retc = 0;
	int ret;

	char *hostfile = NULL;
	char *cachefile = NULL;
	char *xml = NULL;
	char *xmlfile = NULL;

	int cachefd = -1;

	char value[64];
	char units[64];

	int retry_count = 0, ret2;

	if (get_config(argc, argv) < 0) {
		retc = 2;
		goto cleanup;
	}

	if (config.heartbeat > 0) {
		debug("Checking heartbeat for %s with threshold %d\n",
		      config.host, config.heartbeat);
	} else {
		debug("Checking %s for %s metric\n",
		      config.host, config.metric);
	}

	hostfile = get_full_cache_path(config.cachepath, config.host);
	cachefile = get_full_cache_path(config.cachepath, config.cachename);

retry:
	debug("Checking cache at %s\n", cachefile);
	ret = check_cache_age(cachefile);
	if (ret < 0) {
		printf("ERROR: Unable to check cache age.\n");
		retc = 2;
		goto cleanup;
	}

	if (ret < config.max_age) {
		debug("Cache age is %d\n", ret);
	} else {
		debug("Cache age greater than configured max (%d >= %d)\n", ret, config.max_age);
		debug("Connecting to %s on port %d\n", config.gmetad_host, config.gmetad_port);
		ret = fetch_xml(config.gmetad_host, config.gmetad_port, &xml);
		if (ret < 0) {
			printf("ERROR: Unable to get XML data: %d.\n", ret);
			retc = 2;
			goto cleanup;
		}

		debug("Read %d bytes from %s\n", ret, config.gmetad_host);
		if (config.dump) {
			xmlfile = calloc((strlen(config.cachepath) + 9), sizeof(char));
			sprintf(xmlfile, "%s/dump.xml", config.cachepath);

			debug("Dumping XML to %s\n", xmlfile);
			if (write_xml(xml, ret, xmlfile) < 0) {
				printf("ERROR: Unable to dump XML.\n");
				retc = 2;
				goto cleanup;
			}
		}

		ret2 = get_cache_lock(cachefile, &cachefd);
		if (ret2 < 0) {
			if (retry_count == MAX_RETRY) {
				printf("ERROR: Unable to get cache lock after retrying %d times. Stale lock?", retry_count);
				retc = 2;
				goto cleanup;
			} else {
				backoff(retry_count / 2.0);
			}

			retry_count++;
			goto retry;
		}

		debug("Parsing XML into %s\n", config.cachepath);
		ret = parse_xml_to_cache(xml, ret, config.cachepath, cachefile);
		if (ret < 0) {
			printf("ERROR: Unable to parse XML.\n");
			retc = 2;
			goto cleanup;
		}

		touch_cache_lock(cachefile);
		release_cache_lock(cachefile, &cachefd);
	}

	if (config.heartbeat > 0) {
		strcpy(config.metric, "#REPORTED");
	}

	if (locate_hostfile(hostfile) < 0) {
		printf("CRITICAL - Unable to locate cache file for %s\n", config.host);
		retc = 2;
		goto cleanup;
	}

	debug("Fetching %s metric from cache at %s\n", config.metric, hostfile);

	ret = fetch_value_from_cache(hostfile, config.metric, value, units);
	if (ret < 0) {
		printf("CRITICAL - Unable to read cache at %s\n", hostfile);
		retc = 2;
		goto cleanup;
	} else if (ret == 0) {
		printf("CRITICAL - Metric %s not found\n", config.metric);
		retc = 2;
		goto cleanup;
	}

	debug("Checking...\n");

	if (config.heartbeat > 0) {
		int diff = time(NULL) - strtol(value, NULL, 10);
		if (diff > config.heartbeat) {
			printf("CRITICAL - %d over threshold %d\n", diff, config.heartbeat);
			retc = 2;
			goto cleanup;
		} else {
			printf("OK - %d\n", diff);
			goto cleanup;
		}
	}

	if (threshold_check(config.critical, value)) {
		printf("CRITICAL - %s %s\n", value, units);
		retc = 2;
	} else {
		if (threshold_check(config.warning, value)) {
			printf("WARNING - %s %s\n", value, units);
			retc = 1;
		} else {
			printf("OK - %s %s\n", value, units);
		}
	}

cleanup:
	if (cachefd >= 0) {
		release_cache_lock(cachefile, &cachefd);
	}

	if (xml != NULL)
		free(xml);

	if (xmlfile != NULL)
		free(xmlfile);

	if (hostfile != NULL)
		free(hostfile);

	if (cachefile != NULL)
		free(cachefile);

	exit(retc);
}
Example #26
0
/*
Manage the whole stuff.
*/
void	makeit()

  {
   checkstruct		*check;
   picstruct		*dfield, *field,*pffield[MAXFLAG], *wfield,*dwfield;
   catstruct		*imacat;
   tabstruct		*imatab;
   patternstruct	*pattern;
   static time_t        thetime1, thetime2;
   struct tm		*tm;
   unsigned int		modeltype;
   int			nflag[MAXFLAG], nparam2[2],
			i, nok, ntab, next, ntabmax, forcextflag,
			nima0,nima1, nweight0,nweight1, npsf0,npsf1, npat,npat0;

   next = 0;
   nok = 1;

/* Processing start date and time */
  dtime = counter_seconds();
  thetimet = time(NULL);
  tm = localtime(&thetimet);
  sprintf(prefs.sdate_start,"%04d-%02d-%02d",
        tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
  sprintf(prefs.stime_start,"%02d:%02d:%02d",
        tm->tm_hour, tm->tm_min, tm->tm_sec);

  NFPRINTF(OUTPUT, "");
  QPRINTF(OUTPUT, "----- %s %s started on %s at %s with %d thread%s\n\n",
		BANNER,
		MYVERSION,
		prefs.sdate_start,
		prefs.stime_start,
		prefs.nthreads,
		prefs.nthreads>1? "s":"");

/* Initialize globals variables */
  initglob();

  NFPRINTF(OUTPUT, "Setting catalog parameters");
  readcatparams(prefs.param_name);
  useprefs();			/* update things accor. to prefs parameters */

/* Check if a specific extension should be loaded */
/* Never true for an NDF, although we could through all NDFs in a container, */
/* so we make selectext go away. */
  nima0 = -1;
  forcextflag = 0;

/* Do the same for other data (but do not force single extension mode) */
  nima1 = -1;    /* selectext(prefs.image_name[1]) */
  nweight0 = -1; /* selectext(prefs.wimage_name[0]) */
  nweight1 = -1; /* selectext(prefs.wimage_name[1]) */
  if (prefs.dpsf_flag)
    {
    npsf0 = -1; /* selectext(prefs.psf_name[0]) */
    npsf1 = -1; /* selectext(prefs.psf_name[1]) */
    }
  else
    npsf0 = -1; /* selectext(prefs.psf_name[0]) */
  for (i=0; i<prefs.nfimage_name; i++)
    nflag[i] = -1; /* selectext(prefs.fimage_name[i]) */

  if (prefs.psf_flag)
    {
/*-- Read the first PSF extension to set up stuff such as context parameters */
    NFPRINTF(OUTPUT, "Reading PSF information");
    if (prefs.dpsf_flag)
      {
      thedpsf = psf_load(prefs.psf_name[0],nima0<0? 1 :(npsf0<0? 1:npsf0)); 
      thepsf = psf_load(prefs.psf_name[1], nima1<0? 1 :(npsf1<0? 1:npsf1));
      }
    else
      thepsf = psf_load(prefs.psf_name[0], nima0<0? 1 :(npsf0<0? 1:npsf0)); 
 /*-- Need to check things up because of PSF context parameters */
    updateparamflags();
    useprefs();
    }

  if (prefs.prof_flag)
    {
#ifdef USE_MODEL
    fft_init(prefs.nthreads);
/* Create profiles at full resolution */
    NFPRINTF(OUTPUT, "Preparing profile models");
    modeltype = (FLAG(obj2.prof_offset_flux)? MODEL_BACK : MODEL_NONE)
	|(FLAG(obj2.prof_dirac_flux)? MODEL_DIRAC : MODEL_NONE)
	|(FLAG(obj2.prof_spheroid_flux)?
		(FLAG(obj2.prof_spheroid_sersicn)?
			MODEL_SERSIC : MODEL_DEVAUCOULEURS) : MODEL_NONE)
	|(FLAG(obj2.prof_disk_flux)? MODEL_EXPONENTIAL : MODEL_NONE)
	|(FLAG(obj2.prof_bar_flux)? MODEL_BAR : MODEL_NONE)
	|(FLAG(obj2.prof_arms_flux)? MODEL_ARMS : MODEL_NONE);
    theprofit = profit_init(thepsf, modeltype);
    changecatparamarrays("VECTOR_MODEL", &theprofit->nparam, 1);
    changecatparamarrays("VECTOR_MODELERR", &theprofit->nparam, 1);
    nparam2[0] = nparam2[1] = theprofit->nparam;
    changecatparamarrays("MATRIX_MODELERR", nparam2, 2);
    if (prefs.dprof_flag)
      thedprofit = profit_init(thedpsf, modeltype);
    if (prefs.pattern_flag)
      {
      npat0 = prefs.prof_disk_patternvectorsize;
      if (npat0<prefs.prof_disk_patternmodvectorsize)
        npat0 = prefs.prof_disk_patternmodvectorsize;
      if (npat0<prefs.prof_disk_patternargvectorsize)
        npat0 = prefs.prof_disk_patternargvectorsize;
/*---- Do a copy of the original number of pattern components */
      prefs.prof_disk_patternncomp = npat0;
      pattern = pattern_init(theprofit, prefs.pattern_type, npat0);
      if (FLAG(obj2.prof_disk_patternvector))
        {
        npat = pattern->size[2];
        changecatparamarrays("DISK_PATTERN_VECTOR", &npat, 1);
        }
      if (FLAG(obj2.prof_disk_patternmodvector))
        {
        npat = pattern->ncomp*pattern->nfreq;
        changecatparamarrays("DISK_PATTERNMOD_VECTOR", &npat, 1);
        }
      if (FLAG(obj2.prof_disk_patternargvector))
        {
        npat = pattern->ncomp*pattern->nfreq;
        changecatparamarrays("DISK_PATTERNARG_VECTOR", &npat, 1);
        }
      pattern_end(pattern);
      }
    QPRINTF(OUTPUT, "Fitting model: ");
    for (i=0; i<theprofit->nprof; i++)
      {
      if (i)
        QPRINTF(OUTPUT, "+");
      QPRINTF(OUTPUT, "%s", theprofit->prof[i]->name);
      }
    QPRINTF(OUTPUT, "\n");
    if (FLAG(obj2.prof_concentration)|FLAG(obj2.prof_concentration))
      {
      thepprofit = profit_init(thepsf, MODEL_DIRAC);
      theqprofit = profit_init(thepsf, MODEL_EXPONENTIAL);
      }
#else
    error(EXIT_FAILURE,
		"*Error*: model-fitting is not supported in this build.\n",
			" Please check your configure options");
#endif
    }

  if (prefs.filter_flag)
    {
    NFPRINTF(OUTPUT, "Reading detection filter");
    getfilter(prefs.filter_name);	/* get the detection filter */
    }

  if (FLAG(obj2.sprob))
    {
    NFPRINTF(OUTPUT, "Initializing Neural Network");
    neurinit();
    NFPRINTF(OUTPUT, "Reading Neural Network Weights");
    getnnw(); 
    }

  if (prefs.somfit_flag)
    {
     int	margin;

    thesom = som_load(prefs.som_name);
    if ((margin=(thesom->inputsize[1]+1)/2) > prefs.cleanmargin)
      prefs.cleanmargin = margin;
    if (prefs.somfit_vectorsize>thesom->neurdim)
      {
      prefs.somfit_vectorsize = thesom->neurdim;
      sprintf(gstr,"%d", prefs.somfit_vectorsize);
      warning("Dimensionality of the SOM-fit vector limited to ", gstr);
      }
    }

/* Prepare growth-curve buffer */
  if (prefs.growth_flag)
    initgrowth();

/* Allocate memory for multidimensional catalog parameter arrays */
  alloccatparams();
  useprefs();

/*-- Init the CHECK-images */
  if (prefs.check_flag)
    {
      checkenum	c;
      
      NFPRINTF(OUTPUT, "Initializing check-image(s)");
      for (i=0; i<prefs.ncheck_type; i++)
        if ((c=prefs.check_type[i]) != CHECK_NONE)
          {
            if (prefs.check[c])
              error(EXIT_FAILURE,"*Error*: 2 CHECK_IMAGEs cannot have the same ",
                        " CHECK_IMAGE_TYPE");
            prefs.check[c] = initcheck(prefs.check_name[i], prefs.check_type[i],
                                       next);
            free(prefs.check_name[i]);
          }
    }

  NFPRINTF(OUTPUT, "Initializing catalog");
  initcat();
  
/* Initialize XML data */
  if (prefs.xml_flag || prefs.cat_type==ASCII_VO)
    init_xml(next);

/* Go through all images */
/* for all images in an MEF */

/*---- Initial time measurement*/
  time(&thetime1);
  thecat.currext = nok+1;
  
  dfield = field = wfield = dwfield = NULL;

/*---- Init the Detection and Measurement-images */
  if (prefs.dimage_flag)
  {
      dfield = newfield(prefs.image_name[0], DETECT_FIELD, nok);
      field = newfield(prefs.image_name[1], MEASURE_FIELD, nok);
      if ((field->width!=dfield->width) || (field->height!=dfield->height))
          error(EXIT_FAILURE, "*Error*: Frames have different sizes","");
/*---- Prepare interpolation */
      if (prefs.dweight_flag && prefs.interp_type[0] == INTERP_ALL)
          init_interpolate(dfield, -1, -1);
      if (prefs.interp_type[1] == INTERP_ALL)
          init_interpolate(field, -1, -1);
  }
  else
  {
      field = newfield(prefs.image_name[0], DETECT_FIELD | MEASURE_FIELD, nok);
/*-- Prepare interpolation */
      if ((prefs.dweight_flag || prefs.weight_flag)
          && prefs.interp_type[0] == INTERP_ALL)
          init_interpolate(field, -1, -1);       /* 0.0 or anything else */
  }

/*-- Init the WEIGHT-images */
  if (prefs.dweight_flag || prefs.weight_flag) 
  {
      weightenum	wtype;
      PIXTYPE	interpthresh;

      if (prefs.nweight_type>1)
      {
/*------ Double-weight-map mode */
          if (prefs.weight_type[1] != WEIGHT_NONE)
          {
/*-------- First: the "measurement" weights */
              wfield = newweight(prefs.wimage_name[1],field,prefs.weight_type[1],
                                 nok);
              wtype = prefs.weight_type[1];
              interpthresh = prefs.weight_thresh[1];
/*-------- Convert the interpolation threshold to variance units */
              weight_to_var(wfield, &interpthresh, 1);
              wfield->weight_thresh = interpthresh;
              if (prefs.interp_type[1] != INTERP_NONE)
                  init_interpolate(wfield,
                                   prefs.interp_xtimeout[1], prefs.interp_ytimeout[1]);
          }
/*------ The "detection" weights */
          if (prefs.weight_type[0] != WEIGHT_NONE)
          {
              interpthresh = prefs.weight_thresh[0];
              if (prefs.weight_type[0] == WEIGHT_FROMINTERP)
              {
                  dwfield=newweight(prefs.wimage_name[0],wfield,prefs.weight_type[0], 
                                    nok);
                  weight_to_var(wfield, &interpthresh, 1);
              }
              else
              {
                  dwfield = newweight(prefs.wimage_name[0], dfield?dfield:field,
                                      prefs.weight_type[0], nok);
                  weight_to_var(dwfield, &interpthresh, 1);
              }
              dwfield->weight_thresh = interpthresh;
              if (prefs.interp_type[0] != INTERP_NONE)
                  init_interpolate(dwfield,
                                   prefs.interp_xtimeout[0], prefs.interp_ytimeout[0]);
          }
      }
      else
      {
/*------ Single-weight-map mode */
          wfield = newweight(prefs.wimage_name[0], dfield?dfield:field,
                             prefs.weight_type[0], nok);
          wtype = prefs.weight_type[0];
          interpthresh = prefs.weight_thresh[0];
/*------ Convert the interpolation threshold to variance units */
          weight_to_var(wfield, &interpthresh, 1);
          wfield->weight_thresh = interpthresh;
          if (prefs.interp_type[0] != INTERP_NONE)
              init_interpolate(wfield,
                               prefs.interp_xtimeout[0], prefs.interp_ytimeout[0]);
      }
  }

/*-- Init the FLAG-images */
  for (i=0; i<prefs.nimaflag; i++)
  {
      pffield[i] = newfield(prefs.fimage_name[i], FLAG_FIELD, nok);
      if ((pffield[i]->width!=field->width)
          || (pffield[i]->height!=field->height))
          error(EXIT_FAILURE,
                "*Error*: Incompatible FLAG-map size in ", prefs.fimage_name[i]);
  }

/*-- Compute background maps for `standard' fields */
  QPRINTF(OUTPUT, dfield? "Measurement image:"
          : "Detection+Measurement image: ");
  makeback(field, wfield, prefs.wscale_flag[1]);
  QPRINTF(OUTPUT, (dfield || (dwfield&&dwfield->flags^INTERP_FIELD))? "(M)   "
          "Background: %-10g RMS: %-10g / Threshold: %-10g \n"
          : "(M+D) "
          "Background: %-10g RMS: %-10g / Threshold: %-10g \n",
          field->backmean, field->backsig, (field->flags & DETECT_FIELD)?
          field->dthresh: field->thresh);
  if (dfield)
  {
      QPRINTF(OUTPUT, "Detection image: ");
      makeback(dfield, dwfield? dwfield
                        : (prefs.weight_type[0] == WEIGHT_NONE?NULL:wfield),
                prefs.wscale_flag[0]);
      QPRINTF(OUTPUT, "(D)   "
              "Background: %-10g RMS: %-10g / Threshold: %-10g \n",
              dfield->backmean, dfield->backsig, dfield->dthresh);
  }
  else if (dwfield && dwfield->flags^INTERP_FIELD)
  {
      makeback(field, dwfield, prefs.wscale_flag[0]);
      QPRINTF(OUTPUT, "(D)   "
              "Background: %-10g RMS: %-10g / Threshold: %-10g \n",
              field->backmean, field->backsig, field->dthresh);
  }

/*-- For interpolated weight-maps, copy the background structure */
  if (dwfield && dwfield->flags&(INTERP_FIELD|BACKRMS_FIELD))
      copyback(dwfield->reffield, dwfield);
  if (wfield && wfield->flags&(INTERP_FIELD|BACKRMS_FIELD))
      copyback(wfield->reffield, wfield);

/*-- Prepare learn and/or associations */
  if (prefs.assoc_flag)
      init_assoc(field);                  /* initialize assoc tasks */

/*-- Update the CHECK-images */
  if (prefs.check_flag)
      for (i=0; i<MAXCHECK; i++)
        if ((check=prefs.check[i]))
          reinitcheck(field, check);

    if (!forcextflag && nok>1)
      {
      if (prefs.psf_flag)
        {
/*------ Read other PSF extensions */
        NFPRINTF(OUTPUT, "Reading PSF information");
        psf_end(thepsf, thepsfit);
        if (prefs.dpsf_flag)
          {
          psf_end(thedpsf, thedpsfit);
          thedpsf = psf_load(prefs.psf_name[0], nok);
          thepsf = psf_load(prefs.psf_name[1], nok);
          }
        else
          thepsf = psf_load(prefs.psf_name[0], nok); 
        }

#ifdef USE_MODEL
      if (prefs.prof_flag)
        {
/*------ Create profiles at full resolution */
        profit_end(theprofit);
        theprofit = profit_init(thepsf, modeltype);
        if (prefs.dprof_flag)
          {
          profit_end(thedprofit);
          thedprofit = profit_init(thedpsf, modeltype);
          }
        if (prefs.pattern_flag)
          {
          pattern = pattern_init(theprofit, prefs.pattern_type, npat0);
          pattern_end(pattern);
          }
        if (FLAG(obj2.prof_concentration)|FLAG(obj2.prof_concentration))
          {
          profit_end(thepprofit);
          profit_end(theqprofit);
          thepprofit = profit_init(thepsf, MODEL_DIRAC);
          theqprofit = profit_init(thepsf, MODEL_EXPONENTIAL);
          }
        }
#endif
      }

/*-- Initialize PSF contexts and workspace */
  if (prefs.psf_flag)
  {
      psf_readcontext(thepsf, field);
      psf_init();
      if (prefs.dpsf_flag)
        {
        psf_readcontext(thepsf, dfield);
        psf_init();
        }
  }

/*-- Copy field structures to static ones (for catalog info) */
  if (dfield)
  {
      thefield1 = *field;
      thefield2 = *dfield;
  }
  else
      thefield1 = thefield2 = *field;

  if (wfield)
  {
      thewfield1 = *wfield;
      thewfield2 = dwfield? *dwfield: *wfield;
  }
  else if (dwfield)
      thewfield2 = *dwfield;

  reinitcat(field);

/*-- Start the extraction pipeline */
  NFPRINTF(OUTPUT, "Scanning image");
  scanimage(field, dfield, pffield, prefs.nimaflag, wfield, dwfield);

  NFPRINTF(OUTPUT, "Closing files");

/*-- Finish the current CHECK-image processing */
  if (prefs.check_flag)
      for (i=0; i<MAXCHECK; i++)
        if ((check=prefs.check[i]))
          reendcheck(field, check);

/*-- Final time measurements*/
    if (time(&thetime2)!=-1)
      {
      if (!strftime(thecat.ext_date, 12, "%d/%m/%Y", localtime(&thetime2)))
        error(EXIT_FAILURE, "*Internal Error*: Date string too long ","");
      if (!strftime(thecat.ext_time, 10, "%H:%M:%S", localtime(&thetime2)))
          error(EXIT_FAILURE, "*Internal Error*: Time/date string too long ","");
      thecat.ext_elapsed = difftime(thetime2, thetime1);
      
  }

  reendcat();

/* Update XML data */
    if (prefs.xml_flag || prefs.cat_type==ASCII_VO)
      update_xml(&thecat, dfield? dfield:field, field,
	dwfield? dwfield:wfield, wfield);


/*-- Close ASSOC routines */
  end_assoc(field);

  for (i=0; i<prefs.nimaflag; i++)
      endfield(pffield[i]);
  endfield(field);
  if (dfield)
      endfield(dfield);
  if (wfield)
      endfield(wfield);
  if (dwfield)
      endfield(dwfield);

    QPRINTF(OUTPUT, "      Objects: detected %-8d / sextracted %-8d        \n\n",
	thecat.ndetect, thecat.ntotal);
/* End look around all images in an MEF */

  if (nok<0)
     error(EXIT_FAILURE, "Not enough valid FITS image extensions in ",
           prefs.image_name[0]);

  NFPRINTF(OUTPUT, "Closing files");

/* End CHECK-image processing */
  if (prefs.check_flag)
    for (i=0; i<MAXCHECK; i++)
      {
      if ((check=prefs.check[i]))
        endcheck(check);
      prefs.check[i] = NULL;
      }

  if (prefs.filter_flag)
    endfilter();

  if (prefs.somfit_flag)
    som_end(thesom);

  if (prefs.growth_flag)
    endgrowth();

#ifdef USE_MODEL
  if (prefs.prof_flag)
    {
    profit_end(theprofit);
    if (prefs.dprof_flag)
      profit_end(thedprofit);
    if (FLAG(obj2.prof_concentration)|FLAG(obj2.prof_concentration))
      {
      profit_end(thepprofit);
      profit_end(theqprofit);
      }
    fft_end();
    }
#endif

  if (prefs.psf_flag)
    psf_end(thepsf, thepsfit);

  if (prefs.dpsf_flag)
    psf_end(thedpsf, thedpsfit);

  if (FLAG(obj2.sprob))
    neurclose();

/* Processing end date and time */
  thetimet2 = time(NULL);
  tm = localtime(&thetimet2);
  sprintf(prefs.sdate_end,"%04d-%02d-%02d",
	tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
  sprintf(prefs.stime_end,"%02d:%02d:%02d",
	tm->tm_hour, tm->tm_min, tm->tm_sec);
  prefs.time_diff = counter_seconds() - dtime;

/* Write XML */
  if (prefs.xml_flag)
    write_xml(prefs.xml_name);

  endcat((char *)NULL);

  if (prefs.xml_flag || prefs.cat_type==ASCII_VO)
    end_xml();

/* Free FITS headers (now catalogues are closed). */
  if (field->fitsheadsize > 0) {
      free(field->fitshead);
  }

  return;
  }
Example #27
0
 inline std::ostream& operator << (std::ostream& S, const XMLCh* const X) {
   write_xml(S, X);
   return S;
 }