コード例 #1
0
ファイル: test_gif_main.c プロジェクト: zzy-cv/graphics_plat
int gif_main_init() 
{
	int colors_num;
	unsigned char *colors;
	int Size;
	int i;

	/*  unsigned char *Buffer, *BufferP; */
	fp_gif = fopen(".\\res\\res_gif\\porsche.gif", "rb");  // "porsche.gif"  "jump.gif"  "gif_gril.gif" "460.gif"
	if(NULL == fp_gif)
	{
		assert(0);
	}
	if ((gif_file = DGifOpenFileHandle(fp_gif)) == NULL) 
	{
		assert(0);
	}

	colors_num = (1<<gif_file->SColorMap->BitsPerPixel);
	colors = gif_file->SColorMap->Colors;

	BackGround = gif_file->SBackGroundColor;
	ColorMap = (gif_file->Image.ColorMap ? gif_file->Image.ColorMap : gif_file->SColorMap);
	ColorMapSize = ColorMap->ColorCount;

	Size = gif_file->SWidth * sizeof(GifPixelType); 
  
	if ((GifRow = (GifRowType) mymalloc(Size)) == NULL)
	{
		assert(0); /* First row. */
	}
  
	for (i = 0; i < gif_file->SWidth; i++) 
	{
		GifRow[i] = gif_file->SBackGroundColor;
	}
	open_trace_file();
#if 0
	{
		int i=0;
		for(i=0; i<256;i++)
		{
			write_trace("", i);
			write_trace("   ", ColorMap->Colors[i].Red);
			write_trace("   ", ColorMap->Colors[i].Green);
			write_trace("   ", ColorMap->Colors[i].Blue);
		}
	}
#endif
}
コード例 #2
0
ファイル: traceType.c プロジェクト: svn2github/staden-io_lib
/*
 * Determine the trace type for file 'fn'.
 *
 * Returns:
 *     TT_SCF, TT_CTF, TT_ZTR, TT_ABI, TT_ALF, TT_BIO, or TT_PLN for success.
 *     TT_UNK for unknown type.
 *     TT_ERR for error.
 */
int determine_trace_type(char *fn)
{
    FILE *fp;
    int r;

#ifdef USE_BIOLIMS
    if(IS_BIOLIMS_PATH(fn))
      return TT_BIO;
#endif

    if ( (fp = open_trace_file(fn, NULL)) == NULL ) return TT_ERR;

    r = fdetermine_trace_type(fp);
    fclose(fp);

    return r;
}
コード例 #3
0
ファイル: rtkserver.c プロジェクト: ampimis/RtkGps
static jboolean RtkServer__rtksvrstart(JNIEnv* env, jclass thiz,
      jint j_cycle,
      jint j_buffsize,
      jintArray j_strs,
      jobjectArray j_paths,
      jintArray j_format,
      jint j_navsel,
      jobjectArray j_cmds,
      jobjectArray j_rcvopts,
      jint j_nmea_cycle,
      jint j_nmea_req,
      jdoubleArray j_nmeapos,
      jobject j_procopt,
      jobject j_solopt1,
      jobject j_solopt2
      ) {

   struct native_ctx_t *nctx;
   int i;
   jobject obj;
   jboolean res;

   /* Input stream types */
   int strs[8];
   /* input stream paths */
   const char *paths[8] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
   jstring paths_jstring[8] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
   /* input stream formats (STRFMT_???) */
   int format[3];
   /* input stream start commands */
   const char *cmds[3] = {NULL, NULL, NULL};
   jstring cmds_jstring[3] = {NULL, NULL, NULL};
   /* receiver options */
   const char *rcvopts[3] = {NULL, NULL, NULL};
   char *rcvopts_jstring[3] = {NULL, NULL, NULL};
   /* rtk processing options */
   prcopt_t prcopt;
   /* solution options */
   solopt_t solopt[2];
   /* nmea position */
   double nmeapos[3];

   res = JNI_FALSE;
   for (i=0; i<sizeof(paths)/sizeof(paths[0]); ++i) {
      paths_jstring[i] = (*env)->GetObjectArrayElement(env, j_paths, i);
      if ((*env)->ExceptionOccurred(env))
	 goto rtksvrstart_end;
      if (paths_jstring[i] != NULL) {
	 paths[i] = (*env)->GetStringUTFChars(env, paths_jstring[i], NULL);
	 if (paths[i] == NULL)
	    goto rtksvrstart_end;
      }
   }
   for (i=0; i<sizeof(cmds)/sizeof(cmds[0]); ++i) {
      cmds_jstring[i] = (*env)->GetObjectArrayElement(env, j_cmds, i);
      if ((*env)->ExceptionOccurred(env))
	 goto rtksvrstart_end;
      if (cmds_jstring[i] != NULL) {
	 cmds[i] = (*env)->GetStringUTFChars(env, cmds_jstring[i], NULL);
	 if (cmds[i] == NULL)
	    goto rtksvrstart_end;
      }
   }
   for (i=0; i<sizeof(rcvopts)/sizeof(rcvopts[0]); ++i) {
      rcvopts_jstring[i] = (*env)->GetObjectArrayElement(env, j_rcvopts, i);
      if ((*env)->ExceptionOccurred(env))
	 goto rtksvrstart_end;
      if (rcvopts_jstring[i] != NULL) {
	 rcvopts[i] = (*env)->GetStringUTFChars(env, rcvopts_jstring[i], NULL);
	 if (rcvopts[i] == NULL)
	    goto rtksvrstart_end;
      }
   }

   (*env)->GetIntArrayRegion(env, j_strs, 0,
	 sizeof(strs)/sizeof(strs[0]), strs);
   if ((*env)->ExceptionOccurred(env))
      goto rtksvrstart_end;

   (*env)->GetIntArrayRegion(env, j_format, 0,
	 sizeof(format)/sizeof(format[0]), format);
   if ((*env)->ExceptionOccurred(env))
      goto rtksvrstart_end;

   (*env)->GetDoubleArrayRegion(env, j_nmeapos, 0,
	 sizeof(nmeapos)/sizeof(nmeapos[0]), nmeapos);
   if ((*env)->ExceptionOccurred(env))
      goto rtksvrstart_end;

   solution_options2solopt_t(env, j_solopt1, &solopt[0]);
   solution_options2solopt_t(env, j_solopt2, &solopt[1]);

   nctx = (struct native_ctx_t *)(uintptr_t)(*env)->GetLongField(env, thiz, m_object_field);
   if (nctx == NULL) {
      LOGV("nctx is null");
      goto rtksvrstart_end;
   }

   {
      /* Open trace / solution files */
      gtime_t now;
      now = timeget();
      if (solopt[0].trace > 0)
	 open_trace_file(env, solopt[0].trace, now);

      /* treat processing options only now for having trace */
      processing_options2prcopt_t(env, j_procopt, &prcopt);

      if (solopt[0].sstat > 0)
	 open_solution_status_file(env, solopt[0].sstat, now);
   }

   if ((*env)->ExceptionOccurred(env))
      goto rtksvrstart_end;

    char errmsg[2048]="";                       //  Modif Mathieu Peyréga : adapt to new 2.4.3b26 API
    char *cmds_periodic[]={NULL,NULL,NULL};     //  Modif Mathieu Peyréga : adapt to new 2.4.3b26 API

   if (!rtksvrstart(
	    &nctx->rtksvr,
	    /* SvrCycle ms */ j_cycle,
	    /* SvrBuffSize */ j_buffsize,
	    /* stream types */ strs,
	    /* paths */ (char **)paths,
	    /* input stream format */ format,
	    /* NavSelect */ j_navsel,
	    /* input stream start commands */ (char **)cmds,
        /* input stream periodic  commands */ (char **)cmds_periodic,   //  Modif Mathieu Peyréga : adapt to new 2.4.3b26 API
	    /* receiver options */ (char **)rcvopts,
	    /* nmea request cycle ms */ j_nmea_cycle,
	    /* nmea request type */ j_nmea_req,
	    /* transmitted nmea position  */ nmeapos,
	    /* rtk processing options */&prcopt,
	    /* solution options */ solopt,
	    /* monitor stream */ &nctx->monistr,
        /* err */errmsg                                                  //  Modif Mathieu Peyréga : adapt to new 2.4.3b26 API
	    )) {
   }else {
      res = JNI_TRUE;
   }

rtksvrstart_end:

   for (i=0; i<sizeof(paths)/sizeof(paths[0]); ++i) {
      if (paths[i] != NULL)
	 (*env)->ReleaseStringUTFChars(env, paths_jstring[i], paths[i]);
   }
   for (i=0; i<sizeof(cmds)/sizeof(cmds[0]); ++i) {
      if (cmds[i] != NULL)
	 (*env)->ReleaseStringUTFChars(env, cmds_jstring[i], cmds[i]);
   }
   for (i=0; i<sizeof(rcvopts)/sizeof(rcvopts[0]); ++i) {
      if (rcvopts[i] != NULL)
	 (*env)->ReleaseStringUTFChars(env, rcvopts_jstring[i], rcvopts[i]);
   }

   if (!res) {
      traceclose();
      rtkclosestat();
   }

   return res;
}
コード例 #4
0
ファイル: init_exp.c プロジェクト: svn2github/staden-master
int convert(char *file, int format, mFILE *ofp, char *name, int output_conf) {
    Read *r;
    Exp_info *e;
    char buf[50];
    double aq;

    if (format == TT_BIO) {
        if (NULL == (r = read_reading(file, format))) {
            fprintf(stderr, "%s: failed to read\n", file);
            return 1;
        }
    } else {
        FILE *infp;
        if (NULL == (infp = open_trace_file(file, NULL))) {
            perror(file);
            return 1;
        }
        if (NULL == (r = fread_reading(infp, file, format))) {
            fprintf(stderr, "%s: failed to read\n", file);
            return 1;
        }
        fclose(infp);
    }

    e = read2exp(r, name);
    if (NULL == e) {
        fprintf(stderr, "Failed to create experiment file.\n");
        read_deallocate(r);
        return 1;
    }

    sprintf(buf, "%f", aq = avg_qual(r));
    exp_set_entry(e, EFLT_AQ, buf);
    exp_print_mfile(ofp, e);

    if (output_conf && aq != 0) {
        char *cstr;
        int1 *conf;
        int i;

        conf = xmalloc(r->NBases * sizeof(*conf));
        cstr = xmalloc(5 * r->NBases+2);
        for (i = 0; i < r->NBases; i++) {
            switch (r->base[i]) {
            case 'a':
            case 'A':
                conf[i] = r->prob_A[i];
                break;
            case 'c':
            case 'C':
                conf[i] = r->prob_C[i];
                break;
            case 'g':
            case 'G':
                conf[i] = r->prob_G[i];
                break;
            case 't':
            case 'T':
                conf[i] = r->prob_T[i];
                break;
            default:
                conf[i] = (r->prob_A[i] +
                           r->prob_C[i] +
                           r->prob_G[i] +
                           r->prob_T[i]) / 4;
                break;
            }
        }

        conf2str(conf, r->NBases, cstr);
        exp_set_entry(e, EFLT_AV, cstr);

        xfree(cstr);
        xfree(conf);
    }

    read_deallocate(r);
    exp_destroy_info(e);

    mfflush(ofp);

    return 0;
}
コード例 #5
0
ファイル: vscript.c プロジェクト: stevexu01/curl-loader
V_EXPORT VSCRIPT_STATUS VSCRIPT_CL_compile_to_bytecode(VSCRIPT_CL_CTX *ctx, const char *source_file, VSCRIPTXLIB *extlib)
{
    VSCRIPT_STATUS ret;
    FILE *fp;
    int rt;
    AST_BASE *ast;

    vscript_ctx = (VSCRIPTCTX *) ctx;
    vscript_ctx->extension_library = (struct tagXMETHODLIB *) extlib;

    if ( MY_YY_open_file( source_file ) ) {
        fprintf( stderr, "Can't open file %s\n", source_file );
        return VSCRIPT_STATUS_CL_NO_INPUT_ERROR;
    }

    /* ********************************************** *
    			parsing
     * ********************************************** */
    ret = MY_YY_parse(&ast);

    switch(ret) {
    case MY_YY_PARSE_STATUS_OK:
    {
        if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_TRACE) {
            fprintf(stdout,"*** syntax ok ***\n");
        }

        if (! VTREE_check_tree( &vscript_ctx->my_ast_root->node )) {
            if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_TRACE) {
                fprintf(stdout,"*** ERROR: parse tree is not ok ***\n");
            }
            return VSCRIPT_STATUS_INTERNAL_ERROR;
        }

        if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_DUMP_AST) {

            FILE *fp = open_trace_file(source_file, TRACE_FILE_AST);
            if (fp) {
                MY_YY_dump_as_xml( fp, vscript_ctx->my_ast_root );
                fclose(fp);
            }
        }
    }
    break;

    case MY_YY_PARSE_STATUS_SYNTAX_ERROR:
        if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_TRACE) {
            fprintf(stderr,"*** ERROR: some kind of syntax error ***\n");
        }
        return VSCRIPT_STATUS_CL_SYNTAX_ERROR;

    default:
        if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_TRACE) {
            fprintf(stderr,"*** internal parser error (%d) ***\n",ret);
        }
        return VSCRIPT_STATUS_INTERNAL_ERROR;
    }

    /* ********************************************** *
    			semantics check / code gen
     * ********************************************** */
    if (!MY_YY_code_gen( vscript_ctx->my_ast_root )) {
        if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_TRACE) {
            fprintf(stdout,"*** semantics and code generation ok ***\n");
        }
    } else {
        if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_TRACE) {
            fprintf(stderr,"*** ERROR semantics or code generation ***\n");
        }
        return VSCRIPT_STATUS_CL_SEMANTIC_OR_CODEGEN_ERROR;
    }

    if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_DUMP_LISTING) {

        FILE *fp = open_trace_file( source_file, TRACE_FILE_LISTING);
        if (fp) {
            ASM_CONSTANT_POOL_dump(fp, vscript_ctx);
            ASM_write_listing(fp, vscript_ctx->my_code );
            fclose(fp);
        }
    }

    /* ********************************************** *
    		link back references in opcodes
     * ********************************************** */
    //resolution of back references (now that all locations are set)
    if (!ASM_resolve_backrefs( vscript_ctx->my_code )) {
        if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_TRACE) {
            fprintf(stderr,"*** resolving back references ok ***\n");
        }

    } else {
        if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_TRACE) {
            fprintf(stderr,"*** ERROR resolving back references ***\n");
        }
        return VSCRIPT_STATUS_CL_BACKREF_ERROR;
    }


    if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_DUMP_LISTING_LINKED) {

        FILE *fp = open_trace_file(source_file, TRACE_FILE_LISTING_RESOLVED);
        if (fp) {
            ASM_CONSTANT_POOL_dump(fp, vscript_ctx);
            ASM_write_listing(fp, vscript_ctx->my_code );
            fclose(fp);
        }
    }

    /* ********************************************** *
    		write executable file
     * ********************************************** */

    fp = open_trace_file( source_file, TRACE_FILE_OUTPUT_FILE);
    if (!fp) {
        return VSCRIPT_STATUS_CL_WRITE_EXE_ERROR;
    }
    rt = EXE_write_exe_file( fp, vscript_ctx );
    fclose(fp);
    if (!rt) {
        if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_TRACE) {
            fprintf(stderr,"*** write exe file ok ***\n");
        }
    } else {
        if (vscript_ctx->trace_opts & VSCRIPT_CL_DEBUG_TRACE) {
            fprintf(stderr,"*** ERROR write exe file ***\n");
        }
        return VSCRIPT_STATUS_CL_WRITE_EXE_ERROR;
    }

    return VSCRIPT_STATUS_OK;
}
コード例 #6
0
/*
 * ---------------------------------------------------------------------------
 * Loads confidence values from the trace file and averages them.
 * 'opos' is optional - if not known then set to NULL.
 *
 * Returns 0 for success
 *        -1 for failure
 */
int get_read_conf(Exp_info *e, int length, int2 *opos, int1 *conf) {
    int ttype, i;
    FILE *fp;
    uint_1 *prob_A, *prob_C, *prob_G, *prob_T;
    char *seq;
    float scf_version;
    int nbases = 0;

    /* Sanity check */
    if (!(exp_Nentries(e,EFLT_LT) && exp_Nentries(e,EFLT_LN)))
	return -1;

    /* Find and load trace file */
    ttype = trace_type_str2int(exp_get_entry(e, EFLT_LT));

    if (ttype != TT_SCF &&
	ttype != TT_ZTR)
	return -1;

    /*
     * We only support direct reading accuracy values from SCF files.
     * Otherwise we have to take a slower approach.
     */
    if (ttype != TT_SCF) {
	Read *r;
	int sec = read_sections(0);
	read_sections(READ_BASES);

	if (NULL == (r = read_reading(exp_get_entry(e,EFLT_LN), TT_ANYTR))) {
	    read_sections(sec);
	    return -1;
	}

	prob_A = (int1 *)xmalloc(r->NBases);
	prob_C = (int1 *)xmalloc(r->NBases);
	prob_G = (int1 *)xmalloc(r->NBases);
	prob_T = (int1 *)xmalloc(r->NBases);
	seq    = (char *)xmalloc(r->NBases);

	memcpy(prob_A, r->prob_A, r->NBases);
	memcpy(prob_C, r->prob_C, r->NBases);
	memcpy(prob_G, r->prob_G, r->NBases);
	memcpy(prob_T, r->prob_T, r->NBases);
	memcpy(seq,    r->base,   r->NBases);

	nbases = r->NBases;

	read_deallocate(r);
	read_sections(sec);

    } else {
	Header h;
	/* For SCF files we read directly - the above code would also do. */

	if (NULL == (fp = open_trace_file(exp_get_entry(e,EFLT_LN), NULL)))
	    return -1;

	/* Read the SCF header */
	if (-1 == read_scf_header(fp, &h))
	    return -1;
	scf_version = scf_version_str2float(h.version);
	nbases = h.bases;

	/* Alloc memory */
	prob_A = (uint_1 *)xmalloc(h.bases * sizeof(*prob_A));
	prob_C = (uint_1 *)xmalloc(h.bases * sizeof(*prob_A));
	prob_G = (uint_1 *)xmalloc(h.bases * sizeof(*prob_A));
	prob_T = (uint_1 *)xmalloc(h.bases * sizeof(*prob_A));
	seq    = (char   *)xmalloc(h.bases * sizeof(*seq));
	if (NULL == prob_A ||
	    NULL == prob_C ||
	    NULL == prob_G ||
	    NULL == prob_T ||
	    NULL == seq)
	    return -1;

	/* Load base scores */
	if (scf_version >= 3.0) {
	    /*
	     * Version 3 base format:
	     * num_bases * 4byte peak index
	     * num_bases * prob_A
	     * num_bases * prob_C
	     * num_bases * prob_G
	     * num_bases * prob_T
	     * num_bases * base
	     * num_bases * spare (x3)
	     */
	    fseek(fp, (off_t)h.bases_offset + 4 * h.bases, SEEK_SET);
	    if (h.bases != fread(prob_A, 1, h.bases, fp))
		return -1;
	    if (h.bases != fread(prob_C, 1, h.bases, fp))
		return -1;
	    if (h.bases != fread(prob_G, 1, h.bases, fp))
		return -1;
	    if (h.bases != fread(prob_T, 1, h.bases, fp))
		return -1;
	    if (h.bases != fread(seq, 1, h.bases, fp))
		return -1;
	} else {
	    int i;
	    uint_1 buf[12];

	    /*
	     * Version 2 base format
	     * num_bases * base_struct,  where base_struct is 12 bytes:
	     *     0-3 peak_index
	     *     4-7 prob_A/C/G/T
	     *     8   base
	     *     9-  spare
	     */
	    fseek(fp, (off_t)h.bases_offset, SEEK_SET);

	    for (i = 0; (unsigned)i < h.bases; i++) {
		if (1 != fread(buf, 12, 1, fp))
		    return -1;
		prob_A[i] = buf[4];
		prob_C[i] = buf[5];
		prob_G[i] = buf[6];
		prob_T[i] = buf[7];
		seq[i]    = buf[8];
	    }
	}

	fclose(fp);
    }

    /* Determine confidence values */
    if (opos) {
	for (i=0; i<length; i++) {
	    if (opos[i] == 0) {
		/* Inserted base, change to 0% */
		conf[i] = 0;
	    } else {
		switch(seq[opos[i]-1]) {
		case 'a':
		case 'A':
		    conf[i] = prob_A[opos[i]-1];
		    break;
		case 'c':
		case 'C':
		    conf[i] = prob_C[opos[i]-1];
		    break;
		case 'g':
		case 'G':
		    conf[i] = prob_G[opos[i]-1];
		    break;
		case 't':
		case 'T':
		    conf[i] = prob_T[opos[i]-1];
		    break;
		default:
		    conf[i] = 2;
		}
	    }
	}
    } else {
	int mlength = MIN(length, nbases);

	for (i=0; i < mlength; i++) {
	    switch(seq[i]) {
	    case 'a':
	    case 'A':
		conf[i] = prob_A[i];
		break;
	    case 'c':
	    case 'C':
		conf[i] = prob_C[i];
		break;
	    case 'g':
	    case 'G':
		conf[i] = prob_G[i];
		break;
	    case 't':
	    case 'T':
		conf[i] = prob_T[i];
		break;
	    case 'n':
	    case 'N':
	    case '-':
		conf[i] = (prob_A[i] + prob_C[i] + prob_G[i] + prob_T[i]) / 4;
		break;
	    default:
		conf[i] = 2;
	    }
	}
	for (; i < length; i++)
	    conf[i] = 2;
    }

    xfree(prob_A);
    xfree(prob_C);
    xfree(prob_G);
    xfree(prob_T);
    xfree(seq);

    return 0;
}
コード例 #7
0
ファイル: trace_main.c プロジェクト: lanian09/mysource
int trace_main(char *hostIp, int portNum, char *imsi, int outflag, char *path)
{
	int				fd_stdin, peersock, maxfd, status, readsize;
	int				selStatus;
	fd_set			fdset_Read;
	FILE			*fp = NULL;
	char			buff[128];
	struct timeval	timeout;

	fd_stdin = fileno(stdin);

	peersock = connect_to_peer(hostIp, portNum);
	if(peersock < 0)
		return 1;

	if(outflag){
		fp = open_trace_file(path, imsi);
		if(!fp)
			exit(1);
	}

	timeout.tv_sec = 0;
	timeout.tv_usec = 100;

	while(1){
		FD_ZERO(&fdset_Read);
		FD_SET(fd_stdin, &fdset_Read);
		FD_SET(peersock, &fdset_Read);
		maxfd = (fd_stdin >= peersock)?fd_stdin:peersock;
		maxfd += 1;

		selStatus = select(maxfd, &fdset_Read, NULL, NULL, &timeout);
		if(selStatus < 0){
			fprintf(stderr, "[ERROR] select - %s\n", strerror(errno));
		}else if(selStatus > 0){
			if(FD_ISSET(fd_stdin, &fdset_Read)){
				memset(buff, 0x00, sizeof(buff));
				read_from_fd(fd_stdin, buff, 1);
				if(buff[0] == 'q' || buff[0] == 'Q'){
					close(peersock);
					fclose(fp);
					return 1;
				}
			}
			if(FD_ISSET(peersock, &fdset_Read)){
				status = read_trace(peersock, fp, imsi);
				if(status < 0){
					// try to reconnect to peer.
					peersock = connect_to_peer(hostIp, portNum);
					if(peersock < 0)
						return 1;
				}
			}
		}
#ifdef DEBUG_1
		else{
			printf(".");
		}
#endif
	}

	return 0;

}