File mttroot/mtt/lib/control/PPP/ppp_ustar2h.m artifact d77ecc26ba part of check-in 2e8cbaac42


function ppp_ustar2h (Ustar,DT,name)

  ## usage:  ppp_Ustar2h (Ustar[,name])
  ##
  ## 

  if nargin<2
    DT = 1;
  endif
  
  if nargin<3
    name = "Ustar";
  endif

  [N,N_U] = size(Ustar);

  ## Open the file 
  filename = sprintf("%s.h", name);
  fid = fopen(filename,"w");

  ## Header
  header = sprintf("/*\n File %s generated by ppp_ustar2h on %s */\n", \
		   filename, ctime(time));

  def = sprintf("#define N_U %i\n#define N_T %i\n#define DT %g\n", \
		 N_U, N, DT);
  def = sprintf("%sdouble U[N_U]={",def);
  for j=1:N_U
    if j<N_U
      comma = ",";
    else
      comma = "";
    endif
    def = sprintf("%s0.0%s ",def, comma);
  endfor
  def = sprintf("%s};\n",def)

  fprintf(fid, "%s%sdouble %s[N_T][N_U] = {\n",header,def,name);
  for i=1:N
    fprintf(fid, "{");
    for j=1:N_U
      if j<N_U
	comma = ",";
      else
	comma = "";
      endif
      fprintf(fid, "%g%s ", Ustar(i,j),comma);
    endfor

    if i<N
      fprintf(fid, "},\n");
    else
      fprintf(fid, "}\n");
    endif
    
  endfor
  fprintf(fid, "};\n");

  fclose(fid);

endfunction

MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]