本文发表在 rolia.net 枫下论坛#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define MAXIMAGES 300
#define LINELENGTH 100
#define TRUE 1
#define FALSE 0
void write_symmetric_pair(char *file_in, char *file_out)
{
FILE *fp1, *fp2;
char line[300];
float x1, y1, x2, y2;
int length;
printf("Pair in %s \nout %s\n", file_in, file_out);
length = strlen(file_in);
while (!isalpha(file_in[length]))
file_in[length--] = 0;
length = strlen(file_out);
while (!isalpha(file_out[length]))
file_out[length--] = 0;
fp1 = fopen(file_in, "r");
if (fp1 == NULL) {puts("Failed in"); return;}
fp2 = fopen(file_out, "w");
if (fp2 == NULL) {puts("Failed out"); return;}
while (fgets(line, LINELENGTH, fp1)) {
sscanf(line,"%f %f %f %f\n", &x1, &y1, &x2, &y2);
fprintf(fp2, "%f %f %f %f\n", x2, y2, x1, y1);
}
fclose(fp1);
fclose(fp2);
}
void write_symmetric_triple(char *file_in, char *file_out)
{
FILE *fp1, *fp2;
char line[300];
float x1, y1, x2, y2, x3, y3;
int length;
printf("Pair in %s \nout %s\n", file_in, file_out);
length = strlen(file_in);
while (!isalpha(file_in[length]))
file_in[length--] = 0;
length = strlen(file_out);
while (!isalpha(file_out[length]))
file_out[length--] = 0;
fp1 = fopen(file_in, "r");
if (fp1 == NULL) {puts("Failed in"); return;}
fp2 = fopen(file_out, "w");
if (fp2 == NULL) {puts("Failed out"); return;}
while (fgets(line, LINELENGTH, fp1)) {
sscanf(line, "%f %f %f %f %f %f\n", &x1, &y1, &x2, &y2, &x3, &y3);
fprintf(fp2, "%f %f %f %f %f %f\n", x3, y3, x2, y2, x1, y1);
}
fclose(fp1);
fclose(fp2);
}
main(int argc, char *argv[])
{
char line[LINELENGTH];
char fname[300];
char command_filename[300], postamble[300], ftype1[10], ftype2[10], ftype3[10], number[300], c;
char preamble1[300], preamble2[300], preamble3[300], outstring[300];
int number1, number2, number3;
int index, i, j, k, l;
FILE *fp1, *fp2;
int lengthtwo = FALSE;
int tempIndex;
printf("Argc %d\n", argc);
if (argc == 1) {
puts("symmetric <file list>");
exit(2);
}
printf("Argc %d\n", argc);
/* get file list and optional args for the compFM */
puts("Arg 1");
puts(argv[1]); puts("\n");
strcpy(fname, argv[1]);
strcpy(command_filename, fname);
fp1 = fopen(fname, "r");
printf("Command filename %s\n", command_filename);
while (fgets(line, LINELENGTH, fp1)) {
lengthtwo = FALSE;
printf("Filename %s\n", line);
//sscanf(line, "[^-]%d.%s-%s-%d.%s.%s\n", preamble1, &number1, ftype1, preamble2, &number2, ftype2, postamble);
//printf("Preamble1 %s number1 %d ftype1 %s preamble2 %s number2 %d ftype2 %s postamble %s\n",
// preamble1, number1, ftype1, preamble2, number2, ftype2, postamble);
/* get first sequence */
index = 0;
i = 0;
while ((c = line[index++]) != '-' && c != 0 && c!='.') {
if(!isdigit(c))
preamble1[i++] = c;
}
preamble1[i++] = 0;
printf("Preamble1 %s\n", preamble1);
if (c == 0) {
strcpy(postamble, preamble1);
printf("postamble %s\n", postamble);
} else {
i = 0; index=0;
while ((c = line[index++]) != '.' ){
if(isdigit(c))
number[i++] = c;
}
number[i] = 0;
printf("Number %s\n", number);
number1 = atoi(number);
ftype1[0] = line[index++]; ftype1[1] = line[index++];
ftype1[2] = line[index++]; ftype1[3] = 0;
printf("File type 1 %s\n", ftype1);
}
line[index++];
tempIndex=index; //Save the begining position of the second image file name
i = 0;
while ((c = line[index++]) != '-' && c != 0 && c!= '.') {
if(!isdigit(c))
preamble2[i++] = c;
}
preamble2[i++] = 0;
printf("Preamble2 %s\n", preamble2);
if (c == 0) {
strcpy(postamble, preamble2);
printf("postamble %s\n", postamble);
} else {
i = 0; index = tempIndex; //Restore the saved position
while ((c = line[index++]) != '.'){
if(isdigit(c))
number[i++] = c;
}
number[i] = 0;
printf("Number %s\n", number);
number2 = atoi(number);
ftype2[0] = line[index++]; ftype2[1] = line[index++];
ftype2[2] = line[index++]; ftype2[3] = 0;
printf("File type 2 %s\n", ftype2);
printf("is left %s\n", &line[index]);
if (line[index] == '-') index++;
}
//line[index++];
tempIndex=index; //Save the begining position of the third image file name
i = 0;
while ((c = line[index++]) != '-' && c != 0 && c!='.' ) {
if(!isdigit(c)) {
preamble3[i++] = c;
printf("Char %d\n", c);
}
}
preamble3[i++] = 0;
//if (preamble3[0]!=0) {
lengthtwo = FALSE;
printf("Preamble3 %s\n", preamble3);
if (c == 0) {
strcpy(postamble, preamble3);
printf("postamble %s\n", postamble);
lengthtwo = TRUE;
} else {
i = 0; index = tempIndex; //Restore the saved position
while ((c = line[index++]) != '.') {
if(isdigit(c))
number[i++] = c;
}
number[i] = 0;
printf("Number %s\n", number);
number3 = atoi(number);
ftype3[0] = line[index++]; ftype3[1] = line[index++];
ftype3[2] = line[index++]; ftype3[3] = 0;
printf("File type 3 %s\n", ftype3);
}
// }// End of " if (preamble3[0]!=0) { "
if (lengthtwo) { //length = two, symmetricing FMmatches
printf("Length two\n");
printf("%s%d.%s-%s%d.%s%s\n",preamble2, number2, ftype2, preamble1, number1, ftype1, postamble);
sprintf(outstring, "%s%d.%s-%s%d.%s%s\n",preamble2, number2, ftype2, preamble1, number1, ftype1, postamble);
write_symmetric_pair(line, outstring);
}
else { //length != two , symmetricing TMmatches
i = 0;
while ((c = line[index++]) != '-' && c != 0) {
postamble[i++] = c;
}
postamble[i++] = 0;
printf("final Postamble3 %s\n", postamble);
printf("Length three\n");
printf("%s%d.%s-%s%d.%s-%s%d.%s%s\n",
preamble3, number3, ftype3, preamble2, number2, ftype2, preamble1, number1, ftype1, postamble);
sprintf(outstring, "%s%d.%s-%s%d.%s-%s%d.%s%s\n",
preamble3, number3, ftype3, preamble2, number2, ftype2, preamble1, number1, ftype1, postamble);
write_symmetric_triple(line, outstring);
}
}
fclose(fp1);
}更多精彩文章及讨论,请光临枫下论坛 rolia.net
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define MAXIMAGES 300
#define LINELENGTH 100
#define TRUE 1
#define FALSE 0
void write_symmetric_pair(char *file_in, char *file_out)
{
FILE *fp1, *fp2;
char line[300];
float x1, y1, x2, y2;
int length;
printf("Pair in %s \nout %s\n", file_in, file_out);
length = strlen(file_in);
while (!isalpha(file_in[length]))
file_in[length--] = 0;
length = strlen(file_out);
while (!isalpha(file_out[length]))
file_out[length--] = 0;
fp1 = fopen(file_in, "r");
if (fp1 == NULL) {puts("Failed in"); return;}
fp2 = fopen(file_out, "w");
if (fp2 == NULL) {puts("Failed out"); return;}
while (fgets(line, LINELENGTH, fp1)) {
sscanf(line,"%f %f %f %f\n", &x1, &y1, &x2, &y2);
fprintf(fp2, "%f %f %f %f\n", x2, y2, x1, y1);
}
fclose(fp1);
fclose(fp2);
}
void write_symmetric_triple(char *file_in, char *file_out)
{
FILE *fp1, *fp2;
char line[300];
float x1, y1, x2, y2, x3, y3;
int length;
printf("Pair in %s \nout %s\n", file_in, file_out);
length = strlen(file_in);
while (!isalpha(file_in[length]))
file_in[length--] = 0;
length = strlen(file_out);
while (!isalpha(file_out[length]))
file_out[length--] = 0;
fp1 = fopen(file_in, "r");
if (fp1 == NULL) {puts("Failed in"); return;}
fp2 = fopen(file_out, "w");
if (fp2 == NULL) {puts("Failed out"); return;}
while (fgets(line, LINELENGTH, fp1)) {
sscanf(line, "%f %f %f %f %f %f\n", &x1, &y1, &x2, &y2, &x3, &y3);
fprintf(fp2, "%f %f %f %f %f %f\n", x3, y3, x2, y2, x1, y1);
}
fclose(fp1);
fclose(fp2);
}
main(int argc, char *argv[])
{
char line[LINELENGTH];
char fname[300];
char command_filename[300], postamble[300], ftype1[10], ftype2[10], ftype3[10], number[300], c;
char preamble1[300], preamble2[300], preamble3[300], outstring[300];
int number1, number2, number3;
int index, i, j, k, l;
FILE *fp1, *fp2;
int lengthtwo = FALSE;
int tempIndex;
printf("Argc %d\n", argc);
if (argc == 1) {
puts("symmetric <file list>");
exit(2);
}
printf("Argc %d\n", argc);
/* get file list and optional args for the compFM */
puts("Arg 1");
puts(argv[1]); puts("\n");
strcpy(fname, argv[1]);
strcpy(command_filename, fname);
fp1 = fopen(fname, "r");
printf("Command filename %s\n", command_filename);
while (fgets(line, LINELENGTH, fp1)) {
lengthtwo = FALSE;
printf("Filename %s\n", line);
//sscanf(line, "[^-]%d.%s-%s-%d.%s.%s\n", preamble1, &number1, ftype1, preamble2, &number2, ftype2, postamble);
//printf("Preamble1 %s number1 %d ftype1 %s preamble2 %s number2 %d ftype2 %s postamble %s\n",
// preamble1, number1, ftype1, preamble2, number2, ftype2, postamble);
/* get first sequence */
index = 0;
i = 0;
while ((c = line[index++]) != '-' && c != 0 && c!='.') {
if(!isdigit(c))
preamble1[i++] = c;
}
preamble1[i++] = 0;
printf("Preamble1 %s\n", preamble1);
if (c == 0) {
strcpy(postamble, preamble1);
printf("postamble %s\n", postamble);
} else {
i = 0; index=0;
while ((c = line[index++]) != '.' ){
if(isdigit(c))
number[i++] = c;
}
number[i] = 0;
printf("Number %s\n", number);
number1 = atoi(number);
ftype1[0] = line[index++]; ftype1[1] = line[index++];
ftype1[2] = line[index++]; ftype1[3] = 0;
printf("File type 1 %s\n", ftype1);
}
line[index++];
tempIndex=index; //Save the begining position of the second image file name
i = 0;
while ((c = line[index++]) != '-' && c != 0 && c!= '.') {
if(!isdigit(c))
preamble2[i++] = c;
}
preamble2[i++] = 0;
printf("Preamble2 %s\n", preamble2);
if (c == 0) {
strcpy(postamble, preamble2);
printf("postamble %s\n", postamble);
} else {
i = 0; index = tempIndex; //Restore the saved position
while ((c = line[index++]) != '.'){
if(isdigit(c))
number[i++] = c;
}
number[i] = 0;
printf("Number %s\n", number);
number2 = atoi(number);
ftype2[0] = line[index++]; ftype2[1] = line[index++];
ftype2[2] = line[index++]; ftype2[3] = 0;
printf("File type 2 %s\n", ftype2);
printf("is left %s\n", &line[index]);
if (line[index] == '-') index++;
}
//line[index++];
tempIndex=index; //Save the begining position of the third image file name
i = 0;
while ((c = line[index++]) != '-' && c != 0 && c!='.' ) {
if(!isdigit(c)) {
preamble3[i++] = c;
printf("Char %d\n", c);
}
}
preamble3[i++] = 0;
//if (preamble3[0]!=0) {
lengthtwo = FALSE;
printf("Preamble3 %s\n", preamble3);
if (c == 0) {
strcpy(postamble, preamble3);
printf("postamble %s\n", postamble);
lengthtwo = TRUE;
} else {
i = 0; index = tempIndex; //Restore the saved position
while ((c = line[index++]) != '.') {
if(isdigit(c))
number[i++] = c;
}
number[i] = 0;
printf("Number %s\n", number);
number3 = atoi(number);
ftype3[0] = line[index++]; ftype3[1] = line[index++];
ftype3[2] = line[index++]; ftype3[3] = 0;
printf("File type 3 %s\n", ftype3);
}
// }// End of " if (preamble3[0]!=0) { "
if (lengthtwo) { //length = two, symmetricing FMmatches
printf("Length two\n");
printf("%s%d.%s-%s%d.%s%s\n",preamble2, number2, ftype2, preamble1, number1, ftype1, postamble);
sprintf(outstring, "%s%d.%s-%s%d.%s%s\n",preamble2, number2, ftype2, preamble1, number1, ftype1, postamble);
write_symmetric_pair(line, outstring);
}
else { //length != two , symmetricing TMmatches
i = 0;
while ((c = line[index++]) != '-' && c != 0) {
postamble[i++] = c;
}
postamble[i++] = 0;
printf("final Postamble3 %s\n", postamble);
printf("Length three\n");
printf("%s%d.%s-%s%d.%s-%s%d.%s%s\n",
preamble3, number3, ftype3, preamble2, number2, ftype2, preamble1, number1, ftype1, postamble);
sprintf(outstring, "%s%d.%s-%s%d.%s-%s%d.%s%s\n",
preamble3, number3, ftype3, preamble2, number2, ftype2, preamble1, number1, ftype1, postamble);
write_symmetric_triple(line, outstring);
}
}
fclose(fp1);
}更多精彩文章及讨论,请光临枫下论坛 rolia.net