Hi there. My ingredients are some coordinates and a function N that returns a 4-element Vector. I need to create a txt file that has as colums x,y, N[1], N[2], N[3] and N[4].
Two other important info are that N is created inside a loop on the x,y couples because there should be a very large number of x,y couples, and that I need this file to be nicely formatted because it needs to be read by an external software.
This is a semplified version of the code I use:
using DelimitedFiles
using Printf
include(shapef.jl)
npoin=10
x=rand(10)
y=rand(10)
shapeFile="shapef.txt"
fmt(a,b,c,d,e,f)=@sprintf("%3.1f %3.1f %5.2f %5.2f %5.2f %5.2f",a,b,c,d,e,f)
file=open("file.txt","a")
for ipoin=1:npoin
N=shapef(x[ipoin],y[ipoin])
println(file,fmt(x[ipoin],y[ipoin],N[1],N[2],N[3],N[4]))
end
close(file)
Where shapef.jl contains the following function:
function shapef(s,t)
N=zeros(nnode)
N[1]=0.25*(1+s)*(1+t)
N[2]=0.25*(1-s)*(1+t)
N[3]=0.25*(1-s)*(1-t)
N[4]=0.25*(1+s)*(1-t)
return N
end
This thing works more or less, but I would prefer to have a better formatting, so I would like to do the same thing with writedlm, do you know if it would be possible, and eventually how?