How Do You Read and Manipulate Complex Number Data in Fortran?

In summary, the conversation is about reading a fortran data file containing complex and real numbers. The file has 256 lines and the first 64 lines need to be read separately from the next 64 lines. The data from the first column will be saved as a variable called k2, while the data from the second and third columns will be saved as a variable called E0. The same process will be repeated for the next 64 lines, with the second and third columns being saved as a variable called E1. This process will be repeated for the remaining lines in the file.
  • #1
Raziel13
3
0
Hello, I need to read a fortran data with complex numbers and real numbers,
the first column is the real numbers, the second and third complex numbers (real, imaginary).

I need to read the first 64 lines and then the next 64 lines in separate ways and save in a variable. for example

read from 1 to 64 the first column that I will call k2 which is a real number and the second and third column that I will call E0 which is a complex number (part real and imaginary),

then read from 65 to 128 again the first column in which I can call time again k2 because the values are the same, but the second and third column will be my E1 because the values are no longer repeated.
93
then do the same for 129 to 193 and the same for 194 to 256.

Can someone help me ?
thanks
Code:
   0.3475999158309906D-03   0.1000000000000000D+01  -0.0000000000000000D+00
   0.1833296439467811D-02   0.9999949615756608D+00   0.1829832969435655D-14
   0.4513595263596993D-02   0.9999685090269346D+00   0.8610978679697199D-15
   0.8401876425510740D-02   0.9998904236081211D+00   0.8610978679697199D-15
   0.1351685480299403D-01   0.9997161185401198D+00   0.4305489339848600D-15
   0.1988323578908195D-01   0.9993856054848251D+00  -0.1076372334962150D-15
   0.2753201395850637D-01   0.9988221275112609D+00   0.5381861674810750D-15
   0.3650080488705306D-01   0.9979304502530658D+00   0.4305489339848600D-15
   0.4683424556300787D-01   0.9965948061656795D+00   0.1076372334962150D-14
   0.5858447526034363D-01   0.9946764945490979D+00   0.1184009568458365D-14
   0.7181170689468865D-01   0.9920111543230785D+00   0.3659665938871310D-14
   0.8658490010557232D-01   0.9884057503391426D+00   0.4520763806841030D-14
   0.1029825493929753D+00   0.9836353513267678D+00   0.6565871243269115D-14
   0.1210936032577395D+00   0.9774398339009408D+00   0.8288066979208554D-14
   0.1410185334589130D+00   0.9695207297376155D+00   0.1130190951710258D-13
   0.1628705773018296D+00   0.9595385515367878D+00   0.1350847280377498D-13
   0.1867771804509159D+00   0.9471110994656604D+00   0.1684522704215765D-13
   0.2128816733065060D+00   0.9318134768763994D+00   0.2066634883127328D-13
   0.2413452207319886D+00   0.9131808456567779D+00   0.2437983338689270D-13
   0.2723490931675873D+00   0.8907153367325286D+00   0.2830859240950455D-13
   0.3060973173045934D+00   0.8638989960823151D+00   0.3137625356414667D-13
   0.3428197770124591D+00   0.8322151579545033D+00   0.3299081206658989D-13
   0.3827758507475470D+00   0.7951811047074102D+00   0.3369045408431530D-13
   0.4262586910527104D+00   0.7523951072774169D+00   0.3035369984593263D-13
   0.4736002760595692D+00   0.7036005955085440D+00   0.2357255413567108D-13
   0.5251773935465452D+00   0.6487687219107892D+00   0.1087136058311772D-13
   0.5814187569572651D+00   0.5881971611468716D+00  -0.7426969111238834D-14
   0.6428135023366771D+00   0.5226167217783453D+00  -0.3153770941439099D-13
   0.7099213787340648D+00   0.4532876377370986D+00  -0.6172995341007930D-13
   0.7833850267593251D+00   0.3820549050592221D+00  -0.9439785377618055D-13
   0.8639448467923458D+00   0.3113201577456072D+00  -0.1265006586664267D-12
   0.9524570982449548D+00   0.2438841128848114D+00  -0.1546747045340610D-12
   0.1049916055896533D+01   0.1826305284653794D+00  -0.1718697525850813D-12
   0.1157481294914600D+01   0.1300708966838944D+00  -0.1748028671978531D-12
   0.1276511505634412D+01   0.8784606175054865D-01  -0.1617047613467825D-12
   0.1408606685127873D+01   0.5635473357345396D-01  -0.1363360108771433D-12
   0.1555661162008767D+01   0.3468869480994791D-01  -0.1043240249026596D-12
   0.1719930752205679D+01   0.2095036471103247D-01  -0.7363732236559808D-13
   0.1904118517453612D+01   0.1283919806400845D-01  -0.4880003073634647D-13
   0.2111485255710072D+01   0.8246343265954895D-02  -0.3031165405159817D-13
   0.2345993221933724D+01   0.5616414055055371D-02  -0.1962277221589201D-13
   0.2612495009930844D+01   0.4004079448995915D-02  -0.1401218141990180D-13
   0.2916984570477848D+01   0.2924767359531206D-02  -0.9237671244252310D-14
   0.3266934871581749D+01   0.2155876043675108D-02  -0.6236021986715284D-14
   0.3671758140882298D+01   0.1592209468999256D-02  -0.5399310679459550D-14
   0.4143442314569344D+01   0.1174791948100784D-02  -0.3846244151230472D-14
   0.4697445226110210D+01   0.8645900884451562D-03  -0.2418106189417654D-14
   0.5353973100920618D+01   0.6333910886683653D-03  -0.1268942073013972D-14
   0.6139844387895875D+01   0.4603362803121361D-03  -0.1171290715672191D-14
   0.7091266484425319D+01   0.3306447016578899D-03  -0.5865388309657028D-15
   0.8258074523321996D+01   0.2341796781250851D-03  -0.1013829215889642D-14
   0.9710383029886540D+01   0.1632957168524006D-03   0.4687974675184881D-15
   0.1154935789936476D+02   0.1117266529545774D-03   0.1878067379123717D-15
   0.1392530609899710D+02   0.7451295627757056D-04  -0.2119830696546856D-15
   0.1706936855807103D+02   0.4811281408853923D-04  -0.3162566396041439D-15
   0.2135189727044204D+02   0.2982137989322365D-04   0.2274611776940583D-15
   0.2739665613112830D+02   0.1755172699612436D-04  -0.4665079426238695D-15
   0.3632135308034874D+02   0.9663125194392776D-05  -0.7393432663015580D-15
   0.5029362477052696D+02   0.4864767650024737D-05   0.9990635048538857D-15
   0.7398170762169443D+02   0.2161879609180998D-05   0.1299916766248431D-14
   0.1190210316547486D+03   0.7982433375114770D-06   0.4217067937690845D-15
   0.2215528733967777D+03   0.2169925441877510D-06   0.3852726656010782D-15
   0.5454655223627067D+03   0.3157102436351680D-07   0.3253355408323738D-15
   0.2876870662092502D+04   0.3494143826275012D-09   0.4140718487780305D-15
   0.3475999158309906D-03  -0.8733997719885090D-15  -0.1455056665833896D-08
   0.1833296439467811D-02   0.2416115304760093D-16  -0.7674057388064735D-08
   0.4513595263596993D-02   0.6313988500916080D-15  -0.1889182202030143D-07
   0.8401876425510740D-02   0.2652459378271201D-15  -0.3515653925677366D-07
   0.1351685480299403D-01   0.5974413568903742D-15  -0.5652419730346947D-07
   0.1988323578908195D-01  -0.3659643586645440D-15  -0.8304847156857286D-07
   0.2753201395850637D-01   0.4654433055924298D-15  -0.1147639369810866D-06
   0.3650080488705306D-01  -0.4810980821862747D-15  -0.1516632990964897D-06
   0.4683424556300787D-01   0.7793848409895145D-15  -0.1936677117106545D-06
   0.5858447526034363D-01   0.1815349753580583D-15  -0.2405890593921787D-06
   0.7181170689468865D-01  -0.1375700461128853D-15  -0.2920832320133602D-06
   0.8658490010557232D-01   0.1595081373327718D-14  -0.3475938060222055D-06
   0.1029825493929753D+00   0.5296778222158051D-15  -0.4062864285807373D-06
   0.1210936032577395D+00   0.7863744025492185D-15  -0.4669757665713327D-06
   0.1410185334589130D+00   0.1390888323847228D-14  -0.5280494923715648D-06
   0.1628705773018296D+00   0.8988982791518660D-15  -0.5873977311507574D-06
   0.1867771804509159D+00   0.3379035513801605D-15  -0.6423620783025709D-06
   0.2128816733065060D+00   0.1628514914058735D-14  -0.6897260164978229D-06
   0.2413452207319886D+00   0.2129162532714469D-14  -0.7257778952315798D-06
   0.2723490931675873D+00   0.1912735245181821D-14  -0.7464876736207860D-06
   0.3060973173045934D+00   0.1970019714412867D-14  -0.7478461711433848D-06
   0.3428197770124591D+00   0.1440059935933419D-14  -0.7264150608421358D-06
   0.3827758507475470D+00   0.2694062150719036D-14  -0.6801172368370289D-06
   0.4262586910527104D+00   0.1983053808005684D-14  -0.6092463604097870D-06
   0.4736002760595692D+00   0.2287396274954972D-14  -0.5175747587457052D-06
   0.5251773935465452D+00   0.1723009398021452D-14  -0.4132801411110632D-06
   0.5814187569572651D+00   0.1830203949662034D-14  -0.3092083034950250D-06
   0.6428135023366771D+00   0.2242053437485190D-14  -0.2218128026173135D-06
   0.7099213787340648D+00   0.1665706964889018D-14  -0.1681275892419838D-06
   0.7833850267593251D+00   0.1588318131262786D-14  -0.1605937019942488D-06
   0.8639448467923458D+00   0.1609886964224556D-14  -0.2007131787033556D-06
   0.9524570982449548D+00   0.2385090463370206D-14  -0.2742290087894907D-06
   0.1049916055896533D+01   0.1251399861379684D-14  -0.3518728354072258D-06
   0.1157481294914600D+01   0.3092226943766533D-15  -0.3987447853792095D-06
   0.1276511505634412D+01  -0.3657043568546687D-15  -0.3904456501467158D-06
   0.1408606685127873D+01   0.5260705681662269D-15  -0.3269097207443796D-06
   0.1555661162008767D+01   0.4356172177970416D-15  -0.2325158794195402D-06
   0.1719930752205679D+01   0.1127584428112931D-14  -0.1401791169097913D-06
   0.1904118517453612D+01   0.3333114970094542D-15  -0.7200028112835087D-07
   0.2111485255710072D+01   0.3875241775972240D-16  -0.3205642042665038D-07
   0.2345993221933724D+01   0.3131162184320873D-15  -0.1289824011960974D-07
   0.2612495009930844D+01  -0.7765031918218519D-15  -0.5130539217639537D-08
   0.2916984570477848D+01   0.2022355383834758D-15  -0.2307679181447039D-08
   0.3266934871581749D+01  -0.5420592942883447D-15  -0.1267576387470081D-08
   0.3671758140882298D+01  -0.5826579323652031D-15  -0.8061997052306844D-09
   0.4143442314569344D+01   0.3342887842195372D-15  -0.5427584922350266D-09
   0.4697445226110210D+01   0.2348953258393024D-15  -0.3666879024144684D-09
   0.5353973100920618D+01  -0.5469195170770313D-15  -0.2431829525939626D-09
   0.6139844387895875D+01   0.5377557829284162D-16  -0.1569965510493959D-09
   0.7091266484425319D+01  -0.2910341105947241D-15  -0.9802805615852434D-10
   0.8258074523321996D+01  -0.9860788121527835D-16  -0.5841877824494821D-10
   0.9710383029886540D+01  -0.3003046174034079D-15  -0.3219681333822845D-10
   0.1154935789936476D+02  -0.2483339064857475D-16  -0.1897158684902246D-11
   0.1392530609899710D+02   0.4901567447468588D-15  -0.1172031033380893D-10
   0.1706936855807103D+02  -0.2398416562072209D-15  -0.4818932621194005D-11
   0.2135189727044204D+02  -0.1775856923938541D-15  -0.2138845788398870D-11
   0.2739665613112830D+02  -0.2686764687542991D-15  -0.9889042059520092D-12
   0.3632135308034874D+02  -0.1206920071946245D-15  -0.4194568948885728D-12
   0.5029362477052696D+02  -0.2447518635624472D-15  -0.1541611363581582D-12
   0.7398170762169443D+02   0.3010623066066283D-15  -0.4623266143420919D-13
   0.1190210316547486D+03  -0.3369955857880252D-15  -0.1076229507803411D-13
   0.2215528733967777D+03   0.7619316117631777D-15  -0.2021459215536639D-14
   0.5454655223627067D+03  -0.5864664272748860D-15   0.6148311046782166D-16
   0.2876870662092502D+04  -0.4056929326897661D-15   0.3342501892659557D-16
   0.3475999158309906D-03   0.1848656039410625D-03   0.2028840969744941D-15
   0.1833296439467811D-02   0.1848562032489020D-03   0.1956443367625295D-15
   0.4513595263596993D-02   0.1848068478938808D-03   0.8616628583310893D-15
   0.8401876425510740D-02   0.1846611537137981D-03   0.2429589946995253D-15
   0.1351685480299403D-01   0.1843359200091747D-03  -0.1387905392359032D-15
   0.1988323578908195D-01   0.1837191821660309D-03   0.8022994524551250D-15
   0.2753201395850637D-01   0.1826676188326764D-03   0.3041356254561632D-15
   0.3650080488705306D-01   0.1810032828268234D-03   0.6824557992911874D-15
   0.4683424556300787D-01   0.1785096270908737D-03   0.1183457717407725D-14
   0.5858447526034363D-01   0.1749268103198742D-03   0.2254140730823994D-14
   0.7181170689468865D-01   0.1699462996607832D-03   0.3438754707575916D-14
   0.8658490010557232D-01   0.1632048544058181D-03   0.5300266555180440D-14
   0.1029825493929753D+00   0.1542780972306471D-03   0.7308413110526391D-14
   0.1210936032577395D+00   0.1426740947165766D-03   0.9834642687937251D-14
   0.1410185334589130D+00   0.1278277305276408D-03   0.1385933181818531D-13
   0.1628705773018296D+00   0.1090972425316932D-03   0.1790127943307660D-13
   0.1867771804509159D+00   0.8576521725961464D-04   0.2319975247234246D-13
   0.2128816733065060D+00   0.5704772630100787D-04   0.2932827847315187D-13
   0.2413452207319886D+00   0.2211728831791783D-04   0.3754280801503499D-13
   0.2723490931675873D+00  -0.1985197093365777D-04   0.4675922313935462D-13
   0.3060973173045934D+00  -0.6960532203289708D-04   0.5794068787982738D-13
   0.3428197770124591D+00  -0.1276796825900629D-03   0.7037730170187581D-13
   0.3827758507475470D+00  -0.1942103614243251D-03   0.8322096480066935D-13
   0.4262586910527104D+00  -0.2686580848945300D-03   0.9945717165120308D-13
   0.4736002760595692D+00  -0.3494540529878669D-03   0.1165993733944693D-12
   0.5251773935465452D+00  -0.4335893355066667D-03   0.1328448434590674D-12
   0.5814187569572651D+00  -0.5162276627590251D-03   0.1482343925441231D-12
   0.6428135023366771D+00  -0.5904998653809707D-03   0.1633163240863794D-12
   0.7099213787340648D+00  -0.6477289755677672D-03   0.1753175602777499D-12
   0.7833850267593251D+00  -0.6783879846336999D-03   0.1803122327439831D-12
   0.8639448467923458D+00  -0.6740118634383764D-03   0.1805934665508378D-12
   0.9524570982449548D+00  -0.6299527648066868D-03   0.1712384349831494D-12
   0.1049916055896533D+01  -0.5482406528706048D-03   0.1540266737288811D-12
   0.1157481294914600D+01  -0.4391112160383313D-03   0.1293711250456402D-12
   0.1276511505634412D+01  -0.3195992939993111D-03   0.1002451361156523D-12
   0.1408606685127873D+01  -0.2086956646787709D-03   0.7079785162039551D-13
   0.1555661162008767D+01  -0.1208668528681256D-03   0.4577660964093063D-13
   0.1719930752205679D+01  -0.6157351244253159D-04   0.2619904322360354D-13
   0.1904118517453612D+01  -0.2752100904109864D-04   0.1336022688805535D-13
   0.2111485255710072D+01  -0.1084855352911824D-04   0.8074977743831828D-14
   0.2345993221933724D+01  -0.3758654643861246D-05   0.2632538098109554D-14
   0.2612495009930844D+01  -0.8701264203233716D-06   0.1384795276449009D-14
   0.2916984570477848D+01   0.7830013643097617D-06   0.7572418817393842D-15
   0.3266934871581749D+01   0.2637989678420009D-05   0.5378260682463941D-15
   0.3671758140882298D+01   0.5135337628825519D-05  -0.8818160973694087D-16
   0.4143442314569344D+01   0.7883682020575292D-05   0.3273010514792248D-15
   0.4697445226110210D+01   0.1013876606363818D-04   0.5272977849209071D-15
   0.5353973100920618D+01   0.1139565774038222D-04  -0.6779810427808658D-15
   0.6139844387895875D+01   0.1136919396889468D-04  -0.9653369472285132D-16
   0.7091266484425319D+01   0.9837991686548136D-05  -0.1410537855090627D-15
   0.8258074523321996D+01   0.7130470326935327D-05  -0.9197353269278784D-16
   0.9710383029886540D+01   0.4285450977624413D-05  -0.8261756330679615D-15
   0.1154935789936476D+02   0.2246177877841349D-05  -0.1258099267437897D-15
   0.1392530609899710D+02   0.1031545452112179D-05   0.1769071664079108D-15
   0.1706936855807103D+02   0.4378818457430551D-06  -0.1343729002331806D-14
   0.2135189727044204D+02   0.1700480665169558D-06  -0.2906121695268202D-15
   0.2739665613112830D+02   0.6219438509173145D-07   0.3363119497171824D-16
   0.3632135308034874D+02   0.2605711365528449D-07   0.5381881050161532D-15
   0.5029362477052696D+02   0.9682208178426647D-08  -0.4781738140635490D-15
   0.7398170762169443D+02   0.2788834406768809D-08  -0.1045431857546606D-14
   0.1190210316547486D+03   0.1027600894319595D-08   0.4626019379675053D-15
   0.2215528733967777D+03   0.3075858809608018D-09   0.4030756312836121D-16
   0.5454655223627067D+03   0.5439778738986877D-10   0.1889392503974009D-15
   0.2876870662092502D+04   0.9608248579180385D-12  -0.7279525934514845D-15
   0.3475999158309906D-03   0.3711665442749685D-04  -0.6841116809258749D-14
   0.1833296439467811D-02   0.2657461358558079D-01  -0.5312134611318257D-11
   0.4513595263596993D-02   0.2919882139978147D+00  -0.5742989975052226D-10
   0.8401876425510740D-02   0.4604174422851450D+00  -0.9182274060201710D-10
   0.1351685480299403D-01   0.5130959599539389D+00  -0.1021401999815633D-09
   0.1988323578908195D-01   0.5245352482643203D+00  -0.1039035131406983D-09
   0.2753201395850637D-01   0.5266736940021662D+00  -0.1043129651769179D-09
   0.3650080488705306D-01   0.5266923025744201D+00  -0.1049570125635425D-09
   0.4683424556300787D-01   0.5259373636630101D+00  -0.1046986293845348D-09
   0.5858447526034363D-01   0.5246365566402391D+00  -0.1051149702036982D-09
   0.7181170689468865D-01   0.5227607562534307D+00  -0.1057278027926089D-09
   0.8658490010557232D-01   0.5202001078776072D+00  -0.1065177524492376D-09
   0.1029825493929753D+00   0.5168050174542463D+00  -0.1069862973266466D-09
   0.1210936032577395D+00   0.5123961761748981D+00  -0.1091742931905410D-09
   0.1410185334589130D+00   0.5067667073985429D+00  -0.1096434300727342D-09
   0.1628705773018296D+00   0.4996825609151804D+00  -0.1111616532511983D-09
   0.1867771804509159D+00   0.4908833146653196D+00  -0.1135675068756890D-09
   0.2128816733065060D+00   0.4800846467916449D+00  -0.1151234838138019D-09
   0.2413452207319886D+00   0.4669837008363743D+00  -0.1196067629540778D-09
   0.2723490931675873D+00   0.4512688225276932D+00  -0.1224104437935705D-09
   0.3060973173045934D+00   0.4326355095482476D+00  -0.1272717179885768D-09
   0.3428197770124591D+00   0.4108107437213624D+00  -0.1318178841825229D-09
   0.3827758507475470D+00   0.3855879452074180D+00  -0.1375479253983856D-09
   0.4262586910527104D+00   0.3568742131955406D+00  -0.1443716416344949D-09
   0.4736002760595692D+00   0.3247497005494051D+00  -0.1531417888732246D-09
   0.5251773935465452D+00   0.2895351810455067D+00  -0.1614128491695407D-09
   0.5814187569572651D+00   0.2518575961321720D+00  -0.1688927488903513D-09
   0.6428135023366771D+00   0.2126950854520832D+00  -0.1765449892766436D-09
   0.7099213787340648D+00   0.1733752076935676D+00  -0.1844437862009131D-09
   0.7833850267593251D+00   0.1354978447851120D+00  -0.1939325330651177D-09
   0.8639448467923458D+00   0.1007642207693468D+00  -0.1984606363858178D-09
   0.9524570982449548D+00   0.7071997015524834D-01  -0.2016128196780628D-09
   0.1049916055896533D+01   0.4646041215981891D-01  -0.2026235904828726D-09
   0.1157481294914600D+01   0.2838615694883695D-01  -0.1992640524694559D-09
   0.1276511505634412D+01   0.1611230685311180D-01  -0.1970765544277665D-09
   0.1408606685127873D+01   0.8598484894333474D-02  -0.1911255819037417D-09
   0.1555661162008767D+01   0.4473672244359425D-02  -0.1866136409863838D-09
   0.1719930752205679D+01   0.2421494775253672D-02  -0.1815605730084602D-09
   0.1904118517453612D+01   0.1452906340458963D-02  -0.1758845226919879D-09
   0.2111485255710072D+01   0.9748601873694136D-03  -0.1709177520251039D-09
   0.2345993221933724D+01   0.7007806571062660D-03  -0.1651563153197262D-09
   0.2612495009930844D+01   0.5167979811052178D-03  -0.1630088822424430D-09
   0.2916984570477848D+01   0.3828065733824403D-03  -0.1557593854333271D-09
   0.3266934871581749D+01   0.2830854629256306D-03  -0.1549588621528963D-09
   0.3671758140882298D+01   0.2087729455436860D-03  -0.1512318383784860D-09
   0.4143442314569344D+01   0.1534769531120022D-03  -0.1486769193920228D-09
   0.4697445226110210D+01   0.1123562040326752D-03  -0.1472571032257998D-09
   0.5353973100920618D+01   0.8175221985657395D-04  -0.1451370215552787D-09
   0.6139844387895875D+01   0.5894429819511890D-04  -0.1436889794330563D-09
   0.7091266484425319D+01   0.4196875125118042D-04  -0.1426188147621635D-09
   0.8258074523321996D+01   0.2942150885807123D-04  -0.1417458532709309D-09
   0.9710383029886540D+01   0.2025054334971717D-04  -0.1417073402463571D-09
   0.1154935789936476D+02   0.1363300080959531D-04  -0.1407792926769395D-09
   0.1392530609899710D+02   0.8927910808379660D-05  -0.1410592706999196D-09
   0.1706936855807103D+02   0.5650897506135906D-05  -0.1414467350637302D-09
   0.2135189727044204D+02   0.3428296379756167D-05  -0.1397833656893875D-09
   0.2739665613112830D+02   0.1971677079401429D-05  -0.1402732323249772D-09
   0.3632135308034874D+02   0.1058455302418004D-05  -0.1402163795036603D-09
   0.5029362477052696D+02   0.5183089093494448D-06  -0.1389509663166628D-09
   0.7398170762169443D+02   0.2232992863388601D-06  -0.1386070954279062D-09
   0.1190210316547486D+03   0.7952919191617421D-07  -0.1383200189277319D-09
   0.2215528733967777D+03   0.2067350176573896D-07  -0.1388069459183895D-09
   0.5454655223627067D+03   0.2787861460038876D-08  -0.1390822755609575D-09
   0.2876870662092502D+04  -0.4627967448074155D-11  -0.6726700201895319D-10
 
Technology news on Phys.org
  • #2
This looks like a homework problem.

Whether it is or it isn't, we can't help you until you make an attempt at a solution.

Also it would help if you tell us what fortran you're using and what this program is for.
 
  • #3
is not a homework problem ,
i using fortran 90 , the program is to fit the first four moments of Chebyschev from BSA of pion.
 
  • #4
Great so what have you written so far?

We have [ code ] tags to bracket your sample code:

Fortran:
[ code=fortran ]
  DO I=1,20
    PRINT(...)
  END
[ /code ]

When posting don't forget to remove the spaces around "code=fortran" and "/code"
 
  • #5
i try, but the variables are not being allocated , so when I do the last DO to write, it just repeats the first read value
Fortran:
PROGRAM chesb_tay

      IMPLICIT None
 
      call chebtay
 
      STOP
      END

 
 
      subroutine chebtay 
      complex*8 EH0,EH1,EH2,EH3
      double precision k2, EH0R ,EH1R, EH2R,EH3R
      double precision  EH0IM,EH1IM,EH2IM,EH3IM,
      integer  i0,i1,i2,i3,j
      open (1,file='data.out',status='old')
      open (12,file='chesb.out',status='unknown')
 
 
      do i0 =1,64
      read(1,*) k2,EH0R,EH0IM
      EH0=CMPLX(EH0R,EH0IM)
      end do
      do i1= 65, 129
      read(1,*) k2,EH1R,EH1IM
      EH1=CMPLX(EH1R,EH1IM)
      end do

      do j =1,64
      write (12,*) k2,EH0,EH1
      end do
      close(unit=12)
      close(unit=1)
      return
      end
 
  • #7
I could understand it printing the LAST value in the input file, but not the first. It looks like EH0 and EH1 will have only the final value in their respective loops when they get to the last write loop. You should make them arrays and increment their index. If you have a debugger, step through to see what is happening, otherwise, just put some writes to the terminal (or a text file) inside the loops to see what is happening at each step of each loop. It should soon become obvious.
 
  • #8
As @jedishrfu and @FactChecker suggested, you'll need to use arrays -- you're not referencing your counter variables (i0, i1, j) to subscript the variables that are being assigned the input values inside the loops, so you'll just re-use the same non-arrayed variables each time through the loops.

Also (just a sideline observation), your input file has 256 lines, but your code reads only the first half of them.

I shudder to consider how you got to the point of implementing moment methods for pion amplitude distribution analysis without even a rudimentary knowledge of programming -- whether in fortran or another computer language -- but I did encounter something like that a long time ago --

I had a buddy who'd done well as an undergrad in his homeland in Civil Engineering, and was still trying to do all his Fourier transforms and such by hand in graduate school in the US in the early '80s. He was failing. He said "too many variables".

When I learned that he was trying to do it all by hand, I asked him how fast can you count to ten million, and he shook his head and smiled.

I showed him how to use TSO (time sharing option) on the university's IBM mainframe, gave him a copy of a textbook entitled "Ten Statement Fortran", and he did the rest -- he aced all his classes, and wound up writing a faster 'fast Fourier transform' subroutine that got accepted into the university's fortlib as an alternate.

Best wishes to you, @Raziel13.
 
Last edited:
  • Like
Likes Raziel13
  • #9
try something like this, fill in the rest of your data. I think I have my FORTRAN syntax correct, it has been a while

Code:
ic = complex(0,1)
do ii = 1,256
read(1,*) K(ii),RealPart(ii),ImagPart(ii)
enddo

k2 = K(1:64)
E0 = RealPart(1:64) + ic*ImagPart(1:64)

...
 
  • Like
Likes Raziel13

1. What is a complex number in Fortran?

In Fortran, a complex number is a data type that includes both a real and an imaginary part. It is denoted by the format (real, imag), where "real" represents the real part of the number and "imag" represents the imaginary part. Complex numbers are often used in scientific and mathematical computations.

2. How do I read complex numbers in Fortran?

To read a complex number in Fortran, you can use the READ statement followed by the format (real, imag). For example, if you want to read a complex number with a real part of 3.5 and an imaginary part of -2.1, you would use the statement READ (3.5,-2.1). You can also use the COMPLEX function to read complex numbers in Fortran.

3. Can I read multiple complex numbers in one line in Fortran?

Yes, you can read multiple complex numbers in one line in Fortran by using the format (real1, imag1, real2, imag2, ...). For example, if you want to read two complex numbers with the real parts 3.5 and 2.0 and the imaginary parts -2.1 and 4.0, you would use the statement READ (3.5,-2.1,2.0,4.0).

4. How do I handle errors when reading complex numbers in Fortran?

If there is an error while reading a complex number in Fortran, the program will stop and display an error message. To handle errors, you can use the IOSTAT or ERR options in the READ statement. The IOSTAT option will return a value indicating the status of the read operation, while the ERR option will allow you to specify a specific error handling subroutine.

5. Are there any specific rules for reading complex numbers in Fortran?

Yes, there are a few rules to keep in mind when reading complex numbers in Fortran. The real and imaginary parts must be separated by a comma, and the imaginary part must be followed by the letter "i" to indicate it is an imaginary number. Additionally, you must use a decimal point for real numbers, even if they are whole numbers. For example, use 3.0 instead of 3 when reading a real number.

Similar threads

Replies
58
Views
3K
  • Programming and Computer Science
Replies
2
Views
2K
Replies
2
Views
999
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
4
Views
1K
Replies
2
Views
1K
  • Nuclear Engineering
Replies
7
Views
531
  • Programming and Computer Science
Replies
4
Views
2K
Replies
1
Views
911
  • Programming and Computer Science
Replies
11
Views
3K
Back
Top