| 1 | function issm(fid,toolkitstring,solutionstring,modelname){
|
|---|
| 2 | /*issm
|
|---|
| 3 | usage: var output = issm(fid,toolkitstring);
|
|---|
| 4 | where: fid is a pointer to a memory buffer created by marshall, toolkitstring is a toolkits
|
|---|
| 5 | string created by ToolkitsToFile and
|
|---|
| 6 | output is a binary buffer to be read by loadresultsfromcluster.
|
|---|
| 7 | */
|
|---|
| 8 |
|
|---|
| 9 | /*variables: */
|
|---|
| 10 | var poutput,output,poutputsize,outputsize;
|
|---|
| 11 | var dbinaryPtr,binHeap,binary,binarybuffer,nb
|
|---|
| 12 |
|
|---|
| 13 | /*recover input buffer: */
|
|---|
| 14 | binarybuffer=fid.rawbuffer(); //binarybuffer is now an arraybuffer
|
|---|
| 15 | nb = fid.ptr; //size of array buffer in bytes.
|
|---|
| 16 |
|
|---|
| 17 | /*dyanmically allocate the raw buffer onto the Module heap: */
|
|---|
| 18 | dbinaryPtr= Module._malloc(nb); binHeap = new Uint8Array(Module.HEAPU8.buffer,dbinaryPtr,nb);
|
|---|
| 19 | binHeap.set(new Uint8Array(binarybuffer)); binary=binHeap.byteOffset;
|
|---|
| 20 |
|
|---|
| 21 | /*allocate output pointers: */
|
|---|
| 22 | poutputsize = Module._malloc(4);
|
|---|
| 23 | poutput = Module._malloc(4);
|
|---|
| 24 |
|
|---|
| 25 | //Declare TriMesh module:
|
|---|
| 26 | issmmodule= Module.cwrap('IssmModule','number',['number','number','number','number','string','string','string']);
|
|---|
| 27 |
|
|---|
| 28 | //Call issm:
|
|---|
| 29 | issmmodule(poutput, poutputsize,binary, nb, toolkitstring,solutionstring,modelname);
|
|---|
| 30 |
|
|---|
| 31 | //recover outputs from pointers:
|
|---|
| 32 | var outputsize = Module.getValue(poutputsize,'i32');
|
|---|
| 33 |
|
|---|
| 34 | var outputptr = Module.getValue(poutput,'i32');
|
|---|
| 35 | output = Module.HEAP8.slice(outputptr, outputptr + outputsize);
|
|---|
| 36 |
|
|---|
| 37 | return [output,outputsize];
|
|---|
| 38 | }
|
|---|