<?xml version="1.0" encoding="UTF-8"?>
<feed
  xmlns="http://www.w3.org/2005/Atom"
  xmlns:thr="http://purl.org/syndication/thread/1.0"
  xml:lang="en"
   >
  <title type="text">Avi Gozolchiani אבי גוזולצני</title>
  <subtitle type="text">Environmental Physics at Ben Gurion University</subtitle>

  <updated>2016-06-23T10:34:42Z</updated>
  <generator uri="http://blogofile.com/">Blogofile</generator>

  <link rel="alternate" type="text/html" href="http://avigdev.github.io/blog" />
  <id>http://avigdev.github.io/blog/feed/atom/</id>
  <link rel="self" type="application/atom+xml" href="http://avigdev.github.io/blog/feed/atom/" />
  <entry>
    <author>
      <name></name>
      <uri>http://avigdev.github.io/blog</uri>
    </author>
    <title type="html"><![CDATA[MITGCM recipee for building a package]]></title>
    <link rel="alternate" type="text/html" href="http://avigdev.github.io/blog/20150611/2015-06-11-mitgcm-recipee-for-building-a-package-html" />
    <id>http://avigdev.github.io/blog/20150611/2015-06-11-mitgcm-recipee-for-building-a-package-html</id>
    <updated>2015-06-11T16:00:50Z</updated>
    <published>2015-06-11T15:13:03Z</published>
    <category scheme="http://avigdev.github.io/blog" term="mitgcm" />
    <summary type="html"><![CDATA[MITGCM recipee for building a package]]></summary>
    <content type="html" xml:base="http://avigdev.github.io/blog/20150611/2015-06-11-mitgcm-recipee-for-building-a-package-html"><![CDATA[


<p>
It is not easy to include a new functionality in a huge computer simulation such as <a href="http://mitgcm.org">MITgcm</a> , even if it is very modular and written with extensions in mind (and it is). So here is my experience with it. In the following, some of the replacements could be done on your local "code" directory, rather than on the root. The name of the example package is mypack.
</p>
<div id="outline-container-sec-1" class="outline-2">
<h2 id="sec-1"><span class="section-number-2">1</span> prepare an empty package that does nothing</h2>
<div class="outline-text-2" id="text-1">
<p>
the minimal list of files (which can be coppied, with necessary name changes of files/variables/parameters/functions, from MYPACKAGE) is:
</p>

<pre class="example">
mypack_calc.F
mypack_diagnostics_init.F
MYPACK_OPTIONS.h
MYPACK_PARAMS.h
MYPACK.h
mypack_output.F
mypack_routines.F
mypack_check.F
mypack_init_varia.F
mypack_readparms.F
</pre>


<p>
their description :
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">


<colgroup>
<col  class="left" />

<col  class="left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="left">file</th>
<th scope="col" class="left">description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="left">headers</td>
<td class="left">&#xa0;</td>
</tr>
</tbody>
<tbody>
<tr>
<td class="left">MYPACK.h</td>
<td class="left">define pkg variables, and their common blocks</td>
</tr>

<tr>
<td class="left">MYPACK_OPTIONS.h</td>
<td class="left">package specific MACRO option defs</td>
</tr>

<tr>
<td class="left">MYPACK_PARAMS.h</td>
<td class="left">package parameters and their common block  (read from data.mypack)</td>
</tr>
</tbody>
<tbody>
<tr>
<td class="left">code</td>
<td class="left">&#xa0;</td>
</tr>
</tbody>
<tbody>
<tr>
<td class="left">mypack_calc.F</td>
<td class="left">interface for mitgcnuv (this is what the model's core calls)</td>
</tr>

<tr>
<td class="left">mypack_check.F</td>
<td class="left">check dependencies/conflicts with other packages</td>
</tr>

<tr>
<td class="left">mypack_diagnostics_init.F</td>
<td class="left">define diagnostics related to the package</td>
</tr>

<tr>
<td class="left">mypack_init_varia.F</td>
<td class="left">initialize MYPACK parameters and variables</td>
</tr>

<tr>
<td class="left">mypack_output.F</td>
<td class="left">create diagnostic outputs</td>
</tr>

<tr>
<td class="left">mypack_readparms.F</td>
<td class="left">parse data.mypack</td>
</tr>

<tr>
<td class="left">mypack_routines.F</td>
<td class="left">routines that implement double diffusion parametrization schemes</td>
</tr>
</tbody>
</table>

<p>
they should be under a new directory of the rootdir (in mypack case ~/MITgcm/model/pkg/mypack )
</p>

<p>
the input file data.pkg should include the new entry "useMypack=.TRUE.," under the namelist "&amp;PACKAGES"
</p>

<p>
this parameter should be declared (with the type <code>LOGICAL</code>), and included in the common block <i>PARM_PACKAGES</i> under <code>~/MITgcm/model/inc/PARAMS.h</code> .  it should also be included under the namelist "PACKAGES" in <code>~/MITgcm/model/src/packages_boot.F</code> , and its default value should usually be declared in this file to be <code>.FALSE.</code>.
</p>
</div>
</div>

<div id="outline-container-sec-2" class="outline-2">
<h2 id="sec-2"><span class="section-number-2">2</span> parse user parameters</h2>
<div class="outline-text-2" id="text-2">
<p>
in <code>mypack_readparms</code> - create a separate NAMELIST for each namelist that should appear in <code>data.mypack</code> .
then give the parameters default values.  (e.g.       mypack_scheme    = 'kunze' )
then try to read them    (e.g.   "READ(UNIT=iUnit,NML=MYPACK_SCHEME,IOSTAT=errIO)" ) and monitor events where errIO&lt;0 :
</p>

<div class="org-src-container">

<pre class="src src-fortran"><span class="linenr"> 1: </span> <span style="color: #932092;">READ</span>(UNIT=iUnit,NML=MYPACK_SCHEME,IOSTAT=errIO)
<span class="linenr"> 2: </span> <span style="color: #932092;">IF</span> ( errIO <span style="color: #932092;">.LT.</span> 0 ) <span style="color: #932092;">THEN</span>
<span class="linenr"> 3: </span>  <span style="color: #932092;">WRITE</span>(msgBuf,<span style="color: #8b2252;">'(A)'</span>)
<span class="linenr"> 4: </span>&amp;  <span style="color: #8b2252;">'S/R INI_PARMS'</span>
<span class="linenr"> 5: </span>  <span style="color: #932092;">CALL</span> <span style="color: #0000ff;">PRINT_ERROR</span>( msgBuf , 1)
<span class="linenr"> 6: </span>  <span style="color: #932092;">WRITE</span>(msgBuf,<span style="color: #8b2252;">'(A)'</span>)
<span class="linenr"> 7: </span>&amp;  <span style="color: #8b2252;">'Error reading numerical model '</span>
<span class="linenr"> 8: </span>  <span style="color: #932092;">CALL</span> <span style="color: #0000ff;">PRINT_ERROR</span>( msgBuf , 1)
<span class="linenr"> 9: </span>  <span style="color: #932092;">WRITE</span>(msgBuf,<span style="color: #8b2252;">'(A)'</span>)
<span class="linenr">10: </span>&amp;  <span style="color: #8b2252;">'parameter file "data.mypack"'</span>
<span class="linenr">11: </span>  <span style="color: #932092;">CALL</span> <span style="color: #0000ff;">PRINT_ERROR</span>( msgBuf , 1)
<span class="linenr">12: </span>  <span style="color: #932092;">WRITE</span>(msgBuf,<span style="color: #8b2252;">'(A)'</span>)
<span class="linenr">13: </span>&amp;  <span style="color: #8b2252;">'Problem in namelist MYPACK_SCHEME'</span>
<span class="linenr">14: </span>  <span style="color: #932092;">CALL</span> <span style="color: #0000ff;">PRINT_ERROR</span>( msgBuf , 1)
<span class="linenr">15: </span>  <span style="color: #932092;">STOP</span> <span style="color: #8b2252;">'ABNORMAL END: S/R MYPACK_INIT'</span>
<span class="linenr">16: </span> <span style="color: #932092;">ENDIF</span>
<span class="linenr">17: </span>
<span class="linenr">18: </span> <span style="color: #932092;">CLOSE</span>(iUnit)
</pre>
</div>

<p>
finally tell <code>STDOUT.*</code> that you're finished
</p>
<div class="org-src-container">

<pre class="src src-fortran"><span class="linenr">1: </span><span style="color: #932092;">WRITE</span>(msgBuf,<span style="color: #8b2252;">'(A)'</span>) <span style="color: #8b2252;">' MYPACK_INIT: finished reading data.mypack'</span>
</pre>
</div>

<p>
declare these variables in <code>MYPACK_PARAMS.h</code>
</p>

<p>
these subroutines are run from the model file <code>packages_readparms.F</code>. these are the needed lines in <code>packages_readparms.F</code>:
</p>
<div class="org-src-container">

<pre class="src src-fortran"><span class="linenr">1: </span><span style="color: #b22222;">C--   </span><span style="color: #b22222;">Initialize Mypack parameters</span>
<span class="linenr">2: </span>      <span style="color: #932092;">IF</span> (useMypack) <span style="color: #932092;">CALL</span> <span style="color: #0000ff;">MYPACK_READPARMS</span>( myThid )
<span class="linenr">3: </span><span style="color: #483d8b;">#endif</span>
</pre>
</div>
</div>
</div>
<p>Copyright (C) 2015 by Avi Gozolchiani. See the <a href="/copying.html">License</a> for information about copying.<p><p><a href="/org/2015/06/11/MITGCM-recipee-for-building-a-package.org">org-mode source</a><p>]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://avigdev.github.io/blog</uri>
    </author>
    <title type="html"><![CDATA[Alternative to keyword substitution in git, using org-mode]]></title>
    <link rel="alternate" type="text/html" href="http://avigdev.github.io/blog/20150430/2015-04-30-alternative-to-keyword-substitution-in-git-using-org-mode-html" />
    <id>http://avigdev.github.io/blog/20150430/2015-04-30-alternative-to-keyword-substitution-in-git-using-org-mode-html</id>
    <updated>2015-04-30T14:08:29Z</updated>
    <published>2015-04-30T13:52:36Z</published>
    <category scheme="http://avigdev.github.io/blog" term="orgmode" />
    <category scheme="http://avigdev.github.io/blog" term="max" />
    <category scheme="http://avigdev.github.io/blog" term="git" />
    <category scheme="http://avigdev.github.io/blog" term="linux" />
    <summary type="html"><![CDATA[Alternative to keyword substitution in git, using org-mode]]></summary>
    <content type="html" xml:base="http://avigdev.github.io/blog/20150430/2015-04-30-alternative-to-keyword-substitution-in-git-using-org-mode-html"><![CDATA[


<p>
Linus Torvalds <a href="http://www.gelato.unsw.edu.au/archives/git/0610/28891.html">thinks</a> that cvs-style keyword substitution (like having the string \(Log\) substituted by actual cvs logs in text file) is idiotic. He's got some points, like avoiding mess in binary files.
 I think that seeing a log in my <a href="http://orgmode.org">org-files</a> is not that bad, and it gives me a notion of the gradual advances that were made. I found the following lines to be non-intrusive enough to make them an almost keyword-substitution-substitution.
</p>

<div class="org-src-container">

<pre class="src src-example"># git logging 
#+BEGIN_SRC sh :exports results :results raw drawer
git log | sed -e "s/^/# /g"
\#+END_SRC
</pre>
</div>
<p>Copyright (C) 2015 by Avi Gozolchiani. See the <a href="/copying.html">License</a> for information about copying.<p><p><a href="/org/2015/04/30/Alternative-to-keyword-substitution-in-git,-using-org-mode.org">org-mode source</a><p>
]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://avigdev.github.io/blog</uri>
    </author>
    <title type="html"><![CDATA[Backups on OS X]]></title>
    <link rel="alternate" type="text/html" href="http://avigdev.github.io/blog/20150319/2015-03-19-backups-on-os-x-html" />
    <id>http://avigdev.github.io/blog/20150319/2015-03-19-backups-on-os-x-html</id>
    <updated>2015-03-26T17:17:46Z</updated>
    <published>2015-03-19T18:31:45Z</published>
    <category scheme="http://avigdev.github.io/blog" term="mac" />
    <category scheme="http://avigdev.github.io/blog" term="linux" />
    <summary type="html"><![CDATA[Backups on OS X]]></summary>
    <content type="html" xml:base="http://avigdev.github.io/blog/20150319/2015-03-19-backups-on-os-x-html"><![CDATA[



<p>
Back to <a href="http://avigdev.github.io/blog/20150319/2015-03-19-backups-html/">backing up</a> (no pun intended), OS X uses a launchd system rather than "cron.daily". If you are like me, you probably don't want to know why and you don't care. You just want a cron.daily approach, and a way to know whether it worked or not. 
</p>

<p>
So put your bash script from <a href="http://avigdev.github.io/blog/20150319/2015-03-19-backups-html/">here</a> somewhere on your system, and put the following script in your ~/Library/LaunchAgents/ ,  with a name like me.bckup.daily.plist (though the name should not matter, or so they tell) : 
</p>
<pre class="example">
<span class="linenr"> 1: </span>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<span class="linenr"> 2: </span>&lt;!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/
<span class="linenr"> 3: </span>DTDs/PropertyList-1.0.dtd"&gt;
<span class="linenr"> 4: </span>&lt;plist version="1.0"&gt;
<span class="linenr"> 5: </span>&lt;dict&gt;
<span class="linenr"> 6: </span>&lt;key&gt;Label&lt;/key&gt;
<span class="linenr"> 7: </span>&lt;string&gt;me.bckup.daily&lt;/string&gt;
<span class="linenr"> 8: </span>&lt;key&gt;LowPriorityIO&lt;/key&gt;
<span class="linenr"> 9: </span>&lt;true/&gt;
<span class="linenr">10: </span>&lt;key&gt;Nice&lt;/key&gt;
<span class="linenr">11: </span>&lt;integer&gt;12&lt;/integer&gt;
<span class="linenr">12: </span>&lt;key&gt;Program&lt;/key&gt;
<span class="linenr">13: </span>&lt;string&gt;/path/to/your/script/bckup_to_hd&lt;/string&gt;
<span class="linenr">14: </span>&lt;key&gt;StartCalendarInterval&lt;/key&gt;
<span class="linenr">15: </span>&lt;dict&gt;
<span class="linenr">16: </span>&lt;key&gt;Hour&lt;/key&gt;
<span class="linenr">17: </span>&lt;integer&gt;16&lt;/integer&gt;
<span class="linenr">18: </span>&lt;key&gt;Minute&lt;/key&gt;
<span class="linenr">19: </span>&lt;integer&gt;49&lt;/integer&gt;
<span class="linenr">20: </span>&lt;/dict&gt;
<span class="linenr">21: </span>&lt;key&gt;StandardErrorPath&lt;/key&gt;
<span class="linenr">22: </span>&lt;string&gt;/path/to/log_err_file.txt&lt;/string&gt;
<span class="linenr">23: </span>&lt;key&gt;StandardOutPath&lt;/key&gt;
<span class="linenr">24: </span>&lt;string&gt;/path/to/log_out_file.txt&lt;/string&gt;
<span class="linenr">25: </span>&lt;/dict&gt;
<span class="linenr">26: </span>&lt;/plist&gt;
</pre>
<p>
with the obvious ammendments of the exact time you want it to be launched every day, and your exact absolute paths.
</p>

<p>
To begin its action for the first time, either logout and login or :
</p>
<div class="org-src-container">

<pre class="src src-sh"><span class="linenr">1: </span>launchctl load me.bckup.daily.plist
</pre>
</div>

<p>
If something went wrong, you could use <code>launchctl unload</code> instead of <code>load</code> , get things straight and <code>load</code> again.
</p>

<p>
Now, how do you know if something went wrong ? 
</p>

<p>
first, you have your log files /path/to/log_*_file.txt . Second, you could search for clues in /private/var/log/system.log in the time you designated.
</p>
<p>Copyright (C) 2015 by Avi Gozolchiani. See the <a href="/copying.html">License</a> for information about copying.<p><p><a href="/org/2015/03/19/Backups-on-OS-X.org">org-mode source</a><p>]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://avigdev.github.io/blog</uri>
    </author>
    <title type="html"><![CDATA[Backups]]></title>
    <link rel="alternate" type="text/html" href="http://avigdev.github.io/blog/20150319/2015-03-19-backups-html" />
    <id>http://avigdev.github.io/blog/20150319/2015-03-19-backups-html</id>
    <updated>2015-03-19T18:36:19Z</updated>
    <published>2015-03-19T18:31:45Z</published>
    <category scheme="http://avigdev.github.io/blog" term="mac" />
    <category scheme="http://avigdev.github.io/blog" term="linux" />
    <summary type="html"><![CDATA[Backups]]></summary>
    <content type="html" xml:base="http://avigdev.github.io/blog/20150319/2015-03-19-backups-html"><![CDATA[



<p>
Backuping should be - routine,automatic, and simple. I'm using the following: 
</p>

<div class="org-src-container">

<pre class="src src-sh"><span class="linenr">1: </span>rsync --force --ignore-errors --delete <span style="color: #8b2252;">\</span>
<span class="linenr">2: </span> --exclude /path/to/*excluded_files* <span style="color: #8b2252;">\</span>
<span class="linenr">3: </span> --backup-dir=<span style="color: #ff40ff;">`date +%Y-%m`</span> -avb /home/yourname/ <span style="color: #8b2252;">\</span>
<span class="linenr">4: </span> /path/to/your/BCK/hd
</pre>
</div>

<p>
Each month you get a new directory <code>YYYYmm</code> (year+month) on your backup hard drive, for files that have been changed/deleted during this month. You should probably delete it after a few months, but sometimes you will want to recover some data which was mistakenly deleted. Otherwise, all other files (which weren't deleted or modified) are just duplicated to the backup hd. 
</p>

<p>
If you are using linux, you should probably put this script in your <code>/etc/cron.daily/</code> directory. And give it the correct permissions.
</p>
<p>Copyright (C) 2015 by Avi Gozolchiani. See the <a href="/copying.html">License</a> for information about copying.<p><p><a href="/org/2015/03/19/Backups.org">org-mode source</a><p>]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://avigdev.github.io/blog</uri>
    </author>
    <title type="html"><![CDATA[GMT pen attributes]]></title>
    <link rel="alternate" type="text/html" href="http://avigdev.github.io/blog/20150226/2015-02-26-gmt-pen-attributes-html" />
    <id>http://avigdev.github.io/blog/20150226/2015-02-26-gmt-pen-attributes-html</id>
    <updated>2015-02-26T04:17:11Z</updated>
    <published>2015-02-26T04:17:11Z</published>
    <category scheme="http://avigdev.github.io/blog" term="gmt" />
    <summary type="html"><![CDATA[GMT pen attributes]]></summary>
    <content type="html" xml:base="http://avigdev.github.io/blog/20150226/2015-02-26-gmt-pen-attributes-html"><![CDATA[


<p>
A lot of GMT programs have flags with "<i>pen</i>" attributes. It is not very easy to find in the man pages or the pdf documentation what is a pen. So&#x2026; 
</p>

<p>
A pen is a comma separated triple parameter :
</p>
<pre class="example">
width,color,style
</pre>
<p>
where : 
</p>
<ul class="org-ul">
<li>width = faint default thinnest thinner thin thick thicker thickest fat fatter fattest obese
it can also be indicated in numbers in the range [0 18p]
</li>
<li>color = a gray shade in the range 0–255 (linearly going from black (0) to white (255)).
or RGB, by specifying r/g/b, each ranging from 0–255. Here 0/0/0 is black, 255/255/255 is white, 255/0/0 is red, etc.
or color Name. There are  663 valid color names. Use man gmtcolors to list all valid names. A very small yet versatile subset consists of the 29 choices white, black, and [light:|dark]{red, orange, yellow, green, cyan, blue, magenta, gray|grey, brown}. The color names are case-insensitive, so mixed upper and lower case can be used (like DarkGreen).
</li>
<li>style = solid, dashed, etc.
</li>
</ul>
<p>Copyright (C) 2015 by Avi Gozolchiani. See the <a href="/copying.html">License</a> for information about copying.<p><p><a href="/org/2015/02/26/GMT-pen-attributes.org">org-mode source</a><p>]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://avigdev.github.io/blog</uri>
    </author>
    <title type="html"><![CDATA[A general slicing syntax]]></title>
    <link rel="alternate" type="text/html" href="http://avigdev.github.io/blog/20150219/2015-02-19-a-general-slicing-syntax-html" />
    <id>http://avigdev.github.io/blog/20150219/2015-02-19-a-general-slicing-syntax-html</id>
    <updated>2015-02-19T11:16:40Z</updated>
    <published>2015-02-19T11:16:40Z</published>
    <category scheme="http://avigdev.github.io/blog" term="matlab" />
    <category scheme="http://avigdev.github.io/blog" term="octave" />
    <summary type="html"><![CDATA[A general slicing syntax]]></summary>
    <content type="html" xml:base="http://avigdev.github.io/blog/20150219/2015-02-19-a-general-slicing-syntax-html"><![CDATA[



<p>
To slice the 4th cross section of the second dimension of a 3-dimensional array in Matlab/Octave, you would use a code like : 
</p>
<div class="org-src-container">

<pre class="src src-matlab"><span class="linenr">1: </span>z=z(<span style="color: #228b22;">:</span>,4,<span style="color: #228b22;">:</span>);
</pre>
</div>

<p>
If you want a bit more flexibility than that, you can have the sliced dimension as a parameter, using <a href="http://www.mathworks.com/help/matlab/ref/subsref.html">subsref</a> : 
</p>

<div class="org-src-container">

<pre class="src src-matlab"><span class="linenr">1: </span>dim=2;
<span class="linenr">2: </span>idx.type=<span style="color: #8b2252;">'()'</span>;               
<span class="linenr">3: </span>idx.subs={<span style="color: #8b2252;">':'</span>,<span style="color: #8b2252;">':'</span>,<span style="color: #8b2252;">':'</span>};
<span class="linenr">4: </span>idx.subs{dim}=4;
<span class="linenr">5: </span>z=subsref(z,idx);
</pre>
</div>
<p>Copyright (C) 2015 by Avi Gozolchiani. See the <a href="/copying.html">License</a> for information about copying.<p><p><a href="/org/2015/02/19/A-general-slicing-syntax.org">org-mode source</a><p>]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://avigdev.github.io/blog</uri>
    </author>
    <title type="html"><![CDATA[save a plot in png, eps, and fig formats]]></title>
    <link rel="alternate" type="text/html" href="http://avigdev.github.io/blog/20150212/2015-02-12-save-a-plot-in-png-eps-and-fig-formats-html" />
    <id>http://avigdev.github.io/blog/20150212/2015-02-12-save-a-plot-in-png-eps-and-fig-formats-html</id>
    <updated>2015-02-12T01:07:53Z</updated>
    <published>2015-02-12T01:07:53Z</published>
    <category scheme="http://avigdev.github.io/blog" term="matlab" />
    <category scheme="http://avigdev.github.io/blog" term="octave" />
    <category scheme="http://avigdev.github.io/blog" term="workflow" />
    <summary type="html"><![CDATA[save a plot in png, eps, and fig formats]]></summary>
    <content type="html" xml:base="http://avigdev.github.io/blog/20150212/2015-02-12-save-a-plot-in-png-eps-and-fig-formats-html"><![CDATA[



<p>
When you save a figure, what you really want to save is - several formats, a fig file, all relevant data that is needed to reconstruct the fig, and a README that tells you what is there. That's the purpose of my savefigs : 
</p>

<div class="org-src-container">

<pre class="src src-matlab"><span class="linenr"> 1: </span><span style="color: #b22222;">% purpose : save a figure in png,eps, and fig formats</span>
<span class="linenr"> 2: </span><span style="color: #b22222;">% syntax : savefigs(filename,readme_text,data_str)</span>
<span class="linenr"> 3: </span><span style="color: #b22222;">% filename - file name without any suffix (savefigs does not check this, so</span>
<span class="linenr"> 4: </span><span style="color: #b22222;">% if you mistakenly set filename="stam.fig", the output files will </span>
<span class="linenr"> 5: </span><span style="color: #b22222;">% be stam.fig.fig, stam.fig.eps, stam.fig.png)</span>
<span class="linenr"> 6: </span><span style="color: #b22222;">% readme_text - a string that describes the figure, and the data.</span>
<span class="linenr"> 7: </span><span style="color: #b22222;">% data_str - a data structure that contains all needed info in</span>
<span class="linenr"> 8: </span><span style="color: #b22222;">% order to reconstruct the figure</span>
<span class="linenr"> 9: </span><span style="color: #b22222;">% </span>
<span class="linenr">10: </span><span style="color: #b22222;">% see also: print, hgsave</span>
<span class="linenr">11: </span>
<span class="linenr">12: </span>
<span class="linenr">13: </span><span style="color: #b22222;">% Copyright 2013 Avi Gozolchiani (http://tiny.cc/avigoz)</span>
<span class="linenr">14: </span><span style="color: #b22222;">% This program is free software: you can redistribute it and/or modify</span>
<span class="linenr">15: </span><span style="color: #b22222;">% it under the terms of the GNU General Public License as published by</span>
<span class="linenr">16: </span><span style="color: #b22222;">% the Free Software Foundation, either version 3 of the License, or</span>
<span class="linenr">17: </span><span style="color: #b22222;">% (at your option) any later version.</span>
<span class="linenr">18: </span><span style="color: #b22222;">%</span>
<span class="linenr">19: </span><span style="color: #b22222;">% This program is distributed in the hope that it will be useful,</span>
<span class="linenr">20: </span><span style="color: #b22222;">% but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="linenr">21: </span><span style="color: #b22222;">% </span><span style="color: #008b8b;">MERCHANTABILITY </span><span style="color: #b22222;">or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="linenr">22: </span><span style="color: #b22222;">% </span><span style="color: #008b8b;">GNU </span><span style="color: #b22222;">General Public License for more details.</span>
<span class="linenr">23: </span><span style="color: #b22222;">%</span>
<span class="linenr">24: </span><span style="color: #b22222;">% You should have received a copy of the GNU General Public License</span>
<span class="linenr">25: </span><span style="color: #b22222;">% along with this program.  If not, see &lt;<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.</span>
<span class="linenr">26: </span>
<span class="linenr">27: </span><span style="color: #b22222;">% $Log$</span>
<span class="linenr">28: </span><span style="color: #932092;">function</span> <span style="color: #0000ff;">savefigs</span>(<span style="color: #a0522d;">filename</span>,<span style="color: #a0522d;">readme_text</span>,<span style="color: #a0522d;">data_str</span>)
<span class="linenr">29: </span>isoctave=(exist(<span style="color: #8b2252;">'OCTAVE_VERSION'</span>,<span style="color: #8b2252;">'builtin'</span>)<span style="color: #228b22;">~=</span>0);
<span class="linenr">30: </span><span style="color: #932092;">if</span>(isoctave)
<span class="linenr">31: </span>    prints=struct(<span style="color: #8b2252;">'suff'</span>,{<span style="color: #8b2252;">'png'</span>,<span style="color: #8b2252;">'eps'</span>},<span style="text-decoration: underline;">...</span>
<span class="linenr">32: </span>                  <span style="color: #8b2252;">'func'</span>,{@(x)print(<span style="color: #8b2252;">'-dpng'</span>,x),@(x)print(<span style="color: #8b2252;">'-depsc2'</span>,x)});    
<span class="linenr">33: </span><span style="color: #932092;">else</span>
<span class="linenr">34: </span>    prints=struct(<span style="color: #8b2252;">'suff'</span>,{<span style="color: #8b2252;">'png'</span>,<span style="color: #8b2252;">'eps'</span>,<span style="color: #8b2252;">'fig'</span>},<span style="text-decoration: underline;">...</span>
<span class="linenr">35: </span>                  <span style="color: #8b2252;">'func'</span>,{@(x)print(<span style="color: #8b2252;">'-dpng'</span>,x),@(x)print(<span style="color: #8b2252;">'-depsc2'</span>,x), <span style="text-decoration: underline;">...</span>
<span class="linenr">36: </span>                        @hgsave});
<span class="linenr">37: </span><span style="color: #932092;">end</span>
<span class="linenr">38: </span>n_printfuncs=length(prints);
<span class="linenr">39: </span><span style="color: #932092;">for</span> <span style="color: #a0522d;">i_printfunc</span>=<span style="color: #008b8b;">1:n_printfuncs </span><span style="color: #b22222;">% fig,png, and eps files</span>
<span class="linenr">40: </span>    prints(i_printfunc).func([filename,<span style="color: #8b2252;">'.'</span>,prints(i_printfunc).suff]);
<span class="linenr">41: </span><span style="color: #932092;">end</span> <span style="color: #b22222;">% for </span><span style="color: #b22222;">i_printfunc</span><span style="color: #b22222;">=</span><span style="color: #b22222;">1:n_printfuncs</span>
<span class="linenr">42: </span><span style="color: #b22222;">% document what is it</span>
<span class="linenr">43: </span>fid=fopen([filename,<span style="color: #8b2252;">'_README'</span>,<span style="color: #8b2252;">'.txt'</span>],<span style="color: #8b2252;">'wt'</span>);
<span class="linenr">44: </span>fprintf(fid,<span style="color: #8b2252;">'%s'</span>,readme_text);
<span class="linenr">45: </span>fclose(fid);
<span class="linenr">46: </span><span style="color: #b22222;">% save the vector/matrix for future crunching</span>
<span class="linenr">47: </span>save([filename,<span style="color: #8b2252;">'_data'</span>,<span style="color: #8b2252;">'.mat'</span>],<span style="color: #8b2252;">'data_str'</span>);
</pre>
</div>
<p>Copyright (C) 2015 by Avi Gozolchiani. See the <a href="/copying.html">License</a> for information about copying.<p><p><a href="/org/2015/02/12/save-a-plot-in-png,-eps,-and-fig-formats.org">org-mode source</a><p>]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://avigdev.github.io/blog</uri>
    </author>
    <title type="html"><![CDATA[Regridding unequally spaced sampled field, and plotting an imagesc]]></title>
    <link rel="alternate" type="text/html" href="http://avigdev.github.io/blog/20150207/2015-02-07-regridding-unequally-spaced-sampled-field-and-plotting-an-imagesc-html" />
    <id>http://avigdev.github.io/blog/20150207/2015-02-07-regridding-unequally-spaced-sampled-field-and-plotting-an-imagesc-html</id>
    <updated>2015-02-07T18:48:28Z</updated>
    <published>2015-02-07T18:48:28Z</published>
    <category scheme="http://avigdev.github.io/blog" term="matlab" />
    <category scheme="http://avigdev.github.io/blog" term="octave" />
    <summary type="html"><![CDATA[Regridding unequally spaced sampled field, and plotting an imagesc]]></summary>
    <content type="html" xml:base="http://avigdev.github.io/blog/20150207/2015-02-07-regridding-unequally-spaced-sampled-field-and-plotting-an-imagesc-html"><![CDATA[



<p>
In <a href="http://avigdev.github.io/blog/20150112/2015-01-12-matlab-discrete-colorbar-html/">a previous post</a> we discussed a better way for using imagesc, with a more sane colormap. Let's now speak about the grid. Imagesc will happily embed every xy-axis you plug in, without checking whether dimensions fit. If your grid is non-equally spaced - it will just draw the z-axis on a regular axis (i.e. ignoring the xy input), and show the xy-axes as if they genuinely represent the input. My conclusion from this wild behavior is - never use imagesc on non-equally spaced data. Matlab has nice interpolant interfaces to help you get your data equally gridded. 
</p>

<div class="org-src-container">

<pre class="src src-matlab"><span class="linenr">1: </span>[x1,y1]=ndgrid(x,y); <span style="color: #b22222;">% this step is actually not crucial</span>
<span class="linenr">2: </span>I = griddedInterpolant(x1,y1,z);  
<span class="linenr">3: </span>x1 = linspace(min(x),max(x),5);     <span style="color: #b22222;">% Define an equally spaced grid</span>
<span class="linenr">4: </span>y1 = linspace(min(y),max(y),5);
<span class="linenr">5: </span>[x1,y1]=ndgrid(x1,y1);
<span class="linenr">6: </span>z1=I(x1,y1);
<span class="linenr">7: </span>myimagesc(x1(1,<span style="color: #228b22;">:</span>),y1(<span style="color: #228b22;">:</span>,1),z1,0.55,0.95,0.05);
</pre>
</div>

<p>
Where your input parameters to <a href="http://avigdev.github.io/blog/20150112/2015-01-12-matlab-discrete-colorbar-html/">myimagesc</a> may vary, and you could replace "5" by whatever division of the equally spaced grids you fancy. 
</p>
<p>Copyright (C) 2015 by Avi Gozolchiani. See the <a href="/copying.html">License</a> for information about copying.<p><p><a href="/org/2015/02/07/Regridding-unequally-spaced-sampled-field,-and-plotting-an-imagesc.org">org-mode source</a><p>]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://avigdev.github.io/blog</uri>
    </author>
    <title type="html"><![CDATA[Screen - unique logs for each run]]></title>
    <link rel="alternate" type="text/html" href="http://avigdev.github.io/blog/20150129/2015-01-29-screen-unique-logs-for-each-run-html" />
    <id>http://avigdev.github.io/blog/20150129/2015-01-29-screen-unique-logs-for-each-run-html</id>
    <updated>2015-01-29T01:58:34Z</updated>
    <published>2015-01-29T01:58:34Z</published>
    <category scheme="http://avigdev.github.io/blog" term="workflow" />
    <category scheme="http://avigdev.github.io/blog" term="linux" />
    <summary type="html"><![CDATA[Screen - unique logs for each run]]></summary>
    <content type="html" xml:base="http://avigdev.github.io/blog/20150129/2015-01-29-screen-unique-logs-for-each-run-html"><![CDATA[



<p>
<a href="https://wiki.archlinux.org/index.php/GNU_Screen">Screen</a> is a little wrap around linux shell that enables detaching and logging out while the session you created is still running. It could be used for lots of different purposes, and running an intensive computation on a remote computer is an obvious example.
</p>

<p>
You would normally do :
</p>
<div class="org-src-container">

<pre class="src src-sh"><span class="linenr">1: </span>screen -md -L -S session_name your_program
</pre>
</div>

<p>
-md = detach immediately after running, and return to the current terminal session
-L = create a log file
-S = create meaningful name for your session
</p>

<p>
To check the stat of your sessions you will use:
</p>
<div class="org-src-container">

<pre class="src src-sh"><span class="linenr">1: </span>screen -ls
</pre>
</div>

<p>
To have different log files with unique names for different sessions, you need to create a <code>~/.screenrc</code> file, with the following single line
</p>
<pre class="example">
logfile screenlog-%Y%m%d-%c:%s
</pre>
<p>Copyright (C) 2015 by Avi Gozolchiani. See the <a href="/copying.html">License</a> for information about copying.<p><p><a href="/org/2015/01/29/Screen---unique-logs-for-each-run.org">org-mode source</a><p>]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://avigdev.github.io/blog</uri>
    </author>
    <title type="html"><![CDATA[Consistent Latex units in non italics]]></title>
    <link rel="alternate" type="text/html" href="http://avigdev.github.io/blog/20150127/2015-01-27-consistent-latex-units-in-non-italics-html" />
    <id>http://avigdev.github.io/blog/20150127/2015-01-27-consistent-latex-units-in-non-italics-html</id>
    <updated>2015-01-27T19:24:35Z</updated>
    <published>2015-01-27T19:23:23Z</published>
    <category scheme="http://avigdev.github.io/blog" term="latex" />
    <summary type="html"><![CDATA[Consistent Latex units in non italics]]></summary>
    <content type="html" xml:base="http://avigdev.github.io/blog/20150127/2015-01-27-consistent-latex-units-in-non-italics-html"><![CDATA[



<p>
Yet another latex tidbit. Its purpose - remove <i>italics</i> from the units inside math mode.
</p>

<p>
in the header :
</p>
<div class="org-src-container">

<pre class="src src-latex"><span class="linenr">1: </span><span style="color: #932092;">\newcommand</span>{<span style="color: #0000ff;">\unit</span>}[1]{<span style="color: #932092;">\ensuremath</span>{<span style="color: #932092;">\,</span> <span style="color: #932092;">\mathrm</span>{#1}}}
</pre>
</div>

<p>
in the body :
</p>
<div class="org-src-container">

<pre class="src src-latex"><span class="linenr">1: </span><span style="color: #8b2252;">$\tau=0.0257\left[\unit{N\cdot m^</span><span style="color: #8b2252;">{-2}</span><span style="color: #8b2252;">}\right]$</span>
</pre>
</div>

<p>
If you want to take this approach to the very extreme, you could have the units of every var defined in the header : 
</p>
<div class="org-src-container">

<pre class="src src-latex"><span class="linenr">1: </span><span style="color: #932092;">\newcommand</span>{<span style="color: #0000ff;">\tauunit</span>}{<span style="color: #932092;">\unit</span>{N}<span style="color: #932092;">\cdot\unit</span>{m}^{-2}}
</pre>
</div>

<p>
And use them consistently without silly unit mistakes inside your manuscript : 
</p>
<div class="org-src-container">

<pre class="src src-latex"><span class="linenr">1: </span><span style="color: #8b2252;">$\tau=0.4\tauunit$</span>
</pre>
</div>
<p>Copyright (C) 2015 by Avi Gozolchiani. See the <a href="/copying.html">License</a> for information about copying.<p><p><a href="/org/2015/01/27/Consistent-Latex-units-in-non-italics.org">org-mode source</a><p>]]></content>
  </entry>
</feed>
