separated femwind_solve from femwind_main
[wrf-fire-matlab.git] / femwind / femwind_solve_fortran.m
blob184111c3d730bec015a29ee74df74c07d99eda4b
1 function [w,rate]=femwind_solve_fortran(A,X,u0,params)
3 exe  = './fortran/femwind_solve.exe';
4 if exist(exe,'file') & params.run_fortran
5     write_array_nd(swap23(X{1}),'X');
6     write_array_nd(swap23(X{2}),'Y');
7     write_array_nd(swap23(X{3}),'Z');
8     write_array_nd(swap23(u0{1}),'Xu0');
9     write_array_nd(swap23(u0{2}),'Yu0');
10     write_array_nd(swap23(u0{3}),'Zu0');
12     write_array(A,'A')
13     write_array(iflags,'iflags')
15     % defaults
16     Xw =zeros(nel);
17     Yw =zeros(nel);
18     Zw =zeros(nel);
19     rate=0;
21     try
22         disp(['running ',exe])
23         system(exe);
24         Xw=swap23(read_array_nd('Xw'));
25         Yw=swap23(read_array_nd('Yw'));
26         Zw=swap23(read_array_nd('Zw'));
27         rate=read_array_nd('rate');
28     catch
29         disp([exe,' failed'])
30     end
32     wf = {Xw,Yw,Zw};
33     w = wf;
34 end
36 if params.run_matlab
37     
38     [wm,rate]=femwind_solve(A,X,u0,params)
39     w = wm;
40 end
42 if exist('wf','var') & exist('wm','var')
44     tol = 10*eps(single(1.));
45     
46     wwf=cell2mat(uf);
47     wwm=cell2mat(um);
49     err= norm(wwf(:)-wwm(:),inf)/norm(wwm(:));
50     if err < tol
51         fprintf('error %g OK, tol = %g\n',err,tol)
52     else
53         warning(sprintf('error %g too large, tol=%g',err,tol))
54     end
56 end