| Author |
Topic  |
|
|
cferri39
USA
Posts |
Posted - 05/07/2007 : 5:48:00 PM
|
Origin Version (Select Help-->About Origin): 7.5885 Operating System: Windows XP Pro
Hello all,
I have just recently been called on to write a script that imports multiple ascii data files each containing a spectrum from a spectrometer. After importing this data the script is designed to resize and fill in a matrix (which is opened by the user before the program runs) titled Matrix1. The cells of the matrix are filled in with the intensities. I intend to use this data to plot a 3D graph of wavelength v. position v. intensity. The wavelength and position data are used to set the x and y bounds. As a side note, the wavelengths are included in the files and the positions are part of the filename, e.g. C:/data_12.3456.dat.
The main problem I am currently having is that Origin says there is a memory addressing problem error and then crashes if I try to import more than three files at a time. I think this is because I am using wks.importAscii() function. In other words I think this problem exists because I am importing each file as a seperate worksheet before compiling the data rather than just stripping the data directly from the files leading to a memory error.
Here's the clincher I have very limited experience with C and I am the only programmer working for my lab. These two things are making it difficult for me to even come up with a way to strip the data dirrectly from the files. So I was wondering if those of you experienced with this would be able to help me with my problem? Bellow are links to the source code and files I am using to test the program. Also, the main function used to do the import is called custom3D().
Thank you very much,
-Chris Ferri
The source: http://sm.batcave.net/customMatrix.c
The data: http://sm.batcave.net/data.zip
Edited by - cferri39 on 05/07/2007 5:49:52 PM |
|
|
Mike Buess
USA
3037 Posts |
Posted - 05/07/2007 : 9:34:42 PM
|
Hi Chris,
The source code comes through fine but the data link leads only to the site http://www.batcave.net/links.php That data will surely be necessary for debugging because it's not immediately clear what the source code is meant to accomplish. The first question that comes to mind is... why the excessive use of pointers? Wouldn't normal variables be just as good?
Mike Buess Origin WebRing Member |
 |
|
|
cferri39
USA
Posts |
Posted - 05/07/2007 : 11:20:29 PM
|
The excesive use of pointers is because, as I said earlier, I am not very experienced with C. I was under the impression that some of origins built in functions required pointers rather than regular variables. I would gladly get rid of some of the pointers if you could tell me which ones aren't needed. Also the link to the data.zip file should work now if it doesnt it means the server I am using to host the file is deleting it. And I will find another server soon.
P.S. If it looks like my code is frankensteined from some of the programming examples...thats because a lot of it is. |
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 05/08/2007 : 07:49:08 AM
|
The link to data.zip still takes me to your server. Please email the file to mlb@nmrtools.com if it's smaller than 25MB. If it's larger than 25MB and contains multiple data files you can break it up in smaller chunks.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 05/08/2007 07:59:53 AM |
 |
|
|
cferri39
USA
Posts |
Posted - 05/09/2007 : 3:57:37 PM
|
| email sent |
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 05/09/2007 : 4:35:51 PM
|
Working on reply. Should be ready in a few minutes. :-)
...Reply sent.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 05/09/2007 4:43:12 PM |
 |
|
|
cferri39
USA
Posts |
Posted - 05/09/2007 : 9:22:02 PM
|
Thank you Mike for all your help. Mike has rewriten my code so it is much more efficient and well it doesn't crash. He has also given me permission to post the new code in the forum for all of you who might need a part of it in the future.
Here ya go:
/*------------------------------------------------------------------------------* * File Name: * * Creation: * * Purpose: OriginC Source C file * * Copyright (c) ABCD Corp. 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 * * All Rights Reserved * * * * Modification Log: * *------------------------------------------------------------------------------*/ //////////////////////////////////////////////////////////////////////////////////// // Including the system header file Origin.h should be sufficient for most Origin // applications and is recommended. Origin.h includes many of the most common system // header files and is automatically pre-compiled when Origin runs the first time. // Programs including Origin.h subsequently compile much more quickly as long as // the size and number of other included header files is minimized. All NAG header // files are now included in Origin.h and no longer need be separately included. // // Right-click on the line below and select 'Open "Origin.h"' to open the Origin.h // system header file. #include <Origin.h> ////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////// // Include your own header files here.
//////////////////////////////////////////////////////////////////////////////////// // Start your functions here.
int getWavelengths(string strFile, double& dLower, double& dUpper) { stdioFile ff(strFile, file::modeRead); string str,strTmp; ff.ReadString(str); // first line - ignore ff.ReadString(str); // second line dLower = atof( str.GetToken(0,'\t') ); // dLower int nLines = 1; while( ff.ReadString(strTmp) ) { nLines++; str = strTmp; } dUpper = atof( str.GetToken(0,'\t') ); // last line - dUpper ff.Close(); return nLines; }
double collectNumbers(string strFile, char cDelimiter) { string sName = GetFileName(strFile,true); // file name sans extension return atof( sName.GetToken(1,cDelimiter) ); }
void custom3D() { //Defining what file types can be imported by GetMultiOpenBox() StringArray fileTypes, filePath; fileTypes.SetSize(1); fileTypes[0]="[Data File (*.dat)] *.dat"; int totalFiles = GetMultiOpenBox(filePath, fileTypes, NULL, NULL, NULL, false); if( !totalFiles ) return; //Declaring permanent local variables positionLow,positionHigh,upperWave,lowerWave are used to set the range and domain for the graph double dPositionLow, dPositionMid, dPositionHigh; double dLowerWave, dUpperWave; //Retreaving filenames that contain the initial and final position values //GetMultiOpenBox() sets the last file to index 0 in the filePath[] string array ////Can reorder by clicking the File Name column header in bottom list
//Extracting postions from the filenames dPositionLow = collectNumbers(filePath[0], '_'); dPositionMid = collectNumbers(filePath[1], '_'); dPositionHigh = collectNumbers(filePath[totalFiles-1], '_'); if( dPositionLow>dPositionMid ) { // forgot to sort by clicking the File Name header - compensate here filePath.Add(filePath[0]); filePath.RemoveAt(0,1); dPositionHigh = dPositionLow; dPositionLow = dPositionMid; } if( dPositionLow>dPositionHigh ) { out_str("Error: wrong file order."); return; } int nLines = getWavelengths(filePath[0], dLowerWave, dUpperWave);
//Populate Matrix with data from the spectrum files Worksheet wks; wks.Create("Origin.otw"); wks.DeleteCol(0); ASCIMP ascimp; // ASCII options (see OC_types.h) wks.GetASCIMP(ascimp); ascimp.iDelimited = 1; ascimp.iDelimiter = ASCIMP_DELIM_TAB; ascimp.iHeaderLines = 1; ascimp.iSubHeaderLines = 0; ascimp.iAutoSubHeaderLines = 0; ascimp.iAutoColTypes = 0; ascimp.iMode = ASCIMP_MODE_APPEND_COLS; ascimp.iPartial = ASCIMP_PARTIAL_YES; ascimp.iPartialC1 = 1; ascimp.iPartialC2 = 1; wks.SetASCIMP(ascimp); progressBox aa("Importing to Worksheet"); aa.SetRange(0,totalFiles); for(int i=0;i<totalFiles;i++) { wks.ImportASCII(filePath[i], ascimp); aa.Set(i); } //Create a matrix MatrixLayer ml; ml.Create(); Matrix mData(ml); mData.CopyFromWks(wks); wks.Destroy(); // close wks //Set bounds for 3D graph mData.Transpose(); mData.SetYMin(dPositionLow); mData.SetYMax(dPositionHigh); mData.SetXMin(dLowerWave); mData.SetXMax(dUpperWave); //printf("YMin=%f\n",dPositionLow); //printf("YMax=%f\n",dPositionHigh); //printf("XMin=%f\n",dLowerWave); //printf("XMax=%f\n",dUpperWave); }
/////////////////////////////////////////////////////////////////////////////////
|
 |
|
| |
Topic  |
|
|
|