<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Here is a working demo.  Read the station ID's from the first file into a local array.  Also read the station ID's and heights from the second file into two other local arrays.  Create a new array for the new heights, and the same size as the first ID array.  Then use the following method to match ID's between arrays.  The new heights array is then written out to the first file.</div><div><br></div><div>This program will work for either numeric or string station ID's.  The first three statements below are to create dummy data for demo only.  Your code to read the file arrays should replace these dummy data statements.  Also note that the "ind" function below will change size if there are any duplicate ID's in file 2, so its output needs to be handled carefully, as follows.</div><div><br></div><div><div><font face="monospace">begin</font></div><div><font face="monospace">  id1  = (/  3, 5, 7, 2, 1, 4, 6, 8, 7, 6 /)</font></div><div><font face="monospace">  id2  = (/  1, 2, 3, 4, 4, 6, 7, 8 /)</font></div><div><font face="monospace">  hgt2 = (/ 30,70,45,60,55,78,95,30 /)</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">  n1   = dimsizes (id1)</font></div><div><font face="monospace">  hgt1 = new (n1, integer, -9)</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">  do i1 = 0, n1-1</font></div><div><font face="monospace">    i2 := ind (id1(i1) .eq. id2(:))</font></div><div><font face="monospace">    if (.not. ismissing (i2(0))) then</font></div><div><font face="monospace">      hgt1(i1) = hgt2(i2(0))</font></div><div><font face="monospace">    end if</font></div><div><font face="monospace">    </font></div><div><font face="monospace">    if (dimsizes (i2) .gt. 1) then</font></div><div><font face="monospace">      print ("*** File 2 contains more than one ID = " + id1(i1))</font></div><div><font face="monospace">      print ("    Assigning value for the first ID found in file 2.")</font></div><div><font face="monospace">    end if</font></div><div><font face="monospace">    </font></div><div><font face="monospace">    if (ismissing (i2(0))) then</font></div><div><font face="monospace">      print ("*** ID not found in file 2 = " + id1(i1))</font></div><div><font face="monospace">      print ("    No value is assigned for this ID.")</font></div><div><font face="monospace">    end if</font></div><div><font face="monospace">  end do</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">  print ("ID1  =" + str_concat (sprinti ("%4i",  id1(:))))</font></div><div><font face="monospace">  print ("Hgt1 =" + str_concat (sprinti ("%4i", hgt1(:))))</font></div><div><font face="monospace">end</font></div><div><br></div><div>This demo makes the following output.  Note that -9 is a missing value in the output array.</div><div><br></div><div><div><font face="monospace">(0)<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>*** ID not found in file 2 = 5</font></div><div><font face="monospace">(0)<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>    No value is assigned for this ID.</font></div><div><font face="monospace">(0)<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>*** File 2 contains more than one ID = 4</font></div><div><font face="monospace">(0)<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>    Assigning value from the first ID found in file 2.</font></div><div><font face="monospace">(0)<span class="gmail-Apple-tab-span" style="white-space:pre">        </span></font></div><div><font face="monospace">(0)<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>ID1  =   3   5   7   2   1   4   6   8   7   6</font></div><div><font face="monospace">(0)<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>Hgt1 =  45  -9  95  70  30  60  78  30  95  78</font></div></div><div><br></div></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Sep 12, 2020 at 11:08 AM Ehsan Taghizadeh via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="font-family:"bookman old style","new york",times,serif;font-size:16px"><div dir="ltr">Dear NCL-talk</div><div dir="ltr">I hope you are doing great.</div><div dir="ltr">My question is about how to match two files based on the same id from one column.</div><div dir="ltr"><br></div><div dir="ltr">I have two files with different columns and rows. However, each of them has a column including station ids. This column has same ids for two files but not in the same order or the same number. Based on the same ids in this column I want to pass a column<span><span style="color:rgb(0,0,0);font-family:"bookman old style","new york",times,serif;font-size:16px">, including height,</span></span> from one file to the other one. I mean I want to pass height of the each station from file2 to file1.</div><div dir="ltr">May I ask how I could find the correct height from file2 and write for the proper row in file?</div><div dir="ltr">I want to ask only about the matching part.</div><div dir="ltr"><br></div><div dir="ltr">I hope I could explain the problem correctly.</div><div dir="ltr">Any help will be appreciated.</div><div dir="ltr"><br></div><div dir="ltr"><i><font size="2">Sincerely</font></i></div><div dir="ltr"><i><font size="2">Ehsan</font></i></div></div></blockquote></div></div></div></div>