<div dir="ltr">Thank you Jeff. As I wrote in my response to Jan, that didn't resolve the problem. Moreover, reading in the bin file as type 'float32' as per your suggestion gave me back an array with all entries being 'inf' and the penultimate column being '0'.<div> I am attaching my script to make things clear.</div><div>Would it be possible to attach that python script in an email that you mention? I could not find it there.</div><div>Best</div><div>Jeremy</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 1 Apr 2021 at 23:59, Jeffery R Scott <<a href="mailto:jscott@mit.edu">jscott@mit.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="overflow-wrap: break-word;">
Hi Jeremy,
<div><br>
</div>
<div>As Jan responded, MITgcm requires big endian files, which the byteswap statement accomplishes.</div>
<div>(the other way to do this : data.astype('>f4').tofile('data.bin’) forces python to write out the field in big endian, as mentioned in manual section 3.9)</div>
<div><br>
</div>
<div>When you write out a file in big endian, you also need to tell python to read it back in big endian format:</div>
<div><br>
</div>
<div>
<div>
<div style="margin:0px;line-height:normal;background-color:rgb(255,255,255)">
<font face="Menlo"><span style="font-size:11px">tau_2_1 = np.fromfile(</span></font><span style="font-family:Menlo;font-size:11px;color:rgb(39,42,216)">'windx_siny.bin'</span><font face="Menlo"><span style="font-size:11px">,dtype=</span></font><font color="#272ad8" face="Menlo"><span style="font-size:11px">‘>f4’</span></font><font face="Menlo"><span style="font-size:11px">)</span></font></div>
</div>
</div>
<div style="margin:0px;line-height:normal;background-color:rgb(255,255,255)">
<font face="Menlo"><span style="font-size:11px"><br>
</span></font></div>
<div style="margin:0px;line-height:normal;background-color:rgb(255,255,255)">
<font face="Menlo"><span style="font-size:11px">(you might then also want to reshape it)</span></font></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">
<br>
</div>
<div>This is why when you read in field tau2_1 without telling python it is big endian, it doesn’t match your tau2 field.</div>
<div><br>
</div>
<div>However, I believe the reason your run is failing using the sine profile is different: as configured, the model expects single precision aka float32 files.</div>
<div>(MITgcm default for namelist parm <a href="http://mitgcm.org/lxr/ident/MITgcm?_i=readBinaryPrec" target="_blank">readBinaryPrec</a> is 32, i.e. float32; this can be changed in file data)</div>
<div>The cosine profile file in github is float32, and this works for you. However it looks like you are writing the sine profile file out as float64.</div>
<div><br>
</div>
<div>Incidentally, I’ve written a python gendata.py for this tutorial, and better still, a carefully documented python script to compute and display some output</div>
<div>for tutorial baroclinic gyre, which you might find very helpful. These will hopefully be merged soon into the main github repository, but for</div>
<div>now can be found in this pull request: <a href="https://github.com/MITgcm/MITgcm/pull/386" target="_blank">https://github.com/MITgcm/MITgcm/pull/386</a></div>
<div><br>
</div>
<div>Jeff</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>But if you write a file <br>
<div>
<blockquote type="cite">
<div>On Apr 1, 2021, at 9:47 AM, Jan Klaus Rieck <<a href="mailto:jan.rieck@mail.mcgill.ca" target="_blank">jan.rieck@mail.mcgill.ca</a>> wrote:</div>
<br>
<div>
<div style="text-align:left;direction:ltr">
<div>Hello Jeremy Miller,</div>
<div><br>
</div>
<div>I also use python to to generate input data for the MITgcm. I found that, to generate files that can be read by the MITgcm consistently, I needed to specify the type explicitly. </div>
<div>My way of saving the files would look like this in your case: </div>
<div><br>
</div>
<div>if sys.byteorder == 'little': tau_2.byteswap(True)</div>
<div>fid = open(''windx_siny.bin', 'wb')</div>
<div>tau_2.astype('float32').tofile(fid)</div>
<div><br>
</div>
<div>Of course, 'float32' could be replaced by 'float64' if you require double precision.</div>
<div><br>
</div>
<div>I hope this helps,</div>
<div>Jan Rieck</div>
<div> </div>
<div>On Thu, 2021-04-01 at 10:22 +0300, Jeremy Miller wrote:</div>
<blockquote type="cite" style="margin:0px 0px 0px 0.8ex;border-left:2px solid rgb(114,159,207);padding-left:1ex">
<div dir="ltr">Dear MITGCM forum,
<div><br>
</div>
<div>I am Jeremy Miller, I am new to MITgcm and I've been going through the tutorials. I have a question about the "Barotropic Ocean Gyre" tutorial (section 4.1).</div>
<div><br>
</div>
<div>I managed to compile and run the code, and re-produce the first two plots shown in section 4.1.5 for wind stress of τ = τ0 cos( πy/Ly), for both the advection and non-advection cases (with the provided input binary files). </div>
<div>I ran into problems when trying to produce the third plot, for the case where τ = τ0 sin( πy/Ly). I am a python user, so I translated gendata.m into python to write the input binary files 'windx_cosy.bin' 'windx_siny.bin' (see the file gendata_tut4.1py
attached). As explained in section 3.9 I've included the snippet </div>
<span style="color:rgb(80,0,80)">
<div><br>
</div>
<div>if sys.byteorder == 'little': tau_2.byteswap(True)</div>
<div><br>
</div>
</span>
<div>where "tau2" is the array to be output. There was no issue in the cosine wind stress, and I managed to reproduce the results that I got with the original 'windx_cosy.bin' provided in the tutorial. However, with the sine wind stress case, the output
in 'Eta.0000077760.001.001' is all zeros. </div>
<div><br>
</div>
<div>When I attempt to read 'windx_siny.bin' with python into a new array called tau2_1. I get absurdly big numbers back, which do not match the original array tau2 that I created. If I Remove the snippet " if sys.byteorder == 'little': tau_2.byteswap(True)
", in the python gendata code, tau2_1 and tau2 match. But, then when I run the code again, the file output.txt contains a long list of NaNs.</div>
<span style="color:rgb(80,0,80)">
<div><br>
</div>
<div>I have also included the python code used to generate the plots in the file <a href="http://tut_4.1_plots.py/" target="_blank">tut_4.1_plots.py</a></div>
<div><br>
</div>
<div>Look forward to hearing from you.</div>
<div>Yours sincerely</div>
<div>Jeremy Miller</div>
</span></div>
<pre>_______________________________________________</pre>
<pre>MITgcm-support mailing list</pre>
<a href="mailto:MITgcm-support@mitgcm.org" target="_blank">
<pre>MITgcm-support@mitgcm.org</pre>
</a>
<pre><br></pre>
<a href="http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support" target="_blank">
<pre>http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support</pre>
</a>
<pre><br></pre>
</blockquote>
</div>
_______________________________________________<br>
MITgcm-support mailing list<br>
<a href="mailto:MITgcm-support@mitgcm.org" target="_blank">MITgcm-support@mitgcm.org</a><br>
<a href="http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support" target="_blank">http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support</a><br>
</div>
</blockquote>
</div>
<br>
</div>
</div>
_______________________________________________<br>
MITgcm-support mailing list<br>
<a href="mailto:MITgcm-support@mitgcm.org" target="_blank">MITgcm-support@mitgcm.org</a><br>
<a href="http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support" rel="noreferrer" target="_blank">http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support</a><br>
</blockquote></div>