<div><div dir="auto">Aha! Perfect, thanks Dennis.</div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 23, 2019 at 7:30 PM Dennis Shea <<a href="mailto:shea@ucar.edu">shea@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div> If array 'x' is (say) float, abd you do</div><div><br></div><div> x = toint(x) ; floattointeger(x)</div><div> print(typeof(x)) ; float<br></div><div><br></div><div>the 'x' will still be float. NCL coerces to integer to float. Use the reassignment operator :=</div><div><br></div><div> x <b>:=</b> toint(x) ; use syntac := to reassign float to integer</div><div> print(typeof(x)) ; integer</div><div><br></div><div>Then you can use the fortran integer descriptors.</div><div><br></div></div><br><div class="gmail_quote"></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 23, 2019 at 1:32 PM Dave Allured - NOAA Affiliate via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>> wrote:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Fortran 90+ also has I0 format to suppress leading zeros on integers. Use that with integer data for this application.</div><div><br></div><div>Floattointeger will not convert to integer if you assign the result to a pre-existing float variable. Try assigning the result to a new variable not previously defined, or a previously defined variable of type integer. Use printVarSummary to confirm.</div><div><br></div><div>I think you could also use floattointeger in-line within the write_matrix procedure call, and save a little memory that way.</div><div><br></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 23, 2019 at 11:00 AM Micah Sklut <<a href="mailto:micahs2005@gmail.com" target="_blank">micahs2005@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">NCL wont allow me to use i5 format on the variable. I've used the floattointeger, but when I print that variable, it still shows that is of type float, even though the values were properly converted to integer. </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 23, 2019 at 12:57 PM Dennis Shea <<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><b> <em>fmtf</em></b>
<p>Format to be used, specified <b>via Fortran style</b>. The format string
used must agree with the variable type.</p><p>===</p><p>Google fortran edit descriptors..</p><p><span>"384(f0.1,','),f0.1"</span></p><p><span><span>"384(i5,','),i5"</span></span></p></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 23, 2019 at 12:43 PM Micah Sklut via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">This worked great Dave. I appreciate the great support. I did the asciiread to read back in all the string arrays, and then used write_table to format the final output. <div><br></div><div>One last question. When formating the write_matrix calls, I'm trying to write a float variable to integer format. When I use, floattointeger function, it properly converts the values to integers, however, it doesn't change the variable type in the metadata from float to integer. This doesn't allow me to write_matrix using integer format. Is there an easy way to get around this?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 22, 2019 at 8:31 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Write_matrix is strictly for output to only a text file, or Unix standard output. There is no internal write capability. However, you can simulate internal writes by using one or more temporary files.</div><div dir="ltr"><br></div><div dir="ltr">Read the formatted lines back in from a temp file with asciiread ("tmp.txt", -1, "string"). This gives you a 1-D array of strings, one full line for each of your grid points. Then repeat for each of your other variables. This will efficiently give you arrays of full formatted line strings for several variables.</div><div dir="ltr"><br></div><div dir="ltr">You should then be able to join these line strings together, however you have in mind. Also, now that you are operating on strings, you can add text columns at the beginning or end of each string, if this would be of any help. For example:</div><div dir="ltr"><br></div><div>long_lines = "precip," + p_lines(:) + ",Tmin," + tmin_lines(:) + ",Tmax," + tmax_lines(:)</div><div><br></div><div>This example is for joining horizontally. You could also join vertically by simply joining the string arrays, with or without interleaving. There are many variations on this theme, depending on how you want your final output to be structured.</div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 22, 2019 at 5:29 PM Micah Sklut <<a href="mailto:micahs2005@gmail.com" target="_blank">micahs2005@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Instead of sending output to a file, is it possible to do a write_matrix formatting to 1d array? I need to add more than 1 of these variables together, so if I can create 1d arrays for all of the variables and metadata, such as lat/lon, then I can use write_table to join everything together. When I'm re-ordering or reshaping the arrays, I'll just need to delete the old arrays, to free up memory. </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 22, 2019 at 1:51 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>There is a mistake in the untested example that I sent. Please change the format spec from "384(f0.1,','),f0.1" to "383(f0.1,','),f0.1". The latter is correct for 384 numbers per line. I split the format spec into two parts so that there would not be a trailing comma at the end of each line.</div><div><br></div><div>Generally speaking, the format spec in write_matrix is specified for a single output line. It is repeated for each output line. It is important that the total item count in the format spec (383 + 1 in this case) exactly matches the intended number of items per line.</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 22, 2019 at 11:32 AM Micah Sklut <<a href="mailto:micahs2005@gmail.com" target="_blank">micahs2005@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Okay, thanks, Dave. That sounds like what I need. I've always struggled with the formatting in NCL, but I'll give that a go and see where I get. </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 22, 2019 at 1:26 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Try write_matrix and the F0 format descriptor. F0 format is part of fortran 90 and up. It is described in modern fortran documentation. It is like the common Fw.d format descriptor, except leading blanks to the left of the decimal point are suppressed.</div><div><br></div><div>Reshape your array from, e.g. (lat,lon,time), to a 2-D array in the desired output order, (points,time). Npoints = Nlats x Nlons. Then a single call to write_matrix should write the entire output file:</div><div><br></div><div> opt = True</div><div> opt@fout = "temperature.csv"</div><div> write_matrix (data_out, "384(f0.1,','),f0.1", opt)</div><div><br></div><div>You can add arbitrary extra numeric columns to the output array, if it would be helpful to have lats and lons, or other such metadata, on each line of output.</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Sep 21, 2019 at 2:53 PM Micah Sklut via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi, <div><br></div><div>I have a task to take GFS data and concatenate variables across all the forecast hours, for each grid point. </div><div><br clear="all"><div>For example, taking a temperature variable for each grid point, for all latitude and longitudes, and creating a string that represents the values for each forecast hour. </div><div>So, if we have for latitude y, and longitude x, there would be a string value like "70.5,71.5,71.5,72.0,...nHours". The end product will be a line for each grid point for the variables i"m looking at that will be written to a file to be imported into a database. </div><div><br></div><div>Creating loops through all hours, latitudes, and longitudes will get the job done, but is expensive and was looking to see if there were any NCL functions that would help here. </div><div><br></div><div>Thank you.</div></div></div></blockquote></div></div></blockquote></div></blockquote></div></div></blockquote></div></blockquote></div></div></div></div></blockquote></div></blockquote></div></blockquote></div>
</blockquote></div></div></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
_______________________________________________</blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></blockquote></div>
</blockquote></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Micah Sklut<br><br></div>