size_t load_rectangle_to_file(int rect_id, struct cseq **sequences, int cseq_count)
{
    int i;
    size_t size;
    char tmpfilename[255];
    FILE *tmpfile;

    size = 0;
    sprintf(tmpfilename, "%s/rect%03d.cfa", outdirname, rect_id);
    tmpfile = fopen(tmpfilename, "w");
    if(!tmpfile)
        return 0;

    for(i = 0; i < cseq_count; i++) {
        cseq_write(tmpfile, sequences[i]);
        size += cseq_size(sequences[i]);
    }
    fclose(tmpfile);

    return size;
}
int main(int argc, char ** argv)
{
	const char *progname = "sand_compress_reads";
	FILE * infile;
	FILE * outfile;
	int quiet_mode = 0;
	struct seq *s;
	struct cseq *c;
	signed char d;
	int clip = 0;
	int internal = 0;
	char tmp_id[128];
	int count = 0;

		while((d=getopt(argc,argv,"cvqhi")) > -1) {
				switch(d) {
		case 'c':
			clip = 1;
			break;
		case 'i':
			internal = 1;
			break;
		case 'q':
			quiet_mode = 1;
			break;
		case 'v':
			cctools_version_print(stdout, progname);
			exit(0);
			break;
				case 'h':
		default:
						show_help(progname);
						exit(0);
						break;
				}
		}

	cctools_version_debug(D_DEBUG, argv[0]);

	if( optind<argc ) {
		infile = fopen(argv[optind], "r");
		if(!infile) {
			fprintf(stderr,"%s: couldn't open %s: %s\n",progname,argv[optind],strerror(errno));
			return 1;
		}
		optind++;
	} else {
		infile = stdin;
	}

	if( optind<argc ) {
		outfile = fopen(argv[optind],"w");
		if(!outfile) {
			fprintf(stderr,"%s: couldn't open %s: %s\n",progname,argv[optind],strerror(errno));
			return 1;
		}
		optind++;
	} else {
		outfile = stdout;
	}

	while((s = seq_read(infile))) {
		if(clip != 0 || internal != 0){
			strcpy(tmp_id, s->name);
			strcpy(s->name, strtok(tmp_id,","));
			if(internal != 0){
				strcpy(s->name, strtok(NULL,","));
			}
		}

		c = seq_compress(s);
		cseq_write(outfile,c);
		cseq_free(c);
		seq_free(s);
		count++;
	}

	if(!quiet_mode) {
		fprintf(stderr,"%d sequences compressed.\n",count);
	}

	fclose(infile);
	fclose(outfile);

	return 0;
}