<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello,<div class=""><br class=""></div><div class="">Compiling NCL_NCARG 6.4 on OSX with Intel ifort resulted in random crashes for me. Debugging the code, I saw that ncl was crashing where C code was accessing fortran strings. As explained in this note by Intel:</div><div class=""><br class=""></div><div class=""> <a href="https://software.intel.com/en-us/articles/passing-character-string-in-intel-64-mixed-fortranc-project" class="">https://software.intel.com/en-us/articles/passing-character-string-in-intel-64-mixed-fortranc-project</a></div><div class=""><br class=""></div><div class="">the hidden string length with Intel fortran is 8 bytes for x86_64 and 4 bytes for 32-bit code. In the NCL source code, size_t should therefore be used when passing string lengths between C and Fortran when using the Intel fortran compiler.</div><div class=""><br class=""></div><div class="">Gfortran always uses 4 byte integers for the string length, so the current NCL code works with gfortran.</div><div class=""><br class=""></div><div class="">So, for example, in ni/src/lib/hlu/Format.c, the code:</div><div class=""><br class=""></div><div class=""><div class=""> NGCALLF(cpinrc,CPINRC)();</div><div class=""><br class=""></div><div class=""> {</div><div class=""> int len1,len2,len3,len4;</div><div class=""> NGstring cex1_f;</div><div class=""> NGstring cex2_f;</div><div class=""> NGstring cex3_f;</div><div class=""> NGstring cbuf_f;</div><div class=""> char *cbuf_c;</div><div class=""> len1 = NGSTRLEN(cex1);</div><div class=""> len2 = NGSTRLEN(cex2);</div><div class=""> len3 = NGSTRLEN(cex3);</div><div class=""> len4 = 128;</div><div class=""> cex1_f = NGCstrToFstr(cex1,len1);</div><div class=""> cex2_f = NGCstrToFstr(cex2,len2);</div><div class=""> cex3_f = NGCstrToFstr(cex3,len3);</div><div class=""> cbuf_f = NGCstrToFstr(cbuf,len4);</div><div class=""> NGCALLF(cpnumb,CPNUMB)(&value,&ndgd,&lmsd,&iexp,&lexp,</div><div class=""> cex1_f,cex2_f,cex3_f,</div><div class=""> &lex1[ix],&lex2[ix],&lex3[ix],</div><div class=""> &ioma,&iodp,&iotz,cbuf_f,&nbuf,&ndgs,&ieva,</div><div class=""> len1,len2,len3,len4);</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">should be</div><div class=""><br class=""></div><div class=""><div class=""> NGCALLF(cpinrc,CPINRC)();</div><div class=""><br class=""></div><div class=""> {</div><div class=""> size_t len1,len2,len3,len4;</div><div class=""> NGstring cex1_f;</div><div class=""> NGstring cex2_f;</div><div class=""> NGstring cex3_f;</div><div class=""> NGstring cbuf_f;</div><div class=""> char *cbuf_c;</div><div class=""> len1 = NGSTRLEN(cex1);</div><div class=""> len2 = NGSTRLEN(cex2);</div><div class=""> len3 = NGSTRLEN(cex3);</div><div class=""> len4 = 128;</div><div class=""> cex1_f = NGCstrToFstr(cex1,len1);</div><div class=""> cex2_f = NGCstrToFstr(cex2,len2);</div><div class=""> cex3_f = NGCstrToFstr(cex3,len3);</div><div class=""> cbuf_f = NGCstrToFstr(cbuf,len4);</div><div class=""> NGCALLF(cpnumb,CPNUMB)(&value,&ndgd,&lmsd,&iexp,&lexp,</div><div class=""> cex1_f,cex2_f,cex3_f,</div><div class=""> &lex1[ix],&lex2[ix],&lex3[ix],</div><div class=""> &ioma,&iodp,&iotz,cbuf_f,&nbuf,&ndgs,&ieva,</div><div class=""> len1,len2,len3,len4);</div></div><div class=""><br class=""></div><div class="">for the Intel compiler. Changing some of these resulting in a working NCL for me.</div><div class=""><br class=""></div><div class="">Although passing the wrong size argument on OSX causes crashes, Linux seems more forgiving and the code doesn’t crash (although it’s still incorrect).</div><div class=""><br class=""></div><div class="">Maybe the type for fortran string sizes should be a preprocessing symbol that gets set before compilation to “size_t” or “int” depending on if one is using ifort or gfortran?</div><div class=""><br class=""></div><div class="">Thanks and I hope this is helpful,</div><div class=""><br class=""></div><div class="">Martin</div><div class=""><br class=""></div></body></html>