ROBAST logo
/******************************************************************************
 * Copyright (C) 2006-, Akira Okumura                                         *
 * All rights reserved.                                                       *
 *****************************************************************************/

///////////////////////////////////////////////////////////////////////////////
//
// ARefractiveIndexDotInfo
//
// Wrapper class to read text files retreived from https://reflactiveindex.info
//
///////////////////////////////////////////////////////////////////////////////

#include <fstream>
#include <iostream>

#include "TSystem.h"

#include "AOpticsManager.h"
#include "ARefractiveIndexDotInfo.h"

ClassImp(ARefractiveIndexDotInfo);

ARefractiveIndexDotInfo::ARefractiveIndexDotInfo(const char* fname)
    : ARefractiveIndex() {
  std::ifstream fin;
  fin.open(gSystem->ExpandPathName(fname));

  if (!fin.is_open()) {
    Error("ARefractiveIndexDotInfo", "Cannot open %s", fname);
    return;
  }

  char buf[50];
  fin.getline(buf, 50);

  bool CSV;      // comma separated values
  bool CRLF;     // delimiter \r\n
  char S = ',';  // separator
  if (strcmp(buf, "wl,n\r") == 0) {
    CSV = true;
    CRLF = true;
  } else if (strcmp(buf, "wl,n") == 0) {
    CSV = true;
    CRLF = false;  // \n
  } else if (strcmp(buf, "wl\tn\r") == 0) {
    CSV = false;  // TSV, tab separated values
    S = '\t';
    CRLF = true;
  } else if (strcmp(buf, "wl\tn") == 0) {
    CSV = false;  // TSV, tab separated values
    S = '\t';
    CRLF = false;
  } else {
    Error("ARefractiveIndexDotInfo", "Invalid data format");
    return;
  }

  fRefractiveIndex = std::make_shared<TGraph>();

  while (1) {
    double wl, n;
    char* endptr;
    fin.getline(buf, 50, S);
    wl = strtod(buf, &endptr);
    if (*endptr != '\0') {  // cannot convert to double
      break;
    }
    fin.getline(buf, 50, CRLF ? '\r' : '\n');
    n = strtod(buf, &endptr);
    if (*endptr != '\0') {  // cannot convert to double
      break;
    }

    fRefractiveIndex->SetPoint(fRefractiveIndex->GetN(),
                               wl * AOpticsManager::um(), n);
  }

  // Check if extinction coefficient data exists
  fin.getline(buf, 50, CRLF ? '\r' : '\n');
  // "wl," or "wl\t" should have been alread read in the previous while loop
  if (strcmp(buf, "k") != 0) {
    return;
  }

  fExtinctionCoefficient = std::make_shared<TGraph>();

  while (1) {
    double wl, k;
    char* endptr;
    fin.getline(buf, 50, S);
    wl = strtod(buf, &endptr);
    if (*endptr != '\0') {  // cannot convert to double
      break;
    }
    fin.getline(buf, 50, CRLF ? '\r' : '\n');
    k = strtod(buf, &endptr);
    if (*endptr != '\0') {  // cannot convert to double
      break;
    }

    fExtinctionCoefficient->SetPoint(fExtinctionCoefficient->GetN(),
                                     wl * AOpticsManager::um(), k);
  }
}
 ARefractiveIndexDotInfo.cxx:1
 ARefractiveIndexDotInfo.cxx:2
 ARefractiveIndexDotInfo.cxx:3
 ARefractiveIndexDotInfo.cxx:4
 ARefractiveIndexDotInfo.cxx:5
 ARefractiveIndexDotInfo.cxx:6
 ARefractiveIndexDotInfo.cxx:7
 ARefractiveIndexDotInfo.cxx:8
 ARefractiveIndexDotInfo.cxx:9
 ARefractiveIndexDotInfo.cxx:10
 ARefractiveIndexDotInfo.cxx:11
 ARefractiveIndexDotInfo.cxx:12
 ARefractiveIndexDotInfo.cxx:13
 ARefractiveIndexDotInfo.cxx:14
 ARefractiveIndexDotInfo.cxx:15
 ARefractiveIndexDotInfo.cxx:16
 ARefractiveIndexDotInfo.cxx:17
 ARefractiveIndexDotInfo.cxx:18
 ARefractiveIndexDotInfo.cxx:19
 ARefractiveIndexDotInfo.cxx:20
 ARefractiveIndexDotInfo.cxx:21
 ARefractiveIndexDotInfo.cxx:22
 ARefractiveIndexDotInfo.cxx:23
 ARefractiveIndexDotInfo.cxx:24
 ARefractiveIndexDotInfo.cxx:25
 ARefractiveIndexDotInfo.cxx:26
 ARefractiveIndexDotInfo.cxx:27
 ARefractiveIndexDotInfo.cxx:28
 ARefractiveIndexDotInfo.cxx:29
 ARefractiveIndexDotInfo.cxx:30
 ARefractiveIndexDotInfo.cxx:31
 ARefractiveIndexDotInfo.cxx:32
 ARefractiveIndexDotInfo.cxx:33
 ARefractiveIndexDotInfo.cxx:34
 ARefractiveIndexDotInfo.cxx:35
 ARefractiveIndexDotInfo.cxx:36
 ARefractiveIndexDotInfo.cxx:37
 ARefractiveIndexDotInfo.cxx:38
 ARefractiveIndexDotInfo.cxx:39
 ARefractiveIndexDotInfo.cxx:40
 ARefractiveIndexDotInfo.cxx:41
 ARefractiveIndexDotInfo.cxx:42
 ARefractiveIndexDotInfo.cxx:43
 ARefractiveIndexDotInfo.cxx:44
 ARefractiveIndexDotInfo.cxx:45
 ARefractiveIndexDotInfo.cxx:46
 ARefractiveIndexDotInfo.cxx:47
 ARefractiveIndexDotInfo.cxx:48
 ARefractiveIndexDotInfo.cxx:49
 ARefractiveIndexDotInfo.cxx:50
 ARefractiveIndexDotInfo.cxx:51
 ARefractiveIndexDotInfo.cxx:52
 ARefractiveIndexDotInfo.cxx:53
 ARefractiveIndexDotInfo.cxx:54
 ARefractiveIndexDotInfo.cxx:55
 ARefractiveIndexDotInfo.cxx:56
 ARefractiveIndexDotInfo.cxx:57
 ARefractiveIndexDotInfo.cxx:58
 ARefractiveIndexDotInfo.cxx:59
 ARefractiveIndexDotInfo.cxx:60
 ARefractiveIndexDotInfo.cxx:61
 ARefractiveIndexDotInfo.cxx:62
 ARefractiveIndexDotInfo.cxx:63
 ARefractiveIndexDotInfo.cxx:64
 ARefractiveIndexDotInfo.cxx:65
 ARefractiveIndexDotInfo.cxx:66
 ARefractiveIndexDotInfo.cxx:67
 ARefractiveIndexDotInfo.cxx:68
 ARefractiveIndexDotInfo.cxx:69
 ARefractiveIndexDotInfo.cxx:70
 ARefractiveIndexDotInfo.cxx:71
 ARefractiveIndexDotInfo.cxx:72
 ARefractiveIndexDotInfo.cxx:73
 ARefractiveIndexDotInfo.cxx:74
 ARefractiveIndexDotInfo.cxx:75
 ARefractiveIndexDotInfo.cxx:76
 ARefractiveIndexDotInfo.cxx:77
 ARefractiveIndexDotInfo.cxx:78
 ARefractiveIndexDotInfo.cxx:79
 ARefractiveIndexDotInfo.cxx:80
 ARefractiveIndexDotInfo.cxx:81
 ARefractiveIndexDotInfo.cxx:82
 ARefractiveIndexDotInfo.cxx:83
 ARefractiveIndexDotInfo.cxx:84
 ARefractiveIndexDotInfo.cxx:85
 ARefractiveIndexDotInfo.cxx:86
 ARefractiveIndexDotInfo.cxx:87
 ARefractiveIndexDotInfo.cxx:88
 ARefractiveIndexDotInfo.cxx:89
 ARefractiveIndexDotInfo.cxx:90
 ARefractiveIndexDotInfo.cxx:91
 ARefractiveIndexDotInfo.cxx:92
 ARefractiveIndexDotInfo.cxx:93
 ARefractiveIndexDotInfo.cxx:94
 ARefractiveIndexDotInfo.cxx:95
 ARefractiveIndexDotInfo.cxx:96
 ARefractiveIndexDotInfo.cxx:97
 ARefractiveIndexDotInfo.cxx:98
 ARefractiveIndexDotInfo.cxx:99
 ARefractiveIndexDotInfo.cxx:100
 ARefractiveIndexDotInfo.cxx:101
 ARefractiveIndexDotInfo.cxx:102
 ARefractiveIndexDotInfo.cxx:103
 ARefractiveIndexDotInfo.cxx:104
 ARefractiveIndexDotInfo.cxx:105