Changeset 56


Ignore:
Timestamp:
08/30/11 11:18:11 (21 months ago)
Author:
joseba
Message:

started reading the UPF file.
Some other doc corrections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/read_upf.c

    r50 r56  
    2424 
    2525#include <pspio.h> 
    26 #include <stdio.h> 
     26#include "stdio.h" 
    2727 
     28/** 
     29 * Init the UPF file read 
     30 * @param[in,out] psp_data the data structure 
     31 * @param[in] fp a stream of the input file 
     32 * @return error code 
     33 */ 
     34int pspio_upf_init(char FILE * fp, pspio_pspdata_t * psp_data); 
     35int pspio_upf_end(pspio_pspdata_t * psp_data); 
     36int pspio_upf_file_read(FILE * fp, pspio_pspdata_t * psp_data); 
    2837 
    29 int init_tag(int unit, char * string, int go_back); 
     38int tag_isdef(FILE * fp, char * string); 
     39int init_tag(FILE * fp, char * string, int go_back); 
    3040int check_end_tag(char * tag); 
    31 int ps_upf_init(pspio_pspdata_t * ps_upf, char * filename); 
    32 int ps_upf_end(pspio_pspdata_t * ps_upf); 
    33 int ps_upf_file_read(int unit, pspio_pspdata_t * ps_upf); 
    34 int tag_isdef(int unit, char * string); 
    3541 
    36 int ps_upf_cutoff_radii(pspio_pspdata_t * ps_upf); 
     42int pspio_upf_cutoff_radii(pspio_pspdata_t * psp_data); 
     43 
    3744/** 
    3845 * checks normalization of the pseudo wavefunctions 
    3946 */    
    40 int ps_upf_check_rphi(pspio_pspdata_t * ps_upf); 
     47int pspio_upf_check_rphi(pspio_pspdata_t * psp_data); 
     48 
     49 
     50 
     51 /* start the implementations */ 
     52/*****************************/ 
     53int  pspio_upf_init(char FILE * fp, pspio_pspdata_t * psp_data){ 
     54  char tmp_filename[256]; 
     55  int ierr; 
     56   
     57  pspio_upf_file_read(fp,psp_data); 
     58} 
     59 
     60int pspio_upf_file_read(FILE * fp, pspio_pspdata_t * psp_data){ 
     61  int ierr; 
     62  int version_number; 
     63  char line[MAX_LINE + 1]; 
     64   
     65  init_tag(fp,"PP_HEADER", 1); 
     66  fscanf(fp,"%d",version_number); //read the version number 
     67  fgets(line, sizeof line, fp); //skip the rest of the line 
     68  fgets(psp_data->symbol, sizeof line, fp); //read the symbol 
     69  fgets(line, 2, fp);  // kind of pseudo-potentials US|NC|PAW    "Ultrasoft|Norm conserving|Projector-augmented"  
     70  if (!strncpm(line,"NC",2)) { 
     71    printf("LIBPSP_IO can only read norm-conserving pseudo-potentials from UPF format."); 
     72    return PSPIO_TYPE_ERROR; 
     73  } 
     74  fscanf(fp,"%d",psp_data->nlcc); // read the nonlinear core correction 
     75  fgets(line, sizeof line, fp); //skip the rest of the line 
     76  fscanf(fp,"%d",psp_data->exchange); //read the exchange-correlation functional !!CORRECTION NEEDED!!!!!!!!!!!!!!!!! either we have to skipt or read it like in LIBXC 
     77  //read(unit,*) dummy                ! dft      "Exch-Corr"                                                                                                                                                           
     78  fgets(line, sizeof line, fp); //skip the rest of the line 
     79  fscanf(fp,"%4.11f",psp_data->zvalence); //read the Z valence 
     80  fgets(line, sizeof line, fp); //skip the rest of the line 
     81  fgets(line, sizeof line, fp); //skip the total energy 
     82  fscanf(fp,"4.7f",psp_data->rc); //read the suggested cutoff for wfc 
     83  //fscanf ??? read the suggested cutoff for rho 
     84  fgets(line, sizeof line, fp); //skip the rest of the line 
     85  fscanf(fp,"%d",psp_data->lmax); //read the max angular momentun component (Note: is not the lmax needed by Octopus 
     86  fgets(line, sizeof line, fp); //skip the rest of the line 
     87  fscanf(fp,"%d",psp_data->states->np); //read the number of points in mesh 
     88  fgets(line, sizeof line, fp); //skip the rest of the line 
     89  fscanf(fp,"%d %d",psp_data->n_states,psp_data->pspio_kb_projectors_t->nproj);  //read the number of wavefunctions, projector  
     90 
     91  //read the wavefuntions: @todo 
     92   
     93} 
     94 
     95int init_tag(FILE * fp, char * string, int go_back){ 
     96  char line[MAX_LINE + 1]; 
     97  char * compare_string = NULL; 
     98  if (go_back) rewind(fp); 
     99   
     100  strcat(compare_string,"<"); 
     101  strncat(compare_string,string,strlen(string)); 
     102  strcat(compare_string,">"); 
     103   
     104  while(fgets(line, sizeof line, fp) != NULL){ 
     105    if( strcamp(line,compare_string) ) return; 
     106  } 
     107} 
     108 
Note: See TracChangeset for help on using the changeset viewer.