next up previous [pdf]

Next: A 2-D Modeling experiment Up: Forward modeling Previous: Forward modeling

Write your own code and run it as a test

You have to
  1. create a user directory in /RSFSRC/user/dirname, where dirname is the directory name, for example, 'pyang'.
  2. copy a SConstruct from other existing users, and use it as a template to create your own things. For example, take /RSFSRC/user/psava/SConstruct. Assume you are going to do C programming to generate a target executable sfmodeling2d. You need to empty all other code list while add a name in C code list: \begin{lstlisting}
import os, systry:
import bldutil
glob_build = True  ...

  3. Use text editor (emacs, gedit, ...) to create a file Mmodeling2d.c (which will generate the target sfmodeling2d, M will be automatically replaced by sf). In Mmodeling2d.c, start your codes by including the RSF header file: #include <rsf.h>, which defines many useful interfaces/subroutines for the convenience of data I/O (including parameters and files)
      sf_input()/sf_output()
      sf_histint()/sf_histfloat()
      sf_getint()/sf_getfloat()
    
    and memory allocation for the variables
      
      sf_intalloc()/sf_floatalloc()
      sf_intalloc2()/sf_floatalloc2()
      ...
    
    which will be used frequently when coding with Madagascar.

  4. specify your input and output files, and initialize Madagascar:
    \begin{lstlisting}
sf_file vinit, shots; /* input and output file*/
sf_init(arg...
... model in m/s */
shots=sf_output(''out''); /* output image */
\end{lstlisting} Here the input file vinit is the velocity model, while the output shots is a shot gather (or many shots) collected at many receivers for different sources.
  5. read the parameters from the input file using the interfaces Madagascar prepared: sf_hist*(),sf_get*() \begin{lstlisting}
/* get parameters for forward modeling */
if (!sf_histint(vin...
...
/* default, common shot-gather; if n, record at every point*/
\end{lstlisting}

  6. specify the parameters for the output file using the interfaces Madagascar prepared: sf_put*() \begin{lstlisting}
/* put the labels, legends and parameters in output */
sf_put...
...ts,''jgz'',jgz);
sf_putint(shots,''csdgather'',csdgather?1:0);
\end{lstlisting}

  7. allocate memory for the arries, format: sf_floatalloc2(n1,n2) \begin{lstlisting}
/* allocate the variables */
wlt=(float*)malloc(nt*sizeof(flo...
...int*)malloc(ns*sizeof(int));
gxz=(int*)malloc(ng*sizeof(int));
\end{lstlisting}

  8. do your own computation (forward simulation) as usual. The whole time stepping looks like \begin{lstlisting}
memset(p0[0],0,nz*nx*sizeof(float));
memset(p1[0],0,nz*nx*s...
...1=p2; p2=ptr;
record_seis(&dobs[it*ng], gxz, p0, ng, nz);
}
\end{lstlisting}

  9. free the variables \begin{lstlisting}
/* free the variables */
free(sxz);
free(gxz);
free(bndr);
fr...
...free(*p0); free(p0);
free(*p1); free(p1);
free(*p2); free(p2);\end{lstlisting}

  10. Finally, you end up with a complete code /RSFSRC/user/pyang/Mmodeling2d.c. You can go into directory RSFSRC, compile and install the target executable sfmodeling2d:
       cd $RSFSRC
       scons install
    
    If there exists any error in your code, you will get the reporting message in the terminal.


next up previous [pdf]

Next: A 2-D Modeling experiment Up: Forward modeling Previous: Forward modeling

2021-08-31