void CBacnetProgram::OnBnClickedButtonProgramEdit()
{
	// TODO: Add your control notification handler code here
	for (int i=0;i<m_program_list.GetItemCount();++i)
	{
		if(m_program_list.GetCellChecked(i,0))
		{
			program_list_line = i;
			break;
		}
	}

#if 0
	int	resend_count = 0;
	do 
	{
		resend_count ++;
		if(resend_count>RESEND_COUNT)
			return;
		if(m_Program_data.at(program_list_line).bytes <450)
			g_invoke_id = GetPrivateData(g_bac_instance,READPROGRAMCODE_T3000,program_list_line,program_list_line,m_Program_data.at(program_list_line).bytes + 10);
			//g_invoke_id = GetPrivateData(g_bac_instance,READPROGRAMCODE_T3000,program_list_line,program_list_line,200);
		else
		{
			g_invoke_id = GetPrivateData(g_bac_instance,READPROGRAMCODE_T3000,program_list_line,program_list_line, 10);
			TRACE("m_Program_data.at(program_list_line).bytes = %d\r\n",m_Program_data.at(program_list_line).bytes);
		}
		Sleep(200);
	} while (g_invoke_id<0);



	if(g_invoke_id>=0)
	{
		CString temp_cs;
		temp_cs.Format(_T("Task ID = %d. Read program code from item %d "),g_invoke_id,program_list_line);
		Post_Invoke_ID_Monitor_Thread(MY_INVOKE_ID,g_invoke_id,this->m_hWnd,temp_cs);
	}
	KillTimer(1);
	this->ShowWindow(0);
	CBacnetProgramEdit dlg;
	dlg.DoModal();
	this->ShowWindow(1);
	SetTimer(1,BAC_LIST_REFRESH_TIME,NULL);
#endif
	::PostMessage(BacNet_hwd,WM_FRESH_CM_LIST,MENU_CLICK,TYPE_PROGRAMCODE);

	//PostMessage(WM_REFRESH_BAC_PROGRAM_LIST,NULL,NULL);
		//Post_Invoke_ID_Monitor_Thread(MY_INVOKE_ID,g_invoke_id,this->m_hWnd);
	
	//OnBnClickedButtonProgramRead();
}
void CBacnetProgramEdit::OnRefresh()
{
	// TODO: Add your command handler code here
	((CRichEditCtrl *)GetDlgItem(IDC_RICHEDIT2_PROGRAM))->SetWindowTextW(_T(""));
	if(m_Program_data.at(program_list_line).bytes <450)
		g_invoke_id = GetPrivateData(g_bac_instance,READPROGRAMCODE_T3000,program_list_line,program_list_line,m_Program_data.at(program_list_line).bytes + 10);
	else
	{
		g_invoke_id = GetPrivateData(g_bac_instance,READPROGRAMCODE_T3000,program_list_line,program_list_line, 10);
	}
	if(g_invoke_id>=0)
	{
		CString temp_cs_show;
		temp_cs_show.Format(_T("Task ID = %d. Read program code from item %d "),g_invoke_id,program_list_line);
		Post_Invoke_ID_Monitor_Thread(MY_INVOKE_ID,g_invoke_id,BacNet_hwd,temp_cs_show);
	}
}
Esempio n. 3
0
void CBacnetSettingHealth::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
	//Post_Refresh_Message(g_bac_instance,READ_MISC,0,0,sizeof(Str_MISC),1);
	GetPrivateData(g_bac_instance,READ_MISC,0,0,sizeof(Str_MISC));

	Refresh_Health_Data();
	CDialogEx::OnTimer(nIDEvent);
}
Esempio n. 4
0
void ScorePB(double fissE, double wgt, long id)
{
  long pbd, pbl, ptr, ncol, idx;

  /* Check pointer */

  if ((pbd = (long)RDB[DATA_PTR_PB0]) < 0)
    return;

  /* Check fission energy */

  if (fissE < ZERO)
    return;

  /* Get collision number */

  ptr = (long)RDB[DATA_PTR_COLLISION_COUNT];
  ncol = (long)GetPrivateData(ptr, id);

  /* Loop over geometries */

  while (pbd > 0)
    {
      /* Get pointer to pebble where collision occured */

      if ((ptr = (long)RDB[pbd + PBED_PTR_POW]) > VALID_PTR)
	if ((pbl = TestValuePair(pbd + PBED_PTR_COL_PEBBLE, ncol, id)) 
	    > VALID_PTR)
	  {
	    /* Get pebble index */
	    
	    idx = (long)RDB[pbl + PEBBLE_IDX];
	    
	    /* Score */
	    
	    AddBuf1D(fissE, wgt, ptr, id, idx);
	  }
      
      /* Next */
      
      pbd = NextItem(pbd);
    }
}
BOOL CBacnetScheduleTime::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	Initial_List();
	// TODO:  Add extra initialization here
#if 0
	g_invoke_id = GetPrivateData(g_bac_instance,READTIMESCHEDULE_T3000,weekly_list_line,weekly_list_line,WEEKLY_SCHEDULE_SIZE);
	if(g_invoke_id>=0)
	{
		CString temp_cs_show;
		temp_cs_show.Format(_T("Task ID = %d. Read weekly schedule time from item %d "),g_invoke_id,weekly_list_line);
		Post_Invoke_ID_Monitor_Thread(MY_INVOKE_ID,g_invoke_id,this->m_hWnd,temp_cs_show);
	}
#endif
	PostMessage(WM_REFRESH_BAC_SCHEDULE_LIST,NULL,NULL);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}
Esempio n. 6
0
double MacroXS(long rea0, double E, long id)
{
  long i, ptr, rea, erg, ne, mat, nuc, ncol, mt;
  double xs0, xs1, xs, adens, f, mult, Emin, Emax, Er, T;
  
  /* Check Pointer */

  CheckPointer(FUNCTION_NAME, "(rea0)", DATA_ARRAY, rea0);

  /* Get mt */
  
  mt = (long)RDB[rea0 + REACTION_MT];
  CheckValue(FUNCTION_NAME, "mt", "", mt, -30, -1);

  /* Get pointer to material */
      
  mat = (long)RDB[rea0 + REACTION_PTR_MAT];
  CheckPointer(FUNCTION_NAME, "(mat)", DATA_ARRAY, mat);

  /* Get pointer to data */

  if ((ptr = (long)RDB[rea0 + REACTION_PTR_XS]) > VALID_PTR)
    {
      /***********************************************************************/

      /***** Interpolate pre-calculated data *********************************/

#ifdef DEBUG

      /* Sanity check for TMS */

      if (((long)RDB[mat + MATERIAL_TMS_MODE] == TMS_MODE_MG) ||
	  (((long)RDB[mat + MATERIAL_TMS_MODE] == TMS_MODE_CE) &&
	   (mt != MT_MACRO_TMP_MAJORANTXS)))
	Die(FUNCTION_NAME, "Pre-calculated data in %s %ld", 
	    GetText(mat + MATERIAL_PTR_NAME), mt);

#endif

      /* Test existing data (ei voi käyttää TMS:n kanssa) */

      if ((xs = TestValuePair(rea0 + REACTION_PTR_PREV_XS, E, id)) > -INFTY)
	return xs;
      
      /* Get pointer to energy grid */

      erg = (long)RDB[rea0 + REACTION_PTR_EGRID];
      CheckPointer(FUNCTION_NAME, "(erg)", DATA_ARRAY, erg);

      /* Get interpolation factor */

      if ((f = GridFactor(erg, E, id)) < 0)
	xs = 0.0;
      else
	{
	  /* Check interpolation factor */

	  CheckValue(FUNCTION_NAME, "f", "", f, 0.0, MAX_EGRID_NE);

	  /* Separate integer and decimal parts of interpolation factor */
      
	  i = (long)f;
	  f = f - (double)i;
      
	  /* Get number of points */
      
	  ne = (long)RDB[rea0 + REACTION_XS_NE];
	  CheckValue(FUNCTION_NAME, "ne", "", ne, 2, MAX_EGRID_NE);
      
	  /* Check boundaries */
	  
	  if ((i < 0) || (i > ne - 1))
	    xs = 0.0;
	  else
	    {      
	      /* Get tabulated cross sections */
	  
	      xs0 = RDB[ptr + i];
	      xs1 = RDB[ptr + i + 1];

	      if (mt != MT_MACRO_TMP_MAJORANTXS) 
		{	      		
		  /* Interpolate in normal case */
		  
		  if (i == ne - 1)
		    xs = (1.0 - f)*xs0;
		  else
		    xs = f*(xs1 - xs0) + xs0;
		}
	      else 
		{     		
		  /* TMS-tapauksessa majoranttia ei interpoloida */
		  /* (histogrammimajorantti) */
		  
		  xs = xs0;
		}
      	    }
	}

      /* Add poison cross section */
      
      if (((long)RDB[DATA_XENON_EQUILIBRIUM_MODE] == YES) ||
	  ((long)RDB[DATA_SAMARIUM_EQUILIBRIUM_MODE] == YES))
	if ((mt == MT_MACRO_TOTXS) || (mt == MT_MACRO_ABSXS))
	  xs = xs + PoisonXS(mat, E, mt, id);
      
      /* Perform ures correction */

      xs = MacroUresCorr(rea0, xs, E, id);

      /* Store value */

      StoreValuePair(rea0 + REACTION_PTR_PREV_XS, E, xs, id);

      /* Return value */
      
      return xs;

      /***********************************************************************/
    }
  else if (((long)RDB[mat + MATERIAL_TMS_MODE] != TMS_MODE_NONE) &&
	   (mt != MT_MACRO_TMP_MAJORANTXS))
    {
      /***********************************************************************/
      
      /***** TMS-moodi ******************************************************/

#ifdef DEBUG

      /* Sanity check for TMS */

      if ((RDB[mat + MATERIAL_TMS_TMIN] == 0.0) || 
	  (RDB[mat + MATERIAL_TMS_TMIN] > RDB[mat + MATERIAL_TMS_TMAX]))
	Die(FUNCTION_NAME, "Error in temperature in %s", 
	    GetText(mat + MATERIAL_PTR_NAME));

#endif

      /* Get collision number */

      ptr = (long)RDB[DATA_PTR_COLLISION_COUNT];
      ncol = (long)GetPrivateData(ptr, id);

      /* Test existing data (HUOM! ncol, koska lämpötila voi olla eri) */
      
      if ((xs = TestValuePair(rea0 + REACTION_PTR_PREV_XS, ncol, id)) > -INFTY)
	return xs;
      
      /* Reset cross section */

      xs = 0.0;
   
      /* Get material temperature for on-the-fly temperature treatment */

      if ((T = GetTemp(mat, id)) > 0.0)
	{
	  /* Get pointer to partial list */

	  ptr = (long)RDB[rea0 + REACTION_PTR_PARTIAL_LIST];
	  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);

	  /* Reset reaction pointer (rewind list) */
	  
	  rea = -1;

	  /* Loop over reactions */
	  
	  while (NextReaction(ptr, &rea, &adens, &Emin, &Emax, id) > VALID_PTR)
	    {
	      /* Check reaction pointer */
	      
	      CheckPointer(FUNCTION_NAME, "(rea)", DATA_ARRAY, rea);
	      
	      /* get multiplier */
	      
	      mult = ReaMulti(rea, mt, E, id);

	      /* Pointer to nuclide */

	      nuc = (long)RDB[rea + REACTION_PTR_NUCLIDE];
	      CheckPointer(FUNCTION_NAME, "(nuc)", DATA_ARRAY, nuc);
		
	      /* Add to cross section */
	  
	      xs = xs + mult*adens*DopMicroXS(mat, rea, E, &Er, T, id);
	  
	      /* Check energy cut-off */
	      
	      if (E < Emin)
		break;
	    }
	  
	  /* Store cross section */

	  StoreValuePair(rea0 + REACTION_PTR_PREV_XS, ncol, xs, id);

	  /* Return interpolated value */
	  
	  return xs;
	}

      /***********************************************************************/
    }

  /***************************************************************************/
  
  /***** Calculate sum of partials *******************************************/

  /* Test existing data */

  if ((xs = TestValuePair(rea0 + REACTION_PTR_PREV_XS, E, id)) > -INFTY)
    return xs;

  /* Reset cross section */
  
  xs = 0.0;
  
  /* Get pointer to partial list */
  
  ptr = (long)RDB[rea0 + REACTION_PTR_PARTIAL_LIST];
  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);

  /* Reset reaction pointer (rewind list) */
  
  rea = -1;
  
  /* Loop over reactions */

  while (NextReaction(ptr, &rea, &adens, &Emin, &Emax, id) > VALID_PTR)
    {
      /* Check reaction pointer */

      CheckPointer(FUNCTION_NAME, "(rea)", DATA_ARRAY, rea);

      /* Get multiplier */

      mult = ReaMulti(rea, mt, E, id);

      /* Add to cross section */

      if (mt != MT_MACRO_TMP_MAJORANTXS)
	xs = xs + mult*adens*MicroXS(rea, E, id);

      /* In case of majorantxs, use MicroMajorantXS */

      else
	xs = xs + mult*adens*MicroMajorantXS(rea, E, id);
            
      /* Check energy cut-off */
      
      if (E < Emin)
	break;
    }

  /* Store cross section */

  StoreValuePair(rea0 + REACTION_PTR_PREV_XS, E, xs, id);

  /* Return value */

  return xs;
  
  /****************************************************************************/
}
Esempio n. 7
0
void MyThread::RootFunction()
{
    PRStatus rv;
    PRUintn keys;
    const RCThreadPrivateData *pd;
    
    MyPrivateData extension = MyPrivateData("EXTENSION");
    MyPrivateData key_string[] = {
        "Key #0", "Key #1", "Key #2", "Key #3",
        "Bogus #5", "Bogus #6", "Bogus #7", "Bogus #8"};
    
    did = should = PR_FALSE;
    for (keys = 0; keys < 8; ++keys)
    {
        pd = GetPrivateData(key[keys]);
        MY_ASSERT(NULL == pd);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = SetPrivateData(keys, &key_string[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

#if !defined(DEBUG)
    did = should = PR_FALSE;
    for (keys = 4; keys < 8; ++keys)
    {
        rv = SetPrivateData(keys, &key_string[keys]);
        MY_ASSERT(PR_FAILURE == rv);
    }
    PrintProgress(__LINE__);
#endif
    
    did = PR_FALSE; should = PR_TRUE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = SetPrivateData(key[keys], &key_string[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = PR_FALSE; should = PR_TRUE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = SetPrivateData(key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = SetPrivateData(key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = SetPrivateData(key[keys], &extension);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = PR_FALSE; should = PR_TRUE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = SetPrivateData(key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = SetPrivateData(key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
}  /* MyThread::RootFunction */
Esempio n. 8
0
double OTFSabXS(long rea, double E, double T, long id){

  long nuc, sab1, sab2, nuc1, nuc2, mt, rea2, sab0, ptr, ncol; 
  double f, xs1, xs2, T1, T2, xs;
 
  /* Check reaction pointer */

  CheckPointer(FUNCTION_NAME, "(rea)", DATA_ARRAY, rea);

  /* Avoid compiler warning */

  sab1 = -1;

  /* Get reaction mt and rea nuclide */

  mt = (long)RDB[rea + REACTION_MT];

  nuc = (long)RDB[rea + REACTION_PTR_NUCLIDE];
  CheckPointer(FUNCTION_NAME, "(nuc)", DATA_ARRAY, nuc);

  if (E > RDB[nuc + NUCLIDE_SAB_EMAX])
    return MicroXS(rea, E, id);

  /* Check that data exists */

  if ((sab2 = (long)RDB[nuc + NUCLIDE_PTR_SAB]) < VALID_PTR )
    Die(FUNCTION_NAME, "S(a,b) data not available for nuclide %s", 
	GetText(nuc + NUCLIDE_PTR_NAME));
  
  /* Find correct temperature */
  
  while(sab2 > VALID_PTR)
    {
      if (RDB[sab2 + SAB_T] > T)
	break;
    
      sab2 = NextItem(sab2);
    }

  /* Check that sab was found */

  if (sab2 < VALID_PTR)
    Die(FUNCTION_NAME, "S(a,b) OTF nuclide not found for %s", 
	GetText(nuc + NUCLIDE_PTR_NAME));

  sab1 = PrevItem(sab2);

  /* Check Pointers */

  CheckPointer(FUNCTION_NAME, "(sab1)", DATA_ARRAY, sab1);
  CheckPointer(FUNCTION_NAME, "(sab2)", DATA_ARRAY, sab2);

  /* Temperatures */

  T1 = RDB[sab1 + SAB_T];
  T2 = RDB[sab2 + SAB_T];

  /* Pointers to S(a,b) nuclides */

  nuc1 = RDB[sab1 + SAB_PTR_ISO];
  nuc2 = RDB[sab2 + SAB_PTR_ISO];

  CheckPointer(FUNCTION_NAME, "(nuc1)", DATA_ARRAY, nuc1);
  CheckPointer(FUNCTION_NAME, "(nuc2)", DATA_ARRAY, nuc2);

  /* Find reaction pointers in S(a,b) data */
  
  /* Elastic scattering xs = total xs in case of S(a,b) nuclides 
     (which only have 1004 and 1002 reactions and total is 
     calculated over them) */
  
  if ((mt == 1) || (mt == 2))
    rea2 = (long)RDB[nuc1 + NUCLIDE_PTR_TOTXS];
  
  /* Find reaction at first temperature */

  else
    {
      /* Pointer to reaction */

      rea2 = (long)RDB[nuc1 + NUCLIDE_PTR_REA];
      CheckPointer(FUNCTION_NAME, "(rea2)", DATA_ARRAY, rea2);

      /* JLe: Tässä voisi käyttää SeekList():iä */

      while (rea2 > VALID_PTR)
	{     
	  if ((long)RDB[rea2 + REACTION_MT] == mt - 1000)
	    break;
      
	  rea2 = NextItem(rea2);
	}
    
      if (rea2 < VALID_PTR)
	Die(FUNCTION_NAME, "mt %ld not found for S(a,b) nuclide %s", mt, 
	    GetText(nuc1 + NUCLIDE_PTR_NAME));
    }

  /* Get cross section */

  xs1 = MicroXS(rea2, E, id);
  CheckValue(FUNCTION_NAME, "xs1", "", xs1, 0.0, 1E+10);

  if ((mt == 1) || (mt == 2))
    rea2 = (long)RDB[nuc2 + NUCLIDE_PTR_TOTXS];

    /* Find reaction at second temperature */

  else
    {
      rea2 = (long)RDB[nuc2 + NUCLIDE_PTR_REA];
      CheckPointer(FUNCTION_NAME, "(rea2)", DATA_ARRAY, rea2);

      /* JLe: Tässä voisi käyttää SeekList():iä */

      while (rea2 > VALID_PTR)
	{
	  if ((long)RDB[rea2 + REACTION_MT] == mt - 1000)
	    break;
      
	  rea2 = NextItem(rea2);
	}
    
      if (rea2 < VALID_PTR)
	Die(FUNCTION_NAME, "mt %ld not found for S(a,b) nuclide %s", mt, 
	    GetText(nuc1 + NUCLIDE_PTR_NAME));
    }

  /* Get cross section */

  xs2 = MicroXS(rea2, E, id);
  CheckValue(FUNCTION_NAME, "xs2", "", xs2, 0.0, 1E+10);

  /* Avoid compiler warning */
  
  f = -1.0;

  /* Calculate factor */

  if (T1 != T2)
    f = (T-T1)/(T2-T1);
  else
    Die(FUNCTION_NAME, "Division by zero");

  /* Check value */

  CheckValue(FUNCTION_NAME, "f", "", f, 0.0, 1.0);

  /* Get collision number */
  
  ptr = (long)RDB[DATA_PTR_COLLISION_COUNT];
  ncol = (long)GetPrivateData(ptr, id);

  /* Pointer to first item in sab list */

  sab0 = (long)RDB[nuc + NUCLIDE_PTR_SAB];

  /* Store values */

  StoreValuePair(sab0 + SAB_PTR_PREV_FRAC, ncol, f, id);
  StoreValuePair(sab0 + SAB_PTR_PREV_SAB1, ncol, (double)sab1, id);

  xs = xs1 + f*(xs2-xs1);

  /* Tämä poistettiin juuri ennen 2.1.25:n jakelua, sillä se sotkee */
  /* myöhemmin käytettävän kokonaisvaikutusalan arvon (JLe / 19.2.2016). */
  
  /*
  StoreValuePair(rea + REACTION_PTR_PREV_XS, E, xs, id);
  */

  /* Näillä voisi varmaan optimoida myös tuota rutiinin alkupäätä */

  /* JLe: Jos palautettava arvo on samalla energialla aina sama, niin   */
  /* alkuun voi laittaa TestValuePair() -kutsun. Onko nuo kaksi ylempää */
  /* tosiaan tarkoitus kiinnittää törmäykseen eikä energiaan? */

  return xs;
}
Esempio n. 9
0
void PulseDet(long part, long mat, double dE, double x0, double y0, double z0, 
	      double wgt0, long id)
{
  long det, loc0, loc1, idx, ptr, pts, hix, i;
  double Etot, wgt;

  /* Loop over detectors */

  det = (long)RDB[DATA_PTR_DET0];
  while (det > VALID_PTR)
    {
      /* Check type */
      
      if (((long)RDB[det + DET_PARTICLE] != PARTICLE_TYPE_GAMMA) || 
	  ((long)RDB[det + DET_PTR_SBINS] > VALID_PTR))
	{
	  /* Next detector */
      
	  det = NextItem(det);

	  /* Cycle loop */

	  continue;
	}

      /* Get pointer to response functions */

      loc0 = (long)RDB[det + DET_PTR_RBINS];
      CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0);

      /* Check mt (no multiple reaction bins allowed) */

      if ((long)RDB[loc0 + DET_RBIN_MT] != MT_PHOTON_PULSE_HEIGHT)
	{
	  /* Next detector */

	  det = NextItem(det);

	  /* Cycle loop */

	  continue;
	}
	  
      /* Pointer to pulse data */

      loc1 = (long)RDB[loc0 + DET_RBIN_PTR_PULSE_DATA];
      CheckPointer(FUNCTION_NAME, "(loc1)", DATA_ARRAY, loc1);
      
      /* Get pointer to statistics */
	      
      pts = (long)RDB[det + DET_PTR_STAT];
      CheckPointer(FUNCTION_NAME, "(pts)", DATA_ARRAY, pts);

      /* Check call type */
      
      if (part == -1)
	{
	  /*******************************************************************/

	  /***** Called after last batch *************************************/

	  /* Loop over OpenMP threads */
		  
	  for (i = 0; i < (long)RDB[DATA_OMP_MAX_THREADS]; i++)
	    {
	      /* Retrieve stored energy and weight */
	      
	      Etot = GetPrivateData(loc1 + DET_PULSE_EDEP, i);
	      wgt = GetPrivateData(loc1 + DET_PULSE_WGT, i);
	      
	      /* Pointer to energy grid */
	      
	      if ((ptr = (long)RDB[det + DET_PTR_EGRID]) < VALID_PTR)
		idx = 0;
	      else
		{
		  /* Grid search */
		  
		  idx = GridSearch(ptr, Etot);
		}
	      
	      /* Check index */
	      
	      if (idx > -1)
		{
		  /* Score pulse */
		  
		  AddBuf(1.0, wgt, pts, i, -1, idx, 0);
		}
	      
	      /* Reset pulse data */
		  
	      PutPrivateData(loc1 + DET_PULSE_PHOTON_IDX, -1, i);
	      PutPrivateData(loc1 + DET_PULSE_EDEP, 0.0, i);
	      PutPrivateData(loc1 + DET_PULSE_WGT, -1.0, i);
	    }
	  
	  /***************************************************************/
	}
      else
	{
	  /*******************************************************************/

	  /***** Called from collision point *********************************/

	  /* Check particle pointer */

	  CheckPointer(FUNCTION_NAME, "(part)", DATA_ARRAY, part);
	  
	  /* Check bin (this is just to check that the collision is */
	  /* inside the detector, the index is not relevant here).  */
	  
	  if (DetBin(det, mat, x0, y0, z0, -INFTY, 0.0, id) < 0)
	    {
	      /* Next detector */

	      det = NextItem(det);

	      /* Cycle loop */
	      
	      continue;
	    }
	  
	  /* Get history index */

	  hix = (long)RDB[part + PARTICLE_HISTORY_IDX] + 1;
	  
	  /* Check index */
	  
	  if (hix == (long)GetPrivateData(loc1 + DET_PULSE_PHOTON_IDX, id))
	    {
	      /* Still same history, add to temporary storage */
	      
	      AddPrivateData(loc1 + DET_PULSE_EDEP, dE, id);

	      /* Compare weight */

	      if (wgt0 != GetPrivateData(loc1 + DET_PULSE_WGT, id))
		Die(FUNCTION_NAME, "Mismatch in weight");
	    }
	  else
	    {
	      /* New history, retrieve stored energy and weight */
	      
	      Etot = GetPrivateData(loc1 + DET_PULSE_EDEP, id);
	      wgt = GetPrivateData(loc1 + DET_PULSE_WGT, id);

	      /* Pointer to energy grid */
	      
	      if ((ptr = (long)RDB[det + DET_PTR_EGRID]) < VALID_PTR)
		idx = 0;
	      else
		{
		  /* Grid search */
		  
		  idx = GridSearch(ptr, Etot);
		}
	      
	      /* Check index */
	      
	      if (idx > -1)
		{
		  /* Score pulse */
		  
		  AddBuf(1.0, wgt, pts, id, -1, idx, 0);
		}
	      
	      /* Store new data */

	      PutPrivateData(loc1 + DET_PULSE_PHOTON_IDX, hix, id);
	      PutPrivateData(loc1 + DET_PULSE_EDEP, dE, id);
	      PutPrivateData(loc1 + DET_PULSE_WGT, wgt0, id);
	    }

	  /*******************************************************************/
	}
      
      /* Next detector */
      
      det = NextItem(det);
    }
}
Esempio n. 10
0
void CoordTrans(long ptr, double *x, double *y, double *z, double *u, 
		double *v, double *w, long id)
{
  long lvl;
  double x0, y0, z0, u0, v0, w0;

  /* Check coordinates and direction cosines */

  CheckValue(FUNCTION_NAME, "x", "", *x, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "y", "", *y, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "z", "", *z, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "u", "", *u, -1.0, 1.0);
  CheckValue(FUNCTION_NAME, "v", "", *v, -1.0, 1.0);
  CheckValue(FUNCTION_NAME, "w", "", *w, -1.0, 1.0);

  /* Check pointer */

  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);

  /* Loop over transformations */

  while (ptr > VALID_PTR)
    {
      /* Check level pointer */
  
      if ((lvl = (long)RDB[ptr + TRANS_PTR_LVL]) > VALID_PTR)
	{
	  /* Get coordinates and direction cosines */
	  
	  *x = GetPrivateData(lvl + LVL_PRIV_X, id);
	  *y = GetPrivateData(lvl + LVL_PRIV_Y, id);
	  *z = GetPrivateData(lvl + LVL_PRIV_Z, id);
	  *u = GetPrivateData(lvl + LVL_PRIV_U, id);
	  *v = GetPrivateData(lvl + LVL_PRIV_V, id);
	  *w = GetPrivateData(lvl + LVL_PRIV_W, id);
	}
      
      /* Check rotations */
      
      if ((long)RDB[ptr + TRANS_ROT] == YES)
	{
	  /* Copy values to temporary variables */
	  
	  x0 = *x;
	  y0 = *y;
	  z0 = *z;
	  u0 = *u;
	  v0 = *v;
	  w0 = *w;
	  
	  /* Do matrix multiplication */
	  
	  *x = x0*RDB[ptr + TRANS_RX1] + y0*RDB[ptr + TRANS_RX2] 
	    + z0*RDB[ptr + TRANS_RX3];
	  *y = x0*RDB[ptr + TRANS_RX4] + y0*RDB[ptr + TRANS_RX5] 
	    + z0*RDB[ptr + TRANS_RX6];
	  *z = x0*RDB[ptr + TRANS_RX7] + y0*RDB[ptr + TRANS_RX8] 
	    + z0*RDB[ptr + TRANS_RX9];
	  *u = u0*RDB[ptr + TRANS_RX1] + v0*RDB[ptr + TRANS_RX2] 
	    + w0*RDB[ptr + TRANS_RX3];
	  *v = u0*RDB[ptr + TRANS_RX4] + v0*RDB[ptr + TRANS_RX5] 
	    + w0*RDB[ptr + TRANS_RX6];
	  *w = u0*RDB[ptr + TRANS_RX7] + v0*RDB[ptr + TRANS_RX8] 
	    + w0*RDB[ptr + TRANS_RX9];
	  
	  /* Copy values to temporary variables */
	  
	  x0 = *x;
	  y0 = *y;
	  z0 = *z;
	  u0 = *u;
	  v0 = *v;
	  w0 = *w;
	  
	  /* Do matrix multiplication */
	  
	  *x = x0*RDB[ptr + TRANS_RY1] + y0*RDB[ptr + TRANS_RY2] 
	    + z0*RDB[ptr + TRANS_RY3];
	  *y = x0*RDB[ptr + TRANS_RY4] + y0*RDB[ptr + TRANS_RY5] 
	    + z0*RDB[ptr + TRANS_RY6];
	  *z = x0*RDB[ptr + TRANS_RY7] + y0*RDB[ptr + TRANS_RY8] 
	    + z0*RDB[ptr + TRANS_RY9];
	  *u = u0*RDB[ptr + TRANS_RY1] + v0*RDB[ptr + TRANS_RY2] 
	    + w0*RDB[ptr + TRANS_RY3];
	  *v = u0*RDB[ptr + TRANS_RY4] + v0*RDB[ptr + TRANS_RY5] 
	    + w0*RDB[ptr + TRANS_RY6];
	  *w = u0*RDB[ptr + TRANS_RY7] + v0*RDB[ptr + TRANS_RY8] 
	    + w0*RDB[ptr + TRANS_RY9];
	  
	  /* Copy values to temporary variables */
	  
	  x0 = *x;
	  y0 = *y;
	  z0 = *z;
	  u0 = *u;
	  v0 = *v;
	  w0 = *w;
	  
	  /* Do matrix multiplication */
	  
	  *x = x0*RDB[ptr + TRANS_RZ1] + y0*RDB[ptr + TRANS_RZ2] 
	    + z0*RDB[ptr + TRANS_RZ3];
	  *y = x0*RDB[ptr + TRANS_RZ4] + y0*RDB[ptr + TRANS_RZ5] 
	    + z0*RDB[ptr + TRANS_RZ6];
	  *z = x0*RDB[ptr + TRANS_RZ7] + y0*RDB[ptr + TRANS_RZ8] 
	    + z0*RDB[ptr + TRANS_RZ9];
	  *u = u0*RDB[ptr + TRANS_RZ1] + v0*RDB[ptr + TRANS_RZ2] 
	    + w0*RDB[ptr + TRANS_RZ3];
	  *v = u0*RDB[ptr + TRANS_RZ4] + v0*RDB[ptr + TRANS_RZ5] 
	    + w0*RDB[ptr + TRANS_RZ6];
	  *w = u0*RDB[ptr + TRANS_RZ7] + v0*RDB[ptr + TRANS_RZ8] 
	    + w0*RDB[ptr + TRANS_RZ9];
	}

      /* Transfer coordinates */
      
      *x = *x - RDB[ptr + TRANS_X0];
      *y = *y - RDB[ptr + TRANS_Y0];
      *z = *z - RDB[ptr + TRANS_Z0];

      /* Next */

      ptr = NextItem(ptr);
    }

  /* Check coordinates and direction cosines */

  CheckValue(FUNCTION_NAME, "x", "", *x, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "y", "", *y, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "z", "", *z, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "u", "", *u, -1.0, 1.0);
  CheckValue(FUNCTION_NAME, "v", "", *v, -1.0, 1.0);
  CheckValue(FUNCTION_NAME, "w", "", *w, -1.0, 1.0);
}
void ScoreInterfacePower(double fissE, double wgt, double x, double y, 
			 double z, double t, long id)
{
  long loc0, loc1, ptr, ncol, idx, nz, nr, i, j, k, uni, na, nt, l;
  double zmin, zmax, x0, y0, r0, r, f, r2, phi;

  /* Check that interfaces are defined */

  if ((loc0 = (long)RDB[DATA_PTR_IFC0]) < VALID_PTR)
    return;

  /***************************************************************************/

  /***** Interface to thermal hydraulics *************************************/

  /* Get zone index */

  ptr = (long)RDB[DATA_PTR_ZONE_IDX];
  idx = (long)GetPrivateData(ptr, id);

  /* Loop over interfaces */

  while (loc0 > VALID_PTR)
    {
      /* Check flag and type */
      
      if (((long)RDB[loc0 + IFC_CALC_OUTPUT] == YES) &&
	  (((long)RDB[loc0 + IFC_TYPE] < IFC_TYPE_FUEP) || 
	   ((long)RDB[loc0 + IFC_TYPE] > IFC_TYPE_FPIP)))
	{
	  /* Get pointer to statistics */
		    
	  ptr = (long)RDB[loc0 + IFC_PTR_STAT];
	  CheckPointer(FUNCTION_NAME, "ptr", DATA_ARRAY, ptr);

	  /* Check type */

	  if ((long)RDB[loc0 + IFC_TYPE] == IFC_TYPE_TET_MESH)
	    {
	      /* Get collision number */
	      
	      ncol = (long)RDB[DATA_PTR_COLLISION_COUNT];
	      ncol = (long)GetPrivateData(ncol, id);
	  
	      /* Get pointer to tet cell (set in ifcpoint.c) */

	      if ((loc1 = TestValuePair(loc0 + IFC_PTR_PREV_COL_CELL, ncol, id))
		  > VALID_PTR)
		{
		  /* Get index to statistics and score */
		  
		  if ((i = (long)RDB[loc1 + IFC_TET_MSH_STAT_IDX]) > -1)
		    AddBuf1D(fissE, wgt, ptr, id, i);
		}
	    }
	  else
	    {
	      /* Other types, get axial boundaries and number of bins */
	      
	      zmin = RDB[loc0 + IFC_ZMIN];
	      zmax = RDB[loc0 + IFC_ZMAX];
	      nz = (long)RDB[loc0 + IFC_NZ];
	      nr = (long)RDB[loc0 + IFC_NR];
	      
	      /* Find region (toi z-tarkistus tarvitaan että indeksi menee */
	      /* alarajalla oikein) */

	      if ((z >= zmin) && (z < zmax))
		if ((loc1 = (long)RDB[loc0 + IFC_PTR_SCORE]) > VALID_PTR)
		  if ((loc1 = SeekList(loc1, IFC_SCORE_REG_IDX, idx, 
				       SORT_MODE_ASCEND)) > VALID_PTR)
		    {
		      /* Get stat index */
		      
		      i = (long)RDB[loc1 + IFC_SCORE_STAT_IDX];
		      CheckValue(FUNCTION_NAME, "i", "", i, 0, 
				 (long)RDB[loc0 + IFC_STAT_NREG]);
		      
		      /* Get pointer to output data */
		      
		      loc1 = (long)RDB[loc1 + IFC_SCORE_PTR_OUT];
		      CheckPointer(FUNCTION_NAME, "(loc1)", DATA_ARRAY, loc1);
		      
		      /* Calculate axial bin */
		      
		      j = (long)((z - zmin)/(zmax - zmin)*((double)nz));
		      CheckValue(FUNCTION_NAME, "j", "", j, 0, nz - 1);
		      
		      /* Get center coordinates and radius */
		      
		      x0 = RDB[loc1 + IFC_OUT_X0];
		      y0 = RDB[loc1 + IFC_OUT_Y0];
		      r0 = RDB[loc1 + IFC_OUT_R];
		      
		      /* Check for zero radius */
		      
		      if (r0 < ZERO)
			Die(FUNCTION_NAME, "Zero radius");		      
		      
		      /* Get square radius */
		      
		      r = (x - x0)*(x - x0) + (y - y0)*(y - y0);
		      
		      /* Calculate radial zone (typerä toi jälkimmäinen) */
		      
		      if ((f = r/r0/r0) > 1.0)
			Die(FUNCTION_NAME, 
			    "Point is not inside %E %E : %E %E : %E",
			    x, y, x0, y0, r0);
		      else if (f == 1.0)
			f = 0.999999;
		      
		      /* Index */
		      
		      k = (long)(f*nr);		      
		      CheckValue(FUNCTION_NAME, "k", "", k, 0, nr - 1);
		      
		      /* Score */
		      
		      AddBuf(fissE, wgt, ptr, id, -1, i, j, k);
		    }
	    }
	}
      
      /* Next interface */
      
      loc0 = NextItem(loc0);
    }

  /***************************************************************************/

  /***** Interface to fuel performance codes *********************************/

  /* Get collision universe */
  
  ptr = (long)RDB[DATA_PTR_COLLISION_UNI];
  uni = GetPrivateData(ptr, id);
  
  /* Check pointer */
  
  CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni);
  
  /* Check pointer to interface */
  
  if ((loc1 = (long)RDB[uni + UNIVERSE_PTR_IFC_FUEP]) > VALID_PTR)
    {
      /* Get coordinates */
      
      ptr = RDB[uni + UNIVERSE_PTR_PRIVA_X];
      CheckPointer(FUNCTION_NAME, "(xptr)", PRIVA_ARRAY, ptr);
      x = GetPrivateData(ptr, id);
      
      ptr = RDB[uni + UNIVERSE_PTR_PRIVA_Y];
      CheckPointer(FUNCTION_NAME, "(yptr)", PRIVA_ARRAY, ptr);
      y = GetPrivateData(ptr, id);

      ptr = RDB[uni + UNIVERSE_PTR_PRIVA_Z];
      CheckPointer(FUNCTION_NAME, "(zptr)", PRIVA_ARRAY, ptr);
      z = GetPrivateData(ptr, id);

      ptr = RDB[uni + UNIVERSE_PTR_PRIVA_T];
      CheckPointer(FUNCTION_NAME, "(ptr)", PRIVA_ARRAY, ptr);
      t = GetPrivateData(ptr, id);

      /* Coordinate transformation to cold system */

      CoordExpans(loc1, &x, &y, &z, t, 1);

      /* Get the size of the statistics */
      
      ptr = (long)RDB[loc1 + IFC_FUEP_OUT_PTR_LIM];
      CheckPointer(FUNCTION_NAME, "(limptr)", DATA_ARRAY, ptr);

      nz = (long)RDB[ptr + FUEP_NZ];
      na = (long)RDB[ptr + FUEP_NA];
      nr = (long)RDB[ptr + FUEP_NR];
      nt = (long)RDB[ptr + FUEP_NT];

      /* Get pointer to axial output zones */

      ptr = (long)RDB[loc1 + IFC_FUEP_OUT_PTR_Z];
      CheckPointer(FUNCTION_NAME, "(zptr)", DATA_ARRAY, ptr);

      /* Find interval */	  

      i = SearchArray(&RDB[ptr], z, nz + 1);

      /* Check */

      if (i < 0)
	{
	  Warn(FUNCTION_NAME,"Outside of axial zone");
	  return;
	}

      /* Calculate angle */

      phi = PolarAngle(x, y);
	  
      /* Check phi */

      CheckValue(FUNCTION_NAME, "phi", "", phi, 0.0, 2.0*PI);

      /* Get pointer to angular output zones */

      ptr = (long)RDB[loc1 + IFC_FUEP_OUT_PTR_PHI];
      CheckPointer(FUNCTION_NAME, "(aptr)", DATA_ARRAY, ptr);

      /* Rotate if needed */

      if (phi > 2.0*PI+RDB[ptr])
	phi -= 2.0*PI;
      
      /* Find interval */

      j = SearchArray(&RDB[ptr], phi, na + 1);

      /* Check */

      if (j < 0)
	{
	  Warn(FUNCTION_NAME,"Outside of angular zone");
	  return;
	}

      /* Calculate square radius */

      r2 = x*x + y*y;

      /* Get pointer to radial output zones */

      ptr = (long)RDB[loc1 + IFC_FUEP_OUT_PTR_R2];
      CheckPointer(FUNCTION_NAME, "(rptr)", DATA_ARRAY, ptr);

      /* Find interval */
	  
      k = SearchArray(&RDB[ptr], r2, nr + 1);

      /* Check */

      if (k < 0)
	{
	  Warn(FUNCTION_NAME,"Outside of radial zone");
	  return;
	}

      /* Find time bin */

      ptr = (long)RDB[loc1 + IFC_FUEP_OUT_PTR_TB];
      CheckPointer(FUNCTION_NAME, "(TBptr)", DATA_ARRAY, ptr);

      /* Find bin*/

      l = SearchArray(&RDB[ptr], t, nt + 1);

      /* Check */

      if (l < 0)
	return;

      /* Score */

      ptr = (long)RDB[loc1 + IFC_FUEP_PTR_POWER];
      CheckPointer(FUNCTION_NAME, "(Pptr)", DATA_ARRAY, ptr);
      
      AddBuf(fissE, wgt, ptr, id, -1, i, j, k, l);
    }

  /***************************************************************************/
}
Esempio n. 12
0
long WhereAmI(double x, double y, double z, double u, double v, double w, 
	      long id)
{
  long uni, lvl0, lvl, cell, mat, nst, reg, lat, ptr, pbd, umsh, pbl, stl;
  long ncol, zone, idx, type, cgns, tra;

  /* Get pointer to root universe */
  
  uni = (long)RDB[DATA_PTR_ROOT_UNIVERSE];
  CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni);

  /* Pointer to first level */

  lvl0 = (long)RDB[DATA_PTR_LVL0];
  CheckPointer(FUNCTION_NAME, "(lvl0)", DATA_ARRAY, lvl0);

  /* Get collision number */

  ptr = (long)RDB[DATA_PTR_COLLISION_COUNT];
  ncol = (long)GetPrivateData(ptr, id);

  /* Reset zone index */

  zone = 0;

  /* Loop over levels */

  while (lvl0 > VALID_PTR)
    {
      /* Pointer to private data */

      lvl = (long)RDB[lvl0 + LVL_PTR_PRIVATE_DATA];
      CheckPointer(FUNCTION_NAME, "(lvl)", PRIVA_ARRAY, lvl);

      /* Check universe pointer */
  
      CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni);

      /* Do coordinate transformation */
      
      if ((tra = (long)RDB[uni + UNIVERSE_PTR_TRANS]) > VALID_PTR)
	CoordTrans(tra, &x, &y, &z, &u, &v, &w, id);

      /* Universe symmetry */

      if ((ptr = (long)RDB[uni + UNIVERSE_PTR_SYM]) > VALID_PTR)
	UniSym(ptr, &x, &y, &z, &u, &v, &w);

      /* Reset pointers */

      PutPrivateData(lvl + LVL_PRIV_PTR_NEST_REG, NULLPTR, id);
      PutPrivateData(lvl + LVL_PRIV_PTR_LAT, NULLPTR, id);
      PutPrivateData(lvl + LVL_PRIV_PTR_CELL, NULLPTR, id);
      PutPrivateData(lvl + LVL_PRIV_PTR_PBED, NULLPTR, id);
      PutPrivateData(lvl + LVL_PRIV_PTR_PEBBLE, NULLPTR, id);
      PutPrivateData(lvl + LVL_PRIV_PTR_UMSH, NULLPTR, id);
      PutPrivateData(lvl + LVL_PRIV_PTR_STL, NULLPTR, id);
      PutPrivateData(lvl + LVL_PRIV_PTR_MAT, NULLPTR, id);
      PutPrivateData(lvl + LVL_PRIV_ZONE_IDX, NULLPTR, id);

      /* Put coordinates and direction cosines */
      
      PutPrivateData(lvl + LVL_PRIV_X, x, id);
      PutPrivateData(lvl + LVL_PRIV_Y, y, id);
      PutPrivateData(lvl + LVL_PRIV_Z, z, id);
      PutPrivateData(lvl + LVL_PRIV_U, u, id);
      PutPrivateData(lvl + LVL_PRIV_V, v, id);
      PutPrivateData(lvl + LVL_PRIV_W, w, id);

      /* Put coordinates to universe structure */

      ptr = RDB[uni + UNIVERSE_PTR_PRIVA_X];
      PutPrivateData(ptr, x, id);

      ptr = RDB[uni + UNIVERSE_PTR_PRIVA_Y];
      PutPrivateData(ptr, y, id);

      ptr = RDB[uni + UNIVERSE_PTR_PRIVA_Z];
      PutPrivateData(ptr, z, id);

      /* Reset last flag */
      
      PutPrivateData(lvl + LVL_PRIV_LAST, NO, id);
      
      /* Put level type */

      type = (long)RDB[uni + UNIVERSE_TYPE];
      PutPrivateData(lvl + LVL_PRIV_TYPE, type, id);
      
      /* Put universe pointer */

      PutPrivateData(lvl + LVL_PRIV_PTR_UNIV, uni, id);

      /* Put collision flag */

      StoreValuePair(uni + UNIVERSE_COL_COUNT, ncol, 1.0, id);

      /* Put gcu pointer */

      if ((long)RDB[DATA_OPTI_GC_CALC] == YES)
      	if ((ptr = (long)RDB[uni + UNIVERSE_PTR_GCU]) > VALID_PTR)
	  StoreValuePair(DATA_GCU_PTR_UNI, ncol, ptr, id);

      /* Put collision universe */

      ptr = (long)RDB[DATA_PTR_COLLISION_UNI];
      PutPrivateData(ptr, uni, id);      

      /* Avoid warning messages */
      
      cell = -1;

      /* Check universe type */
      
      switch (type)
	{
	case UNIVERSE_TYPE_NEST:
	  {
	    /*****************************************************************/
	    
	    /***** Nest universe *********************************************/

	    /* Pointer to nest */
	    
	    nst = (long)RDB[uni + UNIVERSE_PTR_NEST];
	    CheckPointer(FUNCTION_NAME, "(nst)", DATA_ARRAY, nst);

	    /* Find nest region */
	    
	    reg = FindNestRegion(uni, nst, x, y, z, id);
	    CheckPointer(FUNCTION_NAME, "(reg)", DATA_ARRAY, reg);

	    /* Get region index and update zone */

	    idx = (long)RDB[reg + NEST_REG_IDX];
	    zone = zone + ((long)RDB[lvl0 + LVL_ZONE_IDX_MULT])*idx;
	    PutPrivateData(lvl + LVL_PRIV_ZONE_IDX, zone, id);

	    /* Put region pointer */
	    
	    PutPrivateData(lvl + LVL_PRIV_PTR_NEST_REG, reg, id);
	    
	    /* Get cell pointer */
	    
	    cell = (long)RDB[reg + NEST_REG_PTR_CELL];
	    CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, cell);

	    /* Put cell pointer */
	    
	    PutPrivateData(lvl + LVL_PRIV_PTR_CELL, cell, id);
	    
	    /* Put collision flag */
	    
	    StoreValuePair(cell + CELL_COL_COUNT, ncol, 1.0, id);

	    /* Put collision region */

	    StoreValuePair(nst + NEST_PTR_COL_REG, ncol, reg, id);

	    /* Check fill pointer */
	    
	    if ((ptr = RDB[reg + NEST_REG_PTR_FILL]) > VALID_PTR)
	      {
		/* Filled region, update universe pointer */
		
		uni = ptr;
	      }
	    else
	      {
		/* Put zone index */

		ptr = (long)RDB[DATA_PTR_ZONE_IDX];
		PutPrivateData(ptr, zone, id);

		/* Get material pointer */
	    
		mat = (long)RDB[cell + CELL_PTR_MAT];
		mat = MatPtr(mat, id);
		
		/* Put private pointer */
		
		PutPrivateData(lvl + LVL_PRIV_PTR_MAT, mat, id);
	    
		/* Put last flag */
		
		PutPrivateData(lvl + LVL_PRIV_LAST, YES, id);
		
		/* Return cell pointer */
		
		return cell;
	      }
	    
	    /* Break case */
	    
	    break;
	    
	    /*****************************************************************/
	  }      
	  
	case UNIVERSE_TYPE_CELL:
	  {
	    /*****************************************************************/

	    /***** Cell universe *********************************************/
	    
	    /* Find cell */

	    if ((cell = FindUniverseCell(uni, x, y, z, &idx, id)) < VALID_PTR)
	      {
		/* Geometry error, put last flag */
		
		PutPrivateData(lvl + LVL_PRIV_LAST, YES, id);

		/* Check void and plotter modes */

		if ((long)RDB[DATA_IGNORE_VOID_CELLS] == YES)
		  return (long)RDB[DATA_PTR_VOID_CELL];
		else if ((long)RDB[DATA_PLOTTER_MODE] == YES)
		  return cell;
		else
		  TrackingError(TRACK_ERR_CELL_SEARCH, -1, -1, -1, id);
	      }

	    /* Check pointer */

	    CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, cell);

	    /* Update zone */

	    zone = zone + ((long)RDB[lvl0 + LVL_ZONE_IDX_MULT])*idx;
	    PutPrivateData(lvl + LVL_PRIV_ZONE_IDX, zone, id);

	    /* Put cell pointer */

	    PutPrivateData(lvl + LVL_PRIV_PTR_CELL, cell, id);

	    /* Put collision flag */

	    StoreValuePair(cell + CELL_COL_COUNT, ncol, 1.0, id);
	    
	    /* Check fill pointer and call recursively */
	    
	    if ((ptr = RDB[cell + CELL_PTR_FILL]) > VALID_PTR)
	      {
		/* Do coordinate transformation */
      
		if ((tra = (long)RDB[cell + CELL_PTR_TRANS]) > VALID_PTR)
		  CoordTrans(tra, &x, &y, &z, &u, &v, &w, id);

		/* Filled cell, update universe pointer */
		
		uni = ptr;
	      }
	    else
	      {
		/* Put zone index */

		ptr = (long)RDB[DATA_PTR_ZONE_IDX];
		PutPrivateData(ptr, zone, id);

		/* Get material pointer */
	    
		mat = (long)RDB[cell + CELL_PTR_MAT];
		mat = MatPtr(mat, id);
		
		/* Put private pointer */
		
		PutPrivateData(lvl + LVL_PRIV_PTR_MAT, mat, id);
	    
		/* Put last flag */
		
		PutPrivateData(lvl + LVL_PRIV_LAST, YES, id);

		/* Return cell pointer */
		
		return cell;
	      }

	    /* Break case */

	    break;

	    /*****************************************************************/
	  }      

	case UNIVERSE_TYPE_LATTICE:
	  {
	    /*****************************************************************/

	    /***** Lattice universe ******************************************/

	    /* Pointer to lattice */

	    lat = (long)RDB[uni + UNIVERSE_PTR_LAT];
	    CheckPointer(FUNCTION_NAME, "(lat)", DATA_ARRAY, lat);
	    
	    /* Put lattice pointer */
	    
	    PutPrivateData(lvl + LVL_PRIV_PTR_LAT, lat, id);
	    
	    /* Find lattice universe */
	    
	    if ((ptr = FindLatticeRegion(lat, lvl, &x, &y, &z, &idx, id)) 
		< VALID_PTR)
	      {
		/* Put last flag */
		
		PutPrivateData(lvl + LVL_PRIV_LAST, YES, id);

		/* Check plotter mode */
		
		if ((long)RDB[DATA_PLOTTER_MODE] == YES)
		  return GEOM_ERROR_NO_CELL;
		else
		  TrackingError(TRACK_ERR_LATTICE, -1, -1, -1, id);
	      }

	    /* Update zone */

	    zone = zone + ((long)RDB[lvl0 + LVL_ZONE_IDX_MULT])*idx;
	    PutPrivateData(lvl + LVL_PRIV_ZONE_IDX, zone, id);

	    /* Update universe pointer */
		
	    uni = ptr;

	    /* Break case */
	    
	    break;
	    
	    /*****************************************************************/
	  }
	  
	case UNIVERSE_TYPE_PBED:
	  {
	    /*****************************************************************/
	    
	    /***** Explicit stochastic geometry ******************************/

	    /* Pointer to geometry */
	    
	    pbd = (long)RDB[uni + UNIVERSE_PTR_PBED];
	    CheckPointer(FUNCTION_NAME, "(pbd)", DATA_ARRAY, pbd);
	    
	    /* Put level pointer */
	    
	    PutPrivateData(lvl + LVL_PRIV_PTR_PBED, pbd, id);
	    
	    /* Find universe */

	    ptr = FindPBRegion(uni, pbd, &x, &y, &z, &pbl, &idx, id);

	    /* Update zone (JLe: tää korjattiin 4.6.2013 / 2.1.15) */

	    zone = zone + ((long)RDB[lvl0 + LVL_ZONE_IDX_MULT])*idx;
	    PutPrivateData(lvl + LVL_PRIV_ZONE_IDX, zone, id);

	    /* Put direct pointer to pebble */
	    
	    PutPrivateData(lvl + LVL_PRIV_PTR_PEBBLE, pbl, id);

	    /* Update universe pointer */
		
	    uni = ptr;

	    /* Break case */

	    break;
	    
	    /*****************************************************************/
	  }
	case UNIVERSE_TYPE_UMSH:
	  {
	    /*****************************************************************/
	    
	    /***** Unstructured mesh based geometry **************************/

	    /* Pointer to geometry */
	    
	    umsh = (long)RDB[uni + UNIVERSE_PTR_UMSH];
	    CheckPointer(FUNCTION_NAME, "(umsh)", DATA_ARRAY, umsh);
	    
	    /* Put level pointer */
	    
	    PutPrivateData(lvl + LVL_PRIV_PTR_UMSH, umsh, id);
	    
	    /* Reset cell */

	    cell = -1;

	    /* Check if cell pointer was set by NearestBoundary() */

	    if ((cgns = TestValuePair(uni + UNIVERSE_PTR_NEXT_CELL, ncol, id))
		> VALID_PTR)
	      {
		/* For some reason this does not work with 100% certainty, */
		/* maybe because the neutron is actually moved forward by  */
		/* extrapolation distance, and may end up in a different   */
		/* cell. */

		/* Get pointer to interface */
		ptr = (long)RDB[umsh + UMSH_PTR_IFC];

		if (InTetCell(ptr, cgns, x, y, z, YES, id) == YES)
		  {
		    /* Get cell from tet */

		    cell = (long)RDB[cgns + IFC_TET_MSH_PTR_CELL];
		    CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, cell);

		  }

	      }

	    /* Check cell pointer */

	    if (cell < VALID_PTR)
	      {
		/* Get pointer to interface structure */

		ptr = (long)RDB[umsh + UMSH_PTR_IFC];
		CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);

		/* Find cell */

		if ((cell = FindTetCell(ptr, x, y, z, id)) > VALID_PTR)
		  {
		    /* Put collision flag */

		    StoreValuePair(ptr + IFC_PTR_PREV_COL_CELL, ncol, cell, 
				   id);

		    /* Store pointer to tet-cell */

		    cgns = cell;

		    /* Get pointer to geometry cell */

		    cell = (long)RDB[cell + IFC_TET_MSH_PTR_CELL];
		    CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, cell);
		  }
	      }

	    /* Check cell pointer */

	    if (cell < VALID_PTR)
	      {
		/* Get pointer to background universe */

		uni = (long)RDB[umsh + UMSH_PTR_BG_UNIV];
		CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni);

		/* Index (nää pitää kattoa vielä myöhemmin) */

		idx = 0;

		/* Update zone */

		zone = zone + ((long)RDB[lvl0 + LVL_ZONE_IDX_MULT])*idx;
		PutPrivateData(lvl + LVL_PRIV_ZONE_IDX, zone, id);
	      }
	    else
	      {
		/* Get index */

		idx = (long)RDB[cell + CELL_UMSH_IDX];

		/* Update zone */

		zone = zone + ((long)RDB[lvl0 + LVL_ZONE_IDX_MULT])*idx;
		PutPrivateData(lvl + LVL_PRIV_ZONE_IDX, zone, id);

		/* Put cell pointer */

		PutPrivateData(lvl + LVL_PRIV_PTR_CELL, cell, id);

		/* Put collision flag (tätä ei tarvita mihinkään?) */

		StoreValuePair(cell + CELL_COL_COUNT, ncol, 1.0, id);

		/* Check fill pointer */
	    
		if ((ptr = RDB[cell + CELL_PTR_FILL]) > VALID_PTR)
		  Die(FUNCTION_NAME, "Fill pointer is not null");
		
		/* Get material pointer */
		    
		mat = (long)RDB[cell + CELL_PTR_MAT];
		CheckPointer(FUNCTION_NAME, "(mat)", DATA_ARRAY, mat);

		mat = MatPtr(mat, id);
		CheckPointer(FUNCTION_NAME, "(mat2)", DATA_ARRAY, mat);

		/* Put private pointer */
		
		PutPrivateData(lvl + LVL_PRIV_PTR_MAT, mat, id);
		
		/* Put last flag */
		
		PutPrivateData(lvl + LVL_PRIV_LAST, YES, id);
		
		/* Save tet, where collision happened */
		
		ptr = (long)RDB[cell + CELL_PTR_PREV_TET];
		CheckPointer(FUNCTION_NAME, "(ptr/tet)", PRIVA_ARRAY, ptr);

		/* Store tet cell */

		PutPrivateData(ptr, cgns, id);

		/* Return cell pointer */
		
		return cell;
	       }
	    
	    /* Break case */

	    break;
	    
	    /*****************************************************************/
	  }
	case UNIVERSE_TYPE_STL:
	  {
	    /*****************************************************************/
	    
	    /***** STL based geometry ****************************************/
	    
	    /* Pointer to geometry */
	    
	    stl = (long)RDB[uni + UNIVERSE_PTR_STL];
	    CheckPointer(FUNCTION_NAME, "(stl)", DATA_ARRAY, stl);
	    
	    /* Put level pointer */
	    
	    PutPrivateData(lvl + LVL_PRIV_PTR_STL, stl, id);
	    
	    /* Find solid */

	    if ((ptr = FindSTLSolid(stl, x, y, z, u, v, w, YES, id)) > 
		VALID_PTR)
	      {
		/* Get pointer to cell */

		cell = (long)RDB[ptr + STL_SOLID_PTR_CELL];
		CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, cell);

		/* Get index */

		idx = (long)RDB[ptr + STL_SOLID_REG_IDX];

		/* Update zone */

		zone = zone + ((long)RDB[lvl0 + LVL_ZONE_IDX_MULT])*idx;
		PutPrivateData(lvl + LVL_PRIV_ZONE_IDX, zone, id);

		/* Put cell pointer */

		PutPrivateData(lvl + LVL_PRIV_PTR_CELL, cell, id);

		/* Put collision flag */

		StoreValuePair(cell + CELL_COL_COUNT, ncol, 1.0, id);

		/* Check fill pointer */
	    
		if ((ptr = RDB[cell + CELL_PTR_FILL]) > VALID_PTR)
		  Die(FUNCTION_NAME, "Fill pointer is not null (muuta tää)");
		
		/* Get material pointer */
		    
		mat = (long)RDB[cell + CELL_PTR_MAT];
		mat = MatPtr(mat, id);

		/* Put private pointer */
		
		PutPrivateData(lvl + LVL_PRIV_PTR_MAT, mat, id);
		
		/* Put last flag */
		
		PutPrivateData(lvl + LVL_PRIV_LAST, YES, id);
		
		/* Return cell pointer */
		
		return cell;
	      }
	    else if (ptr == GEOM_ERROR_MULTIPLE_CELLS)
	      {
		/* Check plotter mode */

		if ((long)RDB[DATA_PLOTTER_MODE] == YES)
		  return GEOM_ERROR_MULTIPLE_CELLS;
		else
		  Error(stl, "Overlapping solids at [%1.2E, %1.2E, %1.2E]",
			x, y, z);
	      }
	    else
	      {
		/* Get pointer to background universe */

		uni = (long)RDB[stl + STL_PTR_BG_UNIV];
		CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni);

		/* Index (nää pitää kattoa vielä myöhemmin) */

		idx = 0;

		/* Update zone */

		zone = zone + ((long)RDB[lvl0 + LVL_ZONE_IDX_MULT])*idx;
		PutPrivateData(lvl + LVL_PRIV_ZONE_IDX, zone, id);
	      }
	    
	    /* Break case */

	    break;
	    
	    /*****************************************************************/
	  }

	default:
	  {
	    /* Invalid type */
	    
	    Die(FUNCTION_NAME, "Invalid universe type");
	  }
	}

      /* Next level */

      lvl0 = NextItem(lvl0);
    }

  /* Error */

  Die(FUNCTION_NAME, "No material cell");

  /* Avoid warning message */

  return 0;
}
Esempio n. 13
0
void XSPlotter()
{
  double Emin, Emax, *E;
  long nuc, mat, rea, ne, n, i, ptr, rea1, ncol;
  char tmpstr[MAX_STR];
  FILE *fp;
  unsigned long seed;

  /* Check if plot is defined */

  if ((long)RDB[DATA_XSPLOT_NE] < 1)
    return;

  /* Check mpi task */

  if (mpiid > 0)
    return;

  /* Init random number sequence */
	      
  seed = ReInitRNG(0);
  SEED[0] = seed;
  
  /* Set filename */

  sprintf(tmpstr, "%s_xs%ld.m", GetText(DATA_PTR_INPUT_FNAME),
	  (long)RDB[DATA_BURN_STEP]);

  fprintf(out, "Creating XS plot file \"%s\"...\n", tmpstr);

  /* Open file for writing */

  if ((fp = fopen(tmpstr, "w")) == NULL)
    Die(FUNCTION_NAME, "Unable to open file for writing");
    
  /* Remember collision count */

  ptr = (long)RDB[DATA_PTR_COLLISION_COUNT];
  ncol = GetPrivateData(ptr, 0);
  
  /***************************************************************************/

  /***** Generate energy grid ************************************************/

  /* Boundaries and grid size */

  if (RDB[DATA_XSPLOT_EMIN] > 0.0)
    Emin = RDB[DATA_XSPLOT_EMIN];
  else
    Emin = RDB[DATA_NEUTRON_EMIN];

  if (RDB[DATA_XSPLOT_EMAX] > 0.0)
    Emax = RDB[DATA_XSPLOT_EMAX];
  else
    Emax = RDB[DATA_NEUTRON_EMAX];
  
  ne = (long)RDB[DATA_XSPLOT_NE];

  /* Generate array */

  E = MakeArray(Emin, Emax, ne, 2);

  /* Print array */

  fprintf(fp, "E = [\n");

  for (n = 0; n < ne; n++)
    fprintf(fp, "%1.5E\n", E[n]);

  fprintf(fp, "];\n\n");

  /***************************************************************************/

  /***** Print microscopic cross sections ************************************/

  /* Loop over nuclides */

  nuc = (long)RDB[DATA_PTR_NUC0];
  while(nuc > VALID_PTR)
    {
      /* Check type */

      if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_DOSIMETRY)
	{
	  /* Set name */
	  
	  sprintf(tmpstr, "i%s", GetText(nuc + NUCLIDE_PTR_NAME));
	  
	  if ((long)RDB[nuc + NUCLIDE_TYPE] != NUCLIDE_TYPE_DECAY)
	    tmpstr[strlen(tmpstr) - 4] = '_';
	  
	  /* Print reaction mt's */
	  
	  fprintf(fp, "%s_mt = [\n", tmpstr);
	  
	  /* Loop over reactions */

	  rea = (long)RDB[nuc + NUCLIDE_PTR_REA];
	  while (rea > VALID_PTR)
	    {
	      /* Print mt */
	      
	      fprintf(fp, "%4ld %% %s\n", (long)RDB[rea + REACTION_MT],
		      ReactionMT((long)RDB[rea + REACTION_MT])); 

	      /* Next */

	      rea = NextItem(rea);
	    }
	  
	  fprintf(fp, "];\n\n");
	
	  /* Print cross sections */
	  
	  fprintf(fp, "%s_xs = [\n", tmpstr);
	  
	  for (n = 0; n < ne; n++)
	    {
	      /* Loop over reactions */

	      rea = (long)RDB[nuc + NUCLIDE_PTR_REA];
	      while (rea > VALID_PTR)
		{
		  /* Get cross section */

		  if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_PHOTON)
		    fprintf(fp, "%1.5E ", PhotonMicroXS(rea,  E[n], 0));
		  else
		    fprintf(fp, "%1.5E ", MicroXS(rea, E[n], 0));	      

		  /* 0K data */

		  if ((rea1 = (long)RDB[rea + REACTION_PTR_0K_DATA]) 
		      > VALID_PTR)
		    fprintf(fp, "%1.5E ", MicroXS(rea1, E[n], 0));

		  /* Majorant */

		  if ((rea1 = (long)RDB[rea + REACTION_PTR_TMP_MAJORANT]) 
		      > VALID_PTR)
		    fprintf(fp, "%1.5E ", MicroXS(rea1, E[n], 0));

		  /* Next reaction */

		  rea = NextItem(rea);
		}
	      
	      fprintf(fp, "\n");
	    }

	  fprintf(fp, "];\n\n");
	}
      else if (((long)RDB[nuc + NUCLIDE_TYPE] != NUCLIDE_TYPE_DECAY) ||
	       ((long)RDB[nuc + NUCLIDE_TYPE_FLAGS] & 
		NUCLIDE_FLAG_TRANSMU_DATA))
	{
	  /* Set name */

	  sprintf(tmpstr, "i%s", GetText(nuc + NUCLIDE_PTR_NAME));
	  
	  if ((long)RDB[nuc + NUCLIDE_TYPE] != NUCLIDE_TYPE_DECAY)
	    tmpstr[strlen(tmpstr) - 4] = '_';
	    
	  /* Print reaction mt's */
	  
	  fprintf(fp, "%s_mt = [\n", tmpstr);
	  
	  if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_PHOTON)
	    fprintf(fp, "%4ld %% Total\n", (long)501);
	  else 
	    {
	      fprintf(fp, "%4ld %% Total\n", (long)1);
	      if ((long)RDB[nuc + NUCLIDE_PTR_SUM_ABSXS] > VALID_PTR)
		fprintf(fp, "%4ld %% Sum of absorption\n", (long)101);
	    }

	  if ((long)RDB[nuc + NUCLIDE_PTR_HEATPRODXS] > VALID_PTR)
	    fprintf(fp, "%4ld %% Heat production\n", (long)301);

	  if ((long)RDB[nuc + NUCLIDE_PTR_PHOTPRODXS] > VALID_PTR)
	    fprintf(fp, "%4ld %% Photon production\n", (long)202);

	  /* Pointer total xs */
	  
	  rea = (long)RDB[nuc + NUCLIDE_PTR_TOTXS];
	  CheckPointer(FUNCTION_NAME, "(rea)", DATA_ARRAY, rea);

	  if ((long)RDB[rea + REACTION_PTR_0K_DATA] > VALID_PTR)
	    fprintf(fp, "%4ld %% %s (0K)\n", 
		    (long)RDB[rea + REACTION_MT],
		    ReactionMT((long)RDB[rea + REACTION_MT])); 
	  
	  if ((long)RDB[rea + REACTION_PTR_TMP_MAJORANT] > VALID_PTR)
	    fprintf(fp, "%4ld %% %s (temperature Majorant)\n", 
		    (long)RDB[rea + REACTION_MT],
		    ReactionMT((long)RDB[rea + REACTION_MT])); 
	  
	  /* Pointer to partial list */
	  
	  ptr = (long)RDB[rea + REACTION_PTR_PARTIAL_LIST];
	  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
	  
	  /* Loop over partials */
	  
	  i = 0;
	  while ((rea = ListPtr(ptr, i++)) > VALID_PTR)
	    {
	      /* Pointer to reaction data */
	      
	      rea = (long)RDB[rea + RLS_DATA_PTR_REA];
	      CheckPointer(FUNCTION_NAME, "(rea)", DATA_ARRAY, rea);
	      
	      /* Print mt */
	      
	      fprintf(fp, "%4ld %% %s\n", (long)RDB[rea + REACTION_MT],
		      ReactionMT((long)RDB[rea + REACTION_MT])); 

	      if ((long)RDB[rea + REACTION_PTR_0K_DATA] > VALID_PTR)
		fprintf(fp, "%4ld %% %s (0K)\n", 
			(long)RDB[rea + REACTION_MT],
			ReactionMT((long)RDB[rea + REACTION_MT])); 

	      if ((long)RDB[rea + REACTION_PTR_TMP_MAJORANT] > VALID_PTR)
		fprintf(fp, "%4ld %% %s (temperature Majorant)\n", 
			(long)RDB[rea + REACTION_MT],
			ReactionMT((long)RDB[rea + REACTION_MT])); 
	    }
	  
	  fprintf(fp, "];\n\n");
	
	  /* Print cross sections */
	  
	  fprintf(fp, "%s_xs = [\n", tmpstr);
	  
	  for (n = 0; n < ne; n++)
	    {
	      /* Pointer to total xs */

	      rea = (long)RDB[nuc + NUCLIDE_PTR_TOTXS];
	      CheckPointer(FUNCTION_NAME, "(rea)", DATA_ARRAY, rea);
	      
	      /* Get cross section */

	      if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_PHOTON)
		fprintf(fp, "%1.5E ", PhotonMicroXS(rea, E[n], 0));
	      else
		fprintf(fp, "%1.5E ", MicroXS(rea, E[n], 0));

	      /* Pointer to total absorption xs */

	      if ((rea1 = (long)RDB[nuc + NUCLIDE_PTR_SUM_ABSXS]) > VALID_PTR)
		fprintf(fp, "%1.5E ", MicroXS(rea1, E[n], 0));

	      /* Heat production */

	      if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_PHOTON)
		{
		  ptr = (long)RDB[nuc + NUCLIDE_PTR_PHOTON_HEATPRODXS];
		  fprintf(fp, "%1.5E ", PhotonMicroXS(ptr, E[n], 0));
		}
	      else if ((ptr = (long)RDB[nuc + NUCLIDE_PTR_HEATPRODXS]) > 
		       VALID_PTR)
		fprintf(fp, "%1.5E ", MicroXS(ptr, E[n], 0));

	      /* Photon production */

	      if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_TRANSPORT)
		if ((ptr = (long)RDB[nuc + NUCLIDE_PTR_PHOTPRODXS]) > VALID_PTR)
		  fprintf(fp, "%1.5E ", MicroXS(ptr, E[n], 0));

	      /* 0K data */

	      if ((rea1 = (long)RDB[rea + REACTION_PTR_0K_DATA]) 
		  > VALID_PTR)
		fprintf(fp, "%1.5E ", MicroXS(rea1, E[n], 0));
	      
	      /* Majorant */
	      
	      if ((rea1 = (long)RDB[rea + REACTION_PTR_TMP_MAJORANT]) 
		  > VALID_PTR)
		fprintf(fp, "%1.5E ", MicroXS(rea1, E[n], 0));

	      /* Pointer to partial list */
	      
	      ptr = (long)RDB[rea + REACTION_PTR_PARTIAL_LIST];
	      CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
	      
	      /* Loop over partials */

	      i = 0;
	      while ((rea = ListPtr(ptr, i++)) > VALID_PTR)
		{
		  /* Pointer to reaction data */
		  
		  rea = (long)RDB[rea + RLS_DATA_PTR_REA];
		  CheckPointer(FUNCTION_NAME, "(rea)", DATA_ARRAY, rea);
		  
		  /* Get cross section */

		  if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_PHOTON)
		    fprintf(fp, "%1.5E ", PhotonMicroXS(rea,  E[n], 0));
		  else
		    fprintf(fp, "%1.5E ", MicroXS(rea, E[n], 0));	      

		  /* 0K data */

		  if ((rea1 = (long)RDB[rea + REACTION_PTR_0K_DATA]) 
		      > VALID_PTR)
		    fprintf(fp, "%1.5E ", MicroXS(rea1, E[n], 0));

		  /* Majorant */

		  if ((rea1 = (long)RDB[rea + REACTION_PTR_TMP_MAJORANT]) 
		      > VALID_PTR)
		    fprintf(fp, "%1.5E ", MicroXS(rea1, E[n], 0));
		}
	      
	      fprintf(fp, "\n");
	    }

	  fprintf(fp, "];\n\n");

	  /* Print multi-group cross sections */

	  if ((long)RDB[DATA_OPTI_MG_MODE] == YES)
	    {	  
	      fprintf(fp, "%s_mg_xs = [\n", tmpstr);
	      
	      for (n = 0; n < ne; n++)
		{	  
		  /* Pointer total xs */
		  
		  rea = (long)RDB[nuc + NUCLIDE_PTR_TOTXS];
		  CheckPointer(FUNCTION_NAME, "(rea)", DATA_ARRAY, rea);
		  
		  /* Get cross section */
		  
		  fprintf(fp, "%1.5E ", MGXS(rea, E[n], -1, 0));
		  
		  fprintf(fp, "\n");
		}
	      
	      fprintf(fp, "];\n\n");
	    }
	}

      /* Next nuclide */

      nuc = NextItem(nuc);
    }

  /***************************************************************************/

  /***** Print photon yields *************************************************/

  if ((long)RDB[DATA_PHOTON_PRODUCTION] == YES)
    {
      /* Loop over nuclides */

      nuc = (long)RDB[DATA_PTR_NUC0];
      while(nuc > VALID_PTR)
	{
	  /* Check if reactions exist */

	  if ((long)RDB[nuc + NUCLIDE_PTR_PHOTON_PROD] < VALID_PTR)
	    {
	      /* Next nuclide */

	      nuc = NextItem(nuc);
	      
	      /* Cycle loop */

	      continue;
	    }

	  /* Print mt's */
	  
	  sprintf(tmpstr, "i%s", GetText(nuc + NUCLIDE_PTR_NAME));
	  tmpstr[strlen(tmpstr) - 4] = '_';
	  fprintf(fp, "%s_pprod_mt = [\n", tmpstr);

	  /* Loop over reactions */

	  ptr = (long)RDB[nuc + NUCLIDE_PTR_PHOTON_PROD];
	  while (ptr > VALID_PTR)
	    {
	      fprintf(fp, "%ld\n", (long)RDB[ptr + PHOTON_PROD_MT]);
	      ptr = NextItem(ptr);
	    }

	  fprintf(fp, "];\n\n");

	  /* Print cross sections */
	  
	  sprintf(tmpstr, "i%s", GetText(nuc + NUCLIDE_PTR_NAME));
	  tmpstr[strlen(tmpstr) - 4] = '_';
	  fprintf(fp, "%s_pprod_xs = [\n", tmpstr);

	  for (n = 0; n < ne; n++)
	    {
	      /* Loop over reactions */
	      
	      ptr = (long)RDB[nuc + NUCLIDE_PTR_PHOTON_PROD];
	      while (ptr > VALID_PTR)
		{
		  rea1 = (long)RDB[ptr + PHOTON_PROD_PTR_PRODXS];
		  CheckPointer(FUNCTION_NAME, "(rea1)", DATA_ARRAY, rea1);

		  fprintf(fp, "%1.5E ", MicroXS(rea1, E[n], 0));
		  ptr = NextItem(ptr);
		}
	      fprintf(fp, "\n");
	    }

	  fprintf(fp, "];\n\n");

	  /* Next */

	  nuc = NextItem(nuc);
	}
    }

  /***************************************************************************/

  /***** Print photon line spectra *******************************************/

  /* Loop over nuclides */

  nuc = (long)RDB[DATA_PTR_NUC0];
  while(nuc > VALID_PTR)
    {
      /* Check if line spectra exists */

      if ((ptr = (long)RDB[nuc + NUCLIDE_PTR_PHOTON_LINE_SPEC]) > VALID_PTR)
	{
	  /* Set name */
	  
	  sprintf(tmpstr, "i%s", GetText(nuc + NUCLIDE_PTR_NAME));

	  if ((long)RDB[nuc + NUCLIDE_TYPE] != NUCLIDE_TYPE_DECAY)
	    tmpstr[strlen(tmpstr) - 4] = '_';

	  /* Print spectra */
	  
	  fprintf(fp, "%s_pspec = [\n", tmpstr);
	  
	  while (ptr > VALID_PTR)
	    {
	      fprintf(fp, "%1.5E %1.5E\n", RDB[ptr + PHOTON_LINE_SPEC_E],
		      RDB[ptr + PHOTON_LINE_SPEC_RI]);

	      /* Next line */

	      ptr = NextItem(ptr);
	    }
	      
	  fprintf(fp, "];\n\n");
	}

      /* Next nuclide */

      nuc = NextItem(nuc);
    }

  /***************************************************************************/

  /***** Print nubar data ****************************************************/

  /* Loop over nuclides */

  nuc = (long)RDB[DATA_PTR_NUC0];
  while(nuc > VALID_PTR)
    {
      /* Pointer to fission channel */

      if ((rea = (long)RDB[nuc + NUCLIDE_PTR_FISSXS]) > VALID_PTR)
	{
	  /* Set name */
	  
	  sprintf(tmpstr, "i%s", GetText(nuc + NUCLIDE_PTR_NAME));

	  if ((long)RDB[nuc + NUCLIDE_TYPE] != NUCLIDE_TYPE_DECAY)
	    tmpstr[strlen(tmpstr) - 4] = '_';

	  /* Print nubars */
	  
	  fprintf(fp, "%s_nu = [\n", tmpstr);
	  
	  for (n = 0; n < ne; n++)
	    {	  
	      /* Prompt nubar data */
	      
	      if ((ptr = (long)RDB[rea + REACTION_PTR_TNUBAR])> VALID_PTR)
		fprintf(fp, "%1.5f ", Nubar(ptr, E[n], 0));	      
	      
	      /* Delayed nubar data */
	      
	      if ((ptr = (long)RDB[rea + REACTION_PTR_DNUBAR])> VALID_PTR)
		fprintf(fp, "%1.5f ", Nubar(ptr, E[n], 0));	      

	      fprintf(fp, "\n");
	    }
	      
	  fprintf(fp, "];\n\n");
	}

      /* Next nuclide */

      nuc = NextItem(nuc);
    }

  /***************************************************************************/

  /***** Print energy-dependent isomeric branching ratios ********************/

  /* Tää tehtiinkin eri tavalla */

#ifdef mmmmmmmmmmmmmmmmmmmmmm

  /* Loop over nuclides */

  nuc = (long)RDB[DATA_PTR_NUC0];
  while (nuc > VALID_PTR)
    {
      /* Check pointer to branching data */

      if ((long)RDB[nuc + NUCLIDE_BRA_TYPE] != BRA_TYPE_ENE)
	{
	  /* Next nuclide */

	  nuc = NextItem(nuc);

	  /* Cycle loop */

	  continue;
	}

      /* Set name */

      sprintf(tmpstr, "i%s", GetText(nuc + NUCLIDE_PTR_NAME));
      tmpstr[strlen(tmpstr) - 4] = '_';

      /* Print data */
	  
      fprintf(fp, "%s_bra = [\n", tmpstr);
      
      for (n = 0; n < ne; n++)
	{
	  /* Loop over reactions */

	  rea = (long)RDB[nuc + NUCLIDE_PTR_REA];
	  while (rea > VALID_PTR)
	    {
	      /* Check pointer to branching data */

	      if ((long)RDB[rea + REACTION_RFS] > 0)
		fprintf(fp, "%1.5E ", MicroXS(rea, E[n], 0));		

	      /* Next reaction */

	      rea = NextItem(rea);
	    }

	  fprintf(fp, "\n");

	}

      fprintf(fp, "];\n\n");
	      
      /* Next nuclide */

      nuc = NextItem(nuc);
    }

#endif

  /***************************************************************************/

  /***** Print macroscopic cross sections ************************************/

  /* Loop over materials */

  mat = (long)RDB[DATA_PTR_M0];
  while(mat > VALID_PTR)
    {
      /* Set name */
	  
      sprintf(tmpstr, "m%s", GetText(mat + MATERIAL_PTR_NAME));
	  
      /* Print reaction mt's */
	  
      fprintf(fp, "%s_mt = [\n", tmpstr);

      if ((rea = (long)RDB[mat + MATERIAL_PTR_TOTXS]) > VALID_PTR)
	fprintf(fp, "%4ld\n", (long)RDB[rea + REACTION_MT]);
      if ((rea = (long)RDB[mat + MATERIAL_PTR_ELAXS]) > VALID_PTR)
	fprintf(fp, "%4ld\n", (long)RDB[rea + REACTION_MT]);
      if ((rea = (long)RDB[mat + MATERIAL_PTR_ABSXS]) > VALID_PTR)
	fprintf(fp, "%4ld\n", (long)RDB[rea + REACTION_MT]);
      if ((rea = (long)RDB[mat + MATERIAL_PTR_FISSXS]) > VALID_PTR)
	fprintf(fp, "%4ld\n", (long)RDB[rea + REACTION_MT]);
      if ((rea = (long)RDB[mat + MATERIAL_PTR_HEATTXS]) > VALID_PTR)
	fprintf(fp, "%4ld\n", (long)RDB[rea + REACTION_MT]);
      if ((rea = (long)RDB[mat + MATERIAL_PTR_PHOTPXS]) > VALID_PTR)
	fprintf(fp, "%4ld\n", (long)RDB[rea + REACTION_MT]);
      if ((rea = (long)RDB[mat + MATERIAL_PTR_NSF]) > VALID_PTR)
	fprintf(fp, "%4ld\n", (long)RDB[rea + REACTION_MT]);
      if ((rea = (long)RDB[mat + MATERIAL_PTR_INLPXS]) > VALID_PTR)
	fprintf(fp, "%4ld\n", (long)RDB[rea + REACTION_MT]);
      if ((rea = (long)RDB[mat + MATERIAL_PTR_TOTPHOTXS]) > VALID_PTR)
	fprintf(fp, "%4ld\n", (long)RDB[rea + REACTION_MT]);
      if ((rea = (long)RDB[mat + MATERIAL_PTR_HEATPHOTXS]) > VALID_PTR)
	fprintf(fp, "%4ld\n", (long)RDB[rea + REACTION_MT]);
      if ((rea = (long)RDB[mat + MATERIAL_PTR_TMP_MAJORANTXS]) > VALID_PTR)
	fprintf(fp, "%4ld\n", (long)RDB[rea + REACTION_MT]);
	  
      fprintf(fp, "];\n\n");
      
      /* Print cross sections */
	  
      fprintf(fp, "%s_xs = [\n", tmpstr);

      for (n = 0; n < ne; n++)
	{	
	  /* Add to counter */

	  ptr = (long)RDB[DATA_PTR_COLLISION_COUNT];
	  AddPrivateData(ptr, 1.0, 0);
	  
	  if ((rea = (long)RDB[mat + MATERIAL_PTR_TOTXS]) > VALID_PTR)
	    fprintf(fp, "%1.5E ", MacroXS(rea, E[n],0));
	  if ((rea = (long)RDB[mat + MATERIAL_PTR_ELAXS]) > VALID_PTR)
	    fprintf(fp, "%1.5E ", MacroXS(rea, E[n],0));
	  if ((rea = (long)RDB[mat + MATERIAL_PTR_ABSXS]) > VALID_PTR)
	    fprintf(fp, "%1.5E ", MacroXS(rea, E[n],0));
	  if ((rea = (long)RDB[mat + MATERIAL_PTR_FISSXS]) > VALID_PTR)
	    fprintf(fp, "%1.5E ", MacroXS(rea, E[n],0));
	  if ((rea = (long)RDB[mat + MATERIAL_PTR_HEATTXS]) > VALID_PTR)
	    fprintf(fp, "%1.5E ", MacroXS(rea, E[n],0));
	  if ((rea = (long)RDB[mat + MATERIAL_PTR_PHOTPXS]) > VALID_PTR)
	    fprintf(fp, "%1.5E ", MacroXS(rea, E[n],0));
	  if ((rea = (long)RDB[mat + MATERIAL_PTR_NSF]) > VALID_PTR)
	    fprintf(fp, "%1.5E ", MacroXS(rea, E[n],0));
	  if ((rea = (long)RDB[mat + MATERIAL_PTR_INLPXS]) > VALID_PTR)
	    fprintf(fp, "%1.5E ", MacroXS(rea, E[n],0));
	  if ((rea = (long)RDB[mat + MATERIAL_PTR_TOTPHOTXS]) > VALID_PTR)
	    fprintf(fp, "%1.5E ", PhotonMacroXS(rea, E[n], 0));
	  if ((rea = (long)RDB[mat + MATERIAL_PTR_HEATPHOTXS]) > VALID_PTR)
	    fprintf(fp, "%1.5E ", PhotonMacroXS(rea, E[n], 0));
	  if ((rea = (long)RDB[mat + MATERIAL_PTR_TMP_MAJORANTXS]) > VALID_PTR)
	    fprintf(fp, "%1.5E ", MacroXS(rea, E[n],0));

	  fprintf(fp, "\n");
	}

      fprintf(fp, "];\n\n");
      
      /* Next material */
      
      mat = NextItem(mat);
    }

  /***************************************************************************/

  /***** Print multi-group macroscopic xs ************************************/

  /* Check mode */

  if ((long)RDB[DATA_OPTI_MG_MODE] == YES)
    {
      /* Loop over materials */

      mat = (long)RDB[DATA_PTR_M0];
      while(mat > VALID_PTR)
	{
	  /* Set name */
	  
	  sprintf(tmpstr, "m%s", GetText(mat + MATERIAL_PTR_NAME));
	  
	  /* Print cross sections */
	  
	  fprintf(fp, "%s_mg_xs = [\n", tmpstr);
	  
	  for (n = 0; n < ne; n++)
	    {	
	      if ((rea = (long)RDB[mat + MATERIAL_PTR_TOTXS]) > VALID_PTR)
		{
		  if ((ptr = (long)RDB[rea + REACTION_PTR_MGXS]) > VALID_PTR)
		    fprintf(fp, "%1.5E ", MGXS(rea, E[n], -1, 0));
		}
	      if ((rea = (long)RDB[mat + MATERIAL_PTR_ELAXS]) > VALID_PTR)
		{
		  if ((ptr = (long)RDB[rea + REACTION_PTR_MGXS]) > VALID_PTR)
		    fprintf(fp, "%1.5E ", MGXS(rea, E[n], -1, 0));
		}
	      if ((rea = (long)RDB[mat + MATERIAL_PTR_ABSXS]) > VALID_PTR)
		{
		  if ((ptr = (long)RDB[rea + REACTION_PTR_MGXS]) > VALID_PTR)
		    fprintf(fp, "%1.5E ", MGXS(rea, E[n], -1, 0));
		}
	      if ((rea = (long)RDB[mat + MATERIAL_PTR_FISSXS]) > VALID_PTR)
		{
		  if ((ptr = (long)RDB[rea + REACTION_PTR_MGXS]) > VALID_PTR)
		    fprintf(fp, "%1.5E ", MGXS(rea, E[n], -1, 0));
		}
	      if ((rea = (long)RDB[mat + MATERIAL_PTR_INLPXS]) > VALID_PTR)
		{
		  if ((ptr = (long)RDB[rea + REACTION_PTR_MGXS]) > VALID_PTR)
		    fprintf(fp, "%1.5E ", MGXS(rea, E[n], -1, 0));
		}	      
	      
	      fprintf(fp, "\n");
	    }
	  
	  fprintf(fp, "];\n\n");
	  
	  /* Next material */
	  
	  mat = NextItem(mat);
	}
    }

  /***************************************************************************/

  /***** Print majorant ******************************************************/

  /* TODO: muuta tohon ne simulation moodit instead */

  if ((rea = (long)RDB[DATA_PTR_MAJORANT]) > VALID_PTR)
    {
      fprintf(fp, "majorant_xs = [\n");

      for (n = 0; n < ne; n++)
	fprintf(fp, "%1.5E\n", DTMajorant(PARTICLE_TYPE_NEUTRON, E[n],0));
	
      fprintf(fp, "];\n\n");
    }

  if ((rea = (long)RDB[DATA_PTR_PHOTON_MAJORANT]) > VALID_PTR)
    {
      fprintf(fp, "photon_majorant_xs = [\n");

      for (n = 0; n < ne; n++)
	fprintf(fp, "%1.5E\n", DTMajorant(PARTICLE_TYPE_GAMMA, E[n],0));
	
      fprintf(fp, "];\n\n");
    }

  /***************************************************************************/

  /* Free memory */

  Mem(MEM_FREE, E);

  /* Close file */

  fclose(fp);

  /* Restore collision count */

  ptr = (long)RDB[DATA_PTR_COLLISION_COUNT];
  PutPrivateData(ptr, ncol, 0);

  /* Exit */
  
  fprintf(out, "OK.\n\n");
}
Esempio n. 14
0
long FindPBRegion(long uni0, long pbd, double *x, double *y, double *z, 
		  long *pbl0, long *ridx, long id)
{
  long ptr, lst, pbl, uni, ncol, msh;
  double rp, dx, dy, dz;

  /* Check pointers */

  CheckPointer(FUNCTION_NAME, "(uni0)", DATA_ARRAY, uni0);
  CheckPointer(FUNCTION_NAME, "(pbd)", DATA_ARRAY, pbd);

  /* Check plotter mode */

  if (((long)RDB[DATA_PLOTTER_MODE] == NO) || 
      ((long)RDB[DATA_QUICK_PLOT_MODE] == YES))
    {
      /* Check previous */

      ptr = RDB[uni0 + UNIVERSE_PTR_PREV_REG];
      if ((pbl = GetPrivateData(ptr, id)) > VALID_PTR)
	{
	  /* Get parameters */
	  
	  dx = *x - RDB[pbl + PEBBLE_X0];
	  dy = *y - RDB[pbl + PEBBLE_Y0];
	  dz = *z - RDB[pbl + PEBBLE_Z0];
	  
	  rp = RDB[pbl + PEBBLE_RAD];
	  
	  /* Check if particle is inside */
	  
	  if (dx*dx + dy*dy + dz*dz < rp*rp)
	    {
	      /* Co-ordinate transformation */
	      
	      *x = dx;
	      *y = dy;
	      *z = dz;
	      
	      /* Get pointer to universe */
	      
	      uni = (long)RDB[pbl + PEBBLE_PTR_UNIV];
	      CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni);
	      
	      /* Put pebble pointer */
	      
	      *pbl0 = pbl;
	      
	      /* Get collision number */
	      
	      ptr = (long)RDB[DATA_PTR_COLLISION_COUNT];
	      CheckPointer(FUNCTION_NAME, "(ptr)", PRIVA_ARRAY, ptr);
	      
	      ncol = (long)GetPrivateData(ptr, id);
	      
	      /* Store index */
	      
	      StoreValuePair(pbd + PBED_PTR_COL_PEBBLE, ncol, (double)pbl, id);
	      
	      /* Put region index */
	      
	      *ridx = (long)RDB[pbl + PEBBLE_IDX] + 1;
	      
	      /* Return universe pointer */
	      
	      return uni;
	    }
	}
    }

  /* Reset pebble pointer */

  *pbl0 = -1;

  /* Pointer to search mesh */

  msh = (long)RDB[pbd + PBED_PTR_SEARCH_MESH];
  CheckPointer(FUNCTION_NAME, "(msh)", DATA_ARRAY, msh);

  /* Get pointer to search mesh */
  
  if ((lst = MeshPtr(msh, *x, *y, *z)) > VALID_PTR)
    lst = (long)RDB[lst];
  
  /* Loop over content */

  while (lst > VALID_PTR)
    {
      /* Pointer to pebble */
      
      pbl = (long)RDB[lst + SEARCH_MESH_CELL_CONTENT];
      CheckPointer(FUNCTION_NAME, "(pbl)", DATA_ARRAY, pbl);

      /* Get parameters */

      dx = *x - RDB[pbl + PEBBLE_X0];
      dy = *y - RDB[pbl + PEBBLE_Y0];
      dz = *z - RDB[pbl + PEBBLE_Z0];

      rp = RDB[pbl + PEBBLE_RAD];

      /* Check if particle is inside */

      if (dx*dx + dy*dy + dz*dz < rp*rp)
	{
	  /* Co-ordinate transformation */

	  *x = dx;
	  *y = dy;
	  *z = dz;

	  /* Get pointer to universe */

	  uni = (long)RDB[pbl + PEBBLE_PTR_UNIV];
	  CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni);

	  /* Put pebble pointer */

	  *pbl0 = pbl;

	  /* Get collision number */

	  ptr = (long)RDB[DATA_PTR_COLLISION_COUNT];
	  CheckPointer(FUNCTION_NAME, "(ptr)", PRIVA_ARRAY, ptr);

	  ncol = (long)GetPrivateData(ptr, id);

	  /* Store index */

	  StoreValuePair(pbd + PBED_PTR_COL_PEBBLE, ncol, (double)pbl, id);
	  
	  /* Put region index */

	  *ridx = (long)RDB[pbl + PEBBLE_IDX] + 1;

	  /* Check plotter mode */

	  if ((long)RDB[DATA_PLOTTER_MODE] == NO)
	    {
	      /* Pointer to counter */
	      
	      ptr = (long)RDB[lst + SEARCH_MESH_PTR_CELL_COUNT];
	      CheckPointer(FUNCTION_NAME, "(ptr)", PRIVA_ARRAY, ptr);
	      
	      /* Add counter */
	      
	      AddPrivateData(ptr, 1, id);
	    }

	  /* Put previous pointer */
	  
	  ptr = RDB[uni0 + UNIVERSE_PTR_PREV_REG];
	  PutPrivateData(ptr, pbl, id);

	  /* Return universe pointer */

	  return uni;
     	}
      
      /* Next */

      lst = NextItem(lst);
    }

  /* Get pointer to background universe */

  uni = (long)RDB[pbd + PBED_PTR_BG_UNIV];
  CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni);

  /* Put region index */

  *ridx = 0;

  /* Return pointer */
  
  return uni;
}
Esempio n. 15
0
double NearestBoundary(long id)
{
  long lvl0, lvl, reg, cell, pbd, pbl, surf, type, n, np, ptr, loc0, ltype;
  long surflist, ownrlist, nbrlist, facelist, sidelist, nf, side, k, j, pt;
  long nbhr, uni, ifc, ncol, tbi, ang, i, cgns, loc1,  nt;
  double min, d, x, y, z, u, v, w, y2, z2, params[MAX_SURFACE_PARAMS];
  double t, phi, phi2;

  /* Reset minimum distance */

  min = INFTY;

  /* Pointer to first level */

  lvl0 = (long)RDB[DATA_PTR_LVL0];
  CheckPointer(FUNCTION_NAME, "(lvl0)", DATA_ARRAY, lvl0);

  /* Loop over levels */

  while (lvl0 > VALID_PTR)
    {
      /* Pointer to private data */

      lvl = (long)RDB[lvl0 + LVL_PTR_PRIVATE_DATA];
      CheckPointer(FUNCTION_NAME, "(lvl)", PRIVA_ARRAY, lvl);
      
      /* Get coordinates */

      x = GetPrivateData(lvl + LVL_PRIV_X, id);
      y = GetPrivateData(lvl + LVL_PRIV_Y, id);
      z = GetPrivateData(lvl + LVL_PRIV_Z, id);

      /* Get direction cosines */

      u = GetPrivateData(lvl + LVL_PRIV_U, id);
      v = GetPrivateData(lvl + LVL_PRIV_V, id);
      w = GetPrivateData(lvl + LVL_PRIV_W, id);

      /* Check coordinates and direction cosines */

      CheckValue(FUNCTION_NAME, "x", "", x, -INFTY, INFTY);
      CheckValue(FUNCTION_NAME, "y", "", y, -INFTY, INFTY);
      CheckValue(FUNCTION_NAME, "z", "", z, -INFTY, INFTY);
      CheckValue(FUNCTION_NAME, "u", "", u, -1.0, 1.0);
      CheckValue(FUNCTION_NAME, "v", "", v, -1.0, 1.0);
      CheckValue(FUNCTION_NAME, "w", "", w, -1.0, 1.0);

      /* Pointer to universe */

      uni = (long)GetPrivateData(lvl + LVL_PRIV_PTR_UNIV, id);
      CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni);

      /* Get time */

      ptr = RDB[uni + UNIVERSE_PTR_PRIVA_T];
      CheckPointer(FUNCTION_NAME, "(ptr)", PRIVA_ARRAY, ptr);
      t = GetPrivateData(ptr, id);

      /* Check for symmetry */

      if ((ptr = (long)RDB[uni + UNIVERSE_PTR_SYM]) > VALID_PTR)
	if ((d = SymmetryBoundary(ptr, x, y, z, u, v, w)) < min)
	  min = d;

      /* Get level type */

      ltype = (long)GetPrivateData(lvl + LVL_PRIV_TYPE, id);
      
      /* Check type */

      switch (ltype)
	{
	case UNIVERSE_TYPE_NEST:
	  {
	    /*****************************************************************/

	    /***** Nest ******************************************************/

	    /* Check for fuel performance interface */
	    
	    if ((loc0 = (long)RDB[uni + UNIVERSE_PTR_IFC_FUEP]) > VALID_PTR)
	      {		
		/* First check nest boundaries */
		/* Check nest region surfaces */

		/* Pointer to nest region */
			
		reg = (long)GetPrivateData(lvl + LVL_PRIV_PTR_NEST_REG, id);
		CheckPointer(FUNCTION_NAME, "(reg)", DATA_ARRAY, reg);
		
		/* First surface */
		
		if ((surf = (long)RDB[reg + NEST_REG_PTR_SURF_IN]) > VALID_PTR)
		  {
		    /* Get type */
		    
		    type = (long)RDB[surf + SURFACE_TYPE];
		    
		    /* Die on non-cylindrical */
		    
		    if(type != SURF_CYL)
		      Die(FUNCTION_NAME,"Non-cylindrical surface");
		    
		    /* Get number of parameters */
		    
		    np = (long)RDB[surf + SURFACE_N_PARAMS];
		    
		    /* Pointer to parameter list */
		    
		    ptr = (long)RDB[surf + SURFACE_PTR_PARAMS];
		    CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);

		    /* Copy surface parameters */

		    memcpy(&params,&RDB[ptr],np*sizeof(double));

		    y2 = 0.0;
		    z2 = z;

		    /* Cold to hot expansion of cylinder radius */
		    /* (params[2]) */

		    CoordExpans(loc0,&params[2],&y2,&z2,t,2);

		    /* Get distance */
		
		    d = SurfaceDistance(-1, params, type, np, x, y, z, 
					u, v, w, id);
		    CheckValue(FUNCTION_NAME, "d", "1", d, 0.0, INFTY);

		    /* Compare to minimum */
		    
		    if (d < min)
		      min = d;	      
		  }
		
		/* Second surface */
		
		if ((surf = (long)RDB[reg + NEST_REG_PTR_SURF_OUT]) > 
		    VALID_PTR)
		  {
		    /* Get type */
		    
		    type = (long)RDB[surf + SURFACE_TYPE];
		    
		    /* Die on non-cylindrical */
		    
		    if(type != SURF_CYL)
		      Die(FUNCTION_NAME,"Non-cylindrical surface");
		    
		    /* Get number of parameters */
		    
		    np = (long)RDB[surf + SURFACE_N_PARAMS];
		    
		    /* Pointer to parameter list */
		    
		    ptr = (long)RDB[surf + SURFACE_PTR_PARAMS];
		    CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
		    
		    /* Copy surface parameters */
		    
		    memcpy(&params,&RDB[ptr],np*sizeof(double));
		    
		    y2 = 0.0;
		    z2 = z;
		    
		    /* Cold to hot expansion of cylinder radius */
		    /* (params[2]) */
		    
		    CoordExpans(loc0,&params[2],&y2,&z2,t,2);
		    
		    /* Get distance */
		    
		    d = SurfaceDistance(-1, params, type, np, x, y, z,
					u, v, w, id);
		    CheckValue(FUNCTION_NAME, "d", "2", d, 0.0, INFTY);

		    /* Compare to minimum */
		    
		    if (d < min)
		      min = d;	      
		  }		  		    		  	       
		
		/* Check the interface input boundaries, */

		/* Find time interval */

		tbi = (long)RDB[loc0 + IFC_FUEP_PTR_T];

		/* Get pointer to limits */

		ptr = (long)RDB[loc0 + IFC_FUEP_LIM_PTR_T];
		CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);

		/* Get number of time bins */

		nt = (long)RDB[loc0 + IFC_FUEP_N_T];

		/* Find bin*/

		i = SearchArray(&RDB[ptr], t, nt + 1);

		/* Check if found */

		if (i < 0)
		  break;

		/* Get direct pointer to time bin */

		tbi = ListPtr(tbi, i);

		/* Find axial zone */

		loc1 = (long)RDB[tbi + IFC_FUEP_T_PTR_AX];
		while (loc1 > VALID_PTR)
		  {
		    /* Compare coordinates */
		    
		    if ((z >= RDB[loc1 + IFC_FUEP_AX_ZMIN]) &&
			(z < RDB[loc1 + IFC_FUEP_AX_ZMAX]))
		      {
			
			/* Break loop */
			
			break;
		      }
		    
		    /* Next */
		    
		    loc1 = NextItem(loc1);
		  }
		
		/* Break case if not found*/

		if (loc1 < VALID_PTR)
		  break;

		/* Only check axial boundaries in 3D calculation */
		
		if ((long)RDB[DATA_GEOM_DIM] == 3)
		  {
		    /* Distance to lower boundary */
		    
		    params[0] = RDB[loc1 + IFC_FUEP_AX_ZMIN];
		    d = SurfaceDistance(-1, params, SURF_PZ, 1, x, y, z, 
					u, v, w, id);
		    CheckValue(FUNCTION_NAME, "d", "3", d, 0.0, INFTY);		

		    /* Compare to minimum */
		
		    if (d < min)
		      min = d;
		
		    /* Distance to upper boundary */
		
		    params[0] = RDB[loc1 + IFC_FUEP_AX_ZMAX];
		    d = SurfaceDistance(-1, params, SURF_PZ, 1, x, y, z, 
					u, v, w, id);
		    CheckValue(FUNCTION_NAME, "d", "4", d, 0.0, INFTY);

		    /* Compare to minimum */
		
		    if (d < min)
		      min = d;
		  }		

		/* Get the correct angular segment */
		
		ang = (long)RDB[loc1 + IFC_FUEP_AX_PTR_ANG];
		
		/* Get polar angle */
		
		phi = PolarAngle(x,y);
		
		while (ang > VALID_PTR)
		  {
		    /* Rotate if needed */
		  
		    if(phi > 2.0*PI+RDB[ang + IFC_FUEP_ANG_AMIN])
		      phi2 = phi - 2.0*PI;
		    else
		      phi2 = phi;
		    
		    /* Compare coordinates */
		    
		    if ((phi2 >= RDB[ang + IFC_FUEP_ANG_AMIN]) &&
			(phi2 < RDB[ang + IFC_FUEP_ANG_AMAX]))
		      break;
		    
		    /* Next */
		    
		    ang = NextItem(ang);
		  }
		
		/* Break case if not found */
		
		if (ang < VALID_PTR)
		  break;
	      
		/* Calculate distance to angular zone boundaries            */
		/* Tää ei huomioi että rajoittava taso on vain puoliääretön */
		/* (Tulee ylimääräisiä pysäytyksiä, jos kulmasegmenttejä    */
		/*  on pariton määrä)                                       */

		params[0] = RDB[ang + IFC_FUEP_ANG_CMIN];
		params[1] = 1.0;
		params[2] = 0.0;
		params[3] = 0.0;

		d = SurfaceDistance(-1, params, SURF_PLANE, 4, x, y, z, 
				    u, v, w, id);
		CheckValue(FUNCTION_NAME, "d", "5", d, 0.0, INFTY);

		/* Compare to minimum */
		
		if (d < min)
		  min = d;

		params[0] = RDB[ang + IFC_FUEP_ANG_CMAX];
		
		d = SurfaceDistance(-1, params, SURF_PLANE, 4, x, y, z, 
				    u, v, w, id);
		CheckValue(FUNCTION_NAME, "d", "6", d, 0.0, INFTY);

		/* Compare to minimum */
		
		if (d < min)
		  min = d;
		
	      }
	    else
	      {
		/* Pointer to nest region */

		reg = (long)GetPrivateData(lvl + LVL_PRIV_PTR_NEST_REG, id);
		CheckPointer(FUNCTION_NAME, "(reg)", DATA_ARRAY, reg);
		
		/* First surface */
		
		if ((surf = (long)RDB[reg + NEST_REG_PTR_SURF_IN]) > VALID_PTR)
		  {
		    /* Get type */
		    
		    type = (long)RDB[surf + SURFACE_TYPE];
		    
		    /* Get number of parameters */
		    
		    np = (long)RDB[surf + SURFACE_N_PARAMS];
		    
		    /* Pointer to parameter list */
		    
		    ptr = (long)RDB[surf + SURFACE_PTR_PARAMS];
		    CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);

		    /* Get distance */
		
		    d = SurfaceDistance(-1, &RDB[ptr], type, np, x, y, z, 
					u, v, w, id);
		    CheckValue(FUNCTION_NAME, "d", "10", d, 0.0, INFTY);

		    /* Compare to minimum */
		    
		    if (d < min)
		      min = d;	      
		  }
		
		/* Second surface */
		
		if ((surf = (long)RDB[reg + NEST_REG_PTR_SURF_OUT]) > VALID_PTR)
		  {
		    /* Get type */
		    
		    type = (long)RDB[surf + SURFACE_TYPE];
		    
		    /* Get number of parameters */
		    
		    np = (long)RDB[surf + SURFACE_N_PARAMS];
		    
		    /* Pointer to parameter list */
		    
		    ptr = (long)RDB[surf + SURFACE_PTR_PARAMS];
		    CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
		    
		    /* Get distance */
		    
		    d = SurfaceDistance(-1, &RDB[ptr], type, np, x, y, z, 
					u, v, w, id);
		    CheckValue(FUNCTION_NAME, "d", "11", d, 0.0, INFTY);

		    /* Compare to minimum */
		    
		    if (d < min)
		      min = d;	      
		  }
	      }
	    
	    /* Break case */

	    break;
	    
	    /*****************************************************************/
	  }      

	case UNIVERSE_TYPE_LATTICE:
	  {
	    /*****************************************************************/

	    /***** Lattice ***************************************************/

	    /* Check pointer to lattice */

	    if ((long)GetPrivateData(lvl + LVL_PRIV_PTR_LAT, id) < VALID_PTR)
	      Die(FUNCTION_NAME, "No lattice pointer");

	    /* Get surface type */
	    
	    type = (long)GetPrivateData(lvl + LVL_PRIV_LAT_SURF_TYPE, id);

	    /* Get number of surface parameters */
	    
	    np = (long)GetPrivateData(lvl + LVL_PRIV_LAT_SURF_NP, id);
	    
	    /* Get parameters (noiden kerrointen pitää olla peräkkäin) */

	    for (n = 0; n < np; n++)
	      params[n] = GetPrivateData(lvl + LVL_PRIV_LAT_SURF_C0 + n, id);

	    /* Get distance */

	    d = SurfaceDistance(-1, params, type, np, x, y, z, u, v, w, id);
	    CheckValue(FUNCTION_NAME, "d", "12", d, 0.0, INFTY);

	    /* Compare to minimum */

	    if (d < min)
	      min = d;	      

	    /* Check if type is vertical stack */

	    if (type == SURF_PZ)
	      {
		/* Put parameter for second surface */

		params[0] = GetPrivateData(lvl + LVL_PRIV_LAT_SURF_C1, id);
		
		/* Get distance (ei tarkisteta, reunimmaiset pinnat voi */
		/* olla +/- INFTY) */

		d = SurfaceDistance(-1, params, type, np, x, y, z, u, v, w, id);

		/* Compare to minimum */
		
		if (d < min)
		  min = d;	      
	      }

	    /* Break case */

	    break;

	    /*****************************************************************/
	  }
	  
	case UNIVERSE_TYPE_CELL:
	  {
	    /*****************************************************************/

	    /***** Cell ******************************************************/
	
	    /* Pointer to cell */
	
	    cell = (long)GetPrivateData(lvl + LVL_PRIV_PTR_CELL, id);
	    CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, cell);

	    /* Pointer to surface list */

	    loc0 = (long)RDB[cell + CELL_PTR_SURF_LIST];
	    CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0);

	    /* Loop over list */

	    while ((surf = (long)RDB[loc0++]) > VALID_PTR)
	      {
		/* Get type */

		type = (long)RDB[surf + SURFACE_TYPE];
		
		/* Check infinite */

		if (type != SURF_INF)
		  {
		    /* Get number of parameters */
		
		    np = (long)RDB[surf + SURFACE_N_PARAMS];
		    
		    /* Pointer to parameter list */
		    
		    ptr = (long)RDB[surf + SURFACE_PTR_PARAMS];
		    CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
		    
		    /* Get distance */
		    
		    d = SurfaceDistance(surf, &RDB[ptr], type, np, x, y, z, 
					u, v, w, id);

		    if (d < 0.0)
		      printf("%s %ld: x = %1.14E; y = %1.14E; z = %1.14E; u = %1.14E; v = %1.14E; w = %1.14E;\n", GetText(surf + SURFACE_PTR_NAME),
			     type, x, y, z, u, v, w);

		    CheckValue(FUNCTION_NAME, "d", "14", d, 0.0, INFTY);

		    /* Compare to minimum */
		    
		    if (d < min)
		      min = d;
		  }	      
	      }

	    /* Break case */
	    
	    break;
	    
	    /*****************************************************************/
	  }      

	case UNIVERSE_TYPE_UMSH:
	  {
	    /*****************************************************************/

	    /***** Unstructured mesh based geometry **************************/

	    /* Pointer to cell */

	    if ((cell = (long)GetPrivateData(lvl + LVL_PRIV_PTR_CELL, id))
		> VALID_PTR)
	      {
		/* Get current tetra-cell (set in whereami.c) */

		ptr = (long)RDB[cell + CELL_PTR_PREV_TET];

		if ((cgns = (long)GetPrivateData(ptr, id)) < VALID_PTR)
		  Die(FUNCTION_NAME, "UMSH tet was not stored");

		/* Reset pointer to neighbour */

		nbhr = -1;

		/* Get pointer to UMSH structure */

		ptr = (long)RDB[uni + UNIVERSE_PTR_UMSH];
		CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);

		/* Get pointer to UMSH interface */

		ifc = (long)RDB[ptr + UMSH_PTR_IFC];
		CheckPointer(FUNCTION_NAME, "(ifc)", DATA_ARRAY, ifc);

		/* Get pointer to interface surface list */

		surflist = (long)RDB[ifc + IFC_PTR_SURF_LIST];
		CheckPointer(FUNCTION_NAME, "(surflist)", DATA_ARRAY, surflist);

		/* Get pointer to interface owner list */

		ownrlist = (long)RDB[ifc + IFC_PTR_OWNR_LIST];
		CheckPointer(FUNCTION_NAME, "(ownrlist)", DATA_ARRAY, ownrlist);

		/* Get pointer to interface neighbour list */

		nbrlist = (long)RDB[ifc + IFC_PTR_NBR_LIST];
		CheckPointer(FUNCTION_NAME, "(nbrlist)", DATA_ARRAY, nbrlist);

		/* Get pointer to cell's face list */

		facelist = (long)RDB[cgns + IFC_TET_MSH_PTR_FACES];
		CheckPointer(FUNCTION_NAME, "(facelist)", DATA_ARRAY, facelist);

		/* Get pointer to cell's side list */

		sidelist = (long)RDB[cgns + IFC_TET_MSH_PTR_SIDES];
		CheckPointer(FUNCTION_NAME, "(sidelist)", DATA_ARRAY, sidelist);

		/* Loop over cell faces */

		nf = (long)RDB[cgns + IFC_TET_MSH_NF];
		CheckValue(FUNCTION_NAME, "nf", "", nf, 4, 4);

		for (i = 0; i < nf; i++)
		  {
		    /* Get index of face */

		    n = (long)RDB[facelist + i];

		    /* Get side for face */

		    side = (long)RDB[sidelist + i];

		    /* Get pointer to face surface */

		    surf = ListPtr(surflist, n);		    

		    /* Get pointer to surface parameters */

		    ptr = (long)RDB[surf + SURFACE_PTR_PARAMS];
		    CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
      
		    /* Get number of points on the face */
      
		    np = (long)RDB[surf + SURFACE_N_PARAMS];
		    CheckValue(FUNCTION_NAME, "np", "", np, 3, 3);

		    /* Copy points to params */

		    k = 0;

		    for (j = 0; j < np; j++)
		      {
			/* Get pointer to beginning of point coordinates */

			pt = (long)RDB[ptr + j];
		
			/* Store coordinates to params */

			params[k++] = RDB[pt + 0];
			params[k++] = RDB[pt + 1];
			params[k++] = RDB[pt + 2];
	
		      }

		    /* Get distance */
	      
		    d = SurfaceDistance(surf, params, SURF_PLANE, 9, 
					x, y, z, u, v, w, id);
		    CheckValue(FUNCTION_NAME, "d", "15", d, 0.0, INFTY);

		    /* Compare to minimum */
		    
		    if (d < min)
		      {
			min = d;

			/* Get neighbour */

			if (side == -1)
			  nbhr = (long)RDB[nbrlist + n];
			else
			  nbhr = (long)RDB[ownrlist + n];
		      }
		  }

		/* Get collision count */

		ptr = (long)RDB[DATA_PTR_COLLISION_COUNT];
		ncol = GetPrivateData(ptr, id);

		/* Store value */

		StoreValuePair(uni + UNIVERSE_PTR_NEXT_CELL, ncol, nbhr, id);
	      }
	    else
	      {
		/* Point is in background universe, get distance to search */
		/* mesh boundaries. */

		/* Pointer to geometry */
	
		loc0 = (long)GetPrivateData(lvl + LVL_PRIV_PTR_UMSH, id);
		CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0);

		/* Pointer to interaface structure */

		loc0 = (long)RDB[loc0 + UMSH_PTR_IFC];
		CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0);
		
		/* Get minimum distance */
		
		d = NearestUMSHSurf(loc0, x, y, z, u, v, w, id);

		/* Compare to minimum */
			
		if (d < min)
		  min = d;
	      }

	    /* Break case */
	    
	    break;
	    
	    /*****************************************************************/
	  }      

	case UNIVERSE_TYPE_STL:
	  {
	    /*****************************************************************/

	    /***** STL based geometry ****************************************/

	    /* Pointer to geometry */
	
	    loc0 = (long)GetPrivateData(lvl + LVL_PRIV_PTR_STL, id);
	    CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0);

	    /* Get minimum distance */

	    d = NearestSTLSurf(loc0, x, y, z, u, v, w, id);

	    /* Compare to minimum */
			
	    if (d < min)
	      min = d;

	    /* Break case */
	    
	    break;
	    
	    /*****************************************************************/
	  }      

	case UNIVERSE_TYPE_PBED:
	  {
	    /*****************************************************************/

	    /***** Explicit stochastic geometry ******************************/

	    /* Check direct pointer to pebble */

	    if ((pbl = (long)GetPrivateData(lvl + LVL_PRIV_PTR_PEBBLE, id)) > 
		VALID_PTR)
	      {
		/* Put surface parameters */

		params[0] = RDB[pbl + PEBBLE_X0];
		params[1] = RDB[pbl + PEBBLE_Y0];
		params[2] = RDB[pbl + PEBBLE_Z0];
		params[3] = RDB[pbl + PEBBLE_RAD];

		if ((x - params[0])*(x - params[0]) + 
		    (y - params[1])*(y - params[1]) + 
		    (z - params[2])*(z - params[2]) > params[3]*params[3])
		  Die(FUNCTION_NAME, "not inside");

		/* Get distance */

		d = SurfaceDistance(-1, params, SURF_SPH, 4, x, y, z, 
				    u, v, w, id);
		CheckValue(FUNCTION_NAME, "d", "16", d, 0.0, 2.0*params[3]);
	      }
	    else
	      {
		/* Pointer to PB geometry */
	
		pbd = (long)GetPrivateData(lvl + LVL_PRIV_PTR_PBED, id);
		CheckPointer(FUNCTION_NAME, "(pbd)", DATA_ARRAY, pbd);
		
		/* Get minimum distance */
		
		d = NearestPBSurf(pbd, x, y, z, u, v, w, id);
	      }

	    /* Compare to minimum */
	    
	    if (d < min)
	      min = d;
	    
	    /* Break case */
	    
	    break;

	    /*****************************************************************/
	  }

	default:
	  {
	    /* Invalid type */
	    
	    Die(FUNCTION_NAME, "Invalid universe type");
	  }
	}
      
      /* Break loop if level is last */
      
      if ((long)GetPrivateData(lvl + LVL_PRIV_LAST, id) == YES)
      	break;

      /* Next level */

      lvl0 = NextItem(lvl0);
    }

  /* Return shortest distance */

  return min;
}
Esempio n. 16
0
void UPSDeviceAdded(void *refCon, io_iterator_t iterator)
{
    io_object_t             upsDevice           = MACH_PORT_NULL;
    UPSDataRef              upsDataRef          = NULL;
    CFDictionaryRef         upsProperties       = NULL;
    CFDictionaryRef         upsEvent            = NULL;
    CFSetRef                upsCapabilites 		= NULL;
    CFRunLoopSourceRef      upsEventSource      = NULL;
    CFRunLoopTimerRef       upsEventTimer       = NULL;
    CFTypeRef               typeRef             = NULL;
    IOCFPlugInInterface **	plugInInterface 	= NULL;
    IOUPSPlugInInterface_v140 **	upsPlugInInterface 	= NULL;
    HRESULT                 result              = S_FALSE;
    IOReturn                kr;
    SInt32                  score;
        
    while ( (upsDevice = IOIteratorNext(iterator)) )
    {        
        // Create the CF plugin for this device
        kr = IOCreatePlugInInterfaceForService(upsDevice, kIOUPSPlugInTypeID, 
                    kIOCFPlugInInterfaceID, &plugInInterface, &score);
                    
        if ( kr != kIOReturnSuccess )
            goto UPSDEVICEADDED_NONPLUGIN_CLEANUP;
            
        // Grab the new v140 interface
        result = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOUPSPlugInInterfaceID_v140), 
                                                (LPVOID)&upsPlugInInterface);
                                                
        if ( ( result == S_OK ) && upsPlugInInterface )
        {
            kr = (*upsPlugInInterface)->createAsyncEventSource(upsPlugInInterface, &typeRef);
            
            if ((kr != kIOReturnSuccess) || !typeRef)
                goto UPSDEVICEADDED_FAIL;
                
            if ( CFGetTypeID(typeRef) == CFRunLoopTimerGetTypeID() )
            {
                upsEventTimer = (CFRunLoopTimerRef)typeRef;
                CFRunLoopAddTimer(CFRunLoopGetCurrent(), upsEventTimer, kCFRunLoopDefaultMode);
            }
            else if ( CFGetTypeID(typeRef) == CFRunLoopSourceGetTypeID() )
            {
                upsEventSource = (CFRunLoopSourceRef)typeRef;
                CFRunLoopAddSource(CFRunLoopGetCurrent(), upsEventSource, kCFRunLoopDefaultMode);
            }
        }
        // Couldn't grab the new interface.  Fallback on the old.
        else
        {
            result = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOUPSPlugInInterfaceID), 
                                                (LPVOID)&upsPlugInInterface);
        }
                                                        
        // Got the interface
        if ( ( result == S_OK ) && upsPlugInInterface )
        {
            kr = (*upsPlugInInterface)->getProperties(upsPlugInInterface, &upsProperties);
            
            if (kr != kIOReturnSuccess)
                goto UPSDEVICEADDED_FAIL;
                
            upsDataRef = GetPrivateData(upsProperties);

            if ( !upsDataRef )
                goto UPSDEVICEADDED_FAIL;

            upsDataRef->upsPlugInInterface  = (IOUPSPlugInInterface **)upsPlugInInterface;
            upsDataRef->upsEventSource      = upsEventSource;
            upsDataRef->upsEventTimer       = upsEventTimer;
            upsDataRef->isPresent           = true;
            
            kr = (*upsPlugInInterface)->getCapabilities(upsPlugInInterface, &upsCapabilites);

            if (kr != kIOReturnSuccess)
                goto UPSDEVICEADDED_FAIL;

            kr = CreatePowerManagerUPSEntry(upsDataRef, upsProperties, upsCapabilites);

            if (kr != kIOReturnSuccess)
                goto UPSDEVICEADDED_FAIL;

            kr = (*upsPlugInInterface)->getEvent(upsPlugInInterface, &upsEvent);

            if (kr != kIOReturnSuccess)
                goto UPSDEVICEADDED_FAIL;

            ProcessUPSEvent(upsDataRef, upsEvent);

            (*upsPlugInInterface)->setEventCallback(upsPlugInInterface, UPSEventCallback, NULL, upsDataRef);

            IOServiceAddInterestNotification(	
                                    gNotifyPort,		// notifyPort
                                    upsDevice,			// service
                                    kIOGeneralInterest,		// interestType
                                    DeviceNotification,		// callback
                                    upsDataRef,			// refCon
                                    &(upsDataRef->notification)	// notification
                                    );
                                    
            goto UPSDEVICEADDED_CLEANUP;
        }

UPSDEVICEADDED_FAIL:
        // Failed to allocated a UPS interface.  Do some cleanup
        if ( upsPlugInInterface )
        {
            (*upsPlugInInterface)->Release(upsPlugInInterface);
            upsPlugInInterface = NULL;
        }
        
        if ( upsEventSource )
        {
            CFRunLoopRemoveSource(CFRunLoopGetCurrent(), upsEventSource, kCFRunLoopDefaultMode);
            upsEventSource = NULL;
        }

        if ( upsEventTimer )
        {
            CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), upsEventTimer, kCFRunLoopDefaultMode);
            upsEventSource = NULL;
        }

UPSDEVICEADDED_CLEANUP:
        // Clean up
        (*plugInInterface)->Release(plugInInterface);
        
UPSDEVICEADDED_NONPLUGIN_CLEANUP:
        IOObjectRelease(upsDevice);
    }
}
void CBacnetOutput::OnNMClickListOutput(NMHDR *pNMHDR, LRESULT *pResult)
{
	 
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: Add your control notification handler code here
	long lRow,lCol;
	m_output_list.Set_Edit(true);
	DWORD dwPos=GetMessagePos();//Get which line is click by user.Set the check box, when user enter Insert it will jump to program dialog
	CPoint point( LOWORD(dwPos), HIWORD(dwPos));
	m_output_list.ScreenToClient(&point);
	LVHITTESTINFO lvinfo;
	lvinfo.pt=point;
	lvinfo.flags=LVHT_ABOVE;
	int nItem=m_output_list.SubItemHitTest(&lvinfo);



	if((nItem!=-1) && (nItem < BAC_OUTPUT_ITEM_COUNT))
	{
		output_list_line = nItem;
		if((m_Output_data.at(output_list_line).sub_id !=0) &&
			//(m_Output_data.at(output_list_line).sub_number !=0) &&
			(m_Output_data.at(output_list_line).sub_product !=0))
		{
			unsigned char temp_pid = m_Output_data.at(output_list_line).sub_product;
			if((temp_pid == PM_T3PT10) ||
				(temp_pid == PM_T3IOA) ||
				(temp_pid == PM_T332AI) ||
				(temp_pid == PM_T38AI16O) ||
				(temp_pid == PM_T38I13O) ||
				(temp_pid == PM_T34AO) ||
				(temp_pid == PM_T36CT) ||
				(temp_pid == PM_T322AI) ||
				(temp_pid == PM_T38AI8AO6DO))
			{
				m_output_item_info.ShowWindow(true);
				CString temp_name;
				temp_name = GetProductName(m_Output_data.at(output_list_line).sub_product);
				CString show_info;
				CString temp_id;
				CString temp_number;
				temp_id.Format(_T(" Sub ID: %u        "),(unsigned char)m_Output_data.at(output_list_line).sub_id);
				temp_number.Format(_T("Output%d"),(unsigned char)m_Output_data.at(output_list_line).sub_number+1);
				show_info = _T("Module:") + temp_name +_T("        ") + temp_id + temp_number;
				m_output_item_info.SetWindowTextW(show_info);

			}	
			else
			{
				m_output_item_info.ShowWindow(false);
			}
		}
		else
		{
			m_output_item_info.ShowWindow(false);
		}
	}

	lRow = lvinfo.iItem;
	lCol = lvinfo.iSubItem;

	if(lRow>= OUTPUT_LIMITE_ITEM_COUNT)
		return;

	if(lRow>m_output_list.GetItemCount()) //如果点击区超过最大行号,则点击是无效的
		return;
	if(lRow<0)
		return;

	CString New_CString;
	CString temp_task_info;
	CString temp1;
	CStringArray temparray;

	if(lCol == OUTPUT_VALUE)
	{
		if(m_Output_data.at(lRow).auto_manual == BAC_AUTO)	//If it is auto mode, disable to change the value.
		{
			m_output_list.Set_Edit(false);
			return;
		}

		if(m_Output_data.at(lRow).digital_analog != BAC_UNITS_DIGITAL)
			return;



		memcpy_s(&m_temp_output_data[lRow],sizeof(Str_out_point),&m_Output_data.at(lRow),sizeof(Str_out_point));





		if((m_Output_data.at(lRow).range < 23) &&(m_Output_data.at(lRow).range !=0))
			temp1 = Digital_Units_Array[m_Output_data.at(lRow).range];
		else if((m_Output_data.at(lRow).range >=23) && (m_Output_data.at(lRow).range <= 30))
		{
			if(receive_customer_unit)
				temp1 = temp_unit_no_index[m_Output_data.at(lRow).range - 23];
			else
			{
				m_output_list.Set_Edit(false);
				return;
			}
		}
		else
			return;


		//if(m_Output_data.at(lRow).range > 11)
		//	temp1 = Digital_Units_Array[m_Output_data.at(lRow).range - 11];//11 is the sizeof the array
		//else
		//	temp1 = Digital_Units_Array[m_Output_data.at(lRow).range];
		SplitCStringA(temparray,temp1,_T("/"));
		if(m_Output_data.at(lRow).control == 0)
		{
			m_Output_data.at(lRow).control = 1;
			m_output_list.SetItemText(lRow,OUTPUT_VALUE,temparray.GetAt(1));
			New_CString = temparray.GetAt(1);
		}
		else
		{
			m_Output_data.at(lRow).control = 0;
			m_output_list.SetItemText(lRow,OUTPUT_VALUE,temparray.GetAt(0));
			New_CString = temparray.GetAt(0);
		}
	}
	else if(lCol == OUTPUT_AUTO_MANUAL)
	{
		memcpy_s(&m_temp_output_data[lRow],sizeof(Str_out_point),&m_Output_data.at(lRow),sizeof(Str_out_point));
		if(m_Output_data.at(lRow).auto_manual == 0)
		{
			m_Output_data.at(lRow).auto_manual = 1;
			m_output_list.SetItemText(lRow,OUTPUT_AUTO_MANUAL,_T("Manual"));
			//m_output_list.SetCellEnabled(lRow,OUTPUT_VALUE,TRUE);
			New_CString = _T("Manual");
		}
		else
		{
			m_Output_data.at(lRow).auto_manual = 0;
			m_output_list.SetItemText(lRow,OUTPUT_AUTO_MANUAL,_T("Auto"));
			//m_output_list.SetCellEnabled(lRow,OUTPUT_VALUE,FALSE);
			New_CString = _T("Auto");
		}
	}
	else if(lCol == OUTPUT_RANGE)
	{



			//CString temp_cs = m_output_list.GetItemText(Changed_Item,Changed_SubItem);
			BacnetRange dlg;
			//点击产品的时候 需要读customer units,老的产品firmware 说不定没有 这些,所以不强迫要读到;
			if(!read_customer_unit)
			{

				int temp_invoke_id = -1;
				int send_status = true;
				int	resend_count = 0;
				for (int z=0;z<3;z++)
				{
					do 
					{
						resend_count ++;
						if(resend_count>5)
						{
							send_status = false;
							break;
						}
						temp_invoke_id =  GetPrivateData(
							g_bac_instance,
							READUNIT_T3000,
							0,
							BAC_CUSTOMER_UNITS_COUNT - 1,
							sizeof(Str_Units_element));		

						Sleep(SEND_COMMAND_DELAY_TIME);
					} while (g_invoke_id<0);
					if(send_status)
					{
						for (int z=0;z<1000;z++)
						{
							Sleep(1);
							if(tsm_invoke_id_free(temp_invoke_id))
							{
								read_customer_unit = true;
								break;
							}
							else
								continue;
						}

					}
					if(read_customer_unit)
						break;
				}


			}

			if(m_Output_data.at(lRow).digital_analog == BAC_UNITS_ANALOG)
			{
				bac_ranges_type = OUTPUT_RANGE_ANALOG_TYPE;
				if(m_Output_data.at(lRow).range > (sizeof(Output_Analog_Units_Array) / sizeof(Output_Analog_Units_Array[0])))
				{
					m_Output_data.at(lRow).range = 0;
					bac_range_number_choose = 0;
				}
			}
			else
			{
				bac_ranges_type = OUTPUT_RANGE_DIGITAL_TYPE;
				if(m_Output_data.at(lRow).range > 30)
				{
					m_Output_data.at(lRow).range = 0;
					bac_range_number_choose = 0;
				}
			}


			//if(temp_cs.CompareNoCase(Units_Type[UNITS_TYPE_ANALOG])==0)
			//{
				initial_dialog = 3;
				bac_range_number_choose = m_Output_data.at(lRow).range;
				//bac_ranges_type = OUTPUT_RANGE_ANALOG_TYPE;
				dlg.DoModal();
				if(range_cancel)
				{
					PostMessage(WM_REFRESH_BAC_OUTPUT_LIST,lRow,REFRESH_ON_ITEM);//这里调用 刷新线程重新刷新会方便一点;
					return ;
				}
				if(bac_range_number_choose == 0)	//如果选择的是 unused 就认为是analog 的unused;这样 能显示对应的value;
				{
					m_Output_data.at(lRow).digital_analog =  BAC_UNITS_ANALOG;
					bac_ranges_type = OUTPUT_RANGE_ANALOG_TYPE;
				}

				if(bac_ranges_type == OUTPUT_RANGE_ANALOG_TYPE)
				{
					m_Output_data.at(lRow).digital_analog =  BAC_UNITS_ANALOG;
					m_Output_data.at(lRow).range =  bac_range_number_choose;
					m_output_list.SetItemText(lRow,OUTPUT_UNITE,Output_Analog_Units_Show[bac_range_number_choose]);		
					m_output_list.SetItemText(lRow,OUTPUT_RANGE,OutPut_List_Analog_Range[bac_range_number_choose]);	

					//m_output_list.SetItemText(lRow,OUTPUT_0_PERSENT,_T("0"));
					//m_output_list.SetCellEnabled(lRow,OUTPUT_0_PERSENT,1);
					//m_output_list.SetItemText(lRow,OUTPUT_100_PERSENT,_T("10"));
					//m_output_list.SetCellEnabled(lRow,OUTPUT_100_PERSENT,1);
				 
#if 0
					CString cstemp_value;
					float temp_float_value;
					temp_float_value = m_Output_data.at(Changed_Item).value / 1000;
					cstemp_value.Format(_T("%.2f"),temp_float_value);
					m_output_list.SetItemText(Changed_Item,OUTPUT_VALUE,cstemp_value);	
#endif
					CString cstemp_value;
					cstemp_value.Format(_T("%d"),m_Output_data.at(lRow).value);
					m_output_list.SetItemText(lRow,OUTPUT_VALUE,cstemp_value);	
				}
				else if((bac_ranges_type == VARIABLE_RANGE_DIGITAL_TYPE) || (bac_ranges_type == INPUT_RANGE_DIGITAL_TYPE) || (bac_ranges_type == OUTPUT_RANGE_DIGITAL_TYPE))
				{
					m_Output_data.at(lRow).digital_analog =  BAC_UNITS_DIGITAL;
					m_Output_data.at(lRow).range =  bac_range_number_choose;

					//m_output_list.SetItemText(lRow,OUTPUT_0_PERSENT,_T(""));
					//m_output_list.SetCellEnabled(lRow,OUTPUT_0_PERSENT,0);
					//m_output_list.SetItemText(lRow,OUTPUT_100_PERSENT,_T(""));
					//m_output_list.SetCellEnabled(lRow,OUTPUT_100_PERSENT,0);



					CStringArray temparray;

					if((bac_range_number_choose >= 23) && (bac_range_number_choose <= 30))
					{
						//temp1.Format(_T("%s"), temp_unit_no_index[bac_range_number_choose - 23]);
						temp1 = temp_unit_no_index[bac_range_number_choose - 23];
					}
					else
						temp1 = Digital_Units_Array[bac_range_number_choose];//22 is the sizeof the array



					SplitCStringA(temparray,temp1,_T("/"));

					if(m_Output_data.at(lRow).control == 1)
					{
						if((temparray.GetSize()==2)&&(!temparray.GetAt(1).IsEmpty()))
						{
							m_output_list.SetItemText(lRow,OUTPUT_VALUE,temparray.GetAt(1));
						}
					}
					else
					{
						if((temparray.GetSize()==2)&&(!temparray.GetAt(0).IsEmpty()))
						{
							m_output_list.SetItemText(lRow,OUTPUT_VALUE,temparray.GetAt(0));
						}	
					}
					m_output_list.SetItemText(lRow,OUTPUT_RANGE,temp1);
					m_output_list.SetItemText(lRow,OUTPUT_UNITE,_T(""));//如果是数字单位 Unit 要清空;
				}
			
	}
	else
	{
		return;
	}

		//return;



	m_output_list.Set_Edit(false);

	int cmp_ret = memcmp(&m_temp_output_data[lRow],&m_Output_data.at(lRow),sizeof(Str_out_point));
	if(cmp_ret!=0)
	{
		m_output_list.SetItemBkColor(lRow,lCol,LIST_ITEM_CHANGED_BKCOLOR);
		temp_task_info.Format(_T("Write Output List Item%d .Changed to \"%s\" "),lRow + 1,New_CString);
		Post_Write_Message(g_bac_instance,WRITEOUTPUT_T3000,lRow,lRow,sizeof(Str_out_point),m_output_dlg_hwnd,temp_task_info,lRow,lCol);
	}


	*pResult = 0;
}
Esempio n. 18
-1
void CBacnetVariable::OnNMClickListVariable(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: Add your control notification handler code here
	long lRow,lCol;
	m_variable_list.Set_Edit(true);
	DWORD dwPos=GetMessagePos();//Get which line is click by user.Set the check box, when user enter Insert it will jump to program dialog
	CPoint point( LOWORD(dwPos), HIWORD(dwPos));
	m_variable_list.ScreenToClient(&point);
	LVHITTESTINFO lvinfo;
	lvinfo.pt=point;
	lvinfo.flags=LVHT_ABOVE;
	int nItem=m_variable_list.SubItemHitTest(&lvinfo);

	lRow = lvinfo.iItem;
	lCol = lvinfo.iSubItem;


	if(lRow>m_variable_list.GetItemCount()) //如果点击区超过最大行号,则点击是无效的
		return;
	if(lRow<0)
		return;



	CString temp1;
	m_row = lRow;
	m_col = lCol;

	memcpy_s(&m_temp_variable_data[lRow],sizeof(Str_variable_point),&m_Variable_data.at(lRow),sizeof(Str_variable_point));
	CString New_CString;
	CString temp_task_info;
	if((lCol == VARIABLE_VALUE) &&(m_Variable_data.at(lRow).digital_analog == BAC_UNITS_DIGITAL ) && (m_Variable_data.at(lRow).auto_manual != BAC_AUTO))
	{
		
		
		CString temp1;
		CStringArray temparray;

		if((m_Variable_data.at(lRow).range < 23) &&(m_Variable_data.at(lRow).range !=0))
			temp1 = Digital_Units_Array[m_Variable_data.at(lRow).range];
		else if((m_Variable_data.at(lRow).range >=23) && (m_Variable_data.at(lRow).range <= 30))
		{
			if(receive_customer_unit)
				temp1 = temp_unit_no_index[m_Variable_data.at(lRow).range - 23];
			else
			{
				m_variable_list.Set_Edit(false);
				return;
			}
		}
		else
			return;
		SplitCStringA(temparray,temp1,_T("/"));



		if(m_Variable_data.at(lRow).control == 0)
		{
			m_Variable_data.at(lRow).control = 1;
			m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(1));
			New_CString = temparray.GetAt(1);
		}
		else
		{
			m_Variable_data.at(lRow).control = 0;
			m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(0));
			New_CString = temparray.GetAt(0);
		}
		m_variable_list.Set_Edit(false);

		temp_task_info.Format(_T("Write Variable List Item%d .Changed to \"%s\" "),lRow + 1,New_CString);
	}
	else if((lCol == VARIABLE_VALUE) &&(m_Variable_data.at(lRow).digital_analog == BAC_UNITS_ANALOG ) && (m_Variable_data.at(lRow).auto_manual == BAC_MANUAL) && (m_Variable_data.at(lRow).range == 20))
	{
		m_variable_list.Set_Edit(false);
		m_variable_time_picker.ShowWindow(SW_SHOW);
		CRect list_rect,win_rect;
		m_variable_list.GetWindowRect(list_rect);
		GetWindowRect(win_rect);
		CRect myrect;
		m_variable_list.GetSubItemRect(lRow,lCol,LVIR_BOUNDS,myrect);


		myrect.left = myrect.left + list_rect.left - win_rect.left  +2 ;
		myrect.right = myrect.right + list_rect.left - win_rect.left + 2;
		myrect.top = myrect.top + 24;
		myrect.bottom = myrect.bottom + 26;
		m_variable_time_picker.BringWindowToTop();
		m_variable_time_picker.MoveWindow(myrect);

		
		CString Temp_CString =  m_variable_list.GetItemText(lRow,lCol);

		CStringArray TEMPCS;
		int temp_hour,temp_minute,temp_second;
		SplitCStringA(TEMPCS, Temp_CString, _T(":"));
		if((int)TEMPCS.GetSize() <3)
		{
			temp_hour = 0;
			temp_minute = 0;
			temp_second = 0;
			CTime TimeTemp(2016,1,1,temp_hour,temp_minute,0);
			m_variable_time_picker.SetFormat(_T("HH:mm:ss"));
			m_variable_time_picker.SetTime(&TimeTemp);
			m_variable_time_picker.SetFocus();
		}
		else
		{
			temp_hour = _wtoi(TEMPCS.GetAt(0));
			temp_minute = _wtoi(TEMPCS.GetAt(1));
			temp_second = _wtoi(TEMPCS.GetAt(2));
			if(temp_hour >=24)
				temp_hour = 0;
			if(temp_minute >=60)
				temp_minute = 0;
			if(temp_second >= 60)
				temp_second = 0;
			CTime TimeTemp(2016,1,1,temp_hour,temp_minute,temp_second);
			m_variable_time_picker.SetFormat(_T("HH:mm:ss"));
			m_variable_time_picker.SetTime(&TimeTemp);
			m_variable_time_picker.SetFocus();
		}
		m_variable_list.SetItemText(lRow,lCol,_T(""));
		m_variable_time_picker.Invalidate();
		SetTimer(2,100,NULL);
	}
	else if(lCol == VARIABLE_VALUE)
	{
		if(m_Variable_data.at(lRow).auto_manual == BAC_AUTO)
		{
			m_variable_list.Set_Edit(false);
			return;
		}
	}
	else if(lCol == VARIABLE_AUTO_MANUAL)
	{
		if(m_Variable_data.at(lRow).auto_manual == 0)
		{
			m_Variable_data.at(lRow).auto_manual = 1;
			m_variable_list.SetItemText(lRow,VARIABLE_AUTO_MANUAL,_T("Manual"));
			New_CString = _T("Manual");
		}
		else
		{
			m_Variable_data.at(lRow).auto_manual = 0;
			m_variable_list.SetItemText(lRow,VARIABLE_AUTO_MANUAL,_T("Auto"));
			New_CString = _T("Auto");
		}
		temp_task_info.Format(_T("Write Variable List Item%d .Changed to \"%s\" "),lRow + 1,New_CString);
	}
	else if(lCol == VARIABLE_UNITE)
	{


		BacnetRange dlg;

		//点击产品的时候 需要读customer units,老的产品firmware 说不定没有 这些,所以不强迫要读到;
		if(!read_customer_unit)
		{

			int temp_invoke_id = -1;
			int send_status = true;
			int	resend_count = 0;
			for (int z=0;z<3;z++)
			{
				do 
				{
					resend_count ++;
					if(resend_count>5)
					{
						send_status = false;
						break;
					}
					temp_invoke_id =  GetPrivateData(
						g_bac_instance,
						READUNIT_T3000,
						0,
						BAC_CUSTOMER_UNITS_COUNT - 1,
						sizeof(Str_Units_element));		

					Sleep(SEND_COMMAND_DELAY_TIME);
				} while (g_invoke_id<0);
				if(send_status)
				{
					for (int z=0;z<1000;z++)
					{
						Sleep(1);
						if(tsm_invoke_id_free(temp_invoke_id))
						{
							read_customer_unit = true;
							break;
						}
						else
							continue;
					}

				}
				if(read_customer_unit)
					break;
			}

		}
		if(m_Variable_data.at(lRow).digital_analog == BAC_UNITS_ANALOG)
		{
			bac_ranges_type = VARIABLE_RANGE_ANALOG_TYPE;
			if(m_Variable_data.at(lRow).range > (sizeof(Variable_Analog_Units_Array) / sizeof(Variable_Analog_Units_Array[0])))
			{
				m_Variable_data.at(lRow).range = 0;
				bac_range_number_choose = 0;
			}
		}
		else
		{
			bac_ranges_type = VARIABLE_RANGE_DIGITAL_TYPE;
			if(m_Variable_data.at(lRow).range > 30)
			{
				m_Variable_data.at(lRow).range = 0;
				bac_range_number_choose = 0;
			}
		}


			initial_dialog = 1;
			bac_range_number_choose = m_Variable_data.at(lRow).range;
			dlg.DoModal();
			if(range_cancel)
			{
				PostMessage(WM_REFRESH_BAC_VARIABLE_LIST,lRow,REFRESH_ON_ITEM);//这里调用 刷新线程重新刷新会方便一点;
				return ;
			}
			if(bac_range_number_choose == 0)	//如果选择的是 unused 就认为是analog 的unused;这样 能显示对应的value;
			{
				m_Variable_data.at(lRow).digital_analog =  BAC_UNITS_ANALOG;
				bac_ranges_type = VARIABLE_RANGE_ANALOG_TYPE;
			}

			if(bac_ranges_type == VARIABLE_RANGE_ANALOG_TYPE)
			{
				m_Variable_data.at(lRow).digital_analog = BAC_UNITS_ANALOG;
				m_Variable_data.at(lRow).range = bac_range_number_choose;
				m_variable_list.SetItemText(lRow,lCol,Variable_Analog_Units_Array[bac_range_number_choose]);



				if(m_Variable_data.at(lRow).range == 20)	//如果是时间;
				{
					char temp_char[50];
					int time_seconds = m_Variable_data.at(lRow).value / 1000;
					intervaltotextfull(temp_char,time_seconds,0,0);

					CString temp_11;
					MultiByteToWideChar( CP_ACP, 0, temp_char, strlen(temp_char) + 1, 
						temp_11.GetBuffer(MAX_PATH), MAX_PATH );
					temp_11.ReleaseBuffer();		
					m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temp_11);

				}
				else
				{
					CString cstemp_value;
					float temp_float_value;
					temp_float_value = ((float)m_Variable_data.at(lRow).value) / 1000;
					cstemp_value.Format(_T("%.3f"),temp_float_value);
					m_variable_list.SetItemText(lRow,VARIABLE_VALUE,cstemp_value);

					/*				cstemp_value.Format(_T("%d"),m_Variable_data.at(Changed_Item).value);
					m_variable_list.SetItemText(Changed_Item,VARIABLE_VALUE,cstemp_value);*/	
				}
			}
			else if((bac_ranges_type == VARIABLE_RANGE_DIGITAL_TYPE) || (bac_ranges_type == INPUT_RANGE_DIGITAL_TYPE) || (bac_ranges_type == OUTPUT_RANGE_DIGITAL_TYPE))
			{
				m_Variable_data.at(lRow).digital_analog = BAC_UNITS_DIGITAL;
				m_Variable_data.at(lRow).range = bac_range_number_choose;


				CStringArray temparray;
				if((bac_range_number_choose >= 23) && (bac_range_number_choose <= 30))
				{
					//temp1.Format(_T("%s"), temp_unit_no_index[bac_range_number_choose - 23]);
					temp1 = temp_unit_no_index[bac_range_number_choose - 23];
				}
				else
					temp1 = Digital_Units_Array[bac_range_number_choose];//22 is the sizeof the array

				SplitCStringA(temparray,temp1,_T("/"));





				if(m_Variable_data.at(lRow).control == 1)
				{
					if((temparray.GetSize()==2)&&(!temparray.GetAt(1).IsEmpty()))
					{
						m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(1));
					}
				}
				else
				{
					if((temparray.GetSize()==2)&&(!temparray.GetAt(0).IsEmpty()))
					{
						m_variable_list.SetItemText(lRow,VARIABLE_VALUE,temparray.GetAt(0));
					}			
				}
				m_variable_list.SetItemText(lRow,VARIABLE_UNITE,temp1);
			}
		
	
	}
	else
	{
		return;
	}

	int cmp_ret = memcmp(&m_temp_variable_data[lRow],&m_Variable_data.at(lRow),sizeof(Str_variable_point));
	if(cmp_ret!=0)
	{
		m_variable_list.SetItemBkColor(lRow,lCol,LIST_ITEM_CHANGED_BKCOLOR);
		Post_Write_Message(g_bac_instance,WRITEVARIABLE_T3000,lRow,lRow,sizeof(Str_variable_point),m_variable_dlg_hwnd,temp_task_info,lRow,lCol);
	}
	*pResult = 0;
}