PDA

View Full Version : Fortran: Creating table and interpolation


smurray444
04-26-2007, 01:33 PM
Hi there,

I have a global dataset (text file) where for every 105 values (currently formatted as a continuous string), the 1st represents longitude, the 2nd = latitude, the 3rd is a 'spinup' value which can be ignored, and the 4th to 105th values are hydrological runoff values for the years 1901 to 2002.

I've been trying to create a table where longitude values are listed along the top row (x-axis) and latitude values are listed in the far left column (y-axis), with the corresponding runoff values for each year located in a given grid - therefore there will be 102 grids created (one for each year). The longitude values are currently not ordered and will need to be sorted (low to high) into position along the x-axis.

As I am relatively new to Fortran, despite spending a lot of time on this, I've been having problems getting off the ground. Therefore I would be grateful for any help or Fortran (77 or 90) code which will aid my progress with this.

I thought I'd supply a small sample of the data which I'm reading from (shown below) to demonstrate my problem - each 'record' (3 of which are shown, there are 6059 in total) consists of 10 lines, and just to clarify, the 1st value represents longitude (e.g. -65.25), the 2nd represents latitude (e.g. 81.75), the 3rd can be ignored in each case (e.g. 57.8882) and the 4th to 105th are runoff data for the years 1901 to 2002.

-65.25 81.75 57.8882 49.0414 66.9669 56.2636 57.8166 56.6547 61.7237 63.9533 62.6721 60.6238 60.5001 62.7171 64.6209 59.1937 51.2324 47.3801 44.9323 49.2497 50.0256 45.1342 47.3299 48.1505 44.9142 54.6785 60.1335 56.0597 59.0041 63.1964 68.4900 70.9806 67.8543 61.3597 67.0642 73.8294 63.9610 66.2057 60.6913 69.0662 65.5306 58.2328 55.8040 60.6331 58.3898 56.1888 59.8327 56.5972 52.6948 74.5054 88.8634 102.6831 118.0484 59.6974 54.8864 67.8360 107.2248 74.7033 82.0317 110.6799 87.2599 47.5654 76.7102 54.4816 140.3949 71.4815 73.6531 28.3481 57.2041 76.5902 61.0163 70.0856 43.4862 69.1062 33.0437 50.2283 51.1863 60.6140 40.9061 32.3430 55.4914 37.6491 59.3901 73.9880 59.5245 49.9360 54.3105 57.9623 58.7895 71.1009 66.2700 82.7888 78.3369 90.9131 42.3796 64.1215 100.2878 73.5610 39.5639 23.1466 72.5435 41.6263 64.6415 47.6596 66.5681
-86.25 80.25 17.2965 21.5048 18.7418 17.0611 18.4126 16.5473 16.9740 16.8623 20.2615 20.5288 13.0742 14.6428 18.1277 14.5538 17.8026 19.9247 16.9549 14.2944 14.5556 19.1191 16.7057 13.0094 18.2312 14.7086 14.3001 14.6565 17.9163 19.1163 17.6693 16.4373 18.2093 17.1911 15.1055 16.2847 11.4140 14.9737 14.8923 14.4179 14.1996 15.0845 15.8986 13.3851 16.0098 14.7312 15.3838 15.3049 17.6530 15.4742 9.9054 11.7351 9.1438 9.0147 8.1704 11.3781 15.3670 15.1826 12.7882 8.0089 12.6379 13.4308 10.5928 12.9832 12.0263 11.2028 12.6975 14.8776 13.9480 14.7531 12.8082 12.3341 12.4005 12.7703 14.0361 11.4874 17.2104 14.7869 22.2001 15.3452 20.3430 14.5316 24.1037 22.9716 18.5323 26.0306 23.2168 22.3955 27.9532 23.2315 19.4654 20.9908 23.2717 21.6780 22.0188 19.2084 17.5336 19.8756 19.5406 23.1534 17.5993 17.8828 11.9022 23.9628 22.1741
-84.75 80.25 16.7922 20.1870 20.6662 20.0835 17.6162 18.6830 17.8858 19.8512 18.3699 17.5513 17.3052 19.1035 16.1722 18.0249 20.3505 19.6674 18.1459 21.8207 14.5478 16.3392 17.2769 15.1087 16.2236 13.0636 15.6991 16.7820 15.6829 13.8899 18.2764 18.9172 18.5351 13.9816 14.6210 18.3520 18.6203 21.4323 21.8447 19.6628 16.6373 16.7750 19.0610 14.8760 16.5920 18.9737 18.7555 18.6390 20.6319 12.2532 11.8548 11.5019 12.2412 8.2987 9.3483 13.3286 10.6486 11.8073 11.2122 7.2539 13.2242 11.6904 9.9460 12.8383 10.7944 13.8906 19.1893 16.7340 14.5501 14.0434 13.9703 12.6540 13.9066 13.7670 12.2899 15.0379 12.9359 15.4025 18.0655 19.7602 19.3291 19.0580 24.3158 21.7039 23.7862 25.8743 24.7603 31.4732 28.3987 22.9358 17.8807 27.7425 21.2574 15.7054 22.7776 17.4660 17.9133 18.5386 23.7744 20.5265 21.1981 20.8320 17.8207 21.4408 20.2576


So I'm trying to create a new file consisting of a table output of the above data (ie. reformatted), where all latitude values are listed in the far left-hand column and all longitude values are listed along the top row, with runoff data for a particular year in each table (so 102 tables will be created, one for each year).

The second part is to then perform a linear interpolation of the data for each year's table. This involves creating a new file with new tables for each runoff year as before, but this time creating 18 values via application of a linear interpolation between each adjacent pair of existing runoff values (so for example in the first row, 18 values will be first be created between 49.0414 and 66.9669, whereby they increase via an equal increment.

Thanks again for your advice, if you would be able to tailor any code with respect to these details and the input data shown above, then I'd be very grateful.

Many thanks
smurray444