{"id":237,"date":"2020-03-14T16:29:47","date_gmt":"2020-03-14T08:29:47","guid":{"rendered":"https:\/\/www.yemeng.site\/?p=237"},"modified":"2022-05-30T14:36:09","modified_gmt":"2022-05-30T06:36:09","slug":"fortran%e7%a8%8b%e5%ba%8f%e7%94%9f%e6%88%90%e7%9a%84%e4%ba%8c%e8%bf%9b%e5%88%b6%e6%96%87%e4%bb%b6%e7%9a%84%e8%af%bb%e5%8f%96%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/ru.yemeng.site\/?p=237","title":{"rendered":"Fortran\u7a0b\u5e8f\u751f\u6210\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u7684\u683c\u5f0f\u95ee\u9898"},"content":{"rendered":"\n<p>\u6700\u8fd1\u5728\u7528C++\u7a0b\u5e8f\u8bfb\u53d6Fortran\u7a0b\u5e8f\u751f\u6210\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff08\u5373\u7528unformatted\u683c\u5f0f\u6253\u5f00\u5e76\u5199\u5165\u7684\u6587\u4ef6\uff09\u65f6\u9047\u5230\u4e00\u4e9b\u95ee\u9898\uff0c\u8fd9\u91cc\u5bf9\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u7684\u8fc7\u7a0b\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u8bb0\u5f55\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8ePWmat\u751f\u6210\u7684\u7535\u8377\u5bc6\u5ea6\u6587\u4ef6\uff0c\u53ef\u4ee5\u7528<a href=\"http:\/\/www.pwmat.com:8080\/upload\/utility\/file\/convert_rho.zip\">convert_rho.x<\/a>\u5c06\u5176\u8f6c\u6210xsf\u6587\u4ef6\uff0c\u76f8\u5173\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"fortran\" class=\"language-fortran\">program convert_rho\nimplicit none\ninteger n1,n2,n3,nnodes\nreal*8 AL(3,3)\nopen(11,file=\"TEST.RHO\",form=\"unformatted\")\nrewind(11)\nread(11) n1,n2,n3,nnodes\nread(11) AL\n......<\/code><\/pre>\n\n\n\n<p>\u8bfb\u53d6\u7684\u524d\u56db\u4e2a\u6574\u578b\u6570\u4f9d\u6b21\u4e3a128\u3001128\u3001128\u548c16384\u3002\u5982\u679c\u7528C++\u7a0b\u5e8f\u8bfb\u53d6\u540c\u6837\u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u7684\u5c06\u4e0a\u9762\u7684\u4ee3\u7801\u5bf9\u5e94\u7684\u6539\u5199\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">#include &lt;iostream&gt;\n#include &lt;fstream&gt;\nint main()\n{\n    int n1,n2,n3,nnodes;\n    double AL[3][3];\n    std::ifstream infile (\"TEST.RHO\", std::ios::in|std::ios::binary);\n    if (infile.is_open())\n    {\n        infile.seekg(0, std::ios::beg);\n        \/\/read the first line\n        infile.read((char*)&amp;n1, sizeof(int));\n        infile.read((char*)&amp;n2, sizeof(int));\n        infile.read((char*)&amp;n3, sizeof(int));\n        infile.read((char*)&amp;nnodes, sizeof(int));\n        \/\/read the second line\n        for(int i = 0; i &lt; 3; i++)\n        {\n            infile.read((char*)AL[i], 3 * sizeof(double));\n        }\n......<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f\u5230\u8fd9\u91cc\u8bfb\u53d6\u4e8c\u8fdb\u5236\u6587\u4ef6\u4f7f\u7528read\u65b9\u6cd5\u4e2d\u7528\u5230\u7684\u662f\u4e00\u4e2a<code>char*<\/code>\u578b\u7684\u6307\u9488\uff0c\u5b9e\u9645\u4e0a\u662f\u6309\u7167\u5b57\u8282\u8bfb\u53d6\u518d\u8f6c\u6210\u76f8\u5e94\u7684\u6570\u636e\u7c7b\u578b\u3002\u7136\u800c\u7528\u4e0a\u9762\u7684\u4ee3\u7801\u8bfb\u51fa\u7684\u524d\u56db\u4e2a\u6574\u578b\u53c2\u6570\u4f9d\u6b21\u4e3a16\u3001128\u3001128\u548c128\uff0c\u4e0eFortran\u7a0b\u5e8f\u8bfb\u53d6\u51fa\u7684\u4e0d\u4e00\u81f4\u3002\u9996\u5148\uff0c\u6211\u4eec\u7528<code>hexdump<\/code>\u5de5\u5177\u67e5\u770bTEST.RHO\u6587\u4ef6\u7684\u5934\u90e8\u4fe1\u606f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ hexdump -n 48 TEST.RHO \n0000000 0010 0000 0080 0000 0080 0000 0080 0000\n0000010 4000 0000 0010 0000 0048 0000 5f10 5fc3\n0000020 b9d5 4028 0000 0000 0000 0000 0000 0000\n0000030<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f\u5230x86\u5e73\u53f0\u4f7f\u7528\u7684\u662f\u5c0f\u7aef\uff08little endian\uff09\u5b57\u8282\u5e8f\uff0c\u5373\u4f4e\u4f4d\u5b57\u8282\u5728\u524d\u800c\u9ad8\u4f4d\u5b57\u8282\u5728\u540e\u3002\u56e0\u6b64\u524d\u56db\u4e2a\u5b57\u8282\u5b58\u50a8\u7684\u6574\u578b\u6570\u4e3a<code>0x00000010<\/code>\u537316\uff0c\u540e\u9762\u4e09\u4e2a\u6574\u578b\u6570\u5747\u4e3a<code>0x00000080<\/code>\u5373128\u3002\u7531\u6b64\u53ef\u89c1C++\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u662f\u6ca1\u6709\u95ee\u9898\u7684\uff0c\u95ee\u9898\u5728\u4e8e\u4e8c\u8fdb\u5236\u6587\u4ef6\u5177\u6709\u7279\u6b8a\u7684\u683c\u5f0f\u3002<\/p>\n\n\n\n<p>\u5173\u4e8eFortran\u7a0b\u5e8f\u8f93\u51fa\u7684\u683c\u5f0f\u53ef\u4ee5\u53c2\u770b<a href=\"http:\/\/paulbourke.net\/dataformats\/reading\/\">\u8fd9\u7bc7\u6587\u7ae0<\/a>\u3002\u7b80\u5355\u7684\u8bf4\uff0cFortran\u5bf9\u4e8eunformatted\u683c\u5f0f\u7684\u6587\u4ef6\u662f\u6309\u7167\u884c\u8fdb\u884c\u8bfb\u5199\u7684\uff0c\u5728\u6bcf\u884c\u7684\u5f00\u5934\u548c\u7ed3\u5c3e\u4f1a\u5404\u4f7f\u75284\u4e2a\u5b57\u8282\uff08\u6574\u5f62\uff09\u5b58\u50a8\u8be5\u884c\u5b58\u50a8\u9700\u8981\u7684\u5b57\u8282\u6570\uff08\u4e0d\u5305\u62ec\u5934\u90e8\u548c\u5c3e\u90e8\uff09\u3002 <\/p>\n\n\n\n<p>\u4ee5\u4e0a\u9762\u7684TEST.RHO\u6587\u4ef6\u4e3a\u4f8b\uff0c\u524d\u56db\u4e2a\u5b57\u8282\u5b58\u50a8\u7684\u6574\u578b\u657016\u8868\u793a\u7b2c\u4e00\u884c\u5b58\u50a8\u9700\u898116\u4e2a\u5b57\u8282\uff084\u4e2a\u6574\u578b\u6570\uff0c\u5373n1, n2 , n3, nnodes\uff09\u56e0\u6b64\u540e\u9762\u4e09\u4e2a128\u5bf9\u5e94n1\u3001n2 \u548cn3\uff0c\u63a5\u4e0b\u6765\u56db\u4e2a\u5b57\u8282\u5b58\u50a8\u7684<code>0x00004000<\/code>\u537316384\u8868\u793annodes\uff0c\u540e\u9762\u56db\u4e2a\u5b57\u8282\u5b58\u50a8\u768416\u8868\u793a\u7b2c\u4e00\u884c\u7684\u5c3e\u90e8\u3002\u63a5\u4e0b\u6765\u770b\u7b2c\u4e8c\u884c\uff0c\u5f00\u5934\u56db\u4e2a\u5b57\u8282<code>0x00000048<\/code>\u537372\u8868\u793a\u7b2c\u4e8c\u884c\u5b58\u50a8\u9700\u898172\u4e2a\u5b57\u8282\uff088\u4e2a\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\uff09\uff0c\u518d\u63a5\u4e0b8\u4e2a\u5b57\u8282<code>0x4028B9D55FC35F10<\/code>\uff0c\u4f7f\u7528<a href=\"http:\/\/www.binaryconvert.com\/result_double.html?hexadecimal=4028B9D55FC35F10\">\u8f6c\u6362\u5de5\u5177<\/a>\u53ef\u4ee5\u770b\u5230\u5176\u8868\u793a\u7684\uff08IEEE 754\uff09\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\u7ea6\u4e3a12.363\uff0c\u4ee5\u4e0b\u7684\u90e8\u5206\u7c7b\u4f3c\u3002<\/p>\n\n\n\n<p>\u5173\u4e8e\u6bcf\u4e00\u884c\u7684\u5934\u90e8\u548c\u5c3e\u90e8\uff0cFortran\u8bed\u8a00\u4e2d\u7684<code>read<\/code>\u548c<code>write<\/code>\u8fc7\u7a0b\u4f1a\u81ea\u52a8\u8fdb\u884c\u5904\u7406\uff0c\u4f46\u662fC++\u8bed\u8a00\u4e2d\u6309\u7167\u5b57\u8282\u4f9d\u6b21\u8bfb\u53d6\u5c31\u9700\u8981\u5728\u6bcf\u884c\u8bfb\u53d6\u524d\u540e\u5206\u522b\u52a0\u4e0a\u4e00\u6b21\u8bfb\u53d6\u6574\u578b\u6570\u3002\u56e0\u6b64\u4e0a\u9762\u7684C++\u4ee3\u7801\u5e94\u8be5\u6539\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">#include &lt;iostream&gt;\n#include &lt;fstream&gt;\nint main()\n{\n    int nbyte;\n    int n1,n2,n3,nnodes;\n    double AL[3][3];\n    std::ifstream infile (\"TEST.RHO\", std::ios::in|std::ios::binary);\n    if (infile.is_open())\n    {\n        infile.seekg(0, std::ios::beg);\n        \/\/read the first line\n        infile.read((char*)&amp;nbyte, sizeof(int));\n        infile.read((char*)&amp;n1, sizeof(int));\n        infile.read((char*)&amp;n2, sizeof(int));\n        infile.read((char*)&amp;n3, sizeof(int));\n        infile.read((char*)&amp;nnodes, sizeof(int));\n        infile.read((char*)&amp;nbyte, sizeof(int));\n        \/\/read the second line\n        infile.read((char*)&amp;nbyte, sizeof(int));\n        for(int i = 0; i &lt; 3; i++)\n        {\n            infile.read((char*)AL[i], 3 * sizeof(double));\n        }\n        infile.read((char*)&amp;nbyte, sizeof(int));\n......<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\u8bfb\u53d6\u7684\u6570\u636e\u5c31\u548cFortran\u7a0b\u5e8f\u4e00\u81f4\u4e86\u3002\u5f53\u7136\uff0c\u8fd9\u91cc\u7684\u7a0b\u5e8f\u8fd8\u6bd4\u8f83\u7c97\u7cd9\uff0c\u4e5f\u8bb8\u8fd8\u6709\u66f4\u597d\u7684\u5904\u7406\u7684\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5728\u7528C++\u7a0b\u5e8f\u8bfb\u53d6Fortran\u7a0b\u5e8f\u751f\u6210\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff08\u5373\u7528unformatted\u683c\u5f0f\u6253\u5f00\u5e76\u5199\u5165\u7684\u6587\u4ef6\uff09\u65f6\u9047 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,9],"tags":[8],"class_list":["post-237","post","type-post","status-publish","format-standard","hentry","category-7","category-9","tag-fortran"],"_links":{"self":[{"href":"https:\/\/ru.yemeng.site\/index.php?rest_route=\/wp\/v2\/posts\/237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ru.yemeng.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ru.yemeng.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ru.yemeng.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ru.yemeng.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=237"}],"version-history":[{"count":31,"href":"https:\/\/ru.yemeng.site\/index.php?rest_route=\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":359,"href":"https:\/\/ru.yemeng.site\/index.php?rest_route=\/wp\/v2\/posts\/237\/revisions\/359"}],"wp:attachment":[{"href":"https:\/\/ru.yemeng.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ru.yemeng.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ru.yemeng.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}