Prev: Optional arguments to Fortran statements
Next: fashion sunglasses wholesale from china,paypal payment and free shipping
From: Arjen Markus on 11 May 2010 07:26 On 10 mei, 20:00, Paul van Delst <paul.vande...(a)noaa.gov> wrote: > In the absence of any "why I have to do it like this" details, I would recommend using a > scripting language for this sort of stuff. Your Fortran example of code generation is, in > particular, better suited to use of a language like ruby, python, perl, etc. > > I use ruby to create boilerplate code all the time (e.g. writing the netcdf function calls > to write an arbitrary Fortran derived type to a netcdf format file). I've seen people use > perl to do similar. > > It does, of course, require a bit more up front work devising a system to get the > generated code snippets into a generic whole to result in a compilable unit. > > Anyway... > > cheers, > > paulv > > p.s. BTW, use of the execute statement in IDL, or its equivalent in other languages, tends > to make those wary IT security types get really nervous. Especially if you want to the > script to accept the command.... which, in IDL, hopefully isn't something like: > SPAWN, 'cd ~; rm -fr *' > > > > toylas wrote: > > Dear all, > > > I generally use the execute statement in IDL. For people who do not > > know IDL, here is the description of the statement from the help page: > > > The EXECUTE function compiles and executes one or more IDL statements > > contained in a string at run-time. > > Here's an example: > > ================================== > > for i=0,n do begin > > comm='readu,'+stringns(i+1)+','+filevars(i) > > x=execute(comm) > > endfor > > ================================== > > So this will create strings like > > readu,1,bx > > readu,2,by > > etc.. for filevars=('bx','by',...) > > > Now I want to do something like this in Fortran. I want to create an > > array > > > =================================== > > character :: comm_string > > vars=(/ 'bx','by','bz','vx','vy','vz','jx','jy',jz' /) > > =================================== > > > and then do something like this: > > > =================================================== > > do i=1,9 > > write(comm_string, appropriate format) 'call > > test(',vars(i),',f',vars(i),')' > > execute(comm_string) > > enddo > > =================================================== > > which would do something like: > > > call test(bx,fbx) > > call test(by,fby) > > . > > . > > . > > call test(jz,fjz) > > > I know this can be done in C too but have not been able to find out a > > way to do it in fortran. I was unable to find any useful information > > using google. > > > Does anybody know how to do it? > > > Thanks- Tekst uit oorspronkelijk bericht niet weergeven - > > - Tekst uit oorspronkelijk bericht weergeven - I have developed an interface between Fortran and Tcl that is quite capable of this sort things. See: http://ftcl.sf.net. Regards, Arjen |