# Getcode function does not return output

**URL:** <https://mworks.discourse.group/t/getcode-function-does-not-return-output/508>\
**Category:** Support\
**Created:** [July 12, 2015, 2:23pm UTC](https://mworks.discourse.group/t/getcode-function-does-not-return-output/508 "2015-07-12T14:23:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 12, 2015, 2:23pm UTC](https://mworks.discourse.group/t/getcode-function-does-not-return-output/508/1 "2015-07-12T14:23:09Z")

</div>

Hi Chris,

I am trying to extract data using getcode, however it does not return any output. I was wondering if you have suggestion on how to fix this.  
Thanks,  
Eghbal

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 13, 2015, 2:14pm UTC](https://mworks.discourse.group/t/getcode-function-does-not-return-output/508/2 "2015-07-13T14:14:05Z")

</div>

Hi Eghbal,

I’m not sure what you’re referring to. Do you mean the MWorks MATLAB function `getCodecs`? If so, then I’ll need some more details about how you’re trying to use it.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 15, 2015, 1:26pm UTC](https://mworks.discourse.group/t/getcode-function-does-not-return-output/508/3 "2015-07-15T13:26:16Z")

</div>

Yes, I meant ‘getCodecs’ , here is how I am calling the function:

d=dir([cd,‘/\*’,‘.mwk’]);  
codec = getCodecs(d(1).name);

it never returns an output, and I need to stop the function. I have attached the data file that causes the crash.

Thanks,  
Eghbal

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 15, 2015, 6:44pm UTC](https://mworks.discourse.group/t/getcode-function-does-not-return-output/508/4 "2015-07-15T18:44:55Z")

</div>

Hi Eghbal,

Thanks for the additional info.

Your data file seems to be corrupted. The event stream ends abruptly after a “Called stop on state system” message, whereas a normal experiment shutdown should contain many additional events after that point. Did this experiment terminate abnormally (e.g. with a MWServer crash)?

`getCodecs` is getting stuck because MWorks isn’t handling the corrupted data well. I can improve this somewhat, so that you’ll at least be able to retrieve events up to the point of corruption. I’ll try to get that fix in to the nightly build soon.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 16, 2015, 1:12pm UTC](https://mworks.discourse.group/t/getcode-function-does-not-return-output/508/5 "2015-07-16T13:12:57Z")

</div>

Hi Chris,

Thanks for your email.  
The experiment did not terminate due to MWServer crash, after a number of trial experiment stopped manually.  
Do you recommend any sequence for stopping the task( closing the stream, stopping MWClient, Stopping MWServer, etc).

Thanks,  
Eghbal

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 16, 2015, 7:38pm UTC](https://mworks.discourse.group/t/getcode-function-does-not-return-output/508/6 "2015-07-16T19:38:36Z")

</div>

Hi Eghbal,

> Do you recommend any sequence for stopping the task( closing the stream, stopping MWClient, Stopping MWServer, etc).

I’d recommend the following sequence:

1. Close data file (via MWClient)
2. Close experiment (via MWClient)
3. Close MWClient
4. Close MWServer

However, regardless of the shutdown sequence, the data file shouldn’t get corrupted. Let me play around a little and see if there’s some ordering of these steps that leaves the data file in an invalid state. If there is, then I need to figure out how to prevent that from happening.

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 20, 2015, 5:24pm UTC](https://mworks.discourse.group/t/getcode-function-does-not-return-output/508/7 "2015-07-20T17:24:40Z")

</div>

Hi Eghbal,

The currently [nightly build](http://dicarlo-mwdev.mit.edu/mw/MWorks-NIGHTLY.dmg) has some changes relevant to this issue:

1. You should now be able to read the pre-corruption portion of your event file.
2. It should be much harder to end up with an invalid event file due to abnormal/unexpected server shutdown.

I believe the root of the issue is that, due to file I/O buffering, the end of the data file sometimes contained an incomplete event. If the file was closed normally, the missing data would be flushed to disk, and all would be well. However, if the server process shut down before that could happen, then the file would be unreadable.

In the currently nightly, MWServer now tries to ensure that the on-disk event data is always readable, even if the file is still open. Hopefully, this will eliminate (or at least greatly reduce) future occurrences of this problem.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 20, 2015, 10:13pm UTC](https://mworks.discourse.group/t/getcode-function-does-not-return-output/508/8 "2015-07-20T22:13:22Z")

</div>

Great, Thanks a lot.  
Eghbal

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 10:38pm UTC](https://mworks.discourse.group/t/getcode-function-does-not-return-output/508/9 "2022-07-19T22:38:44Z")

</div>

Closed on July 19, 2022, 10:38pm UTC


