Re: Write_matrix question

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Fri, 04 Apr 2008 14:49:48 -0600

Thanks Don and Dennis. I was hoping to stay within the very simple
confines of write_matrix. Your approach will get the job done with
a bit more code.

--Dave

Don Morton wrote:
> I "think" what I had to do yesterday was sort of similar, and I saw some
> of the same issues with write_matrix(). So, I chose to do what I thought
> would be easier, and use asciiwrite(), which prints a column of items,
> unformatted. BUT, if you format the items, THEN put them in the column,
> it works out. Here's an excerpt of what I was doing, and I hope it
> helps. I guess
> I didn't specifically try it, but it seems like you "should" be able
> to do something
> like sprintf("%3d", float_value)...
>
> ; Extract the date components
> utc_date = ut_calendar(time, 0)
> yr = floattointeger(utc_date(:,0))
> mn = floattointeger(utc_date(:,1))
> dy = floattointeger(utc_date(:,2))
> hr = floattointeger(utc_date(:,3))
> mins = floattointeger(utc_date(:,4))
> sec = floattointeger(utc_date(:,5))
>
> ; Format the date
> date_str = sprinti("%0.4i", yr) + "-" + \
> sprinti("%0.2i", mn) + "-" + \
> sprinti("%0.2i", dy) + "_" + \
> sprinti("%0.2i", hr) + ":" + \
> sprinti("%0.2i", mins) + ":" + \
> sprinti("%0.2i", sec)
>
> ;;; Read in some of the atmospheric variables
> atmosPressure = f->atmos_pressure
> windSpeed_Mean = f->wind_spd_mean
> windDirVec_Avg = f->wind_dir_vec_avg
> lat = f->lat
> lon = f->lon
> alt = f->alt
>
> ; facilityID = f->facility_id
>
> ; Format the data line
> dataLine = date_str + " " + \
> sprintf("%8.3f", lat) + " " + \
> sprintf("%8.3f", lon) + " " + \
> sprintf("%8.1f", alt) + " " + \
> sprintf("%8.2f", atmosPressure) + " " + \
> sprintf("%8.3f", windSpeed_Mean) + " " + \
> sprintf("%8.3f", windDirVec_Avg)
>
> ; What we have now, folks, is a single column array, where each
> ; row is a full, formatted dataLine. So, let's print this single
> ; column formatted array
> asciiwrite("foo.ascii", dataLine)
>
>
> On Fri, Apr 4, 2008 at 1:01 PM, Dennis Shea <shea_at_ucar.edu> wrote:
>> Dave,
>>
>>
>> I am not aware of any fortran format edit descriptor that would drop
>> the decimal point. *Some* fortran compilers will do this. I do not think
>> the fortran standard specifies the behavior of (say, f4.0).
>>
>> I think that the comp.lang.fortran news group, which is very responsive,
>> could answer your question.
>>
>> D
>> Dave Allured wrote:
>>
>>> In write_matrix, I would like to suppress the decimal point on some of the
>> numbers printed. Is there a trick with the Fortran-style format string that
>> would do this?
>>> I am trying to simulate a mix of integers and reals to display a mask
>> array like this:
>>> fmtf = "f6.1, 2x, 12f2"
>>> write_matrix (index_plus_mask, fmtf, option)
>>>
>>> 12.0 1 1 1 0 0 0 0 0 0 0 0 0
>>> 11.5 1 1 1 1 1 0 0 0 0 0 0 0
>>> 11.0 0 1 1 1 1 1 0 0 0 0 0 0
>>> 10.5 0 0 1 1 1 1 1 0 0 0 0 0
>>> 10.0 0 0 0 1 1 1 1 1 0 0 0 0
>>> 9.5 0 0 0 0 1 1 1 1 1 0 0 0
>>> 9.0 0 0 0 0 0 1 1 1 1 1 0 0
>>>
>>> But this is what I actually get, because the format "f2" or "f2.0" always
>> inserts a decimal point:
>>> 12.0 1.1.1.1.1.0.0.0.0.0.0.0.
>>> 11.5 0.1.1.1.1.1.0.0.0.0.0.0.
>>>
>>> "i2" format does not work; it is illegal use with my floating point
>> numeric array.
>>> I can get the display I want with a more complicated string algorithm. I
>> am just wondering whether there is a simple formatting trick for this in
>> write_matrix. Thanks for any insights.
>>> Dave Allured
>>> CU/CIRES Climate Diagnostics Center (CDC)
>>> http://cires.colorado.edu/science/centers/cdc/
>>> NOAA/ESRL/PSD, Climate Analysis Branch (CAB)
>>> http://www.cdc.noaa.gov/
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk_at_ucar.edu
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk_at_ucar.edu
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
>
>

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Apr 04 2008 - 14:49:48 MDT

This archive was generated by hypermail 2.2.0 : Fri Apr 11 2008 - 11:01:25 MDT