Hi Guys
This is a really quick example of reading a Airfoil.DAT file, convert to CSV and plot.
A Friend need a quick way to view the airfoil in the file.
I literally put this together in under an hour... expect a bug or 2, or a much easier/faster way of doing it... but it might help someone I hope
Include a few airfoil DAT files, but thousands can be downloaded here
http://airfoiltools.com/search/airfoils?m=a
// Project: Airfoil.DAT files plot
// Created: 20-03-26
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Airfoil.DAT files plot " )
SetWindowSize( 1280, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1280, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
Global scalex As Float = 900
Global scaley As Float = 900
Global StartX As Float = 200
Global StartY As Float = 350
Global coord As Float = 100
Global spr As Integer[200]
Global txt As Integer[200]
Global header As String
Global counter As Integer
Global dot As Integer
Global editstring As String
Global fid As String
Type airfoil
id As Integer
s As String
x As Float
y As Float
Calc_x As Float
Calc_y As Float
EndType
Global plot As airfoil[200]
AddVirtualButton(1,0,0,80)
SetVirtualButtonText(1,"Load Dat File")
SetVirtualButtonSize(1,150,50)
SetVirtualButtonPosition(1,85,GetDeviceHeight()-90)
Do
spritehit=GetSpriteHit(GetPointerX(),GetPointerY())
If spritehit > 0
s= spritehit - 100000
If spritehit
txt$ = "Point: "+Str(plot[s].id)+Chr(10)+"X: "+Str(plot[s].x)+Chr(10)+"Y: "+Str(plot[s].y)
If GetTextExists(s)
SetTextString(s,txt$)
Else
CreateText(s,txt$)
EndIF
SetTextPosition(s,GetPointerX(),GetPointerY())
SetTextSize(s,25)
SetTextColor(s,255,255,255,255)
EndIF
Else
DeleteAllText()
EndIF
If GetVirtualButtonPressed(1)
Load_AirfoilDatFile()
draw_airfoildots()
EndIF
draw_airfoillines()
If Len(fid) =0
Print("Please load an Airfoil DAT file, to Continue")
Else
Print("Airfoil: "+header)
Print("Data Points: "+Str(Counter))
Print(plot[s].s)
Print("Select Point to show X/Y data")
EndIF
Sync()
Loop
Function load_airfoilDatFile()
DeleteAllSprites()
DeleteAllText()
DrawEllipse(120,120,3,3,MakeColor(255,0,0,255),MakeColor(255,0,0,255),1)
dot = GetImage(117,117,6,6)
For a = 0 To plot.length - 1
plot[a].id=0
plot[a].s=""
plot[a].x=0
plot[a].y=0
plot[a].Calc_x=0
plot[a].Calc_y=0
Next a
fid = ChooseRawFile("*.dat",1)
a = OpenToRead("raw:"+fid)
counter=0
While FileEOF(a) = 0
If counter = 0
header = ReadLine(a)
Inc counter
Else
plot[counter].s = ReadLine(a)
Inc counter
plot[counter].id = counter
EndIF
EndWhile
CloseFile(a)
For a = 0 To plot.length - 1
If Len(plot[a].s) <> 0
plot[a].id = a
If a > 0
l = FindString(plot[a].s," ",1,1)
plot[a].x = ValFloat(Mid(plot[a].s,1,l))
plot[a].y = ValFloat(Mid(plot[a].s,l,Len(plot[a].s)-l))
plot[a].Calc_x = (((coord * plot[a].x) * scaleX) / 100)
plot[a].Calc_y = (((coord * plot[a].y) * scaley) / 100)
EndIF
EndIF
Next a
EndFunction
Function draw_airfoillines()
For a = 0 To plot.length - 1
If Len(plot[a].s) <> 0
If a = 1
DrawLine(StartX-50 , StartY , ScaleX+startx+50 , StartY ,120,120,120)
EndIF
If a > 1
DrawLine(StartX + plot[a].Calc_x, StartY - plot[a].Calc_y, StartX + plot[a-1].Calc_x, StartY - plot[a-1].Calc_y ,255,255,255)
EndIF
EndIF
Next a
EndFunction
Function draw_airfoildots()
For a = 1 To plot.length
If Len(plot[a].s) <> 0
If a > 1
spr[a] = CreateSprite(dot)
plot[a].id = spr[a]-100000
SetSpritePosition(spr[a],StartX + plot[a].Calc_x,StartY - plot[a].Calc_y)
EndIF
EndIF
Next a
EndFunction
Enjoy!!!