source: sans/XOP_Dev/EventLoader/EventLoadWaveOperation.cpp @ 997

Last change on this file since 997 was 878, checked in by srkline, 10 years ago

adding the event loader code to the XOP dev repository

File size: 4.8 KB
Line 
1#include "XOPStandardHeaders.h"                 // Include ANSI headers, Mac headers, IgorXOP.h, XOP.h and XOPSupport.h
2#include "EventLoadWave.h"
3
4// Operation template: EventLoadWave /A[=name:baseName] /D /I /N[=name:baseName] /O /P=name:pathName /Q /R /W [string:fileParamStr]
5
6// Runtime param structure for EventLoadWave operation.
7#pragma pack(2)         // All structures passed to Igor are two-byte aligned.
8struct EventLoadWaveRuntimeParams {
9        // Flag parameters.
10
11        // Parameters for /A flag group.
12        int AFlagEncountered;
13        char ABaseName[MAX_OBJ_NAME+1];                 // Optional parameter.
14        int AFlagParamsSet[1];
15
16        // Parameters for /D flag group.
17        int DFlagEncountered;
18        // There are no fields for this group because it has no parameters.
19
20        // Parameters for /I flag group.
21        int IFlagEncountered;
22        // There are no fields for this group because it has no parameters.
23
24        // Parameters for /N flag group.
25        int NFlagEncountered;
26        char NBaseName[MAX_OBJ_NAME+1];                 // Optional parameter.
27        int NFlagParamsSet[1];
28
29        // Parameters for /O flag group.
30        int OFlagEncountered;
31        // There are no fields for this group because it has no parameters.
32
33        // Parameters for /P flag group.
34        int PFlagEncountered;
35        char pathName[MAX_OBJ_NAME+1];
36        int PFlagParamsSet[1];
37
38        // Parameters for /Q flag group.
39        int QFlagEncountered;
40        // There are no fields for this group because it has no parameters.
41
42        // Parameters for /R flag group.
43        int RFlagEncountered;
44        // There are no fields for this group because it has no parameters.
45       
46        // Parameters for /W flag group.
47        int WFlagEncountered;
48        // There are no fields for this group because it has no parameters.
49
50        // Main parameters.
51
52        // Parameters for Event main group #0.
53        int fileParamStrEncountered;
54        Handle fileParamStr;                                    // Optional parameter.
55        int fileParamStrParamsSet[1];
56
57        // These are postamble fields that Igor sets.
58        int calledFromFunction;                                 // 1 if called from a user function, 0 otherwise.
59        int calledFromMacro;                                    // 1 if called from a macro, 0 otherwise.
60};
61typedef struct EventLoadWaveRuntimeParams EventLoadWaveRuntimeParams;
62typedef struct EventLoadWaveRuntimeParams* EventLoadWaveRuntimeParamsPtr;
63#pragma pack()          // Reset structure alignment to default.
64
65extern "C" int
66ExecuteEventLoadWave(EventLoadWaveRuntimeParamsPtr p)
67{
68        int fileLoaderFlags;
69        char baseName[MAX_OBJ_NAME+1];
70        char symbolicPathName[MAX_OBJ_NAME+1];
71        char fileParam[MAX_PATH_LEN+1];
72        int err = 0;
73       
74        fileLoaderFlags = 0;
75        strcpy(baseName, "wave");
76        *symbolicPathName = 0;
77        *fileParam = 0;
78       
79        if (p->AFlagEncountered) {
80                fileLoaderFlags |= FILE_LOADER_AUTONAME;
81                if (p->AFlagParamsSet[0]) {
82                        if (*p->ABaseName != 0)
83                                strcpy(baseName, p->ABaseName);
84                }
85        }
86
87        //do nothing, and this will force single precision
88        //if (p->DFlagEncountered)
89        //      fileLoaderFlags |= FILE_LOADER_DOUBLE_PRECISION;
90       
91        if (p->IFlagEncountered)
92                fileLoaderFlags |= FILE_LOADER_INTERACTIVE;
93       
94        if (p->NFlagEncountered) {
95                fileLoaderFlags |= FILE_LOADER_AUTONAME | FILE_LOADER_OVERWRITE;
96                if (p->NFlagParamsSet[0]) {
97                        if (*p->NBaseName != 0)
98                                strcpy(baseName, p->NBaseName);
99                }
100        }
101       
102        if (p->OFlagEncountered)
103                fileLoaderFlags |= FILE_LOADER_OVERWRITE;
104       
105        if (p->PFlagEncountered) {
106                strcpy(symbolicPathName, p->pathName);
107
108                if (*symbolicPathName != 0) {                                           // /P=$"" is a like no /P at all.
109                        char symbolicPathPath[MAX_PATH_LEN+1];
110
111                        fileLoaderFlags |= FILE_LOADER_PATH;
112
113                        // This is just to check if the symbolic path name is valid.
114                        if (err = GetPathInfo2(symbolicPathName, symbolicPathPath))
115                                return err;
116                }
117        }
118       
119        if (p->QFlagEncountered)
120                fileLoaderFlags |= FILE_LOADER_QUIET;
121//****
122        if (p->RFlagEncountered)
123                fileLoaderFlags |= EVENT_REMOVE_BAD_EVENTS;
124//**** 
125        if (p->WFlagEncountered)
126                fileLoaderFlags |= EVENT_COUNTS_ONLY;                   //flag for just the read to get the counts...
127       
128        if (p->fileParamStrEncountered) {
129                if (err = GetCStringFromHandle(p->fileParamStr, fileParam, sizeof(fileParam)-1))
130                        return err;
131                if (err = GetNativePath(fileParam, fileParam))
132                        return err;
133        }
134
135        // We have the parameters, now load the data.
136        err = LoadWave(p->calledFromFunction, fileLoaderFlags, baseName, symbolicPathName, fileParam);
137
138        return err;
139}
140
141int
142RegisterEventLoadWave(void)
143{
144        const char* cmdTemplate;
145        const char* runtimeNumVarList;
146        const char* runtimeStrVarList;
147
148        cmdTemplate = "EventLoadWave /A[=name:baseName] /D /I /N[=name:baseName] /O /P=name:pathName /Q /R /W [string:fileParamStr]";
149        runtimeNumVarList = "V_flag;V_nXYevents;V_num0;V_num1;V_num2;V_num3;V_numPP;V_numT0;V_numZero;V_numBad;V_numRemoved;";
150        runtimeStrVarList = "S_path;S_fileName;S_waveNames;";
151        return RegisterOperation(cmdTemplate, runtimeNumVarList, runtimeStrVarList, sizeof(EventLoadWaveRuntimeParams), (void*)ExecuteEventLoadWave, 0);
152}
Note: See TracBrowser for help on using the repository browser.