コード例 #1
0
ファイル: sidc.c プロジェクト: sorki/sidc
void output_spectrum_record( struct timeval *tv)
{
   int i;
   char *stamp = NULL, *prefix = NULL;

   if( !substitute_params( &prefix, tv, CF_output_files, NULL))
      bailout( "error in output_files configuration");

   if( bound_strcmp( prefix, out_prefix))
   {
      char *filename = NULL;

      if( out_prefix) free( out_prefix);
      out_prefix = strdup( prefix);
      append_sprintf( &filename, "%s/%s", CF_datadir, out_prefix);
      report( 0, "using output file [%s]", filename);

      if( sf_fo) fclose( sf_fo);
      if( (sf_fo = fopen( filename, "a+")) == NULL)
            bailout( "cannot open [%s], %s", filename, strerror( errno));

      if( CF_output_header)
      {
         // Header record required.  Output a header every time sidc
         // is started - only way to handle band changes etc
         struct stat st;

         if( stat( filename, &st) < 0) 
            bailout( "cannot stat output file %s: %s",
               filename, strerror( errno));

         fputs( "# FREQ ", sf_fo);
         for( i = cuton; i < cutoff; i++)
            fprintf( sf_fo, "%.2f ", (i+0.5) * DF);
         fputs( "\n", sf_fo);
      }

      free( filename);
   }

   substitute_params( &stamp, tv, CF_timestamp, NULL);
   fprintf( sf_fo, "%s", stamp);

   for( i=cuton; i<cutoff; i++)
   {
      double e = left.powspec[i]/output_int;
      if( CF_log_scale) e = CF_offset_db + 10 * log10( e + 1e-9);
      fputs( " ", sf_fo);
      fprintf( sf_fo, CF_field_format, e); 
   }

   fputs( "\n", sf_fo);
   fflush( sf_fo);
   free( prefix);
   free( stamp);
}
コード例 #2
0
ファイル: LowLevelMoz.cpp プロジェクト: linight/gwt
/*
 * Log a given jsval with a prefix.
 *  cx - JSContext for the JS execution context to use
 *  val - jsval to print
 *  prefix - string to print before the value, defaults to empty string
 *
 * TODO(jat): this whole printf-style logging needs to be replaced, but we
 * run into library version issues if we use C++ iostreams so we would need
 * to implement our own equivalent.  Given that this code is all likely to
 * be rewritten for out-of-process hosted mode, it seems unlikely to be worth
 * the effort until that is completed.
 */
void PrintJSValue(JSContext* cx, jsval val, char* prefix="") {
    JSType type = JS_TypeOfValue(cx, val);
    const char* typeString=JS_GetTypeName(cx, type);
    static const int BUF_SIZE = 256;
    char buf[BUF_SIZE];
    const char *bufEnd = buf + BUF_SIZE;
    char* p = buf;
    p += append_sprintf(p, bufEnd, "%s%s", prefix, typeString);
    switch(type) {
    case JSTYPE_VOID:
        break;
    case JSTYPE_BOOLEAN:
        p += append_sprintf(p, bufEnd, ": %s",
                            JSVAL_TO_BOOLEAN(val) ? "true" : "false");
        break;
    case JSTYPE_NUMBER:
        if (JSVAL_IS_INT(val)) {
            p += append_sprintf(p, bufEnd, ": %d", JSVAL_TO_INT(val));
        } else {
            p += append_sprintf(p, bufEnd, ": %lf", (double)*JSVAL_TO_DOUBLE(val));
        }
        break;
    case JSTYPE_OBJECT: {
        JSObject* obj = JSVAL_TO_OBJECT(val);
        if (!JSVAL_IS_OBJECT(val)) break;
        JSClass* clazz = obj ? JS_GET_CLASS(cx, obj) : 0;
        p += append_sprintf(p, bufEnd, " @ %08x, class %s",
                            (unsigned)obj, clazz ? clazz->name : "<null>");
        break;
    }
    case JSTYPE_FUNCTION:
    case JSTYPE_LIMIT:
        break;
    case JSTYPE_STRING: {
        /*
         * TODO(jat): support JS strings with international characters
         */
        JsStringWrap str(cx, JSVAL_TO_STRING(val));
        p += append_sprintf(p, bufEnd, ": %.*s", str.length(), str.bytes());
        break;
    }
    }
    Tracer::log("%s", buf);
}
コード例 #3
0
ファイル: sidc.c プロジェクト: sorki/sidc
void output_record_each( struct timeval *tv)
{
   int i, j;
   struct BAND *b;
   char *prefix = NULL;

   if( !substitute_params( &prefix, tv, CF_output_files, "ID"))
      bailout( "error in output_files configuration");

   if( bound_strcmp( prefix, out_prefix))
   {
      if( out_prefix) free( out_prefix);
      out_prefix = strdup( prefix);
      report( 0, "using output files [%s]", out_prefix);

      for( b = bands, i = 0; i < nbands; i++, b++)
      {
         char *prefix = NULL, *filename = NULL;
         if( b->fo) fclose( b->fo);
         substitute_params( &prefix, tv, CF_output_files, b->ident);
         append_sprintf( &filename, "%s/%s", CF_datadir, prefix);
         if( (b->fo=fopen( filename, "a")) == NULL)
            bailout( "cannot open [%s], %s", filename, strerror( errno));

         if( CF_output_header)
         {
            // Header record required.  Output a header every time sidc
            // is started - only way to handle band changes etc
            struct stat st;

            if( stat( filename, &st) < 0)
               bailout( "cannot stat output file %s: %s",
                  filename, strerror( errno));

            fputs( "# stamp power\n", b->fo);
         }

         free( prefix);
         free( filename);
      }
   }

   for( b = bands, i = 0; i < nbands; i++, b++)
   {
      double e = 0;
      int n1 = b->start/DF;
      int n2 = b->end/DF;
      char *stamp = NULL;

      substitute_params( &stamp, tv, CF_timestamp, b->ident);

      for( j=n1; j<= n2; j++) e += b->side->powspec[j];
      e /= output_int * (n2 - n1 + 1);
      if( CF_log_scale) e = CF_offset_db + 10 * log10( e + 1e-9);
      fprintf( b->fo, "%s ", stamp);
      fprintf( b->fo, CF_field_format, e);
      fputs( "\n", b->fo);
      fflush( b->fo);

      free( stamp);
   }

   free( prefix);
}
コード例 #4
0
ファイル: sidc.c プロジェクト: sorki/sidc
int substitute_params( char **d, struct timeval *tv,
                              char *format, char *band)
{
   double fsecs = tv->tv_sec + 1e-6 * tv->tv_usec;
   time_t ud = tv->tv_sec;
   struct tm *tm = gmtime( &ud);

   while( *format)
   {
      if( *format != '%') { append_sprintf( d, "%c", *format++); continue; }

      format++;
      switch( *format++)
      {
         case '%': append_sprintf( d, "%c", *format++); break;

         case 'y': append_sprintf( d, "%02d", tm->tm_year % 100);  break;
         case 'm': append_sprintf( d, "%02d", tm->tm_mon+1); break;
         case 'd': append_sprintf( d, "%02d", tm->tm_mday); break;

         case 'H': append_sprintf( d, "%02d", tm->tm_hour);  break;
         case 'M': append_sprintf( d, "%02d", tm->tm_min);  break;
         case 'S': append_sprintf( d, "%02d", tm->tm_sec);  break;

         case 'B': if( !band) bailout( "cannot specify %B in this mode");
                   append_sprintf( d, "%s", band);   break;
         case 'U': append_sprintf( d, "%ld", tv->tv_sec); break;
         case 'u': append_sprintf( d, "%.3f", fsecs);  break;

         case 'E': append_sprintf( d, "%d", (int)(tv->tv_sec % 86400)); break;
         case 'e': append_sprintf( d, "%.3f", 1e-6 * tv->tv_usec + 
                                            (tv->tv_sec % 86400)); break;
         default: return 0;
      }
   }

   return 1;
}
コード例 #5
0
unsigned char *generateBlurCodeARBfp(
    float s, bool vertical, bool tex2D, int img_width, int img_height
) {
    int n = (int) floor(3.0f*s)-1;
    float sum = 0;
    int i ;

    buffer_ptr = &(buffer[0]) ;

    for(i=-n; i<=n; i++) {
        float weight = gaussian(i, s);
        sum += weight;
    }

    append_sprintf(&buffer_ptr, "!!ARBfp1.0\n") ;
    append_sprintf(&buffer_ptr, "OPTION ARB_precision_hint_fastest;\n") ;
    append_sprintf(&buffer_ptr, "TEMP H0;\n") ;
    append_sprintf(&buffer_ptr, "TEMP H1;\n") ;
    append_sprintf(&buffer_ptr, "TEMP H2;\n") ;

    for(i=-n; i<=n; i++) {
        float x_offset, y_offset;
        if (vertical) {
            x_offset = 0; y_offset = i;
        } else {
            x_offset = i; y_offset = 0;
        }
        if (tex2D) {
            x_offset = x_offset / img_width;
            y_offset = y_offset / img_height;
        }
        float weight = gaussian(i, s) / sum;

        append_sprintf(&buffer_ptr, "ADD H0, fragment.texcoord[0], {%f, %f};\n", x_offset, y_offset) ;
        if (tex2D) {
            append_sprintf(&buffer_ptr, "TEX  H1, H0, texture[0], 2D;\n") ;
        } else {
            append_sprintf(&buffer_ptr, "TEX  H1, H0, texture[0], RECT;\n") ;
        }

        if (i==-n) {
            append_sprintf(&buffer_ptr, "MUL H2, H1, {%f}.x;\n", weight) ;
        } else {
            append_sprintf(&buffer_ptr, "MAD H2, H1, {%f}.x, H2;\n", weight) ;
        }
    }
    
    append_sprintf(&buffer_ptr, "MOV result.color.xyz, H2;\n") ;
    append_sprintf(&buffer_ptr, "END\n") ;
    
    return (unsigned char*)buffer ;
}