summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorShashank Bhalotia2017-07-12 13:57:53 +0000
committerGitHub2017-07-12 13:57:53 +0000
commite80ce8970736e56c7e05070dcb7459efdc2e7481 (patch)
tree6a5d72b65a99562c56bba39fa64e41c89f06a960 /modules
parent481b7b084d2f2b1a33f85396263d11aa9fed7069 (diff)
downloadscilab_for_xcos_on_cloud-e80ce8970736e56c7e05070dcb7459efdc2e7481.tar.gz
scilab_for_xcos_on_cloud-e80ce8970736e56c7e05070dcb7459efdc2e7481.tar.bz2
scilab_for_xcos_on_cloud-e80ce8970736e56c7e05070dcb7459efdc2e7481.zip
Update cscope.c
Diffstat (limited to 'modules')
-rwxr-xr-xmodules/scicos_blocks/src/c/cscope.c146
1 files changed, 79 insertions, 67 deletions
diff --git a/modules/scicos_blocks/src/c/cscope.c b/modules/scicos_blocks/src/c/cscope.c
index 44656b6fb..c550d6360 100755
--- a/modules/scicos_blocks/src/c/cscope.c
+++ b/modules/scicos_blocks/src/c/cscope.c
@@ -208,6 +208,7 @@ SCICOS_BLOCKS_IMPEXP void cscope(scicos_block * block, scicos_flag flag)
int i;
BOOL result;
+ // Define file pointer to write data to a log file which can used for output generation to the client
FILE* filePointer;
int processId;
char fileName[25];
@@ -216,92 +217,103 @@ SCICOS_BLOCKS_IMPEXP void cscope(scicos_block * block, scicos_flag flag)
filePointer = NULL;
processId = 0;
+ // Get the process id to give a unique name to the requested simulation
processId = getpid(); // On Linux
sprintf(fileName, "scilab-log-%d.txt", processId);
+ // Open file in append mode
filePointer = fopen(fileName, "a");
+ // Give block id to distinguish blocks
int block_id=1;
switch (flag)
{
case Initialization:
- sco = getScoData(block);
- if (sco == NULL)
- {
- set_block_error(-5);
- break;
- }
- iFigureUID = getFigure(block);
- if (iFigureUID == 0)
- {
- // allocation error
- set_block_error(-5);
- break;
- }
-
-
- fprintf(filePointer, "%d || Initialization %d\n", processId, iFigureUID);
-
- break;
+ sco = getScoData(block);
+ if (sco == NULL)
+ {
+ set_block_error(-5);
+ break;
+ }
+ iFigureUID = getFigure(block);
+ if (iFigureUID == 0)
+ {
+ // allocation error
+ set_block_error(-5);
+ break;
+ }
+
+ // Write data to define Initialization phase
+ fprintf(filePointer, "%d || Initialization %d\n", processId, iFigureUID);
+
+ break;
case StateUpdate:
- iFigureUID = getFigure(block);
- if (iFigureUID == 0)
- {
- // allocation error
- set_block_error(-5);
- break;
- }
-
- t = get_scicos_time();
- u = GetRealInPortPtrs(block, 1);
-
- appendData(block, 0, t, u);
-
- for (i = 0; i < block->insz[0]; i++)
- {
- int iFigureUID = getFigure(block);
- int iAxeUID = getAxe(iFigureUID, block, 0);
- int iPolylineUID = getPolyline(iAxeUID, block, i, FALSE);
- double time = t;
- double y = u[i];
- double z = 0;
- char *labl = GetLabelPtrs(block);
- if (strlen(labl) == 0)
- labl = "CSCOPE";
-
- // 1 to indicate 1 graph in output
- fprintf(filePointer, "%d %d || %d | %d | %d || %f %f %f %d %f %f %f %s\n", block_id, processId, iFigureUID, iAxeUID, iPolylineUID, time, y, z,1,block->rpar[1],block->rpar[2],block->rpar[3],labl);
-
-
- result = pushData(block, 0, i);
- if (result == FALSE)
- {
- Coserror("%s: unable to push some data.", "cscope");
- break;
- }
- }
- break;
+ iFigureUID = getFigure(block);
+ if (iFigureUID == 0)
+ {
+ // allocation error
+ set_block_error(-5);
+ break;
+ }
+
+ t = get_scicos_time();
+ u = GetRealInPortPtrs(block, 1);
+
+ appendData(block, 0, t, u);
+
+ for (i = 0; i < block->insz[0]; i++)
+ {
+ // Store parameters required to generate output on the web
+ int iFigureUID = getFigure(block);
+ int iAxeUID = getAxe(iFigureUID, block, 0);
+ int iPolylineUID = getPolyline(iAxeUID, block, i, FALSE);
+ double time = t;
+ double y = u[i];
+ double z = 0;
+ char *labl = GetLabelPtrs(block);
+ if (strlen(labl) == 0)
+ labl = "CSCOPE";
+
+ // Store scilab's plotted data in the log file
+ fprintf(filePointer, "%d %d || %d | %d | %d || %f %f %f %d %f %f %f %s\n", block_id, processId, iFigureUID, iAxeUID, iPolylineUID, time, y, z, 1, block->rpar[1], block->rpar[2], block->rpar[3], labl);
+ /*
+ block_id - block_id of this block, process_id - process id of currently running scilab's instance, iFigureUID - figure id of graph generated,
+ iAxeUID - axes id of graph, iPolylineUID - id for each separate output line of graph, time - current time interval(x-axis),
+ y - value of y-axis, z - value of z-axis, 1 - representing 1 output graph, block->rpar[1] - yMin value, block->rpar[2] - yMax value,
+ block->rpar[3] - refresh period, labl - Label for graph(default - "CSCOPE")
+ */
+
+ result = pushData(block, 0, i);
+ if (result == FALSE)
+ {
+ Coserror("%s: unable to push some data.", "cscope");
+ break;
+ }
+ }
+ break;
case Ending:
- sco = getScoData(block);
- sco = reallocHistoryBuffer(block, sco->internal.maxNumberOfPoints + sco->internal.numberOfPoints);
- sco->scope.disableBufferUpdate = FALSE;
- sco->scope.historyUpdateCounter = 0;
- pushHistory(block, 0, sco->internal.maxNumberOfPoints);
- deleteBufferPolylines(block);
+ sco = getScoData(block);
+ sco = reallocHistoryBuffer(block, sco->internal.maxNumberOfPoints + sco->internal.numberOfPoints);
+ sco->scope.disableBufferUpdate = FALSE;
+ sco->scope.historyUpdateCounter = 0;
+ pushHistory(block, 0, sco->internal.maxNumberOfPoints);
+ deleteBufferPolylines(block);
- fprintf(filePointer, "%d || Ending %d\n", processId, getFigure(block));
+ // Write data to define Ending phase
+ fprintf(filePointer, "%d || Ending %d\n", processId, getFigure(block));
- freeScoData(block);
- break;
+ freeScoData(block);
+ break;
default:
- break;
-}
-fclose(filePointer);
+ break;
+ }
+ // Close the file pointer
+ fclose(filePointer);
}
/*-------------------------------------------------------------------------*/