/*!\fn int list_push( LIST *list , void *ptr , void (*destructor)( void *ptr ) )
 *\brief Add a pointer to the end of the list. 
 *\param list An initilized list container. A null value will cause an error and a _log message.
 *\param ptr The pointer you wan to put in the list. A null value will cause an error and a _log message.
 *\param destructor Pointer to the ptr type destructor function. Leave to NULL if there isn't.
 *\return TRUE or FALSE. Check error messages in DEBUG mode.
 */
int list_push( LIST *list , void *ptr , void (*destructor)( void *ptr ) ) 
{
   LIST_NODE *node = NULL ;

   n_assert( list , n_log( LOG_ERR , "invalid list: NULL" ); return FALSE );
   n_assert( ptr  , n_log( LOG_ERR , "invalid ptr: NULL" );  return FALSE );

   if( list -> nb_max_items > 0 && ( list -> nb_items >= list -> nb_max_items ) )
   {
      n_log( LOG_ERR , "list is full" );
      return FALSE ;
   }

   node = new_list_node( ptr , destructor );
   n_assert( node , n_log( LOG_ERR , "Couldn't allocate new node" ); return FALSE );

   list -> nb_items ++ ;

   if( list -> end )
   {
      list -> end -> next = node ;
      node -> prev = list -> end ;
      list -> end = node ;               
   }
   else
   {
      list -> start = list -> end = node ;      
   }   
   return TRUE ;
} /* list_push( ... ) */
Esempio n. 2
0
	JNIEnv * GetJNIEnv()
	{
		if (!gJavaVM)
		{
			n_log("?: Java VM empty!");
			return NULL;
		}

		JNIEnv * env = NULL;
		int err = gJavaVM->GetEnv((void**)&env, JNI_VERSION_1_4);

		if (err == JNI_EDETACHED)
		{
			if (gJavaVM->AttachCurrentThread(&env, 0) != 0)
			{
				n_log("?: AttachCurrentThread().");
			}
		}
		else if (err != JNI_OK)
		{
			n_log("?: GetJNIEnv.");
		}
		
		return env;
	}
Esempio n. 3
0
	int ReadAPKFile(void ** data, const char * filename)
	{
		assert (gAssetManager != NULL);

		AAsset * pAsset = AAssetManager_open(gAssetManager, filename, AASSET_MODE_UNKNOWN);
		if (pAsset == NULL)
			return -1;

		size_t size = AAsset_getLength(pAsset);
		if (size > 0 && data != NULL)
		{
			unsigned char * pd = new unsigned char[size];
			int read_count = AAsset_read(pAsset, pd, size);
			if(read_count <= 0)
			{
				n_log("?: Read APK File '%s'.", filename);

				delete[] pd;
				pd = NULL;
				size = 0;
			}

			*data = pd;
		}

		AAsset_close(pAsset);
		
		return size;
	}
/*!\fn void *remove_list_node_f( LIST *list , LIST_NODE *node )
 *\brief Internal function called each time we need to get a node out of a list
 *\param list The list to pick in
 *\param node The node to remove in the list
 *\return The node or NULL
 */
void *remove_list_node_f( LIST *list , LIST_NODE *node )
{
   void *ptr = NULL ;

   n_assert( list        , n_log( LOG_ERR , "can't remove from NULL list" );        return NULL );
   n_assert( list->start , n_log( LOG_ERR , "can't remove from NULL list->start" ); return NULL );
   n_assert( list->end   , n_log( LOG_ERR , "can't remove from NULL list->end" );   return NULL );
   n_assert( node        , n_log( LOG_ERR , "can't remove from NULL node" );        return NULL );

   ptr = node -> ptr ;
   if( node -> prev && node -> next )
   {
      node -> prev -> next = node -> next ;
      node -> next -> prev = node -> prev ;
   }
   else
   {
      if( node -> prev == NULL && node -> next )
      {
         node -> next -> prev = NULL ;
         list -> start = node -> next ;
      }
      else
      {
         if( node -> prev && node -> next == NULL )
         {
            node -> prev -> next = NULL ;
            list -> end = node -> prev ;
         }
         else
         {
            if( node -> prev == NULL && node -> next == NULL )
            {
               /* removing last item */
               list -> start = list -> end = NULL ;
            }
         }
      }
   }
   Free( node );
   list -> nb_items -- ;
   return ptr ;
} /* remove_list_node_f(...) */
/*!\fn int list_push_sorted( LIST *list , void *ptr , int (*comparator)( const void *a , const void *b ) , void (*destructor)( void *ptr ) )
 *\brief Add a pointer sorted in the list , starting by the end of the list.
 *\param list An initilized list container. A null value will cause an error and a _log message.
 *\param ptr The pointer you wan to put in the list. A null value will cause an error and a _log message.
 *\param comparator A pointer to a function which take two void * pointers and return an int.
 *\param destructor Pointer to the ptr type destructor function. Leave to NULL if there isn't.
 *\return TRUE or FALSE. Check error messages in DEBUG mode.
 */
int list_push_sorted( LIST *list , void *ptr , int (*comparator)( const void *a , const void *b ) , void (*destructor)( void *ptr ) )
{
   LIST_NODE *nodeptr = NULL ;

   n_assert( list , n_log( LOG_ERR , "invalid list: NULL" ); return FALSE );
   n_assert( ptr  , n_log( LOG_ERR , "invalid ptr: NULL" );  return FALSE ); 

   if( list -> nb_max_items > 0 && ( list -> nb_items >= list -> nb_max_items ) )
   {
      n_log( LOG_ERR , "list is full" );
      return FALSE ;
   }

   if( list -> end )
   {
      nodeptr = list -> end ;
      while( nodeptr && ( comparator( ptr , nodeptr -> ptr ) < 0 ) )
         nodeptr = nodeptr -> prev ;

      if( !nodeptr )
      {
         /* It's the lower ranked element in the sort */
         list_unshift( list , ptr , destructor );
      }   
      else
      {
         /* we have a match inside the list. let's insert the datas */
         LIST_NODE *node_next = nodeptr -> next  ;
         LIST_NODE *newnode = new_list_node( ptr , destructor );
         n_assert( newnode , n_log( LOG_ERR , "Couldn't allocate new node" ); return FALSE );

         if( node_next )
         {
            link_node( newnode , node_next );
         }   
         else 
            list -> end = newnode ;

         link_node( nodeptr , newnode );
         list -> nb_items ++ ;
      }
   }
/*!\fn LIST_NODE *new_list_node( void *ptr , void (*destructor)( void *ptr ) )
 *\brief Allocate a new node to link in a list.
 *\param ptr The pointer you want to put in the node.
 *\param destructor Pointer to the ptr type destructor function. Leave to NULL if there isn't.
 *\return A new node or NULL on error. Check error messages in DEBUG mode.
 */
LIST_NODE *new_list_node( void *ptr , void (*destructor)( void *ptr ) )
{
   LIST_NODE *node = NULL ;

   Malloc( node , LIST_NODE , 1 ); 
   n_assert( node ,  n_log( LOG_ERR , "Error allocating node for ptr %p" , ptr ); return NULL );

   node -> ptr = ptr ;
   node -> destroy_func = destructor ;
   node -> next = node -> prev = NULL ;

   return node ;
} /* new_list_node(...) */ 
Esempio n. 7
0
	void SetAssetManager(JNIEnv* env, jobject assetManager)
	{
		n_log("-: Setup AssetManager.");
		gAssetManager = AAssetManager_fromJava(env, assetManager);
	}
Esempio n. 8
0
int plot( const GlobalSettings& settings, const SCCResults& results,
          const string& root_dir, int id )
{

  // ----- RESULT OUTPUT TO FILE AND PLOTTING -----

  int const& s = settings.s;

  // make an output directory

  string dir;
  if ( id != -1 ) {
    stringstream tmp;
    tmp << setfill( '0' );
    tmp << "./" << root_dir << "/" << id << '/';
    dir = tmp.str();
    if ( system( ( "test -e " + dir + " || mkdir " + dir ).c_str() ) != 0 ) {
      #pragma omp critical (output)
      { cerr << id << ": ERROR -> unable to create the output directory!"; }
      return 1;
    }
  } else {
    dir = "./" + root_dir + "/";
  }

  ofstream n_log( ( dir + "n.log" ).c_str() );
  if ( !n_log.is_open() ) {
    #pragma omp critical (output)
    { cerr << "ERROR: unable to open occupation output file?" << endl; }
    return 1;
  }
  n_log << setiosflags( ios::scientific );
  n_log.setf( ios::showpos );
  n_log.precision( numeric_limits<fptype>::digits10 + 1 );

#ifdef _VERBOSE
  cout << "Final mean field parameters:" << endl;
#endif
  for ( int i = 0; i < s * s; ++i ) {
#ifdef _VERBOSE
    cout << i << ' ' << idx2x( i, s ) << ' ' << idx2y( i, s ) << ' ' << results.n_up( i ) << ' ' << results.n_down( i ) << endl;
#endif
    n_log << i << ' ' << idx2x( i, s ) << ' ' << idx2y( i, s ) << ' ' << results.n_up( i ) << ' ' << results.n_down( i ) << endl;
  }

  n_log.close();

#ifdef _VERBOSE
  cout << endl << "Plotting ...";
  cout.flush();
#endif

  ofstream gnuplot( ( dir + "plot.gnu" ).c_str() );
  if ( !gnuplot.is_open() ) {
    #pragma omp critical (output)
    { cerr << id << ": ERROR -> unable to create gnuplot script?" << endl; }
    return 1;
  }
  gnuplot << "\
	set terminal pngcairo size 1000,600 \n\
	set size ratio 2/3 \n\
	set xrange [0:" << 1.5 * ( s - 1 ) << "] \n\
	set yrange [0:" << s - 1 << "] \n\
	set tics out \n\
	set cbtics in \n\
	set cbtics \n\
	set dgrid3d " << s * 10 << "," << s * 10 << ",3 \n\
	set pm3d map \n\
	set arrow from 0,0 to " << 0.5 * ( s - 1 ) << "," << s - 1 << " nohead front \n\
	set arrow from " << s - 1 << ",0 to " << 1.5 * ( s - 1 ) << "," << s - 1 << " nohead front \n\
	set output 'm_plot.png' \n\
	set cblabel \"m_z\" \n\
	splot 'n.log' using ($2+0.5*$3):3:($4-$5) notitle \n\
	set output 'n_up_plot.png' \n\
	set cblabel \"n_up\" \n\
	splot 'n.log' using ($2+0.5*$3):3:4 notitle \n\
	set output 'n_down_plot.png' \n\
	set cblabel \"n_down\" \n\
	splot 'n.log' using ($2+0.5*$3):3:5 notitle";
  gnuplot.close();

  if ( system( ( "cd " + dir + " ; gnuplot plot.gnu" ).c_str() ) != 0 ) {
    cerr << id << ": WARNING -> gnuplot call returned exit code != 0" << endl;
  }

#ifdef _VERBOSE
  cout << " done!" << endl;
#endif

  return 0;
}