예제 #1
0
void process(List *from, List *to)
{
    List *l;


    /*
    ** Initialise read
    */
    open_for_read(from);
    open_for_write(to);

    l = read_header(from);
    write_header(to,l);
    destroy_list(l);

    /*
    ** Process Gels
    */
    for (l = read_gel_data(from);
	 !isNil(l);
	 l = read_gel_data(from)) {
	write_gel_data(to,l);
	destroy_list(l);
    }

    /*
    ** Process Contigs
    */
    for (l = read_contig_data(from);
	 !isNil(l);
	 l = read_contig_data(from)) {
	write_contig_data(to,l);
	destroy_list(l);
    }


    /*
    ** Tidy up read
    */
    close_files(from);
    close_files(to);
	
}
void gooda::gcov_file::open(const std::string& file){
    open_for_write(file);
}
예제 #3
0
double sound_overwrite(
  LVAL snd_expr,
  long n,
  unsigned char *filename,
  double offset_secs,
  long format,
  long mode,
  long bits,
  long swap,
  double *duration)
{
    LVAL result;       // the SOUND to be evaluated
    SF_INFO sf_info;   // info about the sound file
    double max_sample; // return value
    long ntotal;       // how many samples were overwritten
    /*
    long flags;
    */
    // first check if sound file exists, do not create new file
    FILE *file = NULL;
    if (ok_to_open((char *) filename, "rb"))
        file = fopen((char *) filename, "rb");
    // if not then fail
    if (!file) {
        *duration = 0;
        return 0.0;
    } else {
        fclose(file);
    }
    memset(&sf_info, 0, sizeof(sf_info));
    sf_info.format = lookup_format(format, mode, bits, swap);
    result = xleval(snd_expr);
    /* BE CAREFUL - DO NOT ALLOW GC TO RUN WHILE RESULT IS UNPROTECTED */
    if (vectorp(result)) {
        SNDFILE *sndfile;  // opened sound file 
        float *buf; // buffer for samples read in from sound file
        /* make sure all elements are of type a_sound */
        long i = getsize(result);
        long channels = i;
        while (i > 0) {
            i--;
            if (!exttypep(getelement(result, i), a_sound)) {
                xlerror("sound_save: array has non-sound element",
                         result);
            }
        }
        sndfile = open_for_write(filename, SFM_RDWR, format, &sf_info, channels,
                                 ROUND(getsound(getelement(result, 0))->sr),
                                 offset_secs, &buf);

        max_sample = sound_save_array(result, n, &sf_info, sndfile, 
                                      buf, &ntotal, NULL);
        *duration = ntotal / (double) sf_info.samplerate;
        free(buf);
        sf_close(sndfile);
    } else if (exttypep(result, a_sound)) {
        SNDFILE *sndfile;  // opened sound file 
        float *buf; // buffer for samples read in from sound file
        sndfile = open_for_write(filename, SFM_RDWR, format, &sf_info, 1, 
                                 ROUND(getsound(result)->sr), 
                                 offset_secs, &buf);
        max_sample = sound_save_sound(result, n, &sf_info, sndfile, buf, 
                                      &ntotal, NULL);
        *duration = ntotal / (double) sf_info.samplerate;
        free(buf);
        sf_close(sndfile);
    } else {
        xlerror("sound_save: expression did not return a sound",
                 result);
        max_sample = 0.0;
    }
    return max_sample;
}