T O P I C R E V I E W |
unique24 |
Posted - 11/28/2004 : 05:27:11 AM Hi
My English is not so well, but I hope you understand my pleasure ...
I have an ASCII File from the EIB (Europan Installation Bus). This will have the Format: #;Zeit;Service;Best.Fehl./Wiederh.;Prio;Quelladr.;Quelle;Zieladr.;Ziel;Rout;DPT;Typ;Daten; 1;2004-11-28 10:37:58.377;vom Bus;- / ;L;1.1.15;FM446 Buderus Heizung Logamatic;7/5/0;Kessel Ist Temp;6;Temperatur (°C);Write;54 °C; 2;2004-11-28 10:38:13.408;vom Bus;- / ;L;1.1.15;FM446 Buderus Heizung Logamatic;7/5/0;Kessel Ist Temp;6;Temperatur (°C);Write;53 °C; 3;2004-11-28 10:38:31.374;vom Bus;- / ;L;1.1.15;FM446 Buderus Heizung Logamatic;7/5/0;Kessel Ist Temp;6;Temperatur (°C);Write;52 °C; 5;2004-11-28 10:38:52.394;vom Bus;- / ;L;1.1.15;FM446 Buderus Heizung Logamatic;7/5/0;Kessel Ist Temp;6;Temperatur (°C);Write;51 °C;
Only Impordent are the colums: "Zeit" "Ziel" "Daten"
"Zeit" should be X "Daten" should be Y "Ziel" should be the different Catergories (The Problem is for me that I can not set a cell for y.)
I will make a Line Graph. I can make this without problems, when I configure the List over Excel. But when I will import the Ascii File direct in OriginPro the I have this problems: * Import the Data´s in correct Typ("Zeit"=Date;"Ziel"=Text;"Daten"=Value) * A big Problem is that the Categories in "Ziel" are not a colum, its in rows.
Each Colum hat the Date and the Graph should be arrange this in correct order.
Via Excel I make a Pivot Tabell and change "Daten" into a Number ("53 °" => "53";"7%"="7")
Mayba is it possible that Someone can make me an Project and send it to my mail: unqiue24@gmx.net ?
Thank you a lot
Unique24
Example: This became I when I impord the Asci File:
X(Date) Y(Cat.) Y(Value) A b c 2004-11.. Cat a 53% 2004-11.. Cat c 9° 2004-11.. Cat b 1 2004-11.. Cat a 20% 2004-11.. Cat b 0
I need: X(Date) Y1(Cat a) X1(Date) Y2(Cat b) X3(Date) Y3(Cat c) A B C D E F 2004-11.. 53 2004-11.. 1 2004-11.. 9 2004-11.. 20 2004-11.. 0
Edited by - unique24 on 11/28/2004 05:47:26 AM |
18 L A T E S T R E P L I E S (Newest First) |
unique24 |
Posted - 12/23/2004 : 02:32:45 AM Hi Rlewis
Thanks, it works without Problems.
Happy X-Mas |
rlewis |
Posted - 12/23/2004 : 01:19:25 AM First you should include the following function bool SetWksPageLabel(Worksheet &Wks, string strLabelText) { if(Wks.IsValid()==true) { string strLTCommand="Page.label$="; strLTCommand+=strLabelText; Wks.GetPage().LT_execute(strLTCommand); return (true); } return (false); }
Then you should edit Import_EIB_ASCII function to insert two calls to the SetWksPageLabel function as follows .....
..... ..... strNoteLine+=Categories[k]; add_line_to_note(NoteWin,strNoteLine); SetWksPageLabel(Wks1, Categories[k]); //// Set Page Label
..... ..... .... strNoteLine+=Categories[0]; add_line_to_note(NoteWin,strNoteLine); SetWksPageLabel(Wks, Categories[0]); //// Set Page Label
|
unique24 |
Posted - 12/21/2004 : 03:03:53 AM Hi Rlewis
Great, it works. Maybe you can tell me, witch Line I have to insert, that set the label of each worksheet to the category? Worksheet 123 (Label: Heizungvorlauf 1) Worksheet 124 (Label: Erdgeschoss Soll Temp)
Thank you |
rlewis |
Posted - 12/20/2004 : 9:14:22 PM Hi ... The code posted below contains a modified version of the "Import_EIB_ASCII" function and the following utility functions .. GenerateSubFolderNane CreateVisibleNote add_line_to_note
The combination of these and the following functions (see previous posts) contains_token CreateVisibleWorkSheet NameIsValid convert_date_time_string AddDataToWorkSheet
should enable you to do Create a Separate Worksheet for each Category read from an file. However, please note the following...
(a) The worksheets have NOT given "category" names because Origin REQUIRES WORKSHEET NAMES TO BE UNIQUE. With the type of data encoded in your datafiles, it is very likely that the same category names may turn up in may different data files, and as a result there is the potential for Worksheet naming conflicts when multiple files are imported into the same Origin project. Although assigning "category names" to Worksheets is quite easy to implement, is probably unwise with your type of data.
(b) Since it seems that there can be many categories in each file, the worksheets generted by each file are consolidated within an Origin Folders with names generated from the name of the import file.
(c) With each of the folder a Notes window will be created. This window contains a list of the File from which the data was imported, and a list of the Worksheets generated by each file and the Category contained in the worjsheet.
(d) Y-Columns have all be set as NUMERIC
Best Wishes for Christmas and fast approaching New Year ....
void Import_EIB_ASCII() { if(FDLogInit()==0) { LabTalk.FDLOG.numTypes=1; LabTalk.FDLOG.type1$="[EIB-Formatted ASCII Files]*.*"; LabTalk.FDLOG.Dlgname$="Select one or more EIB Data Files"; if (LabTalk.FDLOG.multiopen()==0) { string PathToFile, PathToWksTemplate, LineFromFile, strToken, strWksName; Folder FldParent=Project.ActiveFolder(); if(FldParent.IsValid()) { for(int i=1;i<=LabTalk.FDLOG.multiopen.count;i++) { LabTalk.FDLOG.get("V",i); char FilePath[MAXFULLPATH]; LT_get_str("%V",FilePath,MAXFULLPATH); stdioFile InputFile; PathToFile=""+FilePath; if(PathToFile.IsFile()==true) { if(InputFile.Open(PathToFile,file::modeRead)==true) { string NewFolderName=GetFileName(PathToFile); NewFolderName.Replace(".","_"); string PathToNewFolder=FldParent.GetPath(); GenerateSubFolderName(FldParent, NewFolderName); //// Use Filename to create a Subfolder name PathToNewFolder+=NewFolderName; FldParent.AddSubfolder(NewFolderName); Folder NewFolder(PathToNewFolder); vector<string> Categories; vector<int> NumberOfCells; vector<char> CharsToDelete={'C','°','%'}; Worksheet Wks; if(NewFolder.IsValid()==true) { NewFolder.Activate(); Categories.RemoveAll(); NumberOfCells.RemoveAll(); PathToWksTemplate=GetAppPath(true)+"Origin.otw"; strWksName=CreateVisibleWorkSheet(PathToWksTemplate, false); if(Wks.Attach(strWksName)==true) { for(int j=(Wks.GetNumCols()-1);j>=0;j--) { Wks.DeleteCol(j); } while (InputFile.ReadString(LineFromFile)==true) { if(LineFromFile.GetNumTokens(';')>=12) { string Filter=LineFromFile.GetToken(11,';'); if(Filter.CompareNoCase("Write")==0) { string Zeit=LineFromFile.GetToken(1,';'); string Ziel=LineFromFile.GetToken(8,';'); string Daten=LineFromFile.GetToken(12,';'); for(int k=0;k<CharsToDelete.GetSize();k++) { Daten.Remove(CharsToDelete[k]); } if(AddDataToWorkSheet(Wks,Categories,NumberOfCells,Zeit,Ziel,Daten)==true) { continue; } else { InputFile.Close(); return; //// .... error return .... } } } } } } InputFile.Close(); Worksheet Wks1; if(Wks1.Attach(strWksName)==true) { Note NoteWin (CreateVisibleNote(false)); string strNoteLine="File ... "+PathToFile; add_line_to_note(NoteWin,strNoteLine); add_line_to_note(NoteWin," "); add_line_to_note(NoteWin,"Worksheet Category"); Column TempCol, TempCol1; for(int k=1;k<Categories.GetSize();k++) { Wks1.CreateCopy(Wks,CREATE_VISIBLE_SAME); Column TempCol2; if(TempCol.Attach(Wks1,(k*2))==true && TempCol1.Attach(Wks1,((k*2)+1))==true) { while(TempCol2.Attach(Wks1,(k*2)+2)==true) { Wks1.DeleteCol((k*2)+2); } for(int n=((k*2)-1);n>=0;n--) { Wks1.DeleteCol(n); } } if(TempCol2.Attach(Wks1,1)==true) { TempCol2.SetFormat(OKCOLTYPE_NUMERIC); } strNoteLine=Wks1.GetPage().GetName(); append_blanks_to_size(strNoteLine,18); strNoteLine+=Categories[k]; add_line_to_note(NoteWin,strNoteLine); } while (TempCol.Attach(Wks,2)==true) { Wks.DeleteCol(2); } if(TempCol.Attach(Wks,1)==true) { TempCol.SetFormat(OKCOLTYPE_NUMERIC); } strNoteLine=Wks.GetPage().GetName(); append_blanks_to_size(strNoteLine,18); strNoteLine+=Categories[0]; add_line_to_note(NoteWin,strNoteLine); } } } } } } } } //////////////////////////////// **************************** ///////////////////////// void GenerateSubFolderName(Folder &ParentFolder, string &strSubFolderName) { if(ParentFolder.IsValid()==true) { string PathToNewFolder=ParentFolder.GetPath(); strSubFolderName.TrimLeft(); strSubFolderName.TrimRight(); if(strSubFolderName.GetLength()==0) { strSubFolderName="subFld"; } PathToNewFolder+=strSubFolderName; Folder NewFolder(PathToNewFolder); int j=0; bool PreexistingFolderName=false; if(NewFolder.IsValid()==true) { PreexistingFolderName=true; } while(PreexistingFolderName==true) { string strAppend, strNewName, strNewPath; j++; strAppend.Format("%d",j); strNewName=strSubFolderName+"_"+strAppend; strNewPath=PathToNewFolder+"_"+strAppend; Folder NextFolder(strNewPath); if(NextFolder.IsValid()==false) { strSubFolderName=strNewName; PathToNewFolder=strNewPath; PreexistingFolderName=false; } } return; } strSubFolderName=""; } //////////////////////////////// **************************** ///////////////////////// bool add_line_to_note(Note &NotePage, string lpcszText) { if(NotePage) { string strOld = NotePage.Text; strOld += lpcszText; strOld +="\n"; NotePage.Text = strOld; return (true); } return false; }
//////////////////////////////// **************************** ///////////////////////// string CreateVisibleNote(bool Flag) { Note NoteWin; int vFlag; if(Flag==true) { vFlag=CREATE_VISIBLE; } else { vFlag=CREATE_HIDDEN; } if(NoteWin.Create()) { return(NoteWin.GetName()); } return (""); }
//////////////////////////////// **************************** /////////////////////////
|
unique24 |
Posted - 12/13/2004 : 07:17:09 AM Hi rlewis
Maybe you or another can changed the great function? Is it possible when I import from the ascii File, that for each categorie it make a own Worksheet? It should append the data (if the worksheet exist) and the Name of the Worksheet should be the Categorie name. Example:
The ASCII: #;Zeit;Service;Best.Fehl./Wiederh.;Prio;Quelladr.;Quelle;Zieladr.;Ziel;Rout;DPT;Typ;Daten; 1;2004-11-28 10:37:58.377;vom Bus;- / ;L;1.1.15;FM446 Buderus Heizung Logamatic;7/5/0;Kessel Ist Temp;6;Temperatur (°C);Write;54 °C; 2;2004-11-28 10:38:13.408;vom Bus;- / ;L;1.1.15;FM446 Buderus Heizung Logamatic;7/5/0;IST Temp EDV;6;Temperatur (°C);Write;53 °C; 3;2004-11-28 10:38:31.374;vom Bus;- / ;L;1.1.15;FM446 Buderus Heizung Logamatic;7/5/0;Kessel Ist Temp;6;Temperatur (°C);Write;52 °C; 5;2004-11-28 10:38:52.394;vom Bus;- / ;L;1.1.15;FM446 Buderus Heizung Logamatic;7/5/0;Vorlauf Eg;6;Temperatur (°C);Write;51 °C;
In Origin:
Worksheet Name = the 9. data of the ascii;"Ziel" X=the 2. data of the ascii;"Zeit" Y=the 13. data of the asii;"Daten" Column Name and Column Label should be also the 9. data of the ascii;"Ziel"
Because:
When I import the data, sometimes "Kessel Ist Temp" is at Y6, sometimes at Y2, ... So I have to make each Graph new
When I have it in seperat Worksheet the I can Link to Worksheet "Kessel Ist Temp" and Y and ready. X = Date
The script works fine an maybe the changes are not so much?
Oh, there is a little thing, maybe you can fix it: When the function changed the data "34 °C" to "34", then the column with the data is sometimes "Text" or "Text with numeric". It makes Problem with the graph. Can it convert each Y data to "numeric"? And of course each gimmick you build-in since I start the post: format Date, only import Lines with "Write" in the 12. data of the ascii "Typ",...
Ok, this is again a wishlist for X-Mas.
Thanks a lot
The code: void Import_EIB_ASCII() { if(FDLogInit()==0) { LabTalk.FDLOG.numTypes=1; LabTalk.FDLOG.type1$="[EIB-Formatted ASCII Files]*.*"; LabTalk.FDLOG.Dlgname$="Select one or more EIB Data Files"; if (LabTalk.FDLOG.multiopen()==0) { string PathToFile, PathToWksTemplate, LineFromFile, strToken, strWksName; for (int i=1;i<=LabTalk.FDLOG.multiopen.count;i++) { LabTalk.FDLOG.get("V",i); char FilePath[MAXFULLPATH]; LT_get_str("%V",FilePath,MAXFULLPATH); stdioFile InputFile; PathToFile=""+FilePath; if(PathToFile.IsFile()==true) { if(InputFile.Open(PathToFile,file::modeRead)==true) { vector<string> Categories; vector<int> NumberOfCells; vector<char> CharsToDelete={'C','°','%'}; Categories.SetSize(0); NumberOfCells.SetSize(0); PathToWksTemplate=GetAppPath(true)+"Origin.otw"; strWksName=CreateVisibleWorkSheet(PathToWksTemplate, false); Worksheet Wks; if(Wks.Attach(strWksName)==true) { for(int j=(Wks.GetNumCols()-1);j>=0;j--) { Wks.DeleteCol(j); } while (InputFile.ReadString(LineFromFile)==true) { if(LineFromFile.GetNumTokens(';')>=12) { string Filter=LineFromFile.GetToken(11,';'); if(Filter.CompareNoCase("Write")==0) { string Zeit=LineFromFile.GetToken(1,';'); string Ziel=LineFromFile.GetToken(8,';'); string Daten=LineFromFile.GetToken(12,';'); for(int k=0;k<CharsToDelete.GetSize();k++) { Daten.Remove(CharsToDelete[k]); } if(AddDataToWorkSheet(Wks,Categories,NumberOfCells,Zeit,Ziel,Daten)==true) { continue; } else { InputFile.Close(); return; } } } } } InputFile.Close(); } } } } } } bool AddDataToWorkSheet(Worksheet &Wks, vector<string> &Categories, vector<int> &NumberOfCells, string Zeit, string Zeil, string Daten) { int ActiveWksIndex; int ActiveCatIndex; if(contains_token(Categories,Zeil,ActiveCatIndex)==false) { int CurrentX=Wks.AddCol(); int CurrentY=Wks.AddCol(); Column xCurrent; Column yCurrent; if(xCurrent.Attach(Wks,CurrentX)==false || yCurrent.Attach(Wks,CurrentY)==false) { return (false); } xCurrent.SetFormat(OKCOLTYPE_DATE); xCurrent.SetSubFormat(LDF_YYMMDD_AND_HHMMSS_SEPARCOLON); xCurrent.SetLabel("Date"); xCurrent.SetType(OKDATAOBJ_DESIGNATION_X); yCurrent.SetType(OKDATAOBJ_DESIGNATION_Y); yCurrent.SetFormat(OKCOLTYPE_TEXT_NUMERIC); yCurrent.SetLabel(Zeil); // Store Category name as a Y-Column Label Categories.Add(Zeil); NumberOfCells.Add(0); ActiveCatIndex=Categories.GetSize()-1; Zeil.Remove(' '); if(Zeil.GetLength()>10) { Zeil=Zeil.Left(10); } if(NameIsValid(Zeil)==true) { yCurrent.SetName(Zeil); // If Possible, use the first 10 characters of the Category Name as a Y-column Name } } ActiveWksIndex=2*ActiveCatIndex; int ActivColIndex=NumberOfCells[ActiveCatIndex]; convert_date_time_string(Zeit); Wks.SetCell(ActivColIndex,ActiveWksIndex,Zeit); Wks.SetCell(ActivColIndex,(ActiveWksIndex+1),Daten); NumberOfCells[ActiveCatIndex]++; return (true); } void convert_date_time_string(string &strDateTime) { double jDate; string strToken=strDateTime.GetToken(0,' '); string strFormat = "yyyy'-'MM'-'dd"; str_to_date_custom(strToken, strFormat, &jDate); strToken=strDateTime.GetToken(1,' '); double jTime=str_to_time(strToken); jDate+=jTime; strDateTime=get_date_str(jDate,LDF_YYMMDD_AND_HHMMSS_SEPARCOLON); } bool NameIsValid(string NameString) { string LocalCopy, OneChar, ValidCharacters="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; LocalCopy=NameString; LocalCopy.MakeUpper(); for (int i=0;i<LocalCopy.GetLength();i++) { OneChar=LocalCopy.Mid(i,1); if(ValidCharacters.Find(OneChar,0)==-1) return (false); if(i==0 && ValidCharacters.Find(OneChar,26)!=-1) return (false); } return (true); } bool contains_token (StringArray MyStringArray, string MyTokenString, int &TokenNumber) { int NumTokens=MyStringArray.GetSize(); if (MyStringArray.GetSize()==0 || MyTokenString.GetLength()==0) { TokenNumber = -2; return (false); } for (int i=0;i<NumTokens;i++) { if (MyTokenString.Compare(MyStringArray[i])==0) { TokenNumber=i; return (true); } } TokenNumber=-1; return(false); } string CreateVisibleWorkSheet(string PathToTemplate, bool Flag) { if(PathToTemplate.IsFile()) { Worksheet Wks; int vFlag; if(Flag==true) { vFlag=CREATE_VISIBLE; } else { vFlag=CREATE_HIDDEN; } if (Wks.Create(PathToTemplate, vFlag)) { return (Wks.GetPage().GetName()); } } return (""); }
Edited by - unique24 on 12/13/2004 07:19:26 AM |
unique24 |
Posted - 12/08/2004 : 07:07:28 AM Hi rlewis
Great, Thank you. It works perfectly. Indeed there is still some things to change, but not yet. Ist a fine X-Mas gift :-)
I would try to check out how I can made, that when I make a line graph for "Temp" (Woeksheet 3, X=column D (Date),y=column E(Temp)) and I import a new ascii (Data are now for the graph (Worksheet 4, X=Column H (Date), y=Column E(Temp)), that I don´t make the graph new, just replace the date from Worksheet 4 (The new ascii) to Worksheet 3 (the data from Graph 1). I can replace data´s in a graph from the same Worksheet, but not from another Worksheet !
But this is after X-mas. The Function works and I made this time each graph new.
Happy X-Mas
|
rlewis |
Posted - 12/08/2004 : 03:26:43 AM Another error on my part ... I posted the wrong version of the contains_token function ... I must be slowing in my old age ... Here is the correct version ... bool contains_token (StringArray MyStringArray, string MyTokenString, int &TokenNumber) { int NumTokens=MyStringArray.GetSize(); if (MyStringArray.GetSize()==0 || MyTokenString.GetLength()==0) { TokenNumber = -2; return (false); } for (int i=0;i<NumTokens;i++) { if (MyTokenString.Compare(MyStringArray[i])==0) { TokenNumber=i; return (true); } } TokenNumber=-1; return(false); }
|
unique24 |
Posted - 12/08/2004 : 03:13:50 AM quote:
OOps ... a bit careless of me ...I forgot to include a couple of my utility functions ... The new version also requires the CreateVisibleWorksheet finction ...
Just add the code below to the rest and it should work ...
Hi rlewis
Thanks for the update, but not it comes follow error:
compiling... Origin.C compiling... page_utils.c compiling... tree_utils.c compiling... matrix.c compiling... internal.c compiling... theme_utils.OP compiling... OriginEvents.OP compiling... analysis_utils.c compiling... GetNBox.OP compiling... LT_wks.c compiling... sys_utils.c compiling... LT_PE.c compiling... LT_math.c compiling... eib.c C:\.....\Temp\~otfWMBL\eib.c(105) :Error, function call and declaration mismatch C:\.....\Temp\~otfWMBL\eib.c(105) :Error, general compile error C:\.....\Temp\~otfWMBL\eib.c(101) :Error, error(s) found in compiling function AddDataToWorkSheet
Compiling errors found, linking cannot start! |
rlewis |
Posted - 12/07/2004 : 5:28:25 PM OOps ... a bit careless of me ...I forgot to include a couple of my utility functions ... The new version also requires the CreateVisibleWorksheet finction ...
Just add the code below to the rest and it should work ...
bool contains_token (string MyString, string MyTokenString, int &TokenNumber) { if (MyString.GetLength()==0 || MyTokenString.GetLength()==0) { TokenNumber = -2; return (false); } int NumTokens=MyString.GetNumTokens(); for (int i=0;i<NumTokens;i++) { if (MyTokenString.Compare(MyString.GetToken(i))==0) { TokenNumber = i; return (true); } } TokenNumber = -1; return (false); }
string CreateVisibleWorkSheet(string PathToTemplate, bool Flag) { if(PathToTemplate.IsFile()) { Worksheet Wks; int vFlag; if(Flag==true) { vFlag=CREATE_VISIBLE; } else { vFlag=CREATE_HIDDEN; } if (Wks.Create(PathToTemplate, vFlag)) { return (Wks.GetPage().GetName()); } } return (""); }
|
unique24 |
Posted - 12/07/2004 : 4:15:37 PM Hi rlewis
Fine, but I became this errors when I rebuild:
compiling... Origin.C compiling... matrix.c compiling... tree_utils.c compiling... page_utils.c compiling... internal.c compiling... theme_utils.OP compiling... OriginEvents.OP compiling... analysis_utils.c compiling... GetNBox.OP compiling... LT_wks.c compiling... sys_utils.c compiling... LT_math.c compiling... LT_PE.c compiling... eib.c C:\....\Temp\~otfCQQU\eib.c(105) :Error, function or variable contains_token not found C:\....\Temp\~otfCQQU\eib.c(105) :Error, general compile error C:\....\Temp\~otfCQQU\eib.c(101) :Error, error(s) found in compiling function AddDataToWorkSheet
Compiling errors found, linking cannot start!
Maybe a not includet function in my version of originlab?
Thanks for your help
|
rlewis |
Posted - 12/07/2004 : 12:54:24 PM How about this version ... void Import_EIB_ASCII() { if(FDLogInit()==0) { LabTalk.FDLOG.numTypes=1; LabTalk.FDLOG.type1$="[EIB-Formatted ASCII Files]*.*"; LabTalk.FDLOG.Dlgname$="Select one or more EIB Data Files"; if (LabTalk.FDLOG.multiopen()==0) { string PathToFile, PathToWksTemplate, LineFromFile, strToken, strWksName; for (int i=1;i<=LabTalk.FDLOG.multiopen.count;i++) { LabTalk.FDLOG.get("V",i); char FilePath[MAXFULLPATH]; LT_get_str("%V",FilePath,MAXFULLPATH); stdioFile InputFile; PathToFile=""+FilePath; if(PathToFile.IsFile()==true) { if(InputFile.Open(PathToFile,file::modeRead)==true) { vector<string> Categories; vector<int> NumberOfCells; vector<char> CharsToDelete={'C','°','%'}; Categories.RemoveAll(); NumberOfCells.RemoveAll(); PathToWksTemplate=GetAppPath(true)+"Origin.otw"; strWksName=CreateVisibleWorkSheet(PathToWksTemplate, false); Worksheet Wks; if(Wks.Attach(strWksName)==true) { for(int j=(Wks.GetNumCols()-1);j>=0;j--) { Wks.DeleteCol(j); } while (InputFile.ReadString(LineFromFile)==true) { if(LineFromFile.GetNumTokens(';')>=12) { string Filter=LineFromFile.GetToken(11,';'); if(Filter.CompareNoCase("Write")==0) { string Zeit=LineFromFile.GetToken(1,';'); string Ziel=LineFromFile.GetToken(8,';'); string Daten=LineFromFile.GetToken(12,';'); for(int k=0;k<CharsToDelete.GetSize();k++) { Daten.Remove(CharsToDelete[k]); } if(AddDataToWorkSheet(Wks,Categories,NumberOfCells,Zeit,Ziel,Daten)==true) { continue; } else { InputFile.Close(); return; } } } }
} InputFile.Close(); } } } } } }
bool AddDataToWorkSheet(Worksheet &Wks, vector<string> &Categories, vector<int> &NumberOfCells, string Zeit, string Zeil, string Daten) { int ActiveWksIndex; int ActiveCatIndex; if(contains_token(Categories,Zeil,ActiveCatIndex)==false) { int CurrentX=Wks.AddCol(); int CurrentY=Wks.AddCol(); Column xCurrent; Column yCurrent; if(xCurrent.Attach(Wks,CurrentX)==false || yCurrent.Attach(Wks,CurrentY)==false) { return (false); } xCurrent.SetFormat(OKCOLTYPE_DATE); xCurrent.SetSubFormat(LDF_YYMMDD_AND_HHMMSS_SEPARCOLON); xCurrent.SetLabel("Date"); xCurrent.SetType(OKDATAOBJ_DESIGNATION_X); yCurrent.SetType(OKDATAOBJ_DESIGNATION_Y); yCurrent.SetFormat(OKCOLTYPE_TEXT_NUMERIC); yCurrent.SetLabel(Zeil); // Store Category name as a Y-Column Label Categories.Add(Zeil); NumberOfCells.Add(0); ActiveCatIndex=Categories.GetSize()-1; Zeil.Remove(' '); if(Zeil.GetLength()>10) { Zeil=Zeil.Left(10); } if(NameIsValid(Zeil)==true) { yCurrent.SetName(Zeil); // If Possible, use the first 10 characters of the Category Name as a Y-column Name } } ActiveWksIndex=2*ActiveCatIndex; int ActivColIndex=NumberOfCells[ActiveCatIndex]; convert_date_time_string(Zeit); Wks.SetCell(ActivColIndex,ActiveWksIndex,Zeit); Wks.SetCell(ActivColIndex,(ActiveWksIndex+1),Daten); NumberOfCells[ActiveCatIndex]++; return (true); }
void convert_date_time_string(string &strDateTime) { double jDate; string strToken=strDateTime.GetToken(0,' '); string strFormat = "yyyy'-'MM'-'dd"; str_to_date_custom(strToken, strFormat, &jDate); strToken=strDateTime.GetToken(1,' '); double jTime=str_to_time(strToken); jDate+=jTime; strDateTime=get_date_str(jDate,LDF_YYMMDD_AND_HHMMSS_SEPARCOLON); }
bool NameIsValid(string NameString) { string LocalCopy, OneChar, ValidCharacters="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; LocalCopy=NameString; LocalCopy.MakeUpper(); for (int i=0;i<LocalCopy.GetLength();i++) { OneChar=LocalCopy.Mid(i,1); if(ValidCharacters.Find(OneChar,0)==-1) return (false); if(i==0 && ValidCharacters.Find(OneChar,26)!=-1) return (false); } return (true); }
|
unique24 |
Posted - 12/07/2004 : 10:03:26 AM quote:
Open the script window and issue the command "Import_EIB_ASCII()" ...
Hello rlewis
Great, it works !
Would it be impertinently to ask you, that you added some feature again ?
* The format of column "Zeit" (the second in the ascii) is Date in the format is "yyyy-mm-dd HH:mm:ss.###" When I start the function and change the column to date, he delete all values, because the year is standing in front. Maybe you can set the colum "Zeit" to the Date format? Example: "2004-12-20 12:04:32.132" for the date?
* Only import lines, where are standing in column 12 (Typ) the text "Write"
* When I link from a Line Graph to H(Y3) (Column label: Brenner) I have the Problem when I import a other ascii, that the Value "Brenner" is in D(Y2) (Column label: Brenner) Is it possible to link from a saved plot to a column label? So he look for "brenner" and not for H(Y3) Or did you have another idea?
But Your function works great. Thanks a lot
|
rlewis |
Posted - 12/04/2004 : 11:11:43 AM Open the script window and issue the command "Import_EIB_ASCII()" ... |
unique24 |
Posted - 12/04/2004 : 10:18:12 AM quote:
It seems that the vectorbase member function is not available in the version of 7.5 (presumably the German Edition) you are running ... Patching to 7.5-SR4 of higher should solve this problem. If a suitable patch is not available ... you can get around this by changing the lines " Categories.RemoveAll(); NumberOfCells.RemoveAll(); "
to
" Categories.SetSize(0); NumberOfCells.SetSize(0); " ....
Hi
Thank you for your help. I changed it and now I can compile the Function. But how can I start it?
Thanks |
rlewis |
Posted - 12/01/2004 : 12:03:01 PM It seems that the vectorbase member function is not available in the version of 7.5 (presumably the German Edition) you are running ... Patching to 7.5-SR4 of higher should solve this problem. If a suitable patch is not available ... you can get around this by changing the lines " Categories.RemoveAll(); NumberOfCells.RemoveAll(); "
to
" Categories.SetSize(0); NumberOfCells.SetSize(0); " .... |
unique24 |
Posted - 12/01/2004 : 08:41:52 AM Hi
Thank you, put when I put it in Origin C as C-File I became the following error:
Linking... C:\****\OriginLab\Origin75E\User Files\OriginC\eib.c(117) :Error, external DLL cannot find function RemoveAll Linking Failed!
Thanks |
rlewis |
Posted - 12/01/2004 : 02:53:03 AM The following OriginC functions seem toi work (7.5-SR5) ..
void Import_EIB_ASCII() { if(FDLogInit()==0) { LabTalk.FDLOG.numTypes=1; LabTalk.FDLOG.type1$="[EIB-Formatted ASCII Files]*.*"; LabTalk.FDLOG.Dlgname$="Select one or more EIB Data Files"; if (LabTalk.FDLOG.multiopen()==0) { string PathToFile, PathToWksTemplate, LineFromFile, strToken, strWksName; for (int i=1;i<=LabTalk.FDLOG.multiopen.count;i++) { LabTalk.FDLOG.get("V",i); char FilePath[MAXFULLPATH]; LT_get_str("%V",FilePath,MAXFULLPATH); stdioFile InputFile; PathToFile=""+FilePath; if(PathToFile.IsFile()==true) { if(InputFile.Open(PathToFile,file::modeRead)==true) { vector<string> Categories; vector<int> NumberOfCells; vector<char> CharsToDelete={'C','°','%'}; Categories.RemoveAll(); NumberOfCells.RemoveAll(); PathToWksTemplate=GetAppPath(true)+"Origin.otw"; strWksName=CreateVisibleWorkSheet(PathToWksTemplate, false); Worksheet Wks; if(Wks.Attach(strWksName)==true) { for(int j=(Wks.GetNumCols()-1);j>=0;j--) { Wks.DeleteCol(j); } while (InputFile.ReadString(LineFromFile)==true) { if(LineFromFile.GetNumTokens(';')>=12) { string Zeit=LineFromFile.GetToken(1,';'); string Ziel=LineFromFile.GetToken(8,';'); string Daten=LineFromFile.GetToken(12,';'); for(int k=0;k<CharsToDelete.GetSize();k++) { Daten.Remove(CharsToDelete[k]); } if(AddDataToWorkSheet(Wks,Categories,NumberOfCells,Zeit,Ziel,Daten)==true) { continue; } else { InputFile.Close(); return; } } } foreach(Column wksCol in Wks.Columns) { if(wksCol.GetType()==OKDATAOBJ_DESIGNATION_X) { wksCol.SetFormat(OKCOLTYPE_TIME); wksCol.SetLabel("Time"); } } } InputFile.Close(); } } } } } }
bool AddDataToWorkSheet(Worksheet &Wks, vector<string> &Categories, vector<int> &NumberOfCells, string Zeit, string Zeil, string Daten) { int ActiveWksIndex; int ActiveCatIndex; for(int i=0;i<Categories.GetSize();i++) { if(Zeil.CompareNoCase(Categories[i])==0) { ActiveCatIndex=i; goto AddMoreData; } } int CurrentX=Wks.AddCol(); int CurrentY=Wks.AddCol(); Column xCurrent; Column yCurrent; if(xCurrent.Attach(Wks,CurrentX)==false || yCurrent.Attach(Wks,CurrentY)==false) { return (false); } xCurrent.SetFormat(OKCOLTYPE_TEXT); xCurrent.SetType(OKDATAOBJ_DESIGNATION_X); yCurrent.SetType(OKDATAOBJ_DESIGNATION_Y); yCurrent.SetFormat(OKCOLTYPE_TEXT_NUMERIC); yCurrent.SetLabel(Zeil); // Store Category name as a Y-Column Label Categories.Add(Zeil); NumberOfCells.Add(0); ActiveCatIndex=Categories.GetSize()-1; AddMoreData: ActiveWksIndex=2*ActiveCatIndex; int ActivColIndex=NumberOfCells[ActiveCatIndex]; Wks.SetCell(ActivColIndex,ActiveWksIndex,Zeit); Wks.SetCell(ActivColIndex,(ActiveWksIndex+1),Daten); NumberOfCells[ActiveCatIndex]++; return (true); }
string CreateVisibleWorkSheet(string PathToTemplate, bool Flag) { if(PathToTemplate.IsFile()) { Worksheet Wks; int vFlag; if(Flag==true) { vFlag=CREATE_VISIBLE; } else { vFlag=CREATE_HIDDEN; } if (Wks.Create(PathToTemplate, vFlag)) { return (Wks.GetPage().GetName()); } } return (""); }
|
easwar |
Posted - 11/30/2004 : 10:33:58 AM Hi,
Looks like you want to: 1> import only a few columns that are scattered and not contiguous/together 2> remove some part of text from a column (such as remove the deg C from 54 deg c) 3> separate the data out into multiple datasets based on a category value in one of the columns
The best way may be to write your own custom import code. If you have version 7 or version 7.5, you could do this with Origin C
Easwar OriginLab
|
|
|