xref: /petsc/src/sys/tests/ex51.c (revision c8025a5415d73fd1c6005393f2b0e60677bf5915)
1c4762a1bSJed Brown static char help[] = "Demonstrates PetscFileRetrieve().\n\n";
2c4762a1bSJed Brown 
3c4762a1bSJed Brown #include <petscsys.h>
4d71ae5a4SJacob Faibussowitsch int main(int argc, char **argv)
5d71ae5a4SJacob Faibussowitsch {
6c4762a1bSJed Brown   PetscBool  found;
7c4762a1bSJed Brown   char       localname[PETSC_MAX_PATH_LEN];
8ae13f97fSSatish Balay   const char url[] = "https://web.cels.anl.gov/projects/petsc/download/datafiles/matrices/tiny";
9c4762a1bSJed Brown 
10c4762a1bSJed Brown   /*
11c4762a1bSJed Brown     Every PETSc routine should begin with the PetscInitialize() routine.
12c4762a1bSJed Brown     argc, argv - These command line arguments are taken to extract the options
13c4762a1bSJed Brown                  supplied to PETSc and options supplied to MPI.
14c4762a1bSJed Brown     help       - When PETSc executable is invoked with the option -help,
15c4762a1bSJed Brown                  it prints the various options that can be applied at
16c4762a1bSJed Brown                  runtime.  The user can use the "help" variable place
17c4762a1bSJed Brown                  additional help messages in this printout.
18c4762a1bSJed Brown   */
19327415f7SBarry Smith   PetscFunctionBeginUser;
20*c8025a54SPierre Jolivet   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
219566063dSJacob Faibussowitsch   PetscCall(PetscFileRetrieve(PETSC_COMM_WORLD, url, localname, PETSC_MAX_PATH_LEN, &found));
22c4762a1bSJed Brown   if (found) {
239566063dSJacob Faibussowitsch     PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Successfully download file %s\n", localname));
2498921bdaSJacob Faibussowitsch   } else SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Unable to download url %s", url);
25c4762a1bSJed Brown 
269566063dSJacob Faibussowitsch   PetscCall(PetscFinalize());
27b122ec5aSJacob Faibussowitsch   return 0;
28c4762a1bSJed Brown }
29c4762a1bSJed Brown 
30c4762a1bSJed Brown /*TEST
31c4762a1bSJed Brown 
32c4762a1bSJed Brown    test:
33dfd57a17SPierre Jolivet      requires: defined(PETSC_HAVE_POPEN)
34c4762a1bSJed Brown 
35c4762a1bSJed Brown TEST*/
36