<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:2080979443;
        mso-list-type:hybrid;
        mso-list-template-ids:1381675330 336134161 336134169 336134171 336134159 336134169 336134171 336134159 336134169 336134171;}
@list l0:level1
        {mso-level-text:"%1\)";
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-NZ" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi, <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">After much angst and wringing of hands I have resolved my problem – by looking in a totally different bit of my code to the area I though the error was occurring.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:Consolas">The best way to track these issues turned out to be using GC.Collect(0) “A Lot”.  As soon as one stuffs up the GC will know about it.  Brilliant!!!!!!  (Just remember to comment them out
 when it is working)</span><span style="color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Lesson 1:<o:p></o:p></p>
<p class="MsoNormal">I think my C# dynamic array definition and expecting the GDAL unmanaged code to automagically resize the array may be just a little optimistic.  I could not find a definitive statement on the size the array had to be so I got lazy and then
 forgot about it (this works inside Net just hunky dory).  I will have to find out the correct array size [maximum possible] and set it first:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:blue">double</span><span style="font-size:9.5pt;font-family:Consolas">[] adblGeoTransform =
<span style="color:blue">new</span> <span style="color:blue">double</span>[0];<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">dsNetCDF.GetGeoTransform(adblGeoTransform);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:Consolas">agcpNetCDF = dsNetCDF.GetGCPs();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:Consolas"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:Consolas">whoops…<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:Consolas"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:EN-NZ">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:EN-NZ"> Robbie
 Price <br>
<b>Sent:</b> Monday, 16 March 2015 2:57 p.m.<br>
<b>To:</b> 'gdal-dev@lists.osgeo.org'<br>
<b>Subject:</b> trouble with netCDF in C#?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m having trouble converting some netcdf (version 3) files to Kea files using the GDAL C# bindings.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The problem is some form of memory leak caused by the netCDF code (from what I can establish through various tests).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">There are two issues:<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="mso-list:Ignore">1)<span style="font:7.0pt "Times New Roman"">     
</span></span><![endif]> A memory leak in this call (which I noticed, but can work around as I am only dealing with a small number of subdatasets)<o:p></o:p></p>
<p class="MsoListParagraph" style="margin-left:72.0pt;text-indent:-18.0pt;mso-list:l0 level2 lfo2;text-autospace:none">
<![if !supportLists]><span style="font-size:9.5pt;font-family:Consolas"><span style="mso-list:Ignore">a.<span style="font:7.0pt "Times New Roman""> 
</span></span></span><![endif]><span style="font-size:9.5pt;font-family:Consolas">dsNetCDF = OSGeo.GDAL.<span style="color:#2B91AF">Gdal</span>.Open(strNetCDF_DSN, OSGeo.GDAL.<span style="color:#2B91AF">Access</span>.GA_ReadOnly);<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="mso-list:Ignore">2)<span style="font:7.0pt "Times New Roman"">     
</span></span><![endif]>A memory issue/leak pointer assignment causing a crash that I cannot trace the error reports as:<o:p></o:p></p>
<p class="MsoNormal"><span style="color:red"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:red">Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'O:\Projects\KEA_ReadWrite\bin\x64\Debug\KEA_ReadWrite.vshost.exe'.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:red">Additional Information: The runtime has encountered a fatal error. The address of the error was at 0xebc85654, on thread 0x16ec. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or
 non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The error is consistent in nature but happens inconsistently in the code (between 1800 and 4000 bands) – here from another run:<o:p></o:p></p>
<p class="MsoNormal"><span style="color:red">Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'O:\Projects\KEA_ReadWrite\bin\x64\Debug\KEA_ReadWrite.vshost.exe'.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:red">Additional Information: The runtime has encountered a fatal error. The address of the error was at 0xebc85654, on thread 0x199c. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or
 non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The error <i>MAY</i> be occurring more often only on lines handling string functions (?)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Version Details<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Using MSVS 2010 (C#) and the following:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">http://www.gisinternals.com/query.html?content=filelist&file=release-1600-x64-gdal-mapserver.zip<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<table class="MsoNormalTable" border="1" cellpadding="0" style="background:white;border:solid #9999FF 1.5pt">
<tbody>
<tr>
<td style="border:solid silver 1.0pt;padding:1.5pt 6.0pt 1.5pt 6.0pt">
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Tahoma","sans-serif";color:#4F2107"><a href="http://download2.gisinternals.com/sdk/Download.aspx?file=release-1600-x64-gdal-mapserver/gdal-200-1600-x64-core.msi"><b><i><span style="font-size:13.5pt;font-family:"Segoe UI","sans-serif";color:#660066">gdal-200-1600-x64-core.msi</span></i></b></a><o:p></o:p></span></p>
</td>
<td style="border:solid silver 1.0pt;padding:1.5pt 6.0pt 1.5pt 6.0pt">
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Tahoma","sans-serif";color:#4F2107">3/15/2015 4:13 AM<o:p></o:p></span></p>
</td>
<td style="border:solid silver 1.0pt;padding:1.5pt 6.0pt 1.5pt 6.0pt">
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Tahoma","sans-serif";color:#4F2107">21556 kB<o:p></o:p></span></p>
</td>
<td style="border:solid silver 1.0pt;padding:1.5pt 6.0pt 1.5pt 6.0pt">
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Tahoma","sans-serif";color:#4F2107">Generic installer for the GDAL core components<o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Basic scenario is converting from one file type to another but taking the meta info from the NetCDF and using as band name info in the Kea file.  Input files have between 365 and 8000 bands but not large spatially (260*243).<o:p></o:p></p>
</div>
<br>
<hr>
<font face="Arial" color="Green" size="1"><br>
Please consider the environment before printing this email<br>
Warning: This electronic message together with any attachments is confidential. If you receive it in error: (i) you must not read, use, disclose, copy or retain it; (ii) please contact the sender immediately by reply email and then delete the emails.<br>
The views expressed in this email may not be those of Landcare Research New Zealand Limited. http://www.landcareresearch.co.nz<br>
</font>
</body>
</html>