Difference between revisions of "Rupture Variation Generator v5.4.2 code changes"

From SCECpedia
Jump to navigationJump to search
Line 168: Line 168:
 
         ${CC} -c -o genslip-v5.4.2.o genslip-v5.4.2.c ${LDLIBS}</pre>
 
         ${CC} -c -o genslip-v5.4.2.o genslip-v5.4.2.c ${LDLIBS}</pre>
 
Note that if you copy/paste the line above, make will probably give you a whitespace error.  Remember to replace the whitespace in front of ${CC} with a tab.</li>
 
Note that if you copy/paste the line above, make will probably give you a whitespace error.  Remember to replace the whitespace in front of ${CC} with a tab.</li>
 +
</ol>
 +
 +
=== genslip-v5.4.2.c ===
 +
 +
This is where the majority of changes are made to turn this into an API. I recommend having an original copy for reference.
 +
 +
<ol>
 +
<li>In line 352, change from
 +
<pre>
 +
int main(int ac,char **av)
 +
</pre>
 +
to
 +
<pre>
 +
#ifdef _USE_MEMCACHED
 +
int mc_genslip(int ac, char** av, rg_stats_t *stats, struct standrupformat* srf, int state, char* memcached_server)
 +
#else
 +
int genslip(int ac,char **av, rg_stats_t *stats, struct standrupformat* srf, int state)
 +
#endif
 +
</pre></li>
 +
<li>Change target_hypo_spacing to 4.5:
 +
<pre>float target_hypo_spacing = 4.5;</pre></li>
 +
 
</ol>
 
</ol>

Revision as of 20:35, 2 October 2019

This page documents the code changes required to turn the stand-alone version, genslip-v5.4.2, into an API callable by the CyberShake post-processing.

In this document, $ROOT_DIR is taken to be the <CyberShake home>/software/RuptureCodes/RupGen-api-5.4.2 directory. GenRandV5.0 is the code as received from Rob Graves.

Installing files

  1. Create src, include, lib, and bin directories inside $ROOT_DIR .
  2. Inside src, create GenRandV5.0.
  3. Copy rupgen_api.c from a previous API version into src.
  4. Copy rupgen_defs.h from a previous API version into src.
  5. Copy rupgen_api.h from a previous API version into src.
  6. Confusingly, there are two files named structure.h. One is in StandRupFormat and contains the structures needed for an SRF. The other is in GenRandV5.0 and contains the definition for complex, along with a few other supporting structures.
    1. Copy the StandRupFormat/structure.h into src/srf_structure.h .
    2. Copy the GenRandV5.0/structure.h into src/structure.h .
    3. Create a symlink to both files in src/GenRandV5.0.
  7. There are also two files named defs.h.
    1. Copy GenRandV5.0/StandRupFormat/defs.h into src/GenRandV5.0/srf_defs.h .
    2. Copy GenRandV5.0/defs.h into src/GenRandV5.0/defs.h .
  8. From the code provided by Rob, copy the following files into src/GenRandV5.0:
    • defs.h
    • function.h
    • include.h
    • genslip-v5.4.2.c
    • iofunc.c
    • misc.c
    • ruptime.c
    • slip.c
    • srf_subs.c (from StandRupFormat)
    • makefile
  9. Copy Makefile from a previous API version into src.

Editing files

In $ROOT_DIR/src

structure.h

  1. At the top of the file, change '#include "StandRupFormat/structure.h"' to '#include srf_structure.h'
  2. Above that line, add:
    #ifndef STRUCT_H
    #define STRUCT_H
    
  3. At the end of the file, add:
    #endif
    

srf_structure.h

  1. At the top of the file, add:
    #ifndef SRF_STRUCT_H
    #define SRF_STRUCT_H
    
  2. At the end of the file, add:
    #endif
    

Makefile

  1. Edit the GETPAR values to point to the getpar install.
  2. Edit GENSLIP to have the same name as the GenRandV5.0 directory.
  3. Edit the library creation line (under the librupgen.a target, starts with $(AR)) to point to the correct version of genslip.

In GenRandV5.0

defs.h

  1. At the top of the file, add:
    #ifndef DEFS_H
    #define DEFS_H
    
    #include "srf_defs.h"
    
  2. Delete DEFAULT_SHAL_VRUP_FRAC, as it is not used anymore.
  3. At the end of the file, add:
    #endif
    

srf_defs.h

  1. At the top of the file, add:
    #ifndef SRF_DEFS_H
    #define SRF_DEFS_H
    
  2. Delete DEFAULT_SHAL_VRUP_FRAC, as it is not used anymore.
  3. Delete the lines corresponding to RDONLY_FLAGS, RDWR_FLAGS, CROPTR_FLAGS, and the _FILE_OFFSET_BITS if statement, as this already exists in defs.h.
  4. At the end of the file, add:
    #endif
    

include.h

  1. At the top of the file, add:
    #ifndef RUPGEN_INCLUDE_H
    #define RUPGEN_INCLUDE_H
    
  2. At the end of the file, add:
    #include <string.h>
    #include "fftw3.h"
    
    #ifdef _USE_MEMCACHED
    #include <libmemcached/memcached.h>
    #endif
    
    #endif
    

function.h

  1. At the top of the file, add:
    #ifndef RUPGEN_FUNC_H
    #define RUPGEN_FUNC_H
    
    #include "structure.h"
    
  2. At the end of the file, add:
    void write_srf1(struct standrupformat *srf,char *file,int bflag);
    void write_srf2(struct standrupformat *srf,char *file,int bflag);
    
    #endif
    

makefile

  1. Edit the 2nd line that begins with OBJS so it contains
    OBJS = iofunc.o misc.o slip.o ruptime.o srf_subs.o
    
  2. Delete the SRF_OBJS and FDRT_OBJS lines, 3-5.
  3. Edit GETPARLIB and GETPARINC so it correctly points to the Getpar install in <CyberShake home>/software/Getpar .
  4. Delete all targets except genslip-v5.4.2, ${OBJS}, and clean.
  5. Modify the genslip-v5.4.2 target. We need to remove unnecessary objects, and compile it to an object rather than an executable for inclusion in the genslip library. It should look like:
  6. genslip-v5.4.2.o : genslip-v5.4.2.c ${OBJS}
            ${CC} -c -o genslip-v5.4.2.o genslip-v5.4.2.c ${LDLIBS}
    Note that if you copy/paste the line above, make will probably give you a whitespace error. Remember to replace the whitespace in front of ${CC} with a tab.

genslip-v5.4.2.c

This is where the majority of changes are made to turn this into an API. I recommend having an original copy for reference.

  1. In line 352, change from
    int main(int ac,char **av)
    

    to

    #ifdef _USE_MEMCACHED
    int mc_genslip(int ac, char** av, rg_stats_t *stats, struct standrupformat* srf, int state, char* memcached_server)
    #else
    int genslip(int ac,char **av, rg_stats_t *stats, struct standrupformat* srf, int state)
    #endif
    
  2. Change target_hypo_spacing to 4.5:
    float target_hypo_spacing = 4.5;