Smart way to implement lookup in high-perf FORTRAN code -


i'm writing simulation in fortran 77, in need parameter value experimental data. data comes internet database, have downloaded in advance, there no simple mathematical model can used provide values on continous scale - have discrete data points. however, need know parameter value on x axis, , not discrete ones have database.

to simplify, know value of f(x) integer values of x, , need way find f(x) real x value (never outside smallest or largest x have knowledge of).

my idea take data , make linear interpolation, able fetch parameter value; in pseudo-code:

double xd = largest_data_x_lower_than(x)  double slope = (f(xd+dx)-f(xd))/dx // dx distance between 2 x values double xtra = x-xd  double fofx = f(xd)+slope*xtra 

to implement this, need kind of lookup data points. make lookup xd easy getting values database integer x, xd = int(x) , dx = 1, still have no idea how implement lookup f(xd).

what way implement this?

the value fetched 10^7 10^9 times during 1 simulation run, performance critical. in other words, reading io each time need value f(xd) not option.

i have data points in text file 1 pair of (tab-delimited) x,f(x) on each line, bonus points solution provides smooth way of getting data there whatever shape needs be.

you that have values integers. have pairs i, f(i) integers i m n? read values f(i) array y dimensioned m:n. unless number of values huge. real values between m , n easy index array , interpolate between nearest pair of values.

and why use fortran 77? fortran 90/95/2003 have been years now...

edit: answering question in comment, re how read data values once, in fortran 77, without having pass them argument in long chain of calls. technique 1: on program startup, read them array, in named common block. technique 2: first time function returns f(x) called, read values local variable on save statement. use logical saved designate whether or not function on first call or not. i'd prefer technique 2 being more "local", not thread safe. if doing simulation in parallel, first technique done in startup phase, before program goes multi-threaded.

here example of use of save: fortran save statement. (in fortran 95 notation ... convert fortran 77). put read of data array in if block.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

php - HTTP_REFERER woes: How can I allow access to a specific page, only when a visitor has visited another specific page beforehand? -

java Extracting Zip file -