The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Import ascii-file into a note window

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Septor Posted - 08/04/2004 : 08:08:32 AM
I have an Ascii-File with a Header and i only want the header in my note window. At the moment i use:

%B=Path; %A=Filename
LT_execute("open -n %B %A");

it opens the whole File. I only need the first 17.
Is there nothing like:

ASCIMP ascimp;
if(AscImpReadFileStruct(strFile,&ascimp)!=0)
{
out_str("cannot read " + strFile);
return;
}
ascimp.iHeaderLines = 0;
ascimp.iSubHeaderLines = 0;
ascimp.iAutoSubHeaderLines=0;

Note note;
note.Create();
note.ImportASCII(strFile, ascimp);

that only works with worksheets.
i use origin 7.0
thx
10   L A T E S T    R E P L I E S    (Newest First)
easwar Posted - 08/10/2004 : 12:02:26 PM
Hi,

To view all ASCIMP settings stored in the current worksheet, you can use an OC function such as below:

Easwar
OriginLab



// If you have version 7.5, then can use code such as below
// that uses a tree for getting and dumping the structure
//
void pg_dump_ascimp()
{
// Declare worksheet using active layer
Worksheet wks = Project.ActiveLayer();
if( !wks )
{
printf("Active layer is not a worksheet!\n");
return;
}

// Get ASCIMP structure from worksheet and dump it
ASCIMP ascimp;
wks.GetASCIMP(ascimp);
Tree tr;
tr = ascimp;
out_tree(tr);
}
//
//
//
//
//
// If you have version 7.0, then you can use the following function:
//
void pg_dump_ascimp()
{
// Declare worksheet using active layer
Worksheet wks = Project.ActiveLayer();
if( !wks )
{
printf("Active layer is not a worksheet!\n");
return;
}

// Get ASCIMP structure from worksheet
ASCIMP ascimp;
wks.GetASCIMP(ascimp);

// Dump all ASCIMP properties
printf( "\nASCIMP Settings in current worksheet layer:\n\n" );
printf( "ascimp.iDelimited \t= %d\n", ascimp.iDelimited );
printf( "ascimp.iDelimiter \t= %d\n", ascimp.iDelimiter );
printf( "ascimp.cChar \t\t= %d\n", ascimp.cChar );
printf( "ascimp.szFixedWidth \t= \"%s\"\n", ascimp.szFixedWidth );
printf( "ascimp.iHeaderLines \t= %d\n", ascimp.iHeaderLines );
printf( "ascimp.iSubHeaderLines \t= %d\n", ascimp.iSubHeaderLines );
printf( "ascimp.iAutoSubHeaderLines \t= %d\n", ascimp.iAutoSubHeaderLines );
printf( "ascimp.iAutoColTypes \t= %d\n", ascimp.iAutoColTypes );
printf( "ascimp.iTestLines; \t= %d\n", ascimp.iTestLines );
printf( "ascimp.iMode \t\t= %d\n", ascimp.iMode );
printf( "ascimp.iNumcolumns \t= %d\n", ascimp.iNumcolumns );
printf( "ascimp.iPartial \t= %d\n", ascimp.iPartial );
printf( "ascimp.iPartialC1 \t= %d\n", ascimp.iPartialC1 );
printf( "ascimp.iPartialC2 \t= %d\n", ascimp.iPartialC2 );
printf( "ascimp.iPartialR1 \t= %d\n", ascimp.iPartialR1 );
printf( "ascimp.iPartialR2 \t= %d\n", ascimp.iPartialR2 );
printf( "ascimp.iRenameWKS \t= %d\n", ascimp.iRenameWKS );
printf( "ascimp.iApplyRange \t= %d\n", ascimp.iApplyRange );
printf( "ascimp.iRenameCols \t= %d\n", ascimp.iRenameCols );
printf( "ascimp.iLabels \t= %d\n", ascimp.iLabels );
printf( "ascimp.iMaxLabels \t= %d\n", ascimp.iMaxLabels );
printf( "ascimp.iLeadingZeroes \t= %d\n", ascimp.iLeadingZeroes );
printf( "ascimp.iNonnumeric \t= %d\n", ascimp.iNonnumeric );
printf( "ascimp.iSkipRows \t= %d\n", ascimp.iSkipRows );
printf( "\n\n" );
}

easwar Posted - 08/10/2004 : 11:29:54 AM
Hello,

We received the files, resolved the problem, and sent files back to you.

I just wanted to summarize the approach we took to solve the problem, for the benefit of others:

The .COR files were ASCII files with varying header length. The customer's code was already parsing the file to correcty determine the number of header lines and writing it to notes window. The problem was in getting the rest of the data into the worksheet correctly for all files.

We imported one file manually into a worksheet by modyfing the ASCII options till we got the data to come in correctly. Once that was done, we saved the worksheet as a custom template. Thus all ASCII options get saved and can be used later - only need to change the settings for number of header lines.

Then, in OC code, one can create an instance of the pre-saved worksheet template, just change those ASCIMP settings that need to be chnaged for current file, and import using those modified settings, with code such as pasted below.

Using the template approach simplifies having to set all ASCIMP options in code. Another advantage is that if column names and labels are all same for each file, such things can be pre-set in the template and do not have to deal with in the code.

If template apporach is not suitable, and one wants to just directly set ASCIMP structure in code, then one can still manually set the ASCIMP options while importing to get the data in correclty, and then write code to read and dump all the current ASCIMP settings, to see what all needs to be set in code for the data to come in properly.

Easwar
OriginLab


// Create a worksheet using pre-saved template
Worksheet wks;
wks.Create("COR_Import.OTW");

// Read the ascimp structure from the wks and change header lines as needed
// Also set structure so that column names and labels are not assigned - these are preset in template
ASCIMP ascimp;
wks.GetASCIMP(ascimp);
ascimp.iHeaderLines = HeaderLines + 1; // HeaderLines variable was set by another function call

// Import file by using the modified ascimp structure - also save modified structure to wks
wks.SetASCIMP(ascimp);
wks.ImportASCII(strFile, ascimp);


easwar Posted - 08/09/2004 : 09:41:06 AM
quote:

I can't see any differences between the *.cor Files which i can import and those which i can not import.



Hi,

Please send one .cor file that works and one that does not, to tech@originlab.com and mention this forum post in your e-mail.

Easwar
OriginLab

Septor Posted - 08/09/2004 : 07:10:01 AM
I can't see any differences between the *.cor Files which i can import and those which i can not import.

i allready wrote a function where i get the number of headerlines

  int HeaderLines = ReadFileHeadIntoNote(PathToFile,Filename);
ReadASCIIIntoWks(PathToFile,HeaderLines,Filename);


How can i customize the ascimp structure?
with the Parameters?

int iDelimited;
int iDelimiter;
char cChar;
char szFixedWidth[MAX_FIXED_COL_WIDTH];
...
i don't know how? i tried nearly everything ...
cpyang Posted - 08/06/2004 : 3:47:26 PM
As rlewis pointed out, your *.txt might be regualr in structure while your *.cor file might not. Try using the importwizard and see what is the difference and if you can specified the needed header and column parameters to import successfully. If you can with the Import Wizard, then you will need to customize the ascimp structure and call

wks.ImportASCII(strFile, ascimp);

directly without calling scImpReadFileStruct.

CP


rlewis Posted - 08/06/2004 : 3:37:20 PM
In most cases when an ASCII data storage format involves a variable number of headder lines, there is usually a headder element from which one can determine the number of headder lines in the file, or a line containing a predetermined character string which is used to mark the end of header elements.

Is this the case with your ".cor" data files ? If so then the solution is quite easy. If not well .... ????
Septor Posted - 08/06/2004 : 05:01:48 AM
Hi,

I used this code:
 
void ReadASCII(string strFile, int HeaderLines)
{
ASCIMP ascimp;
ASCIMP ascimp;
if(AscImpReadFileStruct(strFile,&ascimp)!=0)
{
out_str("cannot read " + strFile);
return;
}
out_str(strFile);
HeaderLines-=2;
ascimp.iHeaderLines = HeaderLines;
ascimp.iSubHeaderLines = 1;
ascimp.iAutoSubHeaderLines=0;

Worksheet wks;
wks.Create();
wks.ImportASCII(strFile, ascimp);
}


and it worked correctly as long as i used *.txt Files.
now i want to import .cor Files (ASCII-File) and it work only with a part of the it.
Error: "cannot read 'strFile'"
How work this function? -> AscImpReadFileStruct(strFile,&ascimp)

I tried it with LapTalk(+Templates), but there i can't change the ASCII Options (The number of Headerlines change)

win -t data Template \"Winname\"

How can i solve my problem? Or isn't there a Solution? ;-)
thx
Septor Posted - 08/05/2004 : 01:37:26 AM
I thank you for your help!
It's exactly what i was looking for.
rlewis Posted - 08/04/2004 : 10:19:34 PM
Oops ... FDLogInit() is not available in 7.0
However the following works in 7.0-SR4


bool ReadFileHeadIntoNote(int NumberOfLines)
{
//if (FDLogInit()==0)
//{
// NumberOfLines .... Number of Lines to be ead from the file

LabTalk.FDLOG.numTypes=1;
LabTalk.FDLOG.type1$="[All Files]*.*";
LabTalk.FDLOG.Dlgname$="Select File for Reading";
LT_set_str("%Z","");
LabTalk.FDLOG.Open("Z");
char szBuffer[MAXFULLPATH];
LT_get_str("%Z",szBuffer,MAXFULLPATH);
string PathToFile=LabTalk.FDLOG.Path$+szBuffer;
if(PathToFile.IsFile())
{
int i=0;
string strTemp;
stdioFile InStream;
string LineFromFile;
if(InStream.Open(PathToFile, file::modeRead))
{
Note NoteWin;

if(NoteWin.Create(CREATE_HIDDEN))
{
string strNoteString = NoteWin.Text;
while(InStream.ReadString(LineFromFile) && i<NumberOfLines)
{
strNoteString+=LineFromFile;
strNoteString+="\n";
i++;
}
InStream.Close();
NoteWin.Text=strNoteString;
strTemp.Format("%d",i);
strTemp+=" ";
strTemp+="lines read into NoteWindow : ";
strTemp+=NoteWin.GetName();
SetDataDisplayText(strTemp);
return (true);
}
}
}
//}
SetDataDisplayText("Error Return");
return (false);
}
rlewis Posted - 08/04/2004 : 10:10:47 PM
Try this ...

bool ReadFileHeadIntoNote(int NumberOfLines)
{
if (FDLogInit()==0)
{
// NumberOfLines .... Number of Lines to be read from the file

LabTalk.FDLOG.numTypes=1;
LabTalk.FDLOG.type1$="[All Files]*.*";
LabTalk.FDLOG.Dlgname$="Select File for Reading";
LT_set_str("%Z","");
LabTalk.FDLOG.Open("Z");
char szBuffer[MAXFULLPATH];
LT_get_str("%Z",szBuffer,MAXFULLPATH);
string PathToFile=LabTalk.FDLOG.Path$+szBuffer;
if(PathToFile.IsFile())
{
int i=0;
string strTemp;
stdioFile InStream;
string LineFromFile;
if(InStream.Open(PathToFile, file::modeRead))
{
Note NoteWin;

if(NoteWin.Create(CREATE_HIDDEN))
{
string strNoteString = NoteWin.Text;
while(InStream.ReadString(LineFromFile) && i<NumberOfLines)
{
strNoteString+=LineFromFile;
strNoteString+="\n";
i++;
}
InStream.Close();
NoteWin.Text=strNoteString;
strTemp.Format("%d",i);
strTemp+=" ";
strTemp+="lines read into NoteWindow : ";
strTemp+=NoteWin.GetName();
SetDataDisplayText(strTemp);
return (true);
}
}
}
}
SetDataDisplayText("Error Return");
return (false);
}

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000