<div dir="ltr"><div>Giorgio, here is a compact version of Dennis's method.  This preserves attributes, coordinates, and the fill value.  Assumptions are that dim 1 increases by 1, dim 2 is the same, and the new row is added in the last position.  Originally you said "easy", so here you go.  Untested:</div><div><br></div><div>nrows = dimsizes (a, 0)</div><div>c = new (dimsizes (a), typeof (b), getFillValue (b))</div><div>c(0:nrows-2,:) = b(:,:)</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 24, 2023 at 6:09 AM Giorgio Graffino 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"><p><span style="font-family:arial,sans-serif">Hi Dennis,</span></p><p><span style="font-family:arial,sans-serif">Thanks for the tip, but I prefer to not create the variable beforehand. I used the brute-force approch on the table_attach_rows function to read a one-dimensional array and append it to a two-dimensional array in a specific index. Probably it won't work with patterns becasue I removed the metadata part.</span></p><p><span style="font-family:arial,sans-serif">undef("table_attach_singlerow")</span><br><span style="font-family:arial,sans-serif">function table_attach_singlerow (t1[*][*], t2[*], nind:integer)</span><br><span style="font-family:arial,sans-serif">local dim_t1, dim_t2, ncol1, ncol2, nrow1,    \</span><br><span style="font-family:arial,sans-serif">     dimNames_t1, dimNames_t2, dimNames, n</span></p><p><span style="font-family:arial,sans-serif">; ******************************************************************</span><br><span style="font-family:arial,sans-serif">; Attaches/appends additional 1-D row.</span><br><span style="font-family:arial,sans-serif">; Adapted from the function table_attach_rows</span><br><span style="font-family:arial,sans-serif">; (<a href="https://github.com/NCAR/ncl/blob/develop/ni/src/examples/gsun/contributed.ncl" target="_blank">https://github.com/NCAR/ncl/blob/develop/ni/src/examples/gsun/contributed.ncl</a>).</span><br><span style="font-family:arial,sans-serif">; ******************************************************************</span></p><p><span style="font-family:arial,sans-serif">begin</span><br><span style="font-family:arial,sans-serif">                                  ; get array shape/sizes</span><br><span style="font-family:arial,sans-serif"> dim_t1  = dimsizes(t1)</span><br><span style="font-family:arial,sans-serif"> dim_t2  = dimsizes(t2)</span></p><p><span style="font-family:arial,sans-serif"> ncol1   = dim_t1(1)</span><br><span style="font-family:arial,sans-serif"> ncol2   = dim_t2(0)</span></p><p><span style="font-family:arial,sans-serif">;  if (ncol1.ne.ncol2) then</span><br><span style="font-family:arial,sans-serif">;      print ("table_attach_rows: tables must have same number of columns")</span><br><span style="font-family:arial,sans-serif">;      print ("                    ncol1="+ncol1)                                     </span><br><span style="font-family:arial,sans-serif">;      print ("                    ncol2="+ncol2)                                     </span><br><span style="font-family:arial,sans-serif">;      exit</span><br><span style="font-family:arial,sans-serif">;  end if</span></p><p><span style="font-family:arial,sans-serif"> if (typeof(t1).ne.typeof(t2)) then</span><br><span style="font-family:arial,sans-serif">     print ("table_attach_rows: arrays must be of the same type")</span><br><span style="font-family:arial,sans-serif">     print ("                    typeof(t1)="+typeof(t1)) </span><br><span style="font-family:arial,sans-serif">     print ("                    typeof(t2)="+typeof(t2)) </span><br><span style="font-family:arial,sans-serif">     exit</span><br><span style="font-family:arial,sans-serif"> end if</span><br><span style="font-family:arial,sans-serif">                                  ; allocate space for new array</span><br><span style="font-family:arial,sans-serif"> nrow1       = dim_t1(0)</span></p><p><span style="font-family:arial,sans-serif">                                  ; chk _FillValue stuff</span><br><span style="font-family:arial,sans-serif"> if (isatt(t1,"_FillValue") ) then</span><br><span style="font-family:arial,sans-serif">     tNew = new ( (/nrow1+1, ncol1/), typeof(t1), t1@_FillValue)</span><br><span style="font-family:arial,sans-serif"> else if (isatt(t2,"_FillValue") ) then</span><br><span style="font-family:arial,sans-serif">          tNew = new ( (/nrow1+1, ncol1/), typeof(t2), t2@_FillValue)</span><br><span style="font-family:arial,sans-serif">      else </span><br><span style="font-family:arial,sans-serif">          tNew = new ( (/nrow1+1, ncol1/), typeof(t2), "No_FillValue")</span><br><span style="font-family:arial,sans-serif">      end if</span><br><span style="font-family:arial,sans-serif"> end if</span></p><p><span style="font-family:arial,sans-serif">                                ; insert values</span><br><span style="font-family:arial,sans-serif"> tNew(0:nind-1,:)  = (/ t1(0:nind-1,:) /)</span><br><span style="font-family:arial,sans-serif"> tNew(nind    ,:)    = (/ t2 /)</span><br><span style="font-family:arial,sans-serif"> tNew(nind+1:,:)   = (/ t1(nind:,:) /)</span><br><span style="font-family:arial,sans-serif"> return (tNew)</span><br><span style="font-family:arial,sans-serif">end</span><br></p><p><span style="font-family:arial,sans-serif">Cheers,</span></p><p><span style="font-family:arial,sans-serif">Giorgio</span><br> </p><blockquote><p>------ Messaggio Originale ------<br>Da: <span><a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a></span><br>A: <span><a href="mailto:g.graffino@tim.it" target="_blank">g.graffino@tim.it</a></span> Cc: <span><a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a></span><br>Inviato: venerdì 21 aprile 2023 19:35<br>Oggetto: Re: [ncl-talk] Conform a multi-dimensional array to another multi-dimensional array<br></p><div dir="ltr"><div>Maybe this is a start:</div><div> </div><div>=================<br> </div><div>a(12,100),  b(11,100)     ? meta data<br> </div><div>=================</div><div>  dima = dimsizes(a)</div><div>  dimb = dimsizes(b)</div><div> </div><div>  na0   = dima(0)</div><div>  nb0   = dimb(0)</div><div> </div><div>  c       = new(dima, typeof(a))</div><div>  c(0:nb0-1) = (/  b /)    ;   (/ ... /) means no meta data</div><div> </div><div>; meta data</div><div> </div><div>  copy_VatAtts(a,c)    <br></div><div> </div><div>; If necessary, coordinate info (named dimensions and coordinate values) will hav e to be added <br><br></div><div><br></div></div><div class="gmail_quote"><div class="gmail_attr" dir="ltr">On Fri, Apr 21, 2023 at 6:21 AM Giorgio Graffino via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank"><span>ncl-talk@mailman.ucar.edu</span></a>> wrote:<br></div><blockquote class="gmail_quote" style="border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);margin:0px 0px 0px 0.8ex;padding-left:1ex"><p><span style="font-family:Arial;font-size:12pt">Dear NCL folks,</span></p><p><span style="font-family:Arial;font-size:12pt">I have two multi-dimensional arrays: array a is 12x100 and array b is 11x100. I want to conform them to make their dimensions the same. I'm sure there is an easy way to do it, but so far I failed all attempts.</span></p><p><span style="font-family:Arial;font-size:12pt">For now, I mainly tried to add a row of missing values to array b to get an array c with dimensions 12x100 (the same of array a). Here is a list of the things I tried with their error message.</span></p><p><span style="font-family:Arial;font-size:12pt">c = conform(a,b,1)                ; fatal:conform: The array to be conformed must have the same number of dimensions as indicated by the length of the last argument</span></p><p><span style="font-family:Arial;font-size:12pt">c = (/b,new(dimsizes(b(0,:)),typeof(b),b@_FillValue)/)          ; fatal:_NclBuildArray: each element of a literal array must have the same number of dimensions</span> </p><p><span style="font-family:Arial;font-size:12pt">c = array_append_record(b,new(dimsizes(b(0,:)),typeof(b),b@_FillValue),0)                  ; array_append_record: ranks not equal: rank_x1=2  rank_x2=1</span></p><p><span style="font-family:Arial;font-size:12pt">c = table_attach_rows(b,new(dimsizes(b(0,:)),typeof(b),b@_FillValue),0)             ; fatal:Number of dimensions in parameter (1) of (table_attach_rows) is (1), (2) dimensions were expected</span></p><p><span style="font-family:Arial;font-size:12pt">Please let me know what else I can try or what I've done wrong.</span></p><p><span style="font-family:Arial;font-size:12pt">Thanks,</span></p><p><span style="font-family:Arial;font-size:12pt">Giorgio</span></p></blockquote></div></blockquote>
</blockquote></div></div>