/    Sign up×
Community /Pin to ProfileBookmark

file converter

Hi guys Im a researcher and not a great coder and I need help on something.

I have created a c++ program that converts a file called .nxs (nexus) to a file cslled a .med (mega) … This works in dos and is real simple..

I would like to add this to my webpage now.
Im thinking along the lines of creating a VERY scaled down version of this site .. hxxp://www.cbs.dtu.dk/services/TargetP/

For example , browse for file, hit submit… and BAM pingo
either a window comes up asking where you want to save this new file or a new http window popup with the new file in txt format for ctting and pasteing onto notepad.

btw both file formats are very simple txt notepad text files that have slightly different formats.. we just usually edit in notepad and save with new file extension…

this is my C below to give you an idea of what im doing..

thanx guys
brian

#include <iomanip.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>

#define Max_Str_size 500

void main (int argc, char *argv[]) /* pickup command line arguments */
//void main()
{
system(“del tempin.nxs”);
system(“del tempout.nxs”);

if (argc > 3 ) {
FILE *streamIn;
FILE *
streamOut;
char tempNameIn[] = “tempin.nxs”; //temp filename
char tempNameOut[] = “tempout.meg”; //temp filename
int x;
char temp[Max_Str_size];
char *fptr1; // pointer for ‘=’
char *
fptr2; // pointer for ‘=’
char OutFileName[15];
char CommandStr[35];

//gotoxy(15,11);
//cout<< “Stand by try to read file “<< argv[1] << endl << endl;

strcpy(OutFileName, argv[1]);
fptr2 = strrchr(OutFileName, ‘.’); // find the last E in .EXE
OutFileName[fptr2 – OutFileName] = 0; // change it to null
strcat(OutFileName, “.meg”);
strcpy(CommandStr, “copy “);
strcat(CommandStr, argv[1]);
strcat(CommandStr, ” “);
strcat(CommandStr, tempNameIn);
//cout <<” CommandStr -> ” << CommandStr << endl;
system(CommandStr);

/*
cout <<” InFile Name -> ” << argv[1] << endl;
cout <<” OutFile Name -> ” << OutFileName << endl;
cout <<” Temp In File Name -> ” << tempNameIn << endl;
cout <<” Temp File Name -> ” << tempNameOut << endl;
*
/
clrscr();
gotoxy(15,11);
cout <<” Output File Name -> ” << OutFileName << endl;

if ((streamIn = fopen(tempNameIn, “r” )) == NULL) {
cout <<” File ” << tempNameIn << ” could not be opened”;
exit(1);
}

streamOut = fopen(tempNameOut, “w” ); // overwrite file

fprintf(streamOut,”#Megann”);

fprintf(streamOut,”!Title”);
for (x = 3; x < argc; x++) { // dump unwanted lines
fprintf(streamOut,” %s”, argv[x]);
}
fprintf(streamOut,”;n”); // end the command and line

fgets(temp, Max_Str_size, streamIn); // read in ditch the first line
fgets(temp, Max_Str_size, streamIn); // read in ditch the line
fgets(temp, Max_Str_size, streamIn); // read in
fptr1 = strchr(temp,’=’); // find char ‘=’
fptr1++; // move past ‘=’
//cout <<atoi(fptr1) << endl;

fptr2 = strchr(fptr1,’=’); // find char ‘=’
fptr2++; // move past ‘=’
fprintf(streamOut,”!Formatn”);
fprintf(streamOut,” DataType=%s DataFormat=Interleavedn”, argv[2]);
fprintf(streamOut,” NTaxa=%d NSites=%dn”, atoi(fptr1), atoi(fptr2));
fprintf(streamOut,” Identical=. Missing=? Indel=-n”);
fprintf(streamOut,” CodeTable=Standard;nnn”);
fprintf(streamOut,”!Domain=Data Property=Coding;n”);
for (x = 0; x < 6; x++) { // dump unwanted lines
fgets(temp, Max_Str_size, streamIn); // read in
//fputs(temp, streamOut); // write out
//cout <<temp;
}
while (temp[0] !=’;’) {
if (strlen(temp) > 2) fprintf(streamOut,”#%s”,temp);
else fprintf(streamOut,”%s”,temp);
fgets(temp, Max_Str_size, streamIn); // read in
}
fclose(streamIn);
fclose(streamOut);
// write a new suystem command
//strcat(OutFileName, “.meg”);
strcpy(CommandStr, “copy “);
strcat(CommandStr, tempNameOut);
strcat(CommandStr, ” “);
strcat(CommandStr, OutFileName);

//cout <<” CommandStr -> ” << CommandStr << endl;
system(CommandStr);

}

else {
clrscr();
system(“dir/b *.nxs”);
cout << “Syntax clst-meg [filename] [type (Nucleotide | Protein)] [Title]” << endl;
}
}

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CybIROFeb 19.2004 — Hi, Legman7.

I'm quite new in Javascript programming... however, I have a little experience programming for Web an non web applications.

I'd solve it this way.

I'd place 2 textfields: one to write the path of the input file and the second one to write the path of te output file.

Then, I'd convert your C++ code into a Javascript. All the "cout" statements might be replaced with

alert("and your message");

For the string functions, check the next URL [URL=http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/string.html#1193137]http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/string.html#1193137[/URL] .

You will find there functions for Strings in order tu substitute the string functions you used to use...

At the same site, you can search functions for file writing and reading...

Finally you can add a Submit button to execute, wich will call the main function. I think that, as your program... is very simple.

CybIRO
Copy linkTweet thisAlerts:
@johnwhatJun 26.2022 — is this a [online file converter](https://blog.media.io/image-converter/jpg-to-jpeg.html)
×

Success!

Help @legman7 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...