X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 03 Apr 2007 11:07 AM by  anon
Calculating Sat. water vapor pressure from air temperature: What is wrong?
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
03 Apr 2007 11:07 AM
    Goodday, everyone. I came with a new question. Please take a look at this code. I am going to calculate saturated water vapor pressure from air temperature using clausius-clapeyron equation. The air temperature is on tem(4:27, *) in my test.txt below. ;site_id year month day h01 h02 h03 h04 h05 h06 h07 h08 h09 h10 h11 h12 h13 h14 h15 h16 h17 h18 h19 h20 h21 h22 h23 h24 ; 90 2003 1 1 -53 -21 -22 -38 -44 -52 -50 -51 -23 -12 -6 1 1 13 6 4 -13 -19 -29 -34 -43 -59 -59 -61 ; 90 2003 1 2 -71 -65 -76 -69 -70 -73 -67 -69 -43 -9 4 6 14 9 21 14 0 -5 -7 -15 -17 -13 -10 -24 ; 90 2003 1 3 -17 -7 -6 -14 -23 -9 -16 -11 -19 4 13 17 24 15 9 5 -9 -19 -19 -25 -33 -41 -50 -52 . . . I want to keep the first 1 to 4 columns and change 4 to 28 columns with this equation. tem0 = tem/10 - 273.3 ; for unit conversion from celcius into K. SatVP = 6.11*exp(19.59*(tem0-273.3)/tem0) ; modified clausius-clapeyron equation. So, I tried this way. --------------------------------- pro SatVPNWS file = 'test.txt' ndata = file_lines(file) ;number of lines in data file site_num = 72 ; NATIONAL WEATHER STATION IN KOREA tem = intarr(28, ndata) tem0 = tem/10 - 273.3 SatVP = 6.11*exp(19.59*(tem0-273.3)/tem0) close, 1 openr, 1, file ;reading air temperature measured in NWS readf, 1, tem close, 1 openw,2, 'SatVP_00.txt' for j=0,ndata-1 do begin printf, 2, tem[0:3,j], satVP[4:27,j] , format = '(4i6,2x,24F8.3, 2x)' endfor close, 2 end ----------------------------- and this is the SatVP_00.txt 90 2003 1 1 ************************************************************************************************************************************************************************************************* 90 2003 1 2 ************************************************************************************************************************************************************************************************ 90 2003 1 3 ************************************************************************************************************************************************************************************************ There must be something wrong, but I don't know what is it exactly. Firstly, I suspected the format statement. I changed the parmeters and ran again and again, but the results were always same. Please give me some suggestions for correct format for this case, and check if I make other mistakes. Thanks. Harry

    Deleted User



    New Member


    Posts:
    New Member


    --
    03 Apr 2007 11:07 AM
    There ***is*** something wrong with the FORMAT statement. Always the best way to debug a FORMAT statement is to do it in the IDL Output Log with PRINT (rather than in an output file with PRINTF) and start by getting just one element correct. Thus, if you were to debug this one problem: PRINT, SatVP[4,0], FORMAT='(F8.3)' then you would see why your output file is getting all asterisks after the first 4 elements on each line. I made an example from just the first 4 lines of your file (1 header + 3 data lines), and discovered this issue with your SatVP data: It all has values in this neighborhood: "4.36364e+017". For the 'F' format to work, then, there must be a column width of at least 19 characters, as you see below: IDL> print, SatVP[4,0], FORMAT='(F18.0)' ; not enough total character width ****************** IDL> print, SatVP[4,0], FORMAT='(F19.0)' 436364382306304000. That, of course, is not a very reader-friendly format for such a large number, so the 'E' exponential scientific notation format offers a better alternative: IDL> PRINT, SATVP[4,0], FORMAT='(E9.3)' ; Not enough total character width ********* IDL> PRINT, SATVP[4,0], FORMAT='(E10.3)' 4.364E+017 Notice how the full character width of the format must be at least 7 characters greater than the decimal precision of the output number in order to have enough room for the "E+..." substring. It must be 8 characters greater '(E11.3)', if you want a space between each number on a row. Thus, I think if you change your format statement to read: printf, 2, tem[0:3,j], satVP[4:27,j], FORMAT='(4I6,2X,24E11.3,2X)' you will have the output you are looking for. James Jones P.S. In the code lines that you pasted in your original message I see several lines that appear to be executing in the wrong place, but I assume that that is just a pasting error on your part. As it is, the example you pasted would not work unless several of the lines were moved around to different locations.
    You are not authorized to post a reply.