Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fortran: matching real numbers

116 views
Skip to first unread message

jason_paul

unread,
Sep 16, 2012, 2:18:39 AM9/16/12
to
hi, i am an undergrad student workin on my thesis in CFD. i need some help in developing a fortran code similar to one posted for matching data for matching integer data

i have one data set (X Y Z A)

2165
1.1780350000E+00 7.6203720000E-01 4.9945483000E-17 -6.9057642105E-02
1.1779420000E+00 7.6200000000E-01 -9.8036904000E-17 -8.1336765080E-02
1.1752430000E+00 3.5839670000E-01 8.4368690000E-01 -3.1587640812E-03
1.1670980000E+00 1.0125310000E+00 -3.4181080000E+00 8.6667321533E-07
1.1670340000E+00 -5.6713856000E-07 -4.4855350000E+00 3.5846014888E-07
1.1347840000E+00 -1.3373509000E-07 -1.1808430000E+00 4.4077692011E-04
1.1252860000E+00 7.6206920000E-01 -2.6301555000E-03 3.6952285138E-02
1.1252860000E+00 7.6206920000E-01 2.6301555000E-03 -1.3059596352E-01
1.1252820000E+00 7.6199990000E-01 -2.5581506000E-03 5.5176577413E-02
1.1252820000E+00 7.6199990000E-01 2.5581506000E-03 -1.3508150156E-01
1.1190360000E+00 -7.6005030000E-08 -7.4041870000E-01 2.5431006058E-03
1.1089660000E+00 2.0118950000E-01 -5.5606530000E-01 4.1211631588E-03
1.1064270000E+00 7.0756350000E-01 -1.5259469000E-03 9.6403735550E-02
1.1064270000E+00 7.0756350000E-01 1.5259471000E-03 -2.9092222905E-01
1.1064220000E+00 7.0756750000E-01 -1.4261423000E-03 9.5525934358E-02
1.1064220000E+00 7.0756750000E-01 1.4261424000E-03 -2.9191011076E-01
1.0963010000E+00 1.6165530000E-01 1.6131010000E-01 -8.9272560545E-03
1.0895760000E+00 6.5307980000E-01 1.6202781000E-14 -9.7477390372E-02
1.0894980000E+00 6.5314290000E-01 -1.0527023000E-16 -9.7723308746E-02
1.0815650000E+00 4.8449994000E-08 2.1072730000E-01 -9.5352061116E-03
1.0781000000E+00 4.9454260000E-01 -1.0760930000E+00 4.8947142205E-04
1.0748350000E+00 2.1031710000E+00 6.7968030000E+00 1.0924777742E-07
1.0744790000E+00 2.1775540000E-01 -9.0639510000E-01 1.2563334410E-03
1.0726180000E+00 7.6206930000E-01 -5.0242790000E-03 4.6258418935E-02
1.0726180000E+00 7.6206930000E-01 5.0242790000E-03 -1.1036670147E-01
1.0726150000E+00 7.6199990000E-01 -4.9523544000E-03 6.5300968542E-02
1.0726150000E+00 7.6199990000E-01 4.9523544000E-03 -1.0971434601E-01
1.0706830000E+00 2.1516843000E-08 4.9104346000E-03 -2.9592512347E-03
1.0658390000E+00 -1.9310770000E-07 -1.6338360000E+00 6.3733054157E-05
1.0608670000E+00 1.5572000000E-01 3.4249239000E-03 -2.4685599762E-03
1.0584290000E+00 1.8967020000E-01 -3.1880510000E-01 7.5041292937E-03
1.0518170000E+00 7.0756400000E-01 -4.0936442000E-03 1.0384027882E-01
1.0518170000E+00 7.0756400000E-01 4.0936447000E-03 -2.8518142671E-01
1.0518130000E+00 7.0756770000E-01 -3.9938148000E-03 1.0379126357E-01
1.0518130000E+00 7.0756770000E-01 3.9938153000E-03 -2.8527739667E-01
1.0495400000E+00 -3.1884579000E-08 -4.0348420000E-01 7.1002416597E-03
1.0384100000E+00 1.8297200000E-01 3.5606930000E-01 -1.3303251777E-02
1.0375390000E+00 1.2278780000E-07 7.7848020000E-01 -5.9525080142E-03
1.0371120000E+00 1.4264570000E-01 -1.2264600000E-01 4.9177610074E-03
1.0335470000E+00 8.2057902000E-08 4.6733800000E-01 -1.2535930680E-02
1.0329520000E+00 6.5313900000E-01 -2.8469753000E-03 1.0104814761E-01
1.0329520000E+00 6.5313900000E-01 2.8469760000E-03 -2.8840691853E-01
1.0329470000E+00 6.5314280000E-01 -2.7471583000E-03 1.0124770050E-01
1.0329470000E+00 6.5314280000E-01 2.7471590000E-03 -2.8839534359E-01
1.0199250000E+00 7.6206970000E-01 -6.7684590000E-03 7.1073475951E-02
1.0199250000E+00 7.6206970000E-01 6.7684590000E-03 -8.8232357633E-02
1.0199230000E+00 7.6199990000E-01 -6.6968780000E-03 9.3631138540E-02
1.0199230000E+00 7.6199990000E-01 6.6968780000E-03 -8.7081824238E-02
1.0160380000E+00 5.9870640000E-01 -1.6204482000E-03 9.6846963613E-02
1.0160380000E+00 5.9870640000E-01 1.6204485000E-03 -2.9199192164E-01
1.0160330000E+00 5.9871030000E-01 -1.5206435000E-03 9.6055984688E-02
1.0160330000E+00 5.9871030000E-01 1.5206438000E-03 -2.9290565390E-01
1.0044030000E+00 2.0977560000E+01 4.1651960000E-01 1.5005669379E-07
1.0025190000E+00 -3.8098645000E-07 -3.0666860000E+00 1.2798508709E-06
1.0011330000E+00 5.4422270000E-01 1.3404162000E-14 -9.7818645118E-02
1.0010550000E+00 5.4428570000E-01 -1.1250452000E-16 -9.8058055636E-02


and anothr data set (X Y Z B)

160
1.177942E+00 7.620000E-01 -1.708514E-16 2.000000E+00
1.125282E+00 7.620000E-01 2.557083E-03 8.000000E+00
1.125282E+00 7.620000E-01 -2.557083E-03 9.000000E+00
1.107636E+00 7.620000E-01 -1.687248E-16 2.000000E+01
1.089498E+00 6.531429E-01 -1.467781E-16 3.400000E+01
1.072615E+00 7.620000E-01 4.950047E-03 7.000000E+00
1.072615E+00 7.620000E-01 -4.950047E-03 1.000000E+01
1.071915E+00 7.620000E-01 -1.682580E-16 1.900000E+01
1.032948E+00 6.531428E-01 2.747139E-03 7.600000E+01
1.032947E+00 6.531430E-01 -2.742592E-03 1.130000E+02
1.020442E+00 7.620000E-01 -1.736566E-16 1.800000E+01
1.019923E+00 7.620000E-01 6.699929E-03 6.000000E+00
1.019923E+00 7.620000E-01 -6.699929E-03 1.100000E+01
1.013998E+00 6.531429E-01 7.161392E-07 1.360000E+02
1.001055E+00 5.442857E-01 -1.227048E-16 3.300000E+01
9.763886E-01 6.531428E-01 5.318161E-03 7.500000E+01
9.763885E-01 6.531429E-01 -5.315158E-03 1.140000E+02
9.756371E-01 6.531429E-01 5.296648E-07 1.350000E+02
9.672564E-01 7.620000E-01 -1.695739E-16 1.700000E+01
9.672073E-01 7.620000E-01 7.369412E-03 5.000000E+00
9.672073E-01 7.620000E-01 -7.369412E-03 1.200000E+01
9.406130E-01 5.442857E-01 2.936028E-03 7.000000E+01
9.406127E-01 5.442859E-01 -2.931053E-03 1.070000E+02
9.203598E-01 6.531429E-01 2.609557E-07 1.340000E+02
9.203589E-01 5.442857E-01 7.955123E-07 1.300000E+02
9.198030E-01 6.531428E-01 -7.197417E-03 1.150000E+02
9.198028E-01 6.531429E-01 7.191658E-03 7.400000E+01
9.158538E-01 7.620000E-01 -1.784995E-16 1.600000E+01
9.144889E-01 7.620000E-01 6.873445E-03 4.000000E+00
9.144889E-01 7.620000E-01 -6.873445E-03 1.300000E+01
9.126117E-01 4.354286E-01 -9.863150E-17 3.200000E+01
8.801620E-01 5.442856E-01 5.684106E-03 6.900000E+01
8.801618E-01 5.442857E-01 -5.680841E-03 1.080000E+02
8.793588E-01 5.442857E-01 5.913960E-07 1.290000E+02
8.787071E-01 7.620000E-01 -1.512541E-16 1.500000E+01
8.632441E-01 6.531429E-01 -1.668994E-08 1.330000E+02
8.631914E-01 6.531429E-01 7.914689E-03 7.300000E+01
8.631914E-01 6.531429E-01 -7.912514E-03 1.160000E+02
8.617932E-01 7.620000E-01 5.250496E-03 3.000000E+00
8.617932E-01 7.620000E-01 -5.250496E-03 1.400000E+01
8.482783E-01 4.354285E-01 3.124923E-03 6.400000E+01
8.482780E-01 4.354287E-01 -3.119536E-03 1.010000E+02
8.267202E-01 4.354286E-01 8.710186E-07 1.240000E+02
8.241684E-01 3.265714E-01 -7.455818E-17 3.100000E+01
8.202778E-01 5.442857E-01 2.972650E-07 1.280000E+02
8.196826E-01 5.442857E-01 -7.692694E-03 1.090000E+02
8.196825E-01 5.442858E-01 7.686502E-03 6.800000E+01
8.096250E-01 7.620000E-01 -1.733822E-16 1.000000E+00
8.080430E-01 6.531429E-01 -2.850286E-07 1.320000E+02
8.065773E-01 6.531429E-01 7.382563E-03 7.200000E+01
8.065773E-01 6.531429E-01 -7.383807E-03 1.170000E+02
7.839354E-01 4.354285E-01 6.050042E-03 6.300000E+01
7.839352E-01 4.354286E-01 -6.046523E-03 1.020000E+02
7.830805E-01 4.354286E-01 6.498784E-07 1.230000E+02
7.681513E-01 6.531429E-01 -4.789465E-07 1.310000E+02
7.592319E-01 5.442857E-01 -6.648135E-09 1.270000E+02

here i am working with real numbers so cant use "==" for matching X Y Z in the two data sets... also the data in x Y Z are not exactly equal so have to set some tolerance... kindly help me in this matter
the required output is
A B
for matching X Y Z

regards

jason




Gib Bogle

unread,
Sep 16, 2012, 3:38:18 AM9/16/12
to
On 16/09/2012 6:18 p.m., jason_paul wrote:
> hi, i am an undergrad student workin on my thesis in CFD. i need some
> help in developing a fortran code similar to one posted for matching
> data for matching integer data

Undergraduates write theses these days?

...
> here i am working with real numbers so cant use "==" for matching X Y
> Z in the two data sets... also the data in x Y Z are not exactly
> equal so have to set some tolerance... kindly help me in this matter
> the required output is A B for matching X Y Z

To compare two real numbers X and Y, set a suitable small value epsilon,
then test

if (abs(X-Y) < epsilon) then
! match
else
! no match
endif


Arjen Markus

unread,
Sep 17, 2012, 4:01:05 AM9/17/12
to
Or use a relative criterium:

if ( abs(x-y) <= epsilon * (abs(x)+abs(y)) then

(use <= instead of < to capture the case where both x and y are zero)

Regards,

Arjen

robert....@oracle.com

unread,
Sep 17, 2012, 4:37:51 AM9/17/12
to
On Sunday, September 16, 2012 12:38:21 AM UTC-7, Gib Bogle wrote:
> On 16/09/2012 6:18 p.m., jason_paul wrote:
>
> > hi, i am an undergrad student workin on my thesis in CFD. i need some
>
> > help in developing a fortran code similar to one posted for matching
>
> > data for matching integer data
>
>
>
> Undergraduates write theses these days?

I recall some schools required students to complete a senior project, which would include a thesis. Some schools might still require them.

Bob Corbett

Gib Bogle

unread,
Sep 17, 2012, 6:21:06 AM9/17/12
to
On 17/09/2012 8:01 p.m., Arjen Markus wrote:
...
>
> Or use a relative criterium:
>
> if ( abs(x-y) <= epsilon * (abs(x)+abs(y)) then
>
> (use <= instead of < to capture the case where both x and y are zero)
>
> Regards,
>
> Arjen
>

Agreed.

glen herrmannsfeldt

unread,
Sep 17, 2012, 5:12:14 PM9/17/12
to
jason_paul <j2p...@gmail.com> wrote:

> hi, i am an undergrad student workin on my thesis in CFD.
> i need some help in developing a fortran code similar to one
> posted for matching data for matching integer data

> i have one data set (X Y Z A)

(snip)

> and anothr data set (X Y Z B)

(snip)

> here i am working with real numbers so cant use "==" for

Well, you can but you might get the wrong answer.

> matching X Y Z in the two data sets... also the data in x Y Z
> are not exactly equal so have to set some tolerance...
> kindly help me in this matter the required output is

Not so long ago, someone else asked about a similar problem,
though the data was in the form

A X Y Z

and

X Y Z B

It is a pretty easy change to make.

(And that person didn't say it was for an UG project.)

My first suggestion was to do it in AWK, but that normally does
a string match, not a numerical match. You can convert it to do
a numerical match, though.

Later, I made a Fortran suggestion that finds the closest match.
There is a Fortran function to find a matching element in an
array, but not a matching row or column in a 2D matrix.
Finding the closest match was one way to get around that problem,
and also gets around the exact match floating point problem.

You should be sure to understand how it works before using it.
For undergrad programs especially, you need to have them well
commented. You can't do that if you don't understand how it
works.

Look back last week, it should be there.

-- glen

John Harper

unread,
Sep 23, 2012, 9:46:13 PM9/23/12
to
Gib Bogle wrote:

> On 17/09/2012 8:01 p.m., Arjen Markus wrote:
> ...
>>
>> Or use a relative criterium:
>>
>> if ( abs(x-y) <= epsilon * (abs(x)+abs(y)) then
>>
>> (use <= instead of < to capture the case where both x and y are zero)

The OP had better consider what will happen if abs(x)+abs(y) > huge(x)
though both abs(x) and abs(y) < huge(x).

--
John Harper

David Thompson

unread,
Oct 11, 2012, 3:03:39 AM10/11/12
to
On Mon, 17 Sep 2012 21:12:14 +0000 (UTC), glen herrmannsfeldt
<g...@ugcs.caltech.edu> wrote:

> jason_paul <j2p...@gmail.com> wrote:
>
> > hi, i am an undergrad student workin on my thesis in CFD.
> > i need some help in developing a fortran code similar to one
> > posted for matching data for matching integer data
<snip>
> Not so long ago, someone else asked about a similar problem,
> though the data was in the form
>
> A X Y Z
>
> and
>
> X Y Z B
>
> It is a pretty easy change to make.
>
> (And that person didn't say it was for an UG project.)
>
> My first suggestion was to do it in AWK, but that normally does
> a string match, not a numerical match. You can convert it to do
> a numerical match, though.
>
Not necessarily. Original awk treated input as string unless you
converted it, but POSIX made this semi-automatic:
http://www.gnu.org/software/gawk/manual/html_node/Variable-Typing.html

And perhaps also relevant, awk like perl and BASIC stores numbers as
floating-point only, but special-cases values that are exact integers.

<snip other>

fj

unread,
Oct 11, 2012, 8:00:02 AM10/11/12
to john....@vuw.ac.nz
To solve that, the Arjen's test may be replaced by :

if ( abs(x-y) <= epsilon * MAX(abs(x),abs(y)) ) ...


>
>
>
> --
>
> John Harper

Robin Vowels

unread,
Oct 11, 2012, 10:08:21 AM10/11/12
to
Shouldn't that be:
if abs(x) - abs(y) <= ...

Arjen Markus

unread,
Oct 12, 2012, 5:31:15 AM10/12/12
to
That would mean x could also be (almost) equal to -y.

Regards,

Arjen
0 new messages