在Fortran中将数据读入3x3矩阵时出错

时间:2018-07-25 19:58:03

标签: io fortran

我在将数据行读入Fortran中的3x3矩阵时遇到困难。

基本上,我编写了一个文本文件,使用该文本文件编写了一个3x3变量'VAR'

<div class="prod_list_container">
               @foreach (var item in Model.UpcomingProductList)
               {
                   if (item.upcomingproduct == 1)
                   {    
                       System.Web.Script.Serialization.JavaScriptSerializer jSearializer =
                       new System.Web.Script.Serialization.JavaScriptSerializer();
                       string jsonData = jSearializer.Serialize(item.variationlist);
                       <div class="prod_list_item_wrap" data-toggle="modal" data-target="#productModal" datatodo='{"id":"@item.paraentproductsku","desc":"@item.tvdescription","sku":"@item.paraentproductsku","usualprice":"@item.usualprice","promoprice":"@item.promoprice","easttime":"@item.eststartdate","webtext":"@item.webtext","defaultdeliveryinfo":"@item.defaultdeliveryinfo","specification":"@item.webspecification","variationList":@jsonData,"itemid":"@item.itemid"}'>
                           <div class="time_onair_wrap">
                               <span class="time_onair_msg">Estimated time:</span>
                               <span class="time_onair" id="@item.eststartdate">@item.eststartdate </span>
                           </div>

                           <div class="prod_list_img_wrap">
                               <img src="~/Content/base/images/image-port-small.png" alt="product title" />
                           </div>
                           <div class="prod_list_details_wrap">
                               <input type="hidden" id="@item.parentproductid">
                               <input type="hidden" id="@item.itemid">
                               <h3>@item.tvdescription</h3>
                               <div class="list_price_wrap">
                                   @if (item.usualprice > 0)
                                   {
                                       <span class="was_price">@item.currencysymbol @item.usualprice</span>

                                   }
                                   @if (item.promoprice > 0)
                                   {
                                       <span class="list_price">@item.currencysymbol @item.promoprice</span>
                                   }
                               </div>
                               <div class="sku_wrap"><span class="sku_title">SKU:</span>@item.paraentproductsku</div>

                               <div class="stars_container">
                                   <div class="stars_wrap">
                                       <div class="stars_rating" style="width: 80%;">&nbsp;</div>
                                   </div>
                               </div>
                           </div>
                       </div>
                   }
               }
           </div

执行此操作时,文本文件按列主导的顺序在一行中包含9个元素(3x3)(即,一行显示(1,1),(2,1),(3,1)... (3,3))元素排在第n行。

我要在此处复制并粘贴输入文本文件。这就是文件的写入方式。

   open(unit = 1, file = 'Testfile', form = 'formatted', access = 'sequential', status = 'unknown', position='append')
      write(1,'(9ES15.8E2)') VAR(:,:,n)

然后我尝试通过编写

从另一个程序读取此数据
 11.19700702E+31 12.52286128E+29 13.00849485E+31 140.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 00
 21.00000000E+00 22.00000000E+00 23.00000000E+00 24.00000000E+00 0.00000000E+00 0.00000000E+00-7.72501181E+29 2.89893158E+29 6.10314111E+30
 31.00000000E+00 32.00000000E+00 33.00000000E+00 34.00000000E+00 0.00000000E+00 0.00000000E+00-1.11738378E+31 2.00291396E+31 4.38402635E+31
 41.00000000E+00 42.00000000E+00 43.00000000E+00 44.400000000E+00 0.00000000E+00 0.00000000E+00-1.19700702E+31-7.52286128E+29 2.00849485E+31
 51.00000000E+00 52.00000000E+00 530.00000000E+00 54.00000000E+00 0.00000000E+00 0.00000000E+00-7.72501181E+29 2.89893158E+29 6.10314111E+30
 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00-1.11738378E+31 2.00291396E+31 4.38402635E+31
 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00-1.19700702E+31-7.52286128E+29 2.00849485E+31
 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00-7.72501181E+29 2.89893158E+29 6.10314111E+30
 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00-1.11738378E+31 2.00291396E+31 4.38402635E+31

代码没有按我想要的方式读入元素。它的读入如下所示(并且在第一个循环后也遇到错误),我无法弄清楚它以何种顺序读取值。

 open(unit = 1, file = 'Testfile', &
 & form = 'formatted', access = 'sequential', status = 'old')

 do n = 1, m
   read(1,'(9ES15.8E2)') ((VAR(i,j,n), j=1,3), i=1,3)
enddo

我也尝试使用

 VAR   1.11970071E+32   140.000000       0.00000000       1.25228614E+30   0.00000000       0.00000000       1.30084944E+32   0.00000000       0.00000000    

        At line 309 of file SL_MODEL.f90 (unit = 1, file = '../OUTPUT_FW_NoTPW/Testfile')

    Fortran runtime error: Bad real number in item 6 of list input

,它只给我一个运行时错误(文件结尾)。

有人对此问题有见识吗?

0 个答案:

没有答案